2. The main program
2.1. Main subroutine
<<function_declarations>>=
int p_dot(int argc, char *argv[]);
<<functions>>=
int p_dot(int argc, char *argv[])
{
int len;
if(argc < 2) {
print_help();
return 1;
}
len = strlen(argv[1]);
if(0) {
/* hack to start the chain */
}
<<command_parsing>>
else {
fprintf(stderr,
"Could not find subcommand '%s'\n",
argv[1]);
return 1;
}
return 0;
}
2.2. Print Help
Prints all available commands if there are not enough arguments provided.
<<function_declarations>>=
static void print_help(void);
<<functions>>=
static void print_help(void)
{
fprintf(stderr, "Available Commands\n\n");
<<available_commands>>
}
2.3. Matching
<<function_declarations>>=
static int match(const char *s1,
int sz1,
const char *s2,
int sz2);
<<functions>>=
static int match(const char *s1,
int sz1,
const char *s2,
int sz2)
{
return sz1 == sz2 && !strncmp(s1, s2, sz2);
}
prev | home | next