[augeas-devel] augeas: master - * examples/fadot.c: fix formatting, no functional changes
David Lutterkort
lutter at fedoraproject.org
Fri Nov 13 19:26:34 UTC 2009
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=bef18308816a4ef81d003862811aae19d3fe68da
Commit: bef18308816a4ef81d003862811aae19d3fe68da
Parent: 5b341e15f85aaa641b165cead4428afbf5468d77
Author: David Lutterkort <lutter at redhat.com>
AuthorDate: Thu Nov 12 16:07:52 2009 -0800
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Thu Nov 12 16:25:16 2009 -0800
* examples/fadot.c: fix formatting, no functional changes
---
examples/fadot.c | 292 +++++++++++++++++++++++++++---------------------------
1 files changed, 145 insertions(+), 147 deletions(-)
diff --git a/examples/fadot.c b/examples/fadot.c
index 612e4a8..dca3f9b 100644
--- a/examples/fadot.c
+++ b/examples/fadot.c
@@ -37,179 +37,177 @@ const char *progname;
__attribute__((noreturn))
static void usage(void) {
- fprintf(stderr, "\nUsage: %s [OPTIONS] REGEXP\n", progname);
- fprintf(stderr, "Compile REGEXP and apply operation on them.\n");
- fprintf(stderr, "\nOptions:\n\n");
- fprintf(stderr, " -o OPERATION one of : show concat union intersect\n");
- fprintf(stderr, " complement minus example\n");
- fprintf(stderr, " -f DOT_FILE Path of output .dot file\n");
- fprintf(stderr, " -n do not reduce resulting finite automaton\n");
-
- exit(EXIT_FAILURE);
+ fprintf(stderr, "\nUsage: %s [OPTIONS] REGEXP\n", progname);
+ fprintf(stderr, "Compile REGEXP and apply operation on them.\n");
+ fprintf(stderr, "\nOptions:\n\n");
+ fprintf(stderr, " -o OPERATION one of : show concat union intersect\n");
+ fprintf(stderr, " complement minus example\n");
+ fprintf(stderr, " -f DOT_FILE Path of output .dot file\n");
+ fprintf(stderr, " -n do not reduce resulting finite automaton\n");
+
+ exit(EXIT_FAILURE);
}
-int main (int argc, char **argv)
-{
-
- opterr = 0;
-
- int reduce = 1;
- char *file_output = NULL;
- char *operation = NULL;
- int i;
- FILE *fd;
- int c;
- int nb_regexp = 0;
-
- progname = argv[0];
-
- while ((c = getopt (argc, argv, "nf:o:")) != -1)
- switch (c)
- {
- case 'n':
- reduce = 0;
- break;
- case 'f':
- file_output = optarg;
- break;
- case 'o':
- operation = optarg;
- break;
- case '?':
- if (optopt == 'o' || optopt == 'f')
- fprintf (stderr, "Option -%c requires an argument.\n", optopt);
- else if (isprint (optopt))
- fprintf (stderr, "Unknown option `-%c'.\n", optopt);
- else
- fprintf (stderr,
- "Unknown option character `\\x%x'.\n",
- optopt);
- usage();
- break;
- default:
- usage();
- break;
- }
-
- //printf ("reduce = %d, file_output = %s, operation = %s\n",
- // reduce, file_output, operation);
-
- if (!file_output){
- printf("\nPlease specify file output with option -f.\n");
- usage();
+int main (int argc, char **argv) {
+
+ opterr = 0;
+
+ int reduce = 1;
+ char *file_output = NULL;
+ char *operation = NULL;
+ int i;
+ FILE *fd;
+ int c;
+ int nb_regexp = 0;
+
+ progname = argv[0];
+
+ while ((c = getopt (argc, argv, "nf:o:")) != -1)
+ switch (c)
+ {
+ case 'n':
+ reduce = 0;
+ break;
+ case 'f':
+ file_output = optarg;
+ break;
+ case 'o':
+ operation = optarg;
+ break;
+ case '?':
+ if (optopt == 'o' || optopt == 'f')
+ fprintf (stderr, "Option -%c requires an argument.\n", optopt);
+ else if (isprint (optopt))
+ fprintf (stderr, "Unknown option `-%c'.\n", optopt);
+ else
+ fprintf (stderr,
+ "Unknown option character `\\x%x'.\n",
+ optopt);
+ usage();
+ break;
+ default:
+ usage();
+ break;
+ }
+
+ //printf ("reduce = %d, file_output = %s, operation = %s\n",
+ // reduce, file_output, operation);
+
+ if (!file_output) {
+ printf("\nPlease specify file output with option -f.\n");
+ usage();
+ }
+
+ if (!operation) {
+ printf("\nPlease specify an operation with option -o.\n");
+ usage();
+ }
+
+ for (i = optind; i < argc; i++) {
+ nb_regexp++;
+ }
+
+ if (nb_regexp == 0) {
+ printf("Please specify regexp to process.\n");
+ usage();
+ }
+
+ struct fa* fa_result = NULL;
+
+ if (!strcmp(operation,"show")) {
+ fa_compile(argv[optind], strlen(argv[optind]), &fa_result);
+ } else if (!strcmp(operation,"concat")) {
+
+ if (nb_regexp < 2) {
+ fprintf(stderr,"Please specify 2 or more regexp to concat");
+ return 1;
}
- if (!operation){
- printf("\nPlease specify an operation with option -o.\n");
- usage();
+ fa_result = fa_make_basic(FA_EPSILON);
+ struct fa* fa_tmp;
+ for (i = optind; i < argc; i++) {
+ fa_compile(argv[i], strlen(argv[i]), &fa_tmp);
+ fa_result = fa_concat(fa_result, fa_tmp);
}
- for (i = optind; i < argc; i++){
- nb_regexp++;
- }
+ } else if (!strcmp(operation, "union")) {
- if (nb_regexp == 0){
- printf("Please specify regexp to process.\n");
- usage();
+ if (nb_regexp < 2) {
+ fprintf(stderr,"Please specify 2 or more regexp to union");
+ return 1;
}
- struct fa* fa_result = NULL;
-
- if (!strcmp(operation,"show")){
- fa_compile(argv[optind], strlen(argv[optind]), &fa_result);
- } else if (!strcmp(operation,"concat")){
-
- if (nb_regexp < 2){
- fprintf(stderr,"Please specify 2 or more regexp to concat");
- return 1;
- }
-
- fa_result = fa_make_basic(FA_EPSILON);
- struct fa* fa_tmp;
- for (i = optind; i < argc; i++){
- fa_compile(argv[i], strlen(argv[i]), &fa_tmp);
- fa_result = fa_concat(fa_result, fa_tmp);
- }
-
- } else if (!strcmp(operation, "union")){
-
- if (nb_regexp < 2){
- fprintf(stderr,"Please specify 2 or more regexp to union");
- return 1;
- }
-
- fa_result = fa_make_basic(FA_EMPTY);
-
- struct fa* fa_tmp;
- for (i = optind; i < argc; i++){
- fa_compile(argv[i], strlen(argv[i]), &fa_tmp);
- fa_result = fa_union(fa_result, fa_tmp);
- }
+ fa_result = fa_make_basic(FA_EMPTY);
- } else if (!strcmp(operation, "intersect")){
-
- if (nb_regexp < 2){
- fprintf(stderr,"Please specify 2 or more regexp to intersect");
- return 1;
- }
+ struct fa* fa_tmp;
+ for (i = optind; i < argc; i++) {
+ fa_compile(argv[i], strlen(argv[i]), &fa_tmp);
+ fa_result = fa_union(fa_result, fa_tmp);
+ }
- fa_compile(argv[optind], strlen(argv[optind]), &fa_result);
- struct fa* fa_tmp;
+ } else if (!strcmp(operation, "intersect")) {
- for (i = optind+1; i < argc; i++){
- fa_compile(argv[i], strlen(argv[i]), &fa_tmp);
- fa_result = fa_intersect(fa_result, fa_tmp);
- }
+ if (nb_regexp < 2) {
+ fprintf(stderr,"Please specify 2 or more regexp to intersect");
+ return 1;
+ }
- } else if (!strcmp(operation, "complement")){
+ fa_compile(argv[optind], strlen(argv[optind]), &fa_result);
+ struct fa* fa_tmp;
- if (nb_regexp >= 2){
- fprintf(stderr,"Please specify one regexp to complement");
- return 1;
- }
+ for (i = optind+1; i < argc; i++) {
+ fa_compile(argv[i], strlen(argv[i]), &fa_tmp);
+ fa_result = fa_intersect(fa_result, fa_tmp);
+ }
- fa_compile(argv[optind], strlen(argv[optind]), &fa_result);
- fa_result = fa_complement(fa_result);
+ } else if (!strcmp(operation, "complement")) {
- } else if (!strcmp(operation, "minus")){
+ if (nb_regexp >= 2) {
+ fprintf(stderr,"Please specify one regexp to complement");
+ return 1;
+ }
- if (nb_regexp != 2){
- fprintf(stderr,"Please specify 2 regexp for operation minus");
- return 1;
- }
+ fa_compile(argv[optind], strlen(argv[optind]), &fa_result);
+ fa_result = fa_complement(fa_result);
- struct fa* fa_tmp1;
- struct fa* fa_tmp2;
- fa_compile(argv[optind], strlen(argv[optind]), &fa_tmp1);
- fa_compile(argv[optind+1], strlen(argv[optind+1]), &fa_tmp2);
- fa_result = fa_minus(fa_tmp1, fa_tmp2);
+ } else if (!strcmp(operation, "minus")) {
- } else if (!strcmp(operation, "example")){
+ if (nb_regexp != 2) {
+ fprintf(stderr,"Please specify 2 regexp for operation minus");
+ return 1;
+ }
- if (nb_regexp != 1){
- fprintf(stderr,"Please specify one regexp for operation example");
- return 1;
- }
+ struct fa* fa_tmp1;
+ struct fa* fa_tmp2;
+ fa_compile(argv[optind], strlen(argv[optind]), &fa_tmp1);
+ fa_compile(argv[optind+1], strlen(argv[optind+1]), &fa_tmp2);
+ fa_result = fa_minus(fa_tmp1, fa_tmp2);
- char* word = NULL;
- size_t word_len = 0;
- fa_compile(argv[optind], strlen(argv[optind]), &fa_result);
- fa_example(fa_result, &word, &word_len);
- printf("Example word = %s\n", word);
+ } else if (!strcmp(operation, "example")) {
+ if (nb_regexp != 1) {
+ fprintf(stderr,"Please specify one regexp for operation example");
+ return 1;
}
- if ((fd = fopen(file_output, "w")) == NULL) {
- fprintf(stderr, "Error while opening file %s \n", file_output);
- return 1;
- }
+ char* word = NULL;
+ size_t word_len = 0;
+ fa_compile(argv[optind], strlen(argv[optind]), &fa_result);
+ fa_example(fa_result, &word, &word_len);
+ printf("Example word = %s\n", word);
+
+ }
- if (reduce){
- fa_minimize(fa_result);
- }
+ if ((fd = fopen(file_output, "w")) == NULL) {
+ fprintf(stderr, "Error while opening file %s \n", file_output);
+ return 1;
+ }
- fa_dot(fd, fa_result);
+ if (reduce) {
+ fa_minimize(fa_result);
+ }
- return 0;
+ fa_dot(fd, fa_result);
+ return 0;
}
More information about the augeas-devel
mailing list