1 #ifndef MTOOLS_MAINLOOP_H
2 #define MTOOLS_MAINLOOP_H
4 /* Copyright 1997,2001,2002,2007-2009 Alain Knaff.
5 * This file is part of mtools.
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.
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.
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/>.
21 #include <sys/param.h>
23 #include "mtoolsDirentry.h"
25 typedef struct MainParam_t {
26 /* stuff needing to be initialised by the caller */
27 int (*loop)(Stream_t *Dir, struct MainParam_t *mp,
28 const char *filename);
29 int (*dirCallback)(direntry_t *, struct MainParam_t *);
30 int (*callback)(direntry_t *, struct MainParam_t *);
31 int (*unixcallback)(struct MainParam_t *mp);
33 void *arg; /* command-specific parameters
34 * to be passed to callback */
36 int openflags; /* flags used to open disk */
37 int lookupflags; /* flags used to lookup up using vfat_lookup */
38 int fast_quit; /* for commands manipulating multiple files, quit
39 * as soon as even _one_ file has a problem */
41 char *shortname; /* where to put the short name of the matched file */
42 char *longname; /* where to put the long name of the matched file */
47 direntry_t *direntry; /* dir of this entry */
48 char *unixSourceName; /* filename of the last opened Unix source
49 * file (Unix equiv of Dos direntry) */
51 Stream_t *targetDir; /* directory where to place files */
52 char *unixTarget; /* directory on Unix where to put files */
54 const char *targetName; /* basename of target file, or NULL if same
55 * basename as source should be conserved */
57 char *originalArg; /* original argument, complete with wildcards */
58 int basenameHasWildcard; /* true if there are wildcards in the
63 char mcwd[MAX_PATH+4];
65 char *fileName; /* resolved Unix filename */
67 char targetBuffer[4*MAX_VNAMELEN+1]; /* buffer for target name */
70 void init_mp(MainParam_t *MainParam);
71 int main_loop(MainParam_t *MainParam, char **argv, int argc);
73 int target_lookup(MainParam_t *mp, const char *arg);
75 Stream_t *open_root_dir(unsigned char drivename, int flags, int *isRop);
77 const char *mpGetBasename(MainParam_t *mp); /* statically allocated
80 void mpPrintFilename(FILE *file, MainParam_t *mp);
81 const char *mpPickTargetName(MainParam_t *mp); /* statically allocated string */
83 char *mpBuildUnixFilename(MainParam_t *mp); /* dynamically allocated, must
86 int isSpecial(const char *name);
88 int isSpecialW(const wchar_t *name);
90 #define isSpecialW isSpecial
93 #define MISSED_ONE 2 /* set if one cmd line argument didn't match any files */
94 #define GOT_ONE 4 /* set if a match was found, used for exit status */
95 #define NO_CWD 8 /* file not found while looking for current working
97 #define ERROR_ONE 16 /* flat out error, such as problems with target file,
98 interrupt by user, etc. */
99 #define STOP_NOW 32 /* stop as soon as possible, not necessarily an error */