2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Support function for generating code for BOOPSI classes. Part of genmodule.
8 #include "functionhead.h"
10 /* gettype remove the variable name from a variable definition and leave return
11 * the type of the variable
12 * [] at the end will be added as * in the variable type
13 * e.g. char *var[] => type: char **, name: var
14 * This is a destructive function and will change to string pointed to by def
15 * to only contain the type afterwards.
16 * Function return 0 when it did not understand the input, 1 otherwise
18 static int gettype(char *def
);
20 void writeboopsidispatcher(FILE *out
, struct config
*cfg
, struct functions
*functions
)
22 struct functionhead
*methlistit
;
23 struct functionarg
*arglistit
;
26 if (!cfg
->customdispatcher
)
33 "/*** Dispatcher *************************************************************/\n"
34 "BOOPSI_DISPATCHER(IPTR, %s_Dispatcher, CLASS, self, message)\n"
36 " switch (message->MethodID)\n"
43 methlistit
= functions
->methlist
;
45 methlistit
= methlistit
->next
50 fprintf(out
, " case %s: ", methlistit
->name
);
51 if (strcmp(methlistit
->type
, "void") != 0)
52 fprintf(out
, "return (IPTR)");
53 fprintf(out
,"%s__%s(", cfg
->basename
, methlistit
->name
);
55 if (methlistit
->argcount
!= 3)
57 fprintf(stderr
, "Method \"%s\" has wrong number of arguments\n", methlistit
->name
);
61 arglistit
= methlistit
->arguments
;
62 fprintf(out
, "CLASS, ");
64 arglistit
= arglistit
->next
;
65 type
= strdup(arglistit
->type
);
69 "Argument \"%s\" not understood for function %s\n",
70 arglistit
->type
, methlistit
->name
74 fprintf(out
, "(%s)self, ", type
);
77 arglistit
= arglistit
->next
;
78 type
= strdup(arglistit
->type
);
82 "Argument \"%s\" not understood for function %s\n",
83 arglistit
->type
, methlistit
->name
87 fprintf(out
, "(%s) message);", type
);
90 if (strcmp(methlistit
->type
, "void") == 0)
91 fprintf(out
, " break;");
99 " default: return DoSuperMethodA(CLASS, self, message);\n"
102 " return (IPTR) NULL;\n"
104 "BOOPSI_DISPATCHER_END\n"
114 "/*** Custom dispatcher prototype ********************************************/\n"
115 "BOOPSI_DISPATCHER_PROTO(IPTR, %s_Dispatcher, CLASS, object, message);\n",
121 void writeclassinit(FILE *out
, struct config
*cfg
, struct functions
*functions
)
123 struct functionhead
*methlistit
;
124 struct functionarg
*arglistit
;
125 struct stringlist
*linelistit
;
131 "/* Initialisation routines for a BOOPSI class */\n"
132 "/* ===========================================*/\n"
134 "#include <intuition/classes.h>\n"
135 "#include <intuition/classusr.h>\n"
137 "#include <proto/exec.h>\n"
138 "#include <proto/utility.h>\n"
139 "#include <proto/dos.h>\n"
140 "#include <proto/graphics.h>\n"
141 "#include <proto/intuition.h>\n"
142 "#include <proto/muimaster.h>\n"
144 "#include <aros/symbolsets.h>\n"
149 for(linelistit
= cfg
->cdeflines
; linelistit
!= NULL
; linelistit
= linelistit
->next
)
151 fprintf(out
, "%s\n", linelistit
->s
);
157 "/*** Prototypes *************************************************************/\n"
162 methlistit
= functions
->methlist
;
164 methlistit
= methlistit
->next
169 fprintf(out
, "%s %s__%s(", methlistit
->type
, cfg
->basename
, methlistit
->name
);
173 arglistit
= methlistit
->arguments
;
175 arglistit
= arglistit
->next
183 fprintf(out
, "%s", arglistit
->type
);
186 fprintf(out
, ");\n");
189 writeboopsidispatcher(out
, cfg
, functions
);
191 if (cfg
->classdatatype
== NULL
)
192 fprintf(out
, "#define %s_DATA_SIZE (0)\n", cfg
->basename
);
195 "#define %s_DATA_SIZE (sizeof(%s))\n",
196 cfg
->basename
, cfg
->classdatatype
204 "/*** Library startup and shutdown *******************************************/\n"
205 "AROS_SET_LIBFUNC(BOOPSI_Startup, LIBBASETYPE, LIBBASE)\n"
207 " AROS_SET_LIBFUNC_INIT\n"
209 " struct IClass *cl = NULL;\n"
211 " cl = MakeClass(\"%s\", \"%s\", NULL, %s_DATA_SIZE, 0);\n"
214 " GM_CLASSPTR_FIELD(LIBBASE) = cl;\n"
215 " cl->cl_Dispatcher.h_Entry = (APTR)%s_Dispatcher;\n"
216 " cl->cl_Dispatcher.h_SubEntry = NULL;\n"
217 " cl->cl_UserData = (IPTR)LIBBASE\n;"
226 " AROS_SET_LIBFUNC_EXIT\n"
229 "AROS_SET_LIBFUNC(BOOPSI_Shutdown, LIBBASETYPE, LIBBASE)\n"
231 " AROS_SET_LIBFUNC_INIT\n"
233 " if (GM_CLASSPTR_FIELD(LIBBASE) != NULL)\n"
235 " RemoveClass(GM_CLASSPTR_FIELD(LIBBASE));\n"
236 " FreeClass(GM_CLASSPTR_FIELD(LIBBASE));\n"
237 " GM_CLASSPTR_FIELD(LIBBASE) = NULL;\n"
242 " AROS_SET_LIBFUNC_EXIT\n"
245 "ADD2INITLIB(BOOPSI_Startup, 1);\n"
246 "ADD2EXPUNGELIB(BOOPSI_Shutdown, 1);\n",
247 cfg
->classname
, cfg
->superclass
, cfg
->basename
, cfg
->basename
251 static int gettype(char *def
)
253 char *begin
= def
, *end
;
254 unsigned int brackets
= 0, i
;
256 /* Count the [] at the end of the argument */
257 end
= begin
+strlen(begin
);
258 while (isspace(*(end
-1))) end
--;
259 while (*(end
-1)==']')
263 while (isspace(*(end
-1))) end
--;
267 while (isspace(*(end
-1))) end
--;
270 /* Skip over the argument name */
271 while (!isspace(*(end
-1)) && *(end
-1)!='*') end
--;
273 /* Add * for the brackets */
274 while (isspace(*(end
-1))) end
--;
275 for (i
=0; i
<brackets
; i
++)