[cig-commits] r15826 - doc/geodynamics.org/benchmarks/trunk

luis at geodynamics.org luis at geodynamics.org
Sun Oct 18 00:18:19 PDT 2009


Author: luis
Date: 2009-10-18 00:18:18 -0700 (Sun, 18 Oct 2009)
New Revision: 15826

Modified:
   doc/geodynamics.org/benchmarks/trunk/watcher.c
Log:
Don't enable browser reloading by default

Need to call "./watcher -r" in order to enable
reloading in firefox.

Modified: doc/geodynamics.org/benchmarks/trunk/watcher.c
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/watcher.c	2009-10-18 07:18:11 UTC (rev 15825)
+++ doc/geodynamics.org/benchmarks/trunk/watcher.c	2009-10-18 07:18:18 UTC (rev 15826)
@@ -160,8 +160,8 @@
     l = NULL;
 }
 
-/* get the source .rst file, given an .html file */
-void getrst(char *filename)
+/* given an .html filename, set the file extension to .rst */
+void set_rst_extension(char *filename)
 {
     /* 
      * We assume filename is long enough (consists of at least ".html").
@@ -177,6 +177,19 @@
     filename[len-5] = 'r';
 }
 
+/* given an .rst filename, change file extension to .html */
+void set_html_extension(char *filename)
+{
+    /* We assume filename is buffer that's long enough */
+    int len = strlen(filename);
+    assert(len > 4);
+    filename[len+1] = '\0';
+    filename[len]   = 'l';
+    filename[len-1] = 'm';
+    filename[len-2] = 't';
+    filename[len-3] = 'h';
+}
+
 /* read lines from a file, and store them in a linked list */
 int readlines(char *filename, l_list *l)
 {
@@ -192,7 +205,7 @@
 
     while (fgets(line, sizeof(line), fp) != NULL)
     {
-        getrst(line);
+        set_rst_extension(line);
         l_push(l, line);
     }
 
@@ -286,11 +299,24 @@
     struct timespec timeout;
     unsigned int vnode_events;
 
-    /* whether to reload browser when an event happens */
-    int reloading = 1;
+    /* for reloading */
+    int reloading = 0;
     char loaded[1024];
+
+    /* don't reload browser, by default */
+    reloading = 0;
     loaded[0] = '\0';
 
+    /* figure out if we want to reload browser (argv[1] needs to be "-r"). */
+    if (argc > 1)
+    {
+        if (strncmp(argv[1], "-r", 2) == 0)
+        {
+            reloading = 1;
+            printf("Browser reloading enabled\n");
+        }
+    }
+
     /* get list of files to monitor */
     f = readfiles();
     if (f == NULL)
@@ -396,24 +422,19 @@
 
                 if (reloading)
                 {
-                    char html[1000];
-                    int len = strlen(n->path);
-                    strncpy(html, n->path, sizeof(html));
-                    html[len+1] = '\0';
-                    html[len]   = 'l';
-                    html[len-1] = 'm';
-                    html[len-2] = 't';
-                    html[len-3] = 'h';
+                    char buffer[1000];
+                    strncpy(buffer, n->path, sizeof(buffer));
+                    set_html_extension(buffer);
 
-                    if (strncmp(loaded, html, sizeof(html)) == 0)
+                    if (strncmp(loaded, buffer, sizeof(buffer)) == 0)
                     {
                         system("./reload-firefox.sh");
                     }
                     else
                     {
                         char cmd[1024];
-                        strncpy(loaded, html, sizeof(html));
-                        snprintf(cmd, sizeof(cmd), "./reload-firefox.sh %s", html);
+                        strncpy(loaded, buffer, sizeof(buffer));
+                        snprintf(cmd, sizeof(cmd), "./reload-firefox.sh %s", buffer);
                         system(cmd);
                     }
                 }



More information about the CIG-COMMITS mailing list