/branches/win32_port/openslp/slpd/slpd_cmdline.c

# · C · 155 lines · 95 code · 12 blank · 48 comment · 43 complexity · 35677ec0c86187220c28e813eb1c8179 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. #ifdef WIN32
  68. G_SlpdCommandLine.action = -1;
  69. #endif
  70. #if(defined DEBUG)
  71. G_SlpdCommandLine.detach = 0;
  72. #else
  73. G_SlpdCommandLine.detach = 1;
  74. #endif
  75. for(i=1; i<argc; i++)
  76. {
  77. #ifdef WIN32
  78. if(strcmp(argv[i],"-install") == 0)
  79. {
  80. G_SlpdCommandLine.action = SLPD_INSTALL;
  81. }
  82. else if(strcmp(argv[i],"-remove") == 0)
  83. {
  84. G_SlpdCommandLine.action = SLPD_REMOVE;
  85. }
  86. else if(strcmp(argv[i],"-debug") == 0)
  87. {
  88. G_SlpdCommandLine.action = SLPD_DEBUG;
  89. } else
  90. #endif
  91. if(strcmp(argv[i],"-l") == 0)
  92. {
  93. i++;
  94. if(i >= argc) goto USAGE;
  95. strncpy(G_SlpdCommandLine.logfile,argv[i],MAX_PATH);
  96. }
  97. else if(strcmp(argv[i],"-r") == 0)
  98. {
  99. i++;
  100. if(i >= argc) goto USAGE;
  101. strncpy(G_SlpdCommandLine.regfile,argv[i],MAX_PATH);
  102. }
  103. else if(strcmp(argv[i],"-c") == 0)
  104. {
  105. i++;
  106. if(i >= argc) goto USAGE;
  107. strncpy(G_SlpdCommandLine.cfgfile,argv[i],MAX_PATH);
  108. }
  109. else if(strcmp(argv[i],"-p") == 0)
  110. {
  111. i++;
  112. if(i >= argc) goto USAGE;
  113. strncpy(G_SlpdCommandLine.pidfile,argv[i],MAX_PATH);
  114. }
  115. else if(strcmp(argv[i],"-d") == 0)
  116. {
  117. G_SlpdCommandLine.detach = 0;
  118. }
  119. else if((strcmp(argv[i], "-v") == 0)
  120. || (strcmp(argv[i], "-V") == 0)
  121. || (strcmp(argv[i], "--version") == 0)
  122. || (strcmp(argv[i], "-version") == 0))
  123. {
  124. printf("slpd version: %s\n", VERSION);
  125. exit(1);
  126. }
  127. else if((strcmp(argv[i], "-h") == 0)
  128. || (strcmp(argv[i], "-help") == 0)
  129. || (strcmp(argv[i], "--help") == 0))
  130. {
  131. SLPDPrintUsage();
  132. exit(1);
  133. }
  134. else
  135. {
  136. goto USAGE;
  137. }
  138. }
  139. return 0;
  140. USAGE:
  141. SLPDPrintUsage();
  142. return 1;
  143. }