#include "defs.h"#include "names.h"#include "output.h"#include "stdarg.h"Include dependency graph for niceprintf.c:

Go to the source code of this file.
Defines | |
| #define | TOO_LONG_INDENT (2 * tab_size) |
| #define | MAX_INDENT 44 |
| #define | MIN_INDENT 22 |
| #define | SPRINTF(x, a, b, c, d, e, f, g) vsprintf(x,a,ap) |
| #define | max_line_len c_output_line_length |
| #define | isident(x) (Tr[x] & 1) |
| #define | isntident(x) (!Tr[x]) |
Functions | |
| static void ind_printf | Argdcl ((int, FILE *, const char *, va_list)) |
| static void | write_indent (FILE *fp, int use_indent, int extra_indent, char *start, char *end) |
| void | margin_printf (FILE *fp, const char *fmt,...) |
| void | nice_printf (FILE *fp, const char *fmt,...) |
| void | np_init (Void) |
| static char * | adjust_pointer_in_string (register char *pointer) |
| static void | fwd_strcpy (register char *t, register char *s) |
| static void | ind_printf (int use_indent, FILE *fp, const char *a, va_list ap) |
Variables | |
| static int | last_was_newline = 0 |
| int | sharp_line = 0 |
| int | indent = 0 |
| int | in_comment = 0 |
| int | in_define = 0 |
| int | gflag1 |
| char | filename [] |
| static char * | output_buf |
| static char * | next_slot |
| static char * | string_start |
| static char * | word_start = NULL |
| static int | cursor_pos = 0 |
| static int | In_string = 0 |
| #define MAX_INDENT 44 |
| #define max_line_len c_output_line_length |
| #define MIN_INDENT 22 |
| #define TOO_LONG_INDENT (2 * tab_size) |
| static char* adjust_pointer_in_string | ( | register char * | pointer | ) | [static] |
Definition at line 169 of file niceprintf.c.
Referenced by ind_printf().
00171 { 00172 register char *s, *s1, *se, *s0; 00173 00174 /* arrange not to break \002 */ 00175 s1 = string_start ? string_start : output_buf; 00176 for(s = s1; s < pointer; s++) { 00177 s0 = s1; 00178 s1 = s; 00179 if (*s == '\\') { 00180 se = s++ + 4; 00181 if (se > pointer) 00182 break; 00183 if (*s < '0' || *s > '7') 00184 continue; 00185 while(++s < se) 00186 if (*s < '0' || *s > '7') 00187 break; 00188 --s; 00189 } 00190 } 00191 return s0 - 1; 00192 }
Here is the caller graph for this function:

| static void ind_printf Argdcl | ( | (int, FILE *, const char *, va_list) | ) | [static] |
| static void fwd_strcpy | ( | register char * | t, | |
| register char * | s | |||
| ) | [static] |
Definition at line 203 of file niceprintf.c.
Referenced by ind_printf().
Here is the caller graph for this function:

| static void ind_printf | ( | int | use_indent, | |
| FILE * | fp, | |||
| const char * | a, | |||
| va_list | ap | |||
| ) | [static] |
Definition at line 225 of file niceprintf.c.
References adjust_pointer_in_string(), Ansi, c_file, fatalstr(), fwd_strcpy(), gflag1, in_comment, in_define, ind, indent, isident, isntident, last_was_newline, MAX_INDENT, max_line_len, MIN_INDENT, NULL, sharp_line, SPRINTF, strchr(), TOO_LONG_INDENT, tr_tab, and write_indent().
Referenced by margin_printf(), and nice_printf().
00227 { 00228 extern int max_line_len; 00229 extern FILEP c_file; 00230 extern char tr_tab[]; /* in output.c */ 00231 register char *Tr = tr_tab; 00232 int ch, cmax, inc, ind; 00233 static int extra_indent, last_indent, set_cursor = 1; 00234 00235 cursor_pos += indent - last_indent; 00236 last_indent = indent; 00237 SPRINTF (next_slot, a, b, c, d, e, f, g); 00238 00239 if (fp != c_file) { 00240 fprintf (fp,"%s", next_slot); 00241 return; 00242 } /* if fp != c_file */ 00243 00244 do { 00245 char *pointer; 00246 00247 /* The for loop will parse one output line */ 00248 00249 if (set_cursor) { 00250 ind = indent <= MAX_INDENT 00251 ? indent 00252 : MIN_INDENT + indent % (MAX_INDENT - MIN_INDENT); 00253 cursor_pos = extra_indent; 00254 if (use_indent) 00255 cursor_pos += ind; 00256 set_cursor = 0; 00257 } 00258 if (in_comment) { 00259 cmax = max_line_len + 32; /* let comments be wider */ 00260 for (pointer = next_slot; *pointer && *pointer != '\n' && 00261 cursor_pos <= cmax; pointer++) 00262 cursor_pos++; 00263 } 00264 else 00265 for (pointer = next_slot; *pointer && *pointer != '\n' && 00266 cursor_pos <= max_line_len; pointer++) { 00267 00268 /* Update state variables here */ 00269 00270 if (In_string) { 00271 switch(*pointer) { 00272 case '\\': 00273 if (++cursor_pos > max_line_len) { 00274 cursor_pos -= 2; 00275 --pointer; 00276 goto overflow; 00277 } 00278 ++pointer; 00279 break; 00280 case '"': 00281 In_string = 0; 00282 word_start = 0; 00283 } 00284 } 00285 else switch (*pointer) { 00286 case '"': 00287 if (cursor_pos + 5 > max_line_len) { 00288 word_start = 0; 00289 --pointer; 00290 goto overflow; 00291 } 00292 In_string = 1; 00293 string_start = word_start = pointer; 00294 break; 00295 case '\'': 00296 if (pointer[1] == '\\') 00297 if ((ch = pointer[2]) >= '0' && ch <= '7') 00298 for(inc = 3; pointer[inc] != '\'' 00299 && ++inc < 5;); 00300 else 00301 inc = 3; 00302 else 00303 inc = 2; 00304 /*debug*/ if (pointer[inc] != '\'') 00305 /*debug*/ fatalstr("Bad character constant %.10s", 00306 pointer); 00307 if ((cursor_pos += inc) > max_line_len) { 00308 cursor_pos -= inc; 00309 word_start = 0; 00310 --pointer; 00311 goto overflow; 00312 } 00313 word_start = pointer; 00314 pointer += inc; 00315 break; 00316 case '\t': 00317 cursor_pos = 8 * ((cursor_pos + 8) / 8) - 1; 00318 break; 00319 default: { 00320 00321 /* HACK Assumes that all characters in an atomic C token will be written 00322 at the same time. Must check for tokens first, since '-' is considered 00323 part of an identifier; checking isident first would mean breaking up "->" */ 00324 00325 if (word_start) { 00326 if (isntident(*(unsigned char *)pointer)) 00327 word_start = NULL; 00328 } 00329 else if (isident(*(unsigned char *)pointer)) 00330 word_start = pointer; 00331 break; 00332 } /* default */ 00333 } /* switch */ 00334 cursor_pos++; 00335 } /* for pointer = next_slot */ 00336 overflow: 00337 if (*pointer == '\0') { 00338 00339 /* The output line is not complete, so break out and don't output 00340 anything. The current line fragment will be stored in the buffer */ 00341 00342 next_slot = pointer; 00343 break; 00344 } else { 00345 char last_char; 00346 int in_string0 = In_string; 00347 00348 /* If the line was too long, move pointer back to the character before 00349 the current word. This allows line breaking on word boundaries. Make 00350 sure that 80 character comment lines get broken up somehow. We assume 00351 that any non-string 80 character identifier must be in a comment. 00352 */ 00353 00354 if (*pointer == '\n') 00355 in_define = 0; 00356 else if (word_start && word_start > output_buf) 00357 if (In_string) 00358 if (string_start && pointer - string_start < 5) 00359 pointer = string_start - 1; 00360 else { 00361 pointer = adjust_pointer_in_string(pointer); 00362 string_start = 0; 00363 } 00364 else if (word_start == string_start 00365 && pointer - string_start >= 5) { 00366 pointer = adjust_pointer_in_string(next_slot); 00367 In_string = 1; 00368 string_start = 0; 00369 } 00370 else 00371 pointer = word_start - 1; 00372 else if (cursor_pos > max_line_len) { 00373 #ifndef ANSI_Libraries 00374 extern char *strchr(); 00375 #endif 00376 if (In_string) { 00377 pointer = adjust_pointer_in_string(pointer); 00378 if (string_start && pointer > string_start) 00379 string_start = 0; 00380 } 00381 else if (strchr("&*+-/<=>|", *pointer) 00382 && strchr("!%&*+-/<=>^|", pointer[-1])) { 00383 pointer -= 2; 00384 if (strchr("<>", *pointer)) /* <<=, >>= */ 00385 pointer--; 00386 } 00387 else { 00388 if (word_start) 00389 while(isident(*(unsigned char *)pointer)) 00390 pointer++; 00391 pointer--; 00392 } 00393 } 00394 last_char = *pointer; 00395 write_indent(fp, use_indent, extra_indent, output_buf, pointer); 00396 next_slot = output_buf; 00397 if (In_string && !string_start && Ansi == 1 && last_char != '\n') 00398 *next_slot++ = '"'; 00399 fwd_strcpy(next_slot, pointer + 1); 00400 00401 /* insert a line break */ 00402 00403 if (last_char == '\n') { 00404 if (In_string) 00405 last_was_newline = 0; 00406 else { 00407 last_was_newline = 1; 00408 extra_indent = 0; 00409 sharp_line = gflag1; 00410 } 00411 } 00412 else { 00413 extra_indent = TOO_LONG_INDENT; 00414 if (In_string && !string_start) { 00415 if (Ansi == 1) { 00416 fprintf(fp, gflag1 ? "\"\\\n" : "\"\n"); 00417 use_indent = 1; 00418 last_was_newline = 1; 00419 } 00420 else { 00421 fprintf(fp, "\\\n"); 00422 last_was_newline = 0; 00423 } 00424 In_string = in_string0; 00425 } 00426 else { 00427 if (in_define/* | gflag1*/) 00428 putc('\\', fp); 00429 putc ('\n', fp); 00430 last_was_newline = 1; 00431 } 00432 } /* if *pointer != '\n' */ 00433 00434 if (In_string && Ansi != 1 && !string_start) 00435 cursor_pos = 0; 00436 else 00437 set_cursor = 1; 00438 00439 string_start = word_start = NULL; 00440 00441 } /* else */ 00442 00443 } while (*next_slot); 00444 00445 } /* ind_printf */
Here is the call graph for this function:

Here is the caller graph for this function:

| void margin_printf | ( | FILE * | fp, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Definition at line 120 of file niceprintf.c.
References ind_printf().
Referenced by do_p1_comment(), do_p1_label(), ref_defs(), wr_globals(), wr_one_init(), and write_char_init().
00121 { 00122 va_list ap; 00123 va_start(ap,fmt); 00124 ind_printf(0, fp, fmt, ap); 00125 va_end(ap); 00126 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void nice_printf | ( | FILE * | fp, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Definition at line 129 of file niceprintf.c.
References ind_printf().
Referenced by Ado_string(), commonprotos(), compgoto_out(), def_commons(), def_start(), do_init_data(), do_p1_1while(), do_p1_2while(), do_p1_elseifstart(), do_p1_goto(), do_p1_head(), do_p1_subr_ret(), do_string(), do_uninit_equivs(), entry_goto(), expr_out(), extern_out(), fill_dcl(), list_arg_types(), list_init_data(), listargs(), main(), opconv_fudge(), other_undefs(), out_addr(), out_and_free_statement(), out_args(), out_asgoto(), out_call(), out_const(), out_end_for(), out_for(), out_if(), out_name(), output_arg_list(), output_binary(), output_list(), output_literal(), output_prim(), output_rbrace(), output_unary(), prolog(), protowrite(), put_semi(), putentries(), ref_defs(), start_formatting(), wr_abbrevs(), wr_ardecls(), wr_array_init(), wr_char_len(), wr_common_decls(), wr_equiv_init(), wr_globals(), wr_nv_ident_help(), wr_one_init(), wr_struct(), write_assigned_fmts(), write_comment(), write_formats(), write_ioblocks(), write_namelists(), and write_typedefs().
00130 { 00131 va_list ap; 00132 va_start(ap,fmt); 00133 ind_printf(1, fp, fmt, ap); 00134 va_end(ap); 00135 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void np_init | ( | Void | ) |
Definition at line 158 of file niceprintf.c.
References Alloc(), MAX_OUTPUT_SIZE, and memset().
Referenced by fileinit().
00159 { 00160 next_slot = output_buf = Alloc(MAX_OUTPUT_SIZE); 00161 memset(output_buf, 0, MAX_OUTPUT_SIZE); 00162 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void write_indent | ( | FILE * | fp, | |
| int | use_indent, | |||
| int | extra_indent, | |||
| char * | start, | |||
| char * | end | |||
| ) | [static] |
Definition at line 53 of file niceprintf.c.
References filename, in_define, ind, indent, last_was_newline, lineno, MAX_INDENT, MIN_INDENT, and sharp_line.
Referenced by ind_printf().
00055 { 00056 int ind, tab; 00057 00058 if (sharp_line) { 00059 fprintf(fp, "#line %ld \"%s\"\n", lineno, filename); 00060 sharp_line = 0; 00061 } 00062 if (in_define == 1) { 00063 in_define = 2; 00064 use_indent = 0; 00065 } 00066 if (last_was_newline && use_indent) { 00067 if (*start == '\n') do { 00068 putc('\n', fp); 00069 if (++start > end) 00070 return; 00071 } 00072 while(*start == '\n'); 00073 00074 ind = indent <= MAX_INDENT 00075 ? indent 00076 : MIN_INDENT + indent % (MAX_INDENT - MIN_INDENT); 00077 00078 tab = ind + extra_indent; 00079 00080 while (tab > 7) { 00081 putc ('\t', fp); 00082 tab -= 8; 00083 } /* while */ 00084 00085 while (tab-- > 0) 00086 putc (' ', fp); 00087 } /* if last_was_newline */ 00088 00089 while (start <= end) 00090 putc (*start++, fp); 00091 } /* write_indent */
Here is the caller graph for this function:

int cursor_pos = 0 [static] |
Definition at line 154 of file niceprintf.c.
| char filename[] |
Definition at line 81 of file format.c.
Referenced by C2F(), DeleteDirectory(), getfilenamehistory(), Load(), PrintPs(), Save(), SavePs(), write_indent(), and XmuLocatePixmapFile().
| int in_comment = 0 |
Definition at line 38 of file niceprintf.c.
Referenced by def_start(), ind_printf(), and write_indent().
Definition at line 155 of file niceprintf.c.
Definition at line 36 of file niceprintf.c.
Referenced by Check(), CheckCOLUMN(), CheckOptDim(), CheckOptSquare(), CheckROW(), CheckSCALAR(), CheckSquare(), CheckVECTOR(), CreCommon(), CreDIMFOREXT(), CreIMATRIX(), CrePOINTER(), CreSPARSE(), CreSTRINGMAT(), Generate(), GetCOLUMN(), GetCom(), GetIMATRIX(), GetPOINTER(), GetPOLYNOM(), GetROW(), GetSCALAR(), GetSPARSE(), GetSTRINGMAT(), GetVECTOR(), ind_printf(), OptMATRIX(), OptOpointer(), OutCommon(), OutExtBMATRIX1(), OutExtCommon(), OutExtIMATRIX(), OutExtPOLYNOM(), OutExtSPARSE(), OutExtSTRING(), OutExtSTRINGMAT(), OutIMATRIX(), OutLISTarg(), OutPOLYNOM(), OutSPARSE(), OutSTRINGMAT(), write_indent(), WriteArgCheck(), WriteCallConvertion(), WriteCallRest(), WriteCallRestCheck(), WriteCrossCheck(), WriteDeclaration(), WriteExternalVariableOutput(), WriteFortranCall(), WriteFunctionCode(), WriteHeader(), WriteInitDeclarations(), WriteListAnalysis(), WriteMain(), WriteMainHeader(), WriteOptArg(), WriteOptArgPhase2(), WriteOutput(), WriteVariable(), and WriteVariableOutput().
int last_was_newline = 0 [static] |
char* next_slot [static] |
Definition at line 150 of file niceprintf.c.
char* output_buf [static] |
Definition at line 149 of file niceprintf.c.
| int sharp_line = 0 |
char* string_start [static] |
Definition at line 151 of file niceprintf.c.
char* word_start = NULL [static] |
Definition at line 153 of file niceprintf.c.
1.5.1