home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilsa / andylib / c / tracker < prev   
Text File  |  1994-05-11  |  2KB  |  80 lines

  1. /* tracker.c */
  2.  
  3. #include <stdarg.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. #include "tracker.h"
  8.  
  9. #ifdef MODULE
  10. #include "kernel.h"
  11. #define wimpt_complain(e) (e)
  12. #define wimpt_programname() ("Module")
  13. #define os_swix(n, r) _kernel_swi((n), (r), (r))
  14. #define os_error _kernel_oserror
  15. #define os_regset _kernel_swi_regs
  16. #else
  17. #include "os.h"
  18. #include "wimpt.h"
  19. #endif
  20.  
  21. enum
  22. {  Tracker_Open = 0xCF000,
  23.    Tracker_Close, Tracker_SetPos, Tracker_WriteS, Tracker_CLS, Tracker_Simple
  24. };
  25.  
  26. static int trackhandle = 0;
  27.  
  28. static int open(char *title, int width, int height, int flags)
  29. {  os_regset regs;
  30.  
  31.    regs.r[0] = (int) title;
  32.    regs.r[1] = width;
  33.    regs.r[2] = height;
  34.    regs.r[3] = flags;
  35.  
  36.    if (wimpt_complain(os_swix(Tracker_Open, ®s)))
  37.       return -1;
  38.  
  39.    return regs.r[0];
  40. }
  41.  
  42. static void close(int handle)
  43. {  os_regset regs;
  44.  
  45.    regs.r[0] = handle;
  46.    os_swix(Tracker_Close, ®s);
  47. }
  48.  
  49. static void writes(int handle, char *s)
  50. {  os_regset regs;
  51.  
  52.    regs.r[0] = handle;
  53.    regs.r[1] = (int) s;
  54.    os_swix(Tracker_WriteS, ®s);
  55. }
  56.  
  57. static void exithandler(void)
  58. {  if (trackhandle)
  59.       close(trackhandle);
  60. }
  61.  
  62. void tracker_printf(char *fmt, ...)
  63. {  char buf[2048];
  64.    va_list ap;
  65.  
  66.    if (trackhandle == 0)
  67.    {  if (trackhandle = open(wimpt_programname(), 132, 500, 1), trackhandle > 0)
  68.          atexit(exithandler);
  69.       else
  70.          return;
  71.    }
  72.    else if (trackhandle < 0)
  73.       return;
  74.       
  75.    va_start(ap, fmt);
  76.    vsprintf(buf, fmt, ap);
  77.    va_end(ap);
  78.    writes(trackhandle, buf);
  79. }
  80.