[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: question about reserved word file
From: |
Shigio Yamaguchi |
Subject: |
Re: question about reserved word file |
Date: |
Tue, 12 Oct 2004 23:56:24 +0900 |
> On Tue, 12 Oct 2004 00:37:48 +0900, Hideki IWAMOTO wrote...
> > The buffer holding the string without blanks can be referred
> > from the outside of the function to warn about unknown preprocessing direct
ives.
>
> Since it was hard to avoid this problem, I gave up changing reserved_sharp.
Isn't it convenient if a general function to trim string is prepared?
I'm writing a following function for libutil/strmake.c.
-------------------------------------------------------------------
strtrim: delete blanks from original string.
i) p original string.
i) flag TRIM_HEAD from only head
TRIM_TAIL from only tail
TRIM_BOTH from head and tail
TRIM_ALL from all
o) len length of result string
if len == NULL then nothing returned.
r) result string
Usage:
strtrim(" # define ", TRIM_HEAD, NULL) => "# define "
strtrim(" # define ", TRIM_TAIL, NULL) => " # define"
strtrim(" # define ", TRIM_BOTH, NULL) => "# define"
strtrim(" # define ", TRIM_ALL, NULL) => "#define"
NOTE: The result string share the string area.
So, following call of this function may destroy the area.
-------------------------------------------------------------------
With this function, you can write blank processing like follows:
[gctags/asm_scan.l]
^[ \t]*\#[ \t]*{WORD} {
if (reserved_sharp(yytext, yyleng)) {
...
}
[gctags/asm_res.h]
#include "strmake.h"
...
static int
reserved_word(str, len)
const char *str;
int len;
{
char *p = strtrim(p, TRIM_ALL, &len);
struct keyword *keyword = c_lookup(p, len);
int n = keyword ? keyword->token : 0;
return IS_RESERVED_WORD(n) ? n : 0;
}
[htags/c.l]
if (wflag)
unknown_preprocessing_directive(strtrim(LEXTEXT, TRIM_ALL,
NULL), LINENO);
If you think it is useful, please use it.
I will test and commit it in a couple of days.
--
Shigio Yamaguchi <address@hidden> - Tama Communications Corporation
PGP fingerprint: D1CB 0B89 B346 4AB6 5663 C4B6 3CA5 BBB3 57BE DDA3
- question about reserved word file, Hideki IWAMOTO, 2004/10/09
- Re: question about reserved word file, Shigio Yamaguchi, 2004/10/09
- Re: question about reserved word file, Hideki IWAMOTO, 2004/10/09
- Re: question about reserved word file, Shigio Yamaguchi, 2004/10/10
- Re: question about reserved word file, Hideki IWAMOTO, 2004/10/11
- Re: question about reserved word file, Shigio Yamaguchi, 2004/10/11
- Re: question about reserved word file, Hideki IWAMOTO, 2004/10/11
- Re: question about reserved word file, Hideki IWAMOTO, 2004/10/12
- Re: question about reserved word file,
Shigio Yamaguchi <=
- Re: question about reserved word file, Shigio Yamaguchi, 2004/10/12
- Re: question about reserved word file, Hideki IWAMOTO, 2004/10/12
- Re: question about reserved word file, Shigio Yamaguchi, 2004/10/12