ecufinsert.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. #define USE_XON_XOFF
  2. /*+-------------------------------------------------------------------------
  3. ecufinsert.c -- insert file onto comm line
  4. wht@wht.net
  5. Defined functions:
  6. expand_filename(fname, maxlen)
  7. file_insert_clear_xoff()
  8. file_insert_to_line(narg, arg)
  9. --------------------------------------------------------------------------*/
  10. /*+:EDITS:*/
  11. /*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
  12. /*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
  13. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  14. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  15. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  16. /*:05-11-1995-15:55-wht@n4hgf-ck_sigint fools optimizing compilers */
  17. /*:01-12-1995-15:19-wht@n4hgf-apply Andrew Chernov 8-bit clean+FreeBSD patch */
  18. /*:05-04-1994-04:38-wht@n4hgf-ECU release 3.30 */
  19. /*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  20. /*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  21. /*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
  22. /*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  23. /*:07-14-1991-18:18-wht@n4hgf-new ttygets functions */
  24. /*:04-27-1991-01:24-wht@n4hgf-expand_filename was NFG */
  25. /*:03-30-1991-12:40-wht@n4hgf-redi!donovan found q does not restart receiver */
  26. /*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  27. #include "ecu.h"
  28. #include "ecukey.h"
  29. #include "ecutty.h"
  30. extern char kbdintr; /* current input INTR */
  31. extern UINT32 colors_current;
  32. extern UINT32 colors_alert;
  33. extern UINT32 colors_errors;
  34. /*+-------------------------------------------------------------------------
  35. expand_filename(fname) - convert fnames with shell chars
  36. return 0 if no shell characters found
  37. -1 if shell expansion match found
  38. 1 if shell expansion found
  39. --------------------------------------------------------------------------*/
  40. int
  41. expand_filename(fname, maxlen)
  42. char *fname;
  43. int maxlen;
  44. {
  45. char *expcmd;
  46. if (!find_shell_chars(fname))
  47. return (0);
  48. if (expand_wildcard_list(fname, &expcmd))
  49. {
  50. fputs("\r\n", se);
  51. fputs(expcmd, se);
  52. fputs("\r\n", se);
  53. return (-1);
  54. }
  55. strncpy(fname, expcmd, maxlen);
  56. fname[maxlen - 1] = 0;
  57. if (strchr(expcmd, ' '))
  58. {
  59. pputs("\nToo many files:\n");
  60. pputs(expcmd);
  61. pputs("\n");
  62. free(expcmd);
  63. return (-1);
  64. }
  65. strncpy(fname, expcmd, maxlen);
  66. *(fname + maxlen - 1) = 0;
  67. free(expcmd);
  68. return (0);
  69. } /* end of expand_filename */
  70. /*+-------------------------------------------------------------------------
  71. file_insert_clear_xoff()
  72. --------------------------------------------------------------------------*/
  73. void
  74. file_insert_clear_xoff()
  75. {
  76. #ifdef USE_XON_XOFF
  77. #ifdef SAY_CLEARED_XOFF
  78. UINT32 colors_at_entry = colors_current;
  79. setcolor(colors_alert);
  80. fputs("--> local XOFF cleared\r", se);
  81. setcolor(colors_at_entry);
  82. #endif
  83. lclear_xmtr_xoff();
  84. #endif
  85. } /* end of file_insert_clear_xoff */
  86. /*+-------------------------------------------------------------------------
  87. file_insert_to_line(narg,arg)
  88. --------------------------------------------------------------------------*/
  89. file_insert_to_line(narg, arg)
  90. int narg;
  91. char **arg;
  92. {
  93. int itmp;
  94. int rchar;
  95. int old_ttymode = get_ttymode();
  96. long total_chars = 0L;
  97. long total_lines = 0L;
  98. UINT32 colors_at_entry = colors_current;
  99. long timeout_msecs;
  100. FILE *fp;
  101. char file_string[256];
  102. char s256[256];
  103. UINT xmit_mode;
  104. UINT delim;
  105. #ifdef USE_XON_XOFF
  106. int ixon;
  107. int ixoff;
  108. #endif
  109. sigint = 0;
  110. if (narg > 1)
  111. {
  112. strncpy(s256, arg[1], sizeof(s256));
  113. s256[sizeof(s256) - 1] = 0;
  114. }
  115. else
  116. {
  117. ff(se, "\r\n--> File to insert on comm line: ");
  118. ttygets(s256, sizeof(s256), TG_CRLF, &delim, (int *)0);
  119. if ((delim == ESC) || !strlen(s256))
  120. {
  121. ff(se, " --> transmission aborted\r\n");
  122. return (0);
  123. }
  124. }
  125. if ((itmp = expand_filename(s256, sizeof(s256))) < 0)
  126. return (-1);
  127. else if (itmp)
  128. ff(se, "\r\n--> wild card match: %s", s256);
  129. if ((fp = fopen(s256, "r")) == (FILE *) 0)
  130. {
  131. ff(se, "\r\n--> ");
  132. pperror(s256); /* print error if we get one */
  133. return (-1);
  134. }
  135. if (narg > 1)
  136. ff(se, "\r\n");
  137. if (narg > 2)
  138. xmit_mode = *arg[2];
  139. else
  140. {
  141. ASK_OPTION:
  142. ff(se, "(S)ingle line at a time\r\n");
  143. ff(se, "(E)cho pacing\r\n");
  144. ff(se, "(F)ull speed transmission\r\n");
  145. ff(se, "(P)aced transmission (20 msec/char)\r\n");
  146. ff(se, "(Q)uit (or ESC) press a key: ");
  147. xmit_mode = ttygetc(0);
  148. if (xmit_mode > 0x20)
  149. fputs(graphic_char_text(xmit_mode, 0), se);
  150. fputs("\r\n", se);
  151. }
  152. kill_rcvr_process(SIGUSR1);
  153. switch (xmit_mode = to_lower(xmit_mode))
  154. {
  155. case 's':
  156. setcolor(colors_alert);
  157. fputs("--> press SPACE to continue or ESC/'s' to stop\r\n", se);
  158. setcolor(colors_at_entry);
  159. break;
  160. case 'e':
  161. /* fall through */
  162. case 'f':
  163. case 'p':
  164. setcolor(colors_alert);
  165. ff(se, "--> press %s to abort\r\n", graphic_char_text(kbdintr, 0));
  166. setcolor(colors_at_entry);
  167. ttymode(2);
  168. break;
  169. case 'q':
  170. case ESC:
  171. goto INSERT_DONE2;
  172. default:
  173. ring_bell();
  174. fputs("\r\n", se);
  175. goto ASK_OPTION;
  176. }
  177. #ifdef USE_XON_XOFF
  178. lget_xon_xoff(&ixon, &ixoff); /* get current line xon/xoff status */
  179. lxon_xoff(IXON); /* set it for us */
  180. #endif
  181. while (fgets(file_string, sizeof(file_string), fp))
  182. {
  183. int xmit_len = strlen(file_string);
  184. int xmit_cr = xmit_len && (file_string[xmit_len - 1] == NL);
  185. if (xmit_cr)
  186. {
  187. xmit_len--;
  188. file_string[xmit_len] = 0;
  189. }
  190. total_chars += xmit_len;
  191. total_lines++;
  192. /* some destinations, like BBS msg entry, take a blank line to mean
  193. end of message, so do not send completely blank lines */
  194. if (!xmit_len && xmit_cr)
  195. {
  196. lputc(' ');
  197. xmit_len = 1;
  198. }
  199. else if (xmit_mode == 'p')
  200. {
  201. char *cp = file_string;
  202. while (*cp)
  203. {
  204. lputc(*cp++);
  205. Nap(20L);
  206. while (Rdchk(shm->Liofd))
  207. {
  208. rchar = lgetc_xmtr();
  209. process_xmtr_rcvd_char((char)rchar, 1);
  210. }
  211. }
  212. }
  213. else
  214. lputs(file_string);
  215. if (xmit_cr)
  216. {
  217. if (xmit_mode == 'p')
  218. Nap(20L);
  219. lputc('\r');
  220. xmit_len++;
  221. }
  222. if (ck_sigint())
  223. break;
  224. switch (xmit_mode)
  225. {
  226. case 's':
  227. while (1)
  228. {
  229. if (ttyrdchk())
  230. break;
  231. rchar = lgetc_timeout(5 * 1000L);
  232. if (rchar < 0)
  233. file_insert_clear_xoff();
  234. else
  235. process_xmtr_rcvd_char((char)rchar, 1);
  236. if (rchar == 0x0A)
  237. break;
  238. }
  239. rchar = to_lower(ttygetc(1));
  240. if ((rchar == 's') || (rchar == ESC))
  241. goto INSERT_DONE;
  242. break;
  243. case 'e':
  244. timeout_msecs = 5 * 1000L;
  245. while (1)
  246. {
  247. if (ck_sigint())
  248. break;
  249. rchar = lgetc_timeout(timeout_msecs);
  250. if (rchar < 0)
  251. {
  252. if (!xmit_len)
  253. break;
  254. file_insert_clear_xoff();
  255. timeout_msecs = 1 * 1000L;
  256. }
  257. else
  258. {
  259. process_xmtr_rcvd_char((char)rchar, 1);
  260. timeout_msecs = 100L;
  261. if (xmit_len)
  262. xmit_len--;
  263. }
  264. if (rchar == 0x0A)
  265. break;
  266. }
  267. break;
  268. case 'f':
  269. case 'p':
  270. while (Rdchk(shm->Liofd))
  271. {
  272. rchar = lgetc_xmtr();
  273. process_xmtr_rcvd_char((char)rchar, 1);
  274. }
  275. break;
  276. }
  277. if (ck_sigint())
  278. break;
  279. }
  280. INSERT_DONE:
  281. if (ck_sigint())
  282. {
  283. sigint = 0;
  284. setcolor(colors_error);
  285. ff(se, "--> Interrupted\r\n");
  286. setcolor(colors_at_entry);
  287. }
  288. INSERT_DONE2:
  289. fclose(fp);
  290. ttymode(old_ttymode); /* restore old console mode */
  291. sigint = 0; /* reset SIGINT flag */
  292. while (((rchar = lgetc_timeout(200L)) >= 0) && !ck_sigint())
  293. process_xmtr_rcvd_char((char)rchar, 1);
  294. setcolor(colors_success);
  295. ff(se, "\r\n--> done ... sent %ld lines, %ld characters\r\n",
  296. total_lines, total_chars);
  297. setcolor(colors_at_entry);
  298. lclear_xmtr_xoff();
  299. #ifdef USE_XON_XOFF
  300. lxon_xoff(ixon | ixoff); /* restore old line xon/xoff status */
  301. #endif
  302. start_rcvr_process(1);
  303. return (0);
  304. } /* end of file_insert_to_line */
  305. /* vi: set tabstop=4 shiftwidth=4: */
  306. /* end of ecufinsert.c */