1 /* This file contains functions to handle %d, %$, %dist constructs in the
6 pr_text_with_conversions( str)
9 char *ptr, *next_conversion(), *pr_conversion();
11 while ( ptr = next_conversion( str)) {
12 /* ptr points to '%'-sign */
15 out( "fprint( outfile, \"");
20 str = pr_conversion( ptr);
23 out( "fprint( outfile, \"");
32 for ( ; *s != '\0'; s++)
34 case '"' : out( "\\\"");
37 case '\\': out( "\\\\");
40 case '\n': out( "\\n");
43 default : out( "%c", *s);
48 char *next_conversion( str)
51 /* Look for a %-sign, but not in a comment or string! */
56 while ( *str && *str != '%') {
58 case '\'' : str = match( '\'', str) + 1;
60 case '"' : str = match( '"', str) + 1;
64 return( *str == '%' ? str : (char *)0);
71 /* Look for charcter 'c', but watch out for things like \n */
74 while ( *str && ( *str != c || *(str-1) == '\\'))
76 return( *str ? str : str-1);
80 char *match_bracket( str)
83 /* find ')', but look at nesting '('-')' pairs, return position of ')'.
84 * Skip strings and comments.
91 while ( *str && depth != 0) {
93 case '\'' : str = match( '\'', str+1) + 1;
95 case '"' : str = match( '"', str+1) + 1;
110 while ( *str && *str != c)
115 char *pr_conversion( str)
118 /* str points to '%'-sign, returns pointer to first character AFTER the
119 * conversion. %$ will result in a call of eval(), %d will call dist().
122 char *start, *ptr, *match_bracket(), *find();
124 start = find( '(', str+1);
127 ptr = match_bracket( start);
130 if ( *(str+1) == '$')
131 out( "eval( %s);", start);
132 else if ( strncmp( str+1, "dist", 4) == 0)
133 out( "dist( %s);", start);
135 out( "fprint( outfile, \"%%%s\", %s);", str+1, start);