summaryrefslogtreecommitdiffstats
path: root/mdk-stage1
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2002-02-20 20:27:51 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2002-02-20 20:27:51 +0000
commit37cffbcd7e0b1c48acceabab06b5beaa51393dfa (patch)
tree18c7dd177ec88e6beb7fa1fdeda4e15e6b8b2eb1 /mdk-stage1
parent48351d9a571b78326a6807029fcfa4e3d6ae9326 (diff)
downloaddrakx-37cffbcd7e0b1c48acceabab06b5beaa51393dfa.tar
drakx-37cffbcd7e0b1c48acceabab06b5beaa51393dfa.tar.gz
drakx-37cffbcd7e0b1c48acceabab06b5beaa51393dfa.tar.bz2
drakx-37cffbcd7e0b1c48acceabab06b5beaa51393dfa.tar.xz
drakx-37cffbcd7e0b1c48acceabab06b5beaa51393dfa.zip
add an example on modules with options
Diffstat (limited to 'mdk-stage1')
-rw-r--r--mdk-stage1/doc/UPDATEMODULES10
1 files changed, 7 insertions, 3 deletions
diff --git a/mdk-stage1/doc/UPDATEMODULES b/mdk-stage1/doc/UPDATEMODULES
index 4a4a42178..89d86d365 100644
--- a/mdk-stage1/doc/UPDATEMODULES
+++ b/mdk-stage1/doc/UPDATEMODULES
@@ -52,6 +52,8 @@ fat
# updated msdos (handling of 9+4 filenames)
msdos
ppa
+# ISA network card needing options
+ne io=0x300 irq=7
[root@obiwan mnt]#
--=----=----=----=----=----=----=----=----=--
@@ -62,9 +64,11 @@ ppa
b- fat loaded from the marfile on the boot floppy
c- msdos loaded from the update modules floppy
d- ppa loaded from the update modules floppy
+ e- ne loaded from the marfile on the boot floppy
-Beware, the dependencies are not handled automatically in the case of load
-from the update modules floppy, that's why on our example we need to load
-"fat" from the standard modules before "msdos" from the update floppy.
+!!! Beware !!!, the dependencies are not handled automatically in
+the case of load from the update modules floppy, that's why on
+our example we need to load "fat" from the standard modules
+before "msdos" from the update floppy.
04' href='#n204'>204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
/* Copyright (c) 1998, 1999, 2001 John E. Davis
 * This file is part of the S-Lang library.
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Perl Artistic License.
 */
#include "slinclud.h"

#define SL_APP_WANTS_FOREACH
#include "slang.h"
#include "_slang.h"

#define USE_NEW_ANYTYPE_CODE 1

typedef struct _SLAssoc_Array_Element_Type
{
   char *key;		       /* slstring */
   struct _SLAssoc_Array_Element_Type *next;
   SLang_Object_Type value;
}
_SLAssoc_Array_Element_Type;

typedef struct
{
   _SLAssoc_Array_Element_Type *elements[SLASSOC_HASH_TABLE_SIZE];
   SLang_Object_Type default_value;
   unsigned int num_elements;
#define HAS_DEFAULT_VALUE	1
   unsigned int flags;
   unsigned char type;
}
SLang_Assoc_Array_Type;

#define USE_CACHED_STRING	1

#if USE_CACHED_STRING 
static char *Cached_String;
static SLang_Object_Type *Cached_Obj;
static SLang_Assoc_Array_Type *Cached_Array;
#endif

static SLang_Assoc_Array_Type *alloc_assoc_array (unsigned char type, int has_default_value)
{
   SLang_Assoc_Array_Type *a;

   a = (SLang_Assoc_Array_Type *)SLmalloc (sizeof (SLang_Assoc_Array_Type));
   if (a == NULL)
     {
	if (has_default_value)
	  SLdo_pop_n (1);
	return NULL;
     }

   memset ((char *) a, 0, sizeof (SLang_Assoc_Array_Type));
   a->type = type;

   if (has_default_value)
     {
	if (
#if USE_NEW_ANYTYPE_CODE
	    ((type != SLANG_ANY_TYPE) && (-1 == SLclass_typecast (type, 1, 1)))
#else
	    (-1 == SLclass_typecast (type, 1, 1))
#endif
	    || (-1 == SLang_pop (&a->default_value)))
	  {
	     SLfree ((char *) a);
	     return NULL;
	  }

	a->flags |= HAS_DEFAULT_VALUE;
     }
   return a;
}

static void free_element (_SLAssoc_Array_Element_Type *e)
{
   if (e == NULL)
     return;

   SLang_free_object (&e->value);
   SLang_free_slstring (e->key);
#if USE_CACHED_STRING
   if (e->key == Cached_String)
     Cached_String = NULL;
#endif
   SLfree ((char *)e);
}

static void delete_assoc_array (SLang_Assoc_Array_Type *a)
{
   unsigned int i;

   if (a == NULL) return;

   for (i = 0; i < SLASSOC_HASH_TABLE_SIZE; i++)
     {
	_SLAssoc_Array_Element_Type *e;

	e = a->elements[i];
	while (e != NULL)
	  {
	     _SLAssoc_Array_Element_Type *next_e;

	     next_e = e->next;
	     free_element (e);
	     e = next_e;
	  }
     }
   if (a->flags & HAS_DEFAULT_VALUE)
     SLang_free_object (&a->default_value);

   SLfree ((char *) a);
}

_INLINE_
static SLang_Object_Type *
find_element (SLang_Assoc_Array_Type *a, char *str, unsigned long hash)
{
   unsigned int h;
   _SLAssoc_Array_Element_Type *e;

   h = (unsigned int) (hash % SLASSOC_HASH_TABLE_SIZE);
   e = a->elements[h];

   while (e != NULL)
     {
	if (str == e->key)       /* slstrings can be compared this way */
	  {
#if USE_CACHED_STRING
	     Cached_String = str;
	     Cached_Obj = &e->value;
	     Cached_Array = a;
#endif
	     return &e->value;
	  }

	e = e->next;
     }

   return NULL;
}

static _SLAssoc_Array_Element_Type *
create_element (SLang_Assoc_Array_Type *a, char *str, unsigned long hash)
{
   unsigned int h;
   _SLAssoc_Array_Element_Type *e;

   e = (_SLAssoc_Array_Element_Type *) SLmalloc (sizeof (_SLAssoc_Array_Element_Type));
   if (e == NULL)
     return NULL;

   memset ((char *) e, 0, sizeof (_SLAssoc_Array_Element_Type));
   h = (unsigned int) (hash % SLASSOC_HASH_TABLE_SIZE);

   if (NULL == (str = _SLstring_dup_hashed_string (str, hash)))
     {
	SLfree ((char *) e);
	return NULL;
     }

   e->key = str;
   e->next = a->elements[h];
   a->elements[h] = e;

   a->num_elements += 1;
#if USE_CACHED_STRING
   Cached_String = str;
   Cached_Obj = &e->value;
   Cached_Array = a;
#endif
   return e;
}

static int store_object (SLang_Assoc_Array_Type *a, char *s, SLang_Object_Type *obj)
{
   unsigned long hash;
   SLang_Object_Type *v;

#if USE_CACHED_STRING
   if ((s == Cached_String) && (a == Cached_Array))
     {
	v = Cached_Obj;
	SLang_free_object (v);
     }
   else
     {
#endif
	hash = _SLcompute_string_hash (s);
	if (NULL != (v = find_element (a, s, hash)))
	  SLang_free_object (v);
	else
	  {
	     _SLAssoc_Array_Element_Type *e;
	     
	     e = create_element (a, s, hash);
	     if (e == NULL)
	       return -1;
	     
	     v = &e->value;
	  }
#if USE_CACHED_STRING
     }
#endif

   *v = *obj;

   return 0;
}

static void assoc_destroy (unsigned char type, VOID_STAR ptr)
{
   (void) type;
   delete_assoc_array ((SLang_Assoc_Array_Type *) ptr);
}

static int pop_index (unsigned int num_indices,
		      SLang_MMT_Type **mmt,
		      SLang_Assoc_Array_Type **a,
		      char **str)
{
   if (NULL == (*mmt = SLang_pop_mmt (SLANG_ASSOC_TYPE)))
     {
	*a = NULL;
	*str = NULL;
	return -1;
     }

   if ((num_indices != 1)
       || (-1 == SLang_pop_slstring (str)))
     {
	SLang_verror (SL_NOT_IMPLEMENTED,
		      "Assoc_Type arrays require a single string index");
	SLang_free_mmt (*mmt);
	*mmt = NULL;
	*a = NULL;
	*str = NULL;
	return -1;
     }

   *a = (SLang_Assoc_Array_Type *) SLang_object_from_mmt (*mmt);
   return 0;
}

static int assoc_aget (unsigned char type, unsigned int num_indices)
{
   SLang_MMT_Type *mmt;
   char *str;
   SLang_Assoc_Array_Type *a;
   SLang_Object_Type *obj;
   int ret;

   (void) type;

   if (-1 == pop_index (num_indices, &mmt, &a, &str))
     return -1;

#if USE_CACHED_STRING
   if ((str == Cached_String) && (a == Cached_Array))
     obj = Cached_Obj;
   else
#endif
     obj = find_element (a, str, _SLcompute_string_hash (str));

   if ((obj == NULL)
       && (a->flags & HAS_DEFAULT_VALUE))
     obj = &a->default_value;

   if (obj == NULL)
     {
	SLang_verror (SL_INTRINSIC_ERROR,
		      "No such element in Assoc Array: %s", str);
	ret = -1;
     }
   else
     {
#if _SLANG_OPTIMIZE_FOR_SPEED
	if (SLANG_CLASS_TYPE_SCALAR == _SLclass_Class_Type[obj->data_type])
	  ret = SLang_push (obj);
#endif
	else
	  ret = _SLpush_slang_obj (obj);
     }

   SLang_free_slstring (str);
   SLang_free_mmt (mmt);
   return ret;
}

static int assoc_aput (unsigned char type, unsigned int num_indices)
{
   SLang_MMT_Type *mmt;
   char *str;
   SLang_Assoc_Array_Type *a;
   SLang_Object_Type obj;
   int ret;

   (void) type;

   if (-1 == pop_index (num_indices, &mmt, &a, &str))
     return -1;

   ret = -1;

   if (0 == SLang_pop (&obj))
     {
	if ((obj.data_type != a->type)
#if USE_NEW_ANYTYPE_CODE
	    && (a->type != SLANG_ANY_TYPE)
#endif
	    )
	  {
	     (void) SLang_push (&obj);
	     if ((-1 == SLclass_typecast (a->type, 1, 1))
		 || (-1 == SLang_pop (&obj)))
	       goto the_return;
	  }
	
	if (-1 == store_object (a, str, &obj))
	  SLang_free_object (&obj);
	else
	  ret = 0;
     }

   the_return:
   SLang_free_slstring (str);
   SLang_free_mmt (mmt);
   return ret;
}

static int assoc_anew (unsigned char type, unsigned int num_dims)
{
   SLang_MMT_Type *mmt;
   SLang_Assoc_Array_Type *a;
   int has_default_value;

   has_default_value = 0;
   switch (num_dims)
     {
      case 0:
	type = SLANG_ANY_TYPE;
	break;
      case 2:
	(void) SLreverse_stack (2);
	has_default_value = 1;
	/* drop */
      case 1:
	if (0 == _SLang_pop_datatype (&type))
	  break;
	num_dims--;
	/* drop */
      default:
	SLdo_pop_n (num_dims);
	SLang_verror (SL_SYNTAX_ERROR, "Usage: Assoc_Type [DataType_Type]");
	return -1;
     }

   a = alloc_assoc_array (type, has_default_value);
   if (a == NULL)
     return -1;

   if (NULL == (mmt = SLang_create_mmt (SLANG_ASSOC_TYPE, (VOID_STAR) a)))
     {
	delete_assoc_array (a);
	return -1;
     }

   if (-1 == SLang_push_mmt (mmt))
     {
	SLang_free_mmt (mmt);
	return -1;
     }

   return 0;
}

static void assoc_get_keys (SLang_Assoc_Array_Type *a)
{
   SLang_Array_Type *at;
   int num;
   unsigned int i, j;
   char **data;

   /* Note: If support for threads is added, then we need to modify this
    * algorithm to prevent another thread from modifying the array.
    * However, that should be handled in inner_interp.
    */
   num = a->num_elements;

   if (NULL == (at = SLang_create_array (SLANG_STRING_TYPE, 0, NULL, &num, 1)))
     return;

   data = (char **)at->data;

   i = 0;
   for (j = 0; j < SLASSOC_HASH_TABLE_SIZE; j++)
     {
	_SLAssoc_Array_Element_Type *e;

	e = a->elements[j];
	while (e != NULL)
	  {
	     /* Next cannot fail because it is an slstring */
	     data [i] = SLang_create_slstring (e->key);
	     e = e->next;
	     i++;
	  }
     }
   (void) SLang_push_array (at, 1);
}

static int
transfer_element (SLang_Class_Type *cl, VOID_STAR dest_data,
		  SLang_Object_Type *obj)
{
   unsigned int sizeof_type;
   VOID_STAR src_data;

#if USE_NEW_ANYTYPE_CODE
   if (cl->cl_data_type == SLANG_ANY_TYPE)
     {
	SLang_Any_Type *any;

	if ((-1 == _SLpush_slang_obj (obj))
	    || (-1 == SLang_pop_anytype (&any)))
	  return -1;
	
	*(SLang_Any_Type **)dest_data = any;
	return 0;
     }
#endif
   /* Optimize for scalar */
   if (cl->cl_class_type == SLANG_CLASS_TYPE_SCALAR)
     {
	sizeof_type = cl->cl_sizeof_type;
	memcpy ((char *) dest_data, (char *)&obj->v, sizeof_type);
	return 0;
     }

   src_data = _SLclass_get_ptr_to_value (cl, obj);

   if (-1 == (*cl->cl_acopy) (cl->cl_data_type, src_data, dest_data))
     return -1;

   return 0;
}

static void assoc_get_values (SLang_Assoc_Array_Type *a)
{
   SLang_Array_Type *at;
   int num;
   unsigned int i, j;
   char *dest_data;
   unsigned char type;
   SLang_Class_Type *cl;
   unsigned int sizeof_type;

   /* Note: If support for threads is added, then we need to modify this
    * algorithm to prevent another thread from modifying the array.
    * However, that should be handled in inner_interp.
    */
   num = a->num_elements;
   type = a->type;

   cl = _SLclass_get_class (type);
   sizeof_type = cl->cl_sizeof_type;

   if (NULL == (at = SLang_create_array (type, 0, NULL, &num, 1)))
     return;

   dest_data = (char *)at->data;

   i = 0;
   for (j = 0; j < SLASSOC_HASH_TABLE_SIZE; j++)
     {
	_SLAssoc_Array_Element_Type *e;

	e = a->elements[j];
	while (e != NULL)
	  {
	     if (-1 == transfer_element (cl, (VOID_STAR) dest_data, &e->value))
	       {
		  SLang_free_array (at);
		  return;
	       }

	     dest_data += sizeof_type;
	     e = e->next;
	     i++;
	  }
     }
   (void) SLang_push_array (at, 1);
}

static int assoc_key_exists (SLang_Assoc_Array_Type *a, char *key)
{
   return (NULL != find_element (a, key, _SLcompute_string_hash (key)));
}

static void assoc_delete_key (SLang_Assoc_Array_Type *a, char *key)
{
   unsigned int h;
   _SLAssoc_Array_Element_Type *v, *v0;

   h = (unsigned int) (_SLcompute_string_hash (key) % SLASSOC_HASH_TABLE_SIZE);

   v0 = NULL;
   v = a->elements[h];
   while (v != NULL)
     {
	if (v->key == key)
	  {
	     if (v0 != NULL)
	       v0->next = v->next;
	     else
	       a->elements[h] = v->next;

	     free_element (v);
	     a->num_elements -= 1;
	     return;
	  }
	v0 = v;
	v = v->next;
     }

   /* No such element.  Let it pass with no error. */
}

#define A SLANG_ASSOC_TYPE
#define S SLANG_STRING_TYPE
static SLang_Intrin_Fun_Type Assoc_Table [] =
{
   MAKE_INTRINSIC_1("assoc_get_keys", assoc_get_keys, SLANG_VOID_TYPE, A),
   MAKE_INTRINSIC_1("assoc_get_values", assoc_get_values, SLANG_VOID_TYPE, A),
   MAKE_INTRINSIC_2("assoc_key_exists", assoc_key_exists, SLANG_INT_TYPE, A, S),
   MAKE_INTRINSIC_2("assoc_delete_key", assoc_delete_key, SLANG_VOID_TYPE, A, S),

   SLANG_END_INTRIN_FUN_TABLE
};
#undef A
#undef S

static int assoc_length (unsigned char type, VOID_STAR v, unsigned int *len)
{
   SLang_Assoc_Array_Type *a;

   (void) type;
   a = (SLang_Assoc_Array_Type *) SLang_object_from_mmt (*(SLang_MMT_Type **)v);
   *len = a->num_elements;
   return 0;
}

struct _SLang_Foreach_Context_Type
{
   SLang_MMT_Type *mmt;
   SLang_Assoc_Array_Type *a;
   unsigned int this_hash_index;
   unsigned int next_same_hash_index;
#define CTX_WRITE_KEYS		1
#define CTX_WRITE_VALUES	2
   unsigned char flags;
};

static SLang_Foreach_Context_Type *
cl_foreach_open (unsigned char type, unsigned int num)
{
   SLang_Foreach_Context_Type *c;
   unsigned char flags;
   SLang_MMT_Type *mmt;

   (void) type;

   if (NULL == (mmt = SLang_pop_mmt (SLANG_ASSOC_TYPE)))
     return NULL;

   flags = 0;

   while (num--)
     {
	char *s;

	if (-1 == SLang_pop_slstring (&s))
	  {
	     SLang_free_mmt (mmt);
	     return NULL;
	  }

	if (0 == strcmp (s, "keys"))
	  flags |= CTX_WRITE_KEYS;
	else if (0 == strcmp (s, "values"))
	  flags |= CTX_WRITE_VALUES;
	else
	  {
	     SLang_verror (SL_NOT_IMPLEMENTED,
			   "using '%s' not supported by SLassoc_Type",
			   s);
	     SLang_free_slstring (s);
	     SLang_free_mmt (mmt);
	     return NULL;
	  }

	SLang_free_slstring (s);
     }

   if (NULL == (c = (SLang_Foreach_Context_Type *) SLmalloc (sizeof (SLang_Foreach_Context_Type))))
     {
	SLang_free_mmt (mmt);
	return NULL;
     }

   memset ((char *) c, 0, sizeof (SLang_Foreach_Context_Type));

   if (flags == 0) flags = CTX_WRITE_VALUES|CTX_WRITE_KEYS;

   c->flags = flags;
   c->mmt = mmt;
   c->a = (SLang_Assoc_Array_Type *) SLang_object_from_mmt (mmt);

   return c;
}

static void cl_foreach_close (unsigned char type, SLang_Foreach_Context_Type *c)
{
   (void) type;
   if (c == NULL) return;
   SLang_free_mmt (c->mmt);
   SLfree ((char *) c);
}

static int cl_foreach (unsigned char type, SLang_Foreach_Context_Type *c)
{
   SLang_Assoc_Array_Type *a;
   _SLAssoc_Array_Element_Type *e;
   unsigned int i, j;

   (void) type;

   if (c == NULL)
     return -1;

   a = c->a;

   i = c->this_hash_index;
   if (i >= SLASSOC_HASH_TABLE_SIZE)
     return 0;

   e = a->elements[i];

   j = c->next_same_hash_index;
   c->next_same_hash_index = j + 1;

   while ((j > 0) && (e != NULL))
     {
	j--;
	e = e->next;
     }

   if (e == NULL)
     {
	do
	  {
	     i++;
	     if (i >= SLASSOC_HASH_TABLE_SIZE)
	       return 0;		       /* no more */
	  }
	while (a->elements [i] == NULL);

	e = a->elements[i];
	c->this_hash_index = i;
	c->next_same_hash_index = 1;
     }

   if ((c->flags & CTX_WRITE_KEYS)
       && (-1 == SLang_push_string (e->key)))
     return -1;

   if ((c->flags & CTX_WRITE_VALUES)
       && (-1 == _SLpush_slang_obj (&e->value)))
     return -1;

   /* keep going */
   return 1;
}

int SLang_init_slassoc (void)
{
   SLang_Class_Type *cl;

   if (SLclass_is_class_defined (SLANG_ASSOC_TYPE))
     return 0;

   if (NULL == (cl = SLclass_allocate_class ("Assoc_Type")))
     return -1;

   (void) SLclass_set_destroy_function (cl, assoc_destroy);
   (void) SLclass_set_aput_function (cl, assoc_aput);
   (void) SLclass_set_aget_function (cl, assoc_aget);
   (void) SLclass_set_anew_function (cl, assoc_anew);
   cl->cl_length = assoc_length;
   cl->cl_foreach_open = cl_foreach_open;
   cl->cl_foreach_close = cl_foreach_close;
   cl->cl_foreach = cl_foreach;

   if (-1 == SLclass_register_class (cl, SLANG_ASSOC_TYPE, sizeof (SLang_Assoc_Array_Type), SLANG_CLASS_TYPE_MMT))
     return -1;

   if (-1 == SLadd_intrin_fun_table (Assoc_Table, "__SLASSOC__"))
     return -1;

   return 0;
}