home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / c / cwl30 / cwl3demo / cwlfun11.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-02  |  2.2 KB  |  107 lines

  1. #include "cwldemo.h"
  2.  
  3. /* Delay function that either exits when you press a key, or when time
  4.  * runs out.  Demo is terminated if ESC key is pressed  */
  5.  
  6. int delay_approx(int mil)
  7. {
  8.   unsigned start = 5;
  9.   int ch;
  10.  
  11.   /* quit if key is in keyboard buffer */
  12.   while(!ISKEYREADY())
  13.   {
  14.     delay(10);
  15.     start+=10;
  16.   /* return because time ran out */
  17.     if (start > mil)
  18.       return 0;
  19.   }
  20.   /* read the key */
  21.   ch = GET_KEY();
  22.  
  23.   /* quit demo if the Escape key was pressed */
  24.   if (ch == ESC)
  25.   {
  26.     last_function();
  27.   }
  28.   return 0;
  29. }
  30.  
  31.  
  32. FILE *read_file (VWPOINTER vw, char *filename)
  33. {
  34.   char *buf;
  35.   FILE *infile;
  36.   int i = 0;
  37.   unsigned row, col;
  38.  
  39.   buf = (char *)malloc((VIRTUAL_WIDTH(vw) + 1) * sizeof(char));
  40.   if (!buf)
  41.     return (FILE *)0;
  42.   infile = fopen(filename,"r");
  43.   if (!infile)
  44.   {
  45.     free(buf);
  46.     return (FILE *)0;
  47.   }
  48.  
  49.   fgets(buf, VIRTUAL_WIDTH(vw), infile);
  50.   while (!feof(infile) && i < 80)
  51.   {
  52.     VirtualPrintf(vw, buf);
  53.     i++;
  54.     VirtualGetCursorPosition(vw, &row, &col);
  55.     if (row >= 80)
  56.       break;
  57.     fgets(buf, VIRTUAL_WIDTH(vw), infile);
  58.   }
  59.   free(buf);
  60.   return infile;
  61. }
  62.  
  63.  
  64. CWL_VOID last_function()
  65. {
  66.   int i,j,k;
  67.   UninitCWL( );
  68.   printf("Thanks for viewing the Demo of The C Window Library!\n");
  69.   exit( 0 );
  70. }
  71.  
  72.  
  73. CWL_VOID custom_error_func(int error, char *fname, int line, char *func)
  74. {
  75.   char buf[100];
  76.   int ch;
  77.   MakeSound(500,100);
  78.   if (error == NO_HEAP_MEM)
  79.   {
  80.     ClearScreen(0x7);
  81.     VideoWriteString("Unable to allocate memory",0,0);
  82.     GET_KEY();
  83.     WindowUninitSystem( );
  84.     exit(0);
  85.   }
  86.   else
  87.   {
  88.     WindowClear(error_window);
  89.  
  90.     sprintf(buf,"Error %d.  Line %d, Function %s",error,line,func);
  91.     WindowResizeWidth(error_window, strlen(buf), ANCHORLEFT);
  92.     WindowWriteString(error_window,buf,0,0);
  93.     WindowWriteString(error_window,"Press 'q' to quit,",2,0);
  94.     WindowWriteString(error_window,"any other key to continue...",3,0);
  95.  
  96.     WindowDisplay(error_window,1,NOEFFECT);
  97.     ch = GET_KEY();
  98.     if (ch == 'Q' || ch == 'q')
  99.     {
  100. /*      WindowUninitSystem();*/
  101.       exit(0);
  102.     }
  103.     else
  104.       WindowHide(error_window,NOEFFECT);
  105.   }
  106. }
  107.