fix a few more of the patches for gcc 4.8.3
[AROS.git] / tools / genmodule / muisupport.c
blob3528ecc46f702be90c8457763fbcf256c87e9e97
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Support functions for MUI classes. Part of genmodule.
6 */
7 #include "genmodule.h"
8 #include "boopsisupport.h"
10 void writemuiincludes(FILE *out)
12 fprintf
14 out,
15 "#include <proto/muimaster.h>\n"
16 "\n"
20 void writemccinit(struct config *cfg, FILE *out, int inclass, struct classinfo *cl)
22 struct functionhead *methlistit;
23 struct functionarg *arglistit;
24 unsigned int lvo;
26 fprintf
28 out,
29 "/* Initialisation routines of a MUI class */\n"
30 "/* =======================================*/\n"
31 "\n"
34 if (cl->classdatatype == NULL)
35 fprintf(out, "# define %s_DATA_SIZE (0)\n", cl->basename);
36 else
37 fprintf
39 out,
40 "# define %s_DATA_SIZE (sizeof(%s))\n",
41 cl->basename, cl->classdatatype
44 writeboopsidispatcher(cfg, out, cl);
46 fprintf
48 out,
49 "\n"
50 "\n"
51 "/*** Library startup and shutdown *******************************************/\n"
52 "static int MCC_%s_Startup(LIBBASETYPEPTR LIBBASE)\n"
53 "{\n",
54 cl->basename
57 /* When classid is specified MakeClass will be used to make the class
58 * otherwise MUI_CreateCustomClass. The former use is only needed for internal
59 * muimaster use. Other use is deprecated.
61 if (cl->classid == NULL)
63 char *base, disp[256];
65 /* Has the class a provided dispatcher function ? */
66 if (cl->dispatcher == NULL)
67 snprintf(disp, 256, "%s_Dispatcher", cl->basename);
68 else
69 strncpy(disp, cl->dispatcher, 256);
71 /* Is this class the main class then pass the libbase to MUI_CreateCustomClass
72 * otherwise pass NULL
74 if (!inclass)
75 base = "(struct Library *)LIBBASE";
76 else
77 base = "NULL";
79 if (cl->superclass != NULL)
80 fprintf
82 out,
83 " %s_CLASSPTR_FIELD(LIBBASE) = MUI_CreateCustomClass(%s, %s, NULL, %s_DATA_SIZE, %s);\n",
84 cl->basename, base, cl->superclass, cl->basename, disp
86 else if (cl->superclass_field != NULL)
87 fprintf
89 out,
90 " %s_CLASSPTR_FIELD(LIBBASE) = MUI_CreateCustomClass(%s, NULL, LIBBASE->%s, %s_DATA_SIZE, %s);\n",
91 cl->basename, base, cl->superclass_field, cl->basename, disp
93 else
95 fprintf(out, "Internal error: both superclass and superclass_field are NULL\n");
96 exit(20);
99 else
101 char disp[256];
103 /* Has the class a provided dispatcher function ? */
104 if (cl->dispatcher == NULL)
105 snprintf(disp, 256, "%s_Dispatcher", cl->basename);
106 else
107 strncpy(disp, cl->dispatcher, 256);
109 if (cl->superclass != NULL)
110 fprintf
112 out,
113 " Class *superclass = MUI_GetClass(%s),\n",
114 cl->superclass
116 else if (cl->superclass_field != NULL)
117 fprintf
119 out,
120 " Class *superclass = LIBBASE->%s,\n",
121 cl->superclass_field
123 else
125 fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n");
126 exit(20);
129 fprintf
131 out,
132 " *cl = NULL;\n"
133 "\n"
134 " if (superclass)\n"
135 " cl = MakeClass(%s, NULL, superclass, %s_DATA_SIZE, 0);\n"
136 " if (cl)\n"
137 " cl->cl_Dispatcher.h_Entry = %s;\n"
138 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n",
139 cl->classid, cl->basename,
140 disp,
141 cl->basename
145 fprintf
147 out,
148 " \n"
149 " return %s_CLASSPTR_FIELD(LIBBASE) != NULL;\n"
150 "}\n"
151 "\n"
152 "static void MCC_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
153 "{\n",
154 cl->basename,
155 cl->basename
157 if (cl->classid == NULL)
159 fprintf
161 out,
162 " MUI_DeleteCustomClass(%s_CLASSPTR_FIELD(LIBBASE));\n",
163 cl->basename
166 else
168 fprintf
170 out,
171 " Class *cl = %s_CLASSPTR_FIELD(LIBBASE);\n"
172 "\n"
173 " if (cl != NULL)\n"
174 " {\n"
175 " MUI_FreeClass(cl->cl_Super);\n"
176 " FreeClass(cl);\n"
177 " }\n",
178 cl->basename
181 fprintf
183 out,
184 // " return TRUE;\n"
185 "}\n"
186 "\n"
187 "ADD2INITCLASSES(MCC_%s_Startup, %d);\n"
188 "ADD2EXPUNGECLASSES(MCC_%s_Shutdown, %d);\n",
189 cl->basename, -cl->initpri,
190 cl->basename, -cl->initpri
194 void writemccquery(FILE *out, struct config *cfg)
196 fprintf
198 out,
199 "\n"
200 "/* MCC_Query function */\n"
201 "/* ================== */\n"
202 "\n"
203 "#include <libraries/mui.h>\n"
204 "#include <aros/libcall.h>\n"
205 "\n"
206 "#define MCC_CLASS 0\n"
207 "#define MCC_PREFS_CLASS 1\n"
208 "\n"
209 "AROS_LH1(IPTR, MCC_Query,\n"
210 " AROS_LHA(LONG, what, D0),\n"
211 " LIBBASETYPEPTR, LIBBASE, 5, %s\n"
212 ")\n"
213 "{\n"
214 " AROS_LIBFUNC_INIT\n"
215 "\n"
216 " switch( what )\n"
217 " {\n",
218 cfg->basename
221 switch(cfg->modtype)
223 case MCC:
224 case MUI:
225 fprintf(out, " case MCC_CLASS: return (IPTR)GM_CLASSPTR_FIELD(LIBBASE);\n");
226 break;
227 case MCP:
228 fprintf(out, " case MCC_PREFS_CLASS: return (IPTR)GM_CLASSPTR_FIELD(LIBBASE);\n");
229 break;
232 /* FIXME: handle MCC_PREFS_IMAGE somehow */
233 /* FIXME: handle "ONLY_GLOBAL" ?? */
235 fprintf
237 out,
238 " }\n"
239 "\n"
240 " return 0;\n"
241 "\n"
242 " AROS_LIBFUNC_EXIT\n"
243 "}\n"