--- /dev/null
+efax
+*.o
+*.coff
+tags
# Makefile for efax
+CC=
# Change the following to the name of your ANSI C compiler
# (normally gcc).
-CC=gcc
+#CC=gcc
+
+ifeq "" "$(CC)"
+CC=m68k-pic-coff-gcc
+CFLAGS+=-DUCCOMPAT=1
+STACKSIZE = 150000
+endif
# Compile/load options. Add -DNO_STRERROR to CFLAGS if _strerror
# is undefined
-CFLAGS=
+CFLAGS+=-Wall -O2
LDFLAGS=
+CFLAGS+=-DUCLINUX=1
+
# Change the following to the destination directories for
# binaries and man pages. Probably /usr/bin and /usr/man on
# Linux, /usr/local/{bin,man} on other systems.
.c.o:
$(CC) $(CFLAGS) -c $<
-all: efax efix
+all: efax #efix
-efax: efax.o efaxlib.o efaxio.o efaxos.o efaxmsg.o
- $(CC) -o efax $(LDFLAGS) efax.o efaxlib.o efaxio.o efaxos.o efaxmsg.o
- strip efax
+efax: efax.o efaxlib.o efaxio.o efaxos.o efaxmsg.o cleanup.o
+ $(CC) -o efax $(LDFLAGS) efax.o efaxlib.o efaxio.o efaxos.o efaxmsg.o cleanup.o
+ifneq "" "$(findstring -DUCCOMPAT,$(CFLAGS))"
+ /opt/uClinux/m68k-pic-coff/bin/coff2flt -o efax -s $(STACKSIZE) efax.coff
+endif
efix: efix.o efaxlib.o efaxmsg.o
$(CC) -o efix $(LDFLAGS) efix.o efaxlib.o efaxmsg.o
- strip efix
install:
cp fax efax efix $(BINDIR)
cp fax.1 efax.1 efix.1 $(MANDIR)/man1
clean:
- rm -f efax efix efax.o efix.o efaxlib.o efaxio.o efaxos.o efaxmsg.o
+ rm -f efax efix efax.o efix.o efaxlib.o efaxio.o efaxos.o efaxmsg.o cleanup.o
efax.o: efax.c efaxmsg.h efaxlib.h efaxio.h efaxos.h
efaxio.o: efaxio.c efaxmsg.h efaxio.h efaxos.h
--- /dev/null
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+open NM,"-|",'m68k-pic-coff-nm efax.coff|sort'
+ or die "nm: $!";
+my(%big,$prevhex,$prevsym,$tot);
+while (<NM>) {
+ chomp;
+ /^([0-9a-f]+) (\w) (.*)$/ or die "parse: $_";
+ my $hex=hex $1;
+ my $type=$2;
+ my $sym=$3;
+ next if $type!~/[tT]/ || $sym=~/^\./ || $sym=~/^L\d+$/ || $sym eq "__gnu_compiled_c" || $sym eq "gcc2_compiled.";
+ if ($prevhex) {
+ warn "dup: $prevsym" if exists $big{$prevsym};
+ $big{$prevsym}=$hex-$prevhex;
+ $tot+=$hex-$prevhex;
+ }
+ $prevhex=$hex;
+ $prevsym=$sym;
+ }
+close NM;
+$big{"_TOTAL"}=$tot;
+for (sort { $big{$b} <=> $big{$a} } keys %big) {
+ printf "%4u %s\n",$big{$_},$_;
+ }
--- /dev/null
+#include "config.h"
+
+void _cleanup(void)
+{
+}
--- /dev/null
+#ifndef _EFAX_CONFIG_H
+#define _EFAX_CONFIG_H 1
+
+
+#ifdef UCCOMPAT
+
+/* Handle non-existing atoi() */
+#include <limits.h>
+#define atoi(s) ({ \
+ long _atoi_l=strtol((s), (char **)NULL, 10); \
+ /**/ if (_atoi_l<INT_MIN) _atoi_l=INT_MIN; \
+ else if (_atoi_l>INT_MAX) _atoi_l=INT_MAX; \
+ _atoi_l; \
+ })
+
+#include <stdio.h>
+extern size_t fread( void *ptr, size_t size, size_t nmemb, FILE *stream);
+extern size_t fwrite( const void *ptr, size_t size, size_t nmemb, FILE *stream);
+
+#include <stdio.h>
+#include <stdarg.h>
+extern int vfprintf(FILE *stream, const char *format, va_list ap);
+
+#include <unistd.h>
+extern pid_t getpid(void);
+
+#endif
+
+
+#endif /* _EFAX_CONFIG_H */
+#include "config.h"
+
#define Copyright "Copyright 1999 Ed Casas"
#define Version "efax v 0.9"
*/
-const char *Usage =
+static const char *Usage =
"Usage:\n"
" %s [ option ]... [ -t num [ file... ] ]\n"
"Options:\n"
" -c cap set modem and receive capabilites to cap\n"
" -d dev use modem on device dev\n"
" -e cmd exec \"/bin/sh -c cmd\" for voice calls\n"
+#ifndef UCLINUX
" -f fnt use (PBM) font file fnt for headers\n"
+#endif /* UCLINUX */
" -g cmd exec \"/bin/sh -c cmd\" for data calls\n"
" -h hdr use page header hdr (use %%d's for current page/total pages)\n"
" -i str send modem command ATstr at start\n"
" -l id set local identification to id\n"
" -o opt use protocol option opt:\n"
" 0 use class 2.0 instead of class 2 modem commands\n"
+#ifndef UCLINUX
" 1 use class 1 modem commands\n"
+#endif /* UCLINUX */
" 2 use class 2 modem commands\n"
" a if first [data mode] answer attempt fails retry as fax\n"
" e ignore errors in modem initialization commands\n"
" x use XON instead of DC2 to trigger reception\n"
" z add 100 ms to pause before each modem comand (cumulative)\n"
" -q ne ask for retransmission if more than ne errors per page\n"
+#ifndef UCLINUX
" -r pat save received pages into files pat.001, pat.002, ... \n"
+#endif /* UCLINUX */
" -s share (unlock) modem device while waiting for call\n"
" -v lvl print messages of type in string lvl (ewinchamr)\n"
" -w don't answer phone, wait for OK or CONNECT instead\n"
#define HDRSHFT 54 /* shift header right 6.7mm into image area */
#define HDRSPCE 20 /* number of scan lines inserted before image */
#define HDRSTRT 4 /* scan line where header is placed on image */
+#ifndef UCLINUX
#define HDRCHRH 24 /* header character height (pels, at 196lpi) */
+#else /* UCLINUX */
+#define HDRCHRH 0 /* header character height (pels, at 196lpi) */
+#endif /* UCLINUX */
#define HDRCHRW 12 /* header character width (pels) */
#define IDLEN 20 /* length of T.30 ID strings, must be 20 */
#define MAXDIS 8 /* maximum DIS frames sent without response (T1) */
/* capability fields... */
enum captype { VR, BR, WD, LN, DF, EC, BF, ST } ;
-int capmax [ NCAP ] = { 1, 7, 2, 2, 3, 2, 1, 7 } ;
+static int capmax [ NCAP ] = { 1, 7, 2, 2, 3, 2, 1, 7 } ;
/* & maximum values */
+#ifndef UCLINUX
/* vertical resolution, dpi */
int vresolution [ 2 ] = { 98, 196 } ;
+#endif /* UCLINUX */
/* characters per second for br */
-int cps [ 8 ] = { 300, 600, 900, 1200, 1500, 1800, 900, 1200 } ;
+static int cps [ 8 ] = { 300, 600, 900, 1200, 1500, 1800, 900, 1200 } ;
+#ifndef UCLINUX
/* next br = fallback [ br ] */
/* 0, 1, 2, 3, 4, 5, 6, 7 */
int fallback [ 8 ] = {-1, 0, 1, 2, 7, 4, 3, 6 } ;
/* negotiation speed index */
/* 0, 1, 2, 3, 4, 5, 6, 7 */
int brindex [ 8 ] = { 0, 1, 2, 3, 4, 7, 5, 6 } ;
+#endif /* UCLINUX */
/* minimum scan time in ms */
-int mst [ 8 ] = { 0 , 5, 10, 10, 20, 20, 40, 40 } ;
+static int mst [ 8 ] = { 0 , 5, 10, 10, 20, 20, 40, 40 } ;
/* page width in pixels */
-int pagewidth [ 5 ] = { 1728, 2048, 2432, 1216, 864 } ;
+static int pagewidth [ 5 ] = { 1728, 2048, 2432, 1216, 864 } ;
/* Table to convert between T.30 DIS/DCS/DTC FIF and Class 2-like
capability codes. Uses br=6, 7 for V.17 at 7200, 9600. */
#define X 0xff /* invalid values */
-t30tabst t30tab [ NCAP ] = {
+static t30tabst t30tab [ NCAP ] = {
{ "vr", 1, 1, 0x01, 0, { 0, 1 } , { 0, 1 } , { 0, 1 } , { 0, 1 } },
{ "br", 1, 2, 0x0f, 0,
{ 0, 4, 12, 12, 13, 13 } ,
} ;
/* values of capability fields */
-char *capvaluestr [ NCAP ] [8] = {
+static char *capvaluestr [ NCAP ] [8] = {
{ " 98lpi", "196lpi" } ,
{ " 2400bps", " 4800bps", " 7200bps", " 9600bps", " 12kbps", "14.4kbps",
"7200V.17", "9600V.17" } ,
/* Class 1 commands to [receive=0/transmit=1] [data=0/training=1] for
[baud rate=BR]. */
+#ifndef UCLINUX
char *c1cmd [ 2 ] [ 2 ] [ 8 ] = {
{ { "+FRM=24", "+FRM=48", "+FRM=72", "+FRM=96", "+FRM=122", "+FRM=146" ,
"+FRM=74", "+FRM=98" } ,
{ "+FTM=24", "+FTM=48", "+FTM=72", "+FTM=96", "+FTM=121", "+FTM=145" ,
"+FTM=73", "+FTM=97" } }
} ;
+#endif /* UCLINUX */
-struct c2msgstruct
+static struct c2msgstruct
{
int min, max ;
char *msg ;
} c2msg [] = {
+#ifndef UCLINUX
{ 0, 9, "Call Placement and Termination:" },
{ 0, 0, " Normal and proper end of connection" },
{ 1, 1, " Ring Detect without successful handshake" },
{ 102, 102, " COMREC invalid response received" },
{ 103, 103, " Unable to continue after PIN or PIP" },
{ 120, 255, "Reserved Codes" },
+#endif /* UCLINUX */
{ -1, -1, "" }
} ;
/* meaning of efax return codes */
-char *errormsg [] = {
+static char *errormsg [] = {
"success",
"number busy or modem in use",
"unrecoverable error",
/* Return name of frame of type 'fr'. */
+#ifndef UCLINUX
char *frname ( int fr )
{
static struct framenamestruct { int code ; char *name ; }
if ( fr == p->code || ( fr & 0x7f ) == p->code) break ;
return p->code ? p->name : "UNKNOWN" ;
}
+#endif /* UCLINUX */
/* Range-check capability. */
-int checkcap ( cap c )
+static int checkcap ( cap c )
{
int err=0, i ;
/* Print cap[ability] c using text values and prefix s. */
-void printcap ( char *s , cap c )
+static void printcap ( char *s , cap c )
{
int i ;
msg ( "N-+ %s" , s ) ;
/* Convert capability string to cap struct. Returns 0 or 2 on errors. */
-int str2cap ( char *s, cap c )
+static int str2cap ( char *s, cap c )
{
int err=0, n ;
-
- n = sscanf ( s, "%d,%d,%d,%d,%d,%d,%d,%d",
- c+0, c+1, c+2, c+3, c+4, c+5, c+6, c+7 ) ;
-
+ char *end ;
+
+ for ( n=0 ; n<NCAP ; n++ ) {
+ if (!s)
+ break;
+ c [ n ] = strtol ( s, &end, 10 );
+ if (end && *end && *end!=',')
+ break;
+ s = end;
+ }
+
if ( n < NCAP ) msg ( "Wmissing value(s) in \"%s\"", s ) ;
checkcap ( c ) ;
bytes. Converts into DIS format if 'isdis' is true, else into
DCS/DTC format. */
+#ifndef UCLINUX
void mkdis ( cap c, uchar *fif, int len, int isdis, int t4tx )
{
int i, k ;
if ( p->byte < len ) fif [ p->byte ] |= k << p->shift ;
}
}
+#endif /* UCLINUX */
/* Return length of DIS/DTC FIF (counts extension bits). */
+#ifndef UCLINUX
int dislen ( uchar *fif )
{
int n ;
for ( n=3 ; fif [ n-1 ] & 0x01 && n < MAXFIFLEN ; n++ ) ;
return n ;
}
+#endif /* UCLINUX */
/* Convert received DIS/DCS/DTC FIF to cap. Returns 0 or 3 if bad DIS/DCS
field. */
+#ifndef UCLINUX
int mkcap ( uchar *fif, cap c, int dis )
{
int err=0, i, j, k, len ;
}
return err ;
}
+#endif /* UCLINUX */
/* Compute compatible local/remote capabilities. Used by the
sending station only and only for Class 1. Returns 0 if OK or
3 if no compatible settings possible. */
+#ifndef UCLINUX
int mincap ( cap local, cap remote, cap session )
{
int err=0, i ;
return err ;
}
+#endif /* UCLINUX */
/* Skip to start of first/next page (or to start of previous page
RTN is received to restart the page. Returns 0 or 2 on
errors. */
-int rdpage ( IFILE *f, int dp, int *ppm, cap local, int *changed )
+static int rdpage ( IFILE *f, int dp, int *ppm, cap local, int *changed )
{
int err=0, m=EOP, yres, fVR, nVR ;
removes the most recently opened file. Returns 0 if OK, 2 on
errors. */
+#ifndef UCLINUX
int wrpage ( OFILE *f, int page )
{
int err=0 ;
return err ;
}
+#endif /* UCLINUX */
/* Send data for one page. Figures out required padding and 196->98 lpi
Sends RTC when done. Sends DLE-ETX and returns serial port to command
mode when done. Returns 0 if OK, non-0 on errors. */
-int send_data ( TFILE *mf, IFILE *f, int page, int pages,
- cap local, cap session, char *header, faxfont *font )
+static int send_data ( TFILE *mf, IFILE *f, int page, int pages,
+ cap local, cap session
+#ifndef UCLINUX
+ , char *header, faxfont *font
+#endif /* UCLINUX */
+ )
{
int done=0, err=0, noise=0, nr=0, lastnr=0, line, pixels ;
int i, decimate, pwidth, minlen, dcecps, inheader, skip=0 ;
uchar buf [ MAXCODES + 2*EOLBITS/8 + 1 ], *p ;
short runs [ MAXRUNS ], lastruns [ MAXRUNS ] ;
+#ifndef UCLINUX
char headerbuf [ MAXLINELEN ] ;
+#endif /* UCLINUX */
ENCODER e ;
newENCODER ( &e ) ;
msg ( "T limiting output to %d bps for %d byte modem buffer",
dcecps*8, MAXDCEBUF + MINWRITE ) ;
+#ifndef UCLINUX
if ( ckfmt ( header, 6 ) )
msg ( "W too many %%d escapes in header format string \"%s\"", header ) ;
else
sprintf ( headerbuf, header, page, pages, page, pages, page, pages ) ;
msg ("I header:[%s]", headerbuf ) ;
+#endif /* UCLINUX */
done = err = ttymode ( mf, SEND ) ;
continue ;
}
}
+#ifndef UCLINUX
/* generate and OR in header pixels */
if ( line >= HDRSTRT && line < HDRSTRT + HDRCHRH ) {
int hnr ;
hruns, 0 ) ;
nr = runor ( runs, nr, hruns, hnr, 0, &pixels ) ;
}
+#endif /* UCLINUX */
inheader = line < HDRSTRT + HDRCHRH ;
}
-int end_data ( TFILE *mf, cap session, int ppm, int *good )
+static int end_data ( TFILE *mf, cap session, int ppm, int *good )
{
int err=0, c ;
uchar *p ;
null it is used to save pixel count. Returns number of runs
stored, EOF on RTC, or -2 on EOF, DLE-ETX or other error. */
+#ifndef UCLINUX
int readfaxruns ( TFILE *f, DECODER *d, short *runs, int *pels )
{
int err=0, c=EOF, x, n ;
msg ( "H-" ) ;
msg ( "I- %s %s", s, nm ) ;
}
+#endif /* UCLINUX */
/* Send HDLC control frame of type type. Extra bits can be OR'ed
#define MORE_FR 0x100
#define SUB_FR 0x200
-int nframes = 0 ; /* counts frames sent/received */
+static int nframes = 0 ; /* counts frames sent/received */
+#ifndef UCLINUX
int putframe ( int type, uchar *buf, int len, TFILE *f, int t )
{
int err=0 ;
return err ;
}
+#endif /* UCLINUX */
/* Get a Class 1 command or response frame. An attempt to match
*/
+#ifndef UCLINUX
int getfr ( TFILE *mf, uchar *buf, int getcmd )
{
int err=0, frame=0, frlen, c, t ;
return err ;
}
+#endif /* UCLINUX */
/* Check for hangup message. Assumes hsc is initialized to a
was one. If perr is not null, sets it to 2 if the hsc was
non-zero (error). */
-int gethsc ( int *hsc, int *perr )
+static int gethsc ( int *hsc, int *perr )
{
int err=0, i ;
if ( sresponse ( "+FHNG:", hsc ) || sresponse ( "+FHS:", hsc ) ) {
/* Print remote ID and store DCS values in session as per
responses since last command. */
-void getc2dcs ( cap session )
+static void getc2dcs ( cap session )
{
char *p ;
if ( ( p = sresponse ( "+FTI:", 0 ) ) != 0 ||
/* Wait for a starting character XON or DC2. Display & ignore
any other characters received. */
-void getstartc ( TFILE *mf )
+static void getstartc ( TFILE *mf )
{
int c, noise ;
Returns 0 if OK or 2 on errors. */
-int c2sndrcv (
+static int c2sndrcv (
TFILE *mf, cap local, char *localid,
OFILE *outf, IFILE *inf,
- int pages, char *header, faxfont *font,
+ int pages,
+#ifndef UCLINUX
+ char *header, faxfont *font,
+#endif /* UCLINUX */
int maxpgerr, int noretry, int calling )
{
- int err=0, done=0, page, pagetry, nerr, c, dp=0 ;
+#ifndef UCLINUX
+ int c, nerr;
+#endif /* UCLINUX */
+ int err=0, done=0, page, pagetry, dp=0 ;
int ppm=0, good, hsc, changed ;
int remtx=0 ;
char *fname=0 ;
}
if ( calling ) {
- if ( pages ) goto send ;
+#ifndef UCLINUX
+ if ( pages )
+#endif /* UCLINUX */
+ goto send ;
+#ifndef UCLINUX
else goto poll ;
- } else {
+#endif /* UCLINUX */
+ }
+#ifndef UCLINUX
+ else {
if ( pages ) goto pollserver ;
else goto receive ;
}
+#endif /* UCLINUX */
/* Class 2 Send */
+#ifndef UCLINUX
pollserver:
+#endif /* UCLINUX */
/* with +FLP[L]=1 the modem should accept +FDT. */
if ( ! c20 ) getstartc ( mf ) ;
- send_data ( mf, inf, page, pages, local, session, header, font ) ;
+ send_data ( mf, inf, page, pages, local, session
+#ifndef UCLINUX
+ , header, font
+#endif /* UCLINUX */
+ ) ;
pagetry++ ;
if ( c20 ) {
goto done ;
+#ifndef UCLINUX
/* Class 2 Receive */
poll:
}
}
}
+#endif /* UCLINUX */
done:
not to issue +FRH/+FTH. Returns 0 if dialed OK, 1 if busy, 2
on errors. */
-int dial ( TFILE *f, char *s, int nowait )
+static int dial ( TFILE *f, char *s, int nowait )
{
int err=0, hsc=-1 ;
char c, dsbuf [ 128 ], *p ;
enum connectmode { NONE, DATAMODE, FAXMODE, VOICEMODE } ;
+#ifndef UCLINUX
enum connectmode ansmode ( int *crate, int *hsc )
{
enum connectmode mode = NONE ;
return mode ;
}
+#endif /* UCLINUX */
/* Answer the phone. Remove our lock if sharing device with
handle call appropriately. Re-lock if necessary. Exec *getty
or *vcmd for data or voice calls. */
+#ifndef UCLINUX
int answer ( TFILE *f, char **lkfile,
int wait, int share, int softaa,
char *getty, char *vcmd, char *acmd )
return err ;
}
+#endif /* UCLINUX */
/* Initialize modem. Determine class to use and issue
issues commands to enable polling also. Returns 0 or 3 if a
mandatory setup command fails. */
-int modem_init ( TFILE *mf, cap c, char *id,
+static int modem_init ( TFILE *mf, cap c, char *id,
int calling, int poll, int capsset, int *preverse )
{
int err=0, t=-TO_RESET ;
} else {
if ( strinresp ( "2.0" ) ) c20 = 1 ;
else if ( strinresp ( "2" ) ) ;
+#ifndef UCLINUX
else if ( strinresp ( "1" ) ) c1 = 1 ;
+#endif /* UCLINUX */
else err = msg ("E3 can't determine fax modem class support" ) ;
+#ifndef UCLINUX
if ( strstr ( model, "Sportster" ) ) { /* USR Sporsters are buggy */
c1 = 1 ;
c2 = c20 = 0 ;
}
+#endif /* UCLINUX */
}
}
/* the following are global so can terminate properly on signal */
-char *icmd[3][ MAXICMD+1 ] = {{0},{0},{0}} ; /* initialization commands */
-TFILE faxdev = { -1, 0,0, {0}, 0, 0 } ; /* modem */
-char *lkfile [ MAXLKFILE+1 ] = {0} ; /* lock file names */
-IFILE ifile = { 0 } ; /* files being sent */
-int locked = 0 ; /* modem locked */
+static char *icmd[3][ MAXICMD+1 ] = {{0},{0},{0}} ; /* initialization commands */
+static TFILE faxdev = { -1, 0,0, {0}, 0, 0 } ; /* modem */
+static char *lkfile [ MAXLKFILE+1 ] = {0} ; /* lock file names */
+static IFILE ifile = { 0 } ; /* files being sent */
+static int locked = 0 ; /* modem locked */
/* print names of files not sent and reset modem before
exiting. */
-int cleanup ( int err )
+static int cleanup ( int err )
{
/* log names of files not sent */
logifnames ( &ifile, "I failed -> %s" ) ;
/* signal handler */
-void onsig ( int sig )
+static void onsig ( int sig )
{
msg ( "E terminating on signal %d", sig ) ;
exit ( cleanup ( 5 ) ) ;
int main( int argc, char **argv)
{
int err=0, doneargs=0, c=0, i ;
- int testing=0, calling=0 ;
+ int testing=0;
+#ifndef UCLINUX
+ int calling=0 ;
+#else /* UCLINUX */
+#define calling (1)
+#endif /* UCLINUX */
int nicmd[3]={0,0,0}, nlkfile=0, nverb=0 ;
int maxpgerr = MAXPGERR ;
time_t now ;
+#ifndef UCLINUX
char *header = 0, headerbuf [ MAXLINELEN ] ;
char *fontname = 0 ;
faxfont font ;
+#endif /* UCLINUX */
OFILE ofile ;
int pages = 0 ;
- char *phnum="", *ansfname = DEFPAT ;
+ char *phnum="";
+#ifndef UCLINUX
+ char *ansfname = DEFPAT ;
char fnamepat [ EFAX_PATH_MAX ] ;
+#endif /* UCLINUX */
/* print initial message to both stderr & stdout */
argv0 = argv[0] ;
if ( nicmd[2] < MAXICMD ) icmd[2][ nicmd[2]++ ] = nxtoptarg ;
else err = msg ( "E2too many '-k' options");
break ;
+#ifndef UCLINUX
case 'h':
header = nxtoptarg ;
break ;
case 'f':
fontname = nxtoptarg ;
break ;
+#endif /* UCLINUX */
case 'd':
faxfile = nxtoptarg ;
break ;
for ( ; *nxtoptarg ; nxtoptarg++ )
switch ( *nxtoptarg ) {
case '0' : c20 = 1 ; break ;
+#ifndef UCLINUX
case '1' : c1 = 1 ; break ;
+#endif /* UCLINUX */
case '2' : c2 = 1 ; break ;
case 'a' : softaa = 1 ; break ;
case 'e' : ignerr = 1 ; break ;
}
break ;
case 'q':
- if ( sscanf ( nxtoptarg , "%d", &maxpgerr ) != 1 || maxpgerr < 0 )
+ maxpgerr = atoi( nxtoptarg );
+ if ( maxpgerr < 0 )
err=msg ("E2bad quality (-q) argument (%s)", nxtoptarg ) ;
break;
+#ifndef UCLINUX
case 'r':
ansfname = nxtoptarg ;
break;
+#endif /* UCLINUX */
case 's':
share = 1 ;
break;
case 't':
+#ifndef UCLINUX
calling=1;
+#endif /* UCLINUX */
/* fall through */
case 'p':
if ( argv [ argc ] ) err = msg ("E2can't happen(unterminated argv)") ;
if ( ! nicmd[2] ) icmd[2][nicmd[2]++] = "H" ; /* default -k command */
+#ifndef UCLINUX
readfont ( fontname, &font ) ;
if ( ! header ) {
strftime ( tmp, MAXLINELEN, "%c %%s P. %%%%d", localtime ( &now ) ) ;
sprintf ( header = headerbuf, tmp, localid ) ;
}
+#endif /* UCLINUX */
if ( ! err ) {
err = begin_session ( &faxdev, faxfile,
if ( calling ) {
err = dial ( &faxdev, phnum, 0 ) ;
- } else {
+ }
+#ifndef UCLINUX
+ else {
err = answer ( &faxdev, lkfile, wait, share, softaa,
getty, vcmd, acmd ) ;
if ( err == 1 ) locked = 1 ;
}
+#endif /* UCLINUX */
now = time(0) ; /* do it here so use reception time */
+#ifndef UCLINUX
strftime ( fnamepat, EFAX_PATH_MAX, ansfname, localtime ( &now ) ) ;
strncat ( fnamepat, ".%03d", EFAX_PATH_MAX - strlen ( fnamepat ) ) ;
newOFILE ( &ofile, O_TIFF_FAX, fnamepat, 0, 0, 0, 0 ) ;
+#endif /* UCLINUX */
if ( ! err ) {
+#ifndef UCLINUX
if ( c1 ) {
err = c1sndrcv ( &faxdev, local, localid,
&ofile, &ifile, pages, header, &font,
maxpgerr, noretry, calling ) ;
- } else {
+ } else
+#endif /* UCLINUX */
+ {
err = c2sndrcv ( &faxdev, local, localid,
- &ofile, &ifile, pages, header, &font,
+ &ofile, &ifile, pages,
+#ifndef UCLINUX
+ header, &font,
+#endif /* UCLINUX */
maxpgerr, noretry, calling ) ;
}
}
+#include "config.h"
+
#include <ctype.h> /* ANSI C */
#include <signal.h>
#include <stdio.h>
#define MAXRESPB 1024 /* maximum bytes of modem responses saved */
-char *prompts[] = { /* modem responses that are prompts */
+static char *prompts[] = { /* modem responses that are prompts */
"OOK", "-CONNECT FAX", "CCONNECT", "NNO CARRIER", "EERROR",
"NNO DIALTONE", "BBUSY", "NNO ANSWER", "M+FCERROR", "VVCON",
"DDATA", 0 } ;
int lockpolldelay = 8000 ; /* milliseconds between checks of lock files */
/* signals to be caught so can hang up phone */
-int catch [] = { CATCHSIGS, 0 } ;
+static int catch [] = { CATCHSIGS, 0 } ;
/* Modem features */
-int c1=0, c20=0 ; /* use class 1/class 2.0 */
+#ifndef UCLINUX
+int c1=0 ; /* use class 1 */
+#endif /* UCLINUX */
+int c20=0 ; /* use class 2.0 */
int c2=0 ; /* force class 2 */
int cmdpause = T_CMD ; /* delay before each init command */
int vfc = 0 ; /* virtual flow control */
uchar startchar = DC2 ; /* character to start reception */
/* response detector lookup tables */
+#ifdef UCLINUX
+static
+#endif /* UCLINUX */
uchar rd_nexts [ 256 ] = { 0 }, rd_allowed [ 256 ] = { 0 } ;
/* Initialize two lookup tables used by a state machine to detect
data there is a small O(10^-10) chance of spurious
detection. */
-void rd_init ( void )
+static void rd_init ( void )
{
int c ;
or null if times-out in t deciseconds or on i/o error. Trace
messages are buffered to reduce possible timing problems. */
-char *tgets( TFILE *f, char *s, int len, int t )
+static char *tgets( TFILE *f, char *s, int len, int t )
{
int i, n, c ;
are in hex.] Returns pointer to start of data field of
response string or NULL if not found. */
-char responses [ MAXRESPB ], *lresponse = responses ;
+static char responses [ MAXRESPB ], *lresponse = responses ;
char *sresponse ( char *s, int *ip )
{
lenr = strlen ( r ) ;
if ( strspn ( r, " \r\n" ) == lenr && r+lenr < lresponse ) r += lenr ;
- if ( ip && sscanf ( r, "%d", ip ) > 0 )
+ if ( ip ) {
+ *ip = atoi( r );
msg ( "R read value %d from \"%s\"", *ip, r ) ;
+ }
}
}
prefix string is skipped. Returns pointer to the table entry or NULL if
not found. */
-char *strtabmatch ( char **p, char *s )
+static char *strtabmatch ( char **p, char *s )
{
while ( *p && strncmp ( *p+1, s, strlen ( *p+1 ) ) ) p++ ;
return ( ! *p || **p == '-' ) ? NULL : *p ;
enable text responses. Returns 0 if OK or 4 if no response.
*/
-int modemsync ( TFILE *f )
+static int modemsync ( TFILE *f )
{
int err=0, method=0 ;
/* Modem features */
-extern int c1, c20 ; /* use class 1/class 2.0 */
+#ifndef UCLINUX
+extern int c1 ; /* use class 1 */
+#else /* UCLINUX */
+#define c1 (0)
+#endif /* UCLINUX */
+extern int c20 ; /* use class 2.0 */
extern int c2 ; /* force class 2 */
extern int cmdpause ; /* delay before each init command */
extern int vfc ; /* virtual flow control */
int cmd ( TFILE *f, char *s , int t ) ;
int ckcmd ( TFILE *f, int *err, char *s, int t, int r ) ;
-int modemsync ( TFILE *f ) ;
char *sresponse ( char *s, int *ip ) ;
char *strinresp ( char *s ) ;
int getresp ( char *s, char *buf, int len ) ;
Copyright 1995 Ed Casas
*/
+#include "config.h"
+
#include <ctype.h>
#include <stdio.h>
#include <string.h>
extern t4tab wtab [ ( 64 + 27 + 13 ) + 1 ] ; /* T.4 coding tables */
extern t4tab btab [ ( 64 + 27 + 13 ) + 1 ] ;
+#ifndef UCLINUX
short short256 = 256 ; /* for endian-ness detection */
/* Make sure printf strings have only %d escapes and n or fewer
return n < 0 ;
}
+#endif /* UCLINUX */
/* Initialize state of variable-length code word encoder. */
If necessary, zero-length runs are created to avoid copying. Returns
the pixel width change (+/-). */
+#ifndef UCLINUX
int xshift ( short *runs, int nr, int s )
{
int i=0, n=0 ;
}
return outlen ;
}
+#endif /* UCLINUX */
/* Zero-terminated lists of run lengths for each byte. */
-uchar byteruns [ 1408 + 1 ] =
+static uchar byteruns [ 1408 + 1 ] =
"8071061106205120511105210530413041210411110411204220421104310440"
"3140313103121103122031112031111103112103113032303221032111032120"
"3320331103410350215021410213110213202121202121110212210212302111"
lengths. Run length array must have *more* than 8*n elements. First
run is white. Returns number of runs coded. */
-int bittorun ( uchar *bits, int n, short *runs )
+static int bittorun ( uchar *bits, int n, short *runs )
{
static uchar init=0, *rltab [ 256 ] ;
register uchar *p, c, lastc = 0x00 ;
and comments. Returns the number or 0 on EOF. Reads one more
byte than used by the number. */
-int pbmdim ( IFILE *f )
+static int pbmdim ( IFILE *f )
{
int c, n=0 ;
#define putbits( c, b ) { x = ( x << (b) ) | (c) ; shift += (b) ; \
if ( shift >= 0 ) { *out++ = x >> shift ; shift -= 8 ; } }
+#ifndef UCLINUX
void copybits ( uchar *in, int from, short nb )
{
uchar *f ;
if ( nb > 0 ) putbits ( *f >> ( 8 - nb ), nb );
}
}
+#endif /* UCLINUX */
/* Generate scan line 'line' of string 'txt' using font `font'
of white space are added at the left margin. Sets 'pels' to
line width if not null. Returns number of runs coded. */
+#ifndef UCLINUX
int texttorun ( uchar *txt, faxfont *font, short line,
int w, int h, int lmargin,
short *runs, int *ppels )
return nr ;
}
+#endif /* UCLINUX */
/* Image File Input Functions */
/* Names of file formats */
-char *iformatname [ NIFORMATS ] = IFORMATS ;
-char *oformatname [ NOFORMATS ] = OFORMATS ;
-char *pformatname [ NPFORMATS ] = PFORMATS ;
+static char *iformatname [ NIFORMATS ] = IFORMATS ;
+#ifndef UCLINUX
+static char *oformatname [ NOFORMATS ] = OFORMATS ;
+#endif /* UCLINUX */
+static char *pformatname [ NPFORMATS ] = PFORMATS ;
/* Log the names of files still to be sent using the "msg()"
format string s. */
}
+/* Bit reversal lookup tables (note that the `normalbits' array
+ is the one actually used for the bit reversal. */
+
+uchar reversebits [ 256 ], normalbits [ 256 ] ;
+
/* Read run lengths for one scan line from T.4-coded IFILE f into buffer
runs. If pointer pels is not null it is used to save pixel count.
Returns number of runs stored, EOF on RTC, or -2 on EOF or other
error. */
+#ifndef UCLINUX
int readruns ( IFILE *f, short *runs, int *pels )
{
int err=0, c=EOF, n ;
return err ? err : n ;
}
+#endif /* UCLINUX */
/* Read a PCX compressed bit-map */
+#ifndef UCLINUX
int readpcx ( char *p, int len, IFILE *f )
{
int err=0, n, c ;
return err ;
}
+#endif /* UCLINUX */
/* Read a scan line from the current page of IFILE f. Stores
number of runs in runs and line width in pels if not null.
int readline ( IFILE *f, short *runs, int *pels )
{
- int nr = 0, nb ;
+ int nr = 0 ;
+#ifndef UCLINUX
+ int nb ;
+#endif /* UCLINUX */
uchar bits [ MAXBITS ] ;
if ( f->lines != 0 ) { /* -1 allowed as well */
switch ( f->page->format ) {
+#ifndef UCLINUX
case P_TEXT :
if ( f->txtlines <= 0 ) { /* need another text line */
if ( fgets ( f->text, MAXLINELEN, f->f ) ) {
f->txtlines-- ;
}
break ;
+#endif /* UCLINUX */
case P_RAW:
case P_PBM:
}
break ;
+#ifndef UCLINUX
case P_FAX:
nr = readruns ( f, runs, pels ) ;
break ;
if ( pels ) *pels = f->page->w ;
}
break ;
+#endif /* UCLINUX */
}
} else {
/* Deduce the file type by scanning buffer p of n bytes. */
-int getformat ( uchar *p, int n )
+static int getformat ( uchar *p, int n )
{
int format = 0 ;
/* figure out file type if not already set */
+#ifndef UCLINUX
if ( ! format && n < 2 ) {
format = I_TEXT ;
msg ( "W only read %d byte(s) from input file, assuming text", n ) ;
if ( ! format && ! p[0] && ! ( p[1] & 0xe0 ) ) {
format = I_FAX ;
}
+#endif /* UCLINUX */
if ( ! format && ! strncmp ( p, "P4", 2 ) ) {
format = I_PBM ;
}
+#ifndef UCLINUX
if ( ! format && n >= 128 && p[0] == 0x0a &&
strchr ("\02\03\05", p[1] ) && p[2] <= 1 ) {
if ( p[65] != 1 ) {
format = I_TEXT ;
}
}
+#endif /* UCLINUX */
return format ;
}
/* initialize page descriptor */
-void page_init ( PAGE *p, char *fn )
+static void page_init ( PAGE *p, char *fn )
{
p->fname = fn ;
p->offset = 0 ;
}
-void page_report ( PAGE *p, int fmt, int n )
+static void page_report ( PAGE *p, int fmt, int n )
{
msg ( "F page %d : %s + %ld : %dx%d @ %.fx%.f dpi %s/%s",
n,
/* Name of TIFF tag 'tag'. */
+#ifndef UCLINUX
char *tagname ( int tag )
{
static struct tagnamestruct { int code ; char *name ; }
return err ;
}
+#endif /* UCLINUX */
/* Read a TIFF directory at current file offset, save image
format information and seek to next directory if any. Returns
0 if OK, 2 on errors. */
+#ifndef UCLINUX
int tiff_next ( IFILE *f )
{
int err=0 ;
return text_next ( f ) ;
}
+#endif /* UCLINUX */
/* File handling for PBM files */
-int pbm_first ( IFILE *f )
+static int pbm_first ( IFILE *f )
{
int err=0 ;
/* get a 16-bit word in Intel byte order. */
+#ifndef UCLINUX
int fgeti ( IFILE *f )
{
return fgetc ( f->f ) + fgetc ( f->f ) * 256 ;
/* input file state reset for different compression methods */
#define pcx_reset 0
+#endif /* UCLINUX */
#define pbm_reset 0
+#ifndef UCLINUX
int text_reset ( IFILE *f )
{
return 0 ;
}
+#endif /* UCLINUX */
/* Skip to start of same (dp=0) or next (dp=1) page image.
int err=0 ;
int ( *reset [NPFORMATS] ) ( IFILE * ) = {
- raw_reset, fax_reset, pbm_reset, text_reset, pcx_reset
+#ifndef UCLINUX
+ raw_reset, fax_reset,
+#endif /* UCLINUX */
+ pbm_reset,
+#ifndef UCLINUX
+ text_reset, pcx_reset
+#endif /* UCLINUX */
}, (*pf)(IFILE*) ;
/* close current file if any and set to NULL */
int newIFILE ( IFILE *f, char **fnames )
{
- int err=0, i, n, fformat=0 ;
+ int err=0, i, n = 0 /* GCC paranoia */, fformat=0 ;
char **p ;
uchar buf[128] ;
int ( *fun ) ( IFILE * ) ;
int ( *first [NIFORMATS] ) ( IFILE * ) = {
- auto_first, pbm_first, fax_first, text_first, tiff_first,
+ auto_first, pbm_first,
+#ifndef UCLINUX
+ fax_first, text_first, tiff_first,
dfax_first, pcx_first, raw_first, dcx_first
+#endif /* UCLINUX */
} ;
int ( *next [NIFORMATS] ) ( IFILE * ) = {
- auto_next, pbm_next, fax_next, text_next, tiff_next,
+ auto_next, pbm_next,
+#ifndef UCLINUX
+ fax_next, text_next, tiff_next,
dfax_next, pcx_next, raw_next, dcx_next
+#endif /* UCLINUX */
} ;
f->page = f->pages ;
compression is removal of trailing zeroes. Margins and resolution are
set before first write. */
+#ifndef UCLINUX
char *PCLBEGIN =
"\033E" /* Printer reset. */
"\033&l0E" /* top margin = 0 */
return err ;
}
+#endif /* UCLINUX */
/* Initialize bit reversal lookup tables (note that the
/* the lookup tables for each colour and the fill lookup table */
+#ifndef UCLINUX
dtab tw1 [ 512 ], tw2 [ 512 ], tb1 [ 512 ], tb2 [ 512 ], fill [ 512 ] ;
-char tabinit=0 ;
+static char tabinit=0 ;
/* Add code cword shifted left by shift to decoding table tab. */
( p - p0 ) > 63 ? t1 : ot ) ;
}
}
+#endif /* UCLINUX */
/* Initialize a T.4 decoder. */
+#ifndef UCLINUX
void newDECODER ( DECODER *d )
{
int i ;
d->tab = tw1 ;
d->eolcnt = 0 ;
}
+#endif /* UCLINUX */
/* T.4 coding table and default font for efax/efix */
/* T.4 1-D run-length coding tables. codes must be in run length
order for runtocode(). */
-t4tab wtab [ ( 64 + 27 + 13 ) + 1 ] = { /* runs of white */
+static t4tab wtab [ ( 64 + 27 + 13 ) + 1 ] = { /* runs of white */
/* Terminating White Codes */
{0,0,0} } ;
-t4tab btab [ ( 64 + 27 + 13 ) + 1 ] = { /* runs of black */
+static t4tab btab [ ( 64 + 27 + 13 ) + 1 ] = { /* runs of black */
/* Terminating Black Codes */
/* The built-in 8x16 font. Runs of zeroes are coded as 0
followed by the repetition count. */
+#ifndef UCLINUX
uchar stdfont [ 1980 ] = {
0,255,0,255,0,194,8,4,12,10,18,0,3,16,4,8,20,8,4,8,20,0,1,10,8,4,
4,10,18,0,2,16,4,8,20,4,0,68,20,0,1,8,0,2,12,6,48,0,5,2,0,43,14,32,
0,7,48,0,39,12,0,19,32,0,2,24,0,6,30,0,7,24,0,31,24,0,21,48,32,48,
0,255,0,1
} ;
+#endif /* UCLINUX */
#define NOFORMATS 14
#define NPFORMATS 5
-enum iformats { I_AUTO=0, I_PBM=1, I_FAX=2, I_TEXT=3, I_TIFF=4,
- I_DFAX=5, I_PCX=6, I_RAW=7, I_DCX=8 } ;
+enum iformats { I_AUTO=0, I_PBM=1,
+#ifndef UCLINUX
+ I_FAX=2, I_TEXT=3, I_TIFF=4,
+ I_DFAX=5, I_PCX=6, I_RAW=7, I_DCX=8
+#endif /* UCLINUX */
+ } ;
#define IFORMATS { "AUTO", "PBM", "FAX", "TEXT", "TIFF", \
"DFAX", "PCX", "RAW", "DCX" } ;
-enum oformats { O_AUTO=0, O_PBM=1, O_FAX=2, O_PCL=3, O_PS=4,
+enum oformats { O_AUTO=0, O_PBM=1,
+#ifndef UCLINUX
+ O_FAX=2, O_PCL=3, O_PS=4,
O_PGM=5, O_TEXT=6, O_TIFF_FAX=7, O_TIFF_RAW=8, O_DFAX=9,
- O_TIFF=10, O_PCX=11, O_PCX_RAW=12, O_DCX=13 } ;
+ O_TIFF=10, O_PCX=11, O_PCX_RAW=12, O_DCX=13
+#endif /* UCLINUX */
+ } ;
#define OFORMATS { "AUTO", "PBM", "FAX", "PCL", "PS", \
"PGM", "TEXT", "TIFF", "TIFF", "DFAX", \
short *runs, int *pels ) ;
int xpad ( short *runs, int nr, int pad ) ;
-int xscale ( short *runs, int nr, int xs ) ;
-int xshift ( short *runs, int nr, int s ) ;
int runor ( short *a, int na, short *b, int nb, short *c, int *pels ) ;
/* Bit reversal lookup tables (note that the `normalbits' array
is the one actually used for the bit reversal. */
-uchar reversebits [ 256 ], normalbits [ 256 ] ;
+extern uchar reversebits [ 256 ], normalbits [ 256 ] ;
void initbittab(void) ;
+#include "config.h"
+
#include <ctype.h> /* ANSI C */
#include <errno.h>
#include <stdio.h>
/* Print time stamp. */
-time_t tstamp ( time_t last, FILE *f )
+static time_t tstamp ( time_t last, FILE *f )
{
- time_t now ;
- char tbuf [ MAXTSTAMP ] ;
+ time_t now = time ( NULL );
- now = time ( 0 ) ;
+ if ( ! last )
+ last = now;
- strftime ( tbuf, MAXTSTAMP, ( now - last > 600 ) ? "%c" : "%M:%S",
- localtime( &now ) ) ;
- fputs ( tbuf, f ) ;
+ printf ( "+%03ld", (long)(now - last) );
return now ;
}
extern char *argv0 ; /* program name */
char *cname ( unsigned char c ) ;
-time_t tstamp ( time_t last, FILE *f ) ;
int msg ( char *fmt, ... ) ;
extern int nxtoptind ;
Copyright 1995, Ed Casas
*/
+#include "config.h"
+
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
escapes, DLE-ETX terminators and fixing bit order. Evaluates
to the next character, EOF on error/timeout, or -2 on DLE-ETX. */
+#ifndef UCLINUX
int tgetd ( TFILE *f, int t )
{
int c ;
return c ;
}
+#endif /* UCLINUX */
/* Write buffer to modem. Returns 0 or EOF on error. */
/* Compare current termios state with termios struct t. Returns 0 if equal,
1 otherwise. */
-int ckfld ( char *field, int set, int get )
+static int ckfld ( char *field, int set, int get )
{
return set == get ?
0 : msg ( "W1 termios.%s is 0%08o, not 0%08o", field, get, set ) ;
}
-int checktermio ( struct termios *t, TFILE *f )
+static int checktermio ( struct termios *t, TFILE *f )
{
struct termios s ;
int err=0 ;
transmit LS bit first. T.4/T.30 says MS bit is sent
first. `Normal' order therefore reverses bit order. */
-void tinit ( TFILE *f, int fd, int reverse, int hwfc )
+static void tinit ( TFILE *f, int fd, int reverse, int hwfc )
{
f->ip = f->iq = f->ibuf ;
f->obitorder = normalbits ;
name or if no longer locked, 1 if locked by another pid, 2 on error, 3
if locked by us. */
-int ttlocked ( char *fname, int log )
+static int ttlocked ( char *fname, int log )
{
int err=0, ipid ;
FILE *f ;
if ( fname && ( f = fopen ( fname , "r" ) ) ) {
- if ( fread ( buf, sizeof(char), EFAX_PATH_MAX-1, f ) == sizeof(pid_t) ||
- sscanf ( buf, "%d" , &ipid ) != 1 ) {
+ if ( fread ( buf, sizeof(char), EFAX_PATH_MAX-1, f ) == sizeof(pid_t) ||
+ (ipid = atoi(buf)) <= 0 ) {
pid = * (pid_t *) buf ;
if ( log ) msg ("X+ read binary pid %d from %s", (int) pid, fname ) ;
} else {
if ( kill ( pid, 0 ) && errno == ESRCH ) {
if ( log ) msg ("X - stale" ) ;
- if ( remove ( fname ) )
+ if ( unlink ( fname ) )
err = msg ( "ES2can't remove stale lock %s from pid %d:",
fname, pid ) ;
else
file name or if created, 1 if locked by another pid, 2 on
error, 3 if locked by us. */
-int ttlock ( char *fname, int log )
+static int ttlock ( char *fname, int log )
{
int err=0, dirlen, bin=0 ;
FILE *f=0 ;
if ( f ) {
fclose ( f ) ;
- if ( err ) remove ( buf ) ;
+ if ( err ) unlink ( buf ) ;
}
return err ;
/* Remove lock file. Returns 0 on null file name, doesn't exist, or was
removed, 1 if the lock is to another pid, 2 on errors. */
-int ttunlock ( char *fname )
+static int ttunlock ( char *fname )
{
int err = 0 ;
case 1: err = msg ( "E1won't remove lock %s (not ours)" , fname ) ; break ;
case 2: err = 2 ; break ;
case 3:
- if ( remove ( fname ) ) {
+ if ( unlink ( fname ) ) {
err = msg ( "ES2can't remove lock %s:", fname ) ;
} else {
err = msg ( "X0removed lock file %s", fname ) ;
#define _EFAXOS_H
#include <time.h>
+#include <stdlib.h>
#include "efaxlib.h"
#define UNIXSIGS SIGHUP, SIGQUIT, SIGIOT, SIGALRM
#define CATCHSIGS ANSISIGS, UNIXSIGS
-/* Bit order reversal table. */
-
-extern unsigned char normalbits [ ] ;
-
typedef enum ttymodes /* serial port modes: */
{
COMMAND, /* 19200 8N1, no f/c, DTR high */
int tgetd ( TFILE *f, int t ) ;
int tput ( TFILE *f, unsigned char *p, int n ) ;
int tdata ( TFILE *f, int t ) ;
-void tinit ( TFILE *f, int fd, int reverse, int hwfc ) ;
int ttyopen ( TFILE *f, char *fname, int reverse, int hwfc ) ;
int ttymode ( TFILE *f, ttymodes mode ) ;
void msleep ( int t ) ;
+#include "config.h"
+
#define Copyright "Copyright 1999 Ed Casas"
#define Version "efix v 0.3"