From 51e2eda6b8dcd07703ce24aad38414eaf1238668 Mon Sep 17 00:00:00 2001 From: mazze Date: Tue, 31 Dec 2013 08:20:42 +0000 Subject: [PATCH] tabs -> spaces. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@48665 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- tools/genmodule/boopsisupport.c | 182 +- tools/genmodule/config.c | 4714 +++++++++++++++++----------------- tools/genmodule/config.h | 26 +- tools/genmodule/dtsupport.c | 2 +- tools/genmodule/fileread.c | 58 +- tools/genmodule/functionhead.c | 1014 ++++---- tools/genmodule/genmodule.c | 58 +- tools/genmodule/muisupport.c | 220 +- tools/genmodule/oopsupport.c | 138 +- tools/genmodule/stringlist.c | 40 +- tools/genmodule/writeautoinit.c | 4 +- tools/genmodule/writeend.c | 12 +- tools/genmodule/writefd.c | 8 +- tools/genmodule/writefunclist.c | 254 +- tools/genmodule/writegetlibbase.c | 4 +- tools/genmodule/writeincclib.c | 38 +- tools/genmodule/writeincdefines.c | 848 +++--- tools/genmodule/writeincinline.c | 484 ++-- tools/genmodule/writeincinterfaces.c | 6 +- tools/genmodule/writeinclibdefs.c | 134 +- tools/genmodule/writeincproto.c | 46 +- tools/genmodule/writemakefile.c | 40 +- tools/genmodule/writeskel.c | 100 +- tools/genmodule/writestart.c | 1414 +++++----- tools/genmodule/writestubs.c | 34 +- 25 files changed, 4939 insertions(+), 4939 deletions(-) rewrite tools/genmodule/config.c (61%) rewrite tools/genmodule/functionhead.c (62%) rewrite tools/genmodule/writefunclist.c (62%) rewrite tools/genmodule/writeincdefines.c (64%) diff --git a/tools/genmodule/boopsisupport.c b/tools/genmodule/boopsisupport.c index ef9b255005..cb73aee04e 100644 --- a/tools/genmodule/boopsisupport.c +++ b/tools/genmodule/boopsisupport.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2006, The AROS Development Team. All rights reserved. $Id$ - + Support function for generating code for BOOPSI classes. Part of genmodule. */ #include "config.h" @@ -33,15 +33,15 @@ void writeboopsidispatcher(struct config *cfg, FILE *out, struct classinfo *cl) if (cl->dispatcher == NULL) { - fprintf - ( - out, - "\n" + fprintf + ( + out, + "\n" "\n" "/*** Prototypes *************************************************************/\n" - ); + ); - writefuncdefs(out, NULL, cl->methlist); + writefuncdefs(out, NULL, cl->methlist); fprintf ( @@ -63,71 +63,71 @@ void writeboopsidispatcher(struct config *cfg, FILE *out, struct classinfo *cl) " switch (message->MethodID)\n" " {\n" ); - - for + + for ( - methlistit = cl->methlist; - methlistit != NULL; + methlistit = cl->methlist; + methlistit != NULL; methlistit = methlistit->next - ) + ) { - char *type; - + char *type; + fprintf(out, " "); - for - ( - aliasit = methlistit->aliases; - aliasit != NULL; - aliasit = aliasit->next - ) - { - fprintf(out, "case %s: ", aliasit->s); - } - if (strcmp(methlistit->type, "void") != 0) - fprintf(out, "return (IPTR)"); - fprintf(out,"%s(", methlistit->internalname); - + for + ( + aliasit = methlistit->aliases; + aliasit != NULL; + aliasit = aliasit->next + ) + { + fprintf(out, "case %s: ", aliasit->s); + } + if (strcmp(methlistit->type, "void") != 0) + fprintf(out, "return (IPTR)"); + fprintf(out,"%s(", methlistit->internalname); + if (methlistit->argcount != 3) { fprintf(stderr, "Method \"%s\" has wrong number of arguments\n", methlistit->name); exit(20); } - + arglistit = methlistit->arguments; fprintf(out, "CLASS, "); arglistit = arglistit->next; - type = getargtype(arglistit); - if (type == NULL) - { - fprintf(stderr, - "Argument \"%s\" not understood for function %s\n", - arglistit->arg, methlistit->name - ); - exit(20); - } + type = getargtype(arglistit); + if (type == NULL) + { + fprintf(stderr, + "Argument \"%s\" not understood for function %s\n", + arglistit->arg, methlistit->name + ); + exit(20); + } fprintf(out, "(%s)self, ", type); - free(type); - + free(type); + arglistit = arglistit->next; - type = getargtype(arglistit); - if (type == NULL) - { - fprintf(stderr, - "Argument \"%s\" not understood for function %s\n", - arglistit->arg, methlistit->name - ); - exit(20); - } - fprintf(out, "(%s) message);", type); - free(type); - - if (strcmp(methlistit->type, "void") == 0) - fprintf(out, " break;"); + type = getargtype(arglistit); + if (type == NULL) + { + fprintf(stderr, + "Argument \"%s\" not understood for function %s\n", + arglistit->arg, methlistit->name + ); + exit(20); + } + fprintf(out, "(%s) message);", type); + free(type); + + if (strcmp(methlistit->type, "void") == 0) + fprintf(out, " break;"); - fprintf(out, "\n"); + fprintf(out, "\n"); } - + fprintf ( out, @@ -158,7 +158,7 @@ void writeclassinit(struct config *cfg, FILE *out, struct classinfo *cl) struct functionhead *methlistit; struct functionarg *arglistit; unsigned int lvo; - + fprintf ( out, @@ -166,17 +166,17 @@ void writeclassinit(struct config *cfg, FILE *out, struct classinfo *cl) "/* ===========================================*/\n" "\n" ); - + writeboopsidispatcher(cfg, out, cl); if (cl->classdatatype == NULL) - fprintf(out, "#define %s_DATA_SIZE (0)\n", cl->basename); + fprintf(out, "#define %s_DATA_SIZE (0)\n", cl->basename); else - fprintf(out, - "#define %s_DATA_SIZE (sizeof(%s))\n", - cl->basename, cl->classdatatype - ); - + fprintf(out, + "#define %s_DATA_SIZE (sizeof(%s))\n", + cl->basename, cl->classdatatype + ); + fprintf ( out, @@ -190,19 +190,19 @@ void writeclassinit(struct config *cfg, FILE *out, struct classinfo *cl) cl->basename ); if (cl->superclass != NULL) - fprintf(out, - " cl = MakeClass(%s, %s, NULL, %s_DATA_SIZE, 0);\n", - cl->classid, cl->superclass, cl->basename - ); + fprintf(out, + " cl = MakeClass(%s, %s, NULL, %s_DATA_SIZE, 0);\n", + cl->classid, cl->superclass, cl->basename + ); else if (cl->superclass_field != NULL) - fprintf(out, - " cl = MakeClass(%s, NULL, LIBBASE->%s, %s_DATA_SIZE, 0);\n", - cl->classid, cl->superclass_field, cl->basename - ); + fprintf(out, + " cl = MakeClass(%s, NULL, LIBBASE->%s, %s_DATA_SIZE, 0);\n", + cl->classid, cl->superclass_field, cl->basename + ); else { - fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n"); - exit(20); + fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n"); + exit(20); } fprintf ( @@ -217,31 +217,31 @@ void writeclassinit(struct config *cfg, FILE *out, struct classinfo *cl) ); if (cl->dispatcher == NULL) - fprintf(out, - " cl->cl_Dispatcher.h_Entry = (APTR)%s_Dispatcher;\n", - cl->basename - ); + fprintf(out, + " cl->cl_Dispatcher.h_Entry = (APTR)%s_Dispatcher;\n", + cl->basename + ); else - fprintf(out, - " cl->cl_Dispatcher.h_Entry = (APTR)%s;\n", - cl->dispatcher - ); + fprintf(out, + " cl->cl_Dispatcher.h_Entry = (APTR)%s;\n", + cl->dispatcher + ); fprintf ( out, - " cl->cl_Dispatcher.h_SubEntry = NULL;\n" + " cl->cl_Dispatcher.h_SubEntry = NULL;\n" " cl->cl_UserData = (IPTR)LIBBASE\n;" ); - + if (!(cl->options & COPTION_PRIVATE)) - fprintf - ( - out, - "\n" - " AddClass(cl);\n" - ); - + fprintf + ( + out, + "\n" + " AddClass(cl);\n" + ); + fprintf ( out, @@ -261,7 +261,7 @@ void writeclassinit(struct config *cfg, FILE *out, struct classinfo *cl) cl->basename, cl->basename ); if (!(cl->options & COPTION_PRIVATE)) - fprintf(out, " RemoveClass(cl);\n"); + fprintf(out, " RemoveClass(cl);\n"); fprintf ( out, diff --git a/tools/genmodule/config.c b/tools/genmodule/config.c dissimilarity index 61% index add3624f13..f92789df47 100644 --- a/tools/genmodule/config.c +++ b/tools/genmodule/config.c @@ -1,2357 +1,2357 @@ -/* - Copyright © 1995-2013, The AROS Development Team. All rights reserved. - $Id$ - - Code to parse the command line options and the module config file for - the genmodule program -*/ - -#include -#include -#include -#define __USE_XOPEN -#include -#include -#include - -#include "functionhead.h" -#include "config.h" - -const static char bannertemplate[] = - "/*\n" - " *** Automatically generated from '%s'. Edits will be lost. ***\n" - " Copyright © 1995-%4u, The AROS Development Team. All rights reserved.\n" - "*/\n"; - -char* -getBanner(struct config* config) -{ - static unsigned currentyear = 0; - - int bannerlength = strlen(config->conffile) + strlen(bannertemplate); - // No additional bytes needed because - // + 1 (NUL) + 4 (4 digit year) - strlen("%s") - strlen("%4u) = 0 - - char * banner = malloc(bannerlength); - - if (currentyear == 0) - { - time_t rawtime; - time(&rawtime); - struct tm *utctm = gmtime(&rawtime); - currentyear = utctm->tm_year + 1900; - } - - snprintf (banner, bannerlength, bannertemplate, config->conffile, currentyear); - - return(banner); -} - -void -freeBanner(char *banner) -{ - free((void *)banner); -} - -const static char usage[] = - "\n" - "Usage: genmodule [-c conffile] [-s suffix] [-d gendir] [-v versionextra]\n" - " {writefiles|writemakefile|writeincludes|writelibdefs|writefunclist|writefd|writeskel} modname modtype\n" -; - -static void readconfig(struct config *); -static struct classinfo *newclass(struct config *); -static struct handlerinfo *newhandler(struct config *); -static struct interfaceinfo *newinterface(struct config *); - -/* the method prefices for the supported classes */ -static const char *muimprefix[] = -{ - "__OM_", - "__MUIM_", - NULL -}; -static const char *gadgetmprefix[] = -{ - "__OM_", - "__GM_", - "__AROSM_", - NULL -}; -static const char *dtmprefix[] = -{ - "__OM_", - "__GM_", - "__DTM_", - "__PDTM_", - NULL -}; - -/* Create a config struct. Initialize with the values from the programs command - * line arguments and the contents of the modules .conf file - */ -struct config *initconfig(int argc, char **argv) -{ - struct config *cfg; - char *s, **argvit = argv + 1; - int hassuffix = 0, c; - - cfg = malloc(sizeof(struct config)); - if (cfg == NULL) - { - fprintf(stderr, "Out of memory\n"); - exit(20); - } - - memset(cfg, 0, sizeof(struct config)); - - while ((c = getopt(argc, argv, ":c:s:d:v:")) != -1) - { - if (c == ':') - { - fprintf(stderr, "Option -%c needs an argument\n",optopt); - exit(20); - } - - switch (c) - { - case 'c': - cfg->conffile = optarg; - break; - - case 's': - cfg->suffix = optarg; - hassuffix = 1; - break; - - case 'd': - /* Remove / at end if present */ - if ((optarg)[strlen(*argvit)-1]=='/') (optarg)[strlen(optarg)-1]='\0'; - cfg->gendir = optarg; - break; - - case 'v': - cfg->versionextra = optarg; - break; - - default: - fprintf(stderr, "Internal error: Unhandled option\n"); - exit(20); - } - } - - if (optind + 3 != argc) - { - fprintf(stderr, "Wrong number of arguments.\n%s", usage); - exit(20); - } - - if (strcmp(argv[optind], "writefiles") == 0) - { - cfg->command = FILES; - } - else if (strcmp(argv[optind], "writemakefile") == 0) - { - cfg->command = MAKEFILE; - } - else if (strcmp(argv[optind], "writeincludes") == 0) - { - cfg->command = INCLUDES; - } - else if (strcmp(argv[optind], "writelibdefs") == 0) - { - cfg->command = LIBDEFS; - } - else if (strcmp(argv[optind], "writefunclist") == 0) - { - cfg->command = WRITEFUNCLIST; - } - else if (strcmp(argv[optind], "writefd") == 0) - { - cfg->command = WRITEFD; - } - else if (strcmp(argv[optind], "writeskel") == 0) - { - cfg->command = WRITESKEL; - } - else - { - fprintf(stderr, "Unrecognized argument \"%s\"\n%s", argv[optind], usage); - exit(20); - } - - cfg->modulename = argv[optind+1]; - cfg->modulenameupper = strdup(cfg->modulename); - for (s=cfg->modulenameupper; *s!='\0'; *s = toupper(*s), s++) { - if (!isalnum(*s)) *s = '_'; - } - - if (strcmp(argv[optind+2],"library")==0) - { - cfg->modtype = LIBRARY; - cfg->moddir = "Libs"; - } - else if (strcmp(argv[optind+2],"mcc")==0) - { - cfg->modtype = MCC; - cfg->moddir = "Classes/Zune"; - } - else if (strcmp(argv[optind+2],"mui")==0) - { - cfg->modtype = MUI; - cfg->moddir = "Classes/Zune"; - } - else if (strcmp(argv[optind+2],"mcp")==0) - { - cfg->modtype = MCP; - cfg->moddir = "Classes/Zune"; - } - else if (strcmp(argv[optind+2], "device")==0) - { - cfg->modtype = DEVICE; - cfg->moddir = "Devs"; - } - else if (strcmp(argv[optind+2], "resource")==0) - { - cfg->modtype = RESOURCE; - cfg->moddir = "Devs"; - } - else if (strcmp(argv[optind+2], "gadget")==0) - { - cfg->modtype = GADGET; - cfg->moddir = "Classes/Gadgets"; - } - else if (strcmp(argv[optind+2], "datatype")==0) - { - cfg->modtype = DATATYPE; - cfg->moddir = "Classes/DataTypes"; - } - else if (strcmp(argv[optind+2], "usbclass")==0) - { - cfg->modtype = USBCLASS; - cfg->moddir = "Classes/USB"; - if(!hassuffix) - { - cfg->suffix = "class"; - hassuffix = 1; - } - } - else if (strcmp(argv[optind+2], "hidd")==0) - { - cfg->modtype = HIDD; - cfg->moddir = "Devs/Drivers"; - } - else if (strcmp(argv[optind+2], "handler")==0) - { - cfg->modtype = HANDLER; - cfg->moddir = "$(AROS_DIR_FS)"; - } - else if (strcmp(argv[optind+2], "hook")==0) - { - cfg->modtype = HANDLER; - cfg->moddir = "Devs"; - } - else - { - fprintf(stderr, "Unknown modtype \"%s\" specified for second argument\n", argv[optind+2]); - exit(20); - } - cfg->modtypestr = argv[optind+2]; - - if (!hassuffix) - cfg->suffix = argv[optind+2]; - - /* Fill fields with default value if not specified on the command line */ - { - char tmpbuf[256]; - - if (cfg->conffile == NULL) - { - snprintf(tmpbuf, sizeof(tmpbuf), "%s.conf", cfg->modulename); - cfg->conffile = strdup(tmpbuf); - } - - if (cfg->gendir == NULL) - cfg->gendir = "."; - } - - readconfig(cfg); - - /* For a device add the functions given in beginiofunc and abortiofunc to the functionlist - * if they are provided - */ - if (cfg->beginiofunc != NULL) - { - struct functionhead *funchead; - - cfg->intcfg |= CFG_NOREADFUNCS; - - /* Add beginio_func to the list of functions */ - funchead = newfunctionhead(cfg->beginiofunc, REGISTERMACRO); - funchead->type = strdup("void"); - funchead->lvo = 5; - funcaddarg(funchead, "struct IORequest *ioreq", "A1"); - - funchead->next = cfg->funclist; - cfg->funclist = funchead; - - /* Add abortio_func to the list of functions */ - funchead = newfunctionhead(cfg->abortiofunc, REGISTERMACRO); - funchead->type = strdup("LONG"); - funchead->lvo = 6; - funcaddarg(funchead, "struct IORequest *ioreq", "A1"); - - funchead->next = cfg->funclist->next; - cfg->funclist->next = funchead; - } - else if (cfg->modtype == DEVICE && cfg->intcfg & CFG_NOREADFUNCS) - { - fprintf - ( - stderr, - "beginio_func and abortio_func missing for a device with a non empty function list\n" - ); - exit(20); - } - - /* See if we have any stackcall options */ - if (cfg->funclist) { - struct functionhead *funchead; - - for (funchead = cfg->funclist; funchead; funchead = funchead->next) { - if (funchead->libcall == STACK) { - cfg->options |= OPTION_STACKCALL; - break; - } - } - } - - /* Verify that a handler has a handler */ - if (cfg->modtype == HANDLER) { - if (cfg->handlerfunc == NULL) { - fprintf(stderr, "handler modules require a 'handler_func' ##config option\n"); - exit(20); - } - cfg->options |= OPTION_NOAUTOLIB | OPTION_NOEXPUNGE | OPTION_NOOPENCLOSE; - } - - return cfg; -} - -/* Functions to read configuration from the configuration file */ - -#include "fileread.h" - -static char *readsections(struct config *, struct classinfo *cl, struct interfaceinfo *in, int inclass); -static void readsectionconfig(struct config *, struct classinfo *cl, struct interfaceinfo *in, int inclass); -static void readsectioncdef(struct config *); -static void readsectioncdefprivate(struct config *); -static void readsectionstartup(struct config *); -static void readsectionfunctionlist(const char *type, struct functionhead **funclistptr, unsigned int firstlvo, int isattribute, enum libcall def_libcall); -static void readsectionclass_methodlist(struct classinfo *); -static void readsectionclass(struct config *); -static void readsectionhandler(struct config *); -static void readsectioninterface(struct config *); - -static void readconfig(struct config *cfg) -{ - struct classinfo *mainclass = NULL; - - /* Create a classinfo structure if this module is a class */ - switch (cfg->modtype) - { - case LIBRARY: - case DEVICE: - case RESOURCE: - case USBCLASS: - case HANDLER: - break; - - case MCC: - case MUI: - case MCP: - case GADGET: - case DATATYPE: - case HIDD: - mainclass = newclass(cfg); - mainclass->classtype = cfg->modtype; - break; - - default: - fprintf(stderr, "Internal error: unsupported modtype for classinfo creation\n"); - exit(20); - } - - switch (cfg->modtype) - { - case LIBRARY: - case USBCLASS: - cfg->firstlvo = 5; - break; - case DEVICE: - cfg->firstlvo = 7; - break; - case MCC: - case MUI: - case MCP: - cfg->firstlvo = 6; - mainclass->boopsimprefix = muimprefix; - break; - case HANDLER: - case RESOURCE: - cfg->firstlvo = 1; - break; - case GADGET: - cfg->firstlvo = 5; - mainclass->boopsimprefix = gadgetmprefix; - break; - case DATATYPE: - cfg->firstlvo = 6; - mainclass->boopsimprefix = dtmprefix; - break; - case HIDD: - cfg->firstlvo = 5; - /* FIXME: need boopsimprefix ? */ - break; - default: - fprintf(stderr, "Internal error: unsupported modtype for firstlvo\n"); - exit(20); - } - - if (!fileopen(cfg->conffile)) - { - fprintf(stderr, "In readconfig: Could not open %s\n", cfg->conffile); - exit(20); - } - - /* Read all sections and see that we are at the end of the file */ - if (readsections(cfg, mainclass, NULL, 0) != NULL) - exitfileerror(20, "Syntax error"); - - fileclose(); -} - -/* readsections will scan through all the sections in the config file. - * arguments: - * struct config *cfg: The module config data which may be updated by - * the information in the sections - * struct classinfo *cl: The classdata to be filled with data from the sections. - * This may be NULL if this is the main part of the configuration file and the - * type of the module is not a class - * int inclass: Boolean to indicate if we are in a class part. If not we are in the main - * part of the config file. - */ -static char *readsections(struct config *cfg, struct classinfo *cl, struct interfaceinfo *in, int inclass) -{ - char *line, *s, *s2; - int hasconfig = 0; - - while ((line=readline())!=NULL) - { - if (strncmp(line, "##", 2)==0) - { - static char *parts[] = - { - "config", "cdefprivate", "cdef", "startup", "functionlist", "methodlist", "class", "handler", "interface", "attributelist", "cfunctionlist" - }; - const unsigned int nums = sizeof(parts)/sizeof(char *); - unsigned int partnum; - int i, atend = 0; - - s = line+2; - while (isspace(*s)) s++; - - if (strncmp(s, "begin", 5)!=0) - return line; - - s += 5; - if (!isspace(*s)) - exitfileerror(20, "space after begin expected\n"); - while (isspace(*s)) s++; - - for (i = 0, partnum = 0; partnum==0 && ibasename==NULL) - exitfileerror(20, "section functionlist has to come after section config\n"); - - readsectionfunctionlist("functionlist", &cfg->funclist, cfg->firstlvo, 0, REGISTERMACRO); - cfg->intcfg |= CFG_NOREADFUNCS; - break; - - case 6: /* methodlist */ - if (cl == NULL && in == NULL) - exitfileerror(20, "methodlist section when not in a class or interface\n"); - if (cl) - readsectionclass_methodlist(cl); - else - readsectionfunctionlist("methodlist", &in->methodlist, 0, 0, REGISTERMACRO); - cfg->intcfg |= CFG_NOREADFUNCS; - break; - - case 7: /* class */ - if (inclass) - exitfileerror(20, "class section may not be in nested\n"); - readsectionclass(cfg); - break; - case 8: /* handler */ - readsectionhandler(cfg); - break; - case 9: /* interface */ - if (inclass) - exitfileerror(20, "interface section may not be nested\n"); - readsectioninterface(cfg); - break; - case 10: /* attributelist */ - if (!in) - exitfileerror(20, "attributelist only valid in interface sections\n"); - readsectionfunctionlist("attributelist", &in->attributelist, 0, 1, INVALID); - break; - case 11: /* cfunctionlist */ - if (inclass) - exitfileerror(20, "cfunctionlist section not allow in class section\n"); - if (cfg->basename==NULL) - exitfileerror(20, "section cfunctionlist has to come after section config\n"); - - readsectionfunctionlist("cfunctionlist", &cfg->funclist, cfg->firstlvo, 0, REGISTER); - cfg->intcfg |= CFG_NOREADFUNCS; - break; - } - } - else if (strlen(line)!=0) - filewarning("warning line outside section ignored\n"); - } - - if(!inclass) - { - if (!hasconfig) - exitfileerror(20, "No config section in conffile\n"); - - /* If no indication was given for generating includes or not - decide on module type and if there are functions - */ - if(!((cfg->options & OPTION_INCLUDES) || (cfg->options & OPTION_NOINCLUDES))) - { - switch (cfg->modtype) - { - case LIBRARY: - case RESOURCE: - cfg->options |= OPTION_INCLUDES; - break; - - case HANDLER: - case MCC: - case MUI: - case MCP: - case USBCLASS: - cfg->options |= OPTION_NOINCLUDES; - break; - - case DEVICE: - cfg->options |= ( - (cfg->funclist != NULL) - || (cfg->cdeflines != NULL) - || strcmp(cfg->libbasetypeptrextern, "struct Device *") != 0 - ) ? OPTION_INCLUDES : OPTION_NOINCLUDES; - break; - - case GADGET: - case DATATYPE: - case HIDD: - cfg->options |= ( - (cfg->funclist != NULL) - ) ? OPTION_INCLUDES : OPTION_NOINCLUDES; - break; - - default: - fprintf(stderr, "Internal error writemakefile: unhandled modtype for includes\n"); - exit(20); - break; - } - } - - /* If no indication was given for not generating stubs only generate them if - * the module has functions - */ - if(!((cfg->options & OPTION_STUBS) || (cfg->options & OPTION_NOSTUBS))) - { - switch (cfg->modtype) - { - case LIBRARY: - cfg->options |= (cfg->funclist != NULL) ? OPTION_STUBS : OPTION_NOSTUBS; - break; - - case USBCLASS: - case RESOURCE: - case GADGET: - case DEVICE: - case DATATYPE: - case MCC: - case MUI: - case MCP: - case HIDD: - case HANDLER: - cfg->options |= OPTION_NOSTUBS; - break; - - default: - fprintf(stderr, "Internal error writemakefile: unhandled modtype for stubs\n"); - exit(20); - break; - } - } - - /* If no indication was given for generating autoinit code or not - decide on module type - */ - if(!((cfg->options & OPTION_AUTOINIT) || (cfg->options & OPTION_NOAUTOINIT))) - { - switch (cfg->modtype) - { - case LIBRARY: - cfg->options |= OPTION_AUTOINIT; - break; - - case USBCLASS: - case RESOURCE: - case GADGET: - case DEVICE: - case DATATYPE: - case MCC: - case MUI: - case MCP: - case HIDD: - case HANDLER: - cfg->options |= OPTION_NOAUTOINIT; - break; - - default: - fprintf(stderr, "Internal error writemakefile: unhandled modtype for autoinit\n"); - exit(20); - break; - } - } - - if ((cfg->modtype == RESOURCE) || (cfg->modtype == HANDLER)) - /* Enforce noopenclose for resources and handlers */ - cfg->options |= OPTION_NOOPENCLOSE; - else if (!(cfg->options & OPTION_SELFINIT)) - /* Enforce using RTF_AUTOINIT for everything except resources */ - cfg->options |= OPTION_RESAUTOINIT; - } - - return NULL; -} - -static void readsectionconfig(struct config *cfg, struct classinfo *cl, struct interfaceinfo *in, int inclass) -{ - int atend = 0, i; - char *line, *s, *s2, *libbasetypeextern = NULL; - struct tm date; - - while (!atend) - { - line = readline(); - if (line==NULL) - exitfileerror(20, "unexpected end of file in section config\n"); - - if (strncmp(line, "##", 2)!=0) - { - const char *names[] = - { - "basename", "libbase", "libbasetype", "libbasetypeextern", - "version", "date", "copyright", "libcall", "forcebase", "superclass", - "superclass_field", "residentpri", "options", "sysbase_field", - "seglist_field", "rootbase_field", "classptr_field", "classptr_var", - "classid", "classdatatype", "beginio_func", "abortio_func", "dispatcher", - "initpri", "type", "addromtag", "oopbase_field", - "rellib", "interfaceid", "interfacename", - "methodstub", "methodbase", "attributebase", "handler_func" - }; - const unsigned int namenums = sizeof(names)/sizeof(char *); - unsigned int namenum; - - for (i = 0, namenum = 0; namenum==0 && ibasename = strdup(s); - if (cl != NULL) - cl->basename = strdup(s); - if (in != NULL) - exitfileerror(20, "basename not valid config option when in a interface section\n"); - break; - - case 2: /* libbase */ - if (inclass) - exitfileerror(20, "libbase not valid config option when in a class section\n"); - cfg->libbase = strdup(s); - break; - - case 3: /* libbasetype */ - if (inclass) - exitfileerror(20, "libbasetype not valid config option when in a class section\n"); - cfg->libbasetype = strdup(s); - break; - - case 4: /* libbasetypeextern */ - if (inclass) - exitfileerror(20, "libbasetype not valid config option when in a class section\n"); - libbasetypeextern = strdup(s); - break; - - case 5: /* version */ - if (inclass) - exitfileerror(20, "version not valid config option when in a class section\n"); - if (sscanf(s, "%u.%u", &cfg->majorversion, &cfg->minorversion)!=2) - exitfileerror(20, "wrong version string \"%s\"\n", s); - break; - - case 6: /* date */ - if (inclass) - exitfileerror(20, "date not valid config option when in a class section\n"); -#ifndef _WIN32 - if (strptime(s, "%e.%m.%Y", &date) == NULL) - { - exitfileerror(20, "date string has to have d.m.yyyy format\n"); - } -#endif - cfg->datestring = strdup(s); - break; - - case 7: /* copyright */ - if (inclass) - exitfileerror(20, "copyright not valid config option when in a class section\n"); - cfg->copyright = strdup(s); - break; - - case 8: /* libcall */ - fprintf(stderr, "libcall specification is deprecated and ignored\n"); - break; - - case 9: /* forcebase */ - if (inclass) - exitfileerror(20, "forcebase not valid config option when in a class section\n"); - slist_append(&cfg->forcelist, s); - break; - - case 10: /* superclass */ - if (cl == NULL) - exitfileerror(20, "superclass specified when not a BOOPSI class\n"); - cl->superclass = strdup(s); - break; - - case 11: /* superclass_field */ - if (cl == NULL) - exitfileerror(20, "superclass_field specified when not a BOOPSI class\n"); - cl->superclass_field = strdup(s); - break; - - case 12: /* residentpri */ - if (!inclass) - { - int count; - char dummy; - - count = sscanf(s, "%d%c", &cfg->residentpri, &dummy); - if (count != 1 || - cfg->residentpri < -128 || cfg->residentpri > 127 - ) - { - exitfileerror(20, "residentpri number format error\n"); - } - } - else - exitfileerror(20, "residentpri not valid config option when in a class section\n"); - break; - - case 13: /* options */ - if (!inclass) - { - static const char *optionnames[] = - { - "noautolib", "noexpunge", "noresident", "peropenerbase", - "pertaskbase", "includes", "noincludes", "nostubs", - "autoinit", "noautoinit", "resautoinit", "noopenclose", - "selfinit" - }; - const unsigned int optionnums = sizeof(optionnames)/sizeof(char *); - int optionnum; - - do - { - for (i = 0, optionnum = 0; optionnum==0 && ioptions |= OPTION_NOAUTOLIB; - break; - case 2: /* noexpunge */ - cfg->options |= OPTION_NOEXPUNGE; - break; - case 3: /* noresident */ - cfg->options |= OPTION_NORESIDENT; - cfg->firstlvo = 1; - break; - case 5: /* pertaskbase */ - cfg->options |= OPTION_PERTASKBASE; - /* Fall through */ - case 4: /* peropenerbase */ - if (cfg->options & OPTION_DUPBASE) - exitfileerror(20, "Only one option peropenerbase or pertaskbase allowed\n"); - cfg->options |= OPTION_DUPBASE; - break; - case 6: /* includes */ - if (cfg->options & OPTION_NOINCLUDES) - exitfileerror(20, "option includes and noincludes are incompatible\n"); - cfg->options |= OPTION_INCLUDES; - break; - case 7: /* noincludes */ - if (cfg->options & OPTION_INCLUDES) - exitfileerror(20, "option includes and noincludes are incompatible\n"); - cfg->options |= OPTION_NOINCLUDES; - break; - case 8: /* nostubs */ - cfg->options |= OPTION_NOSTUBS; - break; - case 9: /* autoinit */ - if (cfg->options & OPTION_NOAUTOINIT) - exitfileerror(20, "option autoinit and noautoinit are incompatible\n"); - cfg->options |= OPTION_AUTOINIT; - break; - case 10: /* noautoinit */ - if (cfg->options & OPTION_AUTOINIT) - exitfileerror(20, "option autoinit and noautoinit are incompatible\n"); - cfg->options |= OPTION_NOAUTOINIT; - break; - case 11: /* resautoinit */ - if (cfg->options & OPTION_SELFINIT) - exitfileerror(20, "option resautoinit and selfinit are incompatible\n"); - cfg->options |= OPTION_RESAUTOINIT; - break; - case 12: - cfg->options |= OPTION_NOOPENCLOSE; - break; - case 13: /* noresautoinit */ - if (cfg->options & OPTION_RESAUTOINIT) - exitfileerror(20, "option resautoinit and selfinit are incompatible\n"); - cfg->options |= OPTION_SELFINIT; - break; - } - while (isspace(*s)) s++; - } while(*s !='\0'); - } - else - { - static const char *optionnames[] = - { - "private" - }; - const unsigned int optionnums = sizeof(optionnames)/sizeof(char *); - int optionnum; - - do - { - for (i = 0, optionnum = 0; optionnum==0 && ioptions |= COPTION_PRIVATE; - break; - } - while (isspace(*s)) s++; - } while(*s !='\0'); - } - break; - - case 14: /* sysbase_field */ - if (inclass) - exitfileerror(20, "sysbase_field not valid config option when in a class section\n"); - cfg->sysbase_field = strdup(s); - break; - - case 15: /* seglist_field */ - if (inclass) - exitfileerror(20, "seglist_field not valid config option when in a class section\n"); - cfg->seglist_field = strdup(s); - break; - - case 16: /* rootbase_field */ - if (inclass) - exitfileerror(20, "rootbase_field not valid config option when in a class section\n"); - cfg->rootbase_field = strdup(s); - break; - - case 17: /* classptr_field */ - if (cl == NULL) - { - exitfileerror - ( - 20, - "classptr_field specified when not a BOOPSI class\n" - ); - } - cl->classptr_field = strdup(s); - break; - - case 18: /* classptr_var */ - if (cl == NULL) - { - exitfileerror - ( - 20, - "classptr_var specified when not a BOOPSI class\n" - ); - } - cl->classptr_var = strdup(s); - break; - - case 19: /* classid */ - if (cl == NULL) - exitfileerror(20, "classid specified when not a BOOPSI class\n"); - if (cl->classid != NULL) - exitfileerror(20, "classid specified twice\n"); - cl->classid = strdup(s); - if (strcmp(cl->classid, "NULL") == 0) - cl->options |= COPTION_PRIVATE; - break; - - case 20: /* classdatatype */ - if (cl == NULL) - exitfileerror(20, "classdatatype specified when not a BOOPSI class\n"); - cl->classdatatype = strdup(s); - break; - - case 21: /* beginio_func */ - if (inclass) - exitfileerror(20, "beginio_func not valid config option when in a class section\n"); - if (cfg->modtype != DEVICE) - exitfileerror(20, "beginio_func specified when not a device\n"); - cfg->beginiofunc = strdup(s); - break; - - case 22: /* abortio_func */ - if (inclass) - exitfileerror(20, "abortio_func not valid config option when in a class section\n"); - if (cfg->modtype != DEVICE) - exitfileerror(20, "abortio_func specified when not a device\n"); - cfg->abortiofunc = strdup(s); - break; - - case 23: /* dispatcher */ - if (cl == NULL) - exitfileerror(20, "dispatcher specified when not a BOOPSI class\n"); - cl->dispatcher = strdup(s); - /* function references are not needed when dispatcher is specified */ - cfg->intcfg |= CFG_NOREADFUNCS; - break; - - case 24: /* initpri */ - if (cl != NULL) - { - int count; - char dummy; - - count = sscanf(s, "%d%c", &cl->initpri, &dummy); - if (count != 1 || - cl->initpri < -128 || cl->initpri > 127 - ) - { - exitfileerror(20, "initpri number format error\n"); - } - } - else - exitfileerror(20, "initpri only valid config option for a BOOPSI class\n"); - break; - - case 25: /* type */ - if (!inclass) - exitfileerror(20, "type only valid config option in a class section\n"); - if (strcmp(s,"mcc")==0) - cl->classtype = MCC; - else if (strcmp(s,"mui")==0) - cl->classtype = MUI; - else if (strcmp(s,"mcp")==0) - cl->classtype = MCP; - else if (strcmp(s, "image")==0) - cl->classtype = IMAGE; - else if (strcmp(s, "gadget")==0) - cl->classtype = GADGET; - else if (strcmp(s, "datatype")==0) - cl->classtype = DATATYPE; - else if (strcmp(s, "usbclass")==0) - cl->classtype = USBCLASS; - else if (strcmp(s, "class")==0) - cl->classtype = CLASS; - else if (strcmp(s, "hidd")==0) - cl->classtype = HIDD; - else - { - fprintf(stderr, "Unknown type \"%s\" specified\n", s); - exit(20); - } - break; - - case 26: /* addromtag */ - cfg->addromtag = strdup(s); - break; - - case 27: /* oopbase_field */ - cfg->oopbase_field = strdup(s); - break; - case 28: /* rellib */ - slist_append(&cfg->rellibs, s); - break; - case 29: /* interfaceid */ - if (!in) - exitfileerror(20, "interfaceid only valid config option for an interface\n"); - in->interfaceid = strdup(s); - break; - case 30: /* interfacename */ - if (!in) - exitfileerror(20, "interfacename only valid config option for an interface\n"); - in->interfacename = strdup(s); - break; - case 31: /* methodstub */ - if (!in) - exitfileerror(20, "methodstub only valid config option for an interface\n"); - in->methodstub = strdup(s); - break; - case 32: /* methodbase */ - if (!in) - exitfileerror(20, "methodbase only valid config option for an interface\n"); - in->methodbase = strdup(s); - break; - case 33: /* attributebase */ - if (!in) - exitfileerror(20, "attributebase only valid config option for an interface\n"); - in->attributebase = strdup(s); - break; - case 34: /* handler_func */ - if (cfg->modtype != HANDLER) - exitfileerror(20, "handler specified when not a handler\n"); - cfg->handlerfunc = strdup(s); - break; - } - } - else /* Line starts with ## */ - { - s = line+2; - while (isspace(*s)) s++; - if (strncmp(s, "end", 3)!=0) - exitfileerror(20, "\"##end config\" expected\n"); - - s += 3; - if (!isspace(*s)) - exitfileerror(20, "\"##end config\" expected\n"); - - while (isspace(*s)) s++; - if (strncmp(s, "config", 6)!=0) - exitfileerror(20, "\"##end config\" expected\n"); - - s += 6; - while (isspace(*s)) s++; - if (*s!='\0') - exitfileerror(20, "\"##end config\" expected\n"); - - atend = 1; - } - } - - /* When not in a class section fill in default values for fields in cfg */ - if (!inclass) - { - if (cfg->basename==NULL) - { - cfg->basename = strdup(cfg->modulename); - *cfg->basename = toupper(*cfg->basename); - } - if (cfg->libbase==NULL) - { - unsigned int len = strlen(cfg->basename)+5; - cfg->libbase = malloc(len); - snprintf(cfg->libbase, len, "%sBase", cfg->basename); - } - if (cfg->libbasetype == NULL && libbasetypeextern != NULL) - cfg->libbasetype = strdup(libbasetypeextern); - if (cfg->sysbase_field != NULL && cfg->libbasetype == NULL) - exitfileerror(20, "sysbase_field specified when no libbasetype is given\n"); - if (cfg->seglist_field != NULL && cfg->libbasetype == NULL) - exitfileerror(20, "seglist_field specified when no libbasetype is given\n"); - if (cfg->oopbase_field != NULL && cfg->libbasetype == NULL) - exitfileerror(20, "oopbase_field specified when no libbasetype is given\n"); - /* rootbase_field only allowed when duplicating base */ - if (cfg->rootbase_field != NULL && !(cfg->options & OPTION_DUPBASE)) - exitfileerror(20, "rootbasefield only valid for option peropenerbase or pertaskbase\n"); - - /* Set default date to current date */ - if (cfg->datestring == NULL) - { - char tmpbuf[256]; - time_t now = time(NULL); - struct tm *ltime = localtime(&now); - - snprintf(tmpbuf, sizeof(tmpbuf), "%u.%u.%u", - ltime->tm_mday, 1 + ltime->tm_mon, 1900 + ltime->tm_year); - - cfg->datestring = strdup(tmpbuf); - } - - if (cfg->copyright == NULL) - cfg->copyright = ""; - - if ( (cfg->beginiofunc != NULL && cfg->abortiofunc == NULL) - || (cfg->beginiofunc == NULL && cfg->abortiofunc != NULL) - ) - exitfileerror(20, "please specify both beginio_func and abortio_func\n"); - - if (libbasetypeextern==NULL) - { - switch (cfg->modtype) - { - case DEVICE: - cfg->libbasetypeptrextern = "struct Device *"; - break; - case HANDLER: - case RESOURCE: - cfg->libbasetypeptrextern = "APTR "; - break; - case LIBRARY: - case MUI: - case MCP: - case MCC: - case GADGET: - case DATATYPE: - case USBCLASS: - case HIDD: - cfg->libbasetypeptrextern = "struct Library *"; - break; - default: - fprintf(stderr, "Internal error: Unsupported modtype for libbasetypeptrextern\n"); - exit(20); - } - } - else - { - cfg->libbasetypeptrextern = malloc(strlen(libbasetypeextern)+3); - strcpy(cfg->libbasetypeptrextern, libbasetypeextern); - strcat(cfg->libbasetypeptrextern, " *"); - free(libbasetypeextern); - } - } - - /* When class was given too fill in some defaults when not specified */ - if (cl != NULL) - { - if (cl->classtype == UNSPECIFIED) - cl->classtype = CLASS; - - if (cl->basename == NULL) - { - if (!inclass) - cl->basename = cfg->basename; - else - exitfileerror(20, "basename has to be specified in the config section inside of a class section\n"); - } - - /* MUI classes are always private */ - if (cl->classtype == MUI || cl->classtype == MCC || cl->classtype == MCP) - cl->options |= COPTION_PRIVATE; - - if (cl->classid == NULL - && (cl->classtype != MUI && cl->classtype != MCC && cl->classtype != MCP) - ) - { - if (cl->classtype == HIDD) - { - cl->options &= !COPTION_PRIVATE; - } - else if (cl->options & COPTION_PRIVATE) - { - cl->classid = "NULL"; - } - else - { - char s[256] = ""; - - if (cl->classtype == GADGET || cl->classtype == IMAGE || cl->classtype == CLASS || cl->classtype == USBCLASS) - { - sprintf(s, "\"%sclass\"", inclass ? cl->basename : cfg->modulename); - } - else if (cl->classtype == DATATYPE) - { - sprintf(s, "\"%s.datatype\"", inclass ? cl->basename : cfg->modulename); - } - cl->classid = strdup(s); - } - } - - /* Only specify superclass or superclass_field */ - if (cl->superclass != NULL && cl->superclass_field != NULL) - exitfileerror(20, "Only specify one of superclass or superclass_field in config section\n"); - - /* Give default value to superclass if it is not specified */ - if (cl->superclass == NULL && cl->superclass == NULL) - { - switch (cl->classtype) - { - case MUI: - case MCC: - cl->superclass = "MUIC_Area"; - break; - case MCP: - cl->superclass = "MUIC_Mccprefs"; - break; - case IMAGE: - cl->superclass = "IMAGECLASS"; - break; - case GADGET: - cl->superclass = "GADGETCLASS"; - break; - case DATATYPE: - cl->superclass = "DATATYPESCLASS"; - break; - case CLASS: - cl->superclass = "ROOTCLASS"; - break; - case HIDD: - cl->superclass = "CLID_Root"; - break; - default: - exitfileerror(20, "Internal error: unhandled classtype in readsectionconfig\n"); - break; - } - } - } -} - -static void readsectioncdef(struct config *cfg) -{ - int atend = 0; - char *line, *s; - - while (!atend) - { - line = readline(); - if (line==NULL) - exitfileerror(20, "unexptected end of file in section cdef\n"); - - if (strncmp(line, "##", 2)!=0) - { - slist_append(&cfg->cdeflines, line); - } - else - { - s = line+2; - while (isspace(*s)) s++; - if (strncmp(s, "end", 3)!=0) - exitfileerror(20, "\"##end cdef\" expected\n"); - - s += 3; - while (isspace(*s)) s++; - if (strncmp(s, "cdef", 4)!=0) - exitfileerror(20, "\"##end cdef\" expected\n"); - - s += 5; - while (isspace(*s)) s++; - if (*s!='\0') - exitfileerror(20, "unexpected character at position %d\n"); - - atend = 1; - } - } -} - -static void readsectioncdefprivate(struct config *cfg) -{ - int atend = 0; - char *line, *s; - - while (!atend) - { - line = readline(); - if (line==NULL) - exitfileerror(20, "unexptected end of file in section cdef\n"); - - if (strncmp(line, "##", 2)!=0) - { - slist_append(&cfg->cdefprivatelines, line); - } - else - { - s = line+2; - while (isspace(*s)) s++; - if (strncmp(s, "end", 3)!=0) - exitfileerror(20, "\"##end cdefprivate\" expected\n"); - - s += 3; - while (isspace(*s)) s++; - if (strncmp(s, "cdefprivate", 11)!=0) - exitfileerror(20, "\"##end cdefprivate\" expected\n"); - - s += 11; - while (isspace(*s)) s++; - if (*s!='\0') - exitfileerror(20, "unexpected character at position %d\n"); - - atend = 1; - } - } -} - -static void readsectionstartup(struct config *cfg) -{ - int atend = 0; - char *line, *s; - - while (!atend) - { - line = readline(); - if (line==NULL) - exitfileerror(20, "unexptected end of file in section startup\n"); - - if (strncmp(line, "##", 2)!=0) - { - slist_append(&cfg->startuplines, line); - } - else - { - s = line+2; - while (isspace(*s)) s++; - if (strncmp(s, "end", 3)!=0) - exitfileerror(20, "\"##end startup\" expected\n"); - - s += 3; - while (isspace(*s)) s++; - if (strncmp(s, "startup", 7)!=0) - exitfileerror(20, "\"##end startup\" expected\n"); - - s += 7; - while (isspace(*s)) s++; - if (*s!='\0') - exitfileerror(20, "unexpected character at position %d\n"); - - atend = 1; - } - } -} - -static void readsectionfunctionlist(const char *type, struct functionhead **funclistptr, unsigned int firstlvo, int isattribute, enum libcall def_libcall) -{ - int atend = 0, i; - char *line, *s, *s2; - unsigned int lvo = firstlvo; - int minversion = 0; - - while (!atend) - { - line = readline(); - if (line==NULL) - exitfileerror(20, "unexpected EOF in functionlist section\n"); - if (strlen(line)==0) - { - if (*funclistptr != NULL) - funclistptr = &((*funclistptr)->next); - lvo++; - } - else if (isspace(*line)) - { - s = line; - while (isspace(*s)) s++; - if (*s=='\0') - { - if (*funclistptr != NULL) - funclistptr = &((*funclistptr)->next); - lvo++; - } - else - exitfileerror(20, "no space allowed before functionname\n"); - } - else if (strncmp(line, "##", 2)==0) - { - s = line+2; - while (isspace(*s)) s++; - if (strncmp(s, "end", 3)!=0) - exitfileerror(20, "\"##end %s\" expected\n", type); - - s += 3; - while (isspace(*s)) s++; - if (strncmp(s, type, strlen(type))!=0) - exitfileerror(20, "\"##end %s\" expected\n", type); - - s += strlen(type); - while (isspace(*s)) s++; - if (*s!='\0') - exitfileerror(20, "unexpected character on position %d\n", s-line); - - atend = 1; - } - else if (*line=='.') - { - s = line+1; - if (strncmp(s, "skip", 4)==0) - { - int n; - - s += 4; - if (!isspace(*s)) - exitfileerror(20, "syntax is '.skip n'\n"); - - n=strtol(s, &s2, 10); - if (s2==NULL) - exitfileerror(20, "positive number expected\n"); - - while (isspace(*s2)) s2++; - if ((*s2 != '\0') && (*s2 != '#')) - exitfileerror(20, "syntax is '.skip n'\n"); - if (*funclistptr != NULL) - funclistptr = &((*funclistptr)->next); - lvo += n; - } - else if (strncmp(s, "alias", 5)==0) - { - s += 5; - - if (!isspace(*s)) - exitfileerror(20, "syntax is '.alias name'\n"); - - while (isspace(*s)) s++; - if (*s == '\0' || !(isalpha(*s) || *s == '_')) - exitfileerror(20, "syntax is '.alias name'\n"); - - s2 = s; - s++; - while (isalnum(*s) || *s == '_') s++; - - if (isspace(*s)) - { - *s = '\0'; - do { - s++; - } while (isspace(*s)); - } - - if (*s != '\0') - exitfileerror(20, "syntax is '.alias name'\n"); - - if (*funclistptr == NULL) - exitfileerror(20, ".alias has to come after a function declaration\n"); - - slist_append(&(*funclistptr)->aliases, s2); - } - else if (strncmp(s, "function", 8) == 0) - { - s += 8; - - if (!isspace(*s)) - exitfileerror(20, "Syntax error\n"); - - while (isspace(*s)) s++; - if (*s == '\0' || !(isalpha(*s) || *s == '_')) - exitfileerror(20, "syntax is '.function name'\n"); - - s2 = s; - s++; - while (isalnum(*s) || *s == '_') s++; - - if (isspace(*s)) - { - *s = '\0'; - do { - s++; - } while (isspace(*s)); - } - - if (*s != '\0') - exitfileerror(20, "syntax is '.function name'\n"); - - if (*funclistptr == NULL) - exitfileerror(20, ".function has to come after a function declaration\n"); - - funcsetinternalname(*funclistptr, s2); - } - else if (strncmp(s, "cfunction", 9)==0) - { - if (*funclistptr == NULL) - exitfileerror(20, ".cfunction has to come after a function declaration\n"); - - (*funclistptr)->libcall = REGISTER; - } - else if (strncmp(s, "private", 7)==0) - { - if (*funclistptr == NULL) - exitfileerror(20, ".private has to come after a function declaration\n"); - - (*funclistptr)->priv = 1; - } - else if (strncmp(s, "novararg", 8)==0) - { - if (*funclistptr == NULL) - exitfileerror(20, ".novararg has to come after a function declaration\n"); - - (*funclistptr)->novararg = 1; - } - else if (strncmp(s, "version", 7) == 0) - { - /* Mark version number for the following - * functions, so that the automatic OpenLibrary() - * will know what version to use. - */ - char *tmp; - int ver; - - s += 7; - - while (isspace(*s)) s++; - ver = (int)strtol(s, &tmp, 0); - - if (s == tmp) - exitfileerror(20, ".version expects an integer\n"); - - s = tmp; - while (isspace(*s)) s++; - - if (*s && *s != '#') - exitfileerror(20, ".version has junk after the version number\n"); - - minversion = ver; - } - else if (strncmp(s, "unusedlibbase", 13) == 0) - { - if (*funclistptr == NULL) - exitfileerror(20, ".unusedlibbase has to come after a function declaration\n"); - (*funclistptr)->unusedlibbase = 1; - } - else - exitfileerror(20, "Syntax error"); - } - else if (*line!='#') /* Ignore line that is a comment, e.g. that starts with a # */ - { - /* The line is a function or attribute prototype. - * A function can have one of two syntaxes: - * type funcname(argproto1, argproto2, ...) - * type funcname(argproto1, argproto2, ...) (reg1, reg2, ...) - * The former is for C type function argument passing, the latter for - * register argument passing. - * An attribute has the following syntax: - * type attribute - */ - char c, *args[64], *regs[64], *funcname, *cp; - int len, argcount = 0, regcount = 0, brcount = 0; - - cp = strchr(line,'#'); - if (cp) - *(cp++) = 0; - - /* Parse 'type functionname' at the beginning of the line */ - if (isattribute) { - s = line + strlen(line); - } else { - s = strchr(line, '('); - if (s == NULL) - exitfileerror(20, "( expected at position %d\n", strlen(line) + 1); - } - - s2 = s; - while (isspace(*(s2-1))) - s2--; - *s2 = '\0'; - - while (s2 > line && !isspace(*(s2-1)) && !(*(s2-1) == '*')) - s2--; - - if (s2 == line) - exitfileerror(20, "No type specifier before %s name\n", isattribute ? "attribute" : "function"); - - if (*funclistptr != NULL) - funclistptr = &((*funclistptr)->next); - *funclistptr = newfunctionhead(s2, STACK); - - if (cp) - (*funclistptr)->comment = strdup(cp); - else - (*funclistptr)->comment = NULL; - - while (isspace(*(s2-1))) - s2--; - *s2 = '\0'; - (*funclistptr)->type = strdup(line); - (*funclistptr)->lvo = lvo; - (*funclistptr)->version = minversion; - lvo++; - - if (isattribute) - continue; - - /* Parse function prototype */ - s++; - while (isspace(*s)) - s++; - c = *s; - - while (c != ')') - { - while (isspace(*s)) - s++; - - args[argcount] = s; - argcount++; - - while - ( - *s != '\0' - && !(brcount == 0 && (*s == ',' || *s == ')')) - ) - { - if (*s == '(') - brcount++; - if (*s == ')') - { - if (brcount > 0) - brcount--; - else - exitfileerror(20, "Unexected ')' at position %d\n", s-line+1); - } - s++; - } - - c = *s; - if (c == '\0') - exitfileerror(20, "'(' without ')'"); - - s2 = s; - while (isspace(*(s2-1))) - s2--; - *s2 = '\0'; - - if (!(s2 > args[argcount - 1])) - exitfileerror(20, "Syntax error in function prototype\n"); - - s++; - } - - s++; - while (*s != '\0' && isspace(*s)) - s++; - - if (*s == '(') - { - /* Parse registers specifications if available otherwise this prototype for C type argument passing */ - - /* There may be no register specified with () so be sure then c is == ')' */ - s++; - while(isspace(*s)) - s++; - - c = *s; - - while (c != ')') - { - while (isspace(*s)) - s++; - - regs[regcount] = s; - regcount++; - - if (memchr("AD",s[0],2)!=NULL && memchr("01234567",s[1],8)!=NULL) - { - s += 2; - c = *s; - if (c == '/') - { - s++; - if (s[0] == s[-3] && s[1] == s[-2] + 1) - { - s += 2; - c = *s; - } - else - exitfileerror(20, - "wrong register specification \"%s\" for argument %u\n", - regs[regcount-1], regcount - ); - - if (regcount > 4) - exitfileerror(20, "maximum four arguments passed in two registers allowed (%d, %s) \n", regcount, regs[regcount-1]); - } - *s = '\0'; - } - else - exitfileerror(20, - "wrong register \"%s\" for argument %u\n", - regs[regcount-1], regcount - ); - - while (isspace(c)) - { - s++; - c = *s; - } - if (c == '\0') - exitfileerror(20, "'(' without ')'\n"); - if (c != ',' && c != ')') - exitfileerror(20, "',' or ')' expected at position %d\n", s-line+1); - - s++; - } - - s++; - while (isspace(*s)) s++; - if (*s!='\0') - exitfileerror(20, "wrong char '%c' at position %d\n", *s, (int)(s-line) + 1); - - if (argcount != regcount) - exitfileerror(20, "Number of arguments (%d) and registers (%d) mismatch\n", - argcount, regcount - ); - - (*funclistptr)->libcall = def_libcall; - for (i = 0; i < argcount; i++) - funcaddarg(*funclistptr, args[i], regs[i]); - } - else if (*s == '\0') - { /* No registers specified */ - for (i = 0; i < argcount; i++) - funcaddarg(*funclistptr, args[i], NULL); - } - else - exitfileerror(20, "wrong char '%c' at position %d\n", *s, (int)(s-line) + 1); - } - } -} - -static void readsectionclass_methodlist(struct classinfo *cl) -{ - int atend = 0, i; - char *line, *s, *s2; - struct functionhead **methlistptr = &cl->methlist; - struct stringlist *interface = NULL; - - if (cl->basename==NULL) - exitfileerror(20, "section methodlist has to come after section config\n"); - - while (!atend) - { - line = readline(); - if (line==NULL) - exitfileerror(20, "unexptected EOF in methodlist section\n"); - - /* Ignore empty lines or lines that qre a comment, e.g. that starts with a # */ - if (strlen(line)==0 || (line[0] == '#' && line[1] != '#')) - continue; - - if (isspace(*line)) - exitfileerror(20, "No space allowed at start of the line\n"); - - if (strncmp(line, "##", 2)==0) /* Is this the end ? */ - { - s = line+2; - while (isspace(*s)) s++; - if (strncmp(s, "end", 3)!=0) - exitfileerror(20, "\"##end methodlist\" expected\n"); - - s += 3; - while (isspace(*s)) s++; - if (strncmp(s, "methodlist", 10)!=0) - exitfileerror(20, "\"##end methodlist\" expected\n"); - - s += 10; - while (isspace(*s)) s++; - if (*s!='\0') - exitfileerror(20, "unexpected character on position %d\n", s-line); - - atend = 1; - - continue; - } - - if (*line=='.') - { - s = line+1; - if (strncmp(s, "alias", 5)==0) - { - s += 5; - - if (!isspace(*s)) - exitfileerror(20, "syntax is '.alias name'\n"); - - while (isspace(*s)) s++; - if (*s == '\0' || !(isalpha(*s) || *s == '_')) - exitfileerror(20, "syntax is '.alias name'\n"); - - s2 = s; - s++; - while (isalnum(*s) || *s == '_') s++; - - if (isspace(*s)) - { - *s = '\0'; - do { - s++; - } while (isspace(*s)); - } - - if (*s != '\0') - exitfileerror(20, "syntax is '.alias name'\n"); - - if (*methlistptr == NULL) - exitfileerror(20, ".alias has to come after a function declaration\n"); - - slist_append(&(*methlistptr)->aliases, s2); - } - else if (strncmp(s, "function", 8) == 0) - { - s += 8; - - if (!isspace(*s)) - exitfileerror(20, "Syntax error\n"); - - while (isspace(*s)) s++; - if (*s == '\0' || !(isalpha(*s) || *s == '_')) - exitfileerror(20, "syntax is '.function name'\n"); - - s2 = s; - s++; - while (isalnum(*s) || *s == '_') s++; - - if (isspace(*s)) - { - *s = '\0'; - do { - s++; - } while (isspace(*s)); - } - - if (*s != '\0') - exitfileerror(20, "syntax is '.function name'\n"); - - if (*methlistptr == NULL) - exitfileerror(20, ".function has to come after a function declaration\n"); - - funcsetinternalname(*methlistptr, s2); - } - else if (strncmp(s, "interface", 9) == 0) - { - if (cl->classtype != HIDD) - exitfileerror(20, "interface only valid for a HIDD\n"); - - s += 9; - - if (!isspace(*s)) - exitfileerror(20, "Syntax error\n"); - - while (isspace(*s)) s++; - if (*s == '\0' || !isalpha(*s)) - exitfileerror(20, "syntax is '.interface name'\n"); - - s2 = s; - s++; - while (isalnum(*s) || *s == '_') s++; - - if (isspace(*s)) - { - *s = '\0'; - do { - s++; - } while (isspace(*s)); - } - - if (*s != '\0') - exitfileerror(20, "syntax is '.interface name'\n"); - - interface = slist_append(&cl->interfaces, s2); - } - else - exitfileerror(20, "Syntax error"); - } - else if (isalpha(*line)) - { - char stmp[256]; - - for (s = line + 1; isalnum(*s) || *s == '_'; s++) - ; - - if (cl->classtype == HIDD && interface == NULL) - exitfileerror(20, "For a HIDD the first method has to come after an .interface line\n"); - - if (*s != '\0') - exitfileerror(20, "Only letters, digits and an underscore allowed in a methodname\n"); - - if (*methlistptr != NULL) - methlistptr = &((*methlistptr)->next); - if (cl->classtype != HIDD) - { - if (snprintf(stmp, 256, "%s__%s", cl->basename, line) >= 256) - exitfileerror(20, "Method name too large\n"); - - *methlistptr = newfunctionhead(stmp, STACK); - (*methlistptr)->type = "IPTR"; - funcaddarg(*methlistptr, "Class *cl", NULL); - funcaddarg(*methlistptr, "Object *o", NULL); - funcaddarg(*methlistptr, "Msg msg", NULL); - } - else - { - if (snprintf(stmp, 256, "%s__%s__%s", cl->basename, interface->s, line) >= 256) - exitfileerror(20, "Method name too large\n"); - - *methlistptr = newfunctionhead(stmp, STACK); - (*methlistptr)->type = "IPTR"; - funcaddarg(*methlistptr, "OOP_Class *cl", NULL); - funcaddarg(*methlistptr, "OOP_Object *o", NULL); - funcaddarg(*methlistptr, "OOP_Msg msg", NULL); - (*methlistptr)->interface = interface; - if (snprintf(stmp, 256, "mo%s_%s", interface->s, line) >= 256) - exitfileerror(20, "Method name too large\n"); - (*methlistptr)->method = strdup(stmp); - } - slist_append(&(*methlistptr)->aliases, line); - } - else - exitfileerror(20, "Methodname has to begin with a letter\n"); - } -} - -static void -readsectioninterface(struct config *cfg) -{ - char *s; - struct interfaceinfo *in; - - in = newinterface(cfg); - s = readsections(cfg, NULL, in, 1); - if (s == NULL) - exitfileerror(20, "Unexpected end of file\n"); - - if (strncmp(s, "##", 2) != 0) - exitfileerror(20, "'##end interface' expected\n"); - s += 2; - - while (isspace(*s)) s++; - - if (strncmp(s, "end", 3) != 0) - exitfileerror(20, "'##end interface' expected\n"); - s += 3; - - if (!isspace(*s)) - exitfileerror(20, "'##end interface' expected\n"); - while (isspace(*s)) s++; - - if (strncmp(s, "interface", 9) != 0) - exitfileerror(20, "'##end interface' expected\n"); - s += 9; - - while (isspace(*s)) s++; - if (*s != '\0') - exitfileerror(20, "'##end interface' expected\n"); - - if (!in->interfaceid) - exitfileerror(20, "interface has no 'interfaceid' defined!\n"); - - if (!in->interfacename) - exitfileerror(20, "interface has no 'interfacename' defined!\n"); - - if (!in->methodstub) - in->methodstub = strdup(in->interfacename); - - if (!in->methodbase) { - int len = strlen(in->interfacename); - in->methodbase = malloc(len + 4 + 1); - strcpy(in->methodbase, in->interfacename); - strcat(in->methodbase, "Base"); - } - - if (!in->attributebase) { - int len = strlen(in->interfacename); - in->attributebase = malloc(len + 4 + 4 + 1); - strcpy(in->attributebase, in->interfacename); - strcat(in->attributebase, "AttrBase"); - } -} - -static void -readsectionclass(struct config *cfg) -{ - char *s; - struct classinfo *cl; - - cl = newclass(cfg); - s = readsections(cfg, cl, NULL, 1); - if (s == NULL) - exitfileerror(20, "Unexpected end of file\n"); - - if (strncmp(s, "##", 2) != 0) - exitfileerror(20, "'##end class' expected\n"); - s += 2; - - while (isspace(*s)) s++; - - if (strncmp(s, "end", 3) != 0) - exitfileerror(20, "'##end class' expected\n"); - s += 3; - - if (!isspace(*s)) - exitfileerror(20, "'##end class' expected\n"); - while (isspace(*s)) s++; - - if (strncmp(s, "class", 5) != 0) - exitfileerror(20, "'##end class' expected\n"); - s += 5; - - while (isspace(*s)) s++; - if (*s != '\0') - exitfileerror(20, "'##end class' expected\n"); -} - -static struct classinfo *newclass(struct config *cfg) -{ - struct classinfo *cl, *classlistit; - - cl = malloc(sizeof(struct classinfo)); - if (cl == NULL) - { - fprintf(stderr, "Out of memory\n"); - exit(20); - } - memset(cl, 0, sizeof(struct classinfo)); - - /* By default the classes are initialized with a priority of 1 so they - * are initialized before any user added initialization with priority 1 - */ - cl->initpri = 1; - - if (cfg->classlist == NULL) - cfg->classlist = cl; - else - { - for - ( - classlistit = cfg->classlist; - classlistit->next != NULL; - classlistit = classlistit->next - ) - ; - classlistit->next = cl; - } - - return cl; -} - -static struct handlerinfo *newhandler(struct config *cfg) -{ - struct handlerinfo *hl; - - hl = calloc(1,sizeof(*hl)); - hl->next = cfg->handlerlist; - cfg->handlerlist = hl; - return hl; -} - -static struct interfaceinfo *newinterface(struct config *cfg) -{ - struct interfaceinfo *in, *interfacelistit; - - in = malloc(sizeof(struct interfaceinfo)); - if (in == NULL) - { - fprintf(stderr, "Out of memory\n"); - exit(20); - } - memset(in, 0, sizeof(struct interfaceinfo)); - - if (cfg->interfacelist == NULL) - cfg->interfacelist = in; - else - { - for - ( - interfacelistit = cfg->interfacelist; - interfacelistit->next != NULL; - interfacelistit = interfacelistit->next - ) - ; - interfacelistit->next = in; - } - - return in; -} - - -static int getdirective(char *s, const char *directive, int range_min, int range_max, int *val) -{ - char *tmp; - int newval; - - if (strncmp(s, directive, strlen(directive)) != 0) - return 0; - - s += strlen(directive); - if (*s && !isspace(*s)) - exitfileerror(20, "Unrecognized directive \".%s\"\n", directive); - - while (isspace(*s)) s++; - if (!*s) - exitfileerror(20, "No .%s value specified\n", directive); - - newval = strtol(s, &tmp, 0); - if (s == tmp || !(newval >= range_min && newval <= range_max)) { - tmp = s; - while (*tmp && !isspace(*tmp)) tmp++; - exitfileerror(20, "Invalid .%s value of %.*s\n", directive, tmp - s, s); - } - - *val = newval; - return 1; -} - -static void -readsectionhandler(struct config *cfg) -{ - char *line = NULL, *s; - struct handlerinfo *hl; - unsigned char autolevel = 0; - unsigned int stacksize = 0; - int startup = 0; - char priority = 10; - int bootpri = -128; - int has_filesystem = 0; - - for (;;) - { - char *function; - int function_len; - char *tmp; - - s = line = readline(); - - if (s==NULL) - exitfileerror(20, "unexpected end of file in section hanlder\n"); - - if (strncmp(s, "##", 2)==0) - break; - - /* Ignore comments */ - if (strncmp(s, "#", 1)==0) - continue; - - /* Skip ahead to function name */ - while (*s && isspace(*s)) s++; - - /* Permit blank lines */ - if (!*s) - continue; - - if (*s == '.') { - int val; - s++; - - if (getdirective(s, "autodetect", 0, 127, &val)) { - autolevel = val; - } else if (getdirective(s, "stacksize", 0, INT_MAX, &val)) { - stacksize = val; - } else if (getdirective(s, "priority", -128, 127, &val)) { - priority = val; - } else if (getdirective(s, "bootpri", -128, 127, &val)) { - bootpri = val; - } else if (getdirective(s, "startup", INT_MIN, INT_MAX, &val)) { - startup = val; - } else { - exitfileerror(20, "Unrecognized directive \"%s\"\n", line); - } - continue; - } - - do { - unsigned int id = 0; - - if (strncasecmp(s,"resident=",9)==0) { - char *res; - - s = strchr(s, '=') + 1; - res = s; - while (*s && !isspace(*s)) s++; - if (res == s) - exitfileerror(20, "Empty resident= is not permitted\n"); - - if (*s) - *(s++) = 0; - - hl = newhandler(cfg); - hl->type = HANDLER_RESIDENT; - hl->id = 0; - hl->name = strdup(res); - hl->autodetect = autolevel--; - hl->stacksize = stacksize; - hl->priority = priority; - hl->startup = startup; - } else if (strncasecmp(s,"dosnode=",8)==0) { - char *dev; - - s = strchr(s, '=') + 1; - dev = s; - while (*s && !isspace(*s)) s++; - if (dev == s) - exitfileerror(20, "Empty dosnode= is not permitted\n"); - - if (*s) - *(s++) = 0; - - hl = newhandler(cfg); - hl->type = HANDLER_DOSNODE; - hl->id = 0; - hl->name = strdup(dev); - hl->autodetect = autolevel ? autolevel-- : 0; - hl->stacksize = stacksize; - hl->priority = priority; - hl->startup = startup; - hl->bootpri = bootpri; - } else if (strncasecmp(s,"dostype=",8) == 0) { - s = strchr(s, '=') + 1; - - id = (unsigned int)strtoul(s, &tmp, 0); - - if (s == tmp) { - while (*tmp && !isspace(*tmp)) - tmp++; - exitfileerror(20, "\"%.*s\" is not a numerical DOS ID\n", (tmp -s), s); - } - s = tmp; - - if (id == 0 || id == ~0) { - exitfileerror(20, "DOS ID 0x%08x is not permitted\n", id); - } - - hl = newhandler(cfg); - hl->type = HANDLER_DOSTYPE; - hl->id = id; - hl->name = NULL; - hl->autodetect = autolevel ? autolevel-- : 0; - hl->stacksize = stacksize; - hl->priority = priority; - hl->startup = startup; - } else { - for (tmp = s; !isspace(*tmp); tmp++); - exitfileerror(20, "Unknown option \"%.*s\"\n", tmp - s, s); - } - - /* Advance to next ID */ - while (*s && isspace(*s)) s++; - - } while (*s); - } - - if (s == NULL) - exitfileerror(20, "Unexpected end of file\n"); - - if (strncmp(s, "##", 2) != 0) - exitfileerror(20, "'##end handler' expected\n"); - s += 2; - - while (isspace(*s)) s++; - - if (strncmp(s, "end", 3) != 0) - exitfileerror(20, "'##end handler' expected\n"); - s += 3; - - while (isspace(*s)) s++; - - if (strncmp(s, "handler", 7) != 0) - exitfileerror(20, "'##end handler' expected\n"); - s += 7; - - while (isspace(*s)) s++; - if (*s != '\0') - exitfileerror(20, "'##end handler' expected\n"); -} - - +/* + Copyright © 1995-2013, The AROS Development Team. All rights reserved. + $Id$ + + Code to parse the command line options and the module config file for + the genmodule program +*/ + +#include +#include +#include +#define __USE_XOPEN +#include +#include +#include + +#include "functionhead.h" +#include "config.h" + +const static char bannertemplate[] = + "/*\n" + " *** Automatically generated from '%s'. Edits will be lost. ***\n" + " Copyright © 1995-%4u, The AROS Development Team. All rights reserved.\n" + "*/\n"; + +char* +getBanner(struct config* config) +{ + static unsigned currentyear = 0; + + int bannerlength = strlen(config->conffile) + strlen(bannertemplate); + // No additional bytes needed because + // + 1 (NUL) + 4 (4 digit year) - strlen("%s") - strlen("%4u) = 0 + + char * banner = malloc(bannerlength); + + if (currentyear == 0) + { + time_t rawtime; + time(&rawtime); + struct tm *utctm = gmtime(&rawtime); + currentyear = utctm->tm_year + 1900; + } + + snprintf (banner, bannerlength, bannertemplate, config->conffile, currentyear); + + return(banner); +} + +void +freeBanner(char *banner) +{ + free((void *)banner); +} + +const static char usage[] = + "\n" + "Usage: genmodule [-c conffile] [-s suffix] [-d gendir] [-v versionextra]\n" + " {writefiles|writemakefile|writeincludes|writelibdefs|writefunclist|writefd|writeskel} modname modtype\n" +; + +static void readconfig(struct config *); +static struct classinfo *newclass(struct config *); +static struct handlerinfo *newhandler(struct config *); +static struct interfaceinfo *newinterface(struct config *); + +/* the method prefices for the supported classes */ +static const char *muimprefix[] = +{ + "__OM_", + "__MUIM_", + NULL +}; +static const char *gadgetmprefix[] = +{ + "__OM_", + "__GM_", + "__AROSM_", + NULL +}; +static const char *dtmprefix[] = +{ + "__OM_", + "__GM_", + "__DTM_", + "__PDTM_", + NULL +}; + +/* Create a config struct. Initialize with the values from the programs command + * line arguments and the contents of the modules .conf file + */ +struct config *initconfig(int argc, char **argv) +{ + struct config *cfg; + char *s, **argvit = argv + 1; + int hassuffix = 0, c; + + cfg = malloc(sizeof(struct config)); + if (cfg == NULL) + { + fprintf(stderr, "Out of memory\n"); + exit(20); + } + + memset(cfg, 0, sizeof(struct config)); + + while ((c = getopt(argc, argv, ":c:s:d:v:")) != -1) + { + if (c == ':') + { + fprintf(stderr, "Option -%c needs an argument\n",optopt); + exit(20); + } + + switch (c) + { + case 'c': + cfg->conffile = optarg; + break; + + case 's': + cfg->suffix = optarg; + hassuffix = 1; + break; + + case 'd': + /* Remove / at end if present */ + if ((optarg)[strlen(*argvit)-1]=='/') (optarg)[strlen(optarg)-1]='\0'; + cfg->gendir = optarg; + break; + + case 'v': + cfg->versionextra = optarg; + break; + + default: + fprintf(stderr, "Internal error: Unhandled option\n"); + exit(20); + } + } + + if (optind + 3 != argc) + { + fprintf(stderr, "Wrong number of arguments.\n%s", usage); + exit(20); + } + + if (strcmp(argv[optind], "writefiles") == 0) + { + cfg->command = FILES; + } + else if (strcmp(argv[optind], "writemakefile") == 0) + { + cfg->command = MAKEFILE; + } + else if (strcmp(argv[optind], "writeincludes") == 0) + { + cfg->command = INCLUDES; + } + else if (strcmp(argv[optind], "writelibdefs") == 0) + { + cfg->command = LIBDEFS; + } + else if (strcmp(argv[optind], "writefunclist") == 0) + { + cfg->command = WRITEFUNCLIST; + } + else if (strcmp(argv[optind], "writefd") == 0) + { + cfg->command = WRITEFD; + } + else if (strcmp(argv[optind], "writeskel") == 0) + { + cfg->command = WRITESKEL; + } + else + { + fprintf(stderr, "Unrecognized argument \"%s\"\n%s", argv[optind], usage); + exit(20); + } + + cfg->modulename = argv[optind+1]; + cfg->modulenameupper = strdup(cfg->modulename); + for (s=cfg->modulenameupper; *s!='\0'; *s = toupper(*s), s++) { + if (!isalnum(*s)) *s = '_'; + } + + if (strcmp(argv[optind+2],"library")==0) + { + cfg->modtype = LIBRARY; + cfg->moddir = "Libs"; + } + else if (strcmp(argv[optind+2],"mcc")==0) + { + cfg->modtype = MCC; + cfg->moddir = "Classes/Zune"; + } + else if (strcmp(argv[optind+2],"mui")==0) + { + cfg->modtype = MUI; + cfg->moddir = "Classes/Zune"; + } + else if (strcmp(argv[optind+2],"mcp")==0) + { + cfg->modtype = MCP; + cfg->moddir = "Classes/Zune"; + } + else if (strcmp(argv[optind+2], "device")==0) + { + cfg->modtype = DEVICE; + cfg->moddir = "Devs"; + } + else if (strcmp(argv[optind+2], "resource")==0) + { + cfg->modtype = RESOURCE; + cfg->moddir = "Devs"; + } + else if (strcmp(argv[optind+2], "gadget")==0) + { + cfg->modtype = GADGET; + cfg->moddir = "Classes/Gadgets"; + } + else if (strcmp(argv[optind+2], "datatype")==0) + { + cfg->modtype = DATATYPE; + cfg->moddir = "Classes/DataTypes"; + } + else if (strcmp(argv[optind+2], "usbclass")==0) + { + cfg->modtype = USBCLASS; + cfg->moddir = "Classes/USB"; + if(!hassuffix) + { + cfg->suffix = "class"; + hassuffix = 1; + } + } + else if (strcmp(argv[optind+2], "hidd")==0) + { + cfg->modtype = HIDD; + cfg->moddir = "Devs/Drivers"; + } + else if (strcmp(argv[optind+2], "handler")==0) + { + cfg->modtype = HANDLER; + cfg->moddir = "$(AROS_DIR_FS)"; + } + else if (strcmp(argv[optind+2], "hook")==0) + { + cfg->modtype = HANDLER; + cfg->moddir = "Devs"; + } + else + { + fprintf(stderr, "Unknown modtype \"%s\" specified for second argument\n", argv[optind+2]); + exit(20); + } + cfg->modtypestr = argv[optind+2]; + + if (!hassuffix) + cfg->suffix = argv[optind+2]; + + /* Fill fields with default value if not specified on the command line */ + { + char tmpbuf[256]; + + if (cfg->conffile == NULL) + { + snprintf(tmpbuf, sizeof(tmpbuf), "%s.conf", cfg->modulename); + cfg->conffile = strdup(tmpbuf); + } + + if (cfg->gendir == NULL) + cfg->gendir = "."; + } + + readconfig(cfg); + + /* For a device add the functions given in beginiofunc and abortiofunc to the functionlist + * if they are provided + */ + if (cfg->beginiofunc != NULL) + { + struct functionhead *funchead; + + cfg->intcfg |= CFG_NOREADFUNCS; + + /* Add beginio_func to the list of functions */ + funchead = newfunctionhead(cfg->beginiofunc, REGISTERMACRO); + funchead->type = strdup("void"); + funchead->lvo = 5; + funcaddarg(funchead, "struct IORequest *ioreq", "A1"); + + funchead->next = cfg->funclist; + cfg->funclist = funchead; + + /* Add abortio_func to the list of functions */ + funchead = newfunctionhead(cfg->abortiofunc, REGISTERMACRO); + funchead->type = strdup("LONG"); + funchead->lvo = 6; + funcaddarg(funchead, "struct IORequest *ioreq", "A1"); + + funchead->next = cfg->funclist->next; + cfg->funclist->next = funchead; + } + else if (cfg->modtype == DEVICE && cfg->intcfg & CFG_NOREADFUNCS) + { + fprintf + ( + stderr, + "beginio_func and abortio_func missing for a device with a non empty function list\n" + ); + exit(20); + } + + /* See if we have any stackcall options */ + if (cfg->funclist) { + struct functionhead *funchead; + + for (funchead = cfg->funclist; funchead; funchead = funchead->next) { + if (funchead->libcall == STACK) { + cfg->options |= OPTION_STACKCALL; + break; + } + } + } + + /* Verify that a handler has a handler */ + if (cfg->modtype == HANDLER) { + if (cfg->handlerfunc == NULL) { + fprintf(stderr, "handler modules require a 'handler_func' ##config option\n"); + exit(20); + } + cfg->options |= OPTION_NOAUTOLIB | OPTION_NOEXPUNGE | OPTION_NOOPENCLOSE; + } + + return cfg; +} + +/* Functions to read configuration from the configuration file */ + +#include "fileread.h" + +static char *readsections(struct config *, struct classinfo *cl, struct interfaceinfo *in, int inclass); +static void readsectionconfig(struct config *, struct classinfo *cl, struct interfaceinfo *in, int inclass); +static void readsectioncdef(struct config *); +static void readsectioncdefprivate(struct config *); +static void readsectionstartup(struct config *); +static void readsectionfunctionlist(const char *type, struct functionhead **funclistptr, unsigned int firstlvo, int isattribute, enum libcall def_libcall); +static void readsectionclass_methodlist(struct classinfo *); +static void readsectionclass(struct config *); +static void readsectionhandler(struct config *); +static void readsectioninterface(struct config *); + +static void readconfig(struct config *cfg) +{ + struct classinfo *mainclass = NULL; + + /* Create a classinfo structure if this module is a class */ + switch (cfg->modtype) + { + case LIBRARY: + case DEVICE: + case RESOURCE: + case USBCLASS: + case HANDLER: + break; + + case MCC: + case MUI: + case MCP: + case GADGET: + case DATATYPE: + case HIDD: + mainclass = newclass(cfg); + mainclass->classtype = cfg->modtype; + break; + + default: + fprintf(stderr, "Internal error: unsupported modtype for classinfo creation\n"); + exit(20); + } + + switch (cfg->modtype) + { + case LIBRARY: + case USBCLASS: + cfg->firstlvo = 5; + break; + case DEVICE: + cfg->firstlvo = 7; + break; + case MCC: + case MUI: + case MCP: + cfg->firstlvo = 6; + mainclass->boopsimprefix = muimprefix; + break; + case HANDLER: + case RESOURCE: + cfg->firstlvo = 1; + break; + case GADGET: + cfg->firstlvo = 5; + mainclass->boopsimprefix = gadgetmprefix; + break; + case DATATYPE: + cfg->firstlvo = 6; + mainclass->boopsimprefix = dtmprefix; + break; + case HIDD: + cfg->firstlvo = 5; + /* FIXME: need boopsimprefix ? */ + break; + default: + fprintf(stderr, "Internal error: unsupported modtype for firstlvo\n"); + exit(20); + } + + if (!fileopen(cfg->conffile)) + { + fprintf(stderr, "In readconfig: Could not open %s\n", cfg->conffile); + exit(20); + } + + /* Read all sections and see that we are at the end of the file */ + if (readsections(cfg, mainclass, NULL, 0) != NULL) + exitfileerror(20, "Syntax error"); + + fileclose(); +} + +/* readsections will scan through all the sections in the config file. + * arguments: + * struct config *cfg: The module config data which may be updated by + * the information in the sections + * struct classinfo *cl: The classdata to be filled with data from the sections. + * This may be NULL if this is the main part of the configuration file and the + * type of the module is not a class + * int inclass: Boolean to indicate if we are in a class part. If not we are in the main + * part of the config file. + */ +static char *readsections(struct config *cfg, struct classinfo *cl, struct interfaceinfo *in, int inclass) +{ + char *line, *s, *s2; + int hasconfig = 0; + + while ((line=readline())!=NULL) + { + if (strncmp(line, "##", 2)==0) + { + static char *parts[] = + { + "config", "cdefprivate", "cdef", "startup", "functionlist", "methodlist", "class", "handler", "interface", "attributelist", "cfunctionlist" + }; + const unsigned int nums = sizeof(parts)/sizeof(char *); + unsigned int partnum; + int i, atend = 0; + + s = line+2; + while (isspace(*s)) s++; + + if (strncmp(s, "begin", 5)!=0) + return line; + + s += 5; + if (!isspace(*s)) + exitfileerror(20, "space after begin expected\n"); + while (isspace(*s)) s++; + + for (i = 0, partnum = 0; partnum==0 && ibasename==NULL) + exitfileerror(20, "section functionlist has to come after section config\n"); + + readsectionfunctionlist("functionlist", &cfg->funclist, cfg->firstlvo, 0, REGISTERMACRO); + cfg->intcfg |= CFG_NOREADFUNCS; + break; + + case 6: /* methodlist */ + if (cl == NULL && in == NULL) + exitfileerror(20, "methodlist section when not in a class or interface\n"); + if (cl) + readsectionclass_methodlist(cl); + else + readsectionfunctionlist("methodlist", &in->methodlist, 0, 0, REGISTERMACRO); + cfg->intcfg |= CFG_NOREADFUNCS; + break; + + case 7: /* class */ + if (inclass) + exitfileerror(20, "class section may not be in nested\n"); + readsectionclass(cfg); + break; + case 8: /* handler */ + readsectionhandler(cfg); + break; + case 9: /* interface */ + if (inclass) + exitfileerror(20, "interface section may not be nested\n"); + readsectioninterface(cfg); + break; + case 10: /* attributelist */ + if (!in) + exitfileerror(20, "attributelist only valid in interface sections\n"); + readsectionfunctionlist("attributelist", &in->attributelist, 0, 1, INVALID); + break; + case 11: /* cfunctionlist */ + if (inclass) + exitfileerror(20, "cfunctionlist section not allow in class section\n"); + if (cfg->basename==NULL) + exitfileerror(20, "section cfunctionlist has to come after section config\n"); + + readsectionfunctionlist("cfunctionlist", &cfg->funclist, cfg->firstlvo, 0, REGISTER); + cfg->intcfg |= CFG_NOREADFUNCS; + break; + } + } + else if (strlen(line)!=0) + filewarning("warning line outside section ignored\n"); + } + + if(!inclass) + { + if (!hasconfig) + exitfileerror(20, "No config section in conffile\n"); + + /* If no indication was given for generating includes or not + decide on module type and if there are functions + */ + if(!((cfg->options & OPTION_INCLUDES) || (cfg->options & OPTION_NOINCLUDES))) + { + switch (cfg->modtype) + { + case LIBRARY: + case RESOURCE: + cfg->options |= OPTION_INCLUDES; + break; + + case HANDLER: + case MCC: + case MUI: + case MCP: + case USBCLASS: + cfg->options |= OPTION_NOINCLUDES; + break; + + case DEVICE: + cfg->options |= ( + (cfg->funclist != NULL) + || (cfg->cdeflines != NULL) + || strcmp(cfg->libbasetypeptrextern, "struct Device *") != 0 + ) ? OPTION_INCLUDES : OPTION_NOINCLUDES; + break; + + case GADGET: + case DATATYPE: + case HIDD: + cfg->options |= ( + (cfg->funclist != NULL) + ) ? OPTION_INCLUDES : OPTION_NOINCLUDES; + break; + + default: + fprintf(stderr, "Internal error writemakefile: unhandled modtype for includes\n"); + exit(20); + break; + } + } + + /* If no indication was given for not generating stubs only generate them if + * the module has functions + */ + if(!((cfg->options & OPTION_STUBS) || (cfg->options & OPTION_NOSTUBS))) + { + switch (cfg->modtype) + { + case LIBRARY: + cfg->options |= (cfg->funclist != NULL) ? OPTION_STUBS : OPTION_NOSTUBS; + break; + + case USBCLASS: + case RESOURCE: + case GADGET: + case DEVICE: + case DATATYPE: + case MCC: + case MUI: + case MCP: + case HIDD: + case HANDLER: + cfg->options |= OPTION_NOSTUBS; + break; + + default: + fprintf(stderr, "Internal error writemakefile: unhandled modtype for stubs\n"); + exit(20); + break; + } + } + + /* If no indication was given for generating autoinit code or not + decide on module type + */ + if(!((cfg->options & OPTION_AUTOINIT) || (cfg->options & OPTION_NOAUTOINIT))) + { + switch (cfg->modtype) + { + case LIBRARY: + cfg->options |= OPTION_AUTOINIT; + break; + + case USBCLASS: + case RESOURCE: + case GADGET: + case DEVICE: + case DATATYPE: + case MCC: + case MUI: + case MCP: + case HIDD: + case HANDLER: + cfg->options |= OPTION_NOAUTOINIT; + break; + + default: + fprintf(stderr, "Internal error writemakefile: unhandled modtype for autoinit\n"); + exit(20); + break; + } + } + + if ((cfg->modtype == RESOURCE) || (cfg->modtype == HANDLER)) + /* Enforce noopenclose for resources and handlers */ + cfg->options |= OPTION_NOOPENCLOSE; + else if (!(cfg->options & OPTION_SELFINIT)) + /* Enforce using RTF_AUTOINIT for everything except resources */ + cfg->options |= OPTION_RESAUTOINIT; + } + + return NULL; +} + +static void readsectionconfig(struct config *cfg, struct classinfo *cl, struct interfaceinfo *in, int inclass) +{ + int atend = 0, i; + char *line, *s, *s2, *libbasetypeextern = NULL; + struct tm date; + + while (!atend) + { + line = readline(); + if (line==NULL) + exitfileerror(20, "unexpected end of file in section config\n"); + + if (strncmp(line, "##", 2)!=0) + { + const char *names[] = + { + "basename", "libbase", "libbasetype", "libbasetypeextern", + "version", "date", "copyright", "libcall", "forcebase", "superclass", + "superclass_field", "residentpri", "options", "sysbase_field", + "seglist_field", "rootbase_field", "classptr_field", "classptr_var", + "classid", "classdatatype", "beginio_func", "abortio_func", "dispatcher", + "initpri", "type", "addromtag", "oopbase_field", + "rellib", "interfaceid", "interfacename", + "methodstub", "methodbase", "attributebase", "handler_func" + }; + const unsigned int namenums = sizeof(names)/sizeof(char *); + unsigned int namenum; + + for (i = 0, namenum = 0; namenum==0 && ibasename = strdup(s); + if (cl != NULL) + cl->basename = strdup(s); + if (in != NULL) + exitfileerror(20, "basename not valid config option when in a interface section\n"); + break; + + case 2: /* libbase */ + if (inclass) + exitfileerror(20, "libbase not valid config option when in a class section\n"); + cfg->libbase = strdup(s); + break; + + case 3: /* libbasetype */ + if (inclass) + exitfileerror(20, "libbasetype not valid config option when in a class section\n"); + cfg->libbasetype = strdup(s); + break; + + case 4: /* libbasetypeextern */ + if (inclass) + exitfileerror(20, "libbasetype not valid config option when in a class section\n"); + libbasetypeextern = strdup(s); + break; + + case 5: /* version */ + if (inclass) + exitfileerror(20, "version not valid config option when in a class section\n"); + if (sscanf(s, "%u.%u", &cfg->majorversion, &cfg->minorversion)!=2) + exitfileerror(20, "wrong version string \"%s\"\n", s); + break; + + case 6: /* date */ + if (inclass) + exitfileerror(20, "date not valid config option when in a class section\n"); +#ifndef _WIN32 + if (strptime(s, "%e.%m.%Y", &date) == NULL) + { + exitfileerror(20, "date string has to have d.m.yyyy format\n"); + } +#endif + cfg->datestring = strdup(s); + break; + + case 7: /* copyright */ + if (inclass) + exitfileerror(20, "copyright not valid config option when in a class section\n"); + cfg->copyright = strdup(s); + break; + + case 8: /* libcall */ + fprintf(stderr, "libcall specification is deprecated and ignored\n"); + break; + + case 9: /* forcebase */ + if (inclass) + exitfileerror(20, "forcebase not valid config option when in a class section\n"); + slist_append(&cfg->forcelist, s); + break; + + case 10: /* superclass */ + if (cl == NULL) + exitfileerror(20, "superclass specified when not a BOOPSI class\n"); + cl->superclass = strdup(s); + break; + + case 11: /* superclass_field */ + if (cl == NULL) + exitfileerror(20, "superclass_field specified when not a BOOPSI class\n"); + cl->superclass_field = strdup(s); + break; + + case 12: /* residentpri */ + if (!inclass) + { + int count; + char dummy; + + count = sscanf(s, "%d%c", &cfg->residentpri, &dummy); + if (count != 1 || + cfg->residentpri < -128 || cfg->residentpri > 127 + ) + { + exitfileerror(20, "residentpri number format error\n"); + } + } + else + exitfileerror(20, "residentpri not valid config option when in a class section\n"); + break; + + case 13: /* options */ + if (!inclass) + { + static const char *optionnames[] = + { + "noautolib", "noexpunge", "noresident", "peropenerbase", + "pertaskbase", "includes", "noincludes", "nostubs", + "autoinit", "noautoinit", "resautoinit", "noopenclose", + "selfinit" + }; + const unsigned int optionnums = sizeof(optionnames)/sizeof(char *); + int optionnum; + + do + { + for (i = 0, optionnum = 0; optionnum==0 && ioptions |= OPTION_NOAUTOLIB; + break; + case 2: /* noexpunge */ + cfg->options |= OPTION_NOEXPUNGE; + break; + case 3: /* noresident */ + cfg->options |= OPTION_NORESIDENT; + cfg->firstlvo = 1; + break; + case 5: /* pertaskbase */ + cfg->options |= OPTION_PERTASKBASE; + /* Fall through */ + case 4: /* peropenerbase */ + if (cfg->options & OPTION_DUPBASE) + exitfileerror(20, "Only one option peropenerbase or pertaskbase allowed\n"); + cfg->options |= OPTION_DUPBASE; + break; + case 6: /* includes */ + if (cfg->options & OPTION_NOINCLUDES) + exitfileerror(20, "option includes and noincludes are incompatible\n"); + cfg->options |= OPTION_INCLUDES; + break; + case 7: /* noincludes */ + if (cfg->options & OPTION_INCLUDES) + exitfileerror(20, "option includes and noincludes are incompatible\n"); + cfg->options |= OPTION_NOINCLUDES; + break; + case 8: /* nostubs */ + cfg->options |= OPTION_NOSTUBS; + break; + case 9: /* autoinit */ + if (cfg->options & OPTION_NOAUTOINIT) + exitfileerror(20, "option autoinit and noautoinit are incompatible\n"); + cfg->options |= OPTION_AUTOINIT; + break; + case 10: /* noautoinit */ + if (cfg->options & OPTION_AUTOINIT) + exitfileerror(20, "option autoinit and noautoinit are incompatible\n"); + cfg->options |= OPTION_NOAUTOINIT; + break; + case 11: /* resautoinit */ + if (cfg->options & OPTION_SELFINIT) + exitfileerror(20, "option resautoinit and selfinit are incompatible\n"); + cfg->options |= OPTION_RESAUTOINIT; + break; + case 12: + cfg->options |= OPTION_NOOPENCLOSE; + break; + case 13: /* noresautoinit */ + if (cfg->options & OPTION_RESAUTOINIT) + exitfileerror(20, "option resautoinit and selfinit are incompatible\n"); + cfg->options |= OPTION_SELFINIT; + break; + } + while (isspace(*s)) s++; + } while(*s !='\0'); + } + else + { + static const char *optionnames[] = + { + "private" + }; + const unsigned int optionnums = sizeof(optionnames)/sizeof(char *); + int optionnum; + + do + { + for (i = 0, optionnum = 0; optionnum==0 && ioptions |= COPTION_PRIVATE; + break; + } + while (isspace(*s)) s++; + } while(*s !='\0'); + } + break; + + case 14: /* sysbase_field */ + if (inclass) + exitfileerror(20, "sysbase_field not valid config option when in a class section\n"); + cfg->sysbase_field = strdup(s); + break; + + case 15: /* seglist_field */ + if (inclass) + exitfileerror(20, "seglist_field not valid config option when in a class section\n"); + cfg->seglist_field = strdup(s); + break; + + case 16: /* rootbase_field */ + if (inclass) + exitfileerror(20, "rootbase_field not valid config option when in a class section\n"); + cfg->rootbase_field = strdup(s); + break; + + case 17: /* classptr_field */ + if (cl == NULL) + { + exitfileerror + ( + 20, + "classptr_field specified when not a BOOPSI class\n" + ); + } + cl->classptr_field = strdup(s); + break; + + case 18: /* classptr_var */ + if (cl == NULL) + { + exitfileerror + ( + 20, + "classptr_var specified when not a BOOPSI class\n" + ); + } + cl->classptr_var = strdup(s); + break; + + case 19: /* classid */ + if (cl == NULL) + exitfileerror(20, "classid specified when not a BOOPSI class\n"); + if (cl->classid != NULL) + exitfileerror(20, "classid specified twice\n"); + cl->classid = strdup(s); + if (strcmp(cl->classid, "NULL") == 0) + cl->options |= COPTION_PRIVATE; + break; + + case 20: /* classdatatype */ + if (cl == NULL) + exitfileerror(20, "classdatatype specified when not a BOOPSI class\n"); + cl->classdatatype = strdup(s); + break; + + case 21: /* beginio_func */ + if (inclass) + exitfileerror(20, "beginio_func not valid config option when in a class section\n"); + if (cfg->modtype != DEVICE) + exitfileerror(20, "beginio_func specified when not a device\n"); + cfg->beginiofunc = strdup(s); + break; + + case 22: /* abortio_func */ + if (inclass) + exitfileerror(20, "abortio_func not valid config option when in a class section\n"); + if (cfg->modtype != DEVICE) + exitfileerror(20, "abortio_func specified when not a device\n"); + cfg->abortiofunc = strdup(s); + break; + + case 23: /* dispatcher */ + if (cl == NULL) + exitfileerror(20, "dispatcher specified when not a BOOPSI class\n"); + cl->dispatcher = strdup(s); + /* function references are not needed when dispatcher is specified */ + cfg->intcfg |= CFG_NOREADFUNCS; + break; + + case 24: /* initpri */ + if (cl != NULL) + { + int count; + char dummy; + + count = sscanf(s, "%d%c", &cl->initpri, &dummy); + if (count != 1 || + cl->initpri < -128 || cl->initpri > 127 + ) + { + exitfileerror(20, "initpri number format error\n"); + } + } + else + exitfileerror(20, "initpri only valid config option for a BOOPSI class\n"); + break; + + case 25: /* type */ + if (!inclass) + exitfileerror(20, "type only valid config option in a class section\n"); + if (strcmp(s,"mcc")==0) + cl->classtype = MCC; + else if (strcmp(s,"mui")==0) + cl->classtype = MUI; + else if (strcmp(s,"mcp")==0) + cl->classtype = MCP; + else if (strcmp(s, "image")==0) + cl->classtype = IMAGE; + else if (strcmp(s, "gadget")==0) + cl->classtype = GADGET; + else if (strcmp(s, "datatype")==0) + cl->classtype = DATATYPE; + else if (strcmp(s, "usbclass")==0) + cl->classtype = USBCLASS; + else if (strcmp(s, "class")==0) + cl->classtype = CLASS; + else if (strcmp(s, "hidd")==0) + cl->classtype = HIDD; + else + { + fprintf(stderr, "Unknown type \"%s\" specified\n", s); + exit(20); + } + break; + + case 26: /* addromtag */ + cfg->addromtag = strdup(s); + break; + + case 27: /* oopbase_field */ + cfg->oopbase_field = strdup(s); + break; + case 28: /* rellib */ + slist_append(&cfg->rellibs, s); + break; + case 29: /* interfaceid */ + if (!in) + exitfileerror(20, "interfaceid only valid config option for an interface\n"); + in->interfaceid = strdup(s); + break; + case 30: /* interfacename */ + if (!in) + exitfileerror(20, "interfacename only valid config option for an interface\n"); + in->interfacename = strdup(s); + break; + case 31: /* methodstub */ + if (!in) + exitfileerror(20, "methodstub only valid config option for an interface\n"); + in->methodstub = strdup(s); + break; + case 32: /* methodbase */ + if (!in) + exitfileerror(20, "methodbase only valid config option for an interface\n"); + in->methodbase = strdup(s); + break; + case 33: /* attributebase */ + if (!in) + exitfileerror(20, "attributebase only valid config option for an interface\n"); + in->attributebase = strdup(s); + break; + case 34: /* handler_func */ + if (cfg->modtype != HANDLER) + exitfileerror(20, "handler specified when not a handler\n"); + cfg->handlerfunc = strdup(s); + break; + } + } + else /* Line starts with ## */ + { + s = line+2; + while (isspace(*s)) s++; + if (strncmp(s, "end", 3)!=0) + exitfileerror(20, "\"##end config\" expected\n"); + + s += 3; + if (!isspace(*s)) + exitfileerror(20, "\"##end config\" expected\n"); + + while (isspace(*s)) s++; + if (strncmp(s, "config", 6)!=0) + exitfileerror(20, "\"##end config\" expected\n"); + + s += 6; + while (isspace(*s)) s++; + if (*s!='\0') + exitfileerror(20, "\"##end config\" expected\n"); + + atend = 1; + } + } + + /* When not in a class section fill in default values for fields in cfg */ + if (!inclass) + { + if (cfg->basename==NULL) + { + cfg->basename = strdup(cfg->modulename); + *cfg->basename = toupper(*cfg->basename); + } + if (cfg->libbase==NULL) + { + unsigned int len = strlen(cfg->basename)+5; + cfg->libbase = malloc(len); + snprintf(cfg->libbase, len, "%sBase", cfg->basename); + } + if (cfg->libbasetype == NULL && libbasetypeextern != NULL) + cfg->libbasetype = strdup(libbasetypeextern); + if (cfg->sysbase_field != NULL && cfg->libbasetype == NULL) + exitfileerror(20, "sysbase_field specified when no libbasetype is given\n"); + if (cfg->seglist_field != NULL && cfg->libbasetype == NULL) + exitfileerror(20, "seglist_field specified when no libbasetype is given\n"); + if (cfg->oopbase_field != NULL && cfg->libbasetype == NULL) + exitfileerror(20, "oopbase_field specified when no libbasetype is given\n"); + /* rootbase_field only allowed when duplicating base */ + if (cfg->rootbase_field != NULL && !(cfg->options & OPTION_DUPBASE)) + exitfileerror(20, "rootbasefield only valid for option peropenerbase or pertaskbase\n"); + + /* Set default date to current date */ + if (cfg->datestring == NULL) + { + char tmpbuf[256]; + time_t now = time(NULL); + struct tm *ltime = localtime(&now); + + snprintf(tmpbuf, sizeof(tmpbuf), "%u.%u.%u", + ltime->tm_mday, 1 + ltime->tm_mon, 1900 + ltime->tm_year); + + cfg->datestring = strdup(tmpbuf); + } + + if (cfg->copyright == NULL) + cfg->copyright = ""; + + if ( (cfg->beginiofunc != NULL && cfg->abortiofunc == NULL) + || (cfg->beginiofunc == NULL && cfg->abortiofunc != NULL) + ) + exitfileerror(20, "please specify both beginio_func and abortio_func\n"); + + if (libbasetypeextern==NULL) + { + switch (cfg->modtype) + { + case DEVICE: + cfg->libbasetypeptrextern = "struct Device *"; + break; + case HANDLER: + case RESOURCE: + cfg->libbasetypeptrextern = "APTR "; + break; + case LIBRARY: + case MUI: + case MCP: + case MCC: + case GADGET: + case DATATYPE: + case USBCLASS: + case HIDD: + cfg->libbasetypeptrextern = "struct Library *"; + break; + default: + fprintf(stderr, "Internal error: Unsupported modtype for libbasetypeptrextern\n"); + exit(20); + } + } + else + { + cfg->libbasetypeptrextern = malloc(strlen(libbasetypeextern)+3); + strcpy(cfg->libbasetypeptrextern, libbasetypeextern); + strcat(cfg->libbasetypeptrextern, " *"); + free(libbasetypeextern); + } + } + + /* When class was given too fill in some defaults when not specified */ + if (cl != NULL) + { + if (cl->classtype == UNSPECIFIED) + cl->classtype = CLASS; + + if (cl->basename == NULL) + { + if (!inclass) + cl->basename = cfg->basename; + else + exitfileerror(20, "basename has to be specified in the config section inside of a class section\n"); + } + + /* MUI classes are always private */ + if (cl->classtype == MUI || cl->classtype == MCC || cl->classtype == MCP) + cl->options |= COPTION_PRIVATE; + + if (cl->classid == NULL + && (cl->classtype != MUI && cl->classtype != MCC && cl->classtype != MCP) + ) + { + if (cl->classtype == HIDD) + { + cl->options &= !COPTION_PRIVATE; + } + else if (cl->options & COPTION_PRIVATE) + { + cl->classid = "NULL"; + } + else + { + char s[256] = ""; + + if (cl->classtype == GADGET || cl->classtype == IMAGE || cl->classtype == CLASS || cl->classtype == USBCLASS) + { + sprintf(s, "\"%sclass\"", inclass ? cl->basename : cfg->modulename); + } + else if (cl->classtype == DATATYPE) + { + sprintf(s, "\"%s.datatype\"", inclass ? cl->basename : cfg->modulename); + } + cl->classid = strdup(s); + } + } + + /* Only specify superclass or superclass_field */ + if (cl->superclass != NULL && cl->superclass_field != NULL) + exitfileerror(20, "Only specify one of superclass or superclass_field in config section\n"); + + /* Give default value to superclass if it is not specified */ + if (cl->superclass == NULL && cl->superclass == NULL) + { + switch (cl->classtype) + { + case MUI: + case MCC: + cl->superclass = "MUIC_Area"; + break; + case MCP: + cl->superclass = "MUIC_Mccprefs"; + break; + case IMAGE: + cl->superclass = "IMAGECLASS"; + break; + case GADGET: + cl->superclass = "GADGETCLASS"; + break; + case DATATYPE: + cl->superclass = "DATATYPESCLASS"; + break; + case CLASS: + cl->superclass = "ROOTCLASS"; + break; + case HIDD: + cl->superclass = "CLID_Root"; + break; + default: + exitfileerror(20, "Internal error: unhandled classtype in readsectionconfig\n"); + break; + } + } + } +} + +static void readsectioncdef(struct config *cfg) +{ + int atend = 0; + char *line, *s; + + while (!atend) + { + line = readline(); + if (line==NULL) + exitfileerror(20, "unexptected end of file in section cdef\n"); + + if (strncmp(line, "##", 2)!=0) + { + slist_append(&cfg->cdeflines, line); + } + else + { + s = line+2; + while (isspace(*s)) s++; + if (strncmp(s, "end", 3)!=0) + exitfileerror(20, "\"##end cdef\" expected\n"); + + s += 3; + while (isspace(*s)) s++; + if (strncmp(s, "cdef", 4)!=0) + exitfileerror(20, "\"##end cdef\" expected\n"); + + s += 5; + while (isspace(*s)) s++; + if (*s!='\0') + exitfileerror(20, "unexpected character at position %d\n"); + + atend = 1; + } + } +} + +static void readsectioncdefprivate(struct config *cfg) +{ + int atend = 0; + char *line, *s; + + while (!atend) + { + line = readline(); + if (line==NULL) + exitfileerror(20, "unexptected end of file in section cdef\n"); + + if (strncmp(line, "##", 2)!=0) + { + slist_append(&cfg->cdefprivatelines, line); + } + else + { + s = line+2; + while (isspace(*s)) s++; + if (strncmp(s, "end", 3)!=0) + exitfileerror(20, "\"##end cdefprivate\" expected\n"); + + s += 3; + while (isspace(*s)) s++; + if (strncmp(s, "cdefprivate", 11)!=0) + exitfileerror(20, "\"##end cdefprivate\" expected\n"); + + s += 11; + while (isspace(*s)) s++; + if (*s!='\0') + exitfileerror(20, "unexpected character at position %d\n"); + + atend = 1; + } + } +} + +static void readsectionstartup(struct config *cfg) +{ + int atend = 0; + char *line, *s; + + while (!atend) + { + line = readline(); + if (line==NULL) + exitfileerror(20, "unexptected end of file in section startup\n"); + + if (strncmp(line, "##", 2)!=0) + { + slist_append(&cfg->startuplines, line); + } + else + { + s = line+2; + while (isspace(*s)) s++; + if (strncmp(s, "end", 3)!=0) + exitfileerror(20, "\"##end startup\" expected\n"); + + s += 3; + while (isspace(*s)) s++; + if (strncmp(s, "startup", 7)!=0) + exitfileerror(20, "\"##end startup\" expected\n"); + + s += 7; + while (isspace(*s)) s++; + if (*s!='\0') + exitfileerror(20, "unexpected character at position %d\n"); + + atend = 1; + } + } +} + +static void readsectionfunctionlist(const char *type, struct functionhead **funclistptr, unsigned int firstlvo, int isattribute, enum libcall def_libcall) +{ + int atend = 0, i; + char *line, *s, *s2; + unsigned int lvo = firstlvo; + int minversion = 0; + + while (!atend) + { + line = readline(); + if (line==NULL) + exitfileerror(20, "unexpected EOF in functionlist section\n"); + if (strlen(line)==0) + { + if (*funclistptr != NULL) + funclistptr = &((*funclistptr)->next); + lvo++; + } + else if (isspace(*line)) + { + s = line; + while (isspace(*s)) s++; + if (*s=='\0') + { + if (*funclistptr != NULL) + funclistptr = &((*funclistptr)->next); + lvo++; + } + else + exitfileerror(20, "no space allowed before functionname\n"); + } + else if (strncmp(line, "##", 2)==0) + { + s = line+2; + while (isspace(*s)) s++; + if (strncmp(s, "end", 3)!=0) + exitfileerror(20, "\"##end %s\" expected\n", type); + + s += 3; + while (isspace(*s)) s++; + if (strncmp(s, type, strlen(type))!=0) + exitfileerror(20, "\"##end %s\" expected\n", type); + + s += strlen(type); + while (isspace(*s)) s++; + if (*s!='\0') + exitfileerror(20, "unexpected character on position %d\n", s-line); + + atend = 1; + } + else if (*line=='.') + { + s = line+1; + if (strncmp(s, "skip", 4)==0) + { + int n; + + s += 4; + if (!isspace(*s)) + exitfileerror(20, "syntax is '.skip n'\n"); + + n=strtol(s, &s2, 10); + if (s2==NULL) + exitfileerror(20, "positive number expected\n"); + + while (isspace(*s2)) s2++; + if ((*s2 != '\0') && (*s2 != '#')) + exitfileerror(20, "syntax is '.skip n'\n"); + if (*funclistptr != NULL) + funclistptr = &((*funclistptr)->next); + lvo += n; + } + else if (strncmp(s, "alias", 5)==0) + { + s += 5; + + if (!isspace(*s)) + exitfileerror(20, "syntax is '.alias name'\n"); + + while (isspace(*s)) s++; + if (*s == '\0' || !(isalpha(*s) || *s == '_')) + exitfileerror(20, "syntax is '.alias name'\n"); + + s2 = s; + s++; + while (isalnum(*s) || *s == '_') s++; + + if (isspace(*s)) + { + *s = '\0'; + do { + s++; + } while (isspace(*s)); + } + + if (*s != '\0') + exitfileerror(20, "syntax is '.alias name'\n"); + + if (*funclistptr == NULL) + exitfileerror(20, ".alias has to come after a function declaration\n"); + + slist_append(&(*funclistptr)->aliases, s2); + } + else if (strncmp(s, "function", 8) == 0) + { + s += 8; + + if (!isspace(*s)) + exitfileerror(20, "Syntax error\n"); + + while (isspace(*s)) s++; + if (*s == '\0' || !(isalpha(*s) || *s == '_')) + exitfileerror(20, "syntax is '.function name'\n"); + + s2 = s; + s++; + while (isalnum(*s) || *s == '_') s++; + + if (isspace(*s)) + { + *s = '\0'; + do { + s++; + } while (isspace(*s)); + } + + if (*s != '\0') + exitfileerror(20, "syntax is '.function name'\n"); + + if (*funclistptr == NULL) + exitfileerror(20, ".function has to come after a function declaration\n"); + + funcsetinternalname(*funclistptr, s2); + } + else if (strncmp(s, "cfunction", 9)==0) + { + if (*funclistptr == NULL) + exitfileerror(20, ".cfunction has to come after a function declaration\n"); + + (*funclistptr)->libcall = REGISTER; + } + else if (strncmp(s, "private", 7)==0) + { + if (*funclistptr == NULL) + exitfileerror(20, ".private has to come after a function declaration\n"); + + (*funclistptr)->priv = 1; + } + else if (strncmp(s, "novararg", 8)==0) + { + if (*funclistptr == NULL) + exitfileerror(20, ".novararg has to come after a function declaration\n"); + + (*funclistptr)->novararg = 1; + } + else if (strncmp(s, "version", 7) == 0) + { + /* Mark version number for the following + * functions, so that the automatic OpenLibrary() + * will know what version to use. + */ + char *tmp; + int ver; + + s += 7; + + while (isspace(*s)) s++; + ver = (int)strtol(s, &tmp, 0); + + if (s == tmp) + exitfileerror(20, ".version expects an integer\n"); + + s = tmp; + while (isspace(*s)) s++; + + if (*s && *s != '#') + exitfileerror(20, ".version has junk after the version number\n"); + + minversion = ver; + } + else if (strncmp(s, "unusedlibbase", 13) == 0) + { + if (*funclistptr == NULL) + exitfileerror(20, ".unusedlibbase has to come after a function declaration\n"); + (*funclistptr)->unusedlibbase = 1; + } + else + exitfileerror(20, "Syntax error"); + } + else if (*line!='#') /* Ignore line that is a comment, e.g. that starts with a # */ + { + /* The line is a function or attribute prototype. + * A function can have one of two syntaxes: + * type funcname(argproto1, argproto2, ...) + * type funcname(argproto1, argproto2, ...) (reg1, reg2, ...) + * The former is for C type function argument passing, the latter for + * register argument passing. + * An attribute has the following syntax: + * type attribute + */ + char c, *args[64], *regs[64], *funcname, *cp; + int len, argcount = 0, regcount = 0, brcount = 0; + + cp = strchr(line,'#'); + if (cp) + *(cp++) = 0; + + /* Parse 'type functionname' at the beginning of the line */ + if (isattribute) { + s = line + strlen(line); + } else { + s = strchr(line, '('); + if (s == NULL) + exitfileerror(20, "( expected at position %d\n", strlen(line) + 1); + } + + s2 = s; + while (isspace(*(s2-1))) + s2--; + *s2 = '\0'; + + while (s2 > line && !isspace(*(s2-1)) && !(*(s2-1) == '*')) + s2--; + + if (s2 == line) + exitfileerror(20, "No type specifier before %s name\n", isattribute ? "attribute" : "function"); + + if (*funclistptr != NULL) + funclistptr = &((*funclistptr)->next); + *funclistptr = newfunctionhead(s2, STACK); + + if (cp) + (*funclistptr)->comment = strdup(cp); + else + (*funclistptr)->comment = NULL; + + while (isspace(*(s2-1))) + s2--; + *s2 = '\0'; + (*funclistptr)->type = strdup(line); + (*funclistptr)->lvo = lvo; + (*funclistptr)->version = minversion; + lvo++; + + if (isattribute) + continue; + + /* Parse function prototype */ + s++; + while (isspace(*s)) + s++; + c = *s; + + while (c != ')') + { + while (isspace(*s)) + s++; + + args[argcount] = s; + argcount++; + + while + ( + *s != '\0' + && !(brcount == 0 && (*s == ',' || *s == ')')) + ) + { + if (*s == '(') + brcount++; + if (*s == ')') + { + if (brcount > 0) + brcount--; + else + exitfileerror(20, "Unexected ')' at position %d\n", s-line+1); + } + s++; + } + + c = *s; + if (c == '\0') + exitfileerror(20, "'(' without ')'"); + + s2 = s; + while (isspace(*(s2-1))) + s2--; + *s2 = '\0'; + + if (!(s2 > args[argcount - 1])) + exitfileerror(20, "Syntax error in function prototype\n"); + + s++; + } + + s++; + while (*s != '\0' && isspace(*s)) + s++; + + if (*s == '(') + { + /* Parse registers specifications if available otherwise this prototype for C type argument passing */ + + /* There may be no register specified with () so be sure then c is == ')' */ + s++; + while(isspace(*s)) + s++; + + c = *s; + + while (c != ')') + { + while (isspace(*s)) + s++; + + regs[regcount] = s; + regcount++; + + if (memchr("AD",s[0],2)!=NULL && memchr("01234567",s[1],8)!=NULL) + { + s += 2; + c = *s; + if (c == '/') + { + s++; + if (s[0] == s[-3] && s[1] == s[-2] + 1) + { + s += 2; + c = *s; + } + else + exitfileerror(20, + "wrong register specification \"%s\" for argument %u\n", + regs[regcount-1], regcount + ); + + if (regcount > 4) + exitfileerror(20, "maximum four arguments passed in two registers allowed (%d, %s) \n", regcount, regs[regcount-1]); + } + *s = '\0'; + } + else + exitfileerror(20, + "wrong register \"%s\" for argument %u\n", + regs[regcount-1], regcount + ); + + while (isspace(c)) + { + s++; + c = *s; + } + if (c == '\0') + exitfileerror(20, "'(' without ')'\n"); + if (c != ',' && c != ')') + exitfileerror(20, "',' or ')' expected at position %d\n", s-line+1); + + s++; + } + + s++; + while (isspace(*s)) s++; + if (*s!='\0') + exitfileerror(20, "wrong char '%c' at position %d\n", *s, (int)(s-line) + 1); + + if (argcount != regcount) + exitfileerror(20, "Number of arguments (%d) and registers (%d) mismatch\n", + argcount, regcount + ); + + (*funclistptr)->libcall = def_libcall; + for (i = 0; i < argcount; i++) + funcaddarg(*funclistptr, args[i], regs[i]); + } + else if (*s == '\0') + { /* No registers specified */ + for (i = 0; i < argcount; i++) + funcaddarg(*funclistptr, args[i], NULL); + } + else + exitfileerror(20, "wrong char '%c' at position %d\n", *s, (int)(s-line) + 1); + } + } +} + +static void readsectionclass_methodlist(struct classinfo *cl) +{ + int atend = 0, i; + char *line, *s, *s2; + struct functionhead **methlistptr = &cl->methlist; + struct stringlist *interface = NULL; + + if (cl->basename==NULL) + exitfileerror(20, "section methodlist has to come after section config\n"); + + while (!atend) + { + line = readline(); + if (line==NULL) + exitfileerror(20, "unexptected EOF in methodlist section\n"); + + /* Ignore empty lines or lines that qre a comment, e.g. that starts with a # */ + if (strlen(line)==0 || (line[0] == '#' && line[1] != '#')) + continue; + + if (isspace(*line)) + exitfileerror(20, "No space allowed at start of the line\n"); + + if (strncmp(line, "##", 2)==0) /* Is this the end ? */ + { + s = line+2; + while (isspace(*s)) s++; + if (strncmp(s, "end", 3)!=0) + exitfileerror(20, "\"##end methodlist\" expected\n"); + + s += 3; + while (isspace(*s)) s++; + if (strncmp(s, "methodlist", 10)!=0) + exitfileerror(20, "\"##end methodlist\" expected\n"); + + s += 10; + while (isspace(*s)) s++; + if (*s!='\0') + exitfileerror(20, "unexpected character on position %d\n", s-line); + + atend = 1; + + continue; + } + + if (*line=='.') + { + s = line+1; + if (strncmp(s, "alias", 5)==0) + { + s += 5; + + if (!isspace(*s)) + exitfileerror(20, "syntax is '.alias name'\n"); + + while (isspace(*s)) s++; + if (*s == '\0' || !(isalpha(*s) || *s == '_')) + exitfileerror(20, "syntax is '.alias name'\n"); + + s2 = s; + s++; + while (isalnum(*s) || *s == '_') s++; + + if (isspace(*s)) + { + *s = '\0'; + do { + s++; + } while (isspace(*s)); + } + + if (*s != '\0') + exitfileerror(20, "syntax is '.alias name'\n"); + + if (*methlistptr == NULL) + exitfileerror(20, ".alias has to come after a function declaration\n"); + + slist_append(&(*methlistptr)->aliases, s2); + } + else if (strncmp(s, "function", 8) == 0) + { + s += 8; + + if (!isspace(*s)) + exitfileerror(20, "Syntax error\n"); + + while (isspace(*s)) s++; + if (*s == '\0' || !(isalpha(*s) || *s == '_')) + exitfileerror(20, "syntax is '.function name'\n"); + + s2 = s; + s++; + while (isalnum(*s) || *s == '_') s++; + + if (isspace(*s)) + { + *s = '\0'; + do { + s++; + } while (isspace(*s)); + } + + if (*s != '\0') + exitfileerror(20, "syntax is '.function name'\n"); + + if (*methlistptr == NULL) + exitfileerror(20, ".function has to come after a function declaration\n"); + + funcsetinternalname(*methlistptr, s2); + } + else if (strncmp(s, "interface", 9) == 0) + { + if (cl->classtype != HIDD) + exitfileerror(20, "interface only valid for a HIDD\n"); + + s += 9; + + if (!isspace(*s)) + exitfileerror(20, "Syntax error\n"); + + while (isspace(*s)) s++; + if (*s == '\0' || !isalpha(*s)) + exitfileerror(20, "syntax is '.interface name'\n"); + + s2 = s; + s++; + while (isalnum(*s) || *s == '_') s++; + + if (isspace(*s)) + { + *s = '\0'; + do { + s++; + } while (isspace(*s)); + } + + if (*s != '\0') + exitfileerror(20, "syntax is '.interface name'\n"); + + interface = slist_append(&cl->interfaces, s2); + } + else + exitfileerror(20, "Syntax error"); + } + else if (isalpha(*line)) + { + char stmp[256]; + + for (s = line + 1; isalnum(*s) || *s == '_'; s++) + ; + + if (cl->classtype == HIDD && interface == NULL) + exitfileerror(20, "For a HIDD the first method has to come after an .interface line\n"); + + if (*s != '\0') + exitfileerror(20, "Only letters, digits and an underscore allowed in a methodname\n"); + + if (*methlistptr != NULL) + methlistptr = &((*methlistptr)->next); + if (cl->classtype != HIDD) + { + if (snprintf(stmp, 256, "%s__%s", cl->basename, line) >= 256) + exitfileerror(20, "Method name too large\n"); + + *methlistptr = newfunctionhead(stmp, STACK); + (*methlistptr)->type = "IPTR"; + funcaddarg(*methlistptr, "Class *cl", NULL); + funcaddarg(*methlistptr, "Object *o", NULL); + funcaddarg(*methlistptr, "Msg msg", NULL); + } + else + { + if (snprintf(stmp, 256, "%s__%s__%s", cl->basename, interface->s, line) >= 256) + exitfileerror(20, "Method name too large\n"); + + *methlistptr = newfunctionhead(stmp, STACK); + (*methlistptr)->type = "IPTR"; + funcaddarg(*methlistptr, "OOP_Class *cl", NULL); + funcaddarg(*methlistptr, "OOP_Object *o", NULL); + funcaddarg(*methlistptr, "OOP_Msg msg", NULL); + (*methlistptr)->interface = interface; + if (snprintf(stmp, 256, "mo%s_%s", interface->s, line) >= 256) + exitfileerror(20, "Method name too large\n"); + (*methlistptr)->method = strdup(stmp); + } + slist_append(&(*methlistptr)->aliases, line); + } + else + exitfileerror(20, "Methodname has to begin with a letter\n"); + } +} + +static void +readsectioninterface(struct config *cfg) +{ + char *s; + struct interfaceinfo *in; + + in = newinterface(cfg); + s = readsections(cfg, NULL, in, 1); + if (s == NULL) + exitfileerror(20, "Unexpected end of file\n"); + + if (strncmp(s, "##", 2) != 0) + exitfileerror(20, "'##end interface' expected\n"); + s += 2; + + while (isspace(*s)) s++; + + if (strncmp(s, "end", 3) != 0) + exitfileerror(20, "'##end interface' expected\n"); + s += 3; + + if (!isspace(*s)) + exitfileerror(20, "'##end interface' expected\n"); + while (isspace(*s)) s++; + + if (strncmp(s, "interface", 9) != 0) + exitfileerror(20, "'##end interface' expected\n"); + s += 9; + + while (isspace(*s)) s++; + if (*s != '\0') + exitfileerror(20, "'##end interface' expected\n"); + + if (!in->interfaceid) + exitfileerror(20, "interface has no 'interfaceid' defined!\n"); + + if (!in->interfacename) + exitfileerror(20, "interface has no 'interfacename' defined!\n"); + + if (!in->methodstub) + in->methodstub = strdup(in->interfacename); + + if (!in->methodbase) { + int len = strlen(in->interfacename); + in->methodbase = malloc(len + 4 + 1); + strcpy(in->methodbase, in->interfacename); + strcat(in->methodbase, "Base"); + } + + if (!in->attributebase) { + int len = strlen(in->interfacename); + in->attributebase = malloc(len + 4 + 4 + 1); + strcpy(in->attributebase, in->interfacename); + strcat(in->attributebase, "AttrBase"); + } +} + +static void +readsectionclass(struct config *cfg) +{ + char *s; + struct classinfo *cl; + + cl = newclass(cfg); + s = readsections(cfg, cl, NULL, 1); + if (s == NULL) + exitfileerror(20, "Unexpected end of file\n"); + + if (strncmp(s, "##", 2) != 0) + exitfileerror(20, "'##end class' expected\n"); + s += 2; + + while (isspace(*s)) s++; + + if (strncmp(s, "end", 3) != 0) + exitfileerror(20, "'##end class' expected\n"); + s += 3; + + if (!isspace(*s)) + exitfileerror(20, "'##end class' expected\n"); + while (isspace(*s)) s++; + + if (strncmp(s, "class", 5) != 0) + exitfileerror(20, "'##end class' expected\n"); + s += 5; + + while (isspace(*s)) s++; + if (*s != '\0') + exitfileerror(20, "'##end class' expected\n"); +} + +static struct classinfo *newclass(struct config *cfg) +{ + struct classinfo *cl, *classlistit; + + cl = malloc(sizeof(struct classinfo)); + if (cl == NULL) + { + fprintf(stderr, "Out of memory\n"); + exit(20); + } + memset(cl, 0, sizeof(struct classinfo)); + + /* By default the classes are initialized with a priority of 1 so they + * are initialized before any user added initialization with priority 1 + */ + cl->initpri = 1; + + if (cfg->classlist == NULL) + cfg->classlist = cl; + else + { + for + ( + classlistit = cfg->classlist; + classlistit->next != NULL; + classlistit = classlistit->next + ) + ; + classlistit->next = cl; + } + + return cl; +} + +static struct handlerinfo *newhandler(struct config *cfg) +{ + struct handlerinfo *hl; + + hl = calloc(1,sizeof(*hl)); + hl->next = cfg->handlerlist; + cfg->handlerlist = hl; + return hl; +} + +static struct interfaceinfo *newinterface(struct config *cfg) +{ + struct interfaceinfo *in, *interfacelistit; + + in = malloc(sizeof(struct interfaceinfo)); + if (in == NULL) + { + fprintf(stderr, "Out of memory\n"); + exit(20); + } + memset(in, 0, sizeof(struct interfaceinfo)); + + if (cfg->interfacelist == NULL) + cfg->interfacelist = in; + else + { + for + ( + interfacelistit = cfg->interfacelist; + interfacelistit->next != NULL; + interfacelistit = interfacelistit->next + ) + ; + interfacelistit->next = in; + } + + return in; +} + + +static int getdirective(char *s, const char *directive, int range_min, int range_max, int *val) +{ + char *tmp; + int newval; + + if (strncmp(s, directive, strlen(directive)) != 0) + return 0; + + s += strlen(directive); + if (*s && !isspace(*s)) + exitfileerror(20, "Unrecognized directive \".%s\"\n", directive); + + while (isspace(*s)) s++; + if (!*s) + exitfileerror(20, "No .%s value specified\n", directive); + + newval = strtol(s, &tmp, 0); + if (s == tmp || !(newval >= range_min && newval <= range_max)) { + tmp = s; + while (*tmp && !isspace(*tmp)) tmp++; + exitfileerror(20, "Invalid .%s value of %.*s\n", directive, tmp - s, s); + } + + *val = newval; + return 1; +} + +static void +readsectionhandler(struct config *cfg) +{ + char *line = NULL, *s; + struct handlerinfo *hl; + unsigned char autolevel = 0; + unsigned int stacksize = 0; + int startup = 0; + char priority = 10; + int bootpri = -128; + int has_filesystem = 0; + + for (;;) + { + char *function; + int function_len; + char *tmp; + + s = line = readline(); + + if (s==NULL) + exitfileerror(20, "unexpected end of file in section hanlder\n"); + + if (strncmp(s, "##", 2)==0) + break; + + /* Ignore comments */ + if (strncmp(s, "#", 1)==0) + continue; + + /* Skip ahead to function name */ + while (*s && isspace(*s)) s++; + + /* Permit blank lines */ + if (!*s) + continue; + + if (*s == '.') { + int val; + s++; + + if (getdirective(s, "autodetect", 0, 127, &val)) { + autolevel = val; + } else if (getdirective(s, "stacksize", 0, INT_MAX, &val)) { + stacksize = val; + } else if (getdirective(s, "priority", -128, 127, &val)) { + priority = val; + } else if (getdirective(s, "bootpri", -128, 127, &val)) { + bootpri = val; + } else if (getdirective(s, "startup", INT_MIN, INT_MAX, &val)) { + startup = val; + } else { + exitfileerror(20, "Unrecognized directive \"%s\"\n", line); + } + continue; + } + + do { + unsigned int id = 0; + + if (strncasecmp(s,"resident=",9)==0) { + char *res; + + s = strchr(s, '=') + 1; + res = s; + while (*s && !isspace(*s)) s++; + if (res == s) + exitfileerror(20, "Empty resident= is not permitted\n"); + + if (*s) + *(s++) = 0; + + hl = newhandler(cfg); + hl->type = HANDLER_RESIDENT; + hl->id = 0; + hl->name = strdup(res); + hl->autodetect = autolevel--; + hl->stacksize = stacksize; + hl->priority = priority; + hl->startup = startup; + } else if (strncasecmp(s,"dosnode=",8)==0) { + char *dev; + + s = strchr(s, '=') + 1; + dev = s; + while (*s && !isspace(*s)) s++; + if (dev == s) + exitfileerror(20, "Empty dosnode= is not permitted\n"); + + if (*s) + *(s++) = 0; + + hl = newhandler(cfg); + hl->type = HANDLER_DOSNODE; + hl->id = 0; + hl->name = strdup(dev); + hl->autodetect = autolevel ? autolevel-- : 0; + hl->stacksize = stacksize; + hl->priority = priority; + hl->startup = startup; + hl->bootpri = bootpri; + } else if (strncasecmp(s,"dostype=",8) == 0) { + s = strchr(s, '=') + 1; + + id = (unsigned int)strtoul(s, &tmp, 0); + + if (s == tmp) { + while (*tmp && !isspace(*tmp)) + tmp++; + exitfileerror(20, "\"%.*s\" is not a numerical DOS ID\n", (tmp -s), s); + } + s = tmp; + + if (id == 0 || id == ~0) { + exitfileerror(20, "DOS ID 0x%08x is not permitted\n", id); + } + + hl = newhandler(cfg); + hl->type = HANDLER_DOSTYPE; + hl->id = id; + hl->name = NULL; + hl->autodetect = autolevel ? autolevel-- : 0; + hl->stacksize = stacksize; + hl->priority = priority; + hl->startup = startup; + } else { + for (tmp = s; !isspace(*tmp); tmp++); + exitfileerror(20, "Unknown option \"%.*s\"\n", tmp - s, s); + } + + /* Advance to next ID */ + while (*s && isspace(*s)) s++; + + } while (*s); + } + + if (s == NULL) + exitfileerror(20, "Unexpected end of file\n"); + + if (strncmp(s, "##", 2) != 0) + exitfileerror(20, "'##end handler' expected\n"); + s += 2; + + while (isspace(*s)) s++; + + if (strncmp(s, "end", 3) != 0) + exitfileerror(20, "'##end handler' expected\n"); + s += 3; + + while (isspace(*s)) s++; + + if (strncmp(s, "handler", 7) != 0) + exitfileerror(20, "'##end handler' expected\n"); + s += 7; + + while (isspace(*s)) s++; + if (*s != '\0') + exitfileerror(20, "'##end handler' expected\n"); +} + + diff --git a/tools/genmodule/config.h b/tools/genmodule/config.h index c5b4a6ce06..14f00f2c84 100644 --- a/tools/genmodule/config.h +++ b/tools/genmodule/config.h @@ -15,14 +15,14 @@ enum command { CMD_UNSPECIFIED, FILES, LIBDEFS, INCLUDES, MAKEFILE, WRITEFUNCLIST, WRITEFD, WRITESKEL }; enum modtype { UNSPECIFIED, LIBRARY, MCC, MUI, MCP, DEVICE, RESOURCE, IMAGE, GADGET, - DATATYPE, CLASS, HIDD, USBCLASS, HANDLER + DATATYPE, CLASS, HIDD, USBCLASS, HANDLER }; enum optionbit { BIT_NOAUTOLIB, BIT_NOEXPUNGE, BIT_NORESIDENT, - BIT_DUPBASE, BIT_PERTASKBASE, BIT_INCLUDES, BIT_NOINCLUDES, + BIT_DUPBASE, BIT_PERTASKBASE, BIT_INCLUDES, BIT_NOINCLUDES, BIT_STUBS, BIT_NOSTUBS, BIT_AUTOINIT, BIT_NOAUTOINIT, - BIT_RESAUTOINIT, BIT_NOOPENCLOSE, BIT_SELFINIT, - BIT_STACKCALL + BIT_RESAUTOINIT, BIT_NOOPENCLOSE, BIT_SELFINIT, + BIT_STACKCALL }; enum optionflags { @@ -67,13 +67,13 @@ struct classinfo /* Additional options for the class */ enum coptionflags options; - + const char **boopsimprefix; char *classid, *superclass, *superclass_field, *classptr_field, *classptr_var; char *dispatcher; /* == NULL when the generated dispatcher is used, - * otherwise it is the function name of the dispatcher */; + * otherwise it is the function name of the dispatcher */; char *classdatatype; /* The type of the data for every object */ - + struct functionhead *methlist; /* Interfaces used in this class (only for HIDD classes) */ @@ -92,7 +92,7 @@ struct interfaceinfo char *methodstub; char *methodbase; char *attributebase; - + struct functionhead *methodlist; struct functionhead *attributelist; }; @@ -127,10 +127,10 @@ struct config enum modtype modtype; char *modtypestr; char *suffix; - + /* Extra string to include in version */ char *versionextra; - + /* firstlvo is the LVO number of the first user definable function * in the module */ @@ -145,7 +145,7 @@ struct config /* The default path to put the module relative to SYS: */ char *moddir; - + /* The names of the fields in the custom library base for storing internal * information */ @@ -162,7 +162,7 @@ struct config int residentpri; unsigned int majorversion, minorversion; char *addromtag; - + /* In forcelist a list of basenames is present that need to be present in the * static link library so that certain libraries are opened by a program */ @@ -176,7 +176,7 @@ struct config /* The functions of this module */ struct functionhead *funclist; - + /* The classes defined in this module */ struct classinfo *classlist; diff --git a/tools/genmodule/dtsupport.c b/tools/genmodule/dtsupport.c index 6ff9253016..3cfc512b3d 100644 --- a/tools/genmodule/dtsupport.c +++ b/tools/genmodule/dtsupport.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2005, The AROS Development Team. All rights reserved. $Id$ - + Functions to support datatypes. Part of genmodule. */ #include diff --git a/tools/genmodule/fileread.c b/tools/genmodule/fileread.c index 869cc085e9..e240734b43 100644 --- a/tools/genmodule/fileread.c +++ b/tools/genmodule/fileread.c @@ -18,16 +18,16 @@ int fileopen(const char *fname) { if (file!=NULL) { - fclose(file); - free(filename); - file = NULL; - filename = NULL; - lineno = 0; + fclose(file); + free(filename); + file = NULL; + filename = NULL; + lineno = 0; } file = fopen(fname, "r"); if (file!=NULL) - filename = strdup(fname); - + filename = strdup(fname); + return file!=NULL; } @@ -35,10 +35,10 @@ void fileclose(void) { if (file!=NULL) { - fclose(file); - free(filename); - file = NULL; - filename = NULL; + fclose(file); + free(filename); + file = NULL; + filename = NULL; } } @@ -47,24 +47,24 @@ char *readline(void) char haseol; if (file==NULL || feof(file)) - return NULL; + return NULL; if (slen==0) { - slen = 256; - line = malloc(slen); + slen = 256; + line = malloc(slen); } if (fgets(line, slen, file)) { size_t len = strlen(line); - haseol = line[len-1]=='\n'; - if (haseol) line[len-1]='\0'; - - while (!(haseol || feof(file))) - { - slen += 256; - line = (char *)realloc(line, slen); - if (fgets(line+len, slen, file)) + haseol = line[len-1]=='\n'; + if (haseol) line[len-1]='\0'; + + while (!(haseol || feof(file))) + { + slen += 256; + line = (char *)realloc(line, slen); + if (fgets(line+len, slen, file)) { len = strlen(line); haseol = line[len-1]=='\n'; @@ -76,12 +76,12 @@ char *readline(void) free(line); return NULL; } - } + } } else - line[0]='\0'; + line[0]='\0'; lineno++; - + return line; } @@ -90,7 +90,7 @@ void filewarning(const char *format, ...) va_list ap; fprintf(stderr, "%s:%d:warning ", filename, lineno); - + va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); @@ -99,12 +99,12 @@ void filewarning(const char *format, ...) void exitfileerror(int code, const char *format, ...) { va_list ap; - + fprintf(stderr, "%s:%d:error ", filename, lineno); - + va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); - + exit(code); } diff --git a/tools/genmodule/functionhead.c b/tools/genmodule/functionhead.c dissimilarity index 62% index fcad7383de..827b494bd6 100644 --- a/tools/genmodule/functionhead.c +++ b/tools/genmodule/functionhead.c @@ -1,507 +1,507 @@ -/* - Copyright © 1995-2012, The AROS Development Team. All rights reserved. - $Id$ - - The code for storing information of functions present in the module -*/ -#include -#include -#include "functionhead.h" -#include "config.h" - -struct functionhead *newfunctionhead(const char *name, enum libcall libcall) -{ - struct functionhead *funchead = malloc(sizeof(struct functionhead)); - - if (funchead != NULL) - { - funchead->next = NULL; - funchead->internalname = funchead->name = strdup(name); - funchead->type = NULL; - funchead->libcall = libcall; - funchead->lvo = 0; - funchead->argcount = 0; - funchead->arguments = NULL; - funchead->aliases = NULL; - funchead->interface = NULL; - funchead->method = NULL; - funchead->novararg = 0; - funchead->priv= 0; - funchead->unusedlibbase = 0; - } - else - { - puts("Out of memory !"); - exit(20); - } - - return funchead; -} - -struct functionarg *funcaddarg -( - struct functionhead *funchead, - const char *arg, const char *reg -) -{ - struct functionarg **argptr = &funchead->arguments; - - while ((*argptr) != NULL) argptr = &(*argptr)->next; - - *argptr = malloc(sizeof(struct functionarg)); - if (*argptr != NULL) - { - (*argptr)->next = NULL; - (*argptr)->arg = (arg == NULL) ? NULL : strdup(arg); - (*argptr)->reg = (reg == NULL) ? NULL : strdup(reg); - - funchead->argcount++; - } - else - { - puts("Out of memory !"); - exit(20); - } - - return *argptr; -} - -struct stringlist *funcaddalias(struct functionhead *funchead, const char *alias) -{ - return slist_append(&funchead->aliases, alias); -} - -void funcsetinternalname(struct functionhead *funchead, const char *internalname) -{ - if (funchead->name != funchead->internalname) - free(funchead->internalname); - funchead->internalname = strdup(internalname); -} - -void writefuncdefs(FILE *out, struct config *cfg, struct functionhead *funclist) -{ - struct functionhead *funclistit; - struct functionarg *arglistit; - char *type, *name; - int first; - - for(funclistit = funclist; funclistit != NULL; funclistit = funclistit->next) - { - switch (funclistit->libcall) - { - case STACK: - fprintf(out, "%s %s(", funclistit->type, funclistit->internalname); - - for(arglistit = funclistit->arguments, first = 1; - arglistit != NULL; - arglistit = arglistit->next, first = 0 - ) - { - if (!first) - fprintf(out, ", "); - - fprintf(out, "%s", arglistit->arg); - } - fprintf(out, ");\n"); - break; - - case REGISTER: - assert(cfg); - fprintf(out, "%s %s(", funclistit->type, funclistit->internalname); - for (arglistit = funclistit->arguments, first = 1; - arglistit!=NULL; - arglistit = arglistit->next, first = 0 - ) - { - if (!first) - fprintf(out, ", "); - fprintf(out, "%s", arglistit->arg); - } - fprintf(out, - ");\nAROS_LH%d%s(%s, %s,\n", - funclistit->argcount, funclistit->unusedlibbase ? "I" : "", - funclistit->type, funclistit->internalname - ); - for (arglistit = funclistit->arguments; - arglistit!=NULL; - arglistit = arglistit->next - ) - { - type = getargtype(arglistit); - name = getargname(arglistit); - assert(name != NULL && type != NULL); - - fprintf(out, - " AROS_LHA(%s, %s, %s),\n", - type, name, arglistit->reg - ); - free(type); - free(name); - } - fprintf(out, - " %s, %s, %u, %s)\n" - "{\n" - " AROS_LIBFUNC_INIT\n\n" - " %s%s(", - cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename, - (strcasecmp(funclistit->type, "void") == 0) ? "" : "return ", - funclistit->internalname - ); - for (arglistit = funclistit->arguments, first = 1; - arglistit!=NULL; - arglistit = arglistit->next, first = 0 - ) - { - name = getargname(arglistit); - assert(name != NULL); - - if (!first) - fprintf(out, ", "); - fprintf(out, "%s", name); - free(name); - } - fprintf(out, - ");\n\n" - " AROS_LIBFUNC_EXIT\n" - "}\n\n"); - break; - - case REGISTERMACRO: - assert(cfg); - if (funclistit->arguments == NULL - || strchr(funclistit->arguments->reg, '/') == NULL) - { - fprintf(out, - "AROS_LD%d%s(%s, %s,\n", - funclistit->argcount, funclistit->unusedlibbase ? "I" : "", - funclistit->type, funclistit->internalname - ); - for (arglistit = funclistit->arguments; - arglistit!=NULL; - arglistit = arglistit->next - ) - { - type = getargtype(arglistit); - name = getargname(arglistit); - assert(type != NULL && name != NULL); - - fprintf(out, - " AROS_LDA(%s, %s, %s),\n", - type, name, arglistit->reg - ); - free(type); - free(name); - } - fprintf(out, - " LIBBASETYPEPTR, %s, %u, %s\n" - ");\n", - cfg->libbase, funclistit->lvo, cfg->basename - ); - } - else - { - fprintf(out, - "AROS_LDQUAD%d(%s, %s,\n", - funclistit->argcount, funclistit->type, funclistit->internalname - ); - for (arglistit = funclistit->arguments; - arglistit != NULL; - arglistit = arglistit->next - ) - { - if (strlen(arglistit->reg) != 5) - { - fprintf(stderr, "Internal error: ../.. register format expected\n"); - exit(20); - } - arglistit->reg[2] = 0; - - type = getargtype(arglistit); - name = getargname(arglistit); - assert(type != NULL && name != NULL); - - fprintf(out, - " AROS_LDAQUAD(%s, %s, %s, %s),\n", - type, name, arglistit->reg, arglistit->reg+3 - ); - arglistit->reg[2] = '/'; - free(type); - free(name); - } - fprintf(out, - " LIBBASETYPEPTR, %s, %u, %s\n" - ");\n", - cfg->libbase, funclistit->lvo, cfg->basename - ); - } - break; - - default: - fprintf(stderr, "Internal error: unhandled libcall in writefuncdefs\n"); - exit(20); - break; - } - } -} - -void writefuncprotos(FILE *out, struct config *cfg, struct functionhead *funclist) -{ - struct functionhead *funclistit; - struct functionarg *arglistit; - char *type, *name; - int first; - - for(funclistit = funclist; funclistit != NULL; funclistit = funclistit->next) - { - fprintf(out, - "\n" - "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)" - "\n", - cfg->modulenameupper, - funclistit->version, - cfg->modulenameupper - ); - - switch (funclistit->libcall) - { - case STACK: - fprintf( - out, - "#ifndef %s\n" - "%s %s(", - funclistit->name, - funclistit->type, funclistit->name - ); - - for(arglistit = funclistit->arguments, first = 1; - arglistit != NULL; - arglistit = arglistit->next, first = 0 - ) - { - if (!first) - fprintf(out, ", "); - - fprintf(out, "%s", arglistit->arg); - } - fprintf(out, ");\n#endif\n"); - break; - - case REGISTER: - case REGISTERMACRO: - assert(cfg); - if (funclistit->priv || funclistit->lvo < cfg->firstlvo) { - fprintf(out, "/* private */\n"); - break; - } - - if (funclistit->arguments == NULL - || strchr(funclistit->arguments->reg, '/') == NULL - ) - { - fprintf(out, - "AROS_LP%d%s(%s, %s,\n", - funclistit->argcount, funclistit->unusedlibbase ? "I" : "", - funclistit->type, funclistit->name - ); - for (arglistit = funclistit->arguments; - arglistit!=NULL; - arglistit = arglistit->next - ) - { - type = getargtype(arglistit); - name = getargname(arglistit); - assert(type != NULL && name != NULL); - - fprintf(out, - " AROS_LPA(%s, %s, %s),\n", - type, name, arglistit->reg - ); - free(type); - free(name); - } - fprintf(out, - " LIBBASETYPEPTR, %s, %u, %s\n" - ");\n", - cfg->libbase, funclistit->lvo, cfg->basename - ); - } - else - { - fprintf(out, - "AROS_LPQUAD%d(%s, %s,\n", - funclistit->argcount, funclistit->type, funclistit->name - ); - for (arglistit = funclistit->arguments; - arglistit != NULL; - arglistit = arglistit->next - ) - { - if (strlen(arglistit->reg) != 5) - { - fprintf(stderr, "Internal error: ../.. register format expected\n"); - exit(20); - } - arglistit->reg[2] = 0; - - type = getargtype(arglistit); - name = getargname(arglistit); - assert(type != NULL && name != NULL); - - fprintf(out, - " AROS_LPAQUAD(%s, %s, %s, %s),\n", - type, name, arglistit->reg, arglistit->reg+3 - ); - arglistit->reg[2] = '/'; - free(type); - free(name); - } - fprintf(out, - " LIBBASETYPEPTR, %s, %u, %s\n" - ");\n", - cfg->libbase, funclistit->lvo, cfg->basename - ); - } - break; - - default: - fprintf(stderr, "Internal error: unhandled libcall in writefuncdefs\n"); - exit(20); - break; - } - - fprintf(out, - "\n" - "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */" - "\n", - cfg->modulenameupper, - funclistit->version, - cfg->modulenameupper - ); - } -} - -void writefuncinternalstubs(FILE *out, struct config *cfg, struct functionhead *funclist) -{ - struct functionhead *funclistit; - struct functionarg *arglistit; - char *type, *name; - int first; - - for(funclistit = funclist; funclistit != NULL; funclistit = funclistit->next) - { - switch (funclistit->libcall) - { - case STACK: - if ((cfg->options & OPTION_DUPBASE) - && !funclistit->unusedlibbase - ) - { - fprintf(out, - "AROS_GM_STACKCALL(%s,%s,%d);\n" - , funclistit->internalname - , cfg->basename - , funclistit->lvo - ); - } - else - { - fprintf(out, - "AROS_GM_STACKALIAS(%s,%s,%d);\n" - , funclistit->internalname - , cfg->basename - , funclistit->lvo - ); - } - break; - - case REGISTER: - case REGISTERMACRO: - /* NOP */ - break; - - default: - fprintf(stderr, "Internal error: unhandled libcall in writefuncdefs\n"); - exit(20); - break; - } - } -} - -char *getargtype(const struct functionarg *funcarg) -{ - char *s, *begin, *end; - unsigned int brackets = 0, i; - - begin = s = strdup(funcarg->arg); - - /* Count the [] at the end of the argument */ - end = begin+strlen(begin); - while (isspace(*(end-1))) end--; - while (*(end-1)==']') - { - brackets++; - end--; - while (isspace(*(end-1)) || isdigit(*(end-1))) end--; - if (*(end-1)!='[') - { - free(s); - return NULL; - } - end--; - while (isspace(*(end-1))) end--; - } - - /* Skip over the argument name */ - while (!isspace(*(end-1)) && *(end-1)!='*') - { - if (begin == end) - { - free(s); - fprintf(stderr, "no argument type or name found for arg: %s\n", funcarg->arg); - exit(20); - } - end--; - } - - /* Add * for the brackets */ - while (isspace(*(end-1))) end--; - for (i=0; iarg+strlen(funcarg->arg); - while (isspace(*(end-1))) end--; - while (*(end-1)==']') - { - end--; - while (isspace(*(end-1))) end--; - if (*(end-1)!='[') - return NULL; - end--; - while (isspace(*(end-1))) end--; - } - - /* Go to the beginning of the argument name */ - begin = end; - while (!isspace(*(begin-1)) && *(begin-1)!='*') begin--; - - /* Copy the name */ - len = end - begin; - s = malloc(len+1); - strncpy(s, begin, len); - s[len] = '\0'; - - return s; -} +/* + Copyright © 1995-2012, The AROS Development Team. All rights reserved. + $Id$ + + The code for storing information of functions present in the module +*/ +#include +#include +#include "functionhead.h" +#include "config.h" + +struct functionhead *newfunctionhead(const char *name, enum libcall libcall) +{ + struct functionhead *funchead = malloc(sizeof(struct functionhead)); + + if (funchead != NULL) + { + funchead->next = NULL; + funchead->internalname = funchead->name = strdup(name); + funchead->type = NULL; + funchead->libcall = libcall; + funchead->lvo = 0; + funchead->argcount = 0; + funchead->arguments = NULL; + funchead->aliases = NULL; + funchead->interface = NULL; + funchead->method = NULL; + funchead->novararg = 0; + funchead->priv= 0; + funchead->unusedlibbase = 0; + } + else + { + puts("Out of memory !"); + exit(20); + } + + return funchead; +} + +struct functionarg *funcaddarg +( + struct functionhead *funchead, + const char *arg, const char *reg +) +{ + struct functionarg **argptr = &funchead->arguments; + + while ((*argptr) != NULL) argptr = &(*argptr)->next; + + *argptr = malloc(sizeof(struct functionarg)); + if (*argptr != NULL) + { + (*argptr)->next = NULL; + (*argptr)->arg = (arg == NULL) ? NULL : strdup(arg); + (*argptr)->reg = (reg == NULL) ? NULL : strdup(reg); + + funchead->argcount++; + } + else + { + puts("Out of memory !"); + exit(20); + } + + return *argptr; +} + +struct stringlist *funcaddalias(struct functionhead *funchead, const char *alias) +{ + return slist_append(&funchead->aliases, alias); +} + +void funcsetinternalname(struct functionhead *funchead, const char *internalname) +{ + if (funchead->name != funchead->internalname) + free(funchead->internalname); + funchead->internalname = strdup(internalname); +} + +void writefuncdefs(FILE *out, struct config *cfg, struct functionhead *funclist) +{ + struct functionhead *funclistit; + struct functionarg *arglistit; + char *type, *name; + int first; + + for(funclistit = funclist; funclistit != NULL; funclistit = funclistit->next) + { + switch (funclistit->libcall) + { + case STACK: + fprintf(out, "%s %s(", funclistit->type, funclistit->internalname); + + for(arglistit = funclistit->arguments, first = 1; + arglistit != NULL; + arglistit = arglistit->next, first = 0 + ) + { + if (!first) + fprintf(out, ", "); + + fprintf(out, "%s", arglistit->arg); + } + fprintf(out, ");\n"); + break; + + case REGISTER: + assert(cfg); + fprintf(out, "%s %s(", funclistit->type, funclistit->internalname); + for (arglistit = funclistit->arguments, first = 1; + arglistit!=NULL; + arglistit = arglistit->next, first = 0 + ) + { + if (!first) + fprintf(out, ", "); + fprintf(out, "%s", arglistit->arg); + } + fprintf(out, + ");\nAROS_LH%d%s(%s, %s,\n", + funclistit->argcount, funclistit->unusedlibbase ? "I" : "", + funclistit->type, funclistit->internalname + ); + for (arglistit = funclistit->arguments; + arglistit!=NULL; + arglistit = arglistit->next + ) + { + type = getargtype(arglistit); + name = getargname(arglistit); + assert(name != NULL && type != NULL); + + fprintf(out, + " AROS_LHA(%s, %s, %s),\n", + type, name, arglistit->reg + ); + free(type); + free(name); + } + fprintf(out, + " %s, %s, %u, %s)\n" + "{\n" + " AROS_LIBFUNC_INIT\n\n" + " %s%s(", + cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename, + (strcasecmp(funclistit->type, "void") == 0) ? "" : "return ", + funclistit->internalname + ); + for (arglistit = funclistit->arguments, first = 1; + arglistit!=NULL; + arglistit = arglistit->next, first = 0 + ) + { + name = getargname(arglistit); + assert(name != NULL); + + if (!first) + fprintf(out, ", "); + fprintf(out, "%s", name); + free(name); + } + fprintf(out, + ");\n\n" + " AROS_LIBFUNC_EXIT\n" + "}\n\n"); + break; + + case REGISTERMACRO: + assert(cfg); + if (funclistit->arguments == NULL + || strchr(funclistit->arguments->reg, '/') == NULL) + { + fprintf(out, + "AROS_LD%d%s(%s, %s,\n", + funclistit->argcount, funclistit->unusedlibbase ? "I" : "", + funclistit->type, funclistit->internalname + ); + for (arglistit = funclistit->arguments; + arglistit!=NULL; + arglistit = arglistit->next + ) + { + type = getargtype(arglistit); + name = getargname(arglistit); + assert(type != NULL && name != NULL); + + fprintf(out, + " AROS_LDA(%s, %s, %s),\n", + type, name, arglistit->reg + ); + free(type); + free(name); + } + fprintf(out, + " LIBBASETYPEPTR, %s, %u, %s\n" + ");\n", + cfg->libbase, funclistit->lvo, cfg->basename + ); + } + else + { + fprintf(out, + "AROS_LDQUAD%d(%s, %s,\n", + funclistit->argcount, funclistit->type, funclistit->internalname + ); + for (arglistit = funclistit->arguments; + arglistit != NULL; + arglistit = arglistit->next + ) + { + if (strlen(arglistit->reg) != 5) + { + fprintf(stderr, "Internal error: ../.. register format expected\n"); + exit(20); + } + arglistit->reg[2] = 0; + + type = getargtype(arglistit); + name = getargname(arglistit); + assert(type != NULL && name != NULL); + + fprintf(out, + " AROS_LDAQUAD(%s, %s, %s, %s),\n", + type, name, arglistit->reg, arglistit->reg+3 + ); + arglistit->reg[2] = '/'; + free(type); + free(name); + } + fprintf(out, + " LIBBASETYPEPTR, %s, %u, %s\n" + ");\n", + cfg->libbase, funclistit->lvo, cfg->basename + ); + } + break; + + default: + fprintf(stderr, "Internal error: unhandled libcall in writefuncdefs\n"); + exit(20); + break; + } + } +} + +void writefuncprotos(FILE *out, struct config *cfg, struct functionhead *funclist) +{ + struct functionhead *funclistit; + struct functionarg *arglistit; + char *type, *name; + int first; + + for(funclistit = funclist; funclistit != NULL; funclistit = funclistit->next) + { + fprintf(out, + "\n" + "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)" + "\n", + cfg->modulenameupper, + funclistit->version, + cfg->modulenameupper + ); + + switch (funclistit->libcall) + { + case STACK: + fprintf( + out, + "#ifndef %s\n" + "%s %s(", + funclistit->name, + funclistit->type, funclistit->name + ); + + for(arglistit = funclistit->arguments, first = 1; + arglistit != NULL; + arglistit = arglistit->next, first = 0 + ) + { + if (!first) + fprintf(out, ", "); + + fprintf(out, "%s", arglistit->arg); + } + fprintf(out, ");\n#endif\n"); + break; + + case REGISTER: + case REGISTERMACRO: + assert(cfg); + if (funclistit->priv || funclistit->lvo < cfg->firstlvo) { + fprintf(out, "/* private */\n"); + break; + } + + if (funclistit->arguments == NULL + || strchr(funclistit->arguments->reg, '/') == NULL + ) + { + fprintf(out, + "AROS_LP%d%s(%s, %s,\n", + funclistit->argcount, funclistit->unusedlibbase ? "I" : "", + funclistit->type, funclistit->name + ); + for (arglistit = funclistit->arguments; + arglistit!=NULL; + arglistit = arglistit->next + ) + { + type = getargtype(arglistit); + name = getargname(arglistit); + assert(type != NULL && name != NULL); + + fprintf(out, + " AROS_LPA(%s, %s, %s),\n", + type, name, arglistit->reg + ); + free(type); + free(name); + } + fprintf(out, + " LIBBASETYPEPTR, %s, %u, %s\n" + ");\n", + cfg->libbase, funclistit->lvo, cfg->basename + ); + } + else + { + fprintf(out, + "AROS_LPQUAD%d(%s, %s,\n", + funclistit->argcount, funclistit->type, funclistit->name + ); + for (arglistit = funclistit->arguments; + arglistit != NULL; + arglistit = arglistit->next + ) + { + if (strlen(arglistit->reg) != 5) + { + fprintf(stderr, "Internal error: ../.. register format expected\n"); + exit(20); + } + arglistit->reg[2] = 0; + + type = getargtype(arglistit); + name = getargname(arglistit); + assert(type != NULL && name != NULL); + + fprintf(out, + " AROS_LPAQUAD(%s, %s, %s, %s),\n", + type, name, arglistit->reg, arglistit->reg+3 + ); + arglistit->reg[2] = '/'; + free(type); + free(name); + } + fprintf(out, + " LIBBASETYPEPTR, %s, %u, %s\n" + ");\n", + cfg->libbase, funclistit->lvo, cfg->basename + ); + } + break; + + default: + fprintf(stderr, "Internal error: unhandled libcall in writefuncdefs\n"); + exit(20); + break; + } + + fprintf(out, + "\n" + "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */" + "\n", + cfg->modulenameupper, + funclistit->version, + cfg->modulenameupper + ); + } +} + +void writefuncinternalstubs(FILE *out, struct config *cfg, struct functionhead *funclist) +{ + struct functionhead *funclistit; + struct functionarg *arglistit; + char *type, *name; + int first; + + for(funclistit = funclist; funclistit != NULL; funclistit = funclistit->next) + { + switch (funclistit->libcall) + { + case STACK: + if ((cfg->options & OPTION_DUPBASE) + && !funclistit->unusedlibbase + ) + { + fprintf(out, + "AROS_GM_STACKCALL(%s,%s,%d);\n" + , funclistit->internalname + , cfg->basename + , funclistit->lvo + ); + } + else + { + fprintf(out, + "AROS_GM_STACKALIAS(%s,%s,%d);\n" + , funclistit->internalname + , cfg->basename + , funclistit->lvo + ); + } + break; + + case REGISTER: + case REGISTERMACRO: + /* NOP */ + break; + + default: + fprintf(stderr, "Internal error: unhandled libcall in writefuncdefs\n"); + exit(20); + break; + } + } +} + +char *getargtype(const struct functionarg *funcarg) +{ + char *s, *begin, *end; + unsigned int brackets = 0, i; + + begin = s = strdup(funcarg->arg); + + /* Count the [] at the end of the argument */ + end = begin+strlen(begin); + while (isspace(*(end-1))) end--; + while (*(end-1)==']') + { + brackets++; + end--; + while (isspace(*(end-1)) || isdigit(*(end-1))) end--; + if (*(end-1)!='[') + { + free(s); + return NULL; + } + end--; + while (isspace(*(end-1))) end--; + } + + /* Skip over the argument name */ + while (!isspace(*(end-1)) && *(end-1)!='*') + { + if (begin == end) + { + free(s); + fprintf(stderr, "no argument type or name found for arg: %s\n", funcarg->arg); + exit(20); + } + end--; + } + + /* Add * for the brackets */ + while (isspace(*(end-1))) end--; + for (i=0; iarg+strlen(funcarg->arg); + while (isspace(*(end-1))) end--; + while (*(end-1)==']') + { + end--; + while (isspace(*(end-1))) end--; + if (*(end-1)!='[') + return NULL; + end--; + while (isspace(*(end-1))) end--; + } + + /* Go to the beginning of the argument name */ + begin = end; + while (!isspace(*(begin-1)) && *(begin-1)!='*') begin--; + + /* Copy the name */ + len = end - begin; + s = malloc(len+1); + strncpy(s, begin, len); + s[len] = '\0'; + + return s; +} diff --git a/tools/genmodule/genmodule.c b/tools/genmodule/genmodule.c index 9b8605a77c..6145e3fd2a 100644 --- a/tools/genmodule/genmodule.c +++ b/tools/genmodule/genmodule.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ - + Main for genmodule. A tool to generate files for building modules. */ #include "genmodule.h" @@ -14,12 +14,12 @@ int main(int argc, char **argv) switch (cfg->command) { case FILES: - writestart(cfg); - writeend(cfg); - if (cfg->options & OPTION_AUTOINIT) + writestart(cfg); + writeend(cfg); + if (cfg->options & OPTION_AUTOINIT) { - writeautoinit(cfg, 0); /* normal */ - writeautoinit(cfg, 1); /* relbase */ + writeautoinit(cfg, 0); /* normal */ + writeautoinit(cfg, 1); /* relbase */ } if (cfg->modtype == LIBRARY) { @@ -31,8 +31,8 @@ int main(int argc, char **argv) writestubs(cfg, 0); /* normal */ writestubs(cfg, 1); /* relbase */ } - break; - + break; + case INCLUDES: if (cfg->options & OPTION_INCLUDES) { @@ -43,39 +43,39 @@ int main(int argc, char **argv) } if (cfg->interfacelist) writeincinterfaces(cfg); - break; - + break; + case LIBDEFS: - writeinclibdefs(cfg); - break; + writeinclibdefs(cfg); + break; case MAKEFILE: - writemakefile(cfg); - break; + writemakefile(cfg); + break; case WRITEFUNCLIST: - /* Ignore the functionlist and the methodlist that are available in the - * .conf file. - */ - cfg->funclist = NULL; - if (cfg->classlist != NULL) - cfg->classlist->methlist = NULL; + /* Ignore the functionlist and the methodlist that are available in the + * .conf file. + */ + cfg->funclist = NULL; + if (cfg->classlist != NULL) + cfg->classlist->methlist = NULL; - writefunclist(cfg); - break; + writefunclist(cfg); + break; case WRITEFD: - writefd(cfg); - break; + writefd(cfg); + break; case WRITESKEL: - writeskel(cfg); - break; + writeskel(cfg); + break; default: - fprintf(stderr, "Internal error in main: Unhandled command type\n"); - exit(20); + fprintf(stderr, "Internal error in main: Unhandled command type\n"); + exit(20); } - + return 0; } diff --git a/tools/genmodule/muisupport.c b/tools/genmodule/muisupport.c index 973b9b077e..3528ecc46f 100644 --- a/tools/genmodule/muisupport.c +++ b/tools/genmodule/muisupport.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2006, The AROS Development Team. All rights reserved. $Id$ - + Support functions for MUI classes. Part of genmodule. */ #include "genmodule.h" @@ -22,7 +22,7 @@ void writemccinit(struct config *cfg, FILE *out, int inclass, struct classinfo * struct functionhead *methlistit; struct functionarg *arglistit; unsigned int lvo; - + fprintf ( out, @@ -30,19 +30,19 @@ void writemccinit(struct config *cfg, FILE *out, int inclass, struct classinfo * "/* =======================================*/\n" "\n" ); - + if (cl->classdatatype == NULL) - fprintf(out, "# define %s_DATA_SIZE (0)\n", cl->basename); + fprintf(out, "# define %s_DATA_SIZE (0)\n", cl->basename); else - fprintf + fprintf ( - out, - "# define %s_DATA_SIZE (sizeof(%s))\n", - cl->basename, cl->classdatatype - ); - + out, + "# define %s_DATA_SIZE (sizeof(%s))\n", + cl->basename, cl->classdatatype + ); + writeboopsidispatcher(cfg, out, cl); - + fprintf ( out, @@ -53,93 +53,93 @@ void writemccinit(struct config *cfg, FILE *out, int inclass, struct classinfo * "{\n", cl->basename ); - + /* When classid is specified MakeClass will be used to make the class * otherwise MUI_CreateCustomClass. The former use is only needed for internal * muimaster use. Other use is deprecated. */ if (cl->classid == NULL) { - char *base, disp[256]; - - /* Has the class a provided dispatcher function ? */ - if (cl->dispatcher == NULL) - snprintf(disp, 256, "%s_Dispatcher", cl->basename); - else - strncpy(disp, cl->dispatcher, 256); - - /* Is this class the main class then pass the libbase to MUI_CreateCustomClass - * otherwise pass NULL - */ - if (!inclass) - base = "(struct Library *)LIBBASE"; - else - base = "NULL"; - - if (cl->superclass != NULL) - fprintf - ( - out, - " %s_CLASSPTR_FIELD(LIBBASE) = MUI_CreateCustomClass(%s, %s, NULL, %s_DATA_SIZE, %s);\n", - cl->basename, base, cl->superclass, cl->basename, disp - ); - else if (cl->superclass_field != NULL) - fprintf - ( - out, - " %s_CLASSPTR_FIELD(LIBBASE) = MUI_CreateCustomClass(%s, NULL, LIBBASE->%s, %s_DATA_SIZE, %s);\n", - cl->basename, base, cl->superclass_field, cl->basename, disp - ); - else - { - fprintf(out, "Internal error: both superclass and superclass_field are NULL\n"); - exit(20); - } + char *base, disp[256]; + + /* Has the class a provided dispatcher function ? */ + if (cl->dispatcher == NULL) + snprintf(disp, 256, "%s_Dispatcher", cl->basename); + else + strncpy(disp, cl->dispatcher, 256); + + /* Is this class the main class then pass the libbase to MUI_CreateCustomClass + * otherwise pass NULL + */ + if (!inclass) + base = "(struct Library *)LIBBASE"; + else + base = "NULL"; + + if (cl->superclass != NULL) + fprintf + ( + out, + " %s_CLASSPTR_FIELD(LIBBASE) = MUI_CreateCustomClass(%s, %s, NULL, %s_DATA_SIZE, %s);\n", + cl->basename, base, cl->superclass, cl->basename, disp + ); + else if (cl->superclass_field != NULL) + fprintf + ( + out, + " %s_CLASSPTR_FIELD(LIBBASE) = MUI_CreateCustomClass(%s, NULL, LIBBASE->%s, %s_DATA_SIZE, %s);\n", + cl->basename, base, cl->superclass_field, cl->basename, disp + ); + else + { + fprintf(out, "Internal error: both superclass and superclass_field are NULL\n"); + exit(20); + } } else { - char disp[256]; - - /* Has the class a provided dispatcher function ? */ - if (cl->dispatcher == NULL) - snprintf(disp, 256, "%s_Dispatcher", cl->basename); - else - strncpy(disp, cl->dispatcher, 256); - - if (cl->superclass != NULL) - fprintf - ( - out, - " Class *superclass = MUI_GetClass(%s),\n", - cl->superclass - ); - else if (cl->superclass_field != NULL) - fprintf - ( - out, - " Class *superclass = LIBBASE->%s,\n", - cl->superclass_field - ); - else - { - fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n"); - exit(20); - } - - fprintf - ( - out, - " *cl = NULL;\n" - "\n" - " if (superclass)\n" - " cl = MakeClass(%s, NULL, superclass, %s_DATA_SIZE, 0);\n" - " if (cl)\n" - " cl->cl_Dispatcher.h_Entry = %s;\n" - " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n", - cl->classid, cl->basename, - disp, - cl->basename - ); + char disp[256]; + + /* Has the class a provided dispatcher function ? */ + if (cl->dispatcher == NULL) + snprintf(disp, 256, "%s_Dispatcher", cl->basename); + else + strncpy(disp, cl->dispatcher, 256); + + if (cl->superclass != NULL) + fprintf + ( + out, + " Class *superclass = MUI_GetClass(%s),\n", + cl->superclass + ); + else if (cl->superclass_field != NULL) + fprintf + ( + out, + " Class *superclass = LIBBASE->%s,\n", + cl->superclass_field + ); + else + { + fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n"); + exit(20); + } + + fprintf + ( + out, + " *cl = NULL;\n" + "\n" + " if (superclass)\n" + " cl = MakeClass(%s, NULL, superclass, %s_DATA_SIZE, 0);\n" + " if (cl)\n" + " cl->cl_Dispatcher.h_Entry = %s;\n" + " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n", + cl->classid, cl->basename, + disp, + cl->basename + ); } fprintf @@ -156,27 +156,27 @@ void writemccinit(struct config *cfg, FILE *out, int inclass, struct classinfo * ); if (cl->classid == NULL) { - fprintf - ( - out, - " MUI_DeleteCustomClass(%s_CLASSPTR_FIELD(LIBBASE));\n", - cl->basename - ); + fprintf + ( + out, + " MUI_DeleteCustomClass(%s_CLASSPTR_FIELD(LIBBASE));\n", + cl->basename + ); } else { - fprintf - ( - out, - " Class *cl = %s_CLASSPTR_FIELD(LIBBASE);\n" - "\n" - " if (cl != NULL)\n" - " {\n" - " MUI_FreeClass(cl->cl_Super);\n" - " FreeClass(cl);\n" - " }\n", - cl->basename - ); + fprintf + ( + out, + " Class *cl = %s_CLASSPTR_FIELD(LIBBASE);\n" + "\n" + " if (cl != NULL)\n" + " {\n" + " MUI_FreeClass(cl->cl_Super);\n" + " FreeClass(cl);\n" + " }\n", + cl->basename + ); } fprintf ( @@ -217,7 +217,7 @@ void writemccquery(FILE *out, struct config *cfg) " {\n", cfg->basename ); - + switch(cfg->modtype) { case MCC: @@ -228,10 +228,10 @@ void writemccquery(FILE *out, struct config *cfg) fprintf(out, " case MCC_PREFS_CLASS: return (IPTR)GM_CLASSPTR_FIELD(LIBBASE);\n"); break; } - + /* FIXME: handle MCC_PREFS_IMAGE somehow */ /* FIXME: handle "ONLY_GLOBAL" ?? */ - + fprintf ( out, diff --git a/tools/genmodule/oopsupport.c b/tools/genmodule/oopsupport.c index 65e827db4c..c0ec9a0088 100644 --- a/tools/genmodule/oopsupport.c +++ b/tools/genmodule/oopsupport.c @@ -1,7 +1,7 @@ /* Copyright © 2005-2006, The AROS Development Team. All rights reserved. $Id$ - + Desc: Support functions for oop.library classes. Part of genmodule. */ #include "genmodule.h" @@ -34,15 +34,15 @@ void writeoopinit(FILE *out, struct classinfo *cl) ); if (cl->classdatatype == NULL) - fprintf(out, "# define %s_DATA_SIZE (0)\n", cl->basename); + fprintf(out, "# define %s_DATA_SIZE (0)\n", cl->basename); else - fprintf + fprintf ( - out, - "# define %s_DATA_SIZE (sizeof(%s))\n", - cl->basename, cl->classdatatype - ); - + out, + "# define %s_DATA_SIZE (sizeof(%s))\n", + cl->basename, cl->classdatatype + ); + /* Write defines of methods */ writefuncdefs(out, NULL, cl->methlist); @@ -62,40 +62,40 @@ void writeoopinit(FILE *out, struct classinfo *cl) "\n", cl->basename ); - + /* Write variables initialization */ for (methlistit = cl->methlist, interface = NULL, methods = 0; - methlistit != NULL; - methlistit = methlistit->next + methlistit != NULL; + methlistit = methlistit->next ) { - if (interface != methlistit->interface) - { - if (interface != NULL) - { - /* Close the previous declaration */ - fprintf(out, - " {NULL, 0}\n" - " };\n" - "#define NUM_%s_%s_METHODS %d\n" - "\n", - cl->basename, interface->s, methods - ); - } + if (interface != methlistit->interface) + { + if (interface != NULL) + { + /* Close the previous declaration */ + fprintf(out, + " {NULL, 0}\n" + " };\n" + "#define NUM_%s_%s_METHODS %d\n" + "\n", + cl->basename, interface->s, methods + ); + } - /* Start new MethodDescr declaration */ - fprintf(out, " struct OOP_MethodDescr %s_%s_descr[] =\n {\n", - cl->basename, methlistit->interface->s - ); - methods = 1; - interface = methlistit->interface; - } - else - methods++; + /* Start new MethodDescr declaration */ + fprintf(out, " struct OOP_MethodDescr %s_%s_descr[] =\n {\n", + cl->basename, methlistit->interface->s + ); + methods = 1; + interface = methlistit->interface; + } + else + methods++; - fprintf(out, " {(OOP_MethodFunc)%s, %s},\n", - methlistit->internalname, methlistit->method - ); + fprintf(out, " {(OOP_MethodFunc)%s, %s},\n", + methlistit->internalname, methlistit->method + ); } if (methods) { /* Close the last declaration */ @@ -112,52 +112,52 @@ void writeoopinit(FILE *out, struct classinfo *cl) fprintf(out, " struct OOP_InterfaceDescr %s_ifdescr[] =\n {\n", cl->basename); for (interface = cl->interfaces; interface != NULL; interface = interface->next) { - fprintf(out, - " {%s_%s_descr, IID_%s, NUM_%s_%s_METHODS},\n", - cl->basename, interface->s, - interface->s, - cl->basename, interface->s - ); + fprintf(out, + " {%s_%s_descr, IID_%s, NUM_%s_%s_METHODS},\n", + cl->basename, interface->s, + interface->s, + cl->basename, interface->s + ); } fprintf(out, - " {NULL, NULL}\n" - " };\n" - "\n" + " {NULL, NULL}\n" + " };\n" + "\n" ); - + /* Write the class creation TagList */ fprintf(out, - " struct TagItem %s_tags[] =\n" - " {\n", - cl->basename + " struct TagItem %s_tags[] =\n" + " {\n", + cl->basename ); if (cl->superclass != NULL) - fprintf(out, - " {aMeta_SuperID, (IPTR)%s},\n", - cl->superclass - ); + fprintf(out, + " {aMeta_SuperID, (IPTR)%s},\n", + cl->superclass + ); else if (cl->superclass_field != NULL) - fprintf(out, - " {aMeta_SuperPtr, (IPTR)LIBBASE->%s},\n", - cl->superclass_field - ); + fprintf(out, + " {aMeta_SuperPtr, (IPTR)LIBBASE->%s},\n", + cl->superclass_field + ); else { - fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n"); - exit(20); + fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n"); + exit(20); } - + fprintf(out, - " {aMeta_InterfaceDescr, (IPTR)%s_ifdescr},\n" - " {aMeta_InstSize, (IPTR)%s_DATA_SIZE},\n", - cl->basename, - cl->basename + " {aMeta_InterfaceDescr, (IPTR)%s_ifdescr},\n" + " {aMeta_InstSize, (IPTR)%s_DATA_SIZE},\n", + cl->basename, + cl->basename ); if (cl->classid != NULL) - fprintf(out, - " {aMeta_ID, (IPTR)%s},\n", - cl->classid - ); + fprintf(out, + " {aMeta_ID, (IPTR)%s},\n", + cl->classid + ); fprintf(out, " {TAG_DONE, (IPTR)0}\n };\n"); /* Write class constructor */ @@ -205,7 +205,7 @@ void writeoopinit(FILE *out, struct classinfo *cl) cl->basename, cl->basename ); - + fprintf ( out, diff --git a/tools/genmodule/stringlist.c b/tools/genmodule/stringlist.c index ed6b211c41..4e8a223843 100644 --- a/tools/genmodule/stringlist.c +++ b/tools/genmodule/stringlist.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2005, The AROS Development Team. All rights reserved. $Id$ - + Code to handle list of strings */ #include @@ -14,22 +14,22 @@ struct stringlist *slist_append(struct stringlist **list, const char *s) { struct stringlist **listit = list; struct stringlist *node = malloc(sizeof(struct stringlist)); - + if (node == NULL) { - fprintf(stderr, "Out of memory!\n"); - exit(20); + fprintf(stderr, "Out of memory!\n"); + exit(20); } - + while (*listit != NULL) listit = &(*listit)->next; - + *listit = node; node->next = NULL; node->s = strdup(s); if (node->s == NULL) { - fprintf(stderr, "Out of memory!\n"); - exit(20); + fprintf(stderr, "Out of memory!\n"); + exit(20); } return node; @@ -39,19 +39,19 @@ struct stringlist *slist_prepend(struct stringlist **list, const char *s) { struct stringlist **listit = list; struct stringlist *node = malloc(sizeof(struct stringlist)); - + if (node == NULL) { - fprintf(stderr, "Out of memory!\n"); - exit(20); + fprintf(stderr, "Out of memory!\n"); + exit(20); } - + node->next = *listit; node->s = strdup(s); if (node->s == NULL) { - fprintf(stderr, "Out of memory!\n"); - exit(20); + fprintf(stderr, "Out of memory!\n"); + exit(20); } *listit = node; @@ -63,16 +63,16 @@ int slist_remove(struct stringlist **list, struct stringlist *node) struct stringlist **listit = list; while(*listit != NULL && *listit != node) listit = &(*listit)->next; - + if (*listit == node) { - *listit = (*listit)->next; - free(node->s); - free(node); - return 1; + *listit = (*listit)->next; + free(node->s); + free(node); + return 1; } else - return 0; + return 0; } int slist_length(struct stringlist *slist) diff --git a/tools/genmodule/writeautoinit.c b/tools/genmodule/writeautoinit.c index 7e7625a649..b5f304e8ac 100644 --- a/tools/genmodule/writeautoinit.c +++ b/tools/genmodule/writeautoinit.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ - + Function to write module_autoinit.c. Part of genmodule. */ @@ -53,7 +53,7 @@ void writeautoinit(struct config *cfg, int is_rel) if (cfg->forcelist!=NULL) { struct stringlist * forcelistit; - + fprintf(out, "\n"); for (forcelistit = cfg->forcelist; forcelistit!=NULL; diff --git a/tools/genmodule/writeend.c b/tools/genmodule/writeend.c index 03d5f1a76f..41bf02d820 100644 --- a/tools/genmodule/writeend.c +++ b/tools/genmodule/writeend.c @@ -9,18 +9,18 @@ void writeend(struct config *cfg) { FILE *out; char line[256]; - + snprintf(line, 255, "%s/%s_end.c", cfg->gendir, cfg->modulename); out = fopen(line, "w"); if (out==NULL) { - fprintf(stderr, "Could not write %s\n", line); - exit(20); + fprintf(stderr, "Could not write %s\n", line); + exit(20); } fprintf(out, - "#include \"%s_libdefs.h\"\n" - "int GM_UNIQUENAME(End)(void) {return 0;}\n", - cfg->modulename + "#include \"%s_libdefs.h\"\n" + "int GM_UNIQUENAME(End)(void) {return 0;}\n", + cfg->modulename ); fclose(out); } diff --git a/tools/genmodule/writefd.c b/tools/genmodule/writefd.c index 675558024a..aa6710c5ca 100644 --- a/tools/genmodule/writefd.c +++ b/tools/genmodule/writefd.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ - + Write the functionlist to a FD file for identify.library. */ @@ -77,7 +77,7 @@ void writefd(struct config *cfg) else { fprintf(out, "##base _%s\n", cfg->libbase); - + /* * This is correct even for devices. cfg->firstlvo holds LVO number for * the first user function. @@ -92,7 +92,7 @@ void writefd(struct config *cfg) ); fprintf(out, "##public\n"); - + for (lvo = cfg->firstlvo - 1; funclistit != NULL; funclistit = funclistit->next @@ -122,7 +122,7 @@ void writefd(struct config *cfg) lvo = funclistit->lvo; break; - + case STACK: write_fd_func(out, funclistit, lvo); fprintf(out, "sysv"); diff --git a/tools/genmodule/writefunclist.c b/tools/genmodule/writefunclist.c dissimilarity index 62% index 32dacd3286..0ee23f0211 100644 --- a/tools/genmodule/writefunclist.c +++ b/tools/genmodule/writefunclist.c @@ -1,127 +1,127 @@ -/* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. - $Id$ - - Write the functionlist to a file that can be includes the .conf file. -*/ -#include "genmodule.h" - -void writefunclist(struct config *cfg) -{ - FILE *out; - char line[256]; - struct functionhead *funclistit; - struct functionarg *arglistit; - struct stringlist *aliaslistit; - unsigned int lvo; - - snprintf(line, 255, "%s/%s.funclist", cfg->gendir, cfg->modulename); - out = fopen(line, "w"); - - if (out == NULL) - { - perror(line); - exit(20); - } - - /* When not a BOOPSI class write out the functionlist even if it is empty - * when it is a BOOPSI write only the list when it is not empty - * When cfg->basename != cfg->classlist->basename this means we are not in a BOOPSI class - * but there are extra classes defined - */ - if (cfg->classlist == NULL - || strcmp(cfg->basename, cfg->classlist->basename) != 0 - || cfg->funclist != NULL) - { - fprintf(out, "##begin functionlist\n"); - - for (funclistit = cfg->funclist, lvo = cfg->firstlvo - 1; - funclistit != NULL; - funclistit = funclistit->next - ) - { - if (funclistit->libcall == REGISTERMACRO) - { - if (funclistit->lvo > lvo+1) - { - if (funclistit->lvo == lvo+2) - fprintf(out, "\n"); - else - fprintf(out, ".skip %u\n", funclistit->lvo - lvo - 1); - } - - fprintf(out, - "%s %s(", - funclistit->type, funclistit->name - ); - - for (arglistit = funclistit->arguments; - arglistit!=NULL; - arglistit = arglistit->next - ) - { - /* Print a , separator when not the first function argument */ - if (arglistit != funclistit->arguments) - fprintf(out, ", "); - - fprintf(out, "%s", arglistit->arg); - } - fprintf(out, ") ("); - - for (arglistit = funclistit->arguments; - arglistit != NULL; - arglistit = arglistit->next - ) - { - /* Print a , separator when not the first function argument */ - if (arglistit != funclistit->arguments) - fprintf(out, ", "); - - fprintf(out, "%s", arglistit->reg); - } - fprintf(out, ")\n"); - - for (aliaslistit = funclistit->aliases; - aliaslistit != NULL; - aliaslistit = aliaslistit->next - ) - { - fprintf(out, ".alias %s\n", aliaslistit->s); - } - - if (funclistit->novararg) - fprintf(out, ".novararg\n"); - - if (funclistit->priv) - fprintf(out, ".private\n"); - - lvo = funclistit->lvo; - } - } - - fprintf(out, "##end functionlist\n"); - } - - if (cfg->classlist != NULL && strcmp(cfg->basename, cfg->classlist->basename) == 0) - { - fprintf(out, "##begin methodlist\n"); - - for(funclistit = cfg->classlist->methlist; - funclistit != NULL; - funclistit = funclistit->next - ) - { - fprintf(out, "%s\n", funclistit->name); - } - - fprintf(out, "##end methodlist\n"); - } - - if (ferror(out)) - { - perror(line); - exit(20); - } - - fclose(out); -} +/* + Copyright © 1995-2008, The AROS Development Team. All rights reserved. + $Id$ + + Write the functionlist to a file that can be includes the .conf file. +*/ +#include "genmodule.h" + +void writefunclist(struct config *cfg) +{ + FILE *out; + char line[256]; + struct functionhead *funclistit; + struct functionarg *arglistit; + struct stringlist *aliaslistit; + unsigned int lvo; + + snprintf(line, 255, "%s/%s.funclist", cfg->gendir, cfg->modulename); + out = fopen(line, "w"); + + if (out == NULL) + { + perror(line); + exit(20); + } + + /* When not a BOOPSI class write out the functionlist even if it is empty + * when it is a BOOPSI write only the list when it is not empty + * When cfg->basename != cfg->classlist->basename this means we are not in a BOOPSI class + * but there are extra classes defined + */ + if (cfg->classlist == NULL + || strcmp(cfg->basename, cfg->classlist->basename) != 0 + || cfg->funclist != NULL) + { + fprintf(out, "##begin functionlist\n"); + + for (funclistit = cfg->funclist, lvo = cfg->firstlvo - 1; + funclistit != NULL; + funclistit = funclistit->next + ) + { + if (funclistit->libcall == REGISTERMACRO) + { + if (funclistit->lvo > lvo+1) + { + if (funclistit->lvo == lvo+2) + fprintf(out, "\n"); + else + fprintf(out, ".skip %u\n", funclistit->lvo - lvo - 1); + } + + fprintf(out, + "%s %s(", + funclistit->type, funclistit->name + ); + + for (arglistit = funclistit->arguments; + arglistit!=NULL; + arglistit = arglistit->next + ) + { + /* Print a , separator when not the first function argument */ + if (arglistit != funclistit->arguments) + fprintf(out, ", "); + + fprintf(out, "%s", arglistit->arg); + } + fprintf(out, ") ("); + + for (arglistit = funclistit->arguments; + arglistit != NULL; + arglistit = arglistit->next + ) + { + /* Print a , separator when not the first function argument */ + if (arglistit != funclistit->arguments) + fprintf(out, ", "); + + fprintf(out, "%s", arglistit->reg); + } + fprintf(out, ")\n"); + + for (aliaslistit = funclistit->aliases; + aliaslistit != NULL; + aliaslistit = aliaslistit->next + ) + { + fprintf(out, ".alias %s\n", aliaslistit->s); + } + + if (funclistit->novararg) + fprintf(out, ".novararg\n"); + + if (funclistit->priv) + fprintf(out, ".private\n"); + + lvo = funclistit->lvo; + } + } + + fprintf(out, "##end functionlist\n"); + } + + if (cfg->classlist != NULL && strcmp(cfg->basename, cfg->classlist->basename) == 0) + { + fprintf(out, "##begin methodlist\n"); + + for(funclistit = cfg->classlist->methlist; + funclistit != NULL; + funclistit = funclistit->next + ) + { + fprintf(out, "%s\n", funclistit->name); + } + + fprintf(out, "##end methodlist\n"); + } + + if (ferror(out)) + { + perror(line); + exit(20); + } + + fclose(out); +} diff --git a/tools/genmodule/writegetlibbase.c b/tools/genmodule/writegetlibbase.c index d5f16d73e8..a4ae2a6221 100644 --- a/tools/genmodule/writegetlibbase.c +++ b/tools/genmodule/writegetlibbase.c @@ -1,7 +1,7 @@ /* Copyright © 2012, The AROS Development Team. All rights reserved. $Id$ - + Function to write module_getlibbase.c. Part of genmodule. */ @@ -33,7 +33,7 @@ void writegetlibbase(struct config *cfg, int is_rel) "extern %s%s;\n" "\n" "%s__aros_getbase_%s(void);\n" - "\n" + "\n" "%s__aros_getbase_%s(void)\n" "{\n" " return %s;\n" diff --git a/tools/genmodule/writeincclib.c b/tools/genmodule/writeincclib.c index efe586f4cd..e1fc2e56de 100644 --- a/tools/genmodule/writeincclib.c +++ b/tools/genmodule/writeincclib.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2010, The AROS Development Team. All rights reserved. $Id$ - + Function to write clib/modulename_protos.h. Part of genmodule. */ #include "genmodule.h" @@ -13,7 +13,7 @@ void writeincclib(struct config *cfg) struct functionhead *funclistit; struct functionarg *arglistit; struct stringlist *linelistit; - + snprintf(line, 255, "%s/clib/%s_protos.h", cfg->gendir, cfg->modulename); out = fopen(line, "w"); @@ -26,32 +26,32 @@ void writeincclib(struct config *cfg) banner = getBanner(cfg); fprintf(out, - "#ifndef CLIB_%s_PROTOS_H\n" - "#define CLIB_%s_PROTOS_H\n" - "\n" - "%s" - "\n" - "#include \n" - "\n", - cfg->modulenameupper, cfg->modulenameupper, banner + "#ifndef CLIB_%s_PROTOS_H\n" + "#define CLIB_%s_PROTOS_H\n" + "\n" + "%s" + "\n" + "#include \n" + "\n", + cfg->modulenameupper, cfg->modulenameupper, banner ); freeBanner(banner); for (linelistit = cfg->cdeflines; linelistit!=NULL; linelistit = linelistit->next) - fprintf(out, "%s\n", linelistit->s); + fprintf(out, "%s\n", linelistit->s); fprintf(out, - "\n" - "__BEGIN_DECLS\n" - "\n" + "\n" + "__BEGIN_DECLS\n" + "\n" ); writefuncprotos(out, cfg, cfg->funclist); fprintf(out, - "\n" - "__END_DECLS\n" - "\n" - "#endif /* CLIB_%s_PROTOS_H */\n", - cfg->modulenameupper); + "\n" + "__END_DECLS\n" + "\n" + "#endif /* CLIB_%s_PROTOS_H */\n", + cfg->modulenameupper); } diff --git a/tools/genmodule/writeincdefines.c b/tools/genmodule/writeincdefines.c dissimilarity index 64% index ce2311f0a9..997fe16b15 100644 --- a/tools/genmodule/writeincdefines.c +++ b/tools/genmodule/writeincdefines.c @@ -1,424 +1,424 @@ -/* - Copyright © 1995-2012, The AROS Development Team. All rights reserved. - $Id$ - - Function to write defines/modulename.h. Part of genmodule. -*/ -#include "genmodule.h" - -static void writedefineregister(FILE *, struct functionhead *, struct config *); -static void writedefinevararg(FILE *, struct functionhead *, struct config *); -static void writealiases(FILE *, struct functionhead *, struct config *); - -void writeincdefines(struct config *cfg) -{ - FILE *out; - char line[256], *banner; - struct functionhead *funclistit; - - snprintf(line, 255, "%s/defines/%s.h", cfg->gendir, cfg->modulename); - out = fopen(line, "w"); - - if (out == NULL) - { - perror(line); - exit(20); - } - - banner = getBanner(cfg); - fprintf(out, - "#ifndef DEFINES_%s_H\n" - "#define DEFINES_%s_H\n" - "\n" - "%s" - "\n" - "/*\n" - " Desc: Defines for %s\n" - "*/\n" - "\n" - "#include \n" - "#include \n" - "#include \n" - "#include \n" - "\n" - "__BEGIN_DECLS\n" - "\n", - cfg->modulenameupper, cfg->modulenameupper, banner, cfg->modulename - ); - freeBanner(banner); - - for (funclistit = cfg->funclist; funclistit!=NULL; funclistit = funclistit->next) - { - if (!funclistit->priv && (funclistit->lvo >= cfg->firstlvo) && funclistit->libcall != STACK) - { - fprintf(out, - "\n" - "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)" - "\n", - cfg->modulenameupper, - funclistit->version, - cfg->modulenameupper - ); - - writedefineregister(out, funclistit, cfg); - if (!funclistit->novararg) - writedefinevararg(out, funclistit, cfg); - - writealiases(out, funclistit, cfg); - - fprintf(out, - "\n" - "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */" - "\n", - cfg->modulenameupper, - funclistit->version, - cfg->modulenameupper - ); - - } - } - fprintf(out, - "\n" - "__END_DECLS\n" - "\n" - "#endif /* DEFINES_%s_H*/\n", - cfg->modulenameupper - ); - fclose(out); -} - - -void -writedefineregister(FILE *out, struct functionhead *funclistit, struct config *cfg) -{ - struct functionarg *arglistit; - int count, isvoid, nquad = 0, narg = 0; - char *type; - - isvoid = strcmp(funclistit->type, "void") == 0 - || strcmp(funclistit->type, "VOID") == 0; - - fprintf(out, - "\n" - "#define __%s_WB(__%s", - funclistit->name, cfg->libbase - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit!=NULL; - arglistit = arglistit->next, count++ - ) - { - fprintf(out, ", __arg%d", count); - if (strchr(arglistit->reg, '/') != NULL) { - nquad++; - } else { - narg++; - } - } - fprintf(out, - ") ({\\\n" - ); - fprintf(out, - " AROS_LIBREQ(%s,%d)\\\n", - cfg->libbase, funclistit->version - ); - if (nquad == 0) - { - fprintf(out, - " AROS_LC%d%s%s(%s, %s, \\\n", - funclistit->argcount, funclistit->unusedlibbase ? "I" : "", - (isvoid) ? "NR" : "", - funclistit->type, funclistit->name - ); - - for (arglistit = funclistit->arguments, count = 1; - arglistit!=NULL; - arglistit = arglistit->next, count++ - ) - { - type = getargtype(arglistit); - assert(type != NULL); - fprintf(out, - " AROS_LCA(%s,(__arg%d),%s), \\\n", - type, count, arglistit->reg - ); - free(type); - } - } - else - { - if (narg) { - fprintf(out, - " AROS_LC%dQUAD%d%s(%s, %s,\\\n", - narg, nquad, (isvoid) ? "NR" : "", - funclistit->type, funclistit->name - ); - } else { - fprintf(out, - " AROS_LCQUAD%d%s(%s, %s,\\\n", - nquad, (isvoid) ? "NR" : "", - funclistit->type, funclistit->name - ); - } - - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL; - arglistit = arglistit->next, count++ - ) - { - char *quad2 = strchr(arglistit->reg, '/'); - - arglistit->reg[2] = 0; - type = getargtype(arglistit); - assert(type != NULL); - - if (quad2 != NULL) { - *quad2 = 0; - fprintf(out, - " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n", - type, count, arglistit->reg, quad2+1 - ); - *quad2 = '/'; - } else { - fprintf(out, - " AROS_LCA(%s, (__arg%d), %s), \\\n", - type, count, arglistit->reg - ); - } - free(type); - } - } - fprintf(out, - " %s, (__%s), %u, %s);\\\n})\n\n", - cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename - ); - - fprintf(out, "#define %s(", funclistit->name); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL; - arglistit = arglistit->next, count++ - ) - { - if (arglistit != funclistit->arguments) - fprintf(out, ", "); - fprintf(out, "arg%d", count); - } - fprintf(out, ") \\\n __%s_WB(__aros_getbase_%s()", - funclistit->name, cfg->libbase - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL; - arglistit = arglistit->next, count++ - ) - fprintf(out, ", (arg%d)", count); - fprintf(out, ")\n"); -} - -void -writedefinevararg(FILE *out, struct functionhead *funclistit, struct config *cfg) -{ - struct functionarg *arglistit = funclistit->arguments; - char isvararg = 0, *varargname, *lastname; - - /* Go to last argument */ - if (arglistit == NULL) - return; - - while (arglistit->next != NULL) arglistit = arglistit->next; - - lastname = getargname(arglistit); - assert(lastname != NULL); - - if (*(funclistit->name + strlen(funclistit->name) - 1) == 'A') - { - isvararg = 1; - varargname = strdup(funclistit->name); - varargname[strlen(funclistit->name)-1] = '\0'; - } - else if (strcmp(funclistit->name + strlen(funclistit->name) - 7, "TagList") == 0) - { - isvararg = 1; - /* TagList has to be changed in Tags at the end of the functionname */ - varargname = strdup(funclistit->name); - varargname[strlen(funclistit->name)-4] = 's'; - varargname[strlen(funclistit->name)-3] = '\0'; - } - else if (strcmp(funclistit->name + strlen(funclistit->name) - 4, "Args") == 0 - && (strcasecmp(lastname, "args") == 0 || strcasecmp(lastname, "arglist") == 0) - ) - { - isvararg = 1; - varargname = strdup(funclistit->name); - varargname[strlen(funclistit->name)-4] = '\0'; - } - else if ((funclistit->name[0] == 'V') && (strncmp(arglistit->arg, "va_list", 7) == 0)) - { - isvararg = 2; - varargname = malloc(strlen(funclistit->name)); - strcpy(varargname, &funclistit->name[1]); - } - else - { - char *p; - - if (strncmp(arglistit->arg, "const", 5) == 0) { - p = arglistit->arg + 5; - while (isspace(*p)) p++; - } else - p = arglistit->arg; - if (strncmp(p, "struct", 6)==0) - { - p += 6; - while (isspace(*p)) p++; - if (strncmp(p, "TagItem", 7) == 0) - { - p += 7; - while (isspace(*p)) p++; - - if (*p == '*') - { - isvararg = 1; - varargname = malloc(strlen(funclistit->name) + 5); - strcpy(varargname, funclistit->name); - strcat(varargname, "Tags"); - } - } - } - } - - if (isvararg == 1) - { - int count; - char *type; - - fprintf(out, - "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n" - "#define %s(", - cfg->modulenameupper, varargname - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL && arglistit->next != NULL; - arglistit = arglistit->next, count++ - ) - { - fprintf(out, "arg%d, ", count); - } - fprintf(out, - "...) \\\n" - "({ \\\n" - " %s(", - funclistit->name - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL; - arglistit = arglistit->next, count++ - ) - { - if (arglistit != funclistit->arguments) - fprintf(out, ", "); - - if (arglistit->next == NULL) - { - type = getargtype(arglistit); - assert(type != NULL); - fprintf(out, "(%s)(IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type); - free(type); - } - else - fprintf(out, "(arg%d)", count); - } - fprintf(out, - "); \\\n" - "})\n" - "#endif /* !NO_INLINE_STDARG */\n" - ); - - free(varargname); - } - else if (isvararg == 2) - { - int count; - struct functionarg *lastarg; - - fprintf(out, - "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n" - "static inline %s __%s_WB(%s __%s", - cfg->modulenameupper, - funclistit->type, varargname, cfg->libbasetypeptrextern, cfg->libbase - ); - for (arglistit = funclistit->arguments; - arglistit != NULL && arglistit->next != NULL; - arglistit = arglistit->next - ) - { - fprintf(out, ", %s", arglistit->arg); - lastarg = arglistit; - } - fprintf(out, ", ...)\n"); - - fprintf(out, - "{\n" - " %s retval;\n" - " va_list args;\n" - "\n" - " va_start(args, %s);\n" - " retval = __%s_WB(__%s, ", - funclistit->type, - getargname(lastarg), - funclistit->name, cfg->libbase - ); - for (arglistit = funclistit->arguments; - arglistit != NULL && arglistit->next != NULL; - arglistit = arglistit->next - ) - { - fprintf(out, "%s, ", getargname(arglistit)); - } - fprintf(out, - "args);\n" - " va_end(args);\n" - " return retval;\n" - "}\n" - "#define %s(", - varargname - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL && arglistit->next != NULL && arglistit->next->next != NULL; - arglistit = arglistit->next, count++ - ) - { - fprintf(out, "arg%d, ", count); - } - fprintf(out, - "...) __%s_WB(%s, ", - varargname, cfg->libbase - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL && arglistit->next != NULL && arglistit->next->next != NULL; - arglistit = arglistit->next, count++ - ) - { - fprintf(out, "(arg%d), ", count); - } - fprintf(out, - "__VA_ARGS__)\n" - "#endif /* !NO_INLINE_STDARG */\n" - ); - - free(varargname); - } -} - -void -writealiases(FILE *out, struct functionhead *funclistit, struct config *cfg) -{ - struct stringlist *aliasesit; - - for (aliasesit = funclistit->aliases; - aliasesit != NULL; - aliasesit = aliasesit->next - ) - { - fprintf(out, "#define %s %s\n", aliasesit->s, funclistit->name); - } -} +/* + Copyright © 1995-2012, The AROS Development Team. All rights reserved. + $Id$ + + Function to write defines/modulename.h. Part of genmodule. +*/ +#include "genmodule.h" + +static void writedefineregister(FILE *, struct functionhead *, struct config *); +static void writedefinevararg(FILE *, struct functionhead *, struct config *); +static void writealiases(FILE *, struct functionhead *, struct config *); + +void writeincdefines(struct config *cfg) +{ + FILE *out; + char line[256], *banner; + struct functionhead *funclistit; + + snprintf(line, 255, "%s/defines/%s.h", cfg->gendir, cfg->modulename); + out = fopen(line, "w"); + + if (out == NULL) + { + perror(line); + exit(20); + } + + banner = getBanner(cfg); + fprintf(out, + "#ifndef DEFINES_%s_H\n" + "#define DEFINES_%s_H\n" + "\n" + "%s" + "\n" + "/*\n" + " Desc: Defines for %s\n" + "*/\n" + "\n" + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "\n" + "__BEGIN_DECLS\n" + "\n", + cfg->modulenameupper, cfg->modulenameupper, banner, cfg->modulename + ); + freeBanner(banner); + + for (funclistit = cfg->funclist; funclistit!=NULL; funclistit = funclistit->next) + { + if (!funclistit->priv && (funclistit->lvo >= cfg->firstlvo) && funclistit->libcall != STACK) + { + fprintf(out, + "\n" + "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)" + "\n", + cfg->modulenameupper, + funclistit->version, + cfg->modulenameupper + ); + + writedefineregister(out, funclistit, cfg); + if (!funclistit->novararg) + writedefinevararg(out, funclistit, cfg); + + writealiases(out, funclistit, cfg); + + fprintf(out, + "\n" + "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */" + "\n", + cfg->modulenameupper, + funclistit->version, + cfg->modulenameupper + ); + + } + } + fprintf(out, + "\n" + "__END_DECLS\n" + "\n" + "#endif /* DEFINES_%s_H*/\n", + cfg->modulenameupper + ); + fclose(out); +} + + +void +writedefineregister(FILE *out, struct functionhead *funclistit, struct config *cfg) +{ + struct functionarg *arglistit; + int count, isvoid, nquad = 0, narg = 0; + char *type; + + isvoid = strcmp(funclistit->type, "void") == 0 + || strcmp(funclistit->type, "VOID") == 0; + + fprintf(out, + "\n" + "#define __%s_WB(__%s", + funclistit->name, cfg->libbase + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit!=NULL; + arglistit = arglistit->next, count++ + ) + { + fprintf(out, ", __arg%d", count); + if (strchr(arglistit->reg, '/') != NULL) { + nquad++; + } else { + narg++; + } + } + fprintf(out, + ") ({\\\n" + ); + fprintf(out, + " AROS_LIBREQ(%s,%d)\\\n", + cfg->libbase, funclistit->version + ); + if (nquad == 0) + { + fprintf(out, + " AROS_LC%d%s%s(%s, %s, \\\n", + funclistit->argcount, funclistit->unusedlibbase ? "I" : "", + (isvoid) ? "NR" : "", + funclistit->type, funclistit->name + ); + + for (arglistit = funclistit->arguments, count = 1; + arglistit!=NULL; + arglistit = arglistit->next, count++ + ) + { + type = getargtype(arglistit); + assert(type != NULL); + fprintf(out, + " AROS_LCA(%s,(__arg%d),%s), \\\n", + type, count, arglistit->reg + ); + free(type); + } + } + else + { + if (narg) { + fprintf(out, + " AROS_LC%dQUAD%d%s(%s, %s,\\\n", + narg, nquad, (isvoid) ? "NR" : "", + funclistit->type, funclistit->name + ); + } else { + fprintf(out, + " AROS_LCQUAD%d%s(%s, %s,\\\n", + nquad, (isvoid) ? "NR" : "", + funclistit->type, funclistit->name + ); + } + + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL; + arglistit = arglistit->next, count++ + ) + { + char *quad2 = strchr(arglistit->reg, '/'); + + arglistit->reg[2] = 0; + type = getargtype(arglistit); + assert(type != NULL); + + if (quad2 != NULL) { + *quad2 = 0; + fprintf(out, + " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n", + type, count, arglistit->reg, quad2+1 + ); + *quad2 = '/'; + } else { + fprintf(out, + " AROS_LCA(%s, (__arg%d), %s), \\\n", + type, count, arglistit->reg + ); + } + free(type); + } + } + fprintf(out, + " %s, (__%s), %u, %s);\\\n})\n\n", + cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename + ); + + fprintf(out, "#define %s(", funclistit->name); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL; + arglistit = arglistit->next, count++ + ) + { + if (arglistit != funclistit->arguments) + fprintf(out, ", "); + fprintf(out, "arg%d", count); + } + fprintf(out, ") \\\n __%s_WB(__aros_getbase_%s()", + funclistit->name, cfg->libbase + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL; + arglistit = arglistit->next, count++ + ) + fprintf(out, ", (arg%d)", count); + fprintf(out, ")\n"); +} + +void +writedefinevararg(FILE *out, struct functionhead *funclistit, struct config *cfg) +{ + struct functionarg *arglistit = funclistit->arguments; + char isvararg = 0, *varargname, *lastname; + + /* Go to last argument */ + if (arglistit == NULL) + return; + + while (arglistit->next != NULL) arglistit = arglistit->next; + + lastname = getargname(arglistit); + assert(lastname != NULL); + + if (*(funclistit->name + strlen(funclistit->name) - 1) == 'A') + { + isvararg = 1; + varargname = strdup(funclistit->name); + varargname[strlen(funclistit->name)-1] = '\0'; + } + else if (strcmp(funclistit->name + strlen(funclistit->name) - 7, "TagList") == 0) + { + isvararg = 1; + /* TagList has to be changed in Tags at the end of the functionname */ + varargname = strdup(funclistit->name); + varargname[strlen(funclistit->name)-4] = 's'; + varargname[strlen(funclistit->name)-3] = '\0'; + } + else if (strcmp(funclistit->name + strlen(funclistit->name) - 4, "Args") == 0 + && (strcasecmp(lastname, "args") == 0 || strcasecmp(lastname, "arglist") == 0) + ) + { + isvararg = 1; + varargname = strdup(funclistit->name); + varargname[strlen(funclistit->name)-4] = '\0'; + } + else if ((funclistit->name[0] == 'V') && (strncmp(arglistit->arg, "va_list", 7) == 0)) + { + isvararg = 2; + varargname = malloc(strlen(funclistit->name)); + strcpy(varargname, &funclistit->name[1]); + } + else + { + char *p; + + if (strncmp(arglistit->arg, "const", 5) == 0) { + p = arglistit->arg + 5; + while (isspace(*p)) p++; + } else + p = arglistit->arg; + if (strncmp(p, "struct", 6)==0) + { + p += 6; + while (isspace(*p)) p++; + if (strncmp(p, "TagItem", 7) == 0) + { + p += 7; + while (isspace(*p)) p++; + + if (*p == '*') + { + isvararg = 1; + varargname = malloc(strlen(funclistit->name) + 5); + strcpy(varargname, funclistit->name); + strcat(varargname, "Tags"); + } + } + } + } + + if (isvararg == 1) + { + int count; + char *type; + + fprintf(out, + "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n" + "#define %s(", + cfg->modulenameupper, varargname + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL && arglistit->next != NULL; + arglistit = arglistit->next, count++ + ) + { + fprintf(out, "arg%d, ", count); + } + fprintf(out, + "...) \\\n" + "({ \\\n" + " %s(", + funclistit->name + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL; + arglistit = arglistit->next, count++ + ) + { + if (arglistit != funclistit->arguments) + fprintf(out, ", "); + + if (arglistit->next == NULL) + { + type = getargtype(arglistit); + assert(type != NULL); + fprintf(out, "(%s)(IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type); + free(type); + } + else + fprintf(out, "(arg%d)", count); + } + fprintf(out, + "); \\\n" + "})\n" + "#endif /* !NO_INLINE_STDARG */\n" + ); + + free(varargname); + } + else if (isvararg == 2) + { + int count; + struct functionarg *lastarg; + + fprintf(out, + "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n" + "static inline %s __%s_WB(%s __%s", + cfg->modulenameupper, + funclistit->type, varargname, cfg->libbasetypeptrextern, cfg->libbase + ); + for (arglistit = funclistit->arguments; + arglistit != NULL && arglistit->next != NULL; + arglistit = arglistit->next + ) + { + fprintf(out, ", %s", arglistit->arg); + lastarg = arglistit; + } + fprintf(out, ", ...)\n"); + + fprintf(out, + "{\n" + " %s retval;\n" + " va_list args;\n" + "\n" + " va_start(args, %s);\n" + " retval = __%s_WB(__%s, ", + funclistit->type, + getargname(lastarg), + funclistit->name, cfg->libbase + ); + for (arglistit = funclistit->arguments; + arglistit != NULL && arglistit->next != NULL; + arglistit = arglistit->next + ) + { + fprintf(out, "%s, ", getargname(arglistit)); + } + fprintf(out, + "args);\n" + " va_end(args);\n" + " return retval;\n" + "}\n" + "#define %s(", + varargname + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL && arglistit->next != NULL && arglistit->next->next != NULL; + arglistit = arglistit->next, count++ + ) + { + fprintf(out, "arg%d, ", count); + } + fprintf(out, + "...) __%s_WB(%s, ", + varargname, cfg->libbase + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL && arglistit->next != NULL && arglistit->next->next != NULL; + arglistit = arglistit->next, count++ + ) + { + fprintf(out, "(arg%d), ", count); + } + fprintf(out, + "__VA_ARGS__)\n" + "#endif /* !NO_INLINE_STDARG */\n" + ); + + free(varargname); + } +} + +void +writealiases(FILE *out, struct functionhead *funclistit, struct config *cfg) +{ + struct stringlist *aliasesit; + + for (aliasesit = funclistit->aliases; + aliasesit != NULL; + aliasesit = aliasesit->next + ) + { + fprintf(out, "#define %s %s\n", aliasesit->s, funclistit->name); + } +} diff --git a/tools/genmodule/writeincinline.c b/tools/genmodule/writeincinline.c index f0386281af..b6f61ef10a 100644 --- a/tools/genmodule/writeincinline.c +++ b/tools/genmodule/writeincinline.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ - + Function to write inline/modulename.h. Part of genmodule. */ #include "genmodule.h" @@ -27,21 +27,21 @@ void writeincinline(struct config *cfg) banner = getBanner(cfg); fprintf(out, - "#ifndef INLINE_%s_H\n" - "#define INLINE_%s_H\n" - "\n" + "#ifndef INLINE_%s_H\n" + "#define INLINE_%s_H\n" + "\n" "%s" - "\n" + "\n" "/*\n" - " Desc: Inline function for %s\n" - "*/\n" - "\n" - "#include \n" - "#include \n" - "#include \n" - "#include \n" - "\n", - cfg->modulenameupper, cfg->modulenameupper, banner, cfg->modulename + " Desc: Inline function for %s\n" + "*/\n" + "\n" + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "\n", + cfg->modulenameupper, cfg->modulenameupper, banner, cfg->modulename ); freeBanner(banner); @@ -76,9 +76,9 @@ void writeincinline(struct config *cfg) } fprintf(out, - "\n" - "#endif /* INLINE_%s_H*/\n", - cfg->modulenameupper + "\n" + "#endif /* INLINE_%s_H*/\n", + cfg->modulenameupper ); fclose(out); } @@ -91,27 +91,27 @@ writeinlineregister(FILE *out, struct functionhead *funclistit, struct config *c int count, isvoid; int narg=0,nquad=0; char *type; - + isvoid = strcmp(funclistit->type, "void") == 0 - || strcmp(funclistit->type, "VOID") == 0; + || strcmp(funclistit->type, "VOID") == 0; fprintf(out, - "\n" - "static inline %s __inline_%s_%s(", - funclistit->type, cfg->basename, funclistit->name + "\n" + "static inline %s __inline_%s_%s(", + funclistit->type, cfg->basename, funclistit->name ); for (arglistit = funclistit->arguments, count = 1; - arglistit!=NULL; - arglistit = arglistit->next, count++ + arglistit!=NULL; + arglistit = arglistit->next, count++ ) { type = getargtype(arglistit); - fprintf(out, "%s __arg%d, ", type, count); - if (strchr(arglistit->reg, '/') != NULL) { - nquad++; - } else { - narg++; - } + fprintf(out, "%s __arg%d, ", type, count); + if (strchr(arglistit->reg, '/') != NULL) { + nquad++; + } else { + narg++; + } } fprintf(out, "APTR __%s)\n" @@ -148,71 +148,71 @@ writeinlineregister(FILE *out, struct functionhead *funclistit, struct config *c else /* nquad != 0 */ { if (narg) { - fprintf(out, - " %sAROS_LC%dQUAD%d%s(%s, %s,\n", - (isvoid) ? "" : "return ", narg, - nquad, (isvoid) ? "NR" : "", - funclistit->type, funclistit->name - ); - } else { - fprintf(out, - " %sAROS_LCQUAD%d%s(%s, %s,\n", - (isvoid) ? "" : "return ", - nquad, (isvoid) ? "NR" : "", - funclistit->type, funclistit->name - ); - } - - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL; - arglistit = arglistit->next, count++ - ) - { - char *quad2 = strchr(arglistit->reg, '/'); - - arglistit->reg[2] = 0; - type = getargtype(arglistit); - assert(type != NULL); - - if (quad2 != NULL) { - *quad2 = 0; - fprintf(out, - " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n", - type, count, arglistit->reg, quad2+1 - ); - *quad2 = '/'; - } else { - fprintf(out, - " AROS_LCA(%s, (__arg%d), %s), \\\n", - type, count, arglistit->reg - ); - } - free(type); - } + fprintf(out, + " %sAROS_LC%dQUAD%d%s(%s, %s,\n", + (isvoid) ? "" : "return ", narg, + nquad, (isvoid) ? "NR" : "", + funclistit->type, funclistit->name + ); + } else { + fprintf(out, + " %sAROS_LCQUAD%d%s(%s, %s,\n", + (isvoid) ? "" : "return ", + nquad, (isvoid) ? "NR" : "", + funclistit->type, funclistit->name + ); + } + + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL; + arglistit = arglistit->next, count++ + ) + { + char *quad2 = strchr(arglistit->reg, '/'); + + arglistit->reg[2] = 0; + type = getargtype(arglistit); + assert(type != NULL); + + if (quad2 != NULL) { + *quad2 = 0; + fprintf(out, + " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n", + type, count, arglistit->reg, quad2+1 + ); + *quad2 = '/'; + } else { + fprintf(out, + " AROS_LCA(%s, (__arg%d), %s), \\\n", + type, count, arglistit->reg + ); + } + free(type); + } } fprintf(out, - " %s, (__%s), %u, %s" + " %s, (__%s), %u, %s" " );\n" "}\n\n", - cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename + cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename ); fprintf(out, "#define %s(", funclistit->name); for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL; - arglistit = arglistit->next, count++ + arglistit != NULL; + arglistit = arglistit->next, count++ ) { - if (arglistit != funclistit->arguments) - fprintf(out, ", "); - fprintf(out, "arg%d", count); + if (arglistit != funclistit->arguments) + fprintf(out, ", "); + fprintf(out, "arg%d", count); } fprintf(out, ") \\\n __inline_%s_%s(", cfg->basename, funclistit->name); for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL; - arglistit = arglistit->next, count++ + arglistit != NULL; + arglistit = arglistit->next, count++ ) - fprintf(out, "(arg%d), ", count); + fprintf(out, "(arg%d), ", count); fprintf(out, "__aros_getbase_%s())\n", cfg->libbase); } @@ -221,48 +221,48 @@ writeinlinevararg(FILE *out, struct functionhead *funclistit, struct config *cfg { struct functionarg *arglistit = funclistit->arguments; char isvararg = 0, *varargname, *lastname; - + /* Go to last argument */ if (arglistit == NULL) - return; - + return; + while (arglistit->next != NULL) arglistit = arglistit->next; - + lastname = getargname(arglistit); assert(lastname != NULL); - + if (*(funclistit->name + strlen(funclistit->name) - 1) == 'A') { - isvararg = 1; - varargname = strdup(funclistit->name); - varargname[strlen(funclistit->name)-1] = '\0'; + isvararg = 1; + varargname = strdup(funclistit->name); + varargname[strlen(funclistit->name)-1] = '\0'; } else if (strcmp(funclistit->name + strlen(funclistit->name) - 7, "TagList") == 0) { - isvararg = 1; - /* TagList has to be changed in Tags at the end of the functionname */ - varargname = strdup(funclistit->name); - varargname[strlen(funclistit->name)-4] = 's'; - varargname[strlen(funclistit->name)-3] = '\0'; + isvararg = 1; + /* TagList has to be changed in Tags at the end of the functionname */ + varargname = strdup(funclistit->name); + varargname[strlen(funclistit->name)-4] = 's'; + varargname[strlen(funclistit->name)-3] = '\0'; } else if (strcmp(funclistit->name + strlen(funclistit->name) - 4, "Args") == 0 - && (strcasecmp(lastname, "args") == 0 || strcasecmp(lastname, "arglist") == 0) + && (strcasecmp(lastname, "args") == 0 || strcasecmp(lastname, "arglist") == 0) ) { - isvararg = 1; - varargname = strdup(funclistit->name); - varargname[strlen(funclistit->name)-4] = '\0'; + isvararg = 1; + varargname = strdup(funclistit->name); + varargname[strlen(funclistit->name)-4] = '\0'; } else if ((funclistit->name[0] == 'V') && (strncmp(arglistit->arg, "va_list", 7) == 0)) { - isvararg = 2; - varargname = malloc(strlen(funclistit->name)); - strcpy(varargname, &funclistit->name[1]); + isvararg = 2; + varargname = malloc(strlen(funclistit->name)); + strcpy(varargname, &funclistit->name[1]); } else { - char *p; - + char *p; + if (strncmp(arglistit->arg, "const", 5) == 0) { p = arglistit->arg + 5; @@ -270,147 +270,147 @@ writeinlinevararg(FILE *out, struct functionhead *funclistit, struct config *cfg } else p = arglistit->arg; if (strncmp(p, "struct", 6)==0) - { - p += 6; - while (isspace(*p)) p++; - if (strncmp(p, "TagItem", 7) == 0) - { - p += 7; - while (isspace(*p)) p++; - - if (*p == '*') - { - isvararg = 1; - varargname = malloc(strlen(funclistit->name) + 5); - strcpy(varargname, funclistit->name); - strcat(varargname, "Tags"); - } - } - } + { + p += 6; + while (isspace(*p)) p++; + if (strncmp(p, "TagItem", 7) == 0) + { + p += 7; + while (isspace(*p)) p++; + + if (*p == '*') + { + isvararg = 1; + varargname = malloc(strlen(funclistit->name) + 5); + strcpy(varargname, funclistit->name); + strcat(varargname, "Tags"); + } + } + } } if (isvararg == 1) { - int count; - char *type; - - fprintf(out, - "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n" - "#define %s(", - cfg->modulenameupper, varargname - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL && arglistit->next != NULL; - arglistit = arglistit->next, count++ - ) - { - fprintf(out, "arg%d, ", count); - } - fprintf(out, - "...) \\\n" - "({ \\\n" - " %s(", - funclistit->name - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL; - arglistit = arglistit->next, count++ - ) - { - if (arglistit != funclistit->arguments) - fprintf(out, ", "); - - if (arglistit->next == NULL) - { - type = getargtype(arglistit); - assert(type != NULL); - fprintf(out, "(%s)(IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type); - free(type); - } - else - fprintf(out, "(arg%d)", count); - } - fprintf(out, - "); \\\n" - "})\n" - "#endif /* !NO_INLINE_STDARG */\n" - ); - - free(varargname); + int count; + char *type; + + fprintf(out, + "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n" + "#define %s(", + cfg->modulenameupper, varargname + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL && arglistit->next != NULL; + arglistit = arglistit->next, count++ + ) + { + fprintf(out, "arg%d, ", count); + } + fprintf(out, + "...) \\\n" + "({ \\\n" + " %s(", + funclistit->name + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL; + arglistit = arglistit->next, count++ + ) + { + if (arglistit != funclistit->arguments) + fprintf(out, ", "); + + if (arglistit->next == NULL) + { + type = getargtype(arglistit); + assert(type != NULL); + fprintf(out, "(%s)(IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type); + free(type); + } + else + fprintf(out, "(arg%d)", count); + } + fprintf(out, + "); \\\n" + "})\n" + "#endif /* !NO_INLINE_STDARG */\n" + ); + + free(varargname); } else if (isvararg == 2) { - int count; - - fprintf(out, - "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n" - "static inline %s __inline_%s_%s(%s __%s", - cfg->modulenameupper, - funclistit->type, cfg->basename, varargname, cfg->libbasetypeptrextern, cfg->libbase - ); - for (arglistit = funclistit->arguments, count = 0; - arglistit != NULL && arglistit->next != NULL; - arglistit = arglistit->next - ) - { - char *type = getargtype(arglistit); - - fprintf(out, ", %s __arg%d", type, ++count); - } - fprintf(out, ", ...)\n"); - - fprintf(out, - "{\n" - " %s retval;\n" - " va_list __args;\n" - "\n" - " va_start(__args, __arg%d);\n" - " retval = __inline_%s_%s(", - funclistit->type, - count, - cfg->basename, funclistit->name - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL && arglistit->next != NULL; - arglistit = arglistit->next, count++ - ) - { - fprintf(out, "__arg%d, ", count); - } - fprintf(out, - "__args, __%s);\n" - " va_end(__args);\n" - " return retval;\n" - "}\n" - "\n" - "#define %s(", - cfg->libbase, - varargname - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL && arglistit->next != NULL && arglistit->next->next != NULL; - arglistit = arglistit->next, count++ - ) - { - fprintf(out, "arg%d, ", count); - } - fprintf(out, - "...) \\\n" - " __inline_%s_%s(%s, ", - cfg->basename, varargname, cfg->libbase - ); - for (arglistit = funclistit->arguments, count = 1; - arglistit != NULL && arglistit->next != NULL && arglistit->next->next != NULL; - arglistit = arglistit->next, count++ - ) - { - fprintf(out, "(arg%d), ", count); - } - fprintf(out, - "__VA_ARGS__)\n" - "#endif /* !NO_INLINE_STDARG */\n" - ); - - free(varargname); + int count; + + fprintf(out, + "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n" + "static inline %s __inline_%s_%s(%s __%s", + cfg->modulenameupper, + funclistit->type, cfg->basename, varargname, cfg->libbasetypeptrextern, cfg->libbase + ); + for (arglistit = funclistit->arguments, count = 0; + arglistit != NULL && arglistit->next != NULL; + arglistit = arglistit->next + ) + { + char *type = getargtype(arglistit); + + fprintf(out, ", %s __arg%d", type, ++count); + } + fprintf(out, ", ...)\n"); + + fprintf(out, + "{\n" + " %s retval;\n" + " va_list __args;\n" + "\n" + " va_start(__args, __arg%d);\n" + " retval = __inline_%s_%s(", + funclistit->type, + count, + cfg->basename, funclistit->name + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL && arglistit->next != NULL; + arglistit = arglistit->next, count++ + ) + { + fprintf(out, "__arg%d, ", count); + } + fprintf(out, + "__args, __%s);\n" + " va_end(__args);\n" + " return retval;\n" + "}\n" + "\n" + "#define %s(", + cfg->libbase, + varargname + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL && arglistit->next != NULL && arglistit->next->next != NULL; + arglistit = arglistit->next, count++ + ) + { + fprintf(out, "arg%d, ", count); + } + fprintf(out, + "...) \\\n" + " __inline_%s_%s(%s, ", + cfg->basename, varargname, cfg->libbase + ); + for (arglistit = funclistit->arguments, count = 1; + arglistit != NULL && arglistit->next != NULL && arglistit->next->next != NULL; + arglistit = arglistit->next, count++ + ) + { + fprintf(out, "(arg%d), ", count); + } + fprintf(out, + "__VA_ARGS__)\n" + "#endif /* !NO_INLINE_STDARG */\n" + ); + + free(varargname); } } @@ -418,12 +418,12 @@ void writealiases(FILE *out, struct functionhead *funclistit, struct config *cfg) { struct stringlist *aliasesit; - + for (aliasesit = funclistit->aliases; - aliasesit != NULL; - aliasesit = aliasesit->next + aliasesit != NULL; + aliasesit = aliasesit->next ) { - fprintf(out, "#define %s %s\n", aliasesit->s, funclistit->name); + fprintf(out, "#define %s %s\n", aliasesit->s, funclistit->name); } } diff --git a/tools/genmodule/writeincinterfaces.c b/tools/genmodule/writeincinterfaces.c index 6e709cac0a..b6f3c6fec8 100644 --- a/tools/genmodule/writeincinterfaces.c +++ b/tools/genmodule/writeincinterfaces.c @@ -49,7 +49,7 @@ static void writeincinterface(struct config *cfg, struct interfaceinfo *in) , in->interfaceid ); freeBanner(banner); - + /* Emit the get-the-methodbase stub */ fprintf(out, "#if !defined(%s) && !defined(__OOP_NOMETHODBASES__) && !defined(__%s_NOMETHODBASE__)\n" @@ -148,7 +148,7 @@ static void writeincinterface(struct config *cfg, struct interfaceinfo *in) , in->attributebase , in->interfacename ); - + if (!in->methodlist) goto done; @@ -305,7 +305,7 @@ done: fclose(out); } - + void writeincinterfaces(struct config *cfg) { struct interfaceinfo *in; diff --git a/tools/genmodule/writeinclibdefs.c b/tools/genmodule/writeinclibdefs.c index 4ee25a4315..21ea465115 100644 --- a/tools/genmodule/writeinclibdefs.c +++ b/tools/genmodule/writeinclibdefs.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ - + Function to write libdefs.h. Part of genmodule. */ #include "genmodule.h" @@ -19,34 +19,34 @@ void writeinclibdefs(struct config *cfg) char sep; if (funclistit == NULL) - funccount = cfg->firstlvo-1; + funccount = cfg->firstlvo-1; else { - while (funclistit->next != NULL) - funclistit = funclistit->next; - - funccount = funclistit->lvo; + while (funclistit->next != NULL) + funclistit = funclistit->next; + + funccount = funclistit->lvo; } residentflags[0] = 0; - + if (cfg->residentpri >= 105) - strcpy(residentflags, "RTF_SINGLETASK"); + strcpy(residentflags, "RTF_SINGLETASK"); else if (cfg->residentpri >= -60) - strcpy(residentflags, "RTF_COLDSTART"); + strcpy(residentflags, "RTF_COLDSTART"); else if (cfg->residentpri < -120) - strcpy(residentflags, "RTF_AFTERDOS"); + strcpy(residentflags, "RTF_AFTERDOS"); if (cfg->options & OPTION_RESAUTOINIT) { - if(strlen(residentflags) > 0) - strcat(residentflags, "|"); - strcat(residentflags, "RTF_AUTOINIT"); + if(strlen(residentflags) > 0) + strcat(residentflags, "|"); + strcat(residentflags, "RTF_AUTOINIT"); } if (strlen(residentflags) == 0) - strcpy(residentflags, "0"); - + strcpy(residentflags, "0"); + snprintf(line, 1023, "%s/%s_libdefs.h", cfg->gendir, cfg->modulename); out = fopen(line, "w"); @@ -54,9 +54,9 @@ void writeinclibdefs(struct config *cfg) if (out == NULL) { perror(line); - exit(20); + exit(20); } - + fprintf ( out, @@ -83,7 +83,7 @@ void writeinclibdefs(struct config *cfg) "#define REVISION_NUMBER %u\n" "#define MINOR_VERSION %u\n" "#define VERSION_STRING \"$VER: %s.%s ", - cfg->basename, + cfg->basename, cfg->libbase, _libbasetype, _libbasetype, cfg->modulename, sep, cfg->suffix, cfg->majorversion, cfg->majorversion, @@ -91,7 +91,7 @@ void writeinclibdefs(struct config *cfg) cfg->modulename, cfg->suffix ); if (cfg->versionextra) - fprintf(out, "%s ", cfg->versionextra); + fprintf(out, "%s ", cfg->versionextra); fprintf(out, "%u.%u (%s)%s%s\\r\\n\"\n" "#define COPYRIGHT_STRING \"%s\"\n" @@ -109,59 +109,59 @@ void writeinclibdefs(struct config *cfg) ); for (linelistit = cfg->cdefprivatelines; linelistit!=NULL; linelistit = linelistit->next) - fprintf(out, "%s\n", linelistit->s); + fprintf(out, "%s\n", linelistit->s); /* Following code assumes that the input was checked to be consistent during the * parsing of the .conf file in config.c, no checks are done here */ if (cfg->sysbase_field != NULL) - fprintf(out, - "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n", - cfg->sysbase_field - ); + fprintf(out, + "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n", + cfg->sysbase_field + ); if (cfg->oopbase_field != NULL) - fprintf(out, - "#define GM_OOPBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n", - cfg->oopbase_field - ); + fprintf(out, + "#define GM_OOPBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n", + cfg->oopbase_field + ); if (cfg->seglist_field != NULL) - fprintf(out, - "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n", - cfg->seglist_field - ); + fprintf(out, + "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n", + cfg->seglist_field + ); for (classlistit = cfg->classlist; classlistit != NULL; classlistit = classlistit->next) { - int storeptr; - - if (classlistit->classptr_field != NULL) - { - storeptr = 1; - snprintf(line, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit->classptr_field); - } - else if ((classlistit->classid != NULL) && !(classlistit->options & COPTION_PRIVATE)) - { - storeptr = 0; - snprintf(line, 1023, "FindClass(%s)", classlistit->classid); - } - else - /* Don't write anything */ - continue; - - fprintf(out, - "#define %s_STORE_CLASSPTR %d\n", - classlistit->basename, storeptr - ); - - /* When class is the main class also define GM_CLASSPTR_FIELD for legacy */ - if (strcmp(classlistit->basename, cfg->basename) == 0) - fprintf(out, "#define GM_CLASSPTR_FIELD(lh) (%s)\n", line); - - fprintf(out, - "#define %s_CLASSPTR_FIELD(lh) (%s)\n", - classlistit->basename, line - ); + int storeptr; + + if (classlistit->classptr_field != NULL) + { + storeptr = 1; + snprintf(line, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit->classptr_field); + } + else if ((classlistit->classid != NULL) && !(classlistit->options & COPTION_PRIVATE)) + { + storeptr = 0; + snprintf(line, 1023, "FindClass(%s)", classlistit->classid); + } + else + /* Don't write anything */ + continue; + + fprintf(out, + "#define %s_STORE_CLASSPTR %d\n", + classlistit->basename, storeptr + ); + + /* When class is the main class also define GM_CLASSPTR_FIELD for legacy */ + if (strcmp(classlistit->basename, cfg->basename) == 0) + fprintf(out, "#define GM_CLASSPTR_FIELD(lh) (%s)\n", line); + + fprintf(out, + "#define %s_CLASSPTR_FIELD(lh) (%s)\n", + classlistit->basename, line + ); } - + if (cfg->options & OPTION_DUPBASE) { if (cfg->rootbase_field != NULL) @@ -196,13 +196,13 @@ void writeinclibdefs(struct config *cfg) "#endif /* _%s_LIBDEFS_H */\n", cfg->modulenameupper ); - + if (ferror(out)) { - perror("Error writing libdefs.h"); - fclose(out); - exit(20); + perror("Error writing libdefs.h"); + fclose(out); + exit(20); } - + fclose(out); } diff --git a/tools/genmodule/writeincproto.c b/tools/genmodule/writeincproto.c index 28db39ce71..c2fdf43d62 100644 --- a/tools/genmodule/writeincproto.c +++ b/tools/genmodule/writeincproto.c @@ -10,7 +10,7 @@ void writeincproto(struct config *cfg) FILE *out; char line[256], define[256], *banner; struct linelist *linelistit; - + snprintf(line, 255, "%s/proto/%s.h", cfg->gendir, cfg->modulename ); @@ -19,29 +19,29 @@ void writeincproto(struct config *cfg) if (out == NULL) { perror(line); - exit(20); + exit(20); } banner = getBanner(cfg); fprintf(out, - "#ifndef PROTO_%s_H\n" - "#define PROTO_%s_H\n" - "\n" + "#ifndef PROTO_%s_H\n" + "#define PROTO_%s_H\n" + "\n" "%s" - "\n" - , cfg->modulenameupper + "\n" + , cfg->modulenameupper , cfg->modulenameupper , banner ); fprintf(out, - "#include \n" - "%s" - "#include \n" - "\n" - "#include \n" - "\n", - (cfg->modtype == DEVICE) ? "#include \n" : "", - cfg->modulename + "#include \n" + "%s" + "#include \n" + "\n" + "#include \n" + "\n", + (cfg->modtype == DEVICE) ? "#include \n" : "", + cfg->modulename ); freeBanner(banner); if (!(cfg->options & OPTION_DUPBASE)) @@ -113,24 +113,24 @@ void writeincproto(struct config *cfg) // this solves a problem with proto/8svx.h if (isdigit(cfg->modulenameupper[0])) { - snprintf(define, sizeof define, "X%s", cfg->modulenameupper); + snprintf(define, sizeof define, "X%s", cfg->modulenameupper); } else { - strncpy(define, cfg->modulenameupper, sizeof define); + strncpy(define, cfg->modulenameupper, sizeof define); } fprintf(out, "#if !defined(NOLIBINLINE) && !defined(%s_NOLIBINLINE) && !defined(__%s_RELLIBBASE__)\n" "# include \n" - "#elif !defined(NOLIBDEFINES) && !defined(%s_NOLIBDEFINES)\n" - "# include \n" - "#endif\n" - "\n" - "#endif /* PROTO_%s_H */\n", + "#elif !defined(NOLIBDEFINES) && !defined(%s_NOLIBDEFINES)\n" + "# include \n" + "#endif\n" + "\n" + "#endif /* PROTO_%s_H */\n", define, cfg->modulenameupper, cfg->modulename, - define, + define, cfg->modulename, cfg->modulenameupper ); diff --git a/tools/genmodule/writemakefile.c b/tools/genmodule/writemakefile.c index 95a570d739..a120f5d53c 100644 --- a/tools/genmodule/writemakefile.c +++ b/tools/genmodule/writemakefile.c @@ -1,7 +1,7 @@ /* Copyright © 2005-2011, The AROS Development Team. All rights reserved. $Id$ - + Code to write a Makefile with variables that provides the files and configuration for building the module */ @@ -29,24 +29,24 @@ void writemakefile(struct config *cfg) FILE *out; char name[512]; struct stringlist *s; - + snprintf(name, sizeof(name), "%s/Makefile.%s%s", cfg->gendir, cfg->modulename, cfg->modtypestr); - + out = fopen(name, "w"); - + if (out == NULL) { - perror(name); - exit(20); + perror(name); + exit(20); } fprintf(out, - "%s_STARTFILES += %s_start\n" - "%s_ENDFILES += %s_end\n" - "%s_MODDIR += %s\n", - cfg->modulename, cfg->modulename, - cfg->modulename, cfg->modulename, - cfg->modulename, cfg->moddir + "%s_STARTFILES += %s_start\n" + "%s_ENDFILES += %s_end\n" + "%s_MODDIR += %s\n", + cfg->modulename, cfg->modulename, + cfg->modulename, cfg->modulename, + cfg->modulename, cfg->moddir ); fprintf(out, "%s_LINKLIBFILES +=", cfg->modulename); @@ -73,10 +73,10 @@ void writemakefile(struct config *cfg) fprintf(out, "%s_INCLUDES += ", cfg->modulename); if (cfg->options & OPTION_INCLUDES) { - fprintf(out, - "clib/%s_protos.h inline/%s.h defines/%s.h proto/%s.h", - cfg->modulename, cfg->modulename, cfg->modulename, cfg->modulename - ); + fprintf(out, + "clib/%s_protos.h inline/%s.h defines/%s.h proto/%s.h", + cfg->modulename, cfg->modulename, cfg->modulename, cfg->modulename + ); } if (cfg->interfacelist) { @@ -109,10 +109,10 @@ void writemakefile(struct config *cfg) if (ferror(out)) { - perror("Error writing Makefile"); - fclose(out); - exit(20); + perror("Error writing Makefile"); + fclose(out); + exit(20); } - + fclose(out); } diff --git a/tools/genmodule/writeskel.c b/tools/genmodule/writeskel.c index 36509e352e..3b1ab0dba6 100644 --- a/tools/genmodule/writeskel.c +++ b/tools/genmodule/writeskel.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2009, The AROS Development Team. All rights reserved. $Id$ - + The code for creating skeleton files for the functions present in the module */ #include @@ -22,63 +22,63 @@ static void writeskelfunc(struct config *cfg, struct functionhead *funclist) if (out == NULL) { - perror(line); - exit(20); + perror(line); + exit(20); } fprintf(out, - "/*\n" - " Copyright © , The AROS Development Team. All rights reserved.\n" - " $Id$\n" - "*/\n\n" + "/*\n" + " Copyright © , The AROS Development Team. All rights reserved.\n" + " $Id$\n" + "*/\n\n" ); if (funclist->libcall == REGISTERMACRO) { - fprintf(out, - "/*****************************************************************************\n\n" - " NAME */\n" - " AROS_LH%d(%s, %s,\n\n" - "/* SYNOPSIS */\n", - funclist->argcount, funclist->type, funclist->internalname - ); + fprintf(out, + "/*****************************************************************************\n\n" + " NAME */\n" + " AROS_LH%d(%s, %s,\n\n" + "/* SYNOPSIS */\n", + funclist->argcount, funclist->type, funclist->internalname + ); + + for (arglistit = funclist->arguments; + arglistit!=NULL; + arglistit = arglistit->next + ) + { + type = getargtype(arglistit); + name = getargname(arglistit); + assert(name != NULL && type != NULL); - for (arglistit = funclist->arguments; - arglistit!=NULL; - arglistit = arglistit->next - ) - { - type = getargtype(arglistit); - name = getargname(arglistit); - assert(name != NULL && type != NULL); - - fprintf(out, - " AROS_LHA(%s, %s, %s),\n", - type, name, arglistit->reg - ); - free(type); - free(name); - } + fprintf(out, + " AROS_LHA(%s, %s, %s),\n", + type, name, arglistit->reg + ); + free(type); + free(name); + } - fprintf(out, - "\n/* LOCATION */\n" - " %s, %s, %u, %s)\n\n" - "/* FUNCTION\n\n" - " INPUTS\n\n" - " RESULT\n\n" - " NOTES\n\n" - " EXAMPLE\n\n" - " BUGS\n\n" - " SEE ALSO\n\n" - " INTERNALS\n\n" - " HISTORY\n\n" - "*****************************************************************************/\n" - "{\n" - " AROS_LIBFUNC_INIT\n\n" - " AROS_LIBFUNC_EXIT\n" - "}\n\n", - cfg->libbasetypeptrextern, cfg->libbase, funclist->lvo, cfg->basename - ); + fprintf(out, + "\n/* LOCATION */\n" + " %s, %s, %u, %s)\n\n" + "/* FUNCTION\n\n" + " INPUTS\n\n" + " RESULT\n\n" + " NOTES\n\n" + " EXAMPLE\n\n" + " BUGS\n\n" + " SEE ALSO\n\n" + " INTERNALS\n\n" + " HISTORY\n\n" + "*****************************************************************************/\n" + "{\n" + " AROS_LIBFUNC_INIT\n\n" + " AROS_LIBFUNC_EXIT\n" + "}\n\n", + cfg->libbasetypeptrextern, cfg->libbase, funclist->lvo, cfg->basename + ); } } @@ -88,6 +88,6 @@ void writeskel(struct config *cfg) for(funclistit = cfg->funclist; funclistit != NULL; funclistit = funclistit->next) { - writeskelfunc(cfg, funclistit); + writeskelfunc(cfg, funclistit); } } diff --git a/tools/genmodule/writestart.c b/tools/genmodule/writestart.c index 85bd6407c1..aa05be157f 100644 --- a/tools/genmodule/writestart.c +++ b/tools/genmodule/writestart.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2013, The AROS Development Team. All rights reserved. $Id$ - + Print the library magic and init code in the file modname_start.c. This code is partly based on code in CLib37x.lha from Andreas R. Kleinert */ @@ -90,7 +90,7 @@ void writestart(struct config *cfg) FILE *out; char line[256], *banner; struct classinfo *cl; - + snprintf(line, 255, "%s/%s_start.c", cfg->gendir, cfg->modulename); out = fopen(line, "w"); @@ -112,53 +112,53 @@ void writestart(struct config *cfg) writedecl(out, cfg); if (!(cfg->options & OPTION_NORESIDENT)) { - writeresident(out, cfg); - writedeclsets(out, cfg); - writeinitlib(out, cfg); - if (cfg->modtype != RESOURCE && cfg->modtype != HANDLER) - { - writeopenlib(out, cfg); - writecloselib(out, cfg); - writeexpungelib(out, cfg); - writeextfunclib(out, cfg); - if (cfg->modtype == MCC || cfg->modtype == MUI || cfg->modtype == MCP) - writemccquery(out, cfg); - else if (cfg->modtype == DATATYPE) - writeobtainengine(out, cfg); - } - writesets(out, cfg); + writeresident(out, cfg); + writedeclsets(out, cfg); + writeinitlib(out, cfg); + if (cfg->modtype != RESOURCE && cfg->modtype != HANDLER) + { + writeopenlib(out, cfg); + writecloselib(out, cfg); + writeexpungelib(out, cfg); + writeextfunclib(out, cfg); + if (cfg->modtype == MCC || cfg->modtype == MUI || cfg->modtype == MCP) + writemccquery(out, cfg); + else if (cfg->modtype == DATATYPE) + writeobtainengine(out, cfg); + } + writesets(out, cfg); } - + if (cfg->modtype != HANDLER) - writefunctable(out, cfg); + writefunctable(out, cfg); for (cl = cfg->classlist; cl != NULL; cl = cl->next) { - switch (cl->classtype) - { - case MCC: - case MUI: - case MCP: - /* Second argument to next call: the class is not the main class if it is not - * the first class or the modtype is not a MUI class - */ - writemccinit(cfg, out, cl != cfg->classlist || cfg->modtype != cl->classtype, cl); - break; - case GADGET: - case DATATYPE: - case CLASS: - case IMAGE: - writeclassinit(cfg, out, cl); - break; - case HIDD: - writeoopinit(out, cl); - break; - default: - fprintf(stdout, "Internal error: unsupported classtype in writestart\n"); - exit(20); - } + switch (cl->classtype) + { + case MCC: + case MUI: + case MCP: + /* Second argument to next call: the class is not the main class if it is not + * the first class or the modtype is not a MUI class + */ + writemccinit(cfg, out, cl != cfg->classlist || cfg->modtype != cl->classtype, cl); + break; + case GADGET: + case DATATYPE: + case CLASS: + case IMAGE: + writeclassinit(cfg, out, cl); + break; + case HIDD: + writeoopinit(out, cl); + break; + default: + fprintf(stdout, "Internal error: unsupported classtype in writestart\n"); + exit(20); + } } - + fclose(out); } @@ -171,27 +171,27 @@ static void writedecl(FILE *out, struct config *cfg) struct functionarg *arglistit; struct classinfo *classlistit; char *type, *name; - + if (cfg->modtype == DEVICE) { - fprintf(out, - "#include \n" - "#include \n" - ); + fprintf(out, + "#include \n" + "#include \n" + ); } fprintf(out, - "#include \n" - "#include \n" - "#include \n" - "#include \n" - "#include \n" - "#include \n" - "#include \n" - "#include \n" - "\n" - "#include \"%s_libdefs.h\"\n" - "\n" - , cfg->modulename + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "\n" + "#include \"%s_libdefs.h\"\n" + "\n" + , cfg->modulename ); for (s = cfg->rellibs; s; s = s->next) fprintf(out, @@ -199,14 +199,14 @@ static void writedecl(FILE *out, struct config *cfg) , s->s ); fprintf(out, - "\n" - "#undef SysBase\n" - "#undef OOPBase\n" - "#undef UtilityBase\n" - "\n" - "#include \n" + "\n" + "#undef SysBase\n" + "#undef OOPBase\n" + "#undef UtilityBase\n" + "\n" + "#include \n" "#include \n" - "\n" + "\n" ); /* Write out declaration section provided in the config file */ @@ -218,12 +218,12 @@ static void writedecl(FILE *out, struct config *cfg) /* Is there a variable for storing the segList ? */ if (!(cfg->options & OPTION_NOEXPUNGE) && cfg->modtype!=RESOURCE && cfg->modtype != HANDLER) { - fprintf(out, - "#ifndef GM_SEGLIST_FIELD\n" - "static BPTR __attribute__((unused)) GM_UNIQUENAME(seglist);\n" - "#define GM_SEGLIST_FIELD(LIBBASE) (GM_UNIQUENAME(seglist))\n" - "#endif\n" - ); + fprintf(out, + "#ifndef GM_SEGLIST_FIELD\n" + "static BPTR __attribute__((unused)) GM_UNIQUENAME(seglist);\n" + "#define GM_SEGLIST_FIELD(LIBBASE) (GM_UNIQUENAME(seglist))\n" + "#endif\n" + ); } if (cfg->options & OPTION_DUPBASE) fprintf(out, @@ -233,10 +233,10 @@ static void writedecl(FILE *out, struct config *cfg) if (cfg->options & OPTION_DUPBASE) { fprintf(out, - "#ifndef GM_ROOTBASE_FIELD\n" - "static LIBBASETYPEPTR GM_UNIQUENAME(rootbase);\n" - "#define GM_ROOTBASE_FIELD(LIBBASE) (GM_UNIQUENAME(rootbase))\n" - "#endif\n" + "#ifndef GM_ROOTBASE_FIELD\n" + "static LIBBASETYPEPTR GM_UNIQUENAME(rootbase);\n" + "#define GM_ROOTBASE_FIELD(LIBBASE) (GM_UNIQUENAME(rootbase))\n" + "#endif\n" "struct __GM_DupBase {\n" " LIBBASETYPE base;\n" " LIBBASETYPEPTR oldbase;\n" @@ -337,7 +337,7 @@ static void writedecl(FILE *out, struct config *cfg) fprintf(out, "#define __aros_getbase_%s() __aros_getoffsettable()\n", cfg->libbase - ); + ); fprintf(out, "#else /* !__aros_getoffsettable */\n" "static char *__GM_OffsetTable;\n" @@ -374,7 +374,7 @@ static void writedecl(FILE *out, struct config *cfg) ); } } - + for (classlistit = cfg->classlist; classlistit != NULL; classlistit = classlistit->next) { /* For the main class basename is the same as the module basename */ @@ -413,7 +413,7 @@ static void writedecl(FILE *out, struct config *cfg) classlistit->classptr_var, classlistit->basename, classlistit->classptr_var, classlistit->basename - ); + ); } } else @@ -430,7 +430,7 @@ static void writedecl(FILE *out, struct config *cfg) classlistit->basename, classlistit->basename, classlistit->basename, classlistit->basename - ); + ); } else { @@ -443,7 +443,7 @@ static void writedecl(FILE *out, struct config *cfg) } } } - + /* Write out the defines for the functions of the function table */ writefuncdefs(out, cfg, cfg->funclist); /* Write internal stubs */ @@ -453,42 +453,42 @@ static void writedecl(FILE *out, struct config *cfg) /* Write out the includes needed for the classes */ if (cfg->classlist != NULL) - writeboopsiincludes(out); - + writeboopsiincludes(out); + for (classlistit = cfg->classlist; classlistit != NULL; classlistit = classlistit->next) { - switch (classlistit->classtype) - { - case MUI: - case MCC: - case MCP: - if (!muiinc) - { - writemuiincludes(out); - muiinc = 1; - } - /* Fall through: also write boopsi includes */ - case GADGET: - case DATATYPE: - case CLASS: - case IMAGE: - if (!boopsiinc) - { - writeboopsiincludes(out); - boopsiinc = 1; - } - break; - case HIDD: - if (!oopinc) - { - writeoopincludes(out); - oopinc = 1; - } - break; - default: - fprintf(stderr, "Internal error: unhandled classtype in writedecl\n"); - exit(20); - } + switch (classlistit->classtype) + { + case MUI: + case MCC: + case MCP: + if (!muiinc) + { + writemuiincludes(out); + muiinc = 1; + } + /* Fall through: also write boopsi includes */ + case GADGET: + case DATATYPE: + case CLASS: + case IMAGE: + if (!boopsiinc) + { + writeboopsiincludes(out); + boopsiinc = 1; + } + break; + case HIDD: + if (!oopinc) + { + writeoopincludes(out); + oopinc = 1; + } + break; + default: + fprintf(stderr, "Internal error: unhandled classtype in writedecl\n"); + exit(20); + } } } @@ -497,63 +497,63 @@ static void writedeclsets(FILE *out, struct config *cfg) { /* PROGRAM_ENTRIES is marked as handled but are just ignored in modules */ fprintf(out, - "THIS_PROGRAM_HANDLES_SYMBOLSET(INIT)\n" - "THIS_PROGRAM_HANDLES_SYMBOLSET(EXIT)\n" - "DECLARESET(INIT)\n" - "DECLARESET(EXIT)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(INIT)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(EXIT)\n" + "DECLARESET(INIT)\n" + "DECLARESET(EXIT)\n" "THIS_PROGRAM_HANDLES_SYMBOLSET(PROGRAM_ENTRIES)\n" "DECLARESET(PROGRAM_ENTRIES)\n" ); if (cfg->modtype != HANDLER) fprintf(out, - "THIS_PROGRAM_HANDLES_SYMBOLSET(CTORS)\n" - "THIS_PROGRAM_HANDLES_SYMBOLSET(DTORS)\n" - "DECLARESET(CTORS)\n" - "DECLARESET(DTORS)\n" - "THIS_PROGRAM_HANDLES_SYMBOLSET(INIT_ARRAY)\n" - "THIS_PROGRAM_HANDLES_SYMBOLSET(FINI_ARRAY)\n" - "DECLARESET(INIT_ARRAY)\n" - "DECLARESET(FINI_ARRAY)\n" - "THIS_PROGRAM_HANDLES_SYMBOLSET(INITLIB)\n" - "THIS_PROGRAM_HANDLES_SYMBOLSET(EXPUNGELIB)\n" - "DECLARESET(INITLIB)\n" - "DECLARESET(EXPUNGELIB)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(CTORS)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(DTORS)\n" + "DECLARESET(CTORS)\n" + "DECLARESET(DTORS)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(INIT_ARRAY)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(FINI_ARRAY)\n" + "DECLARESET(INIT_ARRAY)\n" + "DECLARESET(FINI_ARRAY)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(INITLIB)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(EXPUNGELIB)\n" + "DECLARESET(INITLIB)\n" + "DECLARESET(EXPUNGELIB)\n" ); if (!(cfg->options & OPTION_NOAUTOLIB)) { fprintf(out, - "THIS_PROGRAM_HANDLES_SYMBOLSET(LIBS)\n" - "DECLARESET(LIBS)\n" - ); - if (cfg->rellibs) + "THIS_PROGRAM_HANDLES_SYMBOLSET(LIBS)\n" + "DECLARESET(LIBS)\n" + ); + if (cfg->rellibs) fprintf(out, - "THIS_PROGRAM_HANDLES_SYMBOLSET(RELLIBS)\n" - "DECLARESET(RELLIBS)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(RELLIBS)\n" + "DECLARESET(RELLIBS)\n" ); } if (!(cfg->options & OPTION_NOOPENCLOSE)) fprintf(out, - "THIS_PROGRAM_HANDLES_SYMBOLSET(OPENLIB)\n" - "THIS_PROGRAM_HANDLES_SYMBOLSET(CLOSELIB)\n" - "DECLARESET(OPENLIB)\n" - "DECLARESET(CLOSELIB)\n" - ); + "THIS_PROGRAM_HANDLES_SYMBOLSET(OPENLIB)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(CLOSELIB)\n" + "DECLARESET(OPENLIB)\n" + "DECLARESET(CLOSELIB)\n" + ); if (cfg->modtype == DEVICE) fprintf(out, - "THIS_PROGRAM_HANDLES_SYMBOLSET(OPENDEV)\n" - "THIS_PROGRAM_HANDLES_SYMBOLSET(CLOSEDEV)\n" - "DECLARESET(OPENDEV)\n" - "DECLARESET(CLOSEDEV)\n" - ); + "THIS_PROGRAM_HANDLES_SYMBOLSET(OPENDEV)\n" + "THIS_PROGRAM_HANDLES_SYMBOLSET(CLOSEDEV)\n" + "DECLARESET(OPENDEV)\n" + "DECLARESET(CLOSEDEV)\n" + ); if (cfg->classlist != NULL) - fprintf(out, + fprintf(out, "THIS_PROGRAM_HANDLES_SYMBOLSET(CLASSESINIT)\n" "THIS_PROGRAM_HANDLES_SYMBOLSET(CLASSESEXPUNGE)\n" - "DECLARESET(CLASSESINIT)\n" - "DECLARESET(CLASSESEXPUNGE)\n" - "#define ADD2INITCLASSES(symbol, pri) ADD2SET(symbol, CLASSESINIT, pri)\n" - "#define ADD2EXPUNGECLASSES(symbol, pri) ADD2SET(symbol, CLASSESEXPUNGE, pri)\n" - ); + "DECLARESET(CLASSESINIT)\n" + "DECLARESET(CLASSESEXPUNGE)\n" + "#define ADD2INITCLASSES(symbol, pri) ADD2SET(symbol, CLASSESINIT, pri)\n" + "#define ADD2EXPUNGECLASSES(symbol, pri) ADD2SET(symbol, CLASSESEXPUNGE, pri)\n" + ); fprintf(out, "\n"); } @@ -563,23 +563,23 @@ static void writeresident(FILE *out, struct config *cfg) char *rt_skip = cfg->addromtag; if (rt_skip) - fprintf(out, "extern const struct Resident %s;\n", rt_skip); + fprintf(out, "extern const struct Resident %s;\n", rt_skip); else { - rt_skip = "GM_UNIQUENAME(End)"; - fprintf(out, "extern const int %s;\n", rt_skip); + rt_skip = "GM_UNIQUENAME(End)"; + fprintf(out, "extern const int %s;\n", rt_skip); } fprintf(out, - "extern const APTR GM_UNIQUENAME(FuncTable)[];\n" + "extern const APTR GM_UNIQUENAME(FuncTable)[];\n" ); if (cfg->options & OPTION_RESAUTOINIT) - fprintf(out, "static const struct InitTable GM_UNIQUENAME(InitTable);\n"); + fprintf(out, "static const struct InitTable GM_UNIQUENAME(InitTable);\n"); fprintf(out, - "\n" - "extern const char GM_UNIQUENAME(LibName)[];\n" - "extern const char GM_UNIQUENAME(LibID)[];\n" - "extern const char GM_UNIQUENAME(Copyright)[];\n" - "\n" + "\n" + "extern const char GM_UNIQUENAME(LibName)[];\n" + "extern const char GM_UNIQUENAME(LibID)[];\n" + "extern const char GM_UNIQUENAME(Copyright)[];\n" + "\n" ); if (cfg->options & OPTION_RESAUTOINIT) @@ -596,34 +596,34 @@ static void writeresident(FILE *out, struct config *cfg) "} while(0)\n" "\n"); } - + fprintf(out, - "AROS_UFP3 (LIBBASETYPEPTR, GM_UNIQUENAME(InitLib),\n" - " AROS_UFPA(LIBBASETYPEPTR, LIBBASE, D0),\n" - " AROS_UFPA(BPTR, segList, A0),\n" - " AROS_UFPA(struct ExecBase *, sysBase, A6)\n" - ");\n" + "AROS_UFP3 (LIBBASETYPEPTR, GM_UNIQUENAME(InitLib),\n" + " AROS_UFPA(LIBBASETYPEPTR, LIBBASE, D0),\n" + " AROS_UFPA(BPTR, segList, A0),\n" + " AROS_UFPA(struct ExecBase *, sysBase, A6)\n" + ");\n" ); if (cfg->modtype != RESOURCE && cfg->modtype != HANDLER) { - fprintf(out, - "AROS_LD1(BPTR, GM_UNIQUENAME(ExpungeLib),\n" - " AROS_LDA(LIBBASETYPEPTR, extralh, D0),\n" - " LIBBASETYPEPTR, LIBBASE, 3, %s\n" - ");\n" - "\n", - cfg->basename - ); + fprintf(out, + "AROS_LD1(BPTR, GM_UNIQUENAME(ExpungeLib),\n" + " AROS_LDA(LIBBASETYPEPTR, extralh, D0),\n" + " LIBBASETYPEPTR, LIBBASE, 3, %s\n" + ");\n" + "\n", + cfg->basename + ); } fprintf(out, - "struct Resident const GM_UNIQUENAME(ROMTag) =\n" - "{\n" - " RTC_MATCHWORD,\n" - " (struct Resident *)&GM_UNIQUENAME(ROMTag),\n" - " (APTR)&%s,\n" - " RESIDENTFLAGS,\n" - " VERSION_NUMBER,\n", - rt_skip + "struct Resident const GM_UNIQUENAME(ROMTag) =\n" + "{\n" + " RTC_MATCHWORD,\n" + " (struct Resident *)&GM_UNIQUENAME(ROMTag),\n" + " (APTR)&%s,\n" + " RESIDENTFLAGS,\n" + " VERSION_NUMBER,\n", + rt_skip ); switch (cfg->modtype) { @@ -635,56 +635,56 @@ static void writeresident(FILE *out, struct config *cfg) case DATATYPE: case USBCLASS: case HIDD: - fprintf(out, " NT_LIBRARY,\n"); - break; + fprintf(out, " NT_LIBRARY,\n"); + break; case DEVICE: - fprintf(out, " NT_DEVICE,\n"); - break; + fprintf(out, " NT_DEVICE,\n"); + break; case RESOURCE: case HANDLER: - fprintf(out, " NT_RESOURCE,\n"); - break; + fprintf(out, " NT_RESOURCE,\n"); + break; default: - fprintf(stderr, "Internal error: unsupported modtype for NT_...\n"); - exit(20); - break; + fprintf(stderr, "Internal error: unsupported modtype for NT_...\n"); + exit(20); + break; } fprintf(out, - " RESIDENTPRI,\n" - " (CONST_STRPTR)&GM_UNIQUENAME(LibName)[0],\n" - " (CONST_STRPTR)&GM_UNIQUENAME(LibID)[6],\n" + " RESIDENTPRI,\n" + " (CONST_STRPTR)&GM_UNIQUENAME(LibName)[0],\n" + " (CONST_STRPTR)&GM_UNIQUENAME(LibID)[6],\n" ); if (cfg->options & OPTION_RESAUTOINIT) { - fprintf(out, - " (APTR)&GM_UNIQUENAME(InitTable)\n" - "};\n" - "\n" - "static struct InitTable\n" - "{\n" - " IPTR Size;\n" - " const APTR *FuncTable;\n" - " struct DataTable *DataTable;\n" - " APTR InitLibTable;\n" - "}\n" - "const GM_UNIQUENAME(InitTable) =\n" - "{\n" - " LIBBASESIZE,\n" - " &GM_UNIQUENAME(FuncTable)[0],\n" - " NULL,\n" - " (APTR)GM_UNIQUENAME(InitLib)\n" - "};\n" - ); + fprintf(out, + " (APTR)&GM_UNIQUENAME(InitTable)\n" + "};\n" + "\n" + "static struct InitTable\n" + "{\n" + " IPTR Size;\n" + " const APTR *FuncTable;\n" + " struct DataTable *DataTable;\n" + " APTR InitLibTable;\n" + "}\n" + "const GM_UNIQUENAME(InitTable) =\n" + "{\n" + " LIBBASESIZE,\n" + " &GM_UNIQUENAME(FuncTable)[0],\n" + " NULL,\n" + " (APTR)GM_UNIQUENAME(InitLib)\n" + "};\n" + ); } else - fprintf(out, " (APTR)GM_UNIQUENAME(InitLib)\n};\n"); - + fprintf(out, " (APTR)GM_UNIQUENAME(InitLib)\n};\n"); + fprintf(out, - "\n" - "const char GM_UNIQUENAME(LibName)[] = MOD_NAME_STRING;\n" - "const char GM_UNIQUENAME(LibID)[] = VERSION_STRING;\n" - "const char GM_UNIQUENAME(Copyright)[] = COPYRIGHT_STRING;\n" - "\n" + "\n" + "const char GM_UNIQUENAME(LibName)[] = MOD_NAME_STRING;\n" + "const char GM_UNIQUENAME(LibID)[] = VERSION_STRING;\n" + "const char GM_UNIQUENAME(Copyright)[] = COPYRIGHT_STRING;\n" + "\n" ); } @@ -754,7 +754,7 @@ static void writehandler(FILE *out, struct config *cfg) fprintf(out, " BPTR seg;\n" ); - + if (need_dos) { fprintf(out, " struct Library *ExpansionBase;\n" @@ -774,7 +774,7 @@ static void writehandler(FILE *out, struct config *cfg) ); } if (need_dos) { - fprintf(out, + fprintf(out, " ExpansionBase = OpenLibrary(\"expansion.library\", 36);\n" " if (ExpansionBase == NULL)\n" " return FALSE;\n" @@ -871,7 +871,7 @@ static void writehandler(FILE *out, struct config *cfg) " }\n" ); if (need_dos) { - fprintf(out, + fprintf(out, " CloseLibrary(ExpansionBase);\n" ); } @@ -890,13 +890,13 @@ static void writeinitlib(FILE *out, struct config *cfg) fprintf(out, "extern const LONG const __aros_libreq_SysBase __attribute__((weak));\n" "\n" - "AROS_UFH3 (LIBBASETYPEPTR, GM_UNIQUENAME(InitLib),\n" - " AROS_UFHA(LIBBASETYPEPTR, LIBBASE, D0),\n" - " AROS_UFHA(BPTR, segList, A0),\n" - " AROS_UFHA(struct ExecBase *, sysBase, A6)\n" - ")\n" - "{\n" - " AROS_USERFUNC_INIT\n" + "AROS_UFH3 (LIBBASETYPEPTR, GM_UNIQUENAME(InitLib),\n" + " AROS_UFHA(LIBBASETYPEPTR, LIBBASE, D0),\n" + " AROS_UFHA(BPTR, segList, A0),\n" + " AROS_UFHA(struct ExecBase *, sysBase, A6)\n" + ")\n" + "{\n" + " AROS_USERFUNC_INIT\n" ); if (cfg->modtype == HANDLER) { @@ -913,9 +913,9 @@ static void writeinitlib(FILE *out, struct config *cfg) } fprintf(out, - "\n" - " int ok;\n" - " int initcalled = 0;\n" + "\n" + " int ok;\n" + " int initcalled = 0;\n" ); /* Set the global SysBase, needed for __aros_setoffsettable()/__aros_getoffsettable() */ if (cfg->options & OPTION_DUPBASE) @@ -927,7 +927,7 @@ static void writeinitlib(FILE *out, struct config *cfg) " struct ExecBase *SysBase = sysBase;\n" ); fprintf(out, - "\n" + "\n" "#ifdef GM_SYSBASE_FIELD\n" " GM_SYSBASE_FIELD(LIBBASE) = (APTR)SysBase;\n" "#endif\n" @@ -972,7 +972,7 @@ static void writeinitlib(FILE *out, struct config *cfg) " ((struct Library*)LIBBASE)->lib_NegSize = vecsize;\n" " ((struct Library*)LIBBASE)->lib_PosSize = sizeof(LIBBASETYPE);\n" ); - + } } else @@ -1000,48 +1000,48 @@ static void writeinitlib(FILE *out, struct config *cfg) ); if (!(cfg->options & OPTION_NOEXPUNGE) && cfg->modtype!=RESOURCE) - fprintf(out, " GM_SEGLIST_FIELD(LIBBASE) = segList;\n"); + fprintf(out, " GM_SEGLIST_FIELD(LIBBASE) = segList;\n"); if (cfg->options & OPTION_DUPBASE) - fprintf(out, " GM_ROOTBASE_FIELD(LIBBASE) = (LIBBASETYPEPTR)LIBBASE;\n"); + fprintf(out, " GM_ROOTBASE_FIELD(LIBBASE) = (LIBBASETYPEPTR)LIBBASE;\n"); fprintf(out, " if ("); if (!(cfg->options & OPTION_NOAUTOLIB)) - fprintf(out, "set_open_libraries() && "); + fprintf(out, "set_open_libraries() && "); if (cfg->rellibs) fprintf(out, "set_open_rellibraries(LIBBASE) && "); fprintf(out, - "set_call_funcs(SETNAME(INIT), 1, 1) &&" + "set_call_funcs(SETNAME(INIT), 1, 1) &&" ); if (cfg->classlist != NULL) - fprintf(out, "set_call_libfuncs(SETNAME(CLASSESINIT), 1, 1, LIBBASE) && "); + fprintf(out, "set_call_libfuncs(SETNAME(CLASSESINIT), 1, 1, LIBBASE) && "); fprintf(out, - "1)\n" - " {\n" - " set_call_funcs(SETNAME(CTORS), -1, 0);\n" - " set_call_funcs(SETNAME(INIT_ARRAY), 1, 0);\n" - "\n" + "1)\n" + " {\n" + " set_call_funcs(SETNAME(CTORS), -1, 0);\n" + " set_call_funcs(SETNAME(INIT_ARRAY), 1, 0);\n" + "\n" ); - + fprintf(out, - " initcalled = 1;\n" - " ok = set_call_libfuncs(SETNAME(INITLIB), 1, 1, LIBBASE);\n" - " }\n" - " else\n" - " ok = 0;\n" - "\n" - " if (!ok)\n" - " {\n" - " if (initcalled)\n" - " set_call_libfuncs(SETNAME(EXPUNGELIB), -1, 0, LIBBASE);\n" - " set_call_funcs(SETNAME(FINI_ARRAY), -1, 0);\n" - " set_call_funcs(SETNAME(DTORS), 1, 0);\n" - " set_call_funcs(SETNAME(EXIT), -1, 0);\n" + " initcalled = 1;\n" + " ok = set_call_libfuncs(SETNAME(INITLIB), 1, 1, LIBBASE);\n" + " }\n" + " else\n" + " ok = 0;\n" + "\n" + " if (!ok)\n" + " {\n" + " if (initcalled)\n" + " set_call_libfuncs(SETNAME(EXPUNGELIB), -1, 0, LIBBASE);\n" + " set_call_funcs(SETNAME(FINI_ARRAY), -1, 0);\n" + " set_call_funcs(SETNAME(DTORS), 1, 0);\n" + " set_call_funcs(SETNAME(EXIT), -1, 0);\n" ); if (cfg->classlist != NULL) - fprintf(out, " set_call_libfuncs(SETNAME(CLASSESEXPUNGE), -1, 0, LIBBASE);\n"); + fprintf(out, " set_call_libfuncs(SETNAME(CLASSESEXPUNGE), -1, 0, LIBBASE);\n"); if (cfg->rellibs) fprintf(out, " set_close_rellibraries(LIBBASE);\n"); if (!(cfg->options & OPTION_NOAUTOLIB)) - fprintf(out, " set_close_libraries();\n"); + fprintf(out, " set_close_libraries();\n"); if (cfg->options & OPTION_RESAUTOINIT) { @@ -1058,37 +1058,37 @@ static void writeinitlib(FILE *out, struct config *cfg) ); } fprintf(out, - " return NULL;\n" - " }\n" - " else\n" - " {\n" + " return NULL;\n" + " }\n" + " else\n" + " {\n" ); if (!(cfg->options & OPTION_RESAUTOINIT) && !(cfg->options & OPTION_SELFINIT)) { - switch (cfg->modtype) - { - case RESOURCE: - fprintf(out, " AddResource(LIBBASE);\n"); - break; - - case DEVICE: - fprintf(out, " AddDevice(LIBBASE);\n"); - - default: - /* Everything else is library */ - fprintf(out, " AddLibrary(LIBBASE);\n"); - break; - } + switch (cfg->modtype) + { + case RESOURCE: + fprintf(out, " AddResource(LIBBASE);\n"); + break; + + case DEVICE: + fprintf(out, " AddDevice(LIBBASE);\n"); + + default: + /* Everything else is library */ + fprintf(out, " AddLibrary(LIBBASE);\n"); + break; + } } fprintf(out, - " return LIBBASE;\n" - " }\n" - "\n" - " AROS_USERFUNC_EXIT\n" - "}\n" - "\n" + " return LIBBASE;\n" + " }\n" + "\n" + " AROS_USERFUNC_EXIT\n" + "}\n" + "\n" ); } @@ -1097,104 +1097,104 @@ static void writeopenlib(FILE *out, struct config *cfg) switch (cfg->modtype) { case RESOURCE: - fprintf(stderr, "Internal error: writeopenlib called for a resource\n"); - break; + fprintf(stderr, "Internal error: writeopenlib called for a resource\n"); + break; case HANDLER: - fprintf(stderr, "Internal error: writeopenlib called for a handler\n"); - break; + fprintf(stderr, "Internal error: writeopenlib called for a handler\n"); + break; case DEVICE: - if (cfg->options & OPTION_NOOPENCLOSE) - fprintf(out, - "AROS_LD3 (void, GM_UNIQUENAME(OpenLib),\n" - " AROS_LDA(struct IORequest *, ioreq, A1),\n" - " AROS_LDA(ULONG, unitnum, D0),\n" - " AROS_LDA(ULONG, flags, D1),\n" - " LIBBASETYPEPTR, LIBBASE, 1, %s\n" - ");\n", - cfg->basename - ); - else - { - fprintf(out, - "AROS_LH3 (void, GM_UNIQUENAME(OpenLib),\n" - " AROS_LHA(struct IORequest *, ioreq, A1),\n" - " AROS_LHA(IPTR, unitnum, D0),\n" - " AROS_LHA(ULONG, flags, D1),\n" - " LIBBASETYPEPTR, LIBBASE, 1, %s\n" - ")\n", - cfg->basename - ); - fprintf(out, - "{\n" - " AROS_LIBFUNC_INIT\n" - "\n" - " if ( set_call_libfuncs(SETNAME(OPENLIB), 1, 1, LIBBASE)\n" - " && set_call_devfuncs(SETNAME(OPENDEV), 1, 1, LIBBASE, ioreq, unitnum, flags)\n" - " )\n" - " {\n" - " ((struct Library *)LIBBASE)->lib_OpenCnt++;\n" - " ((struct Library *)LIBBASE)->lib_Flags &= ~LIBF_DELEXP;\n" - "\n" - " ioreq->io_Message.mn_Node.ln_Type = NT_REPLYMSG;\n" - " }\n" - " else\n" - " {\n" - " if (ioreq->io_Error >= 0)\n" - " ioreq->io_Error = IOERR_OPENFAIL;\n" - " }\n" - "\n" - " return;\n" - "\n" - " AROS_LIBFUNC_EXIT\n" - "}\n" - "\n" - ); - } - break; + if (cfg->options & OPTION_NOOPENCLOSE) + fprintf(out, + "AROS_LD3 (void, GM_UNIQUENAME(OpenLib),\n" + " AROS_LDA(struct IORequest *, ioreq, A1),\n" + " AROS_LDA(ULONG, unitnum, D0),\n" + " AROS_LDA(ULONG, flags, D1),\n" + " LIBBASETYPEPTR, LIBBASE, 1, %s\n" + ");\n", + cfg->basename + ); + else + { + fprintf(out, + "AROS_LH3 (void, GM_UNIQUENAME(OpenLib),\n" + " AROS_LHA(struct IORequest *, ioreq, A1),\n" + " AROS_LHA(IPTR, unitnum, D0),\n" + " AROS_LHA(ULONG, flags, D1),\n" + " LIBBASETYPEPTR, LIBBASE, 1, %s\n" + ")\n", + cfg->basename + ); + fprintf(out, + "{\n" + " AROS_LIBFUNC_INIT\n" + "\n" + " if ( set_call_libfuncs(SETNAME(OPENLIB), 1, 1, LIBBASE)\n" + " && set_call_devfuncs(SETNAME(OPENDEV), 1, 1, LIBBASE, ioreq, unitnum, flags)\n" + " )\n" + " {\n" + " ((struct Library *)LIBBASE)->lib_OpenCnt++;\n" + " ((struct Library *)LIBBASE)->lib_Flags &= ~LIBF_DELEXP;\n" + "\n" + " ioreq->io_Message.mn_Node.ln_Type = NT_REPLYMSG;\n" + " }\n" + " else\n" + " {\n" + " if (ioreq->io_Error >= 0)\n" + " ioreq->io_Error = IOERR_OPENFAIL;\n" + " }\n" + "\n" + " return;\n" + "\n" + " AROS_LIBFUNC_EXIT\n" + "}\n" + "\n" + ); + } + break; default: - if (cfg->options & OPTION_NOOPENCLOSE) - { - fprintf(out, - "AROS_LD1 (LIBBASETYPEPTR, GM_UNIQUENAME(OpenLib),\n" - " AROS_LDA (ULONG, version, D0),\n" - " LIBBASETYPEPTR, LIBBASE, 1, %s\n" - ");\n", - cfg->basename - ); - return; - } - fprintf(out, - "AROS_LH1 (LIBBASETYPEPTR, GM_UNIQUENAME(OpenLib),\n" - " AROS_LHA (ULONG, version, D0),\n" - " LIBBASETYPEPTR, LIBBASE, 1, %s\n" - ")\n" - "{\n" - " AROS_LIBFUNC_INIT\n" - "\n", - cfg->basename - ); - if (!(cfg->options & OPTION_DUPBASE)) - { + if (cfg->options & OPTION_NOOPENCLOSE) + { fprintf(out, - " if ( set_call_libfuncs(SETNAME(OPENLIB), 1, 1, LIBBASE) )\n" - " {\n" - " ((struct Library *)LIBBASE)->lib_OpenCnt++;\n" - " ((struct Library *)LIBBASE)->lib_Flags &= ~LIBF_DELEXP;\n" - " return LIBBASE;\n" - " }\n" - "\n" - " return NULL;\n" - "\n" - " AROS_LIBFUNC_EXIT\n" - "}\n" - "\n" - ); - } - else /* OPTION_DUPBASE */ - { - fprintf(out, - " struct Library *newlib = NULL;\n" - " UWORD possize = ((struct Library *)LIBBASE)->lib_PosSize;\n" + "AROS_LD1 (LIBBASETYPEPTR, GM_UNIQUENAME(OpenLib),\n" + " AROS_LDA (ULONG, version, D0),\n" + " LIBBASETYPEPTR, LIBBASE, 1, %s\n" + ");\n", + cfg->basename + ); + return; + } + fprintf(out, + "AROS_LH1 (LIBBASETYPEPTR, GM_UNIQUENAME(OpenLib),\n" + " AROS_LHA (ULONG, version, D0),\n" + " LIBBASETYPEPTR, LIBBASE, 1, %s\n" + ")\n" + "{\n" + " AROS_LIBFUNC_INIT\n" + "\n", + cfg->basename + ); + if (!(cfg->options & OPTION_DUPBASE)) + { + fprintf(out, + " if ( set_call_libfuncs(SETNAME(OPENLIB), 1, 1, LIBBASE) )\n" + " {\n" + " ((struct Library *)LIBBASE)->lib_OpenCnt++;\n" + " ((struct Library *)LIBBASE)->lib_Flags &= ~LIBF_DELEXP;\n" + " return LIBBASE;\n" + " }\n" + "\n" + " return NULL;\n" + "\n" + " AROS_LIBFUNC_EXIT\n" + "}\n" + "\n" + ); + } + else /* OPTION_DUPBASE */ + { + fprintf(out, + " struct Library *newlib = NULL;\n" + " UWORD possize = ((struct Library *)LIBBASE)->lib_PosSize;\n" " LIBBASETYPEPTR oldbase = (LIBBASETYPEPTR)__aros_getbase_%s();\n", cfg->libbase ); @@ -1218,22 +1218,22 @@ static void writeopenlib(FILE *out, struct config *cfg) ); fprintf(out, - "\n" + "\n" " if (newlib == NULL)\n" " {\n" - " newlib = MakeLibrary(GM_UNIQUENAME(InitTable).FuncTable,\n" - " GM_UNIQUENAME(InitTable).DataTable,\n" - " NULL,\n" - " GM_UNIQUENAME(InitTable).Size,\n" - " (BPTR)NULL\n" - " );\n" - " if (newlib == NULL)\n" - " return NULL;\n" - "\n" - " CopyMem(LIBBASE, newlib, possize);\n" + " newlib = MakeLibrary(GM_UNIQUENAME(InitTable).FuncTable,\n" + " GM_UNIQUENAME(InitTable).DataTable,\n" + " NULL,\n" + " GM_UNIQUENAME(InitTable).Size,\n" + " (BPTR)NULL\n" + " );\n" + " if (newlib == NULL)\n" + " return NULL;\n" + "\n" + " CopyMem(LIBBASE, newlib, possize);\n" " struct __GM_DupBase *dupbase = (struct __GM_DupBase *)newlib;\n" " dupbase->oldbase = oldbase;\n" - " __aros_setoffsettable((char *)newlib);\n" + " __aros_setoffsettable((char *)newlib);\n" ); if (cfg->options & OPTION_PERTASKBASE) fprintf(out, @@ -1245,31 +1245,31 @@ static void writeopenlib(FILE *out, struct config *cfg) " __GM_SetPerTaskBase((LIBBASETYPEPTR)newlib);\n" ); fprintf(out, - "\n" - " if (!(set_open_rellibraries(newlib)\n" + "\n" + " if (!(set_open_rellibraries(newlib)\n" " && set_call_libfuncs(SETNAME(OPENLIB), 1, 1, newlib)\n" " )\n" " )\n" - " {\n"); - if (cfg->options & OPTION_PERTASKBASE) - fprintf(out, - " __GM_SetPerTaskBase(oldpertaskbase);\n"); - fprintf(out, - " __freebase(newlib);\n" - " return NULL;\n" - " }\n" - "\n" - " ((struct Library *)LIBBASE)->lib_OpenCnt++;\n" - " ((struct Library *)LIBBASE)->lib_Flags &= ~LIBF_DELEXP;\n" + " {\n"); + if (cfg->options & OPTION_PERTASKBASE) + fprintf(out, + " __GM_SetPerTaskBase(oldpertaskbase);\n"); + fprintf(out, + " __freebase(newlib);\n" + " return NULL;\n" + " }\n" + "\n" + " ((struct Library *)LIBBASE)->lib_OpenCnt++;\n" + " ((struct Library *)LIBBASE)->lib_Flags &= ~LIBF_DELEXP;\n" " }\n" - "\n" - " return (LIBBASETYPEPTR)newlib;\n" - "\n" - " AROS_LIBFUNC_EXIT\n" - "}\n" - "\n" - ); - } + "\n" + " return (LIBBASETYPEPTR)newlib;\n" + "\n" + " AROS_LIBFUNC_EXIT\n" + "}\n" + "\n" + ); + } } } @@ -1278,62 +1278,62 @@ static void writecloselib(FILE *out, struct config *cfg) { if (cfg->options & OPTION_NOOPENCLOSE) { - if (cfg->modtype != DEVICE) - fprintf(out, - "AROS_LD0 (BPTR, GM_UNIQUENAME(CloseLib),\n" - " LIBBASETYPEPTR, LIBBASE, 2, %s\n" - ");\n", - cfg->basename - ); - else - fprintf(out, - "AROS_LD1(BPTR, GM_UNIQUENAME(CloseLib),\n" - " AROS_LDA(struct IORequest *, ioreq, A1),\n" - " LIBBASETYPEPTR, LIBBASE, 2, %s\n" - ");\n", - cfg->basename - ); - return; + if (cfg->modtype != DEVICE) + fprintf(out, + "AROS_LD0 (BPTR, GM_UNIQUENAME(CloseLib),\n" + " LIBBASETYPEPTR, LIBBASE, 2, %s\n" + ");\n", + cfg->basename + ); + else + fprintf(out, + "AROS_LD1(BPTR, GM_UNIQUENAME(CloseLib),\n" + " AROS_LDA(struct IORequest *, ioreq, A1),\n" + " LIBBASETYPEPTR, LIBBASE, 2, %s\n" + ");\n", + cfg->basename + ); + return; } if (cfg->modtype != DEVICE) - fprintf(out, - "AROS_LH0 (BPTR, GM_UNIQUENAME(CloseLib),\n" - " LIBBASETYPEPTR, LIBBASE, 2, %s\n" - ")\n", - cfg->basename - ); + fprintf(out, + "AROS_LH0 (BPTR, GM_UNIQUENAME(CloseLib),\n" + " LIBBASETYPEPTR, LIBBASE, 2, %s\n" + ")\n", + cfg->basename + ); else - fprintf(out, - "AROS_LH1(BPTR, GM_UNIQUENAME(CloseLib),\n" - " AROS_LHA(struct IORequest *, ioreq, A1),\n" - " LIBBASETYPEPTR, LIBBASE, 2, %s\n" - ")\n", - cfg->basename - ); - + fprintf(out, + "AROS_LH1(BPTR, GM_UNIQUENAME(CloseLib),\n" + " AROS_LHA(struct IORequest *, ioreq, A1),\n" + " LIBBASETYPEPTR, LIBBASE, 2, %s\n" + ")\n", + cfg->basename + ); + fprintf(out, - "{\n" - " AROS_LIBFUNC_INIT\n" - "\n" + "{\n" + " AROS_LIBFUNC_INIT\n" + "\n" ); if (cfg->modtype == DEVICE) - fprintf(out, - " if (!set_call_devfuncs(SETNAME(CLOSEDEV), -1, 1, LIBBASE, ioreq, 0, 0))\n" + fprintf(out, + " if (!set_call_devfuncs(SETNAME(CLOSEDEV), -1, 1, LIBBASE, ioreq, 0, 0))\n" " {\n" - " return BNULL;\n" + " return BNULL;\n" " }\n" - ); + ); if (!(cfg->options & OPTION_DUPBASE)) { - fprintf(out, - " ((struct Library *)LIBBASE)->lib_OpenCnt--;\n" - " set_call_libfuncs(SETNAME(CLOSELIB), -1, 0, LIBBASE);\n" - ); + fprintf(out, + " ((struct Library *)LIBBASE)->lib_OpenCnt--;\n" + " set_call_libfuncs(SETNAME(CLOSELIB), -1, 0, LIBBASE);\n" + ); } else /* OPTION_DUPBASE */ { - fprintf(out, - " LIBBASETYPEPTR rootbase = GM_ROOTBASE_FIELD(LIBBASE);\n" + fprintf(out, + " LIBBASETYPEPTR rootbase = GM_ROOTBASE_FIELD(LIBBASE);\n" " struct __GM_DupBase *dupbase = (struct __GM_DupBase *)LIBBASE;\n" " __aros_setoffsettable(LIBBASE);\n" ); @@ -1345,7 +1345,7 @@ static void writecloselib(FILE *out, struct config *cfg) ); fprintf(out, "\n" - " set_call_libfuncs(SETNAME(CLOSELIB), -1, 0, LIBBASE);\n" + " set_call_libfuncs(SETNAME(CLOSELIB), -1, 0, LIBBASE);\n" " set_close_rellibraries(LIBBASE);\n" " __aros_setoffsettable((char *)dupbase->oldbase);\n" ); @@ -1355,33 +1355,33 @@ static void writecloselib(FILE *out, struct config *cfg) ); fprintf(out, " __freebase(LIBBASE);\n" - " LIBBASE = rootbase;\n" - " ((struct Library *)LIBBASE)->lib_OpenCnt--;\n" - "\n" - ); + " LIBBASE = rootbase;\n" + " ((struct Library *)LIBBASE)->lib_OpenCnt--;\n" + "\n" + ); } if (!(cfg->options & OPTION_NOEXPUNGE)) - fprintf(out, - " if\n" - " (\n" - " (((struct Library *)LIBBASE)->lib_OpenCnt == 0)\n" - " && (((struct Library *)LIBBASE)->lib_Flags & LIBF_DELEXP)\n" - " )\n" - " {\n" - " return AROS_LC1(BPTR, GM_UNIQUENAME(ExpungeLib),\n" - " AROS_LCA(LIBBASETYPEPTR, LIBBASE, D0),\n" - " LIBBASETYPEPTR, LIBBASE, 3, %s\n" - " );\n" - " }\n", - cfg->basename - ); + fprintf(out, + " if\n" + " (\n" + " (((struct Library *)LIBBASE)->lib_OpenCnt == 0)\n" + " && (((struct Library *)LIBBASE)->lib_Flags & LIBF_DELEXP)\n" + " )\n" + " {\n" + " return AROS_LC1(BPTR, GM_UNIQUENAME(ExpungeLib),\n" + " AROS_LCA(LIBBASETYPEPTR, LIBBASE, D0),\n" + " LIBBASETYPEPTR, LIBBASE, 3, %s\n" + " );\n" + " }\n", + cfg->basename + ); fprintf(out, - "\n" - " return BNULL;\n" - "\n" - " AROS_LIBFUNC_EXIT\n" - "}\n" - "\n" + "\n" + " return BNULL;\n" + "\n" + " AROS_LIBFUNC_EXIT\n" + "}\n" + "\n" ); } @@ -1389,16 +1389,16 @@ static void writecloselib(FILE *out, struct config *cfg) static void writeexpungelib(FILE *out, struct config *cfg) { fprintf(out, - "AROS_LH1 (BPTR, GM_UNIQUENAME(ExpungeLib),\n" - " AROS_LHA(LIBBASETYPEPTR, extralh, D0),\n" - " LIBBASETYPEPTR, LIBBASE, 3, %s\n" - ")\n", - cfg->basename + "AROS_LH1 (BPTR, GM_UNIQUENAME(ExpungeLib),\n" + " AROS_LHA(LIBBASETYPEPTR, extralh, D0),\n" + " LIBBASETYPEPTR, LIBBASE, 3, %s\n" + ")\n", + cfg->basename ); fprintf(out, - "{\n" - " AROS_LIBFUNC_INIT\n" - "\n" + "{\n" + " AROS_LIBFUNC_INIT\n" + "\n" ); if (!(cfg->options & OPTION_NOEXPUNGE)) { @@ -1411,56 +1411,56 @@ static void writeexpungelib(FILE *out, struct config *cfg) } if (cfg->options & OPTION_DUPBASE) fprintf(out, " __aros_setoffsettable(LIBBASE);\n"); - fprintf(out, - "\n" - " if ( ((struct Library *)LIBBASE)->lib_OpenCnt == 0 )\n" - " {\n" - " BPTR seglist = GM_SEGLIST_FIELD(LIBBASE);\n" - "\n" - " if(!set_call_libfuncs(SETNAME(EXPUNGELIB), -1, 1, LIBBASE))\n" - " {\n" - " ((struct Library *)LIBBASE)->lib_Flags |= LIBF_DELEXP;\n" - " return BNULL;\n" - " }\n" - "\n" - " Remove((struct Node *)LIBBASE);\n" - "\n" - " set_call_funcs(SETNAME(FINI_ARRAY), -1, 0);\n" - " set_call_funcs(SETNAME(DTORS), 1, 0);\n" - " set_call_funcs(SETNAME(EXIT), -1, 0);\n" - ); - if (cfg->classlist != NULL) - fprintf(out, " set_call_libfuncs(SETNAME(CLASSESEXPUNGE), -1, 0, LIBBASE);\n"); + fprintf(out, + "\n" + " if ( ((struct Library *)LIBBASE)->lib_OpenCnt == 0 )\n" + " {\n" + " BPTR seglist = GM_SEGLIST_FIELD(LIBBASE);\n" + "\n" + " if(!set_call_libfuncs(SETNAME(EXPUNGELIB), -1, 1, LIBBASE))\n" + " {\n" + " ((struct Library *)LIBBASE)->lib_Flags |= LIBF_DELEXP;\n" + " return BNULL;\n" + " }\n" + "\n" + " Remove((struct Node *)LIBBASE);\n" + "\n" + " set_call_funcs(SETNAME(FINI_ARRAY), -1, 0);\n" + " set_call_funcs(SETNAME(DTORS), 1, 0);\n" + " set_call_funcs(SETNAME(EXIT), -1, 0);\n" + ); + if (cfg->classlist != NULL) + fprintf(out, " set_call_libfuncs(SETNAME(CLASSESEXPUNGE), -1, 0, LIBBASE);\n"); if (cfg->rellibs) - fprintf(out, " set_close_rellibraries(LIBBASE);\n"); - if (!(cfg->options & OPTION_NOAUTOLIB)) - fprintf(out, " set_close_libraries();\n" - "#ifdef GM_OOPBASE_FIELD\n" - " CloseLibrary((struct Library *)GM_OOPBASE_FIELD(LIBBASE));\n" - "#endif\n" - ); + fprintf(out, " set_close_rellibraries(LIBBASE);\n"); + if (!(cfg->options & OPTION_NOAUTOLIB)) + fprintf(out, " set_close_libraries();\n" + "#ifdef GM_OOPBASE_FIELD\n" + " CloseLibrary((struct Library *)GM_OOPBASE_FIELD(LIBBASE));\n" + "#endif\n" + ); if (cfg->options & OPTION_PERTASKBASE) fprintf(out, " FreeTaskStorageSlot(__pertaskslot);\n" " __pertaskslot = 0;\n" ); fprintf(out, - "\n" - " __freebase(LIBBASE);\n" - "\n" - " return seglist;\n" - " }\n" - "\n" - " ((struct Library *)LIBBASE)->lib_Flags |= LIBF_DELEXP;\n" - ); + "\n" + " __freebase(LIBBASE);\n" + "\n" + " return seglist;\n" + " }\n" + "\n" + " ((struct Library *)LIBBASE)->lib_Flags |= LIBF_DELEXP;\n" + ); } fprintf(out, - "\n" - " return BNULL;\n" - "\n" - " AROS_LIBFUNC_EXIT\n" - "}\n" - "\n" + "\n" + " return BNULL;\n" + "\n" + " AROS_LIBFUNC_EXIT\n" + "}\n" + "\n" ); } @@ -1468,23 +1468,23 @@ static void writeexpungelib(FILE *out, struct config *cfg) static void writeextfunclib(FILE *out, struct config *cfg) { fprintf(out, - "AROS_LH0 (LIBBASETYPEPTR, GM_UNIQUENAME(ExtFuncLib),\n" - " LIBBASETYPEPTR, LIBBASE, 4, %s\n" - ")\n" - "{\n" - " AROS_LIBFUNC_INIT\n" - " return NULL;\n" - " AROS_LIBFUNC_EXIT\n" - "}\n" - "\n", - cfg->basename + "AROS_LH0 (LIBBASETYPEPTR, GM_UNIQUENAME(ExtFuncLib),\n" + " LIBBASETYPEPTR, LIBBASE, 4, %s\n" + ")\n" + "{\n" + " AROS_LIBFUNC_INIT\n" + " return NULL;\n" + " AROS_LIBFUNC_EXIT\n" + "}\n" + "\n", + cfg->basename ); } static void writefunctable(FILE *out, - struct config *cfg + struct config *cfg ) { struct functionhead *funclistit = cfg->funclist; @@ -1493,198 +1493,198 @@ writefunctable(FILE *out, int i; char *name, *type; int lastversion = 0; - + /* lvo contains the number of functions already printed in the functable */ lvo = 0; - + if (!(cfg->options & OPTION_NORESIDENT)) { - fprintf(out, - "\n" - "const APTR GM_UNIQUENAME(FuncTable)[]=\n" - "{\n" - ); - if (cfg->modtype != RESOURCE && cfg->modtype != HANDLER) - { - fprintf(out, - " &AROS_SLIB_ENTRY(GM_UNIQUENAME(OpenLib),%s,1),\n" - " &AROS_SLIB_ENTRY(GM_UNIQUENAME(CloseLib),%s,2),\n" - " &AROS_SLIB_ENTRY(GM_UNIQUENAME(ExpungeLib),%s,3),\n" - " &AROS_SLIB_ENTRY(GM_UNIQUENAME(ExtFuncLib),%s,4),\n", - cfg->basename, cfg->basename, cfg->basename, cfg->basename - ); - lvo += 4; - } + fprintf(out, + "\n" + "const APTR GM_UNIQUENAME(FuncTable)[]=\n" + "{\n" + ); + if (cfg->modtype != RESOURCE && cfg->modtype != HANDLER) + { + fprintf(out, + " &AROS_SLIB_ENTRY(GM_UNIQUENAME(OpenLib),%s,1),\n" + " &AROS_SLIB_ENTRY(GM_UNIQUENAME(CloseLib),%s,2),\n" + " &AROS_SLIB_ENTRY(GM_UNIQUENAME(ExpungeLib),%s,3),\n" + " &AROS_SLIB_ENTRY(GM_UNIQUENAME(ExtFuncLib),%s,4),\n", + cfg->basename, cfg->basename, cfg->basename, cfg->basename + ); + lvo += 4; + } if (cfg->modtype == MCC || cfg->modtype == MUI || cfg->modtype == MCP) - { - lvo++; - fprintf(out, - " &AROS_SLIB_ENTRY(MCC_Query,%s,%d),\n", - cfg->basename, lvo - ); - } + { + lvo++; + fprintf(out, + " &AROS_SLIB_ENTRY(MCC_Query,%s,%d),\n", + cfg->basename, lvo + ); + } else if (cfg->modtype == DATATYPE) - { - lvo++; - fprintf(out, - " &AROS_SLIB_ENTRY(ObtainEngine,%s,%d),\n", - cfg->basename, lvo - ); - } + { + lvo++; + fprintf(out, + " &AROS_SLIB_ENTRY(ObtainEngine,%s,%d),\n", + cfg->basename, lvo + ); + } } else /* NORESIDENT */ { - if (cfg->modtype != RESOURCE && cfg->modtype != HANDLER) - { - int neednull = 0; - struct functionhead *funclistit2; - - if (funclistit->lvo != 1) - { - fprintf(stderr, "Module without a generated resident structure has to provide the Open function (LVO==1)\n"); - exit(20); - } - else - funclistit = funclistit->next; - - if (funclistit->lvo != 2) - { - fprintf(stderr, "Module without a generated resident structure has to provide the Close function (LVO==2)\n"); - exit(20); - } - else - funclistit = funclistit->next; - - if (funclistit->lvo == 3) - funclistit = funclistit->next; - else - neednull = 1; - - if (funclistit->lvo == 4) - funclistit = funclistit->next; - else - neednull = 1; - - if (neednull) - fprintf(out, - "\n" - "AROS_UFH1S(int, %s_null,\n" - " AROS_UFHA(struct Library *, libbase, A6)\n" - ")\n" - "{\n" - " AROS_USERFUNC_INIT\n" - " return 0;\n" - " AROS_USERFUNC_EXIT\n" - "}\n", - cfg->modulename - ); - - funclistit = cfg->funclist; - funclistit2 = funclistit->next; - fprintf(out, - "\n" - "const APTR GM_UNIQUENAME(FuncTable)[]=\n" - "{\n" - " &AROS_SLIB_ENTRY(%s,%s,%d),\n" - " &AROS_SLIB_ENTRY(%s,%s,%d),\n", - funclistit->internalname, cfg->basename, lvo+1, - funclistit2->internalname, cfg->basename, lvo+2 - ); - lvo += 2; - funclistit = funclistit2->next; - - if (funclistit->lvo == 3) - { - fprintf(out, " &AROS_SLIB_ENTRY(%s,%s,%d),\n", - funclistit->internalname, cfg->basename, lvo+1 - ); - funclistit = funclistit->next; - } - else - fprintf(out, " &%s_null,\n", cfg->modulename); - lvo++; - - if (funclistit->lvo == 4) - { - fprintf(out, " &AROS_SLIB_ENTRY(%s,%s,%d),\n", - funclistit->internalname, cfg->basename, lvo+1 - ); - funclistit = funclistit->next; - } - else - fprintf(out, " &%s_null,\n", cfg->modulename); - lvo++; - } - else - { - fprintf(out, - "\n" - "const APTR GM_UNIQUENAME(FuncTable)[]=\n" - "{\n"); - } + if (cfg->modtype != RESOURCE && cfg->modtype != HANDLER) + { + int neednull = 0; + struct functionhead *funclistit2; + + if (funclistit->lvo != 1) + { + fprintf(stderr, "Module without a generated resident structure has to provide the Open function (LVO==1)\n"); + exit(20); + } + else + funclistit = funclistit->next; + + if (funclistit->lvo != 2) + { + fprintf(stderr, "Module without a generated resident structure has to provide the Close function (LVO==2)\n"); + exit(20); + } + else + funclistit = funclistit->next; + + if (funclistit->lvo == 3) + funclistit = funclistit->next; + else + neednull = 1; + + if (funclistit->lvo == 4) + funclistit = funclistit->next; + else + neednull = 1; + + if (neednull) + fprintf(out, + "\n" + "AROS_UFH1S(int, %s_null,\n" + " AROS_UFHA(struct Library *, libbase, A6)\n" + ")\n" + "{\n" + " AROS_USERFUNC_INIT\n" + " return 0;\n" + " AROS_USERFUNC_EXIT\n" + "}\n", + cfg->modulename + ); + + funclistit = cfg->funclist; + funclistit2 = funclistit->next; + fprintf(out, + "\n" + "const APTR GM_UNIQUENAME(FuncTable)[]=\n" + "{\n" + " &AROS_SLIB_ENTRY(%s,%s,%d),\n" + " &AROS_SLIB_ENTRY(%s,%s,%d),\n", + funclistit->internalname, cfg->basename, lvo+1, + funclistit2->internalname, cfg->basename, lvo+2 + ); + lvo += 2; + funclistit = funclistit2->next; + + if (funclistit->lvo == 3) + { + fprintf(out, " &AROS_SLIB_ENTRY(%s,%s,%d),\n", + funclistit->internalname, cfg->basename, lvo+1 + ); + funclistit = funclistit->next; + } + else + fprintf(out, " &%s_null,\n", cfg->modulename); + lvo++; + + if (funclistit->lvo == 4) + { + fprintf(out, " &AROS_SLIB_ENTRY(%s,%s,%d),\n", + funclistit->internalname, cfg->basename, lvo+1 + ); + funclistit = funclistit->next; + } + else + fprintf(out, " &%s_null,\n", cfg->modulename); + lvo++; + } + else + { + fprintf(out, + "\n" + "const APTR GM_UNIQUENAME(FuncTable)[]=\n" + "{\n"); + } } while (funclistit != NULL) { - for (i = lvo+1; ilvo; i++) - fprintf(out, " NULL,\n"); - lvo = funclistit->lvo; - - switch (funclistit->libcall) - { - case STACK: - case REGISTER: - case REGISTERMACRO: - if (funclistit->version != lastversion) { - lastversion = funclistit->version; - fprintf(out, " /* Version %d */\n", lastversion); - } - fprintf(out, " &AROS_SLIB_ENTRY(%s,%s,%d),\n", funclistit->internalname, cfg->basename, lvo); - break; - - default: - fprintf(stderr, "Internal error: unhandled libcall type in writestart\n"); - exit(20); - break; - } - - funclistit = funclistit->next; + for (i = lvo+1; ilvo; i++) + fprintf(out, " NULL,\n"); + lvo = funclistit->lvo; + + switch (funclistit->libcall) + { + case STACK: + case REGISTER: + case REGISTERMACRO: + if (funclistit->version != lastversion) { + lastversion = funclistit->version; + fprintf(out, " /* Version %d */\n", lastversion); + } + fprintf(out, " &AROS_SLIB_ENTRY(%s,%s,%d),\n", funclistit->internalname, cfg->basename, lvo); + break; + + default: + fprintf(stderr, "Internal error: unhandled libcall type in writestart\n"); + exit(20); + break; + } + + funclistit = funclistit->next; } fprintf(out, " (void *)-1\n};\n"); } - + static void writesets(FILE *out, struct config *cfg) { fprintf(out, - "DEFINESET(INIT)\n" - "DEFINESET(EXIT)\n" + "DEFINESET(INIT)\n" + "DEFINESET(EXIT)\n" ); if (cfg->modtype != HANDLER) - fprintf(out, - "DEFINESET(CTORS)\n" - "DEFINESET(DTORS)\n" - "DEFINESET(INIT_ARRAY)\n" - "DEFINESET(FINI_ARRAY)\n" - "DEFINESET(INITLIB)\n" - "DEFINESET(EXPUNGELIB)\n" - ); + fprintf(out, + "DEFINESET(CTORS)\n" + "DEFINESET(DTORS)\n" + "DEFINESET(INIT_ARRAY)\n" + "DEFINESET(FINI_ARRAY)\n" + "DEFINESET(INITLIB)\n" + "DEFINESET(EXPUNGELIB)\n" + ); if (!(cfg->options & OPTION_NOOPENCLOSE)) fprintf(out, - "DEFINESET(OPENLIB)\n" - "DEFINESET(CLOSELIB)\n" - ); + "DEFINESET(OPENLIB)\n" + "DEFINESET(CLOSELIB)\n" + ); if (cfg->modtype == DEVICE) fprintf(out, - "DEFINESET(OPENDEV)\n" - "DEFINESET(CLOSEDEV)\n" + "DEFINESET(OPENDEV)\n" + "DEFINESET(CLOSEDEV)\n" ); if (cfg->classlist != NULL) - fprintf(out, - "DEFINESET(CLASSESINIT)\n" - "DEFINESET(CLASSESEXPUNGE)\n" - ); + fprintf(out, + "DEFINESET(CLASSESINIT)\n" + "DEFINESET(CLASSESEXPUNGE)\n" + ); fprintf(out, "\n"); } diff --git a/tools/genmodule/writestubs.c b/tools/genmodule/writestubs.c index a33c4af4e2..1e303760df 100644 --- a/tools/genmodule/writestubs.c +++ b/tools/genmodule/writestubs.c @@ -1,7 +1,7 @@ /* Copyright © 1995-2011, The AROS Development Team. All rights reserved. $Id$ - + Function to write module_stubs.c. Part of genmodule. */ @@ -67,22 +67,22 @@ void writestubs(struct config *cfg, int is_rel) } else { - fprintf(out, - "#include \n" - "#include \n\n" - ); + fprintf(out, + "#include \n" + "#include \n\n" + ); - for (linelistit = cfg->cdefprivatelines; linelistit!=NULL; linelistit = linelistit->next) - fprintf(out, "%s\n", linelistit->s); + for (linelistit = cfg->cdefprivatelines; linelistit!=NULL; linelistit = linelistit->next) + fprintf(out, "%s\n", linelistit->s); fprintf(out, - "\n" - "%s__aros_getbase_%s(void);\n" - "\n", - cfg->libbasetypeptrextern, cfg->libbase + "\n" + "%s__aros_getbase_%s(void);\n" + "\n", + cfg->libbasetypeptrextern, cfg->libbase ); } - + fprintf ( out, @@ -93,7 +93,7 @@ void writestubs(struct config *cfg, int is_rel) "#include \n" "\n" ); - + for (funclistit = cfg->funclist; funclistit!=NULL; funclistit = funclistit->next @@ -147,7 +147,7 @@ void writestubs(struct config *cfg, int is_rel) type = getargtype(arglistit); name = getargname(arglistit); assert(type != NULL && name != NULL); - + fprintf(out, " AROS_LCA(%s,%s,%s),\n", type, name, arglistit->reg ); @@ -185,7 +185,7 @@ void writestubs(struct config *cfg, int is_rel) type = getargtype(arglistit); name = getargname(arglistit); assert(type != NULL && name != NULL); - + if (quad2) { *quad2 = 0; fprintf(out, @@ -205,7 +205,7 @@ void writestubs(struct config *cfg, int is_rel) free(name); } } - + fprintf(out, " %s, __aros_getbase_%s(), %u, %s);\n}\n", cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename ); @@ -217,7 +217,7 @@ void writestubs(struct config *cfg, int is_rel) funclistit->name, cfg->libbase, funclistit->lvo ); } - + for (aliasesit = funclistit->aliases; aliasesit != NULL; aliasesit = aliasesit->next -- 2.11.4.GIT