summaryrefslogtreecommitdiffstats
path: root/perl-install/Xconfig
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2005-09-13 14:16:55 +0000
committerPascal Rigaux <pixel@mandriva.com>2005-09-13 14:16:55 +0000
commit230f1fc68eb6b0104f70617e0d4c1c332d532f12 (patch)
treea989fdf75867a8ef3fbeedb04eb88862d97bac77 /perl-install/Xconfig
parent90395d9b0d55741c8292c162c24741804514a877 (diff)
downloaddrakx-backup-do-not-use-230f1fc68eb6b0104f70617e0d4c1c332d532f12.tar
drakx-backup-do-not-use-230f1fc68eb6b0104f70617e0d4c1c332d532f12.tar.gz
drakx-backup-do-not-use-230f1fc68eb6b0104f70617e0d4c1c332d532f12.tar.bz2
drakx-backup-do-not-use-230f1fc68eb6b0104f70617e0d4c1c332d532f12.tar.xz
drakx-backup-do-not-use-230f1fc68eb6b0104f70617e0d4c1c332d532f12.zip
handle DefaultDepth (which is the same as DefaultColorDepth)
Diffstat (limited to 'perl-install/Xconfig')
-rw-r--r--perl-install/Xconfig/parse.pm2
-rw-r--r--perl-install/Xconfig/xfree.pm3
2 files changed, 3 insertions, 2 deletions
diff --git a/perl-install/Xconfig/parse.pm b/perl-install/Xconfig/parse.pm
index 609534b54..71062a093 100644
--- a/perl-install/Xconfig/parse.pm
+++ b/perl-install/Xconfig/parse.pm
@@ -140,7 +140,7 @@ my %kind_names = (
Monitor => [ qw(Identifier VendorName ModelName HorizSync VertRefresh) ],
Device => [ qw(Identifier VendorName BoardName Chipset Driver VideoRam Screen BusID DPMS power_saver) ],
Display => [ qw(Depth Modes Virtual) ], # Subsection in Device
- Screen => [ qw(Identifier Driver Device Monitor DefaultColorDepth) ],
+ Screen => [ qw(Identifier Driver Device Monitor DefaultDepth DefaultColorDepth) ],
InputDevice => [ qw(Identifier Driver Protocol Device Type Mode XkbModel XkbLayout XkbDisable Emulate3Buttons Emulate3Timeout EmulateWheel EmulateWheelButton) ],
WacomCursor => [ qw(Port) ], #-\
WacomStylus => [ qw(Port) ], #--> Port must be first
diff --git a/perl-install/Xconfig/xfree.pm b/perl-install/Xconfig/xfree.pm
index d783d4de3..8c3b7857c 100644
--- a/perl-install/Xconfig/xfree.pm
+++ b/perl-install/Xconfig/xfree.pm
@@ -141,7 +141,7 @@ sub get_resolution {
my ($raw_X, $o_Screen) = @_;
my $Screen = $o_Screen || $raw_X->get_default_screen or return {};
- my $depth = val($Screen->{DefaultColorDepth});
+ my $depth = val($Screen->{DefaultColorDepth} || $Screen->{DefaultDepth});
my $Display = find { !$depth || val($_->{l}{Depth}) eq $depth } @{$Screen->{Display} || []} or return {};
$Display->{l}{Virtual} && val($Display->{l}{Virtual}) =~ /(\d+)\s+(\d+)/ or
val($Display->{l}{Modes}) =~ /(\d+)x(\d+)/ or return {};
@@ -156,6 +156,7 @@ sub set_resolution {
my $Mode_name = (any { $_->{l}{Modes} } @{$Screen->{Display} || []}) ? 'Modes' : 'Virtual';
my $Mode = sprintf($Mode_name eq 'Modes' ? '"%dx%d"' : '%d %d', @$resolution{'X', 'Y'});
+ delete $Screen->{DefaultDepth};
$Screen->{DefaultColorDepth} = { val => $resolution->{Depth} eq '32' ? 24 : $resolution->{Depth} };
$Screen->{Display} = [ map {
{ l => { Depth => { val => $_ }, $Mode_name => { val => $Mode } } };
241'>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 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
/* Structure type implementation */
/* 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"

void _SLstruct_delete_struct (_SLang_Struct_Type *s)
{
   _SLstruct_Field_Type *field, *field_max;

   if (s == NULL) return;

   if (s->num_refs > 1)
     {
	s->num_refs -= 1;
	return;
     }

   field = s->fields;
   if (field != NULL)
     {
	field_max = field + s->nfields;

	while (field < field_max)
	  {
	     SLang_free_object (&field->obj);
	     SLang_free_slstring (field->name);   /* could be NULL */
	     field++;
	  }
	SLfree ((char *) s->fields);
     }
   SLfree ((char *) s);
}

static _SLang_Struct_Type *allocate_struct (unsigned int nfields)
{
   _SLang_Struct_Type *s;
   _SLstruct_Field_Type *f;
   unsigned int i, size;

   s = (_SLang_Struct_Type *) SLmalloc (sizeof (_SLang_Struct_Type));
   if (s == NULL) return NULL;

   SLMEMSET((char *) s, 0, sizeof (_SLang_Struct_Type));

   size = nfields * sizeof(_SLstruct_Field_Type);
   if (NULL == (f = (_SLstruct_Field_Type *) SLmalloc (size)))
     {
	SLfree ((char *) s);
	return NULL;
     }
   SLMEMSET ((char *) f, 0, size);
   s->nfields = nfields;
   s->fields = f;

   /* By default, all structs will be created with elements set to NULL.  I
    * do not know whether or not it is better to use SLANG_UNDEFINED_TYPE.
    */
   for (i = 0; i < nfields; i++)
     f[i].obj.data_type = SLANG_NULL_TYPE;

   return s;
}

static int push_struct_of_type (unsigned char type, _SLang_Struct_Type *s)
{
   SLang_Object_Type obj;

   obj.data_type = type;
   obj.v.struct_val = s;
   s->num_refs += 1;

   if (0 == SLang_push (&obj))
     return 0;

   s->num_refs -= 1;
   return -1;
}

int _SLang_push_struct (_SLang_Struct_Type *s)
{
   return push_struct_of_type (SLANG_STRUCT_TYPE, s);
}

int _SLang_pop_struct (_SLang_Struct_Type **sp)
{
   SLang_Object_Type obj;
   SLang_Class_Type *cl;
   unsigned char type;

   if (0 != SLang_pop (&obj))
     return -1;

   type = obj.data_type;
   if (type != SLANG_STRUCT_TYPE)
     {
	cl = _SLclass_get_class (type);
	if (cl->cl_struct_def == NULL)
	  {
	     *sp = NULL;
	     SLang_free_object (&obj);
	     SLang_verror (SL_TYPE_MISMATCH,
			   "Expecting struct type object.  Found %s",
			   cl->cl_name);
	     return -1;
	  }
     }

   *sp = obj.v.struct_val;
   return 0;
}

static void struct_destroy (unsigned char type, VOID_STAR vs)
{
   (void) type;
   _SLstruct_delete_struct (*(_SLang_Struct_Type **) vs);
}

static int struct_push (unsigned char type, VOID_STAR ptr)
{
   return push_struct_of_type (type, *(_SLang_Struct_Type **) ptr);
}

static _SLstruct_Field_Type *find_field (_SLang_Struct_Type *s, char *name)
{
   _SLstruct_Field_Type *f, *fmax;

   f = s->fields;
   fmax = f + s->nfields;

   while (f < fmax)
     {
	/* Since both these are slstrings, only compare pointer */
	if (name == f->name)
	  return f;

	f++;
     }

   return NULL;
}

static _SLstruct_Field_Type *pop_field (_SLang_Struct_Type *s, char *name)
{
   _SLstruct_Field_Type *f;

   f = find_field (s, name);
   if (f == NULL)
     SLang_verror (SL_SYNTAX_ERROR, "struct has no field named %s", name);
   return f;
}

int SLstruct_create_struct (unsigned int nfields,
			    char **field_names,
			    unsigned char *field_types,
			    VOID_STAR *field_values)
{
   _SLang_Struct_Type *s;
   _SLstruct_Field_Type *f;
   unsigned int i;

   if (NULL == (s = allocate_struct (nfields)))
     return -1;

   f = s->fields;
   for (i = 0; i < nfields; i++)
     {
	unsigned char type;
	SLang_Class_Type *cl;
	VOID_STAR value;
	char *name = field_names [i];

	if (name == NULL)
	  {
	     SLang_verror (SL_INVALID_PARM, "A struct field name cannot be NULL");
	     goto return_error;
	  }

	if (NULL == (f->name = SLang_create_slstring (name)))
	  goto return_error;

	if ((field_values == NULL)
	    || (NULL == (value = field_values [i])))
	  {
	     f++;
	     continue;
	  }

	type = field_types[i];
	cl = _SLclass_get_class (type);

	if ((-1 == (cl->cl_push (type, value)))
	    || (-1 == SLang_pop (&f->obj)))
	  goto return_error;

	f++;
     }

   if (0 == _SLang_push_struct (s))
     return 0;
   /* drop */

   return_error:
   _SLstruct_delete_struct (s);
   return -1;
}

/* Interpreter interface */

int _SLstruct_define_struct (void)
{
   int nfields;
   _SLang_Struct_Type *s;
   _SLstruct_Field_Type *f;

   if (-1 == SLang_pop_integer (&nfields))
     return -1;

   if (nfields <= 0)
     {
	SLang_verror (SL_INVALID_PARM, "Number of struct fields must be > 0");
	return -1;
     }

   if (NULL == (s = allocate_struct (nfields)))
     return -1;

   f = s->fields;
   while (nfields)
     {
	char *name;

	nfields--;
	if (-1 == SLang_pop_slstring (&name))
	  {
	     _SLstruct_delete_struct (s);
	     return -1;
	  }
	f[nfields].name = name;
     }

   if (-1 == _SLang_push_struct (s))
     {
	_SLstruct_delete_struct (s);
	return -1;
     }
   return 0;
}

/* Simply make a struct that contains the same fields as struct s.  Do not
 * duplicate the field values.
 */
static _SLang_Struct_Type *make_struct_shell (_SLang_Struct_Type *s)
{
   _SLang_Struct_Type *new_s;
   _SLstruct_Field_Type *new_f, *old_f;
   unsigned int i, nfields;

   nfields = s->nfields;
   if (NULL == (new_s = allocate_struct (nfields)))
     return NULL;

   new_f = new_s->fields;
   old_f = s->fields;

   for (i = 0; i < nfields; i++)
     {
	if (NULL == (new_f[i].name = SLang_create_slstring (old_f[i].name)))
	  {
	     _SLstruct_delete_struct (new_s);
	     return NULL;
	  }
     }
   return new_s;
}

static int struct_init_array_object (unsigned char type, VOID_STAR addr)
{
   SLang_Class_Type *cl;
   _SLang_Struct_Type *s;

   cl = _SLclass_get_class (type);
   if (NULL == (s = make_struct_shell (cl->cl_struct_def)))
     return -1;

   s->num_refs = 1;
   *(_SLang_Struct_Type **) addr = s;
   return 0;
}

static int
typedefed_struct_datatype_deref (unsigned char type)
{
   SLang_Class_Type *cl;
   _SLang_Struct_Type *s;

   cl = _SLclass_get_class (type);
   if (NULL == (s = make_struct_shell (cl->cl_struct_def)))
     return -1;

   if (-1 == push_struct_of_type (type, s))
     {
	_SLstruct_delete_struct (s);
	return -1;
     }

   return 0;
}

static _SLang_Struct_Type *duplicate_struct (_SLang_Struct_Type *s)
{
   _SLang_Struct_Type *new_s;
   _SLstruct_Field_Type *new_f, *f, *fmax;

   new_s = make_struct_shell (s);

   if (new_s == NULL)
     return NULL;

   f = s->fields;
   fmax = f + s->nfields;
   new_f = new_s->fields;

   while (f < fmax)
     {
	SLang_Object_Type *obj;

	obj = &f->obj;
	if (obj->data_type != SLANG_UNDEFINED_TYPE)
	  {
	     if ((-1 == _SLpush_slang_obj (obj))
		 || (-1 == SLang_pop (&new_f->obj)))
	       {
		  _SLstruct_delete_struct (new_s);
		  return NULL;
	       }
	  }
	new_f++;
	f++;
     }

   return new_s;
}

static int struct_dereference (unsigned char type, VOID_STAR addr)
{
   _SLang_Struct_Type *s;

   if (NULL == (s = duplicate_struct (*(_SLang_Struct_Type **) addr)))
     return -1;

   if (-1 == push_struct_of_type (type, s))
     {
	_SLstruct_delete_struct (s);
	return -1;
     }

   return 0;
}

/*{{{ foreach */

struct _SLang_Foreach_Context_Type
{
   _SLang_Struct_Type *s;
   char *next_field_name;
};

static SLang_Foreach_Context_Type *
struct_foreach_open (unsigned char type, unsigned int num)
{
   SLang_Foreach_Context_Type *c;
   _SLang_Struct_Type *s;
   char *next_name;

   (void) type;

   if (-1 == _SLang_pop_struct (&s))
     return NULL;

   switch (num)
     {
      case 0:
	next_name = SLang_create_slstring ("next");
	break;

      case 1:
	if (-1 == SLang_pop_slstring (&next_name))
	  next_name = NULL;
	break;

      default:
	next_name = NULL;
	SLang_verror (SL_NOT_IMPLEMENTED,
		      "'foreach (Struct_Type) using' requires single control value");
	SLdo_pop_n (num);
	break;
     }

   if (next_name == NULL)
     {
	_SLstruct_delete_struct (s);
	return NULL;
     }

   c = (SLang_Foreach_Context_Type *)SLmalloc (sizeof (SLang_Foreach_Context_Type));
   if (c == NULL)
     {
	_SLstruct_delete_struct (s);
	SLang_free_slstring (next_name);
	return NULL;
     }
   memset ((char *) c, 0, sizeof (SLang_Foreach_Context_Type));

   c->next_field_name = next_name;
   c->s = s;

   return c;
}

static void struct_foreach_close (unsigned char type, SLang_Foreach_Context_Type *c)
{
   (void) type;
   if (c == NULL) return;

   SLang_free_slstring (c->next_field_name);
   if (c->s != NULL) _SLstruct_delete_struct (c->s);
   SLfree ((char *) c);
}

static int struct_foreach (unsigned char type, SLang_Foreach_Context_Type *c)
{
   _SLstruct_Field_Type *f;
   _SLang_Struct_Type *next_s;

   (void) type;

   if (c == NULL)
     return -1;

   if (c->s == NULL)
     return 0;			       /* done */

   if (-1 == _SLang_push_struct (c->s))
     return -1;

   /* Now get the next one ready for the next foreach loop */

   next_s = NULL;
   if (NULL != (f = find_field (c->s, c->next_field_name)))
     {
	SLang_Class_Type *cl;

	cl = _SLclass_get_class (f->obj.data_type);
	/* Note that I cannot simply look for SLANG_STRUCT_TYPE since the
	 * user may have typedefed another struct type.  So, look at the
	 * class methods.
	 */
	if (cl->cl_foreach_open == struct_foreach_open)
	  {
	     next_s = f->obj.v.struct_val;
	     next_s->num_refs += 1;
	  }
     }

   _SLstruct_delete_struct (c->s);
   c->s = next_s;

   /* keep going */
   return 1;
}

/*}}}*/

static int struct_sput (unsigned char type, char *name)
{
   _SLang_Struct_Type *s;
   _SLstruct_Field_Type *f;
   SLang_Object_Type obj;

   (void) type;

   if (-1 == _SLang_pop_struct (&s))
     return -1;

   if ((NULL == (f = pop_field (s, name)))
       || (-1 == SLang_pop (&obj)))
     {
	_SLstruct_delete_struct (s);
	return -1;
     }

   SLang_free_object (&f->obj);
   f->obj = obj;
   _SLstruct_delete_struct (s);
   return 0;
}

static int struct_sget (unsigned char type, char *name)
{
   _SLang_Struct_Type *s;
   _SLstruct_Field_Type *f;
   int ret;

   (void) type;

   if (-1 == _SLang_pop_struct (&s))
     return -1;

   if (NULL == (f = pop_field (s, name)))
     {
	_SLstruct_delete_struct (s);
	return -1;
     }

   ret = _SLpush_slang_obj (&f->obj);
   _SLstruct_delete_struct (s);
   return ret;
}

static int struct_typecast
  (unsigned char a_type, VOID_STAR ap, unsigned int na,
   unsigned char b_type, VOID_STAR bp)
{
   _SLang_Struct_Type **a, **b;
   unsigned int i;
   
   (void) a_type;
   (void) b_type;

   a = (_SLang_Struct_Type **) ap;
   b = (_SLang_Struct_Type **) bp;
   for (i = 0; i < na; i++)
     {
	b[i] = a[i];
	if (a[i] != NULL)
	  a[i]->num_refs += 1;
     }