|
|
1.1 ! root 1: /* ! 2: * various subroutines to deal with archive headers ! 3: */ ! 4: ! 5: #include <stdio.h> ! 6: #include <ctype.h> ! 7: #include "asd.h" ! 8: ! 9: /* ! 10: * convert p to a long value. maximum input length is len, ! 11: * input is to be interpreted in base b. No negative values. ! 12: */ ! 13: long ! 14: cvlong (p, len, base) ! 15: register char *p; ! 16: register int len, base; ! 17: { ! 18: register int i; ! 19: register long r; ! 20: ! 21: r = 0; ! 22: i = len; ! 23: ! 24: do { ! 25: register int c = *p++; ! 26: if (isdigit (c)) ! 27: r = r * base + c - '0'; ! 28: } while (--i > 0); ! 29: ! 30: return r; ! 31: } ! 32: ! 33: long ! 34: read_header (name, file) ! 35: register char *name; ! 36: FILE *file; ! 37: { ! 38: register int n; ! 39: register int i; ! 40: register char *p, *q; ! 41: ! 42: n = fread ((char *) &ar_hdr, sizeof (ar_hdr), 1, file); ! 43: if (n != 1) { ! 44: fprintf (stderr, "can't read %s\n", name); ! 45: exit (1); ! 46: } ! 47: ! 48: if (strncmp (ar_hdr.ar_fmag, ARFMAG, sizeof (ar_hdr.ar_fmag)) != 0) { ! 49: fprintf (stderr, "input phase error on %s\n", name); ! 50: exit (1); ! 51: } ! 52: ! 53: /* check the component name, allowing for trailing blanks */ ! 54: p = name; ! 55: q = ar_hdr.ar_name; ! 56: for (i = 0; i < sizeof (ar_hdr.ar_name); i++) { ! 57: if (*q++ != (*p? *p++: ' ')) { ! 58: fprintf (stderr, "expected %s, got %.*s\n", ! 59: name, sizeof (ar_hdr.ar_name), ar_hdr.ar_name); ! 60: } ! 61: } ! 62: ! 63: /* crack the archive header and put the information in "hdr" */ ! 64: hdr.size = cvlong (ar_hdr.ar_size, sizeof (ar_hdr.ar_size), 10); ! 65: hdr.mode = cvlong (ar_hdr.ar_mode, sizeof (ar_hdr.ar_mode), 8); ! 66: hdr.date = cvlong (ar_hdr.ar_date, sizeof (ar_hdr.ar_date), 10); ! 67: ! 68: return hdr.size; ! 69: } ! 70: ! 71: /* advance to the start of the next archive header */ ! 72: void ! 73: next_header(f) ! 74: register FILE *f; ! 75: { ! 76: if (hdr.size & 1) ! 77: getc(f); ! 78: } ! 79: ! 80: /* skip leading white space, return a field */ ! 81: char * ! 82: getfield (f) ! 83: register FILE *f; ! 84: { ! 85: register char c; ! 86: ! 87: /* skip leading white space */ ! 88: do c = getc (f); ! 89: while (isspace (c) && c != '\n'); ! 90: ! 91: /* if we hit a newline, something's wrong */ ! 92: if (c == '\n') { ! 93: fprintf (stderr, "unexpected newline\n"); ! 94: exit (1); ! 95: } ! 96: ! 97: /* return the nonblank, read a "pathname" and return it */ ! 98: ungetc (c, f); ! 99: return getpath (f); ! 100: } ! 101: ! 102: /* insist on an end of line right here */ ! 103: void ! 104: geteol (f) ! 105: register FILE *f; ! 106: { ! 107: register int c; ! 108: ! 109: c = getc (f); ! 110: if (c != '\n') { ! 111: fprintf (stderr, "expected newline, got %c\n", c); ! 112: exit (1); ! 113: } ! 114: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.