SpyderByte.com: OpenVMS.org dba.OpenVMS.org dcl.OpenVMS.org de.OpenVMS.org fr.OpenVMS.org it.OpenVMS.org
   
Home Contribute News, Jobs, Press Releases, etc. Advertise on OpenVMS.org About/Contact Search News Archives
More Links
  • VAX architecture
  • Pitfalls of F$LOCATE and other functions
  • DCL GOTO
  • Demonstrations
  • OpenVMS Consultant
  • Robert Gezelter, CDP, CSA, CSE, Software Consultant
  • Computer Security Handbook, 5th Edition
  • Ruminations - An IT Blog
  • http://www.rlgsc.com
  • Printer friendly version
    Share this story

    Navigation
    VMS Audio Network (VAN)
    Featured Articles
    Vendors
    Training
    Golden Eggs
    Golden Eggs x86
    Help for VMS Beginners
    Documentation
    Developer Resources
    Books
    Commercial Software
    Open Source & Freeware
    OpenSource ported to VMS
    Resources
    FAQs/How-to
    Lists/Newsgroups/Forums
    Security Advisories & Info
    OpenVMS Patches

    Forums
     HP ITRC OpenVMS forum
     OpenVMS Hobbyist forums
     Usenet: comp.os.vms

    Mailing Lists
    OpenVMS.org Newsletter
    OpenVMS.org Alerts
    Rdb Managers

    Roadmaps
    OpenVMS Roadmap (2009)
    Itanium Roadmap
    HP Roadmaps (2002)
    BCS Roadmap FAQ (2002)
    Storage Roadmap FAQ (2002)


    OpenVMS.org Info
    OpenVMS.org Admin Staff:
    Ken Farmer, Ian Miller
    About
    Search OpenVMS.org
    News Archives
    Mobile Edition
    Submit News
    Advertising Information

    OpenVMS.org Websites

    Databases running on OpenVMS


    Digital Command Languauge


    French



    German


    Italian



    Latest News

    The OpenVMS Consultant: DCL Computed GOTO
    Posted by Bob Gezelter on Tuesday June 09 2009 @ 04:24PM EDT

    Multiple choice transfers of control are one of the most time-honored facilities in programming languages, be they conventional or scripting, interpreted or compiled, assembler or very high level. It is often mistakenly believed that indirection is needed for implementation, but this is not the case. Perfectly serviceable multi-way branches can be implemented without indirection. All that is necessary is some method of re-computing the location of the next instruction (or line in a scripting language) to be executed.

    The syntax of multi-way transfers of control depend on the individual syntax of the underlying programming language, and may take several forms, including:

    • Computed GOTO (FORTRAN)
    • switch/case (C/C++/JAVA)
    • GOTO DEPENDING ON (COBOL)
    • ON GOTO (BASIC)
    • Branch/Jump Tables (assembler)

    Beyond the most basic ability to compute the next statement to be executed, the most important requirement in implementing a multi-way branch is ensuring that the branch value is within the appropriate range. Indeed, the VAX architecture contains the CASE machine instruction to implement bounds checking and transfer of control via an inline table of offsets.

    At its most basic, a multi-way transfer of control depends on an integer index. This is the most basic form, and it is shared by most assembler and third generation languages. C/C++/JAVA enums are integers, for most intents and purposes. DCL, PERL, EnScript® and other interpreted scripting languages often extend this concept to strings. This extension transforms the range check from an integer bounds check to a check based on the presence of an index string value within an enumeration of potential values. This check can be most simply implemented by using a string index function. In DCL the string index operation is provided by the F$LOCATE lexical function.

    However, some caution is needed when using the F$LOCATE function, or for that matter, any index function to locate a substring within the context of a larger string. Consider an index string that can contain the values “THEE”, and “EEM”. Admittedly, this selection of values has more than a small potential for confusion, but it is a useful example.

    Simply checking that the index string is contained within a list of possible strings is insufficient (e.g., the string “THE” is not a valid index, yet is within the valid index string “THEE”). The solution is to ensure that the string containing the valid values starts and ends with the delimiter character. This technique was discussed in a previous column entitled: “Pitfalls of F$LOCATE and other functions”.

    Using the extra delimiters, the validation code is simplicity itself, to wit (INDEX_VALUE contains the index string):

    $       VALID_INDICES = “/ONE/TWO/THREE/FOUR/”
    $       IF F$LOCATE(“/”+indexvalue+”/”, VALID_INDICES) -
               .EQ. F$LENGTH(VALID_INDICES) THEN {error processing}

    Once the string index has been validated, the actual transfer of control consists of combining a simple GOTO statement with symbolic substitution, to wit:

    $       GOTO TARGET_’INDEXVALUE’
    $ TARGET_ONE:
    $       …
    $       GOTO EXITTARGET
    $ TARGET_TWO:
    $       …
    $       GOTO EXITTARGET
    $ TARGET_THREE:
    $       …
    $       GOTO EXITTARGET
    $ TARGET_THREE:
    $       …
    $       GOTO EXITTARGET
    $ TARGET_FOUR:
    $       …
    $ EXITTARGET:
    $ …

    This approach is far safer than attempting to nest IF-THEN-ELSE conditionals. The option is processed directly. If an invalid index is presented, it is detected immediately and dealt with. Adding a new possibility is simply a matter of adding the new index possibility to VALID_STRING and adding the appropriate processing code.

    A segment of DCL implementing and demonstrating the above technique can be found on my www site under "DCL GOTO" under the Demonstrations heading.

    Reader questions about using DCL, or other questions relating to OpenVMS should be addressed to the OpenVMSConsultant (at) OpenVMS.org. While I cannot promise to answer all messages, I will try to respond as time allows. The OpenVMS Consultant welcomes questions from readers about OpenVMS and related technologies. Please submit your questions to the OpenVMS Consultant.


    Biography:

    Robert Gezelter, CDP, CSA, CSE, Software Consultant, has more than 30 years of international consulting experience in both the private and public sectors. He is a regular guest speaker at technical conferences worldwide including the HP Technology Forum. In 2004, the IEEE Computer Society appointed Mr. Gezelter to its Distinguished Visitors Program, which provides meeting speakers for IEEE chapters throughout North America. He is also a published numerous technical papers and book chapters, including two chapters in the recently released Computer Security Handbook, 5th Edition,

    Recently, he started Ruminations - An IT Blog on IT topics not strictly related to OpenVMS.

    His firm's practice emphasizes in-depth technical expertise in computer architectures, operating systems, networks, security, APIs, and related matters. Mr. Gezelter has worked with OpenVMS since the initial release of VAX/VMS in 1977.

    His clients include small businesses to the Fortune 10, locally, nationally, and internationally on matters spanning the range from individual telephone questions to major projects.

    He can be reached via his firm's web site at http://www.rlgsc.com.



    < OpenVMS - The way forward | eCube Adds 3GLs to Eclipse for NXTware Remote >



    ADVERTISEMENT:
    Sponsors







    The OpenVMS Consultant
    OpenVMS Consulting


    The Minimum You Need to Know book series
    Books by Roland Hughes


    Alpha and VAX Replacement
    StanQ.com



    Interested in Advertising? Click here...

    Friends of VMS
    Connect (HP User Community):
    Connect Home
    Connect Chapters
    Connect Special Interest Groups

    United Kingdom
    Canada
    Encompasserve/DECUServe
    OpenVMS Hobbyist
    More usergroups...
    Other Sites:
    Aaron's OpenVMS blog
    Alexey Chupahin
    Arne Vajhoej
    DECUS Library Compendium
    DJE Systems
    Dr OpenVMS blog
    Francesco Gennai
    Eight-Cubed blog
    Free OpenVMS Software
    Galen Tackett
    HoffmanLabs
    Hunter Goatley
    Ian Miller
    Itanium Solutions Alliance
    Jeff Cameron
    John Fisher
    Syltrem VMS Page (French)
    Kednos PL/I
    Keith Parris
    Migration Specialties
    Noetic Systems, Inc
    OpenOffice Port to VMS
    OpenVMSPlanet.org
    OpenVMS Rocks
    Preatorian.net
    Retrobeep
    Steven M. Schweda
    SYSMGR Blog
    TMESIS Software
    Trends That Matter
    VAMP (VMS, Apache, MySQL, PHP)
    VIM
    Vaxination
    Visio Cafe (HP Templates)
    VMSresource.org.uk
    XDelta
    Free VMS Accounts:
    Deathrow Public OpenVMS Cluster
    Encompasserve/DECUServe/EISNER
    Polarhome
    Fafner
    Poetry Hacklab
    Marway.Org
    In Memory:
    John Wisniewski Memorial Site
    Terry Shannon Memorial Site


    OpenVMS Rings

    OpenVMS Webring

    Prev

    Random

    Next

    Prev5

    List

    Next5

    OpenVMS Gurus

    Prev

    Random

    Next

    Prev5

    List

    Next5




    Home About & Contact Search Archive Mobile Submit News Sponsorship & Advertising
         Copyright © 2001-2007 SCORSE, LLC
    OpenVMS® is a trademark of HP
    All other trademarks are those of their owners.
        
      SpyderByte.com ;Technical Portals