ecuicmhelp.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /*+-------------------------------------------------------------------------
  2. ecuicmhelp.c -- help for interactive commands
  3. wht@wht.net
  4. Defined functions:
  5. help_category_menu()
  6. help_choose_cmd()
  7. help_cmd_line_setup(prompt)
  8. help_display_on_stderr(cmd)
  9. help_interactively()
  10. help_right_column()
  11. help_search_pcmds(cmd)
  12. help_show_category(category)
  13. icmd_help(narg, arg)
  14. Whenever the literary German dives into a sentence, that is the
  15. last you are going to see of him until he emerges on the other
  16. side of his Atlantic with his verb in his mouth. -- Mark Twain
  17. --------------------------------------------------------------------------*/
  18. /*+:EDITS:*/
  19. /*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
  20. /*:03-16-1997-02:45-rll@felton.felton.ca.us-Make nice boxes for SCO */
  21. /*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
  22. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  23. /*:07-24-1996-21:37-wht@n4hgf-no more wvline/whline */
  24. /*:11-27-1995-11:50-wht@kepler-if rcvr_ansi_filter off, cr/lf at end of help */
  25. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  26. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  27. /*:01-12-1995-15:19-wht@n4hgf-apply Andrew Chernov 8-bit clean+FreeBSD patch */
  28. /*:05-04-1994-04:38-wht@n4hgf-ECU release 3.30 */
  29. /*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  30. /*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  31. /*:01-11-1992-16:01-wht@n4hgf-bug in help + F1 reverts to cat menu */
  32. /*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh */
  33. /*:08-01-1991-03:52-wht@n4hgf-when editing string, set cursor to end */
  34. /*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
  35. /*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  36. #include "ecucurses.h"
  37. #define OMIT_TERMIO_REFERENCES
  38. #define STDIO_H_INCLUDED
  39. #include "ecu.h"
  40. #define NEED_P_CMD
  41. #include "ecucmd.h"
  42. #include "ecukey.h"
  43. #include "ecuxkey.h"
  44. #include "pc_scr.h"
  45. #define PDAT "ecuhelp.data"
  46. void help_right_column();
  47. static long start_pos[TOKEN_QUAN];
  48. static int start_pos_has_been_read = 0;
  49. static char ecuhelpdata_name[256] = "";
  50. static FILE *fpdat; /* help data file */
  51. static int right_column = 0; /* right column for help_interactively */
  52. static int longest_cmd = 0;
  53. static int longest_descr = 0;
  54. /*+-------------------------------------------------------------------------
  55. help_search_pcmds(cmd)
  56. --------------------------------------------------------------------------*/
  57. P_CMD *
  58. help_search_pcmds(cmd)
  59. char *cmd;
  60. {
  61. P_CMD *cmd_list = icmd_cmds;
  62. while (cmd_list->token != -1)
  63. {
  64. if (minunique(cmd_list->cmd, cmd, cmd_list->min_ch))
  65. break;
  66. cmd_list++;
  67. }
  68. if (cmd_list->token == -1)
  69. return ((P_CMD *) 0);
  70. else
  71. return (cmd_list);
  72. } /* end of help_search_pcmds */
  73. /*+-------------------------------------------------------------------------
  74. help_display_on_stderr(cmd)
  75. --------------------------------------------------------------------------*/
  76. void
  77. help_display_on_stderr(cmd)
  78. char *cmd;
  79. {
  80. int itmp;
  81. P_CMD *pcmd;
  82. char buf[128];
  83. if (!(pcmd = help_search_pcmds(cmd)))
  84. {
  85. ff(se, "'%s' is not a valid command\r\n", cmd);
  86. return;
  87. }
  88. if (!start_pos[pcmd->token])
  89. {
  90. ff(se, "no help available for '%s'\r\n", cmd);
  91. return;
  92. }
  93. fseek(fpdat, start_pos[pcmd->token], 0);
  94. ff(se, "\r\n");
  95. while (fgets(buf, sizeof(buf), fpdat))
  96. {
  97. itmp = strlen(buf);
  98. buf[--itmp] = 0;
  99. if (itmp == 0)
  100. break;
  101. ff(se, "%s\r\n", buf);
  102. }
  103. } /* end of help_display_on_stderr */
  104. /*+-------------------------------------------------------------------------
  105. help_right_column()
  106. --------------------------------------------------------------------------*/
  107. void
  108. help_right_column()
  109. {
  110. int itmp;
  111. P_CMD *pcmd = icmd_cmds;
  112. if (right_column) /* already bee thru here? */
  113. return; /* ... seems so */
  114. while (pcmd->token != -1)
  115. {
  116. if (!*pcmd->descr)
  117. {
  118. pcmd++;
  119. continue;
  120. }
  121. itmp = strlen(pcmd->cmd);
  122. if (itmp > longest_cmd)
  123. longest_cmd = itmp;
  124. itmp = strlen(pcmd->descr);
  125. if (itmp > longest_descr)
  126. longest_descr = itmp;
  127. pcmd++;
  128. }
  129. right_column = 1 + longest_cmd + 2 + longest_descr + 3;
  130. } /* end of help_right_column */
  131. /*+-------------------------------------------------------------------------
  132. help_cmd_line_setup(prompt)
  133. --------------------------------------------------------------------------*/
  134. void
  135. help_cmd_line_setup(prompt)
  136. char *prompt;
  137. {
  138. int icol;
  139. int y;
  140. int x;
  141. touchwin(stdscr);
  142. wmove(stdscr, LINES - 1, 0);
  143. wstandout(stdscr);
  144. waddstr(stdscr, prompt);
  145. getyx(stdscr, y, x);
  146. for (icol = x; icol < COLS - 1; icol++)
  147. waddch(stdscr, ' ');
  148. wmove(stdscr, y, x);
  149. wstandend(stdscr);
  150. wrefresh(stdscr);
  151. } /* end of help_cmd_line_setup */
  152. /*+-------------------------------------------------------------------------
  153. help_choose_cmd() - choose command from category
  154. --------------------------------------------------------------------------*/
  155. char *
  156. help_choose_cmd()
  157. {
  158. int y;
  159. int x;
  160. static char cmd[15];
  161. UINT delim = 0;
  162. int wgpos = -1;
  163. int edit = 0;
  164. help_cmd_line_setup(
  165. "Enter command name (F1 for category menu, ESC to exit): ");
  166. getyx(stdscr, y, x);
  167. wstandout(stdscr);
  168. while ((delim != ESC) && (delim != XF1) && (delim != NL))
  169. {
  170. wingets(stdscr, y, x, cmd, sizeof(cmd) - 1, &delim, edit, &wgpos);
  171. edit = 1;
  172. }
  173. wstandend(stdscr);
  174. if (delim == XF1)
  175. return ("");
  176. else if ((delim == ESC) || (!cmd[0]))
  177. return ((char *)0);
  178. else
  179. return (cmd);
  180. } /* end of help_choose_cmd */
  181. /*+-------------------------------------------------------------------------
  182. help_category_menu() - get user command category choice
  183. --------------------------------------------------------------------------*/
  184. int
  185. help_category_menu()
  186. {
  187. int itmp;
  188. int y;
  189. int x;
  190. char **cpptr;
  191. static UINT keylist[] =
  192. {'g', 'c', 't', 'p', ESC, 0};
  193. static UINT empty_list[] =
  194. {0};
  195. static char *list[] =
  196. {
  197. "g - general commands",
  198. "c - communications-related commands",
  199. "t - transfer-related commands",
  200. "p - procedure-related commands",
  201. "Esc - exit help",
  202. (char *)0
  203. };
  204. tcap_clear_screen();
  205. wclear(stdscr);
  206. wmove(stdscr, 0, 0);
  207. wstandout(stdscr);
  208. waddstr(stdscr, "-- Interactive Command Help Menu ");
  209. getyx(stdscr, y, x);
  210. for (itmp = x; itmp < COLS - 1; itmp++)
  211. waddch(stdscr, '-');
  212. wstandend(stdscr);
  213. itmp = 2;
  214. cpptr = list;
  215. while (*cpptr)
  216. {
  217. wmove(stdscr, itmp++, 4);
  218. waddstr(stdscr, *cpptr++);
  219. }
  220. wmove(stdscr, 9, 4);
  221. waddstr(stdscr, "---- choose a category -------");
  222. return (winget_single(stdscr, empty_list, keylist));
  223. } /* end of help_category_menu */
  224. /*+-------------------------------------------------------------------------
  225. help_show_category(category) - display category and let user choose
  226. --------------------------------------------------------------------------*/
  227. int
  228. help_show_category(category)
  229. int category;
  230. {
  231. int itmp;
  232. P_CMD *pcmd;
  233. int y = 1;
  234. int x = 0;
  235. short cmdclass = 0;
  236. char s80[80];
  237. char *class_descr = "?";
  238. switch (category)
  239. {
  240. case 'g':
  241. cmdclass = ccG;
  242. class_descr = "General";
  243. break;
  244. case 'c':
  245. cmdclass = ccC;
  246. class_descr = "Communications";
  247. break;
  248. case 't':
  249. cmdclass = ccT;
  250. class_descr = "File Transfer";
  251. break;
  252. case 'p':
  253. cmdclass = ccP;
  254. class_descr = "Procedure Related";
  255. break;
  256. }
  257. tcap_clear_screen();
  258. wclear(stdscr);
  259. wmove(stdscr, 0, 0);
  260. wstandout(stdscr);
  261. waddstr(stdscr, "-- ");
  262. waddstr(stdscr, class_descr);
  263. waddstr(stdscr, " Commands ");
  264. getyx(stdscr, y, x);
  265. for (itmp = x; itmp < COLS - 1; itmp++)
  266. waddch(stdscr, '-');
  267. wstandend(stdscr);
  268. pcmd = icmd_cmds;
  269. y = 2;
  270. x = 0;
  271. wmove(stdscr, y, x);
  272. while (pcmd->token != -1)
  273. {
  274. if (!*pcmd->descr || (pcmd->cmdclass != cmdclass))
  275. {
  276. pcmd++;
  277. continue;
  278. }
  279. wmove(stdscr, y, x);
  280. strcpy(s80, pcmd->cmd);
  281. pad_zstr_to_len(s80, longest_cmd + 2);
  282. for (itmp = 0; itmp < pcmd->min_ch; itmp++)
  283. s80[itmp] = to_upper(s80[itmp]);
  284. waddstr(stdscr, s80);
  285. strcpy(s80, pcmd->descr);
  286. if (!x)
  287. pad_zstr_to_len(s80, longest_descr + 1);
  288. waddstr(stdscr, s80);
  289. if (!x)
  290. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  291. waddch(stdscr, sVR);
  292. #else
  293. waddch(stdscr, sVR & 0xFF);
  294. #endif
  295. y++;
  296. if (y >= LINES - 3)
  297. {
  298. y = 2;
  299. x = right_column;
  300. }
  301. pcmd++;
  302. }
  303. wmove(stdscr, LINES - 2, 0);
  304. wstandout(stdscr);
  305. waddstr(stdscr,
  306. "Capitalized portion of listed command sufficient for command recognition");
  307. getyx(stdscr, y, x);
  308. for (itmp = x; itmp < COLS - 1; itmp++)
  309. waddch(stdscr, ' ');
  310. wstandend(stdscr);
  311. return (0);
  312. } /* end of help_show_category */
  313. /*+-------------------------------------------------------------------------
  314. help_interactively()
  315. commands with null descriptions are "undocumented"
  316. --------------------------------------------------------------------------*/
  317. void
  318. help_interactively()
  319. {
  320. char *cp;
  321. int restart_rcvr = need_rcvr_restart();
  322. char category;
  323. kill_rcvr_process(SIGUSR1);
  324. windows_start();
  325. help_right_column();
  326. DISPLAY_MENU:
  327. if ((category = help_category_menu()) != ESC)
  328. {
  329. help_show_category(category);
  330. while (cp = help_choose_cmd())
  331. {
  332. if (!*cp)
  333. goto DISPLAY_MENU;
  334. wmove(stdscr, LINES - 1, 0);
  335. wclrtoeol(stdscr);
  336. wrefresh(stdscr);
  337. help_display_on_stderr(cp);
  338. ff(se, "\r\npress return: ");
  339. ttygetc(1);
  340. help_show_category(category);
  341. }
  342. }
  343. wrefresh(stdscr);
  344. windows_end(1);
  345. if (shm->rcvr_ansi_filter)
  346. redisplay_rcvr_screen();
  347. else
  348. {
  349. tcap_curbotleft();
  350. ff(se, "\r\n");
  351. }
  352. if (restart_rcvr)
  353. start_rcvr_process(0);
  354. } /* end of help_interactively */
  355. /*+-------------------------------------------------------------------------
  356. icmd_help(narg,arg)
  357. --------------------------------------------------------------------------*/
  358. void
  359. icmd_help(narg, arg)
  360. int narg;
  361. char **arg;
  362. {
  363. char *cp;
  364. char *getenv();
  365. ff(se, "\r\n");
  366. if (!ecuhelpdata_name[0])
  367. {
  368. if (!(cp = getenv("ECUHELP")))
  369. sprintf(ecuhelpdata_name, "%s/%s", CFG_EcuLibDir, PDAT);
  370. else
  371. strcpy(ecuhelpdata_name, cp);
  372. }
  373. if (!(fpdat = fopen(ecuhelpdata_name, "r")))
  374. {
  375. pperror(ecuhelpdata_name);
  376. return;
  377. }
  378. if (!start_pos_has_been_read)
  379. {
  380. fread((char *)start_pos, sizeof(long), TOKEN_QUAN, fpdat);
  381. start_pos_has_been_read = 1;
  382. }
  383. if (narg > 1)
  384. help_display_on_stderr(arg[1]);
  385. else
  386. help_interactively();
  387. fclose(fpdat);
  388. } /* end of icmd_help */
  389. /* vi: set tabstop=4 shiftwidth=4: */