From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- pkg/system/pathnames.x | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 pkg/system/pathnames.x (limited to 'pkg/system/pathnames.x') diff --git a/pkg/system/pathnames.x b/pkg/system/pathnames.x new file mode 100644 index 00000000..86ee74f4 --- /dev/null +++ b/pkg/system/pathnames.x @@ -0,0 +1,55 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +# PATHNAMES -- Convert one or more filenames into OS pathnames. If the input +# is redirected, filenames are read from the standard input. Otherwise, +# a file name template is expanded and used as the list of filenames to be +# transformed. If called without any arguments, return the pathname of the +# current working directory. + +procedure t_pathnames() + +int list +pointer sp, fname, osfname +bool streq(), clgetb() +int clgeti(), clpopni(), clpopnu(), clgfil(), fscan() + +begin + call smark (sp) + call salloc (fname, SZ_LINE, TY_CHAR) + call salloc (osfname, SZ_LINE, TY_CHAR) + + # If no arguments, return the pathame of the current + # directory: do not prompt for the template. + + if (clgeti ("$nargs") == 0) { + call fpathname ("", Memc[osfname], SZ_LINE) + call printf ("%s\n") + call pargstr (Memc[osfname]) + call sfree (sp) + return + } + + # Expand template, output pathname of each file therein. + if (clgetb ("sort")) + list = clpopni ("template") + else + list = clpopnu ("template") + + while (clgfil (list, Memc[fname], SZ_FNAME) != EOF) { + if (streq (Memc[fname], "STDIN")) { + while (fscan (STDIN) != EOF) { + call gargstr (Memc[fname], SZ_LINE) + call fpathname (Memc[fname], Memc[osfname], SZ_LINE) + call printf ("%s\n") + call pargstr (Memc[osfname]) + } + } else { + call fpathname (Memc[fname], Memc[osfname], SZ_LINE) + call printf ("%s\n") + call pargstr (Memc[osfname]) + } + } + + call clpcls (list) + call sfree (sp) +end -- cgit