[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lynx-dev removing strings used in CTRACE when configured without tracing
From: |
Vlad Harchev |
Subject: |
lynx-dev removing strings used in CTRACE when configured without tracing |
Date: |
Thu, 15 Apr 1999 07:03:42 +0500 (SAMST) |
The are several approaches:
1)Use a feature of gcc - macros with variable number of arguments, in this
case we can do the following
#ifndef DEBUG
# define CTRACE(f, args...) /*nothing*/
#else
...
I don't know whether cccp - a c preprocessor distributed with GCC can do that,
but gcc supports it.
2) First I've written the following script
_____________
# copyright 1999 by Vlad Harchev <address@hidden>. Distributed under GPL.
#args - the file names to process
#this will match C string that doesn't wrap lines
CSTR='\("\([^"]*\(\\"\)*\)*"\)';
CTRACE='\(CTRACE[ \t]*([ \t]*[A-z_][_A-z0-9]*[ \t]*,[ \t]*\)';
tmpnm="_tmp$$";
for i; do
echo converting $i
mv $i $tmpnm &&
sed -e 's/'"$CTRACE"'\(\('"$CSTR"'[ \t]*\)*\)\([,)]\)/\1CT_(\2)\7/g' \
$tmpnm > $i && rm $tmpnm;
done;
____________
It includes the string used as format specifier in the parentheses preceded
by CT_ (assumming that we'l define macro CT_(x) ). So, the following line
CTRACE( f, "text" "text \"more", params);
will be substituted with
CTRACE( f, CT_("text" "text \"more"), params);
But I found this inacceptable, since when the string constant is long enough,
the sed processes each string VERY slow.
The file I processed with sed was of the form (file had only 1 line):
CTRACE( f, "123456789_123456789" );
It takes 37 seconds for sed to substitute this line (correctly tho'). I have
5x86-133, 32MB of RAM (and no cpu-hungry jobs). Seems that sed I'm using is
broken - it's GNU sed-3.02 (was supplied with my RedHat 5.2). Probably it's a
bug in regexp code.
For shorter lines, like
CTRACE( f, "123456789_123456" );
it takes 5 seconds (the string is 3 chars shorter as you see).
BTW, can you test the script with other seds (probaly with GNU sed 2.x)
3) So I wrote the the small program using lex (it does the same as script
above, but very fast).
--------------ctrace-wrap.l-----
/* copyright 1999 by Vlad Harchev <address@hidden>. Distributed under GPL.*/
%x SEENCTRACE
%option noyywrap
%{
#include <stdio.h>
%}
W ([ \t\n]*)
CSTR (\"([^"\\]*(\\\")*)*\")
%%
CTRACE{W}\({W}[A-z_][A-z_0-9]*{W},{W} { fwrite(yytext,yyleng,1,stdout);
BEGIN(SEENCTRACE); }
<SEENCTRACE>({CSTR}{W})* { fwrite("CT_(",4,1,stdout);
fwrite(yytext,yyleng,1,stdout); fwrite(")",1,1,stdout); BEGIN(0); }
%%
void main()
{
yylex();
};
----------------------------
It should be called by a script that will process all files passed.
So, to remove all string literals from lynx binary when lynx configured with
--disable-trace, the following strings should be added to HTUtils.h:
#ifndef DEBUG
# define CT_(x) NULL
#else
# define CT_(x) x
#endif
So the new rule for using CTRACE macro:
*wrap the format specifier string in CT_(), eg instead of
CTRACE( tfp, "foo" );
use
CTRACE( tfp, CT_("foo") );
More ideas: may be it will be useful to define CT_ the following way
#ifndef DEBUG
# define CT_(x) NULL
#else
# define do_xstr(x) #x
# define xstr(x) do_xstr(x)
# define CT_(x) __FILE_ ":" xstr(__LINE__) " " x
#endif
so each CTRACE record will be preceeded with the name of the file and the line
where CTRACE was invoked.
Best regards,
-Vlad
- lynx-dev removing strings used in CTRACE when configured without tracing,
Vlad Harchev <=