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