Change 16407 by jhi@alpha on 2002/05/05 01:05:17

        Subject: Re: Cross-compiling as of WinCE
        From: "Vadim Konovalov" <[EMAIL PROTECTED]>
        Date: Sat, 4 May 2002 03:49:11 +0400
        Message-ID: <00ca01c1f2fd$20a35fb0$cb5cc3d9@vad>

Affected files ...

.... //depot/perl/MANIFEST#875 edit
.... //depot/perl/configpm#33 edit
.... //depot/perl/makedef.pl#121 edit
.... //depot/perl/wince/Makefile.ce#13 edit
.... //depot/perl/wince/cecopy-lib.pl#2 edit
.... //depot/perl/wince/comp.pl#2 edit
.... //depot/perl/wince/compile.bat#1 add
.... //depot/perl/wince/config.ce#10 edit
.... //depot/perl/wince/config_h.PL#4 edit
.... //depot/perl/wince/perldll.def#7 delete
.... //depot/perl/wince/win32io.c#1 add
.... //depot/perl/wince/wince.c#7 edit

Differences ...

==== //depot/perl/MANIFEST#875 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST.~1~   Sat May  4 19:15:05 2002
+++ perl/MANIFEST       Sat May  4 19:15:05 2002
@@ -2742,6 +2742,7 @@
 wince/bin/runperl.pl                   WinCE port
 wince/bin/search.pl                    WinCE port
 wince/cecopy-lib.pl                    WinCE port
+wince/compile.bat                      WinCE port
 wince/comp.pl                          WinCE port
 wince/config.ce                                WinCE port
 wince/config.h                         WinCE port
@@ -2762,7 +2763,6 @@
 wince/Makefile.ce                      WinCE port
 wince/makeico.pl                       WinCE port
 wince/perl.rc                          WinCE port
-wince/perldll.def                      WinCE port
 wince/perllib.c                                WinCE port
 wince/perlmain.c                       WinCE port
 wince/README.compile                   WinCE port
@@ -2774,6 +2774,7 @@
 wince/win32iop.h                       WinCE port
 wince/win32thread.c                    WinCE port
 wince/win32thread.h                    WinCE port
+wince/win32io.c                                WinCE port
 wince/wince.c                          WinCE port
 wince/wince.h                          WinCE port
 wince/wincesck.c                       WinCE port

==== //depot/perl/configpm#33 (xtext) ====
Index: perl/configpm
--- perl/configpm.~1~   Sat May  4 19:15:05 2002
+++ perl/configpm       Sat May  4 19:15:05 2002
@@ -1,7 +1,36 @@
 #!./miniperl -w
 
-my $config_pm = $ARGV[0] || 'lib/Config.pm';
+# following options are recognized:
+# --no-glossary  - no glossary file inclusion, for compactness
+# --cross=PALTFORM - crosscompiling for PLATFORM
+my %opts = (
+  # %known_opts enumerates allowed opts as well as specifies default and initial 
+values
+  my %known_opts = (
+     'cross' => '',
+     'glossary' => 1,
+  ),
+  # options itself
+  my %specified_opts = (
+    (map {/^--([\-_\w]+)=(.*)$/} @ARGV),                            # --opt=smth
+    (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV),  # --opt 
+--no-opt --noopt
+  ),
+);
+die "option '$_' is not recognized" for grep {!exists $known_opts{$_}} keys 
+%specified_opts;
+@ARGV = grep {!/^--/} @ARGV;
+
+my $config_pm;
 my $glossary = $ARGV[1] || 'Porting/Glossary';
+
+if ($opts{cross}) {
+  # creating cross-platform config file
+  mkdir "xlib";
+  mkdir "xlib/$opts{cross}";
+  $config_pm = $ARGV[0] || "xlib/$opts{cross}/Config.pm";
+}
+else {
+  $config_pm = $ARGV[0] || 'lib/Config.pm';
+}
+
 @ARGV = "./config.sh";
 
 # list names to put first (and hence lookup fastest)
@@ -414,7 +443,9 @@
 
 ENDOFTAIL
 
-open(GLOS, "<$glossary") or die "Can't open $glossary: $!";
+if ($opts{glossary}) {
+  open(GLOS, "<$glossary") or die "Can't open $glossary: $!";
+}
 %seen = ();
 $text = 0;
 $/ = '';
@@ -468,10 +499,12 @@
   s/n[\0]t/n't/g;              # undo can't, won't damage
 }
 
-<GLOS>;                                # Skip the preamble
-while (<GLOS>) {
-  process;
-  print CONFIG;
+if ($opts{glossary}) {
+  <GLOS>;                              # Skip the preamble
+  while (<GLOS>) {
+    process;
+    print CONFIG;
+  }
 }
 
 print CONFIG <<'ENDOFTAIL';
@@ -491,6 +524,19 @@
 close(CONFIG);
 close(GLOS);
 
+# Now create Cross.pm if needed
+if ($opts{cross}) {
+  open CROSS, ">lib/Cross.pm" or die "Can not open >lib/Cross.pm: $!";
+  print CROSS <<"EOS";
+sub BEGIN {
+  \@INC = map {/\\blib\\b/?(do{local 
+\$_=\$_;s/\\blib\\b/xlib\\/$opts{cross}/;\$_},\$_):(\$_)} \@INC;
+}
+1;
+EOS
+  close CROSS;
+}
+
+
 # Now do some simple tests on the Config.pm file we have created
 unshift(@INC,'lib');
 require $config_pm;

==== //depot/perl/makedef.pl#121 (text) ====
Index: perl/makedef.pl
--- perl/makedef.pl.~1~ Sat May  4 19:15:05 2002
+++ perl/makedef.pl     Sat May  4 19:15:05 2002
@@ -17,12 +17,12 @@
     $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
     $CCTYPE   = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
     $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
-       if ($PLATFORM eq 'netware') {
-               $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
-       }
+    if ($PLATFORM eq 'netware') {
+       $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
+    }
 }
 
-my @PLATFORM = qw(aix win32 os2 MacOS netware);
+my @PLATFORM = qw(aix win32 wince os2 MacOS netware);
 my %PLATFORM;
 @PLATFORM{@PLATFORM} = ();
 
@@ -42,7 +42,7 @@
 if ($PLATFORM eq 'aix') {
     # Nothing for now.
 }
-elsif ($PLATFORM eq 'win32' || $PLATFORM eq 'netware') {
+elsif ($PLATFORM =~ /^win(?:32|ce)$/ || $PLATFORM eq 'netware') {
     $CCTYPE = "MSVC" unless defined $CCTYPE;
     foreach ($thrdvar_h, $intrpvar_h, $perlvars_h, $global_sym,
                $pp_sym, $globvar_sym, $perlio_sym) {
@@ -56,7 +56,7 @@
     }
 }
 
-unless ($PLATFORM eq 'win32' || $PLATFORM eq 'MacOS' || $PLATFORM eq 'netware') {
+unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'MacOS' || 
+$PLATFORM eq 'netware') {
     open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
     while (<CFG>) {
        if (/^(?:ccflags|optimize)='(.+)'$/) {
@@ -106,9 +106,10 @@
 
 my $sym_ord = 0;
 
-if ($PLATFORM eq 'win32') {
+if ($PLATFORM =~ /^win(?:32|ce)$/) {
     warn join(' ',keys %define)."\n";
-    print "LIBRARY perl58\n";
+    ($dll = ($define{PERL_DLL} || "perl58")) =~ s/\.dll$//i;
+    print "LIBRARY $dll\n";
     print "DESCRIPTION 'Perl interpreter'\n";
     print "EXPORTS\n";
     if ($define{PERL_IMPLICIT_SYS}) {
@@ -243,6 +244,77 @@
                     Perl_my_popen
                     )];
 }
+elsif ($PLATFORM eq 'wince') {
+    skip_symbols [qw(
+                    PL_statusvalue_vms
+                    PL_archpat_auto
+                    PL_cryptseen
+                    PL_DBcv
+                    PL_generation
+                    PL_lastgotoprobe
+                    PL_linestart
+                    PL_modcount
+                    PL_pending_ident
+                    PL_sortcxix
+                    PL_sublex_info
+                    PL_timesbuf
+                    PL_collation_ix
+                    PL_collation_name
+                    PL_collation_standard
+                    PL_collxfrm_base
+                    PL_collxfrm_mult
+                    PL_numeric_compat1
+                    PL_numeric_local
+                    PL_numeric_name
+                    PL_numeric_radix_sv
+                    PL_numeric_standard
+                    PL_vtbl_collxfrm
+                    Perl_sv_collxfrm
+                    setgid
+                    setuid
+                    win32_async_check
+                    win32_free_childdir
+                    win32_free_childenv
+                    win32_get_childdir
+                    win32_get_childenv
+                    win32_spawnvp
+                    main
+                    Perl_ErrorNo
+                    Perl_GetVars
+                    Perl_do_exec3
+                    Perl_do_ipcctl
+                    Perl_do_ipcget
+                    Perl_do_msgrcv
+                    Perl_do_msgsnd
+                    Perl_do_semop
+                    Perl_do_shmio
+                    Perl_dump_fds
+                    Perl_init_thread_intern
+                    Perl_my_bzero
+                    Perl_my_bcopy
+                    Perl_my_htonl
+                    Perl_my_ntohl
+                    Perl_my_swap
+                    Perl_my_chsize
+                    Perl_same_dirent
+                    Perl_setenv_getix
+                    Perl_unlnk
+                    Perl_watch
+                    Perl_safexcalloc
+                    Perl_safexmalloc
+                    Perl_safexfree
+                    Perl_safexrealloc
+                    Perl_my_memcmp
+                    Perl_my_memset
+                    PL_cshlen
+                    PL_cshname
+                    PL_opsave
+                    Perl_do_exec
+                    Perl_getenv_len
+                    Perl_my_pclose
+                    Perl_my_popen
+                    )];
+}
 elsif ($PLATFORM eq 'aix') {
     skip_symbols([qw(
                     Perl_dump_fds
@@ -880,7 +952,7 @@
     try_symbol($_);
 }
 
-if ($PLATFORM eq 'win32') {
+if ($PLATFORM =~ /^win(?:32|ce)$/) {
     foreach my $symbol (qw(
                            setuid
                            setgid
@@ -1221,7 +1293,7 @@
 
 sub output_symbol {
     my $symbol = shift;
-    if ($PLATFORM eq 'win32') {
+    if ($PLATFORM =~ /^win(?:32|ce)$/) {
        $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
        print "\t$symbol\n";
 # XXX: binary compatibility between compilers is an exercise

==== //depot/perl/wince/Makefile.ce#13 (text) ====
Index: perl/wince/Makefile.ce
--- perl/wince/Makefile.ce.~1~  Sat May  4 19:15:05 2002
+++ perl/wince/Makefile.ce      Sat May  4 19:15:05 2002
@@ -6,19 +6,32 @@
 PV         = 57
 INST_VER   = 5.7.3
 
+# INSTALL_ROOT specifies a path where this perl will be installed on CE device
 INSTALL_ROOT=/netzwerk/sprache/perl
+INST_TOP=$(INSTALL_ROOT)
+INST_VER=
 
 # PERLCEDIR shoud be set to current directory
 PERLCEDIR  = H:\src\wince\perl\wince
 
-WCEROOT    = N:\Windows CE Tools
+# WCEROOT is a directory where Windows CE Tools was installed
 WCEROOT    = D:\Windows CE Tools
-NTPERL     = N:\Programme\perl\bin\perl.exe
-NTPERL     = D:\Programme\ActiveState\perl-5.6\bin\Perl.exe
-CEPATH     = N:\Programme\Microsoft eMbedded Tools\EVC\WCE211\BIN
+
+# HPERL stands for host perl, which is perl on local desktop machine
+# which is usually ..\miniperl.exe
+#HPERL     = N:\Programme\perl\bin\perl.exe
+HPERL = $(MAKEDIR)\..\miniperl.exe
+
 CEPATH     = D:\Programme\Microsoft eMbedded Tools\EVC\WCE211\BIN
 CELIBDLLDIR  = h:\src\wince\celib-palm-3.0
 CECONSOLEDIR = h:\src\wince\w32console
+
+# specify following options to build perl on local machine, by MSVC
+MSVCDIR         = D:\MSVStudio\VC98
+CCHOME         = $(MSVCDIR)
+CCINCDIR       = $(CCHOME)\include
+CCLIBDIR       = $(CCHOME)\lib
+
 # Only for WIN2000
 #YES        = /y
 COPY       = copy $(YES)
@@ -28,6 +41,15 @@
 # cecopy program. Make shure it is in your path, as well as cemkdir, cedel
 CECOPY     = cecopy
 
+#
+# Comment out next assign to disable perl's I/O subsystem and use compiler's 
+# stdio for IO - depending on your compiler vendor and run time library you may 
+# then get a number of fails from make test i.e. bugs - complain to them not us ;-). 
+# You will also be unable to take full advantage of perl5.8's support for multiple 
+# encodings and may see lower IO performance. You have been warned.
+USE_PERLIO     = define
+
+
 NOOP      = @echo
 # keep this untouched!
 NULL      =
@@ -377,6 +399,10 @@
 USE_IMP_SYS    = undef
 !ENDIF
 
+!IF "$(USE_PERLIO)" == ""
+USE_PERLIO     = undef
+!ENDIF
+
 !IF "$(USE_PERLCRT)" == ""
 USE_PERLCRT    = undef
 !ENDIF
@@ -398,6 +424,10 @@
 BUILDOPT       = $(BUILDOPT) -DPERL_IMPLICIT_SYS
 !ENDIF
 
+!IF "$(USE_PERLIO)" == "define"
+BUILDOPT       = $(BUILDOPT) -DUSE_PERLIO
+!ENDIF
+
 # new option - automatically defined in perl.h...
 #BUILDOPT        = $(BUILDOPT) -DUSE_ENVIRON_ARRAY
 
@@ -500,7 +530,7 @@
 #
 # filenames given to xsubpp must have forward slashes (since it puts
 # full pathnames in #line strings)
-XSUBPP         = $(NTPERL) -I..\..\lib ..\$(EXTUTILSDIR)\xsubpp \
+XSUBPP         = $(HPERL) -I..\..\lib ..\$(EXTUTILSDIR)\xsubpp \
                -C++ -prototypes
 
 MICROCORE_SRC  =               \
@@ -713,6 +743,7 @@
  "useithreads=$(USE_ITHREADS)" \
  "usethreads=$(USE_5005THREADS)" \
  "usemultiplicity=$(USE_MULTI)" \
+ "useperlio=$(USE_PERLIO)" \
  "LINK_FLAGS=$(LDLIBPATH) $(LINK_FLAGS) $(SUBSYS)" \
  "optimize=$(OPTIMIZE)"
 
@@ -720,24 +751,25 @@
 # Top targets
 #
 
-all: $(MINIMOD) $(CONFIGPM) $(PERLEXE)
+all: hostminiperl $(MINIMOD) $(CONFIGPM) $(PERLEXE)
 
 $(DYNALOADER)$(o) : $(DYNALOADER).c $(CORE_H) $(EXTDIR)\DynaLoader\dlutils.c
 
 $(CONFIGPM): config.h ..\config.sh ..\minimod.pl
-       cd .. && $(NTPERL) configpm
+       cd .. && $(HPERL) configpm
+       cd .. && $(HPERL) configpm --cross=wince --no-glossary
        -mkdir $(COREDIR)
        $(XCOPY) ..\*.h $(COREDIR)\*.*
        $(XCOPY) *.h $(COREDIR)\*.*
        $(XCOPY) ..\ext\re\re.pm $(LIBDIR)\*.*
        $(RCOPY) include $(COREDIR)\*.*
-       $(NTPERL) -I..\lib config_h.PL "INST_VER=$(INST_VER)"
+       $(HPERL) -I..\lib config_h.PL "INST_VER=$(INST_VER)"
 
 ..\config.sh config.h: config.ce config_sh.PL
-       $(NTPERL) -I..\lib config_sh.PL $(CFG_VARS) config.ce > ..\config.sh
+       $(HPERL) -I..\lib config_sh.PL $(CFG_VARS) config.ce > ..\config.sh
 
 $(MINIMOD) : ..\minimod.pl
-       cd .. && $(NTPERL) minimod.pl > lib\ExtUtils\Miniperl.pm
+       cd .. && $(HPERL) minimod.pl > lib\ExtUtils\Miniperl.pm
 
 perlmain.c : runperl.c 
        $(COPY) runperl.c perlmain.c
@@ -745,8 +777,8 @@
 $(DYNALOADER).c: $(EXTDIR)\DynaLoader\dl_win32.xs $(CONFIGPM)
        if not exist $(AUTODIR) mkdir $(AUTODIR)
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib $(*B)_pm.PL
-       $(NTPERL) -I..\..\lib XSLoader_pm.PL
+       $(HPERL) -I..\..\lib $(*B)_pm.PL
+       $(HPERL) -I..\..\lib XSLoader_pm.PL
        cd ..\..\wince
        $(XCOPY) $(EXTDIR)\$(*B)\$(*B).pm $(LIBDIR)\$(NULL)
        $(XCOPY) $(EXTDIR)\$(*B)\XSLoader.pm $(LIBDIR)\$(NULL)
@@ -759,103 +791,103 @@
 
 $(DUMPER_DLL): $(PERLEXE) $(DUMPER).xs
        cd $(EXTDIR)\Data\$(*B)
-       $(NTPERL) -I..\..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\..\wince
 
 $(DPROF_DLL): $(PERLEXE) $(DPROF).xs
        cd $(EXTDIR)\Devel\$(*B)
-       $(NTPERL) -I..\..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\..\wince
 
 $(GLOB_DLL): $(PERLEXE) $(GLOB).xs
        cd $(EXTDIR)\File\$(*B)
-       $(NTPERL) -I..\..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\..\wince
 
 $(PEEK_DLL): $(PERLEXE) $(PEEK).xs
        cd $(EXTDIR)\Devel\$(*B)
-       $(NTPERL) -I..\..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\..\wince
 
 $(RE_DLL): $(PERLEXE) $(RE).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(B_DLL): $(PERLEXE) $(B).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(THREAD_DLL): $(PERLEXE) $(THREAD).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(ATTRS_DLL): $(PERLEXE) $(ATTRS).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(POSIX_DLL): $(PERLEXE) $(POSIX).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(IO_DLL): $(PERLEXE) $(IO).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(SDBM_FILE_DLL) : $(PERLEXE) $(SDBM_FILE).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(FCNTL_DLL): $(PERLEXE) $(FCNTL).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(OPCODE_DLL): $(PERLEXE) $(OPCODE).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(SOCKET_DLL): $(PERLEXE) $(SOCKET).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(HOSTNAME_DLL): $(PERLEXE) $(HOSTNAME).xs
        cd $(EXTDIR)\Sys\$(*B)
-       $(NTPERL) -I..\..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\..\wince
 
 $(BYTELOADER_DLL): $(PERLEXE) $(BYTELOADER).xs
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
 $(ERRNO_PM): $(PERLEXE) $(ERRNO)_pm.PL
        cd $(EXTDIR)\$(*B)
-       $(NTPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
+       $(HPERL) -I..\..\lib Makefile.PL PERL_CORE=1 INSTALLDIRS=perl
        $(MAKE)
        cd ..\..\wince
 
@@ -875,7 +907,7 @@
 
 install_perlexe: $(PERLEXE)
        cedel /speicherkarte2/bin/perl.exe
-       $(CECOPY) pc:../perl.exe ce:/speicherkarte2/bin
+       $(CECOPY) pc:../perl.exe ce:$(INSTALL_ROOT)/bin
 
 install_perldll: $(PERLDLL)
        cedel /speicherkarte2/bin/perl$(PV).dll
@@ -888,17 +920,17 @@
        ceexec /speicherkarte2/bin/perl.exe /speicherkarte2/bin/test.pl
 
 install_lib: ../lib/Config.pm
-       $(CECOPY)       pc:../lib/Config.pm ce:/speicherkarte2/usr/lib/perl5
+       $(CECOPY)       pc:../lib/Config.pm ce:$(INSTALL_ROOT)/lib
 
 !ELSEIF "$(MACHINE)" == "wince-arm-hpc"
 
 install_perlexe: $(PERLEXE)
        -cedel /speicherkarte/bin/perl.exe
-       $(CECOPY) pc:$(MACHINE)/perl.exe ce:/speicherkarte/bin
+       $(CECOPY) pc:$(MACHINE)/perl.exe ce:$(INSTALL_ROOT)/bin
 
 install_perldll: $(PERLDLL)
        -cedel /speicherkarte/bin/perl$(PV).dll
-       $(CECOPY) pc:$(MACHINE)/perl$(PV).dll ce:/speicherkarte/bin
+       $(CECOPY) pc:$(MACHINE)/perl$(PV).dll ce:$(INSTALL_ROOT)/bin
 
 install_perl: install_perlexe install_perldll
 
@@ -907,7 +939,7 @@
        ceexec /speicherkarte/bin/perl.exe /speicherkarte/bin/test.pl
 
 install_lib: ../lib/Config.pm
-       $(CECOPY)       pc:../lib/Config.pm ce:/speicherkarte/usr/lib/perl5
+       $(CECOPY)       pc:../lib/Config.pm ce:$(INSTALL_ROOT)/lib
 
 !ELSEIF "$(MACHINE)" == "wince-mips-hpc"
 
@@ -924,7 +956,7 @@
        ceexec /netzwerk/compaq/bin/perl.exe $(INSTALL_ROOT)/test.pl
 
 install_lib: ../lib/Config.pm
-       $(CECOPY)       pc:../lib/Config.pm ce:/netzwerk/compaq/usr/lib/perl5
+       $(CECOPY)       pc:../lib/Config.pm ce:$(INSTALL_ROOT)/lib
 
 !ELSEIF "$(MACHINE)" == "wince-x86em-pocket"
 
@@ -934,10 +966,10 @@
        ftpcopy ../lib/Exporter/Heavy.pm ftp!ftp@localhost:/perl/lib/Exporter
 
 install_perlexe: $(PERLEXE)
-       $(CECOPY) pc:../perl.exe ce:/netzwerk/compaq/bin
+       $(CECOPY) pc:../perl.exe ce:$(INSTALL_ROOT)/bin
 
 install_perldll: $(PERLDLL)
-       $(CECOPY) pc:../perl$(PV).dll ce:/netzwerk/compaq/bin
+       $(CECOPY) pc:../perl$(PV).dll ce:$(INSTALL_ROOT)/bin
 
 install_perl: install_perlexe install_perldll
 
@@ -994,6 +1026,10 @@
 {$(SRCDIR)/wince}.c{$(DLLDIR)}.obj:
     $(CC) -c $(CFLAGS) -DPERL_EXTERNAL_GLOB -Fo$(DLLDIR)\ $<
 
+perldll.def : $(HPERL) $(CONFIGPM) ..\global.sym ..\pp.sym ...\makedef.pl
+       $(HPERL) -w ..\makedef.pl PLATFORM=wince $(OPTIMIZE) $(DEFINES) $(BUILDOPT) \
+           CCTYPE=$(CCTYPE) -DPERL_DLL=$(PERLDLL) > perldll.def
+
 $(PERLDLL) : $(DLLDIR) perldll.def $(XDLLOBJS) $(PERLDLL_RES)
        $(LINK32) -dll -def:perldll.def -out:$@ \
                   $(SUBSYS) $(LDLIBPATH) \
@@ -1049,43 +1085,28 @@
 
 !if "$(MACHINE)" == "wince-arm-hpc-wce300"
 install: all
-       $(CECOPY) pc:$(MACHINE)/perl.exe ce:/speicherkarte/bin
-       $(CECOPY) pc:$(MACHINE)/perl$(PV).dll ce:/speicherkarte/bin
+       $(CECOPY) pc:$(MACHINE)/perl.exe ce:$(INSTALL_ROOT)/bin
+       $(CECOPY) pc:$(MACHINE)/perl$(PV).dll ce:$(INSTALL_ROOT)/bin
 install_dlls: dlls
-       $(CECOPY) pc:../lib/auto/IO/io.dll 
ce:/speicherkarte/usr/lib/perl5/auto/IO/io.dll
+       $(CECOPY) pc:../lib/auto/IO/io.dll ce:$(INSTALL_ROOT)/lib/auto/IO/io.dll
 !else
 install: all
        -cemkdir "$(INSTALL_ROOT)"
        -cemkdir "$(INSTALL_ROOT)\bin"
        -cemkdir "$(INSTALL_ROOT)\lib"
        $(CECOPY) "pc:$(MACHINE)/perl.exe" "ce:$(INSTALL_ROOT)/bin"
-       $(CECOPY) "pc:$(MACHINE)/perl.dll" "ce:$(INSTALL_ROOT)/bin"
-       $(CECOPY) "pc:../lib/Config.pm" "ce:$(INSTALL_ROOT)/lib"
+       $(CECOPY) "pc:$(MACHINE)/perl$(PV).dll" "ce:$(INSTALL_ROOT)/bin"
+       $(CECOPY) "pc:../xlib/wince/Config.pm" "ce:$(INSTALL_ROOT)/lib"
 !endif
 
-!if "$(MACHINE)" == "wince-arm-hpc-wce211"
-install: all
-       $(CECOPY) pc:$(MACHINE)/perl.exe ce:/speicherkarte/bin
-       $(CECOPY) pc:$(MACHINE)/perl$(PV).dll ce:/speicherkarte/bin
-!endif
+perl.ico:
+       $(HPERL) makeico.pl
 
-!if "$(MACHINE)" == "wince-mips-hpc-wce211"
-install:
-       $(CECOPY) pc:$(MACHINE)/perl.exe ce:/bin
-       $(CECOPY) pc:$(MACHINE)/perl$(PV).dll ce:/bin
-!endif
+hostminiperl: ..\miniperl.exe
 
-!if "$(MACHINE)" == "wince-mips-hpc-wce200"
-install:
-       $(CECOPY) pc:$(MACHINE)/perl.exe ce:/bin
-       $(CECOPY) pc:$(MACHINE)/perl$(PV).dll ce:/bin
-!endif
+..\miniperl.exe:
+       cd ../win32
+       set PATH=$(CCHOME)\bin;$(PATH)
+       $(MAKE) -f Makefile "CCHOME=$(MSVCDIR)" "CCINCDIR=$(CCHOME)\include" 
+"CCLIBDIR=$(CCHOME)\lib" "INCLUDE=$(CCHOME)\include" "LIB=$(CCHOME)\lib" 
+"LINK_FLAGS=" ..\config.h ..\miniperl.exe
+       cd ../wince
 
-!if "$(MACHINE)" == "wince-sh3-hpc-wce211"
-install:
-       $(CECOPY) pc:$(MACHINE)/perl.exe ce:$(INSTALL_ROOT)/bin
-       $(CECOPY) pc:$(MACHINE)/perl$(PV).dll ce:$(INSTALL_ROOT)/bin
-!endif
-
-perl.ico:
-       perl makeico.pl

==== //depot/perl/wince/cecopy-lib.pl#2 (text) ====
Index: perl/wince/cecopy-lib.pl
--- perl/wince/cecopy-lib.pl.~1~        Sat May  4 19:15:05 2002
+++ perl/wince/cecopy-lib.pl    Sat May  4 19:15:05 2002
@@ -12,8 +12,8 @@
     $r=~/^(.*)\/[^\/]*?$/;
     mk($1);
   }
-  system("$^X comp.pl --do cemkdir [p]\\lib\\$r");
-  print STDERR "$^X comp.pl --do cemkpath [p]\\lib\\$r\n";
+  print STDERR "..\\miniperl.exe comp.pl --do cemkdir [p]\\lib\\$r\n";
+  system("..\\miniperl.exe -I..\\lib comp.pl --do cemkdir [p]\\lib\\$r");
   $dirs{$r}++;
 }
 for (@files) {
@@ -22,7 +22,7 @@
     mk($1);
   }
   # currently no stripping POD
-  system("$^X comp.pl --do cecopy pc:..\\lib\\$_ ce:[p]\\lib\\$_");
+  system("..\\miniperl.exe -I..\\lib comp.pl --copy pc:..\\lib\\$_ ce:[p]\\lib\\$_");
 }
 
 sub BEGIN {

==== //depot/perl/wince/comp.pl#2 (text) ====
Index: perl/wince/comp.pl
--- perl/wince/comp.pl.~1~      Sat May  4 19:15:05 2002
+++ perl/wince/comp.pl  Sat May  4 19:15:05 2002
@@ -2,21 +2,12 @@
 
 helper script to make life for PerlCE easier.
 
-You need edit values for @defs array to reflect your changes and then do
-
-  perl comp.pl [any-additional-options]
-
-This will call
-  nmake -f Makefile.ce
-with most parameters overrided as you specified and additional options
-(such as build target) will also be prepended to command line to execute.
-
-There are also additional different modes for running this script:
+There are different modes for running this script:
   perl comp.pl --run [any-command-line-arguments]
 and
   perl comp.pl --do [any-command-line-arguments]
 and
-  perl comp.pl --copy-pm pc:[pc-location] ce:[ce-location]
+  perl comp.pl --copy pc:[pc-location] ce:[ce-location]
 
 --run executes this build of perl on CE device with arguments provided
 --run=test will display a predefined messagebox that say everything is ok.
@@ -37,32 +28,16 @@
 
 =cut
 
-use Cwd;
 use strict;
+use Cross;
+use Config;
 
 # edit value of $inst_root variable to reflect your desired location of
 # built perl
-my $inst_root = "\\Storage Card\\perl-tests\\perl\@16225";
-my @defs = (
-  "\"PV=\"",
-  "\"INST_VER=\"",
-  "\"INSTALL_ROOT=$inst_root\"",
-  "\"WCEROOT=$ENV{SDKROOT}\"",
-  "NTPERL=$^X", #todo: check version: this must be (almost?) current version
-  "\"CEPATH=$ENV{WCEROOT}\"",
-  "CELIBDLLDIR=d:\\personal\\pocketPC\\celib-palm-3.0",
-  "CECONSOLEDIR=d:\\personal\\pocketPC\\w32console",
-  "YES=/y",
-  "CFG=RELEASE",
-  "MACHINE=wince-mips-pocket-wce300",
-  "PERLCEDIR=".cwd,
-  #NIY "\"CECOPY=\$(NTPERL) \$(PERLCEDIR)\\$0 --copy=compact\"",
-  "\"CECOPY=\$(NTPERL) \$(PERLCEDIR)\\$0 --copy\"",
-);
+my $inst_root = $Config{prefix};
 
 my %opts = (
-  # %known_opts enumerates allowed opts as well as specifies default
-  #   and initial values
+  # %known_opts enumerates allowed opts as well as specifies default and initial 
+values
   my %known_opts = (
      'do' => '',
      'run' => '',
@@ -98,9 +73,7 @@
   system("cecopy",@ARGV);
 }
 else {
-  my $cmd = "nmake -f Makefile.ce @defs @ARGV";
-  print $cmd;
-  system($cmd);
+  # todo
 }
 
 

==== //depot/perl/wince/config.ce#10 (text) ====
Index: perl/wince/config.ce
--- perl/wince/config.ce.~1~    Sat May  4 19:15:05 2002
+++ perl/wince/config.ce        Sat May  4 19:15:05 2002
@@ -43,7 +43,7 @@
 c=''
 castflags='0'
 cat='type'
-cc='cl'
+cc='~CC~'
 cccdlflags=' '
 ccdlflags=' '
 ccflags='-DWIN32'
@@ -61,14 +61,14 @@
 contains='grep'
 cp='copy'
 cpio=''
-cpp='cl -nologo -E'
+cpp='~CC~ -nologo -E'
 cpp_stuff='42'
 cppccsymbols=''
 cppflags='-DWIN32'
 cpplast=''
 cppminus=''
-cpprun='cl -nologo -E'
-cppstdin='cl -nologo -E'
+cpprun='~CC~ -nologo -E'
+cppstdin='~CC~ -nologo -E'
 cppsymbols=''
 crosscompile='undef'
 crypt_r_proto='0'
@@ -331,7 +331,7 @@
 d_sethent='undef'
 d_sethostent_r='undef'
 d_setlinebuf='undef'
-d_setlocale='undef'
+d_setlocale='define'
 d_setlocale_r='undef'
 d_setnent='undef'
 d_setnetent_r='undef'
@@ -379,7 +379,7 @@
 d_stdiobase='undef'
 d_stdstdio='undef'
 d_strchr='define'
-d_strcoll='undef'
+d_strcoll='define'
 d_strctcpy='define'
 d_strerrm='strerror(e)'
 d_strerror='define'
@@ -529,6 +529,7 @@
 i_grp='undef'
 i_ieeefp='undef'
 i_inttypes='undef'
+i_langinfo='undef'
 i_limits='define'
 i_locale='undef'
 i_machcthr='undef'
@@ -542,6 +543,7 @@
 i_netinettcp='undef'
 i_niin='undef'
 i_poll='undef'
+i_prot='undef'
 i_pthread='undef'
 i_pwd='undef'
 i_rpcsvcdbm='define'
@@ -701,6 +703,7 @@
 orderlib='false'
 osname='MSWin32'
 osvers='4.0'
+otherlibdirs=''
 package='perl5'
 pager='more /e'
 passcat=''
@@ -852,7 +855,7 @@
 use64bitall='undef'
 use64bitint='undef'
 usedl='define'
-useithreads='undef'
+useithreads='~USE_ITHREADS~'
 uselargefiles='undef'
 uselongdouble='undef'
 usemorebits='undef'
@@ -860,7 +863,7 @@
 usemymalloc='n'
 usenm='false'
 useopcode='true'
-useperlio='define'
+useperlio='~USE_PERLIO~'
 useposix='true'
 usesfio='false'
 useshrplib='yes'

==== //depot/perl/wince/config_h.PL#4 (text) ====
Index: perl/wince/config_h.PL
--- perl/wince/config_h.PL.~1~  Sat May  4 19:15:05 2002
+++ perl/wince/config_h.PL      Sat May  4 19:15:05 2002
@@ -1,5 +1,11 @@
 #
-use Config;
+BEGIN { warn "Running ".__FILE__."\n" };
+BEGIN 
+ {
+  require "../lib/Config.pm";
+  die "../Config.pm:$@" if $@;
+  Config::->import;
+ }
 use File::Compare qw(compare);
 use File::Copy qw(copy);
 my $name = $0;
@@ -13,6 +19,8 @@
 
 $opt{CONFIG_H} ||= 'config.h';
 
+warn "Writing $opt{CONFIG_H}\n";
+
 my $patchlevel = $opt{INST_VER};
 $patchlevel =~ s|^[\\/]||;
 $patchlevel =~ s|~VERSION~|$Config{version}|g;
@@ -68,9 +76,9 @@
 close(SH);
 
 
-chmod(0666,"config.h");
-copy("$file.new","config.h") || die "Cannot copy:$!";
-chmod(0444,"config.h");
+chmod(0666,"../lib/CORE/config.h");
+copy("$file.new","../lib/CORE/config.h") || die "Cannot copy:$!";
+chmod(0444,"../lib/CORE/config.h");
 
 if (compare("$file.new",$file))
  {

==== //depot/perl/wince/wince.c#7 (text) ====
Index: perl/wince/wince.c
--- perl/wince/wince.c.~1~      Sat May  4 19:15:05 2002
+++ perl/wince/wince.c  Sat May  4 19:15:05 2002
@@ -1632,7 +1632,115 @@
     int fh;
     char fileflags=0;          /* _osfile flags */
 
-    XCEMessageBoxA(NULL, "NEED TO IMPLEMENT a place in 
../wince/wince.c(win32_open_osfhandle)", "Perl(developer)", 0);
+    XCEMessageBoxA(NULL, "NEED TO IMPLEMENT in wince/wince.c(win32_open_osfhandle)", 
+"error", 0);
     Perl_croak_nocontext("win32_open_osfhandle() TBD on this platform");
     return 0;
 }
+
+int
+win32_get_osfhandle(intptr_t osfhandle, int flags)
+{
+    int fh;
+    char fileflags=0;          /* _osfile flags */
+
+    XCEMessageBoxA(NULL, "NEED TO IMPLEMENT in wince/wince.c(win32_get_osfhandle)", 
+"error", 0);
+    Perl_croak_nocontext("win32_get_osfhandle() TBD on this platform");
+    return 0;
+}
+
+/*
+ * a popen() clone that respects PERL5SHELL
+ *
+ * changed to return PerlIO* rather than FILE * by BKS, 11-11-2000
+ */
+
+DllExport PerlIO*
+win32_popen(const char *command, const char *mode)
+{
+    XCEMessageBoxA(NULL, "NEED TO IMPLEMENT in wince/wince.c(win32_popen)", "error", 
+0);
+    Perl_croak_nocontext("win32_popen() TBD on this platform");
+}
+
+/*
+ * pclose() clone
+ */
+
+DllExport int
+win32_pclose(PerlIO *pf)
+{
+#ifdef USE_RTL_POPEN
+    return _pclose(pf);
+#else
+    dTHX;
+    int childpid, status;
+    SV *sv;
+
+    LOCK_FDPID_MUTEX;
+    sv = *av_fetch(w32_fdpid, PerlIO_fileno(pf), TRUE);
+
+    if (SvIOK(sv))
+       childpid = SvIVX(sv);
+    else
+       childpid = 0;
+
+    if (!childpid) {
+       errno = EBADF;
+        return -1;
+    }
+
+#ifdef USE_PERLIO
+    PerlIO_close(pf);
+#else
+    fclose(pf);
+#endif
+    SvIVX(sv) = 0;
+    UNLOCK_FDPID_MUTEX;
+
+    if (win32_waitpid(childpid, &status, 0) == -1)
+        return -1;
+
+    return status;
+
+#endif /* USE_RTL_POPEN */
+}
+
+FILE *
+win32_fdupopen(FILE *pf)
+{
+    FILE* pfdup;
+    fpos_t pos;
+    char mode[3];
+    int fileno = win32_dup(win32_fileno(pf));
+
+    XCEMessageBoxA(NULL, "NEED TO IMPLEMENT a place in 
+.../wince/wince.c(win32_fdupopen)", "Perl(developer)", 0);
+    Perl_croak_nocontext("win32_fdupopen() TBD on this platform");
+
+#if 0
+    /* open the file in the same mode */
+    if((pf)->_flag & _IOREAD) {
+       mode[0] = 'r';
+       mode[1] = 0;
+    }
+    else if((pf)->_flag & _IOWRT) {
+       mode[0] = 'a';
+       mode[1] = 0;
+    }
+    else if((pf)->_flag & _IORW) {
+       mode[0] = 'r';
+       mode[1] = '+';
+       mode[2] = 0;
+    }
+
+    /* it appears that the binmode is attached to the
+     * file descriptor so binmode files will be handled
+     * correctly
+     */
+    pfdup = win32_fdopen(fileno, mode);
+
+    /* move the file pointer to the same position */
+    if (!fgetpos(pf, &pos)) {
+       fsetpos(pfdup, &pos);
+    }
+#endif
+    return pfdup;
+}

==== //depot/perl/wince/compile.bat#1 (text) ====
Index: perl/wince/compile.bat
--- perl/wince/compile.bat.~1~  Sat May  4 19:15:05 2002
+++ perl/wince/compile.bat      Sat May  4 19:15:05 2002
@@ -0,0 +1,25 @@
+@echo off
+rem
+rem edit ARG-xxx variable to reflect your system and run
+rem   compile.bat [target] [additional parameters for nmake]
+rem
+
+set ARG-1=PV=
+set ARG-2=INST_VER=
+set ARG-3=INSTALL_ROOT=\Storage Card\perl-tests\perl@16376
+set ARG-4=WCEROOT=%SDKROOT%
+set ARG-5=CEPATH=%WCEROOT%
+set ARG-6=CELIBDLLDIR=d:\personal\pocketPC\celib-palm-3.0
+set ARG-7=CECONSOLEDIR=d:\personal\pocketPC\w32console
+
+rem Only for WIN2000
+set ARG-8=YES=/y
+
+set ARG-9=CFG=RELEASE
+set ARG-10=MACHINE=wince-mips-pocket-wce300
+set ARG-11=PERLCEDIR=$(MAKEDIR)
+set ARG-12=MSVCDIR=D:\MSVStudio\VC98
+set ARG-13=CECOPY=$(HPERL) -I$(PERLCEDIR)\lib $(PERLCEDIR)\comp.pl --copy
+set ARG-14=USE_PERLIO=undef
+
+nmake -f Makefile.ce "%ARG-1%" "%ARG-2%" "%ARG-3%" "%ARG-4%" "%ARG-5%" "%ARG-6%" 
+"%ARG-7%" "%ARG-8%" "%ARG-9%" "%ARG-10%" "%ARG-11%" "%ARG-12%" "%ARG-13%" "%ARG-14%" 
+%1 %2 %3 %4 %5 %6 %7 %8 %9

==== //depot/perl/wince/win32io.c#1 (text) ====
Index: perl/wince/win32io.c
--- perl/wince/win32io.c.~1~    Sat May  4 19:15:05 2002
+++ perl/wince/win32io.c        Sat May  4 19:15:05 2002
@@ -0,0 +1,370 @@
+#define PERL_NO_GET_CONTEXT
+#define WIN32_LEAN_AND_MEAN
+#define WIN32IO_IS_STDIO
+#include <tchar.h>
+#ifdef __GNUC__
+#define Win32_Winsock
+#endif
+#include <windows.h>
+#include <cewin32.h>
+
+#include <sys/stat.h>
+#include "EXTERN.h"
+#include "perl.h"
+
+#ifdef PERLIO_LAYERS
+
+#include "perliol.h"
+
+#define NO_XSLOCKS
+#include "XSUB.h"
+
+
+/* Bottom-most level for Win32 case */
+
+typedef struct
+{
+ struct _PerlIO base;       /* The generic part */
+ HANDLE                h;          /* OS level handle */
+ IV            refcnt;     /* REFCNT for the "fd" this represents */
+ int           fd;         /* UNIX like file descriptor - index into fdtable */
+} PerlIOWin32;
+
+PerlIOWin32 *fdtable[256];
+IV max_open_fd = -1;
+
+IV
+PerlIOWin32_popped(pTHX_ PerlIO *f)
+{
+ PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
+ if (--s->refcnt > 0)
+  {
+   *f = PerlIOBase(f)->next;
+   return 1;
+  }
+ fdtable[s->fd] = NULL;
+ return 0;
+}
+
+IV
+PerlIOWin32_fileno(pTHX_ PerlIO *f)
+{
+ return PerlIOSelf(f,PerlIOWin32)->fd;
+}
+
+IV
+PerlIOWin32_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg)
+{
+ IV code = PerlIOBase_pushed(aTHX_ f,mode,arg);
+ if (*PerlIONext(f))
+  {
+   PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
+   s->fd     = PerlIO_fileno(PerlIONext(f));
+  }
+ PerlIOBase(f)->flags |= PERLIO_F_OPEN;
+ return code;
+}
+
+PerlIO *
+PerlIOWin32_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char 
+*mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args)
+{
+ const char *tmode = mode;
+ HANDLE h = INVALID_HANDLE_VALUE;
+ if (f)
+  {
+   /* Close if already open */
+   if (PerlIOBase(f)->flags & PERLIO_F_OPEN)
+    (*PerlIOBase(f)->tab->Close)(aTHX_ f);
+  }
+ if (narg > 0)
+  {
+   char *path = SvPV_nolen(*args);
+   DWORD  access = 0;
+   DWORD  share  = 0;
+   DWORD  create = -1;
+   DWORD  attr   = FILE_ATTRIBUTE_NORMAL;
+   if (*mode == '#')
+    {
+     /* sysopen - imode is UNIX-like O_RDONLY etc.
+        - do_open has converted that back to string form in mode as well
+        - perm is UNIX like permissions
+      */
+     mode++;
+    }
+   else
+    {
+     /* Normal open - decode mode string */
+    }
+   switch(*mode)
+    {
+     case 'r':
+      access  = GENERIC_READ;
+      create  = OPEN_EXISTING;
+      if (*++mode == '+')
+       {
+        access |= GENERIC_WRITE;
+        create  = OPEN_ALWAYS;
+        mode++;
+       }
+      break;
+
+     case 'w':
+      access  = GENERIC_WRITE;
+      create  = TRUNCATE_EXISTING;
+      if (*++mode == '+')
+       {
+        access |= GENERIC_READ;
+        mode++;
+       }
+      break;
+
+     case 'a':
+      access = GENERIC_WRITE;
+      create  = OPEN_ALWAYS;
+      if (*++mode == '+')
+       {
+        access |= GENERIC_READ;
+        mode++;
+       }
+      break;
+    }
+   if (*mode == 'b')
+    {
+     mode++;
+    }
+   else if (*mode == 't')
+    {
+     mode++;
+    }
+   if (*mode || create == -1)
+    {
+     //FIX-ME: SETERRNO(EINVAL,LIB$_INVARG);
+     XCEMessageBoxA(NULL, "NEED TO IMPLEMENT a place in ../wince/win32io.c", 
+"Perl(developer)", 0);
+     return NULL;
+    }
+   if (!(access & GENERIC_WRITE))
+    share = FILE_SHARE_READ;
+   h = CreateFileW(path,access,share,NULL,create,attr,NULL);
+   if (h == INVALID_HANDLE_VALUE)
+    {
+     if (create == TRUNCATE_EXISTING)
+      h = CreateFileW(path,access,share,NULL,(create = OPEN_ALWAYS),attr,NULL);
+    }
+  }
+ else
+  {
+   /* fd open */
+   h = INVALID_HANDLE_VALUE;
+   if (fd >= 0 && fd <= max_open_fd)
+    {
+     PerlIOWin32 *s = fdtable[fd];
+     if (s)
+      {
+       s->refcnt++;
+       if (!f)
+        f = PerlIO_allocate(aTHX);
+       *f = &s->base;
+       return f;
+      }
+    }
+   if (*mode == 'I')
+    {
+     mode++;
+     switch(fd)
+      {
+       case 0:
+        h = XCEGetStdHandle(STD_INPUT_HANDLE);
+        break;
+       case 1:
+        h = XCEGetStdHandle(STD_OUTPUT_HANDLE);
+        break;
+       case 2:
+        h = XCEGetStdHandle(STD_ERROR_HANDLE);
+        break;
+      }
+    }
+  }
+ if (h != INVALID_HANDLE_VALUE)
+  fd = win32_open_osfhandle((intptr_t) h, PerlIOUnix_oflags(tmode));
+ if (fd >= 0)
+  {
+   PerlIOWin32 *s;
+   if (!f)
+    f = PerlIO_allocate(aTHX);
+   s = PerlIOSelf(PerlIO_push(aTHX_ f,self,tmode,PerlIOArg),PerlIOWin32);
+   s->h      = h;
+   s->fd     = fd;
+   s->refcnt = 1;
+   if (fd >= 0)
+    {
+     fdtable[fd] = s;
+     if (fd > max_open_fd)
+      max_open_fd = fd;
+    }
+   return f;
+  }
+ if (f)
+  {
+   /* FIXME: pop layers ??? */
+  }
+ return NULL;
+}
+
+SSize_t
+PerlIOWin32_read(pTHX_ PerlIO *f, void *vbuf, Size_t count)
+{
+ PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
+ DWORD len;
+ if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD))
+  return 0;
+ if (ReadFile(s->h,vbuf,count,&len,NULL))
+  {
+   return len;
+  }
+ else
+  {
+   if (GetLastError() != NO_ERROR)
+    {
+     PerlIOBase(f)->flags |= PERLIO_F_ERROR;
+     return -1;
+    }
+   else
+    {
+     if (count != 0)
+      PerlIOBase(f)->flags |= PERLIO_F_EOF;
+     return 0;
+    }
+  }
+}
+
+SSize_t
+PerlIOWin32_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count)
+{
+ PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
+ DWORD len;
+ if (WriteFile(s->h,vbuf,count,&len,NULL))
+  {
+   return len;
+  }
+ else
+  {
+   PerlIOBase(f)->flags |= PERLIO_F_ERROR;
+   return -1;
+  }
+}
+
+IV
+PerlIOWin32_seek(pTHX_ PerlIO *f, Off_t offset, int whence)
+{
+ static const DWORD where[3] = { FILE_BEGIN, FILE_CURRENT, FILE_END };
+ PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
+ DWORD high = (sizeof(offset) > sizeof(DWORD)) ? (DWORD)(offset >> 32) : 0;
+ DWORD low  = (DWORD) offset;
+ DWORD res  = SetFilePointer(s->h,low,&high,where[whence]);
+ if (res != 0xFFFFFFFF || GetLastError() != NO_ERROR)
+  {
+   return 0;
+  }
+ else
+  {
+   return -1;
+  }
+}
+
+Off_t
+PerlIOWin32_tell(pTHX_ PerlIO *f)
+{
+ PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
+ DWORD high = 0;
+ DWORD res  = SetFilePointer(s->h,0,&high,FILE_CURRENT);
+ if (res != 0xFFFFFFFF || GetLastError() != NO_ERROR)
+  {
+   return ((Off_t) high << 32) | res;
+  }
+ return (Off_t) -1;
+}
+
+IV
+PerlIOWin32_close(pTHX_ PerlIO *f)
+{
+ PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
+ if (s->refcnt == 1)
+  {
+   if (CloseHandle(s->h))
+    {
+     s->h = INVALID_HANDLE_VALUE;
+     return -1;
+    }
+  }
+ PerlIOBase(f)->flags &= ~PERLIO_F_OPEN;
+ return 0;
+}
+
+PerlIO *
+PerlIOWin32_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *params, int flags)
+{
+ PerlIOWin32 *os = PerlIOSelf(f,PerlIOWin32);
+ HANDLE proc = GetCurrentProcess();
+ HANDLE new; 
+//vvv todo if (DuplicateHandle(proc, os->h, proc, &new, 0, FALSE,  
+DUPLICATE_SAME_ACCESS))
+ if (0)
+  {
+   char mode[8];
+   int fd = win32_open_osfhandle((intptr_t) new, 
+PerlIOUnix_oflags(PerlIO_modestr(o,mode)));
+   if (fd >= 0) 
+    {
+     f = PerlIOBase_dup(aTHX_ f, o, params, flags);
+     if (f) 
+      {
+       PerlIOWin32 *fs = PerlIOSelf(f,PerlIOWin32);
+       fs->h  = new;
+       fs->fd = fd;
+       fs->refcnt = 1;
+       fdtable[fd] = fs;
+       if (fd > max_open_fd)
+        max_open_fd = fd;
+      }
+     else
+      {
+       win32_close(fd);
+      }
+    }
+   else
+    {
+     CloseHandle(new);
+    }
+  }
+ return f;
+}
+
+PerlIO_funcs PerlIO_win32 = {
+ "win32",
+ sizeof(PerlIOWin32),
+ PERLIO_K_RAW,
+ PerlIOWin32_pushed,
+ PerlIOWin32_popped,
+ PerlIOWin32_open,
+ NULL,                 /* getarg */
+ PerlIOWin32_fileno,
+ PerlIOWin32_dup,
+ PerlIOWin32_read,
+ PerlIOBase_unread,
+ PerlIOWin32_write,
+ PerlIOWin32_seek,
+ PerlIOWin32_tell,
+ PerlIOWin32_close,
+ PerlIOBase_noop_ok,   /* flush */
+ PerlIOBase_noop_fail, /* fill */
+ PerlIOBase_eof,
+ PerlIOBase_error,
+ PerlIOBase_clearerr,
+ PerlIOBase_setlinebuf,
+ NULL, /* get_base */
+ NULL, /* get_bufsiz */
+ NULL, /* get_ptr */
+ NULL, /* get_cnt */
+ NULL, /* set_ptrcnt */
+};
+
+
+#endif
End of Patch.

Reply via email to