header.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* =============================================================================
  2. * PROGRAM: ularn
  3. * FILENAME: header.h
  4. *
  5. * DESCRIPTION:
  6. * This file contains the macro definitions for macros commonly used in ularn.
  7. *
  8. * =============================================================================
  9. * EXPORTED VARIABLES
  10. *
  11. * None.
  12. *
  13. * =============================================================================
  14. * EXPORTED FUNCTIONS
  15. *
  16. * None.
  17. *
  18. * =============================================================================
  19. */
  20. #ifndef __HEADER_H
  21. #define __HEADER_H
  22. #include "config.h"
  23. #include <sys/stat.h>
  24. #include <sys/types.h>
  25. #ifdef FTIMER
  26. #include <sys/timeb.h>
  27. #endif /* FTIMER */
  28. #ifdef ITIMER
  29. #include SYSTIME
  30. #endif /* ITIMER */
  31. #include <ctype.h>
  32. #include <fcntl.h>
  33. #include <signal.h>
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #ifdef UNIX
  38. #include <unistd.h>
  39. #endif
  40. #ifdef WINDOWS
  41. #include <io.h>
  42. #endif
  43. /*
  44. * ------------------- macros --------------------
  45. */
  46. #ifdef DRAND48
  47. #define srand srand48
  48. #define rand lrand48
  49. #else
  50. #ifdef RANDOM
  51. #define srand srandom
  52. #define rand random
  53. #endif
  54. #endif /* RANDOM */
  55. // Generate a random number between 1 and x
  56. #define rnd(x) ((int)(rand() % (x)) + 1)
  57. #define rndl(x) ((long)(rand() % (x)) + 1)
  58. // Generate a random number between 0 and x-1
  59. #define rund(x) ((int)(rand() % (x)))
  60. #define rundl(x) ((long)(rand() % (x)))
  61. /* macros for miscellaneous data conversion */
  62. #ifndef min
  63. #define min(x, y) ((int)((x) > (y)) ? (y) : (x))
  64. #endif
  65. #ifndef max
  66. #define max(x, y) ((int)((x) > (y)) ? (x) : (y))
  67. #endif
  68. #ifndef abs
  69. #define abs(x) (((x) < 0) ? -(x) : (x))
  70. #endif
  71. /* Macro for adding plural to item descriptions */
  72. #define plural(x) ((x == 1) ? "" : "s")
  73. #define ESC '\033'
  74. #endif