diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /pkg/utilities/nttools/stxtools/tpbreak.x | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/utilities/nttools/stxtools/tpbreak.x')
-rw-r--r-- | pkg/utilities/nttools/stxtools/tpbreak.x | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/pkg/utilities/nttools/stxtools/tpbreak.x b/pkg/utilities/nttools/stxtools/tpbreak.x new file mode 100644 index 00000000..be5aed1d --- /dev/null +++ b/pkg/utilities/nttools/stxtools/tpbreak.x @@ -0,0 +1,80 @@ +# TP_BREAK -- Break an image name into bracket delimeted substrings +# +# B.Simon 02-Jun-89 Original + +procedure tp_break (imname, part, npart, maxch) + +char imname[ARB] # i: Image name +char part[maxch,ARB] # o: Array of image name parts +int npart # i: Maximum number of parts +int maxch # i: Maximum length of part +#-- +bool inside +char ch +int ic, jc, ipart +pointer sp, errmsg + +string syntax "Syntax error in image name (%s)" + +begin + # Allocate memory for error message + + call smark (sp) + call salloc (errmsg, SZ_LINE, TY_CHAR) + + # Initialize output to null string + + do ipart = 1, npart + part[1,ipart] = EOS + + # Break image name into bracket delimeted components + # The variable inside is used as a check that brackets are paired + + jc = 1 + ipart = 1 + inside = false + + for (ic = 1; ipart <= npart && imname[ic] != EOS; ic = ic + 1) { + + ch = imname[ic] + if (ch == '\\') { + ic = ic + 1 + + } else if (ch == '[') { + if (inside) { + call sprintf (Memc[errmsg], SZ_LINE, syntax) + call pargstr (imname) + call error (1, Memc[errmsg]) + } + part[jc,ipart] = EOS + ipart = ipart + 1 + inside = true + jc = 1 + + } else if (ch == ']') { + if (! inside) { + call sprintf (Memc[errmsg], SZ_LINE, syntax) + call pargstr (imname) + call error (1, Memc[errmsg]) + } + inside = false + + } else if (ipart > 1 && ! inside) { + call sprintf (Memc[errmsg], SZ_LINE, syntax) + call pargstr (imname) + call error (1, Memc[errmsg]) + } + + part[jc,ipart] = imname[ic] + jc = jc + 1 + + if (jc > maxch) { + call sprintf (Memc[errmsg], SZ_LINE, syntax) + call pargstr (imname) + call error (1, Memc[errmsg]) + } + } + + part[jc,ipart] = EOS + call sfree (sp) +end |