aboutsummaryrefslogtreecommitdiff
path: root/pkg/xtools/ranges/rgencode.x
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/xtools/ranges/rgencode.x')
-rw-r--r--pkg/xtools/ranges/rgencode.x52
1 files changed, 52 insertions, 0 deletions
diff --git a/pkg/xtools/ranges/rgencode.x b/pkg/xtools/ranges/rgencode.x
new file mode 100644
index 00000000..ff0a0343
--- /dev/null
+++ b/pkg/xtools/ranges/rgencode.x
@@ -0,0 +1,52 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <pkg/rg.h>
+
+# RG_ENCODE -- Encode a range structure into a string, return the
+# number of characters that were written or ERR for string overflow.
+
+int procedure rg_encode (rg, outstr, maxch)
+
+pointer rg # First set of ranges
+char outstr[maxch] # String to receive the ranges
+int maxch # Maximum length of the string
+
+char tmpstr[SZ_LINE]
+int i, outlen
+
+int strlen()
+
+begin
+ if (rg == NULL)
+ call error (0, "Range descriptor undefined")
+
+ outlen = 0
+ outstr[1] = EOS
+
+ do i = 1, RG_NRGS(rg) {
+ if (RG_X1(rg, i) != RG_X2(rg, i)) {
+ call sprintf (tmpstr, maxch, "%d:%d,")
+ call pargi (RG_X1(rg, i))
+ call pargi (RG_X2(rg, i))
+ } else {
+ call sprintf (tmpstr, maxch, "%d,")
+ call pargi (RG_X1(rg, i))
+ }
+
+ outlen = outlen + strlen (tmpstr)
+
+ if (outlen <= maxch)
+ call strcat (tmpstr, outstr, maxch)
+ else {
+ outstr[1] = EOS
+ return (ERR)
+ }
+ }
+
+ # remove the last comma
+
+ outstr[outlen] = EOS
+ outlen = outlen - 1
+
+ return (outlen)
+end