-
Notifications
You must be signed in to change notification settings - Fork 0
/
inco.c
69 lines (60 loc) · 1.27 KB
/
inco.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// (c) 2015 Allen R. Belletti
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "defs.h"
#include "comp.h"
#include "decomp.h"
#include "inco.h"
int Mode = DEFAULT;
int Debug = 0;
char *myName; // what name were we invoked with?
int main( int argc, char* argv[] )
{
int opt;
myName = basename( argv[0] );
while( -1 != (opt = getopt( argc, argv, OPTIONS )))
{
switch( opt )
{
case 'c':
Mode = COMPRESS;
break;
case 'd':
Mode = DECOMPRESS;
break;
case 'D':
Debug++;
break;
case '?':
case 'h':
showHelp();
exit( 1 );
}
}
switch( Mode )
{
case COMPRESS:
exit( comp() );
case DECOMPRESS:
exit( decomp() );
case DEFAULT:
// we'll take compress in the case of an unknown name
if( strcmp( myName, DECOMPNAME ))
exit( comp() );
else
exit( decomp() );
}
exit( 0 ); // unreachable
}
void showHelp( void )
{
fprintf( stderr, "usage: %s -%s\n", myName, OPTIONS );
fprintf( stderr, " -c : Compression mode\n" );
fprintf( stderr, " -d : Decompression mode\n" );
fprintf( stderr, " -D : Send debug output to stderr\n" );
fprintf( stderr, " -DD : Generate additional debug output\n" );
fprintf( stderr, " -h : This listing of options\n" );
}