Deleted Added
full compact
cxxfilt.c (280932) cxxfilt.c (295577)
1/*-
2 * Copyright (c) 2009 Kai Wang
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

30#include <getopt.h>
31#include <libelftc.h>
32#include <stdlib.h>
33#include <stdio.h>
34#include <string.h>
35
36#include "_elftc.h"
37
1/*-
2 * Copyright (c) 2009 Kai Wang
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

30#include <getopt.h>
31#include <libelftc.h>
32#include <stdlib.h>
33#include <stdio.h>
34#include <string.h>
35
36#include "_elftc.h"
37
38ELFTC_VCSID("$Id: cxxfilt.c 3174 2015-03-27 17:13:41Z emaste $");
38ELFTC_VCSID("$Id: cxxfilt.c 3356 2016-01-22 22:31:38Z jkoshy $");
39
40#define STRBUFSZ 8192
41
42static int stripus = 0;
43static int noparam = 0;
44static int format = 0;
45
46enum options

--- 60 unchanged lines hidden (view full) ---

107 if (!strcmp(fstr, flist[i].fname))
108 return (flist[i].fvalue);
109 }
110
111 return (-1);
112}
113
114static char *
39
40#define STRBUFSZ 8192
41
42static int stripus = 0;
43static int noparam = 0;
44static int format = 0;
45
46enum options

--- 60 unchanged lines hidden (view full) ---

107 if (!strcmp(fstr, flist[i].fname))
108 return (flist[i].fvalue);
109 }
110
111 return (-1);
112}
113
114static char *
115demangle(char *name, int strict, int *pos)
115demangle(char *name, int strict, size_t *pos)
116{
117 static char dem[STRBUFSZ];
118 char nb[STRBUFSZ];
116{
117 static char dem[STRBUFSZ];
118 char nb[STRBUFSZ];
119 int p, t;
119 size_t p, t;
120
121 if (stripus && *name == '_') {
122 strncpy(nb, name + 1, sizeof(nb) - 1);
123 t = 1;
124 } else {
125 strncpy(nb, name, sizeof(nb) - 1);
126 t = 0;
127 }
128 nb[sizeof(nb) - 1] = '\0';
129
130 p = strlen(nb);
120
121 if (stripus && *name == '_') {
122 strncpy(nb, name + 1, sizeof(nb) - 1);
123 t = 1;
124 } else {
125 strncpy(nb, name, sizeof(nb) - 1);
126 t = 0;
127 }
128 nb[sizeof(nb) - 1] = '\0';
129
130 p = strlen(nb);
131 if (p <= 0)
131 if (p == 0)
132 return NULL;
133
132 return NULL;
133
134 while (elftc_demangle(nb, dem, sizeof(dem), format) < 0) {
134 while (elftc_demangle(nb, dem, sizeof(dem), (unsigned) format) < 0) {
135 if (!strict && p > 1) {
136 nb[--p] = '\0';
137 continue;
138 } else
139 return (NULL);
140 }
141
142 if (pos != NULL)
143 *pos = t ? p + 1 : p;
144
145 return (dem);
146}
147
148int
149main(int argc, char **argv)
150{
151 char *dem, buf[STRBUFSZ];
135 if (!strict && p > 1) {
136 nb[--p] = '\0';
137 continue;
138 } else
139 return (NULL);
140 }
141
142 if (pos != NULL)
143 *pos = t ? p + 1 : p;
144
145 return (dem);
146}
147
148int
149main(int argc, char **argv)
150{
151 char *dem, buf[STRBUFSZ];
152 int c, i, p, s, opt;
152 size_t i, p, s;
153 int c, n, opt;
153
154 while ((opt = getopt_long(argc, argv, "_nps:V", longopts, NULL)) !=
155 -1) {
156 switch (opt) {
157 case '_':
158 stripus = 1;
159 break;
160 case 'n':

--- 16 unchanged lines hidden (view full) ---

177 /* NOT REACHED */
178 }
179 }
180
181 argv += optind;
182 argc -= optind;
183
184 if (*argv != NULL) {
154
155 while ((opt = getopt_long(argc, argv, "_nps:V", longopts, NULL)) !=
156 -1) {
157 switch (opt) {
158 case '_':
159 stripus = 1;
160 break;
161 case 'n':

--- 16 unchanged lines hidden (view full) ---

178 /* NOT REACHED */
179 }
180 }
181
182 argv += optind;
183 argc -= optind;
184
185 if (*argv != NULL) {
185 for (i = 0; i < argc; i++) {
186 if ((dem = demangle(argv[i], 1, NULL)) == NULL)
187 fprintf(stderr, "Failed: %s\n", argv[i]);
186 for (n = 0; n < argc; n++) {
187 if ((dem = demangle(argv[n], 1, NULL)) == NULL)
188 fprintf(stderr, "Failed: %s\n", argv[n]);
188 else
189 printf("%s\n", dem);
190 }
191 } else {
192 p = 0;
193 for (;;) {
194 c = fgetc(stdin);
195 if (c == EOF || !isprint(c) || strchr(" \t\n", c)) {

--- 12 unchanged lines hidden (view full) ---

208 if (c == EOF)
209 break;
210 if (isprint(c) || strchr(" \t\n", c))
211 putchar(c);
212 } else {
213 if ((size_t) p >= sizeof(buf) - 1)
214 warnx("buffer overflowed");
215 else
189 else
190 printf("%s\n", dem);
191 }
192 } else {
193 p = 0;
194 for (;;) {
195 c = fgetc(stdin);
196 if (c == EOF || !isprint(c) || strchr(" \t\n", c)) {

--- 12 unchanged lines hidden (view full) ---

209 if (c == EOF)
210 break;
211 if (isprint(c) || strchr(" \t\n", c))
212 putchar(c);
213 } else {
214 if ((size_t) p >= sizeof(buf) - 1)
215 warnx("buffer overflowed");
216 else
216 buf[p++] = c;
217 buf[p++] = (char) c;
217 }
218
219 }
220 }
221
222 exit(0);
223}
218 }
219
220 }
221 }
222
223 exit(0);
224}