From 72f72d64a422d6628c4796f5c0bf2e508f134214 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Wed, 4 May 2011 16:05:14 +0900 Subject: Adding upstream version 0.5.1 --- scripts/w3mman/.cvsignore | 5 + scripts/w3mman/Makefile.in | 96 +++++++++++++ scripts/w3mman/README | 54 ++++++++ scripts/w3mman/hlink.cgi | 97 ++++++++++++++ scripts/w3mman/w3mman.1.in | 53 ++++++++ scripts/w3mman/w3mman.in | 41 ++++++ scripts/w3mman/w3mman2html.cgi.in | 274 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 620 insertions(+) create mode 100644 scripts/w3mman/.cvsignore create mode 100644 scripts/w3mman/Makefile.in create mode 100644 scripts/w3mman/README create mode 100644 scripts/w3mman/hlink.cgi create mode 100644 scripts/w3mman/w3mman.1.in create mode 100644 scripts/w3mman/w3mman.in create mode 100644 scripts/w3mman/w3mman2html.cgi.in (limited to 'scripts/w3mman') diff --git a/scripts/w3mman/.cvsignore b/scripts/w3mman/.cvsignore new file mode 100644 index 0000000..e867c6e --- /dev/null +++ b/scripts/w3mman/.cvsignore @@ -0,0 +1,5 @@ +w3mman +w3mman2html.cgi +w3mman.1 + +Makefile diff --git a/scripts/w3mman/Makefile.in b/scripts/w3mman/Makefile.in new file mode 100644 index 0000000..ab941c5 --- /dev/null +++ b/scripts/w3mman/Makefile.in @@ -0,0 +1,96 @@ +@SET_MAKE@ +SHELL=@SHELL@ +PACKAGE = @PACKAGE@ +VERSION = @VERSION@ +DOMAIN = $(PACKAGE) +srcidr=@srcdir@ +top_srcdir=@top_srcdir@ +VPATH= $(srcdir):. +prefix = @prefix@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +datadir = @datadir@ +libdir = @libdir@ +includedir = @includedir@ +infodir = @infodir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +oldincludedir = @oldincludedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +top_srcdir = @top_srcdir@ +VPATH = $(top_srcdir):. +DESTDIR = + +CGIBIN_DIR = $(libexecdir)/$(PACKAGE)/cgi-bin +AUXBIN_DIR = $(libexecdir)/$(PACKAGE) +HELP_DIR = @HELP_DIR@ +RC_DIR = @RC_DIR@ +ETC_DIR = $(sysconfdir) +CONF_DIR = $(sysconfdir)/$(PACKAGE) +BIN_DIR = $(bindir) +MAN1_DIR = $(mandir)/man1 + +TARGETS = w3mman +CGIBIN_TARGETS = w3mman2html.cgi +MAN1_TARGETS = w3mman.1 +MAN_TARGETS = $(MAN1_TARGETS) + +MKDIR = mkdir -p +INSTALL = @INSTALL@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_MAN = @INSTALL_DATA@ + +all: $(TARGETS) $(CGIBIN_TARGETS) $(MAN_TARGETS) + +# do nothing +$(TARGETS) $(CGIBIN_TARGETS) $(MAN_TARGETS): + +install: $(TARGETS) $(CGIBIN_TARGETS) $(MAN_TARGETS) + -$(MKDIR) $(DESTDIR)$(BIN_DIR) + -$(MKDIR) $(DESTDIR)$(CGIBIN_DIR) + -$(MKDIR) $(DESTDIR)$(MAN1_DIR) + for file in $(TARGETS); \ + do \ + $(INSTALL_SCRIPT) $$file $(DESTDIR)$(BIN_DIR); \ + done + for file in $(CGIBIN_TARGETS); \ + do \ + $(INSTALL_SCRIPT) $$file $(DESTDIR)$(CGIBIN_DIR); \ + done + for file in $(MAN1_TARGETS); \ + do \ + $(INSTALL_MAN) $$file $(DESTDIR)$(MAN1_DIR); \ + done + +uninstall: + -for file in $(TARGETS); \ + do \ + rm -f $(BIN_DIR)/$$file; \ + done + -for file in $(CGIBIN_TARGETS); \ + do \ + rm -f $(CGIBIN_DIR)/$$file; \ + done + -for file in $(MAN1_TARGETS); \ + do \ + rm -f $(MAN1_DIR)/$$file; \ + done + +clean: + +distclean: + -rm -f $(TARGETS) $(CGIBIN_TARGETS) $(MAN_TARGETS) + -rm -f Makefile + +dist: all + @-rm -fr $(distdir)/w3mman + -$(MKDIR) $(distdir)/w3mman + cp Makefile README w3mman.in w3mman2html.cgi.in hlink.cgi w3mman.1.in $(distdir)/w3mman + ( cd $(distdir); tar -cf - w3mman | GZIP='' gzip ) \ + > $(distdir)/w3mman.tar.gz + -rm -fr $(distdir)/w3mman + diff --git a/scripts/w3mman/README b/scripts/w3mman/README new file mode 100644 index 0000000..3bcbb3b --- /dev/null +++ b/scripts/w3mman/README @@ -0,0 +1,54 @@ + +w3mman + + 他のマニュアルやヘッダファイルにリンクをはることができる + man コマンドの代替コマンドです。 + +使用法 + + w3mman + w3mman [(
)] + w3mman [
] + w3mman -k + +環境変数 + + W3MMAN_W3M + 使用する w3m コマンドを指定します(デフォルトは w3m) + W3MMAN_MAN + 使用する man コマンドを指定します(デフォルトは man) + +インストール + + make install + 必要なら PERL, MAN, LIBDIR を設定してください。 + w3mman2html.cgi もインストールされます。 + +================ + +w3mman2html.cgi + +使用法 + + w3m file:///$LIB/w3mman2html.cgi + w3m file:///$LIB/w3mman2html.cgi?[(
)] + w3m file:///$LIB/w3mman2html.cgi?man=[§ion=
] + w3m file:///$LIB/w3mman2html.cgi?keyword= + +インストール + + make install + 必要なら PERL, MAN, LIBDIR を設定してください。 + w3mman もインストールされます。 + +================ + +hlink.cgi + + ヘッダファイルなどにリンクを張る + +インストール + + /$LIB/ にコピー + w3mman2html.cgi で使用するならば $CGI2 に設定してください。 + diff --git a/scripts/w3mman/hlink.cgi b/scripts/w3mman/hlink.cgi new file mode 100644 index 0000000..a92ac1d --- /dev/null +++ b/scripts/w3mman/hlink.cgi @@ -0,0 +1,97 @@ +#!/usr/local/bin/perl + +$SCRIPT_NAME = $ENV{'SCRIPT_NAME'} || $0; +$CGI = "file://$SCRIPT_NAME?"; + +if ($ENV{'QUERY_STRING'}) { + $file = $ENV{'QUERY_STRING'}; +} else { + $file = $ARGV[0]; +} +$file = &cleanup($file); + +if (-d $file) { + print <$file +$_ +EOF + exit 1; +} + +$file = &html_quote($file); +($dir = $file) =~ s@[^/]*$@@; + +print <$file +
+EOF
+while () {
+  $_ = &html_quote($_);
+
+  s/^(\#\s*include\s+)(\".*\"|\<\;.*\>\;)/$1 . &header_ref($2)/ge;
+
+  print;
+}
+close(FILE);
+print "
\n"; + +sub header_ref { + local($_) = @_; + local($d); + + if (s/^\"//) { + s/\"$//; + return ""$_""; + } + s/^\<\;//; + s/\>\;$//; + + for $d ( + "/usr/include", + "/usr/local/include", + "/usr/X11R6/include", + "/usr/X11/include", + "/usr/X/include", + "/usr/include/X11" + ) { + -f "$d/$_" && return "<$_>"; + } + return $_; +} + + +sub html_quote { + local($_) = @_; + local(%QUOTE) = ( + '<', '<', + '>', '>', + '&', '&', + '"', '"', + ); + s/[<>&"]/$QUOTE{$&}/g; + return $_; +} + +sub cleanup { + local($_) = @_; + + s@//+@/@g; + s@/\./@/@g; + while(m@/\.\./@) { + s@^/(\.\./)+@/@; + s@/[^/]+/\.\./@/@; + } + return $_; +} diff --git a/scripts/w3mman/w3mman.1.in b/scripts/w3mman/w3mman.1.in new file mode 100644 index 0000000..eb30237 --- /dev/null +++ b/scripts/w3mman/w3mman.1.in @@ -0,0 +1,53 @@ +.TH W3MMAN 1 "Mar 14, 2002" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +w3mman \- an interface to the on-line reference manuals by w3m(1) +.SH SYNOPSIS +.B w3mman +.RI "[-M " path ] " " [ section ] " page" +.br +.B w3mman +.RI "[-M " path "] -k " keyword +.SH DESCRIPTION +.B w3mman +is the system's manual pager by +.BR w3m (1). +.SH OPTIONS +A summary of options is included below. +.TP +.BI \-M " path" +Specify +.I path +as MANPATH. +.TP +.B \-k " keyword" +Specify +.I keyword. +.SH ENVIRONMENT +.TP +.B W3MMAN_W3M +If W3MMAN_W3M is set, its value is used instead of @W3M@. +.TP +.B W3MMAN_MAN +If W3MMAN_MAN is set, its value is used instead of @MAN@. +.SH FILES +.TP +.I @libexecdir@/@PACKAGE@/cgi-bin/w3mman2html.cgi +convert manual page to html. +.SH SEE ALSO +.BR man (1), +.BR w3m (1). +.SH AUTHOR +This manual page was written by Fumitoshi UKAI , +for the Debian GNU/Linux system (but may be used by others). diff --git a/scripts/w3mman/w3mman.in b/scripts/w3mman/w3mman.in new file mode 100644 index 0000000..6c6f65d --- /dev/null +++ b/scripts/w3mman/w3mman.in @@ -0,0 +1,41 @@ +#!@PERL@ + +@W3M = split(' ', $ENV{'W3MMAN_W3M'} || '@W3M@'); +$ENV{'W3MMAN_MAN'} ||= '@MAN@'; +$SCRIPT = 'file:///$LIB/w3mman2html.cgi'; + +sub usage { + ($_ = $0) =~ s@.*/@@; + print STDERR "$_ [-M ] [[
] ]\n"; + print STDERR "$_ [-M ] [-k ]\n"; + exit 1; +} + +$query = ""; +while (@ARGV) { + $_ = shift @ARGV; + if (/^-M$/) { + @ARGV || &usage(); + $ENV{'MANPATH'} = shift @ARGV; + } elsif (/^-k$/) { + @ARGV || &usage(); + $query = "?keyword=" . &form_encode(shift @ARGV); + } elsif (/^-/) { + &usage(); + } elsif (/^\d/ || $_ eq 'n') { + @ARGV || &usage(); + $query = "?quit=ok&man=" . &form_encode(shift @ARGV); + $query .= "§ion=" . &form_encode($_); + } else { + $query = "?quit=ok&man=" . &form_encode($_); + } +} + +exec @W3M, "$SCRIPT$query"; + +sub form_encode { + local($_) = @_; + s/[\000-\040\+:#?&%<>"\177-\377]/sprintf('%%%02X', unpack('C', $&))/eg; + return $_; +} + diff --git a/scripts/w3mman/w3mman2html.cgi.in b/scripts/w3mman/w3mman2html.cgi.in new file mode 100644 index 0000000..f41d487 --- /dev/null +++ b/scripts/w3mman/w3mman2html.cgi.in @@ -0,0 +1,274 @@ +#!@PERL@ + +$MAN = $ENV{'W3MMAN_MAN'} || '@MAN@'; +$QUERY = $ENV{'QUERY_STRING'} || $ARGV[0]; +$SCRIPT_NAME = $ENV{'SCRIPT_NAME'} || $0; +$CGI = "file://$SCRIPT_NAME"; +$CGI2 = "file:"; +# $CGI2 = "file:///\$LIB/hlink.cgi?"; +$SQUEEZE = 1; +$ENV{'PAGER'} = 'cat'; + +if ($QUERY =~ /\=/) { + for (split('&', $QUERY)) { + ($v, $q) = split('=', $_, 2); + $query{$v} = &form_decode($q); + } +} else { + $QUERY =~ s/^man=//; + $query{"man"} = &form_decode($QUERY); +} + +if (! $query{"man"}) { + if ($query{"keyword"}) { + $keyword = $query{"keyword"}; + $k = &html_quote($keyword); + print < +man -k $k + +

man -k $k

+
    +EOF + $keyword =~ s:([^-\w\200-\377.,])::g; + open(F, "$MAN -k $keyword 2> /dev/null |"); + @line = (); + while() { + chop; + $_ = &html_quote($_); + s/(\s+-.*)$//; + $title = $1; + s@(\w[\w.\-]*(\s*\,\s*\w[\w.\-]*)*)\s*(\([\dn]\w*\))@&keyword_ref($1, $3)@ge; + print "
  • $_$title\n"; + } + close(F); + print < + + +EOF + exit; + } + print < +man + +
    + +
    Manual: +
    Section: +
    Keyword: +
    +
    +
    + + +EOF + exit; +} + +$man = $query{"man"}; +if ($man =~ s/\((\w+)\)$//) { + $section = $1; + $man_section = "$man($1)"; +} elsif ($query{"section"}) { + $section = $query{"section"}; + $man_section = "$man($section)"; +} else { + $section = ""; + $man_section = "$man"; +} + +$section =~ s:([^-\w\200-\377.,])::g; +$man =~ s:([^-\w\200-\377.,])::g; +open(F, "$MAN $section $man 2> /dev/null |"); +$ok = 0; +undef $header; +$blank = -1; +$cmd = ""; +$prev = ""; +while() { + if (! defined($header)) { + /^\s*$/ && next; + $header = $_; + $space = $header; + chop $space; + $space =~ s/\S.*//; + } elsif ($_ eq $header) { # delete header + $blank = -1; + next; + } elsif (!/\010/ && /^$space[\w\200-\377].*\s\S/o) { # delete footer + $blank = -1; + next; + } + if ($SQUEEZE) { + if (/^\s*$/) { + $blank || $blank++; + next; + } elsif ($blank) { + $blank > 0 && print "\n"; + $blank = 0; + } + } + + s/\&/\&/g; + s/\/\>/g; + + s@([\200-\377].)(\010{1,2}\1)+@$1@g; + s@(\&\w+;|.)(\010\1)+@$1@g; + s@__\010{1,2}((\)?[\200-\377].(\)?)@$1@g; + s@_\010((\)?(\&\w+\;|.)(\)?)@$1@g; + s@((\)?[\200-\377].(\)?)\010{1,2}__@$1@g; + s@((\)?(\&\w+\;|.)(\)?)\010_@$1@g; + s@.\010(.)@$1@g; + + s@\\\_\\\@_@g; + s@\\_\\@_@g; + s@\\@@g; + s@\\@@g; + + if (! $ok) { + /^No/ && last; + print < +man $man_section + +
    +EOF
    +    print;
    +    $ok = 1;
    +    next;
    +  }
    +
    +  s@(http|ftp)://[\w.\-/~]+[\w/]@$&@g;
    +  s@(\W)(mailto:)?(\w[\w.\-]*\@\w[\w.\-]*\.[\w.\-]*\w)@$1$2$3@g;
    +  s@(\W)(\~?/[\w.][\w.\-/~]*)@$1 . &file_ref($2)@ge;
    +  s@(include(<\/?[bu]\>|\s)*\<)([\w.\-/]+)@$1 . &include_ref($3)@ge;
    +  if ($prev && m@^\s*(\<[bu]\>)*(\w[\w.\-]*)(\)*(\([\dm]\w*\))@) {
    +    $cmd .= "$2$4";
    +    $prev =~ s@(\w[\w.\-]*-)((\)*\s*)$@$1$2@;
    +    print $prev;
    +    $prev = '';
    +    s@^(\s*(\<[bu]\>)*)(\w[\w.\-]*)@@;
    +    print "$1$3";
    +  } elsif ($prev) {
    +    print $prev;
    +    $prev = '';
    +  }
    +  s@(\w[\w.\-]*)((\)*)(\([\dm]\w*\))@$1$2$4@g;
    +  if (m@(\w[\w.\-]*)-(\)*\s*$@) {
    +    $cmd = $1;
    +    $prev = $_;
    +    next;
    +  }
    +  print;
    +}
    +if ($prev) {
    +  print $prev;
    +}
    +close(F);
    +if (! $ok) {
    +  if ($query{'quit'}) {
    +    print STDERR "No manual entry for $man_section.\n";
    +    print <
    +man $man_section
    +
    +
    +EOF
    +  print "No manual entry for $man_section.\n";
    +}
    +print <
    +
    +
    +EOF
    +
    +sub is_command {
    +  local($_) = @_;
    +  local($p);
    +
    +  (! -d && -x) || return 0;
    +  if (! defined(%PATH)) {
    +    for $p (split(":", $ENV{'PATH'})) {
    +      $p =~ s@/+$@@;
    +      $PATH{$p} = 1;
    +    }
    +  }
    +  s@/[^/]*$@@;
    +  return defined($PATH{$_});
    +}
    +
    +sub file_ref {
    +  local($_) = @_;
    +
    +  if (&is_command($_)) {
    +    ($man = $_) =~ s@.*/@@;
    +    return "$_";
    +  }
    +  if (/^\~/ || -f || -d) {
    +    return "$_";
    +  }
    +  return $_;
    +}
    +
    +sub include_ref {
    +  local($_) = @_;
    +  local($d);
    +
    +  for $d (
    +	"/usr/include",
    +	"/usr/local/include",
    +	"/usr/X11R6/include",
    +	"/usr/X11/include",
    +	"/usr/X/include",
    +	"/usr/include/X11"
    +  ) {
    +    -f "$d/$_" && return "$_";
    +  }
    +  return $_;
    +}
    +
    +sub keyword_ref {
    +  local($_, $s) = @_;
    +  local(@a) = ();
    +
    +  for (split(/\s*,\s*/)) {
    +    push(@a, "$_");
    +  }
    +  return join(", ", @a) . $s;
    +}
    +
    +sub html_quote {
    +  local($_) = @_;
    +  local(%QUOTE) = (
    +    '<', '<',
    +    '>', '>',
    +    '&', '&',
    +    '"', '"',
    +  );
    +  s/[<>&"]/$QUOTE{$&}/g;
    +  return $_;
    +}
    +
    +sub form_decode {
    +  local($_) = @_;
    +  s/\+/ /g;
    +  s/%([\da-f][\da-f])/pack('c', hex($1))/egi;
    +  return $_;
    +}
    +
    -- 
    cgit v1.2.3