#! /bin/sh
# (next line not seen by tcl) \
exec tclsh $0 ${1+"$@"}    # goto tcl, wherever it is

# quick-and-dirty remove // comments for IRIX ezxml compile, highly non-general
if {$argc < 2} {
  puts "\nuse: rmcm \[-f\] <infile> <outfile>   \[rm c++ style // comments\]\n"
  return
}
set force 0
set argv2 ""
foreach arg $argv {
  if [string match "-f" $arg] { set force 1; continue }
  set argv2 "$argv2 $arg"
}
set infile [lindex $argv2 0]
set outfile [lindex $argv2 1]

if ![file exists $infile] {
  puts "rmcm: ### $infile not found"
  return
}
if { [file exists $outfile] && !$force } {
  puts "rmcm: ### $outfile already exists"
  return
}

# go
set id [open $infile r]
set lines [split [read $id] "\n"]
close $id
set id [open $outfile w 0644]
foreach line $lines {
  set i [expr [string first "//" $line] - 1]
  if {$i > -2} {
    puts $id [string range $line -1 $i]
  } else {
    puts $id $line
  }
}
close $id

