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


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

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