/tags/OpenSLP_0-7-8/openslp/slpd/slpd_cmdline.c

# · C · 176 lines · 112 code · 15 blank · 49 comment · 36 complexity · 117f1b43e6c6cbaa526dc41f96e99ccd MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* Project: OpenSLP - OpenSource implementation of Service Location */
  4. /* Protocol Version 2 */
  5. /* */
  6. /* File: slpd_cmdline.c */
  7. /* */
  8. /* Abstract: Simple command line processor */
  9. /* */
  10. /*-------------------------------------------------------------------------*/
  11. /* */
  12. /* Copyright (c) 1995, 1999 Caldera Systems, Inc. */
  13. /* */
  14. /* This program is free software; you can redistribute it and/or modify it */
  15. /* under the terms of the GNU Lesser General Public License as published */
  16. /* by the Free Software Foundation; either version 2.1 of the License, or */
  17. /* (at your option) any later version. */
  18. /* */
  19. /* This program is distributed in the hope that it will be useful, */
  20. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  21. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  22. /* GNU Lesser General Public License for more details. */
  23. /* */
  24. /* You should have received a copy of the GNU Lesser General Public */
  25. /* License along with this program; see the file COPYING. If not, */
  26. /* please obtain a copy from http://www.gnu.org/copyleft/lesser.html */
  27. /* */
  28. /*-------------------------------------------------------------------------*/
  29. /* */
  30. /* Please submit patches to http://www.openslp.org */
  31. /* */
  32. /***************************************************************************/
  33. #include "slpd.h"
  34. /*=========================================================================*/
  35. SLPDCommandLine G_SlpdCommandLine;
  36. /* Global variable containing command line options */
  37. /*=========================================================================*/
  38. /*=========================================================================*/
  39. void SLPDPrintUsage()
  40. /* Displays available command line options of SLPD */
  41. /*=========================================================================*/
  42. {
  43. #ifdef WIN32
  44. printf("USAGE: slpd -install|-remove|-debug [-d] [-c conf file] [-l log file] [-r reg file] [-v version]\n");
  45. #else
  46. printf("USAGE: slpd [-d] [-c conf file] [-l log file] [-r reg file] [-v version]\n");
  47. #endif
  48. }
  49. /*=========================================================================*/
  50. int SLPDParseCommandLine(int argc,char* argv[])
  51. /* Must be called to initialize the command line */
  52. /* */
  53. /* argc (IN) the argc as passed to main() */
  54. /* */
  55. /* argv (IN) the argv as passed to main() */
  56. /* */
  57. /* Returns - zero on success. non-zero on usage error */
  58. /*=========================================================================*/
  59. {
  60. int i;
  61. /* Set defaults */
  62. memset(&G_SlpdCommandLine,0,sizeof(SLPDCommandLine));
  63. strcpy(G_SlpdCommandLine.cfgfile,"/etc/slp.conf");
  64. strcpy(G_SlpdCommandLine.logfile,"/var/log/slpd.log");
  65. strcpy(G_SlpdCommandLine.regfile,"/etc/slp.reg");
  66. strcpy(G_SlpdCommandLine.pidfile,"/var/run/slpd.pid");
  67. G_SlpdCommandLine.detach = 1;
  68. #ifdef WIN32
  69. G_SlpdCommandLine.action = -1;
  70. #endif
  71. for (i=1; i<argc; i++)
  72. {
  73. #ifdef WIN32
  74. if (strcmp(argv[i],"-install") == 0)
  75. {
  76. G_SlpdCommandLine.action = SLPD_INSTALL;
  77. }
  78. else if (strcmp(argv[i],"-remove") == 0)
  79. {
  80. G_SlpdCommandLine.action = SLPD_REMOVE;
  81. }
  82. else if (strcmp(argv[i],"-debug") == 0)
  83. {
  84. G_SlpdCommandLine.action = SLPD_DEBUG;
  85. }
  86. else
  87. #endif
  88. if (strcmp(argv[i],"-l") == 0)
  89. {
  90. i++;
  91. if (i >= argc) goto USAGE;
  92. strncpy(G_SlpdCommandLine.logfile,argv[i],MAX_PATH);
  93. }
  94. else if (strcmp(argv[i],"-r") == 0)
  95. {
  96. i++;
  97. if (i >= argc) goto USAGE;
  98. strncpy(G_SlpdCommandLine.regfile,argv[i],MAX_PATH);
  99. }
  100. else if (strcmp(argv[i],"-c") == 0)
  101. {
  102. i++;
  103. if (i >= argc) goto USAGE;
  104. strncpy(G_SlpdCommandLine.cfgfile,argv[i],MAX_PATH);
  105. }
  106. else if (strcmp(argv[i],"-p") == 0)
  107. {
  108. i++;
  109. if (i >= argc) goto USAGE;
  110. strncpy(G_SlpdCommandLine.pidfile,argv[i],MAX_PATH);
  111. }
  112. else if (strcmp(argv[i],"-d") == 0)
  113. {
  114. G_SlpdCommandLine.detach = 0;
  115. }
  116. else if ((strcmp(argv[i], "-v") == 0)
  117. || (strcmp(argv[i], "-V") == 0)
  118. || (strcmp(argv[i], "--version") == 0)
  119. || (strcmp(argv[i], "-version") == 0))
  120. {
  121. #ifdef WIN32
  122. printf("slpd version: %s\n", SLP_VERSION);
  123. #else /* UNIX */
  124. printf("slpd version: %s\n", VERSION);
  125. #endif
  126. /* Show options. */
  127. printf("compile options:\n"
  128. " debugging "
  129. #ifdef DEBUG
  130. "enabled (--enable-debug) "
  131. #else
  132. "disabled"
  133. #endif /* NDEBUG */
  134. "\n"
  135. " predicates "
  136. #ifdef USE_PREDICATES
  137. "enabled "
  138. #else
  139. "disabled (--disable-predicates) "
  140. #endif /* USE_PREDICATES */
  141. "\n"
  142. " slpv1 compatability "
  143. #ifdef ENABLE_SLPv1
  144. "enabled "
  145. #else
  146. "disabled (--enable-slpv1=no)"
  147. #endif /* ENABLE_SLPv1 */
  148. "\n"
  149. );
  150. exit(1);
  151. }
  152. else
  153. {
  154. goto USAGE;
  155. }
  156. }
  157. return 0;
  158. USAGE:
  159. SLPDPrintUsage();
  160. return 1;
  161. }