/* --------------------------------------------------------------- */ void R_sql( const int func ) { int rc; const char *tail; if (ARGN!=1) Lerror(ERR_INCORRECT_CALL,0); get_s(1); if (!sqldb) Lerror(ERR_DATABASE,1); if (sqlstmt) { sqlite3_finalize(sqlstmt); sqlstmt = NULL; } Licpy(ARGR, sqlite3_prepare_v2(sqldb, LSTR(*ARG1), LLEN(*ARG1), &sqlstmt, &tail)); if (LINT(*ARGR) == SQLITE_OK) { if (sqlite3_bind_parameter_count(sqlstmt)==0) { rc = sqlite3_step(sqlstmt); if (rc == SQLITE_ROW) Lscpy(ARGR, "ROW"); else if (rc == SQLITE_DONE) Licpy(ARGR, SQLITE_OK); else Licpy(ARGR, rc); } } } /* R_sql */
/* --------------------------------------------------------------- */ void R_sqlget( const int func ) { int col, bytes; if (ARGN==0) { Licpy(ARGR, sqlite3_column_count(sqlstmt)); return; } if (ARGN>1) Lerror(ERR_INCORRECT_CALL,0); get_i0(1,col); col--; switch (sqlite3_column_type(sqlstmt, col)) { case SQLITE_INTEGER: Licpy(ARGR, sqlite3_column_int(sqlstmt, col)); break; case SQLITE_FLOAT: Lrcpy(ARGR, sqlite3_column_double(sqlstmt, col)); break; case SQLITE_TEXT: Lscpy(ARGR, (char*)sqlite3_column_text(sqlstmt, col)); break; case SQLITE_BLOB: bytes = sqlite3_column_bytes(sqlstmt, col); Lfx(ARGR, bytes); LLEN(*ARGR) = bytes; LTYPE(*ARGR) = LSTRING_TY; MEMCPY(LSTR(*ARGR), sqlite3_column_blob(sqlstmt, col), bytes); break; case SQLITE_NULL: Lfx(ARGR,1); LTYPE(*ARGR) = LSTRING_TY; LLEN(*ARGR) = 1; LSTR(*ARGR)[0] = 0; break; default: Lfx(ARGR,0); LTYPE(*ARGR) = LSTRING_TY; LLEN(*ARGR) = 0; } } /* R_sqlget */
/* WARNING!!! length is size_t type DO NOT PASS A NEGATIVE value */ void __CDECL _Lsubstr( const PLstr to, const PLstr from, size_t start, size_t length ) { L2STR(from); start--; if ((length==0) || (length+start>LLEN(*from))) length = LLEN(*from) - start; if (start<LLEN(*from)) { if (LMAXLEN(*to)<length) Lfx(to,length); MEMCPY( LSTR(*to), LSTR(*from)+start, length ); LLEN(*to) = length; } else LZEROSTR(*to); LTYPE(*to) = LSTRING_TY; } /* Lstrsub */
/* ----------------- Lstrset ------------------ */ void __CDECL Lstrset( const PLstr to, const size_t length, const char value) { Lfx(to,length); LTYPE(*to) = LSTRING_TY; LLEN(*to) = length; MEMSET(LSTR(*to),value,length); } /* Lstrset */
/**************************************************************************** * * * Functions: FormMain_OnCommand related event code * * * * Purpose : Handle WM_COMMAND messages: this is the heart of the app. * * * * History : Date Reason * * 00/00/00 Created * * * ****************************************************************************/ void btnDetails_Click (HWND hwnd) { RECT rect; GetWindowRect( hwnd, &rect ); mod *= -1; ShowWindow( GetDlgItem(hwnd,IDC_TAB1), mod > 0? SW_SHOW: SW_HIDE ); if(!flag && mod==1) { static PWSTR tabnames[]= {L"Connection", L"Metadata", L"Cursors/Results", L"Debug", L"SSL", L"Misc", 0}; static PWSTR dlgnames[]= {MAKEINTRESOURCE(IDD_TAB1), MAKEINTRESOURCE(IDD_TAB2), MAKEINTRESOURCE(IDD_TAB3), MAKEINTRESOURCE(IDD_TAB4), MAKEINTRESOURCE(IDD_TAB5), MAKEINTRESOURCE(IDD_TAB6),0}; New_TabControl( &TabCtrl_1, // address of TabControl struct GetDlgItem(hwnd, IDC_TAB1), // handle to tab control tabnames, // text for each tab dlgnames, // dialog id's of each tab page dialog &FormMain_DlgProc, // address of main windows proc NULL, // address of size function TRUE); // stretch tab page to fit tab ctrl flag = true; HWND ssl_tab = TabCtrl_1.hTabPages[4]; HWND combo = GetDlgItem(ssl_tab, IDC_EDIT_sslmode); ComboBox_ResetContent(combo); ComboBox_AddString(combo, L""); ComboBox_AddString(combo, LSTR(ODBC_SSL_MODE_DISABLED)); ComboBox_AddString(combo, LSTR(ODBC_SSL_MODE_PREFERRED)); ComboBox_AddString(combo, LSTR(ODBC_SSL_MODE_REQUIRED)); ComboBox_AddString(combo, LSTR(ODBC_SSL_MODE_VERIFY_CA)); ComboBox_AddString(combo, LSTR(ODBC_SSL_MODE_VERIFY_IDENTITY)); syncTabs(hwnd, pParams); } MoveWindow( hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + 310*mod, TRUE ); }
static u32 lua_os_getenv(LSTATE) { lstring_t *str = lstate_getstring(0); char *value = getenv(str->data); if (value == NULL) { lstate_return1(LUAV_NIL); } lstate_return1(LSTR(value)); }
/* ----------------- Lstrcmp ------------------ */ int __CDECL Lstrcmp( const PLstr a, const PLstr b ) { int r; L2STR(a); L2STR(b); if ( (r=MEMCMP( LSTR(*a), LSTR(*b), MIN(LLEN(*a),LLEN(*b))))!=0 ) return r; else { if (LLEN(*a) > LLEN(*b)) return 1; else if (LLEN(*a) == LLEN(*b)) return 0; else return -1; } } /* Lstrcmp */
/* -- are of the same type */ int __CDECL _Lstrcmp( const PLstr a, const PLstr b ) { int r; if ( (r=MEMCMP( LSTR(*a), LSTR(*b), MIN(LLEN(*a),LLEN(*b))))!=0 ) return r; else { if (LLEN(*a) > LLEN(*b)) return 1; else if (LLEN(*a) == LLEN(*b)) { if (LTYPE(*a) > LTYPE(*b)) return 1; else if (LTYPE(*a) < LTYPE(*b)) return -1; return 0; } else return -1; } } /* _Lstrcmp */
/* ---------------- Lwscpy ------------------ */ void __CDECL Lwscpy(const PLstr to, const wchar_t *from ) { size_t len; if (!from) Lfx(to,len=0); else { Lfx(to,len = wcslen(from)); wcstombs(LSTR(*to), from ,len ); } LLEN(*to) = len; LTYPE(*to) = LSTRING_TY; } /* Lwscpy */
/* ---------------- Lscpy ------------------ */ void __CDECL Lscpy( const PLstr to, const char *from ) { size_t len; if (!from) Lfx(to,len=0); else { Lfx(to,len = STRLEN(from)); MEMCPY( LSTR(*to), from, len ); } LLEN(*to) = len; LTYPE(*to) = LSTRING_TY; } /* Lscpy */
INIT static void lua_math_init() { lua_math = lhash_alloc(); lhash_set(lua_math, LSTR("pi"), lv_number(M_PI)); lhash_set(lua_math, LSTR("huge"), lv_number(HUGE_VAL)); cfunc_register(lua_math, "abs", lua_math_abs); cfunc_register(lua_math, "acos", lua_math_acos); cfunc_register(lua_math, "asin", lua_math_asin); cfunc_register(lua_math, "atan", lua_math_atan); cfunc_register(lua_math, "atan2", lua_math_atan2); cfunc_register(lua_math, "ceil", lua_math_ceil); cfunc_register(lua_math, "cos", lua_math_cos); cfunc_register(lua_math, "cosh", lua_math_cosh); cfunc_register(lua_math, "deg", lua_math_deg); cfunc_register(lua_math, "exp", lua_math_exp); cfunc_register(lua_math, "floor", lua_math_floor); cfunc_register(lua_math, "fmod", lua_math_fmod); cfunc_register(lua_math, "frexp", lua_math_frexp); cfunc_register(lua_math, "ldexp", lua_math_ldexp); cfunc_register(lua_math, "log", lua_math_log); cfunc_register(lua_math, "log10", lua_math_log10); cfunc_register(lua_math, "min", lua_math_min); cfunc_register(lua_math, "max", lua_math_max); cfunc_register(lua_math, "mod", lua_math_mod); cfunc_register(lua_math, "modf", lua_math_modf); cfunc_register(lua_math, "pow", lua_math_pow); cfunc_register(lua_math, "rad", lua_math_rad); cfunc_register(lua_math, "random", lua_math_random); cfunc_register(lua_math, "randomseed", lua_math_randomseed); cfunc_register(lua_math, "sin", lua_math_sin); cfunc_register(lua_math, "sinh", lua_math_sinh); cfunc_register(lua_math, "sqrt", lua_math_sqrt); cfunc_register(lua_math, "tan", lua_math_tan); cfunc_register(lua_math, "tanh", lua_math_tanh); lhash_set(lua_globals, LSTR("math"), lv_table(lua_math)); }
/* ----------------- Lstrcat ------------------ */ void __CDECL Lstrcat( const PLstr to, const PLstr from ) { size_t l; if (LLEN(*from)==0) return; if (LLEN(*to)==0) { Lstrcpy( to, from ); return; } L2STR(to); L2STR(from); l = LLEN(*to)+LLEN(*from); if (LMAXLEN(*to) < l) #ifdef JCC Lfx(to, MAX(l,LMAXLEN(*to) + CAT_INC)); #else Lfx(to, l); #endif MEMCPY( LSTR(*to) + LLEN(*to), LSTR(*from), LLEN(*from) ); LLEN(*to) = l; } /* Lstrcat */
/* ---------------- Lcat ------------------- */ void __CDECL Lcat( const PLstr to, const char *from ) { size_t l; if (from==NULL) return; if (LLEN(*to)==0) Lscpy( to, from ); else { L2STR(to); l=LLEN(*to) + STRLEN(from); if (LMAXLEN(*to)<l) Lfx(to,l); STRCPY( LSTR(*to) + LLEN(*to), from ); LLEN(*to) = l; } } /* Lcat */
/* ------------------ Lcmp ------------------- */ int __CDECL Lcmp( const PLstr a, const char *b ) { int r,blen; L2STR(a); blen = STRLEN(b); if ( (r=MEMCMP( LSTR(*a), b, MIN(LLEN(*a),blen)))!=0 ) return r; else { if (LLEN(*a) > blen) return 1; else if (LLEN(*a) == blen) return 0; else return -1; } } /* Lcmp */
LispObj * LispNewObj () { LispObj *s; if (LispObjFreeQ) { s = LispObjFreeQ; LispObjFreeQ = LispObjFreeQ->n; if (LTYPE(s) == S_STRING) freeMagic(LSTR(s)); } else { s = (LispObj *) mallocMagic((unsigned) (sizeof(LispObj))); } s->t = S_INT; s->u.l = NULL; if (!LispObjAllocQ) LispObjAllocQTail = s; s->n = LispObjAllocQ; LispObjAllocQ = s; return s; }
/* --------------- Lhashvalue ------------------ */ dword __CDECL Lhashvalue( const PLstr str ) { dword value = 0; size_t i,l=0; if (LISNULL(*str)) return 0; switch (LTYPE(*str)) { case LINTEGER_TY: l = sizeof(long); break; case LREAL_TY: l = sizeof(double); break; case LSTRING_TY: l = MIN(255,LLEN(*str)); break; } for (i=0; i<l; i++) value = 31*value + LSTR(*str)[i]; /* for (i=0; i<l; i+=4) { for (j=0; j<4 && i+j<l; j++) value ^= LSTR(*str)[i+j] << (8*j); value = (value>>3) | (value<<29); } */ return value; } /* Lhashvalue */
/* ---------------- TraceSet -------------------- */ void __CDECL TraceSet( PLstr trstr ) { unsigned char *ch; L2STR(trstr); Lupper(trstr); LASCIIZ(*trstr); ch = LSTR(*trstr); if (*ch=='!') { ch++; } else if (*ch=='?') { _proc[_rx_proc].interactive_trace = 1 - _proc[_rx_proc].interactive_trace; if (_proc[_rx_proc].interactive_trace) #ifndef WIN fprintf(STDERR," +++ %s +++\n",errortext[2].errormsg); #else PUTS(" +++ "); PUTS(errortext[0].errormsg); PUTS(" +++\n"); #endif ch++; } switch (*ch) { case 'A': _proc[_rx_proc].trace = all_trace; break; case 'C': _proc[_rx_proc].trace = commands_trace; break; case 'E': _proc[_rx_proc].trace = error_trace; break; /* /// case 'F': /// _proc[_rx_proc].trace = ; /// break; */ case 'I': _proc[_rx_proc].trace = intermediates_trace; break; case 'L': _proc[_rx_proc].trace = labels_trace; break; case 'N': _proc[_rx_proc].trace = normal_trace; break; case 'O': _proc[_rx_proc].trace = off_trace; _proc[_rx_proc].interactive_trace = FALSE; break; case 'R': _proc[_rx_proc].trace = results_trace; break; case 'S': _proc[_rx_proc].trace = scan_trace; break; #ifdef __DEBUG__ case 'D': __debug__ = 1-__debug__; if (__debug__) printf("\n\nInternal DEBUG starting...\n"); else printf("\n\nInternal DEBUG ended\n"); break; #endif default: Lerror(ERR_INVALID_TRACE,1,trstr); } } /* TraceSet */
/* ----------------- TraceCurline ----------------- */ int __CDECL TraceCurline( RxFile **rxf, int print ) { size_t line; size_t cl, codepos; char *ch, *chend; if (symbolptr==NULL) { /* we are in intepret */ if (CompileClause==NULL) { if (rxf) *rxf = rxFileList; return -1; } codepos = (size_t)((byte huge *)Rxcip - (byte huge *)Rxcodestart); /* search for clause */ cl = 0; while (CompileClause[cl].ptr) { if (CompileClause[cl].code >= codepos) break; cl++; } cl--; line = CompileClause[cl].line; ch = CompileClause[cl].ptr; chend = CompileClause[cl+1].ptr; if (chend==NULL) for (chend=ch; *chend!='\n'; chend++) /*do nothing*/;; _nesting = _rx_proc + CompileClause[cl].nesting; if (rxf) *rxf = CompileClause[ cl ].fptr; } else { /* we are in compile */ if (CompileCurClause==0) cl = 0; else cl = CompileCurClause-1; _nesting = CompileClause[ cl ].nesting; if (rxf) { if (CompileCurClause==0) *rxf = CompileRxFile; else *rxf = CompileClause[ cl ].fptr; } if (_in_nextsymbol) { line = symboline; ch = symbolptr; while (ch>symbolprevptr) if (*ch--=='\n') line--; ch = symbolprevptr; } else if (cl==0) { line = 1; ch = (char*)LSTR((*rxf)->file); } else { cl = CompileCurClause-1; line = CompileClause[ cl ].line; ch = CompileClause[ cl ].ptr; } for (chend=ch; *chend!=';' && *chend!='\n'; chend++) /*do nothing*/;; } #ifndef WIN if (print) { int i; fprintf(STDERR,"%6zd *-* ",line); for (i=1; i<_nesting; i++) fputc(' ',STDERR); while (*ch && ch<chend) { if (*ch!='\n') fputc(*ch,STDERR); ch++; } fputc('\n',STDERR); } #else if (print) { int i; PUTINT(line,6,10); PUTS(" *-* "); for (i=1; i<_nesting; i++) PUTCHAR(' '); while (*ch && ch<chend) { if (*ch!='\n') PUTCHAR(*ch); ch++; } PUTCHAR('\n'); } #endif return line; } /* TraceCurline */
INIT static void lua_os_init() { str_sec = LSTR("sec"); str_min = LSTR("min"); str_hour = LSTR("hour"); str_day = LSTR("day"); str_month = LSTR("month"); str_year = LSTR("year"); str_wday = LSTR("wday"); str_yday = LSTR("yday"); str_isdst = LSTR("isdst"); str_collate = LSTR("collate"); str_ctype = LSTR("ctype"); str_monetary = LSTR("monetary"); str_numeric = LSTR("numeric"); str_time = LSTR("time"); lua_os = lhash_alloc(); cfunc_register(lua_os, "clock", lua_os_clock); cfunc_register(lua_os, "exit", lua_os_exit); cfunc_register(lua_os, "execute", lua_os_execute); cfunc_register(lua_os, "getenv", lua_os_getenv); cfunc_register(lua_os, "date", lua_os_date); cfunc_register(lua_os, "setlocale", lua_os_setlocale); cfunc_register(lua_os, "tmpname", lua_os_tmpname); cfunc_register(lua_os, "remove", lua_os_remove); cfunc_register(lua_os, "rename", lua_os_rename); lhash_set(lua_globals, LSTR("os"), lv_table(lua_os)); }
/* -------------------------------------------------------- */ int __CDECL _Lisnum( const PLstr s ) { bool F, R; register char *ch; int sign; int exponent; int expsign; int fractionDigits; lLastScannedNumber = 0.0; /* --- #ifdef USEOPTION if (LOPT(*s) & (LOPTINT | LOPTREAL)) { if (LOPT(*s) & LOPTINT) return LINTEGER_TY; else return LREAL_TY; } #endif --- */ ch = LSTR(*s); if (ch==NULL) return LSTRING_TY; LASCIIZ(*s); /* ///// Remember to erase LASCIIZ ///// before all the calls to Lisnum */ /* skip leading spaces */ while (ISSPACE(*ch)) ch++; /* accept one sign */ if (*ch=='-') { sign = TRUE; ch++; } else { sign=FALSE; if (*ch=='+') ch++; } /* skip following spaces after sign */ while (ISSPACE(*ch)) ch++; /* accept many digits */ R = FALSE; lLastScannedNumber = 0.0; fractionDigits=0; exponent=0; expsign=FALSE; if (IN_RANGE('0',*ch,'9')) { lLastScannedNumber = lLastScannedNumber*10.0 + (*ch-'0'); ch++; F = TRUE; while (IN_RANGE('0',*ch,'9')) { lLastScannedNumber = lLastScannedNumber*10.0 + (*ch-'0'); ch++; } if (!*ch) goto isnumber; } else F = FALSE; /* accept one dot */ if (*ch=='.') { R = TRUE; ch++; /* accept many digits */ if (IN_RANGE('0',*ch,'9')) { lLastScannedNumber = lLastScannedNumber*10.0 + (*ch-'0'); fractionDigits++; ch++; while (IN_RANGE('0',*ch,'9')) { lLastScannedNumber = lLastScannedNumber*10.0 + (*ch-'0'); fractionDigits++; ch++; } } else if (!F) return LSTRING_TY; if (!*ch) goto isnumber; } else if (!F) return LSTRING_TY; /* accept on 'e' or 'E' */ if (*ch=='e' || *ch=='E') { ch++; R = TRUE; /* accept one sign */ if (*ch=='-') { expsign = TRUE; ch++; } else if (*ch=='+') ch++; /* accept many digits */ if (IN_RANGE('0',*ch,'9')) { exponent = exponent*10+(*ch-'0'); ch++; while (IN_RANGE('0',*ch,'9')) { exponent = exponent*10+(*ch-'0'); ch++; } } else return LSTRING_TY; } /* accept many blanks */ while (ISSPACE(*ch)) ch++; /* is it end of string */ if (*ch) return LSTRING_TY; isnumber: if (expsign) exponent = -exponent; exponent -= fractionDigits; if (exponent) #ifdef __BORLAND_C__ lLastScannedNumber *= pow10(exponent); #else lLastScannedNumber *= pow(10.0,(double)exponent); #endif if (lLastScannedNumber>LONG_MAX) R = TRUE; /* Treat it as real number */ if (sign) lLastScannedNumber = -lLastScannedNumber; if (R) return LREAL_TY; return LINTEGER_TY; } /* _Lisnum */
/* --------------------------------------------------------------- */ void R_sqlbind( const int func ) { int col, i; double d; char type; if (!sqldb) Lerror(ERR_DATABASE,1); if (!sqlstmt) Lerror(ERR_DATABASE,0); if (ARGN==0) { Licpy(ARGR, sqlite3_bind_parameter_count(sqlstmt)); return; } if (ARGN!=3) Lerror(ERR_INCORRECT_CALL,0); if (Ldatatype(ARG1,'N')) col = Lrdint(ARG1); else { LASCIIZ(*ARG1); col = sqlite3_bind_parameter_index(sqlstmt, LSTR(*ARG1)); } get_pad(2, type); switch (type) { case 'b': case 'B': /* blob */ Licpy(ARGR, sqlite3_bind_blob(sqlstmt, col, LSTR(*ARG3), LLEN(*ARG3), SQLITE_TRANSIENT)); break; case 'i': case 'I': /* integer */ get_i(3, i); Licpy(ARGR, sqlite3_bind_int(sqlstmt, col, i)); break; case 'd': case 'D': /* double */ case 'f': case 'F': L2REAL(ARG3); Licpy(ARGR, sqlite3_bind_double(sqlstmt, col, LREAL(*ARG3))); break; case 's': case 'S': /* double */ case 't': case 'T': L2STR(ARG3); Licpy(ARGR, sqlite3_bind_text(sqlstmt, col, LSTR(*ARG3), LLEN(*ARG3), SQLITE_TRANSIENT)); break; case 'n': case 'N': /* null */ Licpy(ARGR, sqlite3_bind_null(sqlstmt, col)); break; case 'z': case 'Z': /* zero blob */ get_i(3, i); Licpy(ARGR, sqlite3_bind_zeroblob(sqlstmt, col, i)); break; default: Lerror(ERR_INCORRECT_CALL,0); } } /* R_sqlbind */