4 * This file defines commonly used utility functions to produce
5 * nicely indented output.
7 * Copyright (c) 1999 Frank Strauss, Technical University of Braunschweig.
8 * Copyright (c) 2007 J. Schoenwaelder, Jacobs University Bremen.
10 * See the file "COPYING" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 * @(#) $Id: fprint.c 8024 2008-04-11 13:25:26Z schoenw $
32 * This module keeps internal state. Hence, these functions are not
33 * thread safe. Note, however, that multi-threaded concurrent output
34 * generation may not be such a wonderful idea anyway - so using
35 * static variables may be good enough.
39 int fprint_current_column = 0;
40 int fprint_indent_max = 64;
41 int fprint_indent_texts = 4;
46 fprint(FILE *f, char *fmt, ...)
53 fprint_current_column += smiVasprintf(&s, fmt, ap);
56 if ((p = strrchr(s, '\n'))) {
57 fprint_current_column = strlen(p) - 1;
65 fprintSegment(FILE *f, int column, char *string, int length)
67 fprint(f, "%*c%s", column, ' ', string);
69 fprint(f, "%*c", length - strlen(string) - column, ' ');
76 fprintWrapped(FILE *f, int column, char *string)
78 if ((fprint_current_column + strlen(string)) > fprint_indent_max) {
80 fprint_current_column = 0;
81 fprintSegment(f, column, "", 0);
83 fprint(f, "%s", string);
89 fprintMultilineString(FILE *f, int column, const char *s)
93 fprintSegment(f, column - 1 + fprint_indent_texts, "\"", 0);
96 for (i=0; i < len; i++) {
98 fprint_current_column++;
100 fprint_current_column = 0;
101 fprintSegment(f, column + fprint_indent_texts, "", 0);
106 fprint_current_column++;