* Added support for multiple BOOPSI classes in one module. The class can be a general...
[AROS.git] / tools / genmodule / functionhead.c
blob6bc600056968ec5dadc146ac47ad15c34d05ca04
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
5 The code for storing information of functions present in the module
6 */
7 #include <string.h>
8 #include "functionhead.h"
10 struct functionhead *newfunctionhead(const char *name, enum libcall libcall)
12 struct functionhead *funchead = malloc(sizeof(struct functionhead));
14 if (funchead != NULL)
16 funchead->next = NULL;
17 funchead->name = strdup(name);
18 funchead->type = NULL;
19 funchead->libcall = libcall;
20 funchead->lvo = 0;
21 funchead->argcount = 0;
22 funchead->arguments = NULL;
23 funchead->aliases = NULL;
25 else
27 puts("Out of memory !");
28 exit(20);
31 return funchead;
34 struct functionarg *funcaddarg
36 struct functionhead *funchead,
37 const char *arg, const char *reg
40 struct functionarg **argptr = &funchead->arguments;
42 while ((*argptr) != NULL) argptr = &(*argptr)->next;
44 *argptr = malloc(sizeof(struct functionarg));
45 if (*argptr != NULL)
47 (*argptr)->next = NULL;
48 (*argptr)->arg = (arg == NULL) ? NULL : strdup(arg);
49 (*argptr)->reg = (reg == NULL) ? NULL : strdup(reg);
51 funchead->argcount++;
53 else
55 puts("Out of memory !");
56 exit(20);
59 return *argptr;
62 struct stringlist *funcaddalias(struct functionhead *funchead, const char *alias)
64 return slist_append(&funchead->aliases, alias);
67 char *getargtype(const struct functionarg *funcarg)
69 char *s, *begin, *end;
70 unsigned int brackets = 0, i;
72 begin = s = strdup(funcarg->arg);
74 /* Count the [] at the end of the argument */
75 end = begin+strlen(begin);
76 while (isspace(*(end-1))) end--;
77 while (*(end-1)==']')
79 brackets++;
80 end--;
81 while (isspace(*(end-1))) end--;
82 if (*(end-1)!='[')
84 free(s);
85 return NULL;
87 end--;
88 while (isspace(*(end-1))) end--;
91 /* Skip over the argument name */
92 while (!isspace(*(end-1)) && *(end-1)!='*') end--;
94 /* Add * for the brackets */
95 while (isspace(*(end-1))) end--;
96 for (i=0; i<brackets; i++)
98 *end='*';
99 end++;
101 *end='\0';
103 return s;
106 char *getargname(const struct functionarg *funcarg)
108 char *s, *begin, *end;
109 int len;
111 /* Count the [] at the end of the argument */
112 end = funcarg->arg+strlen(funcarg->arg);
113 while (isspace(*(end-1))) end--;
114 while (*(end-1)==']')
116 end--;
117 while (isspace(*(end-1))) end--;
118 if (*(end-1)!='[')
119 return NULL;
120 end--;
121 while (isspace(*(end-1))) end--;
124 /* Go to the beginning of the argument name */
125 begin = end;
126 while (!isspace(*(begin-1)) && *(begin-1)!='*') begin--;
128 /* Copy the name */
129 len = end - begin;
130 s = malloc(len+1);
131 strncpy(s, begin, len);
132 s[len] = '\0';
134 return s;