Magellan Linux

Diff of /trunk/grubby/grubby.c

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

revision 3135 by niro, Tue Jul 7 11:08:26 2020 UTC revision 3136 by niro, Tue Jul 7 11:09:37 2020 UTC
# Line 3566  static void removeElement(struct singleL Line 3566  static void removeElement(struct singleL
3566   line->numElements--;   line->numElements--;
3567  }  }
3568    
3569  int argMatch(const char *one, const char *two)  static int argNameMatch(const char *one, const char *two)
3570  {  {
3571   char *first, *second;   char *first, *second;
3572   char *chptr;   char *chptra, *chptrb;
3573     int rc;
3574    
3575   first = strcpy(alloca(strlen(one) + 1), one);   first = strcpy(alloca(strlen(one) + 1), one);
3576   second = strcpy(alloca(strlen(two) + 1), two);   second = strcpy(alloca(strlen(two) + 1), two);
3577    
3578   chptr = strchr(first, '=');   chptra = strchr(first, '=');
3579   if (chptr)   if (chptra)
3580   *chptr = '\0';   *chptra = '\0';
3581    
3582     chptrb = strchr(second, '=');
3583     if (chptrb)
3584     *chptrb = '\0';
3585    
3586     rc = strcmp(first, second);
3587    
3588     if (chptra)
3589     *chptra = '=';
3590     if (chptrb)
3591     *chptrb = '=';
3592    
3593   chptr = strchr(second, '=');   return rc;
3594    }
3595    
3596    static int argHasValue(const char *arg)
3597    {
3598     char *chptr;
3599    
3600     chptr = strchr(arg, '=');
3601   if (chptr)   if (chptr)
3602   *chptr = '\0';   return 1;
3603     return 0;
3604    }
3605    
3606   return strcmp(first, second);  static int argValueMatch(const char *one, const char *two)
3607    {
3608     char *first, *second;
3609     char *chptra, *chptrb;
3610    
3611     first = strcpy(alloca(strlen(one) + 1), one);
3612     second = strcpy(alloca(strlen(two) + 1), two);
3613    
3614     chptra = strchr(first, '=');
3615     if (chptra)
3616     chptra += 1;
3617    
3618     chptrb = strchr(second, '=');
3619     if (chptrb)
3620     chptrb += 1;
3621    
3622     if (!chptra && !chptrb)
3623     return 0;
3624     else if (!chptra)
3625     return *chptrb - 0;
3626     else if (!chptrb)
3627     return 0 - *chptra;
3628     else
3629     return strcmp(chptra, chptrb);
3630  }  }
3631    
3632  int updateActualImage(struct grubConfig *cfg, const char *image,  int updateActualImage(struct grubConfig *cfg, const char *image,
# Line 3726  int updateActualImage(struct grubConfig Line 3770  int updateActualImage(struct grubConfig
3770   }   }
3771   if (usedElements[i])   if (usedElements[i])
3772   continue;   continue;
3773   if (!argMatch(line->elements[i].item, *arg)) {   if (!argNameMatch(line->elements[i].item, *arg)) {
3774   usedElements[i] = 1;   usedElements[i] = 1;
3775   break;   break;
3776   }   }
# Line 3785  int updateActualImage(struct grubConfig Line 3829  int updateActualImage(struct grubConfig
3829      !strcmp(line->elements[i].item, "--"))      !strcmp(line->elements[i].item, "--"))
3830   /* reached the end of hyper args, stop here */   /* reached the end of hyper args, stop here */
3831   break;   break;
3832   if (!argMatch(line->elements[i].item, *arg)) {   if (!argNameMatch(line->elements[i].item, *arg)) {
3833   removeElement(line, i);   if (!argHasValue(*arg) ||
3834   break;      !argValueMatch(line->elements[i].item, *arg)) {
3835     removeElement(line, i);
3836     break;
3837     }
3838   }   }
3839   }   }
3840   /* handle removing LT_ROOT line too */   /* handle removing LT_ROOT line too */

Legend:
Removed from v.3135  
changed lines
  Added in v.3136