home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsm / netpbmsca / h / pbmplus < prev    next >
Encoding:
Text File  |  1994-02-21  |  8.4 KB  |  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. #define RGB_DB "/usr/lib/X11/rgb"
  45. */
  46. /*#define RGB_DB "/usr/openwin/lib/rgb.txt"*/
  47. #ifdef VMS
  48. #define RGB_DB "PBMplus_Dir:RGB.TXT"
  49. #endif
  50.  
  51. /* CONFIGURE: If you want to enable writing "raw" files, set this option.
  52. ** "Raw" files are smaller, and much faster to read and write, but you
  53. ** must have a filesystem that allows all 256 ASCII characters to be read
  54. ** and written.  You will no longer be able to mail P?M files without 
  55. ** using uuencode or the equivalent, or running the files through pnmnoraw.
  56. ** Note that reading "raw" files works whether writing is enabled or not.
  57. */
  58. #define PBMPLUS_RAWBITS
  59.  
  60. /* CONFIGURE: PGM can store gray values as either bytes or shorts.  For most
  61. ** applications, bytes will be big enough, and the memory savings can be
  62. ** substantial.  However, if you need more than 8 bits of grayscale resolution,
  63. ** then define this symbol. Unless your computer is very slow or you are short
  64. ** of memory, there is no reason why you should not set this symbol.
  65. */
  66. #define PGM_BIGGRAYS
  67.  
  68. /* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
  69. ** If grays are stored in bytes, that's 24 bits per color pixel; if
  70. ** grays are stored as shorts, that's 48 bits per color pixel.  PPM
  71. ** can also be configured to pack the three grays into a single longword,
  72. ** 10 bits each, 30 bits per pixel.
  73. **
  74. ** If you have configured PGM with the PGM_BIGGRAYS option, AND you don't
  75. ** need more than 10 bits for each color component, AND you care more about
  76. ** memory use than speed, then this option might be a win.  Under these
  77. ** circumstances it will make some of the programs use 1.5 times less space,
  78. ** but all of the programs will run about 1.4 times slower.
  79. **
  80. ** If you are not using PGM_BIGGRAYS, then this option is useless -- it
  81. ** doesn't save any space, but it still slows things down.
  82. */
  83. /* #define PPM_PACKCOLORS */
  84.  
  85. /* CONFIGURE: uncomment this to enable debugging checks. */
  86. /* #define DEBUG */
  87.  
  88.  
  89. #ifdef __STDC__
  90. #include <string.h>
  91. #else
  92. #if ( defined(SYSV) || defined(AMIGA))
  93.  
  94. #include <string.h>
  95. #define index(s,c) strchr(s,c)
  96. #define rindex(s,c) strrchr(s,c)
  97. #define srandom(s) srand(s)
  98. #define random rand
  99. #ifndef _DCC    /* Amiga DICE Compiler */
  100. #define bzero(dst,len) memset(dst,0,len)
  101. #define bcopy(src,dst,len) memcpy(dst,src,len)
  102. #define bcmp memcmp
  103. extern void srand();
  104. extern int rand();
  105. #endif /* _DCC */
  106.  
  107. #else /* SYSV or AMIGA */
  108.  
  109. #include <strings.h>
  110. extern void srandom();
  111. extern long random();
  112.  
  113. #endif /*SYSV or AMIGA*/
  114. #endif
  115.  
  116. #ifdef AMIGA
  117. #include <fcntl.h>
  118. #include <time.h>
  119. #include <stdlib.h>
  120. #else
  121. extern int atoi();
  122. extern void exit();
  123. extern long time();
  124. extern int write();
  125. #endif
  126.  
  127. /* CONFIGURE: On most BSD systems, malloc() gets declared in stdlib.h, on
  128. ** system V, it gets declared in malloc.h. On some systems, malloc.h
  129. ** doesn't declare these, so we have to do it here. On other systems,
  130. ** for example HP/UX, it declares them incompatibly.  And some systems,
  131. ** for example Dynix, don't have a malloc.h at all.  A sad situation.
  132. ** If you have compilation problems that point here, feel free to tweak
  133. ** or remove these declarations.
  134. */
  135. #ifdef BSD
  136. #include <stdlib.h>
  137. #endif
  138. #if (defined(SYSV) && !defined(VMS))
  139. #include <malloc.h>
  140. #endif
  141. /* extern char* malloc(); */
  142. /* extern char* realloc(); */
  143. /* extern char* calloc(); */
  144.  
  145. /* CONFIGURE: Some systems don't have vfprintf(), which we need for the
  146. ** error-reporting routines.  If you compile and get a link error about
  147. ** this routine, uncomment the first define, which gives you a vfprintf
  148. ** that uses the theoretically non-portable but fairly common routine
  149. ** _doprnt().  If you then get a link error about _doprnt, or
  150. ** message-printing doesn't look like it's working, try the second
  151. ** define instead.
  152. */
  153. /* #define NEED_VFPRINTF1 */
  154. /* #define NEED_VFPRINTF2 */
  155.  
  156. /* CONFIGURE: Some systems don't have strstr(), which some routines need.
  157. ** If you compile and get a link error about this routine, uncomment the
  158. ** define, which gives you a strstr.
  159. */
  160. /* #define NEED_STRSTR */
  161.  
  162. /* CONFIGURE: If you don't want a fixed path to an X11 color name file
  163. ** compiled into PBMPlus, set this option.  Now RGB_DB (see Makefile)
  164. ** defines the name of an environment-variable that holds the complete
  165. ** path and name of this file.
  166. */
  167. /* #define A_RGBENV */
  168.  
  169. /* CONFIGURE: Set this option if your compiler uses strerror(errno)
  170. ** instead of sys_errlist[errno] for error messages.
  171. */
  172. /* #define A_STRERROR */
  173.  
  174. /* CONFIGURE: On small systems without VM it is possible that there is
  175. ** enough memory for a large array, but it is fragmented.  So the usual
  176. ** malloc( all-in-one-big-chunk ) fails.  With this option, if the first
  177. ** method fails, pm_allocarray() tries to allocate the array row by row.
  178. */
  179. /* #define A_FRAGARRAY */
  180.  
  181. /*
  182. ** Some special things for the Amiga.
  183. */
  184.  
  185. /* End of configurable definitions. */
  186.  
  187.  
  188. #ifdef AMIGA
  189. #include <clib/exec_protos.h>
  190. #define getpid(x)   ((long)FindTask(NULL))
  191. #ifdef _DCC /* Amiga DICE Compiler, dynamic stack variables */
  192. long _stack_fudge = 16384;
  193. long _stack_chunk = 32768;
  194. #endif /* _DCC */
  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.