[Refdb-cvs] CVS: refdb/src refdba.c,1.45,1.46
Status: Beta
Brought to you by:
mhoenicka
|
From: Markus H. <mho...@us...> - 2004-05-17 23:30:43
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31968 Modified Files: refdba.c Log Message: added db_type and db_encoding config variables;added type attribute to createdb() command Index: refdba.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/refdba.c,v retrieving revision 1.45 retrieving revision 1.46 diff -u -U2 -r1.45 -r1.46 --- refdba.c 1 May 2004 14:56:03 -0000 1.45 +++ refdba.c 17 May 2004 23:30:23 -0000 1.46 @@ -96,5 +96,5 @@ /*+ this array will hold the user preferences +*/ -Prefs prefs[12] = { +Prefs prefs[14] = { {"serverip", ""}, {"port", ""}, @@ -108,4 +108,6 @@ {"loglevel", ""}, {"refdblib", ""}, + {"db_type", ""}, + {"db_encoding", ""}, {"", ""} }; @@ -123,4 +125,6 @@ char log_level[PREFS_BUF_LEN] = "6"; /*+ default level up to which messages are logged (0 through 7). -1 means no logging +*/ char refdblib[PREFS_BUF_LEN] = ""; /* path to shareable files */ +char dbtype[PREFS_BUF_LEN] = "risx"; /* default database type */ +char dbencoding[PREFS_BUF_LEN] = ""; /* default database character encoding */ char confdir[_POSIX_PATH_MAX+1] = ""; /* path to the config files */ int main_argc = 0; /* save argc for commands in batch mode */ @@ -232,4 +236,6 @@ prefs[9].varvalue = log_level; prefs[10].varvalue = refdblib; + prefs[11].varvalue = dbtype; + prefs[12].varvalue = dbencoding; /* a slimy hack to detect options before we run getopt */ @@ -492,6 +498,23 @@ char outbuffer[COMMAND_INBUF_LEN] = ""; /* holds the command for the server */ char inbuffer[COMMAND_INBUF_LEN] = ""; - struct simplelistvals slvals; char scrambled_passwd[PASSWD_LENGTH*3+1] = ""; + char my_dbtype[PREFS_BUF_LEN] = ""; + char my_dbencoding[PREFS_BUF_LEN] = ""; + char *fileargs; + char *newarg; + char **inargv; /* tokens of the argument */ + int inargc = 0; /* number of tokens of the argument */ + int inargcmax; /* maximum number of tokens */ + int n_just_help = 0; + int result; + int n_opt = 0; + int n_cmdlinerror = 0; + int i; + struct simplelistvals slvals; + struct lilimem sentinel; + + sentinel.ptr_mem = NULL; + sentinel.ptr_next = NULL; + sentinel.varname[0] = '\0'; slvals.outbuffer = outbuffer; @@ -504,10 +527,111 @@ slvals.outpipe = NULL; - if (strncmp(arg, "-h", 2) == 0) { - printf("Creates new databases\nSyntax: createdb [-E encoding] [-h] {name} [name1...]\nOptions: -E set character encoding\n -h prints this mini-help\nAll other arguments are interpreted as database names\n"); - return 0; + strcpy(my_dbtype, dbtype); + strcpy(my_dbencoding, dbencoding); + + inargc = 0; + inargcmax = 10; + inargv = (char**)malloc((size_t)inargcmax*sizeof(char*)); + if (inargv == NULL) { + return 1; + } + + if (insert_lilimem(&sentinel, (void**)&inargv, "inargv")) { + return 1; + } + + /* the following is a temporary hack to allow cmdln_tokenize to work */ + newarg = (char*)malloc((size_t)(strlen(arg)+9)); + if (newarg == NULL) { + delete_all_lilimem(&sentinel); + return 1; + } + + if (insert_lilimem(&sentinel, (void**)&newarg, "newarg")) { + delete_all_lilimem(&sentinel); + return 1; + } + + strcpy(newarg, "createdb "); + strcat(newarg, arg); + + result = cmdln_tokenize(&inargc, &inargv, inargcmax, newarg); + + + if (result == 1 || result == 2) { /* memory error */ + delete_all_lilimem(&sentinel); + return 1; + } + + /* get options */ + optind = 0; + + while ((n_opt = getopt(inargc, inargv, "c:C:e:E:hi:l:L:o:O:p:qrt:T:u:vVw:")) != -1) { + switch(n_opt) { + case 'E': + strncpy(my_dbencoding, optarg, PREFS_BUF_LEN); + my_dbencoding[PREFS_BUF_LEN-1] = '\0'; + break; + case 'h': + printf("Creates new databases\nSyntax: createdb [-E encoding] [-h] [-t type] {name} [name1...]\nOptions: -E set character encoding\n -h prints this mini-help\n -t database type (risx|mods)\nAll other arguments are interpreted as database names\n"); + n_just_help++; + break; + case 't': + strncpy(my_dbtype, optarg, PREFS_BUF_LEN); + my_dbtype[PREFS_BUF_LEN-1] = '\0'; + break; + case 'c': /* fall through, has been taken care of in main() */ + case 'C': + case 'e': + case 'i': + case 'l': + case 'L': + case 'o': + case 'O': + case 'p': + case 'q': + case 'r': + case 'T': + case 'u': + case 'v': + case 'V': + case 'w': + break; + case ':': + fprintf(stderr, "missing option\n"); + n_cmdlinerror = 1; + break; + case '?': + fprintf(stderr, "unknown option\n"); + n_cmdlinerror = 1; + break; + } + } + + + /* get arguments */ +/* for (i = optind; i < inargc; i++) { */ +/* printf("argument %s\n", inargv[i]); */ +/* } */ + + if (n_cmdlinerror || n_just_help) { + delete_all_lilimem(&sentinel); + return (n_just_help) ? 0:1; + } + + fileargs = build_batchcommand(inargc, inargv, optind, "", ""); + + if (fileargs == NULL) { + delete_all_lilimem(&sentinel); + return 1; + } + + if (insert_lilimem(&sentinel, (void**)&fileargs, "fileargs")) { + delete_all_lilimem(&sentinel); + return 1; } if (connect_to_server(&slvals.n_sockfd, server_ip, port_address) != 0) { + delete_all_lilimem(&sentinel); return 1; } @@ -517,20 +641,31 @@ if (init_dialog(slvals.n_sockfd, scrambled_passwd, inbuffer)) { close(slvals.n_sockfd); + delete_all_lilimem(&sentinel); return 1; } - /* arg will contain the encoding (-E <encoding>) if specified */ - strcat(slvals.outbuffer, arg); + if (*my_dbencoding) { + strcat(slvals.outbuffer, " -E "); + strcat(slvals.outbuffer, my_dbencoding); + } + + strcat(slvals.outbuffer, " -t "); + strcat(slvals.outbuffer, my_dbtype); + strcat(slvals.outbuffer, " -u "); strcat(slvals.outbuffer, username); - if (strlen(passwd) > 0) { + if (*passwd) { strcat(slvals.outbuffer, " -w "); strcat(slvals.outbuffer, scrambled_passwd); } + strcat(slvals.outbuffer, fileargs); + getsimplelist(&slvals, 0); close(slvals.n_sockfd); + delete_all_lilimem(&sentinel); + return 0; } |