summaryrefslogtreecommitdiff
path: root/ipl/procs/basename.icn
diff options
context:
space:
mode:
Diffstat (limited to 'ipl/procs/basename.icn')
-rw-r--r--ipl/procs/basename.icn41
1 files changed, 41 insertions, 0 deletions
diff --git a/ipl/procs/basename.icn b/ipl/procs/basename.icn
new file mode 100644
index 0000000..8ad7b98
--- /dev/null
+++ b/ipl/procs/basename.icn
@@ -0,0 +1,41 @@
+############################################################################
+#
+# File: basename.icn
+#
+# Subject: Procedures to produce base name of a file
+#
+# Author: Ralph E. Griswold
+#
+# Date: September 22, 1998
+#
+############################################################################
+#
+# This file is in the public domain.
+#
+############################################################################
+#
+# Contributor: Charles Shartsis
+#
+############################################################################
+#
+# This procedure is based on the UNIX basename(1) utility. It strips off
+# any path information and removes the specified suffix, if present.
+#
+# If no suffix is provided, the portion of the name up to the first
+# "." is returned.
+#
+# It should work under UNIX, MS-DOS, and the Macintosh.
+#
+############################################################################
+
+procedure basename(name, suffix) #: base name of file
+ local i, base
+
+ name ? {
+ every i := upto('/\\:')
+ tab(integer(i) + 1) # get rid of path, if any
+ if base := 1(tab(find(\suffix)), pos(-*suffix)) then return base
+ else return tab(0)
+ }
+
+end