ref: b3e875d7db45fca0cde9f4efa12872f61afc54d7
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], "disksize") == 0){ if((c->size = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid disk 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 source config\n", service); i++; /* skip over to */ if((c->config.dest[0] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid destination config\n", service); // if((c->config.dest[1] = atoll(tokens[++i])) == 0) // panic("mafs: %s initconfig(): invalid destination config\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 source super\n", service); i++; /* skip over to */ if((c->super.dest[0] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid destination super\n", service); // if((c->super.dest[1] = atoll(tokens[++i])) == 0) // panic("mafs: %s initconfig(): invalid destination super\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 source root\n", service); i++; /* skip over to */ if((c->root.dest[0] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid destination root\n", service); // if((c->root.dest[1] = atoll(tokens[++i])) == 0) // panic("mafs: %s initconfig(): invalid destination root\n", service); }else if(strcmp(tokens[i], "service") == 0){ snprint(c->service, Servicelen,"%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; }