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


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

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