home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 337_01 / l_input.c < prev    next >
C/C++ Source or Header  |  1991-01-14  |  4KB  |  121 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   L_INPUT.C   ***************************/
  4.  
  5. #include "mydef.h"
  6. #include "stdio.h"
  7.  
  8. /*****************************************************************
  9.  
  10.  Usage: int  input(struct in_struc in_scrn[]);
  11.  
  12.   in_scrn[] = a array of struct in_struc.
  13.  
  14.   Creates a data input screen based on the data structure in_scrn[].
  15.   Allows full editing of input screen until the user presses "Enter"
  16.   on the last field, or presses "PgUp", "PgDn" or "Esc".
  17.  
  18. *****************************************************************/
  19.  
  20. int  input(struct in_struc in_scrn[])
  21. {
  22. extern struct  screen_structure scr;
  23. extern struct window_structure w[];
  24.  
  25. int number=0;
  26. int i,x,y,done=FALSE;
  27. char old_current=scr.current; /* save current attribute */
  28. char temp_attr;
  29. char ext;
  30. int val_code;
  31.  
  32. /* search for terminating zero in data structure */
  33. for(;;){
  34.  if (in_scrn[number++].x==0) break;
  35.  if (number==1000) return(1);  /* count too high, must not
  36.                                   have terminator */
  37. }
  38. number--;  /* reset to correct value */
  39.  
  40.   /* write field prompts and highlight input area */
  41.    for(i=0;i<number;i++){
  42.     x= in_scrn[i].x; y= in_scrn[i].y;   /* calc. x-y coordinates */
  43.  
  44.     if (scr.mode==COLOR_80) /*if color then set label x_attribute */
  45.         scr.current= set_color(in_scrn[i].label_f,
  46.                                in_scrn[i].label_b);
  47.       else
  48.        scr.current=scr.normal;
  49.  
  50.     print(x,y,in_scrn[i].prompt);   /* print input label */
  51.  
  52.     if (scr.mode==COLOR_80)
  53.      scr.current = set_color(in_scrn[i].input_f,in_scrn[i].input_b);
  54.     else
  55.        scr.current = scr.inverse;
  56.  
  57.     x=x+strlen(in_scrn[i].prompt)+1; /* move past input label */
  58.         hilight_field(x,y,in_scrn[i].length,scr.current);
  59.  
  60.     print(x,y,in_scrn[i].ptr); /* show contents */
  61.    }
  62.  
  63.    /* At this point we have set up the screen,
  64.       we now input the data. */
  65.  
  66.    i=0;  /* use first field */
  67.  
  68.    /* this is the main loop in which editing occurs */
  69.    while(!done){
  70.     x= in_scrn[i].x; y=in_scrn[i].y;       /* get x,y coordinates */
  71.     x=x+strlen(in_scrn[i].prompt )+1;      /* move past label */
  72.  
  73. /* set up field attribute */
  74.     if (scr.mode==COLOR_80)
  75.      scr.current = set_color(in_scrn[i].input_f,in_scrn[i].input_b);
  76.       else
  77.       scr.current=scr.inverse;
  78.  
  79.  for(;;){   /* loop until a valid field is read */
  80.     gotoxy(x,y);
  81.     /* get the string */
  82.     ext=getfield(in_scrn[i].ptr,in_scrn[i].length,0,scr.current);
  83.  
  84.    if (ext==ESCAPE) break; /* don't validate if Escape pressed */
  85.  
  86.    /* validate the field */
  87.  
  88.    temp_attr=scr.current;  /* save our attribute */
  89.  
  90.    /* validate data entered */
  91.    val_code=val_field(in_scrn[i].ptr,in_scrn[i].length,i);
  92.    scr.current=temp_attr;
  93.  
  94.        if (val_code==REDO) putchar(BELL);
  95.        if (val_code==OK) break;
  96.  
  97.    if (val_code==REDRAW) {         /* redraw field is requested */
  98.       /* highlight input field to erase current contents */
  99.       hilight_field(x,y,in_scrn[i].length,scr.current);
  100.       print (x,y,in_scrn[i].ptr); /* print new contents */
  101.       break;
  102.    }
  103.  } /* end for(;;) */
  104.  
  105.     if(ext== UP) i--;
  106.     if(ext== DOWN|| ext==RETURN) i++;
  107.     if(ext== ESCAPE || ext== PGUP || ext==PGDN) break;
  108.  
  109.     if (i==number && ext==RETURN ){     /* last field? */
  110.       ext=RETURN;
  111.       break;
  112.     }
  113.     if (i<0) i=(number-1);    /* check boundary conditions */
  114.     if (i> (number-1)) i=0;
  115.  
  116.     }   /*end while (!done)*/
  117.  
  118.    scr.current=old_current;
  119.    return(ext);
  120. }
  121.