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

Defined functions

done defined in line 179; used 39 times
main defined in line 14; never used
max defined in line 172; used 2 times
min defined in line 165; used 2 times
noroom defined in line 208; used 2 times
ralloc defined in line 196; used 5 times
savestr defined in line 151; used 2 times
talloc defined in line 186; used 8 times

Defined variables

diff defined in line 10; used 3 times
diffh defined in line 11; used 2 times
pr defined in line 12; used 3 times
sccsid defined in line 2; never used
Last modified: 1991-11-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3443
Valid CSS Valid XHTML 1.0 Strict