dbquery

Query RDBMS and return S-expression
git clone https://logand.com/git/dbquery.git/
Log | Files | Refs | README

commit c24d9558e84d073b7fe2f1783b2b4fd17e629220
parent 7c47fc3ec32c8859f26e70d907c8ffdee53f24cb
Author: Tomas Hlavaty <tom@logand.com>
Date:   Tue,  5 Mar 2013 22:42:31 +0100

forgot to commit common.c

Diffstat:
Acommon.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+), 0 deletions(-)

diff --git a/common.c b/common.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 2013 Tomas Hlavaty <tom@logand.com> + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> + +#define BLEN 4096 + +void query(char *q); + +void die(const char *format, ...) { + va_list argv; + va_start(argv, format); + vfprintf(stderr, format, argv); + va_end(argv); + fprintf(stderr, "\n"); + fflush(stderr); + exit(-1); +} + +void repl() { + for(; !feof(stdin);) { + char buf[BLEN]; + if(!fgets(buf, BLEN, stdin)) break; + query(buf); + } +}