1 #ifndef MTOOLS_MAINLOOP_H 2 #define MTOOLS_MAINLOOP_H 3 4 /* Copyright 1997,2001,2002,2007-2009 Alain Knaff. 5 * This file is part of mtools. 6 * 7 * Mtools is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * Mtools is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with Mtools. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #include <sys/param.h> 22 #include "vfat.h" 23 #include "mtoolsDirentry.h" 24 25 typedef struct bounded_string { 26 char *data; /* storage of converted string, including final null byte */ 27 size_t len; /* max length of converted string, including final null 28 * byte */ 29 } bounded_string; 30 31 typedef struct MainParam_t { 32 /* stuff needing to be initialised by the caller */ 33 int (*loop)(Stream_t *Dir, struct MainParam_t *mp, 34 const char *filename); 35 int (*dirCallback)(direntry_t *, struct MainParam_t *); 36 int (*callback)(direntry_t *, struct MainParam_t *); 37 int (*unixcallback)(struct MainParam_t *mp); 38 39 void *arg; /* command-specific parameters 40 * to be passed to callback */ 41 42 int openflags; /* flags used to open disk */ 43 int lookupflags; /* flags used to lookup up using vfat_lookup */ 44 int fast_quit; /* for commands manipulating multiple files, quit 45 * as soon as even _one_ file has a problem */ 46 47 bounded_string shortname; /* where to put the short name of the 48 * matched file */ 49 bounded_string longname; /* where to put the long name of the 50 * matched file */ 51 /* out parameters */ 52 Stream_t *File; 53 54 direntry_t *direntry; /* dir of this entry */ 55 char *unixSourceName; /* filename of the last opened Unix source 56 * file (Unix equiv of Dos direntry) */ 57 58 Stream_t *targetDir; /* directory where to place files */ 59 char *unixTarget; /* directory on Unix where to put files */ 60 61 const char *targetName; /* basename of target file, or NULL if same 62 * basename as source should be conserved */ 63 64 char *originalArg; /* original argument, complete with wildcards */ 65 int basenameHasWildcard; /* true if there are wildcards in the 66 * basename */ 67 68 69 /* internal data */ 70 char mcwd[MAX_PATH+4]; 71 72 char *fileName; /* resolved Unix filename */ 73 74 char targetBuffer[4*MAX_VNAMELEN+1]; /* buffer for target name */ 75 } MainParam_t; 76 77 void init_mp(MainParam_t *MainParam); 78 int main_loop(MainParam_t *MainParam, char **argv, int argc); 79 80 int target_lookup(MainParam_t *mp, const char *arg); 81 82 Stream_t *open_root_dir(unsigned char drivename, int flags, int *isRop); 83 84 const char *mpGetBasename(MainParam_t *mp); /* statically allocated 85 * string */ 86 87 void mpPrintFilename(FILE *file, MainParam_t *mp); 88 const char *mpPickTargetName(MainParam_t *mp); /* statically allocated string */ 89 90 char *mpBuildUnixFilename(MainParam_t *mp); /* dynamically allocated, must 91 * be freed */ 92 93 int isSpecial(const char *name); 94 #ifdef HAVE_WCHAR_H 95 int isSpecialW(const wchar_t *name); 96 #else 97 #define isSpecialW isSpecial 98 #endif 99 100 #define MISSED_ONE 2 /* set if one cmd line argument didn't match any files */ 101 #define GOT_ONE 4 /* set if a match was found, used for exit status */ 102 #define NO_CWD 8 /* file not found while looking for current working 103 * directory */ 104 #define ERROR_ONE 16 /* flat out error, such as problems with target file, 105 interrupt by user, etc. */ 106 #define STOP_NOW 32 /* stop as soon as possible, not necessarily an error */ 107 108 #endif 109