home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / PSCRIPT / PSFIX.ZIP / MYDEFS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-01  |  5.6 KB  |  218 lines

  1. /*
  2.  *
  3.  * miscellaneous definitions
  4.  *
  5.  */
  6.  
  7. /*
  8.  * This software is property of the U.S. Government and may be freely
  9.  * distributed under the following conditions:
  10.  *         1. It is distributed in its current form, without alterations.
  11.  *         2. No monetary profit is made, under any circumstances.
  12.  *
  13.  *             Marc A. Murison
  14.  *             Smithsonian Astrophysical Observatory
  15.  *             60 Garden Street, MS 63
  16.  *             Cambridge, MA  02138
  17.  *
  18.  *             (617) 495-7079      murison@cfacx2.harvard.edu
  19.  */
  20.  
  21.  
  22. #ifndef  MYDEFS_H
  23. #define  MYDEFS_H
  24.  
  25. /* constants */
  26. #define  PI            3.14159265358979323846264
  27. #define  TWOPI        6.28318530717958647692528
  28. #define  PI2           1.57079632679489661923132
  29. #define  PI4          PI / 4.0
  30.  
  31.  
  32. /* enums */
  33. typedef  enum  { BINARY_RADIX=2,   OCTAL_RADIX=8, 
  34.                  DECIMAL_RADIX=10, HEX_RADIX=16   } Radix;
  35. typedef  enum  { FALSE=0, TRUE=1, OFF=0, ON=1, NO=0, YES=1 } Boolean;
  36.  
  37.  
  38. /* characters */
  39. #define  BELL        '\a'
  40. #define  BEEP        '\a'
  41. #define  BLANK      ' '
  42. #define  SPACE        ' '
  43. #define  ESCAPE        '\x1b'
  44. #define  CR         '\r'
  45. #define  LF            '\x0a'
  46. #define  FORMFEED    '\x0c'
  47. #define  NEWLINE    '\n'
  48. #define  TAB        '\t'
  49. #define  BACKSPACE    '\b'
  50. #define  DOT        '.'
  51. #define  PERIOD        '.'
  52. #define  PLUS        '+'
  53. #define  MINUS        '-'
  54. #define  HYPHEN        '-'
  55. #define  ASTERISK    '*'
  56. #define  STAR       '*'
  57. #define  SQUOTE        '\''
  58. #define  DQUOTE        '\"'
  59. #define  SLASH        '/'
  60. #define  BSLASH        '\\'
  61.      
  62.  
  63. /* type definitions */
  64. typedef  Boolean        Flag;
  65. typedef  short int        sint;
  66. typedef  unsigned int    counter;
  67. typedef  unsigned int    uint;
  68. typedef  unsigned short    ushort;
  69. typedef  unsigned long    ulong;
  70. typedef  unsigned char    uchar;
  71.  
  72.  
  73. /* file stuff */
  74. #ifdef FILES
  75.  
  76. #ifndef STDIO_H
  77. #define STDIO_H
  78. #include <stdio.h>
  79. #endif
  80.  
  81. #define    MAX_FNAME    32
  82. typedef  struct    { FILE *fp; char name[MAX_FNAME+1]; }    File_Def;
  83. typedef  enum    { FTEXT, FBINARY }                     File_Type;
  84. typedef  enum    { FREAD, FWRITE, FAPPEND }             File_Mode;
  85.  
  86. #endif
  87.  
  88.  
  89.  
  90.  
  91.  
  92. /* macros */
  93.  
  94. #define  IS_ODD( x )   ( (x) & 1 )
  95.  
  96. #define  IS_EVEN( x )  ( !((x) & 1) )
  97.  
  98. #define  SWAP( a, b )  ( (a) ^= (b), (b) ^= (a), (a) ^= (b) )
  99.  
  100. #define  CINDEX( c )  ( (int)(c) )
  101.  
  102. #define  STREQ( a , b )  ( strcmp( (a), (b) ) == 0 )
  103.  
  104. #define  UPPER( c )  ( ((c) >= 'a' && (c) <= 'z')  ?  ((c)-'a'+'A'): (c) )
  105.  
  106. #define  LOWER( c )  ( ((c) >= 'A' && (c) <= 'Z')  ?  ((c)-'A'+'a'): (c) )
  107.  
  108. #define  IABS( x )  ( ((x) < 0)  ?  (-(x)) : (x) )
  109.  
  110. #define  FABS( x )  ( ((x) < 0.0)  ?  (-(x)) : (x) )
  111.  
  112. #define  RANGE( x, xmin, xmax )  ( ((x) < (xmin)) ?                        \
  113.                                    (xmin) :                                \
  114.                                    ( ((x) > (xmax)) ? (xmax) : (x) )  )
  115.  
  116. #define  INRANGE( x, xmin, xmax )  ( ((x) < (xmin)) ?                        \
  117.                                      0 : ( ((x) > (xmax)) ? 0 : 1 )  )
  118.  
  119. #define  NINT( x )  ( ((x) > 0) ?  ((int)(0.5+(x))) : (-(int)(0.5-(x))) )
  120.  
  121. #define  FLOOR( x )    ( ((x) > 0) ? (int)(x) : -(int)(-(x)) )
  122.  
  123. #define  CEILING( x )  ( ((x) > 0) ? (1+(int)(x)) : (-(1+(int)(-(x)))) )
  124.  
  125. #define  MAX( a , b )  ( ((a) > (b))  ?  (a) : (b) )
  126.  
  127. #define  MIN( a , b )  ( ((a) < (b))  ?  (a) : (b) )
  128.  
  129. #define  SQR( x )  ( (x) * (x) )
  130.  
  131. /* x modulo y (floating point) */
  132. #define  FMOD( x, y )    (                                                        \
  133.                           (FABS(x) < (y))  ?                                \
  134.                           (x) :                                             \
  135.                           ( (x) - (double)((ulong)((x)/(y))) * (y) )        \
  136.                         )
  137.  
  138. /* if ax = fabs(x) is within eps of zero, return zero; if ax > 1.0, 
  139.    return 1.0 or -1.0, depending on sign of x (x = sin or cos) */
  140. #define  TRIGFIX( x, ax, eps )    ( ((ax) < (eps)) ? 0.0 :                      \
  141.                                   (                                         \
  142.                                     (1.0 - (ax) > 0.0) ?                    \
  143.                                     (x) :                                   \
  144.                                     ( ((x) > 0) ? 1.0 : -1.0 )              \
  145.                                   )                                         \
  146.                                 )
  147.  
  148.  
  149.  
  150. /* generic function prototyping */
  151. #if defined(__STDC__) || defined(__MSDOS__)
  152. #define  PROTO( arglist )    arglist
  153. #else
  154. #define  PROTO( arglist )    ()
  155. #endif
  156.  
  157.  
  158.  
  159. /* key scan codes (for not-extended keys, the ascii code is given) */
  160. #ifdef    KEY_CODES
  161. typedef  enum    {    
  162.                     KEY_ESCAPE=27, 
  163.  
  164.                     KEY_ENTER=13, KEY_CR=13, KEY_TAB=9, KEY_SP=32, 
  165.                     KEY_LF=10,    KEY_FF=12, 
  166.  
  167.                     KEY_PRTSC=42, KEY_UP=72,   KEY_DN=80,   KEY_LEFT=75,
  168.                     KEY_RIGHT=77, KEY_PGUP=73, KEY_PGDN=81, KEY_HOME=71,
  169.                     KEY_END=79,   KEY_INS=82,  KEY_DEL=83,
  170.  
  171.                     KEY_F1=59, KEY_F2=60, KEY_F3=61, KEY_F4=62, KEY_F5=63,
  172.                     KEY_F6=64, KEY_F7=65, KEY_F8=66, KEY_F9=67, KEY_F10=68,
  173.  
  174.                     KEY_0=48, KEY_1=49, KEY_2=50, KEY_3=51, KEY_4=52, 
  175.                     KEY_5=53, KEY_6=54, KEY_7=55, KEY_8=56, KEY_9=57,
  176.  
  177.                     KEY_A=65, KEY_B=66, KEY_C=67, KEY_D=68, KEY_E=69,
  178.                     KEY_F=70, KEY_G=71, KEY_H=72, KEY_I=73, KEY_J=74,
  179.                     KEY_K=75, KEY_L=76, KEY_M=77, KEY_N=78, KEY_O=79,
  180.                     KEY_P=80, KEY_Q=81, KEY_R=82, KEY_S=83, KEY_T=84,
  181.                     KEY_U=85, KEY_V=86, KEY_W=87, KEY_X=88, KEY_Y=89,
  182.                     KEY_Z=90,
  183.  
  184.                     KEY_a= 97, KEY_b= 98, KEY_c= 99, KEY_d=100, KEY_e=101,
  185.                     KEY_f=102, KEY_g=103, KEY_h=104, KEY_i=105, KEY_j=106,
  186.                     KEY_k=107, KEY_l=108, KEY_m=109, KEY_n=110, KEY_o=111,
  187.                     KEY_p=112, KEY_q=113, KEY_r=114, KEY_s=115, KEY_t=116,
  188.                     KEY_u=117, KEY_v=118, KEY_w=119, KEY_x=120, KEY_y=121,
  189.                     KEY_z=122
  190.  
  191.                 } Key_Code;
  192. #endif
  193.  
  194.  
  195.  
  196. /*
  197.  *
  198.  *  generic error output routine
  199.  *
  200.  */
  201.  
  202. /*
  203. void  errout( Boolean bell, FILE *device, char *errstring );
  204.  
  205. #ifdef  ERROUT
  206. void  errout( Boolean bell, FILE *device, char *errstring )
  207. {
  208.     if( bell )  putc( BELL, device );
  209.     fprintf( device, "%s", errstring );
  210.     return;
  211. }
  212. #endif
  213. */
  214.  
  215.  
  216. #endif
  217.  
  218.