void quit_cb (int i) { procclean(); if ((!tracemode) && (!DEBUG)) exit_ui(); exit(0); }
int main(int argc, char **argv) { int i; bool no_filenames = true; init_qt(&argc, &argv); QStringList files; QStringList importedFiles; QStringList arguments = QCoreApplication::arguments(); bool dedicated_console = arguments.length() > 1 && (arguments.at(1) == QString("--win32console")); subsurface_console_init(dedicated_console); for (i = 1; i < arguments.length(); i++) { QString a = arguments.at(i); if (a.at(0) == '-') { parse_argument(a.toLocal8Bit().data()); continue; } if (imported) { importedFiles.push_back(a); } else { no_filenames = false; files.push_back(a); } } #if !LIBGIT2_VER_MAJOR && LIBGIT2_VER_MINOR < 22 git_threads_init(); #else git_libgit2_init(); #endif setup_system_prefs(); prefs = default_prefs; fill_profile_color(); parse_xml_init(); taglist_init_global(); init_ui(); if (no_filenames) { QString defaultFile(prefs.default_filename); if (!defaultFile.isEmpty()) files.push_back(QString(prefs.default_filename)); } MainWindow *m = MainWindow::instance(); m->setLoadedWithFiles(!files.isEmpty() || !importedFiles.isEmpty()); m->loadFiles(files); m->importFiles(importedFiles); if (!quit) run_ui(); exit_ui(); taglist_free(g_tag_list); parse_xml_exit(); subsurface_console_exit(); free_prefs(); return 0; }
void clean_up() { //close file descriptors for(std::vector<int>::const_iterator it=pc_loop_fd_list.begin(); it != pc_loop_fd_list.end(); ++it) { close(*it); } procclean(); if ((!tracemode) && (!DEBUG)) exit_ui(); }
void forceExit(const char *msg, const char* msg2) { if ((!tracemode)&&(!DEBUG)){ exit_ui(); } std::cerr << msg; if (msg2 != NULL) { std::cerr << msg2; } std::cerr << std::endl; exit(0); }
void forceExit(bool success, const char *msg, ...) { if ((!tracemode)&&(!DEBUG)){ exit_ui(); } va_list argp; va_start(argp, msg); vfprintf(stderr, msg, argp); va_end(argp); std::cerr << std::endl; if (success) exit(EXIT_SUCCESS); else exit(EXIT_FAILURE); }
int main(int argc, char **argv) { int i; bool no_filenames = true; setup_system_prefs(); prefs = default_prefs; init_ui(&argc, &argv); parse_xml_init(); taglist_init_global(); QStringList files; QStringList importedFiles; QStringList arguments = QCoreApplication::arguments(); for (i = 1; i < arguments.length(); i++) { QString a = arguments.at(i); if (a.at(0) == '-') { parse_argument(a.toLocal8Bit().data()); continue; } if (imported) { importedFiles.push_back(a); } else { no_filenames = false; files.push_back(a); } } if (no_filenames) { QString defaultFile(prefs.default_filename); if (!defaultFile.isEmpty()) files.push_back( QString(prefs.default_filename) ); } parse_xml_exit(); MainWindow::instance()->loadFiles(files); MainWindow::instance()->importFiles(importedFiles); if (!quit) run_ui(); exit_ui(); return 0; }
int main(int argc, char **argv) { int i; bool no_filenames = true; QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); QApplication *application = new QApplication(argc, argv); (void)application; QStringList files; QStringList importedFiles; QStringList arguments = QCoreApplication::arguments(); bool dedicated_console = arguments.length() > 1 && (arguments.at(1) == QString("--win32console")); subsurface_console_init(dedicated_console); for (i = 1; i < arguments.length(); i++) { QString a = arguments.at(i); if (a.at(0) == '-') { parse_argument(a.toLocal8Bit().data()); continue; } if (imported) { importedFiles.push_back(a); } else { no_filenames = false; files.push_back(a); } } #if !LIBGIT2_VER_MAJOR && LIBGIT2_VER_MINOR < 22 git_threads_init(); #else git_libgit2_init(); #endif setup_system_prefs(); if (uiLanguage(0).contains("-US")) default_prefs.units = IMPERIAL_units; prefs = default_prefs; fill_profile_color(); parse_xml_init(); taglist_init_global(); init_ui(); loadPreferences(); // some hard coded settings prefs.animation_speed = 0; // we render the profile to pixmap, no animations // always show the divecomputer reported ceiling in red prefs.dcceiling = 1; prefs.redceiling = 1; init_proxy(); if (no_filenames) { if (prefs.default_file_behavior == LOCAL_DEFAULT_FILE) { QString defaultFile(prefs.default_filename); if (!defaultFile.isEmpty()) files.push_back(QString(prefs.default_filename)); } else if (prefs.default_file_behavior == CLOUD_DEFAULT_FILE) { QString cloudURL; if (getCloudURL(cloudURL) == 0) files.push_back(cloudURL); } } if (!quit) run_ui(); exit_ui(); taglist_free(g_tag_list); parse_xml_exit(); subsurface_console_exit(); free_prefs(); return 0; }
int main(int argc, char **argv) { int i; bool no_filenames = true; QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); QApplication *application = new QApplication(argc, argv); (void)application; QStringList files; QStringList importedFiles; QStringList arguments = QCoreApplication::arguments(); bool dedicated_console = arguments.length() > 1 && (arguments.at(1) == QString("--win32console")); subsurface_console_init(dedicated_console); const char *default_directory = system_default_directory(); const char *default_filename = system_default_filename(); subsurface_mkdir(default_directory); for (i = 1; i < arguments.length(); i++) { QString a = arguments.at(i); if (a.isEmpty()) continue; if (a.at(0) == '-') { parse_argument(a.toLocal8Bit().data()); continue; } if (imported) { importedFiles.push_back(a); } else { no_filenames = false; files.push_back(a); } } #if !LIBGIT2_VER_MAJOR && LIBGIT2_VER_MINOR < 22 git_threads_init(); #else git_libgit2_init(); #endif setup_system_prefs(); copy_prefs(&default_prefs, &prefs); fill_profile_color(); parse_xml_init(); taglist_init_global(); init_ui(); if (no_filenames) { if (prefs.default_file_behavior == LOCAL_DEFAULT_FILE) { QString defaultFile(prefs.default_filename); if (!defaultFile.isEmpty()) files.push_back(QString(prefs.default_filename)); } else if (prefs.default_file_behavior == CLOUD_DEFAULT_FILE) { QString cloudURL; if (getCloudURL(cloudURL) == 0) files.push_back(cloudURL); } } MainWindow *m = MainWindow::instance(); filesOnCommandLine = !files.isEmpty() || !importedFiles.isEmpty(); m->loadFiles(files); m->importFiles(importedFiles); // in case something has gone wrong make sure we show the error message m->showError(); // now let's set up some connections QObject::connect(m->graphics(), &ProfileWidget2::enableToolbar ,m, &MainWindow::setEnabledToolbar, Qt::AutoConnection); QObject::connect(m->graphics(), &ProfileWidget2::showError, m, &MainWindow::showError, Qt::AutoConnection); QObject::connect(m->graphics(), &ProfileWidget2::disableShortcuts, m, &MainWindow::disableShortcuts, Qt::AutoConnection); QObject::connect(m->graphics(), &ProfileWidget2::enableShortcuts, m, &MainWindow::enableShortcuts, Qt::AutoConnection); QObject::connect(m->graphics(), &ProfileWidget2::refreshDisplay, m, &MainWindow::refreshDisplay, Qt::AutoConnection); QObject::connect(m->graphics(), &ProfileWidget2::updateDiveInfo, m->information(), &MainTab::updateDiveInfo, Qt::AutoConnection); QObject::connect(m->graphics(), &ProfileWidget2::editCurrentDive, m, &MainWindow::editCurrentDive, Qt::AutoConnection); QObject::connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), m->graphics(), SLOT(settingsChanged())); if (verbose > 0) print_files(); if (!quit) run_ui(); exit_ui(); taglist_free(g_tag_list); parse_xml_exit(); free((void *)default_directory); free((void *)default_filename); subsurface_console_exit(); free_prefs(); return 0; }
int main(int argc, char **argv) { int i; bool no_filenames = true; QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); QApplication *application = new QApplication(argc, argv); (void)application; QStringList files; QStringList importedFiles; QStringList arguments = QCoreApplication::arguments(); bool win32_log = arguments.length() > 1 && (arguments.at(1) == QString("--win32log")); if (win32_log) { subsurface_console_init(true, true); } else { bool dedicated_console = arguments.length() > 1 && (arguments.at(1) == QString("--win32console")); subsurface_console_init(dedicated_console, false); } const char *default_directory = system_default_directory(); const char *default_filename = system_default_filename(); subsurface_mkdir(default_directory); for (i = 1; i < arguments.length(); i++) { QString a = arguments.at(i); if (a.isEmpty()) continue; if (a.at(0) == '-') { parse_argument(a.toLocal8Bit().data()); continue; } if (imported) { importedFiles.push_back(a); } else { no_filenames = false; files.push_back(a); } } if (subsurface_user_is_root() && !force_root) { printf("You are running Subsurface as root. This is not recommended.\n"); printf("If you insist to do so, run with option --allow_run_as_root.\n"); exit(0); } #if !LIBGIT2_VER_MAJOR && LIBGIT2_VER_MINOR < 22 git_threads_init(); #else git_libgit2_init(); #endif /* * Initialize the random number generator - not really secure as * this is based only on current time, but it should not matter * that much in our context. Moreover this is better than * the constant numbers we used to get before. */ qsrand(time(NULL)); setup_system_prefs(); copy_prefs(&default_prefs, &prefs); fill_profile_color(); fill_computer_list(); parse_xml_init(); taglist_init_global(); init_ui(); if (no_filenames) { if (prefs.default_file_behavior == LOCAL_DEFAULT_FILE) { QString defaultFile(prefs.default_filename); if (!defaultFile.isEmpty()) files.push_back(QString(prefs.default_filename)); } else if (prefs.default_file_behavior == CLOUD_DEFAULT_FILE) { QString cloudURL; if (getCloudURL(cloudURL) == 0) files.push_back(cloudURL); } } MainWindow *m = MainWindow::instance(); filesOnCommandLine = !files.isEmpty() || !importedFiles.isEmpty(); m->loadFiles(files); m->importFiles(importedFiles); // in case something has gone wrong make sure we show the error message m->showError(); if (verbose > 0) { print_files(); printf("%s\n", QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion()).toUtf8().data()); } if (!quit) run_ui(); exit_ui(); taglist_free(g_tag_list); parse_xml_exit(); free((void *)default_directory); free((void *)default_filename); subsurface_console_exit(); free_prefs(); return 0; }
int main(int argc, char *argv[]) { const char *name; int exit_status = EXIT_FAILURE; name = (const char *)strrchr(argv[0], '/'); name = name ? (name + 1) : argv[0]; enum opt { OPT_COMMIT = 0x100 }; struct opt_help helps[] = { { 'h', "help", "Show this help message" }, { 'V', "version", "Print version information" }, #ifdef COMMIT { 0, "commit", "Display commit information" }, #endif /* COMMIT */ { 0, NULL, NULL } }; struct option opts[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, #ifdef COMMIT { "commit", no_argument, NULL, OPT_COMMIT }, #endif /* COMMIT */ { NULL, 0, NULL, 0 } }; while(1) { int c = getopt_long(argc, argv, "hV", opts, NULL); if(c == -1) break; switch(c) { #ifdef COMMIT case(OPT_COMMIT): commit(); exit_status = EXIT_SUCCESS; goto EXIT; #endif /* COMMIT */ case('V'): version(TARGET); exit_status = EXIT_SUCCESS; goto EXIT; case('h'): exit_status = EXIT_SUCCESS; default: help(name, "[OPTIONS] ... [PCAP FILE]", helps); goto EXIT; } } /* Initialise the UI. */ init_ui(exit_cb, save_cb, save_as_cb, open_cb); pcap_list_init(warn_ui); if((argc - optind) == 1) { int ret; filename = argv[optind]; ret = access(filename, R_OK); switch(ret) { case 0: pcap_list_load_from_file(filename); break; case ENOENT: break; default: err(EXIT_FAILURE, "cannot access %s", filename); } } /* Start the UI. */ main_ui(); exit_status = EXIT_SUCCESS; EXIT: exit_ui(); return exit_status; }
int main(int argc, char **argv) { int i; bool no_filenames = true; QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); QApplication *application = new QApplication(argc, argv); QStringList files; QStringList importedFiles; QStringList arguments = QCoreApplication::arguments(); bool dedicated_console = arguments.length() > 1 && (arguments.at(1) == QString("--win32console")); subsurface_console_init(dedicated_console); const char *default_directory = system_default_directory(); const char *default_filename = system_default_filename(); subsurface_mkdir(default_directory); for (i = 1; i < arguments.length(); i++) { QString a = arguments.at(i); if (a.isEmpty()) continue; if (a.at(0) == '-') { parse_argument(a.toLocal8Bit().data()); continue; } if (imported) { importedFiles.push_back(a); } else { no_filenames = false; files.push_back(a); } } #if !LIBGIT2_VER_MAJOR && LIBGIT2_VER_MINOR < 22 git_threads_init(); #else git_libgit2_init(); #endif setup_system_prefs(); copy_prefs(&default_prefs, &prefs); fill_profile_color(); parse_xml_init(); taglist_init_global(); init_ui(); if (no_filenames) { if (prefs.default_file_behavior == LOCAL_DEFAULT_FILE) { QString defaultFile(prefs.default_filename); if (!defaultFile.isEmpty()) files.push_back(QString(prefs.default_filename)); } else if (prefs.default_file_behavior == CLOUD_DEFAULT_FILE) { QString cloudURL; if (getCloudURL(cloudURL) == 0) files.push_back(cloudURL); } } MainWindow *m = MainWindow::instance(); m->setLoadedWithFiles(!files.isEmpty() || !importedFiles.isEmpty()); m->loadFiles(files); m->importFiles(importedFiles); // in case something has gone wrong make sure we show the error message m->showError(); if (verbose > 0) print_files(); if (!quit) run_ui(); exit_ui(); taglist_free(g_tag_list); parse_xml_exit(); free((void *)default_directory); free((void *)default_filename); subsurface_console_exit(); free_prefs(); return 0; }
int main(int argc, char **argv) { int i; gboolean no_filenames = TRUE; const char *path; /* set up l18n - the search directory needs to change * so that it uses the correct system directory when * subsurface isn't run from the local directory */ path = subsurface_gettext_domainpath(argv[0]); setlocale(LC_ALL, ""); bindtextdomain("subsurface", path); bind_textdomain_codeset("subsurface", "utf-8"); textdomain("subsurface"); setup_system_prefs(); prefs = default_prefs; #if DEBUGFILE > 1 debugfile = stderr; #elif defined(DEBUGFILE) debugfilename = strdup(prefs.default_filename); strncpy(debugfilename + strlen(debugfilename) - 3, "log", 3); if (g_mkdir_with_parents(g_path_get_dirname(debugfilename), 0664) != 0 || (debugfile = g_fopen(debugfilename, "w")) == NULL) printf("oh boy, can't create debugfile"); #endif subsurface_command_line_init(&argc, &argv); parse_xml_init(); init_ui(&argc, &argv); for (i = 1; i < argc; i++) { const char *a = argv[i]; if (a[0] == '-') { parse_argument(a); continue; } GError *error = NULL; /* if we have exactly one filename, parse_file will set * that to be the default. Otherwise there will be no default filename */ set_filename(NULL, TRUE); parse_file(a, &error, no_filenames); no_filenames = FALSE; if (error != NULL) { report_error(error); g_error_free(error); error = NULL; } } if (no_filenames) { GError *error = NULL; const char *filename = prefs.default_filename; parse_file(filename, &error, TRUE); /* don't report errors - this file may not exist, but make sure we remember this as the filename in use */ set_filename(filename, FALSE); } report_dives(imported, FALSE); if (dive_table.nr == 0) show_dive_info(NULL); run_ui(); exit_ui(); parse_xml_exit(); subsurface_command_line_exit(&argc, &argv); #ifdef DEBUGFILE if (debugfile) fclose(debugfile); #endif return 0; }