Debian Codegraph @

output/outform.c

raw
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /* Copyright 1996-2011 The NASM Authors - All Rights Reserved */
3
4 /*
5 * outform.c manages a list of output formats, and associates
6 * them with their relevant drivers. Also has a
7 * routine to find the correct driver given a name
8 * for it
9 */
10
11 #include "compiler.h"
12
13
14 #define BUILD_DRIVERS_ARRAY
15 #include "outform.h"
16 #include "outlib.h"
17
18 const struct ofmt *ofmt_find(const char *name,
19 const struct ofmt_alias **ofmt_alias)
20 {
21 const struct ofmt * const *ofp;
22 const struct ofmt *of;
23 unsigned int i;
24
25 *ofmt_alias = NULL;
26
27 /* primary targets first */
28 for (ofp = drivers; (of = *ofp); ofp++) {
29 if (!nasm_stricmp(name, of->shortname))
30 return of;
31 }
32
33 /* lets walk thru aliases then */
34 for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
35 if (ofmt_aliases[i].shortname &&
36 !nasm_stricmp(name, ofmt_aliases[i].shortname)) {
37 *ofmt_alias = &ofmt_aliases[i];
38 return ofmt_aliases[i].ofmt;
39 }
40 }
41
42 return NULL;
43 }
44
45 const struct dfmt *dfmt_find(const struct ofmt *ofmt, const char *name)
46 {
47 const struct dfmt * const *dfp;
48 const struct dfmt *df;
49
50 for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
51 if (!nasm_stricmp(name, df->shortname))
52 return df;
53 }
54 return NULL;
55 }
56
57 void ofmt_list(const struct ofmt *deffmt, FILE * fp)
58 {
59 const struct ofmt * const *ofp, *of;
60 unsigned int i;
61
62 /* primary targets first */
63 for (ofp = drivers; (of = *ofp); ofp++) {
64 fprintf(fp, " %-20s %s%s\n",
65 of->shortname,
66 of->fullname,
67 of == deffmt ? " [default]" : "");
68 }
69
70 /* lets walk through aliases then */
71 for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
72 if (!ofmt_aliases[i].shortname)
73 continue;
74 fprintf(fp, " %-20s Legacy alias for \"%s\"\n",
75 ofmt_aliases[i].shortname,
76 ofmt_aliases[i].ofmt->shortname);
77 }
78 }
79
80 void dfmt_list(FILE *fp)
81 {
82 const struct ofmt * const *ofp;
83 const struct ofmt *of;
84 const struct dfmt * const *dfp;
85 const struct dfmt *df;
86 char prefixbuf[32];
87 const char *prefix;
88
89 for (ofp = drivers; (of = *ofp); ofp++) {
90 if (of->debug_formats && of->debug_formats != null_debug_arr) {
91 snprintf(prefixbuf, sizeof prefixbuf, "%s:",
92 of->shortname);
93 prefix = prefixbuf;
94
95 for (dfp = of->debug_formats; (df = *dfp); dfp++) {
96 if (df != &null_debug_form)
97 fprintf(fp, " %-10s %-9s %s%s\n",
98 prefix,
99 df->shortname, df->fullname,
100 df == of->default_dfmt ? " [default]" : "");
101 prefix = "";
102 }
103 }
104 }
105 }