PTEXT GetPokerHandName( PHAND pHand, PTEXT *ppLastValue ) { int value; PVARTEXT pvt; if( *ppLastValue ) LineRelease( *ppLastValue ); pvt = VarTextCreate(); value = ValuePokerHand( pHand, NULL, TRUE ); if( !value ) { vtprintf( pvt, WIDE("No hand") ); } else switch( value >> 20 ) { case 0: vtprintf( pvt, WIDE("High Card - %s"), cardlongnames[ ((value>>16)&0xF)-1 ] ); break; case 1: vtprintf( pvt, WIDE("A Pair of %ss"), cardlongnames[ (value&0xF) ] ); break; case 2: vtprintf( pvt, WIDE("2 Pair %ss and %ss") , cardlongnames[ (value&0xF0)>>4] , cardlongnames[ (value&0xF) ] ); break; case 3: vtprintf( pvt, WIDE("3 of a Kind %ss"), cardlongnames[ (value&0xF) ] ); break; case 4: vtprintf( pvt, WIDE("Straight") ); break; case 5: vtprintf( pvt, WIDE("Flush") ); break; case 6: vtprintf( pvt, WIDE("Full House %ss over %ss") , cardlongnames[ (value&0xF0)>>4] , cardlongnames[ (value&0xF) ] ); break; case 7: vtprintf( pvt, WIDE("4 of a Kind %ss"), cardlongnames[(value&0xF0)>>4] ); break; case 8: vtprintf( pvt, WIDE("Straight Flush") ); break; case 9: vtprintf( pvt, WIDE("Royal Flush") ); break; case 10: vtprintf( pvt, WIDE("5 of a Kind %ss"), cardlongnames[value&0xF] ); break; } *ppLastValue = VarTextGet( pvt ); VarTextDestroy( &pvt ); return *ppLastValue; }
//-------------------------------------- int CPROC PARSE( PSENTIENT ps, PTEXT parameters ) { PTEXT temp; PTEXT devname; if( ( devname = GetParam( ps, ¶meters ) ) ) { // find device to see if it's already open... // by name! // but - this causes a problem for nested scripts // which are going to have to be artificiailly inceminated // with a unique name maybe something like script_##### PDATAPATH pdp = FindOpenDevice( ps, devname ); if( pdp ) { if( !ps->CurrentMacro ) { PVARTEXT pvt; pvt = VarTextCreate(); vtprintf( pvt, WIDE("Device named %s is already open."), GetText( devname ) ); EnqueLink( &ps->Command->Output, (POINTER)VarTextGet( pvt ) ); VarTextDestroy( &pvt ); } return -1; } if( ( temp = GetParam( ps, ¶meters ) ) ) { PDATAPATH pdp; lprintf( WIDE("Opening device handle named: %s"), GetText( devname ) ); if( ( pdp = OpenDevice( &ps->Data, ps, temp, parameters ) ) ) { while( devname->flags & TF_INDIRECT ) devname = GetIndirect( devname ); pdp->pName = SegDuplicate( devname ); if( pdp->Type ) { if( ps->CurrentMacro ) { ps->CurrentMacro->state.flags.bSuccess = TRUE; } } else { DestroyDataPath( pdp ); // new one did not finish open... } } } else { DECLTEXT( msg, WIDE("Parse must specify a name (/(parse/open) <name> <device> <options...)") ); EnqueLink( &ps->Command->Output, (PTEXT)&msg ); } } return FALSE; }
int SQLQueryf( PODBC odbc, CTEXTSTR *result, CTEXTSTR fmt, ... ) { int result_code; PTEXT cmd; PVARTEXT pvt = VarTextCreate(); va_list args; va_start( args, fmt ); vvtprintf( pvt, fmt, args ); cmd = VarTextGet( pvt ); VarTextDestroy( &pvt ); result_code = SQLQueryEx( odbc, (CTEXTSTR)GetText( cmd ), result DBG_ARGS(SQLQueryf) ); LineRelease( cmd ); return result_code; }
int DoSQLRecordQueryf( int *nResults, CTEXTSTR **result, CTEXTSTR **fields, CTEXTSTR fmt, ... ) { int result_code; PTEXT cmd; PVARTEXT pvt = VarTextCreate(); va_list args; va_start( args, fmt ); vvtprintf( pvt, fmt, args ); cmd = VarTextGet( pvt ); VarTextDestroy( &pvt ); result_code = SQLRecordQueryEx( NULL, GetText( cmd ), nResults, result, fields DBG_ARGS(DoSQLRecordQueryf) ); LineRelease( cmd ); return result_code; }
int DoSQLCommandf( CTEXTSTR fmt, ... ) { int result; PTEXT cmd; PVARTEXT pvt = VarTextCreate(); va_list args; va_start( args, fmt ); vvtprintf( pvt, fmt, args ); cmd = VarTextGet( pvt ); VarTextDestroy( &pvt ); result = DoSQLCommandEx( GetText( cmd ) DBG_ARGS(DoSQLCommandf) ); LineRelease( cmd ); return result; }
//-------------------------------------- int CPROC MEMORY( PSENTIENT ps, PTEXT parameters ) { uint32_t nFree, nUsed, nChunks, nFreeChunks; PVARTEXT vt; PTEXT temp, next; next = GetParam( ps, ¶meters ); while( temp = next ) { if( temp && TextLike( temp, WIDE("log") ) ) { temp = GetParam( ps, ¶meters ); if( temp && TextLike( temp, WIDE("off") ) ) SetAllocateLogging( FALSE ); else { SetAllocateLogging( TRUE ); if( temp ) { next = temp; continue; } } } if( temp && TextLike( temp, WIDE("debug") ) ) { temp = GetParam( ps, ¶meters ); if( temp && TextLike( temp, WIDE("off") ) ) SetAllocateDebug( TRUE ); else { SetAllocateDebug( FALSE ); if( temp ) { next = temp; continue; } } } next = GetParam( ps, ¶meters ); } GetMemStats( &nFree, &nUsed, &nChunks, &nFreeChunks ); vt = VarTextCreate( ); vtprintf( vt, WIDE("Memory : Free %ld(%ld), Used %ld(%ld) (optional paramters \'log\',\'debug\' followed by off to disable."), nFree, nFreeChunks, nUsed, nChunks - nFreeChunks ); EnqueLink( &ps->Command->Output, VarTextGet( vt ) ); VarTextDestroy( &vt ); return FALSE; }
int main( int argc, TEXTCHAR **argv ) { POPTION_TREE_NODE id_root = NULL; pvtSection = VarTextCreate(); if( argc > 1 ) { if( strcmp( argv[1], WIDE("-s") ) == 0 ) { static TEXTCHAR tmp[256]; if( argc > 2 ) { SystemPrefix = argv[2]; } else { #ifdef __NO_NETWORK__ snprintf( tmp, sizeof( tmp ), WIDE("/INI Store/localhost") ); #else snprintf( tmp, sizeof( tmp ), WIDE("/INI Store/%s"), GetSystemName() ); #endif SystemPrefix = tmp; } id_root = GetOptionIndex( id_root, WIDE("DEFAULT"), SystemPrefix, NULL ); if( !id_root ) return 0; } } { LISTFILL lf; MemSet( &lf, 0, sizeof( lf ) ); EnumOptions( id_root, FillList, (uintptr_t)&lf ); } { PTEXT pINI = VarTextGet( pvtIni ); CRYPTOEncryptMemory( GetText( pINI ), GetTextSize( pINI ) ); if( output ) { fwrite( GetText(pINI), 1, GetTextSize( pINI ), output ); LineRelease( pINI ); fclose( output ); output = NULL; } } return 0; }
int SQLCommandf( PODBC odbc, CTEXTSTR fmt, ... ) { int result; PTEXT cmd; PVARTEXT pvt = VarTextCreateExx( 4096, 16384 * 16 ); va_list args; va_start( args, fmt ); vvtprintf( pvt, fmt, args ); cmd = VarTextGet( pvt ); if( cmd ) { VarTextDestroy( &pvt ); result = SQLCommandEx( odbc, GetText( cmd ) DBG_ARGS(SQLCommandf) ); LineRelease( cmd ); } else lprintf( WIDE("ERROR: Sql format failed: %s"), fmt ); return result; }
// Run a program completely detached from the current process // it runs independantly. Program does not suspend until it completes. // No way at all to know if the program works or fails. SYSTEM_PROC( PTASK_INFO, LaunchPeerProgramExx )( CTEXTSTR program, CTEXTSTR path, PCTEXTSTR args , int flags , TaskOutput OutputHandler , TaskEnd EndNotice , uintptr_t psv DBG_PASS ) { PTASK_INFO task; if( program && program[0] ) { #ifdef WIN32 int launch_flags = ( ( flags & LPP_OPTION_NEW_CONSOLE ) ? CREATE_NEW_CONSOLE : 0 ) | ( ( flags & LPP_OPTION_NEW_GROUP ) ? CREATE_NEW_PROCESS_GROUP : 0 ) ; PVARTEXT pvt = VarTextCreateEx( DBG_VOIDRELAY ); PTEXT cmdline; PTEXT final_cmdline; LOGICAL needs_quotes; TEXTSTR expanded_path = ExpandPath( program ); char *new_path; TEXTSTR expanded_working_path = path?ExpandPath( path ):ExpandPath( WIDE(".") ); int first = TRUE; //TEXTCHAR saved_path[256]; task = (PTASK_INFO)AllocateEx( sizeof( TASK_INFO ) DBG_RELAY ); MemSet( task, 0, sizeof( TASK_INFO ) ); task->psvEnd = psv; task->EndNotice = EndNotice; if( l.ExternalFindProgram ) { new_path = l.ExternalFindProgram( expanded_path ); if( new_path ) { Release( expanded_path ); expanded_path = new_path; } } #ifdef _DEBUG xlprintf(LOG_NOISE)( WIDE("%s[%s]"), path, expanded_working_path ); #endif if( StrCmp( path, WIDE(".") ) == 0 ) { path = NULL; Release( expanded_working_path ); expanded_working_path = NULL; } if( expanded_path && StrChr( expanded_path, ' ' ) ) needs_quotes = TRUE; else needs_quotes = FALSE; if( needs_quotes ) vtprintf( pvt, WIDE( "\"" ) ); /* if( !IsAbsolutePath( expanded_path ) && expanded_working_path ) { //lprintf( "needs working path too" ); vtprintf( pvt, WIDE("%s/"), expanded_working_path ); } */ vtprintf( pvt, WIDE("%s"), expanded_path ); if( needs_quotes ) vtprintf( pvt, WIDE( "\"" ) ); if( flags & LPP_OPTION_FIRST_ARG_IS_ARG ) ; else { if( args && args[0] )// arg[0] is passed with linux programs, and implied with windows. args++; } while( args && args[0] ) { if( args[0][0] == 0 ) vtprintf( pvt, WIDE( " \"\"" ) ); else if( StrChr( args[0], ' ' ) ) vtprintf( pvt, WIDE(" \"%s\""), args[0] ); else vtprintf( pvt, WIDE(" %s"), args[0] ); first = FALSE; args++; } cmdline = VarTextGet( pvt ); vtprintf( pvt, WIDE( "cmd.exe /c %s" ), GetText( cmdline ) ); final_cmdline = VarTextGet( pvt ); VarTextDestroy( &pvt ); MemSet( &task->si, 0, sizeof( STARTUPINFO ) ); task->si.cb = sizeof( STARTUPINFO ); #ifdef _DEBUG xlprintf(LOG_NOISE)( WIDE( "quotes?%s path [%s] program [%s] [cmd.exe (%s)]"), needs_quotes?WIDE( "yes"):WIDE( "no"), expanded_working_path, expanded_path, GetText( final_cmdline ) ); #endif /* if( path ) { GetCurrentPath( saved_path, sizeof( saved_path ) ); SetCurrentPath( path ); } */ task->OutputEvent = OutputHandler; if( OutputHandler ) { SECURITY_ATTRIBUTES sa; sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; sa.nLength = sizeof( sa ); CreatePipe( &task->hReadOut, &task->hWriteOut, &sa, 0 ); //CreatePipe( &hReadErr, &hWriteErr, &sa, 0 ); CreatePipe( &task->hReadIn, &task->hWriteIn, &sa, 0 ); task->si.hStdInput = task->hReadIn; task->si.hStdError = task->hWriteOut; task->si.hStdOutput = task->hWriteOut; task->si.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; if( !( flags & LPP_OPTION_DO_NOT_HIDE ) ) task->si.wShowWindow = SW_HIDE; else task->si.wShowWindow = SW_SHOW; } else { task->si.dwFlags |= STARTF_USESHOWWINDOW; if( !( flags & LPP_OPTION_DO_NOT_HIDE ) ) task->si.wShowWindow = SW_HIDE; else task->si.wShowWindow = SW_SHOW; } { HINSTANCE hShellProcess = 0; int success = 0; #ifdef WIN32 if( flags & LPP_OPTION_IMPERSONATE_EXPLORER ) { HANDLE hExplorer = GetImpersonationToken(); if( ( CreateProcessAsUser( hExplorer, NULL //program , GetText( cmdline ) , NULL, NULL, TRUE , launch_flags | CREATE_NEW_PROCESS_GROUP , NULL , expanded_working_path , &task->si , &task->pi ) || FixHandles(task) || DumpError() ) || ( CreateProcessAsUser( hExplorer, program , GetText( cmdline ) , NULL, NULL, TRUE , launch_flags | CREATE_NEW_PROCESS_GROUP , NULL , expanded_working_path , &task->si , &task->pi ) || FixHandles(task) || DumpError() ) || ( CreateProcessAsUser( hExplorer, program , NULL // GetText( cmdline ) , NULL, NULL, TRUE , launch_flags | CREATE_NEW_PROCESS_GROUP , NULL , expanded_working_path , &task->si , &task->pi ) || FixHandles(task) || DumpError() ) || ( CreateProcessAsUser( hExplorer, WIDE( "cmd.exe" ) , GetText( final_cmdline ) , NULL, NULL, TRUE , launch_flags | CREATE_NEW_PROCESS_GROUP , NULL , expanded_working_path , &task->si , &task->pi ) || FixHandles(task) || DumpError() ) ) { success = 1; } CloseHandle( hExplorer ); } else #endif { if( ( CreateProcess( NULL //program , GetText( cmdline ) , NULL, NULL, TRUE , launch_flags | ( OutputHandler?CREATE_NO_WINDOW:0 )//CREATE_NEW_PROCESS_GROUP , NULL , expanded_working_path , &task->si , &task->pi ) || FixHandles(task) || DumpError() ) || ( CreateProcess( program , GetText( cmdline ) , NULL, NULL, TRUE , launch_flags | ( OutputHandler?CREATE_NO_WINDOW:0 )//CREATE_NEW_PROCESS_GROUP , NULL , expanded_working_path , &task->si , &task->pi ) || FixHandles(task) || DumpError() ) || ( CreateProcess( program , NULL // GetText( cmdline ) , NULL, NULL, TRUE , launch_flags | ( OutputHandler?CREATE_NO_WINDOW:0 )//CREATE_NEW_PROCESS_GROUP , NULL , expanded_working_path , &task->si , &task->pi ) || FixHandles(task) || DumpError() ) || ( TryShellExecute( task, expanded_working_path, program, cmdline ) ) || ( CreateProcess( NULL//WIDE( "cmd.exe" ) , GetText( final_cmdline ) , NULL, NULL, TRUE , launch_flags | ( OutputHandler?CREATE_NO_WINDOW:0 )//CREATE_NEW_PROCESS_GROUP , NULL , expanded_working_path , &task->si , &task->pi ) || FixHandles(task) || DumpError() ) || 0 ) { success = 1; } } if( success ) { //CloseHandle( task->hReadIn ); //CloseHandle( task->hWriteOut ); #ifdef _DEBUG xlprintf(LOG_NOISE)( WIDE("Success running %s[%s] in %s (%p): %d"), program, GetText( cmdline ), expanded_working_path, task->pi.hProcess, GetLastError() ); #endif if( OutputHandler ) { task->hStdIn.handle = task->hWriteIn; task->hStdIn.pLine = NULL; //task->hStdIn.pdp = pdp; task->hStdIn.hThread = 0; task->hStdIn.bNextNew = TRUE; task->hStdOut.handle = task->hReadOut; task->hStdOut.pLine = NULL; //task->hStdOut.pdp = pdp; task->hStdOut.bNextNew = TRUE; task->hStdOut.hThread = ThreadTo( HandleTaskOutput, (uintptr_t)task ); ThreadTo( WaitForTaskEnd, (uintptr_t)task ); } else { //task->hThread = ThreadTo( WaitForTaskEnd, (uintptr_t)task ); } } else { xlprintf(LOG_NOISE)( WIDE("Failed to run %s[%s]: %d"), program, GetText( cmdline ), GetLastError() ); CloseHandle( task->hWriteIn ); CloseHandle( task->hReadIn ); CloseHandle( task->hWriteOut ); CloseHandle( task->hReadOut ); CloseHandle( task->pi.hProcess ); CloseHandle( task->pi.hThread ); Release( task ); task = NULL; } } LineRelease( cmdline ); LineRelease( final_cmdline ); Release( expanded_working_path ); Release( expanded_path ); /* if( path ) SetCurrentPath( saved_path ); */ return task; #endif #ifdef __LINUX__ { pid_t newpid; TEXTCHAR saved_path[256]; xlprintf(LOG_ALWAYS)( WIDE("Expand Path was not implemented in linux code!") ); task = (PTASK_INFO)Allocate( sizeof( TASK_INFO ) ); MemSet( task, 0, sizeof( TASK_INFO ) ); task->psvEnd = psv; task->EndNotice = EndNotice; task->OutputEvent = OutputHandler; if( OutputHandler ) { pipe(task->hStdIn.pair); task->hStdIn.handle = task->hStdIn.pair[1]; pipe(task->hStdOut.pair); task->hStdOut.handle = task->hStdOut.pair[0]; } // always have to thread to taskend so waitpid can clean zombies. ThreadTo( WaitForTaskEnd, (uintptr_t)task ); if( path ) { GetCurrentPath( saved_path, sizeof( saved_path ) ); SetCurrentPath( path ); } if( !( newpid = fork() ) ) { char *_program = CStrDup( program ); // in case exec fails, we need to // drop any registered exit procs... //close( task->hStdIn.pair[1] ); //close( task->hStdOut.pair[0] ); //close( task->hStdErr.pair[0] ); if( OutputHandler ) { dup2( task->hStdIn.pair[0], 0 ); dup2( task->hStdOut.pair[1], 1 ); dup2( task->hStdOut.pair[1], 2 ); } DispelDeadstart(); //usleep( 100000 ); execve( _program, (char *const*)args, environ ); lprintf( WIDE( "Direct execute failed... trying along path..." ) ); { char *tmp = strdup( getenv( "PATH" ) ); char *tok; for( tok = strtok( tmp, ":" ); tok; tok = strtok( NULL, ":" ) ) { char fullname[256]; snprintf( fullname, sizeof( fullname ), "%s/%s", tok, _program ); lprintf( WIDE( "program:[%s]" ), fullname ); ((char**)args)[0] = fullname; execve( fullname, (char*const*)args, environ ); } Release( tmp ); } if( OutputHandler ) { close( task->hStdIn.pair[0] ); close( task->hStdOut.pair[1] ); } //close( task->hWriteErr ); close( 0 ); close( 1 ); close( 2 ); lprintf( WIDE( "exec failed - and this is ALLL bad... %d" ), errno ); //DebugBreak(); // well as long as this runs before // the other all will be well... task = NULL; // shit - what can I do now?! exit(0); // just in case exec fails... need to fault this. } else { if( OutputHandler ) { close( task->hStdIn.pair[0] ); close( task->hStdOut.pair[1] ); } } if( OutputHandler ) ThreadTo( HandleTaskOutput, (uintptr_t)task ); task->pid = newpid; lprintf( WIDE("Forked, and set the pid..") ); // how can I know if the command failed? // well I can't - but the user's callback will be invoked // when the above exits. if( path ) { // if path is NULL we didn't change the path... SetCurrentPath( saved_path ); } return task; } #endif } return FALSE; }
int main( int argc, char **argv ) { FILE *input = stdin; PVARTEXT pvt_cmd; TEXTCHAR readbuf[4096]; TEXTCHAR *buf; int offset = 0; int no_headers = 0; PODBC default_odbc = NULL; CTEXTSTR select_into; PLIST output = NULL; PLIST outputs = NULL; int arg_ofs = 0; SQLSetFeedbackHandler( ShowSQLStates ); //SetAllocateDebug( TRUE ); //SetAllocateLogging( TRUE ); if( argc < 2 ) Usage( 1 ); else { while( argv[1+arg_ofs] && ( argv[1+arg_ofs][0] == '-' ) ) { TEXTSTR tmp; switch( argv[1+arg_ofs][1] ) { case 'n': no_headers = 1; break; case 'f': arg_ofs++; input = sack_fopen( 0, tmp = DupCharToText( argv[1+arg_ofs] ), WIDE("rt") ); if( input ) SQLSetFeedbackHandler( LogSQLStates ); break; } if( tmp ) { Deallocate( TEXTSTR, tmp ); tmp = NULL; } arg_ofs++; } if( argv[1+arg_ofs] ) default_odbc = ConnectToDatabase( DupCharToText( argv[1 + arg_ofs] ) ); } SetHeapUnit( 4096 * 1024 ); // 4 megs expansion if needed... pvt_cmd = VarTextCreateExx( 10000, 50000 ); while( (buf = readbuf), fgets( readbuf + offset , sizeof( readbuf ) - offset , input ) ) { CTEXTSTR *result = NULL; size_t len; while( buf[0] == WIDE(' ') || buf[0] == WIDE('\t') ) buf++; len = strlen( buf ); if( buf[0] == WIDE('#') ) continue; if( ( len > 0 ) && buf[len-1] == WIDE('\n') ) { len--; buf[len] = 0; } if( strcmp( buf, WIDE("\\q") ) == 0 ) break; if( !buf[0] && VarTextLength( pvt_cmd ) == 0 ) continue; if( ( len > 0 ) && buf[len-1] == WIDE('\\') ) { buf[len-1] = 0; len--; vtprintf( pvt_cmd, WIDE("%s"), buf ); offset = 0; //offset = (len - 1); // read over the slash continue; } else { if( len > 0 ) vtprintf( pvt_cmd, WIDE("%s"), buf ); offset = 0; } buf = GetText( VarTextPeek( pvt_cmd ) ); if( buf[0] == WIDE('?') ) { int fields; int replace = 0; int ofs = 1; CTEXTSTR *columns; TEXTSTR *_columns; PVARTEXT pvt = NULL; if( buf[1] == WIDE('!') ) { replace = 1; ofs = 2; } if( output ) { if( !select_into || !select_into[0] ) { printf( WIDE("Table name was invalid to insert into on the destination side...\'%s\'"), select_into ); VarTextEmpty( pvt_cmd ); continue; } pvt = VarTextCreateExx( 10000, 50000 ); } if( SQLRecordQuery( default_odbc, buf + ofs, &fields, &result, &columns ) ) { int count = 0; int first = 1; _columns = NewArray( TEXTSTR, fields ); if( !no_headers ) { { int n; for( n = 0; n < fields; n++ ) { _columns[n] = StrDup( columns[n] ); if( !pvt ) fprintf( stdout, WIDE("%s%s"), n?WIDE(","):WIDE(""), columns[n] ); } } if( !pvt ) fprintf( stdout, WIDE("\n") ); } for( ; result; FetchSQLRecord( default_odbc, &result ) ) { if( pvt && first ) { vtprintf( pvt, WIDE("%s into `%s` ("), replace?WIDE("replace"):WIDE("insert ignore"), select_into ); { int first = 1; int n; for( n = 0; n < fields; n++ ) { vtprintf( pvt, WIDE("%s`%s`"), first?WIDE(""):WIDE(","), _columns[n] ); first = 0; } } vtprintf( pvt, WIDE(") values ") ); } if( pvt ) { vtprintf( pvt, WIDE("%s("), first?WIDE(""):WIDE(",") ); { int first = 1; // private first, sorry :) parse that, Visual studio can. int n; for( n = 0; n < fields; n++ ) { TEXTSTR tmp; vtprintf( pvt, WIDE("%s%s") , first?WIDE(""):WIDE(",") , result[n]?(tmp=EscapeStringOpt( result[n], TRUE)):((tmp=NULL),WIDE("NULL")) ); Release( tmp ); first = 0; } } vtprintf( pvt, WIDE(")") ); } else { int n; int first = 1; for( n = 0; n < fields; n++ ) { fprintf( stdout, WIDE("%s%s"), first?WIDE(""):WIDE(","),result[n]?result[n]:WIDE("NULL") ); first = 0; } fprintf( stdout, WIDE("\n") ); } first = 0; count++; if( ( VarTextLength( pvt ) ) > 100000 ) { PTEXT cmd; first = 1; // reset first to rebuild the beginning of the insert. printf( WIDE("Flushing at 100k characters...%d records\n"), count ); if( pvt ) { cmd = VarTextGet( pvt ); if( cmd ) { INDEX idx; PODBC odbc; LIST_FORALL( output, idx, PODBC, odbc ) { if( !SQLCommand( odbc, GetText( cmd ) ) ) printf( WIDE("Failed command to:%s\n"), (CTEXTSTR)GetLink( &outputs, idx ) ); } LineRelease( cmd ); } } } } if( !no_headers ) { int n; for( n = 0; n < fields; n++ ) { Release( _columns[n] ); } } Release( _columns ); }
int CPROC FillList( uintptr_t psv, CTEXTSTR name, POPTION_TREE_NODE ID, int flags ) { PLISTFILL plf = (PLISTFILL)psv; LISTFILL lf = *plf; if( StrCmp( name, WIDE(".") ) == 0 ) return TRUE; lf.nLevel++; lf.flags.bSecondLevel = 1; lprintf( WIDE("%d - %s (%p)"), plf->nLevel, name, ID ); { if( lf.nLevel == 1 ) { if( pvtIni ) { PTEXT pINI = VarTextGet( pvtIni ); CRYPTOEncryptMemory( GetText( pINI ), GetTextSize( pINI ) ); if( output ) { fwrite( GetText(pINI), 1, GetTextSize( pINI ), output ); LineRelease( pINI ); fclose( output ); output = NULL; } VarTextDestroy( &pvtIni ); } // if it's this branch, then don't auto export it. if( StrCmp( name, WIDE("INI Store") ) == 0 ) return TRUE; pvtIni = VarTextCreate(); output = sack_fopen( 0, name, WIDE("wt") ); } else if( lf.nLevel == 2 ) { lprintf( WIDE("Section %s"), name ); vtprintf( pvtSection, WIDE("%s"), name ); } else if( lf.nLevel >= 3 ) { POPTION_TREE_NODE ID_Value = GetOptionValueIndex( ID ); if( ID_Value ) { TEXTCHAR buffer[256]; if( (int)GetOptionStringValue( ID_Value, buffer, sizeof( buffer ) ) > 0 ) { if( VarTextPeek( pvtSection ) ) { PTEXT section =VarTextGet( pvtSection ); vtprintf( pvtIni, WIDE("[%s]\n"), GetText( section ) ); LineRelease( section ); } vtprintf( pvtIni, WIDE("%s=%s\n"), name, buffer ); } else { vtprintf( pvtSection, WIDE("/%s"), name ); } } else { vtprintf( pvtSection, WIDE("/%s"), name ); } } } EnumOptions( ID, FillList, (uintptr_t)&lf ); //lprintf( WIDE("done with all children under this node.") ); return TRUE; }
//-------------------------------------- int CPROC COMMAND( PSENTIENT ps, PTEXT parameters ) { PTEXT temp; PTEXT devname; if( ( devname = GetParam( ps, ¶meters ) ) ) { // find device to see if it's already open... // by name! // but - this causes a problem for nested scripts // which are going to have to be artificiailly inceminated // with a unique name maybe something like script_##### PDATAPATH pdp = FindOpenDevice( ps, devname ); if( pdp ) { if( !ps->CurrentMacro ) { PVARTEXT pvt; pvt = VarTextCreate(); vtprintf( pvt, WIDE("Device named %s is already open."), GetText( devname ) ); EnqueLink( &ps->Command->Output, (POINTER)VarTextGet( pvt ) ); VarTextDestroy( &pvt ); } return -1; } if( ( temp = GetParam( ps, ¶meters ) ) ) { PDATAPATH pdp; //lprintf( WIDE("Opening device handle named: %s"), GetText( devname ) ); if( ( pdp = OpenDevice( &ps->Command, ps, temp, parameters ) ) ) { PTEXT pCommand; PDATAPATH pOldPath; while( devname->flags & TF_INDIRECT ) devname = GetIndirect( devname ); pdp->pName = SegDuplicate( devname ); if( ps->Command ) { // remove old command queue so close won't remove // ps->Command->Input = NULL; // close the command queue... // update to the new queue in the sentience // if the new one is a data source, then we // need to move old commands to new path - // otherwise they may/will get lost. if( ps->Command->flags.Data_Source && !ps->Command->flags.Dont_Relay_Prior) { pOldPath = ps->Command->pPrior; // move all commands from old queue to new queue while( ( pCommand = (PTEXT)DequeLink( &pOldPath->Input ) ) ) { EnqueLink( &ps->Command->Input, pCommand ); } while( ( pCommand = (PTEXT)DequeLink( &pOldPath->Output ) ) ) { EnqueLink( &ps->Command->Output, pCommand ); } } } if( ps->CurrentMacro ) ps->CurrentMacro->state.flags.bSuccess = TRUE; } } else { DECLTEXT( msg, WIDE("Command must specify a name (/command <name> <device> <options...)") ); EnqueLink( &ps->Command->Output, (PTEXT)&msg ); } } return FALSE; }