1988-01-07 15:52:52 +00:00
|
|
|
/* This file contains functions to handle %d, %$, %dist constructs in the
|
|
|
|
* as_table.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1987-11-20 11:12:07 +00:00
|
|
|
pr_text_with_conversions( str)
|
|
|
|
char *str;
|
|
|
|
{
|
1988-05-29 13:52:54 +00:00
|
|
|
char *ptr, *next_conversion(), *pr_conversion();
|
1987-11-20 11:12:07 +00:00
|
|
|
|
|
|
|
while ( ptr = next_conversion( str)) {
|
|
|
|
/* ptr points to '%'-sign */
|
|
|
|
*ptr = '\0';
|
1988-05-27 15:25:30 +00:00
|
|
|
|
|
|
|
out( "fprint( outfile, \"");
|
1988-05-29 13:52:54 +00:00
|
|
|
out_string( str);
|
1988-05-27 15:25:30 +00:00
|
|
|
out( "\");");
|
|
|
|
|
1987-11-20 11:12:07 +00:00
|
|
|
*ptr = '%';
|
|
|
|
str = pr_conversion( ptr);
|
|
|
|
}
|
1988-05-27 15:25:30 +00:00
|
|
|
|
|
|
|
out( "fprint( outfile, \"");
|
1988-05-29 13:52:54 +00:00
|
|
|
out_string( str);
|
1988-05-27 15:25:30 +00:00
|
|
|
out( "\");");
|
1987-11-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
1988-05-29 13:52:54 +00:00
|
|
|
|
|
|
|
out_string( s)
|
|
|
|
char *s;
|
|
|
|
{
|
|
|
|
for ( ; *s != '\0'; s++)
|
|
|
|
switch ( *s) {
|
|
|
|
case '"' : out( "\\\"");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\\': out( "\\\\");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\n': out( "\\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default : out( "%c", *s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1987-11-20 11:12:07 +00:00
|
|
|
char *next_conversion( str)
|
|
|
|
char *str;
|
1988-01-07 15:52:52 +00:00
|
|
|
|
|
|
|
/* Look for a %-sign, but not in a comment or string! */
|
|
|
|
|
1987-11-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
char *match();
|
|
|
|
|
|
|
|
while ( *str && *str != '%') {
|
|
|
|
switch ( *str++) {
|
|
|
|
case '\'' : str = match( '\'', str) + 1;
|
|
|
|
break;
|
|
|
|
case '"' : str = match( '"', str) + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( *str == '%' ? str : (char *)0);
|
|
|
|
}
|
|
|
|
|
1988-01-07 15:52:52 +00:00
|
|
|
|
1987-11-20 11:12:07 +00:00
|
|
|
char *match( c, str)
|
|
|
|
char c, *str;
|
1988-01-07 15:52:52 +00:00
|
|
|
|
|
|
|
/* Look for charcter 'c', but watch out for things like \n */
|
|
|
|
|
1987-11-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
while ( *str && ( *str != c || *(str-1) == '\\'))
|
|
|
|
str++;
|
|
|
|
return( *str ? str : str-1);
|
|
|
|
}
|
|
|
|
|
1988-01-07 15:52:52 +00:00
|
|
|
|
1987-11-20 11:12:07 +00:00
|
|
|
char *match_bracket( str)
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
/* find ')', but look at nesting '('-')' pairs, return position of ')'.
|
1988-01-07 15:52:52 +00:00
|
|
|
* Skip strings and comments.
|
1987-11-20 11:12:07 +00:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
int depth;
|
|
|
|
char *match();
|
|
|
|
|
|
|
|
depth = 1;
|
|
|
|
while ( *str && depth != 0) {
|
|
|
|
switch ( *str++) {
|
|
|
|
case '\'' : str = match( '\'', str+1) + 1;
|
|
|
|
break;
|
|
|
|
case '"' : str = match( '"', str+1) + 1;
|
|
|
|
break;
|
|
|
|
case '(' : depth++;
|
|
|
|
break;
|
|
|
|
case ')' : depth--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( str-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *find( c, str)
|
|
|
|
char c, *str;
|
|
|
|
{
|
|
|
|
while ( *str && *str != c)
|
|
|
|
str++;
|
|
|
|
return( str);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *pr_conversion( str)
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
/* str points to '%'-sign, returns pointer to first character AFTER the
|
1988-01-07 15:52:52 +00:00
|
|
|
* conversion. %$ will result in a call of eval(), %d will call dist().
|
1987-11-20 11:12:07 +00:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
char *start, *ptr, *match_bracket(), *find();
|
|
|
|
|
|
|
|
start = find( '(', str+1);
|
|
|
|
*start++ = '\0';
|
|
|
|
|
|
|
|
ptr = match_bracket( start);
|
|
|
|
*ptr = '\0';
|
|
|
|
|
|
|
|
if ( *(str+1) == '$')
|
|
|
|
out( "eval( %s);", start);
|
|
|
|
else if ( strncmp( str+1, "dist", 4) == 0)
|
|
|
|
out( "dist( %s);", start);
|
|
|
|
else
|
|
|
|
out( "fprint( outfile, \"%%%s\", %s);", str+1, start);
|
|
|
|
|
|
|
|
return( ptr+1);
|
|
|
|
}
|