2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23 $Date: 2010/11/08 10:11:19 $
38 #include "stg_const.h"
40 #define STAT_TIME_3 (1)
41 #define STAT_TIME_2 (2)
42 #define STAT_TIME_1 (3)
43 #define STAT_TIME_1_2 (4)
44 #define STAT_TIME_1_4 (5)
45 #define STAT_TIME_1_6 (6)
47 #define FN_STR_LEN (NAME_MAX)
54 //-----------------------------------------------------------------------------
55 const char * IntToKMG(long long a, int statType = ST_F);
56 const char * LogDate(time_t t);
57 int ParesTimeStat(const char * str);
58 int IsTimeStat(struct tm * t, int statTime);
59 /*bool IsDigit(char c);
60 bool IsAlpha(char c);*/
61 int strtodouble2(const char * s, double &a);
62 int printfd(const char * __file__, const char * fmt, ...);
63 void Encode12(char * dst, const char * src, size_t srcLen);
64 void Decode21(char * dst, const char * src);
66 void Encode12str(std::string & dst, const std::string & src);
67 void Decode21str(std::string & dst, const std::string & src);
69 int ParseIPString(const char * str, uint32_t * ips, int maxIP);
70 void KOIToWin(const char * s1, char * s2, int l);
71 void WinToKOI(const char * s1, char * s2, int l);
72 void KOIToWin(const std::string & s1, std::string * s2);
73 void WinToKOI(const std::string & s1, std::string * s2);
74 int DaysInMonth(unsigned year, unsigned mon);
75 int DaysInCurrentMonth();
77 //char * inet_ntostr(unsigned long);
78 std::string inet_ntostring(uint32_t);
79 uint32_t inet_strington(const std::string & value);
80 int strprintf(std::string * str, const char * fmt, ...);
81 int ParseTariffTimeStr(const char * str, int &h1, int &m1, int &h2, int &m2);
82 uint32_t CalcMask(uint32_t msk);
83 void TouchFile(const std::string & fileName);
85 void EncodeStr(char * str, unsigned long serial, int useHDD);
86 void DecodeStr(char * str, unsigned long serial, int useHDD);
88 void SwapBytes(uint16_t & value);
89 void SwapBytes(uint32_t & value);
90 void SwapBytes(uint64_t & value);
91 void SwapBytes(int16_t & value);
92 void SwapBytes(int32_t & value);
93 void SwapBytes(int64_t & value);
95 std::string & TrimL(std::string & val);
96 std::string & TrimR(std::string & val);
97 std::string & Trim(std::string & val);
99 std::string IconvString(const std::string & source, const std::string & from, const std::string & to);
101 //-----------------------------------------------------------------------------
102 template <typename varT>
103 int str2x(const std::string & str, varT & x)
120 if ((str[pos] < '0' || str[pos] > '9'))
123 x = str[pos++] - '0';
125 for (unsigned i = pos; i < str.size(); i++)
127 if ((str[i] < '0' || str[i] > '9'))
138 //-----------------------------------------------------------------------------
139 template <typename varT>
140 const std::string & x2str(varT x, std::string & s)
174 s[--pos] = -(x % 10) + '0';
176 s[--pos] = x % 10 + '0';
183 //-----------------------------------------------------------------------------
184 template <typename varT>
185 const std::string & unsigned2str(varT x, std::string & s)
212 s[--pos] = x % 10 + '0';
219 //-----------------------------------------------------------------------------
220 int str2x(const std::string & str, int & x);
221 int str2x(const std::string & str, unsigned & x);
222 int str2x(const std::string & str, long & x);
223 int str2x(const std::string & str, unsigned long & x);
224 int str2x(const std::string & str, long long & x);
225 int str2x(const std::string & str, unsigned long long & x);
226 //-----------------------------------------------------------------------------
227 const std::string & x2str(unsigned x, std::string & s);
228 const std::string & x2str(unsigned long x, std::string & s);
229 const std::string & x2str(unsigned long long x, std::string & s);
230 //-----------------------------------------------------------------------------
231 char * stg_strptime(const char *, const char *, struct tm *);
232 time_t stg_timegm(struct tm *);