|
From: Brenda L. <asp...@us...> - 2003-05-13 22:27:20
|
Update of /cvsroot/squeak/squeak/platforms/unix/plugins/FilePlugin In directory sc8-pr-cvs1:/tmp/cvs-serv21322/FilePlugin Modified Files: sqUnixFile.c Log Message: Ian Piumarta's release 3.5-1devel Index: sqUnixFile.c =================================================================== RCS file: /cvsroot/squeak/squeak/platforms/unix/plugins/FilePlugin/sqUnixFile.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** sqUnixFile.c 12 May 2003 07:39:03 -0000 1.6 --- sqUnixFile.c 13 May 2003 22:27:10 -0000 1.7 *************** *** 5,8 **** --- 5,12 ---- * All rights reserved. * + * You are NOT ALLOWED to distribute modified versions of this file + * under its original name. If you want to modify it and then make + * your modifications available publicly, rename the file first. + * * This file is part of Unix Squeak. * *************** *** 13,17 **** * You may use and/or distribute this file ONLY as part of Squeak, under * the terms of the Squeak License as described in `LICENSE' in the base of ! * this distribution, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not --- 17,21 ---- * You may use and/or distribute this file ONLY as part of Squeak, under * the terms of the Squeak License as described in `LICENSE' in the base of ! * this distribution, subject to the following additional restrictions: * * 1. The origin of this software must not be misrepresented; you must not *************** *** 21,42 **** * would be appreciated but is not required. * ! * 2. This notice must not be removed or altered in any source distribution. * * Using (or modifying this file for use) in any context other than Squeak * changes these copyright conditions. Read the file `COPYING' in the * directory `platforms/unix/doc' before proceeding with any such use. - * - * You are not allowed to distribute a modified version of this file - * under its original name without explicit permission to do so. If - * you change it, rename it. */ /* Author: Ian...@IN... * ! * Last edited: 2003-02-06 16:29:22 by piumarta on emilia.local. */ #include "sq.h" #include "FilePlugin.h" #ifdef HAVE_DIRENT_H --- 25,46 ---- * would be appreciated but is not required. * ! * 2. You must not distribute (or make publicly available by any ! * means) a modified copy of this file unless you first rename it. ! * ! * 3. This notice must not be removed or altered in any source distribution. * * Using (or modifying this file for use) in any context other than Squeak * changes these copyright conditions. Read the file `COPYING' in the * directory `platforms/unix/doc' before proceeding with any such use. */ /* Author: Ian...@IN... * ! * Last edited: 2003-03-02 21:07:51 by piumarta on emilia.inria.fr */ #include "sq.h" #include "FilePlugin.h" + #include "sqUnixCharConv.h" #ifdef HAVE_DIRENT_H *************** *** 95,100 **** extern time_t convertToSqueakTime(time_t unixTime); - int maybeOpenDir(char *unixPath); - int dir_Create(char *pathString, int pathStringLength) { --- 99,102 ---- *************** *** 105,111 **** if (pathStringLength >= MAXPATHLEN) return false; ! for (i = 0; i < pathStringLength; i++) ! name[i] = pathString[i]; ! name[i] = 0; /* string terminator */ return mkdir(name, 0777) == 0; /* rwxrwxrwx & ~umask */ } --- 107,112 ---- if (pathStringLength >= MAXPATHLEN) return false; ! if (!sq2uxPath(pathString, pathStringLength, name, MAXPATHLEN, 1)) ! return false; return mkdir(name, 0777) == 0; /* rwxrwxrwx & ~umask */ } *************** *** 118,126 **** if (pathStringLength >= MAXPATHLEN) return false; ! for (i= 0; i < pathStringLength; ++i) ! name[i]= pathString[i]; ! if (!strcmp(lastPath, name)) ! lastPathValid= false; ! name[i]= '\0'; /* string terminator */ return rmdir(name) == 0; } --- 119,124 ---- if (pathStringLength >= MAXPATHLEN) return false; ! if (!sq2uxPath(pathString, pathStringLength, name, MAXPATHLEN, 1)) ! return false; return rmdir(name) == 0; } *************** *** 131,134 **** --- 129,153 ---- } + static int maybeOpenDir(char *unixPath) + { + /* if the last opendir was to the same directory, re-use the directory + pointer from last time. Otherwise close the previous directory, + open the new one, and save its name. Return true if the operation + was successful, false if not. */ + if (!lastPathValid || strcmp(lastPath, unixPath)) + { + /* invalidate the old, open the new */ + if (lastPathValid) + closedir(openDir); + lastPathValid= false; + strcpy(lastPath, unixPath); + if ((openDir= opendir(unixPath)) == 0) + return false; + lastPathValid= true; + lastIndex= 0; /* first entry is index 1 */ + } + return true; + } + int dir_Lookup(char *pathString, int pathStringLength, int index, /* outputs: */ char *name, int *nameLength, int *creationDate, int *modificationDate, *************** *** 159,174 **** if ((pathStringLength == 0)) strcpy(unixPath, "."); ! else ! { ! for (i= 0; i < pathStringLength; i++) ! unixPath[i]= pathString[i]; ! unixPath[i]= 0; ! } /* get file or directory info */ if (!maybeOpenDir(unixPath)) ! { ! return BAD_PATH; ! } if (++lastIndex == index) --- 178,187 ---- if ((pathStringLength == 0)) strcpy(unixPath, "."); ! else if (!sq2uxPath(pathString, pathStringLength, unixPath, MAXPATHLEN, 1)) ! return BAD_PATH; /* get file or directory info */ if (!maybeOpenDir(unixPath)) ! return BAD_PATH; if (++lastIndex == index) *************** *** 201,206 **** } ! strncpy(name, dirEntry->d_name, nameLen); ! *nameLength= nameLen; { --- 214,218 ---- } ! *nameLength= ux2sqPath(dirEntry->d_name, nameLen, name, MAXPATHLEN, 0); { *************** *** 231,255 **** } - int maybeOpenDir(char *unixPath) - { - /* if the last opendir was to the same directory, re-use the directory - pointer from last time. Otherwise close the previous directory, - open the new one, and save its name. Return true if the operation - was successful, false if not. */ - if (!lastPathValid || strcmp(lastPath, unixPath)) - { - /* invalidate the old, open the new */ - if (lastPathValid) - closedir(openDir); - lastPathValid= false; - strcpy(lastPath, unixPath); - if ((openDir= opendir(unixPath)) == 0) - return false; - lastPathValid= true; - lastIndex= 0; /* first entry is index 1 */ - } - return true; - } - int dir_SetMacFileTypeAndCreator(char *filename, int filenameSize, char *fType, char *fCreator) --- 243,246 ---- *************** *** 265,266 **** --- 256,294 ---- return true; } + + + #if defined(SQ_STDIO_UTF8) + + /* Intercept stdio functions to convert pathnames to UTF-8. + * (HFS+ also imposes Unicode2.1 canonically-decomposed UTF-8 encoding on all path elements; + * calling sq2uxPath() on OSX performs the required normalisation on the output path.) + * see sqUnixCharConv.c for gory details. + */ + + # undef fopen + # undef delete + # undef remove + + FILE *sq_fopen(char *path, const char *mode) + { + char normalised[MAXPATHLEN]; + sq2uxPath(path, strlen(path), normalised, MAXPATHLEN, 1); + return fopen(normalised, mode); + } + + int sq_remove(char *path) + { + char normalised[MAXPATHLEN]; + sq2uxPath(path, strlen(path), normalised, MAXPATHLEN, 1); + return remove(normalised); + } + + int sq_rename(char *from, char *to) + { + char normalisedFrom[MAXPATHLEN], normalisedTo[MAXPATHLEN]; + sq2uxPath(from, strlen(from), normalisedFrom, MAXPATHLEN, 1); + sq2uxPath(to, strlen(to), normalisedTo, MAXPATHLEN, 1); + return rename(normalisedFrom, normalisedTo); + } + + #endif /* defined(SQ_UTF8_STDIO) */ |