diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-09-25 18:35:18 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-09-25 18:35:18 +0300 |
commit | cf3446228c9ed5729be74e19695e747477adafef (patch) | |
tree | 3bf329d92ca7a7df3098b9bb1d4f5c0d5f6d6e22 | |
parent | c394bac102404f62842eb56e63af73d84dfc4b2c (diff) | |
download | eclat-cf3446228c9ed5729be74e19695e747477adafef.tar.gz eclat-cf3446228c9ed5729be74e19695e747477adafef.tar.bz2 |
Provide default formats for all implemented commands.
* src/cmdline.opt: Work over quoting errors in getopt.m4
* src/eclat.c: In debug level main.10 and higher dump XML
to the file eclat.dump.xml.
* src/eclat.h (XML_DUMP_FILE_NAME): New define.
* src/eclat.conf: Provide default formats for all implemented
commands.
-rw-r--r-- | src/cmdline.opt | 4 | ||||
-rw-r--r-- | src/eclat.c | 32 | ||||
-rw-r--r-- | src/eclat.conf | 32 | ||||
-rw-r--r-- | src/eclat.h | 2 |
4 files changed, 63 insertions, 7 deletions
diff --git a/src/cmdline.opt b/src/cmdline.opt index a17f2b8..b295456 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -109,13 +109,13 @@ BEGIN add_config_finish_hook(replace_string_var, rv); END -OPTION(access-key,O,KEY, +OPTION(access-key,O,[<STRING>], [<set access key to use>]) BEGIN access_key = optarg; END -OPTION(secret-key,W,KEY, +OPTION(secret-key,W,[<STRING>], [<set secret key to use>]) BEGIN secret_key = optarg; diff --git a/src/eclat.c b/src/eclat.c index a26ef7d..d20af4a 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -30,6 +30,8 @@ char *format_file; int sort_option; enum eclat_command eclat_command; +FILE *xml_dump_file; + static char *categories[] = { "main", @@ -154,6 +156,25 @@ dump_text(FILE *stream, int line, int column, const char *text, size_t len) fputc('\n', stream); } +static void +dumpxml(void *ptr, size_t realsize) +{ + static int open_failed = 0; + + if (open_failed) + return; + if (!xml_dump_file) { + xml_dump_file = fopen(XML_DUMP_FILE_NAME, "w"); + if (!xml_dump_file) { + err("cannot open dump file %s: %s", + XML_DUMP_FILE_NAME, strerror(errno)); + open_failed = 1; + return; + } + } + fwrite(ptr, realsize, 1, xml_dump_file); +} + static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *data) { @@ -163,10 +184,9 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data) int line = XML_GetCurrentLineNumber(parser); int column = XML_GetCurrentColumnNumber(parser); - /* FIXME: Debugging level. */ - if (debug_level(ECLAT_DEBCAT_MAIN) > 10) { - dump_text(stderr, line, column, ptr, realsize); - } + if (debug_level(ECLAT_DEBCAT_MAIN) >= 10) + dumpxml(ptr, realsize); + status = XML_Parse(parser, ptr, realsize, 0); if (status == XML_STATUS_ERROR) { enum XML_Error error = XML_GetErrorCode(parser); @@ -381,7 +401,9 @@ main(int argc, char **argv) rc = command_tab[eclat_command].handler(curl, argc, argv); curl_easy_cleanup(curl); XML_Parse(parser, "", 0, 1); - + if (xml_dump_file) + fclose(xml_dump_file); + xmltree = eclat_partial_tree_finish(part); if (sort_option) diff --git a/src/eclat.conf b/src/eclat.conf index ef212e7..13b004d 100644 --- a/src/eclat.conf +++ b/src/eclat.conf @@ -42,3 +42,35 @@ else { } EOT; +format "StartInstances" <<\EOT +if (.StartInstancesResponse) { + for (var in .StartInstancesResponse.instancesSet.item) { + print(var.instanceId,": ", + var.previousState.name," => ", + var.currentState.name,"\n"); + } +} else if (.Response.Errors) + error("Error: ",.Response.Errors.Error.Message,"\n"); +else { + error("Unrecognized response:\n"); + dump(.); +} +EOT; + +format "StopInstances" <<\EOT +if (.StopInstancesResponse) { + for (var in .StopInstancesResponse.instancesSet.item) { + print(var.instanceId,": ", + var.previousState.name," => ", + var.currentState.name,"\n"); + } +} else if (.Response.Errors) + error("Error: ",.Response.Errors.Error.Message,"\n"); +else { + error("Unrecognized response:\n"); + dump(.); +} +EOT; + + + diff --git a/src/eclat.h b/src/eclat.h index 9b909c4..1726c92 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -71,3 +71,5 @@ int eclat_describe_tags(CURL *curl, int argc, char **argv); char *region_to_endpoint(const char *region); void define_format(const char *name, const char *format, grecs_locus_t *locus); + +#define XML_DUMP_FILE_NAME "eclat.dump.xml" |