home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / newlibs / rawil110.lha / RawINTest.c < prev   
C/C++ Source or Header  |  1992-08-04  |  6KB  |  170 lines

  1. /*
  2. **  $Filename: RawINTest.c $
  3. **  $Release: 1.10 $
  4. **  $Date: August 4, 1992 $
  5. **  $Author: Sam Yee (samy@sfu.ca/1:153/765) $
  6. **
  7. **  Test program for RawIN.lib
  8. */
  9.  
  10. #include <pragmas/dos_pragmas.h>
  11. #include <pragmas/exec_pragmas.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/exec_protos.h>
  14. #include <dos/dos.h>
  15. #include <dos/dosextens.h>
  16. #include <RawIN.h>  /* use "RawIN.h" if it's in currect directory */
  17. #include <sam.h>
  18. int CXBRK(void) {return(0);}    /* disable Lattice C ^C checking */
  19.  
  20. /* required for pragmas */
  21. extern struct SysBase   *SysBase;
  22. extern struct DOSBase   *DOSBase;
  23.  
  24. /*******************************************************************/
  25. main(int argc, char *argv[])
  26. {
  27.     BOOL        quit = FALSE,   /* if true exit program */
  28.                 EOL;            /* true if user presses CR */
  29.     char        prompt[50],
  30.                 tempbuf[10],
  31.                 key;
  32.     struct Line *line;
  33.     long        mask,       /* signal masks */
  34.                 returnmask,
  35.                 readcount,  /* used in RawGets() */
  36.                 i;
  37.     struct History  *history;
  38.  
  39.     printf("\nRawIN test by Sam Yee.  Jul 12, 1992\n\n");
  40.     sprintf(prompt,"%s> ",argv[0]); /* make prompt */
  41.  
  42.     printf("AllocLine(100,10) -- 100 character buffer, 10 history lines.\n");
  43.     if (!(line = AllocLine(100L,10L)))  /* 100 characters for a line, 10 history lines */
  44.     {
  45.         printf("Can't AllocLine()!!!\n");
  46.         exit(10);
  47.     }
  48.     printf("\nLogging into the test program...\n\n\n\n");
  49.     printf("login: ");
  50.     RawGets(line,tempbuf,8,0,FALSE,FALSE,TRUE);
  51.  
  52.     printf("\nPassword:");
  53.     RawGets(line,tempbuf,8,0,FALSE,FALSE,FALSE);
  54.     printf("\n\nPassword okay.  :-)\n\nWelcome to the test program...\n\n\n\n");
  55.     printf("MakeHistory(line,\"This\",4)\n");
  56.     MakeHistory(line,"This",4);
  57.     printf("MakeHistory(line,\"is\",2)\n");
  58.     MakeHistory(line,"is",2);
  59.     printf("MakeHistory(line,\"a\",1)\n");
  60.     MakeHistory(line,"a",1);
  61.     printf("MakeHistory(line,\"test.\",5)\n");
  62.     MakeHistory(line,"test.",5);
  63.     printf("ShowHistory(line,1L,-1L,0) -- ascending order.\n");
  64.     ShowHistory(line,1L,-1L,0);
  65.     printf("ShowHistory(line,-1L,-1L,1) -- descending order.\n");
  66.     ShowHistory(line,-1L,-1L,1);
  67.     printf("GetHistory(line,2L)...\n");
  68.  
  69.     history = GetHistory(line,2L);
  70.     if (history)
  71.         printf("%s\n",history->buf);
  72.  
  73.     printf("DeleteHistory(line,1) -- delete first history line.\n");
  74.     DeleteHistory(line,1);
  75.     printf("DeleteHistory(line,-1L) --- delete last history line.\n");
  76.     DeleteHistory(line,-1L);
  77.     printf("ShowHistory(line,1L,-1L,0)...\n");
  78.     ShowHistory(line,1L,-1L,0);
  79.  
  80.     RawMode(line,TRUE);
  81.     printf("RawMode(line,TRUE) -- Go in raw mode.\n");
  82.     StartAsyncRead(line);   /* start the first read */
  83.     printf("StartAsyncRead() done.\n");
  84.  
  85.     printf("Testing HOT Keys..\n\n");
  86.     for (i = 0; i < 49; ++i)
  87.     {
  88.         printf("*** Smash any key to abort, ^S to pause, ^Q to unpause...\n");
  89.         Delay(5);
  90.         key = PauseKey(line,0x13,0x11,"[PAUSED]");
  91.         if ((key != 0x11) && key)
  92.         {
  93.             printf("PauseKey() returns %c\n",key);
  94.             break;
  95.         }
  96.         if (key = GetKey(line,FALSE,FALSE))
  97.         {
  98.             printf("GetKey() returns %c\n",key);
  99.             break;
  100.         }
  101.     }
  102.     printf("\n\nFor history list type history.  Press ^C or type quit to exit.\n\n");
  103.     printf(prompt);
  104.  
  105.     ResetLine(line);    /* always reset before getting a command line */
  106.     StartAsyncRead(line);
  107.     mask = 1L<<0xc | 1L<<line->ReadReplyPort->mp_SigBit;    /* mask the signals */
  108.     while (!quit)
  109.     {
  110.         if (KeyPressed(line))   /* did user type anything? what about EOF? */
  111.         {
  112.             if (line->flag & LNF_EOF)   /* end-of-file */
  113.                 quit = TRUE;
  114.             else if (EOL = BuildLine(line,-1L,TRUE))    /* did user press CR? */
  115.             {
  116.                 if (!stricmp(line->buf,"QUIT"))
  117.                     break;
  118.                 printf("\nYou typed \"%s\".\n",line->buf);
  119.  
  120.                 if (!strcmp(line->buf,"history"))
  121.                 {
  122.                     printf("\nShowHistory()...\n\n");
  123.                     ShowHistory(line,1L,-1L,0);
  124.                 }
  125.                 ResetLine(line);    /* initialize line */
  126.                 printf("\nResetLine() done.\n\n");
  127.                 printf(prompt);
  128.             }
  129.             if (!quit)
  130.                 StartAsyncRead(line);
  131.         }
  132. /*
  133.         else if (GetMsg(another_port))  /* check your other port(s) here...*/
  134.         {...}
  135. */
  136.         else
  137.         {
  138.             returnmask = Wait(mask);    /* sleep until something happens */
  139.             if ((1L<<0xc) & returnmask) /* break? */
  140.             {
  141.                 printf("\n***Break\n");
  142.                 quit = TRUE;
  143.             }
  144.         }
  145.     }
  146.     printf("\nRawGets() with default option.\n\n");
  147.     printf("Do you like RawIN.lib? => ");
  148.     strcpy(tempbuf,"YES!");
  149.     readcount = RawGets(line,tempbuf,5,strlen(tempbuf),FALSE,FALSE,TRUE);
  150.     if (readcount > 0)  /* if user had indeed typed something */
  151.         printf("\nYou response was \"%s\".\n",tempbuf);
  152.  
  153.     printf("\n\nRawGets() with hotkeys, CAPS, and no echo...\n\n");
  154.     printf("Would you consider using RawIN.lib in your programs?\n[Y/n] => ");
  155.     readcount = RawGets(line,tempbuf,2,0,TRUE,TRUE,FALSE);
  156.     if (!readcount)
  157.         printf("Why, of course! ;)\n");
  158.     else if (readcount > 0)
  159.     {
  160.         if (tempbuf[0] == 'Y')
  161.             printf("Most definitely.\n");
  162.         else
  163.             printf("No thanks, it's utterly useless for me.\n");
  164.     }
  165.     FreeLine(line);
  166.     printf("\nGoodbye.\n\n");
  167. }
  168.  
  169. /*******************************************************************/
  170.