All of lore.kernel.org
 help / color / mirror / Atom feed
From: Larry McVoy <lm@bitmover.com>
To: Alexander Viro <viro@math.psu.edu>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	torvalds@transmeta.com, linux-kernel@vger.kernel.org,
	trivial@rustcorp.com.au
Subject: Re: [PATCH] MAINTAINERS file addition: Al Viro
Date: Sun, 26 May 2002 21:25:56 -0700	[thread overview]
Message-ID: <20020526212556.K30610@work.bitmover.com> (raw)
In-Reply-To: <E17CAjP-0005eK-00@wagner.rustcorp.com.au> <Pine.GSO.4.21.0205262353240.18603-100000@weyl.math.psu.edu>

On Mon, May 27, 2002 at 12:11:09AM -0400, Alexander Viro wrote:
> 	Oh, for crying out loud...  Even mail(1) supports aliases - say
> echo alias bastard viro@math.psu.edu >> ~/.mailrc and enjoy.  If your
> MUA doesn't have aliases/address book/etc. - switch to something sane.

I got sick of everything not having this about 15 years ago.  If you 
compile this as cc -o Alias alias.c and then do stuff like

	alias	mutt='Alias mutt'

then it will do the lookup and tell you how it is rewriting the addresses
as you pop into the tool.  

static char *id = "@(#)alias.c 1.2 - main, strsav; mcvoy@rsch.wisc.edu";

/* Alias - provide front end for whatever that loads aliases.
 * Look in ~/.fingerc for aliases.  You could link this to .mailrc.
 *
 * An alias is the regular expression:
 *
 *       ^alias[ <tab>]+name[ <tab>]+full_name
 *
 * and "finger name" gets translated to finger fullname.  Exception: any
 * fullname that contains a "!" is ignored (can't do uucp, only internet).
 *
 * Options: -I ignores the dotfiles; a good way to finger a local john instead
 * of the aliased john.
 *
 * Revisions:
 *  1/May/87: Add support for general machine aliasing as well as people
 * 	aliasing.  A machine alias for seismo is
 *
 *	alias	seismo	@siesmo.css.gov
 *
 * 	and finger foo@seismo will rewrite to foo@seismo.css.gov
 *
 *  5/May/87:  Make this a general interface to any program.  Usage is:
 *	Alias program args
 *
 * and typical usage is
 *
 *	alias	mail	'Alias Mail \!*'
 */

#include      <stdio.h>
#include      <ctype.h>

char   *malloc();
char   *strcpy();
char   *strsav();
char   *index();
char   *PROG;
int     quiet;

main(ac, av, ev)
	char  **av;
	char  **ev;
{
	char    fingerc[255], buf[500], machine[100];
	register i;
	FILE   *f = (FILE *) - 1;

	sprintf(fingerc, "%s/.fingerc", getenv("HOME"));

	/* quiet or noisy? */
	if (!strcmp(av[1], "-Q")) {
		quiet++;
		for (i = 1; i < ac; i++)
			av[i] = av[i + 1];
		--ac;
	}
	/* grab new program name and shift argv down */
	PROG = av[1];
	av[0] = PROG;
	for (i = 1; i < ac; i++)
		av[i] = av[i + 1];
	--ac;

	if (!(f = fopen(fingerc, "r"))) {
		execvp(PROG, av);
		perror(PROG);
	}
	/* stupid alg: scan the file for each av, but there's usually only one. */
	for (i = 1; i < ac; i++) {
		register len = strlen(av[i]);
		register mlen = 0;

		/* optimization: ignore options */
		if (*av[i] == '-')
			continue;

		rewind(f);

		/* grab machine name, it might be an alias */
		if (index(av[i], '@')) {
			strcpy(machine, index(av[i], '@') + 1);
			mlen = strlen(machine);
		} else
			machine[0] = 0;

		while (fgets(buf, sizeof(buf), f)) {
			register char *s;
			register char *t;

			/* chop newline */
			buf[strlen(buf) - 1] = 0;

			/* only aliases, please (sorry alice) */
			if (strncmp(buf, "alias", 5))
				continue;
			for (s = buf + 5; *s && isspace(*s); s++);

			/* match user alias? */
			if (!strncmp(s, av[i], len) && isspace(*(s + len))) {
				s += len;
				for (; *s && isspace(*s); s++);
				/* is it really a user or is it a machine? */
				if (*s == '@')
					s++;
				for (t = s; *t && !isspace(*t); t++);
				if (!index(s, '!')) {
					if (!quiet)
						fprintf(stderr, "%s --> %s\n", av[i], s);
					av[i] = strsav(s);
					break;	/* while, get next i */
				}
			}
			/* match system alias? */
			if (mlen && !strncmp(machine, s, mlen)) {
				char    buf2[200];
				register char *save;

				/* get to @full.name.part */
				s += mlen;
				for (; *s && isspace(*s); s++);
				if (*s++ != '@')
					continue;
				for (t = s; *t && !isspace(*t); t++);
				*t = NULL;

				*(index(av[i], '@') + 1) = NULL;
				sprintf(buf2, "%s%s", av[i], s);
				if (!quiet)
					fprintf(stderr, "%s%s --> %s\n", av[i], machine, buf2);
				av[i] = strsav(buf2);
				break;	/* while, get next i */
			}
		}
	}
	execvp(PROG, av);
	perror(PROG);
}

char   *
strsav(s)
	register char *s;
{
	register char *t = malloc(strlen(s) + 1);

	return strcpy(t, s);
}

      reply	other threads:[~2002-05-27  4:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-27  2:59 [PATCH] MAINTAINERS file addition: Al Viro Rusty Russell
2002-05-27  4:11 ` Alexander Viro
2002-05-27  4:25   ` Larry McVoy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020526212556.K30610@work.bitmover.com \
    --to=lm@bitmover.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=torvalds@transmeta.com \
    --cc=trivial@rustcorp.com.au \
    --cc=viro@math.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.