home *** CD-ROM | disk | FTP | other *** search
- #ifndef LINT
- static char sccsid[]="@(#) addfname.c 1.5 87/05/03 16:00:28";
- #endif /* LINT */
-
- /*
- Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
- */
- #include "options.h"
-
- /* Adds a filename to global list. (This global list will eventually
- be searched by the inlist() function.) The second through fourth
- parameters suppplied are stored with the name of the file and
- returned by inlist. */
-
- #include <stdio.h>
- #include "various.h"
- #include "zoo.h"
- #include "zoofns.h"
- #include "zoomem.h" /* to get LIST_SIZE */
-
- static struct item *fentry[LIST_SIZE];
- static int lastname = 0; /* index of last name */
-
- struct item { /* global filename list entry */
- char *fname;
- long position;
- unsigned int date;
- unsigned int time;
- };
-
- void addfname(fname,position,date,time)
- char *fname;
- long position;
- unsigned int date, time;
- {
- if (lastname == 0)
- fentry[lastname] = (struct item *) emalloc (sizeof(struct item));
-
- /* keep a few empty spaces at end to avoid off by one errors */
- if (lastname >= LIST_SIZE - 3)
- memerr();
-
- fentry[lastname]->fname = strdup(fname);
- fentry[lastname]->position = position;
- fentry[lastname]->date = date;
- fentry[lastname]->time = time;
- lastname++;
- /* allocate memory for empty entry at end */
- fentry[lastname] = (struct item *) emalloc (sizeof(struct item));
- } /* addfname */
-
- /* inlist() */
- /* Examines global list built by addfname() to see if supplied filename
- is in the list.
-
- If found, returns the file's position within the archive as the function
- value and the date and time as parameters. If not found, returns -1.
-
- A simple sequential search is done.
-
- If justname is nonzero, then the search is for the filename only
- without the directory prefix; else it is for the full
- pathname.
- */
-
- long inlist (fname, date, time, justname)
- char *fname;
- unsigned int *date, *time;
- int justname;
- {
- register int i = 0;
- if (justname)
- fname = nameptr (fname); /* if directory wanted */
- fentry[lastname]->fname = fname; /* sentinel */
-
- #ifdef IGNORECASE
- #define COMPARE strcmpi
- #else
- #define COMPARE strcmp
- #endif
-
- while (COMPARE(fname,
- (justname ? nameptr (fentry[i]->fname) : fentry[i]->fname)) != 0) {
- i++;
- }
-
- if (i == lastname)
- return (-1L);
- else {
- *date = fentry[i]->date;
- *time = fentry[i]->time;
- return (fentry[i]->position);
- }
- } /* inlist() */
-
-