home *** CD-ROM | disk | FTP | other *** search
- /*-
- * glview.c - main routines for grasp viewer.
- *
- * Macintosh version of GL Viewer, compiler: MPW-C 3
- *
- * from XGRASP, Copyright (c) 1991 by Patrick J. Naughton
- *
- */
-
- #pragma segment GLView
-
- #define DEBUG 1
- #define Version "1.0, 15-Oct-91"
-
- #include "grasp.h"
-
-
- char *pname;
- int imageloop = 0;
- int showdirectory = 0;
- int showtext = 0;
- int printthecodes = 0;
- int verbose = 0;
- int imverbose = 0;
- Display *dsp;
- Window win;
- Visual *vis;
- XVisualInfo vinfo;
- int screen;
- int planes;
- GC gc;
- GC gc1;
- long white;
- long black;
- //Atom protocol_atom;
- //Atom kill_atom;
-
- Bool aboutdone = False;
-
-
- void about()
- {
- fprintf(stderr, "\n%s, version %s\n\n",pname,Version);
- fprintf(stderr,
- "This program tries to recreate the functionality provided by the PC\n"
- "program GRASPRT.EXE. It plays animation files which usually have the\n"
- "extension .GL. This file format is partially described by the\n"
- "documents found in the file 'docs'. It has many missing features, but\n"
- "it is complete enough to view a large percentage of the GL files.\n\n");
- fprintf(stderr,
- "This Mac version was hacked from the X-Window source code, XGRASP (v1.7),\n"
- "available at anonymous ftp sites or e-mail to xgrasp@ankh.ftl.fl.us,\n"
- "and copyright (c) 1991 by Patrick J. Naughton.\n\n");
-
- fprintf(stderr, "Command line interface: file.gl -debugopts\n");
- fprintf(stderr, "usage: file.gl -all -verbose -dir -textout -images -imverbose -printcodes\n");
- aboutdone = True;
- }
-
-
- char *
- strdup(s)
- char *s;
- {
- char *new = malloc(strlen(s) + 1);
- return (new ? strcpy(new, s) : (char *) 0);
- }
-
- void
- error(s1, s2)
- char *s1, *s2;
- {
- if (!aboutdone) about();
-
- fprintf(stderr, s1, pname, s2);
- exit(1);
- }
-
- void
- outi(s, i)
- char *s;
- int i;
- {
- fprintf(stderr, "%s: %d\n", s, i);
- }
-
- void
- outs(s1, s2)
- char *s1, *s2;
- {
- fprintf(stderr, "%s: %s\n", s1, s2);
- }
-
-
- u_int
- GetByte(fp)
- FILE *fp;
- {
- return (u_int) getc(fp);
- }
-
- u_int
- GetWord(fp)
- FILE *fp;
- {
- u_char b1 = (u_char) getc(fp);
- u_char b2 = (u_char) getc(fp);
-
- return (u_int) (b1 + b2 * 256);
- }
-
- u_int
- GetLong(fp)
- FILE *fp;
- {
- u_char b1 = (u_char) getc(fp);
- u_char b2 = (u_char) getc(fp);
- u_char b3 = (u_char) getc(fp);
- u_char b4 = (u_char) getc(fp);
- return (u_int) (b1 + b2 * 256 + b3 * 256 * 256 + b4 * 256 * 256 * 256);
- }
-
-
- FilenameStruct *
- readdirectory(fp, count)
- FILE *fp;
- int *count;
- {
- FilenameStruct *fn;
- int i;
- int len = GetWord(fp);
- long plen;
-
- *count = (len / 17) - 1;
- fn = (FilenameStruct *) malloc(*count * sizeof(FilenameStruct));
- for (i = 0; i < *count; i++) {
- fn[i].offset = GetLong(fp);
- fread(fn[i].fname, 13, 1, fp);
- fn[i].fname[13] = 0;
- lowerstr(fn[i].fname);
- }
- if (showdirectory) {
- fprintf(stderr, "%13s %6s %6s\n", "Name", "offset", "hexoff" );
- for (i = 0; i < *count; i++) {
- /* if (i+1 == *count) plen= -1 else plen= fn[i+1].offset - fn[i].offset; */
- fprintf(stderr, "%13s %6d %6X\n", fn[i].fname, fn[i].offset, fn[i].offset);
- }
- }
- return (fn);
- }
-
- usage()
- {
- error("Error: Bad usage.\n", NULL);
- }
-
-
- #ifdef DEBUG
- /* command line reader for Mac/MPW -- dgg */
- int readCmdOptions(FILE *cl, char ***argv)
- {
- #define MAXS 255
- #define addarg(sptr) if (strlen(sptr)>0) { \
- targv = (char **) realloc( targv, (argc+1) * sizeof(char *)); \
- targv[argc] = (char *) malloc(1+strlen(sptr) * sizeof(char)); \
- strcpy( targv[argc], sptr); \
- argc++; }
-
- char *pword, st[MAXS];
- const char *progname = "glview";
-
- int argc = 0;
- char **targv;
-
- targv = NULL;
- addarg( progname);
- fgets( st, MAXS, cl);
- if (!feof(cl) && st!=NULL && *st!=0) {
- pword = strtok( st, "\ \n");
- while (pword!=NULL) {
- addarg( pword);
- pword = strtok( NULL, "\ \n");
- }
- }
-
- *argv = targv;
- return argc;
- }
-
- int ccommand(char ***argv)
- {
- int argc;
- char **targv;
-
- argc = readCmdOptions(stdin, &targv);
- *argv = targv;
- return argc;
- }
-
- #endif DEBUG
-
-
-
- real_main(argc, argv)
- int argc;
- char *argv[];
- {
- char *displayName = "GL View";
- char *filename = 0;
- FILE *fp;
- FilenameStruct *dir;
- int count;
- int i;
- OSType SFTypes[4];
-
- //mac
- SFTypes[0]='TEXT';
- SFTypes[1]='BINA';
- SFTypes[2]='GlVw';
- SFTypes[3]='????';
- filename = StdGetFile( "\pChoose GL File:", SFTypes, 4);
-
- if (!filename) {
- #ifdef DEBUG
- pname = argv[0];
-
- about();
- fprintf(stderr, "command> ");
- argc= ccommand(&argv);
-
- pname = argv[0];
-
- for (i = 1; i < argc; i++) {
- char *s = argv[i];
- int n = strlen(s);
-
- if (!strncmp("-dir", s, n))
- showdirectory = 1;
- else if (!strncmp("-textout", s, n))
- showtext = 1;
- else if (!strncmp("-images", s, n))
- imageloop = 1;
- else if (!strncmp("-verbose", s, n))
- verbose = 1;
- else if (!strncmp("-imverbose", s, n))
- imverbose = 1;
- else if (!strncmp("-printcodes", s, n))
- printthecodes = 1;
- else if (!strncmp("-all", s, n)) {
- showdirectory = 1;
- showtext = 1;
- imageloop = 1;
- verbose = 1;
- imverbose = 1;
- printthecodes = 1;
- }
- else if (filename || s[0] == '-')
- usage();
- else
- filename = s;
- }
-
- if (!filename) error("%s: No gl file selected.\n");
-
- #else
- error("%s: No gl file selected.\n");
- #endif
- }
-
- displayName = filename;
- if (!(dsp = XOpenDisplay(displayName)))
- error("%s: unable to open display.\n");
-
- fp = fopen(filename, "r");
- if (!fp) error("%s: %s not found.\n", filename);
-
- if (verbose) fprintf(stderr, "\n readdirectory...\n");
- dir = readdirectory(fp, &count);
-
- if (verbose) fprintf(stderr, "\n readfiles...\n");
- readfiles(fp, dir, count);
- fclose(fp);
-
- if (verbose) fprintf(stderr, "\n execfile...\n");
- execfile(exec[0], 0);
- exit(0);
- }
-