]> Nishi Git Mirror - dataworks.git/commitdiff
adding stuff
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 22 May 2024 00:53:24 +0000 (00:53 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 22 May 2024 00:53:24 +0000 (00:53 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@59 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

Client/main.c
Library/database.c
Library/dw_database.h

index d7b68637194c7ee03ec3bff1a0421a32121f716c..c7b221bd67f1f2bd9062a351ac1e99bb22848be1 100644 (file)
@@ -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");
                                }
index 2f2a90c2d19b35747421ad74bf18e105edaa605b..98c3a196ed7db6c71d41c0ff333baf1c657515f0 100644 (file)
@@ -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;
+       }
+}
index 99924ba33d87ecc9e0977c98509f62fa4d03dd2e..aadb897e8cb8900930aaf124663de5261138d8f8 100644 (file)
@@ -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