summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2013-12-03 13:32:12 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2013-12-03 13:32:12 (GMT)
commit5e501cf05fd1997018613304761d1104879353aa (patch) (side-by-side diff)
treefd14fa84bf80b72e8472f8451639e33501afe886
parent495c4a5cadf67b7c9b5e0c8b224f7b68c42c8da4 (diff)
downloadeclat-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.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--etc/Makefile.am9
-rw-r--r--etc/flncat.c48
-rw-r--r--etc/lsattr.fln16
-rw-r--r--src/sg-cl.opt30
-rw-r--r--src/sg.c1
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
@@ -45,6 +45,7 @@ FLNFILES=\
detach-volume.fln\
disassociate-address.fln\
get-console-output.fln\
+ lsattr.fln\
modify-instance-attribute.fln\
modify-snapshot-attribute.fln\
reboot-instances.fln\
@@ -62,11 +63,11 @@ 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
diff --git a/etc/flncat.c b/etc/flncat.c
index 0c29453..82c4086 100644
--- a/etc/flncat.c
+++ b/etc/flncat.c
@@ -19,30 +19,44 @@
#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;
}
@@ -54,6 +68,7 @@ main(int argc, char **argv)
int c;
char buf[128];
size_t lev = 0;
+ int outchars = 0;
for (i = 1; i < argc; i++) {
fp = fopen(*++argv, "r");
@@ -62,16 +77,19 @@ main(int argc, char **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;
diff --git a/etc/lsattr.fln b/etc/lsattr.fln
new file mode 100644
index 0000000..c4aab5c
--- a/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
@@ -29,6 +29,13 @@ 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
@@ -108,17 +115,26 @@ ECLAT_CL_PARSER(parse_options, [<int argc, char *argv[]>],[<
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]);
+ }
}>])
diff --git a/src/sg.c b/src/sg.c
index 8b11ed4..fc80e85 100644
--- a/src/sg.c
+++ b/src/sg.c
@@ -29,6 +29,7 @@ static struct {
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;

Return to:

Send suggestions and report system problems to the System administrator.