Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!utgpu!water!watmath!clyde!rutgers!super.upenn.edu!eecae!nancy!umix!utah-gr!spline.utah.edu!thomas
From: thomas@spline.utah.edu.UUCP
Newsgroups: comp.emacs
Subject: Re: Emacs csh alias
Message-ID: <2273@utah-gr.UUCP>
Date: Mon, 7-Dec-87 05:36:14 EST
Article-I.D.: utah-gr.2273
Posted: Mon Dec  7 05:36:14 1987
Date-Received: Sat, 12-Dec-87 09:53:26 EST
References: <8712041951.AA21105@ucbvax.Berkeley.EDU> <1059@mips.UUCP>
Sender: news@utah-gr.UUCP
Reply-To: thomas%spline.utah.edu.UUCP@utah-gr.UUCP (Spencer W. Thomas)
Organization: University of Utah CS Dept
Lines: 66


Here is a pair of aliases that I've been using for years.  The real
work is done by the 's' alias and the start command:

alias e 's emacs \!*'
alias s 'jobs >~/.pcs; eval `start < ~/.pcs \!*`'

Here is start.c:

/*
 * start - figure out if a process is already running
 * from the output of the csh's "jobs" command.
 */

#include 

char *index(), *rindex();

main(argc, argv)
char **argv;
{
	register char *cp;
	int parens = 0;
	char line[512];

	if (argc <= 1)
		exit(1);

	while (gets(line) > 0)
	{
		if ((cp = index(line, 'S')) == NULL)
			continue;
		if (strncmp(cp, "Stopped", 7) != 0)
			continue;
		for (cp += 7; *cp; cp++)
		{
		    if (*cp == '(')
		    	parens++;
		    if (parens == 0 && *cp != ' ')
		        break;
		    if (*cp == ')')
		    	parens--;
		}
		if (*cp == 0)
		    continue;

		if (strncmp(cp, argv[1], strlen(argv[1])) != 0)
			continue;
		if (argc > 2)
			fprintf(stderr, "Arguments ignored for continue of %s\n",
				argv[1]);
		cp = index(line, ']');
		*cp = 0;
		cp = index(line, '[') + 1;
		printf("%%%s\n", cp);
		exit(0);
	}

	/* Not already running: start it up */
	for (argv++, argc--; argc > 0; argv++, argc--)
		printf("%s ", *argv);
	printf("\n");
	exit(0);
}

=Spencer   ({ihnp4,decvax}!utah-cs!thomas, thomas@cs.utah.edu)