Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool splitnext(char* &line, char * &name, char * &value) {
- if (line == NULL || strlen(line) <= 0)
- return 0;
- char * end;
- while ((end = strchr(line, '\n')) != NULL || strlen(line) > 0 && (end = line + strlen(line))) { // search '\n' or end of file
- char * fext = new char[end - line + 1];
- strncpy(fext, line, end - line);
- fext[end - line] = '\0';
- char * r;
- if ((r = strchr(fext, '=')) != NULL) { // search ' = ' and split by name and value
- int len = (r - fext);
- name = new char[len + 1];
- value = new char[strlen(fext) - len];
- strncpy(name, fext, len);
- strncpy(value, r + 1, strlen(fext) - len - 1);
- name[len] = '\0';
- value[strlen(fext) - len - 1] = '\0';
- line = end + 1;
- free(fext);
- return true;
- }
- line = end + 1;
- free(fext);
- }
- return false;
- }
- /*****/
- /* Parse settings */
- char * name = NULL, *value = NULL;
- while (splitnext(buff, name, value)) {
- if (strcmp(name, "width") == 0)
- width = atoi(value);
- else if (strcmp(name, "height") == 0)
- height = atoi(value);
- else if (strcmp(name, "posx") == 0)
- posx = atoi(value);
- else if (strcmp(name, "posy") == 0)
- posy = atoi(value);
- else if (strcmp(name, "RGB") == 0)
- hRGB = atoi(value);
- else if (strcmp(name, "showCmd") == 0)
- nCmdShow = atoi(value);
- free(name); free(value);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement