Commit 4317aaec authored by dcw's avatar dcw
Browse files

added outstring to handle newlines in print control strings

parent 8026b92a
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <dcw.h> #include <dcw.h>
#include "struct.h" #include "struct.h"
#include "decs.h" #include "decs.h"
#include <string.h>
typedef declnlist decln; /* JUST THE FIRST */ typedef declnlist decln; /* JUST THE FIRST */
...@@ -37,6 +38,7 @@ static void writeproc_body( decln ); ...@@ -37,6 +38,7 @@ static void writeproc_body( decln );
static void write_using_case( char * , char * , shapelist ); static void write_using_case( char * , char * , shapelist );
static void write_param( char * , param ); static void write_param( char * , param );
static void write_all_params( char * , shape ); static void write_all_params( char * , shape );
static void outstring( char * );
static void write_bool( void ); static void write_bool( void );
static char * lookup_type( char * ); static char * lookup_type( char * );
static char * lookup_write_proc( char * ); static char * lookup_write_proc( char * );
...@@ -61,6 +63,7 @@ static void writeproc_body(); ...@@ -61,6 +63,7 @@ static void writeproc_body();
static void write_using_case(); static void write_using_case();
static void write_param(); static void write_param();
static void write_all_params(); static void write_all_params();
static void outstring();
static void write_bool(); static void write_bool();
static char * lookup_type(); static char * lookup_type();
static char * lookup_write_proc(); static char * lookup_write_proc();
...@@ -249,7 +252,8 @@ static void impln_declns( globals, modulename, decs ) char *globals, *modulename ...@@ -249,7 +252,8 @@ static void impln_declns( globals, modulename, decs ) char *globals, *modulename
nl(); nl();
line( "FROM FIO IMPORT" ); line( "FROM FIO IMPORT" );
indent(); indent();
line( "File, WriteString, WriteChar, WriteInteger, WriteReal;" ); line( "File, WriteString, WriteChar, WriteInteger," );
line( "WriteReal, WriteLine, WriteLn;" );
nl(); nl();
outdent(); outdent();
line( "FROM Storage IMPORT ALLOCATE;" ); line( "FROM Storage IMPORT ALLOCATE;" );
...@@ -642,8 +646,7 @@ static void write_all_params( dname, s ) char *dname; shape s; ...@@ -642,8 +646,7 @@ static void write_all_params( dname, s ) char *dname; shape s;
{ {
if( pl->item->tag == printitem_is_str ) if( pl->item->tag == printitem_is_str )
{ {
line( "WriteString( f, \"%s\" );", outstring( pl->item->str );
pl->item->str );
} else } else
{ {
int n = pl->item->num; int n = pl->item->num;
...@@ -660,6 +663,39 @@ ASSERT( p != NULL, ...@@ -660,6 +663,39 @@ ASSERT( p != NULL,
} }
static void outstring( str ) char *str;
{
char *p;
BOOL over = FALSE;
while( ! over )
{
p = strstr( str, "\\n" );
if( p == NULL )
{
line( "WriteString( f, \"%s\" );", str );
over = TRUE;
} else
{
if( p == str )
{
line( "WriteLine( f );" );
} else
{
line( "WriteLn( f, \"%.*s\" );", (p-str), str );
}
if( *(p+2) != '\0' )
{
str = p + 2;
} else
{
over = TRUE;
}
}
}
}
static void write_bool() static void write_bool()
{ {
line( "PROCEDURE WriteBool( f : File; bool : BOOLEAN );" ); line( "PROCEDURE WriteBool( f : File; bool : BOOLEAN );" );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment