Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions src/stdio/TermFile.sac
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -73,23 +74,24 @@ 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"
/*
* 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"
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions src/stdio/src/TermFile/TermFile.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#ifndef _SAC_TERMFILE_H_
#define _SAC_TERMFILE_H_

/*
* implementation of standard class TermFile
* Implementation of standard class TermFile
*/


#include <stdio.h>
#include <stdarg.h>
#include <string.h>
Expand All @@ -11,4 +13,4 @@
#include "sac.h"
#include "sacinterface.h"


#endif /* _SAC_TERMFILE_H_ */
16 changes: 2 additions & 14 deletions src/stdio/src/TermFile/feof.c
Original file line number Diff line number Diff line change
@@ -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);
}


/*****************************************************************/



18 changes: 3 additions & 15 deletions src/stdio/src/TermFile/fflush.c
Original file line number Diff line number Diff line change
@@ -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);
}


/*****************************************************************/



16 changes: 2 additions & 14 deletions src/stdio/src/TermFile/fgetc.c
Original file line number Diff line number Diff line change
@@ -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);
}


/*****************************************************************/



28 changes: 9 additions & 19 deletions src/stdio/src/TermFile/fgets.c
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 5 additions & 17 deletions src/stdio/src/TermFile/fprintf.c
Original file line number Diff line number Diff line change
@@ -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);
}


/*****************************************************************/



18 changes: 3 additions & 15 deletions src/stdio/src/TermFile/fputc.c
Original file line number Diff line number Diff line change
@@ -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);
}


/*****************************************************************/



18 changes: 3 additions & 15 deletions src/stdio/src/TermFile/fputs.c
Original file line number Diff line number Diff line change
@@ -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);
}


/*****************************************************************/



27 changes: 7 additions & 20 deletions src/stdio/src/TermFile/fscanf.c
Original file line number Diff line number Diff line change
@@ -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;
}


/*****************************************************************/



Loading