set IP type of service
[unix-history] / usr / src / usr.bin / basename / basename.c
CommitLineData
72aaa5de
KB
1/*
2 * Copyright (c) 1987 Regents of the University of California.
b00122c8
KB
3 * All rights reserved.
4 *
f15db449 5 * %sccs.include.redist.c%
72aaa5de 6 */
38582a33 7
72aaa5de
KB
8#ifndef lint
9char copyright[] =
10"@(#) Copyright (c) 1987 Regents of the University of California.\n\
11 All rights reserved.\n";
12#endif /* not lint */
13
14#ifndef lint
f15db449 15static char sccsid[] = "@(#)basename.c 4.7 (Berkeley) %G%";
72aaa5de
KB
16#endif /* not lint */
17
13564b25
KB
18#include <stdio.h>
19
8c24706b 20main(argc, argv)
b00122c8
KB
21 int argc;
22 char **argv;
8c24706b 23{
b00122c8
KB
24 register char *p, *t;
25 char *base;
8c24706b 26
13564b25
KB
27 if (argc < 2 || argc > 3) {
28 fprintf(stderr, "usage: basename string [suffix]\n");
8c24706b
BJ
29 exit(1);
30 }
b00122c8
KB
31 for (p = base = *++argv; *p;)
32 if (*p++ == '/')
33 base = p;
13564b25 34 if (argc == 3) {
b00122c8
KB
35 for (t = *++argv; *t; ++t);
36 do {
37 if (t == *argv) {
38 *p = '\0';
39 break;
40 }
41 } while (p >= base && *--t == *--p);
8c24706b 42 }
13564b25 43 printf("%s\n", base);
8c24706b
BJ
44 exit(0);
45}