⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mat2html

📁 著名的seismiclab的代码 是地震学研究人员必备的工具
💻
📖 第 1 页 / 共 2 页
字号:
#!/usr/local/bin/perl$URL = "http://www.nd.edu/Courses/kantor/matlab/mat2html";# READ THE HELP SECTION BELOW FOR INFORMATION ON HOW TO USE THIS SCRIPT.## To install, simply save this function at mat2html, and make it # executible with##     chmod +x mat2html## This requires a perl interpreter and access to the standard perl# library. Do not contact me about installing perl, I will ignore# you. Instead, please check out the following standard sites:##    ftp.uu.net                      gnu/perl*#    jpl-decvax.jpl.nasa.gov         pub/perl*#    archive.cis.ohio-state.edu      perl/###                13 Jan 1995: Fixed a bug in tracking cross-#                             references, and other refinements.# Version 1.0 -> 12 Jan 1995: Major workover to allow index of#                             multiple matlab directories.#                10 Jan 1995: Added cross-links to the help text#                 9 Jan 1995: Looks for a Readme.m file to put#                             to put in the directory index.#                 9 Jan 1995: Fixed html cross-links## First posted to comp.soft-sys.matlab on January 9, 1995# Jeffrey C. Kantor# kantor.1@nd.edu# Copyright (c) Jeffrey C. Kantor 1995.# All rights reserved## Please feel free to use this script under the conditions of the# standard GNU public license.########################################################################  Subroutines######################################################################## From the standard Perl Libraryrequire 'getopts.pl';require 'ctime.pl';# Translate special html characterssub htmlchar {  s/&/&amp;/g;  s/\</&lt;/g;  s/\>/&gt;/g;  s/\"/&quot;/g;}# Write an html anchor, and keep track of how many have been# written using the global variable $anchor_count$anchor_count = 0;sub anchor_url{  local($url,$name) = @_;  $anchor_count++;  return("<A HREF = \"$url\">$name<\/A>");}# A standard tagline is added to each page created.# The total page count is kept in $page_count$page_count = 0;sub tagline {  $page_count++;  print HFILE "Produced by ",&anchor_url($URL,'mat2html')," on $date<BR>\n";  print HFILE "Cross-Directory links are: ";  if ($opt_g) {print HFILE "ON<BR>\n"} else {print HFILE "OFF<BR>\n"};}# Assume MFILE and HFILE are open, $headline contains a section# title, and @zref contains cross-reference namessub writehelpblock {  do {$_ = <MFILE>} until /^\s*%/ || eof;  if (!eof) {    print HFILE "<HR><H3>$headline</H3>\n";    print HFILE "<pre>\n";    while (/^\s*%/) {      s/^\s*%//;      &htmlchar;      foreach $z (@zref) {        next if /<A.*$z.*A>/;        $html = "../$hdir{$mdir{$mfile{$z}}}/$z.html";        s/(\W+)($z)(\W+)/$1.&anchor_url($html,$2).$3/eig;      }      print HFILE $_;      $_ = <MFILE>;    }    print HFILE "</pre>\n";  }}########################################################################  Command line processing######################################################################## Get the current date string$date = &ctime(time);# Read the command line arguments&Getopts('ghipqH:M:');warn("WARNING: Options -M and -p are incompatable.\n") if ($opt_M && $opt_p);if (($opt_h) || ($opt_M && $opt_p)) {  print <<EOF;Usage:  mat2html [-i] [-q] [-g] [-M matlab_dir] [-H html_dir]  mat2html [-i] [-q] [-g] [-p] [-H html_dir]mat2html reads a list of matlab .m files and/or directories from thestandard input to produce a hypertext documentation suitable forbrowsing with a WWW browser such as Mosaic or Netscape.  An filehtml_dir/index.html in written. Subdirectories are written for matlabdirectory that is encountered containing.html files corresponding to every .m file.Help:  -h   Print this help message and exit.  -q   Quiet operation. Default is verbose.Output Options:  -H  Specify a directory to place the html files and subdirectories.      The default is the current directory. If necessary, an attempt      is made to create the directory. The file index.html is placed      in this directory.  -i  Include matlab source code in the html documentation  -g  Do global hypertext links, that is, hypertext links among      separate matlab directories. Default is to do hypertext      links only among functions in the same directory.Matlab Source Options:      The standard input is looked at first. If there is nothing there,      then we look in the current directory for .m files as if we did a      -M . option.  -M  Specify a root matlab directory to search. The standard input      is not read.  -p  Search the matlab path obtained by matlab -n. Options -M      and -p are incompatable.Typical usages are:  mat2html       Produces a file index.html in the current directory, and a       .html file corresponding to each .m file in the current directory.      An index.html file is produced in the current directory.  mat2html -M matlab -H html      Same as above, except it looks in subdirectory matlab of      the current directory for the .m files, and puts the results      in subdirectory html. Useful for separating the .m files      from the documentation.  mat2html -p -H html      Creates documentation for everything on the default matlab      path, and puts it into a directory html.  ls *.m | mat2html -H html      Index the .m files in the current directory  find . -name "*.m" -print | mat2html -H html -i      The find command recursively builds a list of all .m files      to be found the directory and its subdirectories. These      are then processed and the html files put in the directory      html. The matlab source code is included in the html files.EOF  exit;}# Read arguments and initializeif ($opt_H) {$hroot = $opt_H} else {$hroot = "."};if ($opt_q) {$verbose = 0} else {$verbose = 1};########################################################################  Reading the input######################################################################## Get the list of files and directories to examine, put in @xfiles# Start by checking the standard input.undef(@xfiles);if (!-t) {  # STDIN is connected to some input  print "Reading from the standard input\n" if $verbose;  warn("Reading from STDIN, ignoring redundant -M option.\n") if ($opt_M);  while (<>) {    chop;    @files = split;    @xfiles = (@xfiles,@files);  }} elsif ($opt_p) {  # Get the matlab path  print "Running matlab -n to get the matlab path.\n" if $verbose;  open(MATLAB,"matlab -n|") || die("Can't run matlab -n to get the path");  do {$_ = <MATLAB>} until /MATLABPATH/ || eof;  while (<MATLAB>) {    last if /^----/;    chop;    s/\s*//g;    push(@xfiles,$_);  }  close(MATLAB);} elsif ($opt_M) {  # We need to find the matlab directories to search  print "Setting matlab directory to $opt_M\n" if $verbose;  if (-d $opt_M) {    @xfiles = ($opt_M);  } else {    die("Specified -M $opt_M is not a directory\n");  }} else {  print "Setting matlab directory to the current directory.\n" if $verbose;  @xfiles = (".");}# Now process the list of @xfiles to get a list of .m files @mfilesprint "Finding .m files in the search path.\n" if $verbose;undef(@mfiles);foreach (@xfiles) {  # chop off any trailing separators, sometimes added by ls  s/\/$//;  # Add to mfiles if it exits and text file with a .m suffix  if ((/\.m$/) && (-e) && (-T)) {    push(@mfiles,$_);    next;  }  # If it's a directory, then read it  if (-d) {    opendir(MDIR,$_) || die("Cannot open directory $_\n");    @files = grep(/\.m$/,readdir(MDIR));    foreach $file (@files) {      push(@mfiles,"$_/$file");    }  }}$n = $#mfiles + 1;print "Found $n .m files.\n" if $verbose;undef($n);undef(@xfiles);undef($mroot);########################################################################  Parse the matlab file names######################################################################## Now we need to parse the mfile names to obtain for each file#  $name{$file} - a matlab identifier used to search the texts#  $mdir{$file} - the directory in which the file is foundprint "Parsing the matlab file names.\n" if $verbose;undef(%mdir);foreach (@mfiles) {  local($x) = $_;  $x =~ s/\.m$//;  split("/",$x);  $name{$_} = pop(@_);  $mdir{$_} = join('/',@_);  $mdir{$_} = "." if $mdir{$_} eq "";}# Compute a unique list of matlab identifier names, put in @names.grep($count{$_}++,values(%name));@names = sort(keys(%count));undef(%count);$n = $#names + 1;print "Found $n unique matlab identifiers.\n" if $verbose;undef($n);# Now we have a problem. Each matlab name may be associated with more# than one .m file. The order of @mfiles is the order they would be# encountered in a standard matlab search, so we preserve that order.# We compute:## $mfile{$name}  - look up the first mfile associated with a $name## Confused yet?print "Linking each matlab identifier to a unique .m file.\n" if $verbose;foreach $n (@names) {  foreach (@mfiles) {    $file = $_;    last if ($n eq $name{$_});  }  $mfile{$n} = $file;}# Compute the set of unique matlab directory names, put in @mdirsgrep($count{$_}++,values(%mdir));@mdirs = sort(keys(%count));undef(%count);$n = $#mdirs + 1;print "Found $n unique matlab directories in the search path.\n" if $verbose;undef($n);########################################################################  Read the m-files, and compute cross-reference information######################################################################## Read each file and tabulate the distinct alphanumeric identifiers in# an array of symbols. This is used to compute cross references within# a matlab directory. Also scan for:##   synposis  - The function declaration line#   lookfor   - The first line of the help text#   mtype     - File type, either "function" or "script"#   cref,href - Arrays o cross references## Dependency matrix value $cref{$x,$y} is 1 if $x refers to $y in the# code section. $href{$x,$y} is 1 if $x refers to $y in the help# lines.  print "Read and compute cross-references among the .m files.\n" if $verbose;foreach $file (@mfiles) {  open(MFILE,"<$file") || die("Cannot open $file\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -