home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / SYSTEM / IED_EED.ZIP / IED.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-22  |  3.3 KB  |  132 lines

  1. /*
  2.  * ied.c -- take a string on the command line or on stdin, allow the
  3.  *        user to edit it, and put the result on stdout
  4.  *
  5.  * Released under the terms of the GNU General Public License.  No warranty
  6.  * is expressed or implied.
  7.  *
  8.  * This version is for MS-DOS only, using MS C 5.1 and the CXL library v5.1.
  9.  * Compile in the small model, and link against CXLMSS.LIB.
  10.  *
  11.  * A curses version for UNIX is in the works.
  12.  *
  13.  * Richard Reiner  rreiner@nexus.yorku.ca
  14.  *
  15.  * Ied leaves the screen undisturbed: it saves the screen on entry, and
  16.  * restores the obscured area on exit.  The cursor, however, is likely
  17.  * to be moved.
  18.  *
  19.  * Limits: the string to be edited, including the terminating
  20.  * '\0', cannot exceed MAXSTRLEN characters.  If a longer string
  21.  * is passed in, ied will abort with an error message and return
  22.  * the string unchanged.
  23.  *
  24.  * Return values:   0 -- normal completion
  25.  *            1 -- input string too long to edit
  26.  *
  27.  * Revision history:
  28.  *
  29.  * 1.0    22 Aug 90    RjR    First version.
  30.  *
  31.  */
  32.  
  33. #include <stdio.h>
  34. #include <string.h>
  35.  
  36. #include <cxl\cxldef.h>
  37. #include <cxl\cxlvid.h>
  38. #include <cxl\cxlwin.h>
  39. #include <cxl\cxlstr.h>
  40.  
  41. #define MAXSTRLEN 77    /* maximum length of editable string including '\0' */
  42. #define INBUFSIZE 512    /* size of input buffer */
  43.  
  44. int fsread(void);
  45. void initcxl(void);
  46. char *strrtrim(char *);
  47.  
  48. char str[INBUFSIZE];
  49.  
  50. main(int argc, char **argv)
  51. {
  52.     /* take arg from command line if there is one; otherwise read stdin */
  53.     if (argc > 1)
  54.     strcpy(str,argv[1]);
  55.     else
  56.     gets(str);
  57.  
  58.     if (strlen(str) > MAXSTRLEN) {
  59.     fputs("\nied: error: string exceeds maximum editable length\n",stderr);
  60.     fputs(str, stdout);
  61.     exit(1);
  62.     }
  63.     else {
  64.     initcxl();
  65.     fsread();
  66.     fputs(str, stdout);
  67.     exit(0);
  68.     }
  69. }
  70.  
  71.  
  72. /*---------------------------------------------------------------------------*/
  73. /* fsread -- input a record in full-screen mode */
  74. int fsread(void)
  75. {
  76.     WINDOW editwin;
  77.     int editstat;
  78.     char mask[MAXSTRLEN];
  79.  
  80.     /* set up the input mask */
  81.     memset(mask,'*',MAXSTRLEN - 1);
  82.     mask[MAXSTRLEN - 1] = '\0';
  83.  
  84.     editwin = wopen(10, 0, 14, 79, 1, LGREY | _BLACK, LGREY | _BLACK);
  85.     wcenters(0, LMAGENTA | _BLACK, "Edit string; CR to accept, ESC to abort");
  86.  
  87.     winpbeg(LGREY | _BLACK, BLACK | _LGREY);
  88.     winpdef(2, 1, str, mask, 0, 1, NULL, 0);
  89. /*    winpdef(2, 1, str, "************************", 0, 1, NULL, 0); */
  90.     editstat = winpread();
  91.  
  92.     wclose();
  93.  
  94.     /* kill all the trailing whitespace */
  95.     strrtrim(str);
  96.  
  97.     return (editstat);
  98. }
  99.  
  100.  
  101. /*---------------------------------------------------------------------------*/
  102. /* initialize CXL video and keyboard handling */
  103. void initcxl(void)
  104. {
  105.     _vinfo.dvcheck = 0;
  106.     /* don 't check for DESQview */
  107.     videoinit();
  108.     _vinfo.usebios = 0;
  109.     wfillch('░');
  110.     /* background char for windows */
  111.     wsetesc(1);
  112.     /* set ESC checking on */
  113. }
  114.  
  115.  
  116.  
  117. /*---------------------------------------------------------------------------*/
  118. /* strrtrim -- kill trailing whitespace in a string */
  119. char *strrtrim(char *s)
  120. {
  121.     char *p;
  122.  
  123.     p = s + strlen(s) - 1;        /* point at the last data char */
  124.  
  125.     while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')
  126.     p--;
  127.  
  128.     *(++p) = '\0';
  129.  
  130.     return (s);
  131. }
  132.