aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2015-05-23 15:18:12 -0700
committerPaul Eggert2015-05-23 15:19:02 -0700
commitfb11a5e11769a7ca909bf5a7798f9e7193fabb13 (patch)
tree3ea9e8c9077a3bf82bedfbcbc8de601930b0c8d8 /lib-src
parentfa658b2e9075f6990e52c2f08a70586c87e98d22 (diff)
downloademacs-fb11a5e11769a7ca909bf5a7798f9e7193fabb13.tar.gz
emacs-fb11a5e11769a7ca909bf5a7798f9e7193fabb13.zip
Cleanup etags.c to use locale-independent code
Although this doesn't alter behavior (as etags doesn't use setlocale), the new version is more clearly locale-independent and the executable is a bit smaller on my platform. * lib-src/etags.c: Include <limits.h>, for UCHAR_MAX. Include <c-ctype.h> instead of <ctype.h>. (CHARS, CHAR, init, _wht, _nin, _itk, _btk, _etk, white, nonam, endtk) (begtk, midtk): Remove; no longer needed. (iswhite, ISALNUM, ISALPHA, ISDIGIT, ISLOWER, lowcase): Remove. All callers changed to use c_isspace, c_isalnum, c_isalpha, c_isdigit, c_islower, c_tolower, respectively. (notinname, begtoken, intoken, endtoken): Rewrite as functions instead of macros, and initialize the tables at compile-time rather than at run-time.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/etags.c214
1 files changed, 109 insertions, 105 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 28729da8720..facb462f67b 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -119,17 +119,18 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
119# define O_CLOEXEC O_NOINHERIT 119# define O_CLOEXEC O_NOINHERIT
120#endif /* WINDOWSNT */ 120#endif /* WINDOWSNT */
121 121
122#include <limits.h>
122#include <unistd.h> 123#include <unistd.h>
123#include <stdarg.h> 124#include <stdarg.h>
124#include <stdlib.h> 125#include <stdlib.h>
125#include <string.h> 126#include <string.h>
126#include <sysstdio.h> 127#include <sysstdio.h>
127#include <ctype.h>
128#include <errno.h> 128#include <errno.h>
129#include <fcntl.h> 129#include <fcntl.h>
130#include <sys/types.h> 130#include <sys/types.h>
131#include <sys/stat.h> 131#include <sys/stat.h>
132#include <binary-io.h> 132#include <binary-io.h>
133#include <c-ctype.h>
133#include <c-strcase.h> 134#include <c-strcase.h>
134 135
135#include <assert.h> 136#include <assert.h>
@@ -156,21 +157,71 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
156#define strneq(s,t,n) (assert ((s)!=NULL || (t)!=NULL), !strncmp (s, t, n)) 157#define strneq(s,t,n) (assert ((s)!=NULL || (t)!=NULL), !strncmp (s, t, n))
157#define strncaseeq(s,t,n) (assert ((s)!=NULL && (t)!=NULL), !c_strncasecmp (s, t, n)) 158#define strncaseeq(s,t,n) (assert ((s)!=NULL && (t)!=NULL), !c_strncasecmp (s, t, n))
158 159
159#define CHARS 256 /* 2^sizeof(char) */ 160/* C is not in a name. */
160#define CHAR(x) ((unsigned int)(x) & (CHARS - 1)) 161static bool
161#define iswhite(c) (_wht[CHAR (c)]) /* c is white (see white) */ 162notinname (unsigned char c)
162#define notinname(c) (_nin[CHAR (c)]) /* c is not in a name (see nonam) */ 163{
163#define begtoken(c) (_btk[CHAR (c)]) /* c can start token (see begtk) */ 164 /* Look at make_tag before modifying! */
164#define intoken(c) (_itk[CHAR (c)]) /* c can be in token (see midtk) */ 165 static bool const table[UCHAR_MAX + 1] = {
165#define endtoken(c) (_etk[CHAR (c)]) /* c ends tokens (see endtk) */ 166 ['\0']=1, ['\t']=1, ['\n']=1, ['\f']=1, ['\r']=1, [' ']=1,
167 ['(']=1, [')']=1, [',']=1, [';']=1, ['=']=1
168 };
169 return table[c];
170}
166 171
167#define ISALNUM(c) isalnum (CHAR (c)) 172/* C can start a token. */
168#define ISALPHA(c) isalpha (CHAR (c)) 173static bool
169#define ISDIGIT(c) isdigit (CHAR (c)) 174begtoken (unsigned char c)
170#define ISLOWER(c) islower (CHAR (c)) 175{
176 static bool const table[UCHAR_MAX + 1] = {
177 ['$']=1, ['@']=1,
178 ['A']=1, ['B']=1, ['C']=1, ['D']=1, ['E']=1, ['F']=1, ['G']=1, ['H']=1,
179 ['I']=1, ['J']=1, ['K']=1, ['L']=1, ['M']=1, ['N']=1, ['O']=1, ['P']=1,
180 ['Q']=1, ['R']=1, ['S']=1, ['T']=1, ['U']=1, ['V']=1, ['W']=1, ['X']=1,
181 ['Y']=1, ['Z']=1,
182 ['_']=1,
183 ['a']=1, ['b']=1, ['c']=1, ['d']=1, ['e']=1, ['f']=1, ['g']=1, ['h']=1,
184 ['i']=1, ['j']=1, ['k']=1, ['l']=1, ['m']=1, ['n']=1, ['o']=1, ['p']=1,
185 ['q']=1, ['r']=1, ['s']=1, ['t']=1, ['u']=1, ['v']=1, ['w']=1, ['x']=1,
186 ['y']=1, ['z']=1,
187 ['~']=1
188 };
189 return table[c];
190}
171 191
172#define lowcase(c) tolower (CHAR (c)) 192/* C can be in the middle of a token. */
193static bool
194intoken (unsigned char c)
195{
196 static bool const table[UCHAR_MAX + 1] = {
197 ['0']=1, ['1']=1, ['2']=1, ['3']=1, ['4']=1,
198 ['5']=1, ['6']=1, ['7']=1, ['8']=1, ['9']=1,
199 ['A']=1, ['B']=1, ['C']=1, ['D']=1, ['E']=1, ['F']=1, ['G']=1, ['H']=1,
200 ['I']=1, ['J']=1, ['K']=1, ['L']=1, ['M']=1, ['N']=1, ['O']=1, ['P']=1,
201 ['Q']=1, ['R']=1, ['S']=1, ['T']=1, ['U']=1, ['V']=1, ['W']=1, ['X']=1,
202 ['Y']=1, ['Z']=1,
203 ['_']=1,
204 ['a']=1, ['b']=1, ['c']=1, ['d']=1, ['e']=1, ['f']=1, ['g']=1, ['h']=1,
205 ['i']=1, ['j']=1, ['k']=1, ['l']=1, ['m']=1, ['n']=1, ['o']=1, ['p']=1,
206 ['q']=1, ['r']=1, ['s']=1, ['t']=1, ['u']=1, ['v']=1, ['w']=1, ['x']=1,
207 ['y']=1, ['z']=1
208 };
209 return table[c];
210}
173 211
212/* C can end a token. */
213static bool
214endtoken (unsigned char c)
215{
216 static bool const table[UCHAR_MAX + 1] = {
217 ['\0']=1, ['\t']=1, ['\n']=1, ['\r']=1, [' ']=1,
218 ['!']=1, ['"']=1, ['#']=1, ['%']=1, ['&']=1, ['\'']=1, ['(']=1, [')']=1,
219 ['*']=1, ['+']=1, [',']=1, ['-']=1, ['.']=1, ['/']=1, [':']=1, [';']=1,
220 ['<']=1, ['=']=1, ['>']=1, ['?']=1, ['[']=1, [']']=1, ['^']=1,
221 ['{']=1, ['|']=1, ['}']=1, ['~']=1
222 };
223 return table[c];
224}
174 225
175/* 226/*
176 * xnew, xrnew -- allocate, reallocate storage 227 * xnew, xrnew -- allocate, reallocate storage
@@ -316,7 +367,6 @@ _Noreturn void fatal (const char *, const char *);
316static _Noreturn void pfatal (const char *); 367static _Noreturn void pfatal (const char *);
317static void add_node (node *, node **); 368static void add_node (node *, node **);
318 369
319static void init (void);
320static void process_file_name (char *, language *); 370static void process_file_name (char *, language *);
321static void process_file (FILE *, char *, language *); 371static void process_file (FILE *, char *, language *);
322static void find_entries (FILE *); 372static void find_entries (FILE *);
@@ -370,20 +420,6 @@ static linebuffer lb; /* the current line */
370static linebuffer filebuf; /* a buffer containing the whole file */ 420static linebuffer filebuf; /* a buffer containing the whole file */
371static linebuffer token_name; /* a buffer containing a tag name */ 421static linebuffer token_name; /* a buffer containing a tag name */
372 422
373/* boolean "functions" (see init) */
374static bool _wht[CHARS], _nin[CHARS], _itk[CHARS], _btk[CHARS], _etk[CHARS];
375static const char
376 /* white chars */
377 *white = " \f\t\n\r\v",
378 /* not in a name */
379 *nonam = " \f\t\n\r()=,;", /* look at make_tag before modifying! */
380 /* token ending chars */
381 *endtk = " \t\n\r\"'#()[]{}=-+%*/&|^~!<>;,.:?",
382 /* token starting chars */
383 *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@",
384 /* valid in-token chars */
385 *midtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789";
386
387static bool append_to_tagfile; /* -a: append to tags */ 423static bool append_to_tagfile; /* -a: append to tags */
388/* The next five default to true in C and derived languages. */ 424/* The next five default to true in C and derived languages. */
389static bool typedefs; /* -t: create tags for C and Ada typedefs */ 425static bool typedefs; /* -t: create tags for C and Ada typedefs */
@@ -1167,8 +1203,6 @@ main (int argc, char **argv)
1167 tagfiledir = absolute_dirname (tagfile, cwd); 1203 tagfiledir = absolute_dirname (tagfile, cwd);
1168 } 1204 }
1169 1205
1170 init (); /* set up boolean "functions" */
1171
1172 linebuffer_init (&lb); 1206 linebuffer_init (&lb);
1173 linebuffer_init (&filename_lb); 1207 linebuffer_init (&filename_lb);
1174 linebuffer_init (&filebuf); 1208 linebuffer_init (&filebuf);
@@ -1637,34 +1671,6 @@ process_file (FILE *fh, char *fn, language *lang)
1637} 1671}
1638 1672
1639/* 1673/*
1640 * This routine sets up the boolean pseudo-functions which work
1641 * by setting boolean flags dependent upon the corresponding character.
1642 * Every char which is NOT in that string is not a white char. Therefore,
1643 * all of the array "_wht" is set to false, and then the elements
1644 * subscripted by the chars in "white" are set to true. Thus "_wht"
1645 * of a char is true if it is the string "white", else false.
1646 */
1647static void
1648init (void)
1649{
1650 const char *sp;
1651 int i;
1652
1653 for (i = 0; i < CHARS; i++)
1654 iswhite (i) = notinname (i) = begtoken (i) = intoken (i) = endtoken (i)
1655 = false;
1656 for (sp = white; *sp != '\0'; sp++) iswhite (*sp) = true;
1657 for (sp = nonam; *sp != '\0'; sp++) notinname (*sp) = true;
1658 notinname ('\0') = notinname ('\n');
1659 for (sp = begtk; *sp != '\0'; sp++) begtoken (*sp) = true;
1660 begtoken ('\0') = begtoken ('\n');
1661 for (sp = midtk; *sp != '\0'; sp++) intoken (*sp) = true;
1662 intoken ('\0') = intoken ('\n');
1663 for (sp = endtk; *sp != '\0'; sp++) endtoken (*sp) = true;
1664 endtoken ('\0') = endtoken ('\n');
1665}
1666
1667/*
1668 * This routine opens the specified file and calls the function 1674 * This routine opens the specified file and calls the function
1669 * which finds the function and type definitions. 1675 * which finds the function and type definitions.
1670 */ 1676 */
@@ -3179,7 +3185,7 @@ C_entries (int c_ext, FILE *inf)
3179 followed by an end of comment, this is a preprocessor 3185 followed by an end of comment, this is a preprocessor
3180 token. */ 3186 token. */
3181 for (cp = newlb.buffer; cp < lp-1; cp++) 3187 for (cp = newlb.buffer; cp < lp-1; cp++)
3182 if (!iswhite (*cp)) 3188 if (!c_isspace (*cp))
3183 { 3189 {
3184 if (*cp == '*' && cp[1] == '/') 3190 if (*cp == '*' && cp[1] == '/')
3185 { 3191 {
@@ -3262,7 +3268,7 @@ C_entries (int c_ext, FILE *inf)
3262 if (*lp != '\0') 3268 if (*lp != '\0')
3263 lp += 1; 3269 lp += 1;
3264 while (*lp != '\0' 3270 while (*lp != '\0'
3265 && !iswhite (*lp) && *lp != '(') 3271 && !c_isspace (*lp) && *lp != '(')
3266 lp += 1; 3272 lp += 1;
3267 c = *lp++; 3273 c = *lp++;
3268 toklen += lp - oldlp; 3274 toklen += lp - oldlp;
@@ -3934,14 +3940,14 @@ F_takeprec (void)
3934 dbp += 3; 3940 dbp += 3;
3935 return; 3941 return;
3936 } 3942 }
3937 if (!ISDIGIT (*dbp)) 3943 if (!c_isdigit (*dbp))
3938 { 3944 {
3939 --dbp; /* force failure */ 3945 --dbp; /* force failure */
3940 return; 3946 return;
3941 } 3947 }
3942 do 3948 do
3943 dbp++; 3949 dbp++;
3944 while (ISDIGIT (*dbp)); 3950 while (c_isdigit (*dbp));
3945} 3951}
3946 3952
3947static void 3953static void
@@ -3959,7 +3965,7 @@ F_getit (FILE *inf)
3959 dbp += 6; 3965 dbp += 6;
3960 dbp = skip_spaces (dbp); 3966 dbp = skip_spaces (dbp);
3961 } 3967 }
3962 if (!ISALPHA (*dbp) && *dbp != '_' && *dbp != '$') 3968 if (!c_isalpha (*dbp) && *dbp != '_' && *dbp != '$')
3963 return; 3969 return;
3964 for (cp = dbp + 1; *cp != '\0' && intoken (*cp); cp++) 3970 for (cp = dbp + 1; *cp != '\0' && intoken (*cp); cp++)
3965 continue; 3971 continue;
@@ -3988,7 +3994,7 @@ Fortran_functions (FILE *inf)
3988 if (LOOKING_AT_NOCASE (dbp, "elemental")) 3994 if (LOOKING_AT_NOCASE (dbp, "elemental"))
3989 dbp = skip_spaces (dbp); 3995 dbp = skip_spaces (dbp);
3990 3996
3991 switch (lowcase (*dbp)) 3997 switch (c_tolower (*dbp))
3992 { 3998 {
3993 case 'i': 3999 case 'i':
3994 if (nocase_tail ("integer")) 4000 if (nocase_tail ("integer"))
@@ -4021,7 +4027,7 @@ Fortran_functions (FILE *inf)
4021 dbp = skip_spaces (dbp); 4027 dbp = skip_spaces (dbp);
4022 if (*dbp == '\0') 4028 if (*dbp == '\0')
4023 continue; 4029 continue;
4024 switch (lowcase (*dbp)) 4030 switch (c_tolower (*dbp))
4025 { 4031 {
4026 case 'f': 4032 case 'f':
4027 if (nocase_tail ("function")) 4033 if (nocase_tail ("function"))
@@ -4075,7 +4081,7 @@ Ada_getit (FILE *inf, const char *name_qualifier)
4075 readline (&lb, inf); 4081 readline (&lb, inf);
4076 dbp = lb.buffer; 4082 dbp = lb.buffer;
4077 } 4083 }
4078 switch (lowcase (*dbp)) 4084 switch (c_tolower (*dbp))
4079 { 4085 {
4080 case 'b': 4086 case 'b':
4081 if (nocase_tail ("body")) 4087 if (nocase_tail ("body"))
@@ -4102,8 +4108,7 @@ Ada_getit (FILE *inf, const char *name_qualifier)
4102 { 4108 {
4103 dbp = skip_spaces (dbp); 4109 dbp = skip_spaces (dbp);
4104 for (cp = dbp; 4110 for (cp = dbp;
4105 (*cp != '\0' 4111 c_isalnum (*cp) || *cp == '_' || *cp == '.';
4106 && (ISALPHA (*cp) || ISDIGIT (*cp) || *cp == '_' || *cp == '.'));
4107 cp++) 4112 cp++)
4108 continue; 4113 continue;
4109 if (cp == dbp) 4114 if (cp == dbp)
@@ -4179,7 +4184,7 @@ Ada_funcs (FILE *inf)
4179 } 4184 }
4180 4185
4181 /* We are at the beginning of a token. */ 4186 /* We are at the beginning of a token. */
4182 switch (lowcase (*dbp)) 4187 switch (c_tolower (*dbp))
4183 { 4188 {
4184 case 'f': 4189 case 'f':
4185 if (!packages_only && nocase_tail ("function")) 4190 if (!packages_only && nocase_tail ("function"))
@@ -4244,13 +4249,13 @@ Asm_labels (FILE *inf)
4244 { 4249 {
4245 /* If first char is alphabetic or one of [_.$], test for colon 4250 /* If first char is alphabetic or one of [_.$], test for colon
4246 following identifier. */ 4251 following identifier. */
4247 if (ISALPHA (*cp) || *cp == '_' || *cp == '.' || *cp == '$') 4252 if (c_isalpha (*cp) || *cp == '_' || *cp == '.' || *cp == '$')
4248 { 4253 {
4249 /* Read past label. */ 4254 /* Read past label. */
4250 cp++; 4255 cp++;
4251 while (ISALNUM (*cp) || *cp == '_' || *cp == '.' || *cp == '$') 4256 while (c_isalnum (*cp) || *cp == '_' || *cp == '.' || *cp == '$')
4252 cp++; 4257 cp++;
4253 if (*cp == ':' || iswhite (*cp)) 4258 if (*cp == ':' || c_isspace (*cp))
4254 /* Found end of label, so copy it and add it to the table. */ 4259 /* Found end of label, so copy it and add it to the table. */
4255 make_tag (lb.buffer, cp - lb.buffer, true, 4260 make_tag (lb.buffer, cp - lb.buffer, true,
4256 lb.buffer, cp - lb.buffer + 1, lineno, linecharno); 4261 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
@@ -4338,7 +4343,7 @@ Perl_functions (FILE *inf)
4338 varstart += 1; 4343 varstart += 1;
4339 do 4344 do
4340 cp++; 4345 cp++;
4341 while (ISALNUM (*cp) || *cp == '_'); 4346 while (c_isalnum (*cp) || *cp == '_');
4342 } 4347 }
4343 else if (qual) 4348 else if (qual)
4344 { 4349 {
@@ -4433,7 +4438,7 @@ PHP_functions (FILE *inf)
4433 if (*cp != '\0') 4438 if (*cp != '\0')
4434 { 4439 {
4435 name = cp; 4440 name = cp;
4436 while (*cp != '\0' && !iswhite (*cp)) 4441 while (*cp != '\0' && !c_isspace (*cp))
4437 cp++; 4442 cp++;
4438 make_tag (name, cp - name, false, 4443 make_tag (name, cp - name, false,
4439 lb.buffer, cp - lb.buffer + 1, lineno, linecharno); 4444 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
@@ -4485,10 +4490,10 @@ Cobol_paragraphs (FILE *inf)
4485 bp += 8; 4490 bp += 8;
4486 4491
4487 /* If eoln, compiler option or comment ignore whole line. */ 4492 /* If eoln, compiler option or comment ignore whole line. */
4488 if (bp[-1] != ' ' || !ISALNUM (bp[0])) 4493 if (bp[-1] != ' ' || !c_isalnum (bp[0]))
4489 continue; 4494 continue;
4490 4495
4491 for (ep = bp; ISALNUM (*ep) || *ep == '-'; ep++) 4496 for (ep = bp; c_isalnum (*ep) || *ep == '-'; ep++)
4492 continue; 4497 continue;
4493 if (*ep++ == '.') 4498 if (*ep++ == '.')
4494 make_tag (bp, ep - bp, true, 4499 make_tag (bp, ep - bp, true,
@@ -4636,7 +4641,7 @@ Pascal_functions (FILE *inf)
4636 /* Check if this is an "extern" declaration. */ 4641 /* Check if this is an "extern" declaration. */
4637 if (*dbp == '\0') 4642 if (*dbp == '\0')
4638 continue; 4643 continue;
4639 if (lowcase (*dbp) == 'e') 4644 if (c_tolower (*dbp) == 'e')
4640 { 4645 {
4641 if (nocase_tail ("extern")) /* superfluous, really! */ 4646 if (nocase_tail ("extern")) /* superfluous, really! */
4642 { 4647 {
@@ -4644,7 +4649,7 @@ Pascal_functions (FILE *inf)
4644 verify_tag = false; 4649 verify_tag = false;
4645 } 4650 }
4646 } 4651 }
4647 else if (lowcase (*dbp) == 'f') 4652 else if (c_tolower (*dbp) == 'f')
4648 { 4653 {
4649 if (nocase_tail ("forward")) /* check for forward reference */ 4654 if (nocase_tail ("forward")) /* check for forward reference */
4650 { 4655 {
@@ -4691,7 +4696,7 @@ Pascal_functions (FILE *inf)
4691 else if (!incomment && !inquote && !found_tag) 4696 else if (!incomment && !inquote && !found_tag)
4692 { 4697 {
4693 /* Check for proc/fn keywords. */ 4698 /* Check for proc/fn keywords. */
4694 switch (lowcase (c)) 4699 switch (c_tolower (c))
4695 { 4700 {
4696 case 'p': 4701 case 'p':
4697 if (nocase_tail ("rocedure")) /* c = 'p', dbp has advanced */ 4702 if (nocase_tail ("rocedure")) /* c = 'p', dbp has advanced */
@@ -4855,13 +4860,13 @@ Forth_words (FILE *inf)
4855 4860
4856 LOOP_ON_INPUT_LINES (inf, lb, bp) 4861 LOOP_ON_INPUT_LINES (inf, lb, bp)
4857 while ((bp = skip_spaces (bp))[0] != '\0') 4862 while ((bp = skip_spaces (bp))[0] != '\0')
4858 if (bp[0] == '\\' && iswhite (bp[1])) 4863 if (bp[0] == '\\' && c_isspace (bp[1]))
4859 break; /* read next line */ 4864 break; /* read next line */
4860 else if (bp[0] == '(' && iswhite (bp[1])) 4865 else if (bp[0] == '(' && c_isspace (bp[1]))
4861 do /* skip to ) or eol */ 4866 do /* skip to ) or eol */
4862 bp++; 4867 bp++;
4863 while (*bp != ')' && *bp != '\0'); 4868 while (*bp != ')' && *bp != '\0');
4864 else if ((bp[0] == ':' && iswhite (bp[1]) && bp++) 4869 else if ((bp[0] == ':' && c_isspace (bp[1]) && bp++)
4865 || LOOKING_AT_NOCASE (bp, "constant") 4870 || LOOKING_AT_NOCASE (bp, "constant")
4866 || LOOKING_AT_NOCASE (bp, "code") 4871 || LOOKING_AT_NOCASE (bp, "code")
4867 || LOOKING_AT_NOCASE (bp, "create") 4872 || LOOKING_AT_NOCASE (bp, "create")
@@ -4972,7 +4977,7 @@ TeX_commands (FILE *inf)
4972 cp++; 4977 cp++;
4973 } 4978 }
4974 for (p = cp; 4979 for (p = cp;
4975 (!iswhite (*p) && *p != '#' && 4980 (!c_isspace (*p) && *p != '#' &&
4976 *p != TEX_opgrp && *p != TEX_clgrp); 4981 *p != TEX_opgrp && *p != TEX_clgrp);
4977 p++) 4982 p++)
4978 continue; 4983 continue;
@@ -5130,7 +5135,7 @@ HTML_labels (FILE *inf)
5130 else if (intag) /* look for "name=" or "id=" */ 5135 else if (intag) /* look for "name=" or "id=" */
5131 { 5136 {
5132 while (*dbp != '\0' && *dbp != '>' 5137 while (*dbp != '\0' && *dbp != '>'
5133 && lowcase (*dbp) != 'n' && lowcase (*dbp) != 'i') 5138 && c_tolower (*dbp) != 'n' && c_tolower (*dbp) != 'i')
5134 dbp++; 5139 dbp++;
5135 if (*dbp == '\0') 5140 if (*dbp == '\0')
5136 break; /* go to next line */ 5141 break; /* go to next line */
@@ -5172,7 +5177,7 @@ HTML_labels (FILE *inf)
5172 if (*dbp == '<') 5177 if (*dbp == '<')
5173 { 5178 {
5174 intag = true; 5179 intag = true;
5175 inanchor = (lowcase (dbp[1]) == 'a' && !intoken (dbp[2])); 5180 inanchor = (c_tolower (dbp[1]) == 'a' && !intoken (dbp[2]));
5176 continue; /* look on the same line */ 5181 continue; /* look on the same line */
5177 } 5182 }
5178 5183
@@ -5192,7 +5197,7 @@ HTML_labels (FILE *inf)
5192 if (*dbp == '\0') 5197 if (*dbp == '\0')
5193 break; /* go to next line */ 5198 break; /* go to next line */
5194 intag = true; 5199 intag = true;
5195 if (lowcase (dbp[1]) == 'a' && !intoken (dbp[2])) 5200 if (c_tolower (dbp[1]) == 'a' && !intoken (dbp[2]))
5196 { 5201 {
5197 inanchor = true; 5202 inanchor = true;
5198 continue; /* look on the same line */ 5203 continue; /* look on the same line */
@@ -5239,7 +5244,7 @@ Prolog_functions (FILE *inf)
5239 { 5244 {
5240 if (cp[0] == '\0') /* Empty line */ 5245 if (cp[0] == '\0') /* Empty line */
5241 continue; 5246 continue;
5242 else if (iswhite (cp[0])) /* Not a predicate */ 5247 else if (c_isspace (cp[0])) /* Not a predicate */
5243 continue; 5248 continue;
5244 else if (cp[0] == '/' && cp[1] == '*') /* comment. */ 5249 else if (cp[0] == '/' && cp[1] == '*') /* comment. */
5245 prolog_skip_comment (&lb, inf); 5250 prolog_skip_comment (&lb, inf);
@@ -5331,11 +5336,11 @@ prolog_atom (char *s, size_t pos)
5331 5336
5332 origpos = pos; 5337 origpos = pos;
5333 5338
5334 if (ISLOWER (s[pos]) || (s[pos] == '_')) 5339 if (c_islower (s[pos]) || s[pos] == '_')
5335 { 5340 {
5336 /* The atom is unquoted. */ 5341 /* The atom is unquoted. */
5337 pos++; 5342 pos++;
5338 while (ISALNUM (s[pos]) || (s[pos] == '_')) 5343 while (c_isalnum (s[pos]) || s[pos] == '_')
5339 { 5344 {
5340 pos++; 5345 pos++;
5341 } 5346 }
@@ -5399,7 +5404,7 @@ Erlang_functions (FILE *inf)
5399 { 5404 {
5400 if (cp[0] == '\0') /* Empty line */ 5405 if (cp[0] == '\0') /* Empty line */
5401 continue; 5406 continue;
5402 else if (iswhite (cp[0])) /* Not function nor attribute */ 5407 else if (c_isspace (cp[0])) /* Not function nor attribute */
5403 continue; 5408 continue;
5404 else if (cp[0] == '%') /* comment */ 5409 else if (cp[0] == '%') /* comment */
5405 continue; 5410 continue;
@@ -5506,12 +5511,12 @@ erlang_atom (char *s)
5506{ 5511{
5507 int pos = 0; 5512 int pos = 0;
5508 5513
5509 if (ISALPHA (s[pos]) || s[pos] == '_') 5514 if (c_isalpha (s[pos]) || s[pos] == '_')
5510 { 5515 {
5511 /* The atom is unquoted. */ 5516 /* The atom is unquoted. */
5512 do 5517 do
5513 pos++; 5518 pos++;
5514 while (ISALNUM (s[pos]) || s[pos] == '_'); 5519 while (c_isalnum (s[pos]) || s[pos] == '_');
5515 } 5520 }
5516 else if (s[pos] == '\'') 5521 else if (s[pos] == '\'')
5517 { 5522 {
@@ -5729,10 +5734,10 @@ add_regex (char *regexp_pattern, language *lang)
5729 *patbuf = zeropattern; 5734 *patbuf = zeropattern;
5730 if (ignore_case) 5735 if (ignore_case)
5731 { 5736 {
5732 static char lc_trans[CHARS]; 5737 static char lc_trans[UCHAR_MAX + 1];
5733 int i; 5738 int i;
5734 for (i = 0; i < CHARS; i++) 5739 for (i = 0; i < UCHAR_MAX + 1; i++)
5735 lc_trans[i] = lowcase (i); 5740 lc_trans[i] = c_tolower (i);
5736 patbuf->translate = lc_trans; /* translation table to fold case */ 5741 patbuf->translate = lc_trans; /* translation table to fold case */
5737 } 5742 }
5738 5743
@@ -5787,7 +5792,7 @@ substitute (char *in, char *out, struct re_registers *regs)
5787 for (t = strchr (out, '\\'); 5792 for (t = strchr (out, '\\');
5788 t != NULL; 5793 t != NULL;
5789 t = strchr (t + 2, '\\')) 5794 t = strchr (t + 2, '\\'))
5790 if (ISDIGIT (t[1])) 5795 if (c_isdigit (t[1]))
5791 { 5796 {
5792 dig = t[1] - '0'; 5797 dig = t[1] - '0';
5793 diglen = regs->end[dig] - regs->start[dig]; 5798 diglen = regs->end[dig] - regs->start[dig];
@@ -5801,7 +5806,7 @@ substitute (char *in, char *out, struct re_registers *regs)
5801 result = xnew (size + 1, char); 5806 result = xnew (size + 1, char);
5802 5807
5803 for (t = result; *out != '\0'; out++) 5808 for (t = result; *out != '\0'; out++)
5804 if (*out == '\\' && ISDIGIT (*++out)) 5809 if (*out == '\\' && c_isdigit (*++out))
5805 { 5810 {
5806 dig = *out - '0'; 5811 dig = *out - '0';
5807 diglen = regs->end[dig] - regs->start[dig]; 5812 diglen = regs->end[dig] - regs->start[dig];
@@ -5921,9 +5926,9 @@ regex_tag_multiline (void)
5921static bool 5926static bool
5922nocase_tail (const char *cp) 5927nocase_tail (const char *cp)
5923{ 5928{
5924 register int len = 0; 5929 int len = 0;
5925 5930
5926 while (*cp != '\0' && lowcase (*cp) == lowcase (dbp[len])) 5931 while (*cp != '\0' && c_tolower (*cp) == c_tolower (dbp[len]))
5927 cp++, len++; 5932 cp++, len++;
5928 if (*cp == '\0' && !intoken (dbp[len])) 5933 if (*cp == '\0' && !intoken (dbp[len]))
5929 { 5934 {
@@ -6257,7 +6262,7 @@ savenstr (const char *cp, int len)
6257static char * 6262static char *
6258skip_spaces (char *cp) 6263skip_spaces (char *cp)
6259{ 6264{
6260 while (iswhite (*cp)) 6265 while (c_isspace (*cp))
6261 cp++; 6266 cp++;
6262 return cp; 6267 return cp;
6263} 6268}
@@ -6266,7 +6271,7 @@ skip_spaces (char *cp)
6266static char * 6271static char *
6267skip_non_spaces (char *cp) 6272skip_non_spaces (char *cp)
6268{ 6273{
6269 while (*cp != '\0' && !iswhite (*cp)) 6274 while (*cp != '\0' && !c_isspace (*cp))
6270 cp++; 6275 cp++;
6271 return cp; 6276 return cp;
6272} 6277}
@@ -6527,7 +6532,7 @@ filename_is_absolute (char *fn)
6527{ 6532{
6528 return (fn[0] == '/' 6533 return (fn[0] == '/'
6529#ifdef DOS_NT 6534#ifdef DOS_NT
6530 || (ISALPHA (fn[0]) && fn[1] == ':' && fn[2] == '/') 6535 || (c_isalpha (fn[0]) && fn[1] == ':' && fn[2] == '/')
6531#endif 6536#endif
6532 ); 6537 );
6533} 6538}
@@ -6541,9 +6546,8 @@ canonicalize_filename (register char *fn)
6541 6546
6542#ifdef DOS_NT 6547#ifdef DOS_NT
6543 /* Canonicalize drive letter case. */ 6548 /* Canonicalize drive letter case. */
6544# define ISUPPER(c) isupper (CHAR (c)) 6549 if (c_isupper (fn[0]) && fn[1] == ':')
6545 if (fn[0] != '\0' && fn[1] == ':' && ISUPPER (fn[0])) 6550 fn[0] = c_tolower (fn[0]);
6546 fn[0] = lowcase (fn[0]);
6547 6551
6548 /* Collapse multiple forward- and back-slashes into a single forward 6552 /* Collapse multiple forward- and back-slashes into a single forward
6549 slash. */ 6553 slash. */