arg man page on Plan9

Man page or keyword search:  
man Server   549 pages
apropos Keyword Search (all sections)
Output format
Plan9 logo
[printable version]

ARG(2)									ARG(2)

NAME
       ARGBEGIN, ARGEND, ARGC, ARGF, EARGF - process option letters from argv

SYNOPSIS
       #include <u.h>
       #include <libc.h>

       ARGBEGIN {
       char *ARGF();
       char *EARGF(code);
       Rune ARGC();
       } ARGEND

       extern char *argv0;

DESCRIPTION
       These  macros assume the names argc and argv are in scope; see exec(2).
       ARGBEGIN and ARGEND surround code for processing program options.   The
       code should be the cases of a C switch on option characters; it is exe‐
       cuted once for each option character.  Options end  after  an  argument
       --, before an argument -, or before an argument that doesn't begin with
       -.

       The function macro ARGC returns the current  option  character,	as  an
       integer.

       The  function macro ARGF returns the current option argument: a pointer
       to the rest of the option string if not empty, or the next argument  in
       argv if any, or 0.  ARGF must be called just once for each option argu‐
       ment.  The macro EARGF is like ARGF but instead of returning zero  runs
       code and, if that returns, calls abort(2).  A typical value for code is
       usage(), as in EARGF(usage()).

       After ARGBEGIN, argv0 is a copy of argv[0] (conventionally the name  of
       the program).

       After  ARGEND,  argv  points at a zero-terminated list of the remaining
       argc arguments.

EXAMPLE
       This C program can take option b and option f, which requires an	 argu‐
       ment.

	      #include <u.h>
	      #include <libc.h>
	      void
	      main(int argc, char *argv[])
	      {
		      char *f;
		      print("%s", argv[0]);
		      ARGBEGIN {
		      case 'b':
			      print(" -b");
			      break;
		      case 'f':
			      print(" -f(%s)", (f=ARGF())? f: "no arg");
			      break;
		      default:
			      print(" badflag('%c')", ARGC());
		      } ARGEND
		      print(" %d args:", argc);
		      while(*argv)
			      print(" '%s'", *argv++);
		      print("\n");
		      exits(nil);
	      }

       Here  is	 the output from running the command prog -bffile1 -r -f file2
       arg1 arg2

	      prog -b -f(file1) badflag('r') -f(file2) 2 args: 'arg1' 'arg2'

SOURCE
       /sys/include/libc.h

SEE ALSO
       getflags(8)

									ARG(2)
[top]
                             _         _         _ 
                            | |       | |       | |     
                            | |       | |       | |     
                         __ | | __ __ | | __ __ | | __  
                         \ \| |/ / \ \| |/ / \ \| |/ /  
                          \ \ / /   \ \ / /   \ \ / /   
                           \   /     \   /     \   /    
                            \_/       \_/       \_/ 
More information is available in HTML format for server Plan9

List of man pages available for Plan9

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net