Commits

overlord  committed f4cf7ad

C ownz Pascal! This project is an attempt to make cstdio-like functions available in
Pascal if you are in the unfortunate situation of needing to write some Pascal,
without really knowing it that well, or for easily converting C to Pascal, not that
you should ever try that!

  • Participants

Comments (0)

Files changed (1)

+(*
+  Copyright (C) 2001 Daybo Logic.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+  David Duncan Ross Palmer - Overlord@DayboLogic.co.uk
+  http://www.daybologic.co.uk
+
+
+  Module: cstdio.pas
+  Author: David Duncan Ross Palmer (Overlord@DayboLogic.co.uk)
+  Language: Turbo Pascal
+  Library: cownspas (C Ownz Pascal!)
+  Description: Replacements for C's stdio functions
+
+  Warning!  I am not expert at crappy Pascal!
+*)
+
+(* Types for header *)
+object CFILE begin
+  name : PChar; (* Dynamic, filename *)
+  pastexttype : text; (* Assosiated Pascal type... or! *)
+  pasbintype : binary; (* this... check istext *)
+  isopen : boolean; (* Marker to know if Pascal says the file is open or not *)
+  istext : boolean; (* Otherwise use binary file type *)
+end;
+
+(* I really hope these are static! *)
+const MAXCFHANDLES = 40; (* Seems reasonable *)
+array fileHandes[MAXCFHANDLES] of CFILE;
+(*-------------------------------------------------------------------------*)
+function fopen(Filename, Mode : string) : CFILE;
+var newcfile : CFILE;
+var modebits : integer;
+begin
+  InitCFILE(newcfile);
+  modebits = CrackModes(Mode);
+end;
+(*-------------------------------------------------------------------------*)
+function fclose(var Handle : CFILE) : integer;
+begin
+end;
+(*-------------------------------------------------------------------------*)
+procedure LeakCheck;
+var i : integer;
+begin
+  if ( IsDebugSet(1) ) then begin
+    for ( i := 0 to i < MAXCFHANDLES ) begin
+      if ( fileHandles[i].isopen ) then begin
+        CloseAtPos(i);
+        writeln('Warning! cownspas detected that file ', fileHandles[i].name, ' was never closed');
+      end;
+    end;
+  end;
+end;
+(*-------------------------------------------------------------------------*)
+procedure CloseAtPos(const Pos : integer);
+begin
+  if ( fileHandles[Pos].isopen ) then begin
+    if ( fileHandles[Pos].istext ) then
+      close(fileHandles[Pos].pastexttype);
+    else
+      close(fileHandles[Pos].pasbintype);
+    end;
+    fileHandles[Pos].isopen = false;
+    (* Scrap filename *)
+    free(fileHandles[Pos].name);
+  end; (*isopen*)
+end;
+(*-------------------------------------------------------------------------*)
+procedure InitCFILE(var Pcfile : CFILE);
+begin
+  (* Init all members of a new CFILE structure *)
+  Pcfile.name = nil; (* That's NULL to you & I *)
+  Pcfile.pastextfile = 0; (* Umm, I don't know what text is exactly, we'll see i this fails *)
+  Pcfile.pasbinfile = 0; (* Same with this *)
+  Pcfile.isopen = false; (* No, no file open *)
+  Pcfile.istext = 1; (* Assume text, just because I do *)
+end;
+(*-------------------------------------------------------------------------*)
+function CrackModes(const ModeString : PChar) : integer
+var i : integer; (* Iterate through string *)
+var len : integer;
+(* Set CrackModes as the return variable *)
+begin
+  (* Mode bits map:
+     0 - Readonly
+     1 - text
+     2 - Append
+     3 - Overwrite  Change these later if I have to
+  *)
+  CrackModes = 0; (* Reset all modes, for great justice! *)
+  len := length(ModeString); (* Do this before the loop to make your time! *)
+  for ( i := 0 to i < len ) begin
+  end;
+end;
+(*-------------------------------------------------------------------------*)