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


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

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