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
|
b
|
short int process_arg(short int arg, char *argv[], int argc) |
| 122 | 122 | exit(-1); |
| 123 | 123 | } |
| 124 | 124 | packfile[0] = 0; |
| 125 | | strncpy(packfile, next_arg, 8); |
| | 125 | strncpy(packfile, next_arg, 17); |
| 126 | 126 | do_pack = TRUE; |
| 127 | 127 | } |
| 128 | 128 | } else if(!strcmp("-bsr", cur_arg)) { |
| … |
… |
static short int parse_pstarter(const char *input, const char *output, |
| 697 | 697 | { |
| 698 | 698 | FILE *f; |
| 699 | 699 | char array[65536]; |
| 700 | | char *token = "tempprog"; |
| | 700 | static const char *token = "tempprog\\tempprog"; |
| 701 | 701 | unsigned int i, n; |
| 702 | 702 | unsigned int j, k; |
| 703 | 703 | |
diff --git a/tigcc/ide/ParsingUnit.pas b/tigcc/ide/ParsingUnit.pas
index 8f3efdf..86357f9 100644
|
a
|
b
|
end; |
| 269 | 269 | |
| 270 | 270 | procedure ParsePStarter(const InputFile: string; const OutputFile: string; const PackVar: string); |
| 271 | 271 | const |
| 272 | | TempProg = 'TEMPPROG'; |
| | 272 | TempProg = 'TEMPPROG\TEMPPROG'; |
| 273 | 273 | var |
| 274 | 274 | I: Integer; |
| 275 | 275 | ObjectFile: TMemoryStream; |
diff --git a/tigcc/ide/ProjectOptionsUnit.pas b/tigcc/ide/ProjectOptionsUnit.pas
index 13073a2..a83761c 100644
|
a
|
b
|
type |
| 93 | 93 | procedure BrowseButtonClick(Sender: TObject); |
| 94 | 94 | procedure ProgramOptionsButtonClick(Sender: TObject); |
| 95 | 95 | private |
| | 96 | function CheckVarName(S: String): Boolean; |
| 96 | 97 | public |
| 97 | 98 | InitialLibOptions: TPredefinedLibOptions; |
| 98 | 99 | ProgramOptionsForm: TProgramOptionsForm; |
| … |
… |
begin |
| 136 | 137 | VarEditChange (Sender); |
| 137 | 138 | end; |
| 138 | 139 | |
| 139 | | procedure TProjectOptionsForm.VarEditChange(Sender: TObject); |
| | 140 | function TProjectOptionsForm.CheckVarName(S: String): Boolean; |
| 140 | 141 | var |
| 141 | | S: string; |
| 142 | 142 | I: Integer; |
| 143 | 143 | OK, |
| 144 | 144 | HasFolder: Boolean; |
| 145 | 145 | begin |
| 146 | | if PackCheckBox.Checked then begin |
| 147 | | S := PackVarEdit.Text; |
| 148 | | 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)); |
| 149 | | if OK then |
| 150 | | for I := Length (S) downto 1 do |
| 151 | | if (not (IsCharAlphaNumeric (S [I]) or (S [I] in ['A'..'Z', 'a'..'z', '0'..'9', '_']))) or ((I = 1) and (S [I] = '_')) then begin |
| | 146 | OK := (Length (S) > 0) and (IsCharAlpha (S [1]) or (S [1] in ['A'..'Z', 'a'..'z'])) and (LowerCase (S) <> LowerCase (MainForm.TopNode.Text)); |
| | 147 | if OK then begin |
| | 148 | HasFolder := False; |
| | 149 | for I := Length (S) downto 1 do begin |
| | 150 | if S [I] = '\' then begin |
| | 151 | if HasFolder then begin |
| 152 | 152 | OK := False; |
| 153 | 153 | Break; |
| 154 | | end; |
| 155 | | end else |
| 156 | | OK := True; |
| 157 | | if OK then begin |
| 158 | | if DataVarCheckBox.Checked then begin |
| 159 | | S := DataVarEdit.Text; |
| 160 | | if PackCheckBox.Checked and (LowerCase (DataVarEdit.Text) = LowerCase (PackVarEdit.Text)) then |
| 161 | | OK := False |
| 162 | | else begin |
| 163 | | OK := (Length (S) > 0) and (IsCharAlpha (S [1]) or (S [1] in ['A'..'Z', 'a'..'z'])) and (LowerCase (S) <> LowerCase (MainForm.TopNode.Text)); |
| 164 | | if OK then begin |
| 165 | | HasFolder := False; |
| 166 | | for I := Length (S) downto 1 do begin |
| 167 | | if S [I] = '\' then begin |
| 168 | | if HasFolder then begin |
| 169 | | OK := False; |
| 170 | | Break; |
| 171 | | end else |
| 172 | | HasFolder := True; |
| 173 | | 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 |
| 174 | | OK := False; |
| 175 | | Break; |
| 176 | | end; |
| 177 | | end; |
| 178 | | I := Pos ('\', S); |
| 179 | | if I > 0 then begin |
| 180 | | 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 |
| 181 | | OK := False; |
| 182 | | end else begin |
| 183 | | if Length (S) > MaxNameLength then |
| 184 | | OK := False; |
| 185 | | end; |
| 186 | | end; |
| | 154 | end else |
| | 155 | HasFolder := True; |
| | 156 | 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 |
| | 157 | OK := False; |
| | 158 | Break; |
| 187 | 159 | end; |
| 188 | 160 | end; |
| | 161 | I := Pos ('\', S); |
| | 162 | if I > 0 then begin |
| | 163 | 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 |
| | 164 | OK := False; |
| | 165 | end else begin |
| | 166 | if Length (S) > MaxNameLength then |
| | 167 | OK := False; |
| | 168 | end; |
| | 169 | end; |
| | 170 | Result := OK; |
| | 171 | end; |
| | 172 | |
| | 173 | procedure TProjectOptionsForm.VarEditChange(Sender: TObject); |
| | 174 | var |
| | 175 | S: string; |
| | 176 | OK: Boolean; |
| | 177 | begin |
| | 178 | OK := True; |
| | 179 | if PackCheckBox.Checked then begin |
| | 180 | if DataVarCheckBox.Checked and (LowerCase (DataVarEdit.Text) = LowerCase (PackVarEdit.Text)) then |
| | 181 | OK := False |
| | 182 | else |
| | 183 | OK := CheckVarName(PackVarEdit.Text); |
| 189 | 184 | end; |
| | 185 | if OK then |
| | 186 | OK := CheckVarName(DataVarEdit.Text); |
| 190 | 187 | OKButton.Enabled := OK; |
| 191 | 188 | end; |
| 192 | 189 | |
diff --git a/tigcc/pstarter/pstarter.s b/tigcc/pstarter/pstarter.s
index 9cfb1a2..6e69a67 100755
|
a
|
b
|
|
| 12 | 12 | | decompression routine. (The Lesser General Public License restrictions |
| 13 | 13 | | do apply in other respects; for example, they cover modification of |
| 14 | 14 | | the launcher. Licensing restrictions of the chosen decompression routine |
| 15 | | | also apply.) Merely replacing "tempprog" with the name of your program |
| | 15 | | also apply.) Merely replacing "tempprog\\tempprog" with the name of your program |
| 16 | 16 | | shall not be considered a modification for the purposes of this |
| 17 | 17 | | paragraph. This exception notice must be removed on modified copies of |
| 18 | 18 | | this launcher. |
| … |
… |
CompressedHandle: .word 0 | handle to unlock, 0 if no unlocking needed |
| 516 | 516 | |
| 517 | 517 | .byte 0 |
| 518 | 518 | ProgramName: | program name |
| 519 | | .asciz "tempprog" | to be patched in by TIGCC |
| | 519 | .asciz "tempprog\\tempprog" | to be patched in by TIGCC |