FreeCalypso > hg > freecalypso-reveng
comparison leo-obj/tool/hints.c @ 130:87b82398a08b
leo-obj project subtree started, tiobjd tool moved into it
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 06 Apr 2014 22:14:39 +0000 |
parents | ticoff/hints.c@a314d6aa9bf1 |
children | c131238c56bf |
comparison
equal
deleted
inserted
replaced
129:597143ba1c37 | 130:87b82398a08b |
---|---|
1 /* | |
2 * Parsing of the disassembly hints file | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <ctype.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include "intstruct.h" | |
12 #include "globals.h" | |
13 | |
14 static char *filename_for_err; | |
15 static int lineno; | |
16 static struct internal_scnhdr *section; | |
17 static struct hint *lasthint; | |
18 | |
19 static void | |
20 set_section(name) | |
21 char *name; | |
22 { | |
23 unsigned n; | |
24 struct internal_scnhdr *sec = 0; | |
25 | |
26 for (n = 0; n < nsections; n++) | |
27 if (!strcmp(sections[n].name, name)) { | |
28 sec = sections + n; | |
29 break; | |
30 } | |
31 if (!sec) { | |
32 fprintf(stderr, "%s line %d: no section named \"%s\" in %s\n", | |
33 filename_for_err, lineno, name, objfilename); | |
34 exit(1); | |
35 } | |
36 if (sec->hints) { | |
37 fprintf(stderr, "%s line %d: [%s] given more than once\n", | |
38 filename_for_err, lineno, name); | |
39 exit(1); | |
40 } | |
41 section = sec; | |
42 lasthint = 0; | |
43 } | |
44 | |
45 static void | |
46 set_mode(arg) | |
47 char *arg; | |
48 { | |
49 char *cp; | |
50 | |
51 if (!section) { | |
52 fprintf(stderr, | |
53 "%s line %d: error: mode line outside of section\n", | |
54 filename_for_err, lineno); | |
55 exit(1); | |
56 } | |
57 while (isspace(*arg)) | |
58 arg++; | |
59 if (!*arg) { | |
60 fprintf(stderr, "%s line %d: mode line: missing argument\n", | |
61 filename_for_err, lineno); | |
62 exit(1); | |
63 } | |
64 for (cp = arg; *cp && !isspace(*cp); cp++) | |
65 ; | |
66 if (*cp) | |
67 *cp++ = '\0'; | |
68 if (!strcmp(arg, "code")) | |
69 section->disasm_mode = DISASM_MODE_CODE; | |
70 else if (!strcmp(arg, "data")) | |
71 section->disasm_mode = DISASM_MODE_DATA; | |
72 else if (!strcmp(arg, "bss")) | |
73 section->disasm_mode = DISASM_MODE_BSS; | |
74 else { | |
75 fprintf(stderr, "%s line %d: unknown mode \"%s\"\n", | |
76 filename_for_err, lineno, arg); | |
77 exit(1); | |
78 } | |
79 } | |
80 | |
81 static void | |
82 regular_hint(arg1, arg2) | |
83 char *arg1, *arg2; | |
84 { | |
85 fprintf(stderr, "error: regular hints not implemented yet\n"); | |
86 exit(1); | |
87 } | |
88 | |
89 read_hints_file(filename) | |
90 char *filename; | |
91 { | |
92 FILE *f; | |
93 char linebuf[128], *cp, *np; | |
94 | |
95 f = fopen(filename, "r"); | |
96 if (!f) { | |
97 perror(filename); | |
98 exit(1); | |
99 } | |
100 filename_for_err = filename; | |
101 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { | |
102 for (cp = linebuf; isspace(*cp); cp++) | |
103 ; | |
104 if (!*cp || *cp == '#') | |
105 continue; | |
106 if (*cp == '[') { | |
107 np = ++cp; | |
108 cp = index(cp, ']'); | |
109 if (!cp) { | |
110 fprintf(stderr, | |
111 "%s line %d: invalid section syntax\n", | |
112 filename, lineno); | |
113 exit(1); | |
114 } | |
115 *cp = '\0'; | |
116 set_section(np); | |
117 continue; | |
118 } | |
119 for (np = cp; *cp && !isspace(*cp); cp++) | |
120 ; | |
121 if (*cp) | |
122 *cp++ = '\0'; | |
123 if (!strcmp(np, "mode")) { | |
124 set_mode(cp); | |
125 continue; | |
126 } | |
127 regular_hint(np, cp); | |
128 } | |
129 fclose(f); | |
130 return(0); | |
131 } |