ref: 80e6c118c65b013bde24f8b9c95881c0e3a73d3e
dir: /parseconfig.c/
#include "all.h" Config * parseconfig(s8 *cfg, Config *c) { char *tokens[128], *nl; s32 n, i; n = tokenize(cfg, tokens, 128); if(n > 128) panic("cannot read config, increase tokens size\n"); if(n == 0){ panic("nil config"); } // for(i=0; i<n; i++) // print("i %d has %s\n", i, tokens[i]); for(i = 0; i<n; i++){ if(strcmp(tokens[i], "nblocks") == 0){ if((c->nblocks = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid nblocks\n", service); }else if(strcmp(tokens[i], "size") == 0){ if((c->size = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); }else if(strcmp(tokens[i], "backup") == 0 && strcmp(tokens[i+1], "config") == 0){ i++; if((c->config.srcbno = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); i++; /* skip over to */ if((c->config.dest[0] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); // if((c->config.dest[1] = atoll(tokens[++i])) == 0) // panic("mafs: %s initconfig(): invalid size\n", service); }else if(strcmp(tokens[i], "backup") == 0 && strcmp(tokens[i+1], "super") == 0){ i++; if((c->super.srcbno = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); i++; /* skip over to */ if((c->super.dest[0] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); // if((c->super.dest[1] = atoll(tokens[++i])) == 0) // panic("mafs: %s initconfig(): invalid size\n", service); }else if(strcmp(tokens[i], "backup") == 0 && strcmp(tokens[i+1], "root") == 0){ i++; if((c->root.srcbno = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); i++; /* skip over to */ if((c->root.dest[0] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); // if((c->root.dest[1] = atoll(tokens[++i])) == 0) // panic("mafs: %s initconfig(): invalid size\n", service); }else if(strcmp(tokens[i], "service") == 0){ snprint(c->service, Namelen,"%s", tokens[++i]); if((nl=strchr(c->service, '\n')) != nil) *nl = '\0'; } } if(chatty9p > 1) dprint("config:\n" "size %llud\n" "nblocks %llud\n" "backup config %llud to %llud\n" "backup super %llud to %llud\n" "backup root %llud to %llud\n" "service %s\n", c->size, c->nblocks, c->config.srcbno, c->config.dest[0], c->super.srcbno, c->super.dest[0], c->root.srcbno, c->root.dest[0], c->service); return c; }