X-Git-Url: http://git.jankratochvil.net/?a=blobdiff_plain;f=efaxlib.c;fp=efaxlib.c;h=23a74b2e197894dc6798d01402c301cbdf6353c6;hb=41bffa4095f9ead16643307f77645ac3a2db1ffe;hp=4887cd9e5d724e0b3275b62f92ea35deb9916266;hpb=9fa7a8f2e9a04a9d869d213fa612bd8b34c447d4;p=efax.git diff --git a/efaxlib.c b/efaxlib.c index 4887cd9..23a74b2 100644 --- a/efaxlib.c +++ b/efaxlib.c @@ -3,6 +3,8 @@ Copyright 1995 Ed Casas */ +#include "config.h" + #include #include #include @@ -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 */