home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-05-11 | 44.4 KB | 1,873 lines |
- Newsgroups: comp.sources.misc
- subject: v12i058: ECU 2.80 part 05/29
- from: wht%n4hgf@gatech.edu (Warren Tucker)
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 12, Issue 58
- Submitted-by: wht%n4hgf@gatech.edu (Warren Tucker)
- Archive-name: ecu2.80/part05
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # This is part 05 of ecu280
- if touch 2>&1 | fgrep '[-amc]' > /dev/null
- then TOUCH=touch
- else TOUCH=true
- fi
- # ============= ecuphone.c ==============
- echo "x - extracting ecuphone.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > ecuphone.c &&
- X/* CHK=0x4180 */
- X/*+-------------------------------------------------------------------------
- X ecuphone.c -- visual phone dialer/directory editor
- X wht%n4hgf@gatech.edu
- X
- X .---[ title ]------------modified-.<-- dirw "top line"
- X | stand out mode |<-- dirw "header line"
- X | |<-- scrw first line
- X | |
- X | |
- X | |
- X | |<-- scrw last line
- X | stand out mode |<-- dirw "cmd line"
- X `---------------------------------'<-- dirw bottom line
- X
- X Defined functions:
- X check_curr_pde()
- X choose_line(baud)
- X copy_pde_to_lvar(tpde)
- X dirw_bot_msg(msg)
- X dirw_cmd_line_setup(prompt)
- X dirw_display_top()
- X dirw_get_cmd(prompt)
- X lookup_logical_telno()
- X pde_add_or_edit(tpde,edit)
- X pde_add_or_edit_read(prompt,edit,x,buf,max,delim)
- X pde_cmd_add(tpde)
- X pde_cmd_down()
- X pde_cmd_dump_list()
- X pde_cmd_find()
- X pde_cmd_remove()
- X pde_cmd_remove_oops()
- X pde_cmd_save()
- X pde_cmd_up()
- X pde_display(line,tpde,stand_out)
- X pde_display_logical(line,tpde,stand_out)
- X pde_list_add(tpde)
- X pde_list_erase()
- X pde_list_manager()
- X pde_list_read()
- X pde_list_remove(tpde)
- X pde_list_save_if_dirty()
- X pde_list_search(logical,exact_flag)
- X pde_list_set_dirty(flag)
- X scrw_fill(tpde,curr_pde_line)
- X scrw_fill_at(line_num,tpde,curr_pde_line)
- X
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:05-07-1990-21:23-wht@n4hgf---- 2.80 --- */
- X/*:04-20-1990-17:58-wht@n4hgf-choose_line now only uses ACU lines */
- X/*:04-19-1990-03:07-wht@n4hgf-GCC run found unused vars -- rm them */
- X/*:04-16-1990-01:16-wht@n4hgf-modify for true field editing */
- X/*:04-15-1990-19:34-wht@n4hgf-add cursor up and down to motion choices */
- X/*:04-14-1990-14:47-wht@n4hgf-refresh dialing directory on no-dial exit */
- X/*:03-25-1990-14:11-wht@n4hgf------ x2.70 ------- */
- X/*:03-23-1990-14:51-wht@n4hgf-use strcmpi instead of ulcmpb */
- X/*:03-12-1990-04:29-wht@n4hgf-add Lrname */
- X/*:02-15-1990-15:48-wht-better diagnostic for LOPEN_LCKERR */
- X/*:11-24-1989-14:41-wht-UNIX tcap-curses blinks with high bits set on addch */
- X/*:11-23-1989-03:11-wht-conditional compile for M_XENIX or M_UNIX */
- X/*:10-23-1989-18:31-wht-was not calling enddvent if getdvbaud succeeded */
- X/*:10-15-1989-16:52-wht-fix bug on adding to empty directory */
- X/*:08-31-1989-12:37-wht-was not always setting brate/parity properly */
- X/*:07-03-1989-22:57-wht------ x2.00 ----- */
- X/*:06-24-1989-16:53-wht-flush edits --- ecu 1.95 */
- X
- X#include <curses.h>
- X#include "pc_scr.h"
- X
- X#define STDIO_H_INCLUDED
- X#define OMIT_TERMIO_REFERENCES
- X#include "ecu.h"
- X
- X#include "ecupde.h"
- X#include "ecukey.h"
- X#include "ecuxkey.h"
- X#include "ecuhangup.h"
- X#include "utmpstatus.h"
- X#include "dvent.h"
- X
- Xvoid dirw_bot_msg();
- X
- X#if defined(pyr)
- X#define strchr index
- X#define strrchr rindex
- X#endif
- X
- Xchar *strchr();
- Xchar *strrchr();
- X
- X/* window definitions */
- X#define DIRW_LINES (LINES - 1)
- X#define DIRW_COLS (COLS)
- X#define DIRW_COLS (COLS)
- X#define DIRW_TOP_LINES 2
- X#define DIRW_BOT_LINES 2
- X#define DIRW_CMD_LINE (DIRW_LINES - 2)
- X#define SCRW_LINES (DIRW_LINES - DIRW_TOP_LINES - DIRW_BOT_LINES)
- X#define SCRW_COLS (DIRW_COLS)
- X#define SCRW_TLY (DIRW_TOP_LINES)
- X#define SCRW_TLX 0
- X
- Xextern int windows_active;
- Xextern int rcvr_pid;
- Xextern char errmsg[];
- Xextern int tcap_LINES;
- X
- XWINDOW *dirw;
- XWINDOW *scrw;
- X
- XPDE *pde_list_head = (PDE *)0; /* pointer to first pde in linked list */
- XPDE *curr_pde = (PDE *)0; /* current pde */
- XPDE *remove_pde = (PDE *)0; /* if non-zero, pde just removed */
- Xint remove_dirty_flag; /* pde_list_dirty at remove time */
- Xint pde_list_quan = 0; /* count of items in list now */
- Xint pde_list_dirty = 0; /* pde_list modified but not saved */
- Xint scrw_curr_pde_line; /* scrw line curr_pde is on */
- Xchar ecuphone_name[256]; /* phone directory name */
- X
- X/*+-------------------------------------------------------------------------
- X pde_list_erase()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_list_erase()
- X{
- Xregister PDE *pde = pde_list_head;
- Xregister PDE *next;
- X
- X while(pde)
- X {
- X next = pde->next;
- X free((char *)pde);
- X pde = next;
- X }
- X pde_list_head = (PDE *)0;
- X pde_list_quan = 0;
- X} /* end of pde_list_erase */
- X
- X/*+-------------------------------------------------------------------------
- X pde_list_set_dirty(flag)
- X0: clean, 1 dirty, -1 do not modify;update screen only
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_list_set_dirty(flag)
- Xint flag;
- X{
- Xregister itmp;
- X if(flag != pde_list_dirty)
- X {
- X if(flag != -1)
- X pde_list_dirty = flag;
- X wmove(dirw,0,DIRW_COLS - 14);
- X if(pde_list_dirty)
- X waddstr(dirw," modified ");
- X else
- X {
- X itmp = 10;
- X while(itmp--)
- X waddch(dirw,(unsigned)sHR);
- X }
- X wrefresh(dirw);
- X }
- X} /* end of pde_list_set_dirty */
- X
- X/*+-------------------------------------------------------------------------
- X pde_list_add(tpde) -- add to linked list
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_list_add(tpde)
- XPDE *tpde;
- X{
- Xregister PDE *this = tpde;
- Xregister PDE *prev;
- Xregister PDE *next;
- X
- X/* if empty, init list with this one and quit */
- X if(pde_list_head == (PDE *)0)
- X {
- X pde_list_head = this;
- X this->prev = (PDE *)0;
- X this->next = (PDE *)0;
- X pde_list_quan++;
- X return;
- X }
- X
- X/* list not empty */
- X prev = (PDE *)0; /* no previous yet */
- X next = pde_list_head; /* init next to top of list */
- X
- X while(strcmp(next->logical,this->logical) < 0)
- X {
- X prev = next;
- X next = prev->next;
- X if(next == (PDE *)0)
- X break;
- X }
- X
- X if(prev) /* if non-zero, we will not update the list head */
- X {
- X this->next = prev->next;
- X this->prev = prev;
- X prev->next = this;
- X if(next)
- X next->prev = this;
- X }
- X else /* 'this' is to become the new list head (1st element) */
- X {
- X this->next = next;
- X this->prev = (PDE *)0;
- X if(next)
- X next->prev = this;
- X pde_list_head = this;
- X }
- X pde_list_quan++;
- X
- X} /* end of pde_add */
- X
- X/*+-------------------------------------------------------------------------
- X pde_list_remove(tpde) -- add to linked list
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_list_remove(tpde)
- Xregister PDE *tpde;
- X{
- Xregister PDE *prev;
- Xregister PDE *next;
- X
- X prev = (PDE *)0; /* there is no previous now */
- X
- X if((next = pde_list_head) == (PDE *)0) /* if empty list */
- X return;
- X
- X while(next != tpde)
- X {
- X prev = next;
- X next = prev->next;
- X if(next == (PDE *)0)
- X return;
- X }
- X
- X/* take care of "current pde" */
- X if(tpde == curr_pde)
- X {
- X if(tpde->next)
- X curr_pde = tpde->next;
- X else if(tpde->prev)
- X curr_pde = tpde->prev;
- X else
- X curr_pde = (PDE *)0;
- X }
- X
- X/* unlink */
- X
- X if(prev) /* if non-zero, we will not update the list head */
- X {
- X prev->next = tpde->next;
- X if(tpde->next)
- X (tpde->next)->prev = prev;
- X }
- X else
- X {
- X pde_list_head = tpde->next;
- X if(tpde->next)
- X (tpde->next)->prev = (PDE *)0;
- X }
- X
- X tpde->next = (PDE *)0;
- X tpde->prev = (PDE *)0;
- X
- X pde_list_quan--;
- X} /* end of pde_list_remove */
- X
- X/*+-----------------------------------------------------------------------
- X PDE *pde_list_search(logical,exact_flag)
- X------------------------------------------------------------------------*/
- XPDE *
- Xpde_list_search(logical,exact_flag)
- Xchar *logical;
- Xint exact_flag;
- X{
- Xregister PDE *tpde;
- X
- X if(!pde_list_quan)
- X {
- X if(pde_list_read())
- X return((PDE *)0);
- X }
- X
- X tpde = pde_list_head;
- X while(tpde)
- X {
- X /* only first few chars necessary for match with ulcmpb */
- X if(exact_flag)
- X {
- X if(strcmp(tpde->logical,logical) == 0)
- X return(tpde);
- X }
- X else
- X {
- X if(ulcmpb(tpde->logical,logical) < 0)
- X return(tpde);
- X }
- X tpde = tpde->next;
- X }
- X if(!tpde)
- X sprintf(errmsg,"'%s' not found",logical);
- X return(tpde);
- X
- X} /* end of pde_list_search */
- X
- X/*+-------------------------------------------------------------------------
- X pde_cmd_dump_list()
- X--------------------------------------------------------------------------*/
- X#if defined(PDE_DEBUG)
- Xvoid
- Xpde_cmd_dump_list()
- X{
- Xregister PDE *tpde = pde_list_head;
- Xint count = 0;
- X
- X curmove(LINES - 1,0);
- X while(tpde)
- X {
- X ff(se,"p:%04x t:%04x n:%04x %c %s\r\n",
- X tpde->prev,tpde,tpde->next,(tpde == curr_pde) ? '*' : ' ',
- X tpde->logical);
- X if((count++ % 15) == 14)
- X {
- X ff(se,"press return: ");
- X ttygetc(1);
- X ff(se,"\r\n");
- X }
- X tpde = tpde->next;
- X }
- X ff(se,"press return: ");
- X ttygetc(1);
- X touchwin(stdscr);
- X touchwin(dirw);
- X touchwin(scrw);
- X wrefresh(stdscr);
- X wrefresh(dirw);
- X wrefresh(scrw);
- X
- X} /* end of pde_cmd_dump_list */
- X#endif
- X
- X/*+-----------------------------------------------------------------------
- X pde_list_read()
- Xsample .ecu/phone:
- X#tri2:426-0624:2400:E:Tridom Pyramid comment
- Xarc:393-3083:2400:N:Atlanta Radio Club
- X
- Xreturn 0 if entire list read, else 1 if error (error msg in errmsg)
- X------------------------------------------------------------------------*/
- Xint
- Xpde_list_read()
- X{
- Xregister itmp;
- Xregister token_number;
- Xregister char *cptr;
- Xregister char *token;
- Xchar readpde_buf[128];
- XFILE *fp_phone;
- XPDE *tpde;
- Xchar *str_token();
- X
- X if(!ecuphone_name[0])
- X {
- X get_home_dir(ecuphone_name);
- X strcat(ecuphone_name,"/.ecu/phone");
- X }
- X
- X if( (fp_phone = fopen(ecuphone_name,"r")) == NULL)
- X {
- X perror_errmsg(ecuphone_name);
- X return(1);
- X }
- X
- X/* we have an open .ecu/phone file */
- X pde_list_erase(); /* clear any previous directory */
- X while(fgets(readpde_buf,sizeof(readpde_buf),fp_phone) != NULL)
- X {
- X if(readpde_buf[0] == '#') /* comment? */
- X continue;
- X if(itmp = strlen(readpde_buf)) /* itmp = len; if > 0 ... */
- X {
- X itmp--;
- X readpde_buf[itmp] = 0; /* ... strip trailing NL */
- X }
- X cptr = readpde_buf; /* first call to str_token, -> buff */
- X while((*cptr == 0x20) || (*cptr == TAB))
- X cptr++; /* strip leading spaces */
- X if(*cptr == 0) /* if line all blank, skip it */
- X continue;
- X
- X if(!(tpde = (PDE *)malloc(sizeof(PDE))))
- X {
- X fclose(fp_phone);
- X strcpy(errmsg,"Out of memory reading phone list");
- X return(1);
- X }
- X
- X tpde->descr[0] = 0;
- X tpde->logical[0] = 0;
- X tpde->telno[0] = 0;
- X tpde->tty[0] = 0;
- X tpde->parity = 0;
- X tpde->baud = 2400;
- X tpde->prev = (PDE *)0;
- X tpde->next = (PDE *)0;
- X
- X token_number = 0;
- X while((token = str_token(cptr,":")) != NULL)
- X {
- X cptr = NULL; /* further calls to str_token need NULL */
- X switch(token_number++)
- X {
- X case 0: /* first field is logical name */
- X strncpy(tpde->logical,token,sizeof(tpde->logical));
- X tpde->logical[sizeof(tpde->logical) - 1] = 0;
- X break;
- X case 1: /* second field is tpde->telno phone number */
- X strncpy(tpde->telno,token,sizeof(tpde->telno));
- X tpde->telno[sizeof(tpde->telno) - 1] = 0;
- X break;
- X case 2: /* third field is line */
- X strncpy(tpde->tty,token,sizeof(tpde->tty));
- X tpde->tty[sizeof(tpde->tty) - 1] = 0;
- X break;
- X case 3: /* fourth field is baud rate */
- X tpde->baud = atoi(token);
- X break;
- X case 4: /* fifth field is parity */
- X switch(itmp = to_lower(token[0]))
- X {
- X case 'o':
- X case 'e':
- X case 'm':
- X case 's':
- X tpde->parity = itmp;
- X break;
- X default:
- X case 'n':
- X tpde->parity = 0;
- X break;
- X }
- X break;
- X default:
- X strncpy(tpde->descr,token,sizeof(tpde->descr));
- X tpde->descr[sizeof(tpde->descr) - 1] = 0;
- X break;
- X } /* end of switch(token_number) */
- X } /* end while not end of record */
- X
- X pde_list_add(tpde);
- X
- X } /* while records left to ready */
- X
- X fclose(fp_phone);
- X return(0);
- X} /* end of pde_list_read */
- X
- X/*+-----------------------------------------------------------------------
- X dirw_display_top()
- X------------------------------------------------------------------------*/
- Xvoid
- Xdirw_display_top()
- X{
- X wmove(dirw,1,1);
- X wstandout(dirw);
- X wprintw(dirw,
- X" entry name %c telephone number %c tty %c baud P %c description ",
- X sVR,sVR,sVR,sVR);
- X wstandend(dirw);
- X wrefresh(dirw);
- X} /* end of dirw_display_top() */
- X
- X/*+-------------------------------------------------------------------------
- X dirw_bot_msg(msg)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xdirw_bot_msg(msg)
- Xchar *msg;
- X{
- Xregister itmp;
- Xregister itmp2;
- Xstatic last_msglen = 0;
- X#define DIRW_BOT_LINE_TLX 2
- X#define DIRW_BOT_LINE_MAX_MSGLEN (DIRW_COLS - DIRW_BOT_LINE_TLX - 8)
- Xchar msg2[80];
- X
- X if(!last_msglen && !strlen(msg))
- X return;
- X
- X wmove(dirw,DIRW_LINES - 1,DIRW_BOT_LINE_TLX);
- X
- X if((itmp = strlen(msg)) == 0)
- X {
- X itmp2 = last_msglen + 2;
- X for(itmp = 0; itmp < itmp2; itmp++)
- X waddch(dirw,(unsigned)sHR);
- X last_msglen = 0;
- X }
- X else
- X {
- X waddch(dirw,' ');
- X if(itmp > DIRW_BOT_LINE_MAX_MSGLEN)
- X {
- X strncpy(msg2,msg,DIRW_BOT_LINE_MAX_MSGLEN);
- X msg2[DIRW_BOT_LINE_MAX_MSGLEN + 1] = 0;
- X waddstr(dirw,msg2);
- X itmp = strlen(msg2);
- X }
- X else
- X {
- X waddstr(dirw,msg);
- X itmp = strlen(msg);
- X }
- X waddch(dirw,' ');
- X if((itmp2 = last_msglen - itmp) > 0)
- X {
- X while(itmp2--)
- X waddch(dirw,(unsigned)sHR);
- X }
- X last_msglen = itmp; /* remember last message length */
- X }
- X wrefresh(dirw);
- X} /* end of dirw_bot_msg */
- X
- X/*+-------------------------------------------------------------------------
- X pde_display_logical(line,tpde,stand_out)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_display_logical(line,tpde,stand_out)
- Xint line;
- XPDE *tpde;
- Xint stand_out;
- X{
- X wmove(scrw,line,0);
- X waddch(scrw,(unsigned)sVR);
- X
- X if(stand_out)
- X wstandout(scrw);
- X wprintw(scrw," %-10.10s",tpde->logical);
- X if(stand_out)
- X wstandend(scrw);
- X
- X} /* end of pde_display_logical */
- X
- X/*+-----------------------------------------------------------------------
- X pde_display(win,line,tpde,stand_out)
- X00000000001111111111222222222233333333334444444444555555555566666666667777777777
- X01234567890123456789012345678901234567890123456789012345678901234567890123456789
- X| entry name | telephone number | tty | baud P | description |
- X| 0123456789 | 0123456789012345 | 01 | baud P | 01234567890123456789012345678 |
- X--------------------------------------------------------------------------*/
- Xpde_display(line,tpde,stand_out)
- Xint line;
- XPDE *tpde;
- Xint stand_out;
- X{
- X
- X pde_display_logical(line,tpde,stand_out);
- X waddch(scrw,' ');
- X waddch(scrw,(unsigned)sVR);
- X waddch(scrw,' ');
- X wprintw(scrw,"%-16.16s %c ",tpde->telno,sVR);
- X if(tpde->tty[0])
- X wprintw(scrw,"%-2.2s %c",tpde->tty,sVR);
- X else
- X wprintw(scrw,"Any %c",sVR);
- X wprintw(scrw,"%5u %c %c ",tpde->baud,
- X (tpde->parity) ? to_upper(tpde->parity) : 'N',sVR);
- X wprintw(scrw,"%-29.29s %c",tpde->descr,sVR);
- X return(0);
- X
- X} /* end of pde_display */
- X
- X/*+-----------------------------------------------------------------------
- X scrw_fill(first_pde,curr_pde_line)
- X------------------------------------------------------------------------*/
- Xvoid
- Xscrw_fill(tpde,curr_pde_line)
- Xregister PDE *tpde;
- Xint *curr_pde_line;
- X{
- Xregister line;
- Xregister is_curr_pde;
- X
- X *curr_pde_line = -1;
- X for(line = 0; line < SCRW_LINES; line++)
- X {
- X if(tpde)
- X {
- X if(is_curr_pde = (tpde == curr_pde))
- X *curr_pde_line = line;
- X pde_display(line,tpde,(tpde == curr_pde));
- X tpde = tpde->next;
- X }
- X else
- X {
- X wmove(scrw,line,0);
- X waddch(scrw,(unsigned)sVR);
- X wclrtoeol(scrw);
- X wmove(scrw,line,SCRW_COLS - 1);
- X waddch(scrw,(unsigned)sVR);
- X }
- X }
- X wrefresh(scrw);
- X
- X} /* end of scrw_fill */
- X
- X/*+-------------------------------------------------------------------------
- X scrw_fill_at(line_num,first_pde,curr_pde_line)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xscrw_fill_at(line_num,tpde,curr_pde_line)
- Xint line_num;
- Xregister PDE *tpde;
- Xint *curr_pde_line;
- X{
- Xregister itmp;
- X
- X if(!tpde)
- X {
- X scrw_fill(tpde,curr_pde_line);
- X/*
- X wclear(scrw);
- X wrefresh(scrw);
- X*/
- X return;
- X }
- X for(itmp = 0; itmp < line_num; itmp++)
- X {
- X if(!tpde->prev)
- X break;
- X tpde = tpde->prev;
- X }
- X
- X scrw_fill(tpde,curr_pde_line);
- X
- X} /* end of scrw_fill_at */
- X
- X/*+-------------------------------------------------------------------------
- X dirw_cmd_line_setup(prompt)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xdirw_cmd_line_setup(prompt)
- Xchar *prompt;
- X{
- Xregister icol;
- Xint y;
- Xint x;
- X
- X wmove(dirw,DIRW_CMD_LINE,1);
- X wstandout(dirw);
- X waddch(dirw,' ');
- X waddstr(dirw,prompt);
- X waddch(dirw,' ');
- X getyx(dirw,y,x);
- X for(icol = x; icol < DIRW_COLS - 1; icol++)
- X waddch(dirw,' ');
- X wmove(dirw,y,x);
- X wstandend(dirw);
- X wrefresh(dirw);
- X} /* end of dirw_cmd_line_setup */
- X
- X/*+-------------------------------------------------------------------------
- X dirw_get_cmd()
- X--------------------------------------------------------------------------*/
- Xuchar
- Xdirw_get_cmd(prompt)
- Xchar *prompt;
- X{
- Xregister uchar cmd;
- X
- X dirw_cmd_line_setup(prompt);
- X cmd = ttygetc(1);
- X dirw_bot_msg("");
- X return(cmd);
- X
- X} /* end of dirw_get_cmd */
- X
- X/*+-------------------------------------------------------------------------
- X pde_cmd_save()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_cmd_save()
- X{
- XFILE *fpold;
- XFILE *fpnew;
- XPDE *tpde;
- Xchar ecuphone_ntmp[256]; /* temp phone directory name */
- Xchar iobuf[128];
- Xint count = 0;
- X
- X if(!pde_list_dirty)
- X {
- X dirw_bot_msg("directory has not been modified");
- X return;
- X }
- X
- X strcpy(ecuphone_ntmp,ecuphone_name);
- X strcat(ecuphone_ntmp,".t");
- X
- X if((fpnew = fopen(ecuphone_ntmp,"w")) == NULL) /* open old file */
- X {
- X sprintf(iobuf,"cannot open %s",ecuphone_ntmp);
- X dirw_bot_msg(iobuf);
- X return;
- X }
- X
- X/* retain commented entries */
- X if((fpold = fopen(ecuphone_name,"r")) != NULL) /* open old file */
- X {
- X while(fgets(iobuf,sizeof(iobuf),fpold) != NULL)
- X {
- X if(iobuf[0] == '#')
- X fputs(iobuf,fpnew);
- X }
- X fclose(fpold);
- X }
- X
- X/* write new entries */
- X tpde = pde_list_head;
- X while(tpde)
- X {
- X sprintf(iobuf,"%d",count+1);
- X dirw_bot_msg(iobuf);
- X sprintf(iobuf,"%s:%s:%s:%u:%c:%s\n",tpde->logical,tpde->telno,
- X tpde->tty,tpde->baud,
- X (tpde->parity) ? to_upper(tpde->parity) : 'N',
- X tpde->descr);
- X fputs(iobuf,fpnew);
- X tpde = tpde->next;
- X count++;
- X }
- X
- X fclose(fpnew);
- X unlink(ecuphone_name);
- X rename(ecuphone_ntmp,ecuphone_name);
- X sprintf(iobuf,"saved %d entries",count);
- X dirw_bot_msg(iobuf);
- X pde_list_set_dirty(0);
- X
- X} /* end of pde_cmd_save */
- X
- X/*+-------------------------------------------------------------------------
- X pde_list_save_if_dirty()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_list_save_if_dirty()
- X{
- Xint cmd = 0;
- X
- X if(pde_list_dirty)
- X {
- X while(!cmd)
- X {
- X ring_bell();
- X cmd = dirw_get_cmd("directory modified: save?");
- X if(isupper(cmd))
- X cmd = tolower(cmd);
- X switch(cmd)
- X {
- X case 'y': pde_cmd_save(); break;
- X case 'n': break;
- X default:
- X ring_bell();
- X cmd = 0;
- X break;
- X }
- X }
- X }
- X} /* end of pde_list_save_if_dirty */
- X
- X/*+-------------------------------------------------------------------------
- X pde_cmd_up()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_cmd_up()
- X{
- Xregister PDE *tpde;
- X
- X if((!curr_pde) || (curr_pde->prev == (PDE *)0))
- X {
- X ring_bell();
- X return;
- X }
- X if(scrw_curr_pde_line)
- X {
- X pde_display_logical(scrw_curr_pde_line,curr_pde,0);
- X scrw_curr_pde_line--;
- X curr_pde = curr_pde->prev;
- X pde_display_logical(scrw_curr_pde_line,curr_pde,1);
- X }
- X else
- X {
- X tpde = curr_pde;
- X curr_pde = curr_pde->prev;
- X scrw_fill_at(10,tpde,&scrw_curr_pde_line);
- X }
- X
- X} /* end of pde_cmd_up */
- X
- X/*+-------------------------------------------------------------------------
- X pde_cmd_down()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_cmd_down()
- X{
- Xregister itmp;
- Xregister PDE *tpde;
- X
- X if((!curr_pde) || (curr_pde->next == (PDE *)0))
- X {
- X ring_bell();
- X return;
- X }
- X if(scrw_curr_pde_line < (SCRW_LINES - 1))
- X {
- X pde_display_logical(scrw_curr_pde_line,curr_pde,0);
- X scrw_curr_pde_line++;
- X curr_pde = curr_pde->next;
- X pde_display_logical(scrw_curr_pde_line,curr_pde,1);
- X }
- X else
- X {
- X tpde = curr_pde;
- X curr_pde = curr_pde->next;
- X scrw_fill_at(SCRW_LINES - 10,tpde,&scrw_curr_pde_line);
- X }
- X
- X} /* end of pde_cmd_down */
- X
- X/*+-------------------------------------------------------------------------
- X check_curr_pde() -- return 1 if there is a current pde, else 0
- X--------------------------------------------------------------------------*/
- Xcheck_curr_pde()
- X{
- X if(!curr_pde)
- X {
- X dirw_bot_msg("no directory entry selected");
- X return(0);
- X }
- X return(1);
- X} /* end of check_curr_pde */
- X
- X/*+-------------------------------------------------------------------------
- X pde_add_or_edit_read(prompt,edit,x,buf,max,delim)
- Xmax must not wrap around to another line
- X--------------------------------------------------------------------------*/
- Xpde_add_or_edit_read(prompt,edit,x,buf,max,delim)
- Xchar *prompt;
- Xint edit;
- Xint x;
- Xchar *buf;
- Xint max;
- Xchar *delim;
- X{
- Xregister itmp;
- Xchar s82[82];
- X
- X while(1)
- X {
- X dirw_cmd_line_setup(prompt);
- X wstandout(scrw);
- X if(edit)
- X strcpy(s82,buf);
- X itmp = wingets(scrw,scrw_curr_pde_line,x,s82,max,delim,edit);
- X wstandend(scrw);
- X
- X switch(*delim)
- X {
- X case ESC:
- X return;
- X
- X case CR:
- X case NL:
- X if(edit && (itmp == 0))
- X {
- X *delim = TAB;
- X return;
- X }
- X strcpy(buf,s82);
- X return;
- X
- X case CTL_B:
- X *buf = 0;
- X return;
- X
- X case TAB:
- X if(!edit)
- X continue;
- X *buf = 0;
- X return;
- X
- X default:
- X break;
- X }
- X }
- X} /* end of pde_add_or_edit_read */
- X
- X/*+-------------------------------------------------------------------------
- X pde_add_or_edit(tpde,edit)
- Xif called with edit == 1, tpde MUST == curr_pde !!!
- X00000000001111111111222222222233333333334444444444555555555566666666667777777777
- X01234567890123456789012345678901234567890123456789012345678901234567890123456789
- X| entry name | telephone number | tty | baud P | description |
- X| 0123456789 | 0123456789012345 | 01 | baud P | 01234567890123456789012345678 |
- X--------------------------------------------------------------------------*/
- Xint
- Xpde_add_or_edit(tpde,edit)
- Xregister PDE *tpde;
- Xint edit;
- X{
- Xregister itmp;
- Xint input_state = 0;
- Xint changed;
- Xchar s50[50];
- Xchar delim;
- Xint done = 0;
- Xint y,x;
- XPDE *old_curr_pde;
- Xuint baud;
- X
- X if(!edit)
- X {
- X dirw_bot_msg("ESC: abort ^U: erase input");
- X dirw_cmd_line_setup("Enter new directory entry name: ");
- X getyx(dirw,y,x);
- X wstandout(dirw);
- X wingets(dirw,y,x,tpde->logical,10+1,&delim,0);
- X wstandend(dirw);
- X if((!strlen(tpde->logical)) || (tpde->logical[0] == ESC))
- X {
- X dirw_bot_msg("add aborted");
- X return(0);
- X }
- X
- X if(!isalpha(tpde->logical[0]))
- X {
- X dirw_bot_msg("first character must be alphabetic");
- X return(0);
- X }
- X
- X if(pde_list_search(tpde->logical,1))
- X {
- X sprintf(s50,"'%s' is already in the directory",tpde->logical);
- X ring_bell();
- X dirw_bot_msg(s50);
- X return(0);
- X }
- X
- X tpde->descr[0] = 0;
- X tpde->telno[0] = 0;
- X tpde->tty[0] = 0;
- X tpde->parity = '-';
- X tpde->baud = 0;
- X
- X pde_list_add(tpde);
- X old_curr_pde = curr_pde;
- X curr_pde = tpde;
- X scrw_fill_at(SCRW_LINES / 2,tpde,&scrw_curr_pde_line);
- X tpde = curr_pde;
- X } /* end of add code */
- X
- X if(edit)
- X dirw_bot_msg("ESC: exit ^U: erase input ^B: back TAB: forward");
- X else
- X dirw_bot_msg("ESC: abort ^U: erase input ^B: back up");
- X
- X/* add/edit common */
- X while(!done)
- X {
- X changed = 0;
- X switch(input_state)
- X {
- X case 0:
- X if(edit)
- X strcpy(s50,tpde->telno);
- X pde_add_or_edit_read("Enter telephone number",
- X edit,15,tpde->telno,16+1,&delim);
- X if(edit && strcmp(tpde->telno,s50))
- X changed = 1;
- X break;
- X
- X case 1:
- X if(edit)
- X strcpy(s50,(tpde->tty[0]) ? tpde->tty : "Any");
- X pde_add_or_edit_read("Enter tty identifier (i.e., 1a)",
- X edit,34,s50,3+1,&delim);
- X if(edit && strcmp((tpde->tty[0]) ? tpde->tty : "Any",s50))
- X changed = 1;
- X if(!strcmpi(s50,"any"))
- X tpde->tty[0] = 0;
- X else
- X {
- X strncpy(tpde->tty,s50,2);
- X tpde->tty[2] = 0;
- X }
- X break;
- X
- X case 2:
- X if(edit)
- X sprintf(s50,"%u",tpde->baud);
- X pde_add_or_edit_read(
- X "Enter baud rate (110,300,600,1200,2400,4800,9600,19200,38400)",
- X edit,39,s50,5+1,&delim);
- X if(valid_baud_rate(baud = atoi(s50)) < 0)
- X {
- X ring_bell();
- X continue;
- X }
- X if(edit && (tpde->baud != baud ))
- X changed = 1;
- X tpde->baud = baud;
- X break;
- X
- X case 3:
- X if(edit)
- X sprintf(s50,"%c",(tpde->parity) ? tpde->parity : 'n');
- X pde_add_or_edit_read("Enter parity (n,o,e)",
- X edit,45,s50,1+1,&delim);
- X switch(s50[0] = to_lower(s50[0]))
- X {
- X case 'n':
- X s50[0] = 0;
- X case 'o':
- X case 'e':
- X if(edit && (tpde->parity != s50[0]))
- X changed = 1;
- X tpde->parity = s50[0];
- X break;
- X default:
- X ring_bell();
- X continue;
- X }
- X break;
- X
- X case 4:
- X if(edit)
- X strcpy(s50,tpde->descr);
- X pde_add_or_edit_read("Enter description",
- X edit,49,tpde->descr,29+1,&delim);
- X if(edit && strcmp(tpde->descr,s50))
- X changed = 1;
- X break;
- X }
- X
- X pde_display(scrw_curr_pde_line,tpde,1); /* regardless of delimiter */
- X
- X switch(delim) /* process delimiter */
- X {
- X case CTL_L:
- X case CTL_R:
- X clear_screen();
- X touchwin(stdscr);
- X wrefresh(stdscr);
- X touchwin(dirw);
- X wrefresh(dirw);
- X touchwin(scrw);
- X wrefresh(scrw);
- X break;
- X
- X case CTL_B:
- X if(input_state)
- X input_state--;
- X break;
- X
- X case TAB:
- X input_state++;
- X input_state %= 5;
- X break;
- X
- X case ESC:
- X if(edit)
- X {
- X dirw_bot_msg("edit finished");
- X done = 1;
- X }
- X else
- X {
- X pde_list_remove(tpde);
- X curr_pde = old_curr_pde;
- X scrw_fill_at(scrw_curr_pde_line + 1,curr_pde,
- X &scrw_curr_pde_line);
- X dirw_bot_msg("add aborted");
- X return(0);
- X }
- X break;
- X
- X case NL:
- X if(edit && changed)
- X pde_list_set_dirty(1);
- X /* fall thru */
- X default:
- X if(!edit && (input_state == 4))
- X done = 1;
- X else
- X {
- X input_state++;
- X input_state %= 5;
- X }
- X break;
- X }
- X }
- X return(1);
- X
- X} /* end of pde_add_or_edit */
- X
- X/*+-------------------------------------------------------------------------
- X pde_cmd_add(tpde)
- Xif tpde != 0, it is an already valid pde that is to be added
- Xelse if == 0, interactive add
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_cmd_add(tpde)
- Xregister PDE *tpde;
- X{
- Xregister itmp;
- X
- X if(tpde)
- X {
- X pde_list_add(tpde);
- X }
- X else
- X {
- X if(!(tpde = (PDE *)malloc(sizeof(PDE))))
- X {
- X dirw_bot_msg("Out of memory -- cannot add new entry");
- X return;
- X }
- X if(!pde_add_or_edit(tpde,0)) /* routine will add to list ... */
- X { /* ... if good return */
- X free((char *)tpde);
- X return;
- X }
- X }
- X pde_list_set_dirty(1);
- X
- X curr_pde = tpde;
- X scrw_fill_at(SCRW_LINES / 2,curr_pde,&scrw_curr_pde_line);
- X
- X} /* end of pde_cmd_add */
- X
- X/*+-------------------------------------------------------------------------
- X pde_cmd_remove_oops()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_cmd_remove_oops()
- X{
- X if(!remove_pde)
- X {
- X dirw_bot_msg("no removed entry to restore");
- X return;
- X }
- X pde_cmd_add(remove_pde);
- X pde_list_set_dirty(remove_dirty_flag);
- X remove_pde = (PDE *)0;
- X} /* end of pde_cmd_remove_oops */
- X
- X/*+-------------------------------------------------------------------------
- X pde_cmd_remove()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_cmd_remove()
- X{
- Xregister itmp;
- Xregister PDE *tpde;
- Xchar s80[80];
- X
- X if(!check_curr_pde())
- X return;
- X
- X remove_pde = curr_pde;
- X remove_dirty_flag = pde_list_dirty;
- X pde_list_remove(curr_pde);
- X pde_list_set_dirty(1);
- X
- X if(pde_list_quan)
- X scrw_fill_at(scrw_curr_pde_line + 1,curr_pde,&scrw_curr_pde_line);
- X else
- X scrw_fill((PDE *)0,&scrw_curr_pde_line);
- X
- X ring_bell();
- X sprintf(s80,"if you did not mean to to remove '%s', press 'o' (oops) NOW!",
- X remove_pde->logical);
- X dirw_bot_msg(s80);
- X
- X} /* end of pde_cmd_remove */
- X
- X/*+-------------------------------------------------------------------------
- X pde_cmd_find()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_cmd_find()
- X{
- Xregister itmp;
- Xregister PDE *tpde;
- Xchar findname[12];
- Xchar s50[50];
- Xchar delim;
- Xint y,x;
- X
- X dirw_bot_msg("ESC: abort ^U: erase input");
- X dirw_cmd_line_setup("Directory entry name to find: ");
- X getyx(dirw,y,x);
- X wstandout(dirw);
- X wingets(dirw,y,x,findname,10+1,&delim,0);
- X wstandend(dirw);
- X if((!strlen(findname)) || (delim == ESC))
- X return;
- X
- X if(! (tpde = pde_list_search(findname,0)))
- X {
- X dirw_bot_msg(errmsg);
- X return;
- X }
- X curr_pde = tpde;
- X scrw_fill_at(SCRW_LINES / 2,tpde,&scrw_curr_pde_line);
- X
- X} /* end of pde_cmd_find */
- X
- X/*+-------------------------------------------------------------------------
- X pde_list_manager()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpde_list_manager()
- X{
- Xregister uchar cmd = 0;
- Xint rcvr_active = (rcvr_pid > 0) || (rcvr_pid == -2);
- Xint done;
- Xchar s80[80];
- XWINDOW *window_create();
- Xchar *find_procedure();
- Xextern int proc_level;
- X
- X if(rcvr_active && (rcvr_pid != -2))
- X kill_rcvr_process(SIGUSR1);
- X
- X windows_start();
- X dirw = window_create("dialing directory",3,0,0,DIRW_LINES,DIRW_COLS);
- X dirw_display_top();
- X
- X scrw = subwin(dirw,SCRW_LINES,SCRW_COLS,SCRW_TLY,SCRW_TLX);
- X scrollok(scrw,0);
- X if(!pde_list_quan)
- X {
- X if(pde_list_read())
- X dirw_bot_msg(errmsg);
- X else if(!pde_list_quan)
- X dirw_bot_msg("directory empty");
- X }
- X
- X if(pde_list_quan)
- X {
- X if(curr_pde)
- X scrw_fill_at(scrw_curr_pde_line,curr_pde,&scrw_curr_pde_line);
- X else
- X {
- X curr_pde = pde_list_head;
- X scrw_fill(curr_pde,&scrw_curr_pde_line);
- X }
- X }
- X
- X pde_list_set_dirty(-1);
- X
- X done = 0;
- X while(!done)
- X {
- X cmd = dirw_get_cmd(
- X#if defined(M_XENIX) || defined(M_UNIX)
- X "d,j:down u,k:up e:edit a:add r:remove s:save f:find END:dial ESC,q:quit");
- X#else
- X "d,j:down u,k:up e:edit a:add r:remove s:save f:find ^D:dial ESC,q:quit");
- X#endif
- X if((cmd != 'o') && (remove_pde))
- X {
- X free((char *)remove_pde);
- X remove_pde = (PDE *)0;
- X }
- X
- X switch(cmd)
- X {
- X case XFcurdn:
- X case 'd':
- X case 'j': pde_cmd_down(); break;
- X
- X case XFcurup:
- X case 'u':
- X case 'k': pde_cmd_up(); break;
- X
- X case 's': pde_cmd_save(); break;
- X
- X case CR:
- X case NL:
- X case XFend:
- X cmd = XFend;
- X if(!check_curr_pde())
- X break;
- X pde_list_save_if_dirty();
- X windows_end(dirw);
- X
- X/* dont do this here
- X redisplay_rcvr_screen();
- X*/
- X
- X done = 1;
- X#ifdef AUTO_DIAL_PROC
- X if(!proc_level && find_procedure(curr_pde->logical))
- X {
- X char *pargv[2];
- X pargv[0] = curr_pde->logical;
- X pargv[1] = "!MENU";
- X rcvr_pid = 0;
- X do_proc(2,pargv);
- X start_rcvr_process(1);
- X }
- X else
- X {
- X if(rcvr_active)
- X rcvr_pid = -2; /* hayes_dial shud start rcvr */
- X hayes_dial_pde(curr_pde);
- X }
- X#else
- X if(rcvr_active)
- X rcvr_pid = -2; /* hayes_dial shud start rcvr */
- X hayes_dial_pde(curr_pde);
- X#endif
- X break;
- X
- X case ESC:
- X case CTL_C:
- X cmd = 'q';
- X case 'q':
- X done = 1;
- X continue;
- X
- X case 'f': pde_cmd_find(); break;
- X
- X case 'r': pde_cmd_remove(); break;
- X case 'o': pde_cmd_remove_oops(); break;
- X
- X case 'a': pde_cmd_add((PDE *)0); break;
- X
- X case 'e': pde_add_or_edit(curr_pde,1); break;
- X
- X#if defined(PDE_DEBUG)
- X case CTL_BSLASH: /* undocumented ^\ */
- X pde_cmd_dump_list(); break;
- X#endif
- X
- X case CTL_L:
- X case CTL_R:
- X touchwin(stdscr);
- X wrefresh(stdscr);
- X touchwin(dirw);
- X wrefresh(dirw);
- X touchwin(scrw);
- X wrefresh(scrw);
- X break;
- X
- X default:
- X sprintf(s80,"illegal command: %c",
- X (isprint(cmd)) ? cmd : '?');
- X dirw_bot_msg(s80);
- X break;
- X }
- X }
- X if(cmd == XFend)
- X return;
- X pde_list_save_if_dirty();
- X windows_end(dirw);
- X
- X redisplay_rcvr_screen();
- X
- X if(rcvr_active)
- X start_rcvr_process(0);
- X} /* end of pde_list_manager */
- X
- X/*+-------------------------------------------------------------------------
- X choose_line(baud) - user is dialing a remote and will take 'Any' line
- X--------------------------------------------------------------------------*/
- Xvoid
- Xchoose_line(baud)
- Xuint baud;
- X{
- Xstruct dvent *dve;
- Xchar s32[32];
- X
- X/* check out current line choice */
- X if(access(shm->Lline,6))
- X goto GET_LINE_THAT_MATCHES_BAUD;
- X dve = getdvline(shm->Lline + 8);
- X enddvent();
- X if(!dve) /* if no match in Devices, let ecu fend for itself */
- X return;
- X
- X/* if shm->Lline is open and baud rate ok, no further */
- X if(shm->Liofd > 0)
- X {
- X if((dve->low_baud <= baud) && (baud <= dve->high_baud))
- X return;
- X lclose(); /* won't do ... gotta find a new one */
- X goto GET_LINE_THAT_MATCHES_BAUD;
- X }
- X
- X if(!shm->Lline[0])
- X memset(shm->Lline,0,sizeof(shm->Lline));
- X
- X/* see if shm->Lline in use by someone else; if not and baud rate ok, no further */
- X switch(utmp_status(shm->Lline))
- X {
- X case US_NOTFOUND: /* not in utmp, or getty dead */
- X if(line_locked(shm->Lline))
- X goto GET_LINE_THAT_MATCHES_BAUD;
- X case US_LOGIN: /* enabled for login, idle */
- X if((dve->low_baud <= baud) && (baud <= dve->high_baud))
- X return;
- X }
- X
- X/* we've got to pick a new line */
- XGET_LINE_THAT_MATCHES_BAUD:
- X
- X strcpy(s32,"/dev/tty");
- X while(1)
- X {
- X if(!(dve = getdvbaud(baud)))
- X {
- X enddvent(); /* no match ... */
- X return; /* ... so let current shm->Lline fail */
- X }
- X/* by now, we know shm->Lline wont work */
- X if(!strcmp(dve->line,shm->Lline + 5))
- X continue;
- X/* if not acu, dont use it */
- X if(ulindex(dve->type,"ACU") < 0)
- X continue;
- X strcpy(&s32[8],dve->line + 3); /* yeech ... make "/dev/ttyxx" */
- X switch(utmp_status(s32))
- X {
- X case US_NOTFOUND: /* not in utmp, or getty dead */
- X if(line_locked(s32))
- X continue;
- X case US_LOGIN: /* enabled for login, idle */
- X strcpy(shm->Lline,s32); /* @@@@@@@@@@@ MATCH @@@@@@@@@ */
- X shm->Lline[9] = to_lower(shm->Lline[9]);
- X enddvent();
- X return;
- X }
- X }
- X /*NOTREACHED*/
- X
- X} /* end of choose_line */
- X
- X/*+-------------------------------------------------------------------------
- X copy_pde_to_lvar(tpde)
- X
- Xif changing line, close old line and open new one
- X--------------------------------------------------------------------------*/
- Xvoid
- Xcopy_pde_to_lvar(tpde)
- Xregister PDE *tpde;
- X{
- Xint reopen = 0;
- Xint lerr;
- X
- X if(tpde->tty[0])
- X {
- X if(shm->Lline[0] && shm->Lline[8] && strcmp(tpde->tty,shm->Lline + 8))
- X {
- X reopen = 1;
- X shm->Lmodem_already_init = 0;
- X lclose();
- X }
- X strcpy(shm->Lline,"/dev/tty");
- X strcat(shm->Lline,tpde->tty);
- X }
- X else
- X choose_line(tpde->baud);
- X
- X if(shm->Liofd < 0)
- X reopen = 1;
- X strcpy(shm->Llogical,tpde->logical);
- X strcpy(shm->Ldescr,tpde->descr);
- X strcpy(shm->Ltelno,tpde->telno);
- X if(!shm->Ldescr[0])
- X strcpy(shm->Ldescr,shm->Llogical);
- X shm->Lparity = tpde->parity;
- X if(shm->Lbaud != tpde->baud)
- X shm->Lmodem_already_init = 0;
- X shm->Lbaud =tpde->baud;
- X if(reopen)
- X {
- X if(lerr = lopen())
- X {
- X curbotleft();
- X if(lerr == LOPEN_LCKERR || lerr == LOPEN_UNKPID)
- X pputs("port not available\n");
- X pprintf("%s: %s\n",shm->Lline,lopen_err_text(lerr));
- X hangup(HANGUP_LINE_OPEN_ERROR);
- X }
- X }
- X else
- X {
- X lset_baud_rate(1);
- X lset_parity(1);
- X }
- X
- X} /* end of copy_pde_to_lvar */
- X
- X/*+-----------------------------------------------------------------------
- X lookup_logical_telno()
- X
- XA logical telephone number is either a symbolic identifer
- Xor an lcb->telno telephone number. A symbolic identifer is a string
- Xwhose initial character is a letter.
- XAn lcb->telno telephone number begins with a numeral.
- X
- XThis function converts a logical telephone number
- Xto a telephone number (suitable for dialing by a Hayes or
- Xcompatible modem). It is called by command line processing
- Xwhen 'ecu logical-name' is specified or in response to
- Xa %dial logical-name. It is not used by the curses directory
- Xmanager.
- X
- XIf the first character of 'shm->Llogical' is a digit, the entire
- Xinput string is copied to 'shm->Ltelno'. If 'shm->Llogical' has a
- Xnon-numeric first character, then the user's home directory is
- Xsearched for the file .ecu/phone (~/.ecu/phone). The file is a series
- Xof records terminated with a newline. Each record has two or three
- Xfields separated by colons. The first field is the logical telephone
- Xnumber and the second field is the telephone number. The third
- X(optional) field contains a string to further identify the telephone
- Xnumber being called.
- X
- XCASE IS INSIGNIFICANT in logical entry names for this procedure
- X
- XThe function returns one of the following:
- X
- X 1 if no error occurs
- X 0 if not numeric phone number and logical string not found in file.
- X
- X------------------------------------------------------------------------*/
- Xlookup_logical_telno()
- X{
- Xregister PDE *tpde;
- X
- X if(!pde_list_quan)
- X {
- X if(pde_list_read())
- X return(0);
- X }
- X
- X/* if literal phone number, return it immediately */
- X
- X if(isdigit(shm->Llogical[0]))
- X {
- X strcpy(shm->Ltelno,shm->Llogical);
- X strcpy(shm->Ldescr,shm->Llogical);
- X return(1);
- X }
- X
- X/* if logical phone number */
- X if(tpde = pde_list_search(shm->Llogical,0)) /* inexact search */
- X {
- X copy_pde_to_lvar(tpde);
- X return(1);
- X }
- X
- X shm->Llogical[0] = 0;
- X shm->Lrname[0] = 0;
- X shm->Ltelno[0] = 0;
- X shm->Ldescr[0] = 0;
- X return(0);
- X
- X} /* end of lookup_logical_telno */
- X
- X/* end of ecuphone.c */
- X/* vi: set tabstop=4 shiftwidth=4: */
- SHAR_EOF
- $TOUCH -am 0507233390 ecuphone.c &&
- chmod 0644 ecuphone.c ||
- echo "restore of ecuphone.c failed"
- set `wc -c ecuphone.c`;Wc_c=$1
- if test "$Wc_c" != "36781"; then
- echo original size 36781, current size $Wc_c
- fi
- # ============= ecuphrase.c ==============
- echo "x - extracting ecuphrase.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > ecuphrase.c &&
- X/* CHK=0x62B9 */
- X/*+-----------------------------------------------------------------
- X ecuphrases.c
- X wht%n4hgf@gatech.edu
- X
- X Defined functions:
- X phrase_help()
- X phrases(nargc,nargv)
- X read_phrases()
- X
- X------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:05-07-1990-21:23-wht@n4hgf---- 2.80 --- */
- X/*:03-25-1990-14:11-wht@n4hgf------ x2.70 ------- */
- X/*:10-15-1989-17:23-wht-dont show empty phrase list */
- X/*:07-03-1989-22:57-wht------ x2.00 ----- */
- X/*:06-24-1989-16:53-wht-flush edits --- ecu 1.95 */
- X
- X#include "ecu.h"
- X
- X#define P_N_QUAN 23
- Xchar *phrases_string[P_N_QUAN];
- Xchar *phrases_label[P_N_QUAN];
- Xint phrases_count = 0;
- Xint phrases_resident = 0;
- X
- X/*+-----------------------------------------------------------------------
- X read_phrases()
- X------------------------------------------------------------------------*/
- Xvoid
- Xread_phrases()
- X{
- Xregister char *phrases_str;
- Xchar phrases_buf[256];
- Xchar phrases_buf_copy[256];
- Xchar *phrases_lbl;
- XFILE *fd_phrase;
- X
- X if(phrases_resident)
- X {
- X while(phrases_count)
- X free(phrases_string[--phrases_count]);
- X phrases_resident = 0;
- X }
- X
- X get_home_dir(phrases_buf);
- X strcat(phrases_buf,"/.ecu/phrases");
- X
- X if( (fd_phrase = fopen(phrases_buf,"r")) == NULL)
- X {
- X ff(se,"\r\n");
- X perror(phrases_buf);
- X ff(se,"\r\n");
- X ff(se,"... no phrases resident\r\n");
- X return;
- X }
- X
- X/* we have an open .ecu/phrase file */
- X phrases_count = 0;
- X while(fgets(phrases_buf,sizeof(phrases_buf),fd_phrase) != NULL)
- X {
- X phrases_buf[strlen(phrases_buf) - 1] = 0;
- X if(strlen(phrases_buf) == 0)
- X continue;
- X
- X if(phrases_count == P_N_QUAN)
- X {
- X ff(se,"\r\nMaximum number of phrases %d exceeded\r\n",P_N_QUAN);
- X ff(se,"rest of file ignored, starting with the following:\r\n");
- X ff(se,"--> %s\r\n\r\n",phrases_buf);
- X phrases_resident = 1;
- X fclose(fd_phrase);
- X return;
- X }
- X strcpy(phrases_buf_copy,phrases_buf);
- X phrases_lbl = phrases_buf_copy;
- X for(phrases_str = phrases_buf_copy; *phrases_str; phrases_str++)
- X {
- X if(*phrases_str == ':')
- X {
- X *phrases_str++ = 0;
- X break;
- X }
- X if(*phrases_str == 0)
- X {
- X ff(se,"invalid entry `%s'\n",phrases_buf);
- X continue;
- X }
- X }
- X
- X if(!(phrases_string[phrases_count] = malloc(strlen(phrases_str)+2)) ||
- X !(phrases_label[phrases_count] = malloc(strlen(phrases_lbl)+2)))
- X {
- X ff(se,"\r\nNo more memory for phrases\r\n");
- X ff(se,"rest of file ignored, starting with the following:\r\n");
- X ff(se,"--> %s\r\n\r\n",phrases_buf);
- X phrases_resident = 1;
- X fclose(fd_phrase);
- X if(phrases_string[phrases_count])
- X free(phrases_string[phrases_count]);
- X return;
- X }
- X strcpy(phrases_string[phrases_count],phrases_str);
- X strcpy(phrases_label[phrases_count],phrases_lbl);
- X phrases_count++;
- X } /* while records left to read */
- X
- X fclose(fd_phrase);
- X phrases_resident = 1;
- X} /* end of read_phrases */
- X
- X/*+-------------------------------------------------------------------------
- X phrases(nargc,nargv)
- X--------------------------------------------------------------------------*/
- Xphrases(nargc,nargv)
- Xint nargc;
- Xchar **nargv;
- X{
- Xregister itmp;
- Xregister ichar;
- Xregister char *cptr;
- Xint old_ttymode = get_ttymode();
- Xextern char *phrases_string[];
- Xextern int phrases_count;
- Xextern int phrases_resident;
- Xextern int interrupt;
- Xextern int icmd_prompt_len;
- X
- X for(itmp = icmd_prompt_len + strlen(nargv[0]); itmp; itmp--)
- X fputs("\b \b",se);
- X
- X itmp = atoi(nargv[0]);
- X
- X if(itmp == 0)
- X {
- X ff(se,"\r\n");
- X read_phrases();
- X if(!phrases_count)
- X return(0);
- X stand_out();
- X ff(se,
- X" # | mnemonic | phrase ");
- X stand_end();
- X ff(se,"\r\n");
- X for(itmp = 0; itmp < phrases_count; itmp++)
- X ff(se,"%2d | %12s | %s\r\n",itmp + 1,phrases_label[itmp],
- X phrases_string[itmp]);
- X return(0);
- X }
- X else
- X if(phrases_resident == 0)
- X read_phrases();
- X
- X if(itmp > phrases_count)
- X {
- X ff(se," unknown: %d\r\n",itmp);
- X return(-1);
- X }
- X else
- X {
- X cptr = phrases_string[itmp - 1];
- X ttymode(2);
- X while(*cptr)
- X {
- X if(interrupt)
- X break;
- X
- X switch(ichar = *cptr++)
- X {
- X case '^':
- X ichar = *cptr++;
- X if((ichar >= '@') && (ichar <= '_'))
- X lputc_paced(0,ichar & 0x1F);
- X else if(ichar == '?')
- X lputc_paced(0,0x7F);
- X else
- X {
- X switch(ichar)
- X {
- X case 0:
- X goto NULL_FOUND;
- X case 'r':
- X lputc_paced(0,'\r');
- X break;
- X case 'n':
- X lputc_paced(0,'\n');
- X break;
- X case 't':
- X lputc_paced(0,'\t');
- X break;
- X case '^':
- X lputc_paced(0,'^');
- X break;
- X case 'p':
- X itmp = atoi(cptr);
- X while((*cptr >= '0') && (*cptr <= '9'))
- X cptr++;
- X if(*cptr == '.')
- X cptr++;
- X if(!itmp)
- X itmp = 1;
- X nap((long)itmp * 100L);
- X break;
- X case 'a':
- X itmp = atoi(cptr);
- X while((*cptr >= '0') && (*cptr <= '9'))
- X cptr++;
- X if(*cptr == '.')
- X cptr++;
- X if(itmp < nargc)
- X {
- X lputs_paced(0,nargv[itmp]);
- X itmp = strlen(nargv[itmp]);
- X }
- X break;
- X }
- X }
- X break;
- X default:
- X lputc_paced(0,ichar);
- X }
- X }
- X
- XNULL_FOUND:
- X if(interrupt)
- X {
- X interrupt = 0;
- X ff(se,"\r\n--> interrupted\r\n");
- X }
- X
- X }
- X
- X ttymode(old_ttymode);
- X return(0);
- X
- X} /* end of phrases */
- X
- X
- X/*+-------------------------------------------------------------------------
- X phrase_help()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xphrase_help()
- X{
- X ff(se,"^r == \\r ^n == \\n ^t == \\t ^^ == '^'\r\n");
- X ff(se,"^p#. pause # secs\r\n");
- X ff(se,"^a#. arg number # of %%# invocation\r\n");
- X} /* end of phrase_help */
- X/* vi: set tabstop=4 shiftwidth=4: */
- SHAR_EOF
- $TOUCH -am 0507233390 ecuphrase.c &&
- chmod 0644 ecuphrase.c ||
- echo "restore of ecuphrase.c failed"
- set `wc -c ecuphrase.c`;Wc_c=$1
- if test "$Wc_c" != "5689"; then
- echo original size 5689, current size $Wc_c
- fi
- echo "End of part 5, continue with part 6"
- exit 0
-
-