Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator) (07/08/90)
Submitted-by: peterc@softway.sw.oz.au (Peter Chubb) Posting-number: Volume 90, Issue 202 Archive-name: unix/env-1.1/part01 ENV is a utility to print out the values of all 1.3 Environment variables. It has been optimised for size, and takes less than 488 bytes. Moreover, unlike other routines I have seen for handling environment variables, it copes with variables with embedded newlines. #!/bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 1 (of 1)." # Contents: Makefile env.c env.doc env.uu # Wrapped by tadguy@xanth on Sun Jul 8 11:36:44 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(389 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# X# Makefile for env X# X# $Header: local:src/MINE/cmd/env/RCS/Makefile,v 1.2 90/05/26 12:55:30 peterc Exp $ X# X# $Log: Makefile,v $ X# Revision 1.2 90/05/26 12:55:30 peterc X# Added RCS goo X# X# X# Xenv: env.o X blink from env.o to env nd X protect env +p X Xenv.o: env.c X lc -cus -v -O env.c X X Xinstall: env X copy env local:bin X Xclean: X rm -f env.o X Xclobber: clean X rm -f env X X.DEFAULT: X co $@ END_OF_FILE if test 389 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'env.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'env.c'\" else echo shar: Extracting \"'env.c'\" \(1689 characters\) sed "s/^X//" >'env.c' <<'END_OF_FILE' X/************************************************************************ X * env.c -- print all the environment * X * * X * Copyright 1990 Peter Chubb * X * All rights reserved * X * * X ************************************************************************/ X Xstatic char RCSID[] = "$Id: env.c,v 1.1 90/05/26 12:46:48 peterc Exp $"; X X/* X * X * $Log: env.c,v $ X * Revision 1.1 90/05/26 12:46:48 peterc X * Initial revision X * X * X */ X X# include <exec/types.h> X# include <proto/dos.h> X# include <proto/exec.h> X# include <string.h> X X# define ENVDIR "ENV:" X# define BUFSIZ 512 X Xvoid X_main() X{ X BPTR lck; X BPTR Op; X BPTR Ep; X struct FileInfoBlock *FB = AllocMem(sizeof(struct FileInfoBlock), 0); X long Status = 0; X register char *p; X register char *q; X int len; X struct DosLibrary *DOSBase; X char *buf = AllocMem(BUFSIZ, 0); X X if (!(DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 0))) X return; X X Op = Output(); X X lck = Lock(ENVDIR, SHARED_LOCK); X if (lck) X { X Status = Examine(lck, FB); X if (Status) X while (ExNext(lck, FB)) X { X if (FB->fib_EntryType >= 0) X continue; X Write(Op, FB->fib_FileName, strlen(FB->fib_FileName)); X Write(Op, "=", 1); X for (p = ENVDIR, q = buf; *p; *q++ = *p++) X ; X for (p = FB->fib_FileName; *p; *q++ = *p++) X ; X *q = '\0'; X X if ((Ep = Open(buf, MODE_OLDFILE)) != (BPTR)0) X { X if ((len = Read(Ep, buf, BUFSIZ)) > 0) X { X Write(Op, buf, len); X } X Close(Ep); X } X Write(Op, "\n", 1); X } X UnLock(lck); X } X X CloseLibrary((struct Library *)DOSBase); X FreeMem(buf, BUFSIZ); X FreeMem(FB, sizeof (*FB)); X} END_OF_FILE if test 1689 -ne `wc -c <'env.c'`; then echo shar: \"'env.c'\" unpacked with wrong size! fi # end of 'env.c' fi if test -f 'env.doc' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'env.doc'\" else echo shar: Extracting \"'env.doc'\" \(1311 characters\) sed "s/^X//" >'env.doc' <<'END_OF_FILE' X ENV -- print out environment variables. X X ENV is a 484 byte program that prints out the values of all the X 1.3 Environment variables. It is fully reentrant (i.e., X can be made resident). X XTo use, just type X env X X The result is a list of environment variables in the form X NAME=Value, one per line. X XBUGS: X Environment variables whose values are greater than 511 bytes X long are truncated at 511 bytes. X XAUTHOR: X Peter Chubb (peterc@softway.oz.au) X X X Copyright 1990 Peter Chubb X All rights reserved. X This program and its associated documentation may not be X distributed for profit. It may be distributed provided X a) no charge is made other than for reasonable copying and X media expenses, X b) no change is made to the source, documentation or binary, X that is not clearly marked as being a change, and X c) all files are provided. These comprise: X env.doc -- this documentation file X env -- the program binary X Makefile-- to make the program X env.c -- the program source. X X This program is not warranted, or guaranteed. X You get exactly what you paid for -- a copy of the program to X do as you wish with. If it crashes your machine, writes rude X letters to your spouse, or explodes in your face ... caveat X emptor! However, to the best of my knowledge and belief it X works as advertised. END_OF_FILE if test 1311 -ne `wc -c <'env.doc'`; then echo shar: \"'env.doc'\" unpacked with wrong size! fi # end of 'env.doc' fi if test -f 'env.uu' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'env.uu'\" else echo shar: Extracting \"'env.uu'\" \(711 characters\) sed "s/^X//" >'env.uu' <<'END_OF_FILE' Xbegin 500 env XM```#\P`````````"``````````$```!@````#````^D```!@3E7_\$CG-S`@Y XM/````01R`"QX``1.KO\Z)$`@2B](`"@@/````@!R`$ZN_SHO0``D0_H!.'``[ XM3J[]V"9`($LO2``@(`MG``$<)&\`*"9(+$M.KO_$+@!#^@$>(@ET_DZN_ZPL! XM`$J&9P``UB(&)`I.KO^:2H!G``#`8```K"`J`'A*@&H``*(D;P`H)F\`($'JH XM``@B2$H99OQ3B9/(+T@`'"(')`@F"2Q+3J[_T"('0_H`S"0)=@%.KO_01_H`I XMNB1O`"1@`A3;2A-F^B9O`!Q@`A3;2A-F^D(2)F\`("1O`"0B"BQ+)#P```/MQ XM3J[_XBH`2H5G("(%)`HF/````@!.KO_62H!O""(')@!.KO_0(@5.KO_<(@=!J XM^@!F)`AV`4ZN_]`D;P`H(@8D"BQ+3J[_E$J`9@#_2"(&+$M.KO^F(DLL>``$Q XM3J[^8B)O`"0@/````@!.KO\N(DH@/````01.KO\N3-\,[$Y=3G5D;W,N;&EB* XM<F%R>0!%3E8Z```]``H````#\@```^H````,)$ED.B!E;G8N8RQV(#$N,2`Y& XB,"\P-2\R-B`Q,CHT-CHT."!P971E<F,@17AP("0````#\G8NU X`` Xend Xsize 484 END_OF_FILE if test 711 -ne `wc -c <'env.uu'`; then echo shar: \"'env.uu'\" unpacked with wrong size! fi # end of 'env.uu' fi echo shar: End of archive 1 \(of 1\). cp /dev/null ark1isdone MISSING="" for I in 1 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have the archive. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Mail submissions (sources or binaries) to <amiga@cs.odu.edu>. Mail comments to the moderator at <amiga-request@cs.odu.edu>. Post requests for sources, and general discussion to comp.sys.amiga.