/[LeafOK_CVS]/lbbs/src/main.c
ViewVC logotype

Diff of /lbbs/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.5 by sysadm, Wed Oct 20 07:46:32 2004 UTC Revision 1.8 by sysadm, Fri Oct 22 17:45:36 2004 UTC
# Line 17  Line 17 
17    
18  #include "bbs.h"  #include "bbs.h"
19  #include "common.h"  #include "common.h"
20    #include "io.h"
21    #include <string.h>
22    
23    void
24    app_help(void)
25    {
26      prints (
27        "Usage: bbsd [-fhv] [...]\n\n"
28        "-f\t--foreground\t\tForce program run in foreground\n"
29        "-h\t--help\t\t\tDisplay this help message\n"
30        "-v\t--version\t\tDisplay version information\n"
31        "\t--display-log\t\tDisplay standard log information\n"
32        "\t--display-error-log\tDisplay error log information\n"
33        "\n    If meet any bug, please report to <leaflet@leafok.com>\n\n"
34      );
35    }
36    
37    void
38    arg_error(void)
39    {
40      prints ("Invalid arguments\n");
41      app_help();
42    }
43    
44  int  int
45  main (int argc, char *argv[])  main (int argc, char *argv[])
46  {  {
47    char log_dir[256], file_log_std[256], file_log_error[256], file_config[256];    char log_dir[256], file_log_std[256], file_log_error[256], file_config[256];
48        int i,j;
49      int daemon = 1, std_log_redir = 0, error_log_redir = 0;
50    
51      //Parse args
52      for (i=1; i<argc; i++)
53      {
54        switch (argv[i][0])
55        {
56          case '-':
57            if (argv[i][1] != '-')
58            {
59            for (j=1; j<strlen(argv[i]); j++)
60            {
61              switch (argv[i][j])
62              {
63                case 'f':
64                  daemon = 0;
65                  break;
66                case 'h':
67                  app_help();
68                  exit(0);
69                case 'v':
70                  puts (app_version);
71                  exit(0);
72                default:
73                  arg_error();
74                  exit(1);
75              }
76            }
77            }
78            else
79            {
80              if (strcmp(argv[i]+2, "foreground") == 0)
81              {
82                  daemon = 0;
83                  break;
84              }
85              if (strcmp(argv[i]+2, "help") == 0)
86              {
87                app_help();
88                exit(0);
89              }
90              if (strcmp(argv[i]+2, "version") == 0)
91              {
92                puts (app_version);
93                exit(0);
94              }
95              if (strcmp(argv[i]+2, "display-log") == 0)
96              {
97                std_log_redir = 1;
98              }
99              if (strcmp(argv[i]+2, "display-error-log") == 0)
100              {
101                error_log_redir = 1;
102              }
103            }
104            break;
105        }
106      }
107                
108    //Initialize daemon    //Initialize daemon
109    init_daemon ();    if (daemon)
110        init_daemon ();
111    
112    //Initialize log    //Initialize log
113    strncpy(app_home_dir, argv[0], rindex(argv[0],'/')-argv[0]+1);    strncpy(app_home_dir, argv[0], rindex(argv[0],'/')-argv[0]+1);
114      strcat(app_home_dir, "../");
115    strcpy(log_dir, app_home_dir);    strcpy(log_dir, app_home_dir);
116    strcat(log_dir, "log/");    strcat(log_dir, "log/");
117    strcpy(file_log_std, log_dir);    strcpy(file_log_std, log_dir);
# Line 37  main (int argc, char *argv[]) Line 121  main (int argc, char *argv[])
121    mkdir(log_dir,0700);    mkdir(log_dir,0700);
122    if (log_begin(file_log_std,file_log_error)<0)    if (log_begin(file_log_std,file_log_error)<0)
123      exit(-1);      exit(-1);
124      if ((!daemon) && std_log_redir)
125        log_std_redirect(2);
126      if ((!daemon) && error_log_redir)
127        log_err_redirect(3);
128    
129    //Load configuration    //Load configuration
130    strcpy(file_config, app_home_dir);    strcpy(file_config, app_home_dir);


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1