Welcome, Guest.
Please login or register.
Command-line arguments
Forum Login
Login Name: Create a new account
Password:     Forgot password

XBLite Forum    General Boards    Working Code Snippets  ›  Command-line arguments
Users Browsing Forum
No Members and 1 Guests

Command-line arguments  This thread currently has 5,666 views. Print Print Thread
1 Pages 1 Recommend Thread
caeman
June 29, 2008, 1:03am Report to Moderator Report to Moderator
Baby Member
Posts: 2
A simple program that gets and displays what ever in the command line of the program.  This is my first step to other command-line programs.

--

'
' ####################
' #####  PROLOG  #####
' ####################
'
' A console program template
'
VERSION "0.0001"
CONSOLE
'
     IMPORT "xst"                    ' Standard library : required by most programs
     IMPORT "xsx"                    ' Extended standard library
     IMPORT "xio"                    ' Console input/ouput library

'     IMPORT "xst_s.lib"
' IMPORT "xsx_s.lib"
' IMPORT "xio_s.lib"

' IMPORT "gdi32"               ' gdi32.dll
'     IMPORT "user32"            ' user32.dll
'     IMPORT "kernel32"       ' kernel32.dll
'     IMPORT "shell32"          ' shell32.dll
'     IMPORT "msvcrt"            ' msvcrt.dll

'
DECLARE FUNCTION Entry ()
'
'
' ######################
' #####  Entry ()  #####
' ######################
'
FUNCTION Entry ()
     XstGetCommandLineArguments (@argc, @argv$[])
     PRINT "Number of command line arguments:"; argc
     
     FOR x = 0 TO argc-1
          PRINT argv$[x]
     NEXT x

END FUNCTION
END PROGRAM
Logged Offline
Private Message Private message
XBLiteAdmin
June 29, 2008, 11:47pm Report to Moderator Report to Moderator
Administrator Group
Posts: 44
Quoted from caeman

     XstGetCommandLineArguments (@argc, @argv$[])
     PRINT "Number of command line arguments:"; argc
     
     FOR x = 0 TO argc-1
          PRINT argv$[x]
     NEXT x


When a function returns an array, it is usually better to make
sure it is not empty. So I would do this instead:

IF argv$[] THEN
  upp = UBOUND(argv$[])
  FOR i = 0 TO upp
    ? argv$[i]
  NEXT i
END IF

Logged Offline
Site Site Private Message Private message Reply: 1 - 4
caeman
June 30, 2008, 3:24am Report to Moderator Report to Moderator
Baby Member
Posts: 2
I figured in this case I could assume the array wasn't empty, since ARGV$ by its nature MUST have at least one entry.  But, yes, in most cases UBOUND should be used.
Logged Offline
Private Message Private message Reply: 2 - 4
Garquint
June 30, 2008, 11:48am Report to Moderator Report to Moderator
Baby Member
Posts: 1

You could do it like this too...i think:

XstGetCommandLineArguments (@argc, @argv$[])

FOR a = 0 TO UBOUND(argv$[])
  addr = &argv$[a]
  FOR b = addr TO addr+XLONGAT(addr-8 )
   chr$ = CHR$(UBYTEAT(b))
   IF (chr$ != "\0") THEN PRINT chr$;
   IF (chr$ == "\0") THEN PRINT
  NEXT b
NEXT a

but really not practical.



Garquint





Logged Offline
Private Message Private message Reply: 3 - 4
17
July 5, 2008, 10:38am Report to Moderator Report to Moderator
Guest User
What about copy/paste this demo?
Guy

PROGRAM "test"
VERSION "1.00"
CONSOLE
  IMPORT "xsx" ' for XstGetCommandLineArguments ()

DECLARE FUNCTION Entry () ' program entry point

FUNCTION Entry ()

'------------------------------------begin
  DIM argv$[]
  XstGetCommandLineArguments (@argc, @argv$[])
  upparg = UBOUND (argv$[])
  IF upparg < 1 THEN
    DIM parm$[]
  ELSE
    DIM parm$[upparg - 1]
    FOR iarg = 1 TO upparg
      parm$[iarg - 1] = TRIM$ (argv$[iarg])
    NEXT iarg
  END IF
'------------------------------------end
  IFZ parm$[] THEN
  ? "No line command arguments"
  ELSE
  ? "Line command arguments:"
    FOR i = 0 TO UBOUND (parm$[])
      ? parm$[i]
    NEXT i
  END IF
  a$ = INLINE$ ("Press Enter to quit >")
  QUIT (0)

END FUNCTION

END PROGRAM

-----------------batch file
@ECHO OFF
test.exe arg1 arg2 arg3
Logged
E-mail E-mail Reply: 4 - 4
1 Pages 1 Recommend Thread
Print Print Thread

XBLite Forum    General Boards    Working Code Snippets  ›  Command-line arguments

Thread Rating
There is currently no rating for this thread