home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_02 / 8n02050a < prev    next >
Text File  |  1990-03-01  |  3KB  |  123 lines

  1.  
  2.  
  3. *****Listing 5*****
  4.  
  5. 001  #include <stdlib.h>
  6. 002  #include <stdarg.h>
  7. 003  #include <stdio.h>
  8. 004  #include "utility.h"
  9. 005  #ifdef __ZTC__
  10. 006  #include <fg.h>
  11. 007  #else
  12. 008  #include <graph.h>
  13. 009  #endif
  14. 010  
  15. 011  int g_white;
  16. 012  int g_black;
  17. 013  
  18. 014  void fatal(char *s)
  19. 015  {
  20. 016      printf("FATAL ERROR: %s\n", s);
  21. 017      exit(1);
  22. 018  }
  23. 019  
  24. 020  void trace(char *fmt, ...)
  25. 021  {
  26. 022      static FILE *outfp = NULL;
  27. 023      va_list arg_ptr;
  28. 024      va_start(arg_ptr, fmt);
  29. 025      if (outfp == NULL) {
  30. 026          unlink("tf");
  31. 027          if ((outfp = fopen("tf", "w")) == NULL)
  32. 028              fatal("fopen failed\n");
  33. 029          setbuf(outfp, NULL);
  34. 030      }
  35. 031      vfprintf(outfp, fmt, arg_ptr);
  36. 032      va_end(arg_ptr);
  37. 033  }
  38. 034  
  39. 035  /* utility function to put screen in graphics mode */
  40. 036  void g_init(void)
  41. 037  {
  42. 038  #ifdef __ZTC__
  43. 039      fg_init_all();
  44. 040      g_white = FG_WHITE;
  45. 041      g_black = FG_BLACK;
  46. 042  #else
  47. 043      struct videoconfig this_screen;
  48. 044      _getvideoconfig(&this_screen);
  49. 045      switch (this_screen.adapter)
  50. 046      {
  51. 047      case _CGA:
  52. 048      case _OCGA:
  53. 049          _setvideomode(_HRESBW);
  54. 050          break;
  55. 051      case _EGA:
  56. 052      case _OEGA:
  57. 053          _setvideomode(_ERESCOLOR);
  58. 054          break;
  59. 055      case _VGA:
  60. 056      case _OVGA:
  61. 057      case _MCGA:
  62. 058          _setvideomode(_VRES2COLOR);
  63. 059          break;
  64. 060      case _HGC:
  65. 061          _setvideomode(_HERCMONO);
  66. 062          break;
  67. 063      default:
  68. 064          printf("This program requires a CGA, EGA, MCGA,");
  69. 065          printf("VGA, or Hercules card\n");
  70. 066          exit(0);
  71. 067      }
  72. 068      g_white = _getcolor();
  73. 069      g_black = 0;
  74. 070  #endif
  75. 071  }
  76. 072  
  77. 073  /* utility function - wait for a key so we can see
  78. 074     graphics, set video mode back to character mode */
  79. 075  void cleanup()
  80. 076  {
  81. 077      int ch;
  82. 078      ch = getchar();
  83. 079  #ifdef __ZTC__
  84. 080      fg_term();
  85. 081  #else
  86. 082      _setvideomode(_DEFAULTMODE);
  87. 083  #endif
  88. 084      /*lint -esym(550,ch) */
  89. 085  }
  90. 086  /*lint +esym(550,ch) */
  91. 087  
  92. 088  void g_circle(int y, int x, int radius, int color)
  93. 089  {
  94. 090  #ifdef __ZTC__
  95. 091      fg_drawarc((fg_color_t)color, FG_MODE_SET, ~0, x, y,
  96. 092        radius, 0, 3600, fg_displaybox);
  97. 093  #else
  98. 094      _setcolor(color);
  99. 095      _ellipse(_GBORDER, x - radius, y - radius, x + radius,
  100. 096        y + radius);
  101. 097  #endif
  102. 098  }
  103. 099  
  104. 100  void g_square(int y, int x, int size, int color)
  105. 101  {
  106. 102  #ifdef __ZTC__
  107. 103      int hs;
  108. 104      fg_box_t box;
  109. 105      hs = size / 2;
  110. 106      box[FG_X1] = x - hs;
  111. 107      box[FG_Y1] = y - hs;
  112. 108      box[FG_X2] = x + hs;
  113. 109      box[FG_Y2] = y + hs;
  114. 110      fg_drawbox((fg_color_t)color, FG_MODE_SET, ~0,
  115. 111        FG_LINE_SOLID, box, fg_displaybox);
  116. 112  #else
  117. 113      int hs;
  118. 114      hs = size / 2;
  119. 115      _setcolor(color);
  120. 116      _rectangle(_GBORDER, x - hs, y - hs, x + hs, y + hs);
  121. 117  #endif
  122. 118  }
  123.