home *** CD-ROM | disk | FTP | other *** search
- From: dfs@doe.carleton.ca (David F. Skoll)
- Newsgroups: comp.sources.misc
- Subject: v42i017: envv - handle env. variables in shell-independent way, Patch01
- Date: 28 Mar 1994 17:30:44 -0600
- Organization: Carleton University
- Sender: kent@sparky.sterling.com
- Approved: kent@sparky.sterling.com
- Message-ID: <2n7pb4$pin@sparky.sterling.com>
- X-Md4-Signature: f2b7393c4d214c502b8f5141e5a7fe2f
-
- Submitted-by: dfs@doe.carleton.ca (David F. Skoll)
- Posting-number: Volume 42, Issue 17
- Archive-name: envv/patch01
- Environment: UNIX
- Patch-To: envv: Volume 41, Issue 153
-
- This is patch 1 for envv, a program to handle environment variables
- in a shell-independent manner.
-
- Envv is available via anonymous ftp at ftp.doe.carleton.ca (134.117.9.35)
- in /pub/misc/envv-1.1.tar.Z
-
- Here's what's new in this patch:
-
- * Version 1.1 (22 March 1994)
-
- + Enhancements
-
- - Modified the path manipulation commands so that trailing slashes do
- not affect comparison of directories. That is, foo/bar/ and foo/bar
- are considered the same.
-
- - Added the 'zsh' shell to the list of shells envv recognizes.
-
- - Added the 'choose' directive -- see the man page.
-
- And here's the patch itself. Unshar in the source directory and type
- 'patch < patch.01'
-
- --
- David F. Skoll
-
- #!/bin/sh
- # This is envv/patch01/part, a shell archive (shar 3.32)
- # made 03/22/1994 17:10 UTC by <dfs@doe.carleton.ca> (David F. Skoll)
- # Source directory /tmp_mnt/home/dfs/work/envv-1.1
- #
- # existing files WILL be overwritten
- #
- #
- #
- #
- # This shar contains:
- # length mode name
- # ------ ---------- ------------------------------------------
- # 11415 -rw------- patch.01
- #
- if touch 2>&1 | fgrep 'amc' > /dev/null
- then TOUCH=touch
- else TOUCH=true
- fi
- if test -r shar3_seq_.tmp; then
- echo "Must unpack archives in sequence!"
- next=`cat shar3_seq_.tmp`; echo "Please unpack part $next next"
- exit 1
- fi
- # ============= patch.01 ==============
- echo "x - extracting patch.01 (Text)"
- sed 's/^X//' << 'SHAR_EOF' > patch.01 &&
- XPrereq: VERSION=1.0
- X*** ../envv-1.0/Makefile Tue Mar 22 12:08:22 1994
- X--- ./Makefile Tue Mar 22 12:01:52 1994
- X***************
- X*** 1,6 ****
- X # Makefile for envv.
- X
- X! VERSION=1.0
- X
- X SRCS=envv.c
- X FILES=$(SRCS) Makefile README envv.1
- X--- 1,6 ----
- X # Makefile for envv.
- X
- X! VERSION=1.1
- X
- X SRCS=envv.c
- X FILES=$(SRCS) Makefile README envv.1
- X*** ../envv-1.0/README Tue Mar 22 12:08:23 1994
- X--- ./README Tue Mar 22 12:00:14 1994
- X***************
- X*** 28,32 ****
- X--- 28,50 ----
- X 'envv', which you can copy to your favourite system directory. The manual
- X page is in 'envv.1'
- X
- X+ CHANGES TO ENVV:
- X+
- X+ * Version 1.1 (22 March 1994)
- X+
- X+ + Enhancements
- X+
- X+ - Modified the path manipulation commands so that trailing slashes do
- X+ not affect comparison of directories. That is, foo/bar/ and foo/bar
- X+ are considered the same.
- X+
- X+ - Added the 'zsh' shell to the list of shells envv recognizes.
- X+
- X+ - Added the 'choose' directive -- see the man page.
- X+
- X+ * Version 1.0 (8 Feb 1994)
- X+
- X+ - First version.
- X+
- X --
- X David F. Skoll
- X*** ../envv-1.0/envv.1 Tue Mar 22 12:08:23 1994
- X--- ./envv.1 Tue Mar 22 12:00:27 1994
- X***************
- X*** 1,4 ****
- X! .TH ENVV 1 "8 February 1994"
- X .UC 4
- X .SH NAME
- X envv \- manipulate environment variables in shell-independent manner
- X--- 1,4 ----
- X! .TH ENVV 1 "22 March 1994"
- X .UC 4
- X .SH NAME
- X envv \- manipulate environment variables in shell-independent manner
- X***************
- X*** 10,15 ****
- X--- 10,17 ----
- X \fBenvv move\fR \fIpath_var\fR \fIdir\fR \fIpos\fR
- X .PP
- X \fBenvv del\fR \fIpath_var\fR \fIdir\fR
- X+ .PP
- X+ \fBenvv choose\fR \fIsh_val\fR \fIcsh_val\fR
- X .SH DESCRIPTION
- X \fBEnvv\fR is used to manipulate environment variables in a shell-independent
- X manner. It is most useful in administrator-maintained setup files for
- X***************
- X*** 87,92 ****
- X--- 89,116 ----
- X envv move P d 1 yields "setenv P d:a:b:c"
- X envv move P e 1 yields nothing - e is not on path.
- X .fi
- X+ .SH CHOOSE
- X+ The \fBchoose\fR command is very simple: It takes two arguments. If
- X+ the user's shell is like \fBsh\fR, then the first argument is printed.
- X+ If it is like \fBcsh\fR, then the second argument is printed.
- X+ .PP
- X+ This is useful if commercial vendors have supplied two versions of
- X+ scripts which must be sourced. Your system script can select the
- X+ proper script as follows:
- X+ .PP
- X+ .nf
- X+ source `envv choose script.sh script.csh`
- X+ .fi
- X+ .PP
- X+ This can also be used as an escape hatch for complicated tests which
- X+ really do require two separate shell scripts.
- X+ .PP
- X+ .SH NOTES
- X+ The path-manipulation directives (\fBadd\fR, \fBmove\fR, \fBdel\fR)
- X+ ignore trailing slashes when comparing path components. Thus,
- X+ "/usr/local" and "/usr/local/" are considered the same. When
- X+ components are added or moved in a path variable, they inherit
- X+ whatever slashes are supplied in the \fIdir\fR argument. Experiment...
- X .PP
- X .SH AUTHOR
- X \fBEnvv\fR is Copyright 1994 by David F. Skoll. It may be distributed for
- X*** ../envv-1.0/envv.c Tue Mar 22 12:08:22 1994
- X--- ./envv.c Tue Mar 22 11:53:31 1994
- X***************
- X*** 8,13 ****
- X--- 8,14 ----
- X /* Copyright (C) 1994 by David F. Skoll */
- X /* */
- X /* Usage: */
- X+ /* eval `envv choose sh-name csh-name` */
- X /* eval `envv set ENVVAR value` */
- X /* eval `envv add PATHVAR dir [position]` */
- X /* eval `envv del PATHVAR dir` */
- X***************
- X*** 14,20 ****
- X /* eval `envv move PATHVAR dir position` */
- X /* */
- X /***************************************************************/
- X! #define VERSION "1.0"
- X
- X #define _POSIX_SOURCE
- X #include <stdio.h>
- X--- 15,21 ----
- X /* eval `envv move PATHVAR dir position` */
- X /* */
- X /***************************************************************/
- X! #define VERSION "1.1"
- X
- X #define _POSIX_SOURCE
- X #include <stdio.h>
- X***************
- X*** 30,36 ****
- X char *PathComp[MAXCOMPONENTS];
- X int NumComponents;
- X
- X! /* Does the C compiler have prototypes? */
- X #ifdef __STDC__
- X #define HAVE_PROTOS
- X #endif
- X--- 31,37 ----
- X char *PathComp[MAXCOMPONENTS];
- X int NumComponents;
- X
- X! /* Does the C compiler have prototypes and const? */
- X #ifdef __STDC__
- X #define HAVE_PROTOS
- X #endif
- X***************
- X*** 52,57 ****
- X--- 53,59 ----
- X #define D_MOVE 1
- X #define D_ADD 2
- X #define D_DEL 3
- X+ #define D_CHOOSE 4
- X
- X /* Positions */
- X #define NO_P 0
- X***************
- X*** 65,70 ****
- X--- 67,73 ----
- X { "bash", SH_LIKE },
- X { "sh", SH_LIKE },
- X { "ksh", SH_LIKE },
- X+ { "zsh", SH_LIKE },
- X { "rsh", SH_LIKE },
- X { "csh", CSH_LIKE },
- X { "tcsh", CSH_LIKE },
- X***************
- X*** 81,91 ****
- X--- 84,96 ----
- X void DoAdd ARGS ((const char *var, const char *val, int shell, int pos));
- X void DoDel ARGS ((const char *var, const char *val, int shell));
- X void DoMove ARGS ((const char *var, const char *val, int shell, int pos));
- X+ void DoChoose ARGS ((const char *val1, const char *val2, int shell));
- X int SplitPath ARGS ((char *path));
- X int FindCurPos ARGS ((const char *dir));
- X void PrintEscaped ARGS ((const char *s, int colon));
- X void PathManip ARGS ((const char *var, const char *dir, int shell, int pos, int what));
- X void Usage ARGS ((const char *name));
- X+ int ComparePathElements ARGS ((const char *p1, const char *p2));
- X
- X /***************************************************************/
- X /* */
- X***************
- X*** 187,196 ****
- X
- X /***************************************************************/
- X /* */
- X! /* MAIN PROGRAM */
- X /* */
- X /* */
- X /* */
- X /***************************************************************/
- X #ifdef HAVE_PROTOS
- X int main(int argc, char *argv[])
- X--- 192,229 ----
- X
- X /***************************************************************/
- X /* */
- X! /* ComparePathElements */
- X /* */
- X+ /* Return 0 if two path elements are the same, non-zero */
- X+ /* otherwise. Trailing slashes do not participate in the */
- X+ /* comparison. */
- X /* */
- X+ /***************************************************************/
- X+ #ifdef HAVE_PROTOS
- X+ int ComparePathElements(const char *p1, const char *p2)
- X+ #else
- X+ int ComparePathElements(p1, p2)
- X+ char *p1;
- X+ char *p2;
- X+ #endif
- X+ {
- X+ while (*p1) {
- X+ if (*p1 != *p2) break;
- X+ p1++;
- X+ p2++;
- X+ }
- X+
- X+ /* Check trailing chars */
- X+ while(*p1 == '/') p1++;
- X+ while(*p2 == '/') p2++;
- X+ return (*p1 - *p2);
- X+
- X+ }
- X+
- X+ /***************************************************************/
- X /* */
- X+ /* MAIN PROGRAM */
- X+ /* */
- X /***************************************************************/
- X #ifdef HAVE_PROTOS
- X int main(int argc, char *argv[])
- X***************
- X*** 210,219 ****
- X Usage(argv[0]);
- X return 1;
- X }
- X! if (!strcmp(argv[1], "set")) what = D_SET;
- X! else if (!strcmp(argv[1], "add")) what = D_ADD;
- X! else if (!strcmp(argv[1], "del")) what = D_DEL;
- X! else if (!strcmp(argv[1], "move")) what = D_MOVE;
- X
- X if (what == NO_D) {
- X Usage(argv[0]);
- X--- 243,253 ----
- X Usage(argv[0]);
- X return 1;
- X }
- X! if (!strcmp(argv[1], "set")) what = D_SET;
- X! else if (!strcmp(argv[1], "add")) what = D_ADD;
- X! else if (!strcmp(argv[1], "del")) what = D_DEL;
- X! else if (!strcmp(argv[1], "move")) what = D_MOVE;
- X! else if (!strcmp(argv[1], "choose")) what = D_CHOOSE;
- X
- X if (what == NO_D) {
- X Usage(argv[0]);
- X***************
- X*** 232,237 ****
- X--- 266,272 ----
- X
- X switch(what) {
- X case D_SET: DoSetenv(var, val, shell); break;
- X+ case D_CHOOSE: DoChoose(argv[2], argv[3], shell); break;
- X case D_ADD:
- X case D_DEL:
- X case D_MOVE: PathManip(var, val, shell, pos, what); break;
- X***************
- X*** 332,338 ****
- X {
- X int i;
- X for (i=0; i<NumComponents; i++)
- X! if (!strcmp(dir, PathComp[i])) return i+1;
- X
- X return NO_P;
- X }
- X--- 367,373 ----
- X {
- X int i;
- X for (i=0; i<NumComponents; i++)
- X! if (!ComparePathElements(dir, PathComp[i])) return i+1;
- X
- X return NO_P;
- X }
- X***************
- X*** 371,378 ****
- X curpos = FindCurPos(dir);
- X
- X /* If it's 'add' and dir already exists in path, do nothing if pos
- X! not specified. If pos specified, convert to 'move' */
- X if (what == D_ADD && curpos != NO_P) {
- X if (pos == NO_P) return;
- X what = D_MOVE;
- X }
- X--- 406,417 ----
- X curpos = FindCurPos(dir);
- X
- X /* If it's 'add' and dir already exists in path, do nothing if pos
- X! not specified. If pos specified, OR trailing slashes
- X! don't match, convert to 'move' */
- X if (what == D_ADD && curpos != NO_P) {
- X+ if (pos == NO_P && strcmp(dir, PathComp[curpos-1])) {
- X+ pos = curpos;
- X+ }
- X if (pos == NO_P) return;
- X what = D_MOVE;
- X }
- X***************
- X*** 406,412 ****
- X break;
- X
- X case D_MOVE:
- X! if (pos <= curpos) {
- X if (pos == j) PrintEscaped(dir, 1);
- X if (j != curpos) PrintEscaped(PathComp[i],1);
- X } else {
- X--- 445,451 ----
- X break;
- X
- X case D_MOVE:
- X! if (pos < curpos) {
- X if (pos == j) PrintEscaped(dir, 1);
- X if (j != curpos) PrintEscaped(PathComp[i],1);
- X } else {
- X***************
- X*** 429,434 ****
- X--- 468,507 ----
- X case CSH_LIKE: putchar('\n'); break;
- X }
- X }
- X+
- X+ /***************************************************************/
- X+ /* */
- X+ /* DoChoose */
- X+ /* */
- X+ /* Simple-minded: If shell is 0, print val1, else print val2 */
- X+ /* */
- X+ /***************************************************************/
- X+ #ifdef HAVE_PROTOS
- X+ void DoChoose(const char *val1, const char *val2, int shell)
- X+ #else
- X+ void DoChoose(val1, val2, shell)
- X+ char *val1;
- X+ char *val2;
- X+ int shell;
- X+ #endif
- X+ {
- X+ switch(shell) {
- X+ case SH_LIKE:
- X+ PrintEscaped(val1, 0);
- X+ putchar('\n');
- X+ break;
- X+
- X+ case CSH_LIKE:
- X+ PrintEscaped(val2, 0);
- X+ putchar('\n');
- X+ break;
- X+
- X+ default:
- X+ fprintf(stderr, "envv: DoChoose - bad value for shell %d\n", shell);
- X+ break;
- X+ }
- X+ }
- X+
- X
- X /***************************************************************/
- X /* */
- SHAR_EOF
- $TOUCH -am 0322121094 patch.01 &&
- chmod 0600 patch.01 ||
- echo "restore of patch.01 failed"
- set `wc -c patch.01`;Wc_c=$1
- if test "$Wc_c" != "11415"; then
- echo original size 11415, current size $Wc_c
- fi
- exit 0
-
-
-
- exit 0 # Just in case...
-