📄 gentex.pl
字号:
# get the current direcotry, and move two directories down.# $dirname = ".";# opendir(DIR, $dirname) or die "can't opendir $dirname: $!";# while (defined($file = readdir(DIR))) { # Only files that end with .c or .h are interesting, # and directories (we recurse through them). # do something with "$dirname/$file"# }# closedir(DIR); sub RemoveTrailingSpace{ $str = shift; while( substr( $str, -1 ) eq " " or substr($str, -1) eq "\n" or substr( $str, -1 ) eq "\r" ) { $str = substr( $str, 0, length($str)-1 ); } return( $str );}sub RemoveWhitespace{ $str = shift; while( substr( $str, 0, 1 ) eq " " ) { $str = substr( $str, 1, length($str)-1 ); } while( substr( $str, -1 ) eq " " or substr($str, -1) eq "\n" or substr( $str, -1 ) eq "\r" ) { $str = substr( $str, 0, length($str)-1 ); } return( $str );}use File::Find;# Find all .c and .h files in ../.., and find the tags# in those files. Store them in %hash.find( sub { # Process only .c and .h files. $File::Find::name, -d && '/' ; # Grab last two chars of filename. Must be .c or .h $ext = substr( $File::Find::name, -2 ); if( ( $ext eq ".h" or $ext eq ".c" or $ext eq ".l" or $ext eq ".b") and $_ ne "lexer.c" ) { $name = $_; # Open each file and search for tags. open( SOURCE, $name ) or die "Could not open $name: $!"; while( defined( $line = <SOURCE> ) ) { # Check each line for a tag. if( $line =~ /( )*\/\*![_A-Za-z]+\*\// ) { $line = RemoveWhitespace $line; $tag = substr( $line, 3, length( $line ) - 5 ); $hash{ $tag } = $File::Find::name; } } close( SOURCE ); } }, "../.." ); # For each TeX file in the current directory (.)opendir(DIR, ".") or die "can't opendir .: $!";while (defined($file = readdir(DIR))) { # Filter out non-TeX files $ext = substr( $file, -4 ); if( $ext eq ".otx" ) { print "Processing $file\n"; # output file = input file - .otx + .tex $output = substr( $file, 0, length( $file ) - 4 ); $output = $output . ".tex"; # For each otx file, scan for tags open( TEX, $file ) or die "Could not open $file: $!"; open( OUTPUT, "> $output" ) or die "Could not open $output for writing: $!"; while( defined( $line = <TEX> ) ) { if( $line =~ /%![A-Za-z]+/ ) { # find TAG in hash, die if not found. $line = RemoveWhitespace $line; $tag = substr( $line, 2, length( $line ) - 2 ); print "* tag: $tag\n"; if( $hash{ $tag } eq undef ) { print "WARNING: Tag $tag undefined!"; } else { # START LATEX CODE print OUTPUT "\\begin{quote}\n\\begin{verbatim}\n"; # open source C file, and find tag. open( SOURCE, $hash{ $tag } ) or die "Could not open $hash{ $tag } for reading: $!"; $copy = 0; while( defined( $line = <SOURCE> ) ) { $wline = RemoveWhitespace $line; if( $wline eq "\/\*!$tag\*\/" ) { $copy = 1; } elsif( $wline eq "\/\*!\*\/" ) { $copy = 0; } else { if( $copy == 1 ) { $line = RemoveTrailingSpace $line; print OUTPUT $line; print OUTPUT "\n"; } } } close( SOURCE ); # END LATEX CODE print OUTPUT "\\end{verbatim}\n\\end{quote}\n"; } } else { print OUTPUT $line; } } close( OUTPUT ); close( TEX ); } }closedir(DIR);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -