Guest User

Untitled

a guest
Mar 10th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. # include <foo.h>
  2. # include <stdio.h>
  3. # include <stdlib.h>
  4.  
  5. void foo_usage (int se)
  6. {
  7. FILE *channel;
  8. if (se == 0){
  9. channel = stdout;
  10. } else {
  11. channel = stderr;
  12. }
  13.  
  14. fprintf (channel, "\n%s usage:\n", PACKAGE);
  15. fprintf (channel, "\n%s -h|-v|-s <server> -q <queue> [-u user -p password] <working dir>\n", PACKAGE);
  16. fprintf (channel, "\t-h\t\tPrint this help screen\n");
  17. fprintf (channel, "\t-s <server>\tServer name or IP of the Tibco (mandatory)\n");
  18. fprintf (channel, "\t-q <queue>\tName of the queue from which to consume messages (mandatory)\n");
  19. fprintf (channel, "\t-d <directory>\tName of the base directory to which to publish the files (mandatory)\n");
  20. fprintf (channel, "\t-u <user>\tUsername for the tibco connection\n");
  21. fprintf (channel, "\t-p <password>\tPassword for the tibco connection\n");
  22. fprintf (channel, "\t-v\t\tPrint version.\n\n"); /* this is the last line. */
  23. if (se == 0){
  24. exit (EXIT_SUCCESS);
  25. } else {
  26. exit (EXIT_FAILURE);
  27. }
  28. }
  29.  
  30. void foo_version (void)
  31. {
  32. fprintf (stdout, "\n%s, version %s\n", PACKAGE, VERSION);
  33. fprintf (stdout, "(c)opyright %s, %s\n", AUTHOR, DATE);
  34. fprintf (stdout, "For more inmsgion visit: %s\n\n", URL);
  35. exit (EXIT_SUCCESS);
  36. }
  37.  
  38. void foo_parse_arguments(int argc,
  39. char *const argv[],
  40. char *foo_server, char *foo_queue, char *foo_user, char *foo_password, char *foo_directory)
  41. {
  42. int opt;
  43. extern char *optarg;
  44. extern int optind, optopt, opterr;
  45. if(argc == 1) {
  46. fprintf(stderr, "This program needs arguments....\n\n");
  47. foo_usage(1);
  48. }
  49. /** check for command line arguments
  50. ** execute what's needed help(), version(),
  51. **/
  52. while((opt = getopt(argc, argv, "hvs:q:u:p:d:")) != -1) {
  53. switch(opt) {
  54.  
  55. case 'h':
  56. foo_usage(0);
  57. break;
  58.  
  59. case 'v':
  60. foo_version();
  61. break;
  62.  
  63. case 's':
  64. if ( !optarg) {
  65. fprintf (stderr, "-%c requires an argument!\n", opt);
  66. exit (EXIT_FAILURE);
  67. } else {
  68. foo_server = optarg;
  69. }
  70. break;
  71.  
  72. case 'q':
  73. if ( !optarg) {
  74. fprintf (stderr, "-%c requires an argument!\n", opt);
  75. exit (EXIT_FAILURE);
  76. } else {
  77. foo_queue = optarg;
  78. }
  79. break;
  80.  
  81. case 'u':
  82. if ( !optarg) {
  83. fprintf (stderr, "-%c requires an argument!\n", opt);
  84. exit (EXIT_FAILURE);
  85. } else {
  86. foo_user = optarg;
  87. }
  88. break;
  89.  
  90. case 'p':
  91. if ( !optarg) {
  92. fprintf (stderr, "-%c requires an argument!\n", opt);
  93. exit (EXIT_FAILURE);
  94. } else {
  95. foo_password = optarg;
  96. }
  97. break;
  98.  
  99. case 'd':
  100. if ( !optarg) {
  101. fprintf (stderr, "-%c requires an argument!\n", opt);
  102. exit (EXIT_FAILURE);
  103. } else {
  104. foo_directory = optarg;
  105. }
  106. break;
  107.  
  108. case ':':
  109. fprintf(stderr, "%s: Error - Option `%c' needs a value\n\n", PACKAGE, optopt);
  110. foo_usage(1);
  111. break;
  112.  
  113. case '?':
  114. default:
  115. fprintf(stderr, "%s: Error - No such option: `%c'\n\n", PACKAGE, optopt);
  116. foo_usage(1);
  117. break;
  118. }
  119. }
  120. if ( !foo_server || !foo_queue || !foo_directory) {
  121. fprintf (stderr, "The options -s <server>, -q <queue>, and -d <directory> are all mandatory.\n");
  122. exit (EXIT_FAILURE);
  123. }
  124. if ( optind < argc ) {
  125. fprintf (stderr, "Unsupported additional parameters\n");
  126. exit (EXIT_FAILURE);
  127. }
  128. }
Add Comment
Please, Sign In to add comment