missed commit
[AROS.git] / workbench / utilities / Installer / procedure.c
blobde0ed4e3346369f315d532eaf2a8f1e83fbf7d6f
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /* procedure.c -- Here are all functions related to user-defined procedures */
8 #include "Installer.h"
9 #include "execute.h"
10 #include "cleanup.h"
11 #include "procedure.h"
13 /* External variables */
14 extern struct CommandList internal_commands[];
17 int numusrprocs = 0, numactiveusrprocs = 0;
18 struct ProcedureList *usrprocs = NULL, **activeusrprocs = NULL;
22 * Activate previously parsed user function
24 void link_function(char *name, long int incarnation)
26 int i = 0, j = 0, inc = -1;
28 for ( ; i < numactiveusrprocs && strcmp(name, activeusrprocs[i]->procname) != 0 ; i++ );
30 while (j < numusrprocs && inc != incarnation)
32 if (strcmp(name, usrprocs[j].procname) == 0)
34 inc++;
36 j++;
38 j--;
40 if (i == numactiveusrprocs)
42 numactiveusrprocs++;
43 activeusrprocs = realloc(activeusrprocs, sizeof(struct ProcedureList *) * numactiveusrprocs);
44 if (activeusrprocs == NULL)
46 end_alloc();
49 activeusrprocs[i] = &((usrprocs[j]));
54 * Return user's function
56 struct ProcedureList *find_proc(char *name)
58 int i;
60 /* Check if procedure is in list */
61 for ( i = 0 ; i < numactiveusrprocs && strcmp(name, activeusrprocs[i]->procname) != 0 ; i++ );
62 if (i == numactiveusrprocs)
64 /* Not in list */
65 fprintf(stderr, "<%s> - Procedure not found!\n", name);
66 return NULL;
69 return activeusrprocs[i];
74 * Remember user functions at parse time
76 long int set_procedure(char **args, int num, ScriptArg *cmd)
78 int i;
79 char *name;
80 long int incarnation = 0;
82 name = args[0];
83 /* Check if name is in preset list */
84 for ( i = 0 ; i < _MAXCOMMAND && strcmp(name, internal_commands[i].cmdsymbol) != 0 ; i++ );
85 if (i < _MAXCOMMAND)
87 fprintf(stderr, "Procedure name <%s> already defined for internal function!\n", name);
88 cleanup();
89 exit(-1);
92 /* Check if name is in list */
93 for ( i = 0 ; i < numusrprocs ; i++)
95 if (strcmp(name, usrprocs[i].procname) == 0)
97 incarnation++;
101 /* Enlarge list for one additional element */
102 numusrprocs++;
103 usrprocs = realloc(usrprocs, sizeof(struct ProcedureList) * numusrprocs);
104 if (usrprocs == NULL)
106 end_alloc();
108 usrprocs[i].procbody = cmd;
109 usrprocs[i].procname = name;
110 usrprocs[i].arglist = &(args[1]);
111 usrprocs[i].argnum = num-1;
113 return incarnation;
118 * Free the memory of the user function list
120 void free_proclist()
122 int i;
124 for ( i = 0 ; i < numusrprocs ; i++)
126 free(usrprocs[i].procname);
128 free(usrprocs);