1
edit
Changes
→BTP600
BTP600 course material goes here. I wouldn't mind doing the Wikipedia Design Pattern stub.
==Code Reading Exercise==
#Which file(s) did you have to examine?
First I looked at loadargc, since argc reminds me of the C/C++ standard command line variables that you use in main. However, that turned out to be a load balancing program. Next I looked at Main.h, since main seems like a good start, and headers tend to define stuff. But there wasn’t anything useful there. So I opened Main.c, and voila! Code that has to do with command line switches.
#What are your first reactions to these files when you examine them?
I don’t think I can put them down, in accordance to Seneca’s Acceptable Use Policy. But the sheer amount of code and underscores and structs were a bit overwhelming.
#How is the code for working with command-line switches organized at the method, class and project levels? (e.g. is is all in one class? broken across multiple classes? spread across many methods? etc)
There are a couple methods defined right near the beginning:
<code>
static void decode_switches PARAMS ((int argc, char **argv, int env));
static void decode_env_switches PARAMS ((char *envar, unsigned int len));
</code>
Almost immediately afterwards, there's the structure for an acceptable command line switch
<code>
/* The structure that describes an accepted command switch. */
struct command_switch
{
int c; /* The switch character. */
enum /* Type of the value. */
{
flag, /* Turn int flag on. */
flag_off, /* Turn int flag off. */
string, /* One string per switch. */
positive_int, /* A positive integer. */
floating, /* A floating-point number (double). */
ignore /* Ignored. */
} type;
char *value_ptr; /* Pointer to the value-holding variable. */
unsigned int env:1; /* Can come from MAKEFLAGS. */
unsigned int toenv:1; /* Should be put in MAKEFLAGS. */
unsigned int no_makefile:1; /* Don't propagate when remaking makefiles. */
char *noarg_value; /* Pointer to value used if no argument is given. */
char *default_value;/* Pointer to default value. */
char *long_name; /* Long option name. */
};
</code>
Main.c then goes on to define a usage output, that is used to define, in English, how to use all the different flags. Presumably, this is used when the /h switch is used
<code>
/* The usage output. We write it this way to make life easier for the
translators, especially those trying to translate to right-to-left
languages like Hebrew. */
static const char *const usage[] =
...
N_("\
-h, --help Print this message and exit.\n"),
...
</code>
Afterwards, there is a table of the command switches, along with a bunch of flags and numbers I don't understand.
<code>
/* The table of command switches. */
static const struct command_switch switches[] =
{ 'b', ignore, 0, 0, 0, 0, 0, 0, 0 },
{ 'B', flag, (char *) &always_make_flag, 1, 1, 0, 0, 0, "always-make" },
...
</code>
It also defines "long names" for short switches, like when you use --help rather than /h
<code>
/* Secondary long names for options. */
static struct option long_option_aliases[] =
{
{ "quiet", no_argument, 0, 's' },
{ "stop", no_argument, 0, 'S' },
{ "new-file", required_argument, 0, 'W' },
{ "assume-new", required_argument, 0, 'W' },
{ "assume-old", required_argument, 0, 'o' },
{ "max-load", optional_argument, 0, 'l' },
{ "dry-run", no_argument, 0, 'n' },
{ "recon", no_argument, 0, 'n' },
{ "makefile", required_argument, 0, 'f' },
};
</code>
Main.h also defines a structure called "file", which has error handling in it for empty filenames:
<code>
static struct file *
enter_command_line_file (name)
char *name;
{
if (name[0] == '\0')
fatal (NILF, _("empty string invalid as file name"));
</code>
=Other Wiki Courses=
[[lkates:dps909]]