home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume42 / envv / patch01 next >
Encoding:
Internet Message Format  |  1994-03-28  |  13.8 KB

  1. From: dfs@doe.carleton.ca (David F. Skoll)
  2. Newsgroups: comp.sources.misc
  3. Subject: v42i017: envv - handle env. variables in shell-independent way, Patch01
  4. Date: 28 Mar 1994 17:30:44 -0600
  5. Organization: Carleton University
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <2n7pb4$pin@sparky.sterling.com>
  9. X-Md4-Signature: f2b7393c4d214c502b8f5141e5a7fe2f
  10.  
  11. Submitted-by: dfs@doe.carleton.ca (David F. Skoll)
  12. Posting-number: Volume 42, Issue 17
  13. Archive-name: envv/patch01
  14. Environment: UNIX
  15. Patch-To: envv: Volume 41, Issue 153
  16.  
  17. This is patch 1 for envv, a program to handle environment variables
  18. in a shell-independent manner.
  19.  
  20. Envv is available via anonymous ftp at ftp.doe.carleton.ca (134.117.9.35)
  21. in /pub/misc/envv-1.1.tar.Z
  22.  
  23. Here's what's new in this patch:
  24.  
  25. * Version 1.1 (22 March 1994)
  26.  
  27. + Enhancements
  28.  
  29. - Modified the path manipulation commands so that trailing slashes do
  30.   not affect comparison of directories.  That is, foo/bar/ and foo/bar
  31.   are considered the same.
  32.  
  33. - Added the 'zsh' shell to the list of shells envv recognizes.
  34.  
  35. - Added the 'choose' directive -- see the man page.
  36.  
  37. And here's the patch itself.  Unshar in the source directory and type
  38. 'patch < patch.01'
  39.  
  40. --
  41. David F. Skoll
  42.  
  43. #!/bin/sh
  44. # This is envv/patch01/part, a shell archive (shar 3.32)
  45. # made 03/22/1994 17:10 UTC by <dfs@doe.carleton.ca> (David F. Skoll)
  46. # Source directory /tmp_mnt/home/dfs/work/envv-1.1
  47. #
  48. # existing files WILL be overwritten
  49. #
  50. #                                                                          
  51. #                                                                          
  52. #
  53. # This shar contains:
  54. # length  mode       name
  55. # ------ ---------- ------------------------------------------
  56. #  11415 -rw------- patch.01
  57. #
  58. if touch 2>&1 | fgrep 'amc' > /dev/null
  59.  then TOUCH=touch
  60.  else TOUCH=true
  61. fi
  62. if test -r shar3_seq_.tmp; then
  63.     echo "Must unpack archives in sequence!"
  64.     next=`cat shar3_seq_.tmp`; echo "Please unpack part $next next"
  65.     exit 1
  66. fi
  67. # ============= patch.01 ==============
  68. echo "x - extracting patch.01 (Text)"
  69. sed 's/^X//' << 'SHAR_EOF' > patch.01 &&
  70. XPrereq: VERSION=1.0
  71. X*** ../envv-1.0/Makefile    Tue Mar 22 12:08:22 1994
  72. X--- ./Makefile    Tue Mar 22 12:01:52 1994
  73. X***************
  74. X*** 1,6 ****
  75. X  # Makefile for envv.
  76. X  
  77. X! VERSION=1.0
  78. X  
  79. X  SRCS=envv.c
  80. X  FILES=$(SRCS) Makefile README envv.1
  81. X--- 1,6 ----
  82. X  # Makefile for envv.
  83. X  
  84. X! VERSION=1.1
  85. X  
  86. X  SRCS=envv.c
  87. X  FILES=$(SRCS) Makefile README envv.1
  88. X*** ../envv-1.0/README    Tue Mar 22 12:08:23 1994
  89. X--- ./README    Tue Mar 22 12:00:14 1994
  90. X***************
  91. X*** 28,32 ****
  92. X--- 28,50 ----
  93. X  'envv', which you can copy to your favourite system directory.  The manual
  94. X  page is in 'envv.1'
  95. X  
  96. X+ CHANGES TO ENVV:
  97. X+ 
  98. X+ * Version 1.1 (22 March 1994)
  99. X+ 
  100. X+ + Enhancements
  101. X+ 
  102. X+ - Modified the path manipulation commands so that trailing slashes do
  103. X+   not affect comparison of directories.  That is, foo/bar/ and foo/bar
  104. X+   are considered the same.
  105. X+ 
  106. X+ - Added the 'zsh' shell to the list of shells envv recognizes.
  107. X+ 
  108. X+ - Added the 'choose' directive -- see the man page.
  109. X+ 
  110. X+ * Version 1.0 (8 Feb 1994)
  111. X+ 
  112. X+ - First version.
  113. X+ 
  114. X  --
  115. X  David F. Skoll
  116. X*** ../envv-1.0/envv.1    Tue Mar 22 12:08:23 1994
  117. X--- ./envv.1    Tue Mar 22 12:00:27 1994
  118. X***************
  119. X*** 1,4 ****
  120. X! .TH ENVV 1 "8 February 1994"
  121. X  .UC 4
  122. X  .SH NAME
  123. X  envv \- manipulate environment variables in shell-independent manner
  124. X--- 1,4 ----
  125. X! .TH ENVV 1 "22 March 1994"
  126. X  .UC 4
  127. X  .SH NAME
  128. X  envv \- manipulate environment variables in shell-independent manner
  129. X***************
  130. X*** 10,15 ****
  131. X--- 10,17 ----
  132. X  \fBenvv move\fR \fIpath_var\fR \fIdir\fR \fIpos\fR
  133. X  .PP
  134. X  \fBenvv del\fR \fIpath_var\fR \fIdir\fR
  135. X+ .PP
  136. X+ \fBenvv choose\fR \fIsh_val\fR \fIcsh_val\fR
  137. X  .SH DESCRIPTION
  138. X  \fBEnvv\fR is used to manipulate environment variables in a shell-independent
  139. X  manner.  It is most useful in administrator-maintained setup files for
  140. X***************
  141. X*** 87,92 ****
  142. X--- 89,116 ----
  143. X      envv move P d 1         yields "setenv P d:a:b:c"
  144. X      envv move P e 1         yields nothing - e is not on path.
  145. X  .fi
  146. X+ .SH CHOOSE
  147. X+ The \fBchoose\fR command is very simple:  It takes two arguments.  If
  148. X+ the user's shell is like \fBsh\fR, then the first argument is printed.
  149. X+ If it is like \fBcsh\fR, then the second argument is printed.
  150. X+ .PP
  151. X+ This is useful if commercial vendors have supplied two versions of
  152. X+ scripts which must be sourced.  Your system script can select the
  153. X+ proper script as follows:
  154. X+ .PP
  155. X+ .nf
  156. X+     source `envv choose script.sh script.csh`
  157. X+ .fi
  158. X+ .PP
  159. X+ This can also be used as an escape hatch for complicated tests which
  160. X+ really do require two separate shell scripts.
  161. X+ .PP
  162. X+ .SH NOTES
  163. X+ The path-manipulation directives (\fBadd\fR, \fBmove\fR, \fBdel\fR)
  164. X+ ignore trailing slashes when comparing path components.  Thus,
  165. X+ "/usr/local" and "/usr/local/" are considered the same.  When
  166. X+ components are added or moved in a path variable, they inherit
  167. X+ whatever slashes are supplied in the \fIdir\fR argument.  Experiment...
  168. X  .PP
  169. X  .SH AUTHOR
  170. X  \fBEnvv\fR is Copyright 1994 by David F. Skoll.  It may be distributed for
  171. X*** ../envv-1.0/envv.c    Tue Mar 22 12:08:22 1994
  172. X--- ./envv.c    Tue Mar 22 11:53:31 1994
  173. X***************
  174. X*** 8,13 ****
  175. X--- 8,14 ----
  176. X  /*  Copyright (C) 1994 by David F. Skoll                       */
  177. X  /*                                                             */
  178. X  /*  Usage:                                                     */
  179. X+ /*  eval `envv choose sh-name csh-name`                        */
  180. X  /*  eval `envv set ENVVAR value`                               */
  181. X  /*  eval `envv add PATHVAR dir [position]`                     */
  182. X  /*  eval `envv del PATHVAR dir`                                */
  183. X***************
  184. X*** 14,20 ****
  185. X  /*  eval `envv move PATHVAR dir position`                      */
  186. X  /*                                                             */
  187. X  /***************************************************************/
  188. X! #define VERSION "1.0"
  189. X  
  190. X  #define _POSIX_SOURCE
  191. X  #include <stdio.h>
  192. X--- 15,21 ----
  193. X  /*  eval `envv move PATHVAR dir position`                      */
  194. X  /*                                                             */
  195. X  /***************************************************************/
  196. X! #define VERSION "1.1"
  197. X  
  198. X  #define _POSIX_SOURCE
  199. X  #include <stdio.h>
  200. X***************
  201. X*** 30,36 ****
  202. X  char *PathComp[MAXCOMPONENTS];
  203. X  int NumComponents;
  204. X  
  205. X! /* Does the C compiler have prototypes? */
  206. X  #ifdef __STDC__
  207. X  #define HAVE_PROTOS
  208. X  #endif
  209. X--- 31,37 ----
  210. X  char *PathComp[MAXCOMPONENTS];
  211. X  int NumComponents;
  212. X  
  213. X! /* Does the C compiler have prototypes and const? */
  214. X  #ifdef __STDC__
  215. X  #define HAVE_PROTOS
  216. X  #endif
  217. X***************
  218. X*** 52,57 ****
  219. X--- 53,59 ----
  220. X  #define D_MOVE 1
  221. X  #define D_ADD  2
  222. X  #define D_DEL  3
  223. X+ #define D_CHOOSE 4
  224. X  
  225. X  /* Positions */
  226. X  #define NO_P  0
  227. X***************
  228. X*** 65,70 ****
  229. X--- 67,73 ----
  230. X     { "bash", SH_LIKE },
  231. X     { "sh",   SH_LIKE },
  232. X     { "ksh",  SH_LIKE },
  233. X+    { "zsh",  SH_LIKE },
  234. X     { "rsh",  SH_LIKE },
  235. X     { "csh",  CSH_LIKE },
  236. X     { "tcsh", CSH_LIKE },
  237. X***************
  238. X*** 81,91 ****
  239. X--- 84,96 ----
  240. X  void DoAdd ARGS ((const char *var, const char *val, int shell, int pos));
  241. X  void DoDel ARGS ((const char *var, const char *val, int shell));
  242. X  void DoMove ARGS ((const char *var, const char *val, int shell, int pos));
  243. X+ void DoChoose ARGS ((const char *val1, const char *val2, int shell));
  244. X  int SplitPath ARGS ((char *path));
  245. X  int FindCurPos ARGS ((const char *dir));
  246. X  void PrintEscaped ARGS ((const char *s, int colon));
  247. X  void PathManip ARGS ((const char *var, const char *dir, int shell, int pos, int what));
  248. X  void Usage ARGS ((const char *name));
  249. X+ int ComparePathElements ARGS ((const char *p1, const char *p2));
  250. X  
  251. X  /***************************************************************/
  252. X  /*                                                             */
  253. X***************
  254. X*** 187,196 ****
  255. X  
  256. X  /***************************************************************/
  257. X  /*                                                             */
  258. X! /* MAIN PROGRAM                                                */
  259. X  /*                                                             */
  260. X  /*                                                             */
  261. X  /*                                                             */
  262. X  /***************************************************************/
  263. X  #ifdef HAVE_PROTOS
  264. X  int main(int argc, char *argv[])
  265. X--- 192,229 ----
  266. X  
  267. X  /***************************************************************/
  268. X  /*                                                             */
  269. X! /*  ComparePathElements                                        */
  270. X  /*                                                             */
  271. X+ /*  Return 0 if two path elements are the same, non-zero       */
  272. X+ /*  otherwise.  Trailing slashes do not participate in the     */
  273. X+ /*  comparison.                                                */
  274. X  /*                                                             */
  275. X+ /***************************************************************/
  276. X+ #ifdef HAVE_PROTOS
  277. X+ int ComparePathElements(const char *p1, const char *p2)
  278. X+ #else
  279. X+ int ComparePathElements(p1, p2)
  280. X+ char *p1;
  281. X+ char *p2;
  282. X+ #endif
  283. X+ {
  284. X+    while (*p1) {
  285. X+       if (*p1 != *p2) break;
  286. X+       p1++;
  287. X+       p2++;
  288. X+    }
  289. X+ 
  290. X+    /* Check trailing chars */
  291. X+    while(*p1 == '/') p1++;
  292. X+    while(*p2 == '/') p2++;
  293. X+    return (*p1 - *p2);
  294. X+ 
  295. X+ }
  296. X+ 
  297. X+ /***************************************************************/
  298. X  /*                                                             */
  299. X+ /* MAIN PROGRAM                                                */
  300. X+ /*                                                             */
  301. X  /***************************************************************/
  302. X  #ifdef HAVE_PROTOS
  303. X  int main(int argc, char *argv[])
  304. X***************
  305. X*** 210,219 ****
  306. X        Usage(argv[0]);
  307. X        return 1;
  308. X     }
  309. X!    if      (!strcmp(argv[1], "set")) what = D_SET;
  310. X!    else if (!strcmp(argv[1], "add")) what = D_ADD;
  311. X!    else if (!strcmp(argv[1], "del")) what = D_DEL;
  312. X!    else if (!strcmp(argv[1], "move")) what = D_MOVE;
  313. X  
  314. X     if (what == NO_D) {
  315. X        Usage(argv[0]);
  316. X--- 243,253 ----
  317. X        Usage(argv[0]);
  318. X        return 1;
  319. X     }
  320. X!    if      (!strcmp(argv[1], "set"))    what = D_SET;
  321. X!    else if (!strcmp(argv[1], "add"))    what = D_ADD;
  322. X!    else if (!strcmp(argv[1], "del"))    what = D_DEL;
  323. X!    else if (!strcmp(argv[1], "move"))   what = D_MOVE;
  324. X!    else if (!strcmp(argv[1], "choose")) what = D_CHOOSE;
  325. X  
  326. X     if (what == NO_D) {
  327. X        Usage(argv[0]);
  328. X***************
  329. X*** 232,237 ****
  330. X--- 266,272 ----
  331. X  
  332. X     switch(what) {
  333. X      case D_SET:  DoSetenv(var, val, shell); break;
  334. X+     case D_CHOOSE: DoChoose(argv[2], argv[3], shell); break;
  335. X      case D_ADD:
  336. X      case D_DEL:
  337. X      case D_MOVE: PathManip(var, val, shell, pos, what); break;
  338. X***************
  339. X*** 332,338 ****
  340. X  {
  341. X     int i;
  342. X     for (i=0; i<NumComponents; i++)
  343. X!      if (!strcmp(dir, PathComp[i])) return i+1;
  344. X  
  345. X     return NO_P;
  346. X  }
  347. X--- 367,373 ----
  348. X  {
  349. X     int i;
  350. X     for (i=0; i<NumComponents; i++)
  351. X!      if (!ComparePathElements(dir, PathComp[i])) return i+1;
  352. X  
  353. X     return NO_P;
  354. X  }
  355. X***************
  356. X*** 371,378 ****
  357. X     curpos = FindCurPos(dir);
  358. X  
  359. X     /* If it's 'add' and dir already exists in path, do nothing if pos
  360. X!       not specified.  If pos specified, convert to 'move' */
  361. X     if (what == D_ADD && curpos != NO_P) {
  362. X        if (pos == NO_P) return;
  363. X        what = D_MOVE;
  364. X     }
  365. X--- 406,417 ----
  366. X     curpos = FindCurPos(dir);
  367. X  
  368. X     /* If it's 'add' and dir already exists in path, do nothing if pos
  369. X!       not specified.  If pos specified, OR trailing slashes
  370. X!       don't match, convert to 'move' */
  371. X     if (what == D_ADD && curpos != NO_P) {
  372. X+       if (pos == NO_P && strcmp(dir, PathComp[curpos-1])) {
  373. X+      pos = curpos;
  374. X+       }
  375. X        if (pos == NO_P) return;
  376. X        what = D_MOVE;
  377. X     }
  378. X***************
  379. X*** 406,412 ****
  380. X       break;
  381. X  
  382. X         case D_MOVE:
  383. X!      if (pos <= curpos) {
  384. X          if (pos == j) PrintEscaped(dir, 1);
  385. X          if (j != curpos) PrintEscaped(PathComp[i],1);
  386. X           } else {
  387. X--- 445,451 ----
  388. X       break;
  389. X  
  390. X         case D_MOVE:
  391. X!      if (pos < curpos) {
  392. X          if (pos == j) PrintEscaped(dir, 1);
  393. X          if (j != curpos) PrintEscaped(PathComp[i],1);
  394. X           } else {
  395. X***************
  396. X*** 429,434 ****
  397. X--- 468,507 ----
  398. X      case CSH_LIKE: putchar('\n'); break;
  399. X     }
  400. X  }
  401. X+ 
  402. X+ /***************************************************************/
  403. X+ /*                                                             */
  404. X+ /*  DoChoose                                                   */
  405. X+ /*                                                             */
  406. X+ /*  Simple-minded:  If shell is 0, print val1, else print val2 */
  407. X+ /*                                                             */
  408. X+ /***************************************************************/
  409. X+ #ifdef HAVE_PROTOS
  410. X+ void DoChoose(const char *val1, const char *val2, int shell)
  411. X+ #else
  412. X+ void DoChoose(val1, val2, shell)
  413. X+ char *val1;
  414. X+ char *val2;
  415. X+ int shell;
  416. X+ #endif
  417. X+ {
  418. X+    switch(shell) {
  419. X+       case SH_LIKE:
  420. X+          PrintEscaped(val1, 0);
  421. X+      putchar('\n');
  422. X+      break;
  423. X+ 
  424. X+      case CSH_LIKE:
  425. X+      PrintEscaped(val2, 0);
  426. X+      putchar('\n');
  427. X+      break;
  428. X+ 
  429. X+      default:
  430. X+      fprintf(stderr, "envv: DoChoose - bad value for shell %d\n", shell);
  431. X+      break;
  432. X+    }
  433. X+ }
  434. X+        
  435. X  
  436. X  /***************************************************************/
  437. X  /*                                                             */
  438. SHAR_EOF
  439. $TOUCH -am 0322121094 patch.01 &&
  440. chmod 0600 patch.01 ||
  441. echo "restore of patch.01 failed"
  442. set `wc -c patch.01`;Wc_c=$1
  443. if test "$Wc_c" != "11415"; then
  444.     echo original size 11415, current size $Wc_c
  445. fi
  446. exit 0
  447.  
  448.  
  449.  
  450. exit 0 # Just in case...
  451.