$! ------------------ CUT HERE ----------------------- $ v='f$verify(f$trnlnm("SHARE_VERIFY"))' $! $! This archive created by VMS_SHARE Version 7.2-007 22-FEB-1990 $! On 9-JUL-1999 11:23:40.90 By user MONIOT $! $! This VMS_SHARE Written by: $! Andy Harper, Kings College London UK $! $! Acknowledgements to: $! James Gray - Original VMS_SHARE $! Michael Bednarek - Original Concept and implementation $! $! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER $! AND EXECUTE AS A COMMAND PROCEDURE ( @name ) $! $! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING: $! 1. SHELL_MUNG.C;1 $! 2. LICENSE.;1 $! $set="set" $set symbol/scope=(nolocal,noglobal) $f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID")) $e="write sys$error ""%UNPACK"", " $w="write sys$output ""%UNPACK"", " $ if f$trnlnm("SHARE_LOG") then $ w = "!" $ ve=f$getsyi("version") $ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START $ e "-E-OLDVER, Must run at least VMS 4.4" $ v=f$verify(v) $ exit 44 $UNPACK: SUBROUTINE ! P1=filename, P2=checksum $ if f$search(P1) .eqs. "" then $ goto file_absent $ e "-W-EXISTS, File ''P1' exists. Skipped." $ delete 'f'* $ exit $file_absent: $ if f$parse(P1) .nes. "" then $ goto dirok $ dn=f$parse(P1,,,"DIRECTORY") $ w "-I-CREDIR, Creating directory ''dn'." $ create/dir 'dn' $ if $status then $ goto dirok $ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped." $ delete 'f'* $ exit $dirok: $ w "-I-PROCESS, Processing file ''P1'." $ if .not. f$verify() then $ define/user sys$output nl: $ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1' PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET( SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:= CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b)); LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION( BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1); IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE; MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1; ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")= 1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF"; POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r); ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1; COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE, "output_file"));ENDPROCEDURE;Unpacker;QUIT; $ delete/nolog 'f'* $ CHECKSUM 'P1' $ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT $ e "-E-CHKSMFAIL, Checksum of ''P1' failed." $ ENDSUBROUTINE $START: $ create 'f' X/******************************************************************/ X X#ifdef VAXC`09`09`09/* v1.2-004 */ X#module SHELL_MUNG "Jym V1.2-005" /* Only VAX C understands this. */ X#else`09`09`09`09/* v1.2-004 */ X#define`09TRUE`09`091`09/* GNU C stdio.h doesn't define TRUE and FALSE*/ X#define`09FALSE`09`090 X#endif X X/* SHELL_MUNG.C X**========================================================================== V=== X** Copyright (C) 1989 Jym Dyer (jym@wheaties.ai.mit.edu) X** X** This program is free software; you can redistribute it and/or modify X** it under the terms of the GNU General Public License as published by X** the Free Software Foundation; either version 1, or (at your option) X** any later version. X** X** This program is distributed in the hope that it will be useful, X** but WITHOUT ANY WARRANTY; without even the implied warranty of X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X** GNU General Public License for more details. X** X** You should have received a copy of the GNU General Public License X** along with this program; if not, write to the Free Software X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X**-------------------------------------------------------------------------- V--- X** Version: V1.2-005 X**-------------------------------------------------------------------------- V--- X** Facility: GNU X**-------------------------------------------------------------------------- V--- X** Prefix: SHELL_ X**-------------------------------------------------------------------------- V--- X** Abstract X** `7E`7E`7E`7E`7E`7E`7E`7E X** If you think "shell mung" is a step in the preparation of a good mung da Vhl, X** you're right, but in this context "mung" is the verb. ("Mung" historical Vly X** means "mung until no good," but one could easily interpret it to mean "mu Vng X** until nearly gnu". Or something to that effect.) X** This file provides the shell_glob() and shell_mung() functions for the X** VMS/DCL/VAX C user. The shell_glob() function "globs" (parses filespecs X** with wildcards and matches them with existing files). The shell_mung() X** function provides GNU-shell-like IO redirection and globbing: it changes X** `60stderr', `60stdin', and/or `60stdout' to do the IO redirection; it mun Vgs a X** VAX C program's main() function's `60argc' and `60argv' variables (using V shell_ X** glob()) to do the globbing; and it truncates `60argv`5B0`5D' down to a fi Vlename X** and filetype or, if the file is a .EXE file, to just the filename. X** This makes it easy to port many GNU utilities to VMS, as these utilities X** often expect the shell to have done the work that shell_mung() does. It V can X** also be used to port Un*x utilities as well, if anybody cares. X**-------------------------------------------------------------------------- V--- X** Functions X** `7E`7E`7E`7E`7E`7E`7E`7E`7E X** shell_glob() X** shell_mung() X** (static) truncate_argv_0() X**-------------------------------------------------------------------------- V--- X** Environment X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** Must be linked with the VAX C RTL. Intended for use with the DCL CLI on X** VMS; it would be pointless to use shell_mung() with the SHELL CLI, though X** shell_glob() might possibly come in handy. X** Must be linked with xmalloc() and xrealloc() functions, which are readil Vy X** available from GNU source code. These are simply malloc() and realloc() X** functions that exit if there is an error getting memory. X**-------------------------------------------------------------------------- V--- X** Author: Jym Dyer (jym@wheaties.ai.mit) 8-Apr-1988 X**-------------------------------------------------------------------------- V--- X** Modifications X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** 1.0-001 - Original version. Inspired by the DECUS C getredirection() X** function written by Martin Minow, Jerry Leichter, and Jym Dyer. X** `7BJym 8-Apr-1988`7D X** 1.1-002 - Added `60shell_default' and use of same by shell_glob(), which X** allows default filespecs to be used in globbing. X** `7BJym 9-Jan-1989`7D X** 1.2-003 - Made shell_glob() accept unglobbable filespecs. X** - In addition to '-', '+' is now accepted as the start of an opti Von. X** `7BJym 3-Jun-1989`7D X** 1.2-004 - Made changes to allow compilation by GNU C. X**`09 `7BHunter Goatley, goathunter@WKUVX1.BITNET, 12-SEP-1991`7D X** 1.2-005 - Added Andrew Greer's patch to fix problem parsing non-filespec X**`09 arguments to options X**`09 `7BHunter Goatley, goathunter@WKUVX1.BITNET, 22-SEP-1991`7D X**`09 `7BAndrew Greer, `7D X**========================================================================== V=== X*/ X X/* -=- FILE INCLUSIONS -=- */ X X#include X#include X#include X#include X X#include X#include X#include X#include X X#ifndef VAXC`09`09`09`09/* v1.2-004 */ X#define _tolower(c) ((c) >= 'A' && (c) <= 'Z' ? (c) `7C 0x20:(c)) X#endif`09`09`09/* Also changed tolower() calls to _tolower() */ X X/* -=- FORWARD DECLARATIONS -=- */ X Xextern void * xmalloc(); Xextern void * xrealloc(); X Xextern void sys$exit(); Xextern int sys$parse(); Xextern int sys$search(); X Xextern char ** shell_glob(); Xstatic char * truncate_argv_0(); X X/* -=- GLOBAL VARIABLE DEFINITION -=- */ X X#ifdef VAXC`09`09`09`09/* v1.2-004 */ Xglobaldef char * shell_default = NULL; /* Default filespec for shell_glob() V.*/ X#else Xchar * shell_default = NULL;`09`09/* Default filespec for shell_glob().*/ X#endif X /* Initialized here to NULL, which X ** means that no default filespec is X ** used by shell_glob(). X */ X X/* -=- FUNCTIONS -=- */ X X/* shell_glob() X**-------------------------------------------------------------------------- V--- X** Functional Description X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** Given a filespec, this function parses that filespec out and searches fo Vr X** the file---or, if the filespec has wildcard characters in it, the files-- V- X** associated with the filespec. It returns a newly-allocated vector of fil Ve- X** specs that are also newly-allocated. This function can be used to find o Vnly X** the first file that matches the filespec or all the files that match it. V In X** the latter case, this function will also provide a count of the files tha Vt X** were found. X** Filespecs returned by this function are in lowercase, to approximate the X** "look and feel" of GNU. X** This function is used by shell_mung(), and is also handy for general use V. X**-------------------------------------------------------------------------- V--- X** Usage X** `7E`7E`7E`7E`7E X** This function returns a vector---that is, a pointer to pointers. Thus y Vou X** will need to declare this function and a vector like this: X** X** extern char ** shell_glob(); X** X** char ** filespec_v; X** X** To find only the first match of a wildcarded filespec, or just to get th Ve X** fully-parsed filespec of a given filespec, call shell_glob() with NULL as X** its second parameter. For example, if you call it like this: X** X** static int const filespec = "*.c"; X** char ** filespec_v; X** ... X** filespec_v = shell_glob(filespec,NULL); X** X** The value in `60filespec_v`5B0`5D' will be (for example) "dev:`5Bdir`5Dba Vr.c;". Note X** that the character string pointer is the content of the vector, not the X** vector itself. X** With this usage, `60filespec_v' points to a pointer (actually an array o Vf one X** pointer, which is the same thing). When used to get a number of filespec Vs, X** it points to an array of pointers. X** To get all the filespecs that match a filespec, use an address of an X** integer as shell_glob()'s second parameter, as in this example: X** X** static int const filespec = "*.c"; X** int filespec_count; X** char ** filespec_v; X** ... X** filespec_v = shell_glob(filespec,&filespec_count); X** X** The result of this would be (for example), X** X** filespec_count = 3, X** filespec_v`5B0`5D = "dev:`5Bdir`5Dbar.c", X** filespec_v`5B1`5D = "dev:`5Bdir`5Dbaz.c", and X** filespec_v`5B2`5D = "dev:`5Bdir`5Dfoo.c". X** X** In either type of usage, both the vector and the character strings are i Vn X** newly-allocated memory. X** VMS globbing entails a feature that allows one to fill in parts of a fil Ve- X** spec with default values. This feature can be used by shell_glob() using X** `60shell_default', a global character string. Use of this character stri Vng is X** optional, and it is initially set to NULL, meaning no default filespec is X** used. To use it, you need to declare it like this: X** X** globalref char * shell_default; X** X** The most frequent use of a default filespec in VMS is to provide a defau Vlt X** filetype, as shown in this example: X** X** static int const filespec = "*.c"; X** int filespec_count; X** char ** filespec_v; X** ... X** shell_default = ".c"; X** filespec_v = shell_glob(filespec,&filespec_count); X** X** If `60user_string' (which is, of course, a character string) is (for exam Vple) X** "foo*", a filespec without a filetype, shell_glob() will look for all fil Ves X** whose filespecs match "foo*.c". If `60user_string' were "foo*.h", a file Vspec X** that has a filetype, the default filespec ".c" is ignored and shell_glob( V) X** will look for all files whose filespecs match "foo*.h". X** Default filespecs can include devices, directories, filenames, filetypes V, X** and version numbers. Wildcards can be used in filenames, filetypes, and X** version numbers. To turn default filespecs off, just set `60shell_defaul Vt' X** back to NULL. X** If the given filespec cannot be globbed, shell_glob() will simply return X** a filespec vector with an array of one pointer, pointing to the unglobbab Vle X** given filespec. The given filespec, therefore, should be something that X** will stick around for as long as you expect to use the filespec vector. V In X** particular, don't call shell_glob() from a function using an automatic X** character string variable of that function and expect the string to still V be X** available when you've exited that function. X**-------------------------------------------------------------------------- V--- X** Calling Sequence X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** filespec_v = shell_glob(given_filespec,filespec_count_p); X**-------------------------------------------------------------------------- V--- X** Formal Arguments Description X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E `7E`7E`7E`7E`7E`7E`7 VE`7E`7E`7E`7E X** given_filespec Filespec "as given"---that is, as typed on the comma Vnd X** line. This is what we parse and search for. X** filespec_count_p Pointer to an integer that is to receive a count of X** filespecs found that match `60given_filespec'. If N VULL, X** indicates that we're only to search for the first fi Vle X** that matches `60given_filespec'. X**-------------------------------------------------------------------------- V--- X** Implicit Input Description X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E `7E`7E`7E`7E`7E`7E`7E`7E V`7E`7E`7E X** shell_default This global variable is a character string of a defa Vult X** filespec. If NULL, no default filespec is used. X**-------------------------------------------------------------------------- V--- X** Implicit Outputs: None X**-------------------------------------------------------------------------- V--- X** Return Value X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** Returns a vector of pointers to newly-parsed filespecs. X**-------------------------------------------------------------------------- V--- X** Side Effects X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** Memory is allocated for the filespec vector and for the filespecs that i Vt X** points to. X**-------------------------------------------------------------------------- V--- X*/ Xchar ** Xshell_glob(given_filespec,filespec_count_p) X char * given_filespec; X int * filespec_count_p; X`7B X /* --- LOCAL VARIABLES --- */ X X register char * character_p; /* General-purpose character pointer V, X ** used to convert filespecs to X ** lowercase. X */ X register char * expanded_filespec;`09/* v1.2-004 */ X /* Buffer to hold the expanded files Vpec X ** from a call to sys$parse(). X */ X register int filespec_count = 0; /* Count of filespecs that sys$searc Vh() X ** finds. X */ X register char ** filespec_v = NULL; /* Vector of pointers to filespecs t Vhat X ** sys$search() finds. Allocated an Vd X ** reallocated as filespecs are foun Vd. X */ X static char *our_path; /* The default device and directory X ** path. Initialized the first time X ** this function is called. X */ X register char * resultant_filespec;`09/* v1.2-004 */ X /* Buffer to hold a resultant filesp Vec X ** from a call to sys$search(). X */ X register int status; /* Status codes returned from calls V to X ** sys$parse() and sys$search(). X */ X struct FAB fab = cc$rms_fab; /* RMS file access block. X */ X struct NAM nam = cc$rms_nam; /* RMS name block. X */ X X /* --- INITIALIZE PATH --- */ X X resultant_filespec = xmalloc(NAM$C_MAXRSS + 1);`09/* v1.2-004 */ X expanded_filespec = xmalloc(NAM$C_MAXRSS + 1);`09/* v1.2-004 */ X if (our_path == NULL) X (char *) our_path = getenv("PATH");`09`09`09/* v1.2-004 */ X /* our_path = getenv("PATH"); */ X X /* --- INITIALIZE FAB AND NAM --- */ X X if (shell_default != NULL) X `7B X fab.fab$l_dna = shell_default; X fab.fab$b_dns = strlen(shell_default); X `7D X fab.fab$l_fna = given_filespec; X fab.fab$b_fns = strlen(given_filespec); X fab.fab$l_nam = &nam; X nam.nam$l_esa = expanded_filespec;`09`09/* v1.2-004 */ X nam.nam$b_ess = NAM$C_MAXRSS; X nam.nam$l_rsa = resultant_filespec;`09`09/* v1.2-004 */ X nam.nam$b_rss = NAM$C_MAXRSS; X X /* --- PARSE OUT THE GIVEN FILESPEC --- */ X X if ((status = sys$parse(&fab)) == RMS$_NORMAL) X `7B X /* --- SEARCH FOR FILE OR FILES --- */ X X while ((status = sys$search(&fab)) == RMS$_NORMAL) X `7B X filespec_v = ((filespec_v == NULL) ? xmalloc(sizeof (char *)) : X xrealloc(filespec_v,(filespec_count + 1) * sizeof (char *))); X X nam.nam$l_rsa`5Bnam.nam$b_rsl`5D = '\0'; X for (character_p = nam.nam$l_rsa; *character_p; ++character_p) X *character_p = _tolower(*character_p);`09`09/* v1.2-004 */ X X if (strncmp(nam.nam$l_rsa,our_path,nam.nam$b_dev + nam.nam$b_dir) == 0 V) X `7B X filespec_v`5Bfilespec_count`5D = xmalloc( X (int) (nam.nam$b_rsl - nam.nam$b_dev - nam.nam$b_dir) + 1 X ); X (void)strcpy(filespec_v`5Bfilespec_count`5D,nam.nam$l_name); X `7D X else if (strncmp(nam.nam$l_rsa,our_path,nam.nam$b_dev) == 0) X `7B X filespec_v`5Bfilespec_count`5D = xmalloc( X (int) (nam.nam$b_rsl - nam.nam$b_dev) + 1 X ); X (void)strcpy(filespec_v`5Bfilespec_count`5D,nam.nam$l_dir); X `7D X else X `7B X filespec_v`5Bfilespec_count`5D = xmalloc((int) nam.nam$b_rsl + 1); X (void)strcpy(filespec_v`5Bfilespec_count`5D,nam.nam$l_rsa); X `7D X X if (filespec_count_p == NULL) X break; X ++filespec_count; X X `7D /* sys$search() while */ X X /* --- UPDATE FILESPEC COUNT AND RETURN FILESPEC VECTOR --- */ X X if ((status == RMS$_NORMAL) `7C`7C (status == RMS$_NMF)) X `7B X if (filespec_count_p) X *filespec_count_p = filespec_count; X return filespec_v; X `7D X X `7D /* sys$parse() if */ X X /* --- RETURN VECTOR REFERRING TO GIVEN FILESPEC --- */ X X /* If we get here, we either could not parse the given filespec or could X ** not find it. In such cases we simply return a vector that refers to X ** the given filespec. X */ X filespec_v = xmalloc(sizeof (char *)); X filespec_v`5B0`5D = given_filespec; X if (filespec_count_p) X *filespec_count_p = 1; X return filespec_v; X X`7D /* shell_glob() */ X X/* shell_mung() X**-------------------------------------------------------------------------- V--- X** Functional Description X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** Given a description of the command line that invoked a program from the X** main() function's `60argc' and `60argv' variables, this function changes V those X** variables to reflect wildcard matching of filespecs in that command line X** and changes standard IO file pointers `60stderr', `60stdin', and `60stdou Vt' to X** reflect any IO redirection requested in that command line. X**-------------------------------------------------------------------------- V--- X** Usage X** `7E`7E`7E`7E`7E X** Since shell_mung() is written for programs running VAX C programs under V the X** DCL CLI on VMS, a call to shell_mung() should be predicated on these thin Vgs: X** X** #if defined(VAXC) && defined(VMS) X** if (!shell$is_shell()) X** shell_mung(&argc,&argv,...,...); X** #endif X** X** One should call shell_mung() before doing anything else---in particular, X** before anything is done with `60argc', `60argv', and parts of the standar Vd IO X** library. X** The first and second arguments to shell_mung() should always be addresse Vs X** of `60argc' and `60argv', respectively. The third and fourth arguments r Vequire X** a bit more thought. Before they are explained, though, we have to define X** some terms. X** A "parameter" is a position-dependent command line argument that isn't a Vn X** IO redirection (those start with '<' or '>'), an option or an option valu Ve. X** An "option" is similar to a DCL qualifier, except that it starts with '-' V or X** '+' instead of '/'. A "value" is a string that follows certain options. X** Which options have values is something that varies from program to progra Vm. X** A value in DCL is indicated with a equal sign (e.g. /qualifier=value), bu Vt X** here it can either be concatenated to an option (e.g. -ovalue) or appear V as X** an argument following the option (e.g. -o value). "Globbing," as mention Ved X** above, is to parse wildcarded filespecs and match them with existing file Vs. X** A "mung" is a legume used in Indian cooking, often after being shelled. X** The third argument to shell_mung() is the number of the parameter where V we X** expect filespecs to appear---in other words, the parameters we expect to X** need globbing. A GNU-shell-like command language interpreter will glob a Vny X** argument that has a wildcard character in it, unless that argument is put V in X** single quotes. DCL doesn't glob arguments, and though you can put argume Vnts X** in double quotes to pass them through exactly as typed, by the time VAX C X** has processed them into `60argv' strings, the double quotes have been str Vipped X** off. This is why we have to tell shell_mung() where to start globbing. V The X** assumption is made that unglobbable arguments (such as strings) will appe Var X** as parameters before globbable arguments (such as filespecs), an assumpti Von X** that holds for most GNU utilities, probably because it's the only rationa Vl X** way to code utilities that accept multiple filespecs on the command line. X** As an example, consider the following command line, where "fgrep" is a D VCL X** command to run the GNU "fgrep" program: X** X** $ fgrep -n xyzzy *.c *.h X** X** "xyzzy", "*.c", and "*.h" are the parameters. For fgrep, the string to b Ve X** searched for is always the first parameter ("xyzzy" in this case); the fi Vles X** to be searched always begin as a second parameter. The "-n" is an option V, X** which could be placed anywhere. The following commands mean the same thi Vng X** as the previous one: X** X** $ fgrep xyzzy -n *.c *.h X** $ fgrep xyzzy *.c -n *.h X** $ fgrep xyzzy *.c *.h -n X** X** (It is, however, usually considered better form to type the options first V. X** Some programs actually require that certain options appear before certain X** parameters.) To indicate that we expect input filespecs to begin as the X** second parameter, we call shell_mung() with 2 as its third argument: X** X** shell_mung(&argc,&argv,2,...); X** X** This changes `60argc' and `60argv' so that if the user types this: X** X** $ fgrep -n xyzzy *.c X** X** It's as if the user had typed this (for example): X** X** $ fgrep -n xyzzy dev:`5Bdir`5Dbar.c dev:`5Bdir`5Dbaz.c dev:`5Bdir`5D Vfoo.c X** X** If all of the parameters are to be considered globbable filespecs, the th Vird X** argument to shell_mung() should be 1 (indicating, of course, that globbin Vg X** can start with the first parameter). If no parameters are to be consider Ved X** globbable, shell_mung()'s third argument should be 0. If the user uses a X** negative number as the third argument, it is treated as 0. X** The fourth argument is a list of options which are followed by values, w Vith X** indications as to which values are to be globbed, and which option/value X** combinations are to be considered as replacements for parameters (more on X** this later). The list is passed as a character string. X** As an example, the "make" program has a "-f" option that expects a files Vpec X** as its value: X** X** $ make `5B-f makefile`5D `5Btarget`5D `5Bmacros`5D... X** X** To indicate that we have a "-f" option followed by a globbable value, we V put X** 'f' in shell_mung()'s fourth argument: X** X** shell_mung(&argc,&argv,0,"f"); X** X** When an option's value is globbed, only the first matching filespec is us Ved X** to replace that value. If, for example, "makefile.vms" and "makefile.xen Vix" X** are the only two files in your directory, and the user types one of these V: X** X** $ make -fmakefile.* X** $ make -f makefile.* X** X** It's as if the user had typed one of these (respectively): X** X** $ make -fdev:`5Bdir`5Dmakefile.vms X** $ make -f dev:`5Bdir`5Dmakefile.vms X** X** Options with unglobbable values must also be listed, with indications th Vat X** they are unglobbable. The "from" program is an example of this: X** X** $ from `5B-s sender`5D `5Buser`5D X** X** The "-s" option is followed by a username, not an input filespec. Thus w Ve X** put a '-' after the 's' in shell_mung()'s fourth argument: X** X** shell_mung(&argc,&argv,0,"s-"); X** X** There are times when an option/value combination can replace a parameter V. X** Using fgrep as an example again, its first parameter---the string to be X** searched for---can be replaced by the "-e" and "-f" options and their X** values. The "-e" option is used when the string to be searched for start Vs X** with a '-' character and could be confused with an option, and the "-f" X** option is used when the string or strings to be searched for is in a file V. X** We indicate such options by appending a '+' character to them in the stri Vng X** that is shell_mungs()'s fourth argument: X** X** shell_mung(&argc,&argv,2,"e+-f+"); X** X** (Note that the "-e" option also has a '-' character following it, since w Ve X** don't want its value to be globbed. When both '+' and '-' are used, the V '+' X** should always be first.) It should be noted that such option/value pairs X** should be typed early in the command line, in positions where the paramet Vers X** they're replacing would have been. For example, you would do this: X** X** $ fgrep -f stringfile inputfile X** X** But this would be an invitation to disaster: X** X** $ fgrep inputfile -f stringfile X** X** Programs that use the getopt() library function to process options will X** help you decide which options to include in shell_mung()'s fourth argumen Vt. X** The third argument to getopt() is a list of options, and options that hav Ve X** values are followed by a ':' character. Here's an example from the sourc Ve X** to the GNU "grep" program: X** X** while ((c = getopt(argc,argv,"0123456789A:B:CVbce:f:hilnsvwx")) != E VOF) X** X** This tells us that the "-A", "-B", "-e", and "-f" options have values. O Vf X** these, "-A", "-B", and "-e" have unglobbable values; and "-e" and "-f" ca Vn X** replace a parameter. Thus, our call to shell_mung() for the GNU grep X** program looks like this: X** X** shell_mung(&argc,&argv,2,"A-B-e+-f+"); X** X** The IO redirection capabilities provided are as follows: X** X** outfile Output goes to "outfile". X** >&outfile Output and errors go to "outfile". X** >>outfile Output appended to "outfile". X** >>&outfile Output and errors appended to "outfile". X** X** They can be used anywhere on the command line, except between an option a Vnd X** its value. Here are some examples: X** X** $ fgrep xyzzy *.txt >&lines_with_xyzzy.lis X** $ from -s flintstone >>accumulated_flintstone_missives.dat X** $ my_mailer -d !", ">&!", ">>!", and ">>&!" is also not implemented. VMS uses X** file versions, which makes it irrelevant. (5) If a globbable argument tu Vrns X** out to be unglobbable, the new vector will simply point to the original X** argument. (6) Pipes (as in the "`7C" and "`7C&" redirection characters) V are not X** implemented. X**-------------------------------------------------------------------------- V--- X** Calling Sequence X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** delta-arg-count = shell_mung(argc_p,argv_p,parameter_number,option_string V); X**-------------------------------------------------------------------------- V--- X** Formal Arguments Description X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E `7E`7E`7E`7E`7E`7E`7 VE`7E`7E`7E`7E X** argc_p Pointer to argument count (main()'s `60argc'). X** argv_p Pointer to argument vector (main()'s `60argv'). X** parameter_number Position among parameters where filespecs are expect Ved. X** option_string List of options that may be followed by filespecs. X**-------------------------------------------------------------------------- V--- X** Implicit Inputs: None X**-------------------------------------------------------------------------- V--- X** Implicit Outputs: None X**-------------------------------------------------------------------------- V--- X** Return Value X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** Returns the number of new arguments that have been added to the argument X** vector. In other words, the difference between the new value of `60argc_ Vp' X** and its old value. X**-------------------------------------------------------------------------- V--- X** Side Effects X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** Function may cause the program to exit if it can't open files for error, X** input, and output redirection. Uses global variable `60vaxc$errno' for e Vxit X** status. X**-------------------------------------------------------------------------- V--- X*/ Xint Xshell_mung(argc_p,argv_p,parameter_number,option_string) X int * argc_p; X char *** argv_p; X int parameter_number; X char * option_string; X`7B X /* --- LOCAL VARIABLES --- */ X X register char * arg_p; /* General-purpose argument pointer. X */ X int filespec_count; /* Number of filespecs in `60filespe Vc_v', X ** returned from shell_glob(). X */ X char ** filespec_v; /* Vector of filespecs returned from X ** shell_glob(). X */ X char from_err_too = FALSE; /* Flag set to indicate that error t Vext X ** will be redirected to a file alon Vg X ** with the output text. X */ X register int i_new; /* Index to new pointers in `60new_a Vrgv'. X */ X register int i_old; /* Index to old pointers in `60argv_ Vp'. X */ X char ** new_argv; /* New argument vector, which `60arg Vv_p' X ** will end up being replaced with. X */ X int new_argv_count; /* Count of pointers in `60new_argv' V. X */ X int output_fd; /* File descriptor for file being X ** created as redirected output, for X ** use with creat() and dup2(). X */ X int parameter_count = 0; /* Counts parameters---arguments tha Vt X ** don't have '<' or '>' or '-' in X ** front of them. When and if the X ** count reaches `60parameter_number V', X ** we start attempting to parse the X ** parameters as filespecs. X */ X register char * place_p; /* Location of a character, as retur Vned X ** from strchr() or strrchr(). X */ X X /* --- INITIALIZE THINGS --- */ X X /* Allocate the new argument vector. X */ X new_argv_count = *argc_p; X new_argv = xmalloc(new_argv_count * sizeof (char *)); X X /* Replace main()'s `60argv`5B0`5D' with a GNU-like truncated version. X */ X new_argv`5B0`5D = truncate_argv_0((*argv_p)`5B0`5D); X X /* --- TRAVERSE THE ARGUMENT VECTOR --- */ X X for (i_new = i_old = 1; i_old < *argc_p; ++i_old) X switch (*(arg_p = (*argv_p)`5Bi_old`5D)) X `7B X /* If it begins with '<', we're redirecting input. X */ X case '<': X filespec_v = shell_glob(++arg_p,NULL); X if (freopen(*filespec_v,"r",stdin) == NULL) X `7B X perror(*filespec_v); X sys$exit(vaxc$errno `7C STS$M_INHIB_MSG); X `7D X free(*filespec_v); X free(filespec_v); X --new_argv_count; X break; X X /* If it begins with '>', we're redirecting output. This comes in four X ** varieties, as one can append output to an existing file and/or send X ** error text out along with the output. If we're told to append it (by X ** two '>' characters), we try to access the filespec and append to it. X ** If we can't access it, we proceed as if we were told to create one. X ** We create an output file (which is also what we're told to do when we X ** only get one '>' character) with "standard" VMS attributes. If we're X ** told to redirect error text as well (by the '&' character), we set X ** `60stderr' to refer to the same file. X */ X case '>': X if (*++arg_p == '>') X `7B X if (*++arg_p == '&') X `7B X from_err_too = TRUE; X ++arg_p; X `7D X if (access(arg_p,2) == 0) X `7B X if (freopen(arg_p,"a",stdout) != NULL) X `7B X if (from_err_too == TRUE) X stderr = stdout; X --new_argv_count; X break; X `7D X perror(arg_p); X sys$exit(vaxc$errno `7C STS$M_INHIB_MSG); X `7D X `7D X /* We get to this point if we didn't want to append output text to an X ** existing file, or if an attempt to establish append access to an X ** existing file has failed. X */ X if ((from_err_too == FALSE) && (*arg_p == '&')) X `7B X from_err_too = TRUE; X ++arg_p; X `7D X if ( X ((output_fd = creat(arg_p,0,"rat=cr","rfm=var","mrs=512")) != 1) X && (dup2(output_fd,fileno(stdout)) != -1) X && ((from_err_too == FALSE) `7C`7C (dup2(output_fd,fileno(stderr)) != V -1)) X ) X `7B X --new_argv_count; X break; X `7D X perror(arg_p); X sys$exit(vaxc$errno `7C STS$M_INHIB_MSG); X X /* If it begins with '-' or '+', it's an option. We check it against X ** `60option_string' to see if it's an option followed by an argument. X */ X case '-': X case '+': X if ( X (option_string == NULL) X `7C`7C (((char *) place_p = strchr(option_string,(*(arg_p + 1)))) == 0 V) X ) X `7B X /* Option is not in `60option_string'. We copy it into `60new_argv'. X */ X new_argv`5Bi_new++`5D = arg_p; X `7D X else X `7B X /* Option is in `60option_string'. First we check to see if its exist Vence X ** is to be thought of as introducing a parameter. This is indicated V by X ** a '+' character following the option in `60option_string'. X */ X if (*++place_p == '+') X ++parameter_count; X else X --place_p; X X /* Next we check to see if the string following it is to be considered V an X ** input filespec. If a '-' character follows the option in `60option V_ X ** string' (or a '+' character following that option), that indicates X ** that it's not to be considered as such. X */ X if (*++place_p == '-') X `7B X new_argv`5Bi_new++`5D = arg_p; X if ((arg_p = (*argv_p)`5B++i_old`5D) == NULL) X goto BREAKOUT; X else`09`09`09`09`09/* V1.2-005 */ X new_argv`5Bi_new++`5D = arg_p;`09`09/* V1.2-005 */ X `7D X else X `7B X /* The string after the option is an input filespec, so we glob it. X ** But we glob it to return only the first match (if it's a wildcard V), X ** not all possible matches. X */ X if (*(arg_p + 2) == '\0') X `7B X new_argv = xrealloc(new_argv,(++new_argv_count * sizeof (char *))) V; X new_argv`5Bi_new++`5D = arg_p; X if ((arg_p = (*argv_p)`5B++i_old`5D) == NULL) X goto BREAKOUT; X X filespec_v = shell_glob(arg_p,NULL); X new_argv`5Bi_new++`5D = *filespec_v; X free(filespec_v); X `7D X else X `7B X filespec_v = shell_glob((arg_p + 2),NULL); X new_argv`5Bi_new`5D = xmalloc(2 + strlen(*filespec_v) + 1); X memcpy(new_argv`5Bi_new`5D,arg_p,2); X (void)strcpy((new_argv`5Bi_new++`5D + 2),*filespec_v); X free(*filespec_v); X free(filespec_v); X `7D X `7D X `7D X break; X X /* If we get here, the argument is a parameter. If we're not concerned X ** about parameters (that is, if `60parameter_number' is zero or less), V or X ** if the parameter count is less than `60parameter_number', we simply c Vopy X ** the parameter into the new argument vector. Otherwise, the parameter X ** and those following it are expected to be filespecs, and an attempt i Vs X ** made to parse them as such and put all resulting filespecs into the X ** argument vector. X */ X default: X if ((parameter_number <= 0) `7C`7C (++parameter_count < parameter_number V)) X new_argv`5Bi_new++`5D = arg_p; X else X `7B X filespec_v = shell_glob(arg_p,&filespec_count); X if (filespec_count == 1) X new_argv`5Bi_new++`5D = *filespec_v; X else X `7B X new_argv_count += filespec_count - 1; X new_argv = xrealloc(new_argv,(new_argv_count * sizeof (char *))); X memcpy(&new_argv`5Bi_new`5D,filespec_v,(filespec_count * sizeof (cha Vr *))); X i_new += filespec_count; X `7D X free(filespec_v); X `7D X break; X X `7D /* for/switch */ X XBREAKOUT: X X new_argv`5Bi_new`5D = NULL; X X /* --- UPDATE ARGUMENT COUNT AND ARGUMENT VECTOR --- */ X X *argc_p = i_new; X *argv_p = new_argv; X X return i_new - i_old; X X`7D /* shell_mung() */ X X/* -=- STATIC FUNCTION -=- */ X X/* truncate_argv_0 X**-------------------------------------------------------------------------- V--- X** Functional Description X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** Programs written in VAX C, when run under VMS DCL, will have their entir Ve X** filespec (i.e., the filespec of the running image) in the main() function V's X** `60argv`5B0`5D' variable. While this makes sense from a VMS standpoint, V it does X** not look very good in programs ported from GNU, which often use `60argv`5 VB0`5D' as X** an error message prefix. X** This function, which is called from shell_mung(), truncates the filespec V in X** `60argv`5B0`5D' to just the filename or, if the filetype is not ".EXE", t Vo the X** filename and filetype. X**-------------------------------------------------------------------------- V--- X** Calling Sequence X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** new_argv`5B0`5D = truncate_argv_0(given_filespec); X**-------------------------------------------------------------------------- V--- X** Formal Argument Description X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E `7E`7E`7E`7E`7E`7E`7E` V7E`7E`7E`7E X** given_filespec The filespec to be truncated. Assumed to be `60argv V`5B0`5D' X** or a pointer to the same thing `60argv`5B0`5D' point Vs to. X**-------------------------------------------------------------------------- V--- X** Implicit Inputs: None X**-------------------------------------------------------------------------- V--- X** Implicit Outputs: None X**-------------------------------------------------------------------------- V--- X** Return Value X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** Returns the truncated filespec, which is in newly-allocated memory. X**-------------------------------------------------------------------------- V--- X** Side Effects X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E X** Memory is allocated for the truncated filespec. X**-------------------------------------------------------------------------- V--- X*/ Xstatic char * Xtruncate_argv_0(given_filespec) X char * given_filespec; X`7B X /* --- LOCAL VARIABLES --- */ X X register char * character_p; /* General-purpose character pointer V, X ** used to lowercase filespec. X */ X char * expanded_filespec;`09`09/* v1.2-004 */ X /* Buffer to hold the expanded files Vpec X ** from a call to sys$parse(). X */ X register char * filespec_p; /* Pointer to truncated filespec to V be X ** returned. X */ X struct FAB fab = cc$rms_fab; /* RMS file access block for file. X */ X struct NAM nam = cc$rms_nam; /* RMS name block for file. X */ X X /* --- INITIALIZE FABS AND NAMS --- */ X X expanded_filespec = xmalloc(NAM$C_MAXRSS + 1);`09/* v1.2-004 */ X fab.fab$l_fna = given_filespec; X fab.fab$b_fns = strlen(given_filespec); X fab.fab$l_nam = &nam; X nam.nam$l_esa = expanded_filespec;`09`09`09/* v1.2-004 */ X nam.nam$b_ess = NAM$C_MAXRSS; X nam.nam$b_nop = NAM$M_SYNCHK; X X /* --- PARSE OUT THE GIVEN FILESPEC --- */ X X sys$parse(&fab); X X /* --- NUL-TERMINATE AND LOWERCASE FILESPEC --- */ X X *nam.nam$l_ver = '\0'; X X for (character_p = nam.nam$l_esa; *character_p; ++character_p) X *character_p = _tolower(*character_p);`09/* v1.2-004 */ X X /* --- RETURN TRUNCATED FILESPEC --- */ X X if (strcmp(nam.nam$l_type,".exe")) X filespec_p = xmalloc(nam.nam$b_name + nam.nam$b_type + 1); X else X `7B X *nam.nam$l_type = '\0'; X filespec_p = xmalloc(nam.nam$b_name + 1); X `7D X X (void)strcpy(filespec_p,nam.nam$l_name); X return filespec_p; X X`7D /* truncate_argv_0() */ $ CALL UNPACK SHELL_MUNG.C;1 69651810 $ create 'f' X`09`09 GNU GENERAL PUBLIC LICENSE X`09`09 Version 2, June 1991 X X Copyright (C) 1989, 1991 Free Software Foundation, Inc. X 675 Mass Ave, Cambridge, MA 02139, USA X Everyone is permitted to copy and distribute verbatim copies X of this license document, but changing it is not allowed. X X`09`09`09 Preamble X X The licenses for most software are designed to take away your Xfreedom to share and change it. By contrast, the GNU General Public XLicense is intended to guarantee your freedom to share and change free Xsoftware--to make sure the software is free for all its users. This XGeneral Public License applies to most of the Free Software XFoundation's software and to any other program whose authors commit to Xusing it. (Some other Free Software Foundation software is covered by Xthe GNU Library General Public License instead.) You can apply it to Xyour programs, too. X X When we speak of free software, we are referring to freedom, not Xprice. Our General Public Licenses are designed to make sure that you Xhave the freedom to distribute copies of free software (and charge for Xthis service if you wish), that you receive source code or can get it Xif you want it, that you can change the software or use pieces of it Xin new free programs; and that you know you can do these things. X X To protect your rights, we need to make restrictions that forbid Xanyone to deny you these rights or to ask you to surrender the rights. XThese restrictions translate to certain responsibilities for you if you Xdistribute copies of the software, or if you modify it. X X For example, if you distribute copies of such a program, whether Xgratis or for a fee, you must give the recipients all the rights that Xyou have. You must make sure that they, too, receive or can get the Xsource code. And you must show them these terms so they know their Xrights. X X We protect your rights with two steps: (1) copyright the software, and X(2) offer you this license which gives you legal permission to copy, Xdistribute and/or modify the software. X X Also, for each author's protection and ours, we want to make certain Xthat everyone understands that there is no warranty for this free Xsoftware. If the software is modified by someone else and passed on, we Xwant its recipients to know that what they have is not the original, so Xthat any problems introduced by others will not reflect on the original Xauthors' reputations. X X Finally, any free program is threatened constantly by software Xpatents. We wish to avoid the danger that redistributors of a free Xprogram will individually obtain patent licenses, in effect making the Xprogram proprietary. To prevent this, we have made it clear that any Xpatent must be licensed for everyone's free use or not licensed at all. X X The precise terms and conditions for copying, distribution and Xmodification follow. X`0C X`09`09 GNU GENERAL PUBLIC LICENSE X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION X X 0. This License applies to any program or other work which contains Xa notice placed by the copyright holder saying it may be distributed Xunder the terms of this General Public License. The "Program", below, Xrefers to any such program or work, and a "work based on the Program" Xmeans either the Program or any derivative work under copyright law: Xthat is to say, a work containing the Program or a portion of it, Xeither verbatim or with modifications and/or translated into another Xlanguage. (Hereinafter, translation is included without limitation in Xthe term "modification".) Each licensee is addressed as "you". X XActivities other than copying, distribution and modification are not Xcovered by this License; they are outside its scope. The act of Xrunning the Program is not restricted, and the output from the Program Xis covered only if its contents constitute a work based on the XProgram (independent of having been made by running the Program). XWhether that is true depends on what the Program does. X X 1. You may copy and distribute verbatim copies of the Program's Xsource code as you receive it, in any medium, provided that you Xconspicuously and appropriately publish on each copy an appropriate Xcopyright notice and disclaimer of warranty; keep intact all the Xnotices that refer to this License and to the absence of any warranty; Xand give any other recipients of the Program a copy of this License Xalong with the Program. X XYou may charge a fee for the physical act of transferring a copy, and Xyou may at your option offer warranty protection in exchange for a fee. X X 2. You may modify your copy or copies of the Program or any portion Xof it, thus forming a work based on the Program, and copy and Xdistribute such modifications or work under the terms of Section 1 Xabove, provided that you also meet all of these conditions: X X a) You must cause the modified files to carry prominent notices X stating that you changed the files and the date of any change. X X b) You must cause any work that you distribute or publish, that in X whole or in part contains or is derived from the Program or any X part thereof, to be licensed as a whole at no charge to all third X parties under the terms of this License. X X c) If the modified program normally reads commands interactively X when run, you must cause it, when started running for such X interactive use in the most ordinary way, to print or display an X announcement including an appropriate copyright notice and a X notice that there is no warranty (or else, saying that you provide X a warranty) and that users may redistribute the program under X these conditions, and telling the user how to view a copy of this X License. (Exception: if the Program itself is interactive but X does not normally print such an announcement, your work based on X the Program is not required to print an announcement.) X`0C XThese requirements apply to the modified work as a whole. If Xidentifiable sections of that work are not derived from the Program, Xand can be reasonably considered independent and separate works in Xthemselves, then this License, and its terms, do not apply to those Xsections when you distribute them as separate works. But when you Xdistribute the same sections as part of a whole which is a work based Xon the Program, the distribution of the whole must be on the terms of Xthis License, whose permissions for other licensees extend to the Xentire whole, and thus to each and every part regardless of who wrote it. X XThus, it is not the intent of this section to claim rights or contest Xyour rights to work written entirely by you; rather, the intent is to Xexercise the right to control the distribution of derivative or Xcollective works based on the Program. X XIn addition, mere aggregation of another work not based on the Program Xwith the Program (or with a work based on the Program) on a volume of Xa storage or distribution medium does not bring the other work under Xthe scope of this License. X X 3. You may copy and distribute the Program (or a work based on it, Xunder Section 2) in object code or executable form under the terms of XSections 1 and 2 above provided that you also do one of the following: X X a) Accompany it with the complete corresponding machine-readable X source code, which must be distributed under the terms of Sections X 1 and 2 above on a medium customarily used for software interchange; or, X X b) Accompany it with a written offer, valid for at least three X years, to give any third party, for a charge no more than your X cost of physically performing source distribution, a complete X machine-readable copy of the corresponding source code, to be X distributed under the terms of Sections 1 and 2 above on a medium X customarily used for software interchange; or, X X c) Accompany it with the information you received as to the offer X to distribute corresponding source code. (This alternative is X allowed only for noncommercial distribution and only if you X received the program in object code or executable form with such X an offer, in accord with Subsection b above.) X XThe source code for a work means the preferred form of the work for Xmaking modifications to it. For an executable work, complete source Xcode means all the source code for all modules it contains, plus any Xassociated interface definition files, plus the scripts used to Xcontrol compilation and installation of the executable. However, as a Xspecial exception, the source code distributed need not include Xanything that is normally distributed (in either source or binary Xform) with the major components (compiler, kernel, and so on) of the Xoperating system on which the executable runs, unless that component Xitself accompanies the executable. X XIf distribution of executable or object code is made by offering Xaccess to copy from a designated place, then offering equivalent Xaccess to copy the source code from the same place counts as Xdistribution of the source code, even though third parties are not Xcompelled to copy the source along with the object code. X`0C X 4. You may not copy, modify, sublicense, or distribute the Program Xexcept as expressly provided under this License. Any attempt Xotherwise to copy, modify, sublicense or distribute the Program is Xvoid, and will automatically terminate your rights under this License. XHowever, parties who have received copies, or rights, from you under Xthis License will not have their licenses terminated so long as such Xparties remain in full compliance. X X 5. You are not required to accept this License, since you have not Xsigned it. However, nothing else grants you permission to modify or Xdistribute the Program or its derivative works. These actions are Xprohibited by law if you do not accept this License. Therefore, by Xmodifying or distributing the Program (or any work based on the XProgram), you indicate your acceptance of this License to do so, and Xall its terms and conditions for copying, distributing or modifying Xthe Program or works based on it. X X 6. Each time you redistribute the Program (or any work based on the XProgram), the recipient automatically receives a license from the Xoriginal licensor to copy, distribute or modify the Program subject to Xthese terms and conditions. You may not impose any further Xrestrictions on the recipients' exercise of the rights granted herein. XYou are not responsible for enforcing compliance by third parties to Xthis License. X X 7. If, as a consequence of a court judgment or allegation of patent Xinfringement or for any other reason (not limited to patent issues), Xconditions are imposed on you (whether by court order, agreement or Xotherwise) that contradict the conditions of this License, they do not Xexcuse you from the conditions of this License. If you cannot Xdistribute so as to satisfy simultaneously your obligations under this XLicense and any other pertinent obligations, then as a consequence you Xmay not distribute the Program at all. For example, if a patent Xlicense would not permit royalty-free redistribution of the Program by Xall those who receive copies directly or indirectly through you, then Xthe only way you could satisfy both it and this License would be to Xrefrain entirely from distribution of the Program. X XIf any portion of this section is held invalid or unenforceable under Xany particular circumstance, the balance of the section is intended to Xapply and the section as a whole is intended to apply in other Xcircumstances. X XIt is not the purpose of this section to induce you to infringe any Xpatents or other property right claims or to contest validity of any Xsuch claims; this section has the sole purpose of protecting the Xintegrity of the free software distribution system, which is Ximplemented by public license practices. Many people have made Xgenerous contributions to the wide range of software distributed Xthrough that system in reliance on consistent application of that Xsystem; it is up to the author/donor to decide if he or she is willing Xto distribute software through any other system and a licensee cannot Ximpose that choice. X XThis section is intended to make thoroughly clear what is believed to Xbe a consequence of the rest of this License. X`0C X 8. If the distribution and/or use of the Program is restricted in Xcertain countries either by patents or by copyrighted interfaces, the Xoriginal copyright holder who places the Program under this License Xmay add an explicit geographical distribution limitation excluding Xthose countries, so that distribution is permitted only in or among Xcountries not thus excluded. In such case, this License incorporates Xthe limitation as if written in the body of this License. X X 9. The Free Software Foundation may publish revised and/or new versions Xof the General Public License from time to time. Such new versions will Xbe similar in spirit to the present version, but may differ in detail to Xaddress new problems or concerns. X XEach version is given a distinguishing version number. If the Program Xspecifies a version number of this License which applies to it and "any Xlater version", you have the option of following the terms and conditions Xeither of that version or of any later version published by the Free XSoftware Foundation. If the Program does not specify a version number of Xthis License, you may choose any version ever published by the Free Software XFoundation. X X 10. If you wish to incorporate parts of the Program into other free Xprograms whose distribution conditions are different, write to the author Xto ask for permission. For software which is copyrighted by the Free XSoftware Foundation, write to the Free Software Foundation; we sometimes Xmake exceptions for this. Our decision will be guided by the two goals Xof preserving the free status of all derivatives of our free software and Xof promoting the sharing and reuse of software generally. X X`09`09`09 NO WARRANTY X X 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, XREPAIR OR CORRECTION. X X 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE XPOSSIBILITY OF SUCH DAMAGES. X X`09`09 END OF TERMS AND CONDITIONS X`0C X`09Appendix: How to Apply These Terms to Your New Programs X X If you develop a new program, and you want it to be of the greatest Xpossible use to the public, the best way to achieve this is to make it Xfree software which everyone can redistribute and change under these terms. X X To do so, attach the following notices to the program. It is safest Xto attach them to the start of each source file to most effectively Xconvey the exclusion of warranty; and each file should have at least Xthe "copyright" line and a pointer to where the full notice is found. X X X Copyright (C) 19yy X X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License as published by X the Free Software Foundation; either version 2 of the License, or X (at your option) any later version. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X XAlso add information on how to contact you by electronic and paper mail. X XIf the program is interactive, make it output a short notice like this Xwhen it starts in an interactive mode: X X Gnomovision version 69, Copyright (C) 19yy name of author X Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `60show V w'. X This is free software, and you are welcome to redistribute it X under certain conditions; type `60show c' for details. X XThe hypothetical commands `60show w' and `60show c' should show the appropri Vate Xparts of the General Public License. Of course, the commands you use may Xbe called something other than `60show w' and `60show c'; they could even be Xmouse-clicks or menu items--whatever suits your program. X XYou should also get your employer (if you work as a programmer) or your Xschool, if any, to sign a "copyright disclaimer" for the program, if Xnecessary. Here is a sample; alter the names: X X Yoyodyne, Inc., hereby disclaims all copyright interest in the program X `60Gnomovision' (which makes passes at compilers) written by James Hacker. X X , 1 April 1989 X Ty Coon, President of Vice X XThis General Public License does not permit incorporating your program into Xproprietary programs. If your program is a subroutine library, you may Xconsider it more useful to permit linking proprietary applications with the Xlibrary. If this is what you want to do, use the GNU Library General XPublic License instead of this License. $ CALL UNPACK LICENSE.;1 2085147919 $ v=f$verify(v) $ EXIT