🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1710

Re: Csh question: Doing cd .. from a symbolically linked directory

#1710
From: Bob Peirce #305
Date: Sat, 03 Nov 1990 00:25
68 lines
2363 bytes
Yesterday I posted a note on the problem facing this user of csh who
has sym links but lacks eval and a setting mechanism for cwd.  After
thinking about it more today I decided the best solution was to build
the path with a small C program and to use a short alias to drive it.
The results follow.  The C program could be made smaller and, possibly
faster by not using stdio, but this works.  Setting the sticky bit
also might help.

============================== csh alias ==============================
#  Handle typical .. moves from a symbolically linked directory
set cwd = `/bin/pwd`
alias	pwd	'echo $cwd'
alias	rpwd	/bin/pwd
alias	rcd	chdir
alias	cd	'\\
	if (\!* == "") set tmp = $home;\\
	if (\!* != "") set tmp = `glob \!*`;\\
	set cwd = `/usr/local/lib/chd $cwd $tmp`;\\
	chdir $cwd'
============================== C program ==============================
/*  @(#) chd.c
	C program for cd
*/

#include <stdio.h>

main(argc,argv)
char **argv;
int argc;
{
	int	i, j;
	char	path[256];

	if (argc != 3) exit();		/*  silent failure  */

	/*  Top dir in Altos Worknet may be @node */
	if (argv[2][0] == '/' || argv[2][0] == '@')
		printf ("%s\n", argv[2]);
	else {
		strcpy(path, argv[1]);
		strcat(path, "/");
		strcat(path, argv[2]);
		i = j = 0;
		while (path[i] != '\0') {
			if ( j != i) path[j] = path[i];
			if (path[i] == '.' && path[i+1] == '.') {
				++i;
				if (j >= 2) {
					j -= 2;
					while (path[j--] != '/')
						;
				}
				else j = -1;
			}
			++i;
			++j;
		}
		if (j == 0)
			strcpy (path, "/");
		else
			path[j] = '\0';
		printf ("%s\n", path);
	}
}
============================== END ==============================
-- 
Bob Peirce, Pittsburgh, PA				  412-471-5320
...!uunet!pitt!investor!rbp			rbp@investor.pgh.pa.us
Technical Details
Message-ID: <1990Nov3.002545.4005@investor.pgh.pa.us>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!mintaka!mit-eddie!uw-beaver!cornell!rochester!pt.cs.cmu.edu!dsl.pitt.edu!pitt!darth!investor.pgh.pa.us!rbp

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!mintaka!mit-eddie!uw-beaver!cornell!rochester!pt.cs.cmu.edu!dsl.pitt.edu!pitt!darth!investor.pgh.pa.us!rbp
From: rbp@investor.pgh.pa.us (Bob Peirce #305)
Newsgroups: comp.unix.shell
Subject: Re: Csh question: Doing cd .. from a symbolically linked directory
Message-ID: <1990Nov3.002545.4005@investor.pgh.pa.us>
Date: 3 Nov 90 00:25:45 GMT
Reply-To: rbp@investor.pgh.pa.us (Bob Peirce #305)
Organization: Cookson, Peirce & Co., Pittsburgh, PA
Lines: 68