home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / prog1 / boss719a.lzh / WN_GTEXT.C < prev    next >
C/C++ Source or Header  |  1990-05-30  |  10KB  |  251 lines

  1. /*
  2. ** The Window BOSS's Data Clerk
  3. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  4. ** All rights reserved.
  5. **
  6. ** wn_gtext - get text from window 
  7. **
  8. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  9. ** All rights reserved.
  10. **
  11. */
  12.  
  13. #include "windows.h"                    /* standard stuff */
  14.  
  15. static char maskchar = 'T';             /* default mask character */
  16. static int  funcode  = GTEXT;           /* default function code */
  17.  
  18. /*
  19. *************
  20. * wns_gtext *
  21. *************
  22. */
  23.  
  24. /*
  25. ** wns_gtext(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,ubuff,hlpmsg,errmsg)
  26. **
  27. **    int        fun - fucntion code (SET || XEQ)
  28. **    (WIFORM)   frm - form pointer  (actual || NFRM)
  29. **    int        fld - field # in form (actual || NFLD)
  30. **    (WINDOWPTR) wn - window pointer
  31. **    int        row - row in window where data input begins
  32. **    int        col - col in window where data input begins
  33. **    (char *) prmpt - field promt (call with NSTR for none)
  34. **    unsigned atrib - field (not prompt) atributes 
  35. **    char      fill - field fill character
  36. **    int     fwidth - width of mask (maximum # of digits is MAXSTR)
  37. **    (char *) ubuff - pointer to char array of fwidth+2 bytes for editing 
  38. **    (char *)hlpmsg - pointer to help message (call with NSTR for none)
  39. **    (char *)errmsg - pointer to err message (call with NSTR) for none)
  40. **
  41. ** RETURNS:
  42. **
  43. **    UBUFF with text data via pointer.
  44. **
  45. **    NULL if error, else the non zero value returned from wn_input.
  46. **
  47. ** NOTES:
  48. **
  49. **  FUN -   fun can only be SET for form setup, or XEQ for immediate
  50. **          execution.  When called with SET, valid arguements for both
  51. **          "frm" and "fld" must be specfied.  frm is the field pointer
  52. **          returned from frmopn(), and fld is the field sequence number
  53. **          in the form for this field.  When called with XEQ frm must
  54. **          be NFRM and fld must NFLD.
  55. **
  56. **  UBUFF - Editing buffer.  Must be of sufficent size to hold the
  57. **          data as it is entered.  Typical value is the length
  58. **          of the mask + 2 bytes (strlen(mask)+2).
  59. **
  60. **          On entry, the first byte of ubuff should be 
  61. **          a null, otherwise wn_input assumes there is valid
  62. **          data there and will enter edit mode.  This can be 
  63. **          handy if there is a need for prefilled but editable
  64. **          fields.  In actual pratice, wn_input uses this
  65. **          buffer for both initial character data entry and
  66. **          subsequent editing.
  67. **
  68. **          On return, ubuff contains the actual data entered in
  69. **          character format with fill and mask characters as
  70. **          spaces (e.g. "This is a line of text ").
  71. **
  72. **  Calls wn_input to perform data entry.
  73. **
  74. **  No validation is performed.
  75. */
  76.  
  77. wns_gtext(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,ubuff,hlpmsg,errmsg)
  78. int fun;                                /* SET or XEQ */
  79. WIFORM frm;                             /* form pointer or NFRM */
  80. int fld;                                /* field number or NFLD */
  81. WINDOWPTR wn;                           /* window to use */
  82. int row, col;                           /* position of input field */
  83. char *prmpt;                            /* prompt string */
  84. unsigned atrib;                         /* data entry atribute */
  85. char fill;                              /* fill char */
  86. int fwidth;                             /* field width */
  87. char *ubuff;                            /* returns "text" */
  88. char *hlpmsg, *errmsg;                  /* help & error messages */
  89. {
  90. char *mask;                             /* mask buffer */
  91. char *p;                                /* scratch */
  92. int i;                                  /* scratch */
  93. int rv;                                 /* return value */
  94.  
  95.   if(fun != SET && fun != XEQ)          /* saftey check */
  96.     return(NULL);
  97.  
  98.   if(fun == SET) {                      /* set up */
  99.     if(frm[fld]->pself != (char *)frm[fld])
  100.       wns_ierr("wn_gtext");             /* die if memory is mangled */
  101.     frm[fld]->wn = wn;                  /* set window */
  102.     frm[fld]->row = row;                /* set row */
  103.     frm[fld]->col = col;                /* set col */
  104.     frm[fld]->prmpt = prmpt;            /* set prompt */
  105.     frm[fld]->atrib = atrib;            /* set attribute */
  106.     frm[fld]->fill = fill;              /* set fill character */
  107.     frm[fld]->fcode = funcode;          /* function code */
  108.     frm[fld]->v1.vi = fwidth;           /* fwidth */
  109.     frm[fld]->v2.vcp = ubuff;           /* &ubuff */
  110.     frm[fld]->v3.vcp = hlpmsg;          /* &hlpmsg */
  111.     frm[fld]->v4.vcp = errmsg;          /* &errmsg */
  112.     return(TRUE);
  113.   }
  114.  
  115.   if(fwidth >= MAXSTR) {                /* dont allow foolishness */
  116.     *ubuff = NUL;                       /* indicate error */
  117.     return(NULL);                       /* and return */
  118.   }
  119.   mask = malloc(fwidth+2);              /* fetch some memory */
  120.   if(!mask) {                           /* allocation fail ?? */
  121.     *ubuff = NUL;                       /* terminate string */
  122.     return(NULL);                       /* say things went bad */
  123.   }
  124.   p = mask;                             /* temp pointer */
  125.   for(i=0; i<fwidth; i++) {             /* set up mask */
  126.     *p = maskchar;                      /* TEXT (any, upper, lower) */
  127.     p++;                                /* bump pointer */
  128.     *p = NUL;                           /* terminate string */
  129.   }
  130.   if(!(rv=wn_input(wn,row,col,prmpt,mask,fill,atrib,ubuff,hlpmsg))) {
  131.     *ubuff= NUL;                        /* indicate error */
  132.     free(mask);                         /* free memory */
  133.     return(NULL);                       /* indicate error */
  134.   }
  135.   free(mask);                           /* free memory */
  136.   if(wni_frmflg) return(TRUE);          /* wn_frmget in progress */
  137.   return(rv);                           /* all done */
  138. }
  139.  
  140. #ifdef COMMENTS
  141. /*
  142. ************
  143. * wn_gtext *                            /* Plain Text */
  144. ************
  145. */
  146. #endif
  147.  
  148. wn_gtext(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,ubuff,hlpmsg,errmsg)
  149. int fun;                                /* SET or XEQ */
  150. WIFORM frm;                             /* form pointer or NFRM */
  151. int fld;                                /* field number or NFLD */
  152. WINDOWPTR wn;                           /* window to use */
  153. int row, col;                           /* position of input field */
  154. char *prmpt;                            /* prompt string */
  155. unsigned atrib;                         /* data entry atribute */
  156. char fill;                              /* fill char */
  157. int fwidth;                             /* field width */
  158. char *ubuff;                            /* returns "text" */
  159. char *hlpmsg, *errmsg;                  /* help & error messages */
  160. {
  161.   maskchar = 'T';
  162.   funcode = GTEXT;                      
  163.   return(wns_gtext(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,
  164.             ubuff,hlpmsg,errmsg));
  165. }
  166.  
  167. #ifdef COMMENTS
  168. /*
  169. *************
  170. * wn_gutext *                           /* Upper Case Only Text */
  171. *************
  172. */
  173. #endif
  174.  
  175. wn_gutext(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,ubuff,hlpmsg,errmsg)
  176. int fun;                                /* SET or XEQ */
  177. WIFORM frm;                             /* form pointer or NFRM */
  178. int fld;                                /* field number or NFLD */
  179. WINDOWPTR wn;                           /* window to use */
  180. int row, col;                           /* position of input field */
  181. char *prmpt;                            /* prompt string */
  182. unsigned atrib;                         /* data entry atribute */
  183. char fill;                              /* fill char */
  184. int fwidth;                             /* field width */
  185. char *ubuff;                            /* returns "text" */
  186. char *hlpmsg, *errmsg;                  /* help & error messages */
  187. {
  188.   funcode = GUTEXT;
  189.   maskchar = 'U';
  190.   return(wns_gtext(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,
  191.             ubuff,hlpmsg,errmsg));
  192. }
  193.  
  194. #ifdef COMMENTS
  195. /*
  196. *************
  197. * wn_gltext *                           /* Lower Case Only Comments */
  198. *************
  199. */
  200. #endif
  201.  
  202. wn_gltext(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,ubuff,hlpmsg,errmsg)
  203. int fun;                                /* SET or XEQ */
  204. WIFORM frm;                             /* form pointer or NFRM */
  205. int fld;                                /* field number or NFLD */
  206. WINDOWPTR wn;                           /* window to use */
  207. int row, col;                           /* position of input field */
  208. char *prmpt;                            /* prompt string */
  209. unsigned atrib;                         /* data entry atribute */
  210. char fill;                              /* fill char */
  211. int fwidth;                             /* field width */
  212. char *ubuff;                            /* returns "text" */
  213. char *hlpmsg, *errmsg;                  /* help & error messages */
  214. {
  215.   funcode = GLTEXT;
  216.   maskchar = 'L';
  217.   return(wns_gtext(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,
  218.             ubuff,hlpmsg,errmsg));
  219.  
  220. }
  221.  
  222. #ifdef COMMENTS
  223. /*
  224. *************
  225. * wn_gatext *                           /* Get Ascii (ANY ASCII) */
  226. *************
  227. */
  228. #endif
  229.  
  230. wn_gatext(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,ubuff,hlpmsg,errmsg)
  231. int fun;                                /* SET or XEQ */
  232. WIFORM frm;                             /* form pointer or NFRM */
  233. int fld;                                /* field number or NFLD */
  234. WINDOWPTR wn;                           /* window to use */
  235. int row, col;                           /* position of input field */
  236. char *prmpt;                            /* prompt string */
  237. unsigned atrib;                         /* data entry atribute */
  238. char fill;                              /* fill char */
  239. int fwidth;                             /* field width */
  240. char *ubuff;                            /* returns "text" */
  241. char *hlpmsg, *errmsg;                  /* help & error messages */
  242. {
  243.   funcode = GATEXT;
  244.   maskchar = 'A';
  245.   return(wns_gtext(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,
  246.             ubuff,hlpmsg,errmsg));
  247.  
  248. }
  249.  
  250. /* End */
  251.