CORE_PROC(int, RelayOutput)( PDATAPATH pdp , PTEXT (CPROC *Datacallback)( PDATAPATH pdp, PTEXT pLine ) ) { extern int gbTrace; if( pdp->pPrior ) { int moved = 0; PTEXT p; //if( gbTrace ) // lprintf( WIDE("Relay output from %s to %s..........") // , GetText( pdp->pName ) // , GetText( pdp->pPrior->pName ) // ); while( ( p = (PTEXT)DequeLink( &pdp->Output ) ) ) { //if( gbTrace ) // lprintf( WIDE("Data is: %s"), GetText( p ) ); if( Datacallback && !( ( p->flags & TF_RELAY ) == TF_RELAY ) ) { for( p = Datacallback( pdp, p ); p; p = Datacallback( pdp, NULL ) ) { EnqueLink( &pdp->pPrior->Output, p ); } } else { #ifdef _DEBUG //PTEXT out = BuildLine( p ); //Log1( WIDE("Relay Out: %s"), GetText( out ) ); //LineRelease( out ); #endif EnqueLink( &pdp->pPrior->Output, p ); } } // stop relaying closes at datasource points //if( !pdp->pPrior->flags.Data_Source ) pdp->flags.Closed |= pdp->pPrior->flags.Closed; if( pdp->pPrior->Write ) moved = pdp->pPrior->Write( pdp->pPrior ); return moved; } else { PTEXT p; while( ( p = (PTEXT)DequeLink( &pdp->Output ) ) ) { if( gbTrace ) { PTEXT pLine = BuildLine( p ); lprintf( WIDE("Relay to dev NULL... Data is: %s"), GetText( pLine ) ); LineRelease( pLine ); } LineRelease( p ); } } return 0; }
CORE_PROC(int, RelayInput)( PDATAPATH pdp , PTEXT (CPROC *Datacallback)( PDATAPATH pdp, PTEXT pLine ) ) { extern int gbTrace; if( pdp->pPrior ) { PTEXT p; int moved = 0; if( gbTrace ) xlprintf(LOG_NOISE+1)( WIDE("Relay input from %s to %s..........") , GetText( pdp->pPrior->pName ) , GetText( pdp->pName ) ); do { if( pdp->pPrior->Read ) { pdp->pPrior->Read( pdp->pPrior ); } if( IsQueueEmpty( &pdp->pPrior->Input ) ) break; //Log( WIDE("Has some input to handle...") ); while( ( p = (PTEXT)DequeLink( &pdp->pPrior->Input ) ) ) { if( gbTrace ) lprintf( WIDE("Data is: %s"), GetText( p ) ); if( Datacallback && !( ( p->flags & TF_RELAY ) == TF_RELAY ) ) { //lprintf( WIDE("Data callback...") ); for( p = Datacallback( pdp, p ); p; p = Datacallback( pdp, NULL ) ) { moved++; if( p != (POINTER)1 ) EnqueLink( &pdp->Input, p ); else lprintf( WIDE("Data was consumed by datapath.") ); } } else { PTEXT out = BuildLine( p ); Log1( WIDE("Relay In: %s"), GetText( out ) ); LineRelease( out ); moved++; EnqueLink( &pdp->Input, p ); } } if( gbTrace && !moved && !pdp->pPrior->flags.Closed ) { lprintf( WIDE("Did not result in data, try reading source again, rerelay. %s %s"), GetText( pdp->pName ), GetText( pdp->pPrior->pName ) ); } } while( !moved && !pdp->pPrior->flags.Closed ); // stop relaying closes at datasource points //if( !pdp->pPrior->flags.Data_Source ) pdp->flags.Closed |= pdp->pPrior->flags.Closed; return moved; } return 0; }
int CPROC KeyGetGatheredLine( PCHAT_LIST list, LOGICAL sendAlt, PUSER_INPUT_BUFFER pci ) { PTEXT tmp_input = GetUserInputLine( pci ); PTEXT line = BuildLine( tmp_input ); // input is in segments of 256 characters... collapse into a single line. list->input.command_mark_start = list->input.command_mark_end = 0; if( line && GetTextSize( line ) ) { list->input.phb_Input->pBlock->pLines[0].flags.nLineLength = (int)LineLengthExEx( list->input.CommandInfo->CollectionBuffer, FALSE, 8, NULL ); list->input.phb_Input->pBlock->pLines[0].pLine = list->input.CommandInfo->CollectionBuffer; list->input.phb_Input->flags.bUpdated = 1; BuildDisplayInfoLines( list->input.phb_Input, 0, list->input_font ); if( line ) { if( sendAlt ) list->AltInputData( list->psvAltInputData, line ); else list->InputData( list->psvInputData, line ); } } else if( line ) LineRelease( line ); if( !line ) { if( sendAlt ) list->AltInputData( list->psvAltInputData, NULL ); else list->InputData( list->psvInputData, NULL ); } return UPDATE_COMMAND; }
//-------------------------------------- int CPROC CMD_GETPARTIAL( PSENTIENT ps, PTEXT parameters ) { if( ps->Data ) { PTEXT pSave, temp; pSave = parameters; if( ( temp = GetParam( ps, ¶meters ) ) ) { if( temp == pSave ) { DECLTEXT( msg, WIDE("Parameter to GetPartial was not a variable reference.") ); EnqueLink( &ps->Command->Output, &msg ); return FALSE; } if( GetIndirect( temp ) ) { LineRelease( GetIndirect( temp ) ); SetIndirect( temp, NULL ); } if( ps->Data->Partial ) { SetIndirect( temp, ps->Data->Partial ); ps->Data->Partial = NULL; if( ps->CurrentMacro ) ps->CurrentMacro->state.flags.bSuccess = TRUE; } } } return FALSE; }
int KeystrokePaste( PCONSOLE_INFO pdp ) { if( OpenClipboard(NULL) ) { uint32_t format; // successful open... format = EnumClipboardFormats( 0 ); while( format ) { //DECLTEXT( msg, " " ); //msg.data.size = sprintf( msg.data.data, "Format: %d", format ); //EnqueLink( pdp->ps->Command->ppOutput, SegDuplicate( (PTEXT)&msg ) ); #ifndef CF_TEXT #define CF_TEXT 1 #endif if( format == CF_TEXT ) { HANDLE hData = GetClipboardData( CF_TEXT ); LPVOID pData = GlobalLock( hData ); PTEXT pStroke = SegCreateFromText( pData ); int ofs, n; GlobalUnlock( hData ); n = ofs = 0; while( pStroke->data.data[n] ) { pStroke->data.data[ofs] = pStroke->data.data[n]; if( pStroke->data.data[n] == '\r' ) // trash extra returns... keep newlines { n++; continue; } else { ofs++; n++; } } pStroke->data.size = ofs; pStroke->data.data[ofs] = pStroke->data.data[n]; if( PSI_DoStroke( pdp, pStroke ) ) 1; // RenderCommandLine( pdp ); //EnqueLink( pdp->ps->Command->ppOutput, SegDuplicate(pStroke) ); LineRelease( pStroke ); break; } format = EnumClipboardFormats( format ); } CloseClipboard(); } else { #ifdef __DEKWARE__PLUGIN__ DECLTEXT( msg, "Clipboard was not available" ); EnqueLink( &pdp->common.Owner->Command->Output, &msg ); #endif } return 0; }
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; }
void DestroyProcess( PENTITY pe ) { PPROCESS process = (PPROCESS)GetLink( &pe->pPlugin, iProcess ); Log( WIDE("Killing process this represents") ); if( process ) { if( WaitForSingleObject( process->pi.hProcess, 0 ) == WAIT_TIMEOUT ) { TerminateProcess( process->pi.hProcess, 0xD1E ); } CloseHandle( process->pi.hProcess ); CloseHandle( process->pi.hThread ); LineRelease( process->command ); LineRelease( process->directory ); Release( process ); SetLink( &pe->pPlugin, iProcess, NULL ); } }
PTEXT win_get_line(HANDLE hFile) { // extern HANDLE hStdin; #define WORKSPACE 1024 // character for workspace PTEXT workline=(PTEXT)NULL; uint32_t length = 0; do { // create a workspace to read input from the file. workline=SegAppend(workline,SegCreate(WORKSPACE)); SetEnd( workline ); // read a line of input from the file. if( !ReadConsole( hFile , GetText(workline) , WORKSPACE , &length , NULL) ) // if no input read. { if (PRIORLINE(workline)) // if we've read some. { PTEXT t; workline=PRIORLINE(workline); // go back one. SegBreak(t = NEXTLINE(workline)); LineRelease(t); // destroy the current segment. } else { LineRelease(workline); // destory only segment. workline = NULL; } break; // get out of the loop- there is no more to read. } } while (GetText(workline)[length-1]!='\n'); //while not at the end of the line. if (workline&&length) // if I got a line, and there was some length to it. SetStart(workline); // set workline to the beginning. return(workline); // return the line read from the file. }
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 CHANGEDIR( PSENTIENT ps, PTEXT parameters ) { PTEXT pDir, pDir1; pDir1 = MacroDuplicateEx( ps, parameters, TRUE, TRUE ); if( pDir1 ) pDir = BuildLine( pDir1 ); else return FALSE; LineRelease( pDir1 ); if( SetCurrentPath( GetText( pDir ) ) ) { if( ps->CurrentMacro ) ps->CurrentMacro->state.flags.bSuccess = TRUE; else { DECLTEXT( msg, WIDE("Changed directory successfully.") ); { TEXTCHAR buf[257]; GetCurrentPath( buf, sizeof( buf ) ); SetDefaultFilePath( buf ); } EnqueLink( &ps->Command->Output, &msg ); } } else { if( !ps->CurrentMacro ) { DECLTEXT( msg, WIDE("Failed to change directory.") ); EnqueLink( &ps->Command->Output, &msg ); } } LineRelease( pDir ); 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; }
int CPROC TableDraw( PCOMMON pf ) { Image surface = GetFrameSurface( pf ); // and then I can draw like cards or something here? { int s, f; for( s = 0; s < 4; s++ ) for( f = 0; f < 13; f++ ) { if( l.card_image[s][f] ) BlotImage( surface, l.card_image[s][f], f * l.step_x, s * l.step_y ); } BlatColor( surface, 300, 10, l.width + l.step_x * 1, l.height, GetBaseColor( NORMAL ) ); BlatColor( surface, 300, 90, l.width + l.step_x * 4, l.height, GetBaseColor( NORMAL ) ); for( s = 0; s < l.nHand; s++ ) { BlotImage( surface, l.hand_image[s], 300 + s * l.step_x, 10 ); } for( s = 0; s < l.nTable; s++ ) { BlotImage( surface, l.table_image[s], 300 + s * l.step_x, 90 ); } { PTEXT hand_string = NULL; TEXTCHAR output[128]; GetPokerHandName( l.hand, &hand_string ); if( hand_string ) { snprintf( output, sizeof( output ), WIDE("%s "), GetText( hand_string ) ); PutString( surface, 50, 200, GetBaseColor( TEXTCOLOR ), GetBaseColor( NORMAL ), output ); } else PutString( surface, 50, 200, GetBaseColor( TEXTCOLOR ), GetBaseColor( NORMAL ), WIDE("Uhh no hand?!") ); LineRelease( hand_string ); } //UpdateFrame( pf, 0, 0, 0, 0 ); } return 1; }
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 ); }
static PTEXT CPROC ParseCommand( PMYDATAPATH pdp, PTEXT buffer ) { if( buffer ) { PTEXT pCommand; //Log2( WIDE("buffer: %s(%d)"), GetText( buffer ), GetTextSize( buffer ) ); //LogBinary( buffer ); pCommand = burst( buffer ); LineRelease( buffer ); if( pCommand ) { PTEXT pTemp, pStart; int bEscaped = FALSE; pStart = pTemp = pCommand; while( pTemp ) { if( TextIs( pTemp, WIDE("\\") ) ) { if( !bEscaped ) { PTEXT pNext; pNext = NEXTLINE( pTemp ); pNext->format.position.offset.spaces = pTemp->format.position.offset.spaces; LineRelease( SegGrab( pTemp ) ); bEscaped = TRUE; pTemp = pNext; continue; } } if( !bEscaped && TextIs( pTemp, WIDE(";") ) ) { PTEXT pPrior; //Log( WIDE("Splitting the line and enqueing it...") ); pPrior = pTemp; SegBreak( pTemp ); if( pStart != pTemp ) { // end of line included! pStart = SegAppend( pStart, SegCreate(0) ); EnqueLink( &pdp->output, pStart ); } pStart = pTemp = NEXTLINE( pTemp ); SegBreak( pTemp ); LineRelease( pPrior ); // remove ';' bEscaped = FALSE; continue; } bEscaped = FALSE; pTemp = NEXTLINE( pTemp ); } if( pStart ) { PTEXT line; line = BuildLine( pStart ); //Log1( WIDE("Enqueu: %s"), GetText( line ) ); LineRelease( line ); EnqueLink( &pdp->output, pStart ); } } else { // well what now? I guess pLine got put into Partial... // next pass through this all for command recall will blow... Log( WIDE("No information from the burst!") ); } } return (PTEXT)DequeLink( &pdp->output ); }
void HTTPCollapse( PTEXT *ppText ) { PTEXT output; PTEXT input = *ppText; while( input ) { if( GetText( input )[0] == '+' ) { PTEXT subst; // sometimes a + can be attached to a number // so much for the natural language parser dealing with // a machine oriented protocol... if( GetTextSize( input ) > 1 ) { SegSplit( &input, 1 ); } subst = GetSubst( '+' ); SegInsert( subst, input ); LineRelease( SegGrab( input ) ); input = subst; if( !PRIORLINE( input ) ) (*ppText) = input; } else if( TextIs( input, WIDE("%") ) ) { PTEXT next = NEXTLINE( input ); if( next ) { PTEXT subst; SegSplit( &next, 2 ); subst = GetSubst( *(unsigned short*)GetText( next ) ); if( subst ) { PTEXT nextnext = NEXTLINE( next ); PTEXT prior = SegBreak( input ); if( !prior ) { *ppText = SegAppend( subst, nextnext ); } if( nextnext ) { SegBreak( nextnext ); if( !prior ) *ppText = nextnext; else SegAppend( prior, nextnext ); SegInsert( subst, nextnext ); input = nextnext; continue; } else { SegAppend( prior, (PTEXT)&subst ); input = NULL; continue; } } // if not subst... just continue stepping, no replacement nessecary? } } input = NEXTLINE( input ); } output = BuildLine( *ppText ); LineRelease( *ppText ); (*ppText) = output; }
int GetInputData( int bWord, PSENTIENT ps, PTEXT parameters ) { if( ps->Data ) { PTEXT pSave, temp; PTEXT *pInd = NULL; pSave = parameters; lprintf( WIDE("Get data from datapath...") ); if( !( ( temp = GetParam( ps, ¶meters ) ) ) ) { lprintf( WIDE("No parameters specified to get line") ); LineRelease( ps->pLastResult ); ps->pLastResult = NULL; pInd = &ps->pLastResult; } else { if( temp == pSave ) { DECLTEXT( msg, WIDE("is not a valid variable reference.") ); EnqueLink( &ps->Command->Output, SegAppend( SegDuplicate( temp ), (PTEXT)&msg ) ); return FALSE; } if( temp->flags & TF_INDIRECT ) { LineRelease( GetIndirect( temp ) ); SetIndirect( temp, NULL ); pInd = (PTEXT*)&temp->data.size; } else { DECLTEXT( msg, WIDE("is not a valid variable reference(not indirect).") ); EnqueLink( &ps->Command->Output, SegAppend( SegDuplicate( temp ), (PTEXT)&msg ) ); return FALSE; } } if( !pInd ) { DECLTEXT( msg, WIDE("FATAL ERROR: Did not set pInd (GetLine)") ); EnqueLink( &ps->Command->Output, (PTEXT)&msg ); return FALSE; } // try grabbing an existing line - could be put there from BURST of prior... if( !ps->Data->CurrentWord ) // just got last word off line... { if( ps->Data->CurrentLine ) { LineRelease( ps->Data->CurrentLine ); ps->Data->CurrentLine = NULL; } } if( !ps->Data->CurrentLine ) { // Gather Data from input source.... // data from HT_CLIENT 'appears' asynchrous // to scripting.... if( ps->Data->Read ) ps->Data->Read( ps->Data ); // this returns a completeline... ps->Data->CurrentLine = (PTEXT)DequeLink( &ps->Data->Input ); } if( ps->Data->CurrentLine ) if( !ps->Data->CurrentWord ) ps->Data->CurrentWord = ps->Data->CurrentLine; if( ps->Data->CurrentWord ) { // indirect pointer will be null. if( bWord ) { *pInd = SegDuplicate( ps->Data->CurrentWord ); ps->Data->CurrentWord = NEXTLINE( ps->Data->CurrentWord ); } else { // duplicate to end of line... which may be whole - or // may be partial because of prior GETWORD from the line... // then release the data input line... // must duplicate the data in either case cause // it will be deleted with additional setting of the // variable... *pInd = TextDuplicate( ps->Data->CurrentWord, FALSE ); LineRelease( ps->Data->CurrentWord ); ps->Data->CurrentLine = NULL; // do NOT release this line... ps->Data->CurrentWord = NULL; // no word on line } } if( ps->CurrentMacro && *pInd ) ps->CurrentMacro->state.flags.bSuccess = TRUE; } return FALSE; }
// 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; }
CORE_PROC( PTEXT, GatherLineEx )( PTEXT *pOutput, INDEX *pIndex, int bInsert, int bSaveCR, int bData, PTEXT pInput ) // if data - assume data is coming from a preformatted source // otherwise use escape as command entry and clear buffer... { // this routine should be used to process user type character // input into a legible line buffer.... // results in a complete line.... // the line returned must be used - the output buffer // is an accumulator and will contain any partial input buffer // which remaineder if an EOL sequence was found.... // build line in buffer using standard console // behavior... INDEX pos , len = 0 , size , maxlen = 0; PTEXT pReturn = NULL; PTEXT pDelete = NULL; TEXTCHAR character; TEXTSTR output; if( !pOutput ) // must supply a holder for partial collection... return NULL; if( !pInput ) // nothing new input - just using previous collection... { if( *pOutput ) { // use prior partial as new input.... pInput = *pOutput; pDelete = pInput; // this is never deleted if we use prior... SetStart( pInput ); *pOutput = NULL; } else return NULL; } // probably first pass of gathering... if( !*pOutput ) { *pOutput = SegCreate( BUILD_LINE_OUTPUT_SIZE ); if( pIndex ) *pIndex = 0; SetTextSize( *pOutput, 0 ); output = GetText( *pOutput ); len = 0; } else if( pIndex ) { output = GetText( *pOutput ); len = *pIndex; if( (*pOutput)->data.size != len ) { if( bInsert ) { // creates a new segment inbetween here..... *pOutput = SplitLine( *pOutput, *pIndex ); output = GetText( *pOutput ); len = *pIndex = GetTextSize( *pOutput ); } else { maxlen = (*pOutput)->data.size; } } } else { output = GetText( *pOutput ); len = GetTextSize( *pOutput ); } while( pInput ) { size = GetTextSize( pInput ); for( pos = 0; pos < size; pos++ ) { switch( character = GetText( pInput )[pos] ) { case '\x1b': if( !bData ) { SetEnd( *pOutput ); SetStart( *pOutput ) { SetTextSize( *pOutput, 0 ); } SetTextSize( *pOutput, 0 ); output = GetText( *pOutput ); len = 0; } else goto defaultcase; break; case '\x7f': // handle unix type delete too ? perhaps... if( !bInsert ) { PTEXT pNext; // this will slide from the middle to the end... // if bInsert - then prior to entrying this switch // the data was split and THIS segment is set to zero. pNext = *pOutput; if( len != (maxlen = GetTextSize( *pOutput )) ) { MemCpy( output + len, output+len+1, maxlen - len ); SetTextSize( *pOutput, --maxlen ); } else { PTEXT pDel; pNext = *pOutput; do { pDel = pNext; pNext = NEXTLINE( pNext ); if( pDel != *pOutput ) { SegGrab( pDel ); LineRelease( pDel ); } } while( pNext && !GetTextSize( pNext ) ); if( pNext ) { size_t len2; output = GetText( pNext ); len2 = GetTextSize( pNext ) - 1; *pOutput = pNext; len = 0; MemCpy( output, output+1, len2 ); SetTextSize( pNext, len2 ); } } } else // was insert is either at end.... { // I dunno perform sliding delete operation... // must refresh the output string.... { PTEXT pNext, pDel; pNext = *pOutput; do { pDel = pNext; pNext = NEXTLINE( pNext ); if( pDel != *pOutput ) { SegGrab( pDel ); LineRelease( pDel ); } } while( pNext && !GetTextSize( pNext ) ); if( pNext ) { size_t len2; TEXTCHAR *data; data = GetText( pNext ); MemCpy( data, data+1, len2 = (GetTextSize( pNext ) - 1 )); SetTextSize( pNext, len2 ); } } } break; case '\b': /* perhaps consider using split for backspace in a line...*/ if( !bInsert ) { PTEXT pNext; size_t maxlen; // this will slide from the middle to the end... // if bInsert - then prior to entrying this switch // the data was split and THIS segment is set to zero. pNext = *pOutput; maxlen = GetTextSize( *pOutput ); while( !maxlen && PRIORLINE( *pOutput ) ) { *pOutput = PRIORLINE( *pOutput ); len = maxlen = GetTextSize( *pOutput ); } if( maxlen ) { if( len != maxlen ) { size_t sz; sz = maxlen - len; MemCpy( output + len - 1, output + len, sz ); SetTextSize( *pOutput, maxlen - 1 ); len--; } else { SetTextSize( *pOutput, --len ); } } } else // was insert is either at end.... { if( len ) { SetTextSize( *pOutput, --len ); } else { if( PRIORLINE( *pOutput ) ) { *pOutput = PRIORLINE( *pOutput ); len = GetTextSize( *pOutput ); } if( len ) SetTextSize( *pOutput, --len ); } } break; case '\r': // ignore this character... if( !bSaveCR ) break; // falls through .. past this and saves the return... if(0) case '\n': if( !pReturn ) { // transfer *pOutput to pReturn.... pReturn = *pOutput; SetEnd( pReturn ); output = GetText( pReturn ); len = GetTextSize( pReturn ); output[len] = character; SetTextSize( pReturn, ++len ); // begin next collection in case more data is in the input... *pOutput = SegCreate( BUILD_LINE_OUTPUT_SIZE ); SetTextSize( *pOutput, 0 ); output = GetText( *pOutput ); len = 0; break; } // store carriage return... default: defaultcase: output[len++] = character; if( (maxlen && len == maxlen ) || len == BUILD_LINE_OUTPUT_SIZE ) { PTEXT pTemp; SetTextSize( *pOutput, len ); if( !NEXTLINE( *pOutput ) ) { SegAppend( *pOutput, pTemp = SegCreate( BUILD_LINE_OUTPUT_SIZE ) ); SetTextSize( pTemp, 0 ); } else { pTemp = NEXTLINE( *pOutput ); maxlen = GetTextSize( pTemp ); } *pOutput = pTemp; output = GetText( *pOutput ); len = 0; } else { if( bInsert ) // insertion happens at end of segment // and the segment is broken... { if( !pIndex || ( len > *pIndex ) ) SetTextSize( *pOutput, len ); } else if( len > GetTextSize( *pOutput ) ) { SetTextSize( *pOutput, len ); } } break; } }
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 HandleArgs( int argc, TEXTCHAR **argv ) { PVARTEXT pvt = NULL; int arg = 1; if( argc == 1 ) { MessageBox( NULL, WIDE( "Available Arguments\n" ) WIDE( " -back $aarrggbb : set background color in hex, alpha, red, green, blue [default black]\n" ) WIDE( " -text $aarrggbb : set text color in hex, alpha, red, green, blue [default white]\n" ) WIDE( " -lines N : Set the target number of lines (font height, bigger number is smaller) [default 20]\n" ) WIDE( " -cols N : Set the target number of columns (font width, bigger number is smaller) [default 30]\n" ) WIDE( " -file <filename> : Use contents fo the file specified for text\n" ) WIDE( " -alpha : enable alpha transparency display\n" ) WIDE( " -dead : disable click and keyboard bypass\n" ) WIDE( " -display N : specify which display to show on\n" ) WIDE( " -timeout N : default time delay for no action (milliseconds)\n" ) WIDE( "\n" ) WIDE( " -notop : shows the banner as not topmost (default is top).\n" ) WIDE( " -yesno : shows the Yes/No buttons, and returns error level 0 for yes and 1 for no.\n" ) WIDE( " -okcancel : shows the Okay/Cancel buttons, and returns error level 0 for yes and 1 for no.\n" ) WIDE( " -yesno and -okaycancel : returns error level 0 for yes and 1 for no, 2 for cancel, 3 for ok.\n" ) WIDE( " \n" ) WIDE( " any other unknown argument or other word will show as text.\n" ) WIDE( " banner_command -back $20800010 -text $FF70A080 Show \"This Text On\" Banner\n" ) WIDE( " - the prior command will show 3 lines 'show', 'this text on', 'banner'" ) WIDE( " banner_command Show \"\\\"This Text On\\\"\" Banner\n" ) WIDE( " - the prior command shows how to include showing quotes" ) , WIDE( "Usage" ) , MB_OK ); return 0; } // default to topmost. l.flags.bTop = 1; while( arg < argc ) { if( argv[arg][0]=='-' ) { if( StrCaseCmp( argv[arg]+1, WIDE( "back" ) ) == 0 ) { // blah arg++; if( arg < argc ) { PTEXT tmp2; PTEXT tmp = SegCreateFromText( argv[arg] ); tmp2 = tmp; GetColorVar( &tmp, &l.back_color ); LineRelease( tmp2 ); } } else if( StrCaseCmp( argv[arg]+1, WIDE( "text" ) ) == 0 ) { arg++; if( arg < argc ) { PTEXT tmp2; PTEXT tmp = SegCreateFromText( argv[arg] ); tmp2 = tmp; GetColorVar( &tmp, &l.text_color ); LineRelease( tmp2 ); } } else if( StrCaseCmp( argv[arg]+1, WIDE( "lines" ) ) == 0 ) { arg++; if( arg < argc ) { #ifdef UNICODE l.lines = _wtoi( argv[arg] ); #else l.lines = atoi( argv[arg] ); #endif } } else if( StrCaseCmp( argv[arg]+1, WIDE( "cols" ) ) == 0 ) { arg++; if( arg < argc ) { #ifdef UNICODE l.columns = _wtoi( argv[arg] ); #else l.columns = atoi( argv[arg] ); #endif } } else if( StrCaseCmp( argv[arg]+1, WIDE( "display" ) ) == 0 ) { arg++; if( arg < argc ) { #ifdef UNICODE l.display = _wtoi( argv[arg] ); #else l.display = atoi( argv[arg] ); #endif } } else if( StrCaseCmp( argv[arg]+1, WIDE( "timeout" ) ) == 0 ) { arg++; if( arg < argc ) { #ifdef UNICODE l.timeout = _wtoi( argv[arg] ); #else l.timeout = atoi( argv[arg] ); #endif } } else if( StrCaseCmp( argv[arg]+1, WIDE( "dead" ) ) == 0 ) { l.flags.bDead = 1; } else if( StrCaseCmp( argv[arg]+1, WIDE( "alpha" ) ) == 0 ) { l.flags.bAlpha = 1; } else if( StrCaseCmp( argv[arg]+1, WIDE( "file" ) ) == 0 ) { // blah arg++; if( arg < argc ) { POINTER p; l.file = argv[arg]; p = OpenSpace( NULL, l.file, &l.text_size ); if( p ) { l.text = NewArray( TEXTCHAR, l.text_size + 1 ); MemCpy( l.text, p, l.text_size ); l.text[l.text_size] = 0; Release( p ); } } } else if( StrCaseCmp( argv[arg]+1, WIDE( "notop" ) ) == 0 ) { l.flags.bTop = 0; } else if( StrCaseCmp( argv[arg]+1, WIDE( "yesno" ) ) == 0 ) { l.flags.bYesNo = 1; } else if( StrCaseCmp( argv[arg]+1, WIDE( "okcancel" ) ) == 0 ) { l.flags.bOkayCancel = 1; } else { if( !pvt ) { pvt = VarTextCreate(); vtprintf( pvt, WIDE( "%s" ), argv[arg] ); } else vtprintf( pvt, WIDE( "\n%s" ), argv[arg] ); } } else { if( !pvt ) { pvt = VarTextCreate(); vtprintf( pvt, WIDE( "%s" ), argv[arg] ); } else vtprintf( pvt, WIDE( "\n%s" ), argv[arg] ); } arg++; } if( pvt ) { l.text = StrDup( GetText( VarTextPeek( pvt ) ) ); } if( !l.text ) { l.text = WIDE( "INVALID COMMAND LINE\nARGUMENTS" ) ; } else { int n = 0; int o = 0; for( n = 0; l.text[n]; n++ ) { if( l.text[n] < 32 ) { if( l.text[n] == '\n' ) { l.text[o++] = l.text[n]; } } else l.text[o++] = l.text[n]; } l.text[o++] = l.text[n]; } return 1; }
static uintptr_t CPROC HandleTaskOutput(PTHREAD thread ) { PTASK_INFO task = (PTASK_INFO)GetThreadParam( thread ); { task->pOutputThread = thread; // read input from task, montiro close and dispatch TaskEnd Notification also. { PHANDLEINFO phi = &task->hStdOut; PTEXT pInput = SegCreate( 4096 ); int done, lastloop; Hold( task ); done = lastloop = FALSE; do { uint32_t dwRead, dwAvail; if( done ) lastloop = TRUE; #ifdef _WIN32 //while( ) { #else while( CanRead( phi->handle ) ) #endif { if( task->flags.log_input ) lprintf( WIDE( "Go to read task's stdout." ) ); #ifdef _WIN32 if( !task->flags.process_ended && ReadFile( phi->handle , GetText( pInput ), (DWORD)(GetTextSize( pInput ) - 1) , (LPDWORD)&dwRead, NULL ) ) //read the pipe { #else dwRead = read( phi->handle , GetText( pInput ) , GetTextSize( pInput ) - 1 ); if( !dwRead ) { #ifdef _DEBUG //lprintf( WIDE( "Ending system thread because of broke pipe! %d" ), errno ); #endif #ifdef WIN32 continue; #else //lprintf( WIDE( "0 read = pipe failure." ) ); break; #endif } #endif if( task->flags.log_input ) lprintf( WIDE( "got read on task's stdout: %d" ), dwRead ); if( task->flags.bSentIoTerminator ) { if( dwRead > 1 ) dwRead--; else { if( task->flags.log_input ) lprintf( WIDE( "Finished, no more data, task has ended; no need for once more around" ) ); lastloop = 1; break; // we're done; task ended, and we got an io terminator on XP } } //lprintf( WIDE( "result %d" ), dwRead ); GetText( pInput )[dwRead] = 0; pInput->data.size = dwRead; //LogBinary( GetText( pInput ), GetTextSize( pInput ) ); if( task->OutputEvent ) { task->OutputEvent( task->psvEnd, task, GetText( pInput ), GetTextSize( pInput ) ); } pInput->data.size = 4096; #ifdef _WIN32 } else { DWORD dwError = GetLastError(); if( ( dwError == ERROR_OPERATION_ABORTED ) && task->flags.process_ended ) { if( PeekNamedPipe( phi->handle, NULL, 0, NULL, (LPDWORD)&dwAvail, NULL ) ) { if( dwAvail > 0 ) { lprintf( WIDE( "caught data" ) ); // there is still data in the pipe, just that the process closed // and we got the sync even before getting the data. } else break; } } } #endif } #ifdef _WIN32 } #endif //allow a minor time for output to be gathered before sending // partial gathers... if( task->flags.process_ended ) #ifdef _WIN32 { // Ending system thread because of process exit! done = TRUE; } #else //if( !dwRead ) // break; if( task->pid == waitpid( task->pid, NULL, WNOHANG ) ) { Log( WIDE( "Setting done event on system reader." ) ); done = TRUE; // do one pass to make sure we completed read } else { //lprintf( WIDE( "process active..." ) ); Relinquish(); } #endif } while( !lastloop ); #ifdef _DEBUG if( lastloop ) { //DECLTEXT( msg, WIDE( "Ending system thread because of process exit!" ) ); //EnqueLink( phi->pdp->&ps->Command->Output, &msg ); } else { //DECLTEXT( msg, WIDE( "Guess we exited from broken pipe" ) ); //EnqueLink( phi->pdp->&ps->Command->Output, &msg ); } #endif LineRelease( pInput ); #ifdef _WIN32 CloseHandle( task->hReadIn ); CloseHandle( task->hReadOut ); CloseHandle( task->hWriteIn ); CloseHandle( task->hWriteOut ); //lprintf( WIDE( "Closing process handle %p" ), task->pi.hProcess ); phi->hThread = 0; #else //close( phi->handle ); close( task->hStdIn.pair[1] ); close( task->hStdOut.pair[0] ); //close( task->hStdErr.pair[0] ); #define INVALID_HANDLE_VALUE -1 #endif if( phi->handle == task->hStdIn.handle ) task->hStdIn.handle = INVALID_HANDLE_VALUE; phi->handle = INVALID_HANDLE_VALUE; task->pOutputThread = NULL; Release( task ); //WakeAThread( phi->pdp->common.Owner ); return 0xdead; } } }
void ParseURI( CTEXTSTR string ) { int state; PTEXT words; PTEXT delete_seg = NULL; PTEXT line = SegCreateFromText( string ); PTEXT filename = NULL; PTEXT varname = NULL; PTEXT varvalue = NULL; PTEXT content = NULL; int content_length; struct { uint32_t bInvalid : 1; uint32_t bGet : 1; uint32_t bPost : 1; uint32_t bBinary : 1; // reading the content... uint32_t bValue : 1; } flags; // we got a line, therefore we can process it... // only thing then is the last line in the block ... state = GET_FILENAME; words = burst( line ); delete_seg = words; // though... LineRelease( line ); flags.bValue = 0; while( words ) { DECLTEXT( page, WIDE("page") ); DECLTEXT( CGI, WIDE("CGI") ); //printf( "state:%d word:%s \r\n",state, GetText(words ) ); // what does stuff have now? the whole thign? a line? if( !GetTextSize( words ) ) switch( state ) { case GET_HTTP_EOL: state = GET_HTTP_METAVAR; break; case GET_HTTP_METAVAR: case GET_CGI: goto AddCGIVariable; break; } else switch( state ) { case RESET: state = GET_COMMAND; continue; // skip ahead and try new state; break; case GET_COMMAND: if( TextLike( words, WIDE("GET") ) ) { state = GET_FILENAME; //flags.bGet = TRUE; } else if( TextLike( words, WIDE("POST") ) ) { state = GET_FILENAME; //flags.bPost = TRUE; } else { flags.bInvalid = TRUE; } break; case GET_FILENAME: if( !filename && TextIs( words, WIDE("/") ) ) { // this is rude, and should never be done, // however this filter consumes all data anyhow, SO // mangling this will not hurt much... words->format.position.offset.spaces = 0; } if( TextIs( words, WIDE("?") ) || words->format.position.offset.spaces ) { if( !words->format.position.offset.spaces ) state = GET_CGI; else state = GET_HTTP_VERSION; filename = NEXTLINE( filename ); LineRelease( SegBreak( filename ) ); HTTPCollapse( &filename ); //AddVariableExxx( ps, ps->Current, (PTEXT)&page, filename, FALSE,TRUE,TRUE DBG_SRC ); //AddVariable( ps, ps->Current, (PTEXT)&CGI, TextDuplicate( NEXTLINE( words ), FALSE ) ); LineRelease( filename ); filename = NULL; } else { filename = SegAppend( filename, SegDuplicate( words ) ); } break; case GET_CGI: if( words->format.position.offset.spaces ) { state = GET_HTTP_VERSION; goto AddCGIVariable; } else { if( TextIs( words, WIDE("=") ) ) { HTTPCollapse( &varname ); flags.bValue = 1; } else if( TextIs( words, WIDE("&") ) ) { AddCGIVariable: HTTPCollapse( &varvalue ); HTTPCollapse( &varname ); if( TextLike( varname, WIDE("content-length") ) ) { content_length= IntCreateFromText( GetText( varvalue ) ); } { struct VAR *v = New( struct VAR ); v->varname = varname; varname = NULL; v->varvalue = varvalue; varvalue = NULL; AddLink( &l.vars, v ); } //AddVariableExxx( ps, ps->Current, pmdp->varname, pmdp->varvalue, FALSE,TRUE,TRUE DBG_SRC ); //LineRelease( varname ); //LineRelease( varvalue ); //varname = NULL; //varvalue = NULL; flags.bValue = 0; } else { if( flags.bValue ) { varvalue = SegAppend( varvalue, SegDuplicate( words ) ); } else { //printf( "add var" ); varname = SegAppend( varname, SegDuplicate( words ) ); } } } break; case GET_HTTP_VERSION: if( TextIs( words, WIDE("HTTP") ) ) { // okay - don't really do anything... next word is the version... } else { // TextIs( words, "/" ); // this is a token before the number... // Version better be something like 1.1 1.0? // well wait for EOL... state = GET_HTTP_EOL; } break; case GET_HTTP_EOL: if( !GetTextSize( words ) ) { state = GET_HTTP_METAVAR; } break; case GET_HTTP_METAVAR: { if( !flags.bValue && TextIs( words, WIDE(":") ) ) { flags.bValue = TRUE; } else { if( flags.bValue ) { varvalue = SegAppend( varvalue, SegDuplicate( words ) ); } else { varname = SegAppend( varname, SegDuplicate( words ) ); } } } break; case GET_HTTP_CONTENT: if( !content_length ) { DebugBreak(); state = RESET; } else { // hmm we've parsed everything up to here, but now we need blocks, binary blocks. content = SegAppend( content, words ); if( LineLength( content ) == content_length ) { //ProcessPostCGI( common.Owner, content ); //AddVariableExxx( ps, ps->Current, (PTEXT)&CGI, content, FALSE,TRUE,TRUE DBG_SRC ); //AddVariable( ps, ps->Current, (PTEXT)&CGI, content ); LineRelease( content ); //InvokeBehavior( "http.request", common.Owner->Current, common.Owner, NULL ); //InvokeBehavior( "http_request", common.Owner->Current, common.Owner, NULL ); state = RESET; } words = NULL; } break; }