mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 23:29:13 +02:00
* cmdline support
This commit is contained in:
parent
ed5e78cc36
commit
bf3e811517
@ -311,6 +311,7 @@ var psp : word;
|
|||||||
al,proxy_argc,proxy_seg,proxy_ofs,lin : longint;
|
al,proxy_argc,proxy_seg,proxy_ofs,lin : longint;
|
||||||
largs : array[0..127] of pchar;
|
largs : array[0..127] of pchar;
|
||||||
rm_argv : ^arrayword;
|
rm_argv : ^arrayword;
|
||||||
|
argv0len : longint;
|
||||||
begin
|
begin
|
||||||
for i := 1 to 127 do
|
for i := 1 to 127 do
|
||||||
largs[i] := nil;
|
largs[i] := nil;
|
||||||
@ -322,10 +323,12 @@ sysseg_move(psp, 128, get_ds, longint(@doscmd), 128);
|
|||||||
Writeln(stderr,'Dos command line is #',doscmd,'# size = ',length(doscmd));
|
Writeln(stderr,'Dos command line is #',doscmd,'# size = ',length(doscmd));
|
||||||
{$EndIf }
|
{$EndIf }
|
||||||
|
|
||||||
// setup cmdline variable
|
{ setup cmdline variable }
|
||||||
cmdline := sysgetmem(length(doscmd)+1);
|
argv0len:=strlen(dos_argv0);
|
||||||
move(doscmd[1],cmdline^,length(doscmd));
|
cmdline:=sysgetmem(argv0len+length(doscmd)+1);
|
||||||
cmdline[length(doscmd)]:=#0;
|
move(dos_argv0^,cmdline^,argv0len);
|
||||||
|
move(doscmd[1],cmdline[argv0len],length(doscmd));
|
||||||
|
cmdline[argv0len+length(doscmd)]:=#0;
|
||||||
|
|
||||||
j := 1;
|
j := 1;
|
||||||
quote := #0;
|
quote := #0;
|
||||||
@ -1289,7 +1292,10 @@ Begin
|
|||||||
End.
|
End.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.23 1999-11-25 16:24:56 pierre
|
Revision 1.24 1999-12-01 22:57:30 peter
|
||||||
|
* cmdline support
|
||||||
|
|
||||||
|
Revision 1.23 1999/11/25 16:24:56 pierre
|
||||||
* avoid a problem with ChDir('c:') on pure DOS
|
* avoid a problem with ChDir('c:') on pure DOS
|
||||||
|
|
||||||
Revision 1.22 1999/11/06 14:38:24 peter
|
Revision 1.22 1999/11/06 14:38:24 peter
|
||||||
|
@ -693,15 +693,13 @@ end;
|
|||||||
function growheap(size :longint) : integer;
|
function growheap(size :longint) : integer;
|
||||||
var
|
var
|
||||||
sizeleft,
|
sizeleft,
|
||||||
NewPos,
|
NewPos : longint;
|
||||||
wantedsize : longint;
|
|
||||||
pcurr : pfreerecord;
|
pcurr : pfreerecord;
|
||||||
begin
|
begin
|
||||||
{$ifdef DUMPGROW}
|
{$ifdef DUMPGROW}
|
||||||
writeln('grow ',size);
|
writeln('grow ',size);
|
||||||
DumpBlocks;
|
DumpBlocks;
|
||||||
{$endif}
|
{$endif}
|
||||||
wantedsize:=size;
|
|
||||||
{ Allocate by 64K size }
|
{ Allocate by 64K size }
|
||||||
size:=(size+$ffff) and $ffff0000;
|
size:=(size+$ffff) and $ffff0000;
|
||||||
{ first try 256K (default) }
|
{ first try 256K (default) }
|
||||||
@ -783,7 +781,10 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.24 1999-11-14 21:34:21 peter
|
Revision 1.25 1999-12-01 22:57:31 peter
|
||||||
|
* cmdline support
|
||||||
|
|
||||||
|
Revision 1.24 1999/11/14 21:34:21 peter
|
||||||
* fixed reallocmem with a block at the end of an allocated memoryblock,
|
* fixed reallocmem with a block at the end of an allocated memoryblock,
|
||||||
had to introduce a flag for such blocks.
|
had to introduce a flag for such blocks.
|
||||||
* flags are now stored in the first 4 bits instead of the highest bit,
|
* flags are now stored in the first 4 bits instead of the highest bit,
|
||||||
|
@ -663,12 +663,71 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure SetupCmdLine;
|
||||||
|
var
|
||||||
|
bufsize,
|
||||||
|
len,j,
|
||||||
|
size,i : longint;
|
||||||
|
found : boolean;
|
||||||
|
buf : array[0..1026] of char;
|
||||||
|
|
||||||
|
procedure AddBuf;
|
||||||
|
begin
|
||||||
|
reallocmem(cmdline,size+bufsize);
|
||||||
|
move(buf,cmdline[size],bufsize);
|
||||||
|
inc(size,bufsize);
|
||||||
|
bufsize:=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
size:=0;
|
||||||
|
bufsize:=0;
|
||||||
|
i:=0;
|
||||||
|
while (i<argc) do
|
||||||
|
begin
|
||||||
|
len:=strlen(argv[i]);
|
||||||
|
if len>sizeof(buf)-2 then
|
||||||
|
len:=sizeof(buf)-2;
|
||||||
|
found:=false;
|
||||||
|
for j:=1 to len do
|
||||||
|
if argv[i][j]=' ' then
|
||||||
|
begin
|
||||||
|
found:=true;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
if bufsize+len>=sizeof(buf)-2 then
|
||||||
|
AddBuf;
|
||||||
|
if found then
|
||||||
|
begin
|
||||||
|
buf[bufsize]:='"';
|
||||||
|
inc(bufsize);
|
||||||
|
end;
|
||||||
|
move(argv[i]^,buf[bufsize],len);
|
||||||
|
inc(bufsize,len);
|
||||||
|
if found then
|
||||||
|
begin
|
||||||
|
buf[bufsize]:='"';
|
||||||
|
inc(bufsize);
|
||||||
|
end;
|
||||||
|
if i<argc then
|
||||||
|
buf[bufsize]:=' '
|
||||||
|
else
|
||||||
|
buf[bufsize]:=#0;
|
||||||
|
inc(bufsize);
|
||||||
|
inc(i);
|
||||||
|
end;
|
||||||
|
AddBuf;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
Begin
|
Begin
|
||||||
{ Set up signals handlers }
|
{ Set up signals handlers }
|
||||||
InstallSignals;
|
InstallSignals;
|
||||||
{ Setup heap }
|
{ Setup heap }
|
||||||
InitHeap;
|
InitHeap;
|
||||||
InitExceptions;
|
InitExceptions;
|
||||||
|
{ Arguments }
|
||||||
|
SetupCmdLine;
|
||||||
{ Setup stdin, stdout and stderr }
|
{ Setup stdin, stdout and stderr }
|
||||||
OpenStdIO(Input,fmInput,StdInputHandle);
|
OpenStdIO(Input,fmInput,StdInputHandle);
|
||||||
OpenStdIO(Output,fmOutput,StdOutputHandle);
|
OpenStdIO(Output,fmOutput,StdOutputHandle);
|
||||||
@ -680,7 +739,10 @@ End.
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.29 1999-11-06 14:39:12 peter
|
Revision 1.30 1999-12-01 22:57:31 peter
|
||||||
|
* cmdline support
|
||||||
|
|
||||||
|
Revision 1.29 1999/11/06 14:39:12 peter
|
||||||
* truncated log
|
* truncated log
|
||||||
|
|
||||||
Revision 1.28 1999/10/28 09:50:06 peter
|
Revision 1.28 1999/10/28 09:50:06 peter
|
||||||
|
@ -678,58 +678,56 @@ procedure setup_arguments;
|
|||||||
var
|
var
|
||||||
arglen,
|
arglen,
|
||||||
count : longint;
|
count : longint;
|
||||||
argstart,scmdline : pchar;
|
argstart,
|
||||||
|
pc : pchar;
|
||||||
quote : set of char;
|
quote : set of char;
|
||||||
argsbuf : array[0..127] of pchar;
|
argsbuf : array[0..127] of pchar;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{ create commandline, it starts with the executed filename which is argv[0] }
|
{ create commandline, it starts with the executed filename which is argv[0] }
|
||||||
{ Win32 passes the command NOT via the args, but via getmodulefilename}
|
{ Win32 passes the command NOT via the args, but via getmodulefilename}
|
||||||
count:=0;
|
count:=0;
|
||||||
cmdline:=getcommandfile;
|
pc:=getcommandfile;
|
||||||
Arglen:=0;
|
Arglen:=0;
|
||||||
repeat
|
repeat
|
||||||
Inc(Arglen);
|
Inc(Arglen);
|
||||||
until (cmdline[Arglen]=#0);
|
until (pc[Arglen]=#0);
|
||||||
getmem(argsbuf[count],arglen+1);
|
getmem(argsbuf[count],arglen+1);
|
||||||
move(cmdline^,argsbuf[count]^,arglen);
|
move(pc^,argsbuf[count]^,arglen);
|
||||||
{ Now skip the first one }
|
{ Now skip the first one }
|
||||||
cmdline:=GetCommandLine;
|
pc:=GetCommandLine;
|
||||||
repeat
|
repeat
|
||||||
{ skip leading spaces }
|
{ skip leading spaces }
|
||||||
while cmdline^ in [' ',#9,#13] do
|
while pc^ in [' ',#9,#13] do
|
||||||
inc(longint(cmdline));
|
inc(pc);
|
||||||
case cmdline^ of
|
case pc^ of
|
||||||
#0 : break;
|
#0 : break;
|
||||||
'"' : begin
|
'"' : begin
|
||||||
quote:=['"'];
|
quote:=['"'];
|
||||||
inc(longint(cmdline));
|
inc(pc);
|
||||||
end;
|
end;
|
||||||
'''' : begin
|
'''' : begin
|
||||||
quote:=[''''];
|
quote:=[''''];
|
||||||
inc(longint(cmdline));
|
inc(pc);
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
quote:=[' ',#9,#13];
|
quote:=[' ',#9,#13];
|
||||||
end;
|
end;
|
||||||
{ scan until the end of the argument }
|
{ scan until the end of the argument }
|
||||||
argstart:=cmdline;
|
argstart:=pc;
|
||||||
while (cmdline^<>#0) and not(cmdline^ in quote) do
|
while (pc^<>#0) and not(pc^ in quote) do
|
||||||
inc(longint(cmdline));
|
inc(pc);
|
||||||
{ Don't copy the first one, it is already there.}
|
{ Don't copy the first one, it is already there.}
|
||||||
If Count<>0 then
|
If Count<>0 then
|
||||||
begin
|
begin
|
||||||
{ reserve some memory }
|
{ reserve some memory }
|
||||||
arglen:=cmdline-argstart;
|
arglen:=pc-argstart;
|
||||||
getmem(argsbuf[count],arglen+1);
|
getmem(argsbuf[count],arglen+1);
|
||||||
move(argstart^,argsbuf[count]^,arglen);
|
move(argstart^,argsbuf[count]^,arglen);
|
||||||
argsbuf[count][arglen]:=#0;
|
argsbuf[count][arglen]:=#0;
|
||||||
end;
|
end;
|
||||||
{ skip quote }
|
{ skip quote }
|
||||||
if cmdline^ in quote then
|
if pc^ in quote then
|
||||||
inc(longint(cmdline));
|
inc(pc);
|
||||||
if count=0 then
|
|
||||||
scmdline:=cmdline-1;
|
|
||||||
inc(count);
|
inc(count);
|
||||||
until false;
|
until false;
|
||||||
{ create argc }
|
{ create argc }
|
||||||
@ -740,8 +738,8 @@ begin
|
|||||||
{ create the argv }
|
{ create the argv }
|
||||||
getmem(argv,count shl 2);
|
getmem(argv,count shl 2);
|
||||||
move(argsbuf,argv^,count shl 2);
|
move(argsbuf,argv^,count shl 2);
|
||||||
// finally setup the abused cmdline variable
|
{ Setup cmdline variable }
|
||||||
cmdline:=scmdline;
|
cmdline:=GetCommandLine;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1009,12 +1007,10 @@ type pexception_record = ^exception_record;
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
|
||||||
old_exception : LPTOP_LEVEL_EXCEPTION_FILTER;
|
|
||||||
|
|
||||||
procedure install_exception_handlers;
|
procedure install_exception_handlers;
|
||||||
begin
|
begin
|
||||||
old_exception:=SetUnhandledExceptionFilter(@syswin32_i386_exception_handler);
|
SetUnhandledExceptionFilter(@syswin32_i386_exception_handler);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1161,7 +1157,10 @@ end.
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.50 1999-11-20 00:16:44 pierre
|
Revision 1.51 1999-12-01 22:57:31 peter
|
||||||
|
* cmdline support
|
||||||
|
|
||||||
|
Revision 1.50 1999/11/20 00:16:44 pierre
|
||||||
+ DLL Hooks for the four callings added
|
+ DLL Hooks for the four callings added
|
||||||
|
|
||||||
Revision 1.49 1999/11/18 22:19:57 pierre
|
Revision 1.49 1999/11/18 22:19:57 pierre
|
||||||
|
Loading…
Reference in New Issue
Block a user