Added support for multiple cut/writemaphtml commands.
authorPekka Riikonen <priikone@silcnet.org>
Sat, 16 Aug 2003 15:45:42 +0000 (15:45 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 16 Aug 2003 15:45:42 +0000 (15:45 +0000)
apps/silcmap/silcmap.c
apps/silcmap/silcmap.h
apps/silcmap/silcmap_client.c
apps/silcmap/silcmap_command.c
apps/silcmap/silcmap_html.c

index 3a8f52d089cd4dbca554d8e435e12f2eea20f7d8..3561c52c20a9a265d755b597b3fc181826d505a3 100644 (file)
@@ -79,6 +79,7 @@ void silc_map_free(SilcMap map)
   SilcMapConnection mapconn;
   SilcMapCommand cmd;
   char *h;
+  int i;
 
   silc_free(map->conffile);
   silc_free(map->bitmap);
@@ -127,12 +128,19 @@ void silc_map_free(SilcMap map)
     silc_dlist_uninit(map->conns);
   }
 
+  for (i = 0; i < map->writemaphtml_count; i++) {
+    silc_free(map->writemaphtml[i].filename);
+    silc_free(map->writemaphtml[i].text);
+  }
+  silc_free(map->writemaphtml);
+
+  for (i = 0; i < map->cut_count; i++)
+    silc_free(map->cut[i].filename);
+  silc_free(map->cut);
+
   silc_free(map->writemap.filename);
   silc_free(map->writehtml.filename);
   silc_free(map->writehtml.text);
-  silc_free(map->writemaphtml.filename);
-  silc_free(map->writemaphtml.text);
-  silc_free(map->cut.filename);
 
   silc_free(map);
 }
index 61259ffb0f450488385af5e87e8545ea8bfb3e0d..7f63318a2ca87c4ec54af1a708acf92ce9507412 100644 (file)
@@ -83,8 +83,10 @@ typedef struct {
   /* Output methods */
   SilcMapCommandStruct writemap;
   SilcMapCommandStruct writehtml;
-  SilcMapCommandStruct writemaphtml;
-  SilcMapCommandStruct cut;
+  SilcMapCommandStruct *writemaphtml;
+  SilcMapCommandStruct *cut;
+  SilcUInt32 writemaphtml_count;
+  SilcUInt32 cut_count;
 } *SilcMap;
 
 /* SilcMap connecetion context. */
index 03cc47e6c55c913770c2c9dcc488ab6f61fa2f5a..e468a83178dca67d3234e49147921fdd4e13b473 100644 (file)
@@ -39,6 +39,7 @@ void silc_map_process_data(SilcMap map, SilcMapConnection mapconn)
   SilcMapCommand cmd;
   SilcMap ret_map;
   SilcInt16 r, g, b, lr, lg, lb;
+  int i;
 
   map->conn_num++;
   SILC_LOG_DEBUG(("Processing the data from server (%d/%d)",
@@ -131,10 +132,10 @@ void silc_map_process_data(SilcMap map, SilcMapConnection mapconn)
     /* Produce output */
     if (map->writemap.writemap)
       silc_map_write_ppm(map, map->writemap.filename);
-    if (map->cut.cut) {
-      if (silc_map_cut(map, map->cut.x, map->cut.y, map->cut.width,
-                      map->cut.height, &ret_map)) {
-       silc_map_write_ppm(ret_map, map->cut.filename);
+    for (i = 0; i < map->cut_count; i++) {
+      if (silc_map_cut(map, map->cut[i].x, map->cut[i].y, map->cut[i].width,
+                      map->cut[i].height, &ret_map)) {
+       silc_map_write_ppm(ret_map, map->cut[i].filename);
        silc_map_free(ret_map);
       }
     }
@@ -143,9 +144,8 @@ void silc_map_process_data(SilcMap map, SilcMapConnection mapconn)
     if (map->writehtml.writehtml)
       silc_map_writehtml_index(map);
 
-    /* Write the HTML map file */
-    if (map->writemaphtml.writemaphtml)
-      silc_map_writemaphtml(map);
+    /* Write the HTML map file(s) */
+    silc_map_writemaphtml(map);
 
     /* Schedule to stop */
     silc_schedule_task_add(map->client->schedule, 0,
index 72f1fcbbcf9d2c2ade3653598140657f95d0d60a..9ba1df67a4fb24e510acc8e4a20cccd874f13dd1 100644 (file)
@@ -414,19 +414,24 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_writemaphtml)
   int retval = SILC_CONFIG_OK;
 
   if (type == SILC_CONFIG_ARG_BLOCK) {
+    int i;
     if (!filename)
       return SILC_CONFIG_EMISSFIELDS;
 
-    SILC_LOG_DEBUG(("writehmaphtml: file: %s", filename));
+    SILC_LOG_DEBUG(("writemaphtml: file: %s", filename));
 
     /* Will generate HTML map page */
-    map->writemaphtml.filename = filename;
-    map->writemaphtml.text = text;
+    i = map->writemaphtml_count;
+    map->writemaphtml = silc_realloc(map->writemaphtml,
+                                    sizeof(*map->writemaphtml) * (i + 1));
+    map->writemaphtml[i].filename = filename;
+    map->writemaphtml[i].text = text;
     if (lon)
-      map->writemaphtml.x = silc_map_lon2x(map, lon);
+      map->writemaphtml[i].x = silc_map_lon2x(map, lon);
     if (lat)
-      map->writemaphtml.y = silc_map_lat2y(map, lat);
-    map->writemaphtml.writemaphtml = TRUE;
+      map->writemaphtml[i].y = silc_map_lat2y(map, lat);
+    map->writemaphtml[i].writemaphtml = TRUE;
+    map->writemaphtml_count++;
 
     /* Clean up */
     silc_free(lat);
@@ -493,6 +498,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_cut)
 
   if (type == SILC_CONFIG_ARG_BLOCK) {
     SilcMap map2;
+    int i;
 
     if (!filename || !lat || !lon || !width || !height)
       return SILC_CONFIG_EMISSFIELDS;
@@ -518,12 +524,15 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_cut)
          retval = SILC_CONFIG_ESILENT;
       } else {
        /* After all connection blocks */
-       map->cut.filename = strdup(filename);
-       map->cut.x = silc_map_lon2x(map, lon);
-       map->cut.y = silc_map_lat2y(map, lat);
-       map->cut.width = width;
-       map->cut.height = height;
-       map->cut.cut = TRUE;
+       i = map->cut_count;
+       map->cut = silc_realloc(map->cut, sizeof(*map->cut) * (i + 1));
+       map->cut[i].filename = strdup(filename);
+       map->cut[i].x = silc_map_lon2x(map, lon);
+       map->cut[i].y = silc_map_lat2y(map, lat);
+       map->cut[i].width = width;
+       map->cut[i].height = height;
+       map->cut[i].cut = TRUE;
+       map->cut_count++;
       }
     } else {
       SilcMapCommand cmd = silc_calloc(1, sizeof(*cmd));
@@ -611,7 +620,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_rectangle)
       cmd->lb = lb;
       cmd->x = silc_map_lon2x(map, lon);
       cmd->y = silc_map_lat2y(map, lat);
-      cmd->text = strdup(text);
+      cmd->text = text ? strdup(text) : NULL;
       cmd->lposx = lposx;
       cmd->lposy = lposy;
       cmd->draw_rectangle = TRUE;
@@ -701,7 +710,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_circle)
       cmd->lb = lb;
       cmd->x = silc_map_lon2x(map, lon);
       cmd->y = silc_map_lat2y(map, lat);
-      cmd->text = strdup(text);
+      cmd->text = text ? strdup(text) : NULL;
       cmd->lposx = lposx;
       cmd->lposy = lposy;
       cmd->draw_circle = TRUE;
@@ -866,7 +875,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_text)
       cmd->b = b;
       cmd->x = silc_map_lon2x(map, lon);
       cmd->y = silc_map_lat2y(map, lat);
-      cmd->text = strdup(text);
+      cmd->text = text ? strdup(text) : NULL;
       cmd->draw_text = TRUE;
       cmd->color_set = color_set;
     }
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;
 }