added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / tools / collect-aros / gensets.c
blobcef49983acd70cc7dd5ef8a330ea5007fd3c6315
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include <ctype.h>
10 #include <errno.h>
12 #include "misc.h"
14 typedef struct setnode
16 char *secname;
17 int off_setname;
18 long pri;
19 struct setnode *next;
20 } setnode;
22 static setnode *new_setnode(const char *name, setnode *next, int off, long pri){
23 setnode *n;
25 if (!(n = calloc(1, sizeof(setnode))) ||
26 !(n->secname = strdup(name))
29 fatal("new_setnode()", strerror(errno));
32 n->off_setname = off;
33 n->pri = pri;
34 n->next = next;
36 return n;
39 static setnode *get_setnode(setnode **list, const char *name, int off, long pri)
41 setnode **curr = list;
43 while (*curr)
45 if (strcmp((*curr)->secname, name) == 0)
49 if ((*curr)->pri == pri)
50 return *curr;
52 if ((*curr)->pri > pri)
53 break;
55 curr = &(*curr)->next;
57 } while (*curr && strcmp((*curr)->secname, name) == 0);
59 break;
62 curr = &(*curr)->next;
65 return (*curr = new_setnode(name, *curr, off, pri));
68 void emit_sets(setnode *setlist, FILE *out)
70 char setname_big[201];
71 int i;
73 while (setlist)
75 setnode *oldnode = setlist;
76 i = 0;
80 setname_big[i] = toupper(setlist->secname[setlist->off_setname + i]);
81 } while (setlist->secname[setlist->off_setname + i++]);
83 fprintf
85 out,
86 " __%s_LIST__ = .;\n"
87 " %s((__%s_END__ - __%s_LIST__) / %d - 2)\n",
88 setname_big, sizeof(long)==4?"LONG":"QUAD", setname_big, setname_big, sizeof(long)
93 fprintf
95 out,
96 " KEEP(*(%s.%ld))\n",
97 setlist->secname, setlist->pri
100 setlist = setlist->next;
101 } while (setlist && (strcmp(oldnode->secname, setlist->secname) == 0));
104 fprintf
106 out,
107 " KEEP(*(%s))\n"
108 " %s(0)\n"
109 " __%s_END__ = .;\n",
110 oldnode->secname, sizeof(long)==4?"LONG":"QUAD", setname_big
116 void parse_secname(const char *secname, setnode **setlist_ptr)
118 char *idx;
119 int off;
120 long pri = 0;
122 if (strncmp(secname, ".aros.set.", 10) == 0)
123 off = 10;
124 else
125 if (strncmp(secname, ".ctors", 5) == 0)
126 off = 1;
127 else
128 if (strncmp(secname, ".dtors", 5) == 0)
129 off = 1;
130 else
131 return;
133 idx = strchr(secname + off, '.');
134 if (idx)
136 *idx = '\0';
137 pri = strtol(&idx[1], NULL, 10);
140 get_setnode(setlist_ptr, secname, off, pri);