2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
6 /* procedure.c -- Here are all functions related to user-defined procedures */
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)
40 if (i
== numactiveusrprocs
)
43 activeusrprocs
= realloc(activeusrprocs
, sizeof(struct ProcedureList
*) * numactiveusrprocs
);
44 if (activeusrprocs
== NULL
)
49 activeusrprocs
[i
] = &((usrprocs
[j
]));
54 * Return user's function
56 struct ProcedureList
*find_proc(char *name
)
60 /* Check if procedure is in list */
61 for ( i
= 0 ; i
< numactiveusrprocs
&& strcmp(name
, activeusrprocs
[i
]->procname
) != 0 ; i
++ );
62 if (i
== numactiveusrprocs
)
65 fprintf(stderr
, "<%s> - Procedure not found!\n", name
);
69 return activeusrprocs
[i
];
74 * Remember user functions at parse time
76 long int set_procedure(char **args
, int num
, ScriptArg
*cmd
)
80 long int incarnation
= 0;
83 /* Check if name is in preset list */
84 for ( i
= 0 ; i
< _MAXCOMMAND
&& strcmp(name
, internal_commands
[i
].cmdsymbol
) != 0 ; i
++ );
87 fprintf(stderr
, "Procedure name <%s> already defined for internal function!\n", name
);
92 /* Check if name is in list */
93 for ( i
= 0 ; i
< numusrprocs
; i
++)
95 if (strcmp(name
, usrprocs
[i
].procname
) == 0)
101 /* Enlarge list for one additional element */
103 usrprocs
= realloc(usrprocs
, sizeof(struct ProcedureList
) * numusrprocs
);
104 if (usrprocs
== NULL
)
108 usrprocs
[i
].procbody
= cmd
;
109 usrprocs
[i
].procname
= name
;
110 usrprocs
[i
].arglist
= &(args
[1]);
111 usrprocs
[i
].argnum
= num
-1;
118 * Free the memory of the user function list
124 for ( i
= 0 ; i
< numusrprocs
; i
++)
126 free(usrprocs
[i
].procname
);