home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Editors / emacs / Emacs-1.14b1-sources / sources / unix-emulation-src / FSSpec2unixfn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-16  |  1.7 KB  |  73 lines  |  [TEXT/EMAC]

  1. /*
  2.  * Copyright (C) 1993, 1994 Marc Parmet.
  3.  * This file is part of the Macintosh port of GNU Emacs.
  4.  *
  5.  * GNU Emacs is distributed in the hope that it will be useful,
  6.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  8.  * GNU General Public License for more details.
  9.  */
  10.  
  11. #if defined(THINK_C)
  12. #include <MacHeaders>
  13. #else
  14. #include <Types.h>
  15. #include <Memory.h>
  16. #include <Quickdraw.h>
  17. #include <Windows.h>
  18. #include <Files.h>
  19. #include <Errors.h>
  20. #endif
  21.  
  22. int
  23. FSSpec2unixfn_internal(FSSpec *spec,Handle *s)
  24. {
  25.     short err;
  26.     long parID;
  27.     CInfoPBRec pb;
  28.     char *alloca();
  29.     struct component {
  30.         struct component *next;
  31.         unsigned char s[32];
  32.     } *component_list,*a;
  33.  
  34.     *s = 0L;
  35.     a = (struct component *)alloca(sizeof(struct component));
  36.     a->next = 0L;
  37.     component_list = a;
  38.     pstrcpy(a->s,spec->name);
  39.     slashes_to_colons(a->s+1,a->s[0]);
  40.     parID = spec->parID;
  41.  
  42.     while (1) {
  43.         a = (struct component *)alloca(sizeof(struct component));
  44.         pb.dirInfo.ioFDirIndex = -1;
  45.         pb.dirInfo.ioNamePtr = a->s;
  46.         pb.dirInfo.ioVRefNum = spec->vRefNum;
  47.         pb.dirInfo.ioDrDirID = parID;
  48.         err = PBGetCatInfo(&pb,0);
  49.         if (err == fnfErr) break;
  50.         if (err != noErr) return err;
  51.  
  52.         a->next = component_list;
  53.         component_list = a;
  54.         slashes_to_colons(a->s+1,a->s[0]);
  55.         parID = pb.dirInfo.ioDrParID;
  56.     }
  57.  
  58.     *s = NewHandle(0);
  59.     err = MemError();
  60.     if (err) return err;
  61.     while (component_list != 0L) {
  62.         err = PtrAndHand("/",*s,1);
  63.         if (err) { DisposHandle(*s); *s = 0L; return err; }
  64.         err = PtrAndHand(component_list->s+1,*s,component_list->s[0]);
  65.         if (err) { DisposHandle(*s); *s = 0L; return err; }
  66.         component_list = component_list->next;
  67.     }
  68.  
  69.     err = PtrAndHand("",*s,1);
  70.     if (err) { DisposHandle(*s); *s = 0L; return err; }
  71.     return 0;
  72. }
  73.