Commits

Palmer, 2E0EOL  committed 8139c20

A basic comcept for a Perl re-write. Note sure if it's worth completing
at this stage, but I tend not to throw code ayway ;). You might
also want to consider dlconfreader for an alternative, OOP interface.

  • Participants
  • Parent commits 08a5e06
  • Branches perlport

Comments (0)

Files changed (4)

File perlport/dlini.pl

+#!/usr/bin/perl -w
+#
+# This is a Perl-based re-write of the GetPrivateProfile... group of functions.
+# nb. that I haven't written all functionality here.  I have been writing them
+# as they are needed.  Please refer to the documentation on the MSDN web-site
+# at http://msdn.microsoft.com/en-us/library/ms724353(VS.85).aspx
+#
+#----------------------------------------------------------------------------
+use constant DLINI_SOURCE => 1;
+use constant DLINI_LINEBUFFER => 3001;
+
+# Function declarations
+sub dlini_GetPrivateProfileSectionNames($$$);
+sub dlini_GetPrivateProfileString($$$$$$);
+#----------------------------------------------------------------------------
+# Function definitions
+require 'dlini_internal.pl';
+require 'dlini_getsectionnames.pl';
+require 'dlini_getstring.pl';
+#----------------------------------------------------------------------------
+1;
+

File perlport/dlini_getsectionnames.pl

+#!/usr/bin/perl -w
+
+die if ( !DLINI_SOURCE() );
+#----------------------------------------------------------------------------
+sub dlini_GetPrivateProfileSectionNames($$$)
+{
+  my $lpszReturnBuffer = $_[0];
+  my $nSize = $_[1];
+  my $lpFileName = $_[2];
+  my $dwRet;
+  my $fileHandle;
+  my $buff; # Do not exceed DLINI_LINEBUFFER
+  my $offset = 0;
+
+  if ( !$lpszReturnBuffer ) {
+    #This is a required parameter.  I don't know exactly how we should
+    #handle this, as the manual isn't unambiguous.  So I am going to use
+    #the "buffer too small" way of doing things, returning nSize-2.
+    #However, if nSize is very small, I shall return zero.
+    return $nSize-2 if ( $nSize >= 2 );
+    return 0;
+  }
+
+  dlini_int_memset($lpszReturnBuffer, 0, $nSize);
+  $lpszReturnBuffer = '';
+  $fileHandle = dlini_int_Open(
+    dlini_int_ResolveFileName(lpFileName),
+    DLINI_FALSE()
+  );
+  return 0 if ( !$fileHandle ); # Can't open or lock file
+  dlini_int_Rewind($fileHandle);
+  while ( dlini_int_FindNextSection($fileHandle) ) {
+    my $end;
+
+    $buff = <$$fileHandle>;
+    $buff = substr($buff, 0, DLINI_LINEBUFFER()-1); # Limit to a sensible line length
+    $end = index($buff, ']');
+    if ( $end != -1 ) {
+      xxx
+
+
+      unsigned int charsCopied;
+
+      *end = '\0';
+      charsCopied = MIN(nSize-offset, strlen(buff)+1);
+
+      memcpy(
+        lpszReturnBuffer + offset,
+        buff,
+        charsCopied
+      );
+      offset += charsCopied;
+
+      if ( strlen(buff) > nSize - offset ) {
+        offset = nSize - 2;
+        break;
+      }
+    }
+  }
+
+  dlini_int_Close(fileHandle);
+  return offset;
+}
+#----------------------------------------------------------------------------
+1;

File perlport/dlini_getstring.pl

+#!/usr/bin/perl -w
+
+die if ( !DLINI_SOURCE() );
+#----------------------------------------------------------------------------
+sub dlini_GetPrivateProfileString($$$$$$)
+{
+  my $dwRet;
+  my $lpAppName = $_[0];
+  my $lpKeyName = $_[1];
+  my $lpDefault = $_[2];
+  my $lpReturnedString = $_[3];
+  my $nSize = $_[4];
+  my $lpFileName = $_[5];
+
+  die;
+}
+#----------------------------------------------------------------------------
+1;

File perlport/dlini_internal.pl

+#!/usr/bin/perl -w
+#
+#----------------------------------------------------------------------------
+#  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+#  % This module provides support to other INI functions only. %
+#  % The functions in here should not be used by users.        %
+#  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+sub dlini_int_Rewind($);
+#----------------------------------------------------------------------------
+die if ( !DLINI_SOURCE() );
+#----------------------------------------------------------------------------
+sub dlini_int_Rewind($)
+{
+  my $f = shift;
+  # http://www.loria.fr/~szathmar/pmwiki/index.php?n=Perl.20080601Rewind
+  seek($$f, 0, 0);
+  return;
+}
+#----------------------------------------------------------------------------
+1;