summaryrefslogtreecommitdiff
path: root/src/icont/lnklist.c
blob: f322355518ecb7ff5c823bfa60849a436729dbea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * lnklist.c -- functions for handling file linking.
 */

#include "../h/gsupport.h"
#include "tproto.h"
#include "lfile.h"

/*
 * Prototype.
 */
static	struct lfile *alclfile	(char *name);

struct lfile *lfiles;
struct invkl *invkls;

/*
 * addinvk adds an "invokable" name to the list.
 *  n==1 if name is an identifier; otherwise it is a string literal.
 */
void addinvk(name, n)
char *name;
int n;
   {
   struct invkl *p;

   if (n == 1) {			/* if identifier, must be "all" */
      if (strcmp(name, "all") != 0) {
         tfatal("invalid operand to invocable", name);
         return;
         }
      else
         name = "0";			/* "0" represents "all" */
      }
   else if (!isalpha(name[0]) && (name[0] != '_'))
      return;				/* if operator, ignore */

   p = alloc(sizeof(struct invkl));
   if (!p)
      tsyserr("not enough memory for invocable list");
   p->iv_name = salloc(name);
   p->iv_link = invkls;
   invkls = p;
   }

/*
 * alclfile allocates an lfile structure for the named file, fills
 *  in the name and returns a pointer to it.
 */
static struct lfile *alclfile(name)
char *name;
   {
   struct lfile *p;

   p = alloc(sizeof(struct lfile));
   if (!p)
      tsyserr("not enough memory for file list");
   p->lf_link = NULL;
   p->lf_name = salloc(name);
   return p;
   }

/*
 * addlfile creates an lfile structure for the named file and add it to the
 *  end of the list of files (lfiles) to generate link instructions for.
 */
void addlfile(name)
char *name;
   {
   struct lfile *nlf, *p;

   nlf = alclfile(name);
   if (lfiles == NULL) {
      lfiles = nlf;
      }
   else {
      p = lfiles;
      while (p->lf_link != NULL) {
         p = p->lf_link;
         }
      p->lf_link = nlf;
      }
   }