int main(int argc, char *argv[]) { progName = argv[0]; if (argc == 1) { fprintf(stderr, "USAGE:\t%s [-rf] names...\n", argv[0]); fprintf(stderr, "\tDelete files or directories. If some of the names refer to\n"); fprintf(stderr, "\tdirectories, and -r is not passed, the directories must be empty.\n"); fprintf(stderr, "\n\t-r\n"); fprintf(stderr, "\t\tRemove recursively - directories and their contents are deleted.\n"); fprintf(stderr, "\n\t-f\n"); fprintf(stderr, "\t\tIf an given name does not exit, ignore silently, still returning success.\n"); return 1; }; int i; for (i=1; i<argc; i++) { if (argv[i][0] == '-') { processSwitches(argv[i]); } else { doRemove(argv[i]); }; }; return 0; };
int main( int argc, char **argv ) { char inputFilename[200]; vector<string> infiles; string str; string newid; // Kludgy way to pass this param around. // Better to have opts be a stuct rather than int. PET *pet; int opts; if( argc < 2 ) { say( "readPET: A PET file translation program for GE file formats." ); say( "Copyright (C) 2000-2005, Andrew Crabb\n"); say( "usage: readPET <inputfiles> [-abdhilmptvw]" ); say( "-a : Analyze: Convert to Analyze format." ); say( "-b : Becquerels: Use units of MBq/cc (default is nCi/cc)." ); say( "-d : Debug: Print debugging information." ); say( "-h : Header: Print short header to screen." ); say( "-i ID: Ident: Replace subject ID with supplied ID value." ); say( "-l : Long Header: Print LONG! header to screen." ); say( "-m : Mean Image: Calculate mean image and write to disk." ); say( "-p S : Parametric: Calculate parametric image files." ); say( " Model/slice range str S: -pMXX or -pMXX-YY." ); say( " Model M = (P)atlak or (L)ogan." ); say( " Slices XX to YY (0 indexed) inclusive." ); say( "-t : Times: Write temporal information to text file." ); say( "-v : Volume: Save all frames in one volume file." ); say( "-w : Write: Write data frames to disk." ); say( "Notes: Switches may be combined." ); say( " Input files may be GE Scanditronix or GE ADVANCE." ); say( " Output PET image files are decay corrected." ); say( "" ); // cout << endres << endl; cout << disclaimer << endl; exit( -1 ); } // infiles initially holds all cmd line arguments. for ( int i = 1; i < argc; i++ ) { str = argv[i]; infiles.push_back( str ); } // processSwitches returns all non-switch cmd line arguments. opts = processSwitches( infiles, newid ); cout << "readPET: newid " << newid << endl; switch( whatHaveWeHere( infiles )) { case PET::ADVANCE: pet = new Advance( opts ); break; case PET::SCANDITRONIX: pet = new Scanditronix; break; default: if ( infiles.size() ) cerr << "Unknown file type: " << infiles[0] << endl; else cerr << "No input file supplied" << endl; exit( 0 ); } // *** KLUDGE *** pet->kludgeSetID( newid ); if ( pet->read( infiles, opts )) exit( 1 ); if ( opts & ( PET::OPT_WRIT | PET::OPT_VOLU )) pet->write( opts ); if ( opts & PET::OPT_PARA ) { if ( !pet->initializeParametric( modelType )) pet->parametric( opts, slices ); } if ( opts & PET::OPT_MEAN ) { pet->makeMean( opts ); pet->writeMean( opts ); } if ( opts & ( PET::OPT_TIME )) pet->writeTimes(); delete( pet ); exit( 0 ); }
int main(int argc, char *argv[]) { progName = argv[0]; char *chspec = NULL; const char **files = NULL; int numFiles = 0; int i; for (i=1; i<argc; i++) { if (argv[i][0] == '-') { processSwitches(argv[i]); } else if (chspec == NULL) { chspec = argv[i]; } else { files = realloc(files, sizeof(const char*)*(++numFiles)); files[numFiles-1] = argv[i]; }; }; if (numFiles == 0) { usage(); return 1; }; const char *newOwner = chspec; const char *group = NULL; char *colonAt = strchr(chspec, ':'); if (colonAt != NULL) { *colonAt = 0; group = &colonAt[1]; }; struct passwd *pwd = getpwnam(newOwner); if (pwd == NULL) { fprintf(stderr, "%s: user '%s' not found\n", argv[0], newOwner); return 1; }; newUID = pwd->pw_uid; if (group != NULL) { struct group *grp = getgrnam(group); if (grp == NULL) { fprintf(stderr, "%s: group '%s' not found\n", argv[0], group); return 1; }; newGID = grp->gr_gid; }; for (i=0; i<numFiles; i++) { doChangeOwner(files[i]); }; return 0; };