/[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.15 by sysadm, Tue May 6 05:31:26 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            common.c  -  description                                                    common.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Mon Oct 18 2004          Copyright            : (C) 2004-2025 by Leaflet
5      copyright            : (C) 2004 by Leaflet          Email                : leaflet@leafok.com
     email                : leaflet@leafok.com  
6   ***************************************************************************/   ***************************************************************************/
7    
8  /***************************************************************************  /***************************************************************************
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
12   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 3 of the License, or     *
13   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #include "common.h"
18    #include "log.h"
19  #include "menu.h"  #include "menu.h"
20    #include <string.h>
21  #include <time.h>  #include <time.h>
22  #include <sys/types.h>  #include <sys/types.h>
23  #include <sys/wait.h>  #include <sys/wait.h>
24    
25  //Version information  // Version information
26  char app_version[256] = "LBBS-devel version 1.0";  char app_version[256] = "LBBS-devel version 1.0";
27    
28  //Global declaration for enviroment  // Global declaration for sockets
 char app_home_dir[256];  
 char app_temp_dir[256];  
   
 //Global declaration for sockets  
29  int socket_server;  int socket_server;
30  int socket_client;  int socket_client;
31  char hostaddr_server[50];  char hostaddr_server[50];
# Line 35  char hostaddr_client[50]; Line 33  char hostaddr_client[50];
33  int port_server;  int port_server;
34  int port_client;  int port_client;
35    
36  //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  
37  int SYS_exit;  int SYS_exit;
38  int SYS_child_process_count;  int SYS_child_process_count;
39    
40  //Common function  // Common function
41  const char *  const char *str_space(char *string, int length)
 str_space (char *string, int length)  
42  {  {
43    int i;          int i;
44    for (i = 0; i < length; i++)          for (i = 0; i < length; i++)
45      {          {
46        string[i] = ' ';                  string[i] = ' ';
47      }          }
48    string[length] = '\0';          string[length] = '\0';
49    return string;          return string;
50  }  }
51    
52  const char *  const char *get_time_str(char *s, size_t len)
 get_time_str (char *string, size_t length)  
53  {  {
54    char week[10], buffer[256];          time_t curtime = time(NULL);
55    time_t curtime;          struct tm *loctime;
56    struct tm *loctime;          loctime = localtime(&curtime);
57    
58    curtime = time (NULL);          size_t j = strftime(s, len, "%Y年%m月%d日%H:%M:%S ", loctime);
59    loctime = localtime (&curtime);  
60            if (j == 0)
61    strftime (buffer, 256, "%Y年%m月%d日%H:%M:%S ", loctime);          {
62                    return NULL;
63    switch (loctime->tm_wday)          }
64      {  
65      case 0:          switch (loctime->tm_wday)
66        strcpy (week, "星期天");          {
67        break;          case 0:
68      case 1:                  strncat(s, "星期天", len - j);
69        strcpy (week, "星期一");                  break;
70        break;          case 1:
71      case 2:                  strncat(s, "星期一", len - j);
72        strcpy (week, "星期二");                  break;
73        break;          case 2:
74      case 3:                  strncat(s, "星期二", len - j);
75        strcpy (week, "星期三");                  break;
76        break;          case 3:
77      case 4:                  strncat(s, "星期三", len - j);
78        strcpy (week, "星期四");                  break;
79        break;          case 4:
80      case 5:                  strncat(s, "星期四", len - j);
81        strcpy (week, "星期五");                  break;
82        break;          case 5:
83      case 6:                  strncat(s, "星期五", len - j);
84        strcpy (week, "星期六");                  break;
85        break;          case 6:
86      }                  strncat(s, "星期六", len - j);
87    strcat (buffer, week);                  break;
88            }
   strncpy (string, buffer, length);  
89    
90    return string;          return s;
91  }  }
92    
93  void  void reload_bbs_menu(int i)
 reload_bbs_menu (int i)  
94  {  {
95    if (reload_menu (&bbs_menu) < 0)          if (reload_menu(&bbs_menu) < 0)
96      log_error ("Reload menu failed\n");                  log_error("Reload menu failed\n");
97    else          else
98      log_std ("Reload menu successfully\n");                  log_std("Reload menu successfully\n");
   
99  }  }
100    
101  void  void system_exit(int i)
 system_exit (int i)  
102  {  {
103    SYS_exit = 1;          SYS_exit = 1;
   log_std ("Get SIG_BBS_EXIT signal successfully\n");  
104  }  }
105    
106  void  void child_exit(int i)
 child_exit (int i)  
107  {  {
108    int pid;          int pid;
109      
110    pid = wait (0);          pid = wait(0);
111    
112    if (pid > 0)          if (pid > 0)
113      {          {
114        SYS_child_process_count --;                  SYS_child_process_count--;
115        log_std ("Child process (%d) exited\n", pid);                  log_std("Child process (%d) exited\n", pid);
116      }          }
117  }  }


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

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