home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacsBug / MacsBug 6.1 / dcmds / Contributed dcmds / File.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-21  |  5.3 KB  |  248 lines  |  [TEXT/MPS ]

  1. /*     file.c
  2.     This is the FCB dcmd.
  3.  
  4.     Copyright © 1988 Apple Computer, Inc.  All rights reserved.
  5.  
  6.     Modification history:
  7.         29Nov88 sad        revised for new dcmd names.
  8.          5Oct88    sad        broke out formatting routines to put.c
  9.         30Sep88 sad        written
  10.  
  11.     The following MPW commands will build the dcmd and copy it to the
  12.     "Debugger Prefs" file in the System folder. The dcmd's name in
  13.     MacsBug will be the name of the file built by the Linker.
  14.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  15.     C Samples folder into this folder.
  16.  
  17.     C Put.c
  18.     C File.c
  19.     Link dcmdGlue.a.o File.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o File
  20.     BuildDcmd File 1003
  21. */
  22.  
  23. #include <Types.h>
  24. #include <Memory.h>
  25. #include <Files.h>
  26.  
  27. #include "dcmd.h"
  28. #include "put.h"
  29.  
  30. #define FSFCBLen 0x3f6
  31. #define FCBsPtr 0x34e
  32.  
  33. typedef struct FCB
  34.     {
  35.     unsigned long fcbFlNum;
  36.     unsigned char fcbMdRByt;
  37.     unsigned char fcbTypByt;
  38.     unsigned short fcbSBlk;
  39.     unsigned long fcbEOF;
  40.     unsigned long fcbPLen;
  41.     unsigned long fcbCrPs;
  42.     VCB* fcbVPtr;
  43.     void* fcbBfAdr;
  44.     unsigned short fcbFlPos;
  45.     unsigned long fcbClmpSize;
  46.     void* fcbBTCBPtr;
  47.     unsigned long fcbExtRec[3];
  48.     OSType fcbFType;
  49.     unsigned long fcbCatPos;
  50.     unsigned long fcbDirID;
  51.     char fcbCName[32];
  52.     } FCB;
  53.  
  54.  
  55. static void DrawHdr()
  56. {
  57. //                             1         2         3         4         5         6         7
  58. //                    1234567890123456789012345678901234567890123456789012345678901234567890
  59.     dcmdDrawLine("\pfRef File         Vol      Type Fl Fork    LEof    Mark  FlNum Parent FCB at");
  60. }
  61.  
  62.  
  63. static void DrawFCB(int fref, FCB* fcbp)
  64. {
  65.     PutUHexWord(fref);
  66.     PutSpace();
  67.     PutPStrTruncTo(fcbp->fcbCName,17);
  68.     PutSpace();
  69.     PutPStrTruncTo(fcbp->fcbVPtr->vcbVN,26);
  70.     PutSpace();
  71.     PutOSType(fcbp->fcbFType);
  72.     PutSpace();
  73.     PutChar((fcbp->fcbMdRByt & 0x80) ? 'D' : 'd');
  74.     PutChar((fcbp->fcbMdRByt & 0x01) ? 'W' : 'w');
  75.     PutSpace();
  76.     if (fcbp->fcbMdRByt & 0x02) PutPStr("\prsrc ");
  77.     else PutPStr("\pdata ");
  78.     PutUDecTo(fcbp->fcbEOF,47);
  79.     PutSpace();
  80.     PutUDecTo(fcbp->fcbCrPs,55);
  81.     PutSpace();
  82.     PutUHexZTo(fcbp->fcbFlNum,6,62);
  83.     PutSpace();
  84.     PutUHexZTo(fcbp->fcbDirID,6,69);
  85.     PutSpace();
  86.     PutUHexZTo((unsigned long)fcbp,6,76);
  87.     PutLine();
  88. } // DrawFCB
  89.  
  90.  
  91. static Boolean PrefixPStr(const Str255 astr, const Str255 bstr)
  92. // returns true if astr is equal to a prefix of bstr
  93. //    astr must not be longer than 31 characters
  94. {
  95.     char newstr[31];
  96.     int alen = *astr;
  97.     int blen = *bstr;
  98.     if (alen <= blen)
  99.         {
  100.         BlockMove(bstr+1,newstr+1,alen);
  101.         newstr[0] = alen;
  102.         return EqualString(astr,newstr,false,true);
  103.         }
  104.     else return false;    
  105. } // PrefixPStr
  106.  
  107. // EJECT
  108.  
  109. pascal void CommandEntry(dcmdBlock* paramPtr)
  110. {
  111.     switch (paramPtr->request)
  112.         {
  113.         case dcmdInit:
  114.             break;
  115.  
  116.         case dcmdHelp:
  117.             dcmdDrawLine("\pfile [fRefNum|\"file name\"]");
  118.             dcmdDrawLine("\p   Displays file information for the given fRefNum, file name or all open files.");
  119.             dcmdDrawLine("\p      Flags are D/d=Dirty, W/w=writeable.");
  120.             break;
  121.  
  122.         case dcmdDoIt:
  123.             {
  124.             Boolean doOneFCB = false;
  125.             long fref;
  126.             short c;
  127.             Boolean haveFileName = false;
  128.             Str255 filename;
  129.             int fcblen;                // the length of one fcb
  130.             char* fcbsbase;
  131.             int fcbslen;            // the length of the fcbs block
  132.  
  133.             dcmdSwapWorlds();
  134.  
  135.             dcmdDrawLine("\pDisplaying File Control Blocks");
  136.  
  137.           // get low-memory values after dcmdSwapWorlds()
  138.             fcblen = *(unsigned short*)FSFCBLen;
  139.             fcbsbase = *(char**)FCBsPtr;
  140.             fcbslen = *(unsigned short*)fcbsbase;
  141.  
  142.             if (fcblen != sizeof(FCB))
  143.                 {
  144.                 PutPStr("\FSFCBLen = ");
  145.                 PutUDec(fcblen);
  146.                 PutPStr("\p expected ");
  147.                 PutUDec(fcblen);
  148.                 PutLine(sizeof(FCB));
  149.                 }
  150.             if ((fcbslen - 2) % fcblen != 0)
  151.                 {
  152.                 PutPStr("\pbad fcbslen ");
  153.                 PutUHexWord(fcbslen);
  154.                 PutLine();
  155.                 }
  156.  
  157.             c = dcmdPeekAtNextChar();
  158.             if (c == '"' || c == '\'')
  159.                 {
  160.                 haveFileName = true;
  161.                 (void)dcmdGetNextParameter(filename);
  162.                 }
  163.             else (void)dcmdGetNextExpression(&fref, &doOneFCB);
  164.  
  165.             if (doOneFCB)
  166.                 {
  167.                 fref = (unsigned short)fref;
  168.                 if ((fref > fcbslen) || ((fref - 2) % fcblen != 0))
  169.                     {
  170.                     PutPStr("\pbad file refnum ");
  171.                     PutUHexWord(fref);
  172.                     PutLine();
  173.                     }
  174.                 else
  175.                     {
  176.                     FCB* fcbp = (FCB*)(fref + fcbsbase);
  177.                     if (fcbp->fcbFlNum)
  178.                         {
  179.                         DrawHdr();
  180.                         DrawFCB(fref,fcbp);
  181.                         }
  182.                     else
  183.                         {
  184.                         PutPStr("\pFCB ");
  185.                         PutUHexWord(fref);
  186.                         PutPStr("\p is not in use");
  187.                         PutLine();
  188.                         }
  189.                     }
  190.                 }
  191.             else
  192.                 {
  193.                 int numfcbs = (fcbslen - 2) / fcblen;
  194.                 int fcbsused = 0;
  195.                 Boolean foundOne = false;
  196.                 for (fref = 2;
  197.                      fref < fcbslen;
  198.                      fref += fcblen)
  199.                     {
  200.                     FCB* fcbp = (FCB*)(fcbsbase + fref);
  201.                     if (fcbp->fcbFlNum &&
  202.                         (!haveFileName || PrefixPStr(filename,fcbp->fcbCName)))
  203.                         {
  204.                         fcbsused++;
  205.                         if (!foundOne)
  206.                             {
  207.                             DrawHdr();
  208.                             foundOne = true;
  209.                             }
  210.                         DrawFCB(fref,fcbp);
  211.                         }
  212.                     if (paramPtr->aborted) break;
  213.                     }
  214.                 if (!paramPtr->aborted)
  215.                     if (haveFileName)
  216.                         {
  217.                         if (!foundOne)
  218.                             {
  219.                             PutPStr("\pno open files match \"");
  220.                             PutPStr(filename);
  221.                             PutChar('"');
  222.                             PutLine();
  223.                             }
  224.                         }
  225.                     else
  226.                         {
  227.                         PutUDec(numfcbs);
  228.                         PutPStr("\p FCBs, ");
  229.                         PutUDec(fcbsused);
  230.                         PutPStr("\p in use, ");
  231.                         PutUDec(numfcbs - fcbsused);
  232.                         PutPStr("\p free");
  233.                         PutLine();
  234.                         }
  235.                 }    
  236.  
  237.             dcmdSwapWorlds();
  238.             }
  239.             break;
  240.  
  241.         default:
  242.             PutPStr("\punknown request ");
  243.             PutUDec(paramPtr->request);
  244.             PutLine();
  245.             break;
  246.         }
  247. } // CommandEntry
  248.