#include <stdlib.h>
#include <stdio.h>
void error_handle(int retval)
{
if (retval)
{
fprintf(stderr, "Error: exiting\n");
exit(1);
}
return;
}
int spew_usage(char* argv_0)
{
fprintf(stderr, "Usage: %s [MESSAGE]\n", argv_0);
fprintf(stderr, "Outputs MESSAGE to all terminals owned by caller\n");
fprintf(stderr, "With no MESSAGE \"Hello World!\" is output\n");
}
int input_length(int argc, char **argv)
{
int counter = 1;
int string_length = 0;
if (argc == 1)
{
return(strlen("Hello World!\n"));
}
while (counter < argc)
{
string_length += (strlen(argv[counter]));
counter++;
}
string_length += argc; /*to account for spaces*/
return(string_length);
}
int parser(int argc, char **argv, char *message)
{
int retval = 0;
int counter = 2;
if (argc == 1)
{
strcpy(message, "Hello World!\n");
return(retval);
}
if (!(strcmp(argv[1], "--help")))
{
spew_usage(argv[0]);
return(retval);
}
strcpy(message, argv[1]);
strcat(message, " ");
while (counter < argc)
{
strcat(message, argv[counter]);
strcat(message, " ");
counter++;
}
return(retval);
}
|