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

Contents of /lbbs/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show 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 /***************************************************************************
2 main.c - description
3 -------------------
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 #include "bbs.h"
19 #include "common.h"
20 #include "io.h"
21 #include "menu.h"
22 #include <string.h>
23
24 void
25 app_help(void)
26 {
27 prints (
28 "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 prints ("Invalid arguments\n");
42 app_help();
43 }
44
45 int
46 main (int argc, char *argv[])
47 {
48 char log_dir[256], file_log_std[256], file_log_error[256], file_config[256];
49 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 //Initialize daemon
110 if (daemon)
111 init_daemon ();
112
113 //Initialize log
114 strncpy(app_home_dir, argv[0], rindex(argv[0],'/')-argv[0]+1);
115 strcat(app_home_dir, "../");
116 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 mkdir(log_dir,0700);
123 if (log_begin(file_log_std,file_log_error)<0)
124 exit(-1);
125 if ((!daemon) && std_log_redir)
126 log_std_redirect(2);
127 if ((!daemon) && error_log_redir)
128 log_err_redirect(3);
129
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
136 //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 //Initialize socket server
143 net_server(BBS_address, BBS_port);
144
145 return 0;
146 }

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