/* * io.h - stream I/O for D compiler * CSE 413 au07 * * This module centralizes file I/O details for the rest of the compiler. * Function io_setup should be called at the beginning of execution to * open streams and perform any other setup needed. After that, use getline * to read from the input stream one line at a time, and putline to write to * the output stream. Lines from the input stream are automatically copied * to the output stream by default. See methods set_echo and set_echo_prefix * to control how this is done. */ #ifndef IO_H #define IO_H /* * Initialize I/O routines. Parameters argc and argv should be those passed * to method main. * If there are no parameters, input is read from stdin and output written * to stdout. * If there is one parameter, it is taken as the name of the input file, and * stdin is redirected to that file. In this case, stdout is redirected to * a new file whose name is the input file name without it's final extension * (following a trailing "."), and with the extension ".s". * If there are two parameters, they are taken as the name of the input and * output files respectively, and stdin and stdout are redirected accordingly. * If either the input or output file cannot be opened, execution of the * program is terminated with a call to exit(). */ void io_init(int argc, char* argv[]); /* * Read the next line of input into s. Return a pointer to s if the read * succeeds, or NULL if there is no more input. (e.g., same as gets). * Copy the input line to output if a line is read and echoing is enabled. * pre: s has enough space for the entire next line. */ char* getline(char* s); /* * Write s to output and advance to the next line. */ void putline(char* s); /* * Write s to output without advancing to a new line. */ void putstr(char* s); /* * Turn echoing of input on or off as specified (default is on). * Return the previous echo setting. */ int set_echo(int on_off); /* * Set the echo prefix to the given string. Default is "; ". * pre: prefix is not too long (see constant in io.c) */ void set_echo_prefix(char* new_prefix); #endif /* ifndef IO_H */