mocallins

Mike Collins

TCL programmer since 2000

Just giving back to the TCL community

Improvements welcome

package provide Equals 0.1

# After doing some work trying converting a C library example into TCL it dawned on me, we don't have +=, -= ...

proc plusEq {var val {float ""}} {

  upvar $var lVar
  if {![info exists lVar]} {set lVar 0}
  if {[regexp -nocase -- {^f(|l|lt|loat)$} $float]} {
    if {[regexp -nocase -- {\.} $val]} {
      set lVar [expr $lVar + ${val}]
    } else {
      set lVar [expr $lVar + ${val}.0]
    }
  } else {
    set lVar [expr $lVar + int($val)]
  }

}

proc minusEq {var val {float ""}} {

  upvar $var lVar
  if {![info exists lVar]} {set lVar 0}
  if {[regexp -nocase -- {^f(l|lt|loat)$} $float]} {
    if {[regexp -nocase -- {\.} $val]} {
      set lVar [expr $lVar - ${val}]
    } else {
      set lVar [expr $lVar - ${val}.0]
    }
  } else {
    set lVar [expr $lVar - int($val)]
  }

}

proc timesEq {var val {float ""}} {

  upvar $var lVar
  if {![info exists lVar]} {set lVar 1}
  if {[regexp -nocase -- {^f(l|lt|loat)$} $float]} {
    if {[regexp -nocase -- {\.} $val]} {
      set lVar [expr $lVar * ${val}]
    } else {
      set lVar [expr $lVar * ${val}.0]
    }
  } else {
    set lVar [expr $lVar * int($val)]
  }

}

proc divEq {var val {float ""}} {

  upvar $var lVar
  if {![info exists lVar]} {set lVar 1}
  if {[regexp -nocase -- {^f(l|lt|loat)$} $float]} {
    if {[regexp -nocase -- {\.} $val]} {
      set lVar [expr $lVar / ${val}]
    } else {
      set lVar [expr $lVar / ${val}.0]
    }
  } else {
    set lVar [expr $lVar / int($val)]
  }

}

Here's another of my creations that i'm currently using in a project. I have this built to be incorporated into a namespace, I currently use it my own tclUtil package. But you can modify it, to use globals as you see fit.

and as always,

Improvements welcome

    proc makeToglVar {var args} {
      # As per its name, this creates a procedure and stores the value in its own
      # dictionary of variables.
      # I originally wrote it to just toggle between 0 and 1, but then thought about it 
      # for a bit and it can toggle between probably any 2 values
      # and that's all it does, by calling the variable name
      # it will simply toggle between the 2 values on succesive calls
      # The latest change in the variable procedure,
      # is to call it with a 1 and it will just return the current value, without toggling.
      # if you're debugging and need to know what it is at that time, lol

      if {$args == ""} {
        lassign {0 1} val0 val1
      } elseif {[llength [eval concat $args]] != 2} {
        error "invalid number of args:$args"
      } else {
        # this might get a little tricky if you use values with spaces.
        lassign [eval concat $args] val0 val1
      }
      pvar val0 val1

      variable $var
      variable mtv
      dict set mtv $var [dict create val1 [list $val1] val0 [list $val0]]
      set $var $val0

      set cmd {proc ::nsTclUtil::$var {{val 0}} {
        variable mtv
        if {\$val} {
          return [set ::nsTclUtil::$var]
        }
        if {[set ::nsTclUtil::$var] == [dict get \$mtv $var val0]} {
          set ::nsTclUtil::$var [dict get \$mtv $var val1]
        } else {
          set ::nsTclUtil::$var [dict get \$mtv $var val0]
        }
      }}
      set cmd [subst -nocommands $cmd]
#       pvar cmd
      uplevel #0 $cmd
      namespace export $var
      uplevel #0 "namespace import ::nsTclUtil::$var"
      eval $var
    }

Anybody care to join in on creating a Network discovery utility, without using SNMP.

I'm thinking of spoofing a routing protocol and capturing the updates or data, and deciphering.

Especially since we have network / port access to be a server or client of sorts, and transmit packets.

I was initally thinking OSPF, because i thought there might be some nice psuedo code, but i don't seem to find any, just C* livbrarys, even in some of the open source packages.

This is intended to perform local disovery only, on your own network

--- Ok, well nevermind, i found a round about solution, that appears to be robust enough --- I created a vm on my network and am running FRRouting, on it, with 2 interfaces, 1 on the main common network that extends into the VM network, and the other interface on the VM network that is attached to the routers running, And since FRRouting runs on a Linux distro, i also installed NMAP, and can now use just a shell script to capture all the ip addresses on every subnet that the routers are advertising. Pretty slick. And being a shell script can pretty much configure the output any way anybody might desire.