a style question

Karl Heuer karl at haddock.ima.isc.com
Wed Oct 3 14:44:29 AEST 1990


In article <1990Oct2.163853.17004 at nntp-server.caltech.edu> manning at nntp-server.caltech.edu (Evan Marshall Manning) writes:
>henry at zoo.toronto.edu (Henry Spencer) writes:
>>In what way is "ix" superior to "i"?  Both are meaningless names ...
>
>If Henry asks it must not be as self evident as I thought.  Hasn't this
>ever happened to you:  [You want to search for the variable "i" to see where
>it's being used.]  You find that a lower case 'i' appears an average of about
>four times per comment line.

Ah yes, that's a different problem.  I solved it by improving my toolbox.

>'ix' appears in the comments only when the comments are about variable 'ix'.

Or when it mentions "Unix".

Solution: Use searching tools that know about word boundaries.  Both vi and
emacs have such support.  Some versions of grep can do it too.  If yours
doesn't, then write a filter that flags the beginning and end of each word
with a special string, and use "wordflag | grep | wordunflag".  (The last one
can be a one-line sed script.)

The next annoying problem is when you want to find the variable "n" or "s",
and even in word-search mode you get false hits on strings like "%s\n".  Write
another tool that filters a C source and keeps track of the lexical state at
all times.  Mine distinguishes 8 states: {program text, character literal,
string literal, comment} x {preprocessor line, real line}; the user selects
which states are of interest.

Exercise: By writing a word-flagging tool that can be used in a pipeline,
rather than adding word-boundary recognition to grep, we have a more general
tool that may have other applications.  In keeping with this spirit, what
should be the semantics of the C-lexing tool?

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint



More information about the Comp.lang.c mailing list