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/tunits/abrev.x | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/utilities/nttools/tunits/abrev.x')
-rw-r--r-- | pkg/utilities/nttools/tunits/abrev.x | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/pkg/utilities/nttools/tunits/abrev.x b/pkg/utilities/nttools/tunits/abrev.x new file mode 100644 index 00000000..f40ca944 --- /dev/null +++ b/pkg/utilities/nttools/tunits/abrev.x @@ -0,0 +1,113 @@ +include <tbset.h> +include "tunits.h" + +#* HISTORY * +#* B.Simon 07-Jan-99 Original + +# FIND_ABREV -- Find the abbreviation for a units string + +int procedure find_abrev (ab, units, abrev, maxch) + +pointer ab # i: abbreviation hash table descriptor +char units[ARB] # i: units string +char abrev[ARB] # o: abbreviation string +int maxch # i: maximum length of abbreviation string +#-- +int status +pointer ptr + +int get_unhash() + +begin + status = get_unhash (ab, units, ptr) + if (status == NO) { + abrev[1] = EOS + } else { + call strcpy (Memc[ptr], abrev, maxch) + } + + return (status) +end + +# FREE_ABREV -- Free the abbreviation hash table + +procedure free_abrev (ab) + +pointer ab # i: abbreviation hash table descriptor +#-- +int index +pointer sp, keyword, value + +int each_unhash() + +begin + call smark (sp) + call salloc (keyword, LEN_UNIT, TY_CHAR) + + index = 0 + while (each_unhash (ab, index, Memc[keyword], + value, LEN_UNIT) != EOF) { + if (value != NULL) + call mfree (value, TY_CHAR) + } + + + call free_unhash (ab) + call sfree (sp) +end + +# READ_ABREV -- Read abbreviations from a table and load into a hash + +pointer procedure read_abrev (abrevtab) + +char abrevtab[ARB] # i: abbreviation table name +#-- +int irow, nrow +pointer tp, c1, c2, sp, units, abrev, ab + +string nocolumn "The abbreviation table must have two coulmns" + +int tbpsta() +pointer tbtopn(), tbcnum(), new_unhash() + +begin + # Dynamic memory for strings + + call smark (sp) + call salloc (units, LEN_UNIT, TY_CHAR) + + # Refer to columns numerically because + # this is supposed to be a text file + + tp = tbtopn (abrevtab, READ_ONLY, NULL) + c1 = tbcnum (tp, 1) + c2 = tbcnum (tp, 2) + + if (c1 == NULL || c2 == NULL) + call tuniterr (nocolumn, abrevtab) + + # Create hash + + nrow = tbpsta (tp, TBL_NROWS) + ab = new_unhash (nrow, LEN_UNIT) + + # Read each row into hash + + do irow = 1, nrow { + call malloc (abrev, LEN_UNIT, TY_CHAR) + + call tbegtt (tp, c1, irow, Memc[units], LEN_UNIT) + call tbegtt (tp, c2, irow, Memc[abrev], LEN_UNIT) + + call strlwr (Memc[units]) + call strlwr (Memc[abrev]) + + call add_unhash (ab, Memc[units], abrev) + } + + # Close table and free memory + + call tbtclo (tp) + call sfree (sp) + return (ab) +end |