Back to index

tetex-bin  3.0
basename.c
Go to the documentation of this file.
00001 /*
00002  * FILE:    basename.c
00003  * PURPOSE: a reimplementation of BSD's basename so that it can also be
00004  *          used as a function in other programs (see filenames.c and
00005  *          filenames.h)
00006  * AUTHOR:  Piet Tutelaers
00007  * VERSION: 1.0 (Sept. 1995)
00008  */
00009 #include <stdio.h>   /* printf() */
00010 #include "basics.h"  /* fatal() */
00011 #include "filenames.h"      /* basename() */
00012 
00013 main(int argc, char **argv)
00014 {
00015    if (argc < 2 || argc > 3) 
00016       fatal("Usage: basename string [suffix]\n");
00017 
00018    if (argc == 2) 
00019       printf("%s\n", basename(argv[1], NULL));
00020    else
00021       printf("%s\n", basename(argv[1], argv[2]));
00022    exit(0);
00023 }