Added support for multiple cut/writemaphtml commands.
[runtime.git] / apps / silcmap / silcmap_html.c
index 6dfce1f7e918d05c42e5c467b23b6c4ec71c7a2b..975e9bd07eee7756420b5df23da6adb9bed08d5d 100644 (file)
@@ -366,93 +366,97 @@ bool silc_map_writehtml_index(SilcMap map)
 bool silc_map_writemaphtml(SilcMap map)
 {
   SilcMapConnection mapconn;
-  SilcMapCommand cmd;
+  SilcMapCommand cmd, c;
   char *hostname, url[256];
   FILE *fp;
-  int xx , yy, w, h;
+  int i, xx , yy, w, h;
 
-  /* Open for writing */
-  fp = fopen(map->writemaphtml.filename, "w+");
-  if (!fp) {
-    fprintf(stderr, "Could not open file '%s'\n", map->writemaphtml.filename);
-    return FALSE;
-  }
-
-  /* The target may be portion of the original map, so we must make the
-     new coordinates relative to the new map. */
-  xx = map->writemaphtml.x;
-  yy = map->writemaphtml.y;
+  for (i = 0; i < map->writemaphtml_count; i++) {
+    c = &map->writemaphtml[i];
 
-  memset(url, 0, sizeof(url));
+    /* Open for writing */
+    fp = fopen(c->filename, "w+");
+    if (!fp) {
+      fprintf(stderr, "Could not open file '%s'\n", c->filename);
+      return FALSE;
+    }
 
-  fprintf(fp, "<!-- Automatically generated by silcmap --!>\n");
-  fprintf(fp, "<img src=\"%s\" usemap=\"#map\" class=\"silcmap\">\n",
-         map->writemaphtml.text);
-  fprintf(fp, "<map name=\"map\">\n");
+    /* The target may be portion of the original map, so we must make the
+       new coordinates relative to the new map. */
+    xx = c->x;
+    yy = c->y;
 
-  silc_dlist_start(map->conns);
-  while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) {
     memset(url, 0, sizeof(url));
-    if (mapconn->html_url && mapconn->html_url[0]) {
-      silc_strncat(url, sizeof(url), mapconn->html_url,
-                  strlen(mapconn->html_url));
-    } else {
-      silc_dlist_start(mapconn->hostnames);
-      hostname = silc_dlist_get(mapconn->hostnames);
-      snprintf(url, sizeof(url) - 1, "%s_%d.html", hostname, mapconn->port);
-    }
 
-    /* Print the positions of various items on the map into the map file */
-    silc_dlist_start(mapconn->commands);
-    while ((cmd = silc_dlist_get(mapconn->commands)) != SILC_LIST_END) {
-      if (cmd->draw_text) {
-       w = strlen(cmd->text) * 5;
-       h = map->font.height - 2;
-       fprintf(fp,
-               "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%s\">\n",
-               (int)(cmd->x - xx), (int)(cmd->y - yy), w, h, url);
+    fprintf(fp, "<!-- Automatically generated by silcmap --!>\n");
+    fprintf(fp, "<img src=\"%s\" usemap=\"#map\" class=\"silcmap\">\n",
+           c->text);
+    fprintf(fp, "<map name=\"map\">\n");
+
+    silc_dlist_start(map->conns);
+    while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) {
+      memset(url, 0, sizeof(url));
+      if (mapconn->html_url && mapconn->html_url[0]) {
+       silc_strncat(url, sizeof(url), mapconn->html_url,
+                    strlen(mapconn->html_url));
+      } else {
+       silc_dlist_start(mapconn->hostnames);
+       hostname = silc_dlist_get(mapconn->hostnames);
+       snprintf(url, sizeof(url) - 1, "%s_%d.html", hostname, mapconn->port);
       }
 
-      if (cmd->draw_circle) {
-       w = 4;
-       fprintf(fp,
-               "<area shape=\"circle\" coords=\"%d,%d,%d\" href=\"%s\">\n",
-               (int)(cmd->x - xx), (int)(cmd->y - yy), w, url);
-       if (cmd->text) {
+      /* Print the positions of various items on the map into the map file */
+      silc_dlist_start(mapconn->commands);
+      while ((cmd = silc_dlist_get(mapconn->commands)) != SILC_LIST_END) {
+       if (cmd->draw_text) {
          w = strlen(cmd->text) * 5;
          h = map->font.height - 2;
          fprintf(fp,
                  "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%s\">\n",
-                 (int)(cmd->x - xx + cmd->lposx),
-                 (int)(cmd->y - yy - cmd->lposy),
-                 (int)(cmd->x - xx + cmd->lposx + w),
-                 (int)(cmd->y - yy - cmd->lposy + h), url);
+                 (int)(cmd->x - xx), (int)(cmd->y - yy), w, h, url);
        }
-      }
 
-      if (cmd->draw_rectangle) {
-       w = 7;
-       h = 6;
-       fprintf(fp,
-               "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%s\">\n",
-               (int)(cmd->x - xx), (int)(cmd->y - yy),
-               (int)(cmd->x - xx + w), (int)(cmd->y - yy + h), url);
-       if (cmd->text) {
-         w = strlen(cmd->text) * 5;
-         h = map->font.height - 2;
+       if (cmd->draw_circle) {
+         w = 4;
+         fprintf(fp,
+                 "<area shape=\"circle\" coords=\"%d,%d,%d\" href=\"%s\">\n",
+                 (int)(cmd->x - xx), (int)(cmd->y - yy), w, url);
+         if (cmd->text) {
+           w = strlen(cmd->text) * 5;
+           h = map->font.height - 2;
+           fprintf(fp,
+                   "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%s\">\n",
+                   (int)(cmd->x - xx + cmd->lposx),
+                   (int)(cmd->y - yy - cmd->lposy),
+                   (int)(cmd->x - xx + cmd->lposx + w),
+                   (int)(cmd->y - yy - cmd->lposy + h), url);
+         }
+       }
+
+       if (cmd->draw_rectangle) {
+         w = 7;
+         h = 6;
          fprintf(fp,
                  "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%s\">\n",
-                 (int)(cmd->x - xx + cmd->lposx),
-                 (int)(cmd->y - yy - cmd->lposy),
-                 (int)(cmd->x - xx + cmd->lposx + w),
-                 (int)(cmd->y - yy - cmd->lposy + h), url);
+                 (int)(cmd->x - xx), (int)(cmd->y - yy),
+                 (int)(cmd->x - xx + w), (int)(cmd->y - yy + h), url);
+         if (cmd->text) {
+           w = strlen(cmd->text) * 5;
+           h = map->font.height - 2;
+           fprintf(fp,
+                   "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%s\">\n",
+                   (int)(cmd->x - xx + cmd->lposx),
+                   (int)(cmd->y - yy - cmd->lposy),
+                   (int)(cmd->x - xx + cmd->lposx + w),
+                   (int)(cmd->y - yy - cmd->lposy + h), url);
+         }
        }
       }
     }
-  }
 
-  fprintf(fp, "</map>\n");
-  fclose(fp);
+    fprintf(fp, "</map>\n");
+    fclose(fp);
+  }
 
   return TRUE;
 }