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

Diff of /lbbs/src/common.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.7 by sysadm, Sat May 7 12:08:28 2005 UTC Revision 1.12 by sysadm, Fri May 2 03:32:19 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            common.c  -  description                                                    common.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Mon Oct 18 2004          begin                : Mon Oct 18 2004
5      copyright            : (C) 2004 by Leaflet          copyright            : (C) 2004 by Leaflet
6      email                : leaflet@leafok.com          email                : leaflet@leafok.com
7   ***************************************************************************/   ***************************************************************************/
8    
9  /***************************************************************************  /***************************************************************************
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18    #include "common.h"
19    #include "log.h"
20  #include "menu.h"  #include "menu.h"
21    #include <string.h>
22  #include <time.h>  #include <time.h>
23  #include <sys/types.h>  #include <sys/types.h>
24  #include <sys/wait.h>  #include <sys/wait.h>
25    
26  //Version information  // Version information
27  char app_version[256] = "LBBS-devel version 1.0";  char app_version[256] = "LBBS-devel version 1.0";
28    
29  //Global declaration for enviroment  // Global declaration for enviroment
30  char app_home_dir[256];  char app_home_dir[256];
31  char app_temp_dir[256];  char app_temp_dir[256];
32    
33  //Global declaration for sockets  // Global declaration for sockets
34  int socket_server;  int socket_server;
35  int socket_client;  int socket_client;
36  char hostaddr_server[50];  char hostaddr_server[50];
# Line 35  char hostaddr_client[50]; Line 38  char hostaddr_client[50];
38  int port_server;  int port_server;
39  int port_client;  int port_client;
40    
41  //Global declaration for database  // Global declaration for system
 char DB_host[256];  
 char DB_username[50];  
 char DB_password[50];  
 char DB_database[50];  
   
 //Global declaration for system  
42  int SYS_exit;  int SYS_exit;
43  int SYS_child_process_count;  int SYS_child_process_count;
44    
45  //Common function  // Common function
46  const char *  const char *str_space(char *string, int length)
 str_space (char *string, int length)  
47  {  {
48    int i;          int i;
49    for (i = 0; i < length; i++)          for (i = 0; i < length; i++)
50      {          {
51        string[i] = ' ';                  string[i] = ' ';
52      }          }
53    string[length] = '\0';          string[length] = '\0';
54    return string;          return string;
55  }  }
56    
57  const char *  const char *get_time_str(char *string, size_t length)
 get_time_str (char *string, size_t length)  
58  {  {
59    char week[10], buffer[256];          char week[20];
60    time_t curtime;          char buffer[LINE_BUFFER_LEN];
61    struct tm *loctime;          time_t curtime;
62            struct tm *loctime;
63    curtime = time (NULL);  
64    loctime = localtime (&curtime);          curtime = time(NULL);
65            loctime = localtime(&curtime);
66    strftime (buffer, 256, "%Y年%m月%d日%H:%M:%S ", loctime);  
67            strftime(buffer, sizeof(buffer), "%Y年%m月%d日%H:%M:%S ", loctime);
68    switch (loctime->tm_wday)  
69      {          switch (loctime->tm_wday)
70      case 0:          {
71        strcpy (week, "星期天");          case 0:
72        break;                  strncpy(week, "星期天", sizeof(week));
73      case 1:                  break;
74        strcpy (week, "星期一");          case 1:
75        break;                  strncpy(week, "星期一", sizeof(week));
76      case 2:                  break;
77        strcpy (week, "星期二");          case 2:
78        break;                  strncpy(week, "星期二", sizeof(week));
79      case 3:                  break;
80        strcpy (week, "星期三");          case 3:
81        break;                  strncpy(week, "星期三", sizeof(week));
82      case 4:                  break;
83        strcpy (week, "星期四");          case 4:
84        break;                  strncpy(week, "星期四", sizeof(week));
85      case 5:                  break;
86        strcpy (week, "星期五");          case 5:
87        break;                  strncpy(week, "星期五", sizeof(week));
88      case 6:                  break;
89        strcpy (week, "星期六");          case 6:
90        break;                  strncpy(week, "星期六", sizeof(week));
91      }                  break;
92    strcat (buffer, week);          }
93            strncat(buffer, week, sizeof(week));
94    
95    strncpy (string, buffer, length);          strncpy(string, buffer, length);
96    
97    return string;          return string;
98  }  }
99    
100  void  void reload_bbs_menu(int i)
 reload_bbs_menu (int i)  
101  {  {
102    if (reload_menu (&bbs_menu) < 0)          if (reload_menu(&bbs_menu) < 0)
103      log_error ("Reload menu failed\n");                  log_error("Reload menu failed\n");
104    else          else
105      log_std ("Reload menu successfully\n");                  log_std("Reload menu successfully\n");
   
106  }  }
107    
108  void  void system_exit(int i)
 system_exit (int i)  
109  {  {
110    SYS_exit = 1;          SYS_exit = 1;
   log_std ("Get SIG_BBS_EXIT signal successfully\n");  
111  }  }
112    
113  void  void child_exit(int i)
 child_exit (int i)  
114  {  {
115    int pid;          int pid;
116      
117    pid = wait (0);          pid = wait(0);
118    
119    if (pid > 0)          if (pid > 0)
120      {          {
121        SYS_child_process_count --;                  SYS_child_process_count--;
122        log_std ("Child process (%d) exited\n", pid);                  log_std("Child process (%d) exited\n", pid);
123      }          }
124  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

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