home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / fontutils-0.6-base.tgz / fontutils-0.6-base.tar / fsf / fontutils / include / pbmplus.h < prev    next >
C/C++ Source or Header  |  1992-09-15  |  6KB  |  198 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.    Configuration options modified for GNU --karl.
  13. */
  14.  
  15. #ifndef _PBMPLUS_H_
  16. #define _PBMPLUS_H_
  17.  
  18. #include <sys/types.h>
  19. #include <ctype.h>
  20. #include <stdio.h>
  21.  
  22. #include "config.h"
  23.  
  24.  
  25. #if 0 /* karl */
  26. #if ! ( defined(BSD) || defined(SYSV) || defined(MSDOS))
  27. /* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
  28. ** System V site, set the SYSV option; and if you're IBM-compatible, set
  29. ** MSDOS.  If your compiler is ANSI C, you're probably better off setting
  30. ** SYSV.
  31. */
  32. #define BSD
  33. /* #define SYSV */
  34. /* #define MSDOS */
  35. #endif
  36. #endif
  37.  
  38. /* CONFIGURE: If you want to enable writing "raw" files, set this option.
  39. ** "Raw" files are smaller, and much faster to read and write, but you
  40. ** must have a filesystem that allows all 256 ASCII characters to be read
  41. ** and written.  You will no longer be able to mail P?M files without 
  42. ** using uuencode or the equivalent, or running the files through pnmnoraw.
  43. ** Note that reading "raw" files works whether writing is enabled or not.
  44. */
  45. #define PBMPLUS_RAWBITS
  46.  
  47. /* CONFIGURE: On some systems, the putc() macro is broken and will return
  48. ** EOF when you write out a 255.  For example, ULTRIX does this.  This
  49. ** only matters if you have defined RAWBITS.  To test whether your system
  50. ** is broken this way, go ahead and compile things with RAWBITS defined,
  51. ** and then try "pbmmake -b 8 1 > file".  If it works, fine.  If not,
  52. ** define BROKENPUTC1 and try again - if that works, good.  Otherwise,
  53. ** BROKENPUTC2 is guaranteed to work, although it's about twice as slow.
  54. */
  55. /* #define PBMPLUS_BROKENPUTC1 */
  56. /* #define PBMPLUS_BROKENPUTC2 */
  57.  
  58. #ifdef PBMPLUS_BROKENPUTC1
  59. #undef putc
  60. /* This is a fixed version of putc() that should work on most Unix systems. */
  61. #define putc(x,p) (--(p)->_cnt>=0? ((int)(unsigned char)(*(p)->_ptr++=(unsigned char)(x))) : _flsbuf((unsigned char)(x),p))
  62. #endif /*PBMPLUS_BROKENPUTC1*/
  63. #ifdef PBMPLUS_BROKENPUTC2
  64. #undef putc
  65. /* For this one, putc() becomes a function, defined in pbm/libpbm1.c. */
  66. #endif /*PBMPLUS_BROKENPUTC2*/
  67.  
  68. /* CONFIGURE: PGM can store gray values as either bytes or shorts.  For most
  69. ** applications, bytes will be big enough, and the memory savings can be
  70. ** substantial.  However, if you need more than 8 bits of resolution, then
  71. ** define this symbol.
  72. **
  73. ** If you are not making PGM, you can ignore this.
  74. */
  75. /* #define PGM_BIGGRAYS */
  76.  
  77. /* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
  78. ** It can also be configured to pack the three values into a single longword,
  79. ** 10 bits each.  If you have configured PGM with the PGM_BIGGRAYS option
  80. ** (store grays as shorts), AND you don't need more than 10 bits for each
  81. ** color component, AND you care more about memory use than speed, then
  82. ** this option might be a win.  Under these circumstances it will make
  83. ** some of the programs use 1.5 times less space,  but all of the programs
  84. ** will run about 1.4 times slower.
  85. **
  86. ** If you are not using PGM_BIGGRAYS, then this option is useless -- it
  87. ** doesn't save any space, but it still slows things down.
  88. **
  89. ** If you are not making PPM, you can ignore this.
  90. */
  91. /* #define PPM_PACKCOLORS */
  92.  
  93. /* CONFIGURE: uncomment this to enable debugging checks. */
  94. /* #define DEBUG */
  95.  
  96. #if 0 /* karl */
  97. #ifdef SYSV
  98. #include <string.h>
  99. #define index strchr
  100. #define rindex strrchr
  101. #define srandom srand
  102. #define random rand
  103. #define bzero(dst,len) memset(dst, 0, len)
  104. #define bcopy(src,dst,len) memcpy(dst, src, len)
  105. #define bcmp memcmp
  106. #else /*SYSV*/
  107. #include <strings.h>
  108. #endif /*SYSV*/
  109. #endif /* 0 */
  110.  
  111. /* CONFIGURE: On some systems, malloc.h doesn't declare these, so we have
  112. ** to do it.  On other systems, for example HP/UX, it declares them
  113. ** incompatibly.  And some systems, for example Dynix, don't have a
  114. ** malloc.h at all.  A sad situation.  If you have compilation problems
  115. ** that point here, feel free to tweak or remove these declarations.
  116. */
  117. /* Thank you, I did remove them:
  118. #include <malloc.h>
  119. extern char* malloc();
  120. extern char* realloc();
  121. extern char* calloc();
  122. */
  123. /* End of configurable definitions. */
  124.  
  125.  
  126. #undef max
  127. #define max(a,b) ((a) > (b) ? (a) : (b))
  128. #undef min
  129. #define min(a,b) ((a) < (b) ? (a) : (b))
  130. #undef abs
  131. #define abs(a) ((a) >= 0 ? (a) : -(a))
  132. #undef odd
  133. #define odd(n) ((n) & 1)
  134.  
  135.  
  136. /* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
  137.  
  138. #if __STDC__
  139. #define ARGS(alist) alist
  140. #else /*__STDC__*/
  141. #define ARGS(alist) ()
  142. #define const
  143. #endif /*__STDC__*/
  144.  
  145.  
  146. /* Initialization. */
  147.  
  148. void pm_init ARGS(( int* argcP, char* argv[] ));
  149.  
  150.  
  151. /* Variable-sized arrays definitions. */
  152.  
  153. char** pm_allocarray ARGS(( int cols, int rows, int size ));
  154. char* pm_allocrow ARGS(( int cols, int size ));
  155. void pm_freearray ARGS(( char** its, int rows ));
  156. void pm_freerow ARGS(( char* itrow ));
  157.  
  158.  
  159. /* Case-insensitive keyword matcher. */
  160.  
  161. int pm_keymatch ARGS(( char* str, char* keyword, int minchars ));
  162.  
  163.  
  164. /* Log base two hacks. */
  165.  
  166. int pm_maxvaltobits ARGS(( int maxval ));
  167. int pm_bitstomaxval ARGS(( int bits ));
  168.  
  169.  
  170. /* Error handling definitions. */
  171.  
  172. void pm_message( /* char* fmt, char* v1, char* v2, char* v3, char* v4, char* v5 */ );    /* prototypes can't handle this */
  173. void pm_error( /* char* fmt, char* v1, char* v2, char* v3, char* v4, char* v5 */ );    /* doesn't return */
  174. void pm_perror ARGS(( char* reason ));            /* doesn't return */
  175. void pm_usage ARGS(( char* usage ));            /* doesn't return */
  176.  
  177.  
  178. /* File open/close that handles "-" as stdin and checks errors. */
  179.  
  180. FILE* pm_openr ARGS(( char* name ));
  181. FILE* pm_openw ARGS(( char* name ));
  182. void pm_close ARGS(( FILE* f ));
  183.  
  184.  
  185. /* Endian I/O. */
  186.  
  187. int pm_readbigshort ARGS(( FILE* in, short* sP ));
  188. int pm_writebigshort ARGS(( FILE* out, short s ));
  189. int pm_readbiglong ARGS(( FILE* in, long* lP ));
  190. int pm_writebiglong ARGS(( FILE* out, long l ));
  191. int pm_readlittleshort ARGS(( FILE* in, short* sP ));
  192. int pm_writelittleshort ARGS(( FILE* out, short s ));
  193. int pm_readlittlelong ARGS(( FILE* in, long* lP ));
  194. int pm_writelittlelong ARGS(( FILE* out, long l ));
  195.  
  196.  
  197. #endif /*_PBMPLUS_H_*/
  198.