Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <foo.h>
- # include <stdio.h>
- # include <stdlib.h>
- void foo_usage (int se)
- {
- FILE *channel;
- if (se == 0){
- channel = stdout;
- } else {
- channel = stderr;
- }
- fprintf (channel, "\n%s usage:\n", PACKAGE);
- fprintf (channel, "\n%s -h|-v|-s <server> -q <queue> [-u user -p password] <working dir>\n", PACKAGE);
- fprintf (channel, "\t-h\t\tPrint this help screen\n");
- fprintf (channel, "\t-s <server>\tServer name or IP of the Tibco (mandatory)\n");
- fprintf (channel, "\t-q <queue>\tName of the queue from which to consume messages (mandatory)\n");
- fprintf (channel, "\t-d <directory>\tName of the base directory to which to publish the files (mandatory)\n");
- fprintf (channel, "\t-u <user>\tUsername for the tibco connection\n");
- fprintf (channel, "\t-p <password>\tPassword for the tibco connection\n");
- fprintf (channel, "\t-v\t\tPrint version.\n\n"); /* this is the last line. */
- if (se == 0){
- exit (EXIT_SUCCESS);
- } else {
- exit (EXIT_FAILURE);
- }
- }
- void foo_version (void)
- {
- fprintf (stdout, "\n%s, version %s\n", PACKAGE, VERSION);
- fprintf (stdout, "(c)opyright %s, %s\n", AUTHOR, DATE);
- fprintf (stdout, "For more inmsgion visit: %s\n\n", URL);
- exit (EXIT_SUCCESS);
- }
- void foo_parse_arguments(int argc,
- char *const argv[],
- char *foo_server, char *foo_queue, char *foo_user, char *foo_password, char *foo_directory)
- {
- int opt;
- extern char *optarg;
- extern int optind, optopt, opterr;
- if(argc == 1) {
- fprintf(stderr, "This program needs arguments....\n\n");
- foo_usage(1);
- }
- /** check for command line arguments
- ** execute what's needed help(), version(),
- **/
- while((opt = getopt(argc, argv, "hvs:q:u:p:d:")) != -1) {
- switch(opt) {
- case 'h':
- foo_usage(0);
- break;
- case 'v':
- foo_version();
- break;
- case 's':
- if ( !optarg) {
- fprintf (stderr, "-%c requires an argument!\n", opt);
- exit (EXIT_FAILURE);
- } else {
- foo_server = optarg;
- }
- break;
- case 'q':
- if ( !optarg) {
- fprintf (stderr, "-%c requires an argument!\n", opt);
- exit (EXIT_FAILURE);
- } else {
- foo_queue = optarg;
- }
- break;
- case 'u':
- if ( !optarg) {
- fprintf (stderr, "-%c requires an argument!\n", opt);
- exit (EXIT_FAILURE);
- } else {
- foo_user = optarg;
- }
- break;
- case 'p':
- if ( !optarg) {
- fprintf (stderr, "-%c requires an argument!\n", opt);
- exit (EXIT_FAILURE);
- } else {
- foo_password = optarg;
- }
- break;
- case 'd':
- if ( !optarg) {
- fprintf (stderr, "-%c requires an argument!\n", opt);
- exit (EXIT_FAILURE);
- } else {
- foo_directory = optarg;
- }
- break;
- case ':':
- fprintf(stderr, "%s: Error - Option `%c' needs a value\n\n", PACKAGE, optopt);
- foo_usage(1);
- break;
- case '?':
- default:
- fprintf(stderr, "%s: Error - No such option: `%c'\n\n", PACKAGE, optopt);
- foo_usage(1);
- break;
- }
- }
- if ( !foo_server || !foo_queue || !foo_directory) {
- fprintf (stderr, "The options -s <server>, -q <queue>, and -d <directory> are all mandatory.\n");
- exit (EXIT_FAILURE);
- }
- if ( optind < argc ) {
- fprintf (stderr, "Unsupported additional parameters\n");
- exit (EXIT_FAILURE);
- }
- }
Add Comment
Please, Sign In to add comment