/** -*- erwin-c -*- erwin - really simple html editor Copyright (C) 2002 Adrian Reber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA File: startup.c Description: startup functions Changes: 04 Jul 2002: created */ /* $Id: startup.c,v 1.14 2004/07/03 20:14:25 erwin Exp $ */ #ifndef lint static const char vcid[] = "$Id: startup.c,v 1.14 2004/07/03 20:14:25 erwin Exp $"; #endif /* lint */ #include #include #include #include "configuration.h" #include "erwindef.h" #include "recent.h" extern gchar license[]; extern int _debug_; extern GtkWidget *main_window; #ifdef ENABLE_DEBUG_OUTPUT #define _DEBUG_ if(_debug_) #else #define _DEBUG_ if(0) #endif void show_help() { fprintf(stderr, "Usage: %s [options] file\n\n", PACKAGE); fprintf(stderr, "%s is a really simple html editor\n\n", PACKAGE); fprintf(stderr, "Options:\n"); fprintf(stderr, " -h, --help Display help information.\n"); fprintf(stderr, " -v, --version Show version information.\n"); fprintf(stderr, " -a, --advise Help me now!\n"); fprintf(stderr, " -d, --debug Enable debug output.\n"); fprintf(stderr, " --author Show author information.\n"); fprintf(stderr, " --license Show license information.\n"); fprintf(stderr, " --url URL of the homepage.\n"); fprintf(stderr, "\n"); fprintf(stderr, "Arguments:\n"); fprintf(stderr, " file File to load\n"); } void print_version() { fprintf(stderr, "build with GTK+: %d.%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION); fprintf(stderr, "running with GTK+: %d.%d.%d\n", gtk_major_version, gtk_minor_version, gtk_micro_version); fprintf(stderr, "%s: %s\n", PACKAGE, VERSION); } void dump_license() { fprintf(stderr, "This program is distributed under the terms of the GPL v2.\n\n"); fprintf(stderr, "%s", license); } void show_authors() { fprintf(stderr, "%s was written by\n", PACKAGE); fprintf(stderr, " Davig Vogler \n"); fprintf(stderr, " Adrian Reber \n"); } char *parse_args(int *argc, char **argv) { int i; for (i = 1; i < *argc; ++i) { if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--debug") == 0)) { #ifdef ENABLE_DEBUG_OUTPUT _debug_ = 1; #else _debug_ = 0; #endif /* ENABLE_DEBUG_OUTPUT */ if (_debug_) { fprintf(stderr, "%s:debug output enabled\n", PACKAGE); } else { fprintf(stderr, "%s:not with debug support compiled - no debug output\n", PACKAGE); } } else if ((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)) { show_help(); exit(1); } else if ((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--version") == 0)) { print_version(); exit(1); } else if ((strcmp(argv[i], "--license") == 0)) { dump_license(); exit(42); } else if ((strcmp(argv[i], "--authors") == 0)) { show_authors(); exit(42); } else if ((strcmp(argv[i], "--url") == 0)) { fprintf(stderr, "http://lisas.de/erwin/\n"); exit(41); } else if ((strcmp(argv[i], "-a") == 0) || (strcmp(argv[i], "--advise") == 0)) { fprintf(stderr, "Don't Panic!\n"); exit(42); } else { if ((argv[i][0] == 45) || (argv[i][1] == 45)) { fprintf(stderr, "Error on option %s: unkown option.\n", (argv[i])); fprintf(stderr, "Run '%s --help' to see a full list of available command line options.", PACKAGE); exit(1); } else return argv[i]; } } return NULL; } void save_recent() { gchar *error; gchar recent[10]; gint i; for (i = 0; i < globals.number_of_recent; i++) { snprintf(recent, 10, "recent%d", i); if (get_recent(i)) config_set_string(recent, get_recent(i), &error); } } void the_end() { gint x, y; gchar *error; gtk_window_get_position(GTK_WINDOW(main_window), &x, &y); config_set_int("width", main_window->allocation.width, &error); config_set_int("height", main_window->allocation.height, &error); config_set_int("xpos", x, &error); config_set_int("ypos", y, &error); config_set_int("display_statistic", globals.display_statistic, &error); config_set_int("show_quickstart", globals.show_quickstart, &error); config_set_int("number_of_recent", globals.number_of_recent, &error); config_set_string("default_highlighting", globals.default_highlighting, &error); if (globals.default_highlighting) free(globals.default_highlighting); globals.default_highlighting = NULL; save_recent(); config_sync(); _DEBUG_ dump_recent(); fprintf(stderr, "Not a Substitute for Human Interaction\n"); } void sighandler(int i) { if (i == 2) { _DEBUG_ fprintf(stderr, "%s:SIGINT received...\n", PACKAGE); } else { _DEBUG_ fprintf(stderr, "%s:SIGTERM received...\n", PACKAGE); } _DEBUG_ fprintf(stderr, "%s:cleaning up...\n", PACKAGE); the_end(); exit(0); } void populate_recent() { gchar *error; gchar recent[10]; gint i; for (i = globals.number_of_recent + 1; i >= 0; i--) { snprintf(recent, 10, "recent%d", i); if (config_get_string(recent, &error)) add_to_recent(config_get_string(recent, &error)); } }