home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2419 < prev    next >
Internet Message Format  |  1990-12-28  |  9KB

  1. From: pjc@pcbox.UUCP (Paul J. Condie)
  2. Newsgroups: alt.sources
  3. Subject: menu(1) part 14 of 14
  4. Message-ID: <448@pcbox.UUCP>
  5. Date: 26 Dec 90 20:17:44 GMT
  6.  
  7.  
  8. #!/bin/sh
  9. # this is part 14 of a multipart archive
  10. # do not concatenate these parts, unpack them in order with /bin/sh
  11. # file utilities.d/msgbox.d/msgbox.c continued
  12. #
  13. CurArch=14
  14. if test ! -r s2_seq_.tmp
  15. then echo "Please unpack part 1 first!"
  16.      exit 1; fi
  17. ( read Scheck
  18.   if test "$Scheck" != $CurArch
  19.   then echo "Please unpack part $Scheck next!"
  20.        exit 1;
  21.   else exit 0; fi
  22. ) < s2_seq_.tmp || exit 1
  23. echo "x - Continuing file utilities.d/msgbox.d/msgbox.c"
  24. sed 's/^X//' << 'SHAR_EOF' >> utilities.d/msgbox.d/msgbox.c
  25. X#define ARG_COUNT_ERR 1    /* improper argc value in main */
  26. X#define MSG_LEN_ERR 2    /* argv[2] message is out of range (1 - 78 chars) */
  27. X#define STANDOUT 2    /* drawbox() needs this for border attribute. */
  28. X
  29. X
  30. Xmain(argc, argv)
  31. Xint argc;
  32. Xchar *argv[];
  33. X{
  34. X    char msg[78];    /* a message gotten from argv[2] or error msg */
  35. X
  36. X    int    BoxColumns,    /* total columns in box, calculated */
  37. X        BoxStartCol,    /* starting left most column of box, calculated */
  38. X        BoxTop,        /* starting top most row of box, from argv[1] */
  39. X        ErrStatus;    /* values: NO_ERR, ARG_COUNT_ERR, MSG_LEN_ERR */
  40. X
  41. X    WINDOW *MsgWind;    /* The mesage box itself */
  42. X
  43. X    /* derive the box's top row value from argv[1] via atoi() */
  44. X    BoxTop = atoi(argv[2]);
  45. X
  46. X    /* if error in argv[2], use 0 as BoxTop value */
  47. X    if (BoxTop > MAX_ROW || BoxTop < 1) {
  48. X    BoxTop=0;
  49. X    }
  50. X
  51. X    /* check for proper arg count and proper msg length; If in error, form msg
  52. X     * as an error message; if no error, use argv[2] as msg.
  53. X     */
  54. X    if (argc < 2 || argc > 3) {
  55. X    ErrStatus=ARG_COUNT_ERR;
  56. X    } else {
  57. X    /* check the string length of the message */
  58. X    if (strlen(argv[1]) && strlen(argv[1]) < 79 ) {
  59. X        ErrStatus=NO_ERR;
  60. X    } else {
  61. X        ErrStatus=MSG_LEN_ERR;
  62. X    }
  63. X    }
  64. X
  65. X
  66. X    /* if no errors were found, use argv[2] as msg, else use a USEAGE message */
  67. X    if (ErrStatus == NO_ERR) {
  68. X    strcpy(msg, argv[1]);
  69. X    } else {
  70. X    sprintf(msg, 
  71. X     " USAGE: %s \"Quote mark delimited message (1-78 chars)\" [TopRow] ",
  72. X     argv[0]); 
  73. X    }
  74. X
  75. X    BoxColumns=strlen(msg) + 2;        /* size box on msg */
  76. X    BoxStartCol=(80 - BoxColumns)/2;        /* center window horizontally */
  77. X
  78. X
  79. X    initscr();
  80. X
  81. X
  82. X    /* Create a new window to display a message to the user */
  83. X    MsgWind=newwin(BOX_ROWS, BoxColumns, BoxTop, BoxStartCol);
  84. X    drawbox(MsgWind, 1, 1, BOX_ROWS, BoxColumns, STANDOUT, STANDOUT, 0, 0);
  85. X    mvwaddstr(MsgWind, 2, 1, msg);
  86. X    wrefresh(MsgWind);
  87. X
  88. X    endwin();
  89. X
  90. X    /* give humans time to view usage error message */
  91. X    if (ErrStatus != NO_ERR) 
  92. X    sleep(5);
  93. X
  94. X    exit(ErrStatus);
  95. X
  96. X}   /* end main */
  97. SHAR_EOF
  98. echo "File utilities.d/msgbox.d/msgbox.c is complete"
  99. chmod 0644 utilities.d/msgbox.d/msgbox.c || echo "restore of utilities.d/msgbox.d/msgbox.c fails"
  100. echo "x - extracting utilities.d/MenuMsg.d/MenuMsg.1 (Text)"
  101. sed 's/^X//' << 'SHAR_EOF' > utilities.d/MenuMsg.d/MenuMsg.1 &&
  102. X. \ %W% DeltaDate %G% ExtrDate %H% 
  103. X.po 6
  104. X.TH MENUMSG 1 "" "Menu Utility"
  105. X
  106. X.SH \s9NAME\s0
  107. XMenuMsg -\ writes a message to a menu screen
  108. X
  109. X.SH SYNOPSIS
  110. X.B MenuMsg [ DONT_CLEAR ] row col message
  111. X
  112. X.SH DESCRIPTION
  113. X.B MenuMsg
  114. Xis designed to be a utility program to be used in conjunction with the menu(1)
  115. Xprogram.  This can be used to display a message to a menu screen without
  116. Xmessing up the screen.  The [ DONT_CLEAR ] option causes MenuMsg not to
  117. Xclear the line before displaying the message.
  118. X
  119. X
  120. X.SH EXAMPLE
  121. XTo print a message to the message row:
  122. X.nf
  123. X
  124. X    MenuMsg `tput lines` 0 "This is a message."
  125. X.fi
  126. X
  127. X.SH AUTHOR
  128. XPaul J. Condie       7/90
  129. X.br
  130. X{att,bellcore,sun,ames,pyramid}!pacbell!pcbox!pjc
  131. X
  132. X.SH SEE ALSO
  133. Xmenu(1).
  134. SHAR_EOF
  135. chmod 0644 utilities.d/MenuMsg.d/MenuMsg.1 || echo "restore of utilities.d/MenuMsg.d/MenuMsg.1 fails"
  136. echo "x - extracting utilities.d/MenuMsg.d/MenuMsg.c (Text)"
  137. sed 's/^X//' << 'SHAR_EOF' > utilities.d/MenuMsg.d/MenuMsg.c &&
  138. X/*
  139. X**  MenuMsg(1)
  140. X**    Display text to a menu(1) screen without trashing the screen.
  141. X**  ARGS
  142. X**    row and col to dispaly text to
  143. X*/
  144. X
  145. X#include    <curses.h>
  146. X#include    <term.h>
  147. X
  148. Xmain (argc, argv)
  149. X    int    argc;
  150. X    char    *argv[];
  151. X{
  152. X    FILE    *fopen(), *fp;
  153. X    char    *tparm();
  154. X    char    *getenv();
  155. X    char    *tparm();
  156. X    int    _outch();
  157. X    char    *term;
  158. X    int    status;
  159. X    char    *str;
  160. X    int    row;
  161. X    int    col;
  162. X
  163. X    if ((fp = fopen ("/dev/tty", "w")) == (FILE *)NULL)/* reopen terminal */
  164. X        exit (1);
  165. X    if ((term = getenv ("TERM")) == (char *)NULL)
  166. X        exit (1);
  167. X    setupterm (term, 1, &status);        /* set-up terminal */
  168. X    if (status != 1)
  169. X        exit (1);
  170. X    if (cursor_address == NULL)        /* we need cursor movement */
  171. X        exit (1);
  172. X    if (strcmp (argv[1], "DONT_CLEAR") == 0)
  173. X    {
  174. X        sscanf (argv[2], "%d", &row);
  175. X        sscanf (argv[3], "%d", &col);
  176. X        fprintf (fp, "%s%s", tparm (cursor_address, row, col), argv[4]);
  177. X    }
  178. X    else
  179. X    {
  180. X        sscanf (argv[1], "%d", &row);
  181. X        sscanf (argv[2], "%d", &col);
  182. X        fprintf (fp, "%s", tparm (cursor_address, row, col));
  183. X        fprintf (fp, "%s", tparm (clr_eol));
  184. X        fprintf (fp, "%s%s", tparm (cursor_address, row, col), argv[3]);
  185. X    }
  186. X    /*
  187. X    tputs (tparm (cursor_address, row, col), 1, _outch);
  188. X    fprintf (fp, "%s", argv[3]);
  189. X    */
  190. X    fclose (fp);
  191. X}
  192. X/* Paul J. Condie  7-90 */
  193. SHAR_EOF
  194. chmod 0644 utilities.d/MenuMsg.d/MenuMsg.c || echo "restore of utilities.d/MenuMsg.d/MenuMsg.c fails"
  195. echo "x - extracting utilities.d/MenuMsg.d/MenuPrompt.1 (Text)"
  196. sed 's/^X//' << 'SHAR_EOF' > utilities.d/MenuMsg.d/MenuPrompt.1 &&
  197. X. \ %W% DeltaDate %G% ExtrDate %H% 
  198. X.po 6
  199. X.TH MENUPROMPT 1 "" "Menu Utility"
  200. X
  201. X.SH \s9NAME\s0
  202. XMenuPrompt -\ writes a prompt message to a menu screen then prompts for a reply
  203. X
  204. X.SH SYNOPSIS
  205. X.B MenuPrompt [ DONT_CLEAR ] row col message
  206. X
  207. X.SH DESCRIPTION
  208. X.B MenuPrompt
  209. Xis designed to be a utility program to be used in conjunction with the menu(1)
  210. Xprogram.  This can be used to prompt for a reply from the user within a
  211. Xmenu screen.
  212. X
  213. X
  214. X.SH EXAMPLE
  215. XTo prompt the user:
  216. X.nf
  217. X
  218. X    reply=`MenuPrompt \\`tput lines\\` 0 "Do you want to continue  (y/n) ? "`
  219. X.fi
  220. X
  221. X.SH AUTHOR
  222. XPaul J. Condie       7/90
  223. X.br
  224. X{att,bellcore,sun,ames,pyramid}!pacbell!pcbox!pjc
  225. X
  226. X.SH SEE ALSO
  227. Xmenu(1).
  228. SHAR_EOF
  229. chmod 0644 utilities.d/MenuMsg.d/MenuPrompt.1 || echo "restore of utilities.d/MenuMsg.d/MenuPrompt.1 fails"
  230. echo "x - extracting utilities.d/MenuMsg.d/MenuPrompt.c (Text)"
  231. sed 's/^X//' << 'SHAR_EOF' > utilities.d/MenuMsg.d/MenuPrompt.c &&
  232. X/*
  233. X**  MenuPrompt(1)
  234. X**  ARGS
  235. X**    row and col to dispaly text to
  236. X*/
  237. X
  238. X#include    <curses.h>
  239. X#include    <term.h>
  240. X
  241. Xmain (argc, argv)
  242. X    int    argc;
  243. X    char    *argv[];
  244. X{
  245. X    FILE    *fopen(), *fpout, *fpin;
  246. X    char    *tparm();
  247. X    char    *getenv();
  248. X    char    *tparm();
  249. X    int    _outch();
  250. X    char    *term;
  251. X    int    status;
  252. X    char    *strp;
  253. X    int    row;
  254. X    int    col;
  255. X    char    buf[BUFSIZ];
  256. X    int    ch;
  257. X
  258. X    if ((fpout = fopen ("/dev/tty", "w")) == (FILE *)NULL)
  259. X        exit (1);
  260. X    if ((fpin = fopen ("/dev/tty", "r")) == (FILE *)NULL)
  261. X        exit (1);
  262. X    if ((term = getenv ("TERM")) == (char *)NULL)
  263. X        exit (1);
  264. X    setupterm (term, 1, &status);        /* set-up terminal */
  265. X    if (status != 1)
  266. X        exit (1);
  267. X    if (cursor_address == NULL)        /* we need cursor movement */
  268. X        exit (1);
  269. X    if (strcmp (argv[1], "DONT_CLEAR") == 0)
  270. X    {
  271. X        sscanf (argv[2], "%d", &row);
  272. X        sscanf (argv[3], "%d", &col);
  273. X        fprintf (fpout, "%s%s", tparm (cursor_address, row, col), 
  274. X            argv[4]);
  275. X    }
  276. X    else
  277. X    {
  278. X        sscanf (argv[1], "%d", &row);
  279. X        sscanf (argv[2], "%d", &col);
  280. X        fprintf (fpout, "%s", tparm (cursor_address, row, col));
  281. X        fprintf (fpout, "%s", tparm (clr_eol));
  282. X        fprintf (fpout, "%s%s", tparm (cursor_address, row, col), 
  283. X            argv[3]);
  284. X    }
  285. X
  286. X    strp = buf;
  287. X    while (1)
  288. X    {
  289. X        ch = fgetc (fpin);
  290. X        if ((char)ch == '\n'  ||  (char)ch == '\r')
  291. X            break;
  292. X        *strp = (char)ch;
  293. X        fprintf (fpout, "%c", *strp); fflush (stdout);
  294. X        strp++;
  295. X    }
  296. X    *strp = '\0';
  297. X    printf ("%s", buf);
  298. X
  299. X    fclose (fpin);
  300. X    fclose (fpout);
  301. X}
  302. X/* Paul J. Condie  7-90 */
  303. SHAR_EOF
  304. chmod 0644 utilities.d/MenuMsg.d/MenuPrompt.c || echo "restore of utilities.d/MenuMsg.d/MenuPrompt.c fails"
  305. echo "x - extracting utilities.d/MenuMsg.d/makefile (Text)"
  306. sed 's/^X//' << 'SHAR_EOF' > utilities.d/MenuMsg.d/makefile &&
  307. Xall: MenuMsg MenuPrompt
  308. X
  309. XMenuMsg: MenuMsg.o
  310. X    $(CC) -O MenuMsg.c -lcurses -o MenuMsg
  311. X
  312. XMenuPrompt: MenuPrompt.o
  313. X    $(CC) -O MenuPrompt.c -lcurses -o MenuPrompt
  314. SHAR_EOF
  315. chmod 0644 utilities.d/MenuMsg.d/makefile || echo "restore of utilities.d/MenuMsg.d/makefile fails"
  316. rm -f s2_seq_.tmp
  317. echo "You have unpacked the last part"
  318. exit 0
  319.