Von C nach Java, Teil 4: Datenkompression und Verschlüsselung

Seite 7: Listing 3

Inhaltsverzeichnis
...
int main(int argc, char *argv[]) {
int argCnt=1, lastOpt=0, fileNameListCount=0;
char *args, **fileNameList=NULL;
bool argFollows=false;

if (argc > 1) {
while (--argc) {
args=argv[argCnt++];
if (*args=='-' && strlen(args)>1) {
int idx, length=strlen(args);
bool isBreak=false;

for (idx=1;idx<length;idx++) {
switch (lastOpt=args[idx]) {
case 'b': // blocksizeKB follows
if ((idx+1) < length) {
if ((blockSizeKB=
str2BlockSizeKB(&args[idx+1]))<0) usage();
isBreak=true;
} else {
argFollows=true;
}
break;
case 'd': // decompress
isDecompress=true; break;
case 'D': // debug
isDebug=true; break;
case 'f': // force overwriting
isForce=true; break;
case 'p': // password follows - implicitly sets
the crypt flag
isCrypt=true;
if ((idx+1) < length) {
passwd=&args[idx+1]; isBreak=true;
} else argFollows=true;
break;
case 'r': // remove source file
isRemoveSource=true; break;
case 't': // test file
isTest=true; break;
case 'v': // sets the verbose flag
isVerbose=true; break;
default: usage();
}
if (argFollows || isBreak) break;
}
continue;
}
if (argFollows) {
switch (lastOpt) {
case 'b': if ((blockSizeKB=
str2BlockSizeKB(args))<0) usage();
break;
case 'p': passwd=args; break;
}
argFollows=false; continue;
}
if (access(args, 0)==-1) {
fprintf(stderr,"unable to access \"%s\"\n", args);
exit(2);
}
fileNameList=realloc(fileNameList,(1+fileNameListCount)
*sizeof(char *));
fileNameList[fileNameListCount++]=args;
}
} else isStdIn=true;
...