home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / DSIIC2.ZIP / L_INPUT.C < prev    next >
C/C++ Source or Header  |  1991-07-15  |  4KB  |  125 lines

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