Diff
Not logged in

Differences From:

File src/browse.c part of check-in [e81cc91aa4] - Additional cleanup in the differencing engine. The new "dir" webpage now uses name= instead of the d= for the query parameter. by drh on 2008-02-04 14:24:28. [view]

To:

File src/browse.c part of check-in [a20dcb5c26] - Hyperlinks to directory browser pages on the pathname in the title of the file history viewer, finfo. by drh on 2008-02-04 19:08:55. [view]

@@ -66,8 +66,37 @@
     sqlite3_result_text(context, zOut, i-n+1, sqlite3_free);
   }
 }
 
+/*
+** Given a pathname which is a relative path from the root of
+** the repository to a file or directory, compute a string which
+** is an HTML rendering of that path with hyperlinks on each
+** directory component of the path where the hyperlink redirects
+** to the "dir" page for the directory.
+**
+** There is no hyperlink on the file element of the path.
+**
+** The computed string is appended to the pOut blob.  pOut should
+** have already been initialized.
+*/
+void hyperlinked_path(const char *zPath, Blob *pOut){
+  int i, j;
+  char *zSep = "";
+
+  for(i=0; zPath[i]; i=j){
+    for(j=i; zPath[j] && zPath[j]!='/'; j++){}
+    if( zPath[j] ){
+      blob_appendf(pOut, "%s<a href=\"%s/dir?name=%#T\">%#h</a>",
+                   zSep, g.zBaseURL, j, zPath, j-i, &zPath[i]);
+    }else{
+      blob_appendf(pOut, "%s%h", zSep, &zPath[i]);
+    }
+    zSep = "/";
+    while( zPath[j]=='/' ){ j++; }
+  }
+}
+
 
 /*
 ** WEBPAGE: dir
 **
@@ -93,33 +122,16 @@
   if( zD && strlen(zD)==0 ){ zD = 0; }
 
   /* Compute the title of the page */
   if( zD ){
-    int i, j;
-    char *zCopy;
     Blob title;
 
     blob_zero(&title);
-    zCopy = sqlite3_mprintf("%s/", zD);
-    blob_appendf(&title,
-       "Files in directory <a href=\"%s/dir\"><i>root</i></a>",
-       g.zBaseURL
-    );
-    for(i=0; zD[i]; i=j){
-      for(j=i; zD[j] && zD[j]!='/'; j++){}
-      if( zD[j] ){
-        zCopy[j] = 0;
-        blob_appendf(&title, "/<a href=\"%s/dir?name=%T\">%h</a>",
-                     g.zBaseURL, zCopy, &zCopy[i]);
-        zCopy[j] = '/';
-      }else{
-        blob_appendf(&title, "/%h", &zCopy[i]);
-      }
-      while( zD[j]=='/' ){ j++; }
-    }
+    blob_appendf(&title, "Files in directory ");
+    hyperlinked_path(zD, &title);
     @ <h2>%s(blob_str(&title))</h2>
     blob_reset(&title);
-    zPrefix = zCopy;
+    zPrefix = mprintf("%h/", zD);
   }else{
     @ <h2>Files in the top-level directory</h2>
     zPrefix = "";
   }