home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume16 / ecu3 / part05 < prev    next >
Encoding:
Internet Message Format  |  1991-01-06  |  50.9 KB

  1. From: wht@n4hgf.uucp (Warren Tucker)
  2. Newsgroups: comp.sources.misc
  3. Subject: v16i029:  ECU async comm package rev 3.0, Part05/35
  4. Message-ID: <1991Jan6.051827.27457@sparky.IMD.Sterling.COM>
  5. Date: 6 Jan 91 05:18:27 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: c7b2d403 2686fd3e f15447fe d842cdf1
  8.  
  9. Submitted-by: wht@n4hgf.uucp (Warren Tucker)
  10. Posting-number: Volume 16, Issue 29
  11. Archive-name: ecu3/part05
  12.  
  13. ---- Cut Here and feed the following to sh ----
  14. #!/bin/sh
  15. # This is part 05 of ecu3
  16. if touch 2>&1 | fgrep 'amc' > /dev/null
  17.  then TOUCH=touch
  18.  else TOUCH=true
  19. fi
  20. # ============= ecuphone.c ==============
  21. echo 'x - extracting ecuphone.c (Text)'
  22. sed 's/^X//' << 'SHAR_EOF' > 'ecuphone.c' &&
  23. X/*+-------------------------------------------------------------------------
  24. X    ecuphone.c -- visual phone dialer/directory editor
  25. X    wht@n4hgf.Mt-Park.GA.US
  26. X
  27. X  .---[ title ]------------modified-.<-- dirw "top line"
  28. X  |   stand out mode                |<-- dirw "header line"
  29. X  |                                 |<-- scrw first line
  30. X  |                                 |
  31. X  |                                 |
  32. X  |                                 |
  33. X  |                                 |<-- scrw last line
  34. X  +---------------------------------+<-- dirw bottom separator line
  35. X  |                                 |<-- dirw extra cmd prompt line
  36. X  |   stand out mode                |<-- dirw "cmd line"
  37. X  `---------------------------------'<-- dirw bottom line
  38. X
  39. X  Defined functions:
  40. X    check_curr_pde()
  41. X    choose_line(baud)
  42. X    copy_pde_to_lvar(tpde)
  43. X    dirw_bot_msg(msg)
  44. X    dirw_cmd_line_setup(prompt1,prompt2)
  45. X    dirw_display()
  46. X    dirw_display_config()
  47. X    dirw_display_phonedir_name()
  48. X    dirw_get_cmd(prompt)
  49. X    lookup_logical_telno()
  50. X    pde_add_or_edit(tpde,edit)
  51. X    pde_add_or_edit_read(prompt,edit,x,buf,max,delim)
  52. X    pde_cmd_add(tpde)
  53. X    pde_cmd_change_dir()
  54. X    pde_cmd_down()
  55. X    pde_cmd_dump_list()
  56. X    pde_cmd_find()
  57. X    pde_cmd_mark(tpde)
  58. X    pde_cmd_remove()
  59. X    pde_cmd_remove_oops()
  60. X    pde_cmd_save()
  61. X    pde_cmd_set_wait()
  62. X    pde_cmd_unmark(tpde)
  63. X    pde_cmd_unmark_all()
  64. X    pde_cmd_up()
  65. X    pde_dial(tpde)
  66. X    pde_dial_cycle()
  67. X    pde_display(line,tpde,stand_out)
  68. X    pde_display_logical(line,tpde,stand_out)
  69. X    pde_list_add(tpde)
  70. X    pde_list_erase()
  71. X    pde_list_manager()
  72. X    pde_list_read()
  73. X    pde_list_remove(tpde)
  74. X    pde_list_save_if_dirty()
  75. X    pde_list_search(logical,exact_flag)
  76. X    pde_list_set_dirty(flag)
  77. X    scrw_fill(tpde,curr_pde_line)
  78. X    scrw_fill_at(line_num,tpde,curr_pde_line)
  79. X    want_pd_create(name)
  80. X
  81. X--------------------------------------------------------------------------*/
  82. X/*+:EDITS:*/
  83. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  84. X
  85. X#include <curses.h>
  86. X
  87. X#define STDIO_H_INCLUDED
  88. X#define OMIT_TERMIO_REFERENCES
  89. X#include "ecu.h"
  90. X#include "pc_scr.h"
  91. X
  92. X#include "ecupde.h"
  93. X#include "ecukey.h"
  94. X#include "ecuxkey.h"
  95. X#include "ecuhangup.h"
  96. X#include "utmpstatus.h"
  97. X#include "dvent.h"
  98. X#include "esd.h"
  99. X#include "var.h"
  100. X
  101. Xextern char *find_procedure();
  102. Xextern char *make_char_graphic();
  103. X
  104. Xvoid dirw_bot_msg();
  105. Xvoid dirw_cmd_line_setup();
  106. Xint pde_list_read();
  107. X
  108. X#if defined(BSD)
  109. X#define strchr index
  110. X#define strrchr rindex
  111. X#endif
  112. X
  113. Xchar *strchr();
  114. Xchar *strrchr();
  115. X
  116. X/* window definitions */
  117. X#define DIRW_LINES        (LINES - 1)
  118. X#define DIRW_COLS        (COLS)
  119. X#define DIRW_COLS        (COLS)
  120. X#define DIRW_TOP_LINES    2
  121. X#define DIRW_BOT_LINES    4
  122. X#define DIRW_CMD_LINE    (DIRW_LINES - 2)
  123. X#define SCRW_LINES        (DIRW_LINES - DIRW_TOP_LINES - DIRW_BOT_LINES)
  124. X#define SCRW_COLS        (DIRW_COLS)
  125. X#define SCRW_TLY        (DIRW_TOP_LINES)
  126. X#define SCRW_TLX        0
  127. X
  128. Xextern int errno;
  129. X
  130. Xextern int windows_active;
  131. Xextern int interrupt;
  132. Xextern int rcvr_pid;
  133. Xextern char errmsg[];
  134. Xextern char kbdintr;
  135. Xextern int proc_level;
  136. X
  137. XWINDOW *dirw = (WINDOW *)0;
  138. XWINDOW *scrw = (WINDOW *)0;
  139. X
  140. XPDE *pde_list_head = (PDE *)0;    /* pointer to first pde in linked list */
  141. XPDE *curr_pde = (PDE *)0;        /* current pde */
  142. XPDE *remove_pde = (PDE *)0;        /* if non-zero, pde just removed */
  143. Xint remove_dirty_flag;            /* pde_list_dirty at remove time */
  144. Xint pde_list_quan = 0;            /* count of items in list now */
  145. Xint pde_list_dirty = 0;            /* pde_list modified but not saved */
  146. Xint pde_marked_for_redial_count = 0;
  147. Xint scrw_curr_pde_line;            /* scrw line curr_pde is on */
  148. Xchar phonedir_name[256];        /* phone directory name */
  149. Xint phonedir_name_x;            /* position for phonedir name on screen */
  150. Xchar *phonedir_trigger = "#ECUPHONE\n";
  151. X
  152. X#ifdef WHT
  153. X#define NAP_DECISEC_SINGLE_MIN         10
  154. X#define NAP_DECISEC_MULTIPLE_MIN       10
  155. X#else
  156. X#define NAP_DECISEC_SINGLE_MIN         150
  157. X#define NAP_DECISEC_MULTIPLE_MIN       50
  158. X#endif
  159. Xint nap_decisec_single   = 150;
  160. Xint nap_decisec_multiple = 50;
  161. X
  162. X/*+-------------------------------------------------------------------------
  163. X    pde_list_erase()
  164. X--------------------------------------------------------------------------*/
  165. Xvoid
  166. Xpde_list_erase()
  167. X{
  168. Xregister PDE *pde = pde_list_head;
  169. Xregister PDE *next;
  170. X
  171. X    while(pde)
  172. X    {
  173. X        next = pde->next;
  174. X        free((char *)pde);
  175. X        pde = next;
  176. X    }
  177. X    pde_list_head = (PDE *)0;
  178. X    pde_list_quan = 0;
  179. X    curr_pde = (PDE *)0;
  180. X    remove_pde = (PDE *)0;
  181. X    pde_marked_for_redial_count = 0;
  182. X
  183. X}    /* end of pde_list_erase */
  184. X
  185. X/*+-------------------------------------------------------------------------
  186. X    pde_list_set_dirty(flag)
  187. X0: clean, 1 dirty, -1 do not modify;update screen only
  188. X--------------------------------------------------------------------------*/
  189. Xvoid
  190. Xpde_list_set_dirty(flag)
  191. Xint flag;
  192. X{
  193. Xregister itmp;
  194. X    if(flag != pde_list_dirty)
  195. X    {
  196. X        if(flag != -1)
  197. X            pde_list_dirty = flag;
  198. X        wmove(dirw,0,DIRW_COLS - 14);
  199. X        if(pde_list_dirty)
  200. X            waddstr(dirw," modified ");
  201. X        else
  202. X        {
  203. X            itmp = 10;
  204. X            while(itmp--)
  205. X                waddch(dirw,(unsigned)sHR);
  206. X        }
  207. X        wrefresh(dirw);
  208. X    }
  209. X}    /* end of pde_list_set_dirty */
  210. X
  211. X/*+-------------------------------------------------------------------------
  212. X    pde_list_add(tpde) -- add to linked list
  213. X--------------------------------------------------------------------------*/
  214. Xvoid
  215. Xpde_list_add(tpde)
  216. XPDE *tpde;
  217. X{
  218. Xregister PDE *this = tpde;
  219. Xregister PDE *prev;
  220. Xregister PDE *next;
  221. X
  222. X/* if empty, init list with this one and quit */
  223. X    if(pde_list_head == (PDE *)0)
  224. X    {
  225. X        pde_list_head = this;
  226. X        this->prev = (PDE *)0;
  227. X        this->next = (PDE *)0;
  228. X        pde_list_quan++;
  229. X        return;
  230. X    }
  231. X
  232. X/* list not empty */
  233. X    prev = (PDE *)0;        /* no previous yet */
  234. X    next = pde_list_head;    /* init next to top of list */
  235. X
  236. X    while(strcmp(next->logical,this->logical) < 0)
  237. X    {
  238. X        prev = next;
  239. X        next = prev->next;
  240. X        if(next == (PDE *)0)
  241. X            break;
  242. X    }
  243. X
  244. X    if(prev)        /* if non-zero, we will not update the list head */
  245. X    {
  246. X        this->next = prev->next;
  247. X        this->prev = prev;
  248. X        prev->next = this;
  249. X        if(next)
  250. X            next->prev = this;
  251. X    }
  252. X    else    /* 'this' is to become the new list head (1st element) */
  253. X    {
  254. X        this->next = next;
  255. X        this->prev = (PDE *)0;
  256. X        if(next)
  257. X            next->prev = this;
  258. X        pde_list_head = this;
  259. X    }
  260. X    pde_list_quan++;
  261. X
  262. X}    /* end of pde_add */
  263. X
  264. X/*+-------------------------------------------------------------------------
  265. X    pde_list_remove(tpde) -- remove from linked list
  266. X--------------------------------------------------------------------------*/
  267. Xvoid
  268. Xpde_list_remove(tpde)
  269. Xregister PDE *tpde;
  270. X{
  271. Xregister PDE *prev;
  272. Xregister PDE *next;
  273. X
  274. X    prev = (PDE *)0;    /* there is no previous now */
  275. X
  276. X    if((next = pde_list_head) == (PDE *)0)    /* if empty list */
  277. X        return;
  278. X
  279. X    while(next != tpde)
  280. X    {
  281. X        prev = next;
  282. X        next = prev->next;
  283. X        if(next == (PDE *)0)
  284. X            return;
  285. X    }
  286. X
  287. X/* take care of "current pde" */
  288. X    if(tpde == curr_pde)
  289. X    {
  290. X        if(tpde->next)
  291. X            curr_pde = tpde->next;
  292. X        else if(tpde->prev)
  293. X            curr_pde = tpde->prev;
  294. X        else
  295. X            curr_pde = (PDE *)0;
  296. X    }
  297. X
  298. X/* marked? */
  299. X    if(tpde->redial)
  300. X    {
  301. X        tpde->redial = 0;
  302. X        pde_marked_for_redial_count--;
  303. X    }
  304. X
  305. X/* unlink */
  306. X
  307. X    if(prev)        /* if non-zero, we will not update the list head */
  308. X    {
  309. X        prev->next = tpde->next;
  310. X        if(tpde->next)
  311. X            (tpde->next)->prev = prev;
  312. X    }
  313. X    else
  314. X    {
  315. X        pde_list_head = tpde->next;
  316. X        if(tpde->next)
  317. X            (tpde->next)->prev = (PDE *)0;
  318. X    }
  319. X
  320. X    tpde->next = (PDE *)0;
  321. X    tpde->prev = (PDE *)0;
  322. X
  323. X    pde_list_quan--;
  324. X}    /* end of pde_list_remove */
  325. X
  326. X/*+-----------------------------------------------------------------------
  327. X    PDE *pde_list_search(logical,exact_flag)
  328. X------------------------------------------------------------------------*/
  329. XPDE *
  330. Xpde_list_search(logical,exact_flag)
  331. Xchar *logical;
  332. Xint exact_flag;
  333. X{
  334. Xregister PDE *tpde;
  335. X
  336. X    if(!pde_list_quan)
  337. X    {
  338. X        if(pde_list_read())
  339. X            return((PDE *)0);
  340. X    }
  341. X
  342. X    tpde = pde_list_head;
  343. X    while(tpde)
  344. X    {
  345. X        /* only first few chars necessary for match with ulcmpb */
  346. X        if(exact_flag)
  347. X        {
  348. X            if(strcmp(tpde->logical,logical) == 0)
  349. X                return(tpde);
  350. X        }
  351. X        else
  352. X        {
  353. X            if(ulcmpb(tpde->logical,logical) < 0)
  354. X                return(tpde);
  355. X        }
  356. X        tpde = tpde->next;
  357. X    }
  358. X    if(!tpde)
  359. X        sprintf(errmsg,"'%s' not found",logical);
  360. X    return(tpde);
  361. X
  362. X}    /* end of pde_list_search */
  363. X
  364. X/*+-------------------------------------------------------------------------
  365. X    want_pd_create(name)
  366. X--------------------------------------------------------------------------*/
  367. Xint
  368. Xwant_pd_create(name)
  369. Xchar *name;
  370. X{
  371. Xuchar itmp = 255;
  372. X
  373. X#ifdef COMPILER_BUG_FIXED
  374. X    dirw_bot_msg("type 'y' or 'n'");
  375. X    while(itmp == 255)
  376. X    {
  377. X        ring_bell();
  378. X        dirw_cmd_line_setup(name,"does not exist: create?");
  379. X        itmp = ttygetc(0);
  380. X        if(isupper(itmp))
  381. X            itmp = tolower(itmp);
  382. X        switch(itmp)
  383. X        {
  384. X            case 'y': itmp = 1; break;
  385. X            case 'n': itmp = 0; break;
  386. X            default: itmp = 255; break;        
  387. X        }
  388. X    }
  389. X    dirw_bot_msg("");
  390. X    return((int)itmp);
  391. X
  392. X#else
  393. X
  394. XKROCK:
  395. X    dirw_bot_msg("type 'y' or 'n'");
  396. X    ring_bell();
  397. X    dirw_cmd_line_setup(name,"does not exist: create?");
  398. X    itmp = ttygetc(0);
  399. X    dirw_bot_msg("");
  400. X    if(isupper(itmp))
  401. X        itmp = tolower(itmp);
  402. X    switch(itmp)
  403. X    {
  404. X        case 'y': return(1);
  405. X        case 'n': return(0);
  406. X    }
  407. X    goto KROCK;
  408. X#endif
  409. X}    /* end of want_pd_create */
  410. X
  411. X/*+-------------------------------------------------------------------------
  412. X    dirw_display_phonedir_name()
  413. X--------------------------------------------------------------------------*/
  414. Xvoid
  415. Xdirw_display_phonedir_name()
  416. X{
  417. Xregister itmp,x;
  418. Xchar s80[80];
  419. X
  420. X    if(!dirw || !phonedir_name[0])
  421. X        return;
  422. X
  423. X    wmove(dirw,0,phonedir_name_x);
  424. X    waddch(dirw,' ');
  425. X    strncpy(s80,phonedir_name,itmp = DIRW_COLS - phonedir_name_x - 5);
  426. X    s80[itmp] = 0;
  427. X    waddstr(dirw,s80);
  428. X    waddch(dirw,' ');
  429. X    getyx(dirw,itmp,x);
  430. X    while(x < DIRW_COLS - 1)
  431. X        waddch(dirw,sHR),x++;
  432. X
  433. X}    /* end of dirw_display_phonedir_name */
  434. X
  435. X/*+-----------------------------------------------------------------------
  436. X    pde_list_read()
  437. Xsample .ecu/phone:
  438. X#tri2:426-0624:2400:E:Tridom Pyramid        comment
  439. Xarc:393-3083:2400:N:Atlanta Radio Club
  440. X
  441. Xreturn 0 if entire list read, else 1 if error (error msg in errmsg)
  442. X------------------------------------------------------------------------*/
  443. Xint
  444. Xpde_list_read()
  445. X{
  446. Xregister token_number;
  447. Xregister char *cptr;
  448. Xregister char *token;
  449. Xint itmp;
  450. Xchar readpde_buf[128];
  451. XFILE *fp_phone;
  452. XPDE *tpde;
  453. Xchar *str_token();
  454. X
  455. X    if(!phonedir_name[0])
  456. X    {
  457. X        get_home_dir(phonedir_name);
  458. X        strcat(phonedir_name,"/.ecu/phone");
  459. X    }
  460. X
  461. XTRY_OPEN:
  462. X    if( (fp_phone = fopen(phonedir_name,"r")) == NULL)
  463. X    {
  464. X        if(errno == ENOENT)
  465. X        {
  466. X            if(!want_pd_create(phonedir_name))
  467. X            {
  468. X                strcpy(errmsg,"non-existent file not created");
  469. X                return(1);
  470. X            }
  471. X            if((itmp = open(phonedir_name,
  472. X                O_RDWR | O_CREAT | O_TRUNC,0600)) >= 0)
  473. X            {
  474. X                write(itmp,phonedir_trigger,strlen(phonedir_trigger));
  475. X                close(itmp);
  476. X                dirw_bot_msg("created new (empty) directory file");
  477. X                ring_bell();
  478. X                nap(1000L);
  479. X                goto TRY_OPEN;
  480. X            }
  481. X            if(errno == ENOENT)
  482. X            {
  483. X                strcpy(errmsg,"directory does not exist");
  484. X                ring_bell();
  485. X                return(1);
  486. X            }
  487. X        }
  488. X        strcpy(errmsg,sys_errlist[errno]);
  489. X        return(1);
  490. X    }
  491. X
  492. X/* we have an open directory file */
  493. X    if(!fgets(readpde_buf,sizeof(readpde_buf),fp_phone) ||
  494. X        strcmp(readpde_buf,phonedir_trigger))
  495. X    {
  496. X        fclose(fp_phone);
  497. X        strcpy(errmsg,"not an ECU phone directory (or is pre-rev-3)");
  498. X        ring_bell();
  499. X        return(1);
  500. X    }
  501. X
  502. X    dirw_display_phonedir_name();
  503. X    pde_list_erase();        /* clear any previous directory */
  504. X    while(fgets(readpde_buf,sizeof(readpde_buf),fp_phone) != NULL)
  505. X    {
  506. X        if(readpde_buf[0] == '#')        /* comment? */
  507. X            continue;
  508. X        if(itmp = strlen(readpde_buf))    /* itmp = len; if > 0 ... */
  509. X        {
  510. X            itmp--;
  511. X            readpde_buf[itmp] = 0;        /* ... strip trailing NL */
  512. X        }
  513. X        cptr = readpde_buf;                /* first call to str_token, -> buff */
  514. X        while((*cptr == 0x20) || (*cptr == TAB))
  515. X            cptr++;                        /* strip leading spaces */
  516. X        if(*cptr == 0)                    /* if line all blank, skip it */
  517. X            continue;
  518. X
  519. X        if(!(tpde = (PDE *)malloc(sizeof(PDE ))))
  520. X        {
  521. X            fclose(fp_phone);
  522. X            strcpy(errmsg,"Out of memory reading phone list");
  523. X            return(1);
  524. X        }
  525. X
  526. X        tpde->descr[0] = 0;
  527. X        tpde->logical[0] = 0;
  528. X        tpde->telno[0] = 0;
  529. X        tpde->tty[0] = 0;
  530. X        tpde->parity = 0;
  531. X        tpde->baud = 2400;
  532. X        tpde->redial = 0;
  533. X        tpde->prev = (PDE *)0;
  534. X        tpde->next = (PDE *)0;
  535. X
  536. X        token_number = 0;
  537. X        while((token = str_token(cptr,":")) != NULL)
  538. X        {
  539. X            cptr = NULL;    /* further calls to str_token need NULL */
  540. X            switch(token_number++)
  541. X            {
  542. X                case 0:        /* first field is logical name */
  543. X                    strncpy(tpde->logical,token,sizeof(tpde->logical));
  544. X                    tpde->logical[sizeof(tpde->logical) - 1] = 0;
  545. X                    break;
  546. X                case 1:        /* second field is tpde->telno phone number */
  547. X                    strncpy(tpde->telno,token,sizeof(tpde->telno));
  548. X                    tpde->telno[sizeof(tpde->telno) - 1] = 0;
  549. X                    break;
  550. X                case 2:        /* third field is line */
  551. X                    strncpy(tpde->tty,token,sizeof(tpde->tty));
  552. X                    tpde->tty[sizeof(tpde->tty) - 1] = 0;
  553. X                    break;
  554. X                case 3:        /* fourth field is baud rate */
  555. X                    tpde->baud = atoi(token);
  556. X                    break;
  557. X                case 4:        /* fifth field is parity */
  558. X                    switch(itmp = to_lower(token[0]))
  559. X                    {
  560. X                        case 'o':
  561. X                        case 'e':
  562. X                        case 'm':
  563. X                        case 's':
  564. X                            tpde->parity = itmp;
  565. X                            break;
  566. X                        default:
  567. X                        case 'n':
  568. X                            tpde->parity = 0;
  569. X                            break;
  570. X                    }
  571. X                    break;
  572. X                default:
  573. X                    strncpy(tpde->descr,token,sizeof(tpde->descr));
  574. X                    tpde->descr[sizeof(tpde->descr) - 1] = 0;
  575. X                    break;
  576. X            }    /* end of switch(token_number) */
  577. X        }        /* end while not end of record */
  578. X
  579. X        pde_list_add(tpde);
  580. X
  581. X    }            /* while records left to ready */
  582. X
  583. X    fclose(fp_phone);
  584. X    return(0);
  585. X}    /* end of pde_list_read */
  586. X
  587. X/*+-------------------------------------------------------------------------
  588. X    dirw_display_config()
  589. X--------------------------------------------------------------------------*/
  590. Xdirw_display_config()
  591. X{
  592. Xregister y,x;
  593. X
  594. X    wmove(dirw,DIRW_LINES - DIRW_BOT_LINES,0);
  595. X    waddch(dirw,sLT);
  596. X    getyx(dirw,y,x);
  597. X    while(x++ < (DIRW_COLS - 1))
  598. X        waddch(dirw,sHR);
  599. X    waddch(dirw,sRT);
  600. X    if(pde_marked_for_redial_count)
  601. X    {
  602. X        wmove(dirw,DIRW_LINES - DIRW_BOT_LINES,2);
  603. X        wstandout(dirw);
  604. X        wprintw(dirw," REDIAL CYCLE  wait: single=%d multiple=%d ",
  605. X            nap_decisec_single / 10,nap_decisec_multiple / 10);
  606. X
  607. X        wmove(dirw,DIRW_LINES - DIRW_BOT_LINES,56);
  608. X        wprintw(dirw," %2d marked entr%s ",
  609. X            pde_marked_for_redial_count,
  610. X            (pde_marked_for_redial_count == 1) ? "y" : "ies");
  611. X        wstandend(dirw);
  612. X    }
  613. X}    /* end of dirw_display_config */
  614. X
  615. X/*+-----------------------------------------------------------------------
  616. X    dirw_display()
  617. X00000000001111111111222222222233333333334444444444555555555566666666667777777777
  618. X01234567890123456789012345678901234567890123456789012345678901234567890123456789
  619. X| entry name | telephone number | tty | baud P | description                   |
  620. X| 0123456789 | 0123456789012345 | 01  | baud P | 01234567890123456789012345678 |
  621. X------------------------------------------------------------------------*/
  622. Xvoid
  623. Xdirw_display()
  624. X{
  625. X    wmove(dirw,1,1);
  626. X    wstandout(dirw);
  627. X    wprintw(dirw,
  628. X" entry name %c telephone number %c tty %c baud P %c description                   ",
  629. X        sVR,sVR,sVR,sVR);
  630. X    wstandend(dirw);
  631. X    dirw_display_phonedir_name();
  632. X    dirw_display_config();
  633. X    wrefresh(dirw);
  634. X}    /* end of dirw_display() */
  635. X
  636. X/*+-------------------------------------------------------------------------
  637. X    dirw_bot_msg(msg)
  638. X--------------------------------------------------------------------------*/
  639. Xvoid
  640. Xdirw_bot_msg(msg)
  641. Xchar *msg;
  642. X{
  643. Xregister itmp;
  644. Xregister itmp2;
  645. Xstatic last_msglen = 0;
  646. X#define DIRW_BOT_LINE_TLX 2
  647. X#define DIRW_BOT_LINE_MAX_MSGLEN    (DIRW_COLS - DIRW_BOT_LINE_TLX - 8)
  648. Xchar msg2[80];
  649. X
  650. X    if(!last_msglen && !strlen(msg))
  651. X        return;
  652. X
  653. X    wmove(dirw,DIRW_LINES - 1,DIRW_BOT_LINE_TLX);
  654. X
  655. X    if((itmp = strlen(msg)) == 0)
  656. X    {
  657. X        itmp2 = last_msglen + 2;
  658. X        for(itmp = 0; itmp < itmp2; itmp++)
  659. X            waddch(dirw,(unsigned)sHR);
  660. X        last_msglen = 0;
  661. X    }
  662. X    else
  663. X    {
  664. X        waddch(dirw,' ');
  665. X        if(itmp > DIRW_BOT_LINE_MAX_MSGLEN)
  666. X        {
  667. X            strncpy(msg2,msg,DIRW_BOT_LINE_MAX_MSGLEN);
  668. X            msg2[DIRW_BOT_LINE_MAX_MSGLEN + 1] = 0;
  669. X            waddstr(dirw,msg2);
  670. X            itmp = strlen(msg2);
  671. X        }
  672. X        else
  673. X        {
  674. X            waddstr(dirw,msg);
  675. X            itmp = strlen(msg);
  676. X        }
  677. X        waddch(dirw,' ');
  678. X        if((itmp2 = last_msglen - itmp) > 0)
  679. X        {
  680. X            while(itmp2--)
  681. X                waddch(dirw,(unsigned)sHR);
  682. X        }
  683. X        last_msglen = itmp;        /* remember last message length */
  684. X    }
  685. X    wrefresh(dirw);
  686. X}    /* end of dirw_bot_msg */
  687. X
  688. X/*+-------------------------------------------------------------------------
  689. X    pde_display_logical(line,tpde,stand_out)
  690. X--------------------------------------------------------------------------*/
  691. Xvoid
  692. Xpde_display_logical(line,tpde,stand_out)
  693. Xint line;
  694. XPDE *tpde;
  695. Xint stand_out;
  696. X{
  697. X    wmove(scrw,line,0);
  698. X    waddch(scrw,(unsigned)sVR);
  699. X
  700. X    if(tpde->redial)
  701. X    {
  702. X        wstandout(scrw);
  703. X        waddch(scrw,'>');
  704. X        wstandend(scrw);
  705. X    }
  706. X    else
  707. X        waddch(scrw,' ');
  708. X
  709. X    if(stand_out)
  710. X        wstandout(scrw);
  711. X    wprintw(scrw,"%-10.10s",tpde->logical);
  712. X    if(stand_out)
  713. X        wstandend(scrw);
  714. X
  715. X}    /* end of pde_display_logical */
  716. X
  717. X/*+-----------------------------------------------------------------------
  718. X    pde_display(win,line,tpde,stand_out)
  719. X00000000001111111111222222222233333333334444444444555555555566666666667777777777
  720. X01234567890123456789012345678901234567890123456789012345678901234567890123456789
  721. X| entry name | telephone number | tty | baud P | description                   |
  722. X| 0123456789 | 0123456789012345 | 01  | baud P | 01234567890123456789012345678 |
  723. X--------------------------------------------------------------------------*/
  724. Xpde_display(line,tpde,stand_out)
  725. Xint line;
  726. XPDE *tpde;
  727. Xint stand_out;
  728. X{
  729. X
  730. X    pde_display_logical(line,tpde,stand_out);
  731. X    waddch(scrw,' ');
  732. X    waddch(scrw,(unsigned)sVR);
  733. X    waddch(scrw,' ');
  734. X    wprintw(scrw,"%-16.16s %c ",tpde->telno,sVR);
  735. X    if(tpde->tty[0])
  736. X        wprintw(scrw,"%-2.2s  %c",tpde->tty,sVR);
  737. X    else
  738. X        wprintw(scrw,"Any %c",sVR);
  739. X    wprintw(scrw,"%5u %c %c ",tpde->baud,
  740. X        (tpde->parity) ? to_upper(tpde->parity) : 'N',sVR);
  741. X    wprintw(scrw,"%-29.29s %c",tpde->descr,sVR);
  742. X    return(0);
  743. X
  744. X}    /* end of pde_display */
  745. X
  746. X/*+-----------------------------------------------------------------------
  747. X    scrw_fill(first_pde,curr_pde_line)
  748. X------------------------------------------------------------------------*/
  749. Xvoid
  750. Xscrw_fill(tpde,curr_pde_line)
  751. Xregister PDE *tpde;
  752. Xint *curr_pde_line;
  753. X{
  754. Xregister line;
  755. Xregister is_curr_pde;
  756. X
  757. X    *curr_pde_line = -1;
  758. X    for(line = 0; line < SCRW_LINES; line++)
  759. X    {
  760. X        if(tpde)
  761. X        {
  762. X            if(is_curr_pde = (tpde == curr_pde))
  763. X                *curr_pde_line = line;
  764. X            pde_display(line,tpde,is_curr_pde);
  765. X            tpde = tpde->next;
  766. X        }
  767. X        else
  768. X        {
  769. X            wmove(scrw,line,0);
  770. X            waddch(scrw,(unsigned)sVR);
  771. X            wclrtoeol(scrw);
  772. X            wmove(scrw,line,SCRW_COLS - 1);
  773. X            waddch(scrw,(unsigned)sVR);
  774. X        }
  775. X    }
  776. X    wrefresh(scrw);
  777. X
  778. X}    /* end of scrw_fill */
  779. X
  780. X/*+-------------------------------------------------------------------------
  781. X    scrw_fill_at(line_num,first_pde,curr_pde_line)
  782. X--------------------------------------------------------------------------*/
  783. Xvoid
  784. Xscrw_fill_at(line_num,tpde,curr_pde_line)
  785. Xint line_num;
  786. Xregister PDE *tpde;
  787. Xint *curr_pde_line;
  788. X{
  789. Xregister itmp;
  790. X
  791. X    if(!tpde)
  792. X    {
  793. X        scrw_fill(tpde,curr_pde_line);
  794. X/*
  795. X        wclear(scrw);
  796. X        wrefresh(scrw);
  797. X*/
  798. X        return;
  799. X    }
  800. X    for(itmp = 0; itmp < line_num; itmp++)
  801. X    {
  802. X        if(!tpde->prev)
  803. X            break;
  804. X        tpde = tpde->prev;
  805. X    }
  806. X
  807. X    scrw_fill(tpde,curr_pde_line);
  808. X
  809. X}    /* end of scrw_fill_at */
  810. X
  811. X/*+-------------------------------------------------------------------------
  812. X    dirw_cmd_line_setup(prompt1,prompt2)
  813. X--------------------------------------------------------------------------*/
  814. Xvoid
  815. Xdirw_cmd_line_setup(prompt1,prompt2)
  816. Xchar *prompt1;
  817. Xchar *prompt2;
  818. X{
  819. Xregister icol;
  820. Xint y;
  821. Xint x;
  822. Xchar *cptr;
  823. Xint standout_mode;
  824. X
  825. X    wmove(dirw,DIRW_CMD_LINE - 1,1);
  826. X    wstandend(dirw);
  827. X    standout_mode = 0;
  828. X    waddch(dirw,' ');
  829. X    cptr = prompt1;
  830. X    while(*cptr)
  831. X    {
  832. X        if(*cptr == '~')
  833. X        {
  834. X            if(standout_mode)
  835. X                wstandend(dirw);
  836. X            else
  837. X                wstandout(dirw);
  838. X            standout_mode = !standout_mode;
  839. X            cptr++;
  840. X        }
  841. X        else
  842. X            waddch(dirw,*cptr++);
  843. X    }
  844. X    wstandend(dirw);
  845. X    standout_mode = 0;
  846. X
  847. X    waddch(dirw,' ');
  848. X    getyx(dirw,y,x);
  849. X    for(icol = x; icol < DIRW_COLS - 1; icol++)
  850. X        waddch(dirw,' ');
  851. X
  852. X    wmove(dirw,DIRW_CMD_LINE,1);
  853. X    waddch(dirw,' ');
  854. X    cptr = prompt2;
  855. X    while(*cptr)
  856. X    {
  857. X        if(*cptr == '~')
  858. X        {
  859. X            if(standout_mode)
  860. X                wstandend(dirw);
  861. X            else
  862. X                wstandout(dirw);
  863. X            standout_mode = !standout_mode;
  864. X            cptr++;
  865. X        }
  866. X        else
  867. X            waddch(dirw,*cptr++);
  868. X    }
  869. X    wstandend(dirw);
  870. X    waddch(dirw,' ');
  871. X    getyx(dirw,y,x);
  872. X    for(icol = x; icol < DIRW_COLS - 1; icol++)
  873. X        waddch(dirw,' ');
  874. X    wmove(dirw,y,x);
  875. X    wrefresh(dirw);
  876. X}    /* end of dirw_cmd_line_setup */
  877. X
  878. X/*+-------------------------------------------------------------------------
  879. X    dirw_get_cmd()
  880. X--------------------------------------------------------------------------*/
  881. Xuchar
  882. Xdirw_get_cmd(prompt)
  883. Xchar *prompt;
  884. X{
  885. Xregister uchar cmd;
  886. Xchar setupline1[128];    /* yetch ... avoid source line > 80 chars */
  887. Xchar *setupline1_1 = "~d~own ~u~p ~e~dit ~a~dd ~r~emove ~s~ave ~f~ind ";
  888. Xchar *setupline1_2 = "~c~hange dial dir ~ENTER~:dial ~ESC,q~uit";
  889. X
  890. X    strcpy(setupline1,setupline1_1);
  891. X    strcat(setupline1,setupline1_2);
  892. X
  893. X    dirw_cmd_line_setup(
  894. X        setupline1,
  895. X        "redial: ~m~ark un~M~ark ~U~nmark all ~w~ait between dial");
  896. X    cmd = ttygetc(1);
  897. X    dirw_bot_msg("");
  898. X    return(cmd);
  899. X
  900. X}    /* end of dirw_get_cmd */
  901. X
  902. X/*+-------------------------------------------------------------------------
  903. X    pde_cmd_save()
  904. X--------------------------------------------------------------------------*/
  905. Xvoid
  906. Xpde_cmd_save()
  907. X{
  908. XFILE *fpold;
  909. XFILE *fpnew;
  910. XPDE *tpde;
  911. Xchar phonedir_ntmp[256];        /* temp phone directory name */
  912. Xchar iobuf[128];
  913. Xint count = 0;
  914. X
  915. X    if(!pde_list_dirty)
  916. X    {
  917. X        dirw_bot_msg("directory has not been modified");
  918. X        return;
  919. X    }
  920. X
  921. X    strcpy(phonedir_ntmp,phonedir_name);
  922. X    strcat(phonedir_ntmp,".t");
  923. X
  924. X    if((fpnew = fopen(phonedir_ntmp,"w")) == NULL)    /* open old file */
  925. X    {
  926. X        sprintf(iobuf,"cannot open %s",phonedir_ntmp);
  927. X        dirw_bot_msg(iobuf);
  928. X        return;
  929. X    }
  930. X
  931. X/* write trigger */
  932. X    fputs(phonedir_trigger,fpnew);
  933. X
  934. X/* retain commented entries */
  935. X    if((fpold = fopen(phonedir_name,"r")) != NULL)    /* open old file */
  936. X    {
  937. X        while(fgets(iobuf,sizeof(iobuf),fpold) != NULL)
  938. X        {
  939. X            if((iobuf[0] == '#') && strcmp(iobuf,phonedir_trigger))
  940. X                fputs(iobuf,fpnew);
  941. X        }
  942. X        fclose(fpold);
  943. X    }
  944. X
  945. X/* write new entries */
  946. X    tpde = pde_list_head;
  947. X    while(tpde)
  948. X    {
  949. X        sprintf(iobuf,"%d",count+1);
  950. X        dirw_bot_msg(iobuf);
  951. X        sprintf(iobuf,"%s:%s:%s:%u:%c:%s\n",tpde->logical,tpde->telno,
  952. X            tpde->tty,tpde->baud,
  953. X            (tpde->parity) ? to_upper(tpde->parity) : 'N',
  954. X            tpde->descr);
  955. X        fputs(iobuf,fpnew);
  956. X        tpde = tpde->next;
  957. X        count++;
  958. X    }
  959. X
  960. X    fclose(fpnew);
  961. X    unlink(phonedir_name);
  962. X    rename(phonedir_ntmp,phonedir_name);
  963. X    sprintf(iobuf,"saved %d entries",count);
  964. X    dirw_bot_msg(iobuf);
  965. X    pde_list_set_dirty(0);
  966. X
  967. X}    /* end of pde_cmd_save */
  968. X
  969. X/*+-------------------------------------------------------------------------
  970. X    pde_list_save_if_dirty()
  971. X--------------------------------------------------------------------------*/
  972. Xvoid
  973. Xpde_list_save_if_dirty()
  974. X{
  975. Xuint cmd = 0;
  976. X
  977. X    if(pde_list_dirty)
  978. X    {
  979. X        dirw_bot_msg("type 'y' or 'n'");
  980. X        while(!cmd)
  981. X        {
  982. X            ring_bell();
  983. X            dirw_cmd_line_setup("","current directory modified: save?");
  984. X            cmd = ttygetc(0);
  985. X            if(isupper(cmd))
  986. X                cmd = tolower(cmd);
  987. X            switch(cmd)
  988. X            {
  989. X                case 'y': pde_cmd_save(); break;
  990. X                case 'n': break;
  991. X                default:
  992. X                    cmd = 0;
  993. X                    break;        
  994. X            }
  995. X        }
  996. X        dirw_bot_msg("");
  997. X    }
  998. X}    /* end of pde_list_save_if_dirty */
  999. X
  1000. X/*+-------------------------------------------------------------------------
  1001. X    pde_cmd_up()
  1002. X--------------------------------------------------------------------------*/
  1003. Xvoid
  1004. Xpde_cmd_up()
  1005. X{
  1006. Xregister PDE *tpde;
  1007. X
  1008. X    if((!curr_pde) || (curr_pde->prev == (PDE *)0))
  1009. X    {
  1010. X        ring_bell();
  1011. X        return;
  1012. X    }
  1013. X    if(scrw_curr_pde_line)
  1014. X    {
  1015. X        pde_display_logical(scrw_curr_pde_line,curr_pde,0);
  1016. X        scrw_curr_pde_line--;
  1017. X        curr_pde = curr_pde->prev;
  1018. X        pde_display_logical(scrw_curr_pde_line,curr_pde,1);
  1019. X    }
  1020. X    else
  1021. X    {
  1022. X        tpde = curr_pde;
  1023. X        curr_pde = curr_pde->prev;
  1024. X        scrw_fill_at(10,tpde,&scrw_curr_pde_line);
  1025. X    }
  1026. X
  1027. X}    /* end of pde_cmd_up */
  1028. X
  1029. X/*+-------------------------------------------------------------------------
  1030. X    pde_cmd_down()
  1031. X--------------------------------------------------------------------------*/
  1032. Xvoid
  1033. Xpde_cmd_down()
  1034. X{
  1035. Xregister itmp;
  1036. Xregister PDE *tpde;
  1037. X
  1038. X    if((!curr_pde) || (curr_pde->next == (PDE *)0))
  1039. X    {
  1040. X        ring_bell();
  1041. X        return;
  1042. X    }
  1043. X    if(scrw_curr_pde_line < (SCRW_LINES - 1))
  1044. X    {
  1045. X        pde_display_logical(scrw_curr_pde_line,curr_pde,0);
  1046. X        scrw_curr_pde_line++;
  1047. X        curr_pde = curr_pde->next;
  1048. X        pde_display_logical(scrw_curr_pde_line,curr_pde,1);
  1049. X    }
  1050. X    else
  1051. X    {
  1052. X        tpde = curr_pde;
  1053. X        curr_pde = curr_pde->next;
  1054. X        scrw_fill_at(SCRW_LINES - 10,tpde,&scrw_curr_pde_line);
  1055. X    }
  1056. X
  1057. X}    /* end of pde_cmd_down */
  1058. X
  1059. X/*+-------------------------------------------------------------------------
  1060. X    check_curr_pde() -- return 1 if there is a current pde, else 0
  1061. X--------------------------------------------------------------------------*/
  1062. Xcheck_curr_pde()
  1063. X{
  1064. X    if(!curr_pde)
  1065. X    {
  1066. X        dirw_bot_msg("no directory entry selected");
  1067. X        return(0);
  1068. X    }
  1069. X    return(1);
  1070. X}    /* end of check_curr_pde */
  1071. X
  1072. X/*+-------------------------------------------------------------------------
  1073. X    pde_add_or_edit_read(prompt,edit,x,buf,max,delim)
  1074. Xmax must not wrap around to another line
  1075. X--------------------------------------------------------------------------*/
  1076. Xpde_add_or_edit_read(prompt,edit,x,buf,max,delim)
  1077. Xchar *prompt;
  1078. Xint edit;
  1079. Xint x;
  1080. Xchar *buf;
  1081. Xint max;
  1082. Xchar *delim;
  1083. X{
  1084. Xregister itmp;
  1085. Xchar s82[82];
  1086. X
  1087. X    while(1)
  1088. X    {
  1089. X        dirw_cmd_line_setup("",prompt);
  1090. X        wstandout(scrw);
  1091. X        if(edit)
  1092. X            strcpy(s82,buf);
  1093. X        itmp = wingets(scrw,scrw_curr_pde_line,x,s82,max,delim,edit);
  1094. X        wstandend(scrw);
  1095. X        
  1096. X        switch(*delim)
  1097. X        {
  1098. X            case ESC:
  1099. X                return;
  1100. X
  1101. X            case CR:
  1102. X            case NL:
  1103. X                if(edit && (itmp == 0))
  1104. X                {
  1105. X                    *delim = TAB;
  1106. X                    return;
  1107. X                }
  1108. X                strcpy(buf,s82);
  1109. X                return;
  1110. X
  1111. X            case CTL_B:
  1112. X                *buf = 0;
  1113. X                return;
  1114. X
  1115. X            case TAB:
  1116. X                if(!edit)
  1117. X                    continue;
  1118. X                *buf = 0;
  1119. X                return;
  1120. X
  1121. X            default:
  1122. X                break;
  1123. X        }
  1124. X    }
  1125. X}    /* end of pde_add_or_edit_read */
  1126. X
  1127. X/*+-------------------------------------------------------------------------
  1128. X    pde_add_or_edit(tpde,edit)
  1129. Xif called with edit == 1, tpde MUST == curr_pde !!!
  1130. X00000000001111111111222222222233333333334444444444555555555566666666667777777777
  1131. X01234567890123456789012345678901234567890123456789012345678901234567890123456789
  1132. X| entry name | telephone number | tty | baud P | description                   |
  1133. X| 0123456789 | 0123456789012345 | 01  | baud P | 01234567890123456789012345678 |
  1134. X--------------------------------------------------------------------------*/
  1135. Xint
  1136. Xpde_add_or_edit(tpde,edit)
  1137. Xregister PDE *tpde;
  1138. Xint edit;
  1139. X{
  1140. Xregister itmp;
  1141. Xint input_state = 0;
  1142. Xint changed;
  1143. Xchar s50[50];
  1144. Xchar delim;
  1145. Xint done = 0;
  1146. Xint y,x;
  1147. XPDE *old_curr_pde;
  1148. Xuint baud;
  1149. X
  1150. X    if(!edit)
  1151. X    {
  1152. X        dirw_bot_msg("ESC: abort  ^U: erase input");
  1153. X        dirw_cmd_line_setup("","Enter new directory entry name: ");
  1154. X        getyx(dirw,y,x);
  1155. X        wstandout(dirw);
  1156. X        wingets(dirw,y,x,tpde->logical,10+1,&delim,0);
  1157. X        wstandend(dirw);
  1158. X        dirw_bot_msg("");
  1159. X        if((!strlen(tpde->logical)) || (tpde->logical[0] == ESC))
  1160. X        {
  1161. X            dirw_bot_msg("add aborted");
  1162. X            return(0);
  1163. X        }
  1164. X    
  1165. X        if(!isalpha(tpde->logical[0]))
  1166. X        {
  1167. X            dirw_bot_msg("first character must be alphabetic");
  1168. X            return(0);
  1169. X        }
  1170. X
  1171. X        if(pde_list_search(tpde->logical,1))
  1172. X        {
  1173. X            sprintf(s50,"'%s' is already in the directory",tpde->logical);
  1174. X            ring_bell();
  1175. X            dirw_bot_msg(s50);
  1176. X            return(0);
  1177. X        }
  1178. X
  1179. X        tpde->descr[0] = 0;
  1180. X        tpde->telno[0] = 0;
  1181. X        tpde->tty[0] = 0;
  1182. X        tpde->parity = '-';
  1183. X        tpde->baud = 0;                
  1184. X    
  1185. X        pde_list_add(tpde);
  1186. X        old_curr_pde = curr_pde;
  1187. X        curr_pde = tpde;
  1188. X        scrw_fill_at(SCRW_LINES / 2,tpde,&scrw_curr_pde_line);
  1189. X        tpde = curr_pde;
  1190. X    }    /* end of add code */
  1191. X
  1192. X    if(edit)
  1193. X        dirw_bot_msg("ESC: exit  ^U: erase input  ^B: back  TAB: forward");
  1194. X    else
  1195. X        dirw_bot_msg("ESC: abort  ^U: erase input  ^B: back up");
  1196. X
  1197. X/* add/edit common */
  1198. X    while(!done)
  1199. X    {
  1200. X        changed = 0;
  1201. X        switch(input_state)
  1202. X        {
  1203. X            case 0:
  1204. X                if(edit)
  1205. X                    strcpy(s50,tpde->telno);
  1206. X                pde_add_or_edit_read("Enter telephone number",
  1207. X                    edit,15,tpde->telno,16+1,&delim);
  1208. X                if(edit && strcmp(tpde->telno,s50))
  1209. X                    changed = 1;
  1210. X                break;
  1211. X
  1212. X            case 1:
  1213. X                if(edit)
  1214. X                    strcpy(s50,(tpde->tty[0]) ? tpde->tty : "Any");
  1215. X                pde_add_or_edit_read("Enter tty identifier (i.e., 1a)",
  1216. X                    edit,34,s50,3+1,&delim);
  1217. X                if(edit && strcmp((tpde->tty[0]) ? tpde->tty : "Any",s50))
  1218. X                    changed = 1;
  1219. X                if(!strcmpi(s50,"any"))
  1220. X                    tpde->tty[0] = 0;
  1221. X                else
  1222. X                {
  1223. X                    strncpy(tpde->tty,s50,2);
  1224. X                    tpde->tty[2] = 0;
  1225. X                }
  1226. X                break;
  1227. X
  1228. X            case 2:
  1229. X                if(edit)
  1230. X                    sprintf(s50,"%u",tpde->baud);
  1231. X                pde_add_or_edit_read(
  1232. X                "Enter baud rate (110,300,600,1200,2400,4800,9600,19200,38400)",
  1233. X                    edit,39,s50,5+1,&delim);
  1234. X                if(valid_baud_rate(baud = atoi(s50)) < 0)
  1235. X                {
  1236. X                    ring_bell();
  1237. X                    continue;
  1238. X                }
  1239. X                if(edit && (tpde->baud != baud ))
  1240. X                    changed = 1;
  1241. X                tpde->baud = baud;
  1242. X                break;
  1243. X
  1244. X            case 3:
  1245. X                if(edit)
  1246. X                    sprintf(s50,"%c",(tpde->parity) ? tpde->parity : 'n');
  1247. X                pde_add_or_edit_read("Enter parity (n,o,e)",
  1248. X                    edit,45,s50,1+1,&delim);
  1249. X                switch(s50[0] = to_lower(s50[0]))
  1250. X                {
  1251. X                    case 'n':
  1252. X                        s50[0] = 0;
  1253. X                    case 'o':
  1254. X                    case 'e':
  1255. X                        if(edit && (tpde->parity != s50[0]))
  1256. X                            changed = 1;
  1257. X                        tpde->parity = s50[0];
  1258. X                        break;
  1259. X                    default:
  1260. X                        ring_bell();
  1261. X                        continue;
  1262. X                }
  1263. X                break;
  1264. X
  1265. X            case 4:
  1266. X                if(edit)
  1267. X                    strcpy(s50,tpde->descr);
  1268. X                pde_add_or_edit_read("Enter description",
  1269. X                    edit,49,tpde->descr,29+1,&delim);
  1270. X                if(edit && strcmp(tpde->descr,s50))
  1271. X                    changed = 1;
  1272. X                break;
  1273. X        }
  1274. X
  1275. X        pde_display(scrw_curr_pde_line,tpde,1);    /* regardless of delimiter */
  1276. X
  1277. X        switch(delim) /* process delimiter */
  1278. X        {
  1279. X            case CTL_L:
  1280. X            case CTL_R:
  1281. X                tcap_clear_screen();
  1282. X                touchwin(stdscr);
  1283. X                wrefresh(stdscr);
  1284. X                touchwin(dirw);
  1285. X                wrefresh(dirw);
  1286. X                touchwin(scrw);
  1287. X                wrefresh(scrw);
  1288. X                break;
  1289. X
  1290. X            case CTL_B:
  1291. X                if(input_state)
  1292. X                    input_state--;
  1293. X                break;
  1294. X
  1295. X            case TAB:
  1296. X                input_state++;
  1297. X                input_state %= 5;
  1298. X                break;
  1299. X
  1300. X            case ESC:
  1301. X                if(edit)
  1302. X                {
  1303. X                    dirw_bot_msg("edit finished");
  1304. X                    done = 1;
  1305. X                }
  1306. X                else
  1307. X                {
  1308. X                    pde_list_remove(tpde);
  1309. X                    curr_pde = old_curr_pde;
  1310. X                    scrw_fill_at(scrw_curr_pde_line + 1,curr_pde,
  1311. X                            &scrw_curr_pde_line);
  1312. X                    dirw_bot_msg("add aborted");
  1313. X                    return(0);
  1314. X                }
  1315. X                break;
  1316. X
  1317. X            case NL:
  1318. X                if(edit && changed)
  1319. X                    pde_list_set_dirty(1);
  1320. X                /* fall thru */
  1321. X            default:
  1322. X                if(!edit && (input_state == 4))
  1323. X                    done = 1;
  1324. X                else 
  1325. X                {
  1326. X                    input_state++;
  1327. X                    input_state %= 5;
  1328. X                }
  1329. X                break;
  1330. X        }
  1331. X    }
  1332. X    return(1);
  1333. X
  1334. X}    /* end of pde_add_or_edit */
  1335. X
  1336. X/*+-------------------------------------------------------------------------
  1337. X    pde_cmd_add(tpde)
  1338. Xif tpde != 0, it is an already valid pde that is to be added
  1339. Xelse if == 0, interactive add
  1340. X--------------------------------------------------------------------------*/
  1341. Xvoid
  1342. Xpde_cmd_add(tpde)
  1343. Xregister PDE *tpde;
  1344. X{
  1345. Xregister itmp;
  1346. X
  1347. X    if(tpde)
  1348. X    {
  1349. X        pde_list_add(tpde);
  1350. X    }
  1351. X    else
  1352. X    {
  1353. X        if(!(tpde = (PDE *)malloc(sizeof(PDE ))))
  1354. X        {
  1355. X            dirw_bot_msg("Out of memory -- cannot add new entry");
  1356. X            return;
  1357. X        }
  1358. X        if(!pde_add_or_edit(tpde,0))    /* routine will add to list ... */
  1359. X        {                                /* ... if good return */
  1360. X            free((char *)tpde);
  1361. X            return;
  1362. X        }
  1363. X    }
  1364. X    pde_list_set_dirty(1);
  1365. X
  1366. X    curr_pde = tpde;
  1367. X    scrw_fill_at(SCRW_LINES / 2,curr_pde,&scrw_curr_pde_line);
  1368. X
  1369. X}    /* end of pde_cmd_add */
  1370. X
  1371. X/*+-------------------------------------------------------------------------
  1372. X    pde_cmd_mark(tpde) - mark for redial
  1373. X--------------------------------------------------------------------------*/
  1374. Xvoid
  1375. Xpde_cmd_mark(tpde)
  1376. Xregister PDE *tpde;
  1377. X{
  1378. X
  1379. X    if(!tpde)
  1380. X        return;
  1381. X    if(!tpde->redial)
  1382. X    {
  1383. X        tpde->redial = 1;
  1384. X        if(tpde == curr_pde)
  1385. X            pde_display_logical(scrw_curr_pde_line,curr_pde,1);
  1386. X        pde_marked_for_redial_count++;
  1387. X        dirw_display_config();
  1388. X    }
  1389. X
  1390. X}    /* end of pde_cmd_mark */
  1391. X
  1392. X/*+-------------------------------------------------------------------------
  1393. X    pde_cmd_unmark(tpde) - unmark for redial
  1394. X--------------------------------------------------------------------------*/
  1395. Xvoid
  1396. Xpde_cmd_unmark(tpde)
  1397. Xregister PDE *tpde;
  1398. X{
  1399. X
  1400. X    if(!tpde)
  1401. X        return;
  1402. X    if(tpde->redial)
  1403. X    {
  1404. X        tpde->redial = 0;
  1405. X        if(tpde == curr_pde)
  1406. X            pde_display_logical(scrw_curr_pde_line,curr_pde,1);
  1407. X        pde_marked_for_redial_count--;
  1408. X        dirw_display_config();
  1409. X    }
  1410. X
  1411. X}    /* end of pde_cmd_unmark */
  1412. X
  1413. X/*+-------------------------------------------------------------------------
  1414. X    pde_cmd_unmark_all() - unmark for redial all PDEs
  1415. X--------------------------------------------------------------------------*/
  1416. Xvoid
  1417. Xpde_cmd_unmark_all()
  1418. X{
  1419. Xregister PDE *tpde;
  1420. Xregister y;
  1421. X
  1422. X    tpde = pde_list_head;
  1423. X    while(tpde)
  1424. X    {
  1425. X        tpde->redial = 0;
  1426. X        tpde = tpde->next;
  1427. X    }
  1428. X
  1429. X    for(y = 0; y < SCRW_LINES; y++)
  1430. X    {
  1431. X        wmove(scrw,y,1);
  1432. X        waddch(scrw,' ');
  1433. X    }
  1434. X    pde_marked_for_redial_count = 0;
  1435. X    dirw_display_config();
  1436. X
  1437. X}    /* end of pde_cmd_unmark_all */
  1438. X
  1439. X/*+-------------------------------------------------------------------------
  1440. X    pde_cmd_remove_oops()
  1441. X--------------------------------------------------------------------------*/
  1442. Xvoid
  1443. Xpde_cmd_remove_oops()
  1444. X{
  1445. X    if(!remove_pde)
  1446. X    {
  1447. X        dirw_bot_msg("no removed entry to restore");
  1448. X        return;
  1449. X    }
  1450. X    pde_cmd_add(remove_pde);
  1451. X    pde_list_set_dirty(remove_dirty_flag);
  1452. X    remove_pde = (PDE *)0;
  1453. X}    /* end of pde_cmd_remove_oops */
  1454. X
  1455. X/*+-------------------------------------------------------------------------
  1456. X    pde_cmd_remove()
  1457. X--------------------------------------------------------------------------*/
  1458. Xvoid
  1459. Xpde_cmd_remove()
  1460. X{
  1461. Xregister itmp;
  1462. Xregister PDE *tpde;
  1463. Xchar s80[80];
  1464. X
  1465. X    if(!check_curr_pde())
  1466. X        return;
  1467. X
  1468. X    remove_pde = curr_pde;
  1469. X    remove_dirty_flag = pde_list_dirty;
  1470. X    pde_list_remove(curr_pde);
  1471. X    pde_list_set_dirty(1);
  1472. X
  1473. X    if(pde_list_quan)
  1474. X        scrw_fill_at(scrw_curr_pde_line + 1,curr_pde,&scrw_curr_pde_line);
  1475. X    else
  1476. X        scrw_fill((PDE *)0,&scrw_curr_pde_line);
  1477. X
  1478. X    ring_bell();
  1479. X    sprintf(s80,"if you did not mean to to remove '%s', press 'o' (oops) NOW!",
  1480. X            remove_pde->logical);
  1481. X    dirw_bot_msg(s80);
  1482. X
  1483. X}    /* end of pde_cmd_remove */
  1484. X
  1485. X/*+-------------------------------------------------------------------------
  1486. X    pde_cmd_find()
  1487. X--------------------------------------------------------------------------*/
  1488. Xvoid
  1489. Xpde_cmd_find()
  1490. X{
  1491. Xregister itmp;
  1492. Xregister PDE *tpde;
  1493. Xchar findname[12];
  1494. Xchar delim;
  1495. Xint y,x;
  1496. X
  1497. X    dirw_bot_msg("ESC: abort  ^U: erase input");
  1498. X    dirw_cmd_line_setup("","Directory entry name to find: ");
  1499. X    getyx(dirw,y,x);
  1500. X    wstandout(dirw);
  1501. X    wingets(dirw,y,x,findname,10+1,&delim,0);
  1502. X    wstandend(dirw);
  1503. X    dirw_bot_msg("");
  1504. X    if((!strlen(findname)) || (delim == ESC))
  1505. X        return;
  1506. X
  1507. X    if(! (tpde = pde_list_search(findname,0)))
  1508. X    {
  1509. X        dirw_bot_msg(errmsg);
  1510. X        return;
  1511. X    }
  1512. X    curr_pde = tpde;
  1513. X    scrw_fill_at(SCRW_LINES / 2,tpde,&scrw_curr_pde_line);
  1514. X
  1515. X}    /* end of pde_cmd_find */
  1516. X
  1517. X/*+-------------------------------------------------------------------------
  1518. X    pde_cmd_change_dir()
  1519. X--------------------------------------------------------------------------*/
  1520. Xpde_cmd_change_dir()
  1521. X{
  1522. Xregister itmp;
  1523. Xregister PDE *tpde;
  1524. Xchar newdirname[256];
  1525. Xchar buf[256];
  1526. Xchar delim;
  1527. Xint y,x;
  1528. Xchar *expcmd;
  1529. Xextern char *sys_errlist[];
  1530. Xextern char errmsg[];
  1531. X
  1532. X    pde_list_save_if_dirty();
  1533. X    dirw_bot_msg("ESC: abort  ^U: erase input");
  1534. X    dirw_cmd_line_setup(" Enter new directory name:","");
  1535. X    getyx(dirw,y,x);
  1536. X    wstandout(dirw);
  1537. X    wingets(dirw,y,x,buf,70+1,&delim,0);
  1538. X    wstandend(dirw);
  1539. X    dirw_bot_msg("");
  1540. X    if((!strlen(buf)) || (delim == ESC))
  1541. X        return;
  1542. X
  1543. X    if((buf[0] == '~') || (buf[0] == '.') || (buf[0] == '/'))
  1544. X        strcpy(newdirname,buf);
  1545. X    else
  1546. X    {
  1547. X        get_curr_dir(newdirname,sizeof(newdirname));
  1548. X        strcat(newdirname,"/");
  1549. X        strcat(newdirname,buf);
  1550. X    }
  1551. X    if(find_shell_chars(newdirname))
  1552. X    {
  1553. X    char *expcmd;
  1554. X
  1555. X        if(expand_cmd_with_wildlist(newdirname,&expcmd))
  1556. X        {
  1557. X            dirw_bot_msg(expcmd);
  1558. X            ring_bell();
  1559. X            return;
  1560. X        }
  1561. X        strncpy(newdirname,expcmd,sizeof(newdirname) - 1);
  1562. X        newdirname[sizeof(newdirname) - 1] = 0;
  1563. X        free(expcmd);
  1564. X    }
  1565. X
  1566. X    if(access(newdirname,4))
  1567. X    {
  1568. X        if(errno == ENOENT)
  1569. X        {
  1570. X            if(!want_pd_create(newdirname))
  1571. X            {
  1572. X                dirw_bot_msg("non-existent file not created");
  1573. X                return;
  1574. X            }
  1575. X            if((itmp = open(newdirname,O_RDWR | O_CREAT | O_TRUNC,0600)) >= 0)
  1576. X            {
  1577. X                write(itmp,phonedir_trigger,strlen(phonedir_trigger));
  1578. X                close(itmp);
  1579. X                dirw_bot_msg("created new (empty) directory file");
  1580. X                ring_bell();
  1581. X                nap(1000L);
  1582. X                goto READ_LIST;
  1583. X            }
  1584. X            if(errno == ENOENT)
  1585. X            {
  1586. X                dirw_bot_msg("directory does not exist");
  1587. X                ring_bell();
  1588. X                return;
  1589. X            }
  1590. X        }
  1591. X        dirw_bot_msg(sys_errlist[errno]);
  1592. X        ring_bell();
  1593. X        return;
  1594. X    }
  1595. X
  1596. XREAD_LIST:
  1597. X    strcpy(phonedir_name,newdirname);
  1598. X    if(pde_list_read())
  1599. X    {
  1600. X        dirw_bot_msg(errmsg);
  1601. X        return;
  1602. X    }
  1603. X    curr_pde = pde_list_head;
  1604. X    scrw_fill(curr_pde,&scrw_curr_pde_line);
  1605. X    if(!pde_list_quan)
  1606. X    {
  1607. X        dirw_bot_msg("directory empty");
  1608. X        return;
  1609. X    }
  1610. X
  1611. X}    /* end of pde_cmd_change_dir */
  1612. X
  1613. X/*+-------------------------------------------------------------------------
  1614. X    pde_dial(tpde) - dial a pde (using procedure if configured)
  1615. Xreturns status ==  DCE_dial $i0 value ($s0 is also set, BTW)
  1616. Xassumes rcvr process dead (rcvr_pid == -1)
  1617. X--------------------------------------------------------------------------*/
  1618. Xint
  1619. Xpde_dial(tpde)
  1620. Xregister PDE *tpde;
  1621. X{
  1622. Xint status;
  1623. X
  1624. X#ifdef AUTO_DIAL_PROC
  1625. X    if(proc_level || !find_procedure(tpde->logical))
  1626. X        status = DCE_dial_pde(tpde);
  1627. X    else
  1628. X    {
  1629. X    char *pargv[2];
  1630. X        pargv[0] = tpde->logical;
  1631. X        pargv[1] = "!MENU";
  1632. X        if(do_proc(2,pargv))
  1633. X            status = 1;
  1634. X    }
  1635. X#else
  1636. X    status = DCE_dial_pde(tpde);
  1637. X#endif
  1638. X    interrupt = 0;
  1639. X    return(status);
  1640. X
  1641. X}    /* end of pde_dial */
  1642. X
  1643. X/*+-------------------------------------------------------------------------
  1644. X    pde_dial_cycle()
  1645. Xreturn 1 if connect occurs, 0 if cycle expires or interrupted
  1646. X--------------------------------------------------------------------------*/
  1647. Xint
  1648. Xpde_dial_cycle()
  1649. X{
  1650. Xregister PDE *tpde = pde_list_head;
  1651. Xuint ans;
  1652. Xint nap_decisec;
  1653. X
  1654. X    if(!tpde || !pde_list_quan)
  1655. X    {
  1656. X        ring_bell();
  1657. X        return(0);
  1658. X    }
  1659. X
  1660. X    if(!pde_marked_for_redial_count)
  1661. X    {
  1662. X        pde_dial(curr_pde);
  1663. X        return(!(int)iv[0]);
  1664. X    }
  1665. X
  1666. X    ff(se,"\r\nbeginning cycle through %d marked redial entries\r\n",
  1667. X        pde_marked_for_redial_count);
  1668. X    while(1)    /* forever until a connect or interrupt */
  1669. X    {
  1670. X        if(tpde->redial)
  1671. X        {
  1672. X            pde_dial(tpde);
  1673. X            switch((int)iv[0])
  1674. X            {
  1675. X                case 0:        /* CONNECTED */
  1676. X                    tpde->redial = 0;
  1677. X                    pde_marked_for_redial_count--;
  1678. X                    bell_notify(XBELL_C);
  1679. X                    return(1);
  1680. X                case 2:        /* INTERRUPTED */
  1681. X                    ff(se,"\r\ndial interrupted: abort cycle (y,n)?  ");
  1682. X                    interrupt = 0;
  1683. X                    ans = 0;
  1684. X                    while(ans == 0)
  1685. X                    {
  1686. X                        switch(ans = to_lower(ttygetc(1)))
  1687. X                        {
  1688. X                            case 'y':
  1689. X                                ff(se,"YES\r\n");
  1690. X                                goto ABORT_CYCLE;
  1691. X                            case 'n':
  1692. X                                ff(se,"NO\r\n");
  1693. X                                break;
  1694. X                            default: 
  1695. X                                ring_bell();
  1696. X                                ans = 0;
  1697. X                        }
  1698. X                    }
  1699. X                    break;
  1700. X                case 1:        /* FAILED TO CONNECT */
  1701. X                case 3:        /* MODEM ERROR */
  1702. X                default:
  1703. X                    if(pde_marked_for_redial_count == 1)
  1704. X                        nap_decisec = nap_decisec_single;
  1705. X                    else
  1706. X                        nap_decisec = nap_decisec_multiple;
  1707. X                    ff(se,
  1708. X                    "waiting %d seconds ... 'c' to cycle, %s to abort\r\n",
  1709. X                        nap_decisec/10,
  1710. X                        (kbdintr == DEL) ?"DEL":make_char_graphic(kbdintr,0));
  1711. X                    while(nap_decisec--)
  1712. X                    {
  1713. X                        nap(100L);
  1714. X                        if(rdchk(0))
  1715. X                        {
  1716. X                            ans = to_lower(ttygetc(1));
  1717. X                            ttyflush(0);
  1718. X                            if(ans == 'c')
  1719. X                                goto CONTINUE_CYCLE;
  1720. X                            else if(ans == kbdintr)
  1721. X                                goto ABORT_CYCLE;
  1722. X                            else
  1723. X                                ring_bell();
  1724. X                        }
  1725. X                        if(interrupt)
  1726. X                            goto ABORT_CYCLE;
  1727. X                    }
  1728. X                    break;
  1729. X            }
  1730. X        }
  1731. XCONTINUE_CYCLE:
  1732. X        tpde = tpde->next;
  1733. X        if(!tpde)
  1734. X            tpde = pde_list_head;
  1735. X    }
  1736. X    /*NOTREACHED*/
  1737. X    return(0);    /* but just in case */
  1738. X
  1739. XABORT_CYCLE:
  1740. X    interrupt = 0;
  1741. X    ff(se,"redial cycle ABORTED\r\n");
  1742. X    return(0);
  1743. X
  1744. X}    /* end of pde_dial_cycle */
  1745. X
  1746. X/*+-------------------------------------------------------------------------
  1747. X    pde_cmd_set_wait()
  1748. X--------------------------------------------------------------------------*/
  1749. Xpde_cmd_set_wait()
  1750. X{
  1751. Xchar buf[64];
  1752. Xchar delim;
  1753. Xint y,x;
  1754. X
  1755. X    dirw_bot_msg("ESC: abort  ^U: erase input");
  1756. X    sprintf(buf,"(Must be greater than or equal to %d seconds)",
  1757. X        NAP_DECISEC_SINGLE_MIN / 10);
  1758. X    dirw_cmd_line_setup(buf,"Wait between dials when one entry marked:");
  1759. X    getyx(dirw,y,x);
  1760. X    sprintf(buf,"%d",nap_decisec_single / 10);
  1761. X    wstandout(dirw);
  1762. X    wingets(dirw,y,x,buf,3+1,&delim,1);
  1763. X    wstandend(dirw);
  1764. X    if((!strlen(buf)) || (delim == ESC))
  1765. X    {
  1766. X        dirw_bot_msg("");
  1767. X        return;
  1768. X    }
  1769. X    nap_decisec_single = 0;
  1770. X    sscanf(buf,"%d",&nap_decisec_single);
  1771. X    nap_decisec_single *= 10;
  1772. X    if(nap_decisec_single <  NAP_DECISEC_SINGLE_MIN)
  1773. X        nap_decisec_single = NAP_DECISEC_SINGLE_MIN;
  1774. X    dirw_display_config();
  1775. X
  1776. X    sprintf(buf,"(Must be greater than or equal to %d seconds)",
  1777. X        NAP_DECISEC_MULTIPLE_MIN / 10);
  1778. X    dirw_cmd_line_setup(buf,"Wait between dials when multiple entries marked:");
  1779. X    getyx(dirw,y,x);
  1780. X    sprintf(buf,"%d",nap_decisec_multiple / 10);
  1781. X    wstandout(dirw);
  1782. X    wingets(dirw,y,x,buf,3+1,&delim,1);
  1783. X    wstandend(dirw);
  1784. X    if((!strlen(buf)) || (delim == ESC))
  1785. X    {
  1786. X        dirw_bot_msg("");
  1787. X        return;
  1788. X    }
  1789. X    nap_decisec_multiple = 0;
  1790. X    sscanf(buf,"%d",&nap_decisec_multiple);
  1791. X    nap_decisec_multiple *= 10;
  1792. X    if(nap_decisec_multiple <  NAP_DECISEC_MULTIPLE_MIN)
  1793. X        nap_decisec_multiple = NAP_DECISEC_MULTIPLE_MIN;
  1794. X    dirw_display_config();
  1795. X
  1796. X    dirw_bot_msg("");
  1797. X
  1798. X}    /* end of pde_cmd_set_wait */
  1799. X
  1800. X/*+-------------------------------------------------------------------------
  1801. X    pde_list_manager()
  1802. X--------------------------------------------------------------------------*/
  1803. Xvoid
  1804. Xpde_list_manager()
  1805. X{
  1806. Xregister uchar cmd = 0;
  1807. Xint done;
  1808. Xchar s80[80];
  1809. XWINDOW *window_create();
  1810. Xint rcvr_was_active = (rcvr_pid > 0) || (rcvr_pid == -2);
  1811. X
  1812. X    kill_rcvr_process(SIGUSR1);
  1813. X    rcvr_pid = -1;
  1814. X
  1815. X    windows_start();
  1816. X    dirw = window_create("dialing directory",3,0,0,DIRW_LINES,DIRW_COLS);
  1817. X    phonedir_name_x = 26;    /* must be set before calling dirw_display */
  1818. X    dirw_display();
  1819. X
  1820. X    scrw = subwin(dirw,SCRW_LINES,SCRW_COLS,SCRW_TLY,SCRW_TLX);
  1821. X    scrollok(scrw,0);
  1822. X    if(!pde_list_quan)
  1823. X    {
  1824. X        if(pde_list_read())
  1825. X            dirw_bot_msg(errmsg);
  1826. X        else if(!pde_list_quan)
  1827. X            dirw_bot_msg("directory empty");
  1828. X    }
  1829. X
  1830. X    if(pde_list_quan)
  1831. X    {
  1832. X        if(curr_pde)
  1833. X            scrw_fill_at(scrw_curr_pde_line,curr_pde,&scrw_curr_pde_line);
  1834. X        else
  1835. X        {
  1836. X            curr_pde = pde_list_head;
  1837. X            scrw_fill(curr_pde,&scrw_curr_pde_line);
  1838. X        }
  1839. X    }
  1840. X
  1841. X    pde_list_set_dirty(-1);
  1842. X
  1843. X    done = 0;
  1844. X    while(!done)
  1845. X    {
  1846. X        cmd = dirw_get_cmd(
  1847. X    "d,j:down u,k:up e:edit a:add r:remove s:save f:find END:dial ESC,q:quit");
  1848. X        if((cmd != 'o') && (remove_pde))
  1849. X        {
  1850. X            free((char *)remove_pde);
  1851. X            remove_pde = (PDE *)0;
  1852. X        }
  1853. X
  1854. X        switch(cmd)
  1855. X        {
  1856. X            case XFcurdn:
  1857. X            case 'd':
  1858. X            case 'j': pde_cmd_down(); break;
  1859. X
  1860. X            case XFcurup:
  1861. X            case 'u':
  1862. X            case 'k': pde_cmd_up(); break;
  1863. X
  1864. X            case 's': pde_cmd_save(); break;
  1865. X
  1866. X            case 'm': pde_cmd_mark(curr_pde); break;
  1867. X            case 'M': pde_cmd_unmark(curr_pde); break;
  1868. X            case 'U': pde_cmd_unmark_all(); break;
  1869. X            case 'c': pde_cmd_change_dir(); break;
  1870. X
  1871. X            case 'w': pde_cmd_set_wait(); break;
  1872. X
  1873. X            case CR:
  1874. X            case NL:
  1875. X                cmd = CR;
  1876. X                if(!check_curr_pde())
  1877. X                    break;
  1878. X                pde_list_save_if_dirty();
  1879. X                windows_end(dirw);
  1880. X                dirw = (WINDOW *)0;
  1881. X                scrw = (WINDOW *)0;
  1882. X                pde_dial_cycle();
  1883. X                done = 1;
  1884. X                if(rcvr_was_active)
  1885. X                    start_rcvr_process(1);
  1886. X                break;
  1887. X
  1888. X            case ESC:
  1889. X            case CTL_C:
  1890. X                cmd = 'q';
  1891. X            case 'q':
  1892. X                done = 1;
  1893. X                continue;
  1894. X
  1895. X            case '/':
  1896. X            case 'f': pde_cmd_find(); break;
  1897. X
  1898. X            case 'r': pde_cmd_remove(); break;
  1899. X            case 'o': pde_cmd_remove_oops(); break;
  1900. X
  1901. X            case 'a': pde_cmd_add((PDE *)0); break;
  1902. X
  1903. X            case 'e': pde_add_or_edit(curr_pde,1); break;
  1904. X
  1905. X            case CTL_L:
  1906. X            case CTL_R:
  1907. X                touchwin(stdscr);
  1908. X                wrefresh(stdscr);
  1909. X                touchwin(dirw);
  1910. X                wrefresh(dirw);
  1911. X                touchwin(scrw);
  1912. X                wrefresh(scrw);
  1913. X                break;
  1914. X
  1915. X            default:
  1916. X                sprintf(s80,"invalid command: %s",
  1917. X                    (cmd < 0x80) ? make_char_graphic(cmd,0) : "?");
  1918. X                ring_bell();
  1919. X                dirw_bot_msg(s80);
  1920. X                break;
  1921. X        }
  1922. X    }
  1923. X    interrupt = 0;
  1924. X    if(cmd == CR)
  1925. X        return;
  1926. X
  1927. X    pde_list_save_if_dirty();
  1928. X    windows_end(dirw);
  1929. X    dirw = (WINDOW *)0;
  1930. X    scrw = (WINDOW *)0;
  1931. X    redisplay_rcvr_screen();
  1932. X    if(rcvr_was_active)
  1933. X        start_rcvr_process(0);
  1934. X}    /* end of pde_list_manager */
  1935. X
  1936. X/*+-------------------------------------------------------------------------
  1937. X    choose_line(baud) - user is dialing a remote and will take 'Any' line
  1938. X--------------------------------------------------------------------------*/
  1939. Xvoid
  1940. Xchoose_line(baud)
  1941. Xuint baud;
  1942. X{
  1943. Xstruct dvent *dve;
  1944. Xchar s32[32];
  1945. X
  1946. X/* check out current line choice */
  1947. X    if(access(shm->Lline,6))
  1948. X        goto GET_LINE_THAT_MATCHES_BAUD;
  1949. X    dve = getdvline(shm->Lline + 8);
  1950. X    enddvent();
  1951. X    if(!dve)    /* if no match in Devices, let ecu fend for itself */
  1952. X        return;
  1953. X
  1954. X/* if shm->Lline is open and baud rate ok, no further */
  1955. X    if(shm->Liofd > 0)
  1956. X    {
  1957. X        if((dve->low_baud <= baud) && (baud <= dve->high_baud))
  1958. X            return;
  1959. X        lclose();    /* won't do ... gotta find a new one */
  1960. X        goto GET_LINE_THAT_MATCHES_BAUD;
  1961. X    }
  1962. X
  1963. X    if(!shm->Lline[0])
  1964. X        memset(shm->Lline,0,sizeof(shm->Lline));
  1965. X
  1966. X/* see if shm->Lline in use by someone else; if not and baud rate ok, no further */
  1967. X    switch(utmp_status(shm->Lline))
  1968. X    {
  1969. X        case US_NOTFOUND:    /* not in utmp, or getty dead */
  1970. X            if(line_locked(shm->Lline))
  1971. X                goto GET_LINE_THAT_MATCHES_BAUD;
  1972. X        case US_LOGIN:        /* enabled for login, idle */
  1973. X            if((dve->low_baud <= baud) && (baud <= dve->high_baud))
  1974. X                return;
  1975. X    }
  1976. X
  1977. X/* we've got to pick a new line */
  1978. XGET_LINE_THAT_MATCHES_BAUD:
  1979. X
  1980. X    strcpy(s32,"/dev/tty");
  1981. X    while(1)
  1982. X    {
  1983. X        if(!(dve = getdvbaud(baud)))
  1984. X        {
  1985. X            enddvent();        /* no match ... */
  1986. X            return;            /* ... so let current shm->Lline fail */
  1987. X        }
  1988. X/* by now, we know shm->Lline wont work */
  1989. X        if(!strcmp(dve->line,shm->Lline + 5))
  1990. X            continue;
  1991. X/* if not acu, dont use it */
  1992. X        if(ulindex(dve->type,"ACU") < 0)
  1993. X            continue;
  1994. X        strcpy(&s32[8],dve->line + 3);    /* yeech ... make "/dev/ttyxx" */
  1995. X        switch(utmp_status(s32))
  1996. X        {
  1997. X            case US_NOTFOUND:    /* not in utmp, or getty dead */
  1998. X                if(line_locked(s32))
  1999. X                    continue;
  2000. X            case US_LOGIN:        /* enabled for login, idle */
  2001. X                strcpy(shm->Lline,s32);    /* @@@@@@@@@@@ MATCH @@@@@@@@@ */
  2002. X                shm->Lline[9] = to_lower(shm->Lline[9]);
  2003. X                enddvent();    
  2004. X                return;
  2005. X        }
  2006. X    }
  2007. X    /*NOTREACHED*/
  2008. X
  2009. X}    /* end of choose_line */
  2010. X
  2011. X/*+-------------------------------------------------------------------------
  2012. X    copy_pde_to_lvar(tpde)
  2013. X
  2014. Xif changing line, close old line and open new one
  2015. X--------------------------------------------------------------------------*/
  2016. Xvoid
  2017. Xcopy_pde_to_lvar(tpde)
  2018. Xregister PDE *tpde;
  2019. X{
  2020. Xint reopen = 0;
  2021. Xint lerr;
  2022. X
  2023. X    if(tpde->tty[0])
  2024. X    {
  2025. X        if(shm->Lline[0] && shm->Lline[8] && strcmp(tpde->tty,shm->Lline + 8))
  2026. X        {
  2027. X            reopen = 1;
  2028. X            shm->Lmodem_already_init = 0;
  2029. X            lclose();
  2030. X        }
  2031. X        strcpy(shm->Lline,"/dev/tty");
  2032. X        strcat(shm->Lline,tpde->tty);
  2033. X    }
  2034. X    else
  2035. X        choose_line(tpde->baud);
  2036. X
  2037. X    if(shm->Liofd < 0)
  2038. X        reopen = 1;
  2039. X    strcpy(shm->Llogical,tpde->logical);
  2040. X    strcpy(shm->Ldescr,tpde->descr);
  2041. X    strcpy(shm->Ltelno,tpde->telno);
  2042. X    if(!shm->Ldescr[0])
  2043. X        strcpy(shm->Ldescr,shm->Llogical);
  2044. X    shm->Lparity = tpde->parity;
  2045. X    if(shm->Lbaud != tpde->baud)
  2046. X        shm->Lmodem_already_init = 0;
  2047. X    shm->Lbaud =tpde->baud;    
  2048. X    if(reopen)
  2049. X    {
  2050. X        if(lerr = lopen())
  2051. X        {
  2052. X            tcap_curbotleft();
  2053. X            pprintf("%s: %s\n",shm->Lline,lopen_err_text(lerr));
  2054. X            hangup(HANGUP_LINE_OPEN_ERROR);
  2055. X        }
  2056. X    }
  2057. X    else
  2058. X    {
  2059. X        lset_baud_rate(1);
  2060. X        lset_parity(1);
  2061. X    }
  2062. X
  2063. X}    /* end of copy_pde_to_lvar */
  2064. X
  2065. X/*+-----------------------------------------------------------------------
  2066. X    lookup_logical_telno()
  2067. X
  2068. XA logical telephone number is either a symbolic identifer
  2069. Xor an lcb->telno telephone number.  A symbolic identifer is a string
  2070. Xwhose initial character is a letter.
  2071. XAn lcb->telno telephone number begins with a numeral.
  2072. X
  2073. XThis function converts a logical telephone number 
  2074. Xto a telephone number (suitable for dialing by a Hayes or
  2075. Xcompatible modem).  It is called by command line processing
  2076. Xwhen 'ecu logical-name' is specified or in response to
  2077. Xa %dial logical-name.  It is not used by the curses directory
  2078. Xmanager.
  2079. X
  2080. XIf the first character of 'shm->Llogical' is a digit, the entire
  2081. Xinput string is copied to 'shm->Ltelno'.  If 'shm->Llogical' has a 
  2082. Xnon-numeric first character, then the user's home directory is
  2083. Xsearched for the file .ecu/phone (~/.ecu/phone). The file is a series
  2084. Xof records terminated with a newline.  Each record has two or three
  2085. Xfields separated by colons.  The first field is the logical telephone
  2086. Xnumber and the second field is the telephone number.  The third
  2087. X(optional) field contains a string to further identify the telephone
  2088. Xnumber being called.
  2089. X
  2090. XCASE IS INSIGNIFICANT in logical entry names for this procedure
  2091. X
  2092. XThe function returns one of the following:
  2093. X
  2094. X  1        if no error occurs
  2095. X  0        if not numeric phone number and logical string not found in file.
  2096. X
  2097. X------------------------------------------------------------------------*/
  2098. Xlookup_logical_telno()
  2099. X{
  2100. Xregister PDE *tpde;
  2101. X
  2102. X    if(!pde_list_quan)
  2103. X    {
  2104. X        if(pde_list_read())
  2105. X            return(0);
  2106. X    }
  2107. X
  2108. X/* if literal phone number, return it immediately */
  2109. X
  2110. X    if(isdigit(shm->Llogical[0]))
  2111. X    {
  2112. X        strcpy(shm->Ltelno,shm->Llogical);
  2113. X        strcpy(shm->Ldescr,shm->Llogical);
  2114. X        return(1);
  2115. X    }
  2116. X
  2117. X/* if logical phone number */
  2118. X    if(tpde = pde_list_search(shm->Llogical,0))    /* inexact search */
  2119. X    {
  2120. X        copy_pde_to_lvar(tpde);
  2121. X        return(1);
  2122. X    }
  2123. X
  2124. X    shm->Llogical[0] = 0;
  2125. X    shm->Lrname[0] = 0;
  2126. X    shm->Ltelno[0] = 0;
  2127. X    shm->Ldescr[0] = 0;
  2128. X    return(0);
  2129. X
  2130. X}    /* end of lookup_logical_telno */
  2131. X
  2132. X/* end of ecuphone.c */
  2133. X/* vi: set tabstop=4 shiftwidth=4: */
  2134. SHAR_EOF
  2135. $TOUCH -am 1224223290 'ecuphone.c' &&
  2136. chmod 0644 ecuphone.c ||
  2137. echo 'restore of ecuphone.c failed'
  2138. Wc_c="`wc -c < 'ecuphone.c'`"
  2139. test 48468 -eq "$Wc_c" ||
  2140.     echo 'ecuphone.c: original size 48468, current size' "$Wc_c"
  2141. true || echo 'restore of ecuphrase.c failed'
  2142. echo End of part 5, continue with part 6
  2143. exit 0
  2144. --------------------------------------------------------------------
  2145. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  2146. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  2147.  
  2148. exit 0 # Just in case...
  2149. -- 
  2150. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2151. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2152. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2153. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2154.