From: John Millaway Date: Sat, 17 Aug 2002 20:04:51 +0000 (+0000) Subject: Start conditions now optional in header. X-Git-Tag: flex-2-5-15~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=67bfe789c2818f8709fd05f058f48ae436715575;p=flex Start conditions now optional in header. undef's now optional in header. Start conditions are NOT prefixed. --- diff --git a/flexdef.h b/flexdef.h index 036611c..a8a8ea9 100644 --- a/flexdef.h +++ b/flexdef.h @@ -1088,16 +1088,4 @@ extern jmp_buf flex_main_jmp_buf; /* Removes all \n and \r chars from tail of str. returns str. */ extern char* chomp(char* str); -/* converts str to lowercase. returns str. */ -extern char * strlower (char *str); - -/* converts str to lowercase. returns str. */ -extern char * strupper (char *str); - -/* guess case preference for str */ -extern int case_preference (const char* str); - -/* creates a name-space safe copy of start cond name in buf. returns buf */ -extern char * fix_scname (char * buf, const char * name); - #endif /* not defined FLEXDEF_H */ diff --git a/main.c b/main.c index 895b5ce..35ddc28 100644 --- a/main.c +++ b/main.c @@ -557,13 +557,18 @@ int exit_status; fprintf(header_out,"#line %d \"%s\"\n", (++nlines)+1, headerfilename); /* Print the prefixed start conditions. */ + fprintf(header_out,"#ifdef YY_HEADER_EXPORT_START_CONDITIONS\n"); + fprintf(header_out,"/* Beware! Start conditions are not prefixed. */\n"); + for (i=1; i <= lastsc; i++) - fprintf(header_out, "#define %s %d\n", - fix_scname(linebuf,scname[i]), i-1); + fprintf(header_out, "#define %s %d\n",scname[i], i-1); + fprintf(header_out,"#endif /* YY_HEADER_EXPORT_START_CONDITIONS */\n\n"); /* Kill ALL flex-related macros. This is so the user * can #include more than one generated header file. */ - fprintf(header_out,"\n"); + fprintf(header_out,"#ifndef YY_HEADER_NO_UNDEFS\n"); + fprintf(header_out,"/* Undefine all internal macros, etc., that do no belong in the header. */\n\n"); + fprintf(header_out,"#undef BEGIN\n"); fprintf(header_out,"#undef ECHO\n"); fprintf(header_out,"#undef EOB_ACT_CONTINUE_SCAN\n"); @@ -715,6 +720,7 @@ int exit_status; for(i=0; i < defs_buf.nelts; i++) fprintf(header_out, "#undef %s\n", ((char**)defs_buf.elts)[i]); + fprintf(header_out,"#endif /* !YY_HEADER_NO_UNDEFS */\n"); fprintf(header_out, "\n"); fprintf(header_out, "#undef %sIN_HEADER\n", prefix); fprintf(header_out, "#endif /* %sHEADER_H */\n", prefix); diff --git a/misc.c b/misc.c index 976ea18..cc595fa 100644 --- a/misc.c +++ b/misc.c @@ -942,104 +942,3 @@ char* chomp(str) return str; } -/* Converts str to lowercase in place. returns str*/ -char * strlower (str) - char* str; -{ - char * s = str; - if (str) - for (s=str; *s; s++) - *s = tolower(*s); - return str; -} - -/* Converts str to uppercase in place. returns str*/ -char * strupper (str) - char* str; -{ - char * s; - if (str) - for (s=str; *s; s++) - *s = toupper(*s); - return str; -} - -/* return < 0 if prefers lowercase - * return > 0 if prefers uppercase - * return 0 if no preference or it looks like first-letter-capitalization - * Similar to strcmp(), the absolute value of the return value is larger - * the more characters are upper or lowercase. - */ -int case_preference (str) - const char* str; -{ - int nup=0, nlow=0, first_up=0; - const char* s; - if (!str) - return 0; - - /* find the first upper or lowercase letter */ - for (s=str; *s; s++){ - if (!isupper(*s) && !islower(*s)) - continue; - first_up = isupper(*s); - break; - } - - for (s=str; *s; s++){ - if (isupper(*s)) - nup++; - if (islower(*s)) - nlow++; - } - - return (first_up && nlow > nup) ? 0 : nup - nlow; -} - -/* Creates a name-space friendly start condition name, safe for - * use in the generated header. - * buf should be large enough to contain name and prefix. - * returns buf - */ -char * fix_scname (buf, name) - char * buf; - const char * name; -{ - char * pre; - int cn,cp; - - buf[0]= '\0'; - if (!name) - return buf; - - /* we do comparisons in lowercase */ - pre = copy_string(prefix); - strlower(pre); - strcpy(buf,name); - strlower(buf); - - /* If the user has already prefixed name, then we leave it alone. */ - if (strncmp(buf,pre,strlen(pre))==0 && strlen(name) > strlen(pre)){ - strcpy(buf,name); - free(pre); - return buf; - } - - /* Build the new name */ - sprintf(buf,"%ssc_%s", prefix, name); - - /* Decide whether the user prefers upper or lowercase or neither */ - cp = case_preference(prefix); - cn = case_preference(name); - - if (cn != 0) { - /* If it's mostly lowercase... */ - if (cn < 0 && (0 - cn) > strlen(name)/2) - strlower(buf); - else if (cn > 0 && cn > strlen(name)/2) - strupper(buf); - } - - free(pre); - return buf; -}