home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dmake40.zip / mac / tomacfil.c < prev   
C/C++ Source or Header  |  1994-10-23  |  4KB  |  119 lines

  1. /* RCS      -- $Header: /u5/dvadura/src/public/dmake/src/mac/RCS/tomacfil.c,v 1.1 1994/10/06 17:43:04 dvadura Exp $
  2. -- SYNOPSIS -- Routines to change unix file names to mac file names
  3. --
  4. -- DESCRIPTION
  5. --  Dmake sometimes assumes that files have '/' as a directory parameter in some makefiles.
  6. --  This works, even on DOS, but not on the Mac.  In fact, on the Mac, you can't even do a
  7. --  a simple switch of ':' for '/' because all other the Mac has decided to reverse the use
  8. --  of a first-character directory delimiter to mean a relative path rather than absolute path.
  9. --  (i.e., ':test:b' means directory test is relative to the current directory, rather than
  10. --  a top-level directory.  Thus, this file attempts to do the directory conversion behind
  11. --  the back of the rest of the program.
  12. --
  13. -- AUTHOR
  14. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  15. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  16. --
  17. --
  18. -- COPYRIGHT
  19. --      Copyright (c) 1992,1994 by Dennis Vadura.  All rights reserved.
  20. -- 
  21. --      This program is free software; you can redistribute it and/or
  22. --      modify it under the terms of the GNU General Public License
  23. --      (version 1), as published by the Free Software Foundation, and
  24. --      found in the file 'LICENSE' included with this distribution.
  25. -- 
  26. --      This program is distributed in the hope that it will be useful,
  27. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  28. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  29. --      GNU General Public License for more details.
  30. -- 
  31. --      You should have received a copy of the GNU General Public License
  32. --      along with this program;  if not, write to the Free Software
  33. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  34. --
  35. -- LOG
  36. --     $Log: tomacfil.c,v $
  37.  * Revision 1.1  1994/10/06  17:43:04  dvadura
  38.  * dmake Release Version 4.0, Initial revision
  39.  *
  40. */
  41.  
  42. #include "extern.h"
  43. int IsUnixFName (char *pFileName);
  44.  
  45.  
  46.  
  47. /*
  48.  * Convert a file that may be in unix format to mac format.
  49.  *
  50.  * The returned name is either the untouched pUnixName, or a static buffer.
  51.  */
  52. PUBLIC char *
  53. Unix2MacFName(char *pUnixName)
  54. {
  55.     static char MacName[256];
  56.     char *pCurMac;
  57.  
  58.     if (IsUnixFName (pUnixName)) {
  59.         if (strlen (pUnixName) + (*pUnixName == '/' ? -1 : 1) >= sizeof (MacName)) {
  60.             Fatal ("File name '%s' is too long and will cause a buffer overflow", pUnixName);
  61.         } /* if */
  62.  
  63.         /* Set up relative or absolute path */
  64.         pCurMac = MacName;
  65.         if (*pUnixName == '/') {
  66.             ++pUnixName;
  67.         } else {
  68.             *(pCurMac++) = ':';
  69.         } /* if ... else */
  70.  
  71.         /* Convert the rest of the name */
  72.         while (*pUnixName != '\0') {
  73.             if (*pUnixName == '/') {
  74.                 *(pCurMac++) = ':';
  75.                 pUnixName++;
  76.  
  77.             } else {
  78.                 *(pCurMac++) = *(pUnixName++);
  79.             } /* if ... else */
  80.         } /* while */
  81.  
  82.         *pCurMac = '\0';
  83.         return (MacName);
  84.  
  85.     } else {
  86.         return (pUnixName);
  87.     } /* if ... else */
  88. } /* PUBLIC char *Unix2MacFName() */
  89.  
  90.  
  91.  
  92. /*
  93.  * Is this file name in UNIX format?
  94.  * (We assume it is if there are any slashes in its name.)
  95.  */
  96. int IsUnixFName (char *pFileName) {
  97.  
  98.     for ( ; *pFileName != '\0'; ++pFileName) {
  99.         if (*pFileName == '/') {
  100.             return (TRUE);
  101.         } /* if */
  102.     } /* while */
  103.  
  104.     return (FALSE);
  105. } /* int IsUnixFName () */
  106.  
  107.  
  108.  
  109. /*
  110.  * Call the real fopen() from this override of the function
  111.  * that the rest of the program uses.
  112.  */
  113. #undef fopen
  114. PUBLIC FILE *
  115. MacFOpen(char *pFName, char *pMode)
  116. {
  117.     return (fopen (Unix2MacFName (pFName), pMode));
  118. } /* PUBLIC FILE *MacFOpen () */
  119.