File:  [LON-CAPA] / capa / capa51 / CapaTools / printsections.tcl
Revision 1.1: download - view: text, annotated - select for diffs
Tue Sep 28 21:25:35 1999 UTC (24 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
Initial revision

    1: #!/usr/local/bin/tclsh7.6
    2: 
    3: puts "Automated printing Version 1.1"
    4: 
    5: proc quit { } {
    6:     global dir
    7:     cd $dir
    8:     exit
    9: }
   10: 
   11: proc parseCapaConfig { } {
   12:     global onesided twosided 
   13: 
   14:     set filename [file join [pwd] capa.config]
   15:     set error [ catch { set fileId [open $filename "r"] } ]
   16:     if { $error } {
   17:         return 
   18:     }
   19: 
   20:     while { 1 } {
   21:         gets $fileId aline
   22:         if { [eof $fileId ] } { break }
   23:         switch -glob -- "$aline" {
   24:             "lprOneSided_command *= *"
   25:             { set onesided [lindex $aline end] }
   26:             "lprTwoSided_command *= *"
   27:             { set twosided [lindex $aline end] }
   28:         }                                              
   29:     }
   30:     if { [string first \$PS_file $onesided] == -1 } {
   31: 	set onesided "$onesided \$PS_file"
   32:     }
   33: 
   34:     if { [string first \$PS_file $twosided] == -1 } {
   35: 	set twosided "$twosided \$PS_file"
   36:     }
   37: }
   38: 
   39: proc parsesection { sec set } {
   40:     if { [ catch { exec echo [pwd] | qzparse -sec $sec \
   41: 	    -set $set >&@ file1 } ] } {
   42: 	puts "Error occured while parsing set: $set section: $sec"
   43: 	quit
   44:     }
   45: }
   46: 
   47: proc latexsection { sec set } { 
   48:     if { [ catch { cd TeX } ] } {
   49: 	puts "Unable to find [pwd]/TeX"
   50: 	quit
   51:     }
   52: 
   53:     if { [ catch { exec latex section$sec-set$set < /dev/null >&@ file1 } ] } {
   54: 	puts "Error occured while latexing set: $set section: $sec"
   55: 	quit
   56:     }
   57:     cd ..
   58: }
   59: 
   60: proc dvisection { sec set } {
   61:     if { [ catch { cd TeX } ] } {
   62: 	puts "Unable to find [pwd]/TeX"
   63: 	quit
   64:     }
   65:     
   66:     if { [ catch { exec dvips -o section$sec-set$set.ps \
   67: 	    section$sec-set$set.dvi < /dev/null >&@ file1 } ] } {
   68: 	puts "Error occured while creating dvi, set: $set section: $sec"
   69: 	quit
   70:     }
   71:     cd ..
   72: }
   73: 
   74: proc printonesided { sec set Printer_selected } {
   75:     global onesided
   76:     if { [ catch { cd TeX } ] } {
   77: 	puts "Unable to find [pwd]/TeX"
   78: 	quit
   79:     }
   80:     set PS_file section$sec-set$set.ps
   81:     if { [ catch { eval "exec $onesided < /dev/null >&@ file1" } ] } {
   82: 	puts "Error occured while printing set: $set section: $sec"
   83: 	quit
   84:     }
   85:     cd ..
   86: }
   87: 
   88: proc printtwosided { sec set Printer_selected } {
   89:     if { [ catch { cd TeX } ] } {
   90: 	puts "Unable to find [pwd]/TeX"
   91: 	quit
   92:     }
   93:     set PS_file section$sec-set$set.ps
   94:     if { [ catch { eval "exec $twosided < /dev/null >&@file1" } ] } {
   95: 	puts "Error occured while printing set: $set section: $sec"
   96: 	quit
   97:     }
   98:     cd ..
   99: }
  100: 
  101: proc cleanup { sec set { some 0 } } {
  102:     set ext "dvi log aux ps tex"
  103:     if { $some } { set ext "dvi log aux" }
  104:     foreach ext { tex dvi ps log aux } {
  105: 	exec rm -f TeX/section$sec-set$set.$ext
  106:     }
  107: }
  108: 
  109: if { $argc == 6 } {
  110:     set pathname [lindex $argv 0]
  111:     set startsection [lindex $argv 1]
  112:     set endsection [lindex $argv 2]
  113:     set setnumber [lindex $argv 3]
  114:     set sided [lindex $argv 4]
  115:     set printqueue [lindex $argv 5]
  116:     puts "Running class $pathname for sections $startsection:$endsection for set $setnumber on printer $printqueue, printing $sided side(s)"
  117: } else {
  118:     if { $argc != 0 } {
  119: 	puts "Usage is $argv0 pathname startsection endsection setnumber #sides printqueue"
  120: 	puts "       Specifying 0 sides will leave the postscript files behind and not print"
  121:     }
  122:     while { 1 } {
  123: 	puts "Enter the ABSOLUTE pathname of the class:"
  124: 	gets file0 pathname
  125: 	puts "Enter start section:"
  126: 	gets file0 startsection
  127: 	puts "Enter end section:"
  128: 	gets file0 endsection
  129: 	puts "Enter set:"
  130: 	gets file0 setnumber
  131: 	puts "One sided or two sided: (1 or 2)"
  132: 	gets file0 sided
  133: 	if { $sided != 0 } {
  134: 	    puts "Enter the name of the printer:"
  135: 	    gets file0 printqueue
  136: 	    puts "Run class $pathname for sections $startsection:$endsection for set $setnumber on printer $printqueue, printing $sided side(s)? (y or n)"
  137: 	} else {
  138: 	    puts "Run class $pathname for sections $startsection:$endsection for set $setnumber with no printing? (y or n)"
  139:         }
  140: 	if { "y" == [string range [string trimleft [gets file0] ] 0 0 ] } {
  141: 	    break
  142: 	}
  143:     }
  144: }
  145: set dir [pwd]
  146: 
  147: if { [ catch { cd $pathname } ] } {
  148:     puts "Invalid class $pathname"
  149:     quit
  150: }
  151: 
  152: set onesided "lpr -P\$Printer_selected"
  153: set twosided "lpspr -K2 \$PS_file | lpr -P\$Printer_selected"
  154: parseCapaConfig
  155: 
  156: if { $endsection == 0 } {
  157:     set endsection $startsection
  158: }
  159: 
  160: 
  161: for { set i $startsection } { $i <= $endsection } { incr i } {
  162:     parsesection $i $setnumber
  163:     latexsection $i $setnumber
  164:     dvisection $i $setnumber
  165:     if { $sided == 1 } {
  166: 	printonesided $i $setnumber $printqueue
  167:     } elseif { $sided == 2 }  {
  168: 	printonesided $i $setnumber $printqueue
  169:     }
  170:     if { $sided != 0 } { cleanup $i $setnumber
  171:     } else { cleanup $i $setnumber 1 
  172:     }
  173: }
  174: 
  175: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>