diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2013-12-03 15:32:12 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2013-12-03 15:32:12 +0200 |
commit | 5e501cf05fd1997018613304761d1104879353aa (patch) | |
tree | fd14fa84bf80b72e8472f8451639e33501afe886 | |
parent | 495c4a5cadf67b7c9b5e0c8b224f7b68c42c8da4 (diff) | |
download | eclat-5e501cf05fd1997018613304761d1104879353aa.tar.gz eclat-5e501cf05fd1997018613304761d1104879353aa.tar.bz2 |
Implement sg --list
* etc/Makefile.am (FLNFILES): Add lsattr.fln
(.fln.forlan): Use all prerequisites, not only the first one.
(FORMATFILES): Remove lsattr.forlan
(lsattr.forlan): Use implicit rule.
(sg.forlan): New rule
* etc/flncat.c (comment): Optionally output the comment.
(main): Output " else " only if some non-whitespace and non-comment
characters were output before.
* etc/lsattr.fln: New file
* src/sg-cl.opt: New option --list.
* src/sg.c (list_option): New variable.
-rw-r--r-- | etc/Makefile.am | 9 | ||||
-rw-r--r-- | etc/flncat.c | 48 | ||||
-rw-r--r-- | etc/lsattr.fln | 16 | ||||
-rw-r--r-- | src/sg-cl.opt | 30 | ||||
-rw-r--r-- | src/sg.c | 1 |
5 files changed, 78 insertions, 26 deletions
diff --git a/etc/Makefile.am b/etc/Makefile.am index 1f53924..caa780c 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -42,12 +42,13 @@ FLNFILES=\ describe-snapshots.fln\ describe-tags.fln\ describe-volumes.fln\ detach-volume.fln\ disassociate-address.fln\ get-console-output.fln\ + lsattr.fln\ modify-instance-attribute.fln\ modify-snapshot-attribute.fln\ reboot-instances.fln\ release-address.fln\ reset-snapshot-attribute.fln\ run-instances.fln\ @@ -59,17 +60,17 @@ EXTRA_DIST=$(FLNFILES) default.fln eclat.cfin SUFFIXES=.cfin .conf if SPLIT_FORMATS SUFFIXES += .forlan .fln .fln.forlan: - $(AM_V_GEN)$(abs_builddir)/flncat $< default.fln > $@ -FORMATFILES = $(FLNFILES:.fln=.forlan) lsattr.forlan + $(AM_V_GEN)$(abs_builddir)/flncat $^ default.fln > $@ +FORMATFILES = $(FLNFILES:.fln=.forlan) FORMATNAME = $${command} -lsattr.forlan: describe-instance-attribute.fln describe-snapshot-attribute.fln default.fln - $(AM_V_GEN)(cd $(srcdir); $(abs_builddir)/flncat describe-instance-attribute.fln describe-snapshot-attribute.fln default.fln) > lsattr.forlan +lsattr.forlan: describe-instance-attribute.fln describe-snapshot-attribute.fln default.fln +sg.forlan: sg.fln describe-security-groups.fln else FORMATFILES = eclat.forlan eclat.forlan: $(FLNFILES) default.fln $(AM_V_GEN)(cd $(srcdir); $(abs_builddir)/flncat $(FLNFILES) default.fln) > eclat.forlan FORMATNAME = eclat endif diff --git a/etc/flncat.c b/etc/flncat.c index 0c29453..82c4086 100644 --- a/etc/flncat.c +++ b/etc/flncat.c @@ -16,65 +16,83 @@ #include <stdio.h> #include <ctype.h> #include <assert.h> int -comment(FILE *fp, int c) +comment(FILE *fp, int c, int echo) { if (c != '/') { ungetc(c, fp); return 0; - } + } else if (echo) + fputc(c, stdout); if ((c = getc(fp)) == '/') { - while ((c = getc(fp)) != EOF && c != '\n') - ; + do + if (echo) fputc(c, stdout); + while ((c = getc(fp)) != EOF && c != '\n'); return 1; } + + if (echo) + fputc(c, stdout); if (c == '*') { do { - while ((c = getc(fp)) != '*') { + do { + c = getc(fp); if (c == EOF) return 0; - } - } while ((c = getc(fp)) != '/'); + else if (echo) + fputc(c, stdout); + } while (c != '*'); + c = getc(fp); + if (echo) + fputc(c, stdout); + } while (c != '/'); return 1; + } else + + if (!echo) { + ungetc(c, fp); + ungetc('/', fp); } - ungetc(c, fp); - ungetc('/', fp); return 0; } int main(int argc, char **argv) { int i; FILE *fp; int c; char buf[128]; size_t lev = 0; + int outchars = 0; for (i = 1; i < argc; i++) { fp = fopen(*++argv, "r"); if (!fp) { perror(*argv); return 1; } - if (i > 1) { - /* Skip whitespace and comment lines */ - do { - while ((c = fgetc(fp)) != EOF && isspace(c)) - ; - } while (c != EOF && comment(fp, c)); + /* Skip initial whitespace and comment lines, unless it is the + first file we process. */ + do { + while ((c = fgetc(fp)) != EOF && isspace(c)) + if (i == 1) fputc(c, stdout); + } while (c != EOF && comment(fp, c, i == 1)); + + if (outchars) { printf(" else "); } while ((c = fgetc(fp)) != EOF) { + outchars = 1; putchar(c); if (c == '}') { lev = 0; while ((c = fgetc(fp)) != EOF && isspace(c)) { assert(lev < sizeof(buf)); diff --git a/etc/lsattr.fln b/etc/lsattr.fln new file mode 100644 index 0000000..c4aab5c --- /dev/null +++ b/etc/lsattr.fln @@ -0,0 +1,16 @@ +/* This file is part of Eclat. + Copyright (C) 2013 Sergey Poznyakoff. + + Eclat is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Eclat is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ + diff --git a/src/sg-cl.opt b/src/sg-cl.opt index 7b16b44..b8a3056 100644 --- a/src/sg-cl.opt +++ b/src/sg-cl.opt @@ -26,12 +26,19 @@ END OPTION(delete,D,, [<delete rules>]) BEGIN command = "RevokeSecurityGroupIngress"; END +OPTION(list,L,, + [<list rules>]) +BEGIN + list_option = 1; + command = "DescribeSecurityGroups"; +END + OPTION(name,n,, [<ID argument is a group name>]) BEGIN dest_n = GROUP_NAME; END @@ -105,20 +112,29 @@ ECLAT_CL_END ECLAT_CL_PARSER(parse_options, [<int argc, char *argv[]>],[< { int idx; GETOPT(argc, argv, idx, exit(EX_USAGE)) if (!command) - die(EX_USAGE, "either --add or --delete must be given"); - eclat_query_add_param(env->query, "Action", command); + die(EX_USAGE, "either --list or --add or --delete must be given"); + if (list_option && + (rule_n > 1 || group_list || source_list || from_port || to_port)) + die(EX_USAGE, "conflicting options"); + argc -= idx; argv += idx; if (argc != 1) die(EX_USAGE, "bad number of arguments"); - if (group_list || source_list || from_port || to_port) - flush_rule(); - if (rule_n == 1) - die(EX_USAGE, "no rules"); translate_ids(1, argv, rt[dest_n].map); - eclat_query_add_param(query, rt[dest_n].resid, argv[0]); + eclat_query_add_param(env->query, "Action", command); + if (list_option) + describe_query_create(env, argc, argv, rt[dest_n].resid); + else { + if (group_list || source_list || from_port || to_port) + flush_rule(); + if (rule_n == 1) + die(EX_USAGE, "no rules"); + + eclat_query_add_param(query, rt[dest_n].resid, argv[0]); + } }>]) @@ -26,12 +26,13 @@ static struct { { "GroupId", MAP_GROUPID }, { "GroupName", MAP_GROUPNAME } }; static struct ec2_query *query; static char *command; +static int list_option; static int dest_n = GROUP_ID; static char *proto = "tcp"; static int rule_n = 1; static char *user; struct group_arg { |