/tags/OpenSLP_0-6-2/openslp/slpd/slpd_cmdline.c

# · C · 104 lines · 51 code · 8 blank · 45 comment · 19 complexity · 2351488488aba7938997a3d0f12f4069 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. int SLPDParseCommandLine(int argc,char* argv[])
  40. /* Must be called to initialize the command line */
  41. /* */
  42. /* argc (IN) the argc as passed to main() */
  43. /* */
  44. /* argv (IN) the argv as passed to main() */
  45. /* */
  46. /* Returns - zero on success. non-zero on usage error */
  47. /*=========================================================================*/
  48. {
  49. int i;
  50. /* Set defaults */
  51. memset(&G_SlpdCommandLine,0,sizeof(SLPDCommandLine));
  52. strcpy(G_SlpdCommandLine.cfgfile,"/etc/slp.conf");
  53. strcpy(G_SlpdCommandLine.logfile,"/var/log/slpd.log");
  54. strcpy(G_SlpdCommandLine.regfile,"/etc/slp.reg");
  55. strcpy(G_SlpdCommandLine.pidfile,"/var/run/slpd.pid");
  56. G_SlpdCommandLine.detach = 1;
  57. for(i=1; i<argc; i++)
  58. {
  59. if(strcmp(argv[i],"-l") == 0)
  60. {
  61. i++;
  62. if(i >= argc) goto USAGE;
  63. strncpy(G_SlpdCommandLine.logfile,argv[i],MAX_PATH);
  64. }
  65. else if(strcmp(argv[i],"-r") == 0)
  66. {
  67. i++;
  68. if(i >= argc) goto USAGE;
  69. strncpy(G_SlpdCommandLine.regfile,argv[i],MAX_PATH);
  70. }
  71. else if(strcmp(argv[i],"-c") == 0)
  72. {
  73. i++;
  74. if(i >= argc) goto USAGE;
  75. strncpy(G_SlpdCommandLine.cfgfile,argv[i],MAX_PATH);
  76. }
  77. else if(strcmp(argv[i],"-p") == 0)
  78. {
  79. i++;
  80. if(i >= argc) goto USAGE;
  81. strncpy(G_SlpdCommandLine.pidfile,argv[i],MAX_PATH);
  82. }
  83. else if(strcmp(argv[i],"-d") == 0)
  84. {
  85. G_SlpdCommandLine.detach = 0;
  86. }
  87. else
  88. {
  89. goto USAGE;
  90. }
  91. }
  92. return 0;
  93. USAGE:
  94. printf("USAGE: slpd [-d] [-c conf file] [-l log file] [-r reg file] \n");
  95. return 1;
  96. }