| 1 | /* MPW-Unix compatibility library.
|
|---|
| 2 | Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of the libiberty library.
|
|---|
| 5 | Libiberty is free software; you can redistribute it and/or
|
|---|
| 6 | modify it under the terms of the GNU Library General Public
|
|---|
| 7 | License as published by the Free Software Foundation; either
|
|---|
| 8 | version 2 of the License, or (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | Libiberty is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | Library General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU Library General Public
|
|---|
| 16 | License along with libiberty; see the file COPYING.LIB. If
|
|---|
| 17 | not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|---|
| 18 | Boston, MA 02111-1307, USA. */
|
|---|
| 19 |
|
|---|
| 20 | /* This should only be compiled and linked under MPW. */
|
|---|
| 21 |
|
|---|
| 22 | #include "mpw.h"
|
|---|
| 23 |
|
|---|
| 24 | #include <stdlib.h>
|
|---|
| 25 |
|
|---|
| 26 | #ifndef USE_MW_HEADERS
|
|---|
| 27 | #include <sys/time.h>
|
|---|
| 28 | #include <sys/resource.h>
|
|---|
| 29 | #endif
|
|---|
| 30 |
|
|---|
| 31 | #include <Types.h>
|
|---|
| 32 | #include <Files.h>
|
|---|
| 33 |
|
|---|
| 34 | #include <Timer.h>
|
|---|
| 35 |
|
|---|
| 36 | /* Initialize to 0 at first, then set to errno_max() later. */
|
|---|
| 37 |
|
|---|
| 38 | int sys_nerr = 0;
|
|---|
| 39 |
|
|---|
| 40 | /* Debug flag for pathname hacking. Set this to one and rebuild. */
|
|---|
| 41 |
|
|---|
| 42 | int DebugPI = -1;
|
|---|
| 43 |
|
|---|
| 44 | void
|
|---|
| 45 | mpwify_filename(char *unixname, char *macname)
|
|---|
| 46 | {
|
|---|
| 47 | int i, j;
|
|---|
| 48 |
|
|---|
| 49 | /* (should truncate 255 chars from end of name, not beginning) */
|
|---|
| 50 | if (strlen (unixname) > 255)
|
|---|
| 51 | {
|
|---|
| 52 | fprintf (stderr, "Pathname \"%s\" is too long for Macs, truncating\n",
|
|---|
| 53 | unixname);
|
|---|
| 54 | }
|
|---|
| 55 | j = 0;
|
|---|
| 56 | /* If you're going to end up with one or more colons in the middle of a
|
|---|
| 57 | path after an all-Unix relative path is translated, you must add a
|
|---|
| 58 | colon on the front, so that the first component is not thought to be
|
|---|
| 59 | a disk name. */
|
|---|
| 60 | if (unixname[0] != '/' && ! strchr (unixname, ':') && strchr (unixname, '/'))
|
|---|
| 61 | {
|
|---|
| 62 | macname[j++] = ':';
|
|---|
| 63 | }
|
|---|
| 64 | for (i = 0; unixname[i] != '\0' && i < 255; ++i)
|
|---|
| 65 | {
|
|---|
| 66 | if (i == 0 && unixname[i] == '/')
|
|---|
| 67 | {
|
|---|
| 68 | if (strncmp (unixname, "/tmp/", 5) == 0)
|
|---|
| 69 | {
|
|---|
| 70 | /* A temporary name, make a more Mac-flavored tmpname. */
|
|---|
| 71 | /* A better choice would be {Boot}Trash:foo, but
|
|---|
| 72 | that would require being able to identify the
|
|---|
| 73 | boot disk's and trashcan's name. Another option
|
|---|
| 74 | would be to have an env var, so user can point it
|
|---|
| 75 | at a ramdisk. */
|
|---|
| 76 | macname[j++] = ':';
|
|---|
| 77 | macname[j++] = 't';
|
|---|
| 78 | macname[j++] = 'm';
|
|---|
| 79 | macname[j++] = 'p';
|
|---|
| 80 | macname[j++] = '_';
|
|---|
| 81 | i += 4;
|
|---|
| 82 | }
|
|---|
| 83 | else
|
|---|
| 84 | {
|
|---|
| 85 | /* Don't copy the leading slash. */
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 | else if (unixname[i] == ':' && unixname[i+1] == '/')
|
|---|
| 89 | {
|
|---|
| 90 | macname[j++] = ':';
|
|---|
| 91 | i += 1;
|
|---|
| 92 | }
|
|---|
| 93 | else if (unixname[i] == '.' && unixname[i+1] == '/')
|
|---|
| 94 | {
|
|---|
| 95 | macname[j++] = ':';
|
|---|
| 96 | i += 1;
|
|---|
| 97 | }
|
|---|
| 98 | else if (unixname[i] == '.' && unixname[i+1] == '.' && unixname[i+2] == '/')
|
|---|
| 99 | {
|
|---|
| 100 | macname[j++] = ':';
|
|---|
| 101 | macname[j++] = ':';
|
|---|
| 102 | i += 2;
|
|---|
| 103 | }
|
|---|
| 104 | else if (unixname[i] == '/')
|
|---|
| 105 | {
|
|---|
| 106 | macname[j++] = ':';
|
|---|
| 107 | }
|
|---|
| 108 | else
|
|---|
| 109 | {
|
|---|
| 110 | macname[j++] = unixname[i];
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 | macname[j] = '\0';
|
|---|
| 114 | /* Allow for getting the debug flag from an env var; quite useful. */
|
|---|
| 115 | if (DebugPI < 0)
|
|---|
| 116 | DebugPI = (*(getenv ("DEBUG_PATHNAMES")) == '1' ? 1 : 0);
|
|---|
| 117 | if (DebugPI)
|
|---|
| 118 | {
|
|---|
| 119 | fprintf (stderr, "# Made \"%s\"\n", unixname);
|
|---|
| 120 | fprintf (stderr, "# into \"%s\"\n", macname);
|
|---|
| 121 | }
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | /* MPW-flavored basename finder. */
|
|---|
| 125 |
|
|---|
| 126 | char *
|
|---|
| 127 | mpw_basename (name)
|
|---|
| 128 | char *name;
|
|---|
| 129 | {
|
|---|
| 130 | char *base = name;
|
|---|
| 131 |
|
|---|
| 132 | while (*name)
|
|---|
| 133 | {
|
|---|
| 134 | if (*name++ == ':')
|
|---|
| 135 | {
|
|---|
| 136 | base = name;
|
|---|
| 137 | }
|
|---|
| 138 | }
|
|---|
| 139 | return base;
|
|---|
| 140 | }
|
|---|
|
|---|