|
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 z
Length: 3928 (0xf58) Types: TextFile Names: »zmisc.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89 └─⟦ff23ba0e6⟧ »./ghostscript-1.3.tar.Z« └─⟦a24a58cd3⟧ └─⟦this⟧ »zmisc.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. */ /* zmisc.c */ /* Miscellaneous operators for GhostScript */ #include "string_.h" #include "ghost.h" #include "memory_.h" #include "errors.h" #include "oper.h" #include "alloc.h" #include "dict.h" #include "store.h" /* Import the dictionary stack pointer (for bind) */ extern ref *dsp; /* Import the operand stack limit */ extern ref *ostop; /* Import the C getenv function */ extern char *getenv(P1(char *)); /* bind */ int zbind(register ref *op) { ref *bsp = op; /* bottom of stack */ switch ( r_type(op) ) { case t_array: case t_packedarray: break; default: return e_typecheck; } /* It appears from the PostScript manual that bind works */ /* even on procedures whose top level isn't writable. */ /* This seems a little counter-intuitive, but we do the same. */ *++bsp = *op; while ( bsp > op ) { while ( bsp->size ) { ref *tp = bsp->value.refs++; bsp->size--; switch ( r_type(tp) ) { case t_name: /* bind the name if an operator */ if ( r_has_attrs(tp, a_executable) ) { ref *pvalue = dict_search(tp, dsp); if ( pvalue != 0 && r_btype(pvalue) == t_operator && r_has_attrs(pvalue, a_executable) ) store(tp, *pvalue); } break; case t_array: /* push into array if procedure */ case t_packedarray: if ( r_has_attrs(tp, a_executable+a_write) && bsp < ostop ) { /* Make reference read-only */ r_clear_attrs(tp, a_write); *++bsp = *tp; } } } bsp--; } return 0; } /* currenttime */ int zcurrenttime(register ref *op) { long date_time[2]; gs_get_clock(date_time); push(1); make_real(op, date_time[0] * 1440.0 + date_time[1] / 60000.0); return 0; } /* getenv */ int zgetenv(register ref *op) { char *str, *value; uint size; check_type(*op, t_string); size = op->size; str = alloc(size + 1, "getenv name"); if ( str == 0 ) return e_VMerror; memcpy(str, (char *)op->value.bytes, size); str[size] = 0; value = getenv(str); alloc_free(str, size + 1, "getenv name"); if ( value == 0 ) /* not found */ { make_bool(op, 0); return 0; } size = strlen(value); str = alloc(size, "getenv value"); if ( str == 0 ) return e_VMerror; memcpy(str, value, size); make_tasv(op, t_string, a_all, size, bytes, (byte *)str); push(1); make_bool(op, 1); return 0; } /* setdebug */ int zsetdebug(register ref *op) { int i; check_type(op[-1], t_string); check_type(*op, t_boolean); #ifdef DEBUG for ( i = 0; i < op[-1].size; i++ ) gs_debug[op[-1].value.bytes[i] & 127] = op->value.index; #endif pop(2); return 0; } /* usertime */ int zusertime(register ref *op) { long date_time[2]; gs_get_clock(date_time); push(1); make_int(op, date_time[0] * 86400000L + date_time[1]); return 0; } /* ------ Initialization procedure ------ */ void zmisc_op_init() { static op_def my_defs[] = { {"1bind", zbind}, {"0currenttime", zcurrenttime}, {"1getenv", zgetenv}, {"2setdebug", zsetdebug}, {"0usertime", zusertime}, op_def_end }; z_op_init(my_defs); }