|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T g
Length: 6695 (0x1a27) Types: TextFile Names: »gs.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89 └─⟦ff23ba0e6⟧ »./ghostscript-1.3.tar.Z« └─⟦a24a58cd3⟧ └─⟦this⟧ »gs.c«
/* Copyright (C) 1989 Aladdin Enterprises. All rights reserved. Distributed by Free Software Foundation, Inc. This file is part of Ghostscript. Ghostscript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Refer to the Ghostscript General Public License for full details. Everyone is granted permission to copy, modify and redistribute Ghostscript, but only under the conditions described in the Ghostscript General Public License. A copy of this license is supposed to have been given to you along with Ghostscript so you can know your rights and responsibilities. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. */ /* gs.c */ /* Driver program for GhostScript */ #include <stdio.h> #include "string_.h" #include "ghost.h" #include "alloc.h" #include "store.h" #include "stream.h" /* Exported data */ uint memory_chunk_size = 20000; /* Imported data */ extern ref null; extern ref *osbot, *osp, *esp; extern ref estack[]; /* Forward references */ private void init1(), init2(); private void run_file(P2(char *file_name, int user_errors)); private void stack_dump(P1(int code)); /* Parameters set by swproc */ private int user_errors; main(int argc, char *argv[]) { int num_files; char line[200]; ref r; int code; int swproc(P2(char, char *)); void argproc(P2(char *, int)); /* Execute files named in the command line, */ /* processing options along the way. */ /* Wait until the first file name (or the end */ /* of the line) to finish initialization. */ user_errors = 1; num_files = gs_main(argc, argv, "GS.MAP", swproc, argproc); if ( num_files == 0 ) { init2(); } strcpy(line, "{start prompt}"); while ( 1 ) { code = tscan(line, &r); if ( !code ) { code = interpret(&r, user_errors); zcopypage(0); /* force display update */ #ifdef DEBUG if ( code < 0 || osp >= osbot || esp >= estack ) #else if ( code < 0 ) #endif stack_dump(code); interp_init(2); } strcpy(line, "{{"); if ( gets(line + 2) == NULL ) break; /* end of input */ strcat(line, "} execute prompt}"); } } /* Process switches */ int swproc(char sw, char *arg) { switch ( sw ) { default: return -1; case 'D': /* define name */ case 'd': case 'S': /* define name as string */ case 's': { char *eqp = strchr(arg, '='); ref value; /* Initialize the object memory, scanner, and */ /* name table now if needed. */ init1(); if ( eqp == NULL ) { value = null; } else if ( eqp == arg ) { printf("Usage: -dname, -dname=token, -sname=string"); gs_exit(1); } else { int code; *eqp++ = 0; /* delimit name */ if ( sw == 'D' || sw == 'd' ) { stream astream; sread_string(&astream, (byte *)eqp, strlen(eqp)); code = scan_token(&astream, 0, &value); if ( code ) { printf("-dname= must be followed by a valid token"); gs_exit(1); } } else { int len = strlen(eqp); char *str = alloc((uint)len, "-s"); if ( str == 0 ) { printf("Out of memory!"); gs_exit(1); } strcpy(str, eqp); make_tasv(&value, t_string, a_read+a_execute, len, bytes, (byte *)str); } } /* Enter the name in systemdict */ initial_enter_name(arg, &value); break; } case 'E': /* suppress normal error handling */ user_errors = 0; break; case 'M': /* set memory allocation increment */ { unsigned msize = 0; sscanf(arg, "%d", &msize); if ( msize <= 0 || msize >= 64 ) { printf("-M must be between 1 and 64"); gs_exit(1); } memory_chunk_size = msize << 10; } break; } return 0; } /* Process file names */ void argproc(char *arg, int index) { char line[200]; int code; ref r; /* Finish initialization */ init2(); strcpy(line, "{("); strcat(line, arg); strcat(line, ")run}"); code = tscan(line, &r); if ( !code ) code = interpret(&r, user_errors); zcopypage(0); /* force display update */ if ( code ) stack_dump(code), gs_exit(1); } tscan(char *str, ref *pr) { stream st; stream *s = &st; int code; sread_string(s, str, strlen(str)); code = scan_token(s, 0, pr); if ( code < 0 ) printf("scan_token returns %d\n", code); return code; } private int init1_done = 0, init2_done = 0; private void init1() { if ( !init1_done ) { alloc_init(memory_chunk_size); name_init(); obj_init(); /* requires name_init */ scan_init(); /* ditto */ init1_done = 1; } } private void init2() { init1(); if ( !init2_done ) { gs_init(); zfile_init(); zfont_init(); zmath_init(); zmatrix_init(); interp_init(1); /* requires obj_init */ op_init(); /* requires obj_init, scan_init */ /* Execute the standard initialization file. */ run_file("ghost.ps", 0); init2_done = 1; } } /* Open and execute a file */ private void run_file(char *file_name, int user_errors) { ref initial_file; int code; if ( file_open(file_name, strlen(file_name), "r", &initial_file) < 0 ) printf("Can't read %s\n", file_name), gs_exit(1); printf("Reading %s... ", file_name); r_set_attrs(&initial_file, a_execute + a_executable); code = interpret(&initial_file, user_errors); if ( code < 0 ) stack_dump(code), gs_exit(1); printf("%s read.\n", file_name); } /* Debugging */ /* Dump the stacks after interpretation */ private void stack_dump(int code) { zflush(osp); /* force out buffered output */ printf("\nInterp returns %d\n", code); dump_refs(osbot, osp + 1, "ostack"); dump_refs(estack, esp + 1, "estack"); } /* Dump a region of memory containing refs */ dump_refs(ref *from, ref *to, char *msg) { ref *p = from; if ( from < to ) printf("%s:\n", msg); while ( p < to ) { unsigned type = r_type(p), attrs = p->type_attrs; unsigned btype = r_btype(p); static char *ts[] = { type_print_strings }; static char *as = attr_print_string; char *ap = as; printf("%lx: %2x ", (ulong)p, type); if ( btype >= t_next_index ) printf("%02x?? ", btype); else printf("%s ", ts[btype]); for ( ; *ap; ap++, attrs >>= 1 ) if ( *ap != '.' ) putchar(((attrs & 1) ? *ap : '-')); printf(" %4x %8lx\n", p->size, *(ulong *)&p->value); p++; } } /* Dump a region of memory */ dump(byte *from, byte *to, char *msg) { byte *p = from; if ( from < to ) printf("%s:\n", msg); while ( p != to ) { byte *q = min(p + 16, to); printf("%lx:", (ulong)p); while ( p != q ) printf(" %02x", *p++); printf("\n"); } }