07.06.2013 Views

Design and Implementation of a Documentation Tool for ... - MADOC

Design and Implementation of a Documentation Tool for ... - MADOC

Design and Implementation of a Documentation Tool for ... - MADOC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

If <strong>for</strong>script was called using a path name (e.g. /usr/bin/<strong>for</strong>script),<br />

everything up to the final slash needs to be cut <strong>of</strong>f. This is done by moving the<br />

pointer to the character immediately following the final slash.<br />

25a 〈set my name 24c〉+≡ (7b) ⊳ 24c<br />

{ char *lastslash;<br />

if ((lastslash = strrchr(MYNAME, ’/’)) != NULL)<br />

MYNAME = lastslash + 1;<br />

}<br />

Uses MYNAME 24a.<br />

A.8.2 Processing Comm<strong>and</strong> Line Arguments<br />

Since <strong>for</strong>scripts invocation tries to mimic scripts as far as possible, comm<strong>and</strong><br />

line argument h<strong>and</strong>ling is designed to closely resemble scripts behavior.<br />

There<strong>for</strong>e, like in script, the comm<strong>and</strong> line switches --version <strong>and</strong> -V are<br />

treated separately. If there is exactly one comm<strong>and</strong> line argument <strong>and</strong> it is one<br />

<strong>of</strong> these, <strong>for</strong>script will print its version <strong>and</strong> terminate.<br />

25b 〈process comm<strong>and</strong> line options 25b〉≡ (7b) 26a ⊲<br />

if ((argc == 2) &&<br />

(!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {<br />

printf("%s %s\n", MYNAME, MYVERSION);<br />

return 0;<br />

}<br />

Uses MYNAME 24a <strong>and</strong> MYVERSION 15a.<br />

The other options are parsed using the normal getopt() method, which<br />

requires unistd.h.<br />

25c 〈includes 8b〉+≡ (15b) ⊳ 23c 27a ⊲<br />

#include <br />

getopt() returns the next option character each time it is called, <strong>and</strong> −1 if<br />

there are none left. The option characters are h<strong>and</strong>led in a switch statement.<br />

As in script, flags that turn on some behavior cause a respective global int<br />

variable to be increased by one. These flags are:<br />

25d 〈globals 8d〉+≡ (15b) ⊳ 24a 25e ⊲<br />

int aflg = 0, fflg = 0, qflg = 0;<br />

Defines:<br />

aflg, used in chunks 26, 27, <strong>and</strong> 34c.<br />

The value <strong>of</strong> the -c parameter is stored in a global string pointer:<br />

25e 〈globals 8d〉+≡ (15b) ⊳ 25d 26b ⊲<br />

char *cflg = NULL;<br />

Defines:<br />

cflg, used in chunks 26a <strong>and</strong> 32d.<br />

25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!