| 1 |
unit base0; |
| 2 |
{$IFDEF FPC} |
| 3 |
{$MODE DELPHI} {$H+} |
| 4 |
{$ENDIF} |
| 5 |
(***************************************) |
| 6 |
(* Copyright (C) 2009, SHIRAISHI Kazuo *) |
| 7 |
(***************************************) |
| 8 |
|
| 9 |
interface |
| 10 |
|
| 11 |
uses |
| 12 |
Classes, SysUtils,StdCtrls,IniFiles, Graphics,ComCtrls, SynEdit, |
| 13 |
base; |
| 14 |
|
| 15 |
const |
| 16 |
RecordSetterCode:array[tpRecordSetter] of AnsiString= |
| 17 |
('rsNone','rsBEGIN','rsEND','rsNEXT','rsSAME'); |
| 18 |
const |
| 19 |
IOOptionCode:array[IOOption] of AnsiString= |
| 20 |
('ioReadWrite','ioCharacterByte','ioSkipRest','ioWhenInside','ioClear','ioNoWait'); |
| 21 |
function IoOptionsCode(option:IOoptions):Ansistring; |
| 22 |
|
| 23 |
|
| 24 |
type |
| 25 |
Array4 = array[1..4] of longint; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
var |
| 30 |
paramIndex:integer; //コマンドパラメータのindex;実行中はプログラムファイル名の位置をさす。 |
| 31 |
|
| 32 |
|
| 33 |
var |
| 34 |
pass :integer =0; |
| 35 |
exline :integer =0; |
| 36 |
expos :integer =0; |
| 37 |
exinsertcount:integer=0; |
| 38 |
helpContext:integer =0; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
const |
| 43 |
bkCancel=0; |
| 44 |
bkStep=1; |
| 45 |
bkContinue=2; |
| 46 |
var |
| 47 |
bkDirective:integer=bkCancel; |
| 48 |
var |
| 49 |
ForceFunctionDeclare:boolean=false; |
| 50 |
InsertDIMst:boolean=false; |
| 51 |
OptionExplicit:boolean=false; |
| 52 |
AutoIndent:boolean=true; |
| 53 |
const |
| 54 |
ac_let=0; |
| 55 |
ac_input=1; |
| 56 |
ac_using=2; |
| 57 |
ac_next=3; |
| 58 |
ac_string=4; |
| 59 |
ac_remark=5; |
| 60 |
ac_exp=6; |
| 61 |
ac_while=7; |
| 62 |
ac_multi=8; |
| 63 |
ac_end=9; |
| 64 |
var |
| 65 |
AutoCorrect:array[0..ac_end]of boolean=(true,true,true,true,true,true,false,false,false,false); |
| 66 |
var |
| 67 |
shift_F5:string='LET '; |
| 68 |
shift_F6:string='PRINT '; |
| 69 |
shift_F7:string='OPTION ANGLE DEGREES'; |
| 70 |
shift_F8:string=''; |
| 71 |
var |
| 72 |
TranslatingNow:boolean=false; |
| 73 |
var |
| 74 |
NoRun:boolean=false; |
| 75 |
OpenAndRun:boolean=false; |
| 76 |
NoBackUp:boolean=true; |
| 77 |
|
| 78 |
|
| 79 |
procedure SelectLine(memo:TSynEdit;i:integer); |
| 80 |
|
| 81 |
var |
| 82 |
HideSyntaxMenu:boolean=false; |
| 83 |
|
| 84 |
procedure upper(var s:string); |
| 85 |
procedure lower(var s:string); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
procedure InitializeEnv; |
| 92 |
|
| 93 |
|
| 94 |
function TruthLiteral(s:boolean):String; |
| 95 |
|
| 96 |
var |
| 97 |
UseMassArrays:boolean=false; |
| 98 |
SystemStackSize:Cardinal={$IFDEF Windows}$4000000{64MB}{$ELSE} $3FE0000{63.875MB}{$ENDIF}; |
| 99 |
VirtualStackSize:Cardinal=$40000000{1024MB}; |
| 100 |
|
| 101 |
OptimizeInteger:boolean=false; |
| 102 |
OptimizeOnlyWhenSubscripts:boolean=true; |
| 103 |
OptimizeDouble:boolean=true; |
| 104 |
var |
| 105 |
originalCW:word; |
| 106 |
|
| 107 |
implementation |
| 108 |
|
| 109 |
uses Types, Forms,Controls, |
| 110 |
{$IFDEF windows}Windows,{$ENDIF} |
| 111 |
{$IFDEF LINUX} Linux,{$ENDIF} |
| 112 |
sconsts,myutils; |
| 113 |
|
| 114 |
procedure upper(var s:string); |
| 115 |
var |
| 116 |
i:integer; |
| 117 |
begin |
| 118 |
i:=0; |
| 119 |
while i<length(s) do |
| 120 |
begin |
| 121 |
inc(i); |
| 122 |
if s[i] in ['a'..'z'] then |
| 123 |
s[i]:=chr(ord(s[i])-32) |
| 124 |
else |
| 125 |
ReadMBC(i,s); //if IsDBCSLeadByte(byte(s[i])) then inc(i); |
| 126 |
end; |
| 127 |
end; |
| 128 |
|
| 129 |
procedure lower(var s:string); |
| 130 |
var |
| 131 |
i:integer; |
| 132 |
begin |
| 133 |
i:=0; |
| 134 |
while i<length(s) do |
| 135 |
begin |
| 136 |
inc(i); |
| 137 |
if s[i] in ['A'..'Z'] then |
| 138 |
s[i]:=chr(ord(s[i])+32) |
| 139 |
else |
| 140 |
ReadMBC(i,s); //if IsDBCSLeadByte(byte(s[i])) then inc(i); |
| 141 |
end; |
| 142 |
end; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
{************} |
| 148 |
{Editor Utils} |
| 149 |
{************} |
| 150 |
|
| 151 |
procedure SelectLine(memo:TSynEdit;i:integer); |
| 152 |
var |
| 153 |
p,q:integer; |
| 154 |
begin |
| 155 |
with memo do |
| 156 |
begin |
| 157 |
(memo.owner as TForm).BringToFront; |
| 158 |
//SelStart:=SendMessage(Handle,EM_LINEINDEX,i,0); |
| 159 |
p:=LineIndex(memo, i); |
| 160 |
q:=LineIndex(memo, i+1); |
| 161 |
SelStart:=p; |
| 162 |
SelectLine; //SelLength:=q-p -Length(EOL); |
| 163 |
end; |
| 164 |
end; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
{*************} |
| 171 |
{generate code} |
| 172 |
{*************} |
| 173 |
function IoOptionsCode(option:IOoptions):Ansistring; |
| 174 |
var |
| 175 |
op:IoOption; |
| 176 |
begin |
| 177 |
result:=''; |
| 178 |
for op:=Low(IOOption){ioReadWrite} to High(IOOption) {ioNoWait} do |
| 179 |
if op in option then |
| 180 |
result:=result+IoOptionCode[op]+','; |
| 181 |
if (result<>'') and (result[length(result)]=',') then |
| 182 |
delete(result,length(result),1); |
| 183 |
result:='['+result+']'; |
| 184 |
end; |
| 185 |
|
| 186 |
function TruthLiteral(s:boolean):String; |
| 187 |
begin |
| 188 |
if s then result:=' true ' else result :=' false ' |
| 189 |
end; |
| 190 |
|
| 191 |
|
| 192 |
function GetPhysicalMemory:Cardinal; |
| 193 |
{$IFDEF WINDOWS} |
| 194 |
var |
| 195 |
GlobalMemoryInfo:TMemoryStatus; |
| 196 |
begin |
| 197 |
GlobalMemoryStatus( GlobalMemoryInfo); |
| 198 |
GetPhysicalMemory:=GlobalMemoryInfo.dwAvailVirtual ; |
| 199 |
end; |
| 200 |
{$ELSE} |
| 201 |
{$IFDEF LINUX} |
| 202 |
var |
| 203 |
info:TSysInfo; |
| 204 |
begin |
| 205 |
SysInfo(@info); |
| 206 |
result:=info.totalram; |
| 207 |
end; |
| 208 |
{$ELSE} |
| 209 |
begin |
| 210 |
result:=$80000000 {2048MB}; //dummy |
| 211 |
end; |
| 212 |
{$ENDIF} |
| 213 |
{$ENDIF} |
| 214 |
|
| 215 |
|
| 216 |
{**********} |
| 217 |
{Initialize} |
| 218 |
{**********} |
| 219 |
|
| 220 |
procedure ReadIniFile; |
| 221 |
var |
| 222 |
IniFile:TMyIniFile; |
| 223 |
begin |
| 224 |
IniFile:=TMyIniFile.create('Frame'); |
| 225 |
with IniFile do |
| 226 |
begin |
| 227 |
AutoIndent:=ReadBool('AutoIndent',AutoIndent); |
| 228 |
OptionExplicit:=ReadBool('OptionExplicit',OptionExplicit); |
| 229 |
UseMassArrays:=ReadBool('UseMassArrays',UseMassArrays); |
| 230 |
SystemStackSize:=ReadInteger('SystemStackSize',SystemStackSize); |
| 231 |
VirtualStackSize:=ReadInteger('VirtualStackSize',VirtualStackSize); |
| 232 |
shift_F5:=ReadString('Shift_F5',Shift_F5); |
| 233 |
shift_F6:=ReadString('Shift_F6',Shift_F6); |
| 234 |
shift_F7:=ReadString('Shift_F7',Shift_F7); |
| 235 |
shift_F8:=ReadString('Shift_F8',Shift_F8); |
| 236 |
OptimizeInteger:=ReadBool('OptimizeInteger',OptimizeInteger); |
| 237 |
OptimizeDouble:=ReadBool('OptimizeDouble',OptimizeDouble); |
| 238 |
//以下,終了時に書き込まれない項目 |
| 239 |
InsertDIMst:=ReadBool('InsertDIM',InsertDIMst); |
| 240 |
InitialOptionBase:=ReadInteger('OptionBase',InitialOptionbase); |
| 241 |
PermitMicrosoft:=ReadBool('Microsoft',PermitMicrosoft); |
| 242 |
MinimalBasic:=ReadBool('MinimalBasic',MinimalBasic); |
| 243 |
NoRun:=ReadBool('NoRun',NoRun); |
| 244 |
IniFileReadOnly:=ReadBool('IniFileReadOnly',IniFileReadOnly); |
| 245 |
end; |
| 246 |
IniFile.free; |
| 247 |
|
| 248 |
end; |
| 249 |
|
| 250 |
procedure WriteIniFile; |
| 251 |
var |
| 252 |
IniFile:TMyIniFile; |
| 253 |
begin |
| 254 |
IniFile:=TMyIniFile.create('Frame'); |
| 255 |
with IniFile do |
| 256 |
begin |
| 257 |
WriteBool('AutoIndent',AutoIndent); |
| 258 |
WriteBool('OptionExplicit',OptionExplicit); |
| 259 |
WriteBool('UseMassArrays',UseMassArrays); |
| 260 |
WriteInteger('SystemStackSize',SystemStackSize); |
| 261 |
WriteInteger('VirtualStackSize',VirtualStackSize); |
| 262 |
WriteString('Shift_F5',Shift_F5); |
| 263 |
WriteString('Shift_F6',Shift_F6); |
| 264 |
WriteString('Shift_F7',Shift_F7); |
| 265 |
WriteString('Shift_F8',Shift_F8); |
| 266 |
WriteBool('OptimizeInteger',OptimizeInteger); |
| 267 |
WriteBool('OptimizeDouble',OptimizeDouble); |
| 268 |
end; |
| 269 |
IniFile.free; |
| 270 |
|
| 271 |
end; |
| 272 |
|
| 273 |
procedure InitializeEnv; |
| 274 |
begin |
| 275 |
if Application.MessageBox(PChar(s_InitEnv),AppTitle,mb_OKCANCEL)=IDOk then |
| 276 |
begin |
| 277 |
IniFileReadOnly:=true; |
| 278 |
SysUtils.DeleteFile(IniFileName); |
| 279 |
end; |
| 280 |
end; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
initialization |
| 286 |
paramIndex:=1; |
| 287 |
while (ParamIndex<=ParamCount) and (copy(ParamStr(paramIndex),1,1)='-') do |
| 288 |
begin |
| 289 |
if ParamStr(paramIndex)='-NI' then NoInitialize:=true; |
| 290 |
if ParamStr(paramIndex)='-OR' then OpenAndRun:=true; |
| 291 |
if ParamStr(paramIndex)='-NR' then NoRun:=true; |
| 292 |
inc(paramIndex); |
| 293 |
end; |
| 294 |
|
| 295 |
readIniFile; |
| 296 |
|
| 297 |
originalCW:=get8087CW; |
| 298 |
|
| 299 |
finalization |
| 300 |
WriteIniFile; |
| 301 |
|
| 302 |
|
| 303 |
end. |
| 304 |
|