#!/usr/bin/sh #c2html.cgi #\ exec /opt/csw/bin/tclsh "$0" ${1+"$@"} #2>/home/pdv/musial/www/cgilog # Defaultwerte (aenderbar) set IndexFile {/home/pdv/pdv/www/lehre/mxBrowser/mxIndex.tcl} ;# Datei mit den Indexdaten set CachePath {/home/pdv/pdv/www/lehre/mxBrowser/cache} ;# Pfad mit den gecachten Files set DefPath {/home/pdv/info4/minmax99/src} ;# Pfad mit den C und H Files set DefLink {http://pdv.cs.tu-berlin.de/lehre/mxBrowser/c2html.cgi} ;# URL, ueber die das ganze laeuft set LogoPath {http://pdv.cs.tu-berlin.de/lehre/mxBrowser/mx-small.jpg} ;# URL mit dem MinMax-Logo set SourceName {Browser für die MinMax99-Quellen} ;# Begruessungszeile set BackLink {http://pdv.cs.tu-berlin.de/MinMax/index.html} ;# zurueck set ErrorTitle {Shit! Geht nicht} ;# Titelzeile fuer Fehlermeldung set ErrorString {Tja, da ist wohl was schiefgegangen!} ;# Fehlermeldung set AsmExt {.S} ;# Extension von Asm-Files set CExt {.c} ;# Extension von C-Files set HExt {.h} ;# Extension von H-Files set cText {"#000000"} ;# normale Textfarbe set cBack {"#FFFFFF"} ;# Hintergrundfarbe set cString {"#008A00"} ;# Farbe fuer Strings set cLink {"#AF00AF"} ;# Farbe fuer Links set cBKeyW {"#CFAF00"} ;# Farbe fuer Schluesselwoerter (Befehle) set cPKeyW {"#1A00FF"} ;# Farbe fuer Schluesselwoerter (Precompiler) set cVKeyW {"#5F005F"} ;# Farbe fuer Schluesselwoerter (Variablen) set cFKeyW {"#006800"} ;# Farbe fuer erkannte Funktionsnamen set cCase {"#FF00AF"} ;# Farbe fuer CASE-Bedingung u. a. set cComment {"#FF0000"} ;# Farbe fuer Kommentare # Defaulwerte (Finger wech!) set BottomLine {


Bei Problemen mit der Seite bitte eine Mail an Marek
Converted with C2HTML V0.669 by Iluvatar
Prozeßdatenverarbeitung
} ;# Finger wech :-) set IncFile {[0-9a-zA-Z_./][0-9a-zA-Z_./]*} ;# Includefile set CName {[a-zA-Z_][0-9a-zA-Z_.-]*} ;# Zulaessige Namen in C set Case {[']?[0-9a-zA-Z_][0-9a-zA-Z_.-]*[']?} ;# Zulaessig im Case-Statement set MName {[a-zA-Z_][0-9a-zA-Z_.()]*} ;# Name eines Macros set FName {[a-zA-Z_][0-9a-zA-Z_.]*} ;# Name einer Funktion in C set All {.*} ;# Alles was wie wo gehen tut :-) set Spaces "\[ \t\]+" ;# Was an Spaces so drinne ist set FPrefix {[ *]} ;# Zeichen, die direkt vor einem Proto. stehen set I {[^a-zA-Z0-9_#]} ;# Rand innen set A "$I|^|\$" ;# Rand außen set Inoqu {[^a-zA-Z0-9_#\"]} ;# Rand innen ohne " set Anoqu "$Inoqu|^|\$" ;# Rand außen ohne " set Ires {[^a-zA-Z0-9_]} ;# Rand innen anspruchsvoll set Ares "$Ires|^|\$" ;# Rand aussen anspruchsvoll # Datei einbinden if {![file exists $IndexFile]} { set index(0) "" } else { catch {source $IndexFile} } # Hilfsroutinen proc Cgi_Parse {} { global env cgi query if {![info exists env(QUERY_STRING)] || [string length $env(QUERY_STRING)] == 0} { if [info exists env(CONTENT_LENGTH)] { set query [read stdin $env(CONTENT_LENGTH)] } else { gets stdin query } } else { set query $env(QUERY_STRING) } regsub -all {\+} $query { } query foreach {name value} [split $query &=] { if [info exists list($name)] { set cgi($name) [list $cgi($name) [CgiDecode $value]] unset list($name) } elseif [info exists cgi($name)] { lappend cgi($name) [CgiDecode $value] } else { set cgi($name) [CgiDecode $value] set list($name) 1 } } return [array names cgi] } proc Cgi_Value {name} { global cgi if ![info exists cgi($name)] { return {} } elseif {[llength $cgi($name)] == 1} { return [lindex $cgi($name) 0] } else { return $cgi($name) } } proc CgiDecode {str} { regsub -all {[][\\\$]} $str {\\&} str regsub -all {%([0-9a-fA-F][0-9a-fA-F])} $str {[format %c 0x\1]} str return [subst $str] } # Die eigendliche Arbeit proc MakeIndex {c path} { global BottomLine cText cBack cLink DefLink SourceName Mindex Pindex Tindex LogoPath BackLink # HTML-Seite beginnen puts $c "" puts $c "" puts $c "" puts $c "" puts $c "HTML-Version von MinMax99 -=\> Liste \<=-" puts $c "" puts $c "" # Ueberschrift puts $c "" puts $c "" puts $c "" puts $c "" puts $c "

$SourceName

" puts $c "

" # Liste der Suchbegriffe puts $c "
" ;# Eine Form definieren puts $c "" ;# Tabelle aufmachen puts $c "" ;# Zeile aufmachen puts $c "" puts $c "" puts $c "" puts $c "" puts $c "" ;# Zeile aufmachen puts $c "" ;# Zelle zumachen puts $c "" ;# Zelle zumachen puts $c "" ;# Zelle zumachen puts $c "" ;# Zeile zumachen puts $c "
Liste der Define's:Liste der Prototypen:Liste der Typedef's:
" ;# Table abschliessen puts $c "
" puts $c "" ;# Submit-Button erzeugen puts $c "
" puts $c "
" ;# Form zumachen puts $c "

" # Liste der Dateien puts $c "
" ;# Tabelle aufmachen puts $c "" ;# Zeile aufmachen puts $c "" puts $c "" puts $c "" puts $c "" puts $c "" ;# Zeile aufmachen puts $c "" puts $c "" ;# Zeile zumachen puts $c "
Header-Files:C-Files:
" foreach f [lsort -dictionary [exec /bin/ls -a1Lb $path]] { if {[file extension $f] == {.h}} { puts $c "$f
" } } puts $c "
" foreach f [lsort -dictionary [exec /bin/ls -a1Lb $path]] { if {[file extension $f] == {.c} || [file extension $f] == {.S}} { puts $c "$f
" } } puts $c "
" ;# Table abschliessen # Seite abschliessen puts $c "$BottomLine" puts $c "" puts $c "" } proc RecurseLine {line infile} { global c I A Inoqu Anoqu All CName Spaces MName DefLink incfile cFKeyW Case HExt CExt AsmExt FName global cString cBKeyW cPKeyW cVKeyW cCase cComment Pindex FPrefix Sindex Tindex Mindex assembler enum typedef if [regexp "($All)/\\*($All)\\*/($All)" $line match first string end] { # den Kommentar einfaerben set line "[RecurseLine $first $infile]/\*$string\*/[RecurseLine $end $infile]" } elseif [regexp "($All)\"($All)\"($All)" $line match first string end] { # den String einfaerben set line "[RecurseLine $first $infile]\"$string\"[RecurseLine $end $infile]" } else { # Befehls-Schluesselwoerter einfaerben regsub -all "($I)if($A)" $line "\\1if\\2" line ;# if regsub -all "($I)do($A)" $line "\\1do\\2" line ;# do regsub -all "($I)for($A)" $line "\\1for\\2" line ;# for regsub -all "($I)while($A)" $line "\\1while\\2" line ;# while regsub -all "($I)switch($A)" $line "\\1switch\\2" line ;# switch regsub -all "($I)else($A)" $line "\\1else\\2" line ;# else regsub -all "($I)exit($A)" $line "\\1exit\\2" line ;# exit regsub -all "($I)return($A)" $line "\\1return\\2" line ;# return regsub -all "($I)sizeof($A)" $line "\\1sizeof\\2" line ;# sizeof regsub -all "($I)break($A)" $line "\\1break\\2" line ;# break regsub -all "($I)continue($A)" $line "\\1continue\\2" line ;# continue regsub -all "($I)default($A)" $line "\\1default\\2" line ;# default regsub -all "($I)goto($A)" $line "\\1goto\\2" line ;# goto regsub -all "($I)case($Spaces)($Case):($A)" $line "\\1case\\2\\3:\\4" line ;# case # defines if [regexp "#define($Spaces)($MName)($Spaces)?($All)?" $line match space1 name space2 define] { set line "#define$space1$name$space2$define" } # typedef's if [regexp "typedef($Spaces)(struct|union|enum)($Spaces)($MName)($Spaces)\{($All)?" $line match space0 type space1 name space2 all] { set line "typedef$space0$type$space1$name$space2\{$all" } if [regexp "typedef($Spaces)(struct|union|enum)($All)\{($All)?" $line match space1 type space2 all] { set line "typedef$space1$type$space2\{$all" set typedef 1 } if [regexp "typedef($Spaces)($MName)($Spaces)?\$" $line match space1 orig space2] { set line "typedef$space1$orig$space2" set typedef 2 } if {$typedef == 1} { if [regexp "($All)\}($Spaces)($MName);($All)?" $line match all1 space name all2] { set line "$all1\}$space$name;$all2" set typedef 0 } } if {$typedef == 2} { if [regexp "($Spaces)?($MName)($All);($All)?" $line match space1 name all1 all2] { set line "$space1$name$all1;$all2" set typedef 0 } } if [regexp "typedef($Spaces)($MName)($Spaces)($MName)($All);($All)?" $line match space1 orig space2 name all all2] { set line "typedef$space1$orig$space2$name$all;$all2" } # if(n)def, endif, else regsub -all "#if($Spaces)($Case)" $line "#if\\1\\2" line regsub -all "#ifndef($Spaces)($CName)" $line "#ifndef\\1\\2" line regsub -all "#ifdef($Spaces)($CName)" $line "#ifdef\\1\\2" line regsub -all "#endif" $line "#endif" line regsub -all "#else" $line "#else" line # Typenbezeichner regsub -all "char($A)" $line "char\\1" line ;# char regsub -all "int($A)" $line "int\\1" line ;# int regsub -all "long($A)" $line "long\\1" line ;# long regsub -all "float($A)" $line "float\\1" line ;# float regsub -all "double($A)" $line "double\\1" line ;# double regsub -all "unsigned($A)" $line "unsigned\\1" line ;# unsigned regsub -all "void($A)" $line "void\\1" line ;# void regsub -all "static($A)" $line "static\\1" line ;# static regsub -all "const($A)" $line "const\\1" line ;# const regsub -all "extern($A)" $line "extern\\1" line ;# extern regsub -all "enum($A)" $line "enum\\1" line ;# enum regsub -all "entry($A)" $line "entry\\1" line ;# entry regsub -all "register($A)" $line "register\\1" line ;# register regsub -all "struct($A)" $line "struct\\1" line ;# struct regsub -all "short($A)" $line "short\\1" line ;# short regsub -all "auto($A)" $line "auto\\1" line ;# auto regsub -all "union($A)" $line "union\\1" line ;# union # Zuletzt noch die Funktionsprototypen einfaerben: .h -> .S/.c if $incfile { if [regexp "($All)($FPrefix)($FName)($Spaces)?\\(($All)(\\);|,)($All)" $line match all1 prefix name space1 all2 end all3] { if {[array get Sindex $name] != ""} { set line "$all1$prefix$name${space1}($all2$end$all3" } elseif {[array get Pindex $name] != ""} { set line "$all1$prefix$name${space1}($all2$end$all3" } } } # bekannte Funktionen und bekannte definierte Typen und bekannte Makros verlinken! regsub -all "$I+" $line " " tokens foreach key [split $tokens] { if {$key == ""} continue ;# leeres Element if [regexp "NAME=\"$key\">" $line] continue ;# hier definiert # Typen if {[array get Tindex $key] != ""} { regsub -all "($A)${key}($I)" $line "\\1$key\\2" line continue } # Makros if {[array get Mindex $key] != ""} { regsub -all "($A)${key}($I)" $line "\\1$key\\2" line continue } if $incfile continue # Funktionen: nur .c -> .h if {[array get Pindex $key] != ""} { regsub "(|)($Spaces)?($FPrefix)($FName)($Spaces)?\\(" $line "\\1\\2\\3\\4\\5(" line regsub -all "($Anoqu)${key}($Inoqu)" $line "\\1$key\\2" line continue } } # Anderer Kram regsub -all "(\[^\"a-zA-Z0-9_\#\])NULL($A)" $line "\\1NULL\\2" line ;# NULL regsub -all "(\[^\"a-zA-Z0-9_\#\])TRUE($A)" $line "\\1TRUE\\2" line ;# TRUE regsub -all "(\[^\"a-zA-Z0-9_\#\])FALSE($A)" $line "\\1FALSE\\2" line ;# FALSE } return $line } proc Convert {c infile} { global cText cBack cLink cPKeyW cFKeyW cVKeyW BottomLine DefPath I A Ires Ares Pindex Mindex Spaces FName All incfile enum typedef global IncFile cComment DefLink ErrorTitle ErrorString LogoPath assembler # Datei oeffnen, wenn Fehler einen solchen ausgeben if [catch {open [file join $DefPath $infile] r} m] { # HTML-Seite beginnen puts $c "" puts $c "" puts $c "" puts $c "" puts $c "$ErrorTitle" puts $c "" puts $c "" puts $c "

$ErrorString

" puts $c "

" puts $c "$m
" puts $c "$BottomLine" puts $c "" puts $c "" close $c return 1 } # HTML-Seite beginnen puts $c "" puts $c "" puts $c "" puts $c "" puts $c "HTML-Version von MinMax99 -=\> $infile \<=-" puts $c "" puts $c "" puts $c "" puts $c "" puts $c "" puts $c "

$infile

" puts $c "

" puts $c "
"

    # Inits
    if {[file extension $infile] == {.h}} {
	set incfile 1					;# Wir haben ein Includefile
	set assembler 0
    } elseif {[file extension $infile] == {.S}} {
	set incfile 0					;# Wir haben ein Asm-File
	set assembler 1
    } else {
	set incfile 0					;# Wir haben ein C-File
	set assembler 0
    }
    set code     1
    set finished 0

    set typedef 0
    set enum 0

    # Convertieren
    for {} {[gets $m line] >= 0} {if {$line != "-"} {puts $c "$line"}} {
	set finished 0

	# zurechtschneiden
	set line [string trimright $line]

	# Geschweifte Klammern weg
	regsub -all {\{} $line {\{} line
	regsub -all {\}} $line {\}} line

	# Eckige Klammern weg
	regsub -all {\[} $line {\[} line
        regsub -all {\]} $line {\]} line

	# Includedirektiven machen und spitze Klammern aufraeumen
	if [regexp "#include($Spaces)\<($IncFile)\>" $line match space ifile] {
	    set line "#include$space\<$ifile\>"
	    set finished 1
	} elseif [regexp "#include($Spaces)\"($IncFile)\"" $line match space ifile] {
            regsub -all {\<} $line {\<} line
            regsub -all {\>} $line {\>} line
	    set line "#include$space\"$ifile\""
	    set finished 1
	} else {
            regsub -all {\<} $line {\<} line
            regsub -all {\>} $line {\>} line
	}

	# Auf Assembler testen
	if $assembler {
	    if [regsub ".GLOBAL($Spaces)_($FName)($All)" $line ".GLOBAL\\1_\\2\\3" line] continue
	    # bekannte Funktionen und bekannte definierte Typen und bekannte Makros verlinken!
	    regsub -all "$Ires+" $line   " " tokens
	    regsub -all "( |^)_" $tokens "\\1" tokens
	    foreach key [split $tokens] {
		if {$key == ""}                    continue    ;# leeres Element
		if [regexp "\#$key\">" $line]      continue    ;# hier schon verlinkt
		# Makros
		if {[array get Mindex $key] != ""} {
		    regsub -all "($Ires)${key}($Ares)" $line "\\1$key\\2" line
		    continue
		}
		# Funktionen: nur .S -> .h
		if {[array get Pindex $key] != ""} {
		    regsub -all "($Ares)_${key}($Ares)" $line "\\1_$key\\2" line
		    continue
		}
	    }
	    continue
	}

	# Mehrzeilige Kommentare behandeln
	if {[regexp "/\\*($All)\\*/" $line match bla] == {0}} {
	    if [regsub -all {/\*} $line "/\*" line] {
		set code 0
		set finished 1
	    }
	    if [regsub -all {\*/} $line {*/} line] {
		set code 1
		set finished 1
	    }
	}

	# Zeile schon fertig -> nexte
	if $finished {
	    continue
	}

	# Normaler Code wird rekursiv geparst!
	if $code {
	    set line [RecurseLine $line $infile]
	}
    }

    # Seite abschliessen
    puts $c "
" puts $c "$BottomLine" puts $c "" puts $c "" # Dateien schliessen close $m close $c } # Dummy-Header proc ReferTo {url} { puts stdout "Content-Type: text/html\n" puts stdout "" puts stdout "" puts stdout "" puts stdout "" } # Hauptprogramm Cgi_Parse if {[Cgi_Value file] != ""} { set mxfile [file tail [Cgi_Value file]] if {![file exists $CachePath/$mxfile] || ([file exists $DefPath/$mxfile] && [file mtime $CachePath/$mxfile] <= [file mtime $DefPath/$mxfile])} { catch {exec rm -f $CachePath/$mxfile} set cache [open $CachePath/$mxfile w 0644] Convert $cache $mxfile } #puts stdout $query puts stdout "Content-Type: text/html\n" set cache [open $CachePath/$mxfile r] puts stdout [read $cache] } elseif {[Cgi_Value Msearch] != ""} { ReferTo "$DefLink?file=[file tail $Mindex([Cgi_Value Msearch])]\#[Cgi_Value Msearch]" } elseif {[Cgi_Value Psearch] != ""} { ReferTo "$DefLink?file=[file tail $Pindex([Cgi_Value Psearch])]\#[Cgi_Value Psearch]" } elseif {[Cgi_Value Tsearch] != ""} { ReferTo "$DefLink?file=[file tail $Tindex([Cgi_Value Tsearch])]\#[Cgi_Value Tsearch]" } else { puts stdout "Content-Type: text/html\n" MakeIndex stdout $DefPath }