2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Function to write defines/modulename.h. Part of genmodule.
9 static void writedefineregister(FILE *, struct functionhead
*, struct config
*);
10 static void writedefinevararg(FILE *, struct functionhead
*, struct config
*);
11 static void writedefinestack(FILE *, struct functionhead
*, struct config
*);
12 static void writealiases(FILE *, struct functionhead
*, struct config
*);
14 void writeincdefines(struct config
*cfg
)
18 struct functionhead
*funclistit
;
20 snprintf(line
, 255, "%s/defines/%s.h", cfg
->gendir
, cfg
->modulename
);
21 out
= fopen(line
, "w");
30 "#ifndef DEFINES_%s_PROTOS_H\n"
31 "#define DEFINES_%s_PROTOS_H\n"
36 " Desc: Defines for %s\n"
39 "#include <aros/libcall.h>\n"
40 "#include <exec/types.h>\n"
41 "#include <aros/preprocessor/variadic/cast2iptr.hpp>\n"
43 cfg
->modulenameupper
, cfg
->modulenameupper
, getBanner(cfg
), cfg
->modulename
45 if (cfg
->command
!=DUMMY
)
47 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
49 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
))
51 if (funclistit
->libcall
!= STACK
)
53 writedefineregister(out
, funclistit
, cfg
);
54 if (!funclistit
->novararg
)
55 writedefinevararg(out
, funclistit
, cfg
);
57 else /* libcall == STACK */
59 writedefinestack(out
, funclistit
, cfg
);
62 writealiases(out
, funclistit
, cfg
);
68 "#endif /* DEFINES_%s_PROTOS_H*/\n",
76 writedefineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
78 struct functionarg
*arglistit
;
82 isvoid
= strcmp(funclistit
->type
, "void") == 0
83 || strcmp(funclistit
->type
, "VOID") == 0;
87 "#define __%s_WB(__%s",
88 funclistit
->name
, cfg
->libbase
90 for (arglistit
= funclistit
->arguments
, count
= 1;
92 arglistit
= arglistit
->next
, count
++
95 fprintf(out
, ", __arg%d", count
);
99 " AROS_LC%d%s(%s, %s, \\\n",
100 funclistit
->argcount
, (isvoid
) ? "NR" : "",
101 funclistit
->type
, funclistit
->name
104 for (arglistit
= funclistit
->arguments
, count
= 1;
106 arglistit
= arglistit
->next
, count
++
109 type
= getargtype(arglistit
);
110 assert(type
!= NULL
);
112 " AROS_LCA(%s,(__arg%d),%s), \\\n",
113 type
, count
, arglistit
->reg
118 " %s, (__%s), %u, %s)\n\n",
119 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
122 fprintf(out
, "#define %s(", funclistit
->name
);
123 for (arglistit
= funclistit
->arguments
, count
= 1;
125 arglistit
= arglistit
->next
, count
++
128 if (arglistit
!= funclistit
->arguments
)
130 fprintf(out
, "arg%d", count
);
132 fprintf(out
, ") \\\n __%s_WB(%s", funclistit
->name
, cfg
->libbase
);
133 for (arglistit
= funclistit
->arguments
, count
= 1;
135 arglistit
= arglistit
->next
, count
++
137 fprintf(out
, ", (arg%d)", count
);
142 writedefinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
144 struct functionarg
*arglistit
= funclistit
->arguments
;
145 char isvararg
= 0, *varargname
, *lastname
;
147 /* Go to last argument */
148 if (arglistit
== NULL
)
151 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
153 lastname
= getargname(arglistit
);
154 assert(lastname
!= NULL
);
156 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
159 varargname
= strdup(funclistit
->name
);
160 varargname
[strlen(funclistit
->name
)-1] = '\0';
162 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
165 /* TagList has to be changed in Tags at the end of the functionname */
166 varargname
= strdup(funclistit
->name
);
167 varargname
[strlen(funclistit
->name
)-4] = 's';
168 varargname
[strlen(funclistit
->name
)-3] = '\0';
170 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
171 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
175 varargname
= strdup(funclistit
->name
);
176 varargname
[strlen(funclistit
->name
)-4] = '\0';
182 if (strncmp(arglistit
->arg
, "struct", 6)==0)
184 p
= arglistit
->arg
+ 6;
185 while (isspace(*p
)) p
++;
186 if (strncmp(p
, "TagItem", 7) == 0)
189 while (isspace(*p
)) p
++;
194 varargname
= malloc(strlen(funclistit
->name
) + 5);
195 strcpy(varargname
, funclistit
->name
);
196 strcat(varargname
, "Tags");
207 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
209 cfg
->modulenameupper
, varargname
211 for (arglistit
= funclistit
->arguments
, count
= 1;
212 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
213 arglistit
= arglistit
->next
, count
++
216 fprintf(out
, "arg%d, ", count
);
221 " IPTR __args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }; \\\n"
225 for (arglistit
= funclistit
->arguments
, count
= 1;
227 arglistit
= arglistit
->next
, count
++
230 if (arglistit
!= funclistit
->arguments
)
233 if (arglistit
->next
== NULL
)
235 type
= getargtype(arglistit
);
236 assert(type
!= NULL
);
237 fprintf(out
, "(%s)__args", type
);
241 fprintf(out
, "(arg%d)", count
);
246 "#endif /* !NO_INLINE_STDARG */\n"
254 writedefinestack(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
256 struct functionarg
*arglistit
;
258 fprintf(out
, "#define %s ((%s (*)(", funclistit
->name
, funclistit
->type
);
259 for (arglistit
= funclistit
->arguments
;
261 arglistit
= arglistit
->next
264 fprintf(out
, "%s", arglistit
->arg
);
265 if (arglistit
->next
!= NULL
)
268 fprintf(out
, "))__AROS_GETVECADDR(%s,%d))\n", cfg
->libbase
, funclistit
->lvo
);
272 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
274 struct stringlist
*aliasesit
;
276 for (aliasesit
= funclistit
->aliases
;
278 aliasesit
= aliasesit
->next
281 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);