mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 19:29:24 +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;
|
||||
largs : array[0..127] of pchar;
|
||||
rm_argv : ^arrayword;
|
||||
argv0len : longint;
|
||||
begin
|
||||
for i := 1 to 127 do
|
||||
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));
|
||||
{$EndIf }
|
||||
|
||||
// setup cmdline variable
|
||||
cmdline := sysgetmem(length(doscmd)+1);
|
||||
move(doscmd[1],cmdline^,length(doscmd));
|
||||
cmdline[length(doscmd)]:=#0;
|
||||
{ setup cmdline variable }
|
||||
argv0len:=strlen(dos_argv0);
|
||||
cmdline:=sysgetmem(argv0len+length(doscmd)+1);
|
||||
move(dos_argv0^,cmdline^,argv0len);
|
||||
move(doscmd[1],cmdline[argv0len],length(doscmd));
|
||||
cmdline[argv0len+length(doscmd)]:=#0;
|
||||
|
||||
j := 1;
|
||||
quote := #0;
|
||||
@ -1289,7 +1292,10 @@ Begin
|
||||
End.
|
||||
{
|
||||
$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
|
||||
|
||||
Revision 1.22 1999/11/06 14:38:24 peter
|
||||
|
@ -693,15 +693,13 @@ end;
|
||||
function growheap(size :longint) : integer;
|
||||
var
|
||||
sizeleft,
|
||||
NewPos,
|
||||
wantedsize : longint;
|
||||
pcurr : pfreerecord;
|
||||
NewPos : longint;
|
||||
pcurr : pfreerecord;
|
||||
begin
|
||||
{$ifdef DUMPGROW}
|
||||
writeln('grow ',size);
|
||||
DumpBlocks;
|
||||
{$endif}
|
||||
wantedsize:=size;
|
||||
{ Allocate by 64K size }
|
||||
size:=(size+$ffff) and $ffff0000;
|
||||
{ first try 256K (default) }
|
||||
@ -783,7 +781,10 @@ end;
|
||||
|
||||
{
|
||||
$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,
|
||||
had to introduce a flag for such blocks.
|
||||
* flags are now stored in the first 4 bits instead of the highest bit,
|
||||
|
@ -663,12 +663,71 @@ begin
|
||||
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
|
||||
{ Set up signals handlers }
|
||||
InstallSignals;
|
||||
{ Setup heap }
|
||||
InitHeap;
|
||||
InitExceptions;
|
||||
{ Arguments }
|
||||
SetupCmdLine;
|
||||
{ Setup stdin, stdout and stderr }
|
||||
OpenStdIO(Input,fmInput,StdInputHandle);
|
||||
OpenStdIO(Output,fmOutput,StdOutputHandle);
|
||||
@ -680,7 +739,10 @@ End.
|
||||
|
||||
{
|
||||
$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
|
||||
|
||||
Revision 1.28 1999/10/28 09:50:06 peter
|
||||
|
@ -678,58 +678,56 @@ procedure setup_arguments;
|
||||
var
|
||||
arglen,
|
||||
count : longint;
|
||||
argstart,scmdline : pchar;
|
||||
argstart,
|
||||
pc : pchar;
|
||||
quote : set of char;
|
||||
argsbuf : array[0..127] of pchar;
|
||||
|
||||
begin
|
||||
{ create commandline, it starts with the executed filename which is argv[0] }
|
||||
{ Win32 passes the command NOT via the args, but via getmodulefilename}
|
||||
count:=0;
|
||||
cmdline:=getcommandfile;
|
||||
pc:=getcommandfile;
|
||||
Arglen:=0;
|
||||
repeat
|
||||
Inc(Arglen);
|
||||
until (cmdline[Arglen]=#0);
|
||||
until (pc[Arglen]=#0);
|
||||
getmem(argsbuf[count],arglen+1);
|
||||
move(cmdline^,argsbuf[count]^,arglen);
|
||||
move(pc^,argsbuf[count]^,arglen);
|
||||
{ Now skip the first one }
|
||||
cmdline:=GetCommandLine;
|
||||
pc:=GetCommandLine;
|
||||
repeat
|
||||
{ skip leading spaces }
|
||||
while cmdline^ in [' ',#9,#13] do
|
||||
inc(longint(cmdline));
|
||||
case cmdline^ of
|
||||
while pc^ in [' ',#9,#13] do
|
||||
inc(pc);
|
||||
case pc^ of
|
||||
#0 : break;
|
||||
'"' : begin
|
||||
quote:=['"'];
|
||||
inc(longint(cmdline));
|
||||
inc(pc);
|
||||
end;
|
||||
'''' : begin
|
||||
quote:=[''''];
|
||||
inc(longint(cmdline));
|
||||
inc(pc);
|
||||
end;
|
||||
else
|
||||
quote:=[' ',#9,#13];
|
||||
end;
|
||||
{ scan until the end of the argument }
|
||||
argstart:=cmdline;
|
||||
while (cmdline^<>#0) and not(cmdline^ in quote) do
|
||||
inc(longint(cmdline));
|
||||
{ Don't copy the first one, it is already there.}
|
||||
If Count<>0 then
|
||||
argstart:=pc;
|
||||
while (pc^<>#0) and not(pc^ in quote) do
|
||||
inc(pc);
|
||||
{ Don't copy the first one, it is already there.}
|
||||
If Count<>0 then
|
||||
begin
|
||||
{ reserve some memory }
|
||||
arglen:=cmdline-argstart;
|
||||
getmem(argsbuf[count],arglen+1);
|
||||
move(argstart^,argsbuf[count]^,arglen);
|
||||
argsbuf[count][arglen]:=#0;
|
||||
{ reserve some memory }
|
||||
arglen:=pc-argstart;
|
||||
getmem(argsbuf[count],arglen+1);
|
||||
move(argstart^,argsbuf[count]^,arglen);
|
||||
argsbuf[count][arglen]:=#0;
|
||||
end;
|
||||
{ skip quote }
|
||||
if cmdline^ in quote then
|
||||
inc(longint(cmdline));
|
||||
if count=0 then
|
||||
scmdline:=cmdline-1;
|
||||
if pc^ in quote then
|
||||
inc(pc);
|
||||
inc(count);
|
||||
until false;
|
||||
{ create argc }
|
||||
@ -740,8 +738,8 @@ begin
|
||||
{ create the argv }
|
||||
getmem(argv,count shl 2);
|
||||
move(argsbuf,argv^,count shl 2);
|
||||
// finally setup the abused cmdline variable
|
||||
cmdline:=scmdline;
|
||||
{ Setup cmdline variable }
|
||||
cmdline:=GetCommandLine;
|
||||
end;
|
||||
|
||||
|
||||
@ -1009,12 +1007,10 @@ type pexception_record = ^exception_record;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
old_exception : LPTOP_LEVEL_EXCEPTION_FILTER;
|
||||
|
||||
procedure install_exception_handlers;
|
||||
begin
|
||||
old_exception:=SetUnhandledExceptionFilter(@syswin32_i386_exception_handler);
|
||||
SetUnhandledExceptionFilter(@syswin32_i386_exception_handler);
|
||||
end;
|
||||
|
||||
|
||||
@ -1161,7 +1157,10 @@ end.
|
||||
|
||||
{
|
||||
$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
|
||||
|
||||
Revision 1.49 1999/11/18 22:19:57 pierre
|
||||
|
Loading…
Reference in New Issue
Block a user