diff --git a/src/stdio/TermFile.sac b/src/stdio/TermFile.sac index c040b923..9984f7f2 100644 --- a/src/stdio/TermFile.sac +++ b/src/stdio/TermFile.sac @@ -51,12 +51,13 @@ external TermFile createStdErr(); * ******************************************************************************/ -external void fputc(char C, TermFile &STREAM); +external int fputc(char C, TermFile &STREAM); #pragma effect TheTerminal #pragma linkname "SACfputc_TF" #pragma linkobj "src/TermFile/fputc.o" + #pragma linksign [0,1,2] -inline void putc(char C) { fputc(C, stdout); } +inline int putc(char C) { return fputc(C, stdout); } /* * Put the character C to the output stream STREAM which must be * either stdout or stderr. @@ -73,15 +74,16 @@ inline char getc() { return fgetc(stdin); } * Get the next character from the input stream STREAM which must be stdin. */ -external void fputs(string S, TermFile &STREAM); +external int fputs(string S, TermFile &STREAM); #pragma effect TheTerminal #pragma linkname "SACfputs_TF" #pragma linkobj "src/TermFile/fputs.o" + #pragma linksign [0,1,2] /* * Write string S to stream. */ -external void puts(string S); +external int puts(string S); #pragma effect TheTerminal #pragma linkname "SACputs_TF" #pragma linkobj "src/TermFile/puts.o" @@ -89,7 +91,7 @@ external void puts(string S); * Write string S and a newline to stdout. */ -external syserr, string fgets (int size, TermFile &STREAM); +external syserr, string fgets(int size, TermFile &STREAM); #pragma effect TheTerminal #pragma linkname "SACfgets_TF" #pragma linkobj "src/TermFile/fgets.o" @@ -98,38 +100,42 @@ external syserr, string fgets (int size, TermFile &STREAM); * Read a string of max. length size from the provided TermFile. */ -syserr, string gets (int size) +syserr, string gets(int size) { - err, str = fgets (size, stdin); + err, str = fgets(size, stdin); return (err, str); } -syserr, string fgetl (TermFile &stream) +syserr, string fgetl(TermFile &stream) { - err, str = fgets (80, stream); + err, str = fgets(80, stream); res = str; - while (!SysErr::fail(err) - && strsel (str, strlen(str)-1) != '\n') { - err, str = fgets (80, stream); - res = strcat (res, str); + + while (!SysErr::fail(err) && strsel(str, strlen(str)-1) != '\n') { + err, str = fgets(80, stream); + res = strcat(res, str); + } + + if (!SysErr::fail(err)) { + res = strtake(res, strlen(res)-1); } - if (!SysErr::fail(err)) - res = strtake (res, strlen(res)-1); + return (err, res); } -syserr, string getl () +syserr, string getl() { - err, str = fgetl (stdin); + err, str = fgetl(stdin); return (err, str); } -external void ungetc(char C, TermFile &STREAM); +external int ungetc(char C, TermFile &STREAM); #pragma effect TheTerminal #pragma linkname "SACungetc_TF" #pragma linkobj "src/TermFile/ungetc.o" + #pragma linksign [0,1,2] -inline void ungetc(char C) { ungetc(C, stdin); } +inline int ungetc(char C) { return ungetc(C, stdin); } /* * Put the character C back to the input stream STREAM which must be * stdin for further read operations. Only one character may be put back @@ -212,12 +218,13 @@ inline string scanl(int MAX) { return fscanl(stdin, MAX); } * ******************************************************************************/ -external void fflush(TermFile &STREAM); +external int fflush(TermFile &STREAM); #pragma effect TheTerminal #pragma linkname "SACfflush_TF" #pragma linkobj "src/TermFile/fflush.o" + #pragma linksign [0,1] -inline void flush() { fflush(stdout); } +inline int flush() { return fflush(stdout); } /* * Write the buffer of a buffered output stream STREAM which must be * either stdout or stderr to the respective file or terminal device. diff --git a/src/stdio/src/TermFile/TermFile.h b/src/stdio/src/TermFile/TermFile.h index 7564485e..bad8823c 100644 --- a/src/stdio/src/TermFile/TermFile.h +++ b/src/stdio/src/TermFile/TermFile.h @@ -1,8 +1,10 @@ +#ifndef _SAC_TERMFILE_H_ +#define _SAC_TERMFILE_H_ + /* - * implementation of standard class TermFile + * Implementation of standard class TermFile */ - #include #include #include @@ -11,4 +13,4 @@ #include "sac.h" #include "sacinterface.h" - +#endif /* _SAC_TERMFILE_H_ */ diff --git a/src/stdio/src/TermFile/feof.c b/src/stdio/src/TermFile/feof.c index bc783e10..d373b8d8 100644 --- a/src/stdio/src/TermFile/feof.c +++ b/src/stdio/src/TermFile/feof.c @@ -1,22 +1,10 @@ /* - * implementation of class File + * Implementation of class File */ - - #include "TermFile.h" - -/*****************************************************************/ - - bool SACfeof_TF(FILE *f) { - return feof( f); + return feof( f); } - - -/*****************************************************************/ - - - diff --git a/src/stdio/src/TermFile/fflush.c b/src/stdio/src/TermFile/fflush.c index 79c8e67b..3b68d1d3 100644 --- a/src/stdio/src/TermFile/fflush.c +++ b/src/stdio/src/TermFile/fflush.c @@ -1,22 +1,10 @@ /* - * implementation of class File + * Implementation of class File */ - - #include "TermFile.h" - -/*****************************************************************/ - - -void SACfflush_TF(FILE *f) +sac_int SACfflush_TF(FILE *f) { - fflush( f); + return (sac_int)fflush(f); } - - -/*****************************************************************/ - - - diff --git a/src/stdio/src/TermFile/fgetc.c b/src/stdio/src/TermFile/fgetc.c index ee43cbb0..0d09a03f 100644 --- a/src/stdio/src/TermFile/fgetc.c +++ b/src/stdio/src/TermFile/fgetc.c @@ -1,22 +1,10 @@ /* - * implementation of class File + * Implementation of class File */ - - #include "TermFile.h" - -/*****************************************************************/ - - char SACfgetc_TF(FILE *stream) { - return fgetc( stream); + return fgetc(stream); } - - -/*****************************************************************/ - - - diff --git a/src/stdio/src/TermFile/fgets.c b/src/stdio/src/TermFile/fgets.c index 76dde214..5eb16703 100644 --- a/src/stdio/src/TermFile/fgets.c +++ b/src/stdio/src/TermFile/fgets.c @@ -1,41 +1,31 @@ /* - * implementation of class File + * Implementation of class File */ - - #include "TermFile.h" #ifdef SACARG_WORKS SAC_C_EXTERN SACtypes *SACTYPE_String__string; #endif -/*****************************************************************/ - #ifdef SACARG_WORKS -int SACfgets_TF(SACarg **str, int size, FILE *stream) +sac_int SACfgets_TF(SACarg **str, sac_int size, FILE *stream) #else -int SACfgets_TF(char **str, int size, FILE *stream) +sac_int SACfgets_TF(char **str, sac_int size, FILE *stream) #endif { - int error=-1; - char *buf, *buf2; - - buf = malloc (sizeof(char) * size); - buf2 = fgets (buf, size, stream); + char *buf = malloc(sizeof(char) * (size_t)size); + char *buf2 = fgets(buf, (int)size, stream); if (buf2 == NULL) { - error = errno; free (buf); + return errno; } + #ifdef SACARG_WORKS *str = SACARGcreateFromPointer (SACTYPE_String__string, buf2, 1, 5); #else *str = buf2; #endif - - return error; -} - - -/*****************************************************************/ + return -1; +} diff --git a/src/stdio/src/TermFile/fprintf.c b/src/stdio/src/TermFile/fprintf.c index 3d0b6c7b..5a1a44b0 100644 --- a/src/stdio/src/TermFile/fprintf.c +++ b/src/stdio/src/TermFile/fprintf.c @@ -1,26 +1,14 @@ /* - * implementation of class TermFile + * Implementation of class TermFile */ - - #include "TermFile.h" - -/*****************************************************************/ - - void SACfprintf_TF(FILE *stream, char *format, ...) { - va_list args; + va_list args; - va_start(args, format); - vfprintf( stream, format, args); - va_end(args); + va_start(args, format); + vfprintf( stream, format, args); + va_end(args); } - - -/*****************************************************************/ - - - diff --git a/src/stdio/src/TermFile/fputc.c b/src/stdio/src/TermFile/fputc.c index 3dee74e7..a07a2570 100644 --- a/src/stdio/src/TermFile/fputc.c +++ b/src/stdio/src/TermFile/fputc.c @@ -1,22 +1,10 @@ /* - * implementation of class File + * Implementation of class File */ - - #include "TermFile.h" - -/*****************************************************************/ - - -int SACfputc_TF(char c, FILE *stream) +sac_int SACfputc_TF(char c, FILE *stream) { - return fputc( c, stream); + return (sac_int)fputc(c, stream); } - - -/*****************************************************************/ - - - diff --git a/src/stdio/src/TermFile/fputs.c b/src/stdio/src/TermFile/fputs.c index 79f68d8b..e8f0b35c 100644 --- a/src/stdio/src/TermFile/fputs.c +++ b/src/stdio/src/TermFile/fputs.c @@ -1,22 +1,10 @@ /* - * implementation of class File + * Implementation of class File */ - - #include "TermFile.h" - -/*****************************************************************/ - - -void SACfputs_TF(char *s, FILE *stream) +sac_int SACfputs_TF(char *s, FILE *stream) { - fputs( s, stream); + return (sac_int)fputs(s, stream); } - - -/*****************************************************************/ - - - diff --git a/src/stdio/src/TermFile/fscanf.c b/src/stdio/src/TermFile/fscanf.c index 1394992f..85dd336d 100644 --- a/src/stdio/src/TermFile/fscanf.c +++ b/src/stdio/src/TermFile/fscanf.c @@ -1,29 +1,16 @@ /* - * implementation of class File + * Implementation of class File */ - - #include "TermFile.h" - -/*****************************************************************/ - - -int SACfscanf_TF(FILE *stream, char *format, ...) +sac_int SACfscanf_TF(FILE *stream, char *format, ...) { - va_list args; - int ret; + va_list args; - va_start(args, format); - ret = vfscanf( stream, format, args); - va_end(args); + va_start(args, format); + sac_int ret = (sac_int)vfscanf(stream, format, args); + va_end(args); - return ret; + return ret; } - - -/*****************************************************************/ - - - diff --git a/src/stdio/src/TermFile/fscanl.c b/src/stdio/src/TermFile/fscanl.c index c86aab6d..59365099 100644 --- a/src/stdio/src/TermFile/fscanl.c +++ b/src/stdio/src/TermFile/fscanl.c @@ -1,32 +1,18 @@ /* - * implementation of class TermFile + * Implementation of class TermFile */ - - #include "TermFile.h" - - -/*****************************************************************/ - -char* term_fscanl(FILE *stream, int length) +char *term_fscanl(FILE *stream, sac_int length) { - char *input, *success; - - input=(char*)SAC_MALLOC(length+3); - - success=fgets(input, length+1, stream); - - if (success==NULL) - { - input[0]=0; - } - - return(input); -} - - -/*****************************************************************/ + char *input= (char *)SAC_MALLOC((size_t)length + 3); + char *success = fgets(input, (int)length + 1, stream); + if (success == NULL) + { + input[0] = '\0'; + } + return input; +} diff --git a/src/stdio/src/TermFile/fscans.c b/src/stdio/src/TermFile/fscans.c index 85b05dd0..05ff96be 100644 --- a/src/stdio/src/TermFile/fscans.c +++ b/src/stdio/src/TermFile/fscans.c @@ -1,33 +1,20 @@ /* - * implementation of class TermFile + * Implementation of class TermFile */ - - #include "TermFile.h" - - -/*****************************************************************/ - -char* term_fscans(FILE *stream, int length) +char *term_fscans(FILE *stream, sac_int length) { - int success; - char *input; - char format[32]; + char format[32]; + char *input = (char *)SAC_MALLOC((size_t)length + 1); + snprintf(format, sizeof(format), " %%%ds", (int)length); - input = (char *) SAC_MALLOC(length + 1); - snprintf(format, sizeof format, " %%%ds", length); + int success = fscanf(stream, format, input); + if (success != 1) + { + input[0] = '\0'; + } - success = fscanf(stream, format, input); - - if (success != 1) - { - input[0] = 0; - } - - return (input); + return input; } - - -/*****************************************************************/ diff --git a/src/stdio/src/TermFile/printf.c b/src/stdio/src/TermFile/printf.c index f2dc21d8..40932728 100644 --- a/src/stdio/src/TermFile/printf.c +++ b/src/stdio/src/TermFile/printf.c @@ -1,26 +1,14 @@ /* - * implementation of class TermFile + * Implementation of class TermFile */ - - #include "TermFile.h" - -/*****************************************************************/ - - void SACprintf_TF(char *format, ...) { - va_list args; + va_list args; - va_start(args, format); - vprintf(format, args); - va_end(args); + va_start(args, format); + vprintf(format, args); + va_end(args); } - - -/*****************************************************************/ - - - diff --git a/src/stdio/src/TermFile/puts.c b/src/stdio/src/TermFile/puts.c index b833aef2..12f65d2e 100644 --- a/src/stdio/src/TermFile/puts.c +++ b/src/stdio/src/TermFile/puts.c @@ -1,22 +1,10 @@ /* - * implementation of class File + * Implementation of class File */ - - #include "TermFile.h" - -/*****************************************************************/ - - -void SACputs_TF(char *s) +sac_int SACputs_TF(char *s) { - puts( s); + return (sac_int)puts(s); } - - -/*****************************************************************/ - - - diff --git a/src/stdio/src/TermFile/scanf.c b/src/stdio/src/TermFile/scanf.c index 406d0011..58b566e3 100644 --- a/src/stdio/src/TermFile/scanf.c +++ b/src/stdio/src/TermFile/scanf.c @@ -1,29 +1,16 @@ /* - * implementation of class File + * Implementation of class File */ - - #include "TermFile.h" - -/*****************************************************************/ - - -int SACscanf_TF( char *format, ...) +sac_int SACscanf_TF(char *format, ...) { - va_list args; - int ret; + va_list args; - va_start(args, format); - ret = vscanf( format, args); - va_end(args); + va_start(args, format); + sac_int ret = (sac_int)vscanf(format, args); + va_end(args); - return ret; + return ret; } - - -/*****************************************************************/ - - - diff --git a/src/stdio/src/TermFile/stdstreams.c b/src/stdio/src/TermFile/stdstreams.c index 0c17544a..9a9551cd 100644 --- a/src/stdio/src/TermFile/stdstreams.c +++ b/src/stdio/src/TermFile/stdstreams.c @@ -1,33 +1,20 @@ /* - * implementation of standard class TermFile + * Implementation of standard class TermFile */ - - #include "TermFile.h" - - -/*****************************************************************/ - -void *SAC_create_stdin( void) +void *SAC_create_stdin(void) { - return(stdin); + return stdin; } - -void *SAC_create_stdout( void) +void *SAC_create_stdout(void) { - return(stdout); + return stdout; } - -void *SAC_create_stderr( void) +void *SAC_create_stderr(void) { - return(stderr); + return stderr; } - - -/*****************************************************************/ - - diff --git a/src/stdio/src/TermFile/ungetc.c b/src/stdio/src/TermFile/ungetc.c index b61c1f9d..53db48d7 100644 --- a/src/stdio/src/TermFile/ungetc.c +++ b/src/stdio/src/TermFile/ungetc.c @@ -1,22 +1,10 @@ /* - * implementation of class File + * Implementation of class File */ - - #include "TermFile.h" - -/*****************************************************************/ - - -void SACungetc_TF(char c, FILE *stream) +sac_int SACungetc_TF(char c, FILE *stream) { - ungetc( c, stream); + return (sac_int)ungetc(c, stream); } - - -/*****************************************************************/ - - -