home *** CD-ROM | disk | FTP | other *** search
- Path: xanth!mcnc!gatech!cwjcc!hal!ncoast!allbery
- From: RJRAY@aardvark.ucs.uoknor.edu (Longshot)
- Newsgroups: comp.sources.misc
- Subject: v04i016: Environment var. echo
- Message-ID: <8808060355.AA24872@uunet.UU.NET>
- Date: 6 Aug 88 03:55:00 GMT
- Sender: allbery@ncoast.UUCP
- Reply-To: RJRAY@aardvark.ucs.uoknor.edu (Longshot)
- Distribution: usa
- Organization: University of Oklahoma, Norman
- Lines: 137
- Approved: allbery@ncoast.UUCP
-
- Posting-number: Volume 4, Issue 16
- Submitted-by: "Longshot" <RJRAY@aardvark.ucs.uoknor.edu>
- Archive-name: echoall
-
- [A PD "printenv", with sorting. ++bsa]
-
- Below is a quick little program I wrote when I decided I needed to know
- the values of my environment variables, with less typing. It works for
- any C that implements the third parameter to main(), namely "envp." It
- runs the array through a small sort written to handle character arrays/
- pointers. The program is small, and the sort is currently a bubble-sort.
- I plan to re-do the sort at least, but I needed to get this running in
- a hurry. For < 25 variables, BS (no pun intended) should be just fine.
- Included is man page and Kwik-Shot Makefile.
-
- Randy
- ---- Cut Here and unpack ----
- #!/bin/sh
- # shar: Shell Archiver (v1.22)
- # Packed Fri Aug 5 22:42:55 CDT 1988 by uokmax!rjray
- # from directory /aurora/eecs/rjray/C
- #
- # Run the following text with /bin/sh to create:
- # Makefile
- # echoall.c
- # ssort.c
- # echoall.1
- #
- echo "x - extracting Makefile (Text)"
- sed 's/^X//' << 'SHAR_EOF' > Makefile &&
- X
- X#
- X# Kwik-Shot Makefile
- XCFLAGS=-O
- XSRC=echoall.c ssort.c
- XOBJ=echoall.o ssort.o
- X
- Xechoall: $(OBJ)
- X cc $(CFLAGS) -o echoall $(OBJ)
- SHAR_EOF
- chmod 0644 Makefile || echo "restore of Makefile fails"
- set `wc -c Makefile`;Sum=$1
- if test "$Sum" != "127"
- then echo original size 127, current size $Sum;fi
- echo "x - extracting echoall.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > echoall.c &&
- X/*
- X Echo all environment variables.
- X*/
- X
- X#include <stdio.h>
- X
- Xextern ssort();
- X
- Xmain(argc,argv,envp)
- Xint argc;
- Xchar **argv,**envp;
- X{
- X int i;
- X
- X ssort(envp);
- X for (i=0; envp[i] != 0; i++) {
- X puts(envp[i]);
- X }
- X}
- SHAR_EOF
- chmod 0644 echoall.c || echo "restore of echoall.c fails"
- set `wc -c echoall.c`;Sum=$1
- if test "$Sum" != "207"
- then echo original size 207, current size $Sum;fi
- echo "x - extracting ssort.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > ssort.c &&
- X/*
- X This routine sorts a given string array. It forces the typing into
- X "char *array[]" to aid in manipulating the pointers.
- X
- X Started: 8-5-88
- X*/
- X
- X/*
- X Source written by and held by Randy J. Ray. Use only by permission.
- X*/
- X
- X#include <string.h>
- X
- Xssort(dest)
- Xchar *dest[];
- X{
- X char *tmp;
- X int count,i,touched=1;
- X
- X /* Determine the number of elements. Adds a small amount of overhead,
- X but eliminates need for caller to do so. */
- X for (count = 0; dest[count] != 0; count++) ;
- X count--;
- X /* The sorting method currently in use is the bubble-sort, mainly
- X due to time needed in development. Later revisions will include
- X faster sorts. */
- X while (touched) {
- X touched=0;
- X for (i=0; i<count; i++) {
- X if (strcmp(dest[i],dest[i+1]) > 0) {
- X tmp=dest[i];
- X dest[i]=dest[i+1];
- X dest[i+1]=tmp;
- X touched=1;
- X }
- X }
- X count--;
- X }
- X}
- SHAR_EOF
- chmod 0644 ssort.c || echo "restore of ssort.c fails"
- set `wc -c ssort.c`;Sum=$1
- if test "$Sum" != "839"
- then echo original size 839, current size $Sum;fi
- echo "x - extracting echoall.1 (Text)"
- sed 's/^X//' << 'SHAR_EOF' > echoall.1 &&
- X.TH ECHOALL 1 LOCAL
- X.SH NAME
- Xechoall \- echo the values of all environment variables
- X.SH SYNOPSIS
- Xechoall
- X.SH DESCRIPTION
- X.B Echoall
- Xreads all environment variables currently set and prints them to the
- Xscreen, one to a line, sorted alphabetically.
- X.SH "SEE ALSO"
- Xsh(1), csh(1)
- X.SH AUTHOR
- XRandy J. Ray
- SHAR_EOF
- chmod 0644 echoall.1 || echo "restore of echoall.1 fails"
- set `wc -c echoall.1`;Sum=$1
- if test "$Sum" != "301"
- then echo original size 301, current size $Sum;fi
- exit 0
-