1: /* Input functions */
   2: 
   3: # include   "link.h"
   4: 
   5:     /* define maximum size of checksum contents */
   6: # define    MAXSIZE     40
   7: 
   8: static char *Fname = NULL;  /* name of current input file */
   9: static FILE *Fp = NULL; /* file pointer of current file */
  10: static char Buff[MAXSIZE];  /* buffer for current checksum module */
  11: static char *Next;      /* next byte to be popped from buffer */
  12: static int  Count;      /* number of bytes left */
  13: static int  Type;       /* type of checksum module */
  14: static char No_code = 0;    /* flag set if a code section was attempted to
  15: 				** be found but was not there */
  16: 
  17: 
  18: /***************************  ch_input  ************************************/
  19: 
  20: 
  21: ch_input(newfile, newmod)   /* change input checksum buffer contents */
  22: char    *newfile;
  23: int newmod;
  24: 
  25: {
  26:     FILE    *fopen();
  27: 
  28:     if (Fname == NULL || strcmp(Fname, newfile))    /* new file is
  29: 							** different */
  30:     {
  31:         Fname = newfile;
  32:         if (Fp != NULL)
  33:             fclose(Fp);
  34:         if ((Fp = fopen(Fname, "r")) == NULL)
  35:             inerror("not found");
  36:         Type = 0;
  37:     }
  38:     if (newmod != Type)         /* if not right module type already */
  39:         while (newmod != read_mod())    /* read until correct module type */
  40:         {
  41:             /* check for missing code section */
  42:             if ( newmod == CODE && Type == SYMBOLS)
  43:             {
  44:                 No_code = 1;
  45:                 break;
  46:             }
  47:             if (Type == 6)      /* check for EOF module */
  48:             {
  49:                 No_code = 1;
  50:                 break;
  51:             }
  52:                 /*
  53: 				inerror("EOF \(linker error\)");
  54: 				*/
  55:         }
  56: }
  57: 
  58: 
  59: /**************************  morebytes  ************************************/
  60: 
  61: 
  62: morebytes() /* returns 1 if there are unread bytes of the current */
  63:         /* checksum module type, returns 0 if not */
  64: {
  65:     register int    temptype;
  66: 
  67:     if (No_code)    /* if no code section, return 0 and reset */
  68:     {
  69:         No_code = 0;
  70:         return (0);
  71:     }
  72:     else if (Count > 0)
  73:         return (1);
  74:     else
  75:     {
  76:             /* read next module and check for same type */
  77:         temptype = Type;
  78:         if (temptype == read_mod())
  79:             return (1);
  80:         else
  81:             return (0);
  82:     }
  83: }
  84: 
  85: 
  86: /******************************  getbyte  ************************************/
  87: 
  88: 
  89: getbyte()   /* return next byte of current checksum module type */
  90: 
  91: {
  92:         /* check for empty buffer, if so check if next module is */
  93:         /* the same type */
  94:     if ((Count == 0) && !morebytes())
  95:     {
  96:         lerror("End of checksum module");
  97:         /* NOTREACHED */
  98:     }
  99:     else
 100:     {
 101:         Count--;
 102:         return (*Next++ & 0377);
 103:     }
 104: }
 105: 
 106: 
 107: /****************************  getword  ************************************/
 108: 
 109: 
 110: WORD getword()  /* return next word */
 111: {
 112:     register int    temp;
 113: 
 114:     temp = 0377 & getbyte();
 115:     return (0400 * getbyte() + temp);
 116: }
 117: 
 118: 
 119: /****************************  inerror  **********************************/
 120: 
 121: 
 122: inerror(mess)   /* print error message and filename then exit. */
 123:         /* called when a user error has occurred concerning the */
 124:         /* input file */
 125: char    *mess;
 126: {
 127:     fprintf(stderr, "%s: %s\n", Fname, mess);
 128:     bail_out();
 129: }
 130: 
 131: 
 132: /****************************************************************************/
 133: 
 134: 
 135: int sum;    /* sum of input bytes */
 136: 
 137: 
 138: /***************************  read_mod  **************************************/
 139: 
 140: 
 141: read_mod()  /* read a checksum module and return type */
 142: 
 143: {
 144:     register int    i;
 145:     sum = 0;
 146:     if (getb() != 1)
 147:     {
 148:         if (feof(Fp) && No_code)
 149:             return ( 6 );
 150:         else
 151:             inerror("Not in object file format");
 152:     }
 153:             /* clear zero byte */
 154:     getb();
 155:             /* Count = next word - 6 (# of bytes in header) */
 156:     Count = getb();
 157:     Count += 0400 * getb() - 6;
 158:     if (Count > MAXSIZE)
 159:         lerror("checksum size too large");
 160:     Type = getb();
 161:             /* clear zero byte */
 162:     getb();
 163:             /* read checksum contents into buffer */
 164:     for (i = 0; i < Count; i++)
 165:         Buff[i] = getb();
 166:             /* read checksum */
 167:     getb();
 168:     if (sum % 0400 != 0)
 169:         inerror("Checksum error, reassemble");
 170:             /* clear zero trailer byte if Count even */
 171:     if (Count % 2 == 0)
 172:         getb();
 173:             /* set pointer to next character to be read */
 174:     Next = Buff;
 175:     return (Type);
 176: }
 177: 
 178: 
 179: /*************************  getb  ***************************************/
 180: 
 181: 
 182: getb()      /* get a byte from input file, add to "sum" */
 183:         /* check for EOF, return the byte */
 184: {
 185:     register int    k;
 186: 
 187:     sum += (k = getc(Fp));
 188: 
 189:     if (k == EOF)
 190:         No_code = 1;
 191:     return (0377 & k);
 192: }

Defined functions

ch_input defined in line 21; used 6 times
getb defined in line 182; used 9 times
getbyte defined in line 89; used 38 times
getword defined in line 110; used 27 times
inerror defined in line 122; used 3 times
morebytes defined in line 62; used 7 times
read_mod defined in line 141; used 2 times

Defined variables

Buff defined in line 10; used 2 times
Count defined in line 12; used 8 times
Fname defined in line 8; used 5 times
Next defined in line 11; used 2 times
No_code defined in line 14; used 6 times
Type defined in line 13; used 7 times
sum defined in line 135; used 3 times

Defined macros

MAXSIZE defined in line 6; used 2 times
Last modified: 1982-12-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1455
Valid CSS Valid XHTML 1.0 Strict