diff options
author | Fred Fish <fnf@specifix.com> | 1992-11-21 06:10:08 +0000 |
---|---|---|
committer | Fred Fish <fnf@specifix.com> | 1992-11-21 06:10:08 +0000 |
commit | 5d074aa97723ff99cdeef26b3cf90e2095f3a566 (patch) | |
tree | e2fc7782cea920368364afebba4a2abc777e12b3 /gdb/c-exp.y | |
parent | 242d9c06b2cc1a554f580023c9c54bc39d420e0d (diff) | |
download | gdb-5d074aa97723ff99cdeef26b3cf90e2095f3a566.zip gdb-5d074aa97723ff99cdeef26b3cf90e2095f3a566.tar.gz gdb-5d074aa97723ff99cdeef26b3cf90e2095f3a566.tar.bz2 |
* defs.h (sevenbit_strings): Add declaration.
* defs.h (printchar): Replace with gdb_printchar.
* language.h (language_defn): Add new function pointers
la_printchar and la_printstr, to do language dependent
printing of characters and strings.
* language.h (local_printchar, local_printstr): New macros
to call language dependent functions pointed to by la_printchar
and la_printstr respectively.
* c-exp.y (emit_char, c_printchar, c_printstr): New language
dependent functions for printing characters and strings.
* c-exp.y (c_language_defn, cplus_language_defn): Add
c_printchar and c_printstr.
* command.c (do_setshow_command): Rename printchar use to
gdb_printchar.
* expprint.c (print_subexp): Replace C style string output
with call to local_printstr.
* language.c (unk_lang_printchar, unk_lang_printstr):
New stubs, currently errors.
* language.c (unknown_language_defn, auto_language_defn,
local_language_defn): Add unk_lang_printchar and
unk_lang_printstr.
* m2-exp.y (emit_char, m2_printchar, m2_printstr): New
language dependent functions to print characters and strings.
* m2-exp.y (m2_language_defn): Add m2_printchar and m2_printstr.
* utils.c (printchar): Renamed to gdb_printchar.
* valprint.c (print_string): Remove prototype, function moved
to c-exp.y, where it becomes c_printstr.
* valprint.c (print_max): Made global for reference from the
language dependent printing routines in *-exp.y.
* valprint.c (repeat_count_threshold): New variable with function
of old REPEAT_COUNT_THREHOLD define, but now settable by user.
Change all references to old macro to references to new variable.
* valprint.c (value_print, val_print): Replace calls to
print_string with calls to local_printstr.
* valprint.c (val_print): Replace C style character printing
with call to local_printchar.
* valprint.c (val_print): Add case for TYPE_CODE_CHAR.
* valprint.c (_initialize_valprint): Add add_show_from_set
call for setting up repeat_count_threshold as print variable.
**** start-sanitize-chill ****
* ch-exp.y (decode_integer_value): New function.
* ch-exp.y (decode_integer_literal): Use decode_integer_value.
* ch-exp.y (chill_printchar, chill_printstr): New language
dependent functions for printing characters and strings.
* ch-exp.y (chill_language_defn): Add chill_printchar and
chill_printstr.
**** end-sanitize-chill ****
Diffstat (limited to 'gdb/c-exp.y')
-rw-r--r-- | gdb/c-exp.y | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/gdb/c-exp.y b/gdb/c-exp.y index e806629..2ba3c8c 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -1471,6 +1471,163 @@ yyerror (msg) error (msg ? msg : "Invalid syntax in expression."); } +/* Print the character C on STREAM as part of the contents of a literal + string whose delimiter is QUOTER. Note that that format for printing + characters and strings is language specific. */ + +static void +emit_char (c, stream, quoter) + register int c; + FILE *stream; + int quoter; +{ + + c &= 0xFF; /* Avoid sign bit follies */ + + if ( c < 0x20 || /* Low control chars */ + (c >= 0x7F && c < 0xA0) || /* DEL, High controls */ + (sevenbit_strings && c >= 0x80)) { /* high order bit set */ + switch (c) + { + case '\n': + fputs_filtered ("\\n", stream); + break; + case '\b': + fputs_filtered ("\\b", stream); + break; + case '\t': + fputs_filtered ("\\t", stream); + break; + case '\f': + fputs_filtered ("\\f", stream); + break; + case '\r': + fputs_filtered ("\\r", stream); + break; + case '\033': + fputs_filtered ("\\e", stream); + break; + case '\007': + fputs_filtered ("\\a", stream); + break; + default: + fprintf_filtered (stream, "\\%.3o", (unsigned int) c); + break; + } + } else { + if (c == '\\' || c == quoter) + { + fputs_filtered ("\\", stream); + } + fprintf_filtered (stream, "%c", c); + } +} + +static void +c_printchar (c, stream) + int c; + FILE *stream; +{ + fputs_filtered ("'", stream); + emit_char (c, stream, '\''); + fputs_filtered ("'", stream); +} + +/* Print the character string STRING, printing at most LENGTH characters. + Printing stops early if the number hits print_max; repeat counts + are printed as appropriate. Print ellipses at the end if we + had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */ + +static void +c_printstr (stream, string, length, force_ellipses) + FILE *stream; + char *string; + unsigned int length; + int force_ellipses; +{ + register unsigned int i; + unsigned int things_printed = 0; + int in_quotes = 0; + int need_comma = 0; + extern int inspect_it; + extern int repeat_count_threshold; + extern int print_max; + + if (length == 0) + { + fputs_filtered ("\"\"", stdout); + return; + } + + for (i = 0; i < length && things_printed < print_max; ++i) + { + /* Position of the character we are examining + to see whether it is repeated. */ + unsigned int rep1; + /* Number of repetitions we have detected so far. */ + unsigned int reps; + + QUIT; + + if (need_comma) + { + fputs_filtered (", ", stream); + need_comma = 0; + } + + rep1 = i + 1; + reps = 1; + while (rep1 < length && string[rep1] == string[i]) + { + ++rep1; + ++reps; + } + + if (reps > repeat_count_threshold) + { + if (in_quotes) + { + if (inspect_it) + fputs_filtered ("\\\", ", stream); + else + fputs_filtered ("\", ", stream); + in_quotes = 0; + } + c_printchar (string[i], stream); + fprintf_filtered (stream, " <repeats %u times>", reps); + i = rep1 - 1; + things_printed += repeat_count_threshold; + need_comma = 1; + } + else + { + if (!in_quotes) + { + if (inspect_it) + fputs_filtered ("\\\"", stream); + else + fputs_filtered ("\"", stream); + in_quotes = 1; + } + emit_char (string[i], stream, '"'); + ++things_printed; + } + } + + /* Terminate the quotes if necessary. */ + if (in_quotes) + { + if (inspect_it) + fputs_filtered ("\\\"", stream); + else + fputs_filtered ("\"", stream); + } + + if (force_ellipses || i < length) + fputs_filtered ("...", stream); +} + + /* Table mapping opcodes into strings for printing operators and precedences of the operators. */ @@ -1561,6 +1718,8 @@ const struct language_defn c_language_defn = { type_check_off, c_parse, c_error, + c_printchar, /* Print a character constant */ + c_printstr, /* Function to print string constant */ &BUILTIN_TYPE_LONGEST, /* longest signed integral type */ &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */ &builtin_type_double, /* longest floating point type */ /*FIXME*/ @@ -1580,6 +1739,8 @@ const struct language_defn cplus_language_defn = { type_check_off, c_parse, c_error, + c_printchar, /* Print a character constant */ + c_printstr, /* Function to print string constant */ &BUILTIN_TYPE_LONGEST, /* longest signed integral type */ &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */ &builtin_type_double, /* longest floating point type */ /*FIXME*/ |