aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/stxtools/changt.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /pkg/utilities/nttools/stxtools/changt.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'pkg/utilities/nttools/stxtools/changt.x')
-rw-r--r--pkg/utilities/nttools/stxtools/changt.x98
1 files changed, 98 insertions, 0 deletions
diff --git a/pkg/utilities/nttools/stxtools/changt.x b/pkg/utilities/nttools/stxtools/changt.x
new file mode 100644
index 00000000..c3d4e511
--- /dev/null
+++ b/pkg/utilities/nttools/stxtools/changt.x
@@ -0,0 +1,98 @@
+#---------------------------------------------------------------------------
+.help change_ext Jun93 xtools
+.ih
+NAME
+change_ext -- Put the specified extension on a file name.
+.ih
+USAGE
+call change_ext (in_name, newext, out_name, max_size)
+.ih
+ARGUMENTS
+.ls in_name (I: char[ARB])
+The input pathname with which to change the arguments.
+.le
+.ls newext (I: char[ARB])
+The extension to replace the original extension with.
+.le
+.ls out_name (O: char[max_size])
+The resultant pathname with the new extension inserted. May be the
+same as the in_name.
+.le
+.ls max_size (I: int)
+The maximum length of the string out_name.
+.le
+.ih
+DESCRIPTION
+This routine replaces the old extension on a pathname with the new
+extension specified in the argument "newext". Thus:
+
+.nf
+ dir$root.ext --> dir$root.newext
+.fi
+.ih
+SEE ALSO
+fparse
+.endhelp
+#---------------------------------------------------------------------------
+procedure change_ext (in_name, newext, out_name, max_size)
+
+char in_name[ARB] # I: Original input name.
+char newext[ARB] # I: Extension to replace old one.
+char out_name[max_size] # O: File name with new extension.
+int max_size # I: Maximum size out_name.
+
+# Misc.
+pointer dir # Directory part of pathname.
+int index # Group index in pathname.
+pointer ksection # Unparsable part of pathname.
+int ngroup # Number of groups.
+pointer root # Root part of pathname.
+pointer section # Section part of pathname.
+pointer sp # Stack pointer.
+pointer sx # Generic string.
+
+begin
+ call smark (sp)
+ call salloc (dir, SZ_LINE, TY_CHAR)
+ call salloc (root, SZ_LINE, TY_CHAR)
+ call salloc (section, SZ_LINE, TY_CHAR)
+ call salloc (ksection, SZ_LINE, TY_CHAR)
+ call salloc (sx, SZ_LINE, TY_CHAR)
+
+ # Parse the file name COMPLETELY.
+ call fparse (in_name, Memc[dir], SZ_LINE, Memc[root], SZ_LINE,
+ Memc[sx], SZ_LINE, index, ngroup,
+ Memc[section], SZ_LINE, Memc[ksection], SZ_LINE)
+
+ # Put directory and root together.
+ call strcpy (Memc[dir], out_name, max_size)
+ call strcat (Memc[root], out_name, max_size)
+
+ # Change the extension.
+ call strcat (".", out_name, max_size)
+ call strcat (newext, out_name, max_size)
+
+ # Handle group syntax.
+ if (index > 0) {
+ call sprintf (Memc[sx], SZ_LINE, "[%d")
+ call pargi (index)
+ call strcat (Memc[sx], out_name, max_size)
+ if (ngroup > 0) {
+ call sprintf (Memc[sx], SZ_LINE, "/%d")
+ call pargi (ngroup)
+ call strcat (Memc[sx], out_name, max_size)
+ }
+ call strcat ("]", out_name, max_size)
+ }
+
+ # Append the "unparsable" parts.
+ call strcat (Memc[ksection], out_name, max_size)
+
+ # Finally image sections.
+ call strcat (Memc[section], out_name, max_size)
+
+ call sfree (sp)
+end
+#---------------------------------------------------------------------------
+# End of change_ext
+#---------------------------------------------------------------------------