Magellan Linux

Diff of /trunk/grubby/grubby.c

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

revision 2980 by niro, Thu Jun 30 10:26:25 2016 UTC revision 2991 by niro, Thu Jun 30 10:34:31 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 837  static int isEntryStart(struct singleLin Line 839  static int isEntryStart(struct singleLin
839  static char * extractTitle(struct grubConfig *cfg, struct singleLine * line) {  static char * extractTitle(struct grubConfig *cfg, struct singleLine * line) {
840      /* bracketed title... let's extract it */      /* bracketed title... let's extract it */
841      char * title = NULL;      char * title = NULL;
     if (cfg->cfi == &grub2ConfigType)  
  return grub2ExtractTitle(line);  
842      if (line->type == LT_TITLE) {      if (line->type == LT_TITLE) {
843   char *tmp = line->elements[cfg->cfi->titlePosition].item;   char *tmp = line->elements[cfg->cfi->titlePosition].item;
844   if (cfg->cfi->titleBracketed) {   if (cfg->cfi->titleBracketed) {
# Line 931  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 1270  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 1286  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 1303  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 1313  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. */
# Line 4190  int addNewKernel(struct grubConfig * con Line 4212  int addNewKernel(struct grubConfig * con
4212      return 0;      return 0;
4213  }  }
4214    
 static void traceback(int signum)  
 {  
     void *array[40];  
     size_t size;  
   
     signal(SIGSEGV, SIG_DFL);  
     memset(array, '\0', sizeof (array));  
     size = backtrace(array, 40);  
   
     fprintf(stderr, "grubby received SIGSEGV!  Backtrace (%ld):\n",  
             (unsigned long)size);  
     backtrace_symbols_fd(array, size, STDERR_FILENO);  
     exit(1);  
 }  
   
4215  int main(int argc, const char ** argv) {  int main(int argc, const char ** argv) {
4216      poptContext optCon;      poptContext optCon;
4217      const char * grubConfig = NULL;      const char * grubConfig = NULL;
# Line 4347  int main(int argc, const char ** argv) { Line 4354  int main(int argc, const char ** argv) {
4354    
4355      useextlinuxmenu=0;      useextlinuxmenu=0;
4356    
     signal(SIGSEGV, traceback);  
   
4357      int i = 0;      int i = 0;
4358      for (int j = 1; j < argc; j++)      for (int j = 1; j < argc; j++)
4359   i += strlen(argv[j]) + 1;   i += strlen(argv[j]) + 1;
# Line 4426  int main(int argc, const char ** argv) { Line 4431  int main(int argc, const char ** argv) {
4431      }      }
4432    
4433      if (!cfi) {      if (!cfi) {
4434          if (grub2FindConfig(&grub2ConfigType))          if (grub2FindConfig(&grub2ConfigType)) {
4435      cfi = &grub2ConfigType;      cfi = &grub2ConfigType;
4436   else      if (envPath)
4437     cfi->envFile = envPath;
4438            } else
4439        #ifdef __ia64__        #ifdef __ia64__
4440      cfi = &eliloConfigType;      cfi = &eliloConfigType;
4441        #elif __powerpc__        #elif __powerpc__

Legend:
Removed from v.2980  
changed lines
  Added in v.2991