* df32func.c\r
* df32func extensions for Console Mode DataFlex 3.2\r
*\r
- * Copyright (c) 2007-2009, glyn@8kb.co.uk\r
+ * Copyright (c) 2007-2015, glyn@8kb.co.uk\r
* Author: Glyn Astill <glyn@8kb.co.uk>\r
*\r
*-------------------------------------------------------------------------\r
*/\r
\r
-#include "df32func.h"\r
#include <windows.h>\r
#include <stdio.h>\r
#include <stdlib.h>\r
#include <winsock.h>\r
+#include <tchar.h>\r
+#include "gnuregex.h"\r
+#include "df32func.h"\r
+\r
+/*\r
+ * Used by GetTzi\r
+ * http://msdn.microsoft.com/en-us/library/ms724253.aspx\r
+ */\r
+typedef struct _REG_TZI_FORMAT\r
+{\r
+ LONG Bias;\r
+ LONG StandardBias;\r
+ LONG DaylightBias;\r
+ SYSTEMTIME StandardDate;\r
+ SYSTEMTIME DaylightDate;\r
+} REG_TZI_FORMAT;\r
\r
SOCKET s, sc; /* Socket handle */\r
\r
return n;\r
}\r
\r
+/*\r
+ * Pull back timezone information from windows registry\r
+ */\r
+DLLIMPORT int GetTzi (TCHAR* zone, TCHAR *result)\r
+{\r
+ DWORD dwStatus, dwType, cbData;\r
+ int cch;\r
+ TCHAR szTime[128], szDate[128], szSubKey[256];\r
+ HKEY hKey;\r
+ REG_TZI_FORMAT tzi;\r
+\r
+ /* https://msdn.microsoft.com/en-us/library/windows/desktop/ms647490%28v=vs.85%29.aspx */\r
+ lstrcpy(szSubKey, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\"));\r
+\r
+ /*\r
+ * https://msdn.microsoft.com/en-us/library/aa272954%28v=vs.60%29.aspx\r
+ * https://msdn.microsoft.com/en-us/library/h1x0y282.aspx\r
+ */\r
+ _tcscat(szSubKey, zone);\r
+\r
+ dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_QUERY_VALUE, &hKey);\r
+ if (dwStatus != NO_ERROR)\r
+ return GetLastError();\r
+\r
+ cbData = sizeof(REG_TZI_FORMAT);\r
+ dwStatus = RegQueryValueEx (hKey, TEXT("TZI"), NULL, &dwType, (LPBYTE)&tzi, &cbData);\r
+ if (dwStatus != NO_ERROR)\r
+ return GetLastError();\r
+\r
+ /*\r
+ * tzi.StandardDate and tzi.DaylightDate are not a real SYSTEMTIME\r
+ * but we should look at them to depict daylight saving\r
+ * if month = 0 then not supported, year = 0 means every year.\r
+ * http://msdn.microsoft.com/en-us/library/ms725481.asp\r
+ */\r
+\r
+ _stprintf(result, "%d,%d,%d,%d/%d/%d/%d,%d:%d:%d,%d/%d/%d/%d,%d:%d:%d",\r
+ tzi.Bias,tzi.StandardBias,tzi.DaylightBias,\r
+ tzi.StandardDate.wYear,tzi.StandardDate.wMonth,tzi.StandardDate.wDay,tzi.StandardDate.wDayOfWeek,tzi.StandardDate.wHour,tzi.StandardDate.wMinute,tzi.StandardDate.wSecond,\r
+ tzi.DaylightDate.wYear,tzi.DaylightDate.wMonth,tzi.DaylightDate.wDay,tzi.DaylightDate.wDayOfWeek,tzi.DaylightDate.wHour,tzi.DaylightDate.wMinute,tzi.DaylightDate.wSecond\r
+ );\r
+\r
+ return -1;\r
+}\r
+\r
+/*\r
+ * Check for a regex match\r
+ */\r
+DLLIMPORT int RegexpMatch (const char *str, const char *pattern, const char *flags, int errors)\r
+{\r
+ return regexp_match(str, pattern, flags, errors);\r
+}\r
+\r
+/*\r
+ * Return all matches in the regex as a string and return in custom format\r
+ */\r
+DLLIMPORT int RegexpMatches(const char *str, const char *pattern, const char *flags, char *output, int output_len, int errors)\r
+{\r
+ char *matches = regexp_matches(str, pattern, flags, errors);\r
+ int matches_len;\r
+ int result = 0;\r
+\r
+ if (matches != NULL)\r
+ {\r
+ matches_len = strlen(matches);\r
+ if (matches_len <= output_len)\r
+ {\r
+ strncpy(output, matches, matches_len);\r
+ result = 0;\r
+ }\r
+ else\r
+ result = -1;\r
+\r
+ wfree(matches);\r
+ }\r
+ else\r
+ result = -2;\r
+\r
+ return result;\r
+}\r
+\r
+/*\r
+ * Substitutes matches with the regex pattern in the string with the replacement\r
+ * pattern/string.\r
+ */\r
+DLLIMPORT int RegexpReplace(const char *str, const char *pattern, const char *replacement, const char *flags, char *output, int output_len, int errors)\r
+{\r
+ char *replaced = regexp_replace(str, pattern, replacement, flags, errors);\r
+ int replaced_len;\r
+ int result = 0;\r
+\r
+ if (replaced != NULL)\r
+ {\r
+ replaced_len = strlen(replaced);\r
+\r
+ if (replaced_len <= output_len)\r
+ {\r
+ strncpy(output, replaced, replaced_len);\r
+ result = 0;\r
+ }\r
+ else\r
+ result = -1;\r
+\r
+ wfree(replaced);\r
+ }\r
+ else\r
+ result = -2;\r
+\r
+\r
+ return result;\r
+}\r
+\r
+\r
/*\r
* DLL entry point\r
*/\r