aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2004-06-22 11:17:05 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2004-06-22 11:17:05 +0000
commitbccef08d287455b36939b2eaf8591f8fe78dfdef (patch)
tree8d81e7b334c93516bbb6494f218f415316e36d5d /src
parentf7cdfaf7b6904f5c9cda683d99aad72acfb62457 (diff)
downloadellinika-bccef08d287455b36939b2eaf8591f8fe78dfdef.tar.gz
ellinika-bccef08d287455b36939b2eaf8591f8fe78dfdef.tar.bz2
(main): Switched to getopt_long.
git-svn-id: file:///home/puszcza/svnroot/ellinika/trunk@161 941c8c0f-9102-463b-b60b-cd22ce0e6858
Diffstat (limited to 'src')
-rw-r--r--src/main.c147
1 files changed, 127 insertions, 20 deletions
diff --git a/src/main.c b/src/main.c
index edbcef3..eea1ab4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,17 +1,44 @@
+/*
+ This file is part of Ellinika project.
+ Copyright (C) 2004 Sergey Poznyakoff
+
+ Ellinika 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 2 of the License, or
+ (at your option) any later version.
+
+ Ellinika 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 Ellinika; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
#include "trans.h"
#include <unistd.h>
+#include <getopt.h>
+
+char *sql_database; /* Database name */
+char *sql_host; /* SQL server host name */
+int sql_port = 3306; /* SQL port */
+char *sql_user; /* SQL user name */
+char *sql_password; /* Password for this user */
-char *sql_database;
-char *sql_host;
-int sql_port = 3306;
-char *sql_password;
-char *sql_user;
-int debug;
-int compile_only;
-int cleanup_flag;
-static int error_count;
-static RAD_LIST *include_list;
-static char *m4_bin = "/usr/bin/m4"; /* FIXME: Should be autoconf'ed */
+int compile_only; /* Compile input into the internal representation
+ and exit. Do not write the database */
+
+int preserve_flag; /* Preserve closed cross-reference links in
+ pending_links table. */
+int debug; /* Debug level */
+
+static int error_count; /* Number of errors encountered during compilation */
+
+static RAD_LIST *include_list; /* List of m4 include directories */
+static char *m4_bin = "/usr/bin/m4"; /* Full file name to the m4 binary.
+ FIXME: Should be autoconf'ed */
void *
emalloc(size_t size)
@@ -162,7 +189,7 @@ pending_fixup()
sql_query("UPDATE pending_links p, dict d SET p.type='CLOSED' "
"WHERE p.word = d.word");
- if (cleanup_flag)
+ if (!preserve_flag)
sql_query("DELETE FROM pending_links WHERE type = 'CLOSED'");
if (sql_query("SELECT count(*) FROM pending_links "
@@ -186,23 +213,86 @@ update_stat()
count);
}
+void
+cleanup_db()
+{
+ sql_query("DELETE FROM links");
+ sql_query("DELETE FROM articles");
+ sql_query("DELETE FROM dict");
+ sql_query("DELETE FROM topic");
+ sql_query("DELETE FROM topic_tab");
+}
+
+#define ARG_CLEANUP 256
+#define ARG_HELP 257
+#define ARG_VERSION 258
+#define ARG_PRESERVE 259
+
+struct option option[] = {
+ { "check", no_argument, 0, 'c' },
+ { "cleanup", no_argument, 0, ARG_CLEANUP },
+ { "database", required_argument, 0, 'd' },
+ { "host", required_argument, 0, 'h' },
+ { "port", required_argument, 0, 'P' },
+ { "password", required_argument, 0, 'p' },
+ { "user", required_argument, 0, 'u' },
+ { "verbose", no_argument, 0, 'v' },
+ { "include-dir", required_argument, 0, 'I' },
+ { "m4-path", required_argument, 0, 'm' },
+ { "help", no_argument, 0, ARG_HELP },
+ { "version", no_argument, 0, ARG_VERSION },
+ { NULL }
+};
+
+
+void
+usage()
+{
+ printf("usage: trans [OPTIONS] [FILE...]\n\
+\n\
+Options are:\n\
+Database location:\n\
+ -d, --database=NAME Set the database name\n\
+ -h, --host=NAME Set the host name or IP address\n\
+ -P, --port Set the port number to connect to\n\
+ -u, --user=NAME Set MySQL user name\n\
+ -p, --password=STRING Set user password\n\
+\n\
+Operation modifiers:\n\
+\n\
+ -c, --check Check input file syntax, do not modify the database\n\
+ --cleanup Clean up the database before starting the operation\n\
+ -v, --verbose Produce verbose output. The more -v you give, the\n\
+ higher verbosity level is.\n\
+ --preserve-xref Preserve closed cross references (may be useful\n\
+ for debugging)\n\
+ -I, --include-dir=DIR Append DIR to m4 include path\n\
+ -m, --m4=FILE Set full file name of the m4 executable\n\
+\n\
+Informational options:\n\
+\n\
+ --help Display this help message\n\
+ --version Display program version\n");
+ exit(0);
+}
+
+
int
main(int argc, char **argv)
{
int rc;
+ int index;
+ int cleanup_flag = 0;
- while ((rc = getopt(argc, argv, "cCd:h:I:m:P:p:u:v")) != EOF) {
+ while ((rc = getopt_long(argc, argv, "cd:h:I:m:P:p:u:v",
+ option, &index)) != EOF) {
switch (rc) {
case 'c':
compile_only = 1;
break;
- case 'C':
- cleanup_flag = 1;
- break;
-
case 'd':
sql_database = optarg;
break;
@@ -235,22 +325,39 @@ main(int argc, char **argv)
case 'm':
m4_bin = optarg;
+ break;
+
+ case ARG_PRESERVE:
+ preserve_flag = 1;
+ break;
+
+ case ARG_HELP:
+ usage();
+ break;
+
+ case ARG_VERSION:
+ printf("trans (%s)\n", PACKAGE_STRING);
+ exit(0);
}
}
make_m4_args (m4_bin, include_list);
- node_list = list_create();
sql_connect();
- argc -= optind;
- argv += optind;
+ node_list = list_create();
+
+ argc -= index;
+ argv += index;
if (parse(argc, argv) || error_count)
return 1;
if (compile_only)
return 0;
+ if (cleanup_flag)
+ cleanup_db();
+
sql_query_n(&dict_index,
"SELECT ident FROM dict ORDER BY ident DESC LIMIT 1");

Return to:

Send suggestions and report system problems to the System administrator.