home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DMAKE38C.ZIP / MAC / TOMACFIL.C < prev   
C/C++ Source or Header  |  1992-01-23  |  4KB  |  115 lines

  1. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/mac/tomacfil.c,v 1.1 1992/01/24 03:29:53 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) 1990 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  1992/01/24  03:29:53  dvadura
  38.  * dmake Version 3.8, 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 *Unix2MacFName(char *pUnixName) {
  53.     static char MacName[256];
  54.     char *pCurMac;
  55.  
  56.     if (IsUnixFName (pUnixName)) {
  57.         if (strlen (pUnixName) + (*pUnixName == '/' ? -1 : 1) >= sizeof (MacName)) {
  58.             Fatal ("File name '%s' is too long and will cause a buffer overflow", pUnixName);
  59.         } /* if */
  60.  
  61.         /* Set up relative or absolute path */
  62.         pCurMac = MacName;
  63.         if (*pUnixName == '/') {
  64.             ++pUnixName;
  65.         } else {
  66.             *(pCurMac++) = ':';
  67.         } /* if ... else */
  68.  
  69.         /* Convert the rest of the name */
  70.         while (*pUnixName != '\0') {
  71.             if (*pUnixName == '/') {
  72.                 *(pCurMac++) = ':';
  73.                 pUnixName++;
  74.  
  75.             } else {
  76.                 *(pCurMac++) = *(pUnixName++);
  77.             } /* if ... else */
  78.         } /* while */
  79.  
  80.         *pCurMac = '\0';
  81.         return (MacName);
  82.  
  83.     } else {
  84.         return (pUnixName);
  85.     } /* if ... else */
  86. } /* PUBLIC char *Unix2MacFName() */
  87.  
  88.  
  89.  
  90. /*
  91.  * Is this file name in UNIX format?
  92.  * (We assume it is if there are any slashes in its name.)
  93.  */
  94. int IsUnixFName (char *pFileName) {
  95.  
  96.     for ( ; *pFileName != '\0'; ++pFileName) {
  97.         if (*pFileName == '/') {
  98.             return (TRUE);
  99.         } /* if */
  100.     } /* while */
  101.  
  102.     return (FALSE);
  103. } /* int IsUnixFName () */
  104.  
  105.  
  106.  
  107. /*
  108.  * Call the real fopen() from this override of the function
  109.  * that the rest of the program uses.
  110.  */
  111. #undef fopen
  112. PUBLIC FILE *MacFOpen (char *pFName, char *pMode) {
  113.     return (fopen (Unix2MacFName (pFName), pMode));
  114. } /* PUBLIC FILE *MacFOpen () */
  115.