diff options
| author | Paul Eggert | 2015-10-12 15:30:18 -0700 |
|---|---|---|
| committer | Paul Eggert | 2015-10-12 15:33:53 -0700 |
| commit | 38f99a02b83e9e408970cb7abdb685725b2004f9 (patch) | |
| tree | 0cee2e10901a3e984e466fae8c72c1db0a953c2b /lib-src | |
| parent | e57a0c3d38b3e2bdd408a7e02b7308fa281f3073 (diff) | |
| download | emacs-38f99a02b83e9e408970cb7abdb685725b2004f9.tar.gz emacs-38f99a02b83e9e408970cb7abdb685725b2004f9.zip | |
Unmacroize ebrowse.c and etags.c a bit
* lib-src/ebrowse.c (READ_CHUNK_SIZE): Now an enum constant.
(streq, filename_eq, set_flag, has_flag): Now inline functions.
(set_flag): First arg is now an address, not an lvalue.
All callers changed.
(filename_eq, set_flag, has_flag):
Rename from FILENAME_EQ, SET_FLAG, HAS_FLAG.
All callers changed.
* lib-src/etags.c (streq, strcaseeq, strneq, strncaseeq):
Now inline functions. Remove asserts that are unnecessary these
days (and in some cases were too-generous anyway).
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/ebrowse.c | 84 | ||||
| -rw-r--r-- | lib-src/etags.c | 27 |
2 files changed, 72 insertions, 39 deletions
diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c index 09edc7d3db3..f2093ae258f 100644 --- a/lib-src/ebrowse.c +++ b/lib-src/ebrowse.c | |||
| @@ -32,27 +32,32 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 32 | #define SEEK_END 2 | 32 | #define SEEK_END 2 |
| 33 | #endif | 33 | #endif |
| 34 | 34 | ||
| 35 | /* Conditionalize function prototypes. */ | ||
| 36 | |||
| 37 | /* Value is non-zero if strings X and Y compare equal. */ | ||
| 38 | |||
| 39 | #define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0) | ||
| 40 | |||
| 41 | #include <min-max.h> | 35 | #include <min-max.h> |
| 42 | 36 | ||
| 43 | /* Files are read in chunks of this number of bytes. */ | 37 | /* Files are read in chunks of this number of bytes. */ |
| 44 | 38 | ||
| 45 | #define READ_CHUNK_SIZE (100 * 1024) | 39 | enum { READ_CHUNK_SIZE = 100 * 1024 }; |
| 46 | 40 | ||
| 47 | #if defined (__MSDOS__) | 41 | /* Value is true if strings X and Y compare equal. */ |
| 48 | #define FILENAME_EQ(X,Y) (strcasecmp (X,Y) == 0) | 42 | |
| 49 | #else | 43 | static bool |
| 50 | #if defined (WINDOWSNT) | 44 | streq (char const *x, char const *y) |
| 51 | #define FILENAME_EQ(X,Y) (stricmp (X,Y) == 0) | 45 | { |
| 46 | return strcmp (x, y) == 0; | ||
| 47 | } | ||
| 48 | |||
| 49 | static bool | ||
| 50 | filename_eq (char const *x, char const *y) | ||
| 51 | { | ||
| 52 | #ifdef __MSDOS__ | ||
| 53 | return strcasecmp (x, y) == 0; | ||
| 54 | #elif defined WINDOWSNT | ||
| 55 | return stricmp (x, y) == 0; | ||
| 52 | #else | 56 | #else |
| 53 | #define FILENAME_EQ(X,Y) (streq (X,Y)) | 57 | return streq (x, y); |
| 54 | #endif | ||
| 55 | #endif | 58 | #endif |
| 59 | } | ||
| 60 | |||
| 56 | /* The default output file name. */ | 61 | /* The default output file name. */ |
| 57 | 62 | ||
| 58 | #define DEFAULT_OUTFILE "BROWSE" | 63 | #define DEFAULT_OUTFILE "BROWSE" |
| @@ -217,10 +222,19 @@ enum visibility | |||
| 217 | #define F_EXTERNC 256 /* Is declared extern "C". */ | 222 | #define F_EXTERNC 256 /* Is declared extern "C". */ |
| 218 | #define F_DEFINE 512 /* Is a #define. */ | 223 | #define F_DEFINE 512 /* Is a #define. */ |
| 219 | 224 | ||
| 220 | /* Two macros to set and test a bit in an int. */ | 225 | /* Set and test a bit in an int. */ |
| 221 | 226 | ||
| 222 | #define SET_FLAG(F, FLAG) ((F) |= (FLAG)) | 227 | static void |
| 223 | #define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0) | 228 | set_flag (int *f, int flag) |
| 229 | { | ||
| 230 | *f |= flag; | ||
| 231 | } | ||
| 232 | |||
| 233 | static bool | ||
| 234 | has_flag (int f, int flag) | ||
| 235 | { | ||
| 236 | return (f & flag) != 0; | ||
| 237 | } | ||
| 224 | 238 | ||
| 225 | /* Structure describing a class member. */ | 239 | /* Structure describing a class member. */ |
| 226 | 240 | ||
| @@ -682,7 +696,7 @@ add_member_decl (struct sym *cls, char *name, char *regexp, int pos, unsigned in | |||
| 682 | m = add_member (cls, name, var, sc, hash); | 696 | m = add_member (cls, name, var, sc, hash); |
| 683 | 697 | ||
| 684 | /* Have we seen a new filename? If so record that. */ | 698 | /* Have we seen a new filename? If so record that. */ |
| 685 | if (!cls->filename || !FILENAME_EQ (cls->filename, filename)) | 699 | if (!cls->filename || !filename_eq (cls->filename, filename)) |
| 686 | m->filename = filename; | 700 | m->filename = filename; |
| 687 | 701 | ||
| 688 | m->regexp = regexp; | 702 | m->regexp = regexp; |
| @@ -745,7 +759,7 @@ add_member_defn (struct sym *cls, char *name, char *regexp, int pos, unsigned in | |||
| 745 | if (!cls->sfilename) | 759 | if (!cls->sfilename) |
| 746 | cls->sfilename = filename; | 760 | cls->sfilename = filename; |
| 747 | 761 | ||
| 748 | if (!FILENAME_EQ (cls->sfilename, filename)) | 762 | if (!filename_eq (cls->sfilename, filename)) |
| 749 | m->def_filename = filename; | 763 | m->def_filename = filename; |
| 750 | 764 | ||
| 751 | m->def_regexp = regexp; | 765 | m->def_regexp = regexp; |
| @@ -830,7 +844,7 @@ add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var, | |||
| 830 | if (!found) | 844 | if (!found) |
| 831 | { | 845 | { |
| 832 | if (!global_symbols->filename | 846 | if (!global_symbols->filename |
| 833 | || !FILENAME_EQ (global_symbols->filename, filename)) | 847 | || !filename_eq (global_symbols->filename, filename)) |
| 834 | m->filename = filename; | 848 | m->filename = filename; |
| 835 | 849 | ||
| 836 | m->regexp = regexp; | 850 | m->regexp = regexp; |
| @@ -931,11 +945,11 @@ mark_virtual (struct sym *r) | |||
| 931 | for (p = r->subs; p; p = p->next) | 945 | for (p = r->subs; p; p = p->next) |
| 932 | { | 946 | { |
| 933 | for (m = r->fns; m; m = m->next) | 947 | for (m = r->fns; m; m = m->next) |
| 934 | if (HAS_FLAG (m->flags, F_VIRTUAL)) | 948 | if (has_flag (m->flags, F_VIRTUAL)) |
| 935 | { | 949 | { |
| 936 | for (m2 = p->sym->fns; m2; m2 = m2->next) | 950 | for (m2 = p->sym->fns; m2; m2 = m2->next) |
| 937 | if (m->param_hash == m2->param_hash && streq (m->name, m2->name)) | 951 | if (m->param_hash == m2->param_hash && streq (m->name, m2->name)) |
| 938 | SET_FLAG (m2->flags, F_VIRTUAL); | 952 | set_flag (&m2->flags, F_VIRTUAL); |
| 939 | } | 953 | } |
| 940 | 954 | ||
| 941 | mark_virtual (p->sym); | 955 | mark_virtual (p->sym); |
| @@ -1159,7 +1173,7 @@ sym_scope_1 (struct sym *p) | |||
| 1159 | strcpy (scope_buffer + scope_buffer_len, p->name); | 1173 | strcpy (scope_buffer + scope_buffer_len, p->name); |
| 1160 | scope_buffer_len += len; | 1174 | scope_buffer_len += len; |
| 1161 | 1175 | ||
| 1162 | if (HAS_FLAG (p->flags, F_TEMPLATE)) | 1176 | if (has_flag (p->flags, F_TEMPLATE)) |
| 1163 | { | 1177 | { |
| 1164 | ensure_scope_buffer_room (3); | 1178 | ensure_scope_buffer_room (3); |
| 1165 | strcpy (scope_buffer + scope_buffer_len, "<>"); | 1179 | strcpy (scope_buffer + scope_buffer_len, "<>"); |
| @@ -2435,7 +2449,7 @@ parm_list (int *flags) | |||
| 2435 | { | 2449 | { |
| 2436 | /* We can overload the same function on `const' */ | 2450 | /* We can overload the same function on `const' */ |
| 2437 | hash = (hash << 1) ^ CONST; | 2451 | hash = (hash << 1) ^ CONST; |
| 2438 | SET_FLAG (*flags, F_CONST); | 2452 | set_flag (flags, F_CONST); |
| 2439 | MATCH (); | 2453 | MATCH (); |
| 2440 | } | 2454 | } |
| 2441 | 2455 | ||
| @@ -2443,7 +2457,7 @@ parm_list (int *flags) | |||
| 2443 | { | 2457 | { |
| 2444 | MATCH (); | 2458 | MATCH (); |
| 2445 | SKIP_MATCHING_IF ('('); | 2459 | SKIP_MATCHING_IF ('('); |
| 2446 | SET_FLAG (*flags, F_THROW); | 2460 | set_flag (flags, F_THROW); |
| 2447 | } | 2461 | } |
| 2448 | 2462 | ||
| 2449 | if (LOOKING_AT ('=')) | 2463 | if (LOOKING_AT ('=')) |
| @@ -2452,7 +2466,7 @@ parm_list (int *flags) | |||
| 2452 | if (LOOKING_AT (CINT) && yyival == 0) | 2466 | if (LOOKING_AT (CINT) && yyival == 0) |
| 2453 | { | 2467 | { |
| 2454 | MATCH (); | 2468 | MATCH (); |
| 2455 | SET_FLAG (*flags, F_PURE); | 2469 | set_flag (flags, F_PURE); |
| 2456 | } | 2470 | } |
| 2457 | } | 2471 | } |
| 2458 | } | 2472 | } |
| @@ -2505,25 +2519,25 @@ member (struct sym *cls, int vis) | |||
| 2505 | /* A function or class may follow. */ | 2519 | /* A function or class may follow. */ |
| 2506 | case TEMPLATE: | 2520 | case TEMPLATE: |
| 2507 | MATCH (); | 2521 | MATCH (); |
| 2508 | SET_FLAG (flags, F_TEMPLATE); | 2522 | set_flag (&flags, F_TEMPLATE); |
| 2509 | /* Skip over template argument list */ | 2523 | /* Skip over template argument list */ |
| 2510 | SKIP_MATCHING_IF ('<'); | 2524 | SKIP_MATCHING_IF ('<'); |
| 2511 | break; | 2525 | break; |
| 2512 | 2526 | ||
| 2513 | case EXPLICIT: | 2527 | case EXPLICIT: |
| 2514 | SET_FLAG (flags, F_EXPLICIT); | 2528 | set_flag (&flags, F_EXPLICIT); |
| 2515 | goto typeseen; | 2529 | goto typeseen; |
| 2516 | 2530 | ||
| 2517 | case MUTABLE: | 2531 | case MUTABLE: |
| 2518 | SET_FLAG (flags, F_MUTABLE); | 2532 | set_flag (&flags, F_MUTABLE); |
| 2519 | goto typeseen; | 2533 | goto typeseen; |
| 2520 | 2534 | ||
| 2521 | case T_INLINE: | 2535 | case T_INLINE: |
| 2522 | SET_FLAG (flags, F_INLINE); | 2536 | set_flag (&flags, F_INLINE); |
| 2523 | goto typeseen; | 2537 | goto typeseen; |
| 2524 | 2538 | ||
| 2525 | case VIRTUAL: | 2539 | case VIRTUAL: |
| 2526 | SET_FLAG (flags, F_VIRTUAL); | 2540 | set_flag (&flags, F_VIRTUAL); |
| 2527 | goto typeseen; | 2541 | goto typeseen; |
| 2528 | 2542 | ||
| 2529 | case '[': | 2543 | case '[': |
| @@ -2761,7 +2775,7 @@ parse_classname (void) | |||
| 2761 | if (LOOKING_AT ('<')) | 2775 | if (LOOKING_AT ('<')) |
| 2762 | { | 2776 | { |
| 2763 | skip_matching (); | 2777 | skip_matching (); |
| 2764 | SET_FLAG (last_class->flags, F_TEMPLATE); | 2778 | set_flag (&last_class->flags, F_TEMPLATE); |
| 2765 | } | 2779 | } |
| 2766 | 2780 | ||
| 2767 | if (!LOOKING_AT (DCOLON)) | 2781 | if (!LOOKING_AT (DCOLON)) |
| @@ -3189,7 +3203,7 @@ declaration (int flags) | |||
| 3189 | break; | 3203 | break; |
| 3190 | 3204 | ||
| 3191 | case T_INLINE: | 3205 | case T_INLINE: |
| 3192 | SET_FLAG (flags, F_INLINE); | 3206 | set_flag (&flags, F_INLINE); |
| 3193 | MATCH (); | 3207 | MATCH (); |
| 3194 | break; | 3208 | break; |
| 3195 | 3209 | ||
| @@ -3335,14 +3349,14 @@ globals (int start_flags) | |||
| 3335 | MATCH_IF ('}'); | 3349 | MATCH_IF ('}'); |
| 3336 | } | 3350 | } |
| 3337 | else | 3351 | else |
| 3338 | SET_FLAG (flags, F_EXTERNC); | 3352 | set_flag (&flags, F_EXTERNC); |
| 3339 | } | 3353 | } |
| 3340 | break; | 3354 | break; |
| 3341 | 3355 | ||
| 3342 | case TEMPLATE: | 3356 | case TEMPLATE: |
| 3343 | MATCH (); | 3357 | MATCH (); |
| 3344 | SKIP_MATCHING_IF ('<'); | 3358 | SKIP_MATCHING_IF ('<'); |
| 3345 | SET_FLAG (flags, F_TEMPLATE); | 3359 | set_flag (&flags, F_TEMPLATE); |
| 3346 | break; | 3360 | break; |
| 3347 | 3361 | ||
| 3348 | case CLASS: case STRUCT: case UNION: | 3362 | case CLASS: case STRUCT: case UNION: |
diff --git a/lib-src/etags.c b/lib-src/etags.c index 791722d4b66..8b980d365ef 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c | |||
| @@ -150,10 +150,29 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4"; | |||
| 150 | # define CTAGS false | 150 | # define CTAGS false |
| 151 | #endif | 151 | #endif |
| 152 | 152 | ||
| 153 | #define streq(s,t) (assert ((s)!=NULL || (t)!=NULL), !strcmp (s, t)) | 153 | static bool |
| 154 | #define strcaseeq(s,t) (assert ((s)!=NULL && (t)!=NULL), !c_strcasecmp (s, t)) | 154 | streq (char const *s, char const *t) |
| 155 | #define strneq(s,t,n) (assert ((s)!=NULL || (t)!=NULL), !strncmp (s, t, n)) | 155 | { |
| 156 | #define strncaseeq(s,t,n) (assert ((s)!=NULL && (t)!=NULL), !c_strncasecmp (s, t, n)) | 156 | return strcmp (s, t) == 0; |
| 157 | } | ||
| 158 | |||
| 159 | static bool | ||
| 160 | strcaseeq (char const *s, char const *t) | ||
| 161 | { | ||
| 162 | return c_strcasecmp (s, t) == 0; | ||
| 163 | } | ||
| 164 | |||
| 165 | static bool | ||
| 166 | strneq (char const *s, char const *t, size_t n) | ||
| 167 | { | ||
| 168 | return strncmp (s, t, n) == 0; | ||
| 169 | } | ||
| 170 | |||
| 171 | static bool | ||
| 172 | strncaseeq (char const *s, char const *t, size_t n) | ||
| 173 | { | ||
| 174 | return c_strncasecmp (s, t, n) == 0; | ||
| 175 | } | ||
| 157 | 176 | ||
| 158 | /* C is not in a name. */ | 177 | /* C is not in a name. */ |
| 159 | static bool | 178 | static bool |