summaryrefslogtreecommitdiffstats
path: root/perl-install/install_steps.pm
blob: b35c6d5b8a891498d1b701bb31ba5a6a37f8667d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
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
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
package install_steps; # $Id$

use diagnostics;
use strict;
use vars qw(@filesToSaveForUpgrade @filesNewerToUseAfterUpgrade);

#-######################################################################################
#- misc imports
#-######################################################################################
use common;
use install_any qw(:all);
use partition_table;
use detect_devices;
use fs::type;
use modules;
use run_program;
use lang;
use keyboard;
use fsedit;
use loopback;
use do_pkgs;
use pkgs;
use any;
use log;

our @ISA = qw(do_pkgs);

@filesToSaveForUpgrade = qw(
/etc/ld.so.conf /etc/fstab /etc/hosts /etc/conf.modules /etc/modules.conf
);

@filesNewerToUseAfterUpgrade = qw(
/etc/profile
);

#-######################################################################################
#- OO Stuff
#-######################################################################################
sub new($$) {
    my ($type, $o) = @_;

    bless $o, ref($type) || $type;
    return $o;
}

sub charsetChanged {
    my ($_o) = @_;
}

#-######################################################################################
#- In/Out Steps Functions
#-######################################################################################
sub enteringStep {
    my ($_o, $step) = @_;
    log::l("starting step `$step'");
}
sub leavingStep {
    my ($o, $step) = @_;
    log::l("step `$step' finished");

    if (-d "$o->{prefix}/root/drakx") {
	eval { cp_af("/tmp/ddebug.log", "$o->{prefix}/root/drakx") };
	output(install_any::auto_inst_file(), install_any::g_auto_install(1));
    }

    foreach my $s (@{$o->{orderedSteps}}) {
	#- the reachability property must be recomputed each time to take
	#- into account failed step.
	next if $o->{steps}{$s}{done} && !$o->{steps}{$s}{redoable};

	my $reachable = 1;
	if (my $needs = $o->{steps}{$s}{needs}) {
	    my @l = ref($needs) ? @$needs : $needs;
	    $reachable = min(map { $o->{steps}{$_}{done} || 0 } @l);
	}
	$o->{steps}{$s}{reachable} = 1 if $reachable;
    }
    $o->{steps}{$step}{reachable} = $o->{steps}{$step}{redoable};

    while (my $f = shift @{$o->{steps}{$step}{toBeDone} || []}) {
	eval { &$f() };
	$o->ask_warn(N("Error"), [
N("An error occurred, but I don't know how to handle it nicely.
Continue at your own risk."), formatError($@) ]) if $@;
    }
}

sub errorInStep { 
    my ($_o, $err) = @_;
    print "error :(\n"; 
    print "$err\n\n";
    c::_exit(1);
}
sub kill_action {}

#-######################################################################################
#- Steps Functions
#-######################################################################################
#------------------------------------------------------------------------------
sub selectLanguage {
    my ($o) = @_;

    #- for auto_install compatibility with old $o->{lang}
    $o->{locale} = lang::system_locales_to_ourlocale($o->{lang}, $o->{lang}) if $o->{lang};
    $o->{locale}{langs} ||= { $o->{locale}{lang} => 1 };

    if (!exists $o->{locale}{country}) {
	my $h = lang::analyse_locale_name(lang::l2locale($o->{locale}{lang}));
	$o->{locale}{country} = $h->{country} if $h->{country};
	$o->{locale}{IM} = lang::get_default_im($o->{locale}{lang});
    }

    lang::set($o->{locale}, !$o->isa('interactive::gtk'));
    add2hash_($o->{locale}, { utf8 => lang::utf8_should_be_needed($o->{locale}) });

    log::l("selectLanguage: pack_langs: ", lang::pack_langs($o->{locale}{langs}), " utf8-flag: ", to_bool($o->{locale}{utf8}));

    #- for auto_install compatibility with old $o->{keyboard} containing directly $o->{keyboard}{KEYBOARD}
    $o->{keyboard} = { KEYBOARD => $o->{keyboard} } if $o->{keyboard} && !ref($o->{keyboard});

    if (!$o->{keyboard} || $o->{keyboard}{unsafe}) {
	$o->{keyboard} = keyboard::from_usb() || keyboard::lang2keyboard($o->{locale}{lang});
	$o->{keyboard}{unsafe} = 1;
	keyboard::setup($o->{keyboard});
    }

    $o->charsetChanged;

    addToBeDone {
	lang::write_langs($o->{locale}{langs});
    } 'formatPartitions';
    addToBeDone {
	lang::write($o->{locale});
    } 'installPackages';
}
#------------------------------------------------------------------------------
sub selectKeyboard {
    my ($o) = @_;
    $o->{keyboard}{KBCHARSET} = lang::l2charset($o->{locale}{lang});
    keyboard::setup($o->{keyboard});

    addToBeDone {
	keyboard::write($o->{keyboard});
    } 'installPackages' if !$o->{isUpgrade} || !$o->{keyboard}{unsafe};

    if ($o->{raw_X}) {
	require Xconfig::default;
	Xconfig::default::config_keyboard($o->{raw_X}, $o->{keyboard});
	$o->{raw_X}->write;
    }
}
#------------------------------------------------------------------------------
sub acceptLicense {}

#------------------------------------------------------------------------------
sub setupSCSI {
    my ($o) = @_;
    install_any::configure_pcmcia($o->{modules_conf}, $o->{pcmcia}) if $o->{pcmcia};
    modules::load(modules::category2modules('disk/cdrom'));
    modules::load_category($o->{modules_conf}, 'bus/firewire');
    modules::load_category($o->{modules_conf}, 'disk/ide|scsi|hardware_raid|firewire');

    install_any::getHds($o);
}

#------------------------------------------------------------------------------
sub selectInstallClass {
    my ($o) = @_;

    if ($o->{partitioning}{use_existing_root} || $o->{isUpgrade}) {
	# either one root is defined (and all is ok), or we take the first one we find
	my $p = fs::get::root_($o->{fstab}) || (first(install_any::find_root_parts($o->{fstab}, $o->{prefix})) || die)->{part};
	$o->{migrate_device_names} = install_any::use_root_part($o->{all_hds}, $p);
    } 
}

#------------------------------------------------------------------------------
sub doPartitionDisksBefore {
    my ($o) = @_;
    eval { 
	eval { fs::umount("$o->{prefix}/sys") };
	eval { fs::umount("$o->{prefix}/proc/bus/usb") };
	eval { fs::umount("$o->{prefix}/proc") };
	eval {          fs::umount_all($o->{fstab}, $o->{prefix}) };
	eval { sleep 1; fs::umount_all($o->{fstab}, $o->{prefix}) } if $@; #- HACK
    } if $o->{fstab} && !$::testing;
}

#------------------------------------------------------------------------------
sub doPartitionDisksAfter {
    my ($o) = @_;

    if (!$::testing) {
	my $hds = $o->{all_hds}{hds};
	partition_table::write($_) foreach @$hds;
	$_->{rebootNeeded} and $o->rebootNeeded foreach @$hds;
    }

    fs::set_removable_mntpoints($o->{all_hds});
    fs::mount_options::set_all_default($o->{all_hds}, %$o, lang::fs_options($o->{locale}))
	if !$o->{isUpgrade};

    $o->{fstab} = [ fs::get::fstab($o->{all_hds}) ];
    fs::get::root_($o->{fstab}) or die "Oops, no root partition";

    if (arch() =~ /ppc/ && detect_devices::get_mac_generation() =~ /NewWorld/) {
	die "Need bootstrap partition to boot system!" if !(defined $partition_table::mac::bootstrap_part);
    }
    
    if (arch() =~ /ia64/ && !fs::get::has_mntpoint("/boot/efi", $o->{all_hds})) {
	die N("You must have a FAT partition mounted in /boot/efi");
    }

    if ($o->{partitioning}{use_existing_root} && !$::recovery) {
	#- ensure those partitions are mounted so that they are not proposed in choosePartitionsToFormat
	fs::mount_part($_, $o->{prefix}) foreach sort { $a->{mntpoint} cmp $b->{mntpoint} }
						 grep { $_->{mntpoint} && maybeFormatted($_) } @{$o->{fstab}};
    }

    cat_("/proc/mounts") =~ m|(\S+)\s+/tmp/nfsimage| &&
      !any { $_->{mntpoint} eq "/mnt/nfs" } @{$o->{all_hds}{nfss}} and
	push @{$o->{all_hds}{nfss}}, { fs_type => 'nfs', mntpoint => "/mnt/nfs", device => $1, options => "noauto,ro,nosuid,soft,rsize=8192,wsize=8192" };
}

#------------------------------------------------------------------------------
sub doPartitionDisks {
    my ($o) = @_;

    if ($o->{partitioning}{auto_allocate}) {
	catch_cdie { fsedit::auto_allocate($o->{all_hds}, $o->{partitions}) } sub { 1 };
    }
}

#------------------------------------------------------------------------------

sub ask_mntpoint_s {#-}}}
    my ($_o, $fstab) = @_;

    #- TODO: set the mntpoints

    my %m; foreach (@$fstab) {
	my $m = $_->{mntpoint};

	next if !$m || $m eq 'swap'; #- there may be a lot of swap.

	$m{$m} and die N("Duplicate mount point %s", $m);
	$m{$m} = 1;

	#- in case the type does not correspond, force it to ext3
	fs::type::set_fs_type($_, 'ext3') if $m =~ m|^/| && !isTrueFS($_) && !isOtherAvailableFS($_);
    }
    1;
}


sub rebootNeeded($) {
    my ($_o) = @_;
    log::l("Rebooting...");
    c::_exit(0);
}

sub choosePartitionsToFormat($$) {
    my ($_o, $fstab) = @_;

    foreach (@$fstab) {
	$_->{mntpoint} = "swap" if isSwap($_);
	$_->{mntpoint} or next;
	
	add2hash_($_, { toFormat => $_->{notFormatted} }) if $_->{fs_type}; #- eg: don't set toFormat for isRawRAID (0xfd)
        $_->{$::recovery ? 'toFormat' : 'toFormatUnsure'} ||= member($_->{mntpoint}, '/', '/usr');

	if (!$_->{toFormat}) {
	    my $fs_type = fs::type::fs_type_from_magic($_);
	    if (!$fs_type || $fs_type ne $_->{fs_type}) {
		log::l("setting toFormatUnsure for $_->{device} because <$_->{fs_type}> ne <$fs_type>");
		$_->{toFormatUnsure} = 1;
	    }
	}
    }
}

sub formatMountPartitions {
    my ($o) = @_;
    fs::formatMount_all($o->{all_hds}{raids}, $o->{fstab}, $o->{prefix});
}

#------------------------------------------------------------------------------
sub setPackages {
    my ($o, $rebuild_needed) = @_;

    install_any::setPackages($o, $rebuild_needed);
    pkgs::selectPackagesAlreadyInstalled($o->{packages}, $o->{prefix});
    $rebuild_needed and pkgs::selectPackagesToUpgrade($o->{packages}, $o->{prefix});
}

sub deselectFoundMedia {
    my (undef, $hdlists) = @_;
    @$hdlists;
}

sub selectSupplMedia { '' }
sub askSupplMirror { '' }

sub choosePackages {
    my ($o, $packages, $_compssUsers, $first_time) = @_;

    #- now for upgrade, package that must be upgraded are
    #- selected first, after is used the same scheme as install.

    #- make sure we kept some space left for available else the system may
    #- not be able to start (xfs at least).
    my $available = install_any::getAvailableSpace($o);
    my $availableCorrected = pkgs::invCorrectSize($available / sqr(1024)) * sqr(1024);
    log::l(sprintf "available size %s (corrected %s)", formatXiB($available), formatXiB($availableCorrected));

    add2hash_($o, { compssListLevel => 5 }) if !$::auto_install;

    #- avoid destroying user selection of packages but only
    #- for expert, as they may have done individual selection before.
    if ($first_time || !$::expert) {
	exists $o->{compssListLevel}
	  and pkgs::setSelectedFromCompssList($packages, $o->{rpmsrate_flags_chosen}, $o->{compssListLevel}, $availableCorrected);
    }
    $availableCorrected;
}

sub upgrading_redhat() {
    #- remove weird config files that bother Xconfig::* too much
    unlink "$::prefix/etc/X11/XF86Config";
    unlink "$::prefix/etc/X11/XF86Config-4";

    sub prefering_mdk {
	my ($lpkg, $rpkg_ver, $c) = @_;
	my $lpkg_ver = $lpkg->version . '-' . $lpkg->release;
	log::l($lpkg->name . ' ' . ': prefering ' . ($c == 1 ? "$lpkg_ver over $rpkg_ver" : "$rpkg_ver over $lpkg_ver"));
    }

    my $old_compare_pkg = \&URPM::Package::compare_pkg;
    undef *URPM::Package::compare_pkg;
    *URPM::Package::compare_pkg = sub {
	my ($lpkg, $rpkg) = @_;
	my $c = ($lpkg->release =~ /mdk$/ ? 1 : 0) - ($rpkg->release =~ /mdk$/ ? 1 : 0);
	if ($c) {
	    prefering_mdk($lpkg, $rpkg->version . '-' . $rpkg->release, $c);
	    $c;
	} else {
	    &$old_compare_pkg;
	}
    };

    my $old_compare = \&URPM::Package::compare;
    undef *URPM::Package::compare;
    *URPM::Package::compare = sub {
	my ($lpkg, $rpkg_ver) = @_;
	my $c = ($lpkg->release =~ /mdk$/ ? 1 : 0) - ($rpkg_ver =~ /mdk$/ ? 1 : 0);
	if ($c) {
	    prefering_mdk($lpkg, $rpkg_ver, $c);
	    return $c;
	}
	&$old_compare;
    };
}

sub beforeInstallPackages {
    my ($o) = @_;

    #- save these files in case of upgrade failure.
    if ($o->{isUpgrade}) {
	foreach (@filesToSaveForUpgrade) {
	    unlink "$o->{prefix}/$_.mdkgisave";
	    if (-e "$o->{prefix}/$_") {
		eval { cp_af("$o->{prefix}/$_", "$o->{prefix}/$_.mdkgisave") };
	    }
	}
	foreach (@filesNewerToUseAfterUpgrade) {
	    unlink "$o->{prefix}/$_.rpmnew";
	}
    }

    #- mainly for upgrading redhat packages, but it can help other
    my @should_not_be_dirs = qw(/usr/X11R6/lib/X11/xkb /usr/share/locale/zh_TW/LC_TIME /usr/include/GL);
    my @should_be_dirs = qw(/etc/X11/xkb);
    my @to_remove = (
		     (grep { !-l $_ && -d $_          } map { "$::prefix$_" } @should_not_be_dirs),
		     (grep { -l $_ || !-d $_ && -e $_ } map { "$::prefix$_" } @should_be_dirs),
		    );
    rm_rf(@to_remove);

    if ($o->{isUpgrade} eq 'redhat') {
	upgrading_redhat();
    }

    #- some packages need such files for proper installation.
    install_any::write_fstab($o);

    require network::network;
    network::network::add2hosts("$o->{prefix}/etc/hosts", "localhost", "127.0.0.1");

    log::l("setting excludedocs to $o->{excludedocs}");
    substInFile { s/%_excludedocs.*//; $_ .= "%_excludedocs yes\n" if eof && $o->{excludedocs} } "$o->{prefix}/etc/rpm/macros";

    #- add oem theme if the files exists.
    mkdir_p("$o->{prefix}/usr/share");
    install_any::getAndSaveFile("install/oem-theme.rpm", "$o->{prefix}/usr/share/oem-theme.rpm");
}

sub pkg_install {
    my ($o, @l) = @_;
    log::l("selecting packages " . join(" ", @l));
    require pkgs;
    if ($::testing) {
	log::l(qq(selecting package "$_")) foreach @l;
    } else {
	$o->{packages}{rpmdb} ||= pkgs::rpmDbOpen($o->{prefix});
	pkgs::selectPackage($o->{packages}, pkgs::packageByName($o->{packages}, $_) || die "$_ rpm not found") foreach @l;
    }
    my @toInstall = pkgs::packagesToInstall($o->{packages});
    if (@toInstall) {
	log::l("installing packages");
	$o->installPackages;
    } else {
	log::l("all packages selected are already installed, nothing to do")
    }
}

sub pkg_install_if_requires_satisfied {
    my ($o, @l) = @_;
    require pkgs;
    $o->{packages}{rpmdb} ||= pkgs::rpmDbOpen($o->{prefix});
    foreach (@l) {
	my %newSelection;
	my $pkg = pkgs::packageByName($o->{packages}, $_) || die "$_ rpm not found";
	pkgs::selectPackage($o->{packages}, $pkg, 0, \%newSelection);
	if (scalar(keys %newSelection) == 1) {
	    pkgs::selectPackage($o->{packages}, $pkg);
	} else {
	    log::l("pkg_install_if_requires_satisfied: not selecting $_ because of ", join(", ", keys %newSelection));
	}
    }
    $o->installPackages;
}

sub installPackages($$) { #- complete REWORK, TODO and TOCHECK!
    my ($o) = @_;
    my $packages = $o->{packages};

    if (%{$packages->{state}{ask_remove} || {}}) {
	log::l("removing : ", join ', ', keys %{$packages->{state}{ask_remove}});
	pkgs::remove($o->{prefix}, [ keys %{$packages->{state}{ask_remove}} ], $packages);
    }

    #- small transaction will be built based on this selection and depslist.
    my @toInstall = pkgs::packagesToInstall($packages);

    my $time = time();
    $ENV{DURING_INSTALL} = 1;
    pkgs::install($o->{prefix}, $o->{isUpgrade}, \@toInstall, $packages);

    any::writeandclean_ldsoconf($o->{prefix});
    delete $ENV{DURING_INSTALL};
    run_program::rooted_or_die($o->{prefix}, 'ldconfig');

    eval {
	run_program::rooted($o->{prefix}, 'gdk-pixbuf-query-loaders', '>', '/etc/gtk-2.0/gdk-pixbuf.loaders.' . (arch() =~ /64/ ? 'lib64' : 'lib'));
	run_program::rooted($o->{prefix}, 'gtk-query-immodules-2.0', '>', '/etc/gtk-2.0/gtk.immodules.' . (arch() =~ /64/ ? 'lib64' : 'lib'));
	run_program::rooted($o->{prefix}, 'pango-querymodules-' . (arch() =~ /64/ ? '64' : '32'), '>', '/etc/pango/' . (arch() =~ /i.86/ ? 'i386' : arch()) . '/pango.modules');
    };

    log::l("Install took: ", formatTimeRaw(time() - $time));
    install_any::log_sizes($o);
    scalar(@toInstall); #- return number of packages installed.
}

sub afterInstallPackages($) {
    my ($o) = @_;

    die N("Some important packages didn't get installed properly.
Either your cdrom drive or your cdrom is defective.
Check the cdrom on an installed computer using \"rpm -qpl media/main/*.rpm\"
") if any { m|read failed: Input/output error| } cat_("$o->{prefix}/root/drakx/install.log");

    if (arch() !~ /^sparc/) { #- TODO restore it as may be needed for sparc
	-x "$o->{prefix}/usr/bin/dumpkeys" or $::testing or die 
"Some important packages didn't get installed properly.

Please switch to console 2 (using ctrl-alt-f2)
and look at the log file /tmp/ddebug.log

Consoles 1,3,4,7 may also contain interesting information";
    }

    #-  why not? cuz weather is nice today :-) [pixel]
    common::sync(); common::sync();

    my $have_devfsd = do {
	my $p = pkgs::packageByName($o->{packages}, 'devfsd');
	$p && $p->flag_installed
    };
    require bootloader;
    bootloader::may_append($o->{bootloader}, devfs => $have_devfsd ? 'mount' : 'nomount');

    #- generate /etc/lvmtab needed for rc.sysinit
    run_program::rooted($o->{prefix}, 'lvm2', 'vgscan') if -e '/etc/lvmtab';

    #- configure PCMCIA services if needed.
    install_any::write_pcmcia($o->{pcmcia});

    #- for mandrake_firstime
    touch "$o->{prefix}/var/lock/TMP_1ST";

    any::config_dvd($o->{prefix}, $have_devfsd);
    any::config_mtools($o->{prefix});

    #- make sure wins is disabled in /etc/nsswitch.conf
    #- else if eth0 is not existing, glibc segfaults.
    substInFile { s/\s*wins// if /^\s*hosts\s*:/ } "$o->{prefix}/etc/nsswitch.conf";

    #- make sure some services have been enabled (or a catastrophic restart will occur).
    #- these are normally base package post install scripts or important services to start.
    run_program::rooted($o->{prefix}, "chkconfig", "--add", $_) foreach
			qw(random netfs network rawdevices sound kheader keytable syslog crond portmap);

    if ($o->{mouse}{device} =~ /ttyS/) {
	log::l("disabling gpm for serial mice (doesn't get along nicely with X)");
	run_program::rooted($o->{prefix}, "chkconfig", "--del", "gpm") 
    }

    #- install urpmi before as rpmdb will be opened, this will cause problem with update-menus.
    $o->install_urpmi;

    #- update menu scheme before calling update menus if desktop mode.
    if ($o->{meta_class} eq 'desktop') {
	run_program::rooted($o->{prefix}, "touch", "/etc/menu/do-not-create-menu-link");
	run_program::rooted($o->{prefix}, "touch", "/etc/menu/enable_simplified");
    } elsif (!$o->{isUpgrade}) {
	run_program::rooted($o->{prefix}, "touch", "/etc/menu/do-not-create-menu-link");
    }

    if ($o->{pcmcia}) {
	substInFile { s/.*(TaskBarShowAPMStatus).*/$1=1/ } "$o->{prefix}/usr/lib/X11/icewm/preferences";
	eval { cp_af("$o->{prefix}/usr/share/applnk/System/kapm.kdelnk",
		     "$o->{prefix}/etc/skel/Desktop/Autostart/kapm.kdelnk") };
    }

    if ($o->{brltty}) {
	output("$o->{prefix}/etc/brltty.conf", <<EOF);
braille-driver $o->{brltty}{driver}
braille-device $o->{brltty}{device}
text-table $o->{brltty}{table}
EOF
    }


    install_any::disable_user_view() if $o->{security} >= 3 || $o->{authentication}{NIS};
    run_program::rooted($o->{prefix}, "kdeDesktopCleanup");

    foreach (list_skels($o->{prefix}, '.kde/share/config/kfmrc')) {
	my $found;
	substInFile {
	    $found ||= /KFM Misc Defaults/;
	    $_ .= 
"[KFM Misc Defaults]
GridWidth=85
GridHeight=70
" if eof && !$found;
	} $_ 
    }

    #- move some file after an upgrade that may be seriously annoying.
    #- and rename saved files to .mdkgiorig.
    if ($o->{isUpgrade}) {
	my $pkg = pkgs::packageByName($o->{packages}, 'rpm');
	$pkg && ($pkg->flag_selected || $pkg->flag_installed) && $pkg->compare(">= 4.0") and pkgs::cleanOldRpmDb($o->{prefix});

	log::l("moving previous desktop files that have been updated to Trash of each user");
	install_any::kdemove_desktop_file($o->{prefix});

	foreach (@filesToSaveForUpgrade) {
	    renamef("$o->{prefix}/$_.mdkgisave", "$o->{prefix}/$_.mdkgiorig")
	      if -e "$o->{prefix}$_.mdkgisave";
	}

	foreach (@filesNewerToUseAfterUpgrade) {
	    if (-e "$o->{prefix}/$_.rpmnew" && -e "$o->{prefix}/$_") {
		renamef("$o->{prefix}/$_", "$o->{prefix}/$_.mdkgiorig");
		renamef("$o->{prefix}/$_.rpmnew", "$o->{prefix}/$_");
	    }
	}
    }

    any::fix_broken_alternatives($o->{isUpgrade} eq 'redhat');

    #- update theme directly from a package (simplest).
    if (-s "$o->{prefix}/usr/share/oem-theme.rpm") {
	run_program::rooted($o->{prefix}, "rpm", "-U", "/usr/share/oem-theme.rpm");
	unlink "/usr/share/oem-theme.rpm";
    }

    #- call update-menus at the end of package installation
    push @{$o->{waitpids}}, run_program::raw({ root => $o->{prefix}, detach => 1 }, "update-menus", "-n");

    if ($o->{updatemodules}) {
	$o->{updatemodules} = detect_devices::floppy() or die N("No floppy drive available");
	$o->updateModulesFromFloppy;
    }
}

sub install_urpmi {
    my ($o) = @_;

    my $pkg = pkgs::packageByName($o->{packages}, 'urpmi');
    if ($pkg && ($pkg->flag_selected || $pkg->flag_installed)) {
	install_any::install_urpmi($o->{prefix}, 
				   $o->{method},
				   $o->{packages},
				   $o->{packages}{mediums});
	pkgs::saveCompssUsers($o->{prefix}, $o->{packages}, $o->{compssUsers});
    }
}

sub updateModulesFromFloppy {
    my ($o) = @_;
    return if $::testing;

    fs::mount($o->{updatemodules}, "/floppy", "ext2", 0);
    foreach (glob_("$o->{prefix}/lib/modules/*")) {
	my ($kernelVersion) = m,lib/modules/(\S*),;
	log::l("examining updated modules for kernel $kernelVersion");
	if (-d "/floppy/$kernelVersion") {
	    my @src_files = glob_("/floppy/$kernelVersion/*");
	    my @dest_files = map { chomp_($_) } run_program::rooted_get_stdout($o->{prefix}, 'find', '/lib/modules');
	    foreach my $s (@src_files) {
		log::l("found updatable module $s");
		my ($sfile, $sext) = $s =~ m!([^/\.]*\.k?o)(?:\.gz|\.bz2)?$!;
		my $qsfile = quotemeta $sfile;
		my $qsext = quotemeta $sext;
		foreach my $target (@dest_files) {
		    $target =~ /$qsfile/ or next;
		    eval { cp_af($s, $target) };
		    if ($@) {
			log::l("updating module $target by $s failed: $@");
		    } else {
			log::l("updating module $target by $s");
		    }
		    if ($target !~ /$qsfile$qsext$/) {
			#- extension differ, first rename target file correctly,
			#- then uncompress source file, then compress it as expected.
			my ($basetarget, $text) = $target =~ /(.*?)(\.gz|\.bz2)$/;
			rename $target, "$basetarget$sext";
			$sext eq '.gz' and run_program::run("gzip", "-d", "$basetarget$sext");
			$sext eq '.bz2' and run_program::run("bzip2", "-d", "$basetarget$sext");
			$text eq '.gz' and run_program::run("gzip", $basetarget);
			$text eq '.bz2' and run_program::run("bzip2", $basetarget);
		    }
		}
	    }
	}
    }
    fs::umount("/floppy");
}

#------------------------------------------------------------------------------
sub selectMouse($) {
    my ($_o) = @_;
}

#------------------------------------------------------------------------------
sub configureNetwork {
    my ($o) = @_;
    require network::network;
    network::network::configureNetwork2($o, $o->{modules_conf}, $o->{prefix}, $o->{netc}, $o->{intf});
    if ($o->{method} =~ /ftp|http|nfs/) {
	$o->{netcnx}{type} = 'lan';
	$o->{netcnx}{$_} = $o->{netc}{$_} foreach qw(NET_DEVICE NET_INTERFACE);
    }
}

#------------------------------------------------------------------------------
sub installUpdates {
    my ($o) = @_;
    my $u = $o->{updates} or return; $u->{updates} or return;

    upNetwork($o);
    require crypto;
    crypto::getPackages($o->{prefix}, $o->{packages}, $u->{mirror}) and
	$o->pkg_install(@{$u->{packages} || []});

    #- re-install urpmi with update security medium.
    $o->install_urpmi;
}

sub summaryBefore {}

sub summary {
    my ($o) = @_;
    configureTimezone($o);
    configurePrinter($o) if $o->{printer};
}

sub summaryAfter {
    my ($_o) = @_;
}

#------------------------------------------------------------------------------
sub configureTimezone {
    my ($o) = @_;
    install_any::preConfigureTimezone($o);

    $o->pkg_install('ntp') if $o->{timezone}{ntp};

    require timezone;
    timezone::write($o->{timezone});
}

#------------------------------------------------------------------------------
sub configureServices {
    my ($o) = @_;
    if ($o->{services}) {
	require services;
	services::doit($o, $o->{services});
    }
}
#------------------------------------------------------------------------------
sub configurePrinter {
    my ($o) = @_;
    eval {
	$o->do_pkgs->install('foomatic-filters', 'foomatic-db-engine', 'foomatic-db', 'printer-utils', 'printer-testpages',
			     if_($o->do_pkgs->is_installed('gimp'), 'gimpprint'));
    };
    if ($@ =~ /rpm not found/) {
	log::l("ERROR: $@");
	if ($o->{printer}) {
	    require printer::printerdrake;
	    printer::printerdrake::final_cleanup($o->{printer});
	}
	return;
    }

    require printer::main;
    eval { add2hash($o->{printer} ||= {}, printer::main::getinfo($o->{prefix})) }; #- get existing configuration.

    require printer::printerdrake;
    printer::printerdrake::install_spooler($o->{printer}, $o->{security}, $o->do_pkgs);

    foreach (values %{$o->{printer}{configured} || {}}) {
	log::l("configuring printer queue " . $_->{queuedata}{queue} || $_->{QUEUE});
	#- when copy is so adulée (sorry french taste :-)
	#- and when there are some configuration in one place and in another place...
	$o->{printer}{currentqueue} = {};
	printer::main::copy_printer_params($_->{queuedata}, $o->{printer}{currentqueue});
	printer::main::copy_printer_params($_, $o->{printer});
	#- setup all configured queues, which is not the case interactively where
	#- only the working queue is setup on configuration.
	printer::main::configure_queue($o->{printer});
    }
}

#------------------------------------------------------------------------------
sub setRootPassword {
    my ($o) = @_;
    $o->{superuser} ||= {};
    $o->{superuser}{name} = 'root';
    any::write_passwd_user($o->{superuser}, $o->{authentication}{md5});
    delete $o->{superuser}{name};
    install_any::set_authentication($o);
}

#------------------------------------------------------------------------------

sub addUser {
    my ($o) = @_;
    my $users = $o->{users} ||= [];

    if ($::prefix) {
	#- getpwnam, getgrnam, getgrid works
	symlinkf("$::prefix/etc/passwd", '/etc/passwd');
	symlinkf("$::prefix/etc/group", '/etc/group');
    }

    my (%uids, %gids); 
    foreach (glob_("$::prefix/home")) { my ($u, $g) = (stat($_))[4,5]; $uids{$u} = 1; $gids{$g} = 1 }

    foreach (@$users) {
	$_->{home} ||= "/home/$_->{name}";

	my $u = $_->{uid} || ($_->{oldu} = (stat("$::prefix$_->{home}"))[4]) || int getpwnam($_->{name});
	my $g = $_->{gid} || ($_->{oldg} = (stat("$::prefix$_->{home}"))[5]) || int getgrnam($_->{name});
	#- search for available uid above 501 else initscripts may fail to change language for KDE.
	if (!$u || getpwuid($u)) { for ($u = 501; getpwuid($u) || $uids{$u}; $u++) {} }
	if (!$g)                 { for ($g = 501; getgrgid($g) || $gids{$g}; $g++) {} }
	
	$_->{uid} = $u; $uids{$u} = 1;
	$_->{gid} = $g; $gids{$g} = 1;
    }

    any::write_passwd_user($_, $o->{authentication}{md5}) foreach @$users;

    append_to_file("$::prefix/etc/group",
		   map { "$_->{name}:x:$_->{gid}:\n" } grep { ! getgrgid($_->{gid}) } @$users);

    foreach my $u (@$users) {
	if (! -d "$::prefix$u->{home}") {
	    my $mode = $o->{security} < 2 ? 0755 : 0750;
	    eval { cp_af("$::prefix/etc/skel", "$::prefix$u->{home}") };
	    if ($@) {
		log::l("copying of skel failed: $@"); mkdir("$::prefix$u->{home}", $mode); 
	    } else {
		chmod $mode, "$::prefix$u->{home}";
	    }
	}
	require commands;
	eval { commands::chown_("-r", "$u->{uid}.$u->{gid}", "$::prefix$u->{home}") }
	    if $u->{uid} != $u->{oldu} || $u->{gid} != $u->{oldg};
    }
    #- since we wrote the password in /etc/passwd, we must convert to shadow
    run_program::rooted($::prefix, 'pwconv') if $o->{authentication}{shadow};

    any::addUsers($users);

    if ($o->{autologin}) {
	$o->{desktop} ||= first(any::sessions());
	$o->pkg_install("autologin") if !member($o->{desktop}, 'KDE', 'GNOME');
    }
    any::set_autologin($o->{autologin}, $o->{desktop});

    install_any::disable_user_view() if @$users == ();
}

#------------------------------------------------------------------------------
sub readBootloaderConfigBeforeInstall {
    my ($o) = @_;

    require bootloader;
    add2hash($o->{bootloader} ||= {}, bootloader::read($o->{all_hds}));

    $o->{bootloader}{bootUnsafe} = 0 if $o->{bootloader}{boot}; #- when upgrading, don't ask where to install the bootloader (mbr vs boot partition)
}

sub setupBootloaderBefore {
    my ($o) = @_;

    require bootloader;

    #- remove previous ide-scsi lines
    bootloader::modify_append($o->{bootloader}, sub {
	my ($_simple, $dict) = @_;
	@$dict = grep { $_->[1] ne 'ide-scsi' } @$dict;
    });

    if ($o->{miscellaneous}{HDPARM}) {
	bootloader::set_append($o->{bootloader}, $_, 'autotune') foreach grep { /ide/ } all("/proc/ide");
    }
    if (cat_("/proc/cmdline") =~ /mem=nopentium/) {
	bootloader::set_append($o->{bootloader}, 'mem', 'nopentium');
    }
    if (cat_("/proc/cmdline") =~ /\b(pci)=(\S+)/) {
	bootloader::set_append($o->{bootloader}, $1, $2);
    }
    if (my ($acpi) = cat_("/proc/cmdline") =~ /\bacpi=(\w+)/) {
	if ($acpi eq 'ht') {
	    #- the user is using the default, which may not be the best
	    my $year = detect_devices::dmidecode()->{BIOS_Year};
	    if (detect_devices::isLaptop() && $year >= 2002) {
		log::l("forcing ACPI on a laptop with recent bios ($year)");
		$acpi = 'on';
	    }
	}
	bootloader::set_append($o->{bootloader}, acpi => $acpi);
    }
    if (cat_("/proc/cmdline") =~ /\bnoapic/) {
	bootloader::set_append($o->{bootloader}, 'noapic');
    }
    my ($MemTotal) = cat_("/proc/meminfo") =~ /^MemTotal:\s*(\d+)/m;
    if (my ($biggest_swap) = sort { $b->{size} <=> $a->{size} } grep { isSwap($_) } @{$o->{fstab}}) {
	log::l("MemTotal: $MemTotal < ", $biggest_swap->{size} / 2);
	bootloader::set_append($o->{bootloader}, resume => devices::make($biggest_swap->{device})) if $MemTotal < $biggest_swap->{size} / 2;
    }

    #- check for valid fb mode to enable a default boot with frame buffer.
    my $vga = $o->{allowFB} && (!detect_devices::matching_desc__regexp('3D Rage LT') &&
                                !detect_devices::matching_desc__regexp('Rage Mobility [PL]') &&
                                !detect_devices::matching_desc__regexp('i740') &&
                                !detect_devices::matching_desc__regexp('Matrox') &&
                                !detect_devices::matching_desc__regexp('Tseng.*ET6\d00') &&
                                !detect_devices::matching_desc__regexp('SiS.*SG86C2.5') &&
                                !detect_devices::matching_desc__regexp('SiS.*559[78]') &&
                                !detect_devices::matching_desc__regexp('SiS.*300') &&
                                !detect_devices::matching_desc__regexp('SiS.*540') &&
                                !detect_devices::matching_desc__regexp('SiS.*6C?326') &&
                                !detect_devices::matching_desc__regexp('SiS.*6C?236') &&
                                !detect_devices::matching_desc__regexp('Voodoo [35]|Voodoo Banshee') && #- 3d acceleration seems to bug in fb mode
                                !detect_devices::matching_desc__regexp('828[14][05].* CGC') #- i810 & i845 now have FB support during install but we disable it afterwards
                               );
    my $force_vga = $o->{allowFB} && (detect_devices::matching_desc__regexp('SiS.*630') || #- SiS 630 need frame buffer.
                                      detect_devices::matching_desc__regexp('GeForce.*Integrated') #- needed for fbdev driver (hack).
                                     );

    #- propose the default fb mode for kernel fb, if aurora or bootsplash is installed.
    my $need_fb = do {
        my $p = pkgs::packageByName($o->{packages}, 'bootsplash');
        $p && $p->flag_installed;
    };
    bootloader::suggest($o->{bootloader}, $o->{all_hds},
                        vga_fb => ($force_vga || $vga && $need_fb) && $o->{vga}, 
                        quiet => $o->{meta_class} ne 'server');

    $o->{bootloader}{keytable} ||= keyboard::keyboard2kmap($o->{keyboard});
}

sub setupBootloader {
    my ($o) = @_;

    any::install_acpi_pkgs($o->do_pkgs, $o->{bootloader});

    require bootloader;
    bootloader::install($o->{bootloader}, $o->{all_hds});
}

#------------------------------------------------------------------------------
sub configureXBefore {
    my ($o) = @_;

    #- keep this here if the package has to be updated.
    $o->pkg_install("xorg-x11");
}
sub configureX {
    my ($o) = @_;
    configureXBefore($o);

    require Xconfig::default;
    $o->{raw_X} = Xconfig::default::configure($o->do_pkgs, $o->{keyboard}, $o->{mouse});

    require Xconfig::main;
    Xconfig::main::configure_everything_auto_install($o->{raw_X}, $o->do_pkgs, $o->{X}, install_any::X_options_from_o($o));
    configureXAfter($o);
}
sub configureXAfter {
    my ($o) = @_;
    if ($o->{X}{bios_vga_mode}) {
	install_any::setupFB($o, $o->{X}{bios_vga_mode}) or do {
	    log::l("disabling automatic start-up of X11 if any as setup framebuffer failed");
	    Xconfig::various::runlevel(3); #- disable automatic start-up of X11 on error.
	};
    }
    if ($o->{X}{default_depth} >= 16 && $o->{X}{resolution_wanted} >= 1024) {
	log::l("setting large icon style for kde");
	install_any::kderc_largedisplay($o->{prefix});
    }
}

#------------------------------------------------------------------------------
sub miscellaneousBefore {
    my ($o) = @_;

    my %s = getVarsFromSh("$o->{prefix}/etc/sysconfig/system");
    $o->{miscellaneous}{HDPARM} = $s{HDPARM} if exists $s{HDPARM};
    require security::level;
    require security::various;
    $o->{security} ||= security::level::get() || ($o->{meta_class} =~ /server|firewall/ ? 3 : 2);
    $o->{security_user} ||= security::various::config_security_user($o->{prefix});
    $o->{libsafe} ||= security::various::config_libsafe($o->{prefix});

    log::l("security $o->{security}");

    add2hash_($o->{miscellaneous} ||= {}, { numlock => !detect_devices::isLaptop() });
}
sub miscellaneous {
    my ($_o) = @_;
    #- keep some given parameters
    #-TODO
}
sub miscellaneousAfter {
    my ($o) = @_;
    add2hash_ $o, { useSupermount => $o->{security} < 4 ? 'magicdev' : 0 };

    $ENV{SECURE_LEVEL} = $o->{security}; #- deprecated with chkconfig 1.3.4-2mdk, uses /etc/sysconfig/msec

    addToBeDone {
	setVarsInSh("$o->{prefix}/etc/sysconfig/system", { 
            CLASS => $::expert && 'expert' || 'beginner',
            SECURITY => $o->{security},
	    META_CLASS => $o->{meta_class} || 'PowerPack',
        });
	substInFile { s/KEYBOARD_AT_BOOT=.*/KEYBOARD_AT_BOOT=yes/ } "$o->{prefix}/etc/sysconfig/usb" if detect_devices::usbKeyboards();

    } 'installPackages';
}

#------------------------------------------------------------------------------
sub exitInstall { 
    my ($o) = @_;
    eval { 
	my $report = '/root/drakx/report.bug';
	unlink "$::prefix$report", "$::prefix$report.gz";
	output "$::prefix$report", install_any::report_bug($o->{prefix});
	run_program::rooted($::prefix, 'gzip', $report);
    };
    install_any::getAndSaveAutoInstallFloppies($o, 1);
    eval { output "$o->{prefix}/root/drakx/README", "This directory contains several installation-related files,
mostly log files (very useful if you ever report a bug!).

Beware that some Mandrakelinux tools rely on the contents of some
of these files... so remove any file from here at your own
risk!
" };
    #- wait for remainging processes.
    foreach (@{$o->{waitpids}}) {
	waitpid $_, 0;
	log::l("pid $_ returned $?");
    }
    install_any::unlockCdrom();
    install_any::log_sizes($o);
}

#------------------------------------------------------------------------------
sub hasNetwork {
    my ($o) = @_;
    $o->{netcnx}{type} && $o->{netc}{NETWORKING} ne 'no' and return 1;
    log::l("no network seems to be configured for internet ($o->{netcnx}{type},$o->{netc}{NETWORKING})");
    0;
}

#------------------------------------------------------------------------------
sub upNetwork {
    my ($o, $b_pppAvoided) = @_;

    #- do not destroy this file if prefix is '' or even '/' (could it happens ?).
    if (length($o->{prefix}) > 1) {
	symlinkf("$o->{prefix}/etc/$_", "/etc/$_") foreach qw(resolv.conf protocols services);
    }
    member($o->{method}, qw(ftp http nfs)) and return 1;
    $o->{modules_conf}->write;
    if (hasNetwork($o)) {
	if ($o->{netcnx}{type} =~ /adsl|lan|cable/) {
	    log::l("starting network ($o->{netcnx}{type})");
	    require network::netconnect;
	    network::netconnect::start_internet($o);
	    return 1;
	} elsif (!$b_pppAvoided) {
	    log::l("starting network (ppp: $o->{netcnx}{type})");
	    eval { modules::load(qw(serial ppp bsd_comp ppp_deflate)) };
	    run_program::rooted($o->{prefix}, "/etc/rc.d/init.d/syslog", "start");
	    require network::netconnect;
	    network::netconnect::start_internet($o);
	    return 1;
	} else {
	    log::l(qq(not starting network (b/c ppp avoided and type is "$o->{netcnx}{type})"));
	}
    }
    $::testing;
}

#------------------------------------------------------------------------------
sub downNetwork {
    my ($o, $costlyOnly) = @_;

    $o->{method} eq "ftp" || $o->{method} eq "http" || $o->{method} eq "nfs" and return 1;
    $o->{modules_conf}->write;
    if (hasNetwork($o)) {
	if (!$costlyOnly) {
	    require network::netconnect;
	    network::netconnect::stop_internet($o);
	    return 1;
	} elsif ($o->{netc}{type} !~ /adsl|lan|cable/) {
	    require network::netconnect;
	    network::netconnect::stop_internet($o);
	    run_program::rooted($o->{prefix}, "/etc/rc.d/init.d/syslog", "stop");
	    eval { modules::unload(qw(ppp_deflate bsd_comp ppp serial)) };
	    return 1;
	}
    }
    $::testing;
}

#------------------------------------------------------------------------------
sub cleanIfFailedUpgrade($) {
    my ($o) = @_;

    #- if an upgrade has failed, there should be .mdkgisave files around.
    if ($o->{isUpgrade}) {
	foreach (@filesToSaveForUpgrade) {
	    if (-e "$o->{prefix}/$_" && -e "$o->{prefix}/$_.mdkgisave") {
		rename "$o->{prefix}/$_", "$o->{prefix}/$_.mdkginew"; #- keep new files around in case !
		rename "$o->{prefix}/$_.mdkgisave", "$o->{prefix}/$_";
	    }
	}
    }
}


1;
); extern void SLtt_narrow_width(void); extern void SLtt_set_alt_char_set (int); extern int SLtt_write_to_status_line (char *, int); extern void SLtt_disable_status_line (void); # ifdef REAL_UNIX_SYSTEM /* These are termcap/terminfo routines that assume SLtt_initialize has * been called. */ extern char *SLtt_tgetstr (char *); extern int SLtt_tgetnum (char *); extern int SLtt_tgetflag (char *); /* The following are terminfo-only routines -- these prototypes will change * in V2.x. */ extern char *SLtt_tigetent (char *); extern char *SLtt_tigetstr (char *, char **); extern int SLtt_tigetnum (char *, char **); # endif #endif extern SLtt_Char_Type SLtt_get_color_object (int); extern void SLtt_set_color_object (int, SLtt_Char_Type); extern void SLtt_set_color (int, char *, char *, char *); extern void SLtt_set_mono (int, char *, SLtt_Char_Type); extern void SLtt_add_color_attribute (int, SLtt_Char_Type); extern void SLtt_set_color_fgbg (int, SLtt_Char_Type, SLtt_Char_Type); /*}}}*/ /*{{{ SLang Preprocessor Interface */ typedef struct { int this_level; int exec_level; int prev_exec_level; char preprocess_char; char comment_char; unsigned char flags; #define SLPREP_BLANK_LINES_OK 1 #define SLPREP_COMMENT_LINES_OK 2 } SLPreprocess_Type; extern int SLprep_open_prep (SLPreprocess_Type *); extern void SLprep_close_prep (SLPreprocess_Type *); extern int SLprep_line_ok (char *, SLPreprocess_Type *); extern int SLdefine_for_ifdef (char *); /* Adds a string to the SLang #ifdef preparsing defines. SLang already defines MSDOS, UNIX, and VMS on the appropriate system. */ extern int (*SLprep_exists_hook) (char *, char); /*}}}*/ /*{{{ SLsmg Screen Management Functions */ extern void SLsmg_fill_region (int, int, unsigned int, unsigned int, unsigned char); extern void SLsmg_set_char_set (int); #ifndef IBMPC_SYSTEM extern int SLsmg_Scroll_Hash_Border; #endif extern int SLsmg_suspend_smg (void); extern int SLsmg_resume_smg (void); extern void SLsmg_erase_eol (void); extern void SLsmg_gotorc (int, int); extern void SLsmg_erase_eos (void); extern void SLsmg_reverse_video (void); extern void SLsmg_set_color (int); extern void SLsmg_normal_video (void); extern void SLsmg_printf (char *, ...); extern void SLsmg_vprintf (char *, va_list); extern void SLsmg_write_string (char *); extern void SLsmg_write_nstring (char *, unsigned int); extern void SLsmg_write_char (char); extern void SLsmg_write_nchars (char *, unsigned int); extern void SLsmg_write_wrapped_string (char *, int, int, unsigned int, unsigned int, int); extern void SLsmg_cls (void); extern void SLsmg_refresh (void); extern void SLsmg_touch_lines (int, unsigned int); extern void SLsmg_touch_screen (void); extern int SLsmg_init_smg (void); extern int SLsmg_reinit_smg (void); extern void SLsmg_reset_smg (void); extern SLsmg_Char_Type SLsmg_char_at(void); extern void SLsmg_set_screen_start (int *, int *); extern void SLsmg_draw_hline (unsigned int); extern void SLsmg_draw_vline (int); extern void SLsmg_draw_object (int, int, unsigned char); extern void SLsmg_draw_box (int, int, unsigned int, unsigned int); extern int SLsmg_get_column(void); extern int SLsmg_get_row(void); extern void SLsmg_forward (int); extern void SLsmg_write_color_chars (SLsmg_Char_Type *, unsigned int); extern unsigned int SLsmg_read_raw (SLsmg_Char_Type *, unsigned int); extern unsigned int SLsmg_write_raw (SLsmg_Char_Type *, unsigned int); extern void SLsmg_set_color_in_region (int, int, int, unsigned int, unsigned int); extern int SLsmg_Display_Eight_Bit; extern int SLsmg_Tab_Width; #define SLSMG_NEWLINE_IGNORED 0 /* default */ #define SLSMG_NEWLINE_MOVES 1 /* moves to next line, column 0 */ #define SLSMG_NEWLINE_SCROLLS 2 /* moves but scrolls at bottom of screen */ #define SLSMG_NEWLINE_PRINTABLE 3 /* prints as ^J */ extern int SLsmg_Newline_Behavior; extern int SLsmg_Backspace_Moves; #ifdef IBMPC_SYSTEM # define SLSMG_HLINE_CHAR 0xC4 # define SLSMG_VLINE_CHAR 0xB3 # define SLSMG_ULCORN_CHAR 0xDA # define SLSMG_URCORN_CHAR 0xBF # define SLSMG_LLCORN_CHAR 0xC0 # define SLSMG_LRCORN_CHAR 0xD9 # define SLSMG_RTEE_CHAR 0xB4 # define SLSMG_LTEE_CHAR 0xC3 # define SLSMG_UTEE_CHAR 0xC2 # define SLSMG_DTEE_CHAR 0xC1 # define SLSMG_PLUS_CHAR 0xC5 /* There are several to choose from: 0xB0, 0xB1, and 0xB2 */ # define SLSMG_CKBRD_CHAR 0xB0 # define SLSMG_DIAMOND_CHAR 0x04 # define SLSMG_DEGREE_CHAR 0xF8 # define SLSMG_PLMINUS_CHAR 0xF1 # define SLSMG_BULLET_CHAR 0xF9 # define SLSMG_LARROW_CHAR 0x1B # define SLSMG_RARROW_CHAR 0x1A # define SLSMG_DARROW_CHAR 0x19 # define SLSMG_UARROW_CHAR 0x18 # define SLSMG_BOARD_CHAR 0xB2 # define SLSMG_BLOCK_CHAR 0xDB #else # if defined(AMIGA) # define SLSMG_HLINE_CHAR '-' # define SLSMG_VLINE_CHAR '|' # define SLSMG_ULCORN_CHAR '+' # define SLSMG_URCORN_CHAR '+' # define SLSMG_LLCORN_CHAR '+' # define SLSMG_LRCORN_CHAR '+' # define SLSMG_CKBRD_CHAR '#' # define SLSMG_RTEE_CHAR '+' # define SLSMG_LTEE_CHAR '+' # define SLSMG_UTEE_CHAR '+' # define SLSMG_DTEE_CHAR '+' # define SLSMG_PLUS_CHAR '+' # define SLSMG_DIAMOND_CHAR '+' # define SLSMG_DEGREE_CHAR '\\' # define SLSMG_PLMINUS_CHAR '#' # define SLSMG_BULLET_CHAR 'o' # define SLSMG_LARROW_CHAR '<' # define SLSMG_RARROW_CHAR '>' # define SLSMG_DARROW_CHAR 'v' # define SLSMG_UARROW_CHAR '^' # define SLSMG_BOARD_CHAR '#' # define SLSMG_BLOCK_CHAR '#' # else # define SLSMG_HLINE_CHAR 'q' # define SLSMG_VLINE_CHAR 'x' # define SLSMG_ULCORN_CHAR 'l' # define SLSMG_URCORN_CHAR 'k' # define SLSMG_LLCORN_CHAR 'm' # define SLSMG_LRCORN_CHAR 'j' # define SLSMG_CKBRD_CHAR 'a' # define SLSMG_RTEE_CHAR 'u' # define SLSMG_LTEE_CHAR 't' # define SLSMG_UTEE_CHAR 'w' # define SLSMG_DTEE_CHAR 'v' # define SLSMG_PLUS_CHAR 'n' # define SLSMG_DIAMOND_CHAR '`' # define SLSMG_DEGREE_CHAR 'f' # define SLSMG_PLMINUS_CHAR 'g' # define SLSMG_BULLET_CHAR '~' # define SLSMG_LARROW_CHAR ',' # define SLSMG_RARROW_CHAR '+' # define SLSMG_DARROW_CHAR '.' # define SLSMG_UARROW_CHAR '-' # define SLSMG_BOARD_CHAR 'h' # define SLSMG_BLOCK_CHAR '0' # endif /* AMIGA */ #endif /* IBMPC_SYSTEM */ #ifndef IBMPC_SYSTEM # define SLSMG_COLOR_BLACK 0x000000 # define SLSMG_COLOR_RED 0x000001 # define SLSMG_COLOR_GREEN 0x000002 # define SLSMG_COLOR_BROWN 0x000003 # define SLSMG_COLOR_BLUE 0x000004 # define SLSMG_COLOR_MAGENTA 0x000005 # define SLSMG_COLOR_CYAN 0x000006 # define SLSMG_COLOR_LGRAY 0x000007 # define SLSMG_COLOR_GRAY 0x000008 # define SLSMG_COLOR_BRIGHT_RED 0x000009 # define SLSMG_COLOR_BRIGHT_GREEN 0x00000A # define SLSMG_COLOR_BRIGHT_BROWN 0x00000B # define SLSMG_COLOR_BRIGHT_BLUE 0x00000C # define SLSMG_COLOR_BRIGHT_CYAN 0x00000D # define SLSMG_COLOR_BRIGHT_MAGENTA 0x00000E # define SLSMG_COLOR_BRIGHT_WHITE 0x00000F #endif typedef struct { void (*tt_normal_video)(void); void (*tt_set_scroll_region)(int, int); void (*tt_goto_rc)(int, int); void (*tt_reverse_index)(int); void (*tt_reset_scroll_region)(void); void (*tt_delete_nlines)(int); void (*tt_cls) (void); void (*tt_del_eol) (void); void (*tt_smart_puts) (SLsmg_Char_Type *, SLsmg_Char_Type *, int, int); int (*tt_flush_output) (void); int (*tt_reset_video) (void); int (*tt_init_video) (void); int *tt_screen_rows; int *tt_screen_cols; int *tt_term_cannot_scroll; int *tt_has_alt_charset; int *tt_use_blink_for_acs; char **tt_graphic_char_pairs; long reserved[4]; } SLsmg_Term_Type; extern void SLsmg_set_terminal_info (SLsmg_Term_Type *); /*}}}*/ /*{{{ SLang Keypad Interface */ #define SL_KEY_ERR 0xFFFF #define SL_KEY_UP 0x101 #define SL_KEY_DOWN 0x102 #define SL_KEY_LEFT 0x103 #define SL_KEY_RIGHT 0x104 #define SL_KEY_PPAGE 0x105 #define SL_KEY_NPAGE 0x106 #define SL_KEY_HOME 0x107 #define SL_KEY_END 0x108 #define SL_KEY_A1 0x109 #define SL_KEY_A3 0x10A #define SL_KEY_B2 0x10B #define SL_KEY_C1 0x10C #define SL_KEY_C3 0x10D #define SL_KEY_REDO 0x10E #define SL_KEY_UNDO 0x10F #define SL_KEY_BACKSPACE 0x110 #define SL_KEY_ENTER 0x111 #define SL_KEY_IC 0x112 #define SL_KEY_DELETE 0x113 #define SL_KEY_F0 0x200 #define SL_KEY_F(X) (SL_KEY_F0 + X) /* I do not intend to use keysymps > 0x1000. Applications can use those. */ /* Returns 0 upon success or -1 upon error. */ extern int SLkp_define_keysym (char *, unsigned int); /* This function must be called AFTER SLtt_get_terminfo and not before. */ extern int SLkp_init (void); /* This function uses SLang_getkey and assumes that what ever initialization * is required for SLang_getkey has been performed. */ extern int SLkp_getkey (void); /*}}}*/ /*{{{ SLang Scroll Interface */ typedef struct _SLscroll_Type { struct _SLscroll_Type *next; struct _SLscroll_Type *prev; unsigned int flags; } SLscroll_Type; typedef struct { unsigned int flags; SLscroll_Type *top_window_line; /* list element at top of window */ SLscroll_Type *bot_window_line; /* list element at bottom of window */ SLscroll_Type *current_line; /* current list element */ SLscroll_Type *lines; /* first list element */ unsigned int nrows; /* number of rows in window */ unsigned int hidden_mask; /* applied to flags in SLscroll_Type */ unsigned int line_num; /* current line number (visible) */ unsigned int num_lines; /* total number of lines (visible) */ unsigned int window_row; /* row of current_line in window */ unsigned int border; /* number of rows that form scroll border */ int cannot_scroll; /* should window scroll or recenter */ } SLscroll_Window_Type; extern int SLscroll_find_top (SLscroll_Window_Type *); extern int SLscroll_find_line_num (SLscroll_Window_Type *); extern unsigned int SLscroll_next_n (SLscroll_Window_Type *, unsigned int); extern unsigned int SLscroll_prev_n (SLscroll_Window_Type *, unsigned int); extern int SLscroll_pageup (SLscroll_Window_Type *); extern int SLscroll_pagedown (SLscroll_Window_Type *); /*}}}*/ /*{{{ Signal Routines */ typedef void SLSig_Fun_Type (int); extern SLSig_Fun_Type *SLsignal (int, SLSig_Fun_Type *); extern SLSig_Fun_Type *SLsignal_intr (int, SLSig_Fun_Type *); extern int SLsig_block_signals (void); extern int SLsig_unblock_signals (void); extern int SLsystem (char *); extern char *SLerrno_strerror (int); extern int SLerrno_set_errno (int); /*}}}*/ /*{{{ Interpreter Macro Definitions */ /* The definitions here are for objects that may be on the run-time stack. * They are actually sub_types of literal and data main_types. The actual * numbers are historical. */ #define SLANG_UNDEFINED_TYPE 0x00 /* MUST be 0 */ #define SLANG_VOID_TYPE 0x01 /* also matches ANY type */ #define SLANG_INT_TYPE 0x02 #define SLANG_DOUBLE_TYPE 0x03 #define SLANG_CHAR_TYPE 0x04 #define SLANG_INTP_TYPE 0x05 /* An object of SLANG_INTP_TYPE should never really occur on the stack. Rather, * the integer to which it refers will be there instead. It is defined here * because it is a valid type for MAKE_VARIABLE. */ #define SLANG_REF_TYPE 0x06 /* SLANG_REF_TYPE refers to an object on the stack that is a pointer (reference) * to some other object. */ #define SLANG_COMPLEX_TYPE 0x07 #define SLANG_NULL_TYPE 0x08 #define SLANG_UCHAR_TYPE 0x09 #define SLANG_SHORT_TYPE 0x0A #define SLANG_USHORT_TYPE 0x0B #define SLANG_UINT_TYPE 0x0C #define SLANG_LONG_TYPE 0x0D #define SLANG_ULONG_TYPE 0x0E #define SLANG_STRING_TYPE 0x0F #define SLANG_FLOAT_TYPE 0x10 #define SLANG_STRUCT_TYPE 0x11 #define SLANG_ISTRUCT_TYPE 0x12 #define SLANG_ARRAY_TYPE 0x20 #define SLANG_DATATYPE_TYPE 0x21 #define SLANG_FILE_PTR_TYPE 0x22 #define SLANG_ASSOC_TYPE 0x23 #define SLANG_ANY_TYPE 0x24 #define SLANG_BSTRING_TYPE 0x25 #define SLANG_FILE_FD_TYPE 0x26 /* Compatibility */ #ifdef FLOAT_TYPE # undef FLOAT_TYPE #endif #define VOID_TYPE SLANG_VOID_TYPE #define INT_TYPE SLANG_INT_TYPE #define INTP_TYPE SLANG_INTP_TYPE #define FLOAT_TYPE SLANG_DOUBLE_TYPE #define ARRAY_TYPE SLANG_ARRAY_TYPE #define CHAR_TYPE SLANG_CHAR_TYPE #define STRING_TYPE SLANG_STRING_TYPE /* I am reserving values greater than or equal to 128 for user applications. * The first 127 are reserved for S-Lang. */ /* Binary and Unary Subtypes */ /* Since the application can define new types and can overload the binary * and unary operators, these definitions must be present in this file. * The current implementation assumes both unary and binary are distinct. */ #define SLANG_PLUS 0x01 #define SLANG_MINUS 0x02 #define SLANG_TIMES 0x03 #define SLANG_DIVIDE 0x04 #define SLANG_EQ 0x05 #define SLANG_NE 0x06 #define SLANG_GT 0x07 #define SLANG_GE 0x08 #define SLANG_LT 0x09 #define SLANG_LE 0x0A #define SLANG_POW 0x0B #define SLANG_OR 0x0C #define SLANG_AND 0x0D #define SLANG_BAND 0x0E #define SLANG_BOR 0x0F #define SLANG_BXOR 0x10 #define SLANG_SHL 0x11 #define SLANG_SHR 0x12 #define SLANG_MOD 0x13 /* UNARY subtypes (may be overloaded) */ #define SLANG_PLUSPLUS 0x20 #define SLANG_MINUSMINUS 0x21 #define SLANG_ABS 0x22 #define SLANG_SIGN 0x23 #define SLANG_SQR 0x24 #define SLANG_MUL2 0x25 #define SLANG_CHS 0x26 #define SLANG_NOT 0x27 #define SLANG_BNOT 0x28 extern char *SLang_Error_Message; int SLadd_intrinsic_variable (char *, VOID_STAR, unsigned char, int); int SLadd_intrinsic_function (char *, FVOID_STAR, unsigned char, unsigned int,...); int SLns_add_intrinsic_variable (SLang_NameSpace_Type *, char *, VOID_STAR, unsigned char, int); int SLns_add_intrinsic_function (SLang_NameSpace_Type *, char *, FVOID_STAR, unsigned char, unsigned int,...); extern void SLadd_at_handler (long *, char *); #define MAKE_INTRINSIC_N(n,f,out,in,a1,a2,a3,a4,a5,a6,a7) \ {(n), NULL, SLANG_INTRINSIC, (FVOID_STAR) (f), \ {a1,a2,a3,a4,a5,a6,a7}, (in), (out)} #define MAKE_INTRINSIC_7(n,f,out,a1,a2,a3,a4,a5,a6,a7) \ MAKE_INTRINSIC_N(n,f,out,7,a1,a2,a3,a4,a5,a6,a7) #define MAKE_INTRINSIC_6(n,f,out,a1,a2,a3,a4,a5,a6) \ MAKE_INTRINSIC_N(n,f,out,6,a1,a2,a3,a4,a5,a6,0) #define MAKE_INTRINSIC_5(n,f,out,a1,a2,a3,a4,a5) \ MAKE_INTRINSIC_N(n,f,out,5,a1,a2,a3,a4,a5,0,0) #define MAKE_INTRINSIC_4(n,f,out,a1,a2,a3,a4) \ MAKE_INTRINSIC_N(n,f,out,4,a1,a2,a3,a4,0,0,0) #define MAKE_INTRINSIC_3(n,f,out,a1,a2,a3) \ MAKE_INTRINSIC_N(n,f,out,3,a1,a2,a3,0,0,0,0) #define MAKE_INTRINSIC_2(n,f,out,a1,a2) \ MAKE_INTRINSIC_N(n,f,out,2,a1,a2,0,0,0,0,0) #define MAKE_INTRINSIC_1(n,f,out,a1) \ MAKE_INTRINSIC_N(n,f,out,1,a1,0,0,0,0,0,0) #define MAKE_INTRINSIC_0(n,f,out) \ MAKE_INTRINSIC_N(n,f,out,0,0,0,0,0,0,0,0) #define MAKE_INTRINSIC_S(n,f,r) \ MAKE_INTRINSIC_1(n,f,r,SLANG_STRING_TYPE) #define MAKE_INTRINSIC_I(n,f,r) \ MAKE_INTRINSIC_1(n,f,r,SLANG_INT_TYPE) #define MAKE_INTRINSIC_SS(n,f,r) \ MAKE_INTRINSIC_2(n,f,r,SLANG_STRING_TYPE,SLANG_STRING_TYPE) #define MAKE_INTRINSIC_SI(n,f,r) \ MAKE_INTRINSIC_2(n,f,r,SLANG_STRING_TYPE,SLANG_INT_TYPE) #define MAKE_INTRINSIC_IS(n,f,r) \ MAKE_INTRINSIC_2(n,f,r,SLANG_INT_TYPE,SLANG_STRING_TYPE) #define MAKE_INTRINSIC_II(n,f,r) \ MAKE_INTRINSIC_2(n,f,r,SLANG_INT_TYPE,SLANG_INT_TYPE) #define MAKE_INTRINSIC_SSS(n,f,r) \ MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_STRING_TYPE,SLANG_STRING_TYPE) #define MAKE_INTRINSIC_SSI(n,f,r) \ MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_STRING_TYPE,SLANG_INT_TYPE) #define MAKE_INTRINSIC_SIS(n,f,r) \ MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_INT_TYPE,SLANG_STRING_TYPE) #define MAKE_INTRINSIC_SII(n,f,r) \ MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_INT_TYPE,SLANG_INT_TYPE) #define MAKE_INTRINSIC_ISS(n,f,r) \ MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_STRING_TYPE,SLANG_STRING_TYPE) #define MAKE_INTRINSIC_ISI(n,f,r) \ MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_STRING_TYPE,SLANG_INT_TYPE) #define MAKE_INTRINSIC_IIS(n,f,r) \ MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_INT_TYPE,SLANG_STRING_TYPE) #define MAKE_INTRINSIC_III(n,f,r) \ MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_INT_TYPE,SLANG_INT_TYPE) #define MAKE_INTRINSIC(n, f, out, in) \ MAKE_INTRINSIC_N(n,f,out,in,0,0,0,0,0,0,0) #define MAKE_VARIABLE(n, v, t, r) \ {n, NULL, SLANG_IVARIABLE + (r), (VOID_STAR)(v), (t)} #define MAKE_APP_UNARY(n,op) \ {(n), NULL, SLANG_APP_UNARY, (op)} #define MAKE_MATH_UNARY(n,op) \ {(n), NULL, SLANG_MATH_UNARY, (op)} #define MAKE_ICONSTANT(n,val) \ {(n),NULL, SLANG_ICONSTANT, (val)} #define MAKE_DCONSTANT(n,val) \ {(n),NULL, SLANG_DCONSTANT, (val)} #ifndef offsetof # define offsetof(T,F) ((unsigned int)((char *)&((T *)0L)->F - (char *)0L)) #endif #define MAKE_ISTRUCT_FIELD(s,f,n,t,r) {(n), offsetof(s,f), (t), (r)} #define SLANG_END_TABLE {NULL} #define SLANG_END_INTRIN_FUN_TABLE MAKE_INTRINSIC_0(NULL,NULL,0) #define SLANG_END_DCONST_TABLE MAKE_DCONSTANT(NULL,0) #define SLANG_END_MATH_UNARY_TABLE MAKE_MATH_UNARY(NULL,0) #define SLANG_END_INTRIN_VAR_TABLE MAKE_VARIABLE(NULL,NULL,0,0) #define SLANG_END_ICONST_TABLE MAKE_ICONSTANT(NULL,0) #define SLANG_END_ISTRUCT_TABLE {NULL, 0, 0, 0} /*}}}*/ /*{{{ Upper/Lowercase Functions */ extern void SLang_define_case(int *, int *); extern void SLang_init_case_tables (void); extern unsigned char _SLChg_UCase_Lut[256]; extern unsigned char _SLChg_LCase_Lut[256]; #define UPPER_CASE(x) (_SLChg_UCase_Lut[(unsigned char) (x)]) #define LOWER_CASE(x) (_SLChg_LCase_Lut[(unsigned char) (x)]) #define CHANGE_CASE(x) (((x) == _SLChg_LCase_Lut[(unsigned char) (x)]) ?\ _SLChg_UCase_Lut[(unsigned char) (x)] : _SLChg_LCase_Lut[(unsigned char) (x)]) /*}}}*/ /*{{{ Regular Expression Interface */ typedef struct { /* These must be set by calling routine. */ unsigned char *pat; /* regular expression pattern */ unsigned char *buf; /* buffer for compiled regexp */ unsigned int buf_len; /* length of buffer */ int case_sensitive; /* 1 if match is case sensitive */ /* The rest are set by SLang_regexp_compile */ int must_match; /* 1 if line must contain substring */ int must_match_bol; /* true if it must match beginning of line */ unsigned char must_match_str[16]; /* 15 char null term substring */ int osearch; /* 1 if ordinary search suffices */ unsigned int min_length; /* minimum length the match must be */ int beg_matches[10]; /* offset of start of \( */ unsigned int end_matches[10]; /* length of nth submatch * Note that the entire match corresponds * to \0 */ int offset; /* offset to be added to beg_matches */ int reserved[10]; } SLRegexp_Type; extern unsigned char *SLang_regexp_match(unsigned char *, unsigned int, SLRegexp_Type *); /* Returns 0 upon success. If failure, the offset into the * pattern is returned (start = 1). */ extern int SLang_regexp_compile (SLRegexp_Type *); extern char *SLregexp_quote_string (char *, char *, unsigned int); /*}}}*/ /*{{{ SLang Command Interface */ struct _SLcmd_Cmd_Type; /* Pre-declaration is needed below */ typedef struct { struct _SLcmd_Cmd_Type *table; int argc; /* Version 2.0 needs to use a union!! */ char **string_args; int *int_args; double *double_args; unsigned char *arg_type; unsigned long reserved[4]; } SLcmd_Cmd_Table_Type; typedef struct _SLcmd_Cmd_Type { int (*cmdfun)(int, SLcmd_Cmd_Table_Type *); char *cmd; char *arg_type; } SLcmd_Cmd_Type; extern int SLcmd_execute_string (char *, SLcmd_Cmd_Table_Type *); /*}}}*/ /*{{{ SLang Search Interface */ typedef struct { int cs; /* case sensitive */ unsigned char key[256]; int ind[256]; int key_len; int dir; } SLsearch_Type; extern int SLsearch_init (char *, int, int, SLsearch_Type *); /* This routine must first be called before any search can take place. * The second parameter specifies the direction of the search: greater than * zero for a forwrd search and less than zero for a backward search. The * third parameter specifies whether the search is case sensitive or not. * The last parameter is a pointer to a structure that is filled by this * function and it is this structure that must be passed to SLsearch. */ extern unsigned char *SLsearch (unsigned char *, unsigned char *, SLsearch_Type *); /* To use this routine, you must first call 'SLsearch_init'. Then the first * two parameters p1 and p2 serve to define the region over which the search * is to take place. The third parameter is the structure that was previously * initialized by SLsearch_init. * * The routine returns a pointer to the match if found otherwise it returns * NULL. */ /*}}}*/ /*{{{ SLang Pathname Interface */ /* These function return pointers to the original space */ extern char *SLpath_basename (char *); extern char *SLpath_extname (char *); extern int SLpath_is_absolute_path (char *); /* These return malloced strings--- NOT slstrings */ extern char *SLpath_dircat (char *, char *); extern char *SLpath_find_file_in_path (char *, char *); extern char *SLpath_dirname (char *); extern int SLpath_file_exists (char *); extern char *SLpath_pathname_sans_extname (char *); /*}}}*/ extern int SLang_set_module_load_path (char *); #define SLANG_MODULE(name) \ extern int init_##name##_module_ns (char *); \ extern void deinit_##name##_module (void) #if 0 { #endif #ifdef __cplusplus } #endif #endif /* _DAVIS_SLANG_H_ */