10 %TITLE "" %SBTTL "Converts strings" %IDENT "V01.00" ! ! COPYRIGHT (c) 1987 BY ! Bert Roseberry, U. S. Coast Guard, Washington, D.C. ! ! Bert Roseberry or Bert Roseberry ! Commandant (G-APA-1) P. O. Box 175 ! 2100 Second St., S.W. Manassas, VA 22110 ! Washington, DC 20593 (703) 368-4350 ! (202) 267-2626 ! ! THIS SOFTWARE IS FURNISHED FREE AND MAY BE USED AND COPIED ONLY WITH ! THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY ! OTHER COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE ! TO ANY OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS ! HEREBY TRANSFERRED. ! ! THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE ! AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY THE U.S. COAST GUARD. ! ! THE U.S. COAST GUARD ASSUMES NO RESPONSIBILITY FOR THE USE OR RELI- ! ABILITY OF ITS SOFTWARE. ! !++ ! ! FACILITY: ! ! CONVERT_STR.BAS ! ! ABSTRACT: ! ! This is the function that converts from string to other data types ! and returns the other data type in a string variable ! ! ENVIRONMENT: ! ! VAX-11 user mode. ! ! AUTHOR: Bert Roseberry, CREATION DATE: 17 Oct 1987 ! ! MODIFIED BY: ! ! Bert Roseberry, 17-OCT-87: VERSION 01.00 ! 00 - Original version of module. BAR ! !-- %SBTTL "Full description" FUNCTION INTEGER CONVERT_STR & (STRING IN_STRING, STRING OUT_STRING, STRING TYPE_CONVERT) !++ ! ! FUNCTIONAL DESCRIPTION: ! ! Converts a string ! ! options: ! ! "STR TO BYTE" - string (len 1) to byte (number) ! "STR TO WORD" - string (len 2) to word (number) ! "STR TO LONG" - string (len 4) to long (number) ! "STR TO QUAD" - string (len 8) to quad (number) ! "STR TO DATE" - string (len 8) to date (VMS Date) ! "BYTE TO STR" - byte (number) to string (len 1) ! "WORD TO STR" - word (number) to string (len 2) ! "LONG TO STR" - long (number) to string (len 4) ! "QUAD TO STR" - quad (number) to string (len 8) ! "DATE TO STR" - date (VMS Date) to string (len 8) ! ! ! FORMAL PARAMETERS: ! ! .. ! is m, r, or w for modify, read, or write. ! is b, d, g, h, l, p, s, t, or w ! is d, r, or v for BY DESC, BY REF, or BY VALUE. ! is or a for scalar or array. ! ! ! IMPLICIT INPUTS: ! ! None ! ! IMPLICIT OUTPUTS: ! ! None ! ! FUNCTION VALUE: ! ! ! SIDE EFFECTS: ! !-- %SBTTL "Declarations" ! ! ENVIRONMENT SPECIFICATION: ! ! ! INCLUDE FILES: ! ! ! EQUATED SYMBOLS: ! ! DECLARE CONSTANT & ! = , & ! = ! ! LOCAL STORAGE: ! ! RECORD ! ! END RECORD RECORD full_date string asc_day = 23 END RECORD full_date RECORD break_string VARIANT CASE string strg_case = 8 CASE string str1_case = 1 CASE string str2_case = 2 CASE string str4_case = 4 CASE byte byte_case CASE word word_case CASE long long_case CASE long date_case(1) END VARIANT END RECORD break_string DECLARE & LONG & stat, & ! Holds return from function calls & WORD & numchrs, & ! Number of characters & STRING & achr, & ! One line & BREAK_STRING & bstr, & ! String that gets broken up & FULL_DATE & fdat & ! String that has date and time ! ! GLOBAL STORAGE: ! !COMMON () & ! & ! , & ! , & ! & ! , & ! !MAP () & ! & ! , & ! , & ! & ! , & ! ! ! EXTERNAL REFERENCES: ! !EXTERNAL CONSTANT & ! EXTERNAL INTEGER CONSTANT & SS$_NORMAL & ! normal return from sys call & !EXTERNAL & ! !EXTERNAL FUNCTION & ! & ! ( BY , & ! BY ) EXTERNAL INTEGER FUNCTION & SYS$ASCTIM, & ! Binary to ASCII time & SYS$BINTIM & ! ASCII to binary time !EXTERNAL SUB & ! & ! ( BY , & ! BY ) ! ! INTERNAL REFERENCES: ! !DECLARE FUNCTION & ! & ! (, & ! ) %SBTTL "Environment initialization" !+ ! Set up global error handler !- ON ERROR GOTO CLEANUP_PART %SBTTL "Convert option to uppercase and remove spaces" 1000 UPPERCASE_ANSWER: !+ ! Uppercase the option !- type_convert = EDIT$(type_convert,169%) %SBTTL "Select the item" 2000 PICK_THE_CHOICE: !+ ! Now pick the option !- SELECT type_convert !+ ! "STR TO BYTE" - string (len 1) to byte (number) ! -127 to 128 !- CASE "STR TO BYTE" bstr::str1_case = SEG$(in_string,1,1) out_string = FORMAT$(bstr::byte_case,"####") !+ ! "STR TO WORD" - string (len 2) to word (number) ! -32768 to 32768 !- CASE "STR TO WORD" bstr::str2_case = SEG$(in_string,1,2) out_string = FORMAT$(bstr::word_case,"######") !+ ! "STR TO LONG" - string (len 4) to long (number) ! -2147483647 to 2147483647 !- CASE "STR TO LONG" bstr::str4_case = SEG$(in_string,1,4) out_string = FORMAT$(bstr::long_case,"###########") !+ ! "STR TO DATE" - string (len 8) to date (VMS Date) ! !- CASE "STR TO DATE" bstr::strg_case = SEG$(in_string,1,8) stat = sys$asctim(,fdat::asc_day,bstr::date_case(0),) if (stat and 1%) <> ss$_normal then fdat::asc_day = "" end if out_string = fdat::asc_day !+ ! "BYTE TO STR" - number (byte) to string (len 1) ! !- CASE "BYTE TO STR" bstr::byte_case = VAL%(in_string) out_string = bstr::str1_case !+ ! "WORD TO STR" - number (word) to string (len 2) ! !- CASE "WORD TO STR" bstr::word_case = VAL%(in_string) out_string = bstr::str2_case !+ ! "LONG TO STR" - number (long) to string (len 4) ! !- CASE "LONG TO STR" bstr::long_case = VAL%(in_string) out_string = bstr::str4_case !+ ! "DATE TO STR" - Date (VMS Date) to string ! !- CASE "DATE TO STR" fdat::asc_day = SEG$(in_string,1,23) stat = sys$bintim(,fdat::asc_day,bstr::date_case(0),) if (stat and 1%) <> ss$_normal then fdat::asc_day = "17-NOV-1858 00:00:00.00" stat = sys$bintim(,fdat::asc_day,bstr::date_case(0),) end if out_string = bstr::strg_case CASE ELSE out_string = "Bad Option for FN$CONVERT_STR" END SELECT GOTO EXIT_PART %SBTTL "Misc errors" 4000 CLEANUP_PART: !+ ! Some errors !- if err = 32 then out_string = in_string resume 32000 else out_string = in_string resume 32000 end if %SBTTL "Exit and return" 32000 EXIT_PART: !+ ! Exit module !- 32767 FUNCTIONEND 1%