home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
CTASK.ZIP
/
CONOUT.C
next >
Wrap
C/C++ Source or Header
|
1989-12-20
|
3KB
|
136 lines
/*
--- Version 2.0 89-12-13 17:41 ---
Sample module for channeling console output through
a single task to avoid problems with non-reentrant output
routines.
*/
#include "tsk.h"
#include "tsksup.h"
#include <conio.h>
#include <string.h>
#include <stdarg.h>
#define BUFSIZE 1024 /* Size of the console out buffer */
#define STRLEN 256 /* Max. length of single output string */
#define STACKSIZE 2048 /* Size of stack for output task */
local buffer conout_buf;
local char conout_stack [STACKSIZE];
local char conout_bufbuf [BUFSIZE];
local char conout_str [STRLEN+1];
local tcb conout_task;
/* -------------------------------------------------------------- */
/*
conout: The console output task. Reads strings from the buffer
and displays them on the console.
*/
local void far conout (void)
{
int siz, i;
register int ch;
while (1)
{
siz = read_buffer (&conout_buf, conout_str, STRLEN, 0L);
for (i = 0; i < siz; i++)
{
switch (ch = conout_str [i])
{
case '\n': putch ('\r');
putch ('\n');
break;
#if (TURBO)
case 0x07: sound (2000);
t_delay (3L);
nosound ();
break;
#endif
default: putch (ch);
}
}
}
}
/*
init_conout: Creates buffer and task. Must be called
before using any other routine from this module.
*/
void init_conout (void)
{
create_buffer (&conout_buf, conout_bufbuf, BUFSIZE
#if (TSK_NAMEPAR)
,"CONOUTBF"
#endif
);
create_task (&conout_task, conout, conout_stack, STACKSIZE, PRI_STD + 100, NULL
#if (TSK_NAMEPAR)
,"CONOUT"
#endif
);
start_task (&conout_task);
}
/*
end_conout: Deletes task and buffer. Should be called before
terminating CTask.
*/
void end_conout (void)
{
kill_task (&conout_task);
delete_buffer (&conout_buf);
}
/* -------------------------------------------------------------- */
/*
tprintf: Buffered replacement for printf/cprintf.
*/
int tprintf (format)
char *format;
{
va_list argptr;
char buf [256];
int res;
va_start (argptr, format);
if ((res = vsprintf (buf, format, argptr)) > 0)
if (write_buffer (&conout_buf, buf, res, 0L) < 0)
res = 0;
va_end (argptr);
return res;
}
/*
tputs: Buffered replacement for puts.
*/
int tputs (char *buf)
{
return (write_buffer (&conout_buf, buf, strlen (buf), 0L) < 0) ? -1 : 0;
}
/*
tputch: Buffered replacement for putch.
*/
int tputch (int ch)
{
return (write_buffer (&conout_buf, &ch, 1, 0L) < 0) ? EOF : ch;
}