2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: CmdLineApp.h /main/1 1996/07/29 16:47:46 cde-hp $ */
24 // Copyright (c) 1996 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef CmdLineApp_INCLUDED
28 #define CmdLineApp_INCLUDED 1
34 #include "MessageReporter.h"
38 #include "CodingSystem.h"
39 #include "OutputCharStream.h"
46 #if defined(linux) || defined(CSRG_BASED)
54 namespace SP_NAMESPACE {
57 class SP_API CmdLineApp : public MessageReporter {
60 #define AppChar wchar_t
65 int run(int argc, AppChar **argv);
66 virtual int processOptions(int argc, AppChar **argv, int &nextArg);
67 virtual void processOption(AppChar opt, const AppChar *arg);
68 virtual int processArguments(int argc, AppChar **files) = 0;
69 static Boolean openFilebufWrite(filebuf &file, const AppChar *filename);
70 StringC usageString();
71 static const CodingSystem *codingSystem();
72 static const CodingSystem *lookupCodingSystem(const AppChar *);
73 static const CodingSystem *codingSystem(size_t, const char *&);
74 static StringC convertInput(const AppChar *s);
75 OutputCharStream *makeStdOut();
76 static OutputCharStream *makeStdErr();
78 virtual void registerOption(AppChar c, const AppChar *argName = 0);
79 virtual int init(int argc, AppChar **argv);
80 const AppChar *errorFile_;
81 const CodingSystem *outputCodingSystem_;
82 String<AppChar> optstr_;
83 Vector<const AppChar *> optArgNames_;
85 Boolean getMessageText(const MessageFragment &, StringC &);
86 static const CodingSystem *codingSystem_;
90 #define SP_DEFINE_APP(CLASS) \
92 wmain(int argc, wchar_t **argv) { CLASS app; return app.run(argc, argv); }
94 #define SP_DEFINE_APP(CLASS) \
95 int main(int argc, char **argv) { CLASS app; return app.run(argc, argv); }
102 #endif /* not CmdLineApp_INCLUDED */