/* Copyright (C) 1999 Southern Gold Development * * 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. */ #define IS_PIC_USER #include "gview.h" #include #ifdef HAVE_WORKING_MSG void catchHandler(int signum) { int dqueue; dqueue = msgget(34, 0); if (dqueue != -1) msgctl(dqueue, IPC_RMID, NULL); exit(1); } #endif /* HAVE_WORKING_MSG */ int main(int argc, char **argv) { GdkImlibInitParams ipa; gchar *spath, *iName, *tmpN, *tmpF, *work, *home, *fname, resChar; sgview *view; gint depth, errIn, dqueue, flag; gshort cnt; gboolean useBrowser, useMsg, forceBrowser; struct stat buff; #ifdef HAVE_WORKING_MSG nmsg msg_buffer; #endif /* HAVE_WORKING_MSG */ #ifdef HAVE_SGC sg_registry *db; sg_reg_key *key; #else FILE *fHnd; gchar *lineIn, *split; #endif /* HAVE_SGC */ gtk_set_locale(); gtk_init(&argc, &argv); gtk_rc_init(); home = getenv("HOME"); fname = g_strconcat(home, "/.gtkrc", NULL); gtk_rc_parse(fname); g_free(fname); #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif /* ENABLE_NLS */ #ifdef HAVE_SGC db = sg_registry_init("/etc/registry"); #else home = getenv("HOME"); fname = g_strconcat(home, "/.gviewrc", NULL); fHnd = fopen(fname, "rb"); g_free(fname); #endif ipa.flags = (PARAMS_IMAGECACHESIZE | PARAMS_PIXMAPCACHESIZE); ipa.imagecachesize = 0; ipa.pixmapcachesize = 0; gdk_imlib_init_params(&ipa); gdk_imlib_set_fallback(0); iName = NULL; flag = FALSE; useMsg = FALSE; useBrowser = TRUE; forceBrowser = FALSE; work = NULL; if (argc > 1) { resChar = getopt(argc, argv, "iv"); while (resChar != EOF) { switch (resChar) { case 'i': useMsg = TRUE; break; case 'v': useBrowser = TRUE; forceBrowser = TRUE; break; default: break; } resChar = getopt(argc, argv, "iv"); } if (optind < argc) work = argv[optind]; else work = NULL; } else work = NULL; #ifdef HAVE_WORKING_MSG if ((useMsg) && (work)) { dqueue = msgget(34,0); if (dqueue != -1) { msg_buffer.mtype = 4351; if (strncmp(work, "./", 2) == 0) { if (strlen(work) == 2) { tmpF = g_malloc(sizeof(gchar) * MAX_BUFF); getcwd(tmpF, MAX_BUFF); work = g_strconcat(tmpF, "/", NULL); g_free(tmpF); } else { tmpF = g_strdup(work); tmpN = tmpF; tmpN += 2; work = g_strdup(tmpN); g_free(tmpF); } flag = TRUE; } if (strncmp(work, "..", 2) == 0) { sortRel(&work); flag = TRUE; } if (work[0] != '/') { tmpF = g_malloc(sizeof(gchar) * MAX_BUFF); getcwd(tmpF, MAX_BUFF); tmpN = g_strconcat(tmpF, "/", work, NULL); strcpy(msg_buffer.mtext, tmpN); g_free(tmpN); g_free(tmpF); } else strcpy(msg_buffer.mtext, work); msgsnd(dqueue, (struct msgbuf *) &msg_buffer, MAX_BUFF, IPC_NOWAIT); if (flag) g_free(work); exit(0); } } #endif /* HAVE_WORKING_MSG */ if (work) { if (strncmp(work, "./", 2) == 0) { if (strlen(work) == 2) { tmpF = g_malloc(sizeof(gchar) * MAX_BUFF); getcwd(tmpF, MAX_BUFF); work = g_strconcat(tmpF, "/", NULL); g_free(tmpF); } else { tmpF = g_strdup(work); tmpN = tmpF; tmpN += 2; work = g_strdup(tmpN); g_free(tmpF); } flag = TRUE; } if (strncmp(work, "..", 2) == 0) { sortRel(&work); flag = TRUE; } if (work[0] != '/') { tmpF = g_malloc(sizeof(gchar) * MAX_BUFF); getcwd(tmpF, MAX_BUFF); tmpN = g_strconcat(tmpF, "/", work, NULL); g_free(tmpF); work = tmpN; } errIn = stat(work, &buff); if (errIn == -1) spath = g_strconcat(getenv("HOME"), "/", NULL); else { if (buff.st_mode & S_IFDIR) if (work[strlen(work) - 1] == '/') spath = g_strdup(work); else spath = g_strconcat(work, "/", NULL); else { tmpN = g_strdup(work); tmpF = rindex(tmpN, '/'); tmpF[0] = '\0'; tmpF++; spath = g_strconcat(tmpN, "/", NULL); iName = g_strdup(tmpF); g_free (tmpN); } } } else spath = g_strconcat(getenv("HOME"), "/", NULL); if (flag) g_free(work); view = g_malloc(sizeof(sgview) * 1); view->currPic = NULL; view->slide = NULL; view->currSlide = NULL; view->disp = NULL; view->bMenu = NULL; view->vMenu = NULL; depth = gdk_visual_get_best_depth(); #ifdef HAVE_SGC key = sg_registry_get_key(db, "Software.gView:SlideTimeOut"); if (key) { view->slideTime = (*(int *)key->value) * 1000; sg_registry_free_key(&key); } else view->slideTime = 2000; key = sg_registry_get_key(db, "Software.gView:ShowHiddenFiles"); if (key) { if (*(int *)key->value) view->statCh = 0x02; else view->statCh = 0x03; sg_registry_free_key(&key); } else view->statCh = 0x03; key = sg_registry_get_key(db, "Software.gView:DefaultGamma"); if (key) { view->defGamma = ((gfloat) *(int *)key->value) / 100; sg_registry_free_key(&key); } else view->defGamma = 1.00; key = sg_registry_get_key(db, "Software.gView:DefaultRender"); if (key) { if ((depth > 8) && (*(int *)key->value >= 4)) gdk_imlib_set_render_type(*(int *)key->value); if ((depth <= 8) && (*(int *)key->value < 4)) gdk_imlib_set_render_type(*(int *) key->value); sg_registry_free_key(&key); } key = sg_registry_get_key(db, "Software.gView:DefaultBackColor"); if (key) { view->defBackColor = g_strdup((gchar *) key->value); sg_registry_free_key(&key); } else { tmpF = back_xpm[2]; tmpF += 4; view->defBackColor = g_strdup(tmpF); } key = sg_registry_get_key(db, "Software.gView:PersistantZoom"); if (key) { if (*(int *)key->value) view->statCh = (view->statCh | 0x80); else view->statCh = (view->statCh & 0x7f); sg_registry_free_key(&key); } else { view->statCh = (view->statCh & 0x7f); } sg_registry_close(db); #else view->defBackColor = NULL; if (fHnd) { view->slideTime = 2000; view->statCh = 0x03; view->defGamma = 1.00; lineIn = getLine(fHnd); while (lineIn) { if (strncmp (lineIn, "SlideTimeOut", 12) == 0) { split = rindex(lineIn, ' '); split++; view->slideTime = atoi(split) * 1000; } if (strncmp (lineIn, "ShowHiddenFiles", 15) == 0) { split = rindex(lineIn, ' '); split++; if (split[0] == '1') view->statCh = 0x02; else view->statCh = 0x03; } if (strncmp (lineIn, "DefaultGamma", 12) == 0) { split = rindex(lineIn, ' '); split++; view->defGamma = (atof (split) / 100.0); } if (strncmp (lineIn, "DefaultRender", 13) == 0) { split = rindex(lineIn, ' '); split++; gdk_imlib_set_render_type(atoi (split)); } if (strncmp (lineIn, "DefaultBackColor", 16) == 0) { split = rindex(lineIn, ' '); split++; view->defBackColor = g_strdup(split); } if (strncmp (lineIn, "PersistantZoom", 14) == 0) { split = rindex(lineIn, ' '); split++; if (split[0] == '1') view->statCh = (view->statCh | 0x80); else view->statCh = (view->statCh & 0x7f); } g_free(lineIn); lineIn = getLine(fHnd); } fclose(fHnd); } else { view->slideTime = 2000; view->statCh = 0x03; view->defGamma = 1.00; view->defBackColor = NULL; } if (!(view->defBackColor)) { tmpF = back_xpm[2]; tmpF += 4; view->defBackColor = g_strdup(tmpF); } #endif /* HAVE_SGC */ view->setrsp = NULL; view->main = NULL; view->currPath = spath; view->matchTimer = 0; view->matchDepth = 0; getExternal(view); genRegexComp(view); if ((iName) && (isImage(view, iName))) { useBrowser = forceBrowser; } view->slideList = NULL; view->factor = 1.0; for (cnt = 0; cnt < MAX_DIR_STACK; cnt++) { view->upDir[cnt] = 0; } view->tips = gtk_tooltips_new(); gtk_tooltips_enable(view->tips); if ((useBrowser) || (!iName)) { createWin(view); gloaddir(view); } if (iName) handleFile(view, iName); g_free(iName); #ifdef HAVE_WORKING_MSG dqueue = msgget(34, 0); if (dqueue == -1) { view->dqueue = msgget(34, IPC_CREAT); signal(SIGHUP, catchHandler); signal(SIGINT, catchHandler); signal(SIGQUIT, catchHandler); signal(SIGILL, catchHandler); signal(SIGPIPE, catchHandler); signal(SIGALRM, catchHandler); signal(SIGTERM, catchHandler); signal(SIGUSR1, catchHandler); signal(SIGUSR2, catchHandler); signal(SIGSEGV, catchHandler); } else view->dqueue = -1; view->msgTimer = gtk_timeout_add(3000, (GtkFunction) ipcIncoming, (gpointer) view); #endif /* HAVE_WORKING_MSG */ gtk_main(); exit(0); }