home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!rutgers!modus!lpds!wcp
- From: wcp@lpds.sublink.org (Walter C. Pelissero)
- Newsgroups: alt.sources
- Subject: mgetty - A modular getty v1.0, Part01/04
- Message-ID: <1993Jan22.161629.754@lpds.sublink.org>
- Date: 22 Jan 93 16:16:29 GMT
- Organization: Sweet home under white clouds
- Lines: 1888
- Phone: + 39 2 8464117 - 8435411 (work) 8267089 (home)
- Postal-Address: Via G. de Ruggiero 87, 20142 Milano - Italia
-
- Since I had enough requests to justify a posting, here it is.
-
- From the README file:
-
- Mgetty is a getty replacement, programmable via Tcl scripts, for lines
- hooked to a DCE. Tcl is a language written by John Ousterhout, that
- within mgetty let you do what you want with ttys and modems without
- writing complex C code, at least for the trivial actions.
-
- Mgetty is modular for two reasons: it is built around Tcl, which is
- itself a modular script language (you can add, delete, and rewrite
- commands in terms of C functions); it needs some external program to
- perform some advanced action (like fax receiving, voice playing and
- recording).
-
- Please send any bug report, fix, hint to
-
- wcp@lpds.sublink.org
-
-
-
- Submitted-by: wcp@lpds
- Archive-name: mgetty-1.0/part01
-
- ---- Cut Here and feed the following to sh ----
- #!/bin/sh
- # This is mgetty-1.0, a shell archive (produced by shar 3.49)
- # To extract the files from this archive, save it to a file, remove
- # everything above the "!/bin/sh" line above, and type "sh file_name".
- #
- # made 01/22/1993 16:10 UTC by wcp@lpds
- # Source directory /u/wcp/c/mgetty
- #
- # existing files will NOT be overwritten unless -c is specified
- # This format requires very little intelligence at unshar time.
- # "if test", "cat", "rm", "echo", "true", and "sed" may be needed.
- #
- # This is part 1 of a multipart archive
- # do not concatenate these parts, unpack them in order with /bin/sh
- #
- # This shar contains:
- # length mode name
- # ------ ---------- ------------------------------------------
- # 3356 -r-------- Makefile
- # 2782 -r-------- README
- # 954 -r-------- ZyXEL
- # 7879 -r-------- c2rec.c
- # 12233 -r-------- class2rec.c
- # 2612 -r-------- common.c
- # 3004 -r-------- common.h
- # 2047 -r-------- config.h
- # 2411 -r-------- doc/c2rec.8
- # 7282 -r-------- doc/mgetty.8
- # 2518 -r-------- doc/play.8
- # 3592 -r-------- doc/record.8
- # 1446 -r-------- listen.sh
- # 1121 -r-------- localize.c
- # 3323 -r-------- locks.c
- # 29247 -r-------- mgetty.c
- # 5215 -r-------- modemio.c
- # 1125 -r-------- modemio.h
- # 6653 -r-------- play.c
- # 2012 -r-------- printfax.sh
- # 11162 -r-------- record.c
- # 2445 -r-------- scripts/zyxel4.tcl
- # 3953 -r-------- scripts/zyxel5.tcl
- # 5120 -r-------- scripts/zyxel5cb.tcl
- # 1463 -r-------- temp.c
- # 3354 -r-------- voice.c
- # 1472 -r-------- voice.h
- # 1641 -r-------- xgetty.c
- # 2724 -r-------- zyxel.c
- # 1666 -r-------- zyxel.h
- #
- if test -r _shar_seq_.tmp; then
- echo 'Must unpack archives in sequence!'
- echo Please unpack part `cat _shar_seq_.tmp` next
- exit 1
- fi
- # ============= Makefile ==============
- if test -f 'Makefile' -a X"$1" != X"-c"; then
- echo 'x - skipping Makefile (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting Makefile (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
- X#
- X# $Id: Makefile,v 1.2 1993/01/07 23:14:50 wcp Exp $
- X#
- X# Copyright (C) 1992 Walter Pelissero
- X#
- X# This program is free software; you can redistribute it and/or modify
- X# it under the terms of the GNU General Public License as published by
- X# the Free Software Foundation; either version 1, or (at your option)
- X# any later version.
- X#
- X# This program is distributed in the hope that it will be useful,
- X# but WITHOUT ANY WARRANTY; without even the implied warranty of
- X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X# GNU General Public License for more details.
- X#
- X# You should have received a copy of the GNU General Public License
- X# along with this program; if not, write to the Free Software
- X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X#
- X
- X#
- X# $Log: Makefile,v $
- X# Revision 1.2 1993/01/07 23:14:50 wcp
- X# Added listen shell script, and moved tcl scripts under appropriate
- X# directory ("scripts").
- X#
- X# Revision 1.1 1993/01/06 18:23:05 wcp
- X# Initial revision
- X#
- X# Revision 1.2 1992/07/07 16:51:47 wally
- X# Added class2 and zyxel senders.
- X# Ps2pbm is a C program now.
- X# Minor fixes.
- X#
- X# Revision 1.1 1992/04/28 16:13:28 wally
- X# Initial revision
- X#
- X#
- X
- XCC = gcc
- XCFLAGS = -g -Wall -DDEBUG=7 -DLIB_DIR=\"$(LIBDIR)\" -DETC_DIR=\"$(ETCDIR)\" \
- X -DTMP_DIR=\"$(TMPDIR)\" -DBIN_DIR=\"$(BINDIR)\" \
- X -DPBMPLUS=\"$(PBMPLUS)\"
- XLDFLAGS = -g -ldbmalloc -lstdc -ltcl -lx
- XINSTALL = /usr/local/gnubin/install
- XBINDIR = /usr/local/bin
- XETCDIR = /usr/local/etc
- XLIBDIR = /usr/local/lib/mgetty
- XTMPDIR = /tmp
- XPBMPLUS = /usr/local/pbmplus
- X
- XBINARIES = localize mgetty c2rec xgetty record play
- XSCRIPTS = printfax listen
- X
- X%: %.sh
- X sed -e "`localize`" $< > $@
- X
- Xall: $(BINARIES) $(SCRIPTS)
- X
- X($SCRIPTS): localize
- X
- X#
- X# Binary executables
- X#
- Xc2rec: c2rec.o common.o modemio.o zyxel.o
- Xrecord: record.o common.o modemio.o zyxel.o voice.o
- Xplay: play.o common.o modemio.o zyxel.o voice.o
- Xxgetty: xgetty.o
- Xmgetty: mgetty.o common.o locks.o temp.o modemio.o
- X
- X#
- X# Object modules
- X#
- Xc2rec.o : c2rec.c common.h config.h modemio.h zyxel.h
- Xcommon.o : common.c
- Xlocalize.o : localize.c
- Xlocks.o : locks.c common.h config.h
- Xmgetty.o : mgetty.c common.h config.h modemio.h
- Xmodemio.o : modemio.c common.h config.h
- Xplay.o : play.c common.h config.h modemio.h zyxel.h voice.h
- Xrecord.o : record.c common.h config.h modemio.h zyxel.h voice.h
- Xtemp.o : temp.c common.h config.h
- Xvoice.o : voice.c voice.h common.h config.h modemio.h zyxel.h
- Xxgetty.o : xgetty.c
- Xzyxel.o : zyxel.c common.h config.h modemio.h zyxel.h
- X
- X#
- X# Miscellaneous
- X#
- Xinstall: all
- X -mkdir $(LIBDIR) && chmod 755 $(LIBDIR)
- X -mkdir $(LIBDIR)/ttys && chmod 755 $(LIBDIR)/ttys
- X $(INSTALL) -m 644 -o bin -g bin scripts/*.tcl $(LIBDIR)/ttys
- X $(INSTALL) -m 711 -o bin -g bin c2rec record play $(LIBDIR)
- X $(INSTALL) -m 755 -o bin -g bin printfax $(LIBDIR)
- X $(INSTALL) -m 755 -o bin -g bin listen $(LIBDIR)
- X -mkdir $(ETCDIR) && chmod 755 $(ETCDIR)
- X $(INSTALL) -m 700 -o bin -g bin mgetty $(ETCDIR)
- X -mkdir $(LIBDIR)/sound && chmod 755 $(LIBDIR)/sound
- X $(INSTALL) -m 644 -o bin -g bin sound/* $(LIBDIR)/sound
- X
- Xinstall_xenix: install
- X [ -f /etc/Getty ] || mv /etc/getty /etc/Getty
- X $(INSTALL) -m 700 -o bin -g bin xgetty /etc/getty
- X
- Xclean:
- X $(RM) *.o faxem core a.out *.a lp-model $(SCRIPTS) $(BINARIES) \
- X c2rec mgetty
- X
- Xdist: clean
- X $(RM) *~ \#*\#
- X rcsclean
- X
- X.PHONY: clean dist all install install_xenix
- SHAR_EOF
- true || echo 'restore of Makefile failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= README ==============
- if test -f 'README' -a X"$1" != X"-c"; then
- echo 'x - skipping README (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting README (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'README' &&
- X$Id: README,v 1.4 1993/01/22 16:08:27 wcp Exp $
- X
- X
- X
- X MGETTY 1.0
- X a modular getty
- X
- XMgetty is a getty replacement, programmable via Tcl scripts, for lines
- Xhooked to a DCE. Tcl is a language written by John Ousterhout, that
- Xwithin mgetty let you do what you want with ttys and modems without
- Xwriting complex C code, at least for the trivial actions.
- X
- XMgetty is modular for two reasons: it is built around Tcl, which is
- Xitself a modular script language (you can add, delete, and rewrite
- Xcommands in terms of C functions); it needs some external program to
- Xperform some advanced action (like fax receiving, voice playing and
- Xrecording).
- X
- XWhile mgetty has been thought as a multi purposes getty, it was tested
- Xonly on a ZyXEL U-1496 attached on a Xenix 2.3.3 system, so all the
- Xexternal programs and configuration scripts were modeled around that
- Xkind of modem, and code may be not so portable. However it's likely
- Xthat most of the work will not be lost adapting Tcl scripts and
- Xexternal programs to a new modem (the fax receiver, for example, could
- Xbe used as is), but if you make any change, please mail me.
- X
- X
- X
- XINSTALLATION.
- X
- XFirst of all you must have Tcl 6.1 or better to be able to compile
- Xmgetty. If you don't have that library you can remove mgetty from your
- Xdirectory, because Tcl is essential.
- X
- XTo install mgetty:
- X
- X- edit the config.h file
- X- edit the Makefile
- X- "make"
- X- do a "make install" or "make install_xenix"
- X
- XManual pages are in doc directory. They are not installed by "make
- Xinstall", you have to do it by hand. The documentation is quite brief
- Xand it relies completely on Tcl docs. You must know Tcl script
- Xlanguage before you start make anything useful with mgetty besides
- Xusing sample scripts.
- X
- XIf you are on a Xenix site you have to substitute your /etc/getty
- Xprogram with xgetty (provided with mgetty) that looking into a file
- X(currently /usr/local/etc/gettys, see the source code) it spawns the
- Xappropriate getty. A sample gettys file is:
- X
- X # Some comment
- X tty05=/u/wcp/c/mgetty/mgetty
- X tty2A=/u/wcp/c/mgetty/mgetty
- X
- XIf an appropriate entry for the tty is not found then the original
- Xgetty is spawned.
- X
- XSample voice files are not provided, so the sound directory is empty.
- XYou can create your greeting messages once you compiled successfully,
- Xand put them in sound directory to install them automatically whenever
- Xyou type "make install". Read ZyXEL, for details.
- X
- XSample mgetty scripts can be found in scripts directory. They are
- Xautomatically installed when you type "make install". Feel free to
- Xmodify them and write many others, and, please, send me the ones you
- Xthink can be interesting to other people, if I also think so, I'll
- Xmake them available with mgetty sources.
- X
- XPlease send any bug report, fix, hint to
- X
- X wcp@lpds.sublink.org
- SHAR_EOF
- true || echo 'restore of README failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= ZyXEL ==============
- if test -f 'ZyXEL' -a X"$1" != X"-c"; then
- echo 'x - skipping ZyXEL (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting ZyXEL (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'ZyXEL' &&
- X$Id: ZyXEL,v 1.1 1993/01/15 23:10:08 wcp Exp $
- X
- XZyXEL U-1496 owners may use the voice features of their modem to send
- Xor receive sound messages. These features are supported with the play
- Xand record programs.
- X
- XStart recording a greeting message using record. You can find the
- Xdocumentation in doc directory. You may also need to read the
- Xdocumentation about this topic that comes with the modem. Here the
- Xtrick to avoid recording of a trailing silence is to interrup the
- Xrecording program (type DEL or whatever is appropriate on you
- Xkeyboard). Record handle this interrumption in the right way.
- X
- XTo listen to your messages use the play program.
- X
- XUnfortunately, I could implement the voice features only for ZyXEL
- XU-1496 modems, because I have only this kind of modem at hand. If you
- Xwrite something for other modems, please send me your work and I'll
- Xmake it available with mgetty.
- X
- XPlease send bug reports, fixes, hints, to
- X
- X wcp@lpds.sublink.org
- SHAR_EOF
- true || echo 'restore of ZyXEL failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= c2rec.c ==============
- if test -f 'c2rec.c' -a X"$1" != X"-c"; then
- echo 'x - skipping c2rec.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting c2rec.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'c2rec.c' &&
- X/*
- X * $Id: c2rec.c,v 4.3 1993/01/22 15:14:24 wcp Exp $
- X *
- X * Copyright (C) 1992 Walter Pelissero
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * $Log: c2rec.c,v $
- X * Revision 4.3 1993/01/22 15:14:24 wcp
- X * Removed magic string.
- X *
- X * Revision 4.2 1993/01/06 17:47:40 wcp
- X * More robust handling of inter-page negotiation.
- X * Already_connected is no longer needed.
- X * Added SPEED as header entry in output files.
- X * Converted debug messages to dprint() syntax.
- X * Modified output file name generation (base name may be a directory
- X * or a file). Removed -b option: now basename is mandatory.
- X *
- X * Revision 4.1 1993/01/02 18:55:30 wcp
- X * Rewritten to make it work under mgetty just as fax receiver.
- X *
- X * Revision 3.2 1992/09/04 13:30:18 wally
- X * Deleted unnecessary array reference in mdread().
- X * Corrected some misspelling.
- X * Fix in getLoginName(): returned value had to point to static area.
- X *
- X * Revision 3.1 1992/08/29 18:21:51 wally
- X * This is now a getty program (no need of an external getty).
- X *
- X * Revision 2.1 1992/08/27 19:30:11 wally
- X * Modified to be a real replacement for getty.
- X * Better baud rates handling.
- X * /etc/utmp management.
- X * New signal handling.
- X * Many bug fixes.
- X *
- X * Revision 1.1 1992/07/17 16:43:57 wally
- X * Initial revision
- X *
- X */
- X
- X#include <sys/types.h>
- X#ifdef DEBUG
- X#include <dbmalloc.h>
- X#endif
- X#include <stdio.h>
- X#include <fcntl.h>
- X#include <termio.h>
- X#include <getopt.h>
- X#include <string.h>
- X#include <ctype.h>
- X#include <errno.h>
- X#include <signal.h>
- X#include <utmp.h>
- X#include <stdlib.h>
- X#include "common.h"
- X#include "modemio.h"
- X#include "zyxel.h"
- X
- X#ifdef DEBUG
- Xstatic int verbosity = 9;
- X#else
- Xstatic int verbosity = 0;
- X#endif
- X
- Xconst char *myname;
- Xstatic char RcsId[] = "$Id: c2rec.c,v 4.3 1993/01/22 15:14:24 wcp Exp $";
- Xstatic bool timedout;
- X
- Xstatic SIGTYPE timeout(int sig)
- X{
- X timedout = TRUE;
- X signal(sig, timeout);
- X#if SIGTYPE == int
- X return 0;
- X#endif
- X}
- X
- Xstatic bool tryRead(ModemReturnCode answer, int fd)
- X{
- X unsigned i;
- X ModemReturnCode ret;
- X
- X dprint(5, (stderr, "%s: trying to read \"%s\"\n", myname,
- X ModemAnswers[answer]));
- X for (i = 0; i < 10; ++i)
- X {
- X if ((ret = receive(10, fd)) == answer)
- X return SUCCEEDED;
- X if (ret < 0)
- X break;
- X }
- X return FAILED;
- X}
- X
- Xstatic bool receivePage(int infd, int outfd)
- X{
- X register unsigned bytes = 0;
- X
- X timedout = FALSE;
- X for (bytes = 0; TRUE; ++bytes)
- X {
- X char c;
- X
- X if ((bytes % 1000) == 0)
- X alarm(30);
- X if (timedout || read(infd, &c, 1) < 1)
- X {
- X alarm(0);
- X return FAILED;
- X }
- X if (c == DLE)
- X {
- X if (timedout || read(infd, &c, 1) < 1)
- X {
- X alarm(0);
- X return FAILED;
- X }
- X switch (c)
- X {
- X case DLE:
- X break;
- X case ETX:
- X alarm(0);
- X return SUCCEEDED;
- X default:
- X continue;
- X }
- X }
- X write(outfd, &c, 1);
- X }
- X}
- X
- Xstatic bool receiveFax(const char *base_name)
- X{
- X unsigned page = 0;
- X
- X do
- X {
- X char pathname[1024];
- X int outfd, ret;
- X FILE *outfp;
- X
- X sprintf(pathname, "%s.%03u", base_name, ++page);
- X if ((outfd = open(pathname, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0)
- X {
- X fprintf(stderr, "%s: cannot open for writing %s (%s)\n",
- X myname, pathname, sys_errlist[errno]);
- X return FAILED;
- X }
- X else
- X {
- X long t = time(0);
- X
- X outfp = fdopen(outfd, "w");
- X fprintf(outfp, "DATE: %s", ctime(&t));
- X }
- X do
- X {
- X switch (ret = receive(10, 0))
- X {
- X case MDOK:
- X case MDFCFR:
- X mdwrite("AT+FDR\r", 1);
- X break;
- X case MDFDCS:
- X case MDFTSI:
- X case MDCONNECT:
- X /* allowed answers */
- X break;
- X default:
- X /* all the other ones are errors */
- X ret = MDERROR;
- X break;
- X }
- X }
- X while (ret != MDCONNECT && ret != MDERROR);
- X if (ret == MDERROR)
- X {
- X fclose(outfp);
- X unlink(pathname);
- X return FAILED;
- X }
- X else
- X {
- X fprintf(outfp, "RESOLUTION: %d\n", C2_resolution);
- X fprintf(outfp, "CALLER: %s\n", C2_caller);
- X fprintf(outfp, "ENCODING: 0\n"); /* 0=plain, 1=reversed */
- X fprintf(outfp, "SPEED: %d\n", (C2_baud + 1) * 2400);
- X fprintf(outfp, "DATA:"); /* no \n because there is one still
- X outstanding since last response */
- X fflush(outfp);
- X dprint(7, (stderr, "%s: sending initial DC2\n", myname));
- X sleep(1);
- X mdwrite("\022", 1);
- X dprint(2, (stderr, "%s: receiving page %u\n", myname, page));
- X if (!receivePage(0, outfd))
- X {
- X dprint(1, (stderr, "%s: page %u discarded\n", myname, page));
- X unlink(pathname);
- X }
- X fclose(outfp);
- X do
- X {
- X switch (ret = receive(10, 0))
- X {
- X case MDFPTS: /* Is it a ZyXEL bug? */
- X mdwrite("AT+FDR\r", 1);
- X case MDFET:
- X break;
- X default:
- X ret = MDERROR;
- X break;
- X }
- X }
- X while (ret != MDERROR && ret != MDFET);
- X if (ret == MDERROR)
- X return FAILED;
- X }
- X }
- X while (C2_eop == 0);
- X mdwrite("AT+FDR\r", 1);
- X if (tryRead(MDFHNG, 0))
- X tryRead(MDOK, 0);
- X sleep(1); /* let modem recover */
- X return SUCCEEDED;
- X}
- X
- Xstatic bool printPages(const char *base_name)
- X{
- X char command[1024];
- X
- X sprintf(command, "%s/printfax %s", LIB_DIR, base_name);
- X return !system(command);
- X}
- X
- Xstatic void deletePages(const char *base_name)
- X{
- X char buf[strlen(base_name) + 10];
- X unsigned i = 0;
- X
- X do sprintf(buf, "%s.%03u", base_name, ++i);
- X while (unlink(buf) == 0);
- X}
- X
- Xstatic SIGTYPE terminate(int sig)
- X{
- X dprint(0, (stderr, "%s: got HANGUP signal\n", myname));
- X mdhangup(1);
- X exit(0);
- X#if SIGTYPE == int
- X return 0;
- X#endif
- X}
- X
- Xint main(unsigned argc, char *argv[])
- X{
- X bool error = FALSE;
- X unsigned print = 0;
- X int i;
- X const char *base = 0;
- X char fax_base_name[1024];
- X
- X myname = basename(argv[0]);
- X while ((i = getopt(argc, argv, "px:")) != EOF)
- X switch (i)
- X {
- X case 'p':
- X ++print;
- X break;
- X case 'x':
- X verbosity = atoi(optarg);
- X break;
- X default:
- X error = TRUE;
- X break;
- X }
- X if (optind == argc)
- X error = TRUE;
- X base = argv[optind++];
- X if (optind < argc) /* too many arguments */
- X error = TRUE;
- X if (error)
- X {
- X fprintf(stderr, "%s\nusage: %s [-x level][-p ...] out{file|dir}\n",
- X RcsId, myname);
- X exit(-1);
- X }
- X mdverbosity = verbosity;
- X signal(SIGALRM, timeout);
- X signal(SIGQUIT, terminate);
- X signal(SIGTERM, terminate);
- X signal(SIGHUP, timeout);
- X signal(SIGINT, terminate);
- X {
- X unsigned nfax = 1;
- X struct stat st;
- X
- X if (stat(base, &st) == 0 && (st.st_mode & S_IFDIR))
- X {
- X /* Base is a directory.
- X */
- X for (; nfax > 0; ++nfax)
- X {
- X sprintf(fax_base_name, "%s/in%08u.%03u", base, nfax, 1);
- X /* We avoid to overwrite existing faxes */
- X if (access(fax_base_name, F_OK))
- X {
- X *strrchr(fax_base_name, '.') = '\0'; /* chop ".001" */
- X break;
- X }
- X }
- X }
- X else
- X /* Base is a probably inexistent file name.
- X */
- X strcpy(fax_base_name, base);
- X if (nfax == 0)
- X {
- X fprintf(stderr, "%s: spool area is full.\n", myname);
- X exit(1);
- X }
- X }
- X receiveFax(fax_base_name);
- X mdhangup(1);
- X if (print-- > 0)
- X {
- X if (fork() == 0)
- X {
- X close(0); close(1); close(2);
- X setpgrp();
- X dup(dup(open("/dev/null", O_RDWR)));
- X if (printPages(fax_base_name) && print > 0)
- X deletePages(fax_base_name);
- X }
- X signal(SIGCLD, SIG_IGN);
- X }
- X return exit(0), 0;
- X}
- SHAR_EOF
- true || echo 'restore of c2rec.c failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= class2rec.c ==============
- if test -f 'class2rec.c' -a X"$1" != X"-c"; then
- echo 'x - skipping class2rec.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting class2rec.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'class2rec.c' &&
- X/*
- X * $Id: class2rec.c,v 1.1 1992/07/17 16:44:41 wally Exp $
- X *
- X * Copyright (C) 1992 Walter Pelissero
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * $Log: class2rec.c,v $
- X * Revision 1.1 1992/07/17 16:44:41 wally
- X * Initial revision
- X *
- X */
- X
- X#include <stdio.h>
- X#include <fcntl.h>
- X#include <termio.h>
- X#include <string.h>
- X#include <ctype.h>
- X#include <errno.h>
- X#include <signal.h>
- X#include <stdlib.h>
- X#include <getopt.h>
- X#include "/u/wally/c/faxem/src/common.h"
- X
- Xextern const char *TMP_DIR;
- Xextern bool loadDefaults(void);
- Xextern char *makeTemp(const char *);
- X
- Xtypedef enum {
- X MDERROR,
- X MDOK,
- X MDRING,
- X MDCONNECT,
- X MDNOCARRIER,
- X MDNODIALTONE,
- X MDBUSY,
- X MDNOANSWER,
- X MDFCON,
- X MDFDCS,
- X MDFDIS,
- X MDFCFR,
- X MDFTSI,
- X MDFCSI,
- X MDFPTS,
- X MDFET,
- X MDFHNG,
- X MDLAST_ANS = MDFHNG
- X} ModemReturnCode;
- X
- Xchar *ModemAnswers[] = {
- X "ERROR",
- X "OK",
- X "RING",
- X "CONNECT",
- X "NO CARRIER",
- X "NO DIAL TONE",
- X "BUSY",
- X "NO ANSWER",
- X "+FCON",
- X "+FDCS:",
- X "+FDIS:",
- X "+FCFR",
- X "+FTSI:",
- X "+FCSI:",
- X "+FPTS:",
- X "+FET:",
- X "+FHNG:",
- X 0
- X};
- X
- Xtypedef struct {
- X int infd, outfd;
- X struct termio orig_tty_settings;
- X} Port;
- X
- Xstatic SIGTYPE catcher();
- X
- X#define DLE '\020'
- X#define ETX '\003'
- X#define DC1 '\021'
- X#define DC3 '\023'
- X#define XON DC1
- X#define XOFF DC3
- X/* #define SLOWRITE */
- X
- X#ifdef DEBUG
- Xstatic int verbosity = 9;
- X#else
- Xstatic int verbosity = 0;
- X#endif
- X
- Xchar *myname;
- Xstatic char *local_phone = "";
- Xstatic char RcsId[] = "$Id: class2rec.c,v 1.1 1992/07/17 16:44:41 wally Exp $";
- Xstatic char read_buffer[1024];
- X
- X#define toprint(x) ((x)<' '?((x)+'@'):'?')
- X
- X/* vgets - Format one character in "always printable" format (like cat -v)
- X */
- Xstatic char *vgets(unsigned char c)
- X{
- X static char buffer[10];
- X char *pnt;
- X
- X pnt = buffer;
- X if (iscntrl(c) || !isprint(c))
- X {
- X if (!isascii(c))
- X { /* Top bit is set */
- X *pnt++ = 'M';
- X *pnt++ = '-';
- X c = toascii(c);
- X }
- X if (iscntrl(c))
- X { /* Not printable */
- X *pnt++ = '^';
- X c = toprint(c);
- X }
- X }
- X *pnt++ = c;
- X *pnt = '\0';
- X return(buffer);
- X}
- X
- Xstatic SIGTYPE catcher(int sig)
- X{
- X signal(sig, catcher);
- X#if SIGTYPE == int
- X return 0;
- X#endif
- X}
- X
- X/* Flush file input.
- X Here we hog all the bytes from fd until alarm() expires. */
- Xstatic void flush_input(int fd)
- X{
- X char c;
- X
- X alarm(2);
- X errno = 0;
- X while (errno != EINTR)
- X read(fd, &c, 1);
- X}
- X
- X/*
- X * mdwrite(c)
- X *
- X * Function: Outputs the string pointed to by c to the ACU device.
- X *
- X * Returns: 0 on completion.
- X * -1 on write errors.
- X *
- X */
- Xstatic int mdwrite(const char *c, int fd)
- X{
- X int err;
- X
- X if (verbosity > 6)
- X fprintf(stderr, "Sent MODEM <<");
- X while (*c)
- X {
- X if ((err = write(fd, c, 1)) != 1)
- X {
- X if (verbosity > 6)
- X fprintf(stderr, ">>-FAIL\n");
- X fprintf(stderr, "ACU write error (%s)\n", sys_errlist[errno]);
- X return(-1);
- X }
- X if (verbosity > 6)
- X fprintf(stderr, "%s", vgets(*c));
- X#ifdef SLOWRITE
- X nap(100);
- X#endif
- X c++;
- X }
- X if (verbosity > 6)
- X fprintf(stderr, ">>-OK\n");
- X return(0);
- X}
- X
- X
- X/*
- X * substr(s, l)
- X *
- X * Function: Checks for the presence of the string pointed to by s
- X * somewhere within the string pointed to by l.
- X *
- X * Returns: 0 if found.
- X * -1 if not found.
- X */
- Xstatic int substr(const char *s, const char *l)
- X{
- X int len;
- X
- X len = strlen(s);
- X while ((l = strchr(l, *s)) != NULL)
- X {
- X if (!strncmp(s, l, len))
- X return(0);
- X l++;
- X }
- X return(-1);
- X}
- X
- X/*
- X * mdread(rtime, fd)
- X *
- X * Function: Reads from the ACU until it finds a valid response (found
- X * in ModemAnswers) or times out after rtime seconds.
- X *
- X * Returns: The index in ModemAnswers of the modem response found.
- X * -1 on timeout.
- X *
- X */
- Xstatic ModemReturnCode mdread(unsigned rtime, int fd)
- X{
- X char **mp, *bp;
- X unsigned char c;
- X
- X bp = read_buffer;
- X alarm(rtime);
- X if (verbosity > 6)
- X fprintf(stderr, "MODEM returned <<");
- X while (read(fd, &c, 1) == 1)
- X {
- X c &= 0177;
- X if ((*bp = c) != '\0')
- X *++bp = '\0';
- X if (verbosity > 6)
- X fprintf(stderr, "%s", vgets(c));
- X if (bp >= read_buffer + sizeof(read_buffer))
- X {
- X alarm(0);
- X if (verbosity > 6)
- X fprintf(stderr, ">>-FAIL\n");
- X return -1;
- X }
- X if (c == '\r')
- X {
- X for (mp = ModemAnswers; *mp; ++mp)
- X if (substr(*mp, read_buffer) == 0)
- X {
- X alarm(0);
- X if (verbosity > 6)
- X fprintf(stderr, ">>-OK\n");
- X if (verbosity > 4)
- X fprintf(stderr, "got %s\n", ModemAnswers[mp - ModemAnswers]);
- X return mp - ModemAnswers;
- X }
- X }
- X }
- X alarm(0);
- X if (verbosity > 6)
- X fprintf(stderr, ">>-FAIL");
- X if (verbosity > 4)
- X fprintf(stderr, " no response\n");
- X return -1;
- X}
- X
- Xstatic bool hangup(Port port)
- X{
- X struct termio tty_settings, old_tty;
- X
- X if (ioctl(port.outfd, TCGETA, &tty_settings) < 0)
- X return FAILED;
- X old_tty = tty_settings;
- X tty_settings.c_cflag = B0;
- X if (verbosity > 5)
- X fprintf(stderr, "%s: hanging\n", myname);
- X if (ioctl(port.outfd, TCSETA, &tty_settings) < 0)
- X return FAILED;
- X sleep(1);
- X if (ioctl(port.outfd, TCSETA, &old_tty) < 0)
- X return FAILED;
- X return SUCCEEDED;
- X}
- X
- Xbool initModem(Port port)
- X{
- X char outbuf[128];
- X
- X mdwrite("ATZ\r", port.outfd);
- X sleep(1); /* to let modem recover */
- X mdwrite("ATPE0V1Q0X6S0=3S7=60&B1&C1&D3\r", port.outfd);
- X flush_input(port.infd); /* to avoid OK propagation */
- X
- X sprintf(outbuf, "ATM%u+FCLASS=2\r", !!verbosity);
- X if (mdwrite(outbuf, port.outfd) < 0)
- X return FAILED;
- X if (mdread(2, port.infd) != MDOK)
- X return FAILED;
- X /* I don't know if the following is necessary, but I saw it in
- X an example session so .... */
- X if (mdwrite("AT+FCR=1\r", port.outfd) < 0)
- X return FAILED;
- X if (mdread(2, port.infd) != MDOK)
- X return FAILED;
- X /* Setting Local IDentification (actually,
- X it is the local fax number). */
- X sprintf(outbuf, "AT+FLID=\"%s\"\r", local_phone);
- X if (mdwrite(outbuf, port.outfd) < 0)
- X return FAILED;
- X if (mdread(2, port.infd) != MDOK)
- X return FAILED;
- X /* Setting Byte ORder (0 = normal, 1 = reverse). */
- X if (mdwrite("AT+FBOR=0\r", port.outfd) < 0)
- X return FAILED;
- X if (mdread(2, port.infd) != MDOK)
- X return FAILED;
- X /* Setting DCE capabilities. */
- X if (mdwrite("AT+FDCC=1\r", port.outfd) < 0)
- X return FAILED;
- X if (mdread(2, port.infd) != MDOK)
- X return FAILED;
- X return SUCCEEDED;
- X}
- X
- Xbool waitConnection(Port port)
- X{
- X int ret = -1;
- X
- X do
- X {
- X switch (ret = mdread(1000, port.infd))
- X {
- X unsigned i;
- X
- X case MDFCON:
- X for (i = 0; i < 10; ++i)
- X if ((ret = mdread(10, port.infd)) == MDOK)
- X break;
- X if (ret != MDOK)
- X {
- X initModem(port);
- X ret = -1;
- X }
- X break;
- X case MDRING:
- X mdwrite("ATA\r", port.outfd);
- X ret = -1;
- X break;
- X default: /* Nothing read */
- X ret = -1;
- X break;
- X }
- X }
- X while (ret < 0);
- X return SUCCEEDED;
- X}
- X
- Xbool tryRead(ModemReturnCode answer, int fd)
- X{
- X unsigned i;
- X ModemReturnCode ret;
- X
- X for (i = 0; i < 10; ++i)
- X if ((ret = mdread(10, fd)) == answer)
- X return SUCCEEDED;
- X return FAILED;
- X}
- X
- Xstatic void receivePage(int infd, int outfd)
- X{
- X register bool dle_read = FALSE;
- X
- X do
- X {
- X char c;
- X
- X if (read(infd, &c, 1) < 1)
- X return;
- X if (c == DLE)
- X {
- X if (dle_read = !dle_read)
- X continue;
- X }
- X else
- X {
- X if (c == ETX && dle_read)
- X return;
- X dle_read = FALSE;
- X }
- X write(outfd, &c, 1);
- X }
- X while (TRUE);
- X}
- X
- Xvoid receiveFax(Port port, const char *base_name)
- X{
- X bool eot;
- X unsigned page = 0;
- X
- X do
- X {
- X mdwrite("AT+FDR\r", port.outfd);
- X if (tryRead(MDCONNECT, port.infd))
- X {
- X char pathname[1024];
- X int outfd;
- X
- X sprintf(pathname, "%s.%u", base_name, ++page);
- X if ((outfd = open(pathname, O_WRONLY | O_TRUNC | O_CREAT, 0640)) < 0)
- X {
- X fprintf(stderr, "%s: cannot open for writing %s (%s)\n",
- X myname, pathname, sys_errlist[errno]);
- X return;
- X }
- X else
- X {
- X if (verbosity > 7)
- X fprintf(stderr, "%s: sending initial DC2\n", myname);
- X sleep(1);
- X mdwrite("\022", port.outfd);
- X receivePage(port.infd, outfd);
- X close(outfd);
- X if (tryRead(MDFET, port.infd))
- X {
- X char *fet = strstr(read_buffer, "+FET:") + 5;
- X
- X *strpbrk(fet, "\r,;") = '\0';
- X eot = (atoi(fet) == 2);
- X tryRead(MDOK, port.infd);
- X }
- X else
- X {
- X initModem(port);
- X return;
- X }
- X }
- X }
- X else
- X return;
- X }
- X while (!eot);
- X mdwrite("AT+FDR\r", port.outfd);
- X if (tryRead(MDFHNG, port.infd))
- X tryRead(MDOK, port.infd);
- X}
- X
- X
- X
- Xstatic bool closeLine(Port port)
- X{
- X bool errflag = FALSE;
- X
- X sleep(1);
- X errflag |= !hangup(port);
- X if (ioctl(port.outfd, TCSETA, &port.orig_tty_settings) < 0)
- X return FAILED;
- X close(port.infd);
- X close(port.outfd);
- X return errflag;
- X}
- X
- Xstatic Port openLine(const char *portname)
- X{
- X Port port;
- X struct termio tty_settings;
- X
- X errno = 0;
- X if (!strcmp(portname, "-"))
- X {
- X port.infd = fileno(stdin);
- X port.outfd = fileno(stdout);
- X }
- X else
- X {
- X if ((port.infd = open(portname, (O_RDONLY | O_NDELAY), 0600)) < 0)
- X {
- X if (errno == EBUSY)
- X fprintf(stderr, "%s: port %s BUSY\n", myname, portname);
- X else
- X fprintf(stderr, "%s: can't connect into %s\n", myname, portname);
- X port.infd = ERROR;
- X return port;
- X }
- X if ((port.outfd = open(portname, (O_WRONLY | O_NDELAY), 0600)) < 0)
- X {
- X if (errno == EBUSY)
- X fprintf(stderr, "%s: port %s BUSY\n", myname, portname);
- X else
- X fprintf(stderr, "%s: can't connect into %s\n", myname, portname);
- X port.infd = ERROR;
- X return port;
- X }
- X }
- X if (ioctl(port.outfd, TCGETA, &port.orig_tty_settings) < 0)
- X {
- X fprintf(stderr, "%s: can't ioctl on %s\n", myname, portname);
- X port.infd = ERROR;
- X return port;
- X }
- X tty_settings = port.orig_tty_settings;
- X
- X tty_settings.c_iflag &= ~(BRKINT | ICRNL | ISTRIP | IXON | IXANY);
- X tty_settings.c_cflag &= ~(CBAUD | PARENB);
- X /* ZyXEL U-1496E ROM 4.09 can receive faxes at 19200 baud only. */
- X tty_settings.c_cflag |= (CSIZE | CS8 | HUPCL | CREAD | B19200);
- X tty_settings.c_cflag |= (CTSFLOW | RTSFLOW);
- X tty_settings.c_lflag &= ~(ISIG | ECHO | ICANON);
- X tty_settings.c_lflag |= XCLUDE;
- X tty_settings.c_cc[VMIN] = 1;
- X tty_settings.c_cc[VTIME] = 0;
- X tty_settings.c_oflag &= ~OPOST;
- X
- X if (ioctl(port.outfd, TCSETAF, &tty_settings) < 0)
- X {
- X fprintf(stderr, "%s: can't set baud for %s\n", myname, portname);
- X port.infd = ERROR;
- X return port;
- X }
- X
- X if (fcntl(port.infd, F_SETFL, O_RDONLY) == ERROR)
- X {
- X fprintf(stderr, "%s: can't unset O_NDELAY for %s\n", myname, portname);
- X port.infd = ERROR;
- X return port;
- X }
- X if (fcntl(port.outfd, F_SETFL, O_WRONLY) == ERROR)
- X {
- X fprintf(stderr, "%s: can't unset O_NDELAY for %s\n", myname, portname);
- X port.infd = ERROR;
- X return port;
- X }
- X if (verbosity > 5)
- X fprintf(stderr, "%s: baud set for %s\n", myname, portname);
- X return port;
- X}
- X
- Xint main(unsigned argc, char *argv[])
- X{
- X Port port;
- X int i;
- X bool error = FALSE;
- X struct option options[] = {
- X { "debug", 2, 0, 'x' },
- X { 0, 0, 0, 0 }
- X };
- X
- X myname = argv[0];
- X while ((i = getopt_long(argc, argv, "x::", options, (int *)0))
- X != EOF)
- X switch (i)
- X {
- X case 'x':
- X if (optarg)
- X verbosity = atoi(optarg);
- X break;
- X case '?':
- X ++error;
- X break;
- X }
- X if (argc - optind < 2 || error)
- X {
- X fprintf(stderr, "usage: %s [-x[debug_level]] [+debug[=level]] device fax_pages_base_name\n", myname);
- X exit(-1);
- X }
- X signal(SIGALRM, catcher);
- X port = openLine(argv[1]);
- X if (port.infd < 0)
- X exit(3);
- X if (!initModem(port))
- X exit(1);
- X if (!waitConnection(port))
- X exit(2);
- X receiveFax(port, argv[2]);
- X closeLine(port);
- X return exit(0), 1;
- X}
- SHAR_EOF
- true || echo 'restore of class2rec.c failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= common.c ==============
- if test -f 'common.c' -a X"$1" != X"-c"; then
- echo 'x - skipping common.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting common.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'common.c' &&
- X/*
- X * $Id: common.c,v 1.1 1993/01/06 17:58:33 wcp Exp $
- X *
- X * Copyright (C) 1992 Walter Pelissero
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * $Log: common.c,v $
- X * Revision 1.1 1993/01/06 17:58:33 wcp
- X * Initial revision
- X *
- X */
- X
- X#include <ctype.h>
- X#include <string.h>
- X#include <stdio.h>
- X#include <sys/utsname.h>
- X
- Xstatic char RcsId[] = "$Id: common.c,v 1.1 1993/01/06 17:58:33 wcp Exp $";
- X
- X
- X/* vgets - Format one character in "always printable" format (like cat -v)
- X */
- Xconst char *vgets(unsigned char c)
- X{
- X static char buffer[10];
- X char *pnt;
- X
- X pnt = buffer;
- X if (iscntrl(c) || !isprint(c))
- X {
- X if (!isascii(c))
- X { /* Top bit is set */
- X *pnt++ = 'M';
- X *pnt++ = '-';
- X c = toascii(c);
- X }
- X if (iscntrl(c))
- X { /* Not printable */
- X *pnt++ = '^';
- X c = c < ' ' ? (c + '@') : '?';
- X }
- X }
- X *pnt++ = c;
- X *pnt = '\0';
- X return(buffer);
- X}
- X
- Xint strcomp(const char *s1, const char *s2)
- X{
- X for (; *s1 && *s2; ++s1, ++s2)
- X {
- X if (isalpha(*s1) && isalpha(*s2))
- X {
- X int c;
- X
- X if (c = tolower(*s1) -tolower(*s2))
- X return c;
- X }
- X else
- X {
- X if (*s1 != *s2)
- X return *s1 - *s2;
- X }
- X }
- X return *s1 - *s2;
- X}
- X
- Xconst char *basename(const char *n)
- X{
- X const char *name;
- X
- X if ((name = strrchr(n, '/')) == NULL)
- X name = n;
- X else
- X ++name;
- X return name;
- X}
- X
- Xchar *strlower(char *s)
- X{
- X char *p = s;
- X
- X for (; *s; ++s)
- X *s = tolower(*s);
- X return p;
- X}
- X
- Xchar *strupper(char *s)
- X{
- X char *p = s;
- X
- X for (; *s; ++s)
- X *s = toupper(*s);
- X return p;
- X}
- X
- Xchar *siteName()
- X{
- X struct utsname un;
- X
- X if (uname(&un) >= 0 && un.nodename[0] != '\0')
- X return strdup(un.nodename);
- X else
- X {
- X /* trying to get site name from the uuname -l command */
- X FILE *fd = popen("uuname -l", "r");
- X
- X if (fd != (FILE *)0)
- X {
- X char site[256];
- X
- X site[0] = '\0';
- X if (fgets(site, sizeof(site), fd))
- X site[strlen(site) - 1] = '\0'; /* chop '\n' */
- X pclose(fd);
- X return strdup(site);
- X }
- X }
- X return 0;
- X}
- SHAR_EOF
- true || echo 'restore of common.c failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= common.h ==============
- if test -f 'common.h' -a X"$1" != X"-c"; then
- echo 'x - skipping common.h (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting common.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'common.h' &&
- X/*
- X * $Id: common.h,v 1.2 1993/01/15 23:04:26 wcp Exp $
- X *
- X * Copyright (C) 1992 Walter Pelissero
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * $Log: common.h,v $
- X * Revision 1.2 1993/01/15 23:04:26 wcp
- X * Removed some garbage from comments.
- X *
- X * Revision 1.1 1993/01/06 17:59:05 wcp
- X * Initial revision
- X *
- X */
- X
- X#ifndef _common_h_INCLUDED
- X#define _common_h_INCLUDED
- X
- X#include "config.h"
- X#undef FALSE
- X#undef TRUE
- Xtypedef enum { FALSE, OFF = FALSE, TRUE, ON = TRUE } bool;
- Xtypedef enum { LOW, HIGH, FINE = HIGH } Resolution;
- Xtypedef enum { NoIntrSheet, English, Deutsche, Italiano, Francais } IntrSheet;
- X
- X#define SUCCEEDED TRUE
- X#define FAILED FALSE
- X#define DLE '\020'
- X#define ETX '\003'
- X#define DC1 '\021'
- X#define DC3 '\023'
- X#define XON DC1
- X#define XOFF DC3
- X
- X
- X#define ALLOW_FILE "allow"
- X#define DENY_FILE "deny"
- X#define CONFIG_FILE "config"
- X#define PERSONAL_CONFIG_FILE ".faxem/config"
- X#define HIGH_RES_FONT "hires.font"
- X#define LOW_RES_FONT "lores.font"
- X#define ALIAS_FILE "alias"
- X#define LOG_FILE "log"
- X#define PERSONAL_ALIAS_FILE ".faxem/alias"
- X
- X#undef min
- X#undef max
- X#ifdef __cplusplus
- Xinline int min(int a, int b) { return (a < b) ? a : b; }
- Xinline int max(int a, int b) { return (a < b) ? b : a; }
- Xinline unsigned min(unsigned a, unsigned b) { return (a < b) ? a : b; }
- Xinline unsigned max(unsigned a, unsigned b) { return (a < b) ? b : a; }
- Xinline long min(long a, long b) { return (a < b) ? a : b; }
- Xinline long max(long a, long b) { return (a < b) ? b : a; }
- Xinline unsigned long min(unsigned long a, unsigned long b)
- X{
- X return (a < b) ? a : b;
- X}
- Xinline unsigned long max(unsigned long a, unsigned long b)
- X{
- X return (a < b) ? b : a;
- X}
- X
- X#else /* __cplusplus */
- X#define min(a,b) (((a) < (b)) ? (a) : (b))
- X#define max(a,b) (((a) < (b)) ? (b) : (a))
- X#endif /* __cplusplus */
- X
- X#define ERROR (-1)
- X#define dprint(l,c) if (verbosity > (l)) fprintf c ;
- X
- X/* The followings are in common.c */
- Xextern const char *basename(const char *);
- Xextern const char *vgets(unsigned);
- Xextern int strcomp(const char*, const char *);
- Xextern char *strlower(char *);
- Xextern char *strupper(char *);
- Xextern char *siteName(void);
- X
- Xextern bool lockLine(const char *, int);
- Xextern bool isLocked(const char *);
- Xextern bool unlockLine(const char *);
- Xextern char *makeTemp(const char *);
- Xextern bool glob(const char *, const char *);
- X#endif /* _common_h_INCLUDED */
- SHAR_EOF
- true || echo 'restore of common.h failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= config.h ==============
- if test -f 'config.h' -a X"$1" != X"-c"; then
- echo 'x - skipping config.h (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting config.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'config.h' &&
- X/*
- X * $Id: config.h,v 1.2 1993/01/15 23:05:25 wcp Exp $
- X *
- X * Copyright (C) 1992 Walter Pelissero
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * $Log: config.h,v $
- X * Revision 1.2 1993/01/15 23:05:25 wcp
- X * Removed some garbage from comments.
- X *
- X * Revision 1.1 1993/01/06 17:59:35 wcp
- X * Initial revision
- X *
- X */
- X
- X#ifndef _config_h_INCLUDED
- X#define _config_h_INCLUDED
- X
- X#define SIGTYPE int /* set it to the return value type of your
- X signal handling functions [wally] */
- X /* some common bits 'n pieces */
- X
- X#define LOCK_DIR "/usr/spool/uucp"
- X#define MAX_NAME_LEN 14 /* Maximum file name length. Define it if
- X your file system have such constraint.
- X Otherwise leave it undefined. */
- X
- X#ifdef __cplusplus
- Xextern "C" {
- X#endif
- X# include <sys/types.h>
- X volatile void abort(void);
- X char *sys_errlist[];
- X int errno;
- X volatile void exit(int);
- X int unlink(const char *);
- X char *mktemp(char *);
- X int system(const char *);
- X void exit(int);
- X int system(const char *);
- X int atoi(const char *);
- X char *regcmp(const char *, const char *, ...);
- X char *regex(const char *, const char *, ...);
- X extern int getpid(void);
- X uid_t getuid(void);
- X const char *getlogin(void);
- X int defopen(const char *);
- X const char *defread(const char *);
- X const char *logname(void);
- X char *getenv(const char *);
- X char *ctime(long *);
- X#ifdef __cplusplus
- X}
- X#endif
- X
- X#endif /* _config_h_INCLUDED */
- SHAR_EOF
- true || echo 'restore of config.h failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= doc/c2rec.8 ==============
- if test ! -d 'doc'; then
- echo 'x - creating directory doc'
- mkdir 'doc'
- fi
- if test -f 'doc/c2rec.8' -a X"$1" != X"-c"; then
- echo 'x - skipping doc/c2rec.8 (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting doc/c2rec.8 (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'doc/c2rec.8' &&
- X.\" -*- Nroff -*-
- X.\"
- X.\" $Id: c2rec.8,v 1.2 1993/01/21 19:45:21 wcp Exp $
- X.\"
- X.\" Copyright (C) 1992 Walter Pelissero
- X.\"
- X.\" This program is free software; you can redistribute it and/or modify
- X.\" it under the terms of the GNU General Public License as published by
- X.\" the Free Software Foundation; either version 2 of the License, or
- X.\" (at your option) any later version.
- X.\"
- X.\" This program is distributed in the hope that it will be useful,
- X.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
- X.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X.\" GNU General Public License for more details.
- X.\"
- X.\" You should have received a copy of the GNU General Public License
- X.\" along with this program; if not, write to the Free Software
- X.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X.\"
- X.\"
- X.\" $Log: c2rec.8,v $
- X.\" Revision 1.2 1993/01/21 19:45:21 wcp
- X.\" Changed .I in \fI/\fP.
- X.\"
- X.\" Revision 1.1 1993/01/13 21:40:54 wcp
- X.\" Initial revision
- X.\"
- X.\"
- X.de XX
- X.ds XX \\$4\ (v\\$3)
- X..
- X.XX $Id: c2rec.8,v 1.2 1993/01/21 19:45:21 wcp Exp $
- X.TH C2REC 8 \*(XX
- X.AT 3
- X.SH NAME
- Xc2rec \- Class 2 receiver program
- X.SH SYNOPSIS
- X.B c2rec
- X.RI [ -x\ level ]
- X.RI [ -p\ ... ]
- X.I outfile_or_directory
- X.SH DESCRIPTION
- X\fIC2rec\fP is fax front end for \fImgetty\fP. On a successfully
- Xestablished connection \fIc2rec\fP negotiate and receive fax pages,
- Xdriving the connection until hang up. Fax pages take the name
- Xspecified on command line plus a dotted extension (eg. \fIfile.001\fP)
- Xnumbering pages. If a directory is specified instead of a file, pages
- Xare created with this name template: inXXXXXXXX.YYY. Where XXXXXXXX
- Xstands for a fax sequence number, and YYY stands for the page sequence
- Xnumber for fax number XXXXXXXX. The program adjust fax sequence number
- Xto avoid overwriting of existing faxes.
- X.SH OPTIONS
- X.IP "-x \fIlevel\fP"
- XTell the verbosity of debug informations displayed during processing.
- X.IP -p
- XEach succesfully received fax should be printed on the default
- Xprinter. Two occurences of this flag cause faxes to be deleted after
- Xprinting.
- X.SH BUGS
- XThis program is not based on any official document describing Class 2
- Xstandard. This may cause incompatibility with other Class 2 modems or
- Xsubsequent implementations of the modem this program is based on.
- X.SH AUTHOR
- XWalter Pelissero <wally@lpds.sublink.org>
- X.SH "SEE ALSO"
- Xmgetty(8), play(8), record(8)
- SHAR_EOF
- true || echo 'restore of doc/c2rec.8 failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= doc/mgetty.8 ==============
- if test -f 'doc/mgetty.8' -a X"$1" != X"-c"; then
- echo 'x - skipping doc/mgetty.8 (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting doc/mgetty.8 (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'doc/mgetty.8' &&
- X.\" -*- Nroff -*-
- X.\"
- X.\" $Id: mgetty.8,v 1.3 1993/01/21 20:02:17 wcp Exp $
- X.\"
- X.\" Copyright (C) 1992 Walter Pelissero
- X.\"
- X.\" This program is free software; you can redistribute it and/or modify
- X.\" it under the terms of the GNU General Public License as published by
- X.\" the Free Software Foundation; either version 2 of the License, or
- X.\" (at your option) any later version.
- X.\"
- X.\" This program is distributed in the hope that it will be useful,
- X.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
- X.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X.\" GNU General Public License for more details.
- X.\"
- X.\" You should have received a copy of the GNU General Public License
- X.\" along with this program; if not, write to the Free Software
- X.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X.\"
- X.\"
- X.\" $Log: mgetty.8,v $
- X.\" Revision 1.3 1993/01/21 20:02:17 wcp
- X.\" Added command line arguments.
- X.\"
- X.\" Revision 1.2 1993/01/21 19:43:47 wcp
- X.\" Changed .I in \fI/\fP.
- X.\"
- X.\" Revision 1.1 1993/01/13 21:40:54 wcp
- X.\" Initial revision
- X.\"
- X.\"
- X.de XX
- X.ds XX \\$4\ (v\\$3)
- X..
- X.XX $Id: mgetty.8,v 1.3 1993/01/21 20:02:17 wcp Exp $
- X.TH MGETTY 8 \*(XX
- X.AT 3
- X.SH NAME
- Xmgetty \- modular getty for multipurposes DCEs
- X.SH SYNOPSIS
- X.B mgetty
- X.I orig_getty
- X.RI [ options ] \ tty_name
- X.SH DESCRIPTION
- X\fIMgetty\fP is a programmable getty program designed to drive any DCE
- X(modems, fax-modems, answering-machines, etc.) that needs more control
- Xthan a normal getty can do.
- X.PP
- X\fIMgetty\fP is executed by \fIinit\fP as a normal getty, it sets line
- Xto some default value and start interpreting a Tcl script associated
- Xwith the line (\fItty_name\fP). If there is no such script,
- X\fImgetty\fP gives up and executes the original getty program
- X(\fIorig_getty\fP).
- X.PP
- X\fIMgetty\fP ignores any option your system \fIinit\fP
- Xprogram may supply because \fImgetty\fP doesn't need it. All the
- Xinformations and logic must me enclosed in the Tcl script.
- X.SH "NEW TCL COMMANDS"
- XIn order to do some tty specific operations or some special and
- Xfrequently used action on tty/DCE, the basic Tcl interpreter has been
- Xmodified a little.
- X.LP
- XSUBSTITUTED COMMANDS
- X.IP "exit [\fIreturn_value\fP]"
- XOn exit, \fImgetty\fP Tcl scripts must restore ttys and DCEs to some
- Xwell known state (normally the one before \fImgetty\fP started). The
- Xnew \fIexit\fP command hangs up the line and do all such things.
- XSyntax is unchanged.
- X.LP
- XADDED COMMANDS
- X.IP "send \fIstring\fP ..."
- XSends one or more strings to DCE returning an error message if there
- Xare problems on the line.
- X.IP "receive [\fIwait_time\fP] [\fItoken ...\fP]"
- XReceive, looking for input for \fIwait_time\fP seconds (or 30 if not
- Xspecified), any input matching one of the tokens (or any '\\r' or
- X'\\n' terminated string, if no tokens are specified). I returns the
- Xreceived string.
- X.IP listen
- XThis is a variation of \fIreceive.\fP It waits indefinitively for a
- X'\\r' or '\\n' terminated string returning it to application.
- X.IP flush_input
- XDiscard any outstanding characters from DCE.
- X.IP hangup
- XHang up the line.
- X.IP login
- XDo the normal getty operations. Send a login prompt waiting for an
- Xaccount name, then invoke \fIlogin\fP for password autentication. This
- Xcommand doesn't fork the original getty. This command should not
- Xreturn. If it is the case it returns an error message.
- X.IP "spawn \fIarg ...\fP"
- X\fIExec\fP replacement. Frequently \fImgetty\fP forked programs need
- Xto deal with tty as stdin/stdout; the standard \fIexec\fP command
- Xcannot be used in such situations. \fISpawn\fP, instead, attachs
- Xstdin and stdout of invoked programs to tty. Syntax is the same as
- X\fIexec\fP. Returned value is the exit status of last program (in case
- Xof pipe).
- X.IP "baudrate [\fIspeed\fP]"
- XSet line speed. All numerical values are allowed but your system may
- Xnot accept all; in this case appropriate conversion to the next lower
- Xbaud rate is made automatically. Return value is the current baud
- Xrate. Without argument it just reports the speed.
- X.IP "stty \fIarg ...\fP"
- XSet special tty settings to arguments. This can viewed as a
- Xreplacement for /etc/gettydef, since \fImgetty doesn't use it. In fact
- Xthis command is a clone of the Unix\fP command \fIstty\fP (refer to
- Xits documentation, for any detail). Both \fIbaudrate\fP and \fImode\fP
- Xcommands do the same things but at higher level and with a more
- Xfriendly interface: you should use \fIstty\fP only when you have no
- Xchoice.
- X.IP "mode \fImode ...\fP"
- XSet to canned modes the tty. This is a higher level interface to stty
- Xfeatures. Currently supported settings are (case is insignificant):
- X.TP
- X raw
- XEach character written to tty or sent by tty is passed without any
- Xprocessing or delay.
- X.TP
- X cooked
- XThe normal status when you login into the system. Characters are
- Xpacked together into lines, interrupts are interpreted, backspaces
- Xerase last character typed, etc.
- X.TP
- X xon_xoff
- XEnable xon/xoff flow control between tty and DCE.
- X.TP
- X cts_rts
- XEnable cts/rts flow control between tty and DCE.
- X.TP
- X no_flow
- XDisable any flow control between tty and DCE.
- X.TP
- X local
- XSet in \fIlocal\fP mode. In other words, CD signal is ignored by
- Xsystem.
- X.TP
- X remote
- XSet in \fI"non local"\fP mode. In other words, CD transition from ON
- Xto OFF causes an \fIhangup\fP signal to be sent to \fImgetty\fP; this
- Xnormally causes a respawning of mgetty.
- X.IP "sleep \fIsecondsfP"
- XWait for at least as many seconds as specified.
- X.IP "slow_write [\fION|OFF|1|0|TRUE|FALSE|TOGGLE\fP]
- XSet the way \fImgetty\fP send strings (see \fIsend\fP ) to DCE. If
- Xthis setting is on (chose the notation you prefer), mgetty will wait
- Xabout 100ns between one character and subsequent. If this is off,
- Xmgetty will send characters as a continuos stream. It returns the
- Xcurrent status. The special value \fITOGGLE\fP may be used to exchange
- Xany previous value. Normally this is off.
- X.SH "EXTERNAL PROGRAMS"
- XThere are some application that cannot be handled efficently or in a
- Xsufficient general way in terms of Tcl commands. These task are done
- Xwith the intervention of external programs. At the current
- Ximplementation only few programs can be inoked from an \fImgetty\fP
- Xscript.
- X.TP
- Xplay
- XThis is a ZyXEL U-1496 specific program able to send voice files
- SHAR_EOF
- true || echo 'restore of doc/mgetty.8 failed'
- fi
- echo 'End of mgetty-1.0 part 1'
- echo 'File doc/mgetty.8 is continued in part 2'
- echo 2 > _shar_seq_.tmp
- exit 0
- --
- P4 32 8 @A ^@@A ^@@Ax^@@A ^@DA"^@D]%xJe&H1\236\331\306
-