First uC-compilable version, not tested yet
authorshort <>
Mon, 15 Apr 2002 00:35:26 +0000 (00:35 +0000)
committershort <>
Mon, 15 Apr 2002 00:35:26 +0000 (00:35 +0000)
15 files changed:
.cvsignore [new file with mode: 0644]
Makefile
bigfunc [new file with mode: 0755]
cleanup.c [new file with mode: 0644]
config.h [new file with mode: 0644]
efax.c
efaxio.c
efaxio.h
efaxlib.c
efaxlib.h
efaxmsg.c
efaxmsg.h
efaxos.c
efaxos.h
efix.c

diff --git a/.cvsignore b/.cvsignore
new file mode 100644 (file)
index 0000000..fe9d640
--- /dev/null
@@ -0,0 +1,4 @@
+efax
+*.o
+*.coff
+tags
index ffefde8..41db9b1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,25 @@
 # 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.
@@ -21,22 +30,23 @@ MANDIR=/usr/man
 .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
diff --git a/bigfunc b/bigfunc
new file mode 100755 (executable)
index 0000000..da300f9
--- /dev/null
+++ b/bigfunc
@@ -0,0 +1,28 @@
+#! /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{$_},$_;
+       }
diff --git a/cleanup.c b/cleanup.c
new file mode 100644 (file)
index 0000000..baa960a
--- /dev/null
+++ b/cleanup.c
@@ -0,0 +1,5 @@
+#include "config.h"
+
+void _cleanup(void)
+{
+}
diff --git a/config.h b/config.h
new file mode 100644 (file)
index 0000000..fe0b027
--- /dev/null
+++ b/config.h
@@ -0,0 +1,30 @@
+#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 */
diff --git a/efax.c b/efax.c
index 42880d2..803722c 100644 (file)
--- a/efax.c
+++ b/efax.c
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #define Copyright         "Copyright 1999 Ed Casas"
 
 #define Version                  "efax v 0.9"
@@ -28,7 +30,7 @@
 
 */
 
-const char *Usage =
+static const char *Usage =
   "Usage:\n"
   "  %s [ option ]... [ -t num [ file... ] ]\n"
   "Options:\n"
@@ -36,7 +38,9 @@ const char *Usage =
   "  -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"
@@ -45,7 +49,9 @@ const char *Usage =
   "  -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"
@@ -57,7 +63,9 @@ const char *Usage =
   "      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"
@@ -111,7 +119,11 @@ const char *Usage =
 #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) */
@@ -132,15 +144,18 @@ typedef int cap [ NCAP ] ;                /* remote/local capabilities */
 
                                         /* 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 } ;
@@ -148,12 +163,13 @@ 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. */
@@ -168,7 +184,7 @@ typedef struct t30tabstruct
 
 #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 } ,
@@ -189,7 +205,7 @@ t30tabst t30tab [ NCAP ] = {
 } ;
 
                                        /* 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" } ,
@@ -217,6 +233,7 @@ enum commanddtype { RCV=0, SND=1, DTA=0, TRN=1 } ;
 /* 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" } ,
@@ -227,12 +244,14 @@ char *c1cmd [ 2 ]  [ 2 ] [ 8 ] = {
   { "+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" },
@@ -292,12 +311,13 @@ struct c2msgstruct
   { 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",
@@ -310,6 +330,7 @@ char *errormsg [] = {
 
 /* Return name of frame of type 'fr'. */
 
+#ifndef UCLINUX
 char *frname ( int fr )
 {
   static struct framenamestruct {  int code ;  char *name ; } 
@@ -351,10 +372,11 @@ char *frname ( int fr )
     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 ;
 
@@ -369,7 +391,7 @@ int checkcap ( cap c )
 
 /* 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 ) ;
@@ -382,13 +404,20 @@ void printcap ( char *s , cap c )
 
 /* 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 ) ;
@@ -401,6 +430,7 @@ int str2cap ( char *s, cap 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 ;
@@ -422,21 +452,25 @@ void mkdis ( cap c, uchar *fif, int len, int isdis, int t4tx )
     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 ;
@@ -462,12 +496,14 @@ int mkcap ( uchar *fif, cap c, int dis )
   }
   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 ;
@@ -492,6 +528,7 @@ int mincap ( cap local, cap remote, cap session )
 
   return err ;
 }
+#endif /* UCLINUX */
 
 
 /* Skip to start of first/next page (or to start of previous page
@@ -508,7 +545,7 @@ int mincap ( cap local, cap remote, cap session )
    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  ;
 
@@ -553,6 +590,7 @@ int rdpage ( IFILE *f, int dp, int *ppm, cap local, int *changed )
    removes the most recently opened file. Returns 0 if OK, 2 on
    errors. */
 
+#ifndef UCLINUX
 int wrpage ( OFILE *f, int page )
 {
   int err=0 ;
@@ -569,6 +607,7 @@ int wrpage ( OFILE *f, int page )
   
   return err ;
 }
+#endif /* UCLINUX */
 
 
 /* Send data for one page.  Figures out required padding and 196->98 lpi
@@ -579,14 +618,20 @@ int wrpage ( OFILE *f, int page )
    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 ) ;
@@ -603,11 +648,13 @@ int send_data ( TFILE *mf, IFILE *f, int page, int pages,
     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 ) ; 
 
@@ -637,6 +684,7 @@ int send_data ( TFILE *mf, IFILE *f, int page, int pages,
        continue ;
       }
     }
+#ifndef UCLINUX
                                /* generate and OR in header pixels */
     if ( line >= HDRSTRT && line < HDRSTRT + HDRCHRH ) {
       int hnr ;
@@ -646,6 +694,7 @@ int send_data ( TFILE *mf, IFILE *f, int page, int pages,
                       hruns, 0 ) ;
       nr = runor ( runs, nr, hruns, hnr, 0, &pixels ) ;
     }
+#endif /* UCLINUX */
     
     inheader = line < HDRSTRT + HDRCHRH ;
 
@@ -695,7 +744,7 @@ int send_data ( TFILE *mf, IFILE *f, int page, int pages,
 }
 
 
-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 ;
@@ -740,6 +789,7 @@ int end_data ( TFILE *mf, cap session, int ppm, int *good )
    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 ;
@@ -951,6 +1001,7 @@ void logfr ( char *s , char *nm , uchar *p , int n )
   msg ( "H-" ) ;
   msg ( "I- %s %s", s, nm ) ;
 }
+#endif /* UCLINUX */
 
 
 /* Send HDLC control frame of type type.  Extra bits can be OR'ed
@@ -964,8 +1015,9 @@ void logfr ( char *s , char *nm , uchar *p , int n )
 #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 ;
@@ -1075,6 +1127,7 @@ int receive_frame_data ( TFILE *f, uchar *buf, int n, int *len )
 
   return err ;
 }
+#endif /* UCLINUX */
 
 
 /* Get a Class 1 command or response frame.  An attempt to match
@@ -1097,6 +1150,7 @@ int receive_frame_data ( TFILE *f, uchar *buf, int n, int *len )
  
 */
 
+#ifndef UCLINUX
 int getfr ( TFILE *mf, uchar *buf, int getcmd )
 {
   int err=0, frame=0, frlen, c, t ;
@@ -1529,6 +1583,7 @@ int c1sndrcv (
 
   return err ;
 }
+#endif /* UCLINUX */
 
 
 /* Check for hangup message.  Assumes hsc is initialized to a
@@ -1536,7 +1591,7 @@ int c1sndrcv (
    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 ) ) {
@@ -1561,7 +1616,7 @@ int gethsc ( int *hsc, int *perr )
 /* 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 ||  
@@ -1578,7 +1633,7 @@ void getc2dcs ( cap session )
 /* 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 ;
   
@@ -1614,13 +1669,19 @@ void getstartc ( TFILE *mf )
    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 ;
@@ -1635,16 +1696,26 @@ int c2sndrcv (
   }
 
   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. */
 
@@ -1676,7 +1747,11 @@ int c2sndrcv (
 
     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 ) {
@@ -1731,6 +1806,7 @@ int c2sndrcv (
 
   goto done ;
 
+#ifndef UCLINUX
   /* Class 2 Receive */
 
  poll:
@@ -1795,6 +1871,7 @@ int c2sndrcv (
       }
     }
   } 
+#endif /* UCLINUX */
 
   
  done:
@@ -1811,7 +1888,7 @@ int c2sndrcv (
    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 ;
@@ -1853,6 +1930,7 @@ int dial ( TFILE *f, char *s, int nowait )
 
 enum connectmode { NONE, DATAMODE, FAXMODE, VOICEMODE } ; 
 
+#ifndef UCLINUX
 enum connectmode ansmode ( int *crate, int *hsc )
 {
   enum connectmode mode = NONE ;
@@ -1891,6 +1969,7 @@ enum connectmode ansmode ( int *crate, int *hsc )
 
   return mode ;
 }
+#endif /* UCLINUX */
 
 
 /* Answer the phone.  Remove our lock if sharing device with
@@ -1899,6 +1978,7 @@ enum connectmode ansmode ( int *crate, int *hsc )
    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 )
@@ -1994,6 +2074,7 @@ int answer ( TFILE *f, char **lkfile,
 
   return err  ;
 }
+#endif /* UCLINUX */
 
 
 /* Initialize modem.  Determine class to use and issue
@@ -2001,7 +2082,7 @@ int answer ( TFILE *f, char **lkfile,
    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 ;
@@ -2027,12 +2108,16 @@ int modem_init ( TFILE *mf, cap c, char *id,
     } 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 */
     }
   }
 
@@ -2117,17 +2202,17 @@ int modem_init ( TFILE *mf, cap c, char *id,
 
 /* 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" ) ;
@@ -2144,7 +2229,7 @@ int cleanup ( int err )
 
 /* signal handler */
 
-void onsig ( int sig ) 
+static void onsig ( int sig ) 
 { 
   msg ( "E terminating on signal %d", sig ) ; 
   exit ( cleanup ( 5 ) ) ;
@@ -2159,7 +2244,12 @@ void onsig ( int sig )
 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 ;
 
@@ -2175,14 +2265,19 @@ int main( int argc, char **argv)
   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] ;
@@ -2223,12 +2318,14 @@ int main( int argc, char **argv)
       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 ;
@@ -2242,7 +2339,9 @@ int main( int argc, char **argv)
       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 ;
@@ -2257,17 +2356,22 @@ int main( int argc, char **argv)
        }
       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)") ;
@@ -2301,6 +2405,7 @@ int main( int argc, char **argv)
 
   if ( ! nicmd[2] ) icmd[2][nicmd[2]++] = "H" ;        /* default -k command */
 
+#ifndef UCLINUX
   readfont ( fontname, &font ) ;
 
   if ( ! header ) {
@@ -2309,6 +2414,7 @@ int main( int argc, char **argv)
     strftime ( tmp, MAXLINELEN, "%c %%s   P. %%%%d", localtime ( &now ) ) ;
     sprintf ( header = headerbuf, tmp, localid ) ;
   }
+#endif /* UCLINUX */
 
   if ( ! err ) {
     err = begin_session ( &faxdev, faxfile, 
@@ -2326,25 +2432,36 @@ int main( int argc, char **argv)
 
     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 ) ;
       }
     }
index 5b8dbde..27da18b 100644 (file)
--- a/efaxio.c
+++ b/efaxio.c
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #include <ctype.h>             /* ANSI C */
 #include <signal.h>    
 #include <stdio.h>
@@ -9,7 +11,7 @@
 
 #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 } ;
@@ -17,18 +19,24 @@ char *prompts[] = {         /* modem responses that are prompts */
 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
@@ -44,7 +52,7 @@ uchar rd_nexts [ 256 ] = { 0 }, rd_allowed [ 256 ] = { 0 } ;
    data there is a small O(10^-10) chance of spurious
    detection. */
 
-void rd_init ( void )
+static void rd_init ( void )
 {
   int c ;
 
@@ -64,7 +72,7 @@ void rd_init ( void )
    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 ;
 
@@ -131,7 +139,7 @@ int sendbuf ( TFILE *f, uchar *p, int n, int dcecps )
    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 )
 {
@@ -147,8 +155,10 @@ 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 ) ;
+      }
     }
     
   }
@@ -204,7 +214,7 @@ int getresp ( char *s, char *buf, int len )
    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 ;
@@ -301,7 +311,7 @@ int ckcmd ( TFILE *f, int *err, char *s, int t, int r )
    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 ;
 
index 257b8df..b326c1b 100644 (file)
--- a/efaxio.h
+++ b/efaxio.h
@@ -21,7 +21,12 @@ enum promptcodes {           /* codes for modem prompts */
 
                      /* 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 */
@@ -37,7 +42,6 @@ extern uchar rd_allowed[], rd_nexts[] ;
 
 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 ) ;
index 4887cd9..23a74b2 100644 (file)
--- a/efaxlib.c
+++ b/efaxlib.c
@@ -3,6 +3,8 @@
                     Copyright 1995 Ed Casas
 */
 
+#include "config.h"
+
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
@@ -23,6 +25,7 @@
 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
@@ -40,6 +43,7 @@ int ckfmt ( char *p, int n )
   
   return n < 0 ;
 }
+#endif /* UCLINUX */
 
 
 /* Initialize state of variable-length code word encoder. */
@@ -127,6 +131,7 @@ int xpad ( short *runs, int nr, int pad )
    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 ;
@@ -160,11 +165,12 @@ int xscale ( short *p, int nr, int xs )
   }
   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"
@@ -192,7 +198,7 @@ uchar byteruns [ 1408 + 1 ] =
    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 ;
@@ -290,7 +296,7 @@ int runor ( short *a, int na, short *b, int nb, short *c, int *pels )
    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 ;
   
@@ -319,6 +325,7 @@ int pbmdim ( IFILE *f )
 #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 ;
@@ -350,6 +357,7 @@ void copybits ( uchar *in, int from, short nb )
     if ( nb > 0 ) putbits ( *f >> ( 8 - nb ), nb );
   }
 }   
+#endif /* UCLINUX */
 
 
 /* Generate scan line 'line' of string 'txt' using font `font'
@@ -358,6 +366,7 @@ void copybits ( uchar *in, int from, short nb )
    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 )
@@ -395,15 +404,18 @@ int texttorun ( uchar *txt, faxfont *font, short line,
 
   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. */
@@ -421,11 +433,17 @@ void logifnames ( IFILE *f, char *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 ;
@@ -497,10 +515,12 @@ int readruns ( IFILE *f, short *runs, int *pels )
   
   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 ;
@@ -531,6 +551,7 @@ int readpcx ( char *p, int len, IFILE *f )
 
   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.
@@ -542,12 +563,16 @@ int readpcx ( char *p, int len, IFILE *f )
 
 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 ) ) {
@@ -567,6 +592,7 @@ int readline ( IFILE *f, short *runs, int *pels )
        f->txtlines-- ;
       } 
       break ;
+#endif /* UCLINUX */
 
     case P_RAW:
     case P_PBM:
@@ -578,6 +604,7 @@ int readline ( IFILE *f, short *runs, int *pels )
       }
       break ;
 
+#ifndef UCLINUX
     case P_FAX:
       nr = readruns ( f, runs, pels ) ;
       break ;
@@ -591,6 +618,7 @@ int readline ( IFILE *f, short *runs, int *pels )
        if ( pels ) *pels = f->page->w ;
       }
       break ;
+#endif /* UCLINUX */
 
     }
   } else {
@@ -605,12 +633,13 @@ int readline ( IFILE *f, short *runs, int *pels )
 
 /* 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 ) ;
@@ -619,11 +648,13 @@ int getformat ( uchar *p, int 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 ) {
@@ -658,6 +689,7 @@ int getformat ( uchar *p, int n )
       format = I_TEXT ;
     }
   }
+#endif /* UCLINUX */
 
   return format ;
 }
@@ -665,7 +697,7 @@ int getformat ( uchar *p, int n )
 
 /* initialize page descriptor */
 
-void page_init ( PAGE *p, char *fn )
+static void page_init ( PAGE *p, char *fn )
 {
   p->fname = fn ;
   p->offset = 0 ;
@@ -678,7 +710,7 @@ void page_init ( PAGE *p, char *fn )
 }
 
 
-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, 
@@ -698,6 +730,7 @@ void page_report ( PAGE *p, int fmt, int n )
 
 /* Name of TIFF tag 'tag'. */
 
+#ifndef UCLINUX
 char *tagname ( int tag )
 {
   static struct tagnamestruct {  int code ;  char *name ; } 
@@ -758,12 +791,14 @@ int fread4 ( unsigned long *p, IFILE *f )
     
   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 ;
@@ -962,11 +997,12 @@ int text_first ( IFILE *f )
   
   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 ;
 
@@ -1000,6 +1036,7 @@ int pbm_first ( IFILE *f )
 
 /* get a 16-bit word in Intel byte order. */
 
+#ifndef UCLINUX
 int fgeti ( IFILE *f )
 {
   return fgetc ( f->f ) + fgetc ( f->f ) * 256 ;
@@ -1084,7 +1121,9 @@ int dcx_first ( IFILE *f )
 /* 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 )
 {
@@ -1109,6 +1148,7 @@ int fax_reset ( IFILE *f )
 
   return 0 ;
 }
+#endif /* UCLINUX */
 
 
 /* Skip to start of same (dp=0) or next (dp=1) page image.
@@ -1119,7 +1159,13 @@ int nextipage ( IFILE *f, int dp )
   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 */
@@ -1191,19 +1237,25 @@ int lastpage ( IFILE *f )
 
 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 ;
@@ -1274,6 +1326,7 @@ int newIFILE ( IFILE *f, char **fnames )
    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 */
@@ -2029,6 +2082,7 @@ int readfont ( char *fname, faxfont *font )
 
   return err ;
 }
+#endif /* UCLINUX */
 
 
 /* Initialize bit reversal lookup tables (note that the
@@ -2069,8 +2123,9 @@ void initbittab ( void )
 
 /* 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. */
 
@@ -2103,10 +2158,12 @@ void init1dtab ( t4tab *p0, dtab *t1, dtab *t2, dtab *ot )
               ( p - p0 ) > 63 ? t1 : ot ) ;
     }
 }
+#endif /* UCLINUX */
 
 
 /* Initialize a T.4 decoder.   */
 
+#ifndef UCLINUX
 void newDECODER ( DECODER *d )
 {
   int i ;
@@ -2147,13 +2204,14 @@ void newDECODER ( DECODER *d )
   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 */
 
@@ -2185,7 +2243,7 @@ t4tab wtab [ ( 64 + 27 + 13 ) + 1 ] = {   /* runs of white */
 
 {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 */
 
@@ -2222,6 +2280,7 @@ t4tab btab [ ( 64 + 27 + 13 ) + 1 ] = {   /* runs of black */
 /* 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,
@@ -2304,3 +2363,4 @@ uchar stdfont [ 1980 ] = {
 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 */
index 9c725ae..a159841 100644 (file)
--- a/efaxlib.h
+++ b/efaxlib.h
@@ -84,15 +84,23 @@ extern short short256 ;
 #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", \
@@ -199,15 +207,13 @@ int texttorun ( uchar *txt, faxfont *font, short line,
               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) ;
 
index 068f5f1..cacbeb1 100644 (file)
--- a/efaxmsg.c
+++ b/efaxmsg.c
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #include <ctype.h>             /* ANSI C */
 #include <errno.h>
 #include <stdio.h>
@@ -34,16 +36,14 @@ extern char *strerror( int i )
 
 /* 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 ;
 }
index d148bbb..f271adc 100644 (file)
--- a/efaxmsg.h
+++ b/efaxmsg.h
@@ -18,7 +18,6 @@ extern char *verb[] ;         /* types of messages to print */
 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 ;
index 6b346d6..9ac66bc 100644 (file)
--- a/efaxos.c
+++ b/efaxos.c
@@ -3,6 +3,8 @@
                    Copyright 1995, Ed Casas
 */
 
+#include "config.h"
+
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
@@ -144,6 +146,7 @@ int tundrflw ( TFILE *f, int t )
    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 ;
@@ -166,6 +169,7 @@ int tgetd ( TFILE *f, int t )
   
   return c ;
 }
+#endif /* UCLINUX */
 
 /* Write buffer to modem.  Returns 0 or EOF on error. */
 
@@ -190,13 +194,13 @@ int tput ( TFILE *f, uchar *p, int n )
 /* 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 ;
@@ -292,7 +296,7 @@ int ttymode ( TFILE *f, enum ttymodes mode )
    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 ;
@@ -344,7 +348,7 @@ int ttyopen ( TFILE *f, char *fname, int reverse, int hwfc )
    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 ;
@@ -355,8 +359,8 @@ int ttlocked ( char *fname, int log )
 
   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 {
@@ -371,7 +375,7 @@ int ttlocked ( char *fname, int log )
 
     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 
@@ -395,7 +399,7 @@ int ttlocked ( char *fname, int log )
    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 ;    
@@ -439,7 +443,7 @@ int ttlock ( char *fname, int log )
 
   if ( f ) { 
     fclose ( f ) ; 
-    if ( err ) remove ( buf ) ; 
+    if ( err ) unlink ( buf ) ; 
   }
 
   return err ;
@@ -449,7 +453,7 @@ int ttlock ( char *fname, int log )
 /* 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 ;
 
@@ -460,7 +464,7 @@ int ttunlock ( char *fname )
   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 ) ;
index 8696993..fc6f9bb 100644 (file)
--- a/efaxos.h
+++ b/efaxos.h
@@ -2,6 +2,7 @@
 #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 */
@@ -56,7 +53,6 @@ int tundrflw ( TFILE *f, int t ) ;
 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 ) ;
diff --git a/efix.c b/efix.c
index 57f96ff..618b762 100644 (file)
--- a/efix.c
+++ b/efix.c
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #define Copyright         "Copyright 1999 Ed Casas"
 
 #define Version                  "efix v 0.3"