Genparse Examples


Example from the info pages

mycopy

Simple example described in the info pages. Below is the output of a call to mycopy4 --help:

usage: mycopy4 [ -iohv ] file
   [ -i ] [ --iterations ] (type=INTEGER, range=1...MAX, default=1)
          Number of times to output <file>.
          do it like this
   [ -o ] [ --outfile ] (type=STRING)
          Output file.
   [ --longonly ] (type=FLAG)
   [ --longonly2 ] (type=FLAG)
   [ -h ] [ --help ] (type=FLAG)
          Display help information.
   [ -v ] [ --version ] (type=FLAG)
          Output version.

Language
Source file containing main program (provided by the user)
Genparse file (provided by the user)
Parser interface (generated by genparse)
Parser implementation (generated by genparse)
Callback functions (generated by genparse)
Exception class (generated by genparse)
C
mycopy3.c mycopy3.gp mycopy3_clp.h mycopy3_clp.c

C++
mycopy4.cc mycopy4.gp mycopy4_clp.h mycopy4_clp.cc mycopy4_clp_cb.cc
Java
mycopy5.java mycopy5.gp CmdlineInterface.java
Cmdline.java
CmdlineEx.java

GNU Coreutils

Dummy functions for demonstrating command line parsing of some well known tools from the GNU Coreutils. Genparse was invoked with the options --longmembers --internationalize --static-headers --gnulib.

echo

Usage: echo [OPTION]... [STRING]...
Echo the STRING(s) to standard output.

  -n                    do not output the trailing newline
  -e                    enable interpretation of backslash escapes (default)
  -E                    disable interpretation of backslash escapes
  -h, --help            display this help and exit
  -v, --version         output version information and exit

If -e is in effect, the following sequences are recognized:

  \0NNN   the character whose ASCII code is NNN (octal)
  \\     backslash
  \a     alert (BEL)
  \b     backspace
  \c     suppress trailing newline
  \f     form feed
  \n     new line
  \r     carriage return
  \t     horizontal tab
  \v     vertical tab

NOTE: your shell may have its own version of echo, which usually supersedes
the version described here.  Please refer to your shell's documentation
for details about the options it supports.

Report bugs to <bug-fileutils@gnu.org>.

Source file containing main program (provided by the user)
Genparse file (provided by the user)
Parser interface (generated by genparse)
Parser implementation (generated by genparse)
Auxiliary file (provided by the user)
echo.c echo.gp echo_clp.h echo_clp.c coreutils.h

ls

Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print octal escapes for nongraphic characters
      --block-size=SIZE      use SIZE-byte blocks
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information)
                               with -l: show ctime and sort by name
                               otherwise: sort by ctime
  -C                         list entries by columns
      --color[=WHEN]         control whether color is used to distinguish file
                               types.  WHEN may be `never', `always', or `auto'
  -d, --directory            list directory entries instead of contents,
                               and do not dereference symbolic links
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -ls --color
  -F, --classify             append indicator (one of /=*>@|) to entries
      --file-type            likewise, except do not append `*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
                               single-column -1, verbose -l, vertical -C
      --full-time            like -l --time-style=full-iso
  -g                         like -l, but do not list owner
      --group-directories-first
                             group directories before files
  -G, --no-group             in a long listing, don't print group names
  -h, --human-readable       with -l, print sizes in human readable format
                               (e.g., 1K 234M 2G)
      --si                   likewise, but use powers of 1000 not 1024
  -H, --dereference-command-line
                             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
                             follow each command line symbolic link
                             that points to a directory
      --hide=PATTERN         do not list implied entries matching shell PATTERN
                               (overridden by -a or -A)
      --indicator-style=WORD  append indicator with style WORD to entry names:
                               none (default), slash (-p),
                               file-type (--file-type), classify (-F)
  -i, --inode                print the index number of each file
  -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  -k                         like --block-size=1K
  -l                         use a long listing format
  -L, --dereference          when showing file information for a symbolic
                               link, show information for the file the link
                               references rather than for the link itself
  -m                         fill width with a comma separated list of entries
  -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
  -N, --literal              print raw entry names (don't treat e.g. control
                               characters specially)
  -o                         like -l, but do not list group information
  -p                         like --indicator-style=slash
                               append / indicator to directories
  -q, --hide-control-chars   print ? instead of non graphic characters
      --show-control-chars   show non graphic characters as-is (default
                             unless program is `ls' and output is a terminal)
  -Q, --quote-name           enclose entry names in double quotes
      --quoting-style=WORD   use quoting style WORD for entry names:
                               literal, locale, shell, shell-always, c, escape
  -r, --reverse              reverse order while sorting
  -R, --recursive            list subdirectories recursively
  -s, --size                 print the size of each file, in blocks
  -S                         sort by file size
      --sort=WORD            sort by WORD instead of name: none -U,
                             extension -X, size -S, time -t, version -v
      --time=WORD            with -l, show time as WORD instead of modification
                             time: atime -u, access -u, use -u, ctime -c,
                             or status -c; use specified time as sort key
                             if --sort=time
      --time-style=STYLE     with -l, show times using style STYLE:
                             full-iso, long-iso, iso, locale, +FORMAT.
                             FORMAT is interpreted like `date'; if FORMAT is
                             FORMAT1<newline>FORMAT2, FORMAT1 applies to
                             non-recent files and FORMAT2 to recent files;
                             if STYLE is prefixed with `posix-', STYLE
                             takes effect only outside the POSIX locale
  -t                         sort by modification time
  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
  -u                         with -lt: sort by, and show, access time
                               with -l: show access time and sort by name
                               otherwise: sort by access time
  -U                         do not sort; list entries in directory order
  -v                         sort by version
  -w, --width=COLS           assume screen width instead of current value
  -x                         list entries by lines instead of by columns
  -X                         sort alphabetically by entry extension
  -Z, --context              print any SELinux security context of each file
  -1                         list one file per line
      --help                 display this help and exit
      --version              output version information and exit

SIZE may be (or may be an integer optionally followed by) one of following:
kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

By default, color is not used to distinguish types of files.  That is
equivalent to using --color=none.  Using the --color option without the
optional WHEN argument is equivalent to using --color=always.  With
--color=auto, color codes are output only if standard output is connected
to a terminal (tty).  The environment variable LS_COLORS can influence the
colors, and can be set easily by the dircolors command.

Exit status is 0 if OK, 1 if minor problems, 2 if serious trouble.

Report bugs to <bug-coreutils@gnu.org>.
Source file containing main program (provided by the user)
Genparse file (provided by the user)
Parser interface (generated by genparse)
Parser implementation (generated by genparse)
Auxiliary file (provided by the user)
ls.c ls.gp, help_version.gp ls_clp.h ls_clp.c coreutils.h, ls.h

mv

Usage: mv [OPTION]... SOURCE DEST
  or:  mv [OPTION]... SOURCE... DIRECTORY
  or:  mv [OPTION]... --target-directory=DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

      --backup                 make a backup of each existing destination file
  -b                           like --backup but does not accept an argument
  -f, --force                  never prompt before overwriting
  -i, --interactive            prompt before overwrite
      --strip-trailing-slashes  remove any trailing slashes from each SOURCE
                                 argument
  -s, --suffix=SUFFIX          override the usual backup suffix
      --target-directory       move all SOURCE arguments into DIRECTORY
  -u, --update                 move only older or brand new non-directories
  -v, --verbose                explain what is being done
  -h, --help                   display this help and exit
      --version                output version information and exit

The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable.  Here are the values:

  none, off       never make backups (even if --backup is given)
  numbered, t     make numbered backups
  existing, nil   numbered if numbered backups exist, simple otherwise
  simple, never   always make simple backups

Report bugs to <bug-fileutils@gnu.org>.

Source file containing main program (provided by the user)
Genparse file (provided by the user)
Parser interface (generated by genparse)
Parser implementation (generated by genparse)
Auxiliary file (provided by the user)
mv.c mv.gp mv_clp.h mv_clp.c coreutils.h

rm

Remove (unlink) the FILE(s).

Usage: rm [OPTION]... FILE...
  -d, --directory       unlink directory, even if non-empty (super-user only)
  -f, --force           ignore nonexistant files, never prompt
  -i, --interactive     prompt before any removal
  -r -R, --recursive    remove the contents of directories recursively
  -v, --verbose         explain what is being done
  -h, --help            print this help and exit
      --version         print version information and exit

To remove a file whose name starts with a `-', for example `-foo',
use one of these commands:
  rm -- -foo

  rm ./-foo

Note that if you use rm to remove a file, it is usually possible to recover
the contents of that file.  If you want more assurance that the contents are
truly unrecoverable, consider using shred.

Report bugs to <bug-fileutils@gnu.org>.

Source file containing main program (provided by the user)
Genparse file (provided by the user)
Parser interface (generated by genparse)
Parser implementation (generated by genparse)
Auxiliary file (provided by the user)
rm.c rm.gp rm_clp.h rm_clp.c coreutils.h

tail

Usage: tail [OPTION]... [FILE]...
Print the last 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.

      --retry              keep trying to open a file even if it is
                           inaccessible when tail starts or if it becomes
                           inaccessible later; useful when following by name,
                           i.e., with --follow=name
  -c, --bytes=N            output the last N bytes; alternatively, use +N to
                           output bytes starting with the Nth of each file
  -f, --follow[={name|descriptor}]
                           output appended data as the file grows;
                           -f, --follow, and --follow=descriptor are
                           equivalent
  -F                       same as --follow=name --retry
  -n, --lines=N            output the last N lines, instead of the last 10;
                           or use +N to output lines starting with the Nth
      --max-unchanged-stats=N
                           with --follow=name, reopen a FILE which has not
                           changed size after N (default 5) iterations
                           to see if it has been unlinked or renamed
                           (this is the usual case of rotated log files)
      --pid=PID            with -f, terminate after process ID, PID dies
  -q, --quiet              never output headers giving file names
      --silent             same as --quiet
  -s, --sleep-interval=S   with -f, sleep for approximately S seconds
                           (default 1.0) between iterations.
  -v, --verbose            always output headers giving file names
      --help               display this help and exit
      --version            output version information and exit

If the first character of N (the number of bytes or lines) is a `+',
print beginning with the Nth item from the start of each file, otherwise,
print the last N items in the file.  N may have a multiplier suffix:
b 512, k 1024, m 1024*1024.

With --follow (-f), tail defaults to following the file descriptor, which
means that even if a tail'ed file is renamed, tail will continue to track
its end.  This default behavior is not desirable when you really want to
track the actual name of the file, not the file descriptor (e.g., log
rotation).  Use --follow=name in that case.  That causes tail to track the
named file by reopening it periodically to see if it has been removed and
recreated by some other program.

Report bugs to <bug-coreutils@gnu.org>.

Source file containing main program (provided by the user)
Genparse file (provided by the user)
Parser interface (generated by genparse)
Parser implementation (generated by genparse)
Auxiliary file (provided by the user)
tail.c tail.gp, help_version.gp tail_clp.h tail_clp.c coreutils.h, tail.h

uname

Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

  -a, --all             print all information, in the following order,
                          except omit -p and -i if unknown:
  -s, --kernel-name     print the kernel name
  -n, --nodename        print the network node hostname
  -v, --kernel-version  print the kernel name
  -r, --kernel-release  print the kernel version
  -m, --machine         print the kernel machine hardware name
  -p, --processor       print the processor type or
  -h, --help            Display help information.

Report bugs to <bug-fileutils@gnu.org>.

Source file containing main program (provided by the user)
Genparse file (provided by the user)
Parser interface (generated by genparse)
Parser implementation (generated by genparse)
Auxiliary file (provided by the user)
uname.c uname.gp uname_clp.h uname_clp.c coreutils.h

wc

Usage: wc [OPTION]... [FILE]...
  or:  wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.  With no FILE, or when FILE is -,
read standard input.

  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
      --files0-from=F    read input from the files specified by
                           NUL-terminated names in file F
  -L, --max-line-length  print the length of the longest line
  -w, --words            print the word counts
      --help             display this help and exit
      --version          output version information and exit

Report bugs to <bug-coreutils@gnu.org>.

Source file containing main program (provided by the user)
Genparse file (provided by the user)
Parser interface (generated by genparse)
Parser implementation (generated by genparse)
Auxiliary file (provided by the user)
wc.c wc.gp,
help_version.gp
wc_clp.h wc_clp.c coreutils.h

GNU Inetutils

Dummy functions for demonstrating command line parsing of the well known ping command from the GNU Inetutils. Genparse was invoked with the options --longmembers --static-headers --gnulib.

ping

Usage: ping [OPTION]... [ADDRESS]...

Informational options:
  -h, --help         display this help and exit
  -L, --license      display license and exit
  -V, --version      output version information and exit
Options controlling ICMP request types:
      --echo         Send ICMP_ECHO requests (default)
      --address    * Send ICMP_ADDRESS packets
      --timestamp    Send ICMP_TIMESTAMP packets
  -t, --type         Send TYPE packets
      --router     * Send ICMP_ROUTERDISCOVERY packets
Options valid for all request types:
  -c, --count=N      stop after sending N packets
  -d, --debug        set the SO_DEBUG option
  -i, --interval=N   wait N seconds between sending each packet
  -n, --numeric      do not resolve host addresses
  -r, --ignore-routing  send directly to a host on an attached network
  -v, --verbose      verbose output
Options valid for --echo requests:
  -f, --flood      * flood ping
  -l, --preload=N  * send N packets as fast as possible before falling into
                     normal mode of behavior
  -p, --pattern=PAT  fill ICMP packet with given pattern (hex)
  -q, --quiet        quiet output
  -R, --route        record route
  -s, --size=N       set number of data octets to send

Options marked with an * are available only to super-user

Report bugs to <bug-inetutils@gnu.org>.

Source file containing main program (provided by the user)
Genparse file (provided by the user)
Parser interface (generated by genparse)
Parser implementation (generated by genparse)
Auxiliary file (provided by the user)
ping.c ping.gp ping_clp.h ping_clp.c ping.h
SourceForge Logo