Menu

#741 Make SysCArgs available through USE and ARG() bif

None
unread
nobody
None
none
1
2021-01-12
2019-02-20
Erich
No

I wish we'd be given access to the main "SysCArgs" arguments through use of the USE keyword instruction and the ARG() built-in function with a new option.

Related

Feature Requests: #741
Feature Requests: #788

Discussion

  • Erich

    Erich - 2020-12-25

    Bob suggests USE (STRICT) ARG SYSCARRAY, I'm leaning towards USE (STRICT) CARG
    The ARG option could be "C", like "CARG"

    Any suggestions?

     
    • Rony G. Flatscher

      +1
      use (strict) carg
      arg: c

       
  • Gil Barmwater

    Gil Barmwater - 2020-12-26

    Not sure I see the usefulness of this proposal; can someone provide an example? The USE instruction provides access to arguments passed by reference but aren't all the elements of SysCArgs always (immutable) strings?

     
    • Rony G. Flatscher

      the idea is to allow fetching thec-style arguments with the Rexx means of fetching arguments. what would be missing is a "PARSE CARG ...".

       
      • Gil Barmwater

        Gil Barmwater - 2020-12-27

        So the idea has less to do with USE (vs. PARSE) than providing a shorthand way of assigning the (string) arguments to meaningfully-named variables. And, I would argue, those arguments have already been 'fetched'; they're immediately accessible, as Bob noted, as .SysCArgs[1], etc. Guess I'm not a fan of this idea.

         
  • Bob Jewett

    Bob Jewett - 2020-12-26

    I was thinking:
    use carg a, b, c, d, e

    instead of:
    a = .SysCArgs[1]; b = .SysCArgs[2]; c = .SysCArgs[3]; d = .SysCArgs[4]; e = .SysCArgs[5]

     
    • Gil Barmwater

      Gil Barmwater - 2020-12-28

      If you could live with this syntax:
      call getCArgs a, b, c, d, e

      then by adding the following code to your program, you would have a solution:
      getCargs: -- can't be a procedure or ROUTINE due to scope of variables; could
      -- be a native routine as that could set the values in the caller's
      -- context
      do j = 1 to min(arg(), .sysCArgs~items)
      call value arg(j), .sysCArgs[j]
      end
      return

       
      • Rony G. Flatscher

        Gil, this would be a little bit cumbersome as you need to copy the code over and over.

        Command line arguments on PCs may denoet files containing blanks nowadays (enclosed in double-quotes or blanks escaped with backslashes on some systems) also causing a need to parse the arguments in a C-style manner (over and over again, despite Rexx having it parsed already.

        Allowing
        PARSE CARG a, b, c, d, e
        or
        USE CARG a, b, c, d, e

        makes it, as Bob writes, easy and intuitive (self documentary) to fetch the command line arguments parsed as C-style arguments and assigning the arguments to individual Rexx variables.

        ---rony

         
  • Gil Barmwater

    Gil Barmwater - 2020-12-29

    I agree that it is not optimal but it was a fun exercise to write and test. And I understand the desirability of accessing the C args for the cases you mention. But for those times that I would need to do that, I would simply use .sysCArgs[n] unless I needed to reference it multiple times. In that case I would code e.g. fn = .sysCArgs[1] and use fn from then on.

     
  • Bob Jewett

    Bob Jewett - 2020-12-29

    It just seemed to me that parsing all of them in one line like a PARSE CARG or USE CARG simplifies the code, especially when one or more arguments passed are double quoted.

     
    • Per Olov Jonsson

      What was the conclusion of this feature request? I have a similar need. I want a program to pick up this kind of input from the commandline (it works just fine from a file):

      "International Business Machines Corporation" 2020

      Without loosing the double quotes.

      arg, parse arg use arg and use strict arg all loose the double quotes, as do SysCArgs

      I can use this to get International Business Machines Corporation into a and 2020 into c:
      a = .SysCArgs[1]
      c = .SysCArgs[2]

      And patch it together again, adding the double quotes manually, but is there really no way to get the input line „as-is“ into ooRexx? Or am I missing the obvious (again)?

      Hälsningar/Regards/Grüsse,
      P.O. Jonsson
      per-olov.jonsson@kabelmail.de

      Am 29.12.2020 um 02:08 schrieb Bob bobjewett@users.sourceforge.net:

      It just seemed to me that parsing all of them in one line like a PARSE CARG or USE CARG simplifies the code, especially when one or more arguments passed are double quoted.


      [feature-requests:#741] Make SysCArgs available through USE and ARG() bif

      Status: unread
      Milestone: None
      Created: Wed Feb 20, 2019 05:24 PM UTC by Erich
      Last Updated: Tue Dec 29, 2020 12:51 AM UTC
      Owner: nobody

      I wish we'd be given access to the main "SysCArgs" arguments through use of the USE keyword instruction and the ARG() built-in function with a new option.


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/oorexx/feature-requests/741/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

      Related

      Feature Requests: #741

  • Gil Barmwater

    Gil Barmwater - 2020-12-29

    OK, one more way to do this and then I'll shut up. Note that I've made this 3 lines of code but of course it could be done in one with an increase in complexity and a decrease in understandability.
    ! = .endofline -- could be any character not in the arguments
    cargs = .sysCArgs~makestring(, !) -- specify the char. to separate the args if not using new line
    parse var cargs a (!) b (!) c (!) d (!) e (!) .

    Note that if there are less arguments than variables, the trailing ones are set to ''.

     

    Last edit: Gil Barmwater 2020-12-30
  • Erich

    Erich - 2021-01-04

    arg, parse arg use arg and use strict arg all loose the double quotes

    On Windows the quotes are kept, on Unix they are removed, which seems to be a bug to me. But which of the two is ways the correct one?

    I believe that the quotes are never part of an argument (if quotes are required in an argument they should be escaped as \" ), and as such shouldn't be part of Rexx' classic single-string argument.

    What was the conclusion of this feature request?

    No conclusion was drawn. Here's a modified proposal:

    Let "use arg" always use multiple arguments, no matter whether this is a COMMAND call or a SUBROUTINE/FUNCTION call. This makes using multiple arguments, potentially including blanks, most simple and straight forward, but in rare cases could break backwards compatibility.

    Of course "parse arg" will keep parsing the classic one-argument string.

     
    • Per Olov Jonsson

      Am 04.01.2021 um 11:01 schrieb Erich erich_st@users.sourceforge.net:

      arg, parse arg use arg and use strict arg all loose the double quotes

      On Windows the quotes are kept, on Unix they are removed, which seems to be a bug to me. But which of the two is ways the correct one?

      Ok, did not know about the difference. „Correct“ is what it was in the past I assume? I never reflected over this until I had the need to use quoted arguments (in macOS i.e. Unix).

      I believe that the quotes are never part of an argument (if quotes are required in an argument they should be escaped as \" ), and as such shouldn't be part of Rexx' classic single-string argument.

      I beg to disagree; I wanted to make the command-line (single-string) input mimic file input (that contains some items within double brackets), I think it would be useful to have a possibility to bypass the parsing occasionally and get the command-line input as-is into a variable in the program.

      IMO what is part and not part of the argument should be the users decision, anything that the OS does not intercept should be possible to get into the program.

       
    • Gil Barmwater

      Gil Barmwater - 2021-01-12

      IMHO, the correct way is to "keep" the quotes and not just because I'm a Windows user! When the user enters a command to the shell/cmd, the arguments are expected to be separated by blanks. If one or more of the arguments contains blanks, then the convention is to tell the shell/cmd that fact by surrounding the parts of the argument by double quotes. It could as well have been to use some other character or even to require the imbedded blanks to be escaped. So the shell/cmd now knows the proper way to populate argv[] which is what gets passed to the program (Rexx). Because Rexx needs to pass a single string containing all the arguments to the script, it needs to "construct" it from the elements of argv[]. On Windows, the quotes are re-inserted - they are NOT in argv[] as they are a directive to the shell/cmd and are therefore removed - so that the script can understand as well as the shell/cmd that one or more of the arguments contains blanks. This is a bug on 'nix to me.

       
  • Rony G. Flatscher

    "parse arg" gives you the command line argument unedited, i.e. as a single string.

    The startup code for C would have parsed the command line argument along white spaces and supply an array (pointer) of arguments to the entry function main().

    White spaces in file names cause a lot of problems all over the different languages and operating systems.

    Allowing double-quotes in file names makes things even more complicated (Windows prohibits quotes in file names).

    On Unix SysFileTree() will list all filenames as they are including quotes and spaces. Using the filenames with quotes and blanks in them via stream works as well. However, if using such filenames in commands one needs to escape the quotes (like: \") and enquote the entire filename in quotes in order to work.

    Also note that ooRexx .sysCargs contains the filenames correctly on Linux and MacOSX according to my tests!

    E.g. the file named (note also the blank after the small a)
    "a ha3".txt
    on the commandline needs to be denoted as
    \"a\ ha3\".txt

    The file named
    "aha3".txt
    on the commandline needs to be denoted as
    \"aha3\".txt


    Having "PARSE CARG " and "USE CARG" for parsing the command line according to C would really be helpful for Rexx programmers. If supplying this feature it should be in both forms, such that PARSE and USE for fetching arguments remain orthogonal to each other.

     
    • Per Olov Jonsson

      Am 04.01.2021 um 16:21 schrieb Rony G. Flatscher orexx@users.sourceforge.net:

      "parse arg" gives you the command line argument unedited, i.e. as a single string.

      This is true for Windows but not for Unix and macOS :-( at least on macOS the straight double quotes are removed from the string before the parsing can take place. Shall I file a bug report for this? Or is it the OS that snatches the double quotes?

      I have nothing to add to this feature request itself, my problem was to input commandline input (not paths or file names) with double quotes.

       
      • Rony G. Flatscher

        P.O.:

        you need to escape the quotes on the command line as I have demonstrated in my post above! E.g.

         rexx mypgm.rex \"a\ ha3\".txt \"aha3\".txt
        

        "parse arg" will give you

        "a ha3".txt "aha3".txt
        

        sysCarg[1] will be

         "a ha3".txt
        

        sysCarg[2] will be

         "aha3".txt
        

        This has nothing to do with Rexx, but is related to the (Unix) shell.

         
        • Per Olov Jonsson

          OK so it is a shell thing, not a rexx thing. Thanks for clarifying. I have my own workaround, as I said I want to mimic file input from the commandline, escaping goes against that goal.

          Hälsningar/Regards/Grüsse,
          P.O. Jonsson
          oorexx@jonases.se

          Am 04.01.2021 um 16:58 schrieb Rony G. Flatscher orexx@users.sourceforge.net:

          P.O.:

          you need to escape the quotes on the command line as I have demonstrated in my post above! E.g.

          rexx mypgm.rex \"a\ ha3\".txt \"aha3\".txt
          

          "parse arg" will give you

          "a ha3".txt "aha3".txt

          sysCarg[1] will be

          "a ha3".txt
          

          sysCarg[2] will be

          "aha3".txt
          

          This has nothing to do with Rexx, but is related to the (Unix) shell.


          [feature-requests:#741] Make SysCArgs available through USE and ARG() bif

          Status: unread
          Milestone: None
          Created: Wed Feb 20, 2019 05:24 PM UTC by Erich
          Last Updated: Mon Jan 04, 2021 03:21 PM UTC
          Owner: nobody

          I wish we'd be given access to the main "SysCArgs" arguments through use of the USE keyword instruction and the ARG() built-in function with a new option.


          Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/oorexx/feature-requests/741/

          To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

           

          Related

          Feature Requests: #741

Anonymous
Anonymous

Add attachments
Cancel