~ubuntu-branches/ubuntu/oneiric/yaboot/oneiric

« back to all changes in this revision

Viewing changes to second/cfg.c

  • Committer: Luke Yelavich
  • Date: 2011-02-19 11:26:19 UTC
  • mfrom: (2.1.4 sid)
  • Revision ID: luke.yelavich@canonical.com-20110219112619-y8ltekbrr68xod37
Merge with Debian unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
/* Imported functions */
30
30
extern int strcasecmp(const char *s1, const char *s2);
31
31
extern int strncasecmp(const char *cs, const char *ct, size_t n);
 
32
extern char bootoncelabel[1024];
32
33
 
33
34
typedef enum {
34
35
     cft_strg, cft_flag, cft_end
40
41
     void *data;
41
42
} CONFIG;
42
43
 
43
 
#define MAX_TOKEN 200
 
44
#define MAX_TOKEN 511
44
45
#define MAX_VAR_NAME MAX_TOKEN
45
46
#define EOF -1
46
47
 
421
422
     return 0;
422
423
}
423
424
 
 
425
static int cfg_reset ()
 
426
{
 
427
    CONFIG *walk;
 
428
#if DEBUG
 
429
    prom_printf("Resetting image table\n");
 
430
#endif
 
431
    line_num = 0;
 
432
    images = NULL;
 
433
    curr_table = NULL;
 
434
    curr_table = cf_options;
 
435
    for (walk = curr_table; walk->type != cft_end; walk++) {
 
436
#if DEBUG
 
437
        prom_printf("ItemA %s = %s\n", walk->name, walk->data);
 
438
#endif
 
439
        if (walk->data != NULL)
 
440
            walk->data = NULL;
 
441
#if DEBUG
 
442
        prom_printf("ItemB %s = %s\n\n", walk->name, walk->data);
 
443
#endif
 
444
    }
 
445
 
 
446
    return 0;
 
447
}
 
448
 
424
449
int cfg_parse (char *cfg_file, char *buff, int len)
425
450
{
426
451
     char *item, *value;
429
454
     currp = buff;
430
455
     endp = currp + len;
431
456
 
 
457
     cfg_reset();
 
458
 
432
459
     if (setjmp (env))
433
460
          return -1;
434
461
     while (1) {
436
463
               return 0;
437
464
          if (!cfg_set (item, value)) {
438
465
#if DEBUG
439
 
              prom_printf("Can't set item %s to value %s\n", item, value);
 
466
               prom_printf("Can't set item %s to value %s\n", item, value);
440
467
#endif
441
468
          }
442
469
          free (item);
482
509
static void printlabel (char *label, int defflag)
483
510
{
484
511
     int len = strlen (label);
 
512
     char a = ' ';
485
513
 
486
514
     if (!printl_count)
487
515
          prom_printf ("\n");
488
 
     prom_printf ("%s %s",defflag?"*":" ", label);
 
516
     switch (defflag) {
 
517
          case 1:  a='*'; break;
 
518
          case 2:  a='&'; break;
 
519
          default: a=' '; break;
 
520
     }
 
521
     prom_printf ("%c %s", a, label);
489
522
     while (len++ < 25)
490
523
          prom_putchar (' ');
491
524
     printl_count++;
513
546
               if (alias)
514
547
                    label = alias + 1;
515
548
          }
516
 
          if(!strcmp(ret,label))
 
549
          if(!strcmp(bootoncelabel,label))
 
550
               defflag=2;
 
551
          else if(!strcmp(ret,label))
517
552
               defflag=1;
518
553
          else
519
554
               defflag=0;
550
585
     return ret;
551
586
}
552
587
 
553
 
/* 
 
588
/*
 
589
 * cfg_set_default_by_mac ()
 
590
 * return 1 if the default cf_option was changed to label with the MAC addr
 
591
 * return 0 if not changed
 
592
 */
 
593
int cfg_set_default_by_mac (char *mac_addr)
 
594
{
 
595
     CONFIG *walk;
 
596
     struct IMAGES *tmp;
 
597
     char * label = NULL;
 
598
     int haslabel = 0;
 
599
 
 
600
     /* check if there is an image label equal to mac_addr */
 
601
     for (tmp = images; tmp; tmp = tmp->next) {
 
602
        label = cfg_get_strg_i (tmp->table, "label");
 
603
        if (!strcmp(label,mac_addr)){
 
604
            haslabel = 1;
 
605
        }
 
606
     }
 
607
 
 
608
     if (!haslabel)
 
609
         return 0;
 
610
     else {
 
611
         /*
 
612
          * if there is an image label equal to mac_addr, change the default
 
613
          * cf_options to this image label
 
614
          */
 
615
         for (walk = cf_options; walk->type != cft_end; walk++) {
 
616
             if (!strcasecmp(walk->name,"default")) {
 
617
                 walk->data = mac_addr;
 
618
                 return 1;
 
619
             }
 
620
         }
 
621
         return 0;
 
622
     }
 
623
}
 
624
 
 
625
/*
554
626
 * Local variables:
555
627
 * c-file-style: "k&r"
556
628
 * c-basic-offset: 5