home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
newlibs
/
rawil110.lha
/
RawINTest.c
< prev
Wrap
C/C++ Source or Header
|
1992-08-04
|
6KB
|
170 lines
/*
** $Filename: RawINTest.c $
** $Release: 1.10 $
** $Date: August 4, 1992 $
** $Author: Sam Yee (samy@sfu.ca/1:153/765) $
**
** Test program for RawIN.lib
*/
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <RawIN.h> /* use "RawIN.h" if it's in currect directory */
#include <sam.h>
int CXBRK(void) {return(0);} /* disable Lattice C ^C checking */
/* required for pragmas */
extern struct SysBase *SysBase;
extern struct DOSBase *DOSBase;
/*******************************************************************/
main(int argc, char *argv[])
{
BOOL quit = FALSE, /* if true exit program */
EOL; /* true if user presses CR */
char prompt[50],
tempbuf[10],
key;
struct Line *line;
long mask, /* signal masks */
returnmask,
readcount, /* used in RawGets() */
i;
struct History *history;
printf("\nRawIN test by Sam Yee. Jul 12, 1992\n\n");
sprintf(prompt,"%s> ",argv[0]); /* make prompt */
printf("AllocLine(100,10) -- 100 character buffer, 10 history lines.\n");
if (!(line = AllocLine(100L,10L))) /* 100 characters for a line, 10 history lines */
{
printf("Can't AllocLine()!!!\n");
exit(10);
}
printf("\nLogging into the test program...\n\n\n\n");
printf("login: ");
RawGets(line,tempbuf,8,0,FALSE,FALSE,TRUE);
printf("\nPassword:");
RawGets(line,tempbuf,8,0,FALSE,FALSE,FALSE);
printf("\n\nPassword okay. :-)\n\nWelcome to the test program...\n\n\n\n");
printf("MakeHistory(line,\"This\",4)\n");
MakeHistory(line,"This",4);
printf("MakeHistory(line,\"is\",2)\n");
MakeHistory(line,"is",2);
printf("MakeHistory(line,\"a\",1)\n");
MakeHistory(line,"a",1);
printf("MakeHistory(line,\"test.\",5)\n");
MakeHistory(line,"test.",5);
printf("ShowHistory(line,1L,-1L,0) -- ascending order.\n");
ShowHistory(line,1L,-1L,0);
printf("ShowHistory(line,-1L,-1L,1) -- descending order.\n");
ShowHistory(line,-1L,-1L,1);
printf("GetHistory(line,2L)...\n");
history = GetHistory(line,2L);
if (history)
printf("%s\n",history->buf);
printf("DeleteHistory(line,1) -- delete first history line.\n");
DeleteHistory(line,1);
printf("DeleteHistory(line,-1L) --- delete last history line.\n");
DeleteHistory(line,-1L);
printf("ShowHistory(line,1L,-1L,0)...\n");
ShowHistory(line,1L,-1L,0);
RawMode(line,TRUE);
printf("RawMode(line,TRUE) -- Go in raw mode.\n");
StartAsyncRead(line); /* start the first read */
printf("StartAsyncRead() done.\n");
printf("Testing HOT Keys..\n\n");
for (i = 0; i < 49; ++i)
{
printf("*** Smash any key to abort, ^S to pause, ^Q to unpause...\n");
Delay(5);
key = PauseKey(line,0x13,0x11,"[PAUSED]");
if ((key != 0x11) && key)
{
printf("PauseKey() returns %c\n",key);
break;
}
if (key = GetKey(line,FALSE,FALSE))
{
printf("GetKey() returns %c\n",key);
break;
}
}
printf("\n\nFor history list type history. Press ^C or type quit to exit.\n\n");
printf(prompt);
ResetLine(line); /* always reset before getting a command line */
StartAsyncRead(line);
mask = 1L<<0xc | 1L<<line->ReadReplyPort->mp_SigBit; /* mask the signals */
while (!quit)
{
if (KeyPressed(line)) /* did user type anything? what about EOF? */
{
if (line->flag & LNF_EOF) /* end-of-file */
quit = TRUE;
else if (EOL = BuildLine(line,-1L,TRUE)) /* did user press CR? */
{
if (!stricmp(line->buf,"QUIT"))
break;
printf("\nYou typed \"%s\".\n",line->buf);
if (!strcmp(line->buf,"history"))
{
printf("\nShowHistory()...\n\n");
ShowHistory(line,1L,-1L,0);
}
ResetLine(line); /* initialize line */
printf("\nResetLine() done.\n\n");
printf(prompt);
}
if (!quit)
StartAsyncRead(line);
}
/*
else if (GetMsg(another_port)) /* check your other port(s) here...*/
{...}
*/
else
{
returnmask = Wait(mask); /* sleep until something happens */
if ((1L<<0xc) & returnmask) /* break? */
{
printf("\n***Break\n");
quit = TRUE;
}
}
}
printf("\nRawGets() with default option.\n\n");
printf("Do you like RawIN.lib? => ");
strcpy(tempbuf,"YES!");
readcount = RawGets(line,tempbuf,5,strlen(tempbuf),FALSE,FALSE,TRUE);
if (readcount > 0) /* if user had indeed typed something */
printf("\nYou response was \"%s\".\n",tempbuf);
printf("\n\nRawGets() with hotkeys, CAPS, and no echo...\n\n");
printf("Would you consider using RawIN.lib in your programs?\n[Y/n] => ");
readcount = RawGets(line,tempbuf,2,0,TRUE,TRUE,FALSE);
if (!readcount)
printf("Why, of course! ;)\n");
else if (readcount > 0)
{
if (tempbuf[0] == 'Y')
printf("Most definitely.\n");
else
printf("No thanks, it's utterly useless for me.\n");
}
FreeLine(line);
printf("\nGoodbye.\n\n");
}
/*******************************************************************/