home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume24 / mkid2 / part01 / init.c < prev    next >
C/C++ Source or Header  |  1991-10-09  |  1KB  |  55 lines

  1. /* Copyright (c) 1986, Greg McGary */
  2. static char sccsid[] = "@(#)init.c    1.1 86/10/09";
  3.  
  4. #include    <id.h>
  5. #include    <string.h>
  6. #include    <stdio.h>
  7. #include    <extern.h>
  8.  
  9. /* initID opens idFile, reads the header into idhp (and verifies the magic
  10.  * number), then builds the idArgs list holding the names of all the
  11.  * files recorded in the database.
  12.  */
  13. FILE *
  14. initID(idFile, idhp, idArgs)
  15.     char        *idFile;
  16.     struct idhead    *idhp;
  17.     struct idarg    **idArgs;
  18. {
  19.     FILE        *idFILE;
  20.     register int    i;
  21.     register char    *strings;
  22.     register struct idarg    *idArg;
  23.  
  24.     if ((idFILE = fopen(idFile, "r")) == NULL)
  25.         return NULL;
  26.  
  27.     fseek(idFILE, 0L, 0);
  28.     fread(idhp, sizeof(struct idhead), 1, idFILE);
  29.     if (!strnequ(idhp->idh_magic, IDH_MAGIC, sizeof(idhp->idh_magic))) {
  30.         fprintf(stderr, "%s: Not an id file: `%s'\n", MyName, idFile);
  31.         exit(1);
  32.     }
  33.     if (idhp->idh_vers != IDH_VERS) {
  34.         fprintf(stderr, "%s: ID version mismatch (want: %d, got: %d)\n", MyName, IDH_VERS, idhp->idh_vers);
  35.         exit(1);
  36.     }
  37.  
  38.     fseek(idFILE, idhp->idh_argo, 0);
  39.     strings = malloc(i = idhp->idh_namo - idhp->idh_argo);
  40.     fread(strings, i, 1, idFILE);
  41.     idArg = *idArgs = (struct idarg *)calloc(idhp->idh_pthc, sizeof(struct idarg));
  42.     for (i = 0; i < idhp->idh_argc; i++) {
  43.         if (*strings == '+' || *strings == '-')
  44.             goto skip;
  45.         idArg->ida_flags = (*strings) ? 0 : IDA_BLANK;
  46.         idArg->ida_arg = strings;
  47.         idArg->ida_next = idArg + 1;
  48.         idArg++;
  49.     skip:
  50.         while (*strings++)
  51.             ;
  52.     }
  53.     return idFILE;
  54. }
  55.