aboutsummaryrefslogtreecommitdiff
path: root/sys/fmtio/itoc.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 /sys/fmtio/itoc.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/fmtio/itoc.x')
-rw-r--r--sys/fmtio/itoc.x53
1 files changed, 53 insertions, 0 deletions
diff --git a/sys/fmtio/itoc.x b/sys/fmtio/itoc.x
new file mode 100644
index 00000000..726fbc40
--- /dev/null
+++ b/sys/fmtio/itoc.x
@@ -0,0 +1,53 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <mach.h>
+include <ctype.h>
+
+# ITOC -- Integer to character string. We do not resolve this into a call
+# to GLTOC for reasons of efficiency.
+
+int procedure itoc (ival, str, maxch)
+
+int ival, maxch
+char str[ARB]
+
+char buf[MAX_DIGITS]
+int b_op, s_op, num, temp
+int gstrcpy()
+
+begin
+ s_op = 1
+
+ if (IS_INDEFI (ival)) {
+ return (gstrcpy ("INDEF", str, maxch))
+ } else if (ival < 0) {
+ str[1] = '-'
+ s_op = 2
+ num = -ival
+ } else
+ num = ival
+
+ # Encode nonnegative number in BUF, least significant digits first.
+
+ b_op = 0
+ repeat {
+ temp = num / 10
+ b_op = b_op + 1
+ buf[b_op] = TO_DIGIT (num - temp * 10)
+ num = temp
+ } until (num == 0)
+
+ # Copy encoded number to output string, reversing the order of the
+ # digits so that the most significant digits are first.
+
+ while (b_op > 0) {
+ if (s_op > maxch)
+ return (gstrcpy ("**********", str, maxch))
+ str[s_op] = buf[b_op]
+ s_op = s_op + 1
+ b_op = b_op - 1
+ }
+
+ str[s_op] = EOS
+ return (s_op - 1)
+end