[BACK]Return to diff.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / diff

Diff for /src/usr.bin/diff/diff.c between version 1.5 and 1.6

version 1.5, 2003/06/25 07:26:59 version 1.6, 2003/06/25 17:49:22
Line 53 
Line 53 
 char pr[] = _PATH_PR;  char pr[] = _PATH_PR;
   
 static void noroom(void);  static void noroom(void);
   __dead void usage(void);
   
 int  int
 main(int argc, char **argv)  main(int argc, char **argv)
 {  {
         char *argp;          int ch;
   
         ifdef1 = "FILE1";          ifdef1 = "FILE1";
         ifdef2 = "FILE2";          ifdef2 = "FILE2";
         status = 2;          status = 2;
         diffargv = argv;          diffargv = argv;
         argc--, argv++;  
         while (argc > 2 && argv[0][0] == '-') {          while ((ch = getopt(argc, argv, "bC:cDefhilnrS:stw")) != -1) {
                 argp = &argv[0][1];                  switch (ch) {
                 argv++, argc--;                  case 'b':
                 while (*argp)                          bflag++;
                         switch (*argp++) {                          break;
 #ifdef notdef                  case 'C':
                         case 'I':                          opt = D_CONTEXT;
                                 opt = D_IFDEF;                          if (!isdigit(*optarg))
                                 wantelses = 0;                                  usage();
                                 continue;                          context = atoi(optarg); /* XXX - use strtol */
                         case 'E':                          break;
                                 opt = D_IFDEF;                  case 'c':
                                 wantelses = 1;                          opt = D_CONTEXT;
                                 continue;                          context = 3;
                         case '1':                          break;
                                 opt = D_IFDEF;                  case 'D':
                                 ifdef1 = argp;                          /* -Dfoo = -E -1 -2foo */
                                 *--argp = 0;                          opt = D_IFDEF;
                                 continue;                          ifdef1 = "";
 #endif                          ifdef2 = optarg;
                         case 'D':                          wantelses++;
                                 /* -Dfoo = -E -1 -2foo */                          break;
                                 wantelses = 1;                  case 'e':
                                 ifdef1 = "";                          opt = D_EDIT;
                                 /* fall through */                          break;
 #ifdef notdef                  case 'f':
                         case '2':                          opt = D_REVERSE;
 #endif                          break;
                                 opt = D_IFDEF;                  case 'h':
                                 ifdef2 = argp;                          hflag++;
                                 *--argp = 0;                          break;
                                 continue;                  case 'i':
                         case 'e':                          iflag++;
                                 opt = D_EDIT;                          break;
                                 continue;                  case 'l':
                         case 'f':                          lflag++;
                                 opt = D_REVERSE;                          break;
                                 continue;                  case 'n':
                         case 'n':                          opt = D_NREVERSE;
                                 opt = D_NREVERSE;                          break;
                                 continue;                  case 'r':
                         case 'b':                          opt = D_REVERSE;
                                 bflag = 1;                          break;
                                 continue;                  case 'S':
                         case 'w':                          start = optarg;
                                 wflag = 1;                          break;
                                 continue;                  case 's':
                         case 'i':                          sflag++;
                                 iflag = 1;                          break;
                                 continue;                  case 't':
                         case 't':                          tflag++;
                                 tflag = 1;                          break;
                                 continue;                  case 'w':
                         case 'c':                          wflag++;
                                 opt = D_CONTEXT;                          break;
                                 if (isdigit(*argp)) {                  default:
                                         context = atoi(argp);                          usage();
                                         while (isdigit(*argp))                          break;
                                                 argp++;                  }
                                         if (*argp) {  
                                                 fprintf(stderr,  
                                                     "diff: -c: bad count\n");  
                                                 done(0);  
                                         }  
                                         argp = "";  
                                 } else  
                                         context = 3;  
                                 continue;  
                         case 'h':  
                                 hflag++;  
                                 continue;  
                         case 'S':  
                                 if (*argp == 0) {  
                                         fprintf(stderr, "diff: use -Sstart\n");  
                                         done(0);  
                                 }  
                                 start = argp;  
                                 *--argp = 0;    /* don't pass it on */  
                                 continue;  
                         case 'r':  
                                 rflag++;  
                                 continue;  
                         case 's':  
                                 sflag++;  
                                 continue;  
                         case 'l':  
                                 lflag++;  
                                 continue;  
                         default:  
                                 fprintf(stderr, "diff: -%s: unknown option\n",  
                                     --argp);  
                                 done(0);  
                         }  
         }          }
         if (argc != 2) {          argc -= optind;
                 fprintf(stderr, "diff: two filename arguments required\n");          argv += optind;
                 done(0);  
         }          if (argc != 2)
                   errx(1, "two filename arguments required");
         file1 = argv[0];          file1 = argv[0];
         file2 = argv[1];          file2 = argv[1];
         if (hflag && opt) {          if (hflag && opt)
                 fprintf(stderr,                  errx(1, "-h doesn't support -D, -c, -C, -e, -f, -I or -n");
                     "diff: -h doesn't support -e, -f, -n, -c, or -I\n");  
                 done(0);  
         }  
         if (!strcmp(file1, "-"))          if (!strcmp(file1, "-"))
                 stb1.st_mode = S_IFREG;                  stb1.st_mode = S_IFREG;
         else if (stat(file1, &stb1) < 0) {          else if (stat(file1, &stb1) < 0)
                 fprintf(stderr, "diff: ");                  err(1, "%s", file1);
                 perror(file1);  
                 done(0);  
         }  
         if (!strcmp(file2, "-"))          if (!strcmp(file2, "-"))
                 stb2.st_mode = S_IFREG;                  stb2.st_mode = S_IFREG;
         else if (stat(file2, &stb2) < 0) {          else if (stat(file2, &stb2) < 0)
                 fprintf(stderr, "diff: ");                  err(1, "%s", file2);
                 perror(file2);  
                 done(0);  
         }  
         if ((stb1.st_mode & S_IFMT) == S_IFDIR &&          if ((stb1.st_mode & S_IFMT) == S_IFDIR &&
             (stb2.st_mode & S_IFMT) == S_IFDIR) {              (stb2.st_mode & S_IFMT) == S_IFDIR) {
                 diffdir(argv);                  diffdir(argv);
         } else          } else
                 diffreg();                  diffreg();
         done(0);          done(0);
         /* notreached */  
         return (0);  
 }  }
   
 int  int
Line 207 
Line 164 
         return (a > b ? a : b);          return (a > b ? a : b);
 }  }
   
 void  __dead void
 done(int sig)  done(int sig)
 {  {
         if (tempfile)          if (tempfile)
Line 240 
Line 197 
 static void  static void
 noroom(void)  noroom(void)
 {  {
         fprintf(stderr, "diff: files too big, try -h\n");          warn("files too big, try -h");
         done(0);          done(0);
   }
   
   __dead void
   usage(void)
   {
           (void)fprintf(stderr, "usage: diff [-c | -C lines | -e | -f | -h | -n ] [-biwt] file1 file2\n"
               "usage: diff [-Dstring] [-biw] file1 file2\n"
               "usage: diff [-l] [-r] [-s] [-c | -C lines | -e | -f | -h | -n ] [-biwt]\n            [-Sname] dir1 dir2\n");
   
           exit(1);
 }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6