Advertisement
Guest User

Untitled

a guest
Nov 8th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bool splitnext(char* &line, char * &name, char * &value) {
  2.     if (line == NULL || strlen(line) <= 0)
  3.         return 0;
  4.  
  5.     char * end;
  6.     while ((end = strchr(line, '\n')) != NULL || strlen(line) > 0 && (end = line + strlen(line))) { // search '\n' or end of file
  7.         char * fext = new char[end - line + 1];
  8.         strncpy(fext, line, end - line);
  9.         fext[end - line] = '\0';
  10.  
  11.         char * r;
  12.         if ((r = strchr(fext, '=')) != NULL) { // search ' = ' and split by name and value
  13.             int len = (r - fext);
  14.             name = new char[len + 1];
  15.             value = new char[strlen(fext) - len];
  16.  
  17.             strncpy(name, fext, len);
  18.             strncpy(value, r + 1, strlen(fext) - len - 1);
  19.  
  20.             name[len] = '\0';
  21.             value[strlen(fext) - len - 1] = '\0';
  22.  
  23.             line = end + 1;
  24.             free(fext);
  25.             return true;
  26.         }
  27.  
  28.         line = end + 1;
  29.         free(fext);
  30.     }
  31.  
  32.     return false;
  33. }
  34.  
  35. /*****/
  36.  
  37. /* Parse settings */
  38. char * name = NULL, *value = NULL;
  39. while (splitnext(buff, name, value)) {
  40.     if (strcmp(name, "width") == 0)
  41.         width = atoi(value);
  42.     else if (strcmp(name, "height") == 0)
  43.         height = atoi(value);
  44.     else if (strcmp(name, "posx") == 0)
  45.         posx = atoi(value);
  46.     else if (strcmp(name, "posy") == 0)
  47.         posy = atoi(value);
  48.     else if (strcmp(name, "RGB") == 0)
  49.         hRGB = atoi(value);
  50.     else if (strcmp(name, "showCmd") == 0)
  51.         nCmdShow = atoi(value);
  52.     free(name); free(value);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement