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

Annotation of /lbbs/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations)
Thu Mar 17 10:48:46 2005 UTC (21 years ago) by sysadm
Branch: MAIN
Changes since 1.8: +7 -0 lines
Content type: text/x-csrc
*** empty log message ***

1 sysadm 1.1 /***************************************************************************
2 sysadm 1.3 main.c - description
3 sysadm 1.1 -------------------
4     begin : Mon Oct 11 2004
5     copyright : (C) 2004 by Leaflet
6     email : leaflet@leafok.com
7     ***************************************************************************/
8    
9     /***************************************************************************
10     * *
11     * This program is free software; you can redistribute it and/or modify *
12     * it under the terms of the GNU General Public License as published by *
13     * the Free Software Foundation; either version 2 of the License, or *
14     * (at your option) any later version. *
15     * *
16     ***************************************************************************/
17    
18 sysadm 1.4 #include "bbs.h"
19 sysadm 1.1 #include "common.h"
20 sysadm 1.7 #include "io.h"
21 sysadm 1.9 #include "menu.h"
22 sysadm 1.7 #include <string.h>
23 sysadm 1.1
24 sysadm 1.6 void
25     app_help(void)
26     {
27 sysadm 1.7 prints (
28 sysadm 1.6 "Usage: bbsd [-fhv] [...]\n\n"
29     "-f\t--foreground\t\tForce program run in foreground\n"
30     "-h\t--help\t\t\tDisplay this help message\n"
31     "-v\t--version\t\tDisplay version information\n"
32     "\t--display-log\t\tDisplay standard log information\n"
33     "\t--display-error-log\tDisplay error log information\n"
34     "\n If meet any bug, please report to <leaflet@leafok.com>\n\n"
35     );
36     }
37    
38     void
39     arg_error(void)
40     {
41 sysadm 1.7 prints ("Invalid arguments\n");
42 sysadm 1.6 app_help();
43     }
44    
45 sysadm 1.1 int
46     main (int argc, char *argv[])
47     {
48 sysadm 1.4 char log_dir[256], file_log_std[256], file_log_error[256], file_config[256];
49 sysadm 1.6 int i,j;
50     int daemon = 1, std_log_redir = 0, error_log_redir = 0;
51    
52     //Parse args
53     for (i=1; i<argc; i++)
54     {
55     switch (argv[i][0])
56     {
57     case '-':
58     if (argv[i][1] != '-')
59     {
60     for (j=1; j<strlen(argv[i]); j++)
61     {
62     switch (argv[i][j])
63     {
64     case 'f':
65     daemon = 0;
66     break;
67     case 'h':
68     app_help();
69     exit(0);
70     case 'v':
71     puts (app_version);
72     exit(0);
73     default:
74     arg_error();
75     exit(1);
76     }
77     }
78     }
79     else
80     {
81     if (strcmp(argv[i]+2, "foreground") == 0)
82     {
83     daemon = 0;
84     break;
85     }
86     if (strcmp(argv[i]+2, "help") == 0)
87     {
88     app_help();
89     exit(0);
90     }
91     if (strcmp(argv[i]+2, "version") == 0)
92     {
93     puts (app_version);
94     exit(0);
95     }
96     if (strcmp(argv[i]+2, "display-log") == 0)
97     {
98     std_log_redir = 1;
99     }
100     if (strcmp(argv[i]+2, "display-error-log") == 0)
101     {
102     error_log_redir = 1;
103     }
104     }
105     break;
106     }
107     }
108    
109 sysadm 1.3 //Initialize daemon
110 sysadm 1.6 if (daemon)
111     init_daemon ();
112 sysadm 1.3
113     //Initialize log
114 sysadm 1.4 strncpy(app_home_dir, argv[0], rindex(argv[0],'/')-argv[0]+1);
115 sysadm 1.8 strcat(app_home_dir, "../");
116 sysadm 1.4 strcpy(log_dir, app_home_dir);
117     strcat(log_dir, "log/");
118     strcpy(file_log_std, log_dir);
119     strcpy(file_log_error, log_dir);
120     strcat(file_log_std, "bbsd.log");
121     strcat(file_log_error, "error.log");
122 sysadm 1.3 mkdir(log_dir,0700);
123 sysadm 1.4 if (log_begin(file_log_std,file_log_error)<0)
124     exit(-1);
125 sysadm 1.6 if ((!daemon) && std_log_redir)
126     log_std_redirect(2);
127     if ((!daemon) && error_log_redir)
128     log_err_redirect(3);
129 sysadm 1.4
130     //Load configuration
131     strcpy(file_config, app_home_dir);
132     strcat(file_config, "conf/bbsd.conf");
133     if (load_conf(file_config)<0)
134     exit(-2);
135 sysadm 1.3
136 sysadm 1.9 //Load menus
137     strcpy(file_config, app_home_dir);
138     strcat(file_config, "conf/main_menu.conf");
139     if (load_menu(&bbs_main_menu, file_config)<0)
140     exit(-3);
141    
142 sysadm 1.3 //Initialize socket server
143 sysadm 1.4 net_server(BBS_address, BBS_port);
144 sysadm 1.3
145 sysadm 1.1 return 0;
146     }

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