From 2105f032fc75c9a95de9a83609deabd2c39d4350 Mon Sep 17 00:00:00 2001 From: gdr-ftp Date: Wed, 25 Mar 1998 15:08:28 +0000 Subject: [PATCH] Initial checkin of basename(1) and dirname(1), as submitted by Scott Moberly. The only change was renaming of the makefiles. --- usr.bin/basename/Makefile | 19 ++++ usr.bin/basename/basename.1 | 92 +++++++++++++++++ usr.bin/basename/basename.c | 164 ++++++++++++++++++++++++++++++ usr.bin/basename/basename.desc | 9 ++ usr.bin/basename/basename.rez | 60 +++++++++++ usr.bin/dirname/Makefile | 19 ++++ usr.bin/dirname/dirname.1 | 1 + usr.bin/dirname/dirname.c | 177 +++++++++++++++++++++++++++++++++ usr.bin/dirname/dirname.desc | 9 ++ usr.bin/dirname/dirname.rez | 60 +++++++++++ 10 files changed, 610 insertions(+) create mode 100644 usr.bin/basename/Makefile create mode 100644 usr.bin/basename/basename.1 create mode 100644 usr.bin/basename/basename.c create mode 100644 usr.bin/basename/basename.desc create mode 100644 usr.bin/basename/basename.rez create mode 100644 usr.bin/dirname/Makefile create mode 100644 usr.bin/dirname/dirname.1 create mode 100644 usr.bin/dirname/dirname.c create mode 100644 usr.bin/dirname/dirname.desc create mode 100644 usr.bin/dirname/dirname.rez diff --git a/usr.bin/basename/Makefile b/usr.bin/basename/Makefile new file mode 100644 index 0000000..ac67899 --- /dev/null +++ b/usr.bin/basename/Makefile @@ -0,0 +1,19 @@ +# Makefile for basename(1) and dirname(1) +# +# Use TESTFLAGS to check stack usage. + +CFLAGS += -w -O -s 768 -c +LDFLAGS += -O +TESTFLAGS += -w -G25 -DSTACK_CHECK + +all : basename dirname + +basename : basename.o basename.r + $(CC) $(LDFLAGS) -o $@ $@.o + $(CATREZ) -d $@ $@.r + +dirname : dirname.o dirname.r + $(CC) $(LDFLAGS) -o $@ $@.o + $(CATREZ) -d $@ $@.r + + diff --git a/usr.bin/basename/basename.1 b/usr.bin/basename/basename.1 new file mode 100644 index 0000000..867368b --- /dev/null +++ b/usr.bin/basename/basename.1 @@ -0,0 +1,92 @@ +.\" Copyright (c) 1990, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)basename.1 8.2 (Berkeley) 4/18/94 +.\" $Id: basename.1,v 1.1 1998/03/25 15:08:16 gdr-ftp Exp $ +.\" +.TH BASENAME 1 +.SH NAME +.PP +\fBbasename\fR, \fBdirname\fR +\- return filename or directory portion of pathname +.SH SYNOPSIS +.PP +\fBbasename\fR \fIstring\fR [\fI.suffix\fR] +.sp 1 +\fBdirname\fR \fIpath\fR +.SH DESCRIPTION +.PP +\fBBasename\fR +deletes any prefix ending with the last slash \/ or colon : +character present in \fIstring\fR, and a \fIsuffix\fR, +if given. The resulting filename is written to the +standard output. Any trailing slash \/ or colon : characters +in \fIstring\fR will be removed. A non-existent suffix is +ignored. +.PP +\fBDirname\fR deletes the filename portion, beginning +with the last slash \/ or colon : character to the end +of \fIstring\fR, and writes the result to the standard +output. +.SH EXAMPLES +.PP +The following line sets the shell variable \fBFOO\fR +to \fI/usr/bin\fR. +.PP +\fBFOO=`dirname /usr/bin/trail`\fR +.PP +Both the \fBbasename\fR and \fBdirname\fR +exit 0 on success, and >0 if an error occurs. +.SH NOTES +.PP +Because these programs use \fBbasename\fR(3) and +\fBdirname\fR(3) respectively, there is a preference +on ':' as a deliminator. Additionally, if a ':' is +used anywhere in the pathname, it will be considered +the deliminator. +.SH SEE ALSO +.PP +\fBcsh\fR(1), +\fBsh\fR(1), +\fBbasename\fR(3) +.SH STANDARDS +.PP +The \fBbasename\fR and \fBdirname\fR functions are +expected to be POSIX 1003.2 compatible. +.SH COPYRIGHT +.PP +.nf +This program contains material from the ORCA/C +Run-Time Libraries, copyright 1987-1992 +by ByteWorks, Inc. Used with Permission. diff --git a/usr.bin/basename/basename.c b/usr.bin/basename/basename.c new file mode 100644 index 0000000..34f3356 --- /dev/null +++ b/usr.bin/basename/basename.c @@ -0,0 +1,164 @@ +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright (c) 1991, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +static char sccsid[] = "@(#)basename.c 8.4 (Berkeley) 5/4/95"; +#endif /* not lint */ + +#include +#include +#include +#include +#include + +void usage (void); + +int +main(int argc, char **argv) +{ + char *p, delimiter = '/'; + int ch; + +# ifdef STACK_CHECK + _beginStackCheck(); +# endif + + while ((ch = getopt(argc, argv, "")) != -1) + switch(ch) { + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc != 1 && argc != 2) + usage(); + + + /* + * (1) Check for the existence of a colon ':' character for the + * delimiter. If a colon is used, it will be used; otherwise + * the delimiter will be a backslash '/'. + */ + +# ifdef __GNO__ + for (p = *argv; *p == NULL; ++p) + if (*p == ':') { + delimiter = ':'; + break; + } +# endif + + /* + * (2) If string consists entirely of slash characters, string shall + * be set to a single slash character. In this case, skip steps + * (3) through (5). + */ + for (p = *argv;; ++p) { + + if (!*p) { + if (p > *argv) + (void)printf("%c\n", delimiter); + else + (void)printf("\n"); + exit(0); + } + + if (*p != delimiter) + break; + } + + /* + * (3) If there are any trailing slash characters in string, they + * shall be removed. + */ + for (; *p; ++p) + continue; + while (*--p == ':') + continue; + *++p = '\0'; + + /* + * (4) If there are any slash characters remaining in string, the + * prefix of string up to an including the last slash character + * in string shall be removed. + */ +# ifdef __GNO__ + p = basename(*argv); +# else + while (--p >= *argv) + if (*p == delimiter) + break; + ++p; +# endif + + /* + * (5) If the suffix operand is present, is not identical to the + * characters remaining in string, and is identical to a suffix + * of the characters remaining in string, the suffix suffix + * shall be removed from string. + */ + if (*++argv) { + int suffixlen, stringlen, off; + + suffixlen = strlen(*argv); + stringlen = strlen(p); + + if (suffixlen < stringlen) { + off = stringlen - suffixlen; + if (!strcmp(p + off, *argv)) + p[off] = '\0'; + } + } + (void)printf("%s\n", p); + +# ifdef STACK_CHECK + fprintf(stdout, "stack used: %d\n", _endStackCheck()); +# endif + exit(0); +} + +void +usage(void) +{ + + (void)fprintf(stderr, "usage: basename string [suffix]\n"); + exit(1); +} diff --git a/usr.bin/basename/basename.desc b/usr.bin/basename/basename.desc new file mode 100644 index 0000000..aa111ed --- /dev/null +++ b/usr.bin/basename/basename.desc @@ -0,0 +1,9 @@ +Name: basename +Version: 1.0 +Shell: GNO/ME +Author: Scott Moberly (FreeBSD port) +Contact: smoberly@s-cwis.unomaha.edu +Where: /usr/bin +FTP: ftp.gno.org + + Shows only the basename of a given fully expanded filename. diff --git a/usr.bin/basename/basename.rez b/usr.bin/basename/basename.rez new file mode 100644 index 0000000..c4c90c0 --- /dev/null +++ b/usr.bin/basename/basename.rez @@ -0,0 +1,60 @@ +/* + * This is a CVS/RCS identification line -- an excellent tool for maintaining + * your sources: + * + * $Id: basename.rez,v 1.1 1998/03/25 15:08:21 gdr-ftp Exp $ + */ + +#include "Types.Rez" +#include "Proginfo.Rez" + +resource rVersion (0x1, purgeable3, nocrossbank) { + + { 1, 0, 0, /* version 1.0.0 */ + release, /* development|alpha|beta|final|release */ + 0 /* non-final release number */ + }, + verUS, /* country code -- only some are avail */ + "basename", /* name */ + /* _Very_ brief descrition. Check "file info" */ + /* shown in the Finder to see if it's too long */ + /* Note that \n is used to separate lines here. */ + "Strips the pathname from a fully expanded file path.\n" + "Ported from FreeBSD source code.\n" + "Scott Moberly " +}; + +#define ON 1 +#define OFF 2 + +resource rProgramInfo (0x1, purgeable3, nocrossbank) { + { 6, 0, 0, /* Minimun System Required */ + release, + 0 + }, + 47104, /* Minimum RAM required */ + 47104, /* Optimal RAM required */ + 768, /* Zero Bank RAM reuired */ + + progCanMultitask * ON + // 1 = program can be multitasked + progCanSwitch * ON + // 1 = program can go into standby mode + progCanStackShare * ON + // 1 = program can stack-share + progAllowsNDAs * ON + // program allows NDA useage + progAllowsCDAs * ON, // program allows CDA access + +//---- shellInfo defining shell compatibility for EXEs +// Options available for each shell. +// piNotCompatible - program not compatible with this +// piUntested - program not tested with this shell +// piCompatible - program compatible with this shell +// piSpecialFeatures - program uses special features of this + + progShellORCA * piUntested + + progShellORCA2 * piUntested + + progShellProSel * piUntested + + progShellMTools * piUntested + + progShellMerlin16 * piUntested + + progShellGSH * piCompatible + + progShellPrizm * piUntested +}; + diff --git a/usr.bin/dirname/Makefile b/usr.bin/dirname/Makefile new file mode 100644 index 0000000..ac67899 --- /dev/null +++ b/usr.bin/dirname/Makefile @@ -0,0 +1,19 @@ +# Makefile for basename(1) and dirname(1) +# +# Use TESTFLAGS to check stack usage. + +CFLAGS += -w -O -s 768 -c +LDFLAGS += -O +TESTFLAGS += -w -G25 -DSTACK_CHECK + +all : basename dirname + +basename : basename.o basename.r + $(CC) $(LDFLAGS) -o $@ $@.o + $(CATREZ) -d $@ $@.r + +dirname : dirname.o dirname.r + $(CC) $(LDFLAGS) -o $@ $@.o + $(CATREZ) -d $@ $@.r + + diff --git a/usr.bin/dirname/dirname.1 b/usr.bin/dirname/dirname.1 new file mode 100644 index 0000000..60a1c84 --- /dev/null +++ b/usr.bin/dirname/dirname.1 @@ -0,0 +1 @@ +.so man1/basename.1 diff --git a/usr.bin/dirname/dirname.c b/usr.bin/dirname/dirname.c new file mode 100644 index 0000000..33b5683 --- /dev/null +++ b/usr.bin/dirname/dirname.c @@ -0,0 +1,177 @@ +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright (c) 1991, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +static char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95"; +#endif /* not lint */ + +#include +#include +#include +#include + +void usage __P((void)); + +int +main(int argc, char **argv) +{ + char *p, delimiter = '/'; + int ch; + +#ifdef STACK_CHECK + _beginStackCheck(); +#endif + + while ((ch = getopt(argc, argv, "")) != -1) + switch(ch) { + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc != 1) + usage(); + + /* + * (1) Check for the existence of a colon ':' character for the + * delimiter. If a colon is used, it will be used; otherwise + * the delimiter will be a backslash '/'. + */ + +# ifdef __GNO__ + for (p = *argv;; ++p) { + if (*p == ':') { + delimiter = ':'; + break; + } + if (!*p) + break; + } +# endif + + /* + * (2) If string consists entirely of slash characters, string + * shall be set to a single slash character. In this case, + * skip steps (3) through (8). + */ + + for (p = *argv;; ++p) { + if (!*p) { + if (p > *argv) + (void)printf("%c\n", delimiter); + else + (void)printf(".\n"); + exit(0); + } + if (*p != delimiter) + break; + } + + /* + * (3) If there are any trailing slash characters in string, they + * shall be removed. + */ + for (; *p; ++p); + while (*--p == delimiter) + continue; + *++p = '\0'; + + /* + * (4) If there are no slash characters remaining in string, + * string shall be set to a single period character. In this + * case skip steps (5) through (8). + * + * (5) If there are any trailing nonslash characters in string, + * they shall be removed. + */ +# ifndef __GNO__ + while (--p >= *argv) + if (*p == delimiter) + break; + ++p; + if (p == *argv) { + (void)printf(".\n"); + exit(0); + } + + /* + * (6) If the remaining string is //, it is implementation defined + * whether steps (7) and (8) are skipped or processed. + * + * This case has already been handled, as part of steps (1) and (2). + */ + + /* + * (7) If there are any trailing slash characters in string, they + * shall be removed. + */ + while (--p >= *argv) + if (*p == delimiter) + break; + ++p; + + /* + * (8) If the remaining string is empty, string shall be set to + * a single slash character. + */ + *p = '\0'; + (void)printf("%s\n", p == *argv ? delimiter : *argv); +# else + if (!(p = dirname(*argv))) + (void)printf(".\n", p, *p); + else + (void)printf("%s%c\n", p, delimiter); +# endif + +#ifdef STACK_CHECK + printf("Stack Usgae: %d\n", _endStackCheck()); +#endif + + exit(0); +} + +void +usage(void) +{ + + (void)fprintf(stderr, "usage: dirname path\n"); + exit(1); +} diff --git a/usr.bin/dirname/dirname.desc b/usr.bin/dirname/dirname.desc new file mode 100644 index 0000000..cdc12b3 --- /dev/null +++ b/usr.bin/dirname/dirname.desc @@ -0,0 +1,9 @@ +Name: dirname +Version: 1.0 +Shell: GNO/ME +Author: Scott Moberly (FreeBSD port) +Contact: smoberly@s-cwis.unomaha.edu +Where: /usr/bin +FTP: ftp.gno.org + + Shows only the directory name of a given fully expanded filename. diff --git a/usr.bin/dirname/dirname.rez b/usr.bin/dirname/dirname.rez new file mode 100644 index 0000000..0dd7a6c --- /dev/null +++ b/usr.bin/dirname/dirname.rez @@ -0,0 +1,60 @@ +/* + * This is a CVS/RCS identification line -- an excellent tool for maintaining + * your sources: + * + * $Id: dirname.rez,v 1.1 1998/03/25 15:08:28 gdr-ftp Exp $ + */ + +#include "Types.Rez" +#include "Proginfo.Rez" + +resource rVersion (0x1, purgeable3, nocrossbank) { + + { 1, 0, 0, /* version 1.0.0 */ + release, /* development|alpha|beta|final|release */ + 0 /* non-final release number */ + }, + verUS, /* country code -- only some are avail */ + "dirname", /* name */ + /* _Very_ brief descrition. Check "file info" */ + /* shown in the Finder to see if it's too long */ + /* Note that \n is used to separate lines here. */ + "Strips the file name from a fully expanded filename path.\n" + "Ported from FreeBSD source code.\n" + "Scott Moberly " +}; + +#define ON 1 +#define OFF 2 + +resource rProgramInfo (0x1, purgeable3, nocrossbank) { + { 6, 0, 0, /* Minimun System Required */ + release, + 0 + }, + 47104, /* Minimum RAM required */ + 47104, /* Optimal RAM required */ + 768, /* Zero Bank RAM reuired */ + + progCanMultitask * ON + // 1 = program can be multitasked + progCanSwitch * ON + // 1 = program can go into standby mode + progCanStackShare * ON + // 1 = program can stack-share + progAllowsNDAs * ON + // program allows NDA useage + progAllowsCDAs * ON, // program allows CDA access + +//---- shellInfo defining shell compatibility for EXEs +// Options available for each shell. +// piNotCompatible - program not compatible with this +// piUntested - program not tested with this shell +// piCompatible - program compatible with this shell +// piSpecialFeatures - program uses special features of this + + progShellORCA * piUntested + + progShellORCA2 * piUntested + + progShellProSel * piUntested + + progShellMTools * piUntested + + progShellMerlin16 * piUntested + + progShellGSH * piCompatible + + progShellPrizm * piUntested +}; +