"Fossies" - the Fresh Open Source Software Archive

Member "mpr-2.8/demangle/mprdem.c" (22 Oct 2002, 1401 Bytes) of package /linux/misc/old/mpr-2.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <stdio.h>
    2 #include <stdlib.h>
    3 #include <string.h>
    4 #include <unistd.h>
    5 #undef NDEBUG
    6 #include <assert.h>
    7 #include "demangle.h"
    8 
    9 void *
   10 xmalloc(size_t sz)
   11 {
   12     void *p = malloc(sz);
   13     assert(p);
   14     return p;
   15 }
   16 
   17 void *
   18 xrealloc(void *p, size_t sz)
   19 {
   20     void *p2 = realloc(p, sz);
   21     assert(p2);
   22     return p2;
   23 }
   24 
   25 char *
   26 xstrdup(char *s)
   27 {
   28     size_t len = strlen(s) + 1;
   29     char *ret = xmalloc(len);
   30     memcpy(ret, s, len);
   31     return ret;
   32 }
   33 
   34 void
   35 usage()
   36 {
   37     fprintf(stderr, "usage: mprdem [-p] [-a]\n");
   38     exit(1);
   39 }
   40 
   41 int
   42 main(int argc, char **argv)
   43 {
   44     char buf[8192], *dem, *cp;
   45     int opt, noparams=0, noansi=0, demopt=0;
   46 
   47     while ((opt = getopt(argc, argv, "ap")) != -1)
   48         switch (opt) {
   49         case 'a':
   50             noansi = 1;
   51             break;
   52         case 'p':
   53             noparams = 1;
   54             break;
   55         case '?':
   56             usage();
   57         }
   58 
   59     if (!noansi)
   60         demopt |= DMGL_ANSI;
   61 
   62     if (!noparams)
   63         demopt |= DMGL_PARAMS;
   64 
   65 #define demangle(style) cplus_demangle(cp+1, demopt|style)
   66 
   67     while (fgets(buf, sizeof buf, stdin)) {
   68         assert(strchr(buf, '\n'));
   69         buf[strlen(buf)-1] = '\0';
   70         cp = strchr(buf, '\t');
   71         assert(cp);
   72         *cp = 0;
   73         printf("%s\t", buf);
   74         if ((dem = demangle(DMGL_GNU)) ||
   75             (dem = demangle(DMGL_AUTO)) ||
   76             (dem = demangle(DMGL_GNU_V3)) ||
   77             (dem = demangle(DMGL_ARM)) ||
   78             (dem = demangle(DMGL_LUCID)) ||
   79             (dem = demangle(DMGL_HP))) {
   80             printf("%s\n", dem);
   81             free(dem);
   82         }
   83         else
   84             printf("%s\n", cp+1);
   85     }
   86     return 0;
   87 }