1: static char *sccsid = "@(#)cmp.c	4.2 (Berkeley) 4/29/83";
   2: #include <stdio.h>
   3: #include <ctype.h>
   4: 
   5: FILE    *file1,*file2;
   6: int eflg;
   7: int lflg    = 1;
   8: long    line    = 1;
   9: long    chr = 0;
  10: long    skip1;
  11: long    skip2;
  12: 
  13: long    otoi();
  14: 
  15: main(argc, argv)
  16: char **argv;
  17: {
  18:     register c1, c2;
  19:     char *arg;
  20: 
  21:     if(argc < 3)
  22:         goto narg;
  23:     arg = argv[1];
  24:     if(arg[0] == '-' && arg[1] == 's') {
  25:         lflg--;
  26:         argv++;
  27:         argc--;
  28:     }
  29:     arg = argv[1];
  30:     if(arg[0] == '-' && arg[1] == 'l') {
  31:         lflg++;
  32:         argv++;
  33:         argc--;
  34:     }
  35:     if(argc < 3)
  36:         goto narg;
  37:     arg = argv[1];
  38:     if( arg[0]=='-' && arg[1]==0 )
  39:         file1 = stdin;
  40:     else if((file1 = fopen(arg, "r")) == NULL)
  41:         goto barg;
  42:     arg = argv[2];
  43:     if((file2 = fopen(arg, "r")) == NULL)
  44:         goto barg;
  45:     if (argc>3)
  46:         skip1 = otoi(argv[3]);
  47:     if (argc>4)
  48:         skip2 = otoi(argv[4]);
  49:     while (skip1) {
  50:         if ((c1 = getc(file1)) == EOF) {
  51:             arg = argv[1];
  52:             goto earg;
  53:         }
  54:         skip1--;
  55:     }
  56:     while (skip2) {
  57:         if ((c2 = getc(file2)) == EOF) {
  58:             arg = argv[2];
  59:             goto earg;
  60:         }
  61:         skip2--;
  62:     }
  63: 
  64: loop:
  65:     chr++;
  66:     c1 = getc(file1);
  67:     c2 = getc(file2);
  68:     if(c1 == c2) {
  69:         if (c1 == '\n')
  70:             line++;
  71:         if(c1 == EOF) {
  72:             if(eflg)
  73:                 exit(1);
  74:             exit(0);
  75:         }
  76:         goto loop;
  77:     }
  78:     if(lflg == 0)
  79:         exit(1);
  80:     if(c1 == EOF) {
  81:         arg = argv[1];
  82:         goto earg;
  83:     }
  84:     if(c2 == EOF)
  85:         goto earg;
  86:     if(lflg == 1) {
  87:         printf("%s %s differ: char %ld, line %ld\n", argv[1], arg,
  88:             chr, line);
  89:         exit(1);
  90:     }
  91:     eflg = 1;
  92:     printf("%6ld %3o %3o\n", chr, c1, c2);
  93:     goto loop;
  94: 
  95: narg:
  96:     printf("cmp: arg count\n");
  97:     exit(2);
  98: 
  99: barg:
 100:     if (lflg)
 101:     perror(arg);
 102:     exit(2);
 103: 
 104: earg:
 105:     printf("cmp: EOF on %s\n", arg);
 106:     exit(1);
 107: }
 108: 
 109: long otoi(s)
 110: char *s;
 111: {
 112:     long v;
 113:     int base;
 114: 
 115:     v = 0;
 116:     base = 10;
 117:     if (*s == '0')
 118:         base = 8;
 119:     while(isdigit(*s))
 120:         v = v*base + *s++ - '0';
 121:     return(v);
 122: }

Defined functions

main defined in line 15; never used
otoi defined in line 109; used 3 times

Defined variables

chr defined in line 9; used 3 times
eflg defined in line 6; used 2 times
lflg defined in line 7; used 5 times
line defined in line 8; used 2 times
sccsid defined in line 1; never used
skip1 defined in line 10; used 3 times
skip2 defined in line 11; used 3 times
Last modified: 1983-07-02
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1118
Valid CSS Valid XHTML 1.0 Strict