home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / tarsrc.sit / tar.c < prev    next >
C/C++ Source or Header  |  1989-09-14  |  3KB  |  131 lines

  1. /*
  2.  * Macintosh TAR
  3.  *
  4.  * Written by Craig Ruff
  5.  *
  6.  * Main routine and global variables.
  7.  */
  8.  
  9. /*#define DEBUG*/
  10. #include "tar.h"
  11. #include <SegLoad.h>
  12. #include <Resources.h>
  13.  
  14. #define FSFCBLen    (*(short *) 0x3f6)
  15.  
  16. /*
  17.  * Global variable declarations
  18.  */
  19. Boolean autoPage = false;    /* List by screenfulls */
  20. Boolean cvtNl = false;        /* Convert newline to return and back */
  21. Boolean doneFlag = false;    /* Quit item selected? */
  22. Boolean doPrint = false;    /* List to printer */
  23. Boolean ignorez = false;    /* Ignore zero blocks */
  24. Boolean    pOpen = false;        /* Printer open? */
  25. Boolean reblock = false;    /* Read enough for a full block size buffer */
  26. Boolean oldArch = false;    /* Old tar compatible */
  27.  
  28. THPrint    prRecHdl;        /* Printer record (when printing) */
  29.  
  30. char    *arName;        /* Archive file name */
  31. short    arVRefNum;        /* Archive file VRefNum */
  32.  
  33. short    archive;        /* File descriptor for archive file */
  34. int    blocking;        /* Size of each block, in records */
  35. int    blockSize;        /* Size of each block, in bytes */
  36.  
  37. char    fdCreator[4];        /* Finder Creator */
  38. char    fdType[4];        /* Finder Type */
  39. char    header[128];        /* Common header for listings */
  40. jmp_buf    errJmp;            /* For error exits */
  41.  
  42. main() {
  43.     WindowPtr    wind;
  44.     EventRecord    e;
  45.     Handle        fTypeH;
  46.  
  47.     /*
  48.      * Standard Mac Initializations
  49.      */
  50.     InitGraf(&qd.thePort);
  51.     InitFonts();
  52.     FlushEvents(everyEvent, 0);
  53.     InitWindows();
  54.     InitMenus();
  55.     TEInit();
  56.     InitDialogs(nil);
  57.     InitCursor();
  58.  
  59. #ifdef DEBUG
  60.     /*
  61.      * So we don't keep copying resources into our application.
  62.      */
  63.     if (OpenResFile("\pDD:tar:tar.rsrc") == -1) {
  64.         OSAlert("\pmain", "\pDebug OpenResFile", nil, 0);
  65.         ExitToShell();
  66.     }
  67. #endif
  68.  
  69.     /* Check for HFS running */
  70.     if (FSFCBLen <= 0) {
  71.         HFSAlert();
  72.         ExitToShell();
  73.     }
  74.  
  75.     if (MenuInit())
  76.         ExitToShell();
  77.  
  78.     blocking = 20;
  79.     blockSize = blocking * RECORDSIZE;
  80.     if ((fTypeH = GetResource('ftyp', 0)) == nil) {
  81.         strncpy(fdCreator, "????", 4);
  82.         strncpy(fdType, "TEXT", 4);
  83.  
  84.     } else {
  85.         strncpy(fdCreator, *fTypeH, 4);
  86.         strncpy(fdType, (*fTypeH) + 4, 4);
  87.         ReleaseResource(fTypeH);
  88.     }
  89.  
  90.     if ((prRecHdl = (THPrint) NewHandle((long) sizeof(TPrint))) == nil) {
  91.         OSAlert("\pmain", "\pNewHandle returned nil", nil, MemError());
  92.         ExitToShell();
  93.     }
  94.  
  95.     sprintf(header, "T     Size Date              Name%*s", 40, "");
  96.     do {
  97.         SystemTask();
  98.         /* Should never have a window open while a DA is running */
  99.         if (!menusOK && (FrontWindow() == nil))
  100.             DDaMenus();
  101.  
  102.         if (GetNextEvent(everyEvent, &e))
  103.             switch (e.what) {
  104.             case mouseDown:
  105.                 switch (FindWindow(e.where, &wind)) {
  106.                 case inSysWindow:
  107.                     SystemClick(&e, wind);
  108.                     break;
  109.  
  110.                 case inMenuBar:
  111.                     MenuCmd(MenuSelect(e.where));
  112.                     break;
  113.  
  114.                 }
  115.                 break;
  116.  
  117.             case keyDown:
  118.             case autoKey:
  119.                 if (e.modifiers & cmdKey)
  120.                     MenuCmd(MenuKey(e.message & charCodeMask));
  121.                 break;
  122.             }
  123.  
  124.     } while (!doneFlag);
  125.  
  126.     if (pOpen)
  127.         PrClose();
  128.  
  129.     ExitToShell();
  130. }
  131.