Revision 9b9a7143 conf/cf-lex.l

View differences:

conf/cf-lex.l
70 70
static struct sym_scope *conf_this_scope;
71 71

  
72 72
static int cf_hash(byte *c);
73
static struct symbol *cf_find_sym(byte *c, unsigned int h0);
73
static inline struct symbol * cf_get_sym(byte *c, uint h0);
74 74

  
75 75
linpool *cfg_mem;
76 76

  
......
194 194
	}
195 195
      k=k->next;
196 196
    }
197
  cf_lval.s = cf_find_sym(yytext, h);
197
  cf_lval.s = cf_get_sym(yytext, h);
198 198
  return SYM;
199 199
}
200 200

  
......
426 426
}
427 427

  
428 428
static struct symbol *
429
cf_new_sym(byte *c, unsigned int h)
429
cf_new_sym(byte *c, uint h0)
430 430
{
431
  uint h = h0 & (SYM_HASH_SIZE-1);
431 432
  struct symbol *s, **ht;
432 433
  int l;
433 434

  
......
449 450
}
450 451

  
451 452
static struct symbol *
452
cf_find_sym(byte *c, unsigned int h0)
453
cf_find_sym(struct config *cfg, byte *c, uint h0)
453 454
{
454
  unsigned int h = h0 & (SYM_HASH_SIZE-1);
455
  uint h = h0 & (SYM_HASH_SIZE-1);
455 456
  struct symbol *s, **ht;
456 457

  
457
  if (ht = new_config->sym_hash)
458
  if (ht = cfg->sym_hash)
458 459
    {
459 460
      for(s = ht[h]; s; s=s->next)
460 461
	if (!strcmp(s->name, c) && s->scope->active)
461 462
	  return s;
462 463
    }
463
  if (new_config->sym_fallback)
464
  if (ht = cfg->sym_fallback)
464 465
    {
465 466
      /* We know only top-level scope is active */
466
      for(s = new_config->sym_fallback[h]; s; s=s->next)
467
      for(s = ht[h]; s; s=s->next)
467 468
	if (!strcmp(s->name, c) && s->scope->active)
468 469
	  return s;
469 470
    }
470
  return cf_new_sym(c, h);
471

  
472
  return NULL;
473
}
474

  
475
static inline struct symbol *
476
cf_get_sym(byte *c, uint h0)
477
{
478
  return cf_find_sym(new_config, c, h0) ?: cf_new_sym(c, h0);
471 479
}
472 480

  
473 481
/**
474 482
 * cf_find_symbol - find a symbol by name
483
 * @cfg: specificed config
484
 * @c: symbol name
485
 *
486
 * This functions searches the symbol table in the config @cfg for a symbol of
487
 * given name. First it examines the current scope, then the second recent one
488
 * and so on until it either finds the symbol and returns a pointer to its
489
 * &symbol structure or reaches the end of the scope chain and returns %NULL to
490
 * signify no match.
491
 */
492
struct symbol *
493
cf_find_symbol(struct config *cfg, byte *c)
494
{
495
  return cf_find_sym(cfg, c, cf_hash(c));
496
}
497

  
498
/**
499
 * cf_get_symbol - get a symbol by name
475 500
 * @c: symbol name
476 501
 *
477
 * This functions searches the symbol table for a symbol of given
478
 * name. First it examines the current scope, then the second recent
479
 * one and so on until it either finds the symbol and returns a pointer
480
 * to its &symbol structure or reaches the end of the scope chain
481
 * and returns %NULL to signify no match.
502
 * This functions searches the symbol table of the currently parsed config
503
 * (@new_config) for a symbol of given name. It returns either the already
504
 * existing symbol or a newly allocated undefined (%SYM_VOID) symbol if no
505
 * existing symbol is found.
482 506
 */
483 507
struct symbol *
484
cf_find_symbol(byte *c)
508
cf_get_symbol(byte *c)
485 509
{
486
  return cf_find_sym(c, cf_hash(c));
510
  return cf_get_sym(c, cf_hash(c));
487 511
}
488 512

  
489 513
struct symbol *
490 514
cf_default_name(char *template, int *counter)
491 515
{
492
  char buf[32];
516
  char buf[SYM_MAX_LEN];
493 517
  struct symbol *s;
494 518
  char *perc = strchr(template, '%');
495 519

  
496 520
  for(;;)
497 521
    {
498 522
      bsprintf(buf, template, ++(*counter));
499
      s = cf_find_sym(buf, cf_hash(buf));
500
      if (!s)
501
	break;
523
      s = cf_get_sym(buf, cf_hash(buf));
502 524
      if (s->class == SYM_VOID)
503 525
	return s;
504 526
      if (!perc)
......
529 551
    {
530 552
      if (sym->scope == conf_this_scope)
531 553
	cf_error("Symbol already defined");
532
      sym = cf_new_sym(sym->name, cf_hash(sym->name) & (SYM_HASH_SIZE-1));
554
      sym = cf_new_sym(sym->name, cf_hash(sym->name));
533 555
    }
534 556
  sym->class = type;
535 557
  sym->def = def;

Also available in: Unified diff