home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / appli / io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  2.3 KB  |  118 lines  |  [TEXT/MPS ]

  1. #include <Dialogs.h>
  2. #include <Events.h>
  3. #include <Files.h>
  4. #include <Stdlib.h>
  5. #include <Types.h>
  6. #include "ui.h"
  7.  
  8. int read(int fd, char * p, unsigned long n)
  9. {
  10.   if (fd == 0) {
  11.     return DoRead(p, n);
  12.   } else {
  13.     return mpw_read(fd, p, n);
  14.   }
  15. }
  16.  
  17. int write(int fd, char * p, unsigned long n)
  18. {
  19.   if (fd == 1 || fd == 2) {
  20.     DoWrite(CAMLPrinter, p, n);
  21.     return n;
  22.   } else {
  23.     return mpw_write(fd, p, n);
  24.   }
  25. }
  26.  
  27. void exit(int status)
  28. {
  29.   if (status != 0) {
  30.     NoteAlert(140, 0);
  31.     while(1) {
  32.       LookEvent(15);
  33.     }
  34.   } else {
  35.     Quit();
  36.   }
  37. }
  38.  
  39. static int maxcount = 30;
  40. static int count = 30;
  41. static unsigned long lastdate = 0;
  42.  
  43. pascal void SpinCursor(short delta)
  44. {
  45. #pragma unused(delta)
  46.  
  47.   unsigned long date;
  48.   
  49.   --count;
  50.   if (count == 0){
  51.     LookEvent (0);
  52.     date = TickCount ();
  53.     if (date - lastdate < 15 && maxcount < 50) ++maxcount;
  54.     if (date - lastdate > 15 && maxcount > 10) --maxcount;
  55.     count = maxcount;
  56.   }
  57. }
  58.  
  59. char *get_wd_name (short wd_refnum, char *postfix)
  60. {
  61.   char buf [64];
  62.   char *temp, *result;
  63.   DirInfo cinfo;
  64.   WDPBRec wd;
  65.  
  66.   wd.ioCompletion = NULL;
  67.   wd.ioNamePtr = NULL;
  68.   wd.ioVRefNum = wd_refnum;
  69.   wd.ioWDIndex = 0;
  70.   wd.ioWDProcID = 0;
  71.   wd.ioWDVRefNum = 0;
  72.   if (PBGetWDInfo (&wd, 0) != noErr) return postfix;
  73.   cinfo.ioDrParID = wd.ioWDDirID;
  74.   result = malloc (strlen (postfix) + 1);
  75.   if (result == NULL) return postfix;
  76.   strcpy (result, postfix);
  77.   do{
  78.     cinfo.ioCompletion = NULL;
  79.     cinfo.ioNamePtr = buf;
  80.     cinfo.ioVRefNum = wd.ioWDVRefNum;
  81.     cinfo.ioFDirIndex = -1;
  82.     cinfo.ioDrDirID = cinfo.ioDrParID;
  83.     if (PBGetCatInfo ((CInfoPBPtr) &cinfo, 0) != noErr) return postfix;
  84.     p2cstr (buf);
  85.     temp = malloc (strlen (result) + strlen (buf) + 2);
  86.     if (temp == NULL){
  87.       free (result);
  88.       return postfix;
  89.     }
  90.     sprintf (temp, ":%s%s", buf, result);
  91.     free (result);
  92.     result = temp;
  93.   }while (cinfo.ioDrDirID != 2);
  94.   return result + 1;
  95. }
  96.  
  97. extern int sub_main (int argc, char *argv []);
  98.  
  99. main (int argc, char *argv [])
  100. {
  101. #pragma unused (argc)
  102.   char *new_argv [4];
  103.   WDPBRec wd;
  104.  
  105.   Initialize ();
  106.   new_argv [0] = argv [0];
  107.   new_argv [1] = "-stdlib";
  108.   wd.ioCompletion = NULL;
  109.   wd.ioNamePtr = NULL;
  110.   if (PBHGetVol (&wd, 0) != noErr){
  111.     new_argv [2] = ":lib:";
  112.   }else{
  113.     new_argv [2] = get_wd_name (wd.ioVRefNum, ":lib:");
  114.   }
  115.   new_argv [3] = NULL;
  116.   return sub_main (3, new_argv);
  117. }
  118.