How to create a Global Proc

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf How to create a Global Proc

  • Creator
    Topic
  • #49479
    Todd Wyndham
    Participant

      I have a tcl proc that I want to make available to all of my sites.  How do I make a proc global?

    Viewing 11 reply threads
    • Author
      Replies
      • #62118
        Steve Carter
        Participant

          Assuming that you’re referring to a TPS proc, just place it in $HCIROOT/tclprocs and create a tclIndex.  You’ll now have access to the proc in all of your sites.

          Keep in mind that like-named procs at the site level will take precedence over a root level proc.

          Steve

        • #62119
          Jim Kosloskey
          Participant

            Be aware!!

            When you do a new release of Cloverleaf(R) all of the procs in the HCIROOT/tclprocs directory will be replaced by the distributed procs in essence removing your procs.

            Over time, you will find the need to share other objects across sites (such as variants and Tables).

            What we did here was to create a special site which contains no integrations but just provides us with a directory structure to place global objects (including tclprocs).

            For Tcl procs, we soft link from HCIROOT/tclprocs directory for each proc to the global site tclprocs directory. Then when  a new release is instaled, we only have to rebuild the links and do a mktclindex to get everything back.

            For other objects, we soft link from the site directory for that object type which needs the global object to the global site (appropriate directory – Tables directory to Tables directory for example).

            In 5.6 of Cloverleaf(R) the concept of a Master Site is introduced. Hopefully this will give all of the advantages of what is described above without the disadvantages of maintaining soft links.

            Jim Kosloskey

            email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

          • #62120
            Steve Carter
            Participant

              That’s true, but I don’t think it’s much of a problem to just copy over custom tclprocs after an upgrade.

              We’ve been using the concept of a ‘master site’ for quite a while now.  We just add the additional path to init.tcl.  Of course, we do have to add our entry back to init.tcl after an upgrade as well.

              It will be nice once this is incorporated in a standard release.

              Steve

            • #62121
              Charlie Bursell
              Participant

                My recommendation would be to create a Tcl package or pacages with shared procedures.  You can share them in different ways.

                1.  Put the packages in a subdirectory of the Tcl Path

                     At a hcitcl prompt “echo $auto_path”  to see defualt for site

                2. Put them anywhere you want.  For example if you wanted a package in /home/smith/mypackage, just put it there, make the package index in that directory.  Then when using enter the following:

                   global auto_path

                   lappend auto_path /home/smith

                   package require mypackage

                Similar to mktclindex you must make a package index. Here is a script that is nothing more than mktclindex modified to do packages.  I suggest you put it in $HCIROOT/contrib to make it available throughout the root.  This one has a Windows suffix (.htc).  For Unix, simply remove the suffix, make sure owner and permissions allow it to be executed.

              • #62122
                Russ Ross
                Participant

                  Jim spoke of creating a global site and storing global TCL procs in it and then creating symbolic links in the $HCIROOT/tclprocs directory to point to those global procs.

                  Here is a copy of the script I wrote that Jim and I have avaialbe to us to make it easy to create a link for all *.tcl files in our mda_global TCL proc directory, plus it does a mktclindex.

                  Code:

                  #!/usr/bin/ksh

                  # Begin Module Header ==============================================================================
                  #
                  #——
                  # Name:
                  #——
                  #
                  # make_links_for_mda_global_tclprocs.ksh
                  #
                  #———
                  # Purpose:
                  #———
                  #
                  # Create all the $HCIROOT/tclprocs symbolic links for all *.tcl file in the mda_global site.
                  #
                  #——-
                  # Notes:
                  #——-
                  #
                  # will remove any existing links in the $HCIROOT/tclprocs directory and
                  # will remove $HCIROOT/mda_global/tclprocs/tclIndex if it exists and
                  # will do mktclindex for the $HCIROOT/tclprocs directory
                  #
                  #———
                  # History:
                  #———
                  #
                  # 2000.08.22 Russ Ross
                  #          – wrote initial version
                  #
                  # 2003.01.08 Russ Ross
                  #          – modified to create absolute paths in the links to adhere to team standard
                  #
                  # End of Module Header =============================================================================

                  #————————————————————-
                  # remove any existing links in the $HCIROOT/tclprocs directory
                  # and chmod -rw-rw-r– all the mda_global TCL files
                  #————————————————————-

                  echo ==========
                  cd $HCIROOT/tclprocs
                  chmod 664 *
                  mda_global_link_list=`ls -l | grep ^l | awk ‘{print $9}’`
                  for mda_global_link in $mda_global_link_list; do
                     echo Deleting link $mda_global_link
                     rm $mda_global_link
                  done

                  #———————————————————-
                  # get list of tcl file that will need links created and
                  # remove $HCIROOT/mda_global/tclprocs/tclIndex if it exists
                  #———————————————————-

                  cd $HCIROOT/mda_global/tclprocs
                  tcl_file_list=`ls *.tcl|sort`
                  rm -f tclIndex

                  #——————————————-
                  # create the symbolic links
                  #——————————————-

                  echo ==========
                  cd $HCIROOT/tclprocs
                  for tcl_file in $tcl_file_list; do
                     echo creating link for $tcl_file
                     ln -s $HCIROOT/mda_global/tclprocs/$tcl_file $tcl_file
                  done

                  #————————————————–
                  # do mktclindex for the $HCIROOT/tclprocs directory
                  #————————————————–

                  echo ==========
                  echo Making TCL index file
                  mktclindex

                  Russ Ross
                  RussRoss318@gmail.com

                • #62123
                  Richard Hart
                  Participant

                    We have a ‘lib’ directory that contains ‘global’ code and the tclIndex file (for each application) just points to this …

                    set auto_index(ccm_xlate_ris)

                      ]

                      set auto_index(ccm_xlate_cap)

                        ]

                        set auto_index(ccm_xlate_ult)

                          ]

                          set auto_index(ccm_xlate_rad)

                            ]

                            set auto_index(ccm_xlate_sud)

                              ]

                              set auto_index(MakeMrn)

                                ]

                                set auto_index(MakeAcct)

                                  ]

                                  set auto_index(MakePtType)

                                    ]

                                    ….

                                    set auto_index(gen_code_over)

                                      ]

                                      set auto_index(gen_code_msginfo)

                                        ]

                                        set auto_index(gen_code_resend)

                                          ]

                                          set auto_index(gen_code_printmsg)

                                            ]

                                            set auto_index(gen_code_splitter)

                                              ]

                                              set auto_index(gen_code_mkreply)

                                                ]

                                                set auto_index(Print)

                                                  ]

                                                  set auto_index(RetRepeat)

                                                    ]

                                                    set auto_index(RetComp)

                                                      ]

                                                    1. #62124
                                                      Russ Ross
                                                      Participant

                                                        With the new global site in QDX 5.6 I no longer have to create the symbolic links for the TCL procs and I have tested this with success so far.

                                                        However, I will need to investigate if putting the packages subdirectory in our $HCIROOT/mda_global/tclporcs directory will make them visible.

                                                        Does anyone out there know if cloverleaf will find the packages in the following master site directory?

                                                        $HCIROOT/mda_global/tclprocs/packages

                                                        With recent posts about how to make a package that cloverleaf can see, I decided to post the updated copy of our pre QDX 5.6 TCL proc called

                                                        make_links_for_mda_global_tclprocs.ksh

                                                        Code:

                                                        #!/usr/bin/ksh

                                                        # Begin Module Header ==============================================================================
                                                        #
                                                        #——
                                                        # Name:
                                                        #——
                                                        #
                                                        # make_links_for_mda_global_tclprocs.ksh
                                                        #
                                                        #———
                                                        # Purpose:
                                                        #———
                                                        #
                                                        # Create all the $HCIROOT/tclprocs symbolic links for all *.tcl file in the mda_global site.
                                                        #
                                                        #——-
                                                        # Notes:
                                                        #——-
                                                        #
                                                        # will remove any existing links in the $HCIROOT/tclprocs directory and
                                                        # will remove $HCIROOT/mda_global/tclprocs/tclIndex if it exists and
                                                        # will do mktclindex for the $HCIROOT/tclprocs directory
                                                        # will create packages link to directory $HCIROOT/mda_global/tclprocs/packages
                                                        # will pkg_mkIndex for $HCIROOT/mda_global/tclprocs/packages directory
                                                        #
                                                        #———
                                                        # History:
                                                        #———
                                                        #
                                                        # 2000.08.22 Russ Ross
                                                        #          – wrote initial version
                                                        #
                                                        # 2003.01.08 Russ Ross
                                                        #          – modified to create absolute paths in the links to adhere to team standard
                                                        #
                                                        # 2007.04.10 Russ Ross
                                                        #          – modified to create packages link to directory $HCIROOT/mda_global/tclprocs/packages
                                                        #          – modified to only chmod 664 *.tcl files instead of *
                                                        #
                                                        #
                                                        # 2007.04.19 Russ Ross
                                                        #          – modified to call mkpkgindex.tcl for $HCIROOT/mda_global/tclprocs/packages directory
                                                        #
                                                        # End of Module Header =============================================================================

                                                        #————————————————————-
                                                        # remove any existing links in the $HCIROOT/tclprocs directory
                                                        # and chmod -rw-rw-r– all the mda_global TCL files
                                                        #————————————————————-

                                                        echo ==========
                                                        cd $HCIROOT/tclprocs
                                                        chmod 664 *.tcl
                                                        mda_global_link_list=`ls -l | grep ^l | awk ‘{print $9}’`
                                                        for mda_global_link in $mda_global_link_list; do
                                                           echo Deleting link $mda_global_link
                                                           rm $mda_global_link
                                                        done

                                                        #———————————————————-
                                                        # get list of tcl file that will need links created and
                                                        # remove $HCIROOT/mda_global/tclprocs/tclIndex if it exists
                                                        #———————————————————-

                                                        cd $HCIROOT/mda_global/tclprocs
                                                        tcl_file_list=`ls *.tcl|sort`
                                                        rm -f tclIndex

                                                        #——————————————-
                                                        # create the symbolic links
                                                        #——————————————-

                                                        echo ==========
                                                        cd $HCIROOT/tclprocs
                                                        for tcl_file in $tcl_file_list; do
                                                           echo creating link for $tcl_file
                                                           ln -s $HCIROOT/mda_global/tclprocs/$tcl_file $tcl_file
                                                        done
                                                        ln -sf $HCIROOT/mda_global/tclprocs/packages packages

                                                        #————————————————–
                                                        # do mktclindex for the $HCIROOT/tclprocs directory
                                                        #————————————————–

                                                        echo ==========
                                                        echo Making TCL index file
                                                        mktclindex

                                                        #——————————————————————————
                                                        # do pkg_mkIndex for the $HCIROOT/tclprocs/packages
                                                        #
                                                        # if for some reason you choose not to run the standalone script mkpkgindex.tcl
                                                        # an alternative would be to run the following command
                                                        # hcitcl -c “pkg_mkIndex -verbose — $HCIROOT/tclprocs/packages”
                                                        #——————————————————————————

                                                        echo ==========
                                                        echo Making packages index file
                                                        echo “”
                                                        cd $HCIROOT/mda_global/tclprocs/packages
                                                        mkpkgindex.tcl -verbose —
                                                        echo ==========

                                                        Russ Ross
                                                        RussRoss318@gmail.com

                                                      • #62125
                                                        Russ Ross
                                                        Participant

                                                          I did a simple test to see if I have a master site subdirectory called

                                                          $HCIROOT/mda_global/tclprocs/packages

                                                          that contains my packages, will they be visible to cloverleaf (QDX 5.6) in that location and the answer seems to be yes.

                                                          Here is the simple test I did

                                                          cd /hcitest

                                                          hcitcl

                                                          package require oth_fileset_delete

                                                          and it returned 1.1 which is the version of the package it found.

                                                          Russ Ross
                                                          RussRoss318@gmail.com

                                                        • #62126
                                                          Russ Ross
                                                          Participant

                                                            I realized I’m calling a stand alone TCL script ( mkpkgindex.tcl ) that I sort of took for granted and here it is:

                                                            Code:

                                                            #!/usr/bin/ksh
                                                            # this line to escape the next line from the tcl interpreter
                                                            exec hcitcl “$0” “$@”
                                                            ################################################################################
                                                            # Name: mkpkgindex
                                                            # Purpose: Creates a Package Index
                                                            #

                                                            # Args: -debug
                                                            #           -direct
                                                            #           -verbose
                                                            #           -load pattern
                                                            #           —        
                                                            #           dir #
                                                            #
                                                            # Author:       Jim Kosloskey
                                                            # Date-written: 04/12/2007
                                                            #
                                                            #**************************************************************************************************************
                                                            #*                                            C O D E   A U D I T                                                               *
                                                            #*_____________________________________________________________________________*
                                                            #*Date       I-Catcher  Description                                                                                          *
                                                            #*———- ———- ———————————————–*
                                                            #*04/12/2007            Program inception
                                                            #*______________________________________________________________________________*
                                                            #*
                                                            #*______________________________________________________________________________*
                                                            #**************************************************************************************************************
                                                            #
                                                            # Notes:
                                                            #            This procedure is intended to be invoked from a command line
                                                            #
                                                            ################################################################################
                                                            #

                                                            proc mkpkgindex { arg_cnt arg_values } {
                                                            # Setup Globals
                                                               global env

                                                            # Initialize local variables
                                                               set module          “[clock format [clock seconds] -format “%m/%d/%Y %T”] MKPKGINDEX (V1.0):”
                                                               set return_code     0
                                                               set debug           0
                                                               set direct          0
                                                               set verbose         0
                                                               set load            0
                                                               set end_o_switches  0
                                                               set directory       “”
                                                               set pattern         “”
                                                               set args_ndx        0
                                                               set end_o_args_ndx  0
                                                               set pattern_ndx     0
                                                               set ret_cd          0
                                                               set err_lit         “”
                                                               set direct_lit      “”
                                                               set verbose_lit     “”
                                                               set load_lit        “”
                                                               set argopts {
                                                                            {debug f+ debug}
                                                                            {direct f+ direct}
                                                                            {verbose f+ verbose}
                                                                            {load f+ load}
                                                                            {- f+ end_o_switches}
                                                                           }

                                                            #  The pattern for getopts options (as near as I can determine) is as follows:
                                                            #    the first parm (ex {-direct f+ direct} above) is the actual switch value
                                                            #    the second parm can have these values:
                                                            #        1  – if the switch requires following data
                                                            #        f+ – the switch does not require data
                                                            #    the third parm indicates the variable where the value associated with
                                                            #      the switch will be placed (if there is no value indicated (f+) then
                                                            #      the variable will contain 1 if the switch existed and 0 if it did not.

                                                            # Get the arguments
                                                            #  The essential command here is the “set args [getopt $argv $argopts]” command.
                                                            #  That command causes the command line to be interrogated and switches indicated by
                                                            #  argopts populated and args will be all command line arguments found which were not
                                                            #  specified in argopts.
                                                            #
                                                            #  The catch is so we can determine if getopt didn’t like something. Usage will then
                                                            #  inform the user of the appropriate syntax.
                                                            #
                                                               if {[catch {set args [getopt $arg_values $argopts]} err]} { ;# Any errors in the arguments?
                                                                   echo “$module Command line argument error – $err.”
                                                                   echo {
                                                            usage: mkpkgindex.tcl [-direct] [-verbose] [-load pattern] [–] [-dir ]
                                                            where:
                                                               -debug            =  Display ‘health and well-being’ of this proc
                                                               -direct           =  Generate an Index with source and load commands.
                                                               -verbose          =  Display the name of each file processed and any errors.
                                                               -load             =  Dynamically loads packages that match pattern.
                                                               —              =  End of pkg_mkIndex switches (Required)
                                                               dir  = The directory and glob pattern of Package files to be used to make index
                                                                   }
                                                               }

                                                            # Construct pkg_mkIndex command from provided switches, etc.

                                                            # Add the -direct if present

                                                               if {$direct} {  
                                                                   if {$debug} {
                                                                       echo “$module -direct switch detected.”
                                                                   }
                                                                   set direct_lit “-direct”
                                                               }

                                                            # Add the -verbose if present

                                                               if {$verbose} {
                                                                   if {$debug} {
                                                                       echo “$module -verbose switch detected.”
                                                                   }
                                                                   set verbose_lit “-verbose”
                                                               }

                                                            # Add the -load if present

                                                               if {$load} {
                                                                   if {$debug} {
                                                                       echo “$module -load switch detected.”
                                                                   }
                                                                   set load_lit “-load”
                                                               }

                                                            # Check to see if the end of switches is present (it MUST be present)

                                                               if {!$end_o_switches} {
                                                                   puts stderr “$module End of switches switch not located!”
                                                                   puts stderr “$module Aborting and returning non-zero return code.”
                                                                   return 001
                                                                  }
                                                               lappend  mkpkgindex_args “–”
                                                                 
                                                            # Okay – let’s find the directory and pattern
                                                            # We need to locate the end of switches switch (the directory will be the next list element)

                                                               if {$debug} {
                                                                   echo “$module Finding Directory argument.”
                                                                   echo “$module Locating the end of switches (–).”
                                                               }
                                                               set args_ndx [lsearch -exact $arg_values “–“]
                                                               if {$debug} {
                                                                   echo “$module End of switches found at the >$args_ndx< element of the arguments list."    }     # Now add one to the index        if {$debug} {        echo "$module Incrementing to the next element (should be the directory)."    }    incr args_ndx 1    if {$debug} {        echo "$module Now working with element >$args_ndx< >[lindex $arg_values $args_ndx]<."        echo "$module Hopefully the above is a directory."    }     # Now let's get the directory...    set directory [lindex $arg_values $args_ndx]    if {[string equal "" $directory]} {        if {$debug} {            echo "$module No directory specified, defaulting to current directory >.<."        }                                                                                      set directory "."    }     # Bump the index by one again (to get by the directory)    if {$debug} {        echo "$module Incrementing to the next element (should be the start of the file patterns)."    }    incr args_ndx 1    if {$debug} {        echo "$module Now starting with element >$args_ndx<."    }     # And get the patterns (there can be more than one and we want to get them all) # So we will use the loop command - but - first we need to know the number of # elements in the arguments list.    if {$debug} {        echo "$module Finding the total number of argument elements..."    }    set end_o_args_ndx [llength $arg_values]    if {$debug} {        echo "$module Total number of argument elements is >$end_o_args_ndx<."    }     # Now let's loop through the patterns # the args_ndx variable points to the start for the loop # and the end_o_args_ndx points to the end for the loop.   # The pattern_ndx variable points to the current pattern in the arguments.    if {$debug} {        echo "$module Looping through the patterns beginning at >$args_ndx – [lindex $arg_values $args_ndx]< until "        echo $module  >$end_o_args_ndx – [lindex $arg_values $end_o_args_ndx]<."    }    loop pattern_ndx $args_ndx $end_o_args_ndx {        if {$debug} {            echo "$module Appending >[lindex $arg_values $pattern_ndx]< to >$pattern<."        }        lappend $pattern [lindex $arg_values $pattern_ndx]    }         # Everything is ready - let's issue the command... # First we need to construct the command    lappend command "pkg_mkIndex" $direct_lit $load_lit $verbose_lit "--" $directory $pattern     # Next we need to remove any nulls. We will use a while command to test if there are any nulls # in the command we just constructed. As long as there are any, we will search (lsearch) for # the location of the first null; then we will delete that element of the list by using lreplace.            while {[lcontain $command ""]} {        set args_ndx [lsearch -exact $command ""]        set command [lreplace $command $args_ndx $args_ndx]    }    if {$debug} {        echo "$module Issuing the pkg_mkIndex command >$command<."    }    set ret_cd [catch [eval $command] err_lit]    if {$ret_cd} {        puts stderr "$module Error detected executing pkg_mkIndex >$err_lit<."        puts stderr "$module Returning return code 002, aborting!"        return 002    }               # Normal end    if {$debug} {        echo "$module pkg_mkIndex successfully executed."    }    return "0" } mkpkgindex [llength $argv] $argv

                                                            Russ Ross
                                                            RussRoss318@gmail.com

                                                          • #62127
                                                            Russ Ross
                                                            Participant

                                                              Interesting observation:

                                                              When I do this in QDX 5.2

                                                              hcitcl -c “pkg_mkIndex -verbose — $HCISITEDIR/tclprocs/packages”

                                                              it work but not in QDX 5.6

                                                              It seems as if the “hcitcl -c” is suspect.

                                                              Jim says he recalls a possible post about this being broken.

                                                              I’m starting my search but if anyone has knowledge of this please direct me to it.

                                                              I did this simple test to see if my hunch is correct

                                                              hcitcl -c “echo hello”

                                                              and it also failed in QDX 5.6 but worked in QDX 5.2

                                                              Russ Ross
                                                              RussRoss318@gmail.com

                                                            • #62128
                                                              Russ Ross
                                                              Participant

                                                                How does one search for “-c” in clovertech?

                                                                Or better yet, something like “hcitcl -c”.

                                                                I’ve noticed weak search capablity or I don’t know the trick.

                                                                Another problematic search has been when under scores “_” are part of my search string like.

                                                                “make_links_for_mda_global_tclprocs.ksh”

                                                                Has anyone out there figured out how to get the clovertech search function to be usefull enough to perform these basic searches?

                                                                I have to keep stripping the search string down to something that is not very limited.

                                                                Russ Ross
                                                                RussRoss318@gmail.com

                                                              • #62129
                                                                Charlie Bursell
                                                                Participant

                                                                  Russ:

                                                                  Tcl 8.3 was front-ended by  TclX.  So when you ran hcitcl or tcl you were actually running TclX which ran Tcl.  TclX had command line options which are no longer available with Tcl 8.4.  There are no options at all with Tcl 8.4.  In the older Tcl to run it an pass it a file you would run

                                                                             tcl -f

                                                                  Now you simply run:

                                                                             tcl

                                                                  There is no -c option.

                                                                  With that said I am uploading a mkpkgindex file.  I use .pkg as a defualt suffix for my packages.  Chage that if you like.  Put the file in your contrib directory.  If on Unix, remove the .htc option and make sure it is executable.

                                                                  It is simply a copy of mktclindex modified.

                                                              Viewing 11 reply threads
                                                              • The forum ‘Cloverleaf’ is closed to new topics and replies.