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");
}
#ifdef M_I86
#define BUFSIZE 128
-#else
#endif
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);
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;
+ }
+}
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
*/
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