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

Contents of /lbbs/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations)
Sun Mar 20 17:37:14 2005 UTC (21 years ago) by sysadm
Branch: MAIN
Changes since 1.11: +74 -76 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 ("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 void
37 arg_error (void)
38 {
39 prints ("Invalid arguments\n");
40 app_help ();
41 }
42
43 int
44 main (int argc, char *argv[])
45 {
46 char log_dir[256], file_log_std[256], file_log_error[256], file_config[256];
47 int i, j;
48 int daemon = 1, std_log_redir = 0, error_log_redir = 0;
49
50 //Parse args
51 for (i = 1; i < argc; i++)
52 {
53 switch (argv[i][0])
54 {
55 case '-':
56 if (argv[i][1] != '-')
57 {
58 for (j = 1; j < strlen (argv[i]); j++)
59 {
60 switch (argv[i][j])
61 {
62 case 'f':
63 daemon = 0;
64 break;
65 case 'h':
66 app_help ();
67 exit (0);
68 case 'v':
69 puts (app_version);
70 exit (0);
71 default:
72 arg_error ();
73 exit (1);
74 }
75 }
76 }
77 else
78 {
79 if (strcmp (argv[i] + 2, "foreground") == 0)
80 {
81 daemon = 0;
82 break;
83 }
84 if (strcmp (argv[i] + 2, "help") == 0)
85 {
86 app_help ();
87 exit (0);
88 }
89 if (strcmp (argv[i] + 2, "version") == 0)
90 {
91 puts (app_version);
92 exit (0);
93 }
94 if (strcmp (argv[i] + 2, "display-log") == 0)
95 {
96 std_log_redir = 1;
97 }
98 if (strcmp (argv[i] + 2, "display-error-log") == 0)
99 {
100 error_log_redir = 1;
101 }
102 }
103 break;
104 }
105 }
106
107 //Initialize daemon
108 if (daemon)
109 init_daemon ();
110
111 //Initialize log
112 strncpy (app_home_dir, argv[0], rindex (argv[0], '/') - argv[0] + 1);
113 strcat (app_home_dir, "../");
114 strcpy (app_temp_dir, "/tmp/lbbs/");
115 mkdir (app_temp_dir, 0700);
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
126 if ((!daemon) && std_log_redir)
127 log_std_redirect (2);
128 if ((!daemon) && error_log_redir)
129 log_err_redirect (3);
130
131 //Load configuration
132 strcpy (file_config, app_home_dir);
133 strcat (file_config, "conf/bbsd.conf");
134 if (load_conf (file_config) < 0)
135 exit (-2);
136
137 //Load menus
138 strcpy (file_config, app_home_dir);
139 strcat (file_config, "conf/menu.conf");
140 if (load_menu (&bbs_menu, file_config) < 0)
141 exit (-3);
142
143 //Initialize socket server
144 net_server (BBS_address, BBS_port);
145
146 return 0;
147 }

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