cxxfilt.c (295577) | cxxfilt.c (300311) |
---|---|
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 3356 2016-01-22 22:31:38Z jkoshy $"); | 38ELFTC_VCSID("$Id: cxxfilt.c 3454 2016-05-07 17:11:05Z kaiwang27 $"); |
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, size_t *pos) | 115demangle(char *name) |
116{ 117 static char dem[STRBUFSZ]; | 116{ 117 static char dem[STRBUFSZ]; |
118 char nb[STRBUFSZ]; 119 size_t p, t; | |
120 | 118 |
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'; | 119 if (stripus && *name == '_') 120 name++; |
129 | 121 |
130 p = strlen(nb); 131 if (p == 0) 132 return NULL; | 122 if (strlen(name) == 0) 123 return (NULL); |
133 | 124 |
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 } | 125 if (elftc_demangle(name, dem, sizeof(dem), (unsigned) format) < 0) 126 return (NULL); |
141 | 127 |
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]; | 128 return (dem); 129} 130 131int 132main(int argc, char **argv) 133{ 134 char *dem, buf[STRBUFSZ]; |
152 size_t i, p, s; | 135 size_t p; |
153 int c, n, opt; 154 155 while ((opt = getopt_long(argc, argv, "_nps:V", longopts, NULL)) != 156 -1) { 157 switch (opt) { 158 case '_': 159 stripus = 1; 160 break; --- 18 unchanged lines hidden (view full) --- 179 } 180 } 181 182 argv += optind; 183 argc -= optind; 184 185 if (*argv != NULL) { 186 for (n = 0; n < argc; n++) { | 136 int c, n, opt; 137 138 while ((opt = getopt_long(argc, argv, "_nps:V", longopts, NULL)) != 139 -1) { 140 switch (opt) { 141 case '_': 142 stripus = 1; 143 break; --- 18 unchanged lines hidden (view full) --- 162 } 163 } 164 165 argv += optind; 166 argc -= optind; 167 168 if (*argv != NULL) { 169 for (n = 0; n < argc; n++) { |
187 if ((dem = demangle(argv[n], 1, NULL)) == NULL) 188 fprintf(stderr, "Failed: %s\n", argv[n]); | 170 if ((dem = demangle(argv[n])) == NULL) 171 printf("%s\n", argv[n]); |
189 else 190 printf("%s\n", dem); 191 } 192 } else { 193 p = 0; 194 for (;;) { 195 c = fgetc(stdin); | 172 else 173 printf("%s\n", dem); 174 } 175 } else { 176 p = 0; 177 for (;;) { 178 c = fgetc(stdin); |
196 if (c == EOF || !isprint(c) || strchr(" \t\n", c)) { | 179 if (c == EOF || !(isalnum(c) || strchr(".$_", c))) { |
197 if (p > 0) { 198 buf[p] = '\0'; | 180 if (p > 0) { 181 buf[p] = '\0'; |
199 if ((dem = demangle(buf, 0, &s)) == 200 NULL) | 182 if ((dem = demangle(buf)) == NULL) |
201 printf("%s", buf); | 183 printf("%s", buf); |
202 else { | 184 else |
203 printf("%s", dem); | 185 printf("%s", dem); |
204 for (i = s; i < p; i++) 205 putchar(buf[i]); 206 } | |
207 p = 0; 208 } 209 if (c == EOF) 210 break; | 186 p = 0; 187 } 188 if (c == EOF) 189 break; |
211 if (isprint(c) || strchr(" \t\n", c)) 212 putchar(c); | 190 putchar(c); |
213 } else { 214 if ((size_t) p >= sizeof(buf) - 1) 215 warnx("buffer overflowed"); 216 else 217 buf[p++] = (char) c; 218 } 219 220 } 221 } 222 223 exit(0); 224} | 191 } else { 192 if ((size_t) p >= sizeof(buf) - 1) 193 warnx("buffer overflowed"); 194 else 195 buf[p++] = (char) c; 196 } 197 198 } 199 } 200 201 exit(0); 202} |