home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk430.lzh / SmartFields / Functions / console_input.c < prev    next >
C/C++ Source or Header  |  1991-01-11  |  3KB  |  93 lines

  1. /***************************************
  2. *  CONSOLE INPUT v1.23
  3. *  © Copyright 1988 Timm Martin
  4. *  All Rights Reserved
  5. ****************************************/
  6.  
  7. #include <exec/io.h>
  8. #include <exec/types.h>
  9. #include <console/console.h>
  10. #include <console/functions.h>
  11.  
  12. int console_input( header )
  13.   struct ConsoleHeader *header;
  14. {
  15.   ULONG actual;      /* actual number of characters read from console */
  16.   UBYTE hold;        /* temporary character storage */
  17.   int   where;       /* character in buffer being examined */
  18.  
  19.   actual = con_read( header->ReadReq, header->Buffer );
  20.   if (!actual)
  21.     return (0);  /* no characters read */
  22.   else
  23.     where = 0;   /* start at beginning of buffer */
  24.  
  25.   /* if read printable character */
  26.   if ((header->Buffer[where] >= 0x20 && header->Buffer[where] <= 0x7E) ||
  27.       (header->Buffer[where] >= 0xA0 && header->Buffer[where] <= 0xFF))
  28.     /* if input is masked */
  29.     if (header->Mask) {
  30.       /* if acceptable input character */
  31.         if ((header->Mask->Element[header->Buffer[where]>>5]) &
  32.             (MASK_ENABLE << (header->Buffer[where] % 32 )))
  33.           return (header->Buffer[where]);
  34.         else
  35.           return (0);
  36.     }
  37.     else
  38.       return (header->Buffer[where]);
  39.  
  40.   else if (header->Buffer[where] == BACKSPACE_CODE)
  41.     return (CON_BACKSPACE);
  42.   else if (header->Buffer[where] == RETURN_CODE)
  43.     return (CON_RETURN);
  44.   else if (header->Buffer[where] == DELETE_CODE)
  45.     return (CON_DELETE);
  46.   else if (header->Buffer[where] == TAB_CODE)
  47.     return (CON_TAB);
  48.   else if (header->Buffer[where] == ESCAPE_CODE)
  49.     return (CON_ESCAPE);
  50.  
  51.   else if ((hold = header->Buffer[where] | CONTROL_CODE) >= ' ' && hold <= '~')
  52.     return (CON_CONTROL + hold);              /* return control key */
  53.  
  54.   else if (header->Buffer[where] == CSI) {
  55.  
  56.     if (actual == 1)
  57.       return (CON_ALT_ESCAPE);
  58.  
  59.     if (header->Buffer[++where] >= '0' && header->Buffer[where] <= '9') {
  60.       if (header->Buffer[where+1] == '~')
  61.         /* function keys F1-F10 */
  62.         return (CON_F + header->Buffer[where] - '0' + 1);
  63.       else if (header->Buffer[where+1] >= '0' &&
  64.                header->Buffer[where+1] <= '9' &&
  65.                header->Buffer[where+2] == '~')
  66.         /* shifted F1-F10 */
  67.         return (CON_SHIFT_F + header->Buffer[where+1] - '0' + 1);
  68.     }   /* if receiving function key input */
  69.  
  70.     else {
  71.       switch (header->Buffer[where]) {
  72.         case 'A': return (CON_CURSOR_UP); break;
  73.         case 'B': return (CON_CURSOR_DOWN); break;
  74.         case 'C': return (CON_CURSOR_RIGHT); break;
  75.         case 'D': return (CON_CURSOR_LEFT); break;
  76.         case ' ': if (header->Buffer[++where] == '@')
  77.                     return (CON_SHIFT_RIGHT);
  78.                   else if (header->Buffer[where] == 'A')
  79.                     return (CON_SHIFT_LEFT);
  80.                   break;
  81.         case 'T': return (CON_SHIFT_UP); break;
  82.         case 'S': return (CON_SHIFT_DOWN); break;
  83.         case '?': if (header->Buffer[++where] == '~')
  84.                     return (CON_HELP);
  85.                   break;
  86.         case 'Z': return (CON_SHIFT_TAB); break;
  87.       } /* switch */
  88.     }   /* else not function keys */
  89.   }     /* else header->Buffer == <CSI> */
  90.  
  91.   return (0);  /* unrecognizable character */
  92. }
  93.