ecu - SCO XENIX V/{2,3}86 Extended CU part 06/47

Warren Tucker wht at tridom.uucp
Mon Oct 9 07:45:09 AEST 1989


---- Cut Here and unpack ----
#!/bin/sh
# this is part 6 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file eculine.c continued
#
CurArch=6
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file eculine.c"
sed 's/^X//' << 'SHAR_EOF' >> eculine.c
X			Ltermio.c_cflag |= CS7 | PARENB | PARODD;
X			Ltermio.c_iflag |= ISTRIP;
X			break;
X		default:
X			ff(se,"invalid parity: %c ... defaulting to no parity\r\n");
X		case 0:
X		case 'n':
X			Ltermio.c_cflag |= CS8;
X			Ltermio.c_iflag &= ~(ISTRIP);
X			Lparity = 0;
X			break;
X	}			
X
X#if defined(HO_HUM)
X	if(ioctl_flag)
X#endif
X		 ioctl(Liofd,TCSETA,(char *)&Ltermio);
X
X}	/* end of lset_parity */
X
X/*+-------------------------------------------------------------------------
X	lclear_xmtr_xoff()
X--------------------------------------------------------------------------*/
Xvoid
Xlclear_xmtr_xoff()
X{
X	ioctl(Liofd,TCXONC,(char *)1); /* restart xmtr output */
X}	/* end of lclear_xmtr_xoff */
X
X/*+-------------------------------------------------------------------------
X	lbreak()
X--------------------------------------------------------------------------*/
Xvoid
Xlbreak()
X{
X	ioctl(Liofd,TCSBRK,(char *)0);
X}	/* end of lbreak */
X
X/*+----------------------------------------------------------------------
X	lopen()
Xreturns negative LOPEN_ codes if failure else positive pid using line
Xelse 0 if successful open
X------------------------------------------------------------------------*/
Xint
Xlopen()
X{
Xregister itmp = strlen(Lline);
Xstruct stat ttystat;
X
X	if(Liofd >= 0)
X		return(LOPEN_ALREADY);
X	if(isupper(Lline[itmp - 1]))
X		Lline[itmp - 1] = tolower(Lline[itmp - 1]);
X	if(!strcmp(Lline,"/dev/tty"))
X		return(LOPEN_INVALID);
X	if(itmp = lock_tty())		/* get lock file */
X		return(itmp);
X	if(stat(Lline,&ttystat) < 0)
X		return(LOPEN_NODEV);
X	Liofd = open(Lline,O_RDWR,0777);
X	if(Liofd < 0)
X		return(LOPEN_OPNFAIL);
X	else
X	{
X		ioctl(Liofd,TCGETA,(char *) &Ltermio);
X		Ltermio.c_iflag = (IGNPAR | IGNBRK | IXOFF );
X		Ltermio.c_cflag |= (CLOCAL | CREAD | HUPCL);
X		Ltermio.c_lflag = 0;
X
X		Ltermio.c_cc[VMIN]   = 1;
X		Ltermio.c_cc[VTIME]  = 1;
X		lset_baud_rate(0);		/* do not perform ioctl */
X		lset_parity(1);			/* do perform ioctl */
X	}
X
X	return(0);
X
X}	/* end of lopen */
X
X/*+-----------------------------------------------------------------------
X	lclose()
X------------------------------------------------------------------------*/
Xvoid
Xlclose()
X{
X	if(Liofd < 0)
X		return;
X	unlock_tty();	/* kill lock file (writes to line; must go before close) */
X	close(Liofd);
X	Liofd = -1;
X
X}	/* end of lclose */
X
X/*+-------------------------------------------------------------------------
X	ltoggle_dtr()
X--------------------------------------------------------------------------*/
Xvoid
Xltoggle_dtr()
X{
X	close(Liofd);
X	nap(300L);
X	Liofd = open(Lline,O_RDWR,0777);
X	ioctl(Liofd,TCSETA,(char *)&Ltermio);
X	nap(600L);
X}	/* end of ltoggle_dtr */
X
X/*+-------------------------------------------------------------------------
X	lxon_xoff(flag)
XIXON specifies whether or not we respond to xon/xoff characters
XIXOFF specifies whether or not we generate XON/XOFF characters
X--------------------------------------------------------------------------*/
Xvoid
Xlxon_xoff(flag)
Xint flag;
X{
X	if(flag & IXON)
X		Ltermio.c_iflag |= IXON;
X	else
X		Ltermio.c_iflag &= ~IXON;
X
X	if(flag & IXOFF)
X		Ltermio.c_iflag |= IXOFF;
X	else
X		Ltermio.c_iflag &= ~IXOFF;
X
X	ioctl(Liofd,TCSETA,(char *)&Ltermio);
X
X}	/* end of lxon_xoff */
X
X/*+-------------------------------------------------------------------------
X	lget_xon_xoff(ixon,ixoff)
X--------------------------------------------------------------------------*/
Xvoid
Xlget_xon_xoff(ixon,ixoff)
Xint *ixon;
Xint *ixoff;
X{
X	*ixon  = (Ltermio.c_iflag & IXON) != 0;
X	*ixoff = (Ltermio.c_iflag & IXOFF) != 0;
X}	/* end of lget_xon_xoff */
X
X/*+-------------------------------------------------------------------------
X	lopen_err_text(lerr)
X--------------------------------------------------------------------------*/
Xchar *
Xlopen_err_text(lerr)
Xint lerr;
X{
Xstatic char lerr_s40[40];
X
X	switch(lerr)
X	{
X		case LOPEN_INVALID: return("invalid line name");
X		case LOPEN_UNKPID: return("unknown pid is using line");
X		case LOPEN_LCKERR: return("error creating lock file");
X		case LOPEN_NODEV: return("line does not exist");
X		case LOPEN_ALREADY: return("line already open");
X		case LOPEN_OPNFAIL: return("line open error (not installed?)");
X		case LOPEN_ENABLED: return("line enabled for incoming login");
X		case LOPEN_ENABLED_IN_USE: return("line in use by incoming login");
X		case LOPEN_DIALOUT_IN_USE: return("line in use by another dial out");
X	}
X	if(lerr > 0)
X		sprintf(lerr_s40,"pid %d using line",lerr);
X	else
X		sprintf(lerr_s40,"unknown line error %d",lerr);
X	return(lerr_s40);
X}	/* end of lopen_err_text */
X
X/* end of eculine.c */
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo "File eculine.c is complete"
chmod 0644 eculine.c || echo "restore of eculine.c fails"
echo "x - extracting ecunumrev.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecunumrev.c &&
X/* CHK=0x0985 */
X/*+-----------------------------------------------------------------------
X	ecunumrev.c
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-03-1989-22:57-wht------------- ecu 2.00 ---------------- */
X/*:06-24-1989-16:53-wht-flush edits --- ecu 1.95 */
X
Xchar *numeric_revision = "unet1";
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
chmod 0644 ecunumrev.c || echo "restore of ecunumrev.c fails"
echo "x - extracting ecuphone.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecuphone.c &&
X/* CHK=0x0280 */
X/*+-------------------------------------------------------------------------
X	ecuphone.c -- visual phone dialer/directory editor
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
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/*:08-31-1989-12:37-wht-was not always setting brate/parity properly */
X/*:07-03-1989-22:57-wht------------- ecu 2.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
X#if defined(M_XENIX)
X#define DIAL	XFend
X#else
X#define DIAL	CTL_D
X#endif
X
Xvoid dirw_bot_msg();
X
X#if defined(M_XENIX)
Xchar *strchr();
Xchar *strrchr();
X#endif
X
X#if defined(pyr)
X#define strchr index
X#define strrchr rindex
Xchar *index();
Xchar *rindex();
X#endif
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[];
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,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->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];
Xchar s80[80];
XFILE *fp_phone;
XPDE		*tpde;
Xchar *str_token();
Xchar *malloc();
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))) == (PDE *)0)
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,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,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--------------------------------------------------------------------------*/
Xpde_display_logical(line,tpde,stand_out)
Xint line;
XPDE		*tpde;
Xint stand_out;
X{
X	wmove(scrw,line,0);
X	waddch(scrw,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,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,sVR);
X			wclrtoeol(scrw);
X			wmove(scrw,line,SCRW_COLS - 1);
X			waddch(scrw,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		wclear(scrw);
X		wrefresh(scrw);
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 itmp;
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		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		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		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;
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			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);
SHAR_EOF
echo "End of part 6"
echo "File ecuphone.c is continued in part 7"
echo "7" > s2_seq_.tmp
exit 0
-- 
-------------------------------------------------------------------
Warren Tucker, Tridom Corporation       ...!gatech!emory!tridom!wht 
Ker-au'-lo-phon.  An 8-foot partial flue-stop, having metal pipes
surmounted by adjustable rings, and with a hole bored near the top
of each pipe, producing a soft and "reedy" tone.



More information about the Alt.sources mailing list