Added comments for functions (@details, @param & @return)
This commit is contained in:
parent
97e6937a84
commit
d7f113584b
44
websh.c
44
websh.c
@ -59,17 +59,32 @@ static char *lines[MAX_LINES] = {NULL};
|
||||
*/
|
||||
volatile sig_atomic_t quit = 0;
|
||||
|
||||
/**
|
||||
* @details Signal handler.
|
||||
* @param signal The number of the received signal.
|
||||
* @return This function has no return value.
|
||||
*/
|
||||
static void handle_signal(int signal)
|
||||
{
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @details Prints the synopsis.
|
||||
* @param void This function takes no parameters.
|
||||
* @return Exit code of the program. Always non-zero.
|
||||
*/
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: websh [-e] [-h] [-s WORD:TAG]\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @details Parses the supplied -s commandline argument (splits it into WORD and TAG).
|
||||
* @param sArg The supplied string after the -s flag.
|
||||
* @return This function has no return value.
|
||||
*/
|
||||
void parsesArg(char *sArg)
|
||||
{
|
||||
char *token;
|
||||
@ -88,6 +103,12 @@ void parsesArg(char *sArg)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @details Parses the commandline arguments and sets the global variables.
|
||||
* @param argc The number of commandline arguments.
|
||||
* @param argv The array of commandline arguments.
|
||||
* @return This function has no return value
|
||||
*/
|
||||
void parse(int argc, char *argv[])
|
||||
{
|
||||
int optInd = 0;
|
||||
@ -129,6 +150,13 @@ void parse(int argc, char *argv[])
|
||||
pname = argv[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @details This function gets called by the second child which gets stdout from
|
||||
* child1 through a pipe and writes the output to stdout.
|
||||
* @param fd The file descriptor for the pipe.
|
||||
* @param line The linux command supplied via stdin.
|
||||
* @return This function has no return value.
|
||||
*/
|
||||
void child2(int fd[], char *line)
|
||||
{
|
||||
/* CHILD TWO */
|
||||
@ -168,6 +196,14 @@ void child2(int fd[], char *line)
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @details This function gets called by the first child. It executes a bash shell
|
||||
* which in turn calls the specified linux command. Stdout is redirected
|
||||
* to the write end of the pipe.
|
||||
* @param fd The file descriptor of the pipe.
|
||||
* @param line The linux command specified via stdin in the calling process.
|
||||
* @return This function has no return value.
|
||||
*/
|
||||
void child1(int fd[], char *line)
|
||||
{
|
||||
/* CHILD ONE */
|
||||
@ -180,6 +216,14 @@ void child1(int fd[], char *line)
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point of the program.
|
||||
* @details Calls the parsing of commandline arguments, sets the signal handler
|
||||
* and forks the process which execute the functions child1 and child2.
|
||||
* @param argc The number of supplied commandline arguments.
|
||||
* @param argv The array of supplied commandline arguments.
|
||||
* @return 0 on success, non-zero on failure.
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
parse(argc, argv);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user