Category : C Source Code
Archive   : SDB.ZIP
Filename : TEST2.C

 
Output of file : TEST2.C contained in archive : SDB.ZIP
int conlock;
int *comanch;
struct INPUT
{ struct INPUT *next;
char text[2];
};
struct INPUT *diskqueue;
char *getmem();

/* This program tests the multi-tasking functions.
* Three functions are attached:
* 1. keytask, which just echoes characters from the keyboard
* to the console until a tilde (~) is encountered.
* 2. diskin, which copies the file "taskfunc.asm" to an internal
* queue, one full line at a time.
* 3. diskout, which dumps the internal queue, at most 10 chars
* at a time, to the file "test2.out"
*
* The main task just waits until all subtasks have completed.
*
*/
#include "stdio.h"

main()
{
int j;
int i;


inittask("main");
if (attach(getmem(100),getmem(1024),1024)) keytask();
if (attach(getmem(100),getmem(1024),1024)) diskin();
if (attach(getmem(100),getmem(1024),1024)) diskout();
while (taskcnt() > 1) { yield(); }
}

keytask()
{
char c;


printf("\nKeyboard task activated");
for (;;)

{
if (iskbhit())
{
c = getch();
if (c == '\r') putch('\n');
putch(c);
if (c == '~')
{
printf("\nKeyboard task terminating");
stop();
}
}
yield();
}
}

diskin()
{
FILE *fp;
char buffer[256], *sp;
struct INPUT *nq, *wp;

printf("\nRead task now active");

fp = fopen("taskfunc.asm","r");
if (!fp) {printf("\nUnable to open taskfunc.asm - terminating"); exit(3);}
while ((sp = fgets(buffer,256,fp)))
{
nq = (struct INPUT *) getmem( 8+sizeof(char *) + strlen(sp));
nq->next = NULL;
strcpy(nq->text, sp);
wp = (struct INPUT *) &diskqueue;
while (wp->next) { wp = wp->next; }
wp->next = nq;
yield();
}
fclose(fp);
printf("\n\nRead subtask terminated.");
stop();
}
diskout()
{
FILE *fp;
char *sp;
int j;
struct INPUT *nq, *wp;
char c;

fp = fopen("test2.out","w");
printf("\nWritetask now active");
while ((nq=diskqueue) || (taskcnt() > 3))
{
diskqueue = nq->next;
sp = nq->text;
j=0;
while (*sp)
{ fputc(*sp++, fp);
if (j++>10) {yield(); j=0;}
}
rlsmem(nq,8+sizeof(char *) + strlen(nq->text));

yield();
}
printf("\n\nWrite task terminating");
fclose(fp);
stop();
}


  3 Responses to “Category : C Source Code
Archive   : SDB.ZIP
Filename : TEST2.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/