.gitignore: Update
[AROS.git] / tools / genmodule / writefd.c
blob023c050003cf4764e06b828fa3c3d5a938900dfc
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Write the functionlist to a FD file for identify.library.
6 */
8 #include "genmodule.h"
10 static void write_fd_func(FILE *out, struct functionhead *funclistit, unsigned int lvo)
12 struct functionarg *arglistit;
13 char *variable;
15 if (funclistit->lvo > lvo + 1)
17 if (funclistit->lvo == lvo + 2)
18 fprintf(out, "private()()\n");
19 else
20 fprintf(out, "##bias %u\n", funclistit->lvo * 6);
23 fprintf(out, "%s(", funclistit->name);
25 for (arglistit = funclistit->arguments;
26 arglistit!=NULL;
27 arglistit = arglistit->next)
29 /* Print a , separator when not the first function argument */
30 if (arglistit != funclistit->arguments)
31 fprintf(out, ",");
33 /* Print only variable name */
34 variable = arglistit->arg + strlen(arglistit->arg) - 1;
35 while ((variable >= arglistit->arg) &&
36 (isalnum(*variable) || (*variable == '_')))
38 variable--;
40 fprintf(out, "%s", variable + 1);
42 fprintf(out, ")(");
45 void writefd(struct config *cfg)
47 FILE *out;
48 char line[256];
49 struct functionhead *funclistit = cfg->funclist;
50 struct functionarg *arglistit;
51 unsigned int lvo;
52 char *lower;
54 if (cfg->modtype == DEVICE)
56 /* Skip BeginIO/EndIO */
57 unsigned int i;
59 for (i = 0; i < 2; i++)
61 if (!funclistit)
62 return;
64 funclistit = funclistit->next;
68 if (!funclistit)
69 return;
71 snprintf(line, 255, "%s/%s_lib.fd", cfg->gendir, cfg->modulename);
73 out = fopen(line, "w");
75 if (out == NULL)
77 perror(line);
78 exit(20);
80 else
82 fprintf(out, "##base _%s\n", cfg->libbase);
85 * This is correct even for devices. cfg->firstlvo holds LVO number for
86 * the first user function.
88 fprintf(out, "##bias %u\n", cfg->firstlvo * 6);
90 fprintf(out, "*\n"
91 "* Automatically generated from '%s'.\n"
92 "* Edits will be lost. This file is supposed to be a support file for identify.library.\n"
93 "*\n",
94 cfg->conffile
97 fprintf(out, "##public\n");
99 for (lvo = cfg->firstlvo - 1;
100 funclistit != NULL;
101 funclistit = funclistit->next
104 switch (funclistit->libcall)
106 case REGISTERMACRO:
107 write_fd_func(out, funclistit, lvo);
109 for (arglistit = funclistit->arguments;
110 arglistit != NULL;
111 arglistit = arglistit->next
114 /* Print a , separator when not the first function argument */
115 if (arglistit != funclistit->arguments)
116 fprintf(out, ",");
118 /* Print register name in lower case */
119 for (lower = arglistit->reg; *lower != '\0'; lower++)
121 fputc(tolower(*lower), out);
124 fprintf(out, ")\n");
126 lvo = funclistit->lvo;
127 break;
129 case STACK:
130 write_fd_func(out, funclistit, lvo);
131 fprintf(out, "sysv");
132 if (cfg->options & OPTION_DUPBASE)
133 fprintf(out, ",rbase");
134 fprintf(out, ")\n");
136 lvo = funclistit->lvo;
137 break;
141 fprintf(out, "##end\n");
143 if (ferror(out))
145 perror(line);
146 exit(20);
149 fclose(out);