/*----------------------------------------------------------------------------*/ int read_options(STUFFS *pstuffs, int argc, char* argv[]) { int loop, length; for(loop=1;loop<argc;loop++) { if(strcmp(argv[loop],"-o")==0) { loop++; if(loop==argc) { fprintf(stderr,"No output file for '-o'\n"); pstuffs->errc = ERROR_OFILE_NONAME; break; } pstuffs->hfile = argv[loop]; } else if(strcmp(argv[loop],"-l")==0) { loop++; if(loop==argc) { fprintf(stderr,"No listing file for '-l'\n"); pstuffs->errc = ERROR_LFILE_NONAME; break; } pstuffs->lfile = argv[loop]; } else if(strcmp(argv[loop],"-m")==0) { loop++; if(loop==argc) { fprintf(stderr,"No name given for '-m'\n"); pstuffs->errc = ERROR_MFILE_NONAME; break; } pstuffs->mfile = argv[loop]; pstuffs->opt_flag |= OPT_GENERATE_VMF; } else if(strcmp(argv[loop],"-c")==0) { pstuffs->opt_flag |= OPT_GENERATE_HEX; } else if(argv[loop][0]=='-') { fprintf(stderr,"Unknown parameter %s\n",argv[loop]); pstuffs->errc = ERROR_UNKNOWN_PARAM; break; } else { if(pstuffs->afile) { fprintf(stderr, "Multiple input '%s' & '%s'\n", argv[loop],pstuffs->afile); pstuffs->errc = ERROR_MULTIPLE_INPUT; break; } pstuffs->afile = argv[loop]; } } /* check filename assignments */ do { /* check previous error */ if(pstuffs->errc<0) break; /* check for input file */ if(!pstuffs->afile) { if(argc>1) { fprintf(stderr, "No input file given!\n"); pstuffs->errc = ERROR_INPUT_NOT_GIVEN; } else { usage(); pstuffs->errc = ERROR_SHOW_USAGE; } break; } /* assign default output filenames */ if(!pstuffs->hfile) { length = strlen(pstuffs->afile)+4; pstuffs->filename = malloc(length); strcpy(pstuffs->filename,pstuffs->afile); stripfilename(pstuffs->filename, 1, 1); strcat(pstuffs->filename,".hex"); pstuffs->hfile = pstuffs->filename; break; } } while(0); return pstuffs->errc; }
int main(int argc, char *argv[]) { int k, i, n, c; int firstarg=1; FILE *input, *output; /* char destination[FILENAME_MAX]; */ char infilecivil[FILENAME_MAX], outfilecivil[FILENAME_MAX]; time_t infiletime, outfiletime; char *s; time_t timenow; /* time_t targettime, sourcetime; */ /* First lay in background of current date and time */ timenow = time (NULL); if (timenow == -1) fprintf(stderr, "Time does not exist!\n"); tm = localtime (&timenow); year = tm->tm_year + 1900; month = tm->tm_mon; day = tm->tm_mday; hour = tm->tm_hour; minute = tm->tm_min; second = tm->tm_sec; defyear = year; /* remember current year */ defmonth = month; /* remember current month */ defday = day; /* remember current day */ /* if (argc < firstarg + 2) { */ if (argc < firstarg + 1) showusage (argc, argv); firstarg = commandline(argc, argv, firstarg); /* if (argc < firstarg + 2) { */ if (argc < firstarg + 1) showusage(argc, argv); /* if (verboseflag != 0) */ if (verboseflag != 0 && (startchar != 0 || endchar != 255)) printf("Start %d (%c) end %d (%c)\n", startchar, startchar, endchar, endchar); if (strcmp(destination, "") == 0) { /* last arg is destination direct ? */ /* strcpy(destination, argv[argc-1]); */ destination = argv[argc-1]; /* the old way of doing this */ argc--; printf("WARNING: destination not specified, using %s\n", destination); } if (verboseflag) printf("Destination is %s\n", destination); /* for (k = firstarg; k < argc-1; k++) { */ for (k = firstarg; k < argc; k++) { strcpy(infilename, argv[k]); s = stripfilename(infilename); c = *s; /* 1992/Oct/ 11 */ if (c >= 'a' && c <= 'z') c = c + 'A' - 'a'; if (c < startchar || c > endchar) continue; strcpy(outfilename, destination); strcat(outfilename, "\\"); strcat(outfilename, s); if (getinfo(infilename, 0) < 0) continue; /* infiletime = statbuf.st_atime; */ infiletime = statbuf[0].st_atime; strcpy(infilecivil, timeptr); if (traceflag != 0) printf("Considering file %s\n", infilename); if (thresholdflag) { if (infiletime < newtime){ if (verboseflag) printf("%s not younger than threshold\n", infilename); continue; } } if (getinfo(outfilename, 1) < 0) { outfiletime = 0; strcpy(outfilecivil, ""); } else { /* outfiletime = statbuf.st_atime; */ outfiletime = statbuf[1].st_atime; strcpy(outfilecivil, timeptr); } /* if (outfiletime == 0 || outfiletime < infiletime) { */ if (outfiletime != 0 && outfiletime >= infiletime) { if (traceflag) printf("Not younger than destination\n"); continue; } /* printf("Copying %s ", infilename); */ printf("Copying %s ", s); /* if (strcmp(outfilecivil, "") != 0) { */ n = strlen(s); for (i = n; i < 14; i++) putc(' ', stdout); printf("new: %s ", infilecivil); if (strcmp(outfilecivil, "") != 0) printf("old: %s", outfilecivil); /* } */ printf("\n"); if ((input = fopen(infilename, "rb")) == NULL) { perror(infilename); continue; } if (outputflag == 0) { printf("Skipping %s\n", outfilename); fclose(input); continue; } if (safeflag != 0) { /* temporary, until debugged */ if ((output = fopen(outfilename, "rb")) != NULL) { fclose(output); printf("%s already exist\n", outfilename); fclose(input); continue; } } if ((output = fopen(outfilename, "wb")) == NULL) { fclose(input); perror(outfilename); exit(3); } /* while ((c = getc(input)) != EOF) putc(c, output); */ copyfile(output, input); if (ferror(input) != 0) { perror(infilename); } fclose(input); if (ferror(output) != 0) { perror(outfilename); exit(5); } fclose(output); if (copydate != 0) { timebuf.actime = statbuf[0].st_atime; timebuf.modtime = statbuf[0].st_atime; /* if (utime(argv[k], &timebuf) != 0) { */ /* if (utime(outfilename, &timebuf) != 0) { */ if (_utime(outfilename, &timebuf) != 0) { fprintf(stderr, "Unable to modify date/time\n"); perror(argv[1]); exit(3); } } /* } */ /* if (traceflag != 0) { if (getinfo(argv[1]) < 0) exit(1); } */ } return 0; }