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