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

# · C · 200 lines · 118 code · 18 blank · 64 comment · 36 complexity · c5c62de7eca16e40cedf17c8e430a1d5 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. /* Please submit patches to http://www.openslp.org */
  13. /* */
  14. /*-------------------------------------------------------------------------*/
  15. /* */
  16. /* Copyright (C) 2000 Caldera Systems, Inc */
  17. /* All rights reserved. */
  18. /* */
  19. /* Redistribution and use in source and binary forms, with or without */
  20. /* modification, are permitted provided that the following conditions are */
  21. /* met: */
  22. /* */
  23. /* Redistributions of source code must retain the above copyright */
  24. /* notice, this list of conditions and the following disclaimer. */
  25. /* */
  26. /* Redistributions in binary form must reproduce the above copyright */
  27. /* notice, this list of conditions and the following disclaimer in */
  28. /* the documentation and/or other materials provided with the */
  29. /* distribution. */
  30. /* */
  31. /* Neither the name of Caldera Systems nor the names of its */
  32. /* contributors may be used to endorse or promote products derived */
  33. /* from this software without specific prior written permission. */
  34. /* */
  35. /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
  36. /* `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
  37. /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
  38. /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CALDERA */
  39. /* SYSTEMS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
  40. /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
  41. /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
  42. /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
  43. /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  44. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
  45. /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  46. /* */
  47. /***************************************************************************/
  48. #include "slpd.h"
  49. #if !defined(ETCDIR)
  50. #define ETCDIR "/etc"
  51. #endif
  52. #if !defined(VARDIR)
  53. #define VARDIR "/var"
  54. #endif
  55. /*=========================================================================*/
  56. SLPDCommandLine G_SlpdCommandLine;
  57. /* Global variable containing command line options */
  58. /*=========================================================================*/
  59. /*=========================================================================*/
  60. void SLPDPrintUsage()
  61. /* Displays available command line options of SLPD */
  62. /*=========================================================================*/
  63. {
  64. #ifdef WIN32
  65. printf("USAGE: slpd -install|-remove|-debug [-d] [-c conf file] [-l log file] [-r reg file] [-v version]\n");
  66. #else
  67. printf("USAGE: slpd [-d] [-c conf file] [-l log file] [-r reg file] [-v version]\n");
  68. #endif
  69. }
  70. /*=========================================================================*/
  71. int SLPDParseCommandLine(int argc,char* argv[])
  72. /* Must be called to initialize the command line */
  73. /* */
  74. /* argc (IN) the argc as passed to main() */
  75. /* */
  76. /* argv (IN) the argv as passed to main() */
  77. /* */
  78. /* Returns - zero on success. non-zero on usage error */
  79. /*=========================================================================*/
  80. {
  81. int i;
  82. /* Set defaults */
  83. memset(&G_SlpdCommandLine,0,sizeof(SLPDCommandLine));
  84. strcpy(G_SlpdCommandLine.cfgfile,ETCDIR "/slp.conf");
  85. strcpy(G_SlpdCommandLine.logfile,VARDIR "/log/slpd.log");
  86. strcpy(G_SlpdCommandLine.regfile,ETCDIR "/slp.reg");
  87. strcpy(G_SlpdCommandLine.pidfile,VARDIR "/run/slpd.pid");
  88. G_SlpdCommandLine.detach = 1;
  89. #ifdef WIN32
  90. G_SlpdCommandLine.action = -1;
  91. #endif
  92. for(i=1; i<argc; i++)
  93. {
  94. #ifdef WIN32
  95. if(strcmp(argv[i],"-install") == 0)
  96. {
  97. G_SlpdCommandLine.action = SLPD_INSTALL;
  98. }
  99. else if(strcmp(argv[i],"-remove") == 0)
  100. {
  101. G_SlpdCommandLine.action = SLPD_REMOVE;
  102. }
  103. else if(strcmp(argv[i],"-debug") == 0)
  104. {
  105. G_SlpdCommandLine.action = SLPD_DEBUG;
  106. }
  107. else
  108. #endif
  109. if(strcmp(argv[i],"-l") == 0)
  110. {
  111. i++;
  112. if(i >= argc) goto USAGE;
  113. strncpy(G_SlpdCommandLine.logfile,argv[i],MAX_PATH-1);
  114. }
  115. else if(strcmp(argv[i],"-r") == 0)
  116. {
  117. i++;
  118. if(i >= argc) goto USAGE;
  119. strncpy(G_SlpdCommandLine.regfile,argv[i],MAX_PATH-1);
  120. }
  121. else if(strcmp(argv[i],"-c") == 0)
  122. {
  123. i++;
  124. if(i >= argc) goto USAGE;
  125. strncpy(G_SlpdCommandLine.cfgfile,argv[i],MAX_PATH-1);
  126. }
  127. else if(strcmp(argv[i],"-p") == 0)
  128. {
  129. i++;
  130. if(i >= argc) goto USAGE;
  131. strncpy(G_SlpdCommandLine.pidfile,argv[i],MAX_PATH-1);
  132. }
  133. else if(strcmp(argv[i],"-d") == 0)
  134. {
  135. G_SlpdCommandLine.detach = 0;
  136. }
  137. else if((strcmp(argv[i], "-v") == 0)
  138. || (strcmp(argv[i], "-V") == 0)
  139. || (strcmp(argv[i], "--version") == 0)
  140. || (strcmp(argv[i], "-version") == 0))
  141. {
  142. #ifdef WIN32
  143. printf("slpd version: %s\n", SLP_VERSION);
  144. #else /* UNIX */
  145. printf("slpd version: %s\n", VERSION);
  146. #endif
  147. /* Show options. */
  148. printf("compile options:\n"
  149. " debugging "
  150. #ifdef DEBUG
  151. "enabled (--enable-debug) "
  152. #else
  153. "disabled"
  154. #endif /* NDEBUG */
  155. "\n"
  156. " predicates "
  157. #ifdef USE_PREDICATES
  158. "enabled "
  159. #else
  160. "disabled (--disable-predicates) "
  161. #endif /* USE_PREDICATES */
  162. "\n"
  163. " slpv1 compatability "
  164. #ifdef ENABLE_SLPv1
  165. "enabled "
  166. #else
  167. "disabled (--enable-slpv1=no)"
  168. #endif /* ENABLE_SLPv1 */
  169. "\n"
  170. );
  171. exit(1);
  172. }
  173. else
  174. {
  175. goto USAGE;
  176. }
  177. }
  178. return 0;
  179. USAGE:
  180. SLPDPrintUsage();
  181. return 1;
  182. }