+1660003394 (Tue Aug 09 2022 02:03:14 GMT+0200 (Central European Summer Time))
+Improved database name system.
+
1659988523 (Mon Aug 08 2022 21:55:23 GMT+0200 (Central European Summer Time))
Minor changes.
char *normalizeStrLimit(const char *str, uint32_t *l, uint32_t limit);
+char *trimStr(const char *str, uint32_t *l);
+
+char *trimStrLimit(const char *str, uint32_t *l, uint32_t limit);
+
ssize_t strInTags(const char *tags, int n, const char *ndl, int m, char sep);
#endif
database *newDatabase(char *name){
database *db = malloc(sizeof(database));
- memcpy(db->name, name, len(name)+1);
+ uint32_t l;
+ name = trimStrLimit(name, &l, 31);
+ memcpy(db->name, name, l+1);
db->lfiles = newLtable(0);
db->ltags = newLtable(0);
db->cfiles = newCtable(0);
void debugAVLtree(node *n){
if(n != NULL){
- printf("\t\t+%" PRIu64 " -> %" PRIu64 "\n", n->h, n->i);
+ printf("\t\t+ %" PRIu64 " -> %" PRIu64 "\n", n->h, n->i);
debugAVLtree(n->left);
debugAVLtree(n->right);
}
printf("Name: %s\n", db->name);
printf("\t-lfiles: %d\n", db->lfiles->size);
for(uint64_t i = 0; i < db->lfiles->size; ++i){
- printf("\t\t+[%" PRIu64 "] %s (%" PRIu64 ")\n", i, db->lfiles->table[i], db->cfiles->table[i]);
+ printf("\t\t+ %s (%" PRIu64 ")\n", db->lfiles->table[i], db->cfiles->table[i]);
}
printf("\t-ltags: %d\n", db->ltags->size);
for(uint64_t i = 0; i < db->ltags->size; ++i){
- printf("\t\t+[%" PRIu64 "] %s (%" PRIu64 ")\n", i, db->ltags->table[i], db->ctags->table[i]);
+ printf("\t\t+ %s (%" PRIu64 ")\n", db->ltags->table[i], db->ctags->table[i]);
}
printf("\t-hfiles: %d\n", db->lfiles->size);
debugAVLtree(db->hfiles);
debugAVLtree(db->htags);
printf("\t-map: %d\n", db->map->size);
for(uint64_t i = 0; i < db->map->size; ++i){
- printf("\t\t+[%" PRIu64 "] %" PRIu64 ":%" PRIu64 "\n", i, db->map->table[i].file, db->map->table[i].tag);
+ printf("\t\t+ %" PRIu64 ":%" PRIu64 "\n", db->map->table[i].file, db->map->table[i].tag);
}
printf("\n");
}
int main(){
-
inputBuffer *in = newInputBuffer();
database *db = newDatabase("miDB");
-
-
+
addFileTag(db, "vaca.png", "naturalezas");
addFileTags(db, "terry-davis.jpg", 3, "holyC", "programmer", "very cool");
addFileTag(db, "vaca.png", "lovely");
}
- addTagFiles(db, "elemento", 2, "vaca.png", "terry-davis.jpg");
-
- printDatabase(db);
-
- debugDatabase(db);
-
-
while(0){
return nstr;
}
+// Trims trailing spaces
+char *trimStr(const char *str, uint32_t *l){
+ *l = len(str);
+ uint32_t trw = 0;
+ while(isspace(str[--(*l)]))
+ ++trw;
+ char *nstr = calloc(++(*l)+1, sizeof(char));
+ for(int i = 0; i < *l; ++i)
+ nstr[i] = str[i];
+ return nstr;
+}
+
+// Same as trimStr but with a limit (str[limit] will be equal to '\0')
+// If limit is 0, it will return NULL
+// WARNING: It allocates limit+1 characters
+char *trimStrLimit(const char *str, uint32_t *l, uint32_t limit){
+ if(limit == 0){
+ return NULL;
+ }
+ *l = len(str);
+ *l = (*l > limit) ? limit : *l;
+ uint32_t trw = 0;
+ while(isspace(str[--(*l)]))
+ ++trw;
+ char *nstr = calloc(++(*l)+1, sizeof(char));
+ for(int i = 0; i < *l; ++i)
+ nstr[i] = str[i];
+ return nstr;
+}
+
// Auxiliary function for creating a lookup table of the haystack
// table[i] will be the number of shifts right until the next
// separator when checking position i