xref: /titanic_50/usr/src/ucbcmd/basename/basename.c (revision 554ff184129088135ad2643c1c9832174a17be88)
1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13  * All Rights Reserved.
14  */
15 
16 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
17 
18 #include	<stdio.h>
19 
20 main(argc, argv)
21 char **argv;
22 {
23 	register char *p1, *p2, *p3;
24 
25 	if (argc < 2) {
26 		(void)putchar('\n');
27 		exit(1);
28 	}
29 	p1 = argv[1];
30 	p2 = p1;
31 	while (*p1) {
32 		if (*p1++ == '/')
33 			p2 = p1;
34 	}
35 	if (argc>2) {
36 		for(p3=argv[2]; *p3; p3++)
37 			;
38 		while(p3>argv[2])
39 			if(p1 <= p2 || *--p3 != *--p1)
40 				goto output;
41 		*p1 = '\0';
42 	}
43 output:
44 	fputs(p2, stdout);
45 	putc('\n', stdout);
46 	exit(0);
47 	/* NOTREACHED */
48 }
49