From 70818baf2fc2b1df461b0f92f9e739fb912fae5d Mon Sep 17 00:00:00 2001
From: Lionel Debroux <lionel_debroux@yahoo.fr>
Date: Wed, 17 Dec 2008 20:45:15 +0100
Subject: Partial implementation of ticket #34: in the Delphi IDE, the C tigcc and pstarter.s, make it possible to specify a folder name for compressed programs.
 The price to pay is an increase of about 9 bytes (< 1%) of the size of each pstarter.

---
 tigcc-linux/sources/tigcc/src/tigcc.c |    4 +-
 tigcc/ide/ParsingUnit.pas             |    2 +-
 tigcc/ide/ProjectOptionsUnit.pas      |   79 +++++++++++++--------------
 tigcc/pstarter/pstarter.s             |    4 +-
 4 files changed, 43 insertions(+), 46 deletions(-)

diff --git a/tigcc-linux/sources/tigcc/src/tigcc.c b/tigcc-linux/sources/tigcc/src/tigcc.c
index d8c5ec8..0c21b56 100755
--- a/tigcc-linux/sources/tigcc/src/tigcc.c
+++ b/tigcc-linux/sources/tigcc/src/tigcc.c
@@ -122,7 +122,7 @@ short int process_arg(short int arg, char *argv[], int argc)
         exit(-1);
       }
       packfile[0] = 0;
-      strncpy(packfile, next_arg, 8);
+      strncpy(packfile, next_arg, 17);
       do_pack = TRUE;
     }
   } else if(!strcmp("-bsr", cur_arg)) {
@@ -697,7 +697,7 @@ static short int parse_pstarter(const char *input, const char *output,
 {
   FILE *f;
   char array[65536];
-  char *token = "tempprog";
+  static const char *token = "tempprog\\tempprog";
   unsigned int i, n;
   unsigned int j, k;
 
diff --git a/tigcc/ide/ParsingUnit.pas b/tigcc/ide/ParsingUnit.pas
index 8f3efdf..86357f9 100644
--- a/tigcc/ide/ParsingUnit.pas
+++ b/tigcc/ide/ParsingUnit.pas
@@ -269,7 +269,7 @@ end;
 
 procedure ParsePStarter(const InputFile: string; const OutputFile: string; const PackVar: string);
 const
-	TempProg = 'TEMPPROG';
+	TempProg = 'TEMPPROG\TEMPPROG';
 var
 	I: Integer;
 	ObjectFile: TMemoryStream;
diff --git a/tigcc/ide/ProjectOptionsUnit.pas b/tigcc/ide/ProjectOptionsUnit.pas
index 13073a2..a83761c 100644
--- a/tigcc/ide/ProjectOptionsUnit.pas
+++ b/tigcc/ide/ProjectOptionsUnit.pas
@@ -93,6 +93,7 @@ type
 		procedure BrowseButtonClick(Sender: TObject);
 		procedure ProgramOptionsButtonClick(Sender: TObject);
 	private
+		function CheckVarName(S: String): Boolean;
 	public
 		InitialLibOptions: TPredefinedLibOptions;
 		ProgramOptionsForm: TProgramOptionsForm;
@@ -136,57 +137,53 @@ begin
 	VarEditChange (Sender);
 end;
 
-procedure TProjectOptionsForm.VarEditChange(Sender: TObject);
+function TProjectOptionsForm.CheckVarName(S: String): Boolean;
 var
-	S: string;
 	I: Integer;
 	OK,
 	HasFolder: Boolean;
 begin
-	if PackCheckBox.Checked then begin
-		S := PackVarEdit.Text;
-		OK := (Length (S) > 0) and (Length (S) <= 8) and (IsCharAlpha (S [1]) or (S [1] in ['A'..'Z', 'a'..'z'])) and (LowerCase (S) <> LowerCase (MainForm.TopNode.Text));
-		if OK then
-			for I := Length (S) downto 1 do
-				if (not (IsCharAlphaNumeric (S [I]) or (S [I] in ['A'..'Z', 'a'..'z', '0'..'9', '_']))) or ((I = 1) and (S [I] = '_')) then begin
+	OK := (Length (S) > 0) and (IsCharAlpha (S [1]) or (S [1] in ['A'..'Z', 'a'..'z'])) and (LowerCase (S) <> LowerCase (MainForm.TopNode.Text));
+	if OK then begin
+		HasFolder := False;
+		for I := Length (S) downto 1 do begin
+			if S [I] = '\' then begin
+				if HasFolder then begin
 					OK := False;
 					Break;
-				end;
-	end else
-		OK := True;
-	if OK then begin
-		if DataVarCheckBox.Checked then begin
-			S := DataVarEdit.Text;
-			if PackCheckBox.Checked and (LowerCase (DataVarEdit.Text) = LowerCase (PackVarEdit.Text)) then
-				OK := False
-			else begin
-				OK := (Length (S) > 0) and (IsCharAlpha (S [1]) or (S [1] in ['A'..'Z', 'a'..'z'])) and (LowerCase (S) <> LowerCase (MainForm.TopNode.Text));
-				if OK then begin
-					HasFolder := False;
-					for I := Length (S) downto 1 do begin
-						if S [I] = '\' then begin
-							if HasFolder then begin
-								OK := False;
-								Break;
-							end else
-								HasFolder := True;
-						end else if (not (IsCharAlphaNumeric (S [I]) or (S [I] in ['A'..'Z', 'a'..'z', '0'..'9', '_']))) or ((I = 1) and (S [I] = '_')) then begin
-							OK := False;
-							Break;
-						end;
-					end;
-					I := Pos ('\', S);
-					if I > 0 then begin
-						if (I - 1 > MaxNameLength) or (Length (S) - I > MaxNameLength) or (I + 1 > Length (S)) or (not (IsCharAlpha (S [I + 1]) or (S [I + 1] in ['A'..'Z', 'a'..'z']))) then
-							OK := False;
-					end else begin
-						if Length (S) > MaxNameLength then
-							OK := False;
-					end;
-				end;
+				end else
+					HasFolder := True;
+			end else if (not (IsCharAlphaNumeric (S [I]) or (S [I] in ['A'..'Z', 'a'..'z', '0'..'9', '_']))) or ((I = 1) and (S [I] = '_')) then begin
+				OK := False;
+				Break;
 			end;
 		end;
+		I := Pos ('\', S);
+		if I > 0 then begin
+			if (I - 1 > MaxNameLength) or (Length (S) - I > MaxNameLength) or (I + 1 > Length (S)) or (not (IsCharAlpha (S [I + 1]) or (S [I + 1] in ['A'..'Z', 'a'..'z']))) then
+				OK := False;
+		end else begin
+			if Length (S) > MaxNameLength then
+				OK := False;
+		end;
+	end;
+	Result := OK;
+end;
+
+procedure TProjectOptionsForm.VarEditChange(Sender: TObject);
+var
+	S: string;
+	OK: Boolean;
+begin
+	OK := True;
+	if PackCheckBox.Checked then begin
+		if DataVarCheckBox.Checked and (LowerCase (DataVarEdit.Text) = LowerCase (PackVarEdit.Text)) then
+			OK := False
+		else
+			OK := CheckVarName(PackVarEdit.Text);
 	end;
+	if OK then
+		OK := CheckVarName(DataVarEdit.Text);
 	OKButton.Enabled := OK;
 end;
 
diff --git a/tigcc/pstarter/pstarter.s b/tigcc/pstarter/pstarter.s
index 9cfb1a2..6e69a67 100755
--- a/tigcc/pstarter/pstarter.s
+++ b/tigcc/pstarter/pstarter.s
@@ -12,7 +12,7 @@
 | decompression routine. (The Lesser General Public License restrictions
 | do apply in other respects; for example, they cover modification of
 | the launcher. Licensing restrictions of the chosen decompression routine
-| also apply.) Merely replacing "tempprog" with the name of your program
+| also apply.) Merely replacing "tempprog\\tempprog" with the name of your program
 | shall not be considered a modification for the purposes of this
 | paragraph. This exception notice must be removed on modified copies of
 | this launcher.
@@ -516,4 +516,4 @@ CompressedHandle: .word 0 | handle to unlock, 0 if no unlocking needed
 
 .byte 0
 ProgramName:      | program name
-.asciz "tempprog" | to be patched in by TIGCC
+.asciz "tempprog\\tempprog" | to be patched in by TIGCC
-- 
1.6.1.rc3.6.g98171


