bug-global
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] generate hypertext of files which is not source dynamically


From: Hideki IWAMOTO
Subject: [PATCH] generate hypertext of files which is not source dynamically
Date: Sat, 07 Jun 2003 01:07:08 +0900

* htags/htags.in: Changed so that hypertext of arbitrary files
    can be obtained using CGI script.
    When the option of both -o and -D was specified, 
    generate hypertext of files which is not source dynamically.

* gtags/gtagc.c: Add undocumented option --secure.
    If this option is specified, outside of the souce tree
    cannot be specified with option --expand.


Index: htags/htags.in
===================================================================
RCS file: /cvsroot/global/global/htags/htags.in,v
retrieving revision 1.132
diff -u -r1.132 htags.in
--- htags/htags.in      1 Jun 2003 10:23:22 -0000       1.132
+++ htags/htags.in      6 Jun 2003 15:45:50 -0000
@@ -1121,8 +1121,10 @@
                exit 0;
        }
 }
-if ($flag eq 'g' || $flag eq 'I') {
-       if ($flag eq 'g' && ! -f "../../GTAGS" || $flag eq 'I' && ! -f 
"../../ID") {
+if ($flag eq 'g' || $flag eq 'I' || $form{'type'} eq 'source') {
+       if (($flag eq 'g' && ! -f "../../GTAGS")
+        || ($flag eq 'I' && ! -f "../../ID")
+        || ($form{'type'} eq 'source' && ! -f "../../GTAGS")) {
                print "<H1><FONT COLOR=#cc0000>Error</FONT></H1>\n";
                print "<H3>Couldn't execute command. <A 
HREF=$htmlbase/address@hidden@>[return]</A></H3>\n";
                print "@address@hidden";
@@ -1143,6 +1145,28 @@
                chdir("../..");
        }
 }
+if ($form{'type'} eq 'source') {
+       local(%ctab) = ('&', '&amp;', '<', '&lt;', '>', '&gt;');
+       open(PIPE, "-|") || exec '@gtagspath@', '--secure', '--expand', 
'address@hidden@', './'.$pattern;
+       if ($?) {       
+               print "<H1><FONT COLOR=#cc0000>Error</FONT></H1>\n";
+               print "<H3>Cannot execute gtags. <A 
HREF=$htmlbase/address@hidden@>[return]</A></H3>\n";
+               print "@address@hidden";
+               print "@address@hidden";
+               exit 0;
+       }
+       print "<PRE>\n";
+       while (<PIPE>) {
+               s/([&<>])/$ctab{$1}/ge;
+               print "<A NAME=$.>";
+               print;
+       }
+       close(PIPE);
+       print "</PRE>\n";
+       print "@address@hidden";
+       print "@address@hidden";
+       exit 0;
+}
 #
 # fork and exec global(1) to avoid command substitutions in $pattern.
 #
@@ -1207,6 +1231,7 @@
        $script =~ s/address@hidden@/$'normal_suffix/g;
        $script =~ s/address@hidden@/$'SRCS/g;
        $script =~ s/address@hidden@/$'HTML/g;
+       $script =~ s/address@hidden@/$'tabs/g;
        $script =~ s/address@hidden@/$globalpath/g;
        $script =~ s/address@hidden@/$gtagspath/g;
        print PROGRAM $script;
@@ -1731,13 +1756,19 @@
                                $includes{$file} = "$includes{$file}\n$_";
                        }
                }
-               local($url) = &'path2url($_);
+               local($url);
+               if ($notsource && $'dynamic) {
+                       local($cgi) = ($'action =~ /^\// || @dirstack == 0) ? 
$'action : "../$'action";
+                       $url = "${cgi}?pattern=$_&type=source";
+               } else {
+                       $url = (@dirstack == 0 ? '' : '../') . "$'SRCS/" . 
&'path2url($_);
+               }
                local($last) = $_;
                if (!$'full_path) {
                        $last =~ s!.*/!!;
                }
                local($li) = "<LI>" .
-                       "<A HREF=" . (@dirstack == 0 ? '' : '../') . "S/$url 
TARGET=$target>" .
+                       "<A HREF=$url TARGET=$target>" .
                        ($'icon_list ? "<IMG SRC=" . (@dirstack == 0 ? '' : 
'../') . "icons/$'file_icon ALT=[$_] HSPACE=3 $'icon_spec>" : '') .
                        "$last</A>\n";
                if (@dirstack == 0) {
@@ -2050,7 +2081,7 @@
 sub makehtml {
        local($dist, $total) = @_;
        local($count) = 0;
-       local($findcom) = ($'other_files) ? "$'findcom --other | sort -t / +1" 
: $'findcom;
+       local($findcom) = ($'other_files && !$'dynamic) ? "$'findcom --other | 
sort -t / +1" : $'findcom;
 
        open(FIND, "$findcom |") || &'error("cannot fork.");
        while (<FIND>) {
Index: gtags/gtags.c
===================================================================
RCS file: /cvsroot/global/global/gtags/gtags.c,v
retrieving revision 1.75
diff -u -r1.75 gtags.c
--- gtags/gtags.c       6 Jun 2003 13:07:04 -0000       1.75
+++ gtags/gtags.c       6 Jun 2003 15:45:50 -0000
@@ -24,6 +24,7 @@
 #endif
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <errno.h>
 
 #include <ctype.h>
 #include <utime.h>
@@ -89,6 +90,7 @@
 int    other_files;
 int    info;
 int    debug;
+int    secure_mode;
 char   *extra_options;
 char   *info_string;
 char   *btree_dbname;
@@ -139,6 +141,7 @@
        {"readdb", required_argument, &do_readdb, 1},
        {"relative", no_argument, &do_relative, 1},
        {"scandb", required_argument, &do_scandb, 1},
+       {"secure", no_argument, &secure_mode, 1},
        {"sort", no_argument, &do_sort, 1},
        {"write", no_argument, &do_write, 1},
        {"version", no_argument, &show_version, 1},
@@ -192,6 +195,7 @@
 int    argc;
 char   *argv[];
 {
+       char    root[MAXPATHLEN+1];
        char    dbpath[MAXPATHLEN+1];
        char    cwd[MAXPATHLEN+1];
        STRBUF  *sb = strbuf_open(0);
@@ -409,9 +413,23 @@
                FILE *ip;
                STRBUF *ib = strbuf_open(MAXBUFLEN);
 
-               ip = (argc) ? fopen(argv[0], "r") : stdin;
-               if (ip == NULL)
-                       exit(1);
+               if (argc) {
+                       if (secure_mode) {
+                               char    buf[MAXPATHLEN+1], *path;
+                               getdbpath(cwd, root, dbpath, 0);
+                               path = realpath(argv[0], buf);
+                               if (path == NULL)
+                                       die("realpath(%s, buf) failed. 
(errno=%d).", argv[0], errno);
+                               if (!isabspath(path))
+                                       die("realpath(3) is not compatible with 
BSD version.");
+                               if (strncmp(path, root, strlen(root)))
+                                       die("'%s' is out of source tree.\n", 
path);
+                       }
+                       ip = fopen(argv[0], "r");
+                       if (ip == NULL)
+                               exit(1);
+               } else
+                       ip = stdin;
                while (strbuf_fgets(ib, ip, STRBUF_NOCRLF) != NULL)
                        detab(stdout, strbuf_value(ib));
                strbuf_close(ib);

----
Hideki IWAMOTO  address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]