2
0

sargs.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 by Pierre Muller,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. var argc : longint;
  13. doscmd : string;
  14. args : ^pchar;
  15. function far_strlen(selector : word;linear_address : longint) : longint;
  16. begin
  17. asm
  18. movl linear_address,%edx
  19. movl %edx,%ecx
  20. movw selector,%gs
  21. Larg19:
  22. movb %gs:(%edx),%al
  23. testb %al,%al
  24. je Larg20
  25. incl %edx
  26. jmp Larg19
  27. Larg20:
  28. movl %edx,%eax
  29. subl %ecx,%eax
  30. movl %eax,__RESULT
  31. end;
  32. end;
  33. function atohex(s : pchar) : longint;
  34. var rv : longint;
  35. v : byte;
  36. begin
  37. rv := 0;
  38. while (s^ <>#0) do
  39. begin
  40. v := ord(s^) - ord('0');
  41. if (v > 9) then v := v - 7;
  42. v := v and 15; { in case it's lower case }
  43. rv := rv*16 + v;
  44. inc(longint(s));
  45. end;
  46. atohex := rv;
  47. end;
  48. procedure setup_arguments;
  49. type arrayword = array [0..0] of word;
  50. var psp : word;
  51. i,j : byte;
  52. quote : char;
  53. proxy_s : string[7];
  54. al,proxy_argc,proxy_seg,proxy_ofs,lin : longint;
  55. largs : array[0..127] of pchar;
  56. rm_argv : ^arrayword;
  57. begin
  58. for i := 1 to 127 do
  59. largs[i] := nil;
  60. psp:=stub_info^.psp_selector;
  61. largs[0]:=dos_argv0;
  62. argc := 1;
  63. sysseg_move(psp, 128, get_ds, longint(@doscmd), 128);
  64. {$IfDef SYSTEMDEBUG}
  65. Writeln('Dos command line is #',doscmd,'# size = ',length(doscmd));
  66. {$EndIf SYSTEMDEBUG}
  67. j := 1;
  68. quote := #0;
  69. for i:=1 to length(doscmd) do
  70. Begin
  71. if doscmd[i] = quote then
  72. begin
  73. quote := #0;
  74. doscmd[i] := #0;
  75. largs[argc]:=@doscmd[j];
  76. inc(argc);
  77. j := i+1;
  78. end else
  79. if (quote = #0) and ((doscmd[i] = '''') or (doscmd[i]='"')) then
  80. begin
  81. quote := doscmd[i];
  82. j := i + 1;
  83. end else
  84. if (quote = #0) and ((doscmd[i] = ' ')
  85. or (doscmd[i] = #9) or (doscmd[i] = #10) or
  86. (doscmd[i] = #12) or (doscmd[i] = #9)) then
  87. begin
  88. doscmd[i]:=#0;
  89. if j<i then
  90. begin
  91. largs[argc]:=@doscmd[j];
  92. inc(argc);
  93. j := i+1;
  94. end else inc(j);
  95. end else
  96. if (i = length(doscmd)) then
  97. begin
  98. doscmd[i+1]:=#0;
  99. largs[argc]:=@doscmd[j];
  100. inc(argc);
  101. end;
  102. end;
  103. if (argc > 1) and (far_strlen(get_ds,longint(largs[1])) = 6) then
  104. begin
  105. move(largs[1]^,proxy_s[1],6);
  106. proxy_s[0] := #6;
  107. if (proxy_s = '!proxy') then
  108. begin
  109. {$IfDef SYSTEMDEBUG}
  110. Writeln('proxy command line ');
  111. {$EndIf SYSTEMDEBUG}
  112. proxy_argc := atohex(largs[2]);
  113. proxy_seg := atohex(largs[3]);
  114. proxy_ofs := atohex(largs[4]);
  115. getmem(rm_argv,proxy_argc*sizeof(word));
  116. sysseg_move(dos_selector,proxy_seg*16+proxy_ofs, get_ds,longint(rm_argv),proxy_argc*sizeof(word));
  117. for i:=0 to proxy_argc - 1 do
  118. begin
  119. lin := proxy_seg*16 + rm_argv^[i];
  120. al :=far_strlen(dos_selector, lin);
  121. getmem(largs[i],al+1);
  122. sysseg_move(dos_selector, lin, get_ds,longint(largs[i]), al+1);
  123. {$IfDef SYSTEMDEBUG}
  124. Writeln('arg ',i,' #',largs[i],'#');
  125. {$EndIf SYSTEMDEBUG}
  126. end;
  127. argc := proxy_argc;
  128. end;
  129. end;
  130. getmem(args,argc*SizeOf(pchar));
  131. for i := 0 to argc-1 do
  132. args[i] := largs[i];
  133. end;
  134. function strcopy(dest,source : pchar) : pchar;
  135. begin
  136. asm
  137. cld
  138. movl 12(%ebp),%edi
  139. movl $0xffffffff,%ecx
  140. xorb %al,%al
  141. repne
  142. scasb
  143. not %ecx
  144. movl 8(%ebp),%edi
  145. movl 12(%ebp),%esi
  146. movl %ecx,%eax
  147. shrl $2,%ecx
  148. rep
  149. movsl
  150. movl %eax,%ecx
  151. andl $3,%ecx
  152. rep
  153. movsb
  154. movl 8(%ebp),%eax
  155. leave
  156. ret $8
  157. end;
  158. end;
  159. procedure setup_environment;
  160. var env_selector : word;
  161. env_count : longint;
  162. dos_env,cp : pchar;
  163. stubaddr : p_stub_info;
  164. begin
  165. asm
  166. movl __stubinfo,%eax
  167. movl %eax,stubaddr
  168. end;
  169. stub_info:=stubaddr;
  170. getmem(dos_env,stub_info^.env_size);
  171. env_count:=0;
  172. sysseg_move(stub_info^.psp_selector,$2c, get_ds, longint(@env_selector), 2);
  173. sysseg_move(env_selector, 0, get_ds, longint(dos_env), stub_info^.env_size);
  174. cp:=dos_env;
  175. while cp ^ <> #0 do
  176. begin
  177. inc(env_count);
  178. while (cp^ <> #0) do inc(longint(cp)); { skip to NUL }
  179. inc(longint(cp)); { skip to next character }
  180. end;
  181. getmem(environ,(env_count+1) * sizeof(pchar));
  182. if (environ = nil) then exit;
  183. cp:=dos_env;
  184. env_count:=0;
  185. while cp^ <> #0 do
  186. begin
  187. getmem(environ[env_count],strlen(cp)+1);
  188. strcopy(environ[env_count], cp);
  189. {$IfDef SYSTEMDEBUG}
  190. Writeln('env ',env_count,' = "',environ[env_count],'"');
  191. {$EndIf SYSTEMDEBUG}
  192. inc(env_count);
  193. while (cp^ <> #0) do inc(longint(cp)); { skip to NUL }
  194. inc(longint(cp)); { skip to next character }
  195. end;
  196. environ[env_count]:=nil;
  197. inc(longint(cp),3);
  198. getmem(dos_argv0,strlen(cp)+1);
  199. if (dos_argv0 = nil) then halt;
  200. strcopy(dos_argv0, cp);
  201. end;
  202. {
  203. $Log$
  204. Revision 1.1 1998-03-25 11:18:42 root
  205. Initial revision
  206. Revision 1.3 1998/01/26 11:57:15 michael
  207. + Added log at the end
  208. Working file: rtl/dos/go32v2/sargs.inc
  209. description:
  210. ----------------------------
  211. revision 1.2
  212. date: 1997/12/01 15:35:01; author: michael; state: Exp; lines: +14 -0
  213. + Added copyright reference in header.
  214. ----------------------------
  215. revision 1.1
  216. date: 1997/11/27 08:33:52; author: michael; state: Exp;
  217. Initial revision
  218. ----------------------------
  219. revision 1.1.1.1
  220. date: 1997/11/27 08:33:52; author: michael; state: Exp; lines: +0 -0
  221. FPC RTL CVS start
  222. =============================================================================
  223. }