Qore Programming Language  0.8.3
include/qore/QoreLib.h (4311)
Go to the documentation of this file.
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */
00002 /*
00003   QoreLib.h
00004 
00005   Qore Programming Language
00006 
00007   Copyright 2003 - 2011 David Nichols
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 */
00023 
00024 #ifndef _QORE_QORELIB_H
00025 
00026 #define _QORE_QORELIB_H
00027 
00028 #include <qore/common.h>
00029 #include <qore/QoreThreadLock.h>
00030 #include <qore/qore_bitopts.h>
00031 #include <qore/safe_dslist>
00032 
00033 #include <time.h>
00034 #include <string.h>
00035 #include <strings.h>
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <ctype.h>
00039 #include <sys/types.h>
00040 
00045 
00046 #undef _QORE_HAS_QORE_XMLNODE_CLASS
00047 
00049 #undef _QORE_HAS_QORE_XMLREADER_CLASS
00050 
00052 #undef _QORE_HAS_QORE_XMLDOC_CLASS
00053 
00055 #define _QORE_HAS_HARD_TYPING 1
00056 
00058 #define _QORE_HAS_DBI_EXECRAW 1
00059 
00061 #define _QORE_HAS_TIME_ZONES 1
00062 
00064 #define _QORE_HAS_THREAD_RESOURCE_IDS 1
00065 
00067 #define _QORE_HAS_PREPARED_STATMENT_API 1
00068 
00070 #define _QORE_HAS_DATASOURCE_ACTIVETRANSACTION 1
00071 
00073 #define _QORE_HAS_DBI_SELECT_ROW 1
00074 
00075 // qore code flags
00076 #define QC_NO_FLAGS                 0   //! no flag
00077 #define QC_NOOP               (1 << 0)  //! this variant is a noop, meaning it returns a constant value with the given argument types
00078 #define QC_USES_EXTRA_ARGS    (1 << 1)  //! code accesses arguments beyond the declared parameter list
00079 #define QC_CONSTANT_INTERN    (1 << 2)  //! internal constant flag, use QC_CONSTANT instead
00080 #define QC_DEPRECATED         (1 << 3)  //! function or method is deprecated and will be removed in a later release
00081 #define QC_RET_VALUE_ONLY     (1 << 4)  //! code only returns a value and has no other side effects
00082 #define QC_RUNTIME_NOOP       (1 << 5)  //! this variant is a noop like QC_NOOP, but additionally is not available to programs executing with %require-types (PO_REQUIRE_TYPES)
00083 
00084 // composite flags
00085 #define QC_CONSTANT (QC_CONSTANT_INTERN | QC_RET_VALUE_ONLY) //! code is safe to use in a constant expression (i.e. has no side effects, does not change internal state, cannot throw an exception under any circumstances, just returns a calculation based on its arguments)
00086 
00088 DLLEXPORT char *make_class_name(const char *fn);
00089 
00091 DLLEXPORT QoreStringNode *q_sprintf(const class QoreListNode *params, int field, int offset, class ExceptionSink *xsink);
00092 
00094 DLLEXPORT QoreStringNode *q_vsprintf(const class QoreListNode *params, int field, int offset, class ExceptionSink *xsink);
00095 
00097 DLLEXPORT struct tm *q_localtime(const time_t *clock, struct tm *tms);
00098 
00100 DLLEXPORT struct tm *q_gmtime(const time_t *clock, struct tm *tms);
00101 
00103 DLLEXPORT int64 q_epoch();
00104 
00106 DLLEXPORT int64 q_epoch_us(int &us);
00107 
00109 DLLEXPORT int64 q_epoch_ns(int &us);
00110 
00112 DLLEXPORT char *q_basename(const char *path);
00113 
00115 DLLEXPORT char *q_basenameptr(const char *path);
00116 
00118 DLLEXPORT char *q_dirname(const char *path);
00119 
00121 DLLEXPORT void *q_realloc(void *ptr, size_t size);
00122 
00123 #if (!defined _WIN32 && !defined __WIN32__) || defined __CYGWIN__
00124 
00125 DLLEXPORT QoreHashNode *q_getpwuid(uid_t uid);
00126 
00128 DLLEXPORT QoreHashNode *q_getpwnam(const char *name);
00129 
00131 DLLEXPORT QoreHashNode *q_getgrgid(uid_t uid);
00132 
00134 DLLEXPORT QoreHashNode *q_getgrnam(const char *name);
00135 
00137 
00142 int q_uname2uid(const char *name, uid_t &uid);
00143 
00145 
00150 int q_gname2gid(const char *name, gid_t &gid);
00151 #endif // ! windows
00152 
00154 DLLEXPORT void qore_setup_argv(int pos, int argc, char *argv[]);
00155 
00157 DLLEXPORT qore_license_t qore_get_license();
00158 
00160 DLLEXPORT void qore_exit_process(int rc);
00161 
00163 
00165 class FeatureList : public safe_dslist<std::string> {
00166 private:
00168    DLLLOCAL FeatureList(const FeatureList&);
00169 
00171    DLLLOCAL FeatureList& operator=(const FeatureList&);
00172 
00173 public:
00175    DLLLOCAL FeatureList();
00176 
00178    DLLLOCAL ~FeatureList();
00179 };
00180 
00182 DLLEXPORT extern FeatureList qoreFeatureList;
00183 
00185 static inline char *strchrs(const char *str, const char *chars) {
00186    while (*str) {
00187       if (strchr(chars, *str))
00188          return (char *)str;
00189       str++;
00190    }
00191    return 0;
00192 }
00193 
00195 static inline char *strnchr(const char *str, int len, char c) {
00196    int i = 0;
00197    while (i++ != len) {
00198       if (*str == c)
00199          return (char *)str;
00200       ++str;
00201    }
00202    return 0;
00203 }
00204 
00206 static inline void strtolower(char *str) {
00207    while (*(str)) {
00208       (*str) = tolower(*str);
00209       str++;
00210    }
00211 }
00212 
00214 static inline char *strtoupper(char *str) {
00215    char *p = str;
00216    while (*(p)) {
00217       *p = toupper(*p);
00218       p++;
00219    }
00220    return str;
00221 }
00222 
00224 DLLEXPORT int getSecZeroInt(const AbstractQoreNode *a);
00225 
00227 DLLEXPORT int64 getSecZeroBigInt(const AbstractQoreNode *a);
00228 
00230 DLLEXPORT int getSecMinusOneInt(const AbstractQoreNode *a);
00231 
00233 DLLEXPORT int64 getSecMinusOneBigInt(const AbstractQoreNode *a);
00234 
00236 DLLEXPORT int getMsZeroInt(const AbstractQoreNode *a);
00237 
00239 DLLEXPORT int64 getMsZeroBigInt(const AbstractQoreNode *a);
00240 
00242 DLLEXPORT int getMsMinusOneInt(const AbstractQoreNode *a);
00243 
00245 DLLEXPORT int64 getMsMinusOneBigInt(const AbstractQoreNode *a);
00246 
00248 DLLEXPORT int getMicroSecZeroInt(const AbstractQoreNode *a);
00249 
00251 DLLEXPORT int64 getMicroSecZeroInt64(const AbstractQoreNode *a);
00252 
00254 static inline bool is_nothing(const AbstractQoreNode *n) {
00255    if (!n || n->getType() == NT_NOTHING)
00256       return true;
00257    
00258    return false;
00259 }
00260 
00262 static inline void discard(AbstractQoreNode *n, ExceptionSink *xsink) {
00263    if (n)
00264       n->deref(xsink);
00265 }
00266 
00267 static inline const char *get_type_name(const AbstractQoreNode *n) {
00268    return n ? n->getTypeName() : "NOTHING";
00269 }
00270 
00271 static inline qore_type_t get_node_type(const AbstractQoreNode *n) {
00272    return n ? n->getType() : NT_NOTHING;
00273 }
00274 
00275 class BinaryNode;
00276 class QoreStringNode;
00277 class ExceptionSink;
00278 
00280 DLLEXPORT BinaryNode     *qore_deflate(void *ptr, unsigned long len, int level, ExceptionSink *xsink);
00282 DLLEXPORT QoreStringNode *qore_inflate_to_string(const BinaryNode *b, const QoreEncoding *enc, ExceptionSink *xsink);
00284 DLLEXPORT BinaryNode     *qore_inflate_to_binary(const BinaryNode *b, ExceptionSink *xsink);
00286 DLLEXPORT BinaryNode     *qore_gzip(void *ptr, unsigned long len, int level, ExceptionSink *xsink);
00288 DLLEXPORT QoreStringNode *qore_gunzip_to_string(const BinaryNode *bin, const QoreEncoding *enc, ExceptionSink *xsink);
00290 DLLEXPORT BinaryNode     *qore_gunzip_to_binary(const BinaryNode *bin, ExceptionSink *xsink);
00292 DLLEXPORT BinaryNode     *qore_bzip2(void *ptr, unsigned long len, int level, ExceptionSink *xsink);
00294 DLLEXPORT QoreStringNode *qore_bunzip2_to_string(const BinaryNode *bin, const QoreEncoding *enc, ExceptionSink *xsink);
00296 DLLEXPORT BinaryNode     *qore_bunzip2_to_binary(const BinaryNode *bin, ExceptionSink *xsink);
00297 
00299 DLLEXPORT BinaryNode *parseBase64(const char *buf, int len, ExceptionSink *xsink);
00300 
00302 DLLEXPORT BinaryNode *parseHex(const char *buf, int len, ExceptionSink *xsink);
00303 
00304 class AbstractQoreZoneInfo;
00305 
00307 DLLEXPORT const AbstractQoreZoneInfo *findCreateOffsetZone(int seconds_east);
00308 
00310 #define QORE_OPT_ATOMIC_OPERATIONS       "atomic operations"
00311 
00312 #define QORE_OPT_STACK_GUARD             "stack guard"
00313 
00314 #define QORE_OPT_SIGNAL_HANDLING         "signal handling"
00315 
00316 #define QORE_OPT_RUNTIME_STACK_TRACE     "runtime stack tracing"
00317 
00318 #define QORE_OPT_LIBRARY_DEBUGGING       "library debugging"
00319 
00320 #define QORE_OPT_SHA224                  "openssl sha224"
00321 
00322 #define QORE_OPT_SHA256                  "openssl sha256"
00323 
00324 #define QORE_OPT_SHA384                  "openssl sha384"
00325 
00326 #define QORE_OPT_SHA512                  "openssl sha512"
00327 
00328 #define QORE_OPT_MDC2                    "openssl mdc2"
00329 
00330 #define QORE_OPT_RC5                     "openssl rc5"
00331 
00332 #define QORE_OPT_MD2                     "openssl md2"
00333 
00334 #define QORE_OPT_TERMIOS                 "termios"
00335 
00336 #define QORE_OPT_FILE_LOCKING            "file locking"
00337 
00338 #define QORE_OPT_UNIX_USERMGT            "unix user management"
00339 
00340 #define QORE_OPT_UNIX_FILEMGT            "unix file management"
00341 
00342 #define QORE_OPT_FUNC_ROUND              "round()"
00343 
00344 #define QORE_OPT_FUNC_TIMEGM             "timegm()"
00345 
00346 #define QORE_OPT_FUNC_SETEUID            "seteuid()"
00347 
00348 #define QORE_OPT_FUNC_SETEGID            "setegid()"
00349 
00350 #define QORE_OPT_FUNC_SYSTEM             "system()"
00351 
00352 #define QORE_OPT_FUNC_KILL               "kill()"
00353 
00354 #define QORE_OPT_FUNC_FORK               "fork()"
00355 
00356 #define QORE_OPT_FUNC_GETPPID            "getppid()"
00357 
00358 #define QORE_OPT_FUNC_STATVFS            "statvfs()"
00359 
00360 #define QORE_OPT_FUNC_SETSID             "setsid()"
00361 
00362 #define QORE_OPT_FUNC_IS_EXECUTABLE      "is_executable()"
00363 
00365 #define QO_OPTION     0
00366 #define QO_ALGORITHM  1
00367 #define QO_FUNCTION   2
00368 
00370 struct qore_option_s {
00371    const char *option;   
00372    const char *constant; 
00373    int type;             
00374    bool value;           
00375 };
00376 
00377 //const char *qore_get_option_list();
00378 
00380 DLLEXPORT QoreStringNode *q_strerror(int errnum);
00382 DLLEXPORT void q_strerror(QoreString &str, int errnum);
00383 
00385 DLLEXPORT extern const qore_option_s *qore_option_list;
00387 DLLEXPORT extern size_t qore_option_list_size;
00388 
00390 
00394 DLLEXPORT QoreStringNode *qore_reassign_signal(int sig, const char *name);
00395 
00397 #define QORE_MAX(a, b) ((a) > (b) ? (a) : (b))
00398 
00399 #define QORE_PARAM_NO_ARG (NULL)
00400 
00401 // define QORE_PATH_MAX
00402 #ifndef QORE_PATH_MAX
00403 #ifdef _XOPEN_PATH_MAX
00404 #define QORE_PATH_MAX _XOPEN_PATH_MAX
00405 #else
00406 #define QORE_PATH_MAX 1024
00407 #endif
00408 #endif
00409 
00411 
00413 DLLEXPORT void parse_set_time_zone(const char *zone);
00414 
00416 DLLEXPORT int qore_usleep(int64 usecs);
00417 
00418 #endif // _QORE_QORELIB_H
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines