home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1990-1992 Michael Davidson.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation.
- *
- * This software is provided "as is" without express or implied warranty.
- */
-
- /*
- * GIF file viewer for SCO UNIX
- */
-
- /*
- * The Graphics Interchange Format(c) is the Copyright property
- * of CompuServe Incorporated.
- *
- * GIF(sm) is a Service Mark property of CompuServe Incorporated.
- */
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <unistd.h>
-
- #include "vg.h"
- #include "kbd.h"
- #include "video.h"
-
- char *cmdname = NULL;
- char *display = NULL;
- int nomenu = 0;
- int vflag = 0;
- int tflag = 0;
- int menuwidth = 80;
- int maxdepth = 24;
- char *InitialDirectory = NULL;
- char *CurrentDirectory = NULL;
-
- int
- main(
- int argc,
- char **argv
- )
- {
- int c;
- list_t *f;
- void sigcatch(int sig);
- extern int optind;
- extern char *optarg;
- extern void showUsage();
-
- cmdname = argv[0];
-
- if (argc < 2)
- {
- showUsage();
- return 0;
- }
-
- display = getenv("VG_DISPLAY");
-
- while ((c = getopt(argc, argv, "1:d:ntvw:x:z")) != EOF)
- {
- switch (c)
- {
- case '1':
- menuwidth = 132;
- break;
-
- case 'n':
- ++nomenu;
- break;
-
- case 'd':
- display = optarg;
- break;
-
- case 't':
- ++tflag;
- break;
-
- case 'v':
- ++vflag;
- break;
-
- case 'w':
- imageSetDefaultDelay(atoi(optarg));
- break;
-
- case 'x':
- maxdepth = atoi(optarg);
- break;
-
- default:
- break;
- }
- }
-
- if (! vflag && ! tflag)
- {
- if ((f = fileListCreate(&argv[optind])) == NULL)
- fatal(0, "can't create file list");
-
- f = fileListSort(f);
- }
-
- if (signal(SIGINT, sigcatch) == SIG_IGN)
- fatal(0, "%s cannot be run in the background", cmdname);
-
- InitialDirectory = getcwd(NULL, 1024);
- CurrentDirectory = InitialDirectory;
-
- signal(SIGHUP, sigcatch);
- signal(SIGTERM, sigcatch);
- signal(SIGBUS, sigcatch);
- signal(SIGSEGV, sigcatch);
- signal(SIGFPE, sigcatch);
-
- vidInit(display);
- kbdInit();
- imageInit();
- ycc_rgb_init();
-
- setuid(getuid());
-
- if (tflag)
- testMenu();
- else if (! vflag)
- fileMenu(f);
-
- kbdReset();
- vidReset();
-
- if (vflag)
- showConfig();
-
- return 0;
- }
-
- void
- sigcatch(
- int sig
- )
- {
- cleanup();
-
- if (sig != SIGINT)
- fprintf(stderr, "%s: caught signal %d\n", cmdname, sig);
-
- exit(sig);
-
- /*NOTREACHED*/
- }
-
- void
- cleanup()
- {
- static int cleaning_up = 0;
-
- if (cleaning_up)
- fprintf(stderr, "%s: recursive call to Cleanup()\n", cmdname);
- else
- {
- cleaning_up = 1;
- if (InitialDirectory != NULL)
- chdir(InitialDirectory);
- kbdReset();
- vidReset();
- cleaning_up = 0;
- }
- }
-
- showConfig()
- {
- vmode_t *v;
-
- printf("%s\n", vidGetName());
-
- for (v = vidGetModes(); v->flags != 0; v++)
- if (v->flags & V_MODE_SUPPORTED)
- printf("%dx%d-%d %s\n", v->width, v->height, v->depth,
- (v->flags & V_GRAPHICS_MODE) ? "graphics" : "text");
- }
-