w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

pbmplus.h
Go to the documentation of this file.
1 /* pbmplus.h - header file for PBM, PGM, PPM, and PNM
2 **
3 ** Copyright (C) 1988, 1989, 1991 by Jef Poskanzer.
4 **
5 ** Permission to use, copy, modify, and distribute this software and its
6 ** documentation for any purpose and without fee is hereby granted, provided
7 ** that the above copyright notice appear in all copies and that both that
8 ** copyright notice and this permission notice appear in supporting
9 ** documentation. This software is provided "as is" without express or
10 ** implied warranty.
11 */
12 
13 #ifndef _PBMPLUS_H_
14 #define _PBMPLUS_H_
15 
16 #include <sys/types.h>
17 #include <ctype.h>
18 #include <stdio.h>
19 
20 #ifdef VMS
21 #include <perror.h>
22 #include <errno.h>
23 #else
24 #ifdef __osf__
25 #include <errno.h>
26 #endif
27 #endif
28 
29 #if defined(USG) || defined(SVR4) || defined(VMS) || defined(__SVR4)
30 #define SYSV
31 #endif
32 #if ! ( defined(BSD) || defined(SYSV) || defined(MSDOS) || defined(AMIGA) )
33 /* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
34 ** System V site, set the SYSV option; if you're IBM-compatible, set MSDOS;
35 ** and if you run on an Amiga, set AMIGA. If your compiler is ANSI C, you're
36 ** probably better off setting SYSV - all it affects is string handling.
37 */
38 #define BSD
39 /* #define SYSV */
40 /* #define MSDOS */
41 /* #define AMIGA */
42 #endif
43 
44 /* CONFIGURE: If you have an X11-style rgb color names file, define its
45 ** path here. This is used by PPM to parse color names into rgb values.
46 ** If you don't have such a file, comment this out and use the alternative
47 ** hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details).
48 */
49 /* There was some evidence before Netpbm 9.1 that the rgb database macros
50  might be already set right now. I couldn't figure out how, so I changed
51  their meanings and they are now set unconditionally. -Bryan 00.05.03.
52 */
53 #ifdef VMS
54 #define RGB_DB1 "PBMplus_Dir:RGB.TXT"
55 #define RGB_DB2 "PBMplus_Dir:RGB.TXT"
56 #else
57 #define RGB_DB1 "/usr/lib/X11/rgb.txt"
58 #define RGB_DB2 "/usr/openwin/lib/rgb.txt"
59 #endif
60 
61 /* CONFIGURE: This is the name of an environment variable that tells
62 ** where the color names database is. If the environment variable isn't
63 ** set, Netpbm tries the hardcoded defaults set above.
64 */
65 #define RGBENV "RGBDEF" /* name of env-var */
66 
67 /* CONFIGURE: If you want to enable writing "raw" files, set this option.
68 ** "Raw" files are smaller, and much faster to read and write, but you
69 ** must have a filesystem that allows all 256 ASCII characters to be read
70 ** and written. You will no longer be able to mail P?M files without
71 ** using uuencode or the equivalent, or running the files through pnmnoraw.
72 ** Note that reading "raw" files works whether writing is enabled or not.
73 */
74 #define PBMPLUS_RAWBITS
75 
76 /* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
77 ** If grays are stored in bytes, that's 24 bits per color pixel; if
78 ** grays are stored as shorts, that's 48 bits per color pixel. PPM
79 ** can also be configured to pack the three grays into a single longword,
80 ** 10 bits each, 30 bits per pixel.
81 **
82 ** If you don't
83 ** need more than 10 bits for each color component, AND you care more about
84 ** memory use than speed, then this option might be a win. Under these
85 ** circumstances it will make some of the programs use 1.5 times less space,
86 ** but all of the programs will run about 1.4 times slower.
87 **
88 */
89 /* #define PPM_PACKCOLORS */
90 
91 /* CONFIGURE: uncomment this to enable debugging checks. */
92 /* #define DEBUG */
93 
94 #if ( defined(SYSV) || defined(AMIGA) )
95 
96 #include <string.h>
97 /* Before Netpbm 9.1, rand and srand were macros for random and
98  srandom here. This caused a failure on a SunOS 5.6 system, which
99  is SYSV, but has both rand and random declared (with different
100  return types). The macro caused the prototype for random to be a
101  second prototype for rand. Before 9.1, Netpbm programs called
102  random() and on a SVID system, that was really a call to rand().
103  We assume all modern systems have rand() itself, so now Netpbm
104  always calls rand() and if we find a platform that doesn't have
105  rand(), we will add something here for that platform. -Bryan 00.04.26
106 #define random rand
107 #define srandom(s) srand(s)
108 extern void srand();
109 extern int rand();
110 */
111 #ifndef __SASC
112 #define index(s,c) strchr(s,c)
113 #define rindex(s,c) strrchr(s,c)
114 #ifndef _DCC /* Amiga DICE Compiler */
115 #define bzero(dst,len) memset(dst,0,len)
116 #define bcopy(src,dst,len) memcpy(dst,src,len)
117 #define bcmp memcmp
118 #endif /* _DCC */
119 #endif /* __SASC */
120 
121 #endif /*SYSV or AMIGA*/
122 
123 #include <fcntl.h>
124 #include <time.h>
125 #include <stdlib.h>
126 #include <unistd.h>
127 /*
128  Before Netpbm 9.0, atoi() and exit() were declared for everybody
129  except MSDOS and AMIGA, and time() and write() were declared for
130  everybody except MSDOS, AMIGA, and __osf__. fcntl.h, time.h, and
131  stlib.h were included for MSDOS and AMIGA, and unistd.h was included
132  for everyone except VMS, MSDOS, and AMIGA. With the netbsd patches,
133  atoi(), exit(), time(), and write() were not declared for __NetBSD__.
134 
135  We're hoping that all current systems have the standard header
136  files, and will reinstate some of these explicit declarations if we
137  hear otherwise.
138 
139  If it turns out to be this easy, we should just move these inclusions
140  to the source files that actually need them.
141 
142  -Bryan 2000.04.13
143 
144 extern int atoi();
145 extern void exit();
146 extern long time();
147 extern int write();
148 */
149 
150 /* CONFIGURE: On most BSD systems, malloc() gets declared in stdlib.h, on
151 ** system V, it gets declared in malloc.h. On some systems, malloc.h
152 ** doesn't declare these, so we have to do it here. On other systems,
153 ** for example HP/UX, it declares them incompatibly. And some systems,
154 ** for example Dynix, don't have a malloc.h at all. A sad situation.
155 ** If you have compilation problems that point here, feel free to tweak
156 ** or remove these declarations.
157 */
158 #ifdef BSD
159 #include <stdlib.h>
160 #endif
161 #if (defined(SYSV) && !defined(VMS))
162 #include <malloc.h>
163 #endif
164 /* extern char* malloc(); */
165 /* extern char* realloc(); */
166 /* extern char* calloc(); */
167 
168 /* CONFIGURE: Some systems don't have vfprintf(), which we need for the
169 ** error-reporting routines. If you compile and get a link error about
170 ** this routine, uncomment the first define, which gives you a vfprintf
171 ** that uses the theoretically non-portable but fairly common routine
172 ** _doprnt(). If you then get a link error about _doprnt, or
173 ** message-printing doesn't look like it's working, try the second
174 ** define instead.
175 */
176 /* #define NEED_VFPRINTF1 */
177 /* #define NEED_VFPRINTF2 */
178 
179 /* CONFIGURE: Some systems don't have strstr(), which some routines need.
180 ** If you compile and get a link error about this routine, uncomment the
181 ** define, which gives you a strstr.
182 */
183 /* #define NEED_STRSTR */
184 
185 /* CONFIGURE: Set this option if your compiler uses strerror(errno)
186 ** instead of sys_errlist[errno] for error messages.
187 */
188 #define A_STRERROR
189 
190 /* CONFIGURE: On small systems without VM it is possible that there is
191 ** enough memory for a large array, but it is fragmented. So the usual
192 ** malloc( all-in-one-big-chunk ) fails. With this option, if the first
193 ** method fails, pm_allocarray() tries to allocate the array row by row.
194 */
195 /* #define A_FRAGARRAY */
196 
197 /* CONFIGURE: If your system has the setmode() function, set HAVE_SETMODE.
198 ** If you do, and also the O_BINARY file mode, pm_init() will set the mode
199 ** of stdin and stdout to binary for all Netpbm programs.
200 */
201 /* #define HAVE_SETMODE */
202 
203 /*
204 ** Some special things for the Amiga.
205 */
206 
207 /* End of configurable definitions. */
208 
209 #ifndef TRUE
210 #define TRUE 1
211 #define FALSE 0
212 #endif
213 
214 #ifdef AMIGA
215 #include <clib/exec_protos.h>
216 #define getpid(x) ((long)FindTask(NULL))
217 #endif /* AMIGA */
218 
219 
220 #undef max
221 #define max(a,b) ((a) > (b) ? (a) : (b))
222 #undef min
223 #define min(a,b) ((a) < (b) ? (a) : (b))
224 #undef abs
225 #define abs(a) ((a) >= 0 ? (a) : -(a))
226 #undef odd
227 #define odd(n) ((n) & 1)
228 
229 
230 /* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
231 
232 #if __STDC__
233 #define ARGS(alist) alist
234 #else /*__STDC__*/
235 #define ARGS(alist) ()
236 #define const
237 #endif /*__STDC__*/
238 
239 
240 /* Initialization. */
241 
242 void pm_init ARGS(( int* argcP, char* argv[] ));
243 
244 /* Variable-sized arrays definitions. */
245 
246 char** pm_allocarray ARGS(( int cols, int rows, int size ));
247 char* pm_allocrow ARGS(( int cols, int size ));
248 void pm_freearray ARGS(( char** its, int rows ));
249 void pm_freerow ARGS(( char* itrow ));
250 
251 
252 /* Case-insensitive keyword matcher. */
253 
254 int pm_keymatch ARGS(( char* str, char* keyword, int minchars ));
255 
256 
257 /* Log base two hacks. */
258 
260 int pm_bitstomaxval ARGS(( int bits ));
261 
262 
263 /* Error handling definitions. */
264 
265 void pm_message ARGS(( char*, ... ));
266 void pm_error ARGS(( char*, ... )); /* doesn't return */
267 void pm_perror ARGS(( char* reason )); /* doesn't return */
268 void pm_usage ARGS(( char* usage )); /* doesn't return */
269 
270 
271 /* File open/close that handles "-" as stdin and checks errors. */
272 
273 FILE* pm_openr ARGS(( char* name ));
274 FILE* pm_openw ARGS(( char* name ));
275 void pm_close ARGS(( FILE* f ));
276 
277 
278 /* Endian I/O. */
279 
280 int pm_readbigshort ARGS(( FILE* in, short* sP ));
281 int pm_writebigshort ARGS(( FILE* out, short s ));
282 int pm_readbiglong ARGS(( FILE* in, long* lP ));
283 int pm_writebiglong ARGS(( FILE* out, long l ));
284 int pm_readlittleshort ARGS(( FILE* in, short* sP ));
285 int pm_writelittleshort ARGS(( FILE* out, short s ));
286 int pm_readlittlelong ARGS(( FILE* in, long* lP ));
287 int pm_writelittlelong ARGS(( FILE* out, long l ));
288 
289 /* By making this <> instead of "", we avoid making shhopt.h a dependency
290  of every program in the package when we do make dep.
291 */
292 #include <shhopt.h>
293 
294 void pm_optParseOptions(int *argc, char *argv[],
295  optStruct opt[], int allowNegNum);
296 /* Use pm_optParseOptions instead of optParseOptions in order to use the
297  shared Netpbm libraries
298 */
299 
300 /* You can use OPTENTRY to assign a value to a dynamically or automatically
301  allocated optStruct structure with minimal typing and easy readability.
302 
303  Here is an example:
304 
305  unsigned int option_def_index = 0;
306  optStruct *option_def = malloc(100*sizeof(optStruct));
307  OPTENTRY('h', "help", OPT_FLAG, &help_flag, 0);
308  OPTENTRY(0, "alphaout", OPT_STRING, &alpha_filename, 0);
309 */
310 
311 #define OPTENTRY(shortvalue,longvalue,typevalue,outputvalue,flagvalue) {\
312  option_def[option_def_index].shortName = (shortvalue); \
313  option_def[option_def_index].longName = (longvalue); \
314  option_def[option_def_index].type = (typevalue); \
315  option_def[option_def_index].arg = (outputvalue); \
316  option_def[option_def_index].flags = (flagvalue); \
317  option_def[++option_def_index].type = OPT_END; \
318  }
319 
320 /* Compatibility stuff */
321 
322 #ifdef NEED_STRSTR
323 char *strstr ARGS((char *s1, char *s2));
324 #endif
325 
326 #if defined(NEED_VFPRINTF1) || defined(NEED_VFPRINTF2)
327 int vfprintf ARGS(( FILE* stream, char* format, va_list args ));
328 #endif /*NEED_VFPRINTF*/
329 
330 #endif /*_PBMPLUS_H_*/
#define name
static gray maxval
Definition: asciitopgm.c:38
mpz_t * f
Definition: gen-fib.c:34
#define s
Definition: afcover.h:80
static char usage[]
Definition: giftopnm.c:59
FILE * out
Definition: hbf2gf.c:286
char * strstr()
static int rows
Definition: pbmclean.c:15
static int format
Definition: pbmclean.c:15
static int cols
Definition: pbmmask.c:21
int pm_maxvaltobits()
void pm_close()
void pm_freerow()
int pm_readlittlelong()
int pm_writelittlelong()
void pm_init()
char ** pm_allocarray()
int pm_writelittleshort()
void pm_freearray()
int pm_writebiglong()
int pm_bitstomaxval()
int pm_readbigshort()
void pm_optParseOptions(int *argc, char *argv[], optStruct opt[], int allowNegNum)
Definition: libpbm1.c:149
int pm_keymatch()
void pm_error()
#define ARGS(alist)
Definition: pbmplus.h:235
FILE * pm_openw()
char * pm_allocrow()
void pm_usage()
int pm_writebigshort()
FILE * pm_openr()
void pm_message()
int pm_readbiglong()
int pm_readlittleshort()
void pm_perror()
static char reason[256]
Definition: pdfsig.cc:141
static int size
Definition: ppmlabel.c:24
struct stream_s stream
Definition: pts_fax.h:93
#define str(s)
Definition: sh6.c:399
static FILE * in
Definition: squeeze.c:36
Definition: usprintf.c:39
Definition: namelist.c:170
def_key keyword[6]
Definition: t1part.c:256
#define FILE
Definition: t1stdio.h:34
s1
Definition: t4ht.c:1059
char * s2
Definition: t4ht.c:1062
char * va_list
Definition: varargs.h:22
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269