1/* 2 See license.txt in the root of this project. 3*/ 4 5# ifndef LMT_UTILITIES_FILE_H 6# define LMT_UTILITIES_FILE_H 7 8/*tex 9 10 We have to deal with wide characters on windows when it comes to filenames. The same is true for 11 the commandline and environment variables. Basically we go from utf8 to wide and back. 12 13 \starttyping 14 libraries/zlib/crc32.c : fopen -> minimalistic, goes via lua anyway 15 libraries/zlib/trees.c : fopen -> minimalistic, goes via lua anyway 16 libraries/zlib/zutil.h : fopen -> minimalistic, goes via lua anyway 17 18 lua/llualib.c : fopen -> utf8_fopen 19 lua/lenginelib.c : fopen -> utf8_fopen 20 21 luacore/lua54/src/lauxlib.c : fopen -> see below 22 luacore/lua54/src/liolib.c : fopen -> see below 23 luacore/lua54/src/loadlib.c : fopen -> see below 24 25 luaffi/call.c : fopen -> not used 26 27 mp/mpw/mp.w : fopen -> overloaded by callback 28 29 libraries/pplib/ppload.c : fopen -> will be abstraction (next pplib) 30 31 libraries/pplib/util/utiliof.c : fopen -> not used 32 libraries/pplib/util/utiliof.c : fopen -> not used 33 libraries/pplib/util/utiliof.c : fopen -> not used 34 libraries/pplib/util/utiliof.c : fopen -> not used 35 libraries/pplib/util/utiliof.c : fopen -> not used 36 libraries/pplib/util/utiliof.c : fopen -> not used 37 libraries/pplib/util/utiliof.c : fopen -> not used 38 libraries/pplib/util/utiliof.c : fopen -> not used 39 libraries/pplib/util/utiliof.c : fopen -> not used 40 libraries/pplib/util/utiliof.c : fopen -> not used 41 libraries/pplib/util/utiliof.c : fopen -> not used 42 libraries/pplib/util/utiliof.c : fopen -> not used 43 44 tex/texfileio.c 12: : fopen -> utf8_fopen 45 \stoptyping 46 47 Furthermore: 48 49 \starttyping 50 - system commands (execute) : done 51 - popen : done 52 53 - lua rename : done 54 - lua remove : done 55 56 - command line argv : done 57 - lua setenv : done 58 - lua getenv : done 59 60 - lfs attributes : done 61 - lfs chdir : done 62 - lfs currentdir : done 63 - lfs dir : done 64 - lfs mkdir : done 65 - lfs rmdir : done 66 - lfs touch : done 67 - lfs link : done 68 - lfs symlink : done 69 - lfs setexecutable : done (needs testing) 70 - lfs isdir : done 71 - lfs isfile : done 72 - lfs iswriteabledir : done 73 - lfs iswriteablefile : done 74 - lfs isreadabledir : done 75 - lfs isreadablefile : done 76 \stoptyping 77 78 Kind of tricky because quite some code (indirectness): 79 80 \starttyping 81 - lua load : via overload ? 82 - lua dofile : via overload -> loadstring 83 - lua require : via overload ? 84 \stoptyping 85 86 So: do we patch lua (fopen) or just copy? We can actually assume flat ascii files for libraries 87 and such so there is no real need unless we load job related files. 88 89 I will probably reshuffle some code and maybe more some more here; once I'm sure all works out 90 well. 91 92*/ 93 94# ifdef _WIN32 95 96 # include <windows.h> 97 # include <ctype.h> 98 # include <stdio.h> 99 100 extern LPWSTR aux_utf8_to_wide (const char *utf8str); 101 extern char *aux_utf8_from_wide (LPWSTR widestr); 102 103 extern FILE *aux_utf8_fopen (const char *path, const char *mode); 104 extern FILE *aux_utf8_popen (const char *path, const char *mode); 105 extern int aux_utf8_system (const char *cmd); 106 extern int aux_utf8_remove (const char *name); 107 extern int aux_utf8_rename (const char *oldname, const char *newname); 108 extern int aux_utf8_setargv (char * **av, char **argv, int argc); 109 extern char *aux_utf8_getownpath (const char *file); 110 extern char *aux_utf8_readlink (const char *file); 111 112# else 113 114 # define aux_utf8_fopen fopen 115 # define aux_utf8_popen popen 116 # define aux_utf8_system system 117 # define aux_utf8_remove remove 118 # define aux_utf8_rename rename 119 120 extern int aux_utf8_setargv (char * **av, char **argv, int argc); 121 extern char *aux_utf8_getownpath (const char *file); 122 extern char *aux_utf8_readlink (const char *file); 123 124 # include <libgen.h> 125 126# endif 127 128# ifdef _WIN32 129 130 extern char *aux_basename (const char *name); 131 extern char *aux_dirname (const char *name); 132 133# else 134 135 # define aux_basename basename 136 # define aux_dirname dirname 137 138# endif 139 140extern int aux_is_readable (const char *filename); 141 142/*tex 143 144 We support unix and windows. In fact, we could stick to |/| only. When 145 scanning filenames entered in \TEX\ we can actually enforce a |/| as 146 convention. 147 148*/ 149 150# ifndef IS_DIR_SEP 151 # ifdef _WIN32 152 # define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\') 153 # else 154 # define IS_DIR_SEP(ch) ((ch) == '/') 155 # endif 156# endif 157 158# ifndef R_OK 159 # define F_OK 0x0 160 # define W_OK 0x2 161 # define R_OK 0x4 162# endif 163 164# ifndef S_ISREG 165 # define S_ISREG(mode) (mode & _S_IFREG) 166# endif 167 168# endif 169 |