Kitlist
A list manager for maintaining kit lists
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2
3 This file is part of Kitlist, a program to maintain a simple list
4 of items and assign items to one or more categories.
5
6 Copyright (C) 2008-2025 Frank Dean
7
8 Kitlist is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 Kitlist is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Kitlist. If not, see <http://www.gnu.org/licenses/>.
20
21*/
22#include "config.h"
23#ifdef HAVE_GUI
24#include "kitlistgui.hpp"
25#endif
26#ifdef HAVE_FINALCUT
27#include "kitlist_finalcut.hpp"
28#endif
29#ifdef HAVE_FTXUI
30#include "kitlist_ftxui.hpp"
31#endif
32#ifdef HAVE_GETOPT_H
33#include <getopt.h>
34#endif
35#include <exception>
36#include <iostream>
37
69
70#ifndef HAVE_GUI
71
72int main(int argc, char* argv[])
73{
74
75 auto show_version = [] {
76 std::cout << PACKAGE_NAME << " version " << PACKAGE_VERSION << std::endl;
77 };
78
79 auto simple_usage = [=] {
80 std::cout << "Usage:\n " << argv[0] << " [OPTIONS] FILE\n\n"
81 << "Options:\n";
82 std::cout << " -h, --help\t\t\t";
83 std::cout << "show this help, then exit\n";
84 std::cout << " -v, --version\t\t\t";
85 std::cout << "show version information, then exit\n";
86
87 };
88 (void) simple_usage; // Disable unused-variable compiler warning when not
89 // used simply due to conditional defines.
90
91 auto usage = [=] {
92 simple_usage();
93#ifdef HAVE_FINALCUT
94 std::cout << " -t, --finalcut\t\t";
95 std::cout << "run with FINALCUT user interface\n";
96#endif
97#ifdef HAVE_FTXUI
98 std::cout << " -x, --ftxui\t\t\t";
99 std::cout << "run with FTXUI user interface\n";
100#endif
101 };
102
103 std::string filename;
104#ifdef HAVE_FTXUI
105 int ftx_flag = 0;
106#endif
107#ifdef HAVE_FINALCUT
108 int fcut_flag = 0;
109#endif
110
111 std::string my_arg_options{"vh"};
112#ifdef HAVE_FINALCUT
113 my_arg_options += "t";
114#endif // HAVE_FINAL_CUT
115#ifdef HAVE_FTXUI
116 my_arg_options += "x";
117#endif // HAVE_FTXUI
118
119#ifdef HAVE_GETOPT_H
120
121 struct option long_options[] = {
122 // Name Argument Flag Shortname
123 {"help", no_argument, nullptr, 'h'},
124 {"version", no_argument, nullptr, 'v'},
125#ifdef HAVE_FTXUI
126 {"ftxui", no_argument, &ftx_flag, 'x'},
127#endif
128#ifdef HAVE_FINALCUT
129 {"finalcut", no_argument, &fcut_flag, 't'},
130#endif
131 {nullptr, 0, nullptr, 0}
132 };
133
134 int ch, option_index;
135 while ((ch = getopt_long(argc, argv,
136 my_arg_options.c_str(),
137 long_options,
138 &option_index)) != -1) {
139 switch (ch) {
140 case 0:
141 break;
142#ifdef HAVE_FINALCUT
143 case 't':
144 fcut_flag = true;
145 break;
146#endif
147#ifdef HAVE_FTXUI
148 case 'x':
149 ftx_flag = true;
150 break;
151#endif
152 case 'v':
153 show_version();
154 exit(0xFF);
155 break;
156 case '?':
157 [[fallthrough]];
158 default:
159 usage();
160 exit(0xFF);
161 }
162 }
163
164 if (optind > 0 && optind < argc)
165 filename = std::string{argv[argc -1]};
166
167#else // !HAVE_GETOPT_H
168
169 for (int i = 1; i < argc; i++) {
170 std::string arg{argv[i]};
171 if (arg == "-v" || arg == "--version") {
172 show_version();
173 exit(0xFF);
174#ifdef HAVE_FINALCUT
175 } else if (arg == "-t" || arg == "--finalcut") {
176 fcut_flag = true;
177#endif
178#ifdef HAVE_FTXUI
179 } else if (arg == "-x" || arg == "--ftxui") {
180 ftx_flag = true;
181#endif
182 } else if (arg == "--") {
183 break;
184 } else if (arg == "-h" || arg == "--help") {
185 usage();
186 exit(0xFF);
187 } else if (arg.starts_with('-')) {
188 arg.erase(0, 1);
189 std::cout << argv[0] << ": illegal option -- " << arg << '\n';
190 usage();
191 exit(0xFF);
192 } else {
193 filename = arg;
194 }
195 }
196#endif // HAVE_GETOPT_H
197
198#ifdef HAVE_FINALCUT
199#ifdef HAVE_FTXUI
200 if (! (fcut_flag || ftx_flag))
201 ftx_flag = true;
202#else
203 fcut_flag = true;
204#endif // HAVE_FTXUI
205#else
206#ifdef HAVE_FTXUI
207 ftx_flag = true;
208#endif
209#endif // HAVE_FINALCUT
210
211 try {
212#ifdef HAVE_FTXUI
213 if (ftx_flag) {
214 if (filename.empty()) {
215 usage();
216 exit(0xFF);
217 }
218 KitListFtxui ftxui_app;
219 ftxui_app.run(filename);
220 }
221#endif // HAVE_FTXUI
222#ifdef HAVE_FINALCUT
223 if (fcut_flag) {
224 fdsd::fc::KitListFinalcut finalcut_app;
225 finalcut_app.run(argc, argv, filename);
226 }
227#else // HAVE_FILECUT
228#ifndef HAVE_FTXUI
229 std::cerr << "\nERROR: " << PACKAGE_NAME
230 << " has been built without enabling an interface.\n"
231 << "Configure with at least one of "
232 << "'--enable-gui', '--enable-ftxui' or\n'--enable-finalcut'. "
233 << "Run 'configure --help' in the source folder "
234 << "to see the\navailable options.\n"
235 << std::endl;
236#endif // HAVE_FTXUI
237#endif // HAVE_FINALCUT
238 } catch (const std::exception& e) {
239 std::cerr << "Exception: " << e.what() << std::endl;
240 }
241} // main
242
243#else // ifndef HAVE_GUI
244// This defines the equivalent of main() for the current platform.
245wxIMPLEMENT_APP(KitListGui);
246#endif
Implements a GUI front-end for the application using wxWidgets.
Main Text-based User Interface (FINALCUT) for the application.
int run(int argc, char *argv[], const std::string filename)
Runs the FINAL CUT text based user interface.
int main(int argc, char *argv[])
Definition main.cpp:72
Copyright 2008-2025 Frank Dean