Magellan Linux

Diff of /trunk/grubby/grubby.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2988 by niro, Thu Jun 30 10:30:31 2016 UTC revision 2989 by niro, Thu Jun 30 10:32:12 2016 UTC
# Line 452  char *grub2ExtractTitle(struct singleLin Line 452  char *grub2ExtractTitle(struct singleLin
452       * whose last character is also quote (assuming it's the closing one) */       * whose last character is also quote (assuming it's the closing one) */
453      int resultMaxSize;      int resultMaxSize;
454      char * result;      char * result;
455        /* need to ensure that ' does not match " as we search */
456        char quote_char = *current;
457            
458      resultMaxSize = sizeOfSingleLine(line);      resultMaxSize = sizeOfSingleLine(line);
459      result = malloc(resultMaxSize);      result = malloc(resultMaxSize);
# Line 465  char *grub2ExtractTitle(struct singleLin Line 467  char *grub2ExtractTitle(struct singleLin
467   current_indent_len = strlen(current_indent);   current_indent_len = strlen(current_indent);
468    
469   strncat(result, current_indent, current_indent_len);   strncat(result, current_indent, current_indent_len);
470   if (!isquote(current[current_len-1])) {   if (current[current_len-1] != quote_char) {
471      strncat(result, current, current_len);      strncat(result, current, current_len);
472   } else {   } else {
473      strncat(result, current, current_len - 1);      strncat(result, current, current_len - 1);
# Line 929  static int lineWrite(FILE * out, struct Line 931  static int lineWrite(FILE * out, struct
931   /* Need to handle this, because we strip the quotes from   /* Need to handle this, because we strip the quotes from
932   * menuentry when read it. */   * menuentry when read it. */
933   if (line->type == LT_MENUENTRY && i == 1) {   if (line->type == LT_MENUENTRY && i == 1) {
934      if(!isquote(*line->elements[i].item))      if(!isquote(*line->elements[i].item)) {
935   fprintf(out, "\'%s\'", line->elements[i].item);   int substring = 0;
936      else   /* If the line contains nested quotes, we did not strip
937     * the "interna" quotes and we must use the right quotes
938     * again when writing the updated file. */
939     for (int j = i; j < line->numElements; j++) {
940        if (strchr(line->elements[i].item, '\'') != NULL) {
941           substring = 1;
942           fprintf(out, "\"%s\"", line->elements[i].item);
943           break;
944        }
945     }
946     if (!substring)
947        fprintf(out, "\'%s\'", line->elements[i].item);
948        } else {
949   fprintf(out, "%s", line->elements[i].item);   fprintf(out, "%s", line->elements[i].item);
950        }
951      fprintf(out, "%s", line->elements[i].indent);      fprintf(out, "%s", line->elements[i].indent);
952    
953      continue;      continue;
# Line 1268  static struct grubConfig * readConfig(co Line 1283  static struct grubConfig * readConfig(co
1283      len = 0;      len = 0;
1284      char *extras;      char *extras;
1285      char *title;      char *title;
1286        /* initially unseen value */
1287        char quote_char = '\0';
1288    
1289      for (int i = 1; i < line->numElements; i++) {      for (int i = 1; i < line->numElements; i++) {
1290   len += strlen(line->elements[i].item);   len += strlen(line->elements[i].item);
# Line 1284  static struct grubConfig * readConfig(co Line 1301  static struct grubConfig * readConfig(co
1301      for (int i = 0; i < line->numElements; i++) {      for (int i = 0; i < line->numElements; i++) {
1302   if (!strcmp(line->elements[i].item, "menuentry"))   if (!strcmp(line->elements[i].item, "menuentry"))
1303      continue;      continue;
1304   if (isquote(*line->elements[i].item))   if (isquote(*line->elements[i].item) && quote_char == '\0') {
1305        /* ensure we properly pair off quotes */
1306        quote_char = *line->elements[i].item;
1307      title = line->elements[i].item + 1;      title = line->elements[i].item + 1;
1308   else   } else {
1309      title = line->elements[i].item;      title = line->elements[i].item;
1310     }
1311    
1312   len = strlen(title);   len = strlen(title);
1313          if (isquote(title[len-1])) {          if (title[len-1] == quote_char) {
1314      strncat(buf, title,len-1);      strncat(buf, title,len-1);
1315      break;      break;
1316   } else {   } else {
# Line 1301  static struct grubConfig * readConfig(co Line 1321  static struct grubConfig * readConfig(co
1321    
1322      /* get extras */      /* get extras */
1323      int count = 0;      int count = 0;
1324        quote_char = '\0';
1325      for (int i = 0; i < line->numElements; i++) {      for (int i = 0; i < line->numElements; i++) {
1326   if (count >= 2) {   if (count >= 2) {
1327      strcat(extras, line->elements[i].item);      strcat(extras, line->elements[i].item);
# Line 1311  static struct grubConfig * readConfig(co Line 1332  static struct grubConfig * readConfig(co
1332      continue;      continue;
1333    
1334   /* count ' or ", there should be two in menuentry line. */   /* count ' or ", there should be two in menuentry line. */
1335   if (isquote(*line->elements[i].item))   if (isquote(*line->elements[i].item) && quote_char == '\0') {
1336        /* ensure we properly pair off quotes */
1337                quote_char = *line->elements[i].item;
1338      count++;      count++;
1339     }
1340    
1341   len = strlen(line->elements[i].item);   len = strlen(line->elements[i].item);
1342    
1343   if (isquote(line->elements[i].item[len -1]))   if (line->elements[i].item[len -1] == quote_char)
1344      count++;      count++;
1345    
1346   /* ok, we get the final ' or ", others are extras. */   /* ok, we get the final ' or ", others are extras. */

Legend:
Removed from v.2988  
changed lines
  Added in v.2989