1: # include   <stdio.h>
   2: # include   <ctype.h>
   3: 
   4: # define    reg register
   5: # define    bool    char
   6: 
   7: # define    TRUE    1
   8: # define    FALSE   0
   9: 
  10: static char *sccsid ="@(#)enteraddr.c	1.6 (Berkeley) 4/10/81";
  11: 
  12: struct fd {
  13:     char    *f_name;
  14:     char    *f_desc;
  15:     char    *f_value;
  16: };
  17: 
  18: typedef struct fd   FDES;
  19: 
  20: char    *Fmtfile,
  21:     *Addrfile,
  22:     Fmt[BUFSIZ],
  23:     *malloc();
  24: 
  25: FDES    Fmtab[BUFSIZ],
  26:     *name();
  27: 
  28: main(ac, av)
  29: int ac;
  30: char    **av;
  31: {
  32:     setbuf(stdout, 0);
  33:     if (ac != 3) {
  34:         printf("usage: %s fmt-file addr-file\n", av[0]);
  35:         exit(1);
  36:     }
  37:     Fmtfile = av[1];
  38:     Addrfile = av[2];
  39:     parseaddr();
  40:     doaddrs();
  41:     putchar('\n');
  42: }
  43: 
  44: /*
  45:  * parse the fmt file
  46:  */
  47: parseaddr()
  48: {
  49:     reg FILE    *inf;
  50:     reg char    *sp;
  51:     reg FDES    *fp;
  52:     reg char    c;
  53:     char        buf[80];
  54: 
  55:     if ((inf = fopen(Fmtfile, "r")) == NULL) {
  56:         perror(Fmtfile);
  57:         exit(1);
  58:     }
  59:     for (fp = Fmtab; fp < &Fmtab[BUFSIZ]; fp++)
  60:         fp->f_name = NULL;
  61: 
  62:     while ((c = getc(inf)) != EOF)
  63:         if (c == '<') {
  64:             register char   c;
  65: 
  66:             sp = buf;
  67:             while ((*sp = getc(inf)) != '>' && *sp != ':')
  68:                 sp++;
  69:             c = *sp;
  70:             *sp++ = '\0';
  71:             fp = name(buf);
  72:             fp->f_name = malloc(sp - buf);
  73:             strcpy(fp->f_name, buf);
  74:             if (c == ':') {
  75:                 for (sp = buf; (*sp = getc(inf)) != '>'; sp++)
  76:                     continue;
  77:                 *sp++ = 0;
  78:                 fp->f_desc = malloc(sp - buf);
  79:                 strcpy(fp->f_desc, buf);
  80:             }
  81:             else
  82:                 fp->f_desc = NULL;
  83:         }
  84:     fclose(inf);
  85: }
  86: 
  87: doaddrs()
  88: {
  89:     reg FILE    *outf;
  90:     reg char    *sp;
  91:     reg FDES    *fp;
  92:     reg int     len;
  93:     char        buf[BUFSIZ];
  94: 
  95:     if ((outf = fopen(Addrfile, "a")) == NULL) {
  96:         perror(Addrfile);
  97:         exit(1);
  98:     }
  99: 
 100:     for (fp = Fmtab; fp->f_name != NULL; fp++)
 101:         fp->f_value = NULL;
 102: 
 103:     for (;;) {
 104:         for (fp = Fmtab; fp->f_name != NULL; fp++) {
 105:             printf("%s", fp->f_name);
 106:             if (fp->f_value != NULL)
 107:                 printf(" (%s)", fp->f_value);
 108:             else if (fp->f_desc != NULL)
 109:                 printf(" (%s)", fp->f_desc);
 110:             printf(": ");
 111:             if (fgets(buf, BUFSIZ, stdin) == NULL)
 112:                 return;
 113:             buf[strlen(buf)-1] = '\0';
 114:             if (buf[0] == '\0')
 115:                 if (fp->f_value == NULL)
 116:                     if (fp->f_desc != NULL)
 117:                         strcpy(buf, fp->f_desc);
 118:                     else
 119:                         strcpy(buf, "");
 120:                 else
 121:                     continue;
 122:             else if (fp->f_value != NULL)
 123:                 cfree(fp->f_value);
 124:             fp->f_value = malloc(strlen(buf) + 1);
 125:             strcpy(fp->f_value, buf);
 126:         }
 127:         putchar('\n');
 128:         for (fp = Fmtab; fp->f_name != NULL; fp++)
 129:             printf("%s: %s\n", fp->f_name, fp->f_value);
 130:         printf("correct? ");
 131:         fgets(buf, BUFSIZ, stdin);
 132:         if (buf[0] == 'y') {
 133:             for (fp = Fmtab; fp->f_name != NULL; fp++) {
 134:                 fprintf(outf, "%s", fp->f_name);
 135:                 if (*fp->f_value != '\0')
 136:                     fprintf(outf, " %s", fp->f_value);
 137:                 putc('\n', outf);
 138:                 cfree(fp->f_value);
 139:                 fp->f_value = NULL;
 140:             }
 141:             fprintf(outf, "$\n");
 142:         }
 143:         putchar('\n');
 144:     }
 145: }
 146: 
 147: FDES *
 148: name(str)
 149: reg char    *str; {
 150: 
 151:     reg FDES    *fp;
 152: 
 153:     for (fp = Fmtab; fp->f_name != NULL; fp++)
 154:         if (strcmp(str, fp->f_name) == 0)
 155:             return fp;
 156:     return fp;
 157: }

Defined functions

doaddrs defined in line 87; used 1 times
  • in line 40
main defined in line 28; never used
name defined in line 147; used 2 times
parseaddr defined in line 47; used 1 times
  • in line 39

Defined variables

Addrfile defined in line 21; used 3 times
Fmt defined in line 22; never used
Fmtab defined in line 25; used 7 times
Fmtfile defined in line 20; used 3 times
sccsid defined in line 10; never used

Defined struct's

fd defined in line 12; used 2 times
  • in line 18(2)

Defined typedef's

FDES defined in line 18; used 5 times

Defined macros

FALSE defined in line 8; never used
TRUE defined in line 7; never used
bool defined in line 5; never used
reg defined in line 4; used 10 times
Last modified: 1982-06-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1239
Valid CSS Valid XHTML 1.0 Strict