.


:




:

































 

 

 

 


POSIX

POSIX , . , , : Linux UNIX . , , (getopt () getopt_long() ), , . , :

 

  1. .
  2. .
  3. - . . , POSIX, -w .
  4. '-'.
  5. , , '-'. (, 'foo -a -b -' 'foo -abc' .)
  6. , (, 'fgrep -f patf ile'). , : 'fgrep -fpatfile'. getopt(3) ngetopt_long(3) '-fpatfile' '-f patfile', '-f -p -a -t....

7. . , , , , . GNU getopt(3) , .

8. , , , .

, , myprog -u. :

myprog -u "arnold, joe, jane" /* */

myprog -u "arnold joe jane" /* */

(.. ), .

9. , . getopt(3) UNIX . GNU getopt (3) , .

10. '--' . , .

11. , , . , , , ( ) . , , , . , 'myprog -u arnold -u jane' to , 'myprog -u "arnold, jane"'. ( ; getopt() .)

12. , . .

13. , , - , , .

. ; .

 

.

GNU --help, --verbose . . , '--', POSIX. ( . ), GNU. (, --help , -h help, -i information . .) GNU , getopc_long(3):

1. , POSIX, ( ) .

2. GNU , .

3. , . , --verbose --verbatim, --verbo --verba.

4. , =. , --sourcefile=/some/file --sourcefile /some/file.

5. ; getopc_long() , , . ( .)

6. . , , . . , - ' foo -xRUSSIANS -z' - 'RUSSIANS'. 'f - -z' - .

7. . ( X Window.)

GNU Coding Standards , GNU. , , , , .

 

argc argv. ! , .. , argc argv . argc , (arg ument c ount), . argv (arg ument v ariables) , . . main(), argc:

int main(int argc, char *argv[ ]) int main(int argc, char **argv)

 

, : argc . , , . 2 :

 

char ** char *

 
 


cat \0

file1 \0

file2 \0

 

 

. 2 argc

 

, argv[0] . argv[1], argv[2] .. . argv NULL.

argc , ; , 'argv [argc] == NULL' . - , UNIX, , , , argc, 'argv[i] == 0', '*argv!= NULL' .. .

 

 

echo V7 ( UNIX System V)

, V7 echo, , . -n, . ( .)

 

#include<stdio.h>

int main (int argc, char **argv)

{ register int i, nflg;

nflg =0;

if(argc > 1 && argv[l][0] == '-' && argv[l][l] == n)

{ nflg++;

argc--; // argc argv .

argv++; //

}

for(i=l; i<argc; i++)

{ fputs(argv[i], stdout);

if (i < argc-1)

putchar(' ');

}

if (nflg == 0)

putchar('\n');

exit(0);

}

 

 

: getopt () getopt_long ()

1980- UNIX System III AT&T , UNIX . , . UNIX getopt(3), , , . GNU getopt_long(3) getopt(3) , .

getopt (3) . GNU getopt (3) . GNU getopt_long(3) getopt_long_only(3) .

 

. . 4. .



<== | ==>
 | , (.. )
:


: 2015-11-23; !; : 686 |


:

:

, , .
==> ...

1788 - | 1467 -


© 2015-2024 lektsii.org - -

: 0.015 .