ecuphdir.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506
  1. /*+-------------------------------------------------------------------------
  2. ecuphdir.c -- visual phone dialer/directory editor
  3. wht@wht.net
  4. .---[ title ]------------modified-.<-- dirw "top line"
  5. | stand out mode |<-- dirw "header line"
  6. | |<-- scrw first line
  7. | |
  8. | |
  9. | |
  10. | |<-- scrw last line
  11. +---------------------------------+<-- dirw bottom separator line
  12. | |<-- dirw extra cmd prompt line
  13. | stand out mode |<-- dirw "cmd line"
  14. `---------------------------------'<-- dirw bottom line
  15. 000000000011111111112222222222333333333344444444445555555555666666666671
  16. 012345678901234567890123456789012345678901234567890123456789012345678901
  17. 0.--[ entry nnnnn ]-----------------------------------------------------.
  18. 1| |
  19. 2| telephone number ___________________ |
  20. 3| device __________ |
  21. 4| bit rate _____ |
  22. 5| parity _ |
  23. 6| description ________________________________________ |
  24. 7| debug level _ (dialer -x value 0-9) |
  25. 8| DCD watch _ |
  26. 9| RTS/CTS flow ctl _ (0=off,7=best,n=no change) |
  27. 10| |
  28. -2| <prompt> |
  29. -1| <control key description> |
  30. n`----------------------------------------------------------------------'
  31. Defined functions:
  32. check_curr_pde()
  33. dirw_bot_msg(msg)
  34. dirw_cmd_line_setup(prompt1, prompt2)
  35. dirw_display()
  36. dirw_display_config()
  37. dirw_display_phonedir_name()
  38. dirw_get_cmd()
  39. field_colon_protect(fieldstr)
  40. field_colon_restore(fieldstr)
  41. phdir_add_or_edit(tpde, edit)
  42. phdir_add_or_edit_read(prompt, y, buf, bufmax, delim)
  43. phdir_cmd_add(tpde)
  44. phdir_cmd_change_dir()
  45. phdir_cmd_down()
  46. phdir_cmd_find()
  47. phdir_cmd_mark(tpde)
  48. phdir_cmd_pgdn()
  49. phdir_cmd_pgup()
  50. phdir_cmd_remove()
  51. phdir_cmd_remove_oops()
  52. phdir_cmd_save()
  53. phdir_cmd_set_wait()
  54. phdir_cmd_unmark(tpde)
  55. phdir_cmd_unmark_all()
  56. phdir_cmd_up()
  57. phdir_dial_cycle()
  58. phdir_display(line, tpde, stand_out)
  59. phdir_display_logical(line, tpde, stand_out)
  60. phdir_list_add(tpde)
  61. phdir_list_erase()
  62. phdir_list_read()
  63. phdir_list_remove(tpde)
  64. phdir_list_save_if_dirty()
  65. phdir_list_search(logical, exact_flag)
  66. phdir_list_set_dirty(flag)
  67. phdir_manager()
  68. scrw_fill(tpde, curr_pde_line)
  69. scrw_fill_at(line_num, tpde, curr_pde_line)
  70. want_pd_create(name)
  71. --------------------------------------------------------------------------*/
  72. /*+:EDITS:*/
  73. /*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
  74. /*:11-16-1997-22:15-wht@kepler-regexp_compile changed shape */
  75. /*:03-16-1997-03:27-rll@felton.felton.ca.us-Fix boxes for curses under SCO */
  76. /*:02-09-1997-19:37-wht@yuriatin-mv find_procedure defn to ecu.h */
  77. /*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
  78. /*:09-16-1996-05:21-wht@yuriatin-protect colons in phdir entries */
  79. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  80. /*:09-09-1996-03:16-wht@yuriatin-CFG_TelnetOption sizing */
  81. /*:08-22-1996-15:27-wht@fep-better add_or_edit abort on ESC */
  82. /*:08-20-1996-12:39-wht@kepler-locale/ctype fixes from ache@nagual.ru */
  83. /*:07-24-1996-21:37-wht@n4hgf-no more wvline/whline */
  84. /*:12-06-1995-13:30-wht@n4hgf-termecu w/errno -1 consideration */
  85. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  86. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  87. /*:10-14-1995-23:17-wht@kepler-widen addw for baud string under Linux/BSD */
  88. /*:10-14-1995-16:29-wht@kepler-use valid_baud_string */
  89. /*:09-17-1995-16:35-wht@kepler-dcdw==1 does not work under Linux */
  90. /*:05-11-1995-15:55-wht@n4hgf-ck_sigint fools optimizing compilers */
  91. /*:05-11-1995-15:00-wht@n4hgf-^F and ^B vi-isms for page down and up */
  92. /*:03-12-1995-02:28-wht@kepler-properly mark dirty on any edited existing pde */
  93. /*:03-12-1995-01:54-wht@kepler-prevent clobber of reentered field during add */
  94. /*:03-12-1995-01:03-wht@kepler-use ECU_MAXPN and clean up get_curr_dir */
  95. /*:01-12-1995-15:19-wht@n4hgf-apply Andrew Chernov 8-bit clean+FreeBSD patch */
  96. /*:05-04-1994-04:38-wht@n4hgf-ECU release 3.30 */
  97. /*:11-17-1993-10:58-wht@n4hgf-ask for 'tty1a' not '1a' in case 1 */
  98. /*:08-17-1993-14:00-wht@n4hgf-with new wingets, skip standout in phdir edit */
  99. /*:05-29-1993-20:21-wht@n4hgf-change linst_err_text to LINST_text */
  100. /*:03-01-1993-03:28-wht@n4hgf-add PgUP and PgDn */
  101. /*:01-11-1993-16:05-wht@n4hgf-improve error checking + bell on error */
  102. /*:12-04-1992-20:43-wht@n4hgf-fix logic error test */
  103. /*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  104. /*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  105. /*:05-17-1992-18:29-wht@n4hgf-pde add now cycles thru fields til END */
  106. /*:11-28-1991-14:32-wht@n4hgf-add dcdwatch option */
  107. /*:11-20-1991-05:19-wht@n4hgf-improve "Any" line handling on add or edit */
  108. /*:08-28-1991-15:15-wht@n4hgf2-fix bad structure in phdir_add_or_edit_read */
  109. /*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh */
  110. /*:08-15-1991-18:13-wht@n4hgf-do not allow edit of non-existent entry */
  111. /*:08-11-1991-19:56-wht@n4hgf-soup up tty name for ISC vs. SCO */
  112. /*:08-07-1991-13:48-root@n4hgf-w subcommand was not asking both questions */
  113. /*:08-01-1991-03:52-wht@n4hgf-when editing string, set cursor to end */
  114. /*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
  115. /*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  116. /*:07-12-1991-15:37-wht@n4hgf-fix core dump when creating phone from setup */
  117. /*:06-09-1991-16:54-jjb-want_pd_create sneak path when not in curses */
  118. /*:06-02-1991-19:43-wht@n4hgf-add dial debug level */
  119. /*:06-02-1991-17:29-wht@n4hgf-move hdb_choose_Any to hdbintf.c */
  120. /*:06-01-1991-23:53-wht@n4hgf-use PDE_..._LEN identifiers */
  121. /*:04-03-1991-14:47-wht@n4hgf-must refresh both windows in terminfo curses */
  122. /*:03-18-1991-21:39-wht@n4hgf-add wrefresh of scrw in up/down */
  123. /*:02-05-1991-14:51-wht@n4hgf-calloc PDE instead of malloc */
  124. /*:01-09-1991-22:31-wht@n4hgf-ISC port */
  125. /*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  126. #include "ecucurses.h"
  127. #define STDIO_H_INCLUDED
  128. #define OMIT_TERMIO_REFERENCES
  129. #include "ecu.h"
  130. #include "pc_scr.h"
  131. #include "ecupde.h"
  132. #include "ecukey.h"
  133. #include "ecuxkey.h"
  134. #include "esd.h"
  135. #include "var.h"
  136. WINDOW *window_create();
  137. void dirw_bot_msg();
  138. void dirw_display_phonedir_name();
  139. void dirw_cmd_line_setup();
  140. /* window definitions */
  141. #define DIRW_LINES (LINES - 1)
  142. #define DIRW_COLS 80
  143. #define DIRW_TOP_LINES 2
  144. #define DIRW_BOT_LINES 4
  145. #define DIRW_CMD_LINE (DIRW_LINES - 2)
  146. #define SCRW_LINES (DIRW_LINES - DIRW_TOP_LINES - DIRW_BOT_LINES)
  147. #define SCRW_COLS (DIRW_COLS)
  148. #define SCRW_TLY (DIRW_TOP_LINES)
  149. #define SCRW_TLX 0
  150. #define PDE_ITEM_COUNT 8
  151. #define ADDW_LINES (PDE_ITEM_COUNT + 6)
  152. #ifdef CFG_TelnetOption
  153. #define ADDW_COLS 75
  154. #else
  155. #define ADDW_COLS 65
  156. #endif
  157. #define ADDW_TLY (SCRW_TLY + 1)
  158. #define ADDW_TLX 4
  159. extern int errno;
  160. extern int windows_active;
  161. extern char errmsg[];
  162. extern char kbdintr;
  163. extern char phonedir_name[]; /* phone directory name */
  164. extern char *phonedir_trigger;
  165. extern char *valid_baud_string;
  166. UINT ttygetc();
  167. WINDOW *dirw = 0;
  168. WINDOW *scrw = 0;
  169. WINDOW *addw = 0;
  170. PDE *phdir_list_head = 0; /* pointer to first pde in linked list */
  171. PDE *curr_pde = 0; /* current pde */
  172. PDE *remove_pde = 0; /* if non-zero, pde just removed */
  173. int remove_dirty_flag; /* phdir_list_dirty at remove time */
  174. int phdir_list_quan = 0; /* count of items in list now */
  175. int phdir_list_dirty = 0; /* phdir_list modified but not saved */
  176. int pde_marked_for_redial_count = 0;
  177. int scrw_curr_pde_line; /* scrw line curr_pde is on */
  178. int phonedir_name_x; /* position for phonedir name on screen */
  179. #define NAP_DECISEC_SINGLE_MIN 10
  180. #define NAP_DECISEC_MULTIPLE_MIN 10
  181. int nap_decisec_single = 150;
  182. int nap_decisec_multiple = 50;
  183. #if LOGICAL_LEN > 20
  184. #define LOGICAL_DISP_LEN 20
  185. #else
  186. #define LOGICAL_DISP_LEN LOGICAL_LEN
  187. #endif
  188. /*+-------------------------------------------------------------------------
  189. phdir_list_erase()
  190. --------------------------------------------------------------------------*/
  191. void
  192. phdir_list_erase()
  193. {
  194. PDE *pde = phdir_list_head;
  195. PDE *next;
  196. while (pde)
  197. {
  198. next = pde->next;
  199. free((char *)pde);
  200. pde = next;
  201. }
  202. phdir_list_head = (PDE *) 0;
  203. phdir_list_quan = 0;
  204. curr_pde = (PDE *) 0;
  205. remove_pde = (PDE *) 0;
  206. pde_marked_for_redial_count = 0;
  207. } /* end of phdir_list_erase */
  208. /*+-------------------------------------------------------------------------
  209. phdir_list_set_dirty(flag)
  210. 0: clean, 1 dirty, -1 do not modify;update screen only
  211. --------------------------------------------------------------------------*/
  212. void
  213. phdir_list_set_dirty(flag)
  214. int flag;
  215. {
  216. int itmp;
  217. char *modified = " modified ";
  218. if (flag != phdir_list_dirty)
  219. {
  220. if (flag != -1)
  221. phdir_list_dirty = flag;
  222. wmove(dirw, 0, DIRW_COLS - 14);
  223. if (phdir_list_dirty)
  224. {
  225. wstandout(dirw);
  226. waddstr(dirw, modified);
  227. wstandend(dirw);
  228. }
  229. else
  230. {
  231. itmp = strlen(modified);
  232. while (itmp--)
  233. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  234. waddch(dirw, sHR);
  235. #else
  236. waddch(dirw, sHR & 0xFF);
  237. #endif
  238. }
  239. wrefresh(dirw);
  240. }
  241. } /* end of phdir_list_set_dirty */
  242. /*+-------------------------------------------------------------------------
  243. phdir_list_add(tpde) -- add to linked list
  244. --------------------------------------------------------------------------*/
  245. void
  246. phdir_list_add(tpde)
  247. PDE *tpde;
  248. {
  249. PDE *this = tpde;
  250. PDE *prev;
  251. PDE *next;
  252. /* if empty, init list with this one and quit */
  253. if (phdir_list_head == (PDE *) 0)
  254. {
  255. phdir_list_head = this;
  256. this->prev = (PDE *) 0;
  257. this->next = (PDE *) 0;
  258. phdir_list_quan++;
  259. return;
  260. }
  261. /* list not empty */
  262. prev = (PDE *) 0; /* no previous yet */
  263. next = phdir_list_head; /* init next to top of list */
  264. while (strcmp(next->logical, this->logical) < 0)
  265. {
  266. prev = next;
  267. next = prev->next;
  268. if (next == (PDE *) 0)
  269. break;
  270. }
  271. if (prev) /* if non-zero, we will not update the list
  272. * head */
  273. {
  274. /*
  275. * 'this' is to be added to a non-empty list
  276. */
  277. this->next = prev->next;
  278. this->prev = prev;
  279. prev->next = this;
  280. if (next)
  281. next->prev = this;
  282. }
  283. else
  284. {
  285. /*
  286. * 'this' is to become the new list head (1st element)
  287. */
  288. this->next = next;
  289. this->prev = (PDE *) 0;
  290. if (next)
  291. next->prev = this;
  292. phdir_list_head = this;
  293. }
  294. phdir_list_quan++;
  295. } /* end of pde_add */
  296. /*+-------------------------------------------------------------------------
  297. phdir_list_remove(tpde) -- remove from linked list
  298. --------------------------------------------------------------------------*/
  299. void
  300. phdir_list_remove(tpde)
  301. PDE *tpde;
  302. {
  303. PDE *prev;
  304. PDE *next;
  305. prev = (PDE *) 0; /* there is no previous now */
  306. if ((next = phdir_list_head) == (PDE *) 0) /* if empty list */
  307. return;
  308. while (next != tpde)
  309. {
  310. prev = next;
  311. next = prev->next;
  312. if (next == (PDE *) 0)
  313. return;
  314. }
  315. /* take care of "current pde" */
  316. if (tpde == curr_pde)
  317. {
  318. if (tpde->next)
  319. curr_pde = tpde->next;
  320. else if (tpde->prev)
  321. curr_pde = tpde->prev;
  322. else
  323. curr_pde = (PDE *) 0;
  324. }
  325. /* marked? */
  326. if (tpde->redial)
  327. {
  328. tpde->redial = 0;
  329. pde_marked_for_redial_count--;
  330. }
  331. /* unlink */
  332. if (prev) /* if non-zero, we will not update the list
  333. * head */
  334. {
  335. prev->next = tpde->next;
  336. if (tpde->next)
  337. (tpde->next)->prev = prev;
  338. }
  339. else
  340. {
  341. phdir_list_head = tpde->next;
  342. if (tpde->next)
  343. (tpde->next)->prev = (PDE *) 0;
  344. }
  345. tpde->next = (PDE *) 0;
  346. tpde->prev = (PDE *) 0;
  347. phdir_list_quan--;
  348. } /* end of phdir_list_remove */
  349. /*+-----------------------------------------------------------------------
  350. PDE *phdir_list_search(logical,exact_flag)
  351. ------------------------------------------------------------------------*/
  352. PDE *
  353. phdir_list_search(logical, exact_flag)
  354. char *logical;
  355. int exact_flag;
  356. {
  357. PDE *tpde;
  358. if (!phdir_list_quan)
  359. {
  360. if (phdir_list_read())
  361. return ((PDE *) 0);
  362. }
  363. if (!logical || !*logical)
  364. return ((PDE *) 0);
  365. tpde = phdir_list_head;
  366. while (tpde)
  367. {
  368. /* only first few chars necessary for match with ulcmpb */
  369. if (exact_flag)
  370. {
  371. if (strcmp(tpde->logical, logical) == 0)
  372. return (tpde);
  373. }
  374. else
  375. {
  376. if (ulcmpb(tpde->logical, logical) < 0)
  377. return (tpde);
  378. }
  379. tpde = tpde->next;
  380. }
  381. if (!tpde)
  382. sprintf(errmsg, "'%s' not found", logical);
  383. return (tpde);
  384. } /* end of phdir_list_search */
  385. /*+-------------------------------------------------------------------------
  386. want_pd_create(name)
  387. --------------------------------------------------------------------------*/
  388. int
  389. want_pd_create(name)
  390. char *name;
  391. {
  392. UINT uctmp = XF_not_yet;
  393. if (!dirw)
  394. return (1);
  395. #ifdef COMPILER_BUG_FIXED
  396. dirw_bot_msg("type 'y' or 'n'");
  397. while (uctmp == XF_not_yet)
  398. {
  399. ring_bell();
  400. dirw_cmd_line_setup(name, "does not exist: create?");
  401. uctmp = to_lower(ttygetc(0));
  402. switch (uctmp)
  403. {
  404. case 'y':
  405. uctmp = 1;
  406. break;
  407. case 'n':
  408. uctmp = 0;
  409. break;
  410. default:
  411. uctmp = XF_not_yet;
  412. break;
  413. }
  414. }
  415. dirw_bot_msg("");
  416. return ((int)uctmp);
  417. #else
  418. KROCK:
  419. dirw_bot_msg("type 'y' or 'n'");
  420. ring_bell();
  421. dirw_cmd_line_setup(name, "does not exist: create?");
  422. uctmp = to_lower(ttygetc(0));
  423. dirw_bot_msg("");
  424. switch (uctmp)
  425. {
  426. case 'y':
  427. return (1);
  428. case 'n':
  429. return (0);
  430. }
  431. goto KROCK;
  432. #endif
  433. } /* end of want_pd_create */
  434. /*+-------------------------------------------------------------------------
  435. dirw_display_phonedir_name()
  436. --------------------------------------------------------------------------*/
  437. void
  438. dirw_display_phonedir_name()
  439. {
  440. int itmp, x;
  441. char s80[80];
  442. if (!dirw || !phonedir_name[0])
  443. return;
  444. wmove(dirw, 0, phonedir_name_x);
  445. waddch(dirw, ' ');
  446. strncpy(s80, phonedir_name, itmp = DIRW_COLS - phonedir_name_x - 5);
  447. s80[itmp] = 0;
  448. waddstr(dirw, s80);
  449. waddch(dirw, ' ');
  450. getyx(dirw, itmp, x);
  451. while (x < DIRW_COLS - 1)
  452. {
  453. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  454. waddch(dirw, sHR);
  455. #else
  456. waddch(dirw, sHR & 0xFF);
  457. #endif
  458. x++;
  459. }
  460. } /* end of dirw_display_phonedir_name */
  461. /*+-------------------------------------------------------------------------
  462. dirw_display_config()
  463. --------------------------------------------------------------------------*/
  464. void
  465. dirw_display_config()
  466. {
  467. int y, x;
  468. if (!dirw)
  469. return;
  470. getyx(dirw, y, x);
  471. while (x++ < (DIRW_COLS - 1))
  472. waddch(dirw, sHR);
  473. waddch(dirw, sRT);
  474. if (pde_marked_for_redial_count)
  475. {
  476. wmove(dirw, DIRW_LINES - DIRW_BOT_LINES, 2);
  477. wstandout(dirw);
  478. wprintw(dirw, " REDIAL CYCLE wait: single=%d multiple=%d ",
  479. nap_decisec_single / 10, nap_decisec_multiple / 10);
  480. wmove(dirw, DIRW_LINES - DIRW_BOT_LINES, 56);
  481. wprintw(dirw, " %2d marked entr%s ",
  482. pde_marked_for_redial_count,
  483. (pde_marked_for_redial_count == 1) ? "y" : "ies");
  484. wstandend(dirw);
  485. }
  486. } /* end of dirw_display_config */
  487. /*+-----------------------------------------------------------------------
  488. dirw_display()
  489. 00000000001111111111222222222233333333334444444444555555555566666666667777777777
  490. 01234567890123456789012345678901234567890123456789012345678901234567890123456789
  491. | entry name | telephone number | tty | baud P | description |
  492. | 0123456789 | 0123456789012345 | 01 | baud P | 01234567890123456789012345678 |
  493. ------------------------------------------------------------------------*/
  494. void
  495. dirw_display()
  496. {
  497. if (!dirw)
  498. return;
  499. wmove(dirw, 1, 1);
  500. wstandout(dirw);
  501. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  502. waddstr(dirw,
  503. " entry name | telephone number | tty | baud P | description "
  504. );
  505. #else
  506. waddstr(dirw, " entry name ");
  507. #ifdef __FreeBSD__
  508. waddch(dirw, sVR);
  509. #else
  510. waddch(dirw, (unsigned)sVR);
  511. #endif
  512. waddstr(dirw, " telephone number ");
  513. #ifdef __FreeBSD__
  514. waddch(dirw, sVR);
  515. #else
  516. waddch(dirw, (unsigned)sVR);
  517. #endif
  518. waddstr(dirw, " tty ");
  519. #ifdef __FreeBSD__
  520. waddch(dirw, sVR);
  521. #else
  522. waddch(dirw, (unsigned)sVR);
  523. #endif
  524. waddstr(dirw, " baud P ");
  525. #ifdef __FreeBSD__
  526. waddch(dirw, sVR);
  527. #else
  528. waddch(dirw, (unsigned)sVR);
  529. #endif
  530. waddstr(dirw, " description ");
  531. #endif
  532. wstandend(dirw);
  533. dirw_display_phonedir_name();
  534. dirw_display_config();
  535. wrefresh(dirw);
  536. } /* end of dirw_display */
  537. /*+-------------------------------------------------------------------------
  538. dirw_bot_msg(msg)
  539. --------------------------------------------------------------------------*/
  540. void
  541. dirw_bot_msg(msg)
  542. char *msg;
  543. {
  544. int itmp;
  545. int itmp2;
  546. static int last_msglen = 0;
  547. #define DIRW_BOT_LINE_TLX 2
  548. #define DIRW_BOT_LINE_MAX_MSGLEN (DIRW_COLS - DIRW_BOT_LINE_TLX - 8)
  549. char msg2[80];
  550. if (!dirw || (!last_msglen && !strlen(msg)))
  551. return;
  552. wmove(dirw, DIRW_LINES - 1, DIRW_BOT_LINE_TLX);
  553. if ((itmp = strlen(msg)) == 0)
  554. {
  555. itmp2 = last_msglen + 2;
  556. for (itmp = 0; itmp < itmp2; itmp++)
  557. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  558. waddch(dirw, sHR);
  559. #else
  560. waddch(dirw, sHR & 0xFF);
  561. #endif
  562. last_msglen = 0;
  563. }
  564. else
  565. {
  566. waddch(dirw, ' ');
  567. if (itmp > DIRW_BOT_LINE_MAX_MSGLEN)
  568. {
  569. strncpy(msg2, msg, DIRW_BOT_LINE_MAX_MSGLEN + 1);
  570. msg2[DIRW_BOT_LINE_MAX_MSGLEN + 1] = 0;
  571. waddstr(dirw, msg2);
  572. itmp = strlen(msg2);
  573. }
  574. else
  575. {
  576. waddstr(dirw, msg);
  577. itmp = strlen(msg);
  578. }
  579. waddch(dirw, ' ');
  580. if ((itmp2 = last_msglen - itmp) > 0)
  581. {
  582. while (itmp2--)
  583. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  584. waddch(dirw, sHR);
  585. #else
  586. waddch(dirw, sHR & 0xFF);
  587. #endif
  588. }
  589. last_msglen = itmp; /* remember last message length */
  590. }
  591. wrefresh(dirw);
  592. } /* end of dirw_bot_msg */
  593. /*+-------------------------------------------------------------------------
  594. phdir_display_logical(line,tpde,stand_out)
  595. --------------------------------------------------------------------------*/
  596. void
  597. phdir_display_logical(line, tpde, stand_out)
  598. int line;
  599. PDE *tpde;
  600. int stand_out;
  601. {
  602. wmove(scrw, line, 0);
  603. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  604. waddch(scrw, sVR);
  605. #else
  606. waddch(scrw, sVR & 0xFF);
  607. #endif
  608. if (tpde->redial)
  609. {
  610. wstandout(scrw);
  611. waddch(scrw, '>');
  612. wstandend(scrw);
  613. }
  614. else
  615. waddch(scrw, ' ');
  616. if (stand_out)
  617. wstandout(scrw);
  618. wprintw(scrw, "%-10.10s", tpde->logical);
  619. if (stand_out)
  620. wstandend(scrw);
  621. } /* end of phdir_display_logical */
  622. /*+-----------------------------------------------------------------------
  623. phdir_display(win,line,tpde,stand_out)
  624. 00000000001111111111222222222233333333334444444444555555555566666666667777777777
  625. 01234567890123456789012345678901234567890123456789012345678901234567890123456789
  626. | entry name | telephone number | tty | baud P | description |
  627. | 0123456789 | 0123456789012345 | 01 | baud P | 01234567890123456789012345678 |
  628. --------------------------------------------------------------------------*/
  629. phdir_display(line, tpde, stand_out)
  630. int line;
  631. PDE *tpde;
  632. int stand_out;
  633. {
  634. phdir_display_logical(line, tpde, stand_out);
  635. waddch(scrw, ' ');
  636. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  637. waddch(scrw, sVR);
  638. waddch(scrw, ' ');
  639. #else
  640. waddch(scrw, (unsigned)sVR);
  641. waddch(scrw, ' ');
  642. #endif
  643. wprintw(scrw, "%-16.16s ", tpde->telno);
  644. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  645. waddch(scrw, sVR);
  646. #else
  647. waddch(scrw, (unsigned)sVR);
  648. #endif
  649. if (tpde->tty[0])
  650. wprintw(scrw, "%-5.5s", tpde->tty);
  651. else
  652. waddstr(scrw, "Any ");
  653. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  654. waddch(scrw, sVR);
  655. #else
  656. waddch(scrw, (unsigned)sVR);
  657. #endif
  658. wprintw(scrw, "%6u %c ", tpde->baud,
  659. (tpde->parity) ? to_upper(tpde->parity) : 'N');
  660. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  661. waddch(scrw, sVR);
  662. #else
  663. waddch(scrw, (unsigned)sVR);
  664. #endif
  665. wprintw(scrw, " %-28.28s ", tpde->descr);
  666. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  667. waddch(scrw, sVR);
  668. #else
  669. waddch(scrw, (unsigned)sVR);
  670. #endif
  671. return (0);
  672. } /* end of phdir_display */
  673. /*+-----------------------------------------------------------------------
  674. scrw_fill(first_pde,curr_pde_line)
  675. ------------------------------------------------------------------------*/
  676. void
  677. scrw_fill(tpde, curr_pde_line)
  678. PDE *tpde;
  679. int *curr_pde_line;
  680. {
  681. int line;
  682. int is_curr_pde;
  683. *curr_pde_line = -1;
  684. for (line = 0; line < SCRW_LINES; line++)
  685. {
  686. if (tpde)
  687. {
  688. if (is_curr_pde = (tpde == curr_pde))
  689. *curr_pde_line = line;
  690. phdir_display(line, tpde, is_curr_pde);
  691. tpde = tpde->next;
  692. }
  693. else
  694. {
  695. wmove(scrw, line, 0);
  696. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  697. waddch(scrw, sVR);
  698. #else
  699. waddch(scrw, (unsigned)sVR & 0xFF);
  700. #endif
  701. wclrtoeol(scrw);
  702. wmove(scrw, line, SCRW_COLS - 1);
  703. #if defined(SVR4) || defined(SCO32v4) || defined(SCO32v5)
  704. waddch(scrw, sVR);
  705. #else
  706. waddch(scrw, sVR & 0xFF);
  707. #endif
  708. }
  709. }
  710. wrefresh(scrw);
  711. } /* end of scrw_fill */
  712. /*+-------------------------------------------------------------------------
  713. scrw_fill_at(line_num,first_pde,curr_pde_line)
  714. --------------------------------------------------------------------------*/
  715. void
  716. scrw_fill_at(line_num, tpde, curr_pde_line)
  717. int line_num;
  718. PDE *tpde;
  719. int *curr_pde_line;
  720. {
  721. int itmp;
  722. if (!tpde)
  723. {
  724. scrw_fill(tpde, curr_pde_line);
  725. return;
  726. }
  727. for (itmp = 0; itmp < line_num; itmp++)
  728. {
  729. if (!tpde->prev)
  730. break;
  731. tpde = tpde->prev;
  732. }
  733. scrw_fill(tpde, curr_pde_line);
  734. } /* end of scrw_fill_at */
  735. /*+-------------------------------------------------------------------------
  736. dirw_cmd_line_setup(prompt1,prompt2)
  737. --------------------------------------------------------------------------*/
  738. void
  739. dirw_cmd_line_setup(prompt1, prompt2)
  740. char *prompt1;
  741. char *prompt2;
  742. {
  743. int icol;
  744. int y;
  745. int x;
  746. char *cp;
  747. int standout_mode;
  748. wmove(dirw, DIRW_CMD_LINE - 1, 1);
  749. wstandend(dirw);
  750. standout_mode = 0;
  751. waddch(dirw, ' ');
  752. cp = prompt1;
  753. while (*cp)
  754. {
  755. if (*cp == '~')
  756. {
  757. if (standout_mode)
  758. wstandend(dirw);
  759. else
  760. wstandout(dirw);
  761. standout_mode = !standout_mode;
  762. cp++;
  763. }
  764. else
  765. waddch(dirw, *cp++);
  766. }
  767. wstandend(dirw);
  768. standout_mode = 0;
  769. waddch(dirw, ' ');
  770. getyx(dirw, y, x);
  771. for (icol = x; icol < DIRW_COLS - 1; icol++)
  772. waddch(dirw, ' ');
  773. wmove(dirw, DIRW_CMD_LINE, 1);
  774. waddch(dirw, ' ');
  775. cp = prompt2;
  776. while (*cp)
  777. {
  778. if (*cp == '~')
  779. {
  780. if (standout_mode)
  781. wstandend(dirw);
  782. else
  783. wstandout(dirw);
  784. standout_mode = !standout_mode;
  785. cp++;
  786. }
  787. else
  788. waddch(dirw, *cp++);
  789. }
  790. wstandend(dirw);
  791. waddch(dirw, ' ');
  792. getyx(dirw, y, x);
  793. for (icol = x; icol < DIRW_COLS - 1; icol++)
  794. waddch(dirw, ' ');
  795. wmove(dirw, y, x);
  796. wrefresh(scrw);
  797. wrefresh(dirw);
  798. } /* end of dirw_cmd_line_setup */
  799. /*+-------------------------------------------------------------------------
  800. dirw_get_cmd()
  801. --------------------------------------------------------------------------*/
  802. UINT
  803. dirw_get_cmd()
  804. {
  805. UINT cmd;
  806. char setupline1[128]; /* yetch ... avoid source line > 80 chars */
  807. char setupline2[128];
  808. char *setupline1_1 =
  809. "~d~own ~u~p ~PgDn~ ~PgUp~ ~e~dit ~a~dd ~r~emove ~s~ave ~f~ind ";
  810. char *setupline1_2 =
  811. "~c~hange dial dir";
  812. char *setupline2_1 =
  813. "redial: ~m~ark un~M~ark ~U~nmark all ~w~ait between dial ";
  814. char *setupline2_2 =
  815. "~ENTER~:dial ~ESC,q~uit";
  816. strcpy(setupline1, setupline1_1);
  817. strcat(setupline1, setupline1_2);
  818. strcpy(setupline2, setupline2_1);
  819. strcat(setupline2, setupline2_2);
  820. dirw_cmd_line_setup(setupline1, setupline2);
  821. cmd = ttygetc(1);
  822. dirw_bot_msg("");
  823. return (cmd);
  824. } /* end of dirw_get_cmd */
  825. /*+-------------------------------------------------------------------------
  826. field_colon_protect(fieldstr) - change field contents: comma to tilde
  827. --------------------------------------------------------------------------*/
  828. void
  829. field_colon_protect(fieldstr)
  830. char *fieldstr;
  831. {
  832. while (*fieldstr) /* cannot have '~' in description */
  833. {
  834. if (*fieldstr == '~')
  835. *fieldstr = '-';
  836. else if (*fieldstr == ':') /* cvt colon to tilde */
  837. *fieldstr = '~';
  838. fieldstr++;
  839. }
  840. } /* end of field_colon_protect */
  841. /*+-------------------------------------------------------------------------
  842. field_colon_restore(fieldstr) - change field contents: comma to tilde
  843. --------------------------------------------------------------------------*/
  844. void
  845. field_colon_restore(fieldstr)
  846. char *fieldstr;
  847. {
  848. while (*fieldstr) /* cannot have ':' in description */
  849. { /* should have picked another separator, ... */
  850. if (*fieldstr == '~')/* ... but compatibility is important */
  851. *fieldstr = ':';
  852. fieldstr++;
  853. }
  854. } /* end of field_colon_restore */
  855. /*+-------------------------------------------------------------------------
  856. phdir_cmd_save()
  857. --------------------------------------------------------------------------*/
  858. void
  859. phdir_cmd_save()
  860. {
  861. FILE *fpold;
  862. FILE *fpnew;
  863. PDE *tpde;
  864. char *cp;
  865. char phonedir_ntmp[256]; /* temp phone directory name */
  866. char iobuf[128];
  867. int count = 0;
  868. if (!phdir_list_dirty)
  869. {
  870. dirw_bot_msg("directory has not been modified");
  871. return;
  872. }
  873. strcpy(phonedir_ntmp, phonedir_name);
  874. strcat(phonedir_ntmp, ".t");
  875. if (!(fpnew = fopen(phonedir_ntmp, "w"))) /* open old file */
  876. {
  877. sprintf(iobuf, "cannot open %s", phonedir_ntmp);
  878. dirw_bot_msg(iobuf);
  879. ring_bell();
  880. return;
  881. }
  882. /* write trigger */
  883. fputs(phonedir_trigger, fpnew);
  884. /* retain commented entries */
  885. if ((fpold = fopen(phonedir_name, "r"))) /* open old file */
  886. {
  887. while (fgets(iobuf, sizeof(iobuf), fpold))
  888. {
  889. if ((iobuf[0] == '#') && strcmp(iobuf, phonedir_trigger))
  890. fputs(iobuf, fpnew);
  891. }
  892. fclose(fpold);
  893. }
  894. /* write new entries */
  895. tpde = phdir_list_head;
  896. while (tpde)
  897. {
  898. cp = tpde->descr;
  899. while (*cp) /* cannot have ':' in description */
  900. { /* should have picked another separator, ... */
  901. if (*cp == ':') /* ... but compatibility is important */
  902. *cp = '-';
  903. cp++;
  904. }
  905. sprintf(iobuf, "%d", count + 1);
  906. dirw_bot_msg(iobuf);
  907. field_colon_protect(tpde->logical);
  908. field_colon_protect(tpde->telno);
  909. field_colon_protect(tpde->tty);
  910. field_colon_protect(tpde->descr);
  911. sprintf(iobuf, "%s:%s:%s:%u:%c:%s:%d:%c:%c\n",
  912. tpde->logical, tpde->telno,
  913. tpde->tty, tpde->baud,
  914. (tpde->parity) ? to_upper(tpde->parity) : 'N',
  915. tpde->descr, tpde->debug_level, to_upper(tpde->dcdwatch),
  916. to_upper(tpde->rtscts_val));
  917. field_colon_restore(tpde->logical);
  918. field_colon_restore(tpde->telno);
  919. field_colon_restore(tpde->tty);
  920. field_colon_restore(tpde->descr);
  921. fputs(iobuf, fpnew);
  922. tpde = tpde->next;
  923. count++;
  924. }
  925. fclose(fpnew);
  926. if (unlink(phonedir_name))
  927. {
  928. sprintf(iobuf, "removing old file: %s", strerror(errno));
  929. dirw_bot_msg(iobuf);
  930. ring_bell();
  931. return;
  932. }
  933. if (rename(phonedir_ntmp, phonedir_name)) /* uh oh on old XENIX */
  934. {
  935. sprintf(iobuf, "renaming new file: %s", strerror(errno));
  936. dirw_bot_msg(iobuf);
  937. ring_bell();
  938. return;
  939. }
  940. sprintf(iobuf, "saved %d entries", count);
  941. dirw_bot_msg(iobuf);
  942. phdir_list_set_dirty(0);
  943. } /* end of phdir_cmd_save */
  944. /*+-------------------------------------------------------------------------
  945. phdir_list_save_if_dirty()
  946. --------------------------------------------------------------------------*/
  947. void
  948. phdir_list_save_if_dirty()
  949. {
  950. UINT cmd = 0;
  951. if (phdir_list_dirty)
  952. {
  953. dirw_bot_msg("type 'y' or 'n'");
  954. ring_bell();
  955. while (!cmd)
  956. {
  957. ring_bell();
  958. dirw_cmd_line_setup("", "current directory modified: save?");
  959. cmd = ttygetc(0);
  960. if (isupper(cmd))
  961. cmd = tolower(cmd);
  962. switch (cmd)
  963. {
  964. case 'y':
  965. phdir_cmd_save();
  966. break;
  967. case 'n':
  968. break;
  969. default:
  970. cmd = 0;
  971. break;
  972. }
  973. }
  974. dirw_bot_msg("");
  975. }
  976. } /* end of phdir_list_save_if_dirty */
  977. /*+-----------------------------------------------------------------------
  978. phdir_list_read()
  979. return 0 if entire list read, else 1 if error (error msg in errmsg)
  980. if file does not exist, create it, asking confirm only if in
  981. interactive (curses) mode
  982. ------------------------------------------------------------------------*/
  983. int
  984. phdir_list_read()
  985. {
  986. int token_number;
  987. char *cp;
  988. char *token;
  989. int itmp;
  990. char readpde_buf[128];
  991. FILE *fp_phone;
  992. PDE *tpde;
  993. char *str_token();
  994. if (!phonedir_name[0])
  995. {
  996. get_home_dir(phonedir_name);
  997. strcat(phonedir_name, "/.ecu/phone");
  998. }
  999. TRY_OPEN:
  1000. if (!(fp_phone = fopen(phonedir_name, "r")))
  1001. {
  1002. if (errno == ENOENT)
  1003. {
  1004. if (!want_pd_create(phonedir_name))
  1005. {
  1006. strcpy(errmsg, "non-existent file not created");
  1007. return (1);
  1008. }
  1009. if ((itmp = open(phonedir_name,
  1010. O_RDWR | O_CREAT | O_TRUNC, 0600)) >= 0)
  1011. {
  1012. write(itmp, phonedir_trigger, strlen(phonedir_trigger));
  1013. close(itmp);
  1014. if (windows_active) /* if called under curses */
  1015. {
  1016. dirw_bot_msg("created new (empty) directory file");
  1017. ring_bell();
  1018. Nap(1000L);
  1019. }
  1020. goto TRY_OPEN;
  1021. }
  1022. if (errno == ENOENT)
  1023. {
  1024. strcpy(errmsg, "~/.ecu directory nonexistent!");
  1025. ring_bell();
  1026. return (1);
  1027. }
  1028. }
  1029. strcpy(errmsg, strerror(errno));
  1030. return (1);
  1031. }
  1032. /* we have an open directory file */
  1033. if (!fgets(readpde_buf, sizeof(readpde_buf), fp_phone) ||
  1034. strcmp(readpde_buf, phonedir_trigger))
  1035. {
  1036. fclose(fp_phone);
  1037. strcpy(errmsg, "not an ECU phone directory (or is pre-rev-3)");
  1038. ring_bell();
  1039. return (1);
  1040. }
  1041. dirw_display_phonedir_name();
  1042. phdir_list_erase(); /* clear any previous directory */
  1043. while (fgets(readpde_buf, sizeof(readpde_buf), fp_phone))
  1044. {
  1045. if (readpde_buf[0] == '#') /* comment? */
  1046. continue;
  1047. if (itmp = strlen(readpde_buf)) /* itmp = len; if > 0 ... */
  1048. {
  1049. itmp--;
  1050. readpde_buf[itmp] = 0; /* ... strip trailing NL */
  1051. }
  1052. cp = readpde_buf; /* first call to str_token, -> buff */
  1053. while ((*cp == 0x20) || (*cp == 0x09))
  1054. cp++; /* strip leading spaces */
  1055. if (*cp == 0) /* if line all blank, skip it */
  1056. continue;
  1057. if (!(tpde = (PDE *) malloc(sizeof(PDE))))
  1058. {
  1059. fclose(fp_phone);
  1060. strcpy(errmsg, "Out of memory reading phone list");
  1061. return (1);
  1062. }
  1063. tpde->descr[0] = 0;
  1064. tpde->logical[0] = 0;
  1065. tpde->telno[0] = 0;
  1066. tpde->tty[0] = 0;
  1067. tpde->parity = 0;
  1068. tpde->baud = 2400;
  1069. tpde->redial = 0;
  1070. tpde->prev = (PDE *) 0;
  1071. tpde->next = (PDE *) 0;
  1072. tpde->debug_level = 0;
  1073. tpde->dcdwatch = 'n';/* do not modify shm->Ldcdwatch */
  1074. tpde->rtscts_val = 'n'; /* do not modify shm->Lrtscts_val */
  1075. token_number = 0;
  1076. while ((token = str_token(cp, ":")))
  1077. {
  1078. cp = (char *)0; /* further calls to str_token need NULL */
  1079. switch (token_number)
  1080. {
  1081. case 0: /* first field is logical name */
  1082. strncpy(tpde->logical, token, sizeof(tpde->logical));
  1083. tpde->logical[sizeof(tpde->logical) - 1] = 0;
  1084. break;
  1085. case 1: /* second field is tpde->telno phone number */
  1086. strncpy(tpde->telno, token, sizeof(tpde->telno));
  1087. tpde->telno[sizeof(tpde->telno) - 1] = 0;
  1088. break;
  1089. case 2: /* third field is line */
  1090. strncpy(tpde->tty, token, sizeof(tpde->tty));
  1091. tpde->tty[sizeof(tpde->tty) - 1] = 0;
  1092. break;
  1093. case 3: /* fourth field is bit rate */
  1094. tpde->baud = atoi(token);
  1095. break;
  1096. case 4: /* fifth field is parity */
  1097. switch (itmp = to_lower(token[0]))
  1098. {
  1099. case 'o':
  1100. case 'e':
  1101. case 'm':
  1102. case 's':
  1103. tpde->parity = itmp;
  1104. break;
  1105. default:
  1106. case 'n':
  1107. tpde->parity = 0;
  1108. break;
  1109. }
  1110. break;
  1111. case 5:
  1112. strncpy(tpde->descr, token, sizeof(tpde->descr));
  1113. tpde->descr[sizeof(tpde->descr) - 1] = 0;
  1114. break;
  1115. case 6:
  1116. if ((tpde->debug_level = (uchar) atoi(token)) > 9)
  1117. tpde->debug_level = 9;
  1118. break;
  1119. case 7:
  1120. tpde->dcdwatch = to_lower(token[0]);
  1121. #ifdef linux
  1122. /*
  1123. * alas, Linux does not handle setting DCD watch to
  1124. * one (catch termination of connection, yet continue
  1125. * line I/O) ... silently convert to terminate ECU
  1126. */
  1127. if (tpde->dcdwatch == '1')
  1128. tpde->dcdwatch = 't';
  1129. #endif
  1130. break;
  1131. case 8:
  1132. tpde->rtscts_val = to_lower(token[0]);
  1133. break;
  1134. } /* end of switch(token_number) */
  1135. token_number++;
  1136. } /* end while not end of record */
  1137. field_colon_restore(tpde->logical);
  1138. field_colon_restore(tpde->telno);
  1139. field_colon_restore(tpde->tty);
  1140. field_colon_restore(tpde->descr);
  1141. phdir_list_add(tpde);
  1142. } /* while records left to ready */
  1143. fclose(fp_phone);
  1144. return (0);
  1145. } /* end of phdir_list_read */
  1146. /*+-------------------------------------------------------------------------
  1147. phdir_cmd_up()
  1148. --------------------------------------------------------------------------*/
  1149. void
  1150. phdir_cmd_up()
  1151. {
  1152. PDE *tpde;
  1153. if ((!curr_pde) || (curr_pde->prev == (PDE *) 0))
  1154. {
  1155. ring_bell();
  1156. return;
  1157. }
  1158. if (scrw_curr_pde_line)
  1159. {
  1160. phdir_display_logical(scrw_curr_pde_line, curr_pde, 0);
  1161. scrw_curr_pde_line--;
  1162. curr_pde = curr_pde->prev;
  1163. phdir_display_logical(scrw_curr_pde_line, curr_pde, 1);
  1164. }
  1165. else
  1166. {
  1167. tpde = curr_pde;
  1168. curr_pde = curr_pde->prev;
  1169. scrw_fill_at(10, tpde, &scrw_curr_pde_line);
  1170. }
  1171. } /* end of phdir_cmd_up */
  1172. /*+-------------------------------------------------------------------------
  1173. phdir_cmd_down()
  1174. --------------------------------------------------------------------------*/
  1175. void
  1176. phdir_cmd_down()
  1177. {
  1178. PDE *tpde;
  1179. if ((!curr_pde) || (curr_pde->next == (PDE *) 0))
  1180. {
  1181. ring_bell();
  1182. return;
  1183. }
  1184. if (scrw_curr_pde_line < (SCRW_LINES - 1))
  1185. {
  1186. phdir_display_logical(scrw_curr_pde_line, curr_pde, 0);
  1187. scrw_curr_pde_line++;
  1188. curr_pde = curr_pde->next;
  1189. phdir_display_logical(scrw_curr_pde_line, curr_pde, 1);
  1190. }
  1191. else
  1192. {
  1193. tpde = curr_pde;
  1194. curr_pde = curr_pde->next;
  1195. scrw_fill_at(SCRW_LINES - 10, tpde, &scrw_curr_pde_line);
  1196. }
  1197. } /* end of phdir_cmd_down */
  1198. /*+-------------------------------------------------------------------------
  1199. phdir_cmd_pgup()
  1200. --------------------------------------------------------------------------*/
  1201. void
  1202. phdir_cmd_pgup()
  1203. {
  1204. PDE *tpde;
  1205. int itmp;
  1206. if (!curr_pde)
  1207. {
  1208. ring_bell();
  1209. return;
  1210. }
  1211. tpde = curr_pde;
  1212. if (!(itmp = SCRW_LINES * 3 / 4))
  1213. itmp = 1;
  1214. while (itmp-- && tpde->prev)
  1215. tpde = tpde->prev;
  1216. curr_pde = tpde;
  1217. scrw_fill_at(SCRW_LINES / 2, tpde, &scrw_curr_pde_line);
  1218. } /* end of phdir_cmd_pgup */
  1219. /*+-------------------------------------------------------------------------
  1220. phdir_cmd_pgdn()
  1221. --------------------------------------------------------------------------*/
  1222. void
  1223. phdir_cmd_pgdn()
  1224. {
  1225. PDE *tpde;
  1226. int itmp;
  1227. if (!curr_pde)
  1228. {
  1229. ring_bell();
  1230. return;
  1231. }
  1232. tpde = curr_pde;
  1233. if (!(itmp = SCRW_LINES * 3 / 4))
  1234. itmp = 1;
  1235. while (itmp-- && tpde->next)
  1236. tpde = tpde->next;
  1237. curr_pde = tpde;
  1238. scrw_fill_at(SCRW_LINES / 2, tpde, &scrw_curr_pde_line);
  1239. } /* end of phdir_cmd_pgdn */
  1240. /*+-------------------------------------------------------------------------
  1241. check_curr_pde() -- return 1 if there is a current pde, else 0
  1242. --------------------------------------------------------------------------*/
  1243. check_curr_pde()
  1244. {
  1245. if (!curr_pde)
  1246. {
  1247. dirw_bot_msg("no directory entry selected");
  1248. ring_bell();
  1249. return (0);
  1250. }
  1251. return (1);
  1252. } /* end of check_curr_pde */
  1253. /*+-------------------------------------------------------------------------
  1254. phdir_add_or_edit_read(prompt,y,buf,bufmax,delim)
  1255. There are numerous theoretcally possible string overflow possibilities
  1256. in here, but no practical string will be long enough
  1257. --------------------------------------------------------------------------*/
  1258. void
  1259. phdir_add_or_edit_read(prompt, y, buf, bufmax, delim)
  1260. char *prompt;
  1261. int y;
  1262. char *buf;
  1263. int bufmax;
  1264. UINT *delim;
  1265. {
  1266. int wgpos = -1;
  1267. char s80[80];
  1268. int done = 0;
  1269. if (!check_curr_pde())
  1270. return;
  1271. wmove(addw, PDE_ITEM_COUNT + 3, 2);
  1272. waddstr(addw, prompt);
  1273. strcpy(s80, buf);
  1274. do
  1275. {
  1276. (void)wingets(addw, y, 20, s80, bufmax, delim, 1, &wgpos);
  1277. clear_area(addw, y, 20, bufmax);
  1278. switch (*((UINT *) delim))
  1279. {
  1280. case ESC:
  1281. waddstr(addw, buf);
  1282. done = 1;
  1283. break;
  1284. case TAB:
  1285. case NL:
  1286. case XFcurdn:
  1287. *delim = NL;
  1288. case XFend:
  1289. strcpy(buf, s80);
  1290. waddstr(addw, buf);
  1291. done = 1;
  1292. break;
  1293. case CTL_U:
  1294. s80[0] = 0;
  1295. break;
  1296. case CTL_B:
  1297. case XFcurup:
  1298. strcpy(buf, s80);
  1299. waddstr(addw, buf);
  1300. *delim = CTL_B;
  1301. done = 1;
  1302. break;
  1303. case CTL_L:
  1304. case CTL_R:
  1305. done = 1; /* we will be right back */
  1306. break;
  1307. default:
  1308. ring_bell();
  1309. break;
  1310. }
  1311. }
  1312. while (!done);
  1313. clear_area(addw, PDE_ITEM_COUNT + 3, 2, strlen(prompt));
  1314. } /* end of phdir_add_or_edit_read */
  1315. /*+-------------------------------------------------------------------------
  1316. phdir_add_or_edit(tpde,edit)
  1317. --------------------------------------------------------------------------*/
  1318. int
  1319. phdir_add_or_edit(tpde, edit)
  1320. PDE *tpde;
  1321. int edit;
  1322. {
  1323. int erc = 0;
  1324. int input_state = 0;
  1325. int changed = 0;
  1326. int done = 0;
  1327. int aborted = 0;
  1328. int have_already_set_dirty = 0;
  1329. int itmp;
  1330. int wgedit = 0;
  1331. int wgpos = -1;
  1332. char s64[64];
  1333. UINT delim = 0;
  1334. int y, x;
  1335. PDE *old_curr_pde = (PDE *) 0;
  1336. UINT baud;
  1337. char cmpbuf[128];
  1338. if (!edit)
  1339. {
  1340. dirw_bot_msg("ESC: abort ^U: erase input");
  1341. dirw_cmd_line_setup(
  1342. "Only the 1st 10 characters appear in the table",
  1343. "Enter new directory entry name: ");
  1344. getyx(dirw, y, x);
  1345. wstandout(dirw);
  1346. while ((delim != ESC) && (delim != NL))
  1347. {
  1348. (void)wingets(dirw, y, x, tpde->logical, LOGICAL_DISP_LEN + 1, &delim,
  1349. wgedit, &wgpos);
  1350. wgedit = 1;
  1351. }
  1352. wstandend(dirw);
  1353. dirw_bot_msg("");
  1354. if ((!strlen(tpde->logical)) || (delim == ESC))
  1355. {
  1356. dirw_bot_msg("add aborted");
  1357. ring_bell();
  1358. return (0);
  1359. }
  1360. if (!isalpha((uchar) tpde->logical[0]))
  1361. {
  1362. dirw_bot_msg("first character must be alphabetic");
  1363. ring_bell();
  1364. return (0);
  1365. }
  1366. if (phdir_list_search(tpde->logical, 1))
  1367. {
  1368. sprintf(s64, "'%s' is already in the directory", tpde->logical);
  1369. dirw_bot_msg(s64);
  1370. ring_bell();
  1371. return (0);
  1372. }
  1373. tpde->descr[0] = 0;
  1374. tpde->telno[0] = 0;
  1375. tpde->tty[0] = 0;
  1376. tpde->parity = 0;
  1377. tpde->baud = CFG_DefaultBitRate;
  1378. tpde->debug_level = 0;
  1379. tpde->dcdwatch = 'n';/* do not modify shm->Ldcdwatch */
  1380. tpde->rtscts_val = 'n'; /* do not modify shm->Lrtscts_val */
  1381. phdir_list_add(tpde);
  1382. old_curr_pde = curr_pde;
  1383. curr_pde = tpde;
  1384. scrw_fill_at(SCRW_LINES / 2, tpde, &scrw_curr_pde_line);
  1385. tpde = curr_pde;
  1386. } /* end of add code */
  1387. dirw_cmd_line_setup("", "");
  1388. /*
  1389. * get a new window
  1390. */
  1391. sprintf(s64, "entry: %s", tpde->logical);
  1392. addw = window_create(s64, 3, ADDW_TLY, ADDW_TLX, ADDW_LINES, ADDW_COLS);
  1393. wmove(addw, 2, 2);
  1394. waddstr(addw, "telephone number");
  1395. wmove(addw, 3, 2);
  1396. waddstr(addw, "device");
  1397. wmove(addw, 4, 2);
  1398. waddstr(addw, "bit rate");
  1399. wmove(addw, 5, 2);
  1400. waddstr(addw, "parity");
  1401. wmove(addw, 6, 2);
  1402. waddstr(addw, "description");
  1403. wmove(addw, 7, 2);
  1404. waddstr(addw, "debug level");
  1405. wmove(addw, 7, 23); /* extra info */
  1406. waddstr(addw, "(dialer -x value 0-9)");
  1407. wmove(addw, 8, 2);
  1408. waddstr(addw, "DCD watch");
  1409. wmove(addw, 9, 2);
  1410. waddstr(addw, "RTS/CTS flow ctl");
  1411. wmove(addw, 9, 23); /* extra info */
  1412. waddstr(addw, "(0=off,7=best,n=no change)");
  1413. wmove(addw, 2, 20);
  1414. waddstr(addw, tpde->telno);
  1415. wmove(addw, 3, 20);
  1416. waddstr(addw, (tpde->tty[0]) ? tpde->tty : "Any");
  1417. sprintf(s64, "%-6u", tpde->baud);
  1418. wmove(addw, 4, 20);
  1419. waddstr(addw, s64);
  1420. s64[0] = (tpde->parity) ? to_upper((char)tpde->parity) : 'N';
  1421. s64[1] = 0;
  1422. wmove(addw, 5, 20);
  1423. waddstr(addw, s64);
  1424. wmove(addw, 6, 20);
  1425. waddstr(addw, tpde->descr);
  1426. sprintf(s64, "%u", tpde->debug_level);
  1427. wmove(addw, 7, 20);
  1428. waddstr(addw, s64);
  1429. wmove(addw, 8, 20);
  1430. waddch(addw, tpde->dcdwatch);
  1431. wmove(addw, 9, 20);
  1432. waddch(addw, tpde->rtscts_val);
  1433. wmove(addw, PDE_ITEM_COUNT + 4, 2);
  1434. if (edit)
  1435. waddstr(addw, "ESC: exit END: accept ^U: erase ^B: back TAB: fwd");
  1436. else
  1437. waddstr(addw, "ESC: cancel END: accept ^U: erase field ^B: back up");
  1438. wrefresh(addw);
  1439. /* add/edit common */
  1440. while (!done)
  1441. {
  1442. int screen_y = input_state + 2; /* leave one blank line in box */
  1443. changed = 0;
  1444. switch (input_state)
  1445. {
  1446. case 0:
  1447. if (edit)
  1448. strcpy(s64, tpde->telno);
  1449. phdir_add_or_edit_read("Enter telephone number",
  1450. screen_y, tpde->telno, DESTREF_LEN + 1, &delim);
  1451. if (delim == ESC)
  1452. break;
  1453. if (edit && strcmp(tpde->telno, s64))
  1454. changed = 1;
  1455. break;
  1456. case 1:
  1457. if (!tpde->tty[0])
  1458. strcpy(tpde->tty, "Any");
  1459. strcpy(s64, tpde->tty);
  1460. erc = 0;
  1461. CASE_1_AGAIN:
  1462. phdir_add_or_edit_read((erc) ? erc_text(erc) :
  1463. "Enter tty (e.g. tty1a), Any or [=/]Devices-type",
  1464. screen_y, tpde->tty, PDE_TTY_LEN + 1, &delim);
  1465. if (delim == ESC)
  1466. break;
  1467. if ((s64[0] == '/') &&
  1468. (erc = regexp_compile(tpde->tty + 1,
  1469. cmpbuf, sizeof(cmpbuf))))
  1470. {
  1471. ring_bell();
  1472. goto CASE_1_AGAIN;
  1473. }
  1474. erc = 0;
  1475. if (!strlen(tpde->tty) || !strcmpi(tpde->tty, "any"))
  1476. {
  1477. strcpy(tpde->tty, "Any");
  1478. clear_area(addw, screen_y, 20, PDE_TTY_LEN + 1);
  1479. waddstr(addw, tpde->tty);
  1480. }
  1481. changed = !!strcmp(tpde->tty, s64);
  1482. if (!strcmpi(tpde->tty, "any"))
  1483. tpde->tty[0] = 0;
  1484. break;
  1485. case 2:
  1486. sprintf(s64, "%u", tpde->baud);
  1487. phdir_add_or_edit_read(
  1488. valid_baud_string,
  1489. screen_y, s64, 6 + 1, &delim);
  1490. if (delim == ESC)
  1491. break;
  1492. if (valid_baud(baud = atoi(s64)) == -1)
  1493. {
  1494. ring_bell();
  1495. continue;
  1496. }
  1497. if (tpde->baud != baud)
  1498. changed = 1;
  1499. tpde->baud = baud;
  1500. break;
  1501. case 3:
  1502. sprintf(s64, "%c", (tpde->parity) ? tpde->parity : 'N');
  1503. phdir_add_or_edit_read("Enter parity (n,o,e)",
  1504. screen_y, s64, 1 + 1, &delim);
  1505. if (delim == ESC)
  1506. break;
  1507. switch (s64[0] = to_lower(s64[0]))
  1508. {
  1509. case 'n':
  1510. s64[0] = 0;
  1511. case 'o':
  1512. case 'e':
  1513. if (tpde->parity != s64[0])
  1514. changed = 1;
  1515. tpde->parity = s64[0];
  1516. break;
  1517. default:
  1518. ring_bell();
  1519. continue;
  1520. }
  1521. break;
  1522. case 4:
  1523. strcpy(s64, tpde->descr);
  1524. phdir_add_or_edit_read("Enter description",
  1525. screen_y, tpde->descr, PDE_DESCR_LEN + 1, &delim);
  1526. if (delim == ESC)
  1527. break;
  1528. if (strcmp(tpde->descr, s64))
  1529. changed = 1;
  1530. break;
  1531. case 5:
  1532. sprintf(s64, "%u", tpde->debug_level);
  1533. phdir_add_or_edit_read("Enter dialer debug level (0-9)",
  1534. screen_y, s64, 1 + 1, &delim);
  1535. if (delim == ESC)
  1536. break;
  1537. if (!isdigit((uchar) s64[0]))
  1538. {
  1539. ring_bell();
  1540. continue;
  1541. }
  1542. itmp = atoi(s64);
  1543. if (itmp != (int)tpde->debug_level)
  1544. changed = 1;
  1545. tpde->debug_level = itmp;
  1546. break;
  1547. case 6:
  1548. s64[0] = tpde->dcdwatch;
  1549. s64[1] = 0;
  1550. phdir_add_or_edit_read(
  1551. #ifdef linux
  1552. "0=off,t=terminate ecu on carrier loss,n=no change",
  1553. #else
  1554. "0=off,1=on,t=terminate ecu on carrier loss,n=no change",
  1555. #endif
  1556. screen_y, s64, 1 + 1, &delim);
  1557. if (delim == ESC)
  1558. break;
  1559. switch (s64[0] = to_lower(s64[0]))
  1560. {
  1561. case '0':
  1562. #ifndef linux
  1563. case '1': /* does not work under Linux 1.1.59 */
  1564. #endif
  1565. case 't':
  1566. case 'n':
  1567. break;
  1568. default:
  1569. ring_bell();
  1570. continue;
  1571. }
  1572. if ((uchar) s64[0] != tpde->dcdwatch)
  1573. changed = 1;
  1574. tpde->dcdwatch = s64[0];
  1575. break;
  1576. case 7:
  1577. s64[0] = tpde->rtscts_val;
  1578. s64[1] = 0;
  1579. phdir_add_or_edit_read(
  1580. "OS/hardware dependent: see doc for other values",
  1581. screen_y, s64, 1 + 1, &delim);
  1582. if (delim == ESC)
  1583. break;
  1584. switch (s64[0] = to_lower(s64[0]))
  1585. {
  1586. case 'n':
  1587. case '0':
  1588. case '1':
  1589. case '2':
  1590. case '3':
  1591. case '7':
  1592. break;
  1593. default:
  1594. ring_bell();
  1595. continue;
  1596. }
  1597. if ((uchar) s64[0] != tpde->rtscts_val)
  1598. changed = 1;
  1599. tpde->rtscts_val = s64[0];
  1600. break;
  1601. }
  1602. switch (delim) /* process delimiter */
  1603. {
  1604. case CTL_L:
  1605. case CTL_R:
  1606. touchwin(stdscr);
  1607. wrefresh(stdscr);
  1608. touchwin(dirw);
  1609. wrefresh(dirw);
  1610. touchwin(scrw);
  1611. wrefresh(scrw);
  1612. touchwin(addw);
  1613. wrefresh(addw);
  1614. break;
  1615. case CTL_B:
  1616. if (input_state)
  1617. input_state--;
  1618. else
  1619. input_state = PDE_ITEM_COUNT - 1;
  1620. break;
  1621. case ESC:
  1622. if (edit)
  1623. {
  1624. dirw_bot_msg("edit exit");
  1625. done = 1;
  1626. }
  1627. else
  1628. {
  1629. phdir_list_remove(tpde);
  1630. if (old_curr_pde)
  1631. curr_pde = old_curr_pde;
  1632. else if (phdir_list_quan)
  1633. {
  1634. pputs("\nphdir_add_or_edit logic error\n");
  1635. errno = -1;
  1636. termecu(TERMECU_LOGIC_ERROR);
  1637. }
  1638. dirw_bot_msg("add aborted");
  1639. ring_bell();
  1640. aborted = 1;
  1641. done = 1;
  1642. }
  1643. break;
  1644. case XFend:
  1645. if (edit)
  1646. dirw_bot_msg("edit exit");
  1647. done = 1;
  1648. break;
  1649. case NL:
  1650. input_state++;
  1651. input_state %= PDE_ITEM_COUNT;
  1652. break;
  1653. default:
  1654. ring_bell();
  1655. break;
  1656. }
  1657. if (edit && changed && !have_already_set_dirty)
  1658. {
  1659. phdir_list_set_dirty(1);
  1660. have_already_set_dirty = 1;
  1661. }
  1662. }
  1663. delwin(addw);
  1664. addw = (WINDOW *) 0;
  1665. touchwin(scrw);
  1666. if (aborted)
  1667. {
  1668. scrw_fill_at(scrw_curr_pde_line + 1, curr_pde,
  1669. &scrw_curr_pde_line);
  1670. }
  1671. else
  1672. phdir_display(scrw_curr_pde_line, tpde, 1);
  1673. return (!aborted);
  1674. } /* end of phdir_add_or_edit */
  1675. /*+-------------------------------------------------------------------------
  1676. phdir_cmd_add(tpde)
  1677. if tpde != 0, it is an already valid pde that is to be added
  1678. else if == 0, interactive add
  1679. --------------------------------------------------------------------------*/
  1680. void
  1681. phdir_cmd_add(tpde)
  1682. PDE *tpde;
  1683. {
  1684. if (tpde)
  1685. {
  1686. phdir_list_add(tpde);
  1687. }
  1688. else
  1689. {
  1690. if (!(tpde = (PDE *) calloc(1, sizeof(PDE))))
  1691. {
  1692. dirw_bot_msg("Out of memory -- cannot add new entry");
  1693. ring_bell();
  1694. return;
  1695. }
  1696. if (!phdir_add_or_edit(tpde, 0)) /* routine will add to list
  1697. * ... */
  1698. { /* ... if good return */
  1699. free((char *)tpde);
  1700. return;
  1701. }
  1702. }
  1703. phdir_list_set_dirty(1);
  1704. curr_pde = tpde;
  1705. scrw_fill_at(SCRW_LINES / 2, curr_pde, &scrw_curr_pde_line);
  1706. } /* end of phdir_cmd_add */
  1707. /*+-------------------------------------------------------------------------
  1708. phdir_cmd_mark(tpde) - mark for redial
  1709. --------------------------------------------------------------------------*/
  1710. void
  1711. phdir_cmd_mark(tpde)
  1712. PDE *tpde;
  1713. {
  1714. if (!tpde)
  1715. return;
  1716. if (!tpde->redial)
  1717. {
  1718. tpde->redial = 1;
  1719. if (tpde == curr_pde)
  1720. phdir_display_logical(scrw_curr_pde_line, curr_pde, 1);
  1721. pde_marked_for_redial_count++;
  1722. dirw_display_config();
  1723. }
  1724. } /* end of phdir_cmd_mark */
  1725. /*+-------------------------------------------------------------------------
  1726. phdir_cmd_unmark(tpde) - unmark for redial
  1727. --------------------------------------------------------------------------*/
  1728. void
  1729. phdir_cmd_unmark(tpde)
  1730. PDE *tpde;
  1731. {
  1732. if (!tpde)
  1733. return;
  1734. if (tpde->redial)
  1735. {
  1736. tpde->redial = 0;
  1737. if (tpde == curr_pde)
  1738. phdir_display_logical(scrw_curr_pde_line, curr_pde, 1);
  1739. pde_marked_for_redial_count--;
  1740. dirw_display_config();
  1741. }
  1742. } /* end of phdir_cmd_unmark */
  1743. /*+-------------------------------------------------------------------------
  1744. phdir_cmd_unmark_all() - unmark for redial all PDEs
  1745. --------------------------------------------------------------------------*/
  1746. void
  1747. phdir_cmd_unmark_all()
  1748. {
  1749. PDE *tpde;
  1750. int y;
  1751. tpde = phdir_list_head;
  1752. while (tpde)
  1753. {
  1754. tpde->redial = 0;
  1755. tpde = tpde->next;
  1756. }
  1757. for (y = 0; y < SCRW_LINES; y++)
  1758. {
  1759. wmove(scrw, y, 1);
  1760. waddch(scrw, ' ');
  1761. }
  1762. pde_marked_for_redial_count = 0;
  1763. dirw_display_config();
  1764. } /* end of phdir_cmd_unmark_all */
  1765. /*+-------------------------------------------------------------------------
  1766. phdir_cmd_remove_oops()
  1767. --------------------------------------------------------------------------*/
  1768. void
  1769. phdir_cmd_remove_oops()
  1770. {
  1771. if (!remove_pde)
  1772. {
  1773. dirw_bot_msg("no removed entry to restore");
  1774. ring_bell();
  1775. return;
  1776. }
  1777. phdir_cmd_add(remove_pde);
  1778. phdir_list_set_dirty(remove_dirty_flag);
  1779. remove_pde = (PDE *) 0;
  1780. } /* end of phdir_cmd_remove_oops */
  1781. /*+-------------------------------------------------------------------------
  1782. phdir_cmd_remove()
  1783. --------------------------------------------------------------------------*/
  1784. void
  1785. phdir_cmd_remove()
  1786. {
  1787. char s80[80];
  1788. if (!check_curr_pde())
  1789. return;
  1790. remove_pde = curr_pde;
  1791. remove_dirty_flag = phdir_list_dirty;
  1792. phdir_list_remove(curr_pde);
  1793. phdir_list_set_dirty(1);
  1794. if (phdir_list_quan)
  1795. scrw_fill_at(scrw_curr_pde_line + 1, curr_pde, &scrw_curr_pde_line);
  1796. else
  1797. scrw_fill((PDE *) 0, &scrw_curr_pde_line);
  1798. ring_bell();
  1799. sprintf(s80, "if you did not mean to to remove '%s', press 'o' (oops) NOW!",
  1800. remove_pde->logical);
  1801. dirw_bot_msg(s80);
  1802. ring_bell();
  1803. } /* end of phdir_cmd_remove */
  1804. /*+-------------------------------------------------------------------------
  1805. phdir_cmd_find()
  1806. --------------------------------------------------------------------------*/
  1807. void
  1808. phdir_cmd_find()
  1809. {
  1810. PDE *tpde;
  1811. char findname[LOGICAL_LEN + 1];
  1812. UINT delim = 0;
  1813. int y, x;
  1814. int wgedit = 0;
  1815. int wgpos = -1;
  1816. dirw_bot_msg("ESC: abort ^U: erase input");
  1817. dirw_cmd_line_setup("", "Directory entry name to find: ");
  1818. getyx(dirw, y, x);
  1819. wstandout(dirw);
  1820. while ((delim != ESC) && (delim != NL))
  1821. {
  1822. (void)wingets(dirw, y, x, findname, LOGICAL_DISP_LEN + 1, &delim,
  1823. wgedit, &wgpos);
  1824. wgedit = 1;
  1825. }
  1826. wstandend(dirw);
  1827. dirw_bot_msg("");
  1828. if ((!strlen(findname)) || (delim == ESC))
  1829. return;
  1830. if (!(tpde = phdir_list_search(findname, 0)))
  1831. {
  1832. dirw_bot_msg(errmsg);
  1833. ring_bell();
  1834. return;
  1835. }
  1836. curr_pde = tpde;
  1837. scrw_fill_at(SCRW_LINES / 2, tpde, &scrw_curr_pde_line);
  1838. } /* end of phdir_cmd_find */
  1839. /*+-------------------------------------------------------------------------
  1840. phdir_cmd_change_dir()
  1841. --------------------------------------------------------------------------*/
  1842. void
  1843. phdir_cmd_change_dir()
  1844. {
  1845. int itmp;
  1846. char newdirname[ECU_MAXPN];
  1847. char buf[256];
  1848. UINT delim = 0;
  1849. int y, x;
  1850. int wgedit = 0;
  1851. int wgpos = -1;
  1852. char *expcmd;
  1853. extern char errmsg[];
  1854. phdir_list_save_if_dirty();
  1855. dirw_bot_msg("ESC: abort ^U: erase input");
  1856. dirw_cmd_line_setup(" Enter new directory name:", "");
  1857. getyx(dirw, y, x);
  1858. wstandout(dirw);
  1859. while ((delim != ESC) && (delim != NL))
  1860. {
  1861. (void)wingets(dirw, y, x, buf, 70 + 1, &delim,
  1862. wgedit, &wgpos);
  1863. wgedit = 1;
  1864. }
  1865. wstandend(dirw);
  1866. dirw_bot_msg("");
  1867. if ((!strlen(buf)) || (delim == ESC))
  1868. return;
  1869. if ((buf[0] == '~') || (buf[0] == '.') || (buf[0] == '/'))
  1870. strcpy(newdirname, buf);
  1871. else
  1872. {
  1873. get_curr_dir(newdirname, sizeof(newdirname) - strlen(buf) - 2);
  1874. strcat(newdirname, "/");
  1875. strcat(newdirname, buf);
  1876. }
  1877. if (find_shell_chars(newdirname))
  1878. {
  1879. if (expand_wildcard_list(newdirname, &expcmd))
  1880. {
  1881. dirw_bot_msg(expcmd);
  1882. ring_bell();
  1883. return;
  1884. }
  1885. strncpy(newdirname, expcmd, sizeof(newdirname) - 1);
  1886. newdirname[sizeof(newdirname) - 1] = 0;
  1887. free(expcmd);
  1888. }
  1889. if (access(newdirname, 4))
  1890. {
  1891. if (errno == ENOENT)
  1892. {
  1893. if (!want_pd_create(newdirname))
  1894. {
  1895. dirw_bot_msg("non-existent file not created");
  1896. ring_bell();
  1897. return;
  1898. }
  1899. if ((itmp = open(newdirname, O_RDWR | O_CREAT | O_TRUNC, 0600)) >= 0)
  1900. {
  1901. write(itmp, phonedir_trigger, strlen(phonedir_trigger));
  1902. close(itmp);
  1903. dirw_bot_msg("created new (empty) directory file");
  1904. ring_bell();
  1905. Nap(1000L);
  1906. goto READ_LIST;
  1907. }
  1908. if (errno == ENOENT)
  1909. {
  1910. dirw_bot_msg("directory does not exist");
  1911. ring_bell();
  1912. return;
  1913. }
  1914. }
  1915. dirw_bot_msg(strerror(errno));
  1916. ring_bell();
  1917. return;
  1918. }
  1919. READ_LIST:
  1920. strcpy(phonedir_name, newdirname);
  1921. if (phdir_list_read())
  1922. {
  1923. dirw_bot_msg(errmsg);
  1924. ring_bell();
  1925. return;
  1926. }
  1927. curr_pde = phdir_list_head;
  1928. scrw_fill(curr_pde, &scrw_curr_pde_line);
  1929. if (!phdir_list_quan)
  1930. {
  1931. dirw_bot_msg("directory empty");
  1932. return;
  1933. }
  1934. } /* end of phdir_cmd_change_dir */
  1935. /*+-------------------------------------------------------------------------
  1936. phdir_dial_cycle() - dial single destination or cycle through list
  1937. return 1 if connect occurs, 0 if cycle expires or interrupted
  1938. --------------------------------------------------------------------------*/
  1939. int
  1940. phdir_dial_cycle()
  1941. {
  1942. PDE *tpde = phdir_list_head;
  1943. UINT ans;
  1944. int nap_decisec;
  1945. int rtn = 0;
  1946. int restart_rcvr = need_rcvr_restart();
  1947. if (!tpde || !phdir_list_quan)
  1948. {
  1949. ring_bell();
  1950. return (0);
  1951. }
  1952. if (!pde_marked_for_redial_count)
  1953. {
  1954. pde_dial(curr_pde);
  1955. return (!(int)iv[0]);
  1956. }
  1957. kill_rcvr_process(SIGUSR1);
  1958. ff(se, "\r\nbeginning cycle through %d marked redial entr%s\r\n",
  1959. pde_marked_for_redial_count,
  1960. (pde_marked_for_redial_count > 1) ? "ies" : "y");
  1961. while (1) /* forever until a connect or interrupt */
  1962. {
  1963. if (tpde->redial)
  1964. {
  1965. pde_dial(tpde);
  1966. switch ((int)iv[0])
  1967. {
  1968. case 0: /* CONNECTED */
  1969. tpde->redial = 0;
  1970. pde_marked_for_redial_count--;
  1971. bell_notify(XBELL_C);
  1972. rtn = 1;
  1973. if (restart_rcvr)
  1974. start_rcvr_process(1);
  1975. return (rtn);
  1976. case 2: /* INTERRUPTED */
  1977. ff(se, "\r\ndial interrupted: abort cycle (y,n)? ");
  1978. sigint = 0;
  1979. ans = 0;
  1980. while (ans == 0)
  1981. {
  1982. switch (ans = to_lower(ttygetc(1)))
  1983. {
  1984. case 'y':
  1985. ff(se, "YES\r\n");
  1986. goto ABORT_CYCLE;
  1987. case 'n':
  1988. ff(se, "NO\r\n");
  1989. break;
  1990. default:
  1991. ring_bell();
  1992. ans = 0;
  1993. }
  1994. }
  1995. break;
  1996. case 1: /* FAILED TO CONNECT */
  1997. case 3: /* MODEM ERROR */
  1998. default:
  1999. if (pde_marked_for_redial_count == 1)
  2000. nap_decisec = nap_decisec_single;
  2001. else
  2002. nap_decisec = nap_decisec_multiple;
  2003. ff(se,
  2004. "waiting %d seconds ... 'c' to cycle, %s to abort\r\n",
  2005. nap_decisec / 10, (kbdintr == DEL)
  2006. ? "DEL" : graphic_char_text(kbdintr, 0));
  2007. while (nap_decisec--)
  2008. {
  2009. Nap(100L);
  2010. if (ttyrdchk())
  2011. {
  2012. ans = (UINT) to_lower(ttygetc(1));
  2013. ttyflush(0);
  2014. if (ans == 'c')
  2015. goto CONTINUE_CYCLE;
  2016. else if (ans == (unsigned)kbdintr)
  2017. goto ABORT_CYCLE;
  2018. else
  2019. ring_bell();
  2020. }
  2021. if (ck_sigint())
  2022. goto ABORT_CYCLE;
  2023. }
  2024. break;
  2025. }
  2026. }
  2027. CONTINUE_CYCLE:
  2028. tpde = tpde->next;
  2029. if (!tpde)
  2030. tpde = phdir_list_head;
  2031. }
  2032. ABORT_CYCLE:
  2033. sigint = 0;
  2034. ff(se, "redial cycle ABORTED\r\n");
  2035. if (restart_rcvr)
  2036. start_rcvr_process(1);
  2037. return (rtn);
  2038. } /* end of phdir_dial_cycle */
  2039. /*+-------------------------------------------------------------------------
  2040. phdir_cmd_set_wait()
  2041. --------------------------------------------------------------------------*/
  2042. void
  2043. phdir_cmd_set_wait()
  2044. {
  2045. char buf[64];
  2046. UINT delim = 0;
  2047. int y, x;
  2048. int wgpos = -1;
  2049. dirw_bot_msg("ESC: abort ^U: erase input");
  2050. sprintf(buf, "(Must be greater than or equal to %d seconds)",
  2051. NAP_DECISEC_SINGLE_MIN / 10);
  2052. dirw_cmd_line_setup(buf, "Wait between dials when one entry marked:");
  2053. getyx(dirw, y, x);
  2054. sprintf(buf, "%d", nap_decisec_single / 10);
  2055. wstandout(dirw);
  2056. wgpos = strlen(buf);
  2057. while ((delim != ESC) && (delim != NL))
  2058. (void)wingets(dirw, y, x, buf, 3 + 1, &delim, 1, &wgpos);
  2059. wstandend(dirw);
  2060. if ((!strlen(buf)) || (delim == ESC))
  2061. {
  2062. dirw_bot_msg("");
  2063. return;
  2064. }
  2065. nap_decisec_single = 0;
  2066. sscanf(buf, "%d", &nap_decisec_single);
  2067. nap_decisec_single *= 10;
  2068. if (nap_decisec_single < NAP_DECISEC_SINGLE_MIN)
  2069. nap_decisec_single = NAP_DECISEC_SINGLE_MIN;
  2070. dirw_display_config();
  2071. sprintf(buf, "(Must be greater than or equal to %d seconds)",
  2072. NAP_DECISEC_MULTIPLE_MIN / 10);
  2073. dirw_cmd_line_setup(buf, "Wait between dials when multiple entries marked:");
  2074. getyx(dirw, y, x);
  2075. sprintf(buf, "%d", nap_decisec_multiple / 10);
  2076. wstandout(dirw);
  2077. wgpos = strlen(buf);
  2078. delim = 0;
  2079. while ((delim != ESC) && (delim != NL))
  2080. (void)wingets(dirw, y, x, buf, 3 + 1, &delim, 1, &wgpos);
  2081. wstandend(dirw);
  2082. if ((!strlen(buf)) || (delim == ESC))
  2083. {
  2084. dirw_bot_msg("");
  2085. return;
  2086. }
  2087. nap_decisec_multiple = 0;
  2088. sscanf(buf, "%d", &nap_decisec_multiple);
  2089. nap_decisec_multiple *= 10;
  2090. if (nap_decisec_multiple < NAP_DECISEC_MULTIPLE_MIN)
  2091. nap_decisec_multiple = NAP_DECISEC_MULTIPLE_MIN;
  2092. dirw_display_config();
  2093. dirw_bot_msg("");
  2094. } /* end of phdir_cmd_set_wait */
  2095. /*+-------------------------------------------------------------------------
  2096. phdir_manager()
  2097. --------------------------------------------------------------------------*/
  2098. void
  2099. phdir_manager()
  2100. {
  2101. UINT cmd = 0;
  2102. int done;
  2103. char s80[80];
  2104. int restart_rcvr = need_rcvr_restart();
  2105. kill_rcvr_process(SIGUSR1);
  2106. windows_start();
  2107. dirw = window_create("dialing directory", 3, 0, 0, DIRW_LINES, DIRW_COLS);
  2108. phonedir_name_x = 26; /* must be set before calling dirw_display */
  2109. dirw_display();
  2110. scrw = subwin(dirw, SCRW_LINES, SCRW_COLS, SCRW_TLY, SCRW_TLX);
  2111. scrollok(scrw, 0);
  2112. if (!phdir_list_quan)
  2113. {
  2114. if (phdir_list_read())
  2115. {
  2116. dirw_bot_msg(errmsg);
  2117. ring_bell();
  2118. }
  2119. else if (!phdir_list_quan)
  2120. {
  2121. dirw_bot_msg("directory empty");
  2122. ring_bell();
  2123. }
  2124. }
  2125. if (phdir_list_quan)
  2126. {
  2127. if (curr_pde)
  2128. scrw_fill_at(scrw_curr_pde_line, curr_pde, &scrw_curr_pde_line);
  2129. else
  2130. {
  2131. curr_pde = phdir_list_head;
  2132. scrw_fill(curr_pde, &scrw_curr_pde_line);
  2133. }
  2134. }
  2135. phdir_list_set_dirty(-1);
  2136. done = 0;
  2137. while (!done)
  2138. {
  2139. cmd = dirw_get_cmd();
  2140. if ((cmd != 'o') && (remove_pde))
  2141. {
  2142. free((char *)remove_pde);
  2143. remove_pde = (PDE *) 0;
  2144. }
  2145. switch (cmd)
  2146. {
  2147. case XFcurdn:
  2148. case 'd':
  2149. case 'j':
  2150. phdir_cmd_down();
  2151. break;
  2152. case XFcurup:
  2153. case 'u':
  2154. case 'k':
  2155. phdir_cmd_up();
  2156. break;
  2157. case XFpgup:
  2158. case CTL_U:
  2159. case CTL_B:
  2160. phdir_cmd_pgup();
  2161. break;
  2162. case XFpgdn:
  2163. case CTL_F:
  2164. case CTL_D:
  2165. phdir_cmd_pgdn();
  2166. break;
  2167. case 's':
  2168. phdir_cmd_save();
  2169. break;
  2170. case 'm':
  2171. phdir_cmd_mark(curr_pde);
  2172. break;
  2173. case 'M':
  2174. phdir_cmd_unmark(curr_pde);
  2175. break;
  2176. case 'U':
  2177. phdir_cmd_unmark_all();
  2178. break;
  2179. case 'c':
  2180. phdir_cmd_change_dir();
  2181. break;
  2182. case 'w':
  2183. phdir_cmd_set_wait();
  2184. break;
  2185. case CRET:
  2186. case NL:
  2187. case XFend:
  2188. cmd = NL;
  2189. if (!check_curr_pde())
  2190. break;
  2191. phdir_list_save_if_dirty();
  2192. wrefresh(dirw);
  2193. delwin(scrw);
  2194. delwin(dirw);
  2195. windows_end(1);
  2196. dirw = (WINDOW *) 0;
  2197. scrw = (WINDOW *) 0;
  2198. phdir_dial_cycle();
  2199. done = 1;
  2200. if (restart_rcvr)
  2201. start_rcvr_process(1);
  2202. break;
  2203. case ESC:
  2204. case CTL_C:
  2205. cmd = 'q';
  2206. case 'q':
  2207. done = 1;
  2208. continue;
  2209. case '/':
  2210. case 'f':
  2211. phdir_cmd_find();
  2212. break;
  2213. case 'r':
  2214. phdir_cmd_remove();
  2215. break;
  2216. case 'o':
  2217. phdir_cmd_remove_oops();
  2218. break;
  2219. case 'a':
  2220. phdir_cmd_add((PDE *) 0);
  2221. break;
  2222. case 'e':
  2223. phdir_add_or_edit(curr_pde, 1);
  2224. break;
  2225. case CTL_L:
  2226. case CTL_R:
  2227. touchwin(stdscr);
  2228. wrefresh(stdscr);
  2229. touchwin(dirw);
  2230. wrefresh(dirw);
  2231. touchwin(scrw);
  2232. wrefresh(scrw);
  2233. break;
  2234. default:
  2235. sprintf(s80, "invalid command: %s",
  2236. (cmd < 0x80) ? graphic_char_text(cmd, 0) : "?");
  2237. dirw_bot_msg(s80);
  2238. ring_bell();
  2239. break;
  2240. }
  2241. }
  2242. sigint = 0;
  2243. if (cmd == NL)
  2244. return;
  2245. phdir_list_save_if_dirty();
  2246. wrefresh(dirw);
  2247. delwin(scrw);
  2248. delwin(dirw);
  2249. windows_end(0);
  2250. dirw = (WINDOW *) 0;
  2251. scrw = (WINDOW *) 0;
  2252. redisplay_rcvr_screen();
  2253. if (restart_rcvr)
  2254. start_rcvr_process(0);
  2255. } /* end of phdir_manager */
  2256. /* end of ecuphdir.c */
  2257. /* vi: set tabstop=4 shiftwidth=4: */