|
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: 5259 (0x148b) Types: TextFile Names: »gsmain.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89 └─⟦ff23ba0e6⟧ »./ghostscript-1.3.tar.Z« └─⟦a24a58cd3⟧ └─⟦this⟧ »gsmain.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. */ /* gsmain.c */ /* Framework for GhostScript drivers */ #include "string_.h" #include "malloc_.h" #include "gx.h" #include "gsmatrix.h" /* for gxdevice.h */ #include "gxdevice.h" typedef struct gx_device_s gx_device; /* * This routine provides the following standard services for parsing * a command line: * - setting debug flags (-Z switch) [if debugging]; * - tracing (-T switch) [if debugging]; * - passing other arguments and switches back to the caller * * Calling convention: * gs_main(argc, argv, map_name, switch_proc, arg_proc) * Calls * switch_proc(switch_char, rest_of_arg) for switches, * arg_proc(arg, index) for non-switch args. * If switch_proc returns a negative value, gs_main prints an * "unknown switch" error message and aborts. * gs_main returns the number of non-switch args handed to arg_proc. */ private unsigned long proc_reloc; /* relocation of procedures */ int gs_main(int argc, char *argv[], char *map_name, int (*switch_proc)(P2(char, char *)), void (*arg_proc)(P2(char *, int))) { int argi = 1; FILE *mapf; int arg_count = 0; proc_reloc = 0; #ifdef DEBUG /* Reset debugging flags */ memset(gs_debug, 0, 128); /* Open the map file and look up 'main' */ mapf = fopen(map_name, "rt"); if ( mapf == NULL ) printf("Unable to open map file %s\n", map_name); else { extern char *trace_find_symbol(P2(char *, FILE *)); char *main_addr = trace_find_symbol("_MAIN", mapf); if ( main_addr == NULL ) printf("Unable to find _main in map file\n"); else { extern main(); proc_reloc = (unsigned long)main - (unsigned long)main_addr; } } #endif /* Initialize the proper device */ { extern gx_device *gp_default_device_p; extern gx_device *gx_device_default_p; gx_device *dev = gp_default_device_p; /* If debugging is enabled, trace the device calls. */ #ifdef DEBUG { extern gx_device *gs_trace_device(P1(gx_device *)); gx_device *tdev = gs_trace_device(dev); if ( tdev == 0 ) { printf("Can't allocate traced device!"); exit(1); } dev = tdev; } #endif gx_device_default_p = dev; } { extern void gp_init(); gp_init(); /* Platform-dependent init */ } for ( ; argi < argc; argi++ ) { char *arg = argv[argi]; if ( *arg == '-' ) { switch ( *++arg ) { default: if ( (*switch_proc)(*arg, arg + 1) < 0 ) { printf("Unknown switch %s", arg - 1); exit(1); } break; case 'Z': #ifdef DEBUG if ( !arg[1] ) { /* No options, set all flags */ memset(gs_debug, -1, 128); } else { while ( *++arg ) gs_debug[*arg & 127] = -1; } #else printf("Not a debugging configuration, -Z switch ignored\n"); #endif break; case 'T': #ifdef DEBUG if ( mapf != NULL ) { char *delim; char *tname; int rsize = 0; extern int trace_flush_flag; delim = strchr(arg, ':'); if ( delim != NULL ) { sscanf(delim + 1, "%d", &rsize); *delim = 0; /* terminate name */ } tname = malloc(strlen(arg) + 1); strcpy(tname, arg); *tname = '_'; strupr(tname); if ( trace_name(tname, mapf, NULL, rsize) < 0 ) printf("%s not found\n", tname); trace_flush_flag = 1; } #else printf("Not a debugging configuration, -T switch ignored\n"); #endif break; } } else (*arg_proc)(arg, arg_count++); } return arg_count; } /* Close the device and exit */ void gs_exit(int code) { (*gx_device_default_p->procs->close_device)(gx_device_default_p); exit(code); } /* ------ Debugging routines ------ */ #ifdef DEBUG /* ------ ------ */ void gs_dump_C_stack(); /* Log an error return */ int gs_log_error(int err) { if ( gs_debug['e'] ) { printf("Returning error %d:\n", err); gs_dump_C_stack(); } return err; } #endif /* ------ ifdef DEBUG ------ */ /* Dump the C stack. */ /* This is actually only used for debugging. */ extern char *stack_top_frame(); extern unsigned long stack_return(P1(char *)); extern char *stack_next_frame(P1(char *)); void gs_dump_C_stack() { char *nbp = stack_top_frame(); char *bp; do { bp = nbp; printf("frame %8lx called from %8lx (%8lx)\n", (unsigned long)bp, stack_return(bp), stack_return(bp) - proc_reloc); nbp = stack_next_frame(bp); } while ( nbp != 0 ); }