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 */