1: static  char sccsid[] = "@(#)diff.c 4.6 4/3/86";
   2: 
   3: #include "diff.h"
   4: /*
   5:  * diff - driver and subroutines
   6:  */
   7: 
   8: char    diff[] = DIFF;
   9: char    diffh[] = DIFFH;
  10: char    pr[] = PR;
  11: 
  12: main(argc, argv)
  13:     int argc;
  14:     char **argv;
  15: {
  16:     register char *argp;
  17: 
  18:     ifdef1 = "FILE1"; ifdef2 = "FILE2";
  19:     status = 2;
  20:     diffargv = argv;
  21:     argc--, argv++;
  22:     while (argc > 2 && argv[0][0] == '-') {
  23:         argp = &argv[0][1];
  24:         argv++, argc--;
  25:         while (*argp) switch(*argp++) {
  26: 
  27: #ifdef notdef
  28:         case 'I':
  29:             opt = D_IFDEF;
  30:             wantelses = 0;
  31:             continue;
  32:         case 'E':
  33:             opt = D_IFDEF;
  34:             wantelses = 1;
  35:             continue;
  36:         case '1':
  37:             opt = D_IFDEF;
  38:             ifdef1 = argp;
  39:             *--argp = 0;
  40:             continue;
  41: #endif
  42:         case 'D':
  43:             /* -Dfoo = -E -1 -2foo */
  44:             wantelses = 1;
  45:             ifdef1 = "";
  46:             /* fall through */
  47: #ifdef notdef
  48:         case '2':
  49: #endif
  50:             opt = D_IFDEF;
  51:             ifdef2 = argp;
  52:             *--argp = 0;
  53:             continue;
  54:         case 'e':
  55:             opt = D_EDIT;
  56:             continue;
  57:         case 'f':
  58:             opt = D_REVERSE;
  59:             continue;
  60:         case 'n':
  61:             opt = D_NREVERSE;
  62:             continue;
  63:         case 'b':
  64:             bflag = 1;
  65:             continue;
  66:         case 'w':
  67:             wflag = 1;
  68:             continue;
  69:         case 'i':
  70:             iflag = 1;
  71:             continue;
  72:         case 't':
  73:             tflag = 1;
  74:             continue;
  75:         case 'c':
  76:             opt = D_CONTEXT;
  77:             if (isdigit(*argp)) {
  78:                 context = atoi(argp);
  79:                 while (isdigit(*argp))
  80:                     argp++;
  81:                 if (*argp) {
  82:                     fprintf(stderr,
  83:                         "diff: -c: bad count\n");
  84:                     done();
  85:                 }
  86:                 argp = "";
  87:             } else
  88:                 context = 3;
  89:             continue;
  90:         case 'h':
  91:             hflag++;
  92:             continue;
  93:         case 'S':
  94:             if (*argp == 0) {
  95:                 fprintf(stderr, "diff: use -Sstart\n");
  96:                 done();
  97:             }
  98:             start = argp;
  99:             *--argp = 0;        /* don't pass it on */
 100:             continue;
 101:         case 'r':
 102:             rflag++;
 103:             continue;
 104:         case 's':
 105:             sflag++;
 106:             continue;
 107:         case 'l':
 108:             lflag++;
 109:             continue;
 110:         default:
 111:             fprintf(stderr, "diff: -%s: unknown option\n",
 112:                 --argp);
 113:             done();
 114:         }
 115:     }
 116:     if (argc != 2) {
 117:         fprintf(stderr, "diff: two filename arguments required\n");
 118:         done();
 119:     }
 120:     file1 = argv[0];
 121:     file2 = argv[1];
 122:     if (hflag && opt) {
 123:         fprintf(stderr,
 124:             "diff: -h doesn't support -e, -f, -n, -c, or -I\n");
 125:         done();
 126:     }
 127:     if (!strcmp(file1, "-"))
 128:         stb1.st_mode = S_IFREG;
 129:     else if (stat(file1, &stb1) < 0) {
 130:         fprintf(stderr, "diff: ");
 131:         perror(file1);
 132:         done();
 133:     }
 134:     if (!strcmp(file2, "-"))
 135:         stb2.st_mode = S_IFREG;
 136:     else if (stat(file2, &stb2) < 0) {
 137:         fprintf(stderr, "diff: ");
 138:         perror(file2);
 139:         done();
 140:     }
 141:     if ((stb1.st_mode & S_IFMT) == S_IFDIR &&
 142:         (stb2.st_mode & S_IFMT) == S_IFDIR) {
 143:         diffdir(argv);
 144:     } else
 145:         diffreg();
 146:     done();
 147: }
 148: 
 149: char *
 150: savestr(cp)
 151:     register char *cp;
 152: {
 153:     register char *dp = malloc(strlen(cp)+1);
 154: 
 155:     if (dp == 0) {
 156:         fprintf(stderr, "diff: ran out of memory\n");
 157:         done();
 158:     }
 159:     strcpy(dp, cp);
 160:     return (dp);
 161: }
 162: 
 163: min(a,b)
 164:     int a,b;
 165: {
 166: 
 167:     return (a < b ? a : b);
 168: }
 169: 
 170: max(a,b)
 171:     int a,b;
 172: {
 173: 
 174:     return (a > b ? a : b);
 175: }
 176: 
 177: done()
 178: {
 179:     if (tempfile)
 180:         unlink(tempfile);
 181:     exit(status);
 182: }
 183: 
 184: char *
 185: talloc(n)
 186: {
 187:     register char *p;
 188: 
 189:     if ((p = malloc((unsigned)n)) != NULL)
 190:         return(p);
 191:     noroom();
 192: }
 193: 
 194: char *
 195: ralloc(p,n)
 196: char *p;
 197: {
 198:     register char *q;
 199:     char *realloc();
 200: 
 201:     if ((q = realloc(p, (unsigned)n)) == NULL)
 202:         noroom();
 203:     return(q);
 204: }
 205: 
 206: noroom()
 207: {
 208:     fprintf(stderr, "diff: files too big, try -h\n");
 209:     done();
 210: }

Defined functions

done defined in line 177; used 39 times
main defined in line 12; never used
max defined in line 170; used 2 times
min defined in line 163; used 2 times
noroom defined in line 206; used 2 times
ralloc defined in line 194; used 5 times
savestr defined in line 149; used 2 times
talloc defined in line 184; used 8 times

Defined variables

diff defined in line 8; used 3 times
diffh defined in line 9; used 2 times
pr defined in line 10; used 3 times
sccsid defined in line 1; never used
Last modified: 1986-04-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1059
Valid CSS Valid XHTML 1.0 Strict