From: blevy@syl.dl.nec.com (Britt Levy (ESD))
Subject: Re: Demangler available?
Keywords: g++ demangler, emacs
Organization: NEC Systems Lab., C&C Software Technology Center (Dallas, TX)
Date: Thu, 3 Sep 1992 17:45:35 GMT

I created a simple interface to cp-dem.c, from the gcc-2.2.2 release,
called g++dem. It reads g++ mangled names from stdin and spits out the demangled
name to stdout. I also created an emacs function which demangles symbols
between point and mark in an emacs buffer and writes the results to a
separate buffer. The two source files g++dem.c and g++dem.el, and a
shell script used to make g++dem are include below in shar format. You can find
cp-dem.c in the gcc source distribution. 



#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	dem.mak
#	g++dem.c
#	g++dem.el
# This archive created: Thu Sep  3 12:41:21 1992
export PATH; PATH=/bin:$PATH
if test -f 'dem.mak'
then
	echo shar: will not over-write existing file "'dem.mak'"
else
cat << \SHAR_EOF > 'dem.mak'
gcc -g -c cp-dem.c -Dxmalloc=malloc -Dxrealloc=realloc
gcc -g g++dem.c cp-dem.o -o g++dem
SHAR_EOF
chmod +x 'dem.mak'
fi # end of overwriting check
if test -f 'g++dem.c'
then
	echo shar: will not over-write existing file "'g++dem.c'"
else
cat << \SHAR_EOF > 'g++dem.c'
/* Trivial interface to cp-dem() demangler for GNU C++ from gcc 2.2.2
   Copyright 1989, 1991 Free Software Foundation, Inc.
   written by Britt Levy (blevy@esd.dl.nec.com)
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */

#include <stdio.h>

extern char *cplus_demangle (const char *name, int mode);

main()
{
   char inbuf[256];
   while(gets(inbuf) != (char *) 0)
      printf("%s => %s\n",inbuf, cplus_demangle(inbuf,0));
   exit(0);
}
SHAR_EOF
fi # end of overwriting check
if test -f 'g++dem.el'
then
	echo shar: will not over-write existing file "'g++dem.el'"
else
cat << \SHAR_EOF > 'g++dem.el'
;; g++dem.el - Demangles g++ 2.2.2 symbols in current emacs buffer between
;; point and mark using an interface to cp-dem(), from gcc 2.2.2, in
;; an asynchronous subprocess. 

;; Written by Britt Levy (email: blevy@esd.dl.nec.com)

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, you can either send email to this
;; program's author (see below) or write to:
;;
;;              The Free Software Foundation, Inc.
;;              675 Mass Ave.
;;              Cambridge, MA 02139, USA. 
;;


(defun g++dem nil
"Demangles g++ symbols between point and mark. Output is written to
buffer named `g++dem'."  

  (interactive)

  (if (<= (mark) (point))
      (exchange-point-and-mark)
    )

  (let ((process-connection-type nil)
	(out-buf (get-buffer-create "g++dem"))
	(end (mark))
	g++dem-proc
	symbol)
    
    (setq g++dem-proc (start-process "g++dem" out-buf "g++dem" ))

    (while (and (< (point) (mark))
		(re-search-forward "[^ \\t]*" end t))
      (setq symbol (read (current-buffer)))
      (process-send-string g++dem-proc (format "%s\n" (symbol-name symbol)))
      )

    (process-send-eof g++dem-proc)
    
    (switch-to-buffer-other-window out-buf)
    )
  )

    
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0

-- 
------------------------------------------------------------------
Britt Levy, NEC AMERICA INC             1525 W WALNUT HILL LN
blevy@esd.dl.nec.com		        IRVING TX 75038-3793
					Phone: (214) 518-3829
------------------------------------------------------------------