SILC Map distribution added.
[silc.git] / apps / silcmap / silcmap_command.c
index 2fcecaee35aece0b53efe60674bba4dc2ed6e8d3..4b663ace4a86e36f22117bc8f0da0c6d51d7cf33 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2003 Pekka Riikonen
+  Copyright (C) 2003 - 2004 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -237,7 +237,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_server)
   SilcMap map = context;
   int retval = SILC_CONFIG_OK;
 
-  if (!map->bitmap) {
+  if (!map->loadmap.loadmap) {
     fprintf(stderr, "You must call loadmap command before server command\n");
     return SILC_CONFIG_ESILENT;
   }
@@ -366,12 +366,8 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_loadmap)
 
     SILC_LOG_DEBUG(("loadmap: file: %s", filename));
 
-    /* Destroy old bitmap if loadmaped */
-    silc_free(map->bitmap);
-
-    /* Loadmap the bitmap image */
-    if (!silc_map_load_ppm(map, filename))
-      retval = SILC_CONFIG_ESILENT;
+    map->loadmap.filename = strdup(filename);
+    map->loadmap.loadmap = TRUE;
 
     /* Cleanup */
     silc_free(filename);
@@ -401,15 +397,8 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_writemap)
 
     SILC_LOG_DEBUG(("writemap: file: %s", filename));
 
-    /* Execute directly if there are no connections */
-    if (map->conns_num == 0) {
-      /* Writemap the map */
-      if (!silc_map_write_ppm(map, filename))
-       retval = SILC_CONFIG_ESILENT;
-    } else {
-      map->writemap.filename = strdup(filename);
-      map->writemap.writemap = TRUE;
-    }
+    map->writemap.filename = strdup(filename);
+    map->writemap.writemap = TRUE;
 
     /* Cleanup */
     silc_free(filename);
@@ -447,9 +436,9 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_writemaphtml)
     map->writemaphtml[i].filename = filename;
     map->writemaphtml[i].text = text;
     if (lon)
-      map->writemaphtml[i].x = silc_map_lon2x(map, lon);
+      map->writemaphtml[i].alon = strdup(lon);
     if (lat)
-      map->writemaphtml[i].y = silc_map_lat2y(map, lat);
+      map->writemaphtml[i].alat = strdup(lat);
     map->writemaphtml[i].writemaphtml = TRUE;
     map->writemaphtml_count++;
 
@@ -578,8 +567,8 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_cut)
        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].alon = strdup(lon);
+       map->cut[i].alat = strdup(lat);
        map->cut[i].width = width;
        map->cut[i].height = height;
        map->cut[i].cut = TRUE;
@@ -592,8 +581,8 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_cut)
 
       silc_dlist_add(curr_conn->commands, cmd);
       cmd->filename = strdup(filename);
-      cmd->x = silc_map_lon2x(map, lon);
-      cmd->y = silc_map_lat2y(map, lat);
+      cmd->alon = strdup(lon);
+      cmd->alat = strdup(lat);
       cmd->width = width;
       cmd->height = height;
       cmd->cut = TRUE;
@@ -650,7 +639,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_rectangle)
     }
 
     /* Execute directly if not for connection */
-    if (!curr_conn) {
+    if (!curr_conn && map->bitmap) {
       /* Draw the rectangle */
       ret = silc_map_draw_rectangle(map, silc_map_lon2x(map, lon),
                                    silc_map_lat2y(map, lat),
@@ -669,8 +658,8 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_rectangle)
       cmd->lr = lr;
       cmd->lg = lg;
       cmd->lb = lb;
-      cmd->x = silc_map_lon2x(map, lon);
-      cmd->y = silc_map_lat2y(map, lat);
+      cmd->alon = strdup(lon);
+      cmd->alat = strdup(lat);
       cmd->text = text ? strdup(text) : NULL;
       cmd->lposx = lposx;
       cmd->lposy = lposy;
@@ -740,7 +729,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_circle)
     }
 
     /* Execute directly if not for connection */
-    if (!curr_conn) {
+    if (!curr_conn && map->bitmap) {
       /* Draw the circle */
       ret = silc_map_draw_circle(map, silc_map_lon2x(map, lon),
                                 silc_map_lat2y(map, lat),
@@ -759,8 +748,8 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_circle)
       cmd->lr = lr;
       cmd->lg = lg;
       cmd->lb = lb;
-      cmd->x = silc_map_lon2x(map, lon);
-      cmd->y = silc_map_lat2y(map, lat);
+      cmd->alon = strdup(lon);
+      cmd->alat = strdup(lat);
       cmd->text = text ? strdup(text) : NULL;
       cmd->lposx = lposx;
       cmd->lposy = lposy;
@@ -828,7 +817,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_line)
       width = 1;
 
     /* Execute directly if not for connection */
-    if (!curr_conn) {
+    if (!curr_conn && map->bitmap) {
       /* Draw the line */
       ret = silc_map_draw_line(map, width,
                               silc_map_lon2x(map, lon),
@@ -847,10 +836,10 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_line)
       cmd->r = r;
       cmd->g = g;
       cmd->b = b;
-      cmd->x = silc_map_lon2x(map, lon);
-      cmd->y = silc_map_lat2y(map, lat);
-      cmd->x2 = silc_map_lon2x(map, lon2);
-      cmd->y2 = silc_map_lat2y(map, lat2);
+      cmd->alon = strdup(lon);
+      cmd->alat = strdup(lat);
+      cmd->blon = strdup(lon2);
+      cmd->blat = strdup(lat2);
       cmd->width = width;
       cmd->draw_line = TRUE;
       cmd->color_set = color_set;
@@ -907,7 +896,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_text)
                    lat, lon, r, g, b, text));
 
     /* Execute directly if not for connection */
-    if (!curr_conn) {
+    if (!curr_conn && map->bitmap) {
       /* Print the text */
       ret = silc_map_draw_text(map, text,
                               silc_map_lon2x(map, lon),
@@ -924,8 +913,8 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_text)
       cmd->r = r;
       cmd->g = g;
       cmd->b = b;
-      cmd->x = silc_map_lon2x(map, lon);
-      cmd->y = silc_map_lat2y(map, lat);
+      cmd->alon = strdup(lon);
+      cmd->alat = strdup(lat);
       cmd->text = text ? strdup(text) : NULL;
       cmd->draw_text = TRUE;
       cmd->color_set = color_set;
@@ -985,8 +974,8 @@ bool silc_map_commands_parse(SilcMap map, const char *filename)
   SILC_LOG_DEBUG(("Parsing status: %s", silc_config_strerror(ret)));
 
   if (ret && ret != SILC_CONFIG_ESILENT) {
-    fprintf(stderr, "Error parsing commands: %s, line %ld\n",
-           silc_config_strerror(ret), silc_config_get_line(file));
+    fprintf(stderr, "Error parsing commands: %s, line %d\n",
+           silc_config_strerror(ret), (int)silc_config_get_line(file));
     retval = FALSE;
   }