2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
8 /* D E F I N I T I O N M O D U L E S */
10 /* $Id: defmodule.c,v 1.41 1994/06/24 12:40:31 ceriel Exp $ */
44 while ((p = strrindex(fn,'/')) && *(p + 1) == '\0') {
45 /* remove trailing /'s */
51 fn = Salloc(fn, (unsigned) (p - &fn[0] + 1));
62 /* Try to find a file with basename "name" and extension ".def",
63 in the directories mentioned in "DEFPATH".
66 char *strncpy(), *strcat();
68 strncpy(buf, name, 10);
69 buf[10] = '\0'; /* maximum length */
71 DEFPATH[0] = WorkingDir;
72 if (! InsertFile(buf, DEFPATH, &(FileName))) {
73 error("could not find a DEFINITION MODULE for \"%s\"", name);
76 WorkingDir = getwdir(FileName);
78 DO_DEBUG(options['F'], debug("File %s : %ld characters", FileName, sys_filesize(FileName)));
83 GetDefinitionModule(id, incr)
86 /* Return a pointer to the "def" structure of the definition
87 module indicated by "id".
88 We may have to read the definition module itself.
89 Also increment level by "incr".
99 df = lookup(id, GlobalScope, D_IMPORTED, 0);
101 /* Read definition module. Make an exception for SYSTEM.
103 extern int ForeignFlag;
107 open_scope(CLOSEDSCOPE);
108 newsc = CurrentScope;
110 newsc->sc_defmodule = incr;
111 if (!strcmp(id->id_text, "SYSTEM")) {
113 df = lookup(id, GlobalScope, D_IMPORTED, 0);
116 if (!is_anon_idf(id) && GetFile(id->id_text)) {
120 df = lookup(id, GlobalScope, D_IMPORTED, 0);
122 (df && !(df->df_flags & D_FOREIGN))) {
123 /* The module is directly imported by
124 the currently defined module, and
125 is not foreign, so we have to
126 remember its name because we have
127 to call its initialization routine
129 static t_node *nd_end;
131 extern t_node *Modules;
134 n->nd_def = newsc->sc_definedby;
135 if (nd_end) nd_end->nd_NEXT = n;
142 df = lookup(id, GlobalScope, D_IMPORTED, 0);
143 newsc->sc_name = id->id_text;
146 close_scope(SC_CHKFORW);
148 df = MkDef(id, GlobalScope, D_ERROR);
150 newsc->sc_definedby = df;
153 else if (df->df_flags & D_BUSY) {
154 error("definition module \"%s\" depends on itself",
157 else if (df == Defined && level == 1) {
158 error("cannot import from current module \"%s\"", id->id_text);
159 df->df_kind = D_ERROR;