Article View: comp.lang.c.moderated
Article #2051Re: [HELP] TOOL FOR REMOVING TOO MANY #ifdef's
From: Todd Sabin
Date: Sat, 17 Feb 1996 18:03
Date: Sat, 17 Feb 1996 18:03
81 lines
2990 bytes
2990 bytes
danpop@mail.cern.ch (Dan Pop) wrote:
>In <4g16vd$mp0@solutions.solon.com> acs@aracnet.com (ACS) writes:
>>Could anyone point me to a tool that does
>> "SELECTIVELY PREPROCESS THE SOURCE WITHOUT SUBSTITUTING MACROS"
>The name of the tool is the C preprocessor. Remove the definitions of
>the macros and they won't be substituted.
>The practical way to do this is to create a new header, nomacros.h and
>to #undef all the macros (or only those you don't want to be substituted)
>in that header. Include this header after all the other headers have
>been included.
>'grep #define *.h' or its equivalent for your platform will give you the
>list of all the macros defined in the other headers.
There are a number of reasons why you probably don't want to do it
this way.
o The contents of your include files will be in the output instead of
"#include <whatever>".
o You'll get a whole lot of '#line "foo.c" 104'
o Your comments will be gone.
o If you have any #errors you're out of luck.
o You can't undefine __LINE__, __FILE__, __DATE__, etc.
o Any #pragmas will be gone.
etc.
If you have emacs, get the cpp.el library (comes standard with 19.30)
and do the following: Get familiar with it a little, and then set the
face for the things you don't want to 'invisible'. Once the file
looks the way you want it, use the following code to delete the stuff
you made invisible.
(defun cpp-delete-invisible-text ()
"Delete text in invisible cpp overlays."
(interactive)
(cpp-delete-regions-with-prop 'invisible))
(defun cpp-delete-regions-with-prop (prop)
"Delete the text of overlays with property PROP"
(let ((overlays cpp-overlay-list))
(while overlays
(if (overlay-get (car overlays) prop)
(progn
(overlay-put (car overlays) 'modification-hooks nil)
(delete-region (overlay-start (car overlays))
(overlay-end (car overlays)))))
(setq overlays (cdr overlays)))))
Save the file and kill the buffer immediately, as the above code
breaks some assumptions made by cpp.el, and I have no idea what the
consequences are.
If you don't have emacs, get emacs and see above. ;)
C-u 100 M-x praise-emacs
My two cents...
Todd
tas@interport.net
>Dan
>--
>Dan Pop
>CERN, CN Division
>Email: danpop@mail.cern.ch
>Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
Technical Details
Message-ID:
<4g55a5$as5@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4g16vd$mp0@solutions.solon.com> <4g27h7$q64@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: tas@interport.net (Todd Sabin) Newsgroups: comp.lang.c.moderated,alt.religion.emacs Subject: Re: [HELP] TOOL FOR REMOVING TOO MANY #ifdef's Date: 17 Feb 1996 12:03:49 -0600 Organization: Interport Communications Corp. Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4g55a5$as5@solutions.solon.com> References: <4g16vd$mp0@solutions.solon.com> <4g27h7$q64@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Newsreader: Forte Free Agent 1.0.82