Initial import package mtools: Programs for accessing MS-DOS disks without mounting...
[profile/ivi/mtools.git] / mainloop.h
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 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);
32
33         void *arg; /* command-specific parameters
34                     * to be passed to callback */
35
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 */
40
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 */
43
44         /* out parameters */
45         Stream_t *File;
46
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) */
50
51         Stream_t *targetDir; /* directory where to place files */
52         char *unixTarget; /* directory on Unix where to put files */
53
54         const char *targetName; /* basename of target file, or NULL if same
55                                  * basename as source should be conserved */
56
57         char *originalArg; /* original argument, complete with wildcards */
58         int basenameHasWildcard; /* true if there are wildcards in the
59                                   * basename */
60
61
62         /* internal data */
63         char mcwd[MAX_PATH+4];
64
65         char *fileName; /* resolved Unix filename */
66
67         char targetBuffer[4*MAX_VNAMELEN+1]; /* buffer for target name */
68 } MainParam_t;
69
70 void init_mp(MainParam_t *MainParam);
71 int main_loop(MainParam_t *MainParam, char **argv, int argc);
72
73 int target_lookup(MainParam_t *mp, const char *arg);
74
75 Stream_t *open_root_dir(unsigned char drivename, int flags, int *isRop);
76
77 const char *mpGetBasename(MainParam_t *mp); /* statically allocated
78                                              * string */
79
80 void mpPrintFilename(FILE *file, MainParam_t *mp);
81 const char *mpPickTargetName(MainParam_t *mp); /* statically allocated string */
82
83 char *mpBuildUnixFilename(MainParam_t *mp); /* dynamically allocated, must
84                                              * be freed */
85
86 int isSpecial(const char *name);
87 #ifdef HAVE_WCHAR_H
88 int isSpecialW(const wchar_t *name);
89 #else
90 #define isSpecialW isSpecial
91 #endif
92
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
96                       * directory */
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 */
100
101 #endif