home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netpbma.zip / pbmplus.h < prev    next >
C/C++ Source or Header  |  1997-04-12  |  9KB  |  280 lines

  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. #ifdef VMS
  20. #include <perror.h>
  21. #include <errno.h>
  22. #endif
  23.  
  24. #if defined(USG) || defined(SVR4) || defined(VMS)
  25. #define SYSV
  26. #endif
  27. #if ! ( defined(BSD) || defined(SYSV) || defined(MSDOS) || defined(AMIGA) )
  28. /* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
  29. ** System V site, set the SYSV option; if you're IBM-compatible, set MSDOS;
  30. ** and if you run on an Amiga, set AMIGA. If your compiler is ANSI C, you're
  31. ** probably better off setting SYSV - all it affects is string handling.
  32. */
  33. #define BSD
  34. /* #define SYSV */
  35. /* #define MSDOS */
  36. /* #define AMIGA */
  37. #endif
  38.  
  39. /* CONFIGURE: If you have an X11-style rgb color names file, define its
  40. ** path here.  This is used by PPM to parse color names into rgb values.
  41. ** If you don't have such a file, comment this out and use the alternative
  42. ** hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details).
  43. */
  44. #ifndef RGB_DB
  45. #define RGB_DB "/usr/lib/X11/rgb"
  46. /*#define RGB_DB "/usr/openwin/lib/rgb.txt"*/
  47. #ifdef VMS
  48. #define RGB_DB "PBMplus_Dir:RGB.TXT"
  49. #endif
  50. #endif
  51.  
  52. /* CONFIGURE: If you want to enable writing "raw" files, set this option.
  53. ** "Raw" files are smaller, and much faster to read and write, but you
  54. ** must have a filesystem that allows all 256 ASCII characters to be read
  55. ** and written.  You will no longer be able to mail P?M files without
  56. ** using uuencode or the equivalent, or running the files through pnmnoraw.
  57. ** Note that reading "raw" files works whether writing is enabled or not.
  58. */
  59. #define PBMPLUS_RAWBITS
  60.  
  61. /* CONFIGURE: PGM can store gray values as either bytes or shorts.  For most
  62. ** applications, bytes will be big enough, and the memory savings can be
  63. ** substantial.  However, if you need more than 8 bits of grayscale resolution,
  64. ** then define this symbol. Unless your computer is very slow or you are short
  65. ** of memory, there is no reason why you should not set this symbol.
  66. */
  67. #define PGM_BIGGRAYS
  68.  
  69. /* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
  70. ** If grays are stored in bytes, that's 24 bits per color pixel; if
  71. ** grays are stored as shorts, that's 48 bits per color pixel.  PPM
  72. ** can also be configured to pack the three grays into a single longword,
  73. ** 10 bits each, 30 bits per pixel.
  74. **
  75. ** If you have configured PGM with the PGM_BIGGRAYS option, AND you don't
  76. ** need more than 10 bits for each color component, AND you care more about
  77. ** memory use than speed, then this option might be a win.  Under these
  78. ** circumstances it will make some of the programs use 1.5 times less space,
  79. ** but all of the programs will run about 1.4 times slower.
  80. **
  81. ** If you are not using PGM_BIGGRAYS, then this option is useless -- it
  82. ** doesn't save any space, but it still slows things down.
  83. */
  84. /* #define PPM_PACKCOLORS */
  85.  
  86. /* CONFIGURE: uncomment this to enable debugging checks. */
  87. /* #define DEBUG */
  88.  
  89. #if ( defined(SYSV) || defined(AMIGA) )
  90.  
  91. #include <string.h>
  92. #define random rand
  93. #define srandom(s) srand(s)
  94. #ifndef __SASC
  95. #define index(s,c) strchr(s,c)
  96. #define rindex(s,c) strrchr(s,c)
  97. #ifndef _DCC    /* Amiga DICE Compiler */
  98. #define bzero(dst,len) memset(dst,0,len)
  99. #define bcopy(src,dst,len) memcpy(dst,src,len)
  100. #define bcmp memcmp
  101. extern void srand();
  102. extern int rand();
  103. #endif /* _DCC */
  104. #endif /* __SASC */
  105.  
  106. #else /* SYSV or AMIGA */
  107.  
  108. #include <strings.h>
  109. extern void srandom();
  110. extern long random();
  111.  
  112. #endif /*SYSV or AMIGA*/
  113.  
  114. #if (defined(MSDOS) || defined(AMIGA) || defined(__EMX__))
  115. #include <fcntl.h>
  116. #include <time.h>
  117. #include <stdlib.h>
  118. #else
  119. #ifndef VMS
  120. #include <unistd.h>
  121. #endif
  122. extern int atoi();
  123. extern void exit();
  124. extern long time();
  125. extern int write();
  126. #endif
  127.  
  128. /* CONFIGURE: On most BSD systems, malloc() gets declared in stdlib.h, on
  129. ** system V, it gets declared in malloc.h. On some systems, malloc.h
  130. ** doesn't declare these, so we have to do it here. On other systems,
  131. ** for example HP/UX, it declares them incompatibly.  And some systems,
  132. ** for example Dynix, don't have a malloc.h at all.  A sad situation.
  133. ** If you have compilation problems that point here, feel free to tweak
  134. ** or remove these declarations.
  135. */
  136. #ifdef BSD
  137. #include <stdlib.h>
  138. #endif
  139. #if (defined(SYSV) && !defined(VMS))
  140. #include <malloc.h>
  141. #endif
  142. /* extern char* malloc(); */
  143. /* extern char* realloc(); */
  144. /* extern char* calloc(); */
  145.  
  146. /* CONFIGURE: Some systems don't have vfprintf(), which we need for the
  147. ** error-reporting routines.  If you compile and get a link error about
  148. ** this routine, uncomment the first define, which gives you a vfprintf
  149. ** that uses the theoretically non-portable but fairly common routine
  150. ** _doprnt().  If you then get a link error about _doprnt, or
  151. ** message-printing doesn't look like it's working, try the second
  152. ** define instead.
  153. */
  154. /* #define NEED_VFPRINTF1 */
  155. /* #define NEED_VFPRINTF2 */
  156.  
  157. /* CONFIGURE: Some systems don't have strstr(), which some routines need.
  158. ** If you compile and get a link error about this routine, uncomment the
  159. ** define, which gives you a strstr.
  160. */
  161. /* #define NEED_STRSTR */
  162.  
  163. /* CONFIGURE: If you don't want a fixed path to an X11 color name file
  164. ** compiled into PBMPlus, set this option.  Now RGB_DB (see Makefile)
  165. ** defines the name of an environment-variable that holds the complete
  166. ** path and name of this file.
  167. */
  168. /* #define A_RGBENV */
  169. #ifdef A_RGBENV
  170. #define RGB_DB "RGBDEF"    /* name of env-var */
  171. #endif /* A_RGBENV */
  172.  
  173. /* CONFIGURE: Set this option if your compiler uses strerror(errno)
  174. ** instead of sys_errlist[errno] for error messages.
  175. */
  176. /* #define A_STRERROR */
  177.  
  178. /* CONFIGURE: On small systems without VM it is possible that there is
  179. ** enough memory for a large array, but it is fragmented.  So the usual
  180. ** malloc( all-in-one-big-chunk ) fails.  With this option, if the first
  181. ** method fails, pm_allocarray() tries to allocate the array row by row.
  182. */
  183. /* #define A_FRAGARRAY */
  184.  
  185. /*
  186. ** Some special things for the Amiga.
  187. */
  188.  
  189. /* End of configurable definitions. */
  190.  
  191.  
  192. #ifdef AMIGA
  193. #include <clib/exec_protos.h>
  194. #define getpid(x)   ((long)FindTask(NULL))
  195. #endif /* AMIGA */
  196.  
  197.  
  198. #undef max
  199. #define max(a,b) ((a) > (b) ? (a) : (b))
  200. #undef min
  201. #define min(a,b) ((a) < (b) ? (a) : (b))
  202. #undef abs
  203. #define abs(a) ((a) >= 0 ? (a) : -(a))
  204. #undef odd
  205. #define odd(n) ((n) & 1)
  206.  
  207.  
  208. /* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
  209.  
  210. #if __STDC__
  211. #define ARGS(alist) alist
  212. #else /*__STDC__*/
  213. #define ARGS(alist) ()
  214. #define const
  215. #endif /*__STDC__*/
  216.  
  217.  
  218. /* Initialization. */
  219.  
  220. void pm_init ARGS(( int* argcP, char* argv[] ));
  221.  
  222. /* Variable-sized arrays definitions. */
  223.  
  224. char** pm_allocarray ARGS(( int cols, int rows, int size ));
  225. char* pm_allocrow ARGS(( int cols, int size ));
  226. void pm_freearray ARGS(( char** its, int rows ));
  227. void pm_freerow ARGS(( char* itrow ));
  228.  
  229.  
  230. /* Case-insensitive keyword matcher. */
  231.  
  232. int pm_keymatch ARGS(( char* str, char* keyword, int minchars ));
  233.  
  234.  
  235. /* Log base two hacks. */
  236.  
  237. int pm_maxvaltobits ARGS(( int maxval ));
  238. int pm_bitstomaxval ARGS(( int bits ));
  239.  
  240.  
  241. /* Error handling definitions. */
  242.  
  243. void pm_message ARGS(( char*, ... ));
  244. void pm_error ARGS(( char*, ... ));                     /* doesn't return */
  245. void pm_perror ARGS(( char* reason ));                  /* doesn't return */
  246. void pm_usage ARGS(( char* usage ));                    /* doesn't return */
  247.  
  248.  
  249. /* File open/close that handles "-" as stdin and checks errors. */
  250.  
  251. FILE* pm_openr ARGS(( char* name ));
  252. FILE* pm_openw ARGS(( char* name ));
  253. void pm_close ARGS(( FILE* f ));
  254.  
  255.  
  256. /* Endian I/O. */
  257.  
  258. int pm_readbigshort ARGS(( FILE* in, short* sP ));
  259. int pm_writebigshort ARGS(( FILE* out, short s ));
  260. int pm_readbiglong ARGS(( FILE* in, long* lP ));
  261. int pm_writebiglong ARGS(( FILE* out, long l ));
  262. int pm_readlittleshort ARGS(( FILE* in, short* sP ));
  263. int pm_writelittleshort ARGS(( FILE* out, short s ));
  264. int pm_readlittlelong ARGS(( FILE* in, long* lP ));
  265. int pm_writelittlelong ARGS(( FILE* out, long l ));
  266.  
  267.  
  268. /* Compatibility stuff */
  269.  
  270. #ifdef NEED_STRSTR
  271. char *strstr ARGS((char *s1, char *s2));
  272. #endif
  273.  
  274. #if defined(NEED_VFPRINTF1) || defined(NEED_VFPRINTF2)
  275. int vfprintf ARGS(( FILE* stream, char* format, va_list args ));
  276. #endif /*NEED_VFPRINTF*/
  277.  
  278.  
  279. #endif /*_PBMPLUS_H_*/
  280.