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

Contents of /lbbs/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations)
Sat Apr 16 04:49:11 2005 UTC (20 years, 11 months ago) by sysadm
Branch: MAIN
Changes since 1.12: +7 -3 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 #include <unistd.h>
24
25 void
26 app_help (void)
27 {
28 prints ("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 void
38 arg_error (void)
39 {
40 prints ("Invalid arguments\n");
41 app_help ();
42 }
43
44 int
45 main (int argc, char *argv[])
46 {
47 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
109 if (daemon)
110 init_daemon ();
111
112 //Change current dir
113 strncpy (app_home_dir, argv[0], rindex (argv[0], '/') - argv[0] + 1);
114 strcat (app_home_dir, "../");
115 chdir (app_home_dir);
116
117 //Initialize log
118 strcpy (app_temp_dir, "/tmp/lbbs/");
119 mkdir (app_temp_dir, 0750);
120 strcpy (log_dir, app_home_dir);
121 strcat (log_dir, "log/");
122 strcpy (file_log_std, log_dir);
123 strcpy (file_log_error, log_dir);
124 strcat (file_log_std, "bbsd.log");
125 strcat (file_log_error, "error.log");
126 mkdir (log_dir, 0750);
127 if (log_begin (file_log_std, file_log_error) < 0)
128 exit (-1);
129
130 if ((!daemon) && std_log_redir)
131 log_std_redirect (2);
132 if ((!daemon) && error_log_redir)
133 log_err_redirect (3);
134
135 //Load configuration
136 strcpy (file_config, app_home_dir);
137 strcat (file_config, "conf/bbsd.conf");
138 if (load_conf (file_config) < 0)
139 exit (-2);
140
141 //Load menus
142 strcpy (file_config, app_home_dir);
143 strcat (file_config, "conf/menu.conf");
144 if (load_menu (&bbs_menu, file_config) < 0)
145 exit (-3);
146
147 //Initialize socket server
148 net_server (BBS_address, BBS_port);
149
150 return 0;
151 }

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