home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Programming / Source / WAIS / ir / macver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-02  |  4.4 KB  |  157 lines

  1. #include "irverify.h"
  2. #include "panic.h"
  3. #include "irfiles.h"
  4.  
  5. /*----------------------------------------------------------------------*/
  6. /* Class definitions */
  7.  
  8. #include <CApplication.h>
  9. #include <CFile.h>
  10. #include <CView.h>
  11. #include <CWindow.h>
  12. #include <CDesktop.h>
  13. #include <CDirector.h>
  14. #include "CDynamicError.h"
  15.  
  16. extern    CApplication    *gApplication;
  17.  
  18. struct CVerifyApp : CApplication 
  19. {
  20.   void    IVerifyApp(void);
  21. };
  22.  
  23. void CVerifyApp::IVerifyApp(void)
  24. {
  25.   CApplication::IApplication(4, 20480L, 2048L);
  26.   gError->Dispose(); /* get rid if the CError that IApplication defined */
  27.   gError = new(CDynamicError); /* make our own error handler */
  28. }
  29.  
  30. /*----------------------------------------------------------------------*/
  31. /* Gets a full filename from the mac file objects.
  32.  * getwd was taken from utils.c from the 
  33.  * document retrieval system.
  34.  */
  35.  
  36. #include <HFS.H>
  37. #include <string.h>
  38. /* for file manipulation routines */
  39. typedef enum file_style {MAC_FILE_STYLE, UNIX_FILE_STYLE} file_style;
  40. #include <FileMgr.h>
  41.  
  42. static char 
  43. *getwd(file_style style)
  44. /* This function returns the unix style path name which is set by any of the SF
  45.    routines (using the global vars).  The code is from the net, I have no idea
  46.    who the author might be.  He/She does include the following note:
  47.    
  48.           Note that it is perfectly legal for a Macintosh owner to create a
  49.         directory hierarchy where the length of full path names of the deepest
  50.         files exceeds 255 bytes; since the file system never manipulates full
  51.         pathnames internally (it only ever sees them when passed as parameters),
  52.         it doesn't and needn't check.  However, this poses an ethical problem if
  53.         you are constructing full pathnames: my code simply bombs if it would
  54.         construct a pathname >255 bytes, and if I increased the buffer size, the
  55.         resulting pathnames are useless except for documentation purposes (since
  56.         the file system can't have string parameters >255 bytes).
  57.  */
  58. {
  59.     CInfoPBRec d;
  60.     static char ret[255];
  61.     char nm[50], tmp[255];
  62.     long cur_dir = CurDirStore; /* mac global var */
  63.     long cur_vol = 0 - SFSaveDisk; /* mac global var */
  64.     
  65.     ret[0] = '\0';
  66.     d.dirInfo.ioDrDirID = cur_dir;
  67.     for(;;) {
  68.         d.dirInfo.ioCompletion = 0;
  69.         d.dirInfo.ioNamePtr = (StringPtr) nm;
  70.         d.dirInfo.ioVRefNum = cur_vol;
  71.         d.dirInfo.ioFDirIndex = -1;
  72.  
  73.         PBGetCatInfo(&d,0);
  74. /*        if(d.ioResult != noErr) return(0); this is not defined in lightspeed's headers */
  75.         PtoCstr((char *) nm);
  76.         strcpy(tmp,ret);
  77.         if (style == UNIX_FILE_STYLE)
  78.           strcpy(ret,"/");
  79.         else 
  80.           strcpy(ret,":");
  81.         strcat(ret,nm);
  82.         strcat(ret,tmp);
  83.         if(d.dirInfo.ioDrDirID == 2) break;    /* home directory */
  84.         d.dirInfo.ioDrDirID = d.dirInfo.ioDrParID;
  85.     } 
  86.     /* if its MAC style, remove the leading colon */
  87.     if (style == MAC_FILE_STYLE)
  88.       return(ret+1);
  89.     else
  90.       return(ret);
  91. }
  92.  
  93. /*----------------------------------------------------------------------*/
  94. /* Gets a filename from the user (one that exists already) */
  95.  
  96. static boolean 
  97. get_filename(char* prompt, char *filename)
  98. {
  99.    SFReply    macSFReply;
  100.    Point pos;
  101.    pos.h = pos.v = 100;
  102.    CtoPstr(prompt);
  103.    SFGetFile(pos, (StringPtr)prompt, 
  104.              NULL, -1, NULL, NULL, &macSFReply);
  105.    PtoCstr(prompt);
  106.    if(macSFReply.good)
  107.     { /* then we have a gotten a good file.
  108.        * put together the full filename
  109.        */
  110.          
  111.       strcpy(filename, getwd(MAC_FILE_STYLE));
  112.       strcat(filename, ":");
  113.       PtoCstr((char *)macSFReply.fName);
  114.       strcat(filename, (char *)macSFReply.fName);
  115.       CtoPstr((char *)macSFReply.fName);
  116.       return(true);
  117.      }
  118.     else
  119.       return(false);
  120. }
  121.  
  122. /*----------------------------------------------------------------------*/
  123.  
  124. FILE *logfile = NULL;
  125.  
  126. void
  127. main()
  128. {
  129.   char index_filename[MAX_FILE_NAME_LEN + 1]; 
  130.   database* db = NULL;
  131.  
  132. freopen("stdout","w",stdout);
  133.  
  134.   gApplication = new(CVerifyApp);
  135.   ((CVerifyApp *)gApplication)->IVerifyApp();
  136.   
  137.   if(get_filename("Index to verify:",index_filename) == false)
  138.     return;
  139.     
  140.   *(strrchr(index_filename,'.')) = '\0'; 
  141.   printf("verifying:  %s\n",index_filename);
  142.     
  143.   db = openDatabase(index_filename,false,true);
  144.   if (db == NULL)
  145.     panic("unable to open the database\n");
  146.     
  147.   print_dictionary(db);
  148.   printf("\n\n---------------------------------------------------------\n\n");
  149.   printIndex(db);
  150.   printf("\n\n---------------------------------------------------------\n\n");
  151.   printIndexUsingDictionary(db);
  152.   
  153.   closeDatabase(db);
  154. }
  155.  
  156. /*----------------------------------------------------------------------*/
  157.