next up previous contents index
Next: Using vectors and hash Up: Various attributes and functions Previous: Attributes for data dependencies

Controlling the target

By default the script is executed with some initialized variables. The variable $cunit defines the current unit corresponding to the connected window and the variable $csel specifies the current selection in this window. So, the script can be applied to the selection or to the current selection.

Some features are provided to reach the other units. These ones allows to quickly generalized a script wrote for one unit to the whole forlib3. However, they are under development and are thus likely to change.

  $\blacktriangleright$ forlibVar.INITALLUNITS(u)
 
    The expression initializes the list of units in the forlib forlibVar (i.e. given by $forlib). The argument u must be the current unit (i.e. given by $cunit).
  $\blacktriangleright$ forlibVar.NBUNIT
 
    The expression returns the number of units in the forlib forlibVar (i.e. given by $forlib).
  $\blacktriangleright$ forlibVar.FINDUNIT(r)
 
    The expression returns one of the units of the forlib forlibVar. When r is an integer between 0 and varforlibVar.NBUNIT-1, the unit of this rank is returned. A string can also be specified for r to find the unit according to its name. The result is FALSE when search fails.
  $\blacktriangleright$ SETENVTO(unit)
 
   This statement allows to take into account the specified unit like the default one. Using this statement in conjunction with the previous attributs allows to quickly generalize a script wrote for one unit to the whole forlib. In this mode, the interactive context variable ($cstat, $csel) are without effects.

  $\blacktriangleright$ RESTOREENV
 
   This statement is the dual of the previous one. It allows the user to restore the current TSF environment according to the unit from which TSF has been called.

  $\blacktriangleright$ forlibVar.UPDATE(logFile)
 
    This attributes allows to regenerate the main analysis did at the time of the forlib creation. It allows to take into account the modification did by the user. The logFile parameter targets a file which contains the results of the analysis done.

$\vartriangleright$ Example 51:Declare a new variable and add a new statement after the first executable statement of each unit of the forlib.

SCRIPT ApplyToUnit(unit)
   PRINT unit.SNAME
   DECLARE ("integer modifDone")
   newStat := PARSESTAT("       modifDone = 3")
   PRINT newStat
    stat := unit.FIRST
    PASTE(AFTER, newStat, stat)
ENDSCRIPT


SCRIPT main ()
 foo := $cforlib.INITALLUNITS($cunit)
 PRINT $cforlib.NBUNIT
 PRINT ""

 nbunit := $cforlib.NBUNIT
 cpt:=0 
 WHILE(cpt<nbunit)
   unit := $cforlib.FINDUNIT(cpt)
   IF (unit) THEN
        SETENVTO(unit)
        unit_name:=unit.SYMBOL
        unit_fileName := unit.FILENAME
        unit_file := unit.FILE  // get the file where the unit is defined
        CALLSCRIPT ApplyToUnit(unit)
        keepTrace := unit_fileName 
        res := "Unit " + unit_name + " is saved in " + unit_file.SAVE(keepTrace)
        PRINT res
        RESTOREENV
 ENDIF 
   cpt:=cpt+1 // go to the next unit
 ENDWHILE
  log := "/tmp/"+ $cforlib.SYMBOL + ".msg"
  PRINT $cforlib.UPDATE(log)

ENDSCRIPT


next up previous contents index
Next: Using vectors and hash Up: Various attributes and functions Previous: Attributes for data dependencies
Yann Mevel
1999-04-30