wbargs.pas 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. {
  2. This file is part of the Free Pascal run time library.
  3. A file in Amiga system run time library.
  4. Copyright (c) 1998-2003 by Nils Sjoholm
  5. member of the Amiga RTL 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. {
  13. The boolean IsConsole is in system.
  14. Just check the value of system.IsConsole
  15. or just IsConsole, if it is false then you
  16. started from workbench.
  17. Added the define use_amiga_smartlink.
  18. 13 Jan 2003.
  19. Changed integer > smallint.
  20. 10 Feb 2003.
  21. [email protected] Nils Sjoholm
  22. }
  23. {$I useamigasmartlink.inc}
  24. {$ifdef use_amiga_smartlink}
  25. {$smartlink on}
  26. {$endif use_amiga_smartlink}
  27. unit WBArgs;
  28. interface
  29. uses workbench,amigados;
  30. function GetStartupMsg: pWBStartup;
  31. function ProgramName: string;
  32. function WBArgCount: smallint;
  33. function GetWBArg(num : smallint): STRING;
  34. implementation
  35. function GetStartupMsg: pWBStartup;
  36. begin
  37. if system._WBenchMsg <> nil then
  38. GetStartupMsg := pWBStartup(_WBenchMsg)
  39. else
  40. GetStartupMsg := nil;
  41. end;
  42. function ProgramName: string;
  43. var
  44. WBMsg : pWBStartup;
  45. buffer : array[0..255] of char;
  46. begin
  47. WBMsg := GetStartupMsg;
  48. if WBMsg <> nil then begin
  49. ProgramName := strpas(WBMsg^.sm_ArgList^[1].wa_Name);
  50. end else begin
  51. if GetprogramName(buffer,255) then begin
  52. ProgramName := strpas(buffer);
  53. end else begin
  54. ProgramName := '';
  55. end;
  56. end;
  57. end;
  58. function WBArgCount: smallint;
  59. var
  60. WBMsg : pWBStartup;
  61. begin
  62. WBMsg := GetStartupMsg;
  63. if WBMsg <> nil then
  64. WBArgCount := WBMsg^.sm_NumArgs -1
  65. else WBArgCount := 0;
  66. end;
  67. function GetWBArg(num : smallint): string;
  68. var
  69. WBMsg : pWBStartup;
  70. param : smallint;
  71. begin
  72. WBMsg := GetStartupMsg;
  73. if WBMsg <> nil then begin
  74. param := WBMsg^.sm_NumArgs;
  75. end else begin
  76. param := 0;
  77. end;
  78. if (param > 0) AND (num <= param) then begin
  79. GetWBArg := strpas(WBMsg^.sm_ArgList^[num+1].wa_Name);
  80. end else begin
  81. GetWBArg := '';
  82. end;
  83. end;
  84. end.