Command Line Arguments

Gamma: Version 4.0
Prev | Chapter 7. Functions and Program Structure | Next

# 7.8. Command Line Arguments

Gamma provides a mechanism for accessing command line arguments. The symbol `argv` contains a list of the parsed command line arguments. Thus, if you have an application named my_app which takes two arguments `arg1` and `arg2`, then the executable invoked with:

        		my_app arg1 arg2

will receive the following `argv`:

        		(my_app arg1 arg2)

Like any list, the length of `argv` is simply `length (argv);` The command line arguments can be accessed like any list, using any of the following sample approaches:

        for ( i=0; i < length(argv); i++)
        {
            arg = car (nth_cdr (argv, i));
            ... process arg ...
        }

or similarly, but more efficient:

        while (length (argv) > 0)
        {
            arg = car (argv);
            ... process arg ...
            argv = cdr (argv);
        }

which can also be expressed, still more efficiently, and without modifying the original `argv`, with:

        for (i=argv; i; i = cdr(i))
        {
            arg = car (i);
            ... process arg ...
        }

Prev | Home | Next
Running a Gamma Program | Up | Object Oriented Programming

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.