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

Contents of /lbbs/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations)
Fri Oct 22 17:45:36 2004 UTC (21 years, 4 months ago) by sysadm
Branch: MAIN
Changes since 1.7: +1 -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 <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
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 //Initialize log
113 strncpy(app_home_dir, argv[0], rindex(argv[0],'/')-argv[0]+1);
114 strcat(app_home_dir, "../");
115 strcpy(log_dir, app_home_dir);
116 strcat(log_dir, "log/");
117 strcpy(file_log_std, log_dir);
118 strcpy(file_log_error, log_dir);
119 strcat(file_log_std, "bbsd.log");
120 strcat(file_log_error, "error.log");
121 mkdir(log_dir,0700);
122 if (log_begin(file_log_std,file_log_error)<0)
123 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
130 strcpy(file_config, app_home_dir);
131 strcat(file_config, "conf/bbsd.conf");
132 if (load_conf(file_config)<0)
133 exit(-2);
134
135 //Initialize socket server
136 net_server(BBS_address, BBS_port);
137
138 return 0;
139 }

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