home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 155_01 / termctrl.c < prev    next >
C/C++ Source or Header  |  1990-10-09  |  3KB  |  142 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "btree.h"
  4.  
  5. /* Author: Ray Swartz
  6.  *         Berkeley Decision/Systems, Inc.
  7.  *         P.O. Box 2528
  8.  *         Santa Cruz, Calif. 95063
  9.  * Last Modified: 4/28/85
  10.  *
  11.  * ANY USE OF THESE LIBRARY ROUTINES EITHER PERSONAL OR COMMERCIAL
  12.  * IS ALLOWED UPON THE CONDITION THAT THE USER IDENTIFY THEM
  13.  * AS BEING USED IN THE PROGRAM.  IDENTIFYING INFORMATION MUST
  14.  * APPEAR IN THE PROGRAM DOCUMENTATION OR ON THE TERMINAL SCREEN.
  15.  *
  16.  *         #################################    
  17.  *         # UNATTRIBUTED USE IS FORBIDDEN #
  18.  *         #################################
  19.  *
  20.  */
  21.  
  22. /* Modifier: Honma Michimasa
  23.  *    Higashi Kamagaya 2-6-54
  24.  *    Kamagayashi, Chiba, Japan, 273-01
  25.  *
  26.  *
  27.  *
  28.  */
  29.  
  30.  /***** function prot. *************/
  31. void cursor(int row, int col);  /* cursor movement on a MS-DOS machine */
  32. int main_prompt(char *prompt);   /* prompt used as database interface */
  33. void get_key(char *prompt, char *key, struct keyinfo *fileinfo);
  34.             /* prompt for and read the key to FIND (from keyboard) */
  35. void print_msg(char *prompt);  /* go to line 20, clear window, ring bell, prompt */
  36. void t_delay(void); /* display message delay */
  37.  /**********************************/
  38.  
  39. void cursor(int row, int col)  /* cursor movement on a MS-DOS machine */
  40. {
  41.     printf("\033[%d;%dH", row, col);
  42. }
  43.  
  44.  
  45. int main_prompt(char *prompt)   /* prompt used as database interface */
  46. {
  47.     extern char instr[];
  48.  
  49.     int count;
  50.  
  51.     cursor(20,1);
  52.     CLEAR_LINE;
  53.     printf("Find   Next   Previous   Insert   Delete   Quit   Top   Last");
  54.     while(1) {
  55.         cursor(22,1);
  56.         CLEAR_LINE;
  57.         printf(prompt);
  58.         gets(instr);
  59.         switch(*instr) {
  60.             case 'F':
  61.             case 'f':
  62.                 return(FIND);
  63.             case 'I':
  64.             case 'i':
  65.                 return(INSERT);
  66.             case 'N':
  67.             case 'n':
  68.                 return(NEXT);
  69.             case 'P':
  70.             case 'p':
  71.                 return(PREVIOUS);
  72.             case 'D':
  73.             case 'd':
  74.                 return(DELETE);
  75.             case 'Q':
  76.             case 'q':
  77.                 return(QUIT);
  78.             case 'T':
  79.             case 't':
  80.                 return(FIRST);
  81.             case 'L':
  82.             case 'l':
  83.                 return(LAST);
  84.         }
  85.     }
  86. }
  87.  
  88.  
  89.    /* prompt for and read the key to FIND (from keyboard) */
  90. void get_key(char *prompt, char *key, struct keyinfo *fileinfo)
  91. {
  92.     extern char instr[];
  93.  
  94.     cursor(20,1);
  95.     CLEAR_LINE;
  96.     printf(prompt);
  97.     gets(instr);
  98.     strncpy(key, instr, fileinfo->keylength);
  99.     key[fileinfo->keylength]='\0';
  100.     return;
  101. }
  102.  
  103.  
  104. void print_msg(char *prompt)  /* go to line 20, clear window, ring bell, prompt */
  105. {
  106.     cursor(20,1);
  107.     CLEAR_LINE;
  108.     BELL
  109.     printf(prompt);
  110.     t_delay();
  111. }
  112.  
  113.  
  114. void t_delay() /* display message delay */
  115. {
  116.     long  count = 0;
  117.     
  118.     while(count++ < 60000)
  119.       ;
  120. }
  121.  
  122.  
  123. int yes_or_no(char *prompt)  /* print prompt and return YES or NO */
  124. {
  125.     extern char instr[];
  126.  
  127.     while(1) {
  128.         cursor(20,1);
  129.         CLEAR_LINE;
  130.         printf(prompt);
  131.         gets(instr);
  132.         if (*instr == 'Y' || *instr == 'y')
  133.             return(YES);
  134.         else if(*instr == 'N' || *instr == 'n')
  135.             return(NO);
  136.         else {
  137.             BELL
  138.             printf("\nPlease enter Y or N only\n");
  139.         }
  140.     }
  141. }
  142.