From 96f27792e4c3936db5513496f87a33155c9eeca3 Mon Sep 17 00:00:00 2001 From: nishi Date: Wed, 22 May 2024 00:53:24 +0000 Subject: [PATCH] adding stuff git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@59 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- Client/main.c | 16 ++++++++++++++++ Library/database.c | 14 ++++++++++++-- Library/dw_database.h | 22 +++++++++++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/Client/main.c b/Client/main.c index d7b6863..c7b221b 100644 --- a/Client/main.c +++ b/Client/main.c @@ -150,6 +150,22 @@ int main(int argc, char** argv) { printf("Quits from the CLI.\n"); padleft(16, ".version"); printf("Shows the version of DataWorks.\n"); + padleft(16, ".tables"); + printf("Shows the table list.\n"); + } else if(__dw_strcaseequ(buf, ".tables")){ + char** list = dataworks_database_get_table_list(db); + if(list != NULL){ + int i; + for(i = 0; list[i] != NULL; i++); + printf("%d tables found.\n", i); + for(i = 0; list[i] != NULL; i++){ + printf(" %s\n", list[i]); + free(list[i]); + } + free(list); + }else{ + printf("Failed to get the list.\n"); + } } else { printf("Unknown dot-command.\n"); } diff --git a/Library/database.c b/Library/database.c index 2f2a90c..98c3a19 100644 --- a/Library/database.c +++ b/Library/database.c @@ -40,7 +40,6 @@ const char sig[3] = {0x7f, 'D', 'W'}; #ifdef M_I86 #define BUFSIZE 128 -#else #endif int dataworks_database_create(const char* fname) { @@ -60,7 +59,7 @@ int dataworks_database_create(const char* fname) { fwrite(nul, 1, 2, f); int64_t t = time(NULL); __dw_big_endian(t, int64_t, fwrite(__converted_ptr, 1, 8, f)); - for(i = 0; i < 16; i++) nul[i] = 0; + for(i = 0; i < sizeof(nul); i++) nul[i] = 0; for(i = 0; i < 256; i++) { fwrite(nul, 1, 1, f); fwrite(nul, 1, 8, f); @@ -119,3 +118,14 @@ struct dataworks_db* dataworks_database_open(const char* fname) { int dataworks_database_get_version(struct dataworks_db* db) { return db->version; } uint64_t dataworks_database_get_mtime(struct dataworks_db* db) { return db->mtime; } + +char** dataworks_database_get_table_list(struct dataworks_db* db){ + if(db->version == 1){ + __dw_lockfile(db->fp); + fseek(db->fp, sizeof(sig) + 10, SEEK_SET); + __dw_unlockfile(db->fp); + }else{ + /* Not implemented for the version */ + return NULL; + } +} diff --git a/Library/dw_database.h b/Library/dw_database.h index 99924ba..aadb897 100644 --- a/Library/dw_database.h +++ b/Library/dw_database.h @@ -83,7 +83,18 @@ struct dataworks_db_v1_indexentry { uint8_t dbname_len; char dbname[256]; char fields[4096]; -}; +} __attribute__((__packed__)); + +/** + * @~english + * @brief infoentry for database. + * @note See \ref FORMATv1 for more info. + * + */ +struct dataworks_db_infoentry { + uint16_t version; + uint64_t mtime; +} __attribute__((__packed__)); /** * @~english @@ -124,6 +135,15 @@ int dataworks_database_get_version(struct dataworks_db* db); */ uint64_t dataworks_database_get_mtime(struct dataworks_db* db); +/** + * @~english + * @brief Get the table list of the database. + * @param db Database + * @return Table list of the databas + * + */ +char** dataworks_database_get_table_list(struct dataworks_db* db); + #ifdef __cplusplus } #endif -- 2.43.0