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

  1. /***************************************
  2. *  FIELD INPUT v1.35
  3. *  © Copyright 1988 Timm Martin
  4. *  All Rights Reserved
  5. ****************************************/
  6.  
  7. #include <exec/io.h>
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <console/console.h>
  11. #include <console/fields.h>
  12. #include <console/functions.h>
  13. #include <toolkit/toolkit.h>
  14.  
  15. #define CURRENT_FIELD header->CurrentField,header->WriteReq
  16.  
  17. UBYTE field__clip[FIELD_CLIP_SIZE];
  18.  
  19. int field_input( header )
  20.   struct FieldHeader *header;
  21. {
  22.   ULONG actual;      /* actual number of characters read from console */
  23.   UBYTE hold;        /* temporary character storage */
  24.   REG   int where;   /* char in buffer being examined */
  25.  
  26.   if (!(actual = con_read( header->ReadReq, header->Buffer )))
  27.     return (0);
  28.  
  29.   if (!header->CurrentField)
  30.     return (FIELD_NO_CURRENT);
  31.  
  32.   /* check if entire input field is in the window */
  33.   if (header->Window->Width  <= header->CurrentField->Right ||
  34.       header->Window->Height <= header->CurrentField->Bottom) {
  35.     FLASH_SCREEN;
  36.     return (FIELD_OFF);
  37.   }
  38.  
  39.   where  = 0;
  40.   while (where < actual) {
  41.  
  42.     /* if read a printable character */
  43.     if ((header->Buffer[where] >= 0x20 && header->Buffer[where] <= 0x7E) ||
  44.         (header->Buffer[where] >= 0xA0 && header->Buffer[where] <= 0xFF)) {
  45.       /* if field input is masked */
  46.       if (header->CurrentField->Mask) {
  47.         /* if acceptable input character */
  48.         if ((header->CurrentField->Mask->Element[header->Buffer[where]>>5]) &
  49.             (MASK_ENABLE << (header->Buffer[where] % 32)))
  50.           field_char_type( CURRENT_FIELD, header->Buffer[where], header->TypeMode );
  51.         else
  52.           FLASH_SCREEN;
  53.       }
  54.       else
  55.         field_char_type( CURRENT_FIELD, header->Buffer[where], header->TypeMode );
  56.     }
  57.  
  58.     else if (header->Buffer[where] == BACKSPACE_CODE)
  59.       field_char_backspace( CURRENT_FIELD );
  60.  
  61.     else if (header->Buffer[where] == RETURN_CODE)
  62.       return (FIELD_RETURN);
  63.  
  64.     else if (header->Buffer[where] == DELETE_CODE)
  65.       field_char_delete( CURRENT_FIELD );
  66.  
  67.     else if (header->Buffer[where] == TAB_CODE)
  68.       field_tab_forward( CURRENT_FIELD );
  69.  
  70.     else if (header->Buffer[where] == ESCAPE_CODE)
  71.       return (FIELD_ESCAPE);
  72.  
  73.     /* if control key pressed */
  74.     else if ((hold = header->Buffer[where] | CONTROL_CODE) >= ' ' && hold <= '~') {
  75.       switch (hold) {
  76.         case 'x': field_delete( CURRENT_FIELD ); break;
  77.         case 'r': field_restore( CURRENT_FIELD ); break;
  78.         case 'd': field_dup( CURRENT_FIELD ); break;
  79.         case 'f': field_delete_forward( CURRENT_FIELD ); break;
  80.         case 'b': field_delete_backward( CURRENT_FIELD ); break;
  81.         case 't': header->TypeMode = TYPEOVER_TYPE_MODE; break;
  82.         case 'n': header->TypeMode = INSERT_TYPE_MODE; break;
  83.         case 'k': field_cut( CURRENT_FIELD ); break;
  84.         case 'o': field_copy( CURRENT_FIELD ); break;
  85.         case 'p': field_paste( CURRENT_FIELD ); break;
  86.       } /* switch control key */
  87.     }   /* else if control key */
  88.  
  89.     else if (header->Buffer[where] == CSI) {
  90.  
  91.       if (header->Buffer[++where] >= '0' && header->Buffer[where] <= '9') {
  92.         /* function keys 1-10 */
  93.         if (header->Buffer[where+1] == '~')
  94.           return (CON_F + header->Buffer[where++] - '0' + 1);
  95.         /* shifted F1-F10 */
  96.         else if (header->Buffer[where+1] >= '0' &&
  97.                  header->Buffer[where+1] <= '9' &&
  98.                  header->Buffer[where+2] == '~') {
  99.             return (CON_SHIFT_F + header->Buffer[where+1] - '0' + 1);
  100.             where += 2;
  101.         } /* else if shifted function key */
  102.       }   /* if receiving function key input */
  103.  
  104.       else {
  105.         switch (header->Buffer[where]) {
  106.           case 'A': return (FIELD_PREVIOUS); break;
  107.           case 'B': return (FIELD_NEXT); break;
  108.           case 'C': field_cursor_right( CURRENT_FIELD ); break;
  109.           case 'D': field_cursor_left( CURRENT_FIELD ); break;
  110.           case ' ': if (header->Buffer[++where] == '@')
  111.                       field_right( CURRENT_FIELD );
  112.                     else if (header->Buffer[where] == 'A')
  113.                       field_left( CURRENT_FIELD );
  114.                     break;
  115.           case 'T': return (FIELD_FIRST); break;
  116.           case 'S': return (FIELD_FINAL); break;
  117.           case '?': if (header->Buffer[++where] == '~')
  118.                       return (FIELD_HELP);
  119.                     break;
  120.           case 'Z': field_tab_backward( CURRENT_FIELD ); break;
  121.         } /* switch */
  122.       }   /* else not function keys */
  123.     }     /* else buffer == <CSI> */
  124.  
  125.     where++;
  126.   } /* while have not exhausted buffer */
  127.  
  128.   return (FIELD_SWALLOW);
  129.   /* input swallowed into field; no response required from calling program */
  130. }
  131.