Magellan Linux

Diff of /tags/grubby-8_10/grubby.c

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

revision 1751 by niro, Sat Feb 18 01:10:10 2012 UTC revision 1800 by niro, Mon Apr 16 17:46:40 2012 UTC
# Line 265  int sizeOfSingleLine(struct singleLine * Line 265  int sizeOfSingleLine(struct singleLine *
265    return count;    return count;
266  }  }
267    
268    static int isquote(char q)
269    {
270        if (q == '\'' || q == '\"')
271     return 1;
272        return 0;
273    }
274    
275  char *grub2ExtractTitle(struct singleLine * line) {  char *grub2ExtractTitle(struct singleLine * line) {
276      char * current;      char * current;
277      char * current_indent;      char * current_indent;
# Line 281  char *grub2ExtractTitle(struct singleLin Line 288  char *grub2ExtractTitle(struct singleLin
288      current_len = strlen(current);      current_len = strlen(current);
289    
290      /* if second word is quoted, strip the quotes and return single word */      /* if second word is quoted, strip the quotes and return single word */
291      if ((*current == '\'') && (*(current + current_len - 1) == '\'')) {      if (isquote(*current) && isquote(current[current_len - 1])) {
292        char *tmp;   char *tmp;
293    
294        tmp = strdup(current);   tmp = strdup(current);
295        *(tmp + current_len - 1) = '\0';   *(tmp + current_len - 1) = '\0';
296        return ++tmp;   return ++tmp;
297      }      }
298    
299      /* if no quotes, return second word verbatim */      /* if no quotes, return second word verbatim */
300      if (*current != '\'') {      if (!isquote(*current))
301        return current;   return current;
     }  
302    
303      /* second element start with a quote, so we have to find the element      /* second element start with a quote, so we have to find the element
304       * whose last character is also quote (assuming it's the closing one) */       * whose last character is also quote (assuming it's the closing one) */
305      if (*current == '\'') {      int resultMaxSize;
306        int resultMaxSize;      char * result;
307        char * result;      
308        resultMaxSize = sizeOfSingleLine(line);
309        resultMaxSize = sizeOfSingleLine(line);      result = malloc(resultMaxSize);
310        result = malloc(resultMaxSize);      snprintf(result, resultMaxSize, "%s", ++current);
311        snprintf(result, resultMaxSize, "%s", ++current);      
312        i++;
313        i++;      for (; i < line->numElements; ++i) {
       for (; i < line->numElements; ++i) {  
314   current = line->elements[i].item;   current = line->elements[i].item;
315   current_len = strlen(current);   current_len = strlen(current);
316   current_indent = line->elements[i].indent;   current_indent = line->elements[i].indent;
317   current_indent_len = strlen(current_indent);   current_indent_len = strlen(current_indent);
318    
319   strncat(result, current_indent, current_indent_len);   strncat(result, current_indent, current_indent_len);
320   if (*(current + current_len - 1) != '\'') {   if (!isquote(current[current_len-1])) {
321    strncat(result, current, current_len);      strncat(result, current, current_len);
322   } else {   } else {
323    strncat(result, current, current_len - 1);      strncat(result, current, current_len - 1);
324    break;      break;
325   }   }
       }  
       return result;  
326      }      }
327        return result;
     return NULL;  
328  }  }
329    
330  struct configFileInfo grub2ConfigType = {  struct configFileInfo grub2ConfigType = {
# Line 2191  void removeLine(struct singleEntry * ent Line 2193  void removeLine(struct singleEntry * ent
2193      free(line);      free(line);
2194  }  }
2195    
 static int isquote(char q)  
 {  
     if (q == '\'' || q == '\"')  
  return 1;  
     return 0;  
 }  
   
2196  static void requote(struct singleLine *tmplLine, struct configFileInfo * cfi)  static void requote(struct singleLine *tmplLine, struct configFileInfo * cfi)
2197  {  {
2198      struct singleLine newLine = {      struct singleLine newLine = {

Legend:
Removed from v.1751  
changed lines
  Added in v.1800