X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Fsilcmap%2Fsilcmap_command.c;h=4b663ace4a86e36f22117bc8f0da0c6d51d7cf33;hb=ed46e908363484cad4403d6828aec342b4b82c10;hp=9ba1df67a4fb24e510acc8e4a20cccd874f13dd1;hpb=5ea19fe3cccb9d50b312d0e575b52575013077d6;p=silc.git diff --git a/apps/silcmap/silcmap_command.c b/apps/silcmap/silcmap_command.c index 9ba1df67..4b663ace 100644 --- a/apps/silcmap/silcmap_command.c +++ b/apps/silcmap/silcmap_command.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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 @@ -28,6 +28,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_loadmap); SILC_CONFIG_CALLBACK(silc_map_cmd_writemap); SILC_CONFIG_CALLBACK(silc_map_cmd_writemaphtml); SILC_CONFIG_CALLBACK(silc_map_cmd_writehtml); +SILC_CONFIG_CALLBACK(silc_map_cmd_writerel); SILC_CONFIG_CALLBACK(silc_map_cmd_cut); SILC_CONFIG_CALLBACK(silc_map_cmd_rectangle); SILC_CONFIG_CALLBACK(silc_map_cmd_circle); @@ -37,11 +38,13 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_text); static const SilcConfigTable silc_map_table_loadmap[] = { { "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_loadmap, NULL }, + { NULL }, }; static const SilcConfigTable silc_map_table_writemap[] = { { "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_writemap, NULL }, + { NULL }, }; static const SilcConfigTable silc_map_table_writemaphtml[] = @@ -50,12 +53,21 @@ static const SilcConfigTable silc_map_table_writemaphtml[] = { "image", SILC_CONFIG_ARG_STR, silc_map_cmd_writemaphtml, NULL }, { "cut_lat", SILC_CONFIG_ARG_STRE, silc_map_cmd_writemaphtml, NULL }, { "cut_lon", SILC_CONFIG_ARG_STRE, silc_map_cmd_writemaphtml, NULL }, + { NULL }, }; static const SilcConfigTable silc_map_table_writehtml[] = { { "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_writehtml, NULL }, { "class", SILC_CONFIG_ARG_STRE, silc_map_cmd_writehtml, NULL }, + { NULL }, +}; + +static const SilcConfigTable silc_map_table_writerel[] = +{ + { "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_writerel, NULL }, + { "class", SILC_CONFIG_ARG_STRE, silc_map_cmd_writerel, NULL }, + { NULL }, }; static const SilcConfigTable silc_map_table_cut[] = @@ -65,6 +77,7 @@ static const SilcConfigTable silc_map_table_cut[] = { "width", SILC_CONFIG_ARG_INT, silc_map_cmd_cut, NULL }, { "height", SILC_CONFIG_ARG_INT, silc_map_cmd_cut, NULL }, { "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_cut, NULL }, + { NULL }, }; static const SilcConfigTable silc_map_table_rectangle[] = @@ -76,6 +89,7 @@ static const SilcConfigTable silc_map_table_rectangle[] = { "lposx", SILC_CONFIG_ARG_INT, silc_map_cmd_rectangle, NULL }, { "lposy", SILC_CONFIG_ARG_INT, silc_map_cmd_rectangle, NULL }, { "lcolor", SILC_CONFIG_ARG_STR, silc_map_cmd_rectangle, NULL }, + { NULL }, }; static const SilcConfigTable silc_map_table_circle[] = @@ -87,6 +101,7 @@ static const SilcConfigTable silc_map_table_circle[] = { "lposx", SILC_CONFIG_ARG_INT, silc_map_cmd_circle, NULL }, { "lposy", SILC_CONFIG_ARG_INT, silc_map_cmd_circle, NULL }, { "lcolor", SILC_CONFIG_ARG_STR, silc_map_cmd_circle, NULL }, + { NULL }, }; static const SilcConfigTable silc_map_table_line[] = @@ -97,6 +112,7 @@ static const SilcConfigTable silc_map_table_line[] = { "b_lon", SILC_CONFIG_ARG_STR, silc_map_cmd_line, NULL }, { "width", SILC_CONFIG_ARG_STR, silc_map_cmd_line, NULL }, { "color", SILC_CONFIG_ARG_STR, silc_map_cmd_line, NULL }, + { NULL }, }; static const SilcConfigTable silc_map_table_text[] = @@ -105,6 +121,7 @@ static const SilcConfigTable silc_map_table_text[] = { "lon", SILC_CONFIG_ARG_STR, silc_map_cmd_text, NULL }, { "color", SILC_CONFIG_ARG_STR, silc_map_cmd_text, NULL }, { "text", SILC_CONFIG_ARG_STR, silc_map_cmd_text, NULL }, + { NULL }, }; static const SilcConfigTable silc_map_table_server[] = @@ -159,6 +176,7 @@ static const SilcConfigTable silc_map_table_server[] = silc_map_cmd_line, silc_map_table_line }, { "text", SILC_CONFIG_ARG_BLOCK, silc_map_cmd_text, silc_map_table_text }, + { NULL }, }; static const SilcConfigTable silc_map_table_main[] = @@ -173,6 +191,8 @@ static const SilcConfigTable silc_map_table_main[] = silc_map_cmd_writemaphtml, silc_map_table_writemaphtml }, { "writehtml", SILC_CONFIG_ARG_BLOCK, silc_map_cmd_writehtml, silc_map_table_writehtml }, + { "writerel", SILC_CONFIG_ARG_BLOCK, + silc_map_cmd_writerel, silc_map_table_writerel }, { "cut", SILC_CONFIG_ARG_BLOCK, silc_map_cmd_cut, silc_map_table_cut }, { "rectangle", SILC_CONFIG_ARG_BLOCK, @@ -217,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; } @@ -346,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); @@ -381,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); @@ -427,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++; @@ -488,6 +497,37 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_writehtml) return retval; } +/* Command: writerel, writes the uptime reliability graph. */ + +SILC_CONFIG_CALLBACK(silc_map_cmd_writerel) +{ + SilcMap map = context; + int retval = SILC_CONFIG_OK; + + if (type == SILC_CONFIG_ARG_BLOCK) { + if (!filename) + return SILC_CONFIG_EMISSFIELDS; + + SILC_LOG_DEBUG(("writerel: file: %s", filename)); + + /* Will generate uptime reliability graph */ + map->writerel.filename = filename; + map->writerel.text = text; /* class */ + map->writerel.writerel = TRUE; + filename = text = NULL; + + return retval; + } + if (!strcmp(name, "filename")) + filename = strdup((char *)val); + else if (!strcmp(name, "class")) + text = strdup((char *)val); + else + retval = SILC_CONFIG_ESILENT; + + return retval; +} + /* Command: cut, cut's a specified area from the map. */ SILC_CONFIG_CALLBACK(silc_map_cmd_cut) @@ -527,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; @@ -541,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; @@ -599,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), @@ -618,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; @@ -689,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), @@ -708,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; @@ -777,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), @@ -796,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; @@ -856,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), @@ -873,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; @@ -934,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; }