?? fisql.c
字號:
/* Free ISQL - An isql for DB-Library (C) 2007 Nicholas S. Castellano * * This program 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. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */#if HAVE_CONFIG_H#include <config.h>#endif /* HAVE_CONFIG_H */#include <stdio.h>#include <ctype.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <setjmp.h>#include <signal.h>#ifdef HAVE_READLINE#include <readline/readline.h>#include <readline/history.h>#endif#include <sybfront.h>#include <sybdb.h>#include "terminal.h"#include "edit.h"#include "handlers.h"#include "interrupt.h"#include "replacements.h"#define READPASSPHRASE_MAXLEN 128#ifndef HAVE_READLINEstatic FILE *rl_outstream = NULL;static FILE *rl_instream = NULL;static const char *rl_readline_name = NULL;static char *fisql_readline(char *prompt){ size_t sz, pos; char *line, *p; sz = 1024; pos = 0; line = (char*) malloc(sz); if (!line) return NULL; if (prompt && prompt[0]) fprintf(rl_outstream ? rl_outstream : stdout, "%s", prompt); for (;;) { /* read a piece */ if (fgets(line + pos, sz - pos, rl_instream ? rl_instream : stdin) == NULL) { if (pos) return line; break; } /* got end-of-line ? */ p = strchr(line + pos, '\n'); if (p) { *p = 0; return line; } /* allocate space if needed */ pos += strlen(line + pos); if (pos + 1024 >= sz) { sz += 1024; p = (char*) realloc(line, sz); if (!p) break; line = p; } } free(line); return NULL;}static voidfisql_add_history(const char *s){}#define readline fisql_readline#define add_history fisql_add_history#define rl_bind_key(c,f) do {} while(0)#define rl_reset_line_state() do {} while(0)#define rl_on_new_line() do {} while(0)#endif#if !HAVE_RL_ON_NEW_LINE && !defined(rl_on_new_line)#define rl_on_new_line() do {} while(0)#endif#if !HAVE_RL_RESET_LINE_STATE && !defined(rl_reset_line_state)#define rl_reset_line_state() do {} while(0)#endifstatic void *xmalloc(size_t s);static void *xrealloc(void *p, size_t s);static int get_printable_size(int type, int size);static int get_printable_column_size(DBPROCESS * dbproc, int col);static void *xmalloc(size_t s){ void *p = malloc(s); if (!p) { fprintf(stderr, "Out of memory\n"); exit(EXIT_FAILURE); } return p;}static void *xrealloc(void *p, size_t s){ p = realloc(p, s); if (!p) { fprintf(stderr, "Out of memory\n"); exit(EXIT_FAILURE); } return p;}/* adapted from src/dblib/dblib.c (via src/apps/bsqldb.c) */static intget_printable_size(int type, int size){ switch (type) { case SYBINTN: switch (size) { case 1: return 3; case 2: return 6; case 4: return 11; case 8: return 21; } case SYBINT1: return 3; case SYBINT2: return 6; case SYBINT4: return 11; case SYBINT8: return 21; case SYBVARCHAR: case SYBCHAR: return size; case SYBFLT8: return 11; /* FIX ME -- we do not track precision */ case SYBREAL: return 11; /* FIX ME -- we do not track precision */ case SYBMONEY: return 12; /* FIX ME */ case SYBMONEY4: return 12; /* FIX ME */ case SYBDATETIME: return 26; /* FIX ME */ case SYBDATETIME4: return 26; /* FIX ME */#if 0 /* seems not to be exported to sybdb.h */ case SYBBITN:#endif case SYBBIT: return 1; /* FIX ME -- not all types present */ default: return 0; }}static intget_printable_column_size(DBPROCESS * dbproc, int col){ int collen; collen = get_printable_size(dbcoltype(dbproc, col), dbcollen(dbproc, col)); if (strlen(dbcolname(dbproc, col)) > collen) { collen = strlen(dbcolname(dbproc, col)); } return collen;}intmain(int argc, char *argv[]){ int echo = 0;#ifdef notyet int print_statistics = 0;#endif int fipsflagger = 0; int perfstats = 0; int no_prompt = 0; int use_encryption = 0; int chained_transactions = 0; const char *display_charset = ""; const char *cmdend = "go"; int headers = 0; char *columnwidth = NULL; const char *colseparator = " "; const char *lineseparator = "\n"; int timeout = 0; char *username = NULL; char *password = NULL; char *server = NULL; DBCHAR *char_set = NULL; const char *editor; char *hostname = NULL; char *sqlch; char *interfaces_filename = NULL; char *input_filename = NULL; char *output_filename = NULL; int logintime = -1; char *language = NULL; int size = 0; char *sybenv; DBPROCESS *dbproc; LOGINREC *login; char **ibuf = NULL; int ibuflines = 0; int printedlines; int i; char *line; int dbrc; char foobuf[512]; char *firstword; char *cp; int c; int errflg = 0; char *prbuf; int prbuflen; FILE *fp; FILE *tmpfp; FILE *tmpfp2; char *tfn; char tmpfn[256]; int num_cols; int selcol; int col; int collen; DBINT colid; const char *opname; char adbuf[512]; DBINT convlen; int printedcompute = 0; BYTE *bylist; int nby; char adash; editor = getenv("EDITOR"); if (!editor) { editor = getenv("VISUAL"); } if (!editor) { editor = "vi"; } opterr = 0; optarg = NULL; while (!errflg && (c = getopt(argc, argv, "eFgpnvXYa:c:E:h:H:i:I:J:l:m:o:P:s:S:t:U:w:y:z:A:")) != -1) { switch (c) { case 'e': echo = 1; break; case 'F': fipsflagger = 1; break; case 'g': errflg++; break; case 'p': errflg++; perfstats = 1; break; case 'n': no_prompt = 1; break; case 'v': puts("fisql, a free isql replacement by Nicholas S. Castellano"); exit(EXIT_SUCCESS); break; case 'X': /* XXX: We get a different error message than isql gives; neither seems * to work */ use_encryption = 1; break; case 'Y': chained_transactions = 1; break; case 'a': display_charset = optarg; errflg++; break; case 'c': cmdend = optarg; break; case 'E': editor = optarg; break; case 'h': headers = atoi(optarg); break; case 'H': hostname = optarg; break; case 'i': input_filename = optarg; break; case 'I': interfaces_filename = optarg; break; case 'J': errflg++; break; case 'l': logintime = atoi(optarg); break; case 'm': global_errorlevel = atoi(optarg); break; case 'o': output_filename = optarg; break; case 'P': password = optarg; break; case 's': colseparator = optarg; break; case 'S': server = optarg; break; case 't': timeout = atoi(optarg); break; case 'U': username = optarg; break; case 'w': columnwidth = optarg; break; case 'y': /* XXX: this doesn't seem to be what isql does with -y...it doesn't * seem to do anything actually */ sybenv = (char *) xmalloc((strlen(optarg) + 8) * sizeof(char)); strcpy(sybenv, "SYBASE="); strcat(sybenv, optarg); putenv(sybenv); break; case 'z': language = optarg; break; case 'A': size = atoi(optarg); break; default: errflg++; break; } } if (errflg) { fprintf(stderr, "usage: fisql [-e] [-F] [-g] [-p] [-n] [-v] [-X] [-Y]\n"); fprintf(stderr, "\t[-a display_charset] [-c cmdend] [-E editor]\n"); fprintf(stderr, "\t[-h headers] [-H hostname] [-i inputfile]\n"); fprintf(stderr, "\t[-I interfaces_file] [-J client character set]\n"); fprintf(stderr, "\t[-l login_timeout] [-m errorlevel]\n"); fprintf(stderr, "\t[-o outputfile]\n"); fprintf(stderr, "\t[-P password] [-s colseparator] [-S server]\n"); fprintf(stderr, "\t[-t timeout] [-U username] [-w columnwidth]\n"); fprintf(stderr, "\t[-y sybase_dir] [-z language]\n"); exit(EXIT_FAILURE);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -