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


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

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