home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume4 / echoall < prev    next >
Text File  |  1989-02-03  |  4KB  |  151 lines

  1. Path: xanth!mcnc!gatech!cwjcc!hal!ncoast!allbery
  2. From: RJRAY@aardvark.ucs.uoknor.edu (Longshot)
  3. Newsgroups: comp.sources.misc
  4. Subject: v04i016: Environment var. echo
  5. Message-ID: <8808060355.AA24872@uunet.UU.NET>
  6. Date: 6 Aug 88 03:55:00 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: RJRAY@aardvark.ucs.uoknor.edu (Longshot)
  9. Distribution: usa
  10. Organization: University of Oklahoma, Norman
  11. Lines: 137
  12. Approved: allbery@ncoast.UUCP
  13.  
  14. Posting-number: Volume 4, Issue 16
  15. Submitted-by: "Longshot" <RJRAY@aardvark.ucs.uoknor.edu>
  16. Archive-name: echoall
  17.  
  18. [A PD "printenv", with sorting.  ++bsa]
  19.  
  20. Below is a quick little program I wrote when I decided I needed to know
  21. the values of my environment variables, with less typing. It works for
  22. any C that implements the third parameter to main(), namely "envp." It
  23. runs the array through a small sort written to handle character arrays/
  24. pointers. The program is small, and the sort is currently a bubble-sort.
  25. I plan to re-do the sort at least, but I needed to get this running in
  26. a hurry. For < 25 variables, BS (no pun intended) should be just fine.
  27. Included is man page and Kwik-Shot Makefile.
  28.  
  29. Randy
  30. ---- Cut Here and unpack ----
  31. #!/bin/sh
  32. # shar:    Shell Archiver  (v1.22)
  33. #    Packed Fri Aug  5 22:42:55 CDT 1988 by uokmax!rjray
  34. #    from directory /aurora/eecs/rjray/C
  35. #
  36. #    Run the following text with /bin/sh to create:
  37. #      Makefile
  38. #      echoall.c
  39. #      ssort.c
  40. #      echoall.1
  41. #
  42. echo "x - extracting Makefile (Text)"
  43. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  44. X
  45. X#
  46. X# Kwik-Shot Makefile
  47. XCFLAGS=-O
  48. XSRC=echoall.c ssort.c
  49. XOBJ=echoall.o ssort.o
  50. X
  51. Xechoall: $(OBJ)
  52. X    cc $(CFLAGS) -o echoall $(OBJ)
  53. SHAR_EOF
  54. chmod 0644 Makefile || echo "restore of Makefile fails"
  55. set `wc -c Makefile`;Sum=$1
  56. if test "$Sum" != "127"
  57. then echo original size 127, current size $Sum;fi
  58. echo "x - extracting echoall.c (Text)"
  59. sed 's/^X//' << 'SHAR_EOF' > echoall.c &&
  60. X/*
  61. X    Echo all environment variables.
  62. X*/
  63. X
  64. X#include <stdio.h>
  65. X
  66. Xextern ssort();
  67. X
  68. Xmain(argc,argv,envp)
  69. Xint argc;
  70. Xchar **argv,**envp;
  71. X{
  72. X    int i;
  73. X
  74. X    ssort(envp);
  75. X    for (i=0; envp[i] != 0; i++) {
  76. X        puts(envp[i]);
  77. X    }
  78. X}
  79. SHAR_EOF
  80. chmod 0644 echoall.c || echo "restore of echoall.c fails"
  81. set `wc -c echoall.c`;Sum=$1
  82. if test "$Sum" != "207"
  83. then echo original size 207, current size $Sum;fi
  84. echo "x - extracting ssort.c (Text)"
  85. sed 's/^X//' << 'SHAR_EOF' > ssort.c &&
  86. X/*
  87. X    This routine sorts a given string array. It forces the typing into
  88. X    "char *array[]" to aid in manipulating the pointers.
  89. X
  90. X    Started: 8-5-88
  91. X*/
  92. X
  93. X/*
  94. X    Source written by and held by Randy J. Ray. Use only by permission.
  95. X*/
  96. X
  97. X#include <string.h>
  98. X
  99. Xssort(dest)
  100. Xchar *dest[];
  101. X{
  102. X    char *tmp;
  103. X    int count,i,touched=1;
  104. X
  105. X    /* Determine the number of elements. Adds a small amount of overhead,
  106. X       but eliminates need for caller to do so. */
  107. X    for (count = 0; dest[count] != 0; count++) ;
  108. X    count--;
  109. X    /* The sorting method currently in use is the bubble-sort, mainly
  110. X       due to time needed in development. Later revisions will include
  111. X       faster sorts. */
  112. X    while (touched) {
  113. X        touched=0;
  114. X        for (i=0; i<count; i++) {
  115. X            if (strcmp(dest[i],dest[i+1]) > 0) {
  116. X                tmp=dest[i];
  117. X                dest[i]=dest[i+1];
  118. X                dest[i+1]=tmp;
  119. X                touched=1;
  120. X            }
  121. X        }
  122. X        count--;
  123. X    }
  124. X}
  125. SHAR_EOF
  126. chmod 0644 ssort.c || echo "restore of ssort.c fails"
  127. set `wc -c ssort.c`;Sum=$1
  128. if test "$Sum" != "839"
  129. then echo original size 839, current size $Sum;fi
  130. echo "x - extracting echoall.1 (Text)"
  131. sed 's/^X//' << 'SHAR_EOF' > echoall.1 &&
  132. X.TH ECHOALL 1 LOCAL
  133. X.SH NAME
  134. Xechoall \- echo the values of all environment variables
  135. X.SH SYNOPSIS
  136. Xechoall
  137. X.SH DESCRIPTION
  138. X.B Echoall
  139. Xreads all environment variables currently set and prints them to the
  140. Xscreen, one to a line, sorted alphabetically.
  141. X.SH "SEE ALSO"
  142. Xsh(1), csh(1)
  143. X.SH AUTHOR
  144. XRandy J. Ray
  145. SHAR_EOF
  146. chmod 0644 echoall.1 || echo "restore of echoall.1 fails"
  147. set `wc -c echoall.1`;Sum=$1
  148. if test "$Sum" != "301"
  149. then echo original size 301, current size $Sum;fi
  150. exit 0
  151.