/[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.8 by sysadm, Sat May 7 12:15:30 2005 UTC Revision 1.11 by sysadm, Wed Apr 30 09:18: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 database
42  char DB_host[256];  char DB_host[256];
43  char DB_username[50];  char DB_username[50];
44  char DB_password[50];  char DB_password[50];
45  char DB_database[50];  char DB_database[50];
46    char DB_timezone[50];
47    
48  //Global declaration for system  // Global declaration for system
49  int SYS_exit;  int SYS_exit;
50  int SYS_child_process_count;  int SYS_child_process_count;
51    
52  //Common function  // Common function
53  const char *  const char *str_space(char *string, int length)
 str_space (char *string, int length)  
54  {  {
55    int i;          int i;
56    for (i = 0; i < length; i++)          for (i = 0; i < length; i++)
57      {          {
58        string[i] = ' ';                  string[i] = ' ';
59      }          }
60    string[length] = '\0';          string[length] = '\0';
61    return string;          return string;
62  }  }
63    
64  const char *  const char *get_time_str(char *string, size_t length)
 get_time_str (char *string, size_t length)  
65  {  {
66    char week[10], buffer[256];          char week[10], buffer[256];
67    time_t curtime;          time_t curtime;
68    struct tm *loctime;          struct tm *loctime;
69    
70    curtime = time (NULL);          curtime = time(NULL);
71    loctime = localtime (&curtime);          loctime = localtime(&curtime);
72    
73    strftime (buffer, 256, "%Y年%m月%d日%H:%M:%S ", loctime);          strftime(buffer, 256, "%Y年%m月%d日%H:%M:%S ", loctime);
74    
75    switch (loctime->tm_wday)          switch (loctime->tm_wday)
76      {          {
77      case 0:          case 0:
78        strcpy (week, "星期天");                  strcpy(week, "星期天");
79        break;                  break;
80      case 1:          case 1:
81        strcpy (week, "星期一");                  strcpy(week, "星期一");
82        break;                  break;
83      case 2:          case 2:
84        strcpy (week, "星期二");                  strcpy(week, "星期二");
85        break;                  break;
86      case 3:          case 3:
87        strcpy (week, "星期三");                  strcpy(week, "星期三");
88        break;                  break;
89      case 4:          case 4:
90        strcpy (week, "星期四");                  strcpy(week, "星期四");
91        break;                  break;
92      case 5:          case 5:
93        strcpy (week, "星期五");                  strcpy(week, "星期五");
94        break;                  break;
95      case 6:          case 6:
96        strcpy (week, "星期六");                  strcpy(week, "星期六");
97        break;                  break;
98      }          }
99    strcat (buffer, week);          strcat(buffer, week);
100    
101    strncpy (string, buffer, length);          strncpy(string, buffer, length);
102    
103    return string;          return string;
104  }  }
105    
106  void  void reload_bbs_menu(int i)
 reload_bbs_menu (int i)  
107  {  {
108    if (reload_menu (&bbs_menu) < 0)          if (reload_menu(&bbs_menu) < 0)
109      log_error ("Reload menu failed\n");                  log_error("Reload menu failed\n");
110    else          else
111      log_std ("Reload menu successfully\n");                  log_std("Reload menu successfully\n");
   
112  }  }
113    
114  void  void system_exit(int i)
 system_exit (int i)  
115  {  {
116    SYS_exit = 1;          SYS_exit = 1;
117  }  }
118    
119  void  void child_exit(int i)
 child_exit (int i)  
120  {  {
121    int pid;          int pid;
122      
123    pid = wait (0);          pid = wait(0);
124    
125    if (pid > 0)          if (pid > 0)
126      {          {
127        SYS_child_process_count --;                  SYS_child_process_count--;
128        log_std ("Child process (%d) exited\n", pid);                  log_std("Child process (%d) exited\n", pid);
129      }          }
130  }  }


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

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