Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.


21.2 AmigaDOS 2.0 (and above)

This second program can be used as the Shell/CLI part of the previous program to provide much better command line parsing. It can only be used with AmigaDOS 2.0 and above (i.e., OSVERSION which is 37 or more). The template `FILE/M' used with ReadArgs gives command line parsing similar to C's argv array. The template can be much more interesting than this, but for more details you need the AmigaDOS Manual.

OPT OSVERSION=37

PROC main()
  DEF templ, rdargs, args=NIL:PTR TO LONG, i
  IF wbmessage=NIL
    WriteF('Started from Shell/CLI\n')
    templ:='FILE/M'
    rdargs:=ReadArgs(templ,{args},NIL)
    IF rdargs
      IF args
        i:=0
        WHILE args[i]  /* Loop through arguments */
          WriteF('   Argument \d: "\s"\n', i, args[i])
          i++
        ENDWHILE
      ENDIF
      FreeArgs(rdargs)
    ENDIF
  ENDIF
ENDPROC

As you can see the result of the ReadArgs call with this template is an array of filenames. The special quoting of filenames is dealt with correctly (i.e., when you use " around a filename that contains spaces). You need to do all this kind of work yourself if you use the arg method.


Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.