Rename the tool to "database"

This commit is contained in:
Pierre Pronchery 2019-09-01 03:30:08 +02:00
parent 34a835f967
commit 58d5635958
2 changed files with 33 additions and 27 deletions

View File

@ -21,36 +21,37 @@
#include "Database.h" #include "Database.h"
#ifndef PROGNAME #ifndef PROGNAME
# define PROGNAME "client" # define PROGNAME "database"
#endif #endif
/* client */ /* database */
/* private */ /* private */
/* types */ /* types */
typedef struct _Client typedef struct _DatabaseFile
{ {
FILE * fp; FILE * fp;
int first; int first;
int rows; int rows;
} Client; } DatabaseFile;
/* prototypes */ /* prototypes */
static int _client(char const * engine, char const * cfile, static int _database(char const * engine, char const * cfile,
char const * section); char const * section);
static int _usage(void); static int _usage(void);
/* functions */ /* functions */
/* client */ /* database */
static int _client_print(void * data, int argc, char ** argv, char ** columns); static int _database_print(void * data, int argc, char ** argv,
char ** columns);
static int _client(char const * engine, char const * cfile, static int _database(char const * engine, char const * cfile,
char const * section) char const * section)
{ {
Client client; DatabaseFile database;
Config * config; Config * config;
Database * db; Database * db;
char buf[BUFSIZ]; char buf[BUFSIZ];
@ -69,41 +70,41 @@ static int _client(char const * engine, char const * cfile,
config_delete(config); config_delete(config);
return 2; return 2;
} }
client.fp = stdout; database.fp = stdout;
while(fgets(buf, sizeof(buf), stdin) != NULL) while(fgets(buf, sizeof(buf), stdin) != NULL)
{ {
client.first = 1; database.first = 1;
client.rows = 0; database.rows = 0;
/* XXX it may not have picked a complete line */ /* XXX it may not have picked a complete line */
if(database_query(db, buf, _client_print, &client) != 0) if(database_query(db, buf, _database_print, &database) != 0)
{ {
error_print(PROGNAME); error_print(PROGNAME);
continue; continue;
} }
fprintf(client.fp, "(%u rows)\n", client.rows); fprintf(database.fp, "(%u rows)\n", database.rows);
} }
database_delete(db); database_delete(db);
return 0; return 0;
} }
static int _client_print(void * data, int argc, char ** argv, char ** columns) static int _database_print(void * data, int argc, char ** argv, char ** columns)
{ {
Client * client = data; DatabaseFile * database = data;
int i; int i;
client->rows++; database->rows++;
if(argc == 0) if(argc == 0)
return 0; return 0;
if(client->first != 0) if(database->first != 0)
{ {
client->first = 0; database->first = 0;
for(i = 0; i < argc; i++) for(i = 0; i < argc; i++)
fprintf(client->fp, "|%s", columns[i]); fprintf(database->fp, "|%s", columns[i]);
fputs("|\n", client->fp); fputs("|\n", database->fp);
} }
for(i = 0; i < argc; i++) for(i = 0; i < argc; i++)
fprintf(client->fp, "|%s", argv[i]); fprintf(database->fp, "|%s", argv[i]);
fputs("|\n", client->fp); fputs("|\n", database->fp);
return 0; return 0;
} }
@ -147,5 +148,5 @@ int main(int argc, char * argv[])
} }
if(engine == NULL || optind != argc) if(engine == NULL || optind != argc)
return _usage(); return _usage();
return (_client(engine, cfile, section) == 0) ? 0 : 2; return (_database(engine, cfile, section) == 0) ? 0 : 2;
} }

View File

@ -1,4 +1,4 @@
targets=client targets=database
cppflags_force=-I ../include cppflags_force=-I ../include
cflags_force=`pkg-config --cflags libSystem` cflags_force=`pkg-config --cflags libSystem`
cflags=-W -Wall -g -O2 -pedantic -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector-all cflags=-W -Wall -g -O2 -pedantic -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector-all
@ -6,6 +6,11 @@ ldflags_force=`pkg-config --libs libSystem` -L$(OBJDIR)../src -Wl,-rpath,../src
ldflags=-pie -Wl,-z,relro -Wl,-z,now ldflags=-pie -Wl,-z,relro -Wl,-z,now
dist=Makefile dist=Makefile
[client] #targets
[database]
type=binary type=binary
sources=client.c sources=database.c
#sources
[database.c]
depends=../include/Database.h,../include/Database/database.h,../include/Database/engine.h,../include/Database/statement.h