mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-06-08 05:29:33 +00:00
Initial checkin of basename(1) and dirname(1), as submitted by
Scott Moberly. The only change was renaming of the makefiles.
This commit is contained in:
parent
62215a070f
commit
2105f032fc
19
usr.bin/basename/Makefile
Normal file
19
usr.bin/basename/Makefile
Normal file
|
@ -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
|
||||||
|
|
||||||
|
|
92
usr.bin/basename/basename.1
Normal file
92
usr.bin/basename/basename.1
Normal file
|
@ -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.
|
164
usr.bin/basename/basename.c
Normal file
164
usr.bin/basename/basename.c
Normal file
|
@ -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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <gno/gno.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
9
usr.bin/basename/basename.desc
Normal file
9
usr.bin/basename/basename.desc
Normal file
|
@ -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.
|
60
usr.bin/basename/basename.rez
Normal file
60
usr.bin/basename/basename.rez
Normal file
|
@ -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 <smoberly@s-cwis.unomaha.edu>"
|
||||||
|
};
|
||||||
|
|
||||||
|
#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
|
||||||
|
};
|
||||||
|
|
19
usr.bin/dirname/Makefile
Normal file
19
usr.bin/dirname/Makefile
Normal file
|
@ -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
|
||||||
|
|
||||||
|
|
1
usr.bin/dirname/dirname.1
Normal file
1
usr.bin/dirname/dirname.1
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.so man1/basename.1
|
177
usr.bin/dirname/dirname.c
Normal file
177
usr.bin/dirname/dirname.c
Normal file
|
@ -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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <gno/gno.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
9
usr.bin/dirname/dirname.desc
Normal file
9
usr.bin/dirname/dirname.desc
Normal file
|
@ -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.
|
60
usr.bin/dirname/dirname.rez
Normal file
60
usr.bin/dirname/dirname.rez
Normal file
|
@ -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 <smoberly@s-cwis.unomaha.edu>"
|
||||||
|
};
|
||||||
|
|
||||||
|
#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
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user