Beispiel #1
0
int FillControlsList( PSI_CONTROL control, int nLevel, CTEXTSTR basename, CTEXTSTR priorname )
{
	CTEXTSTR name;
	PCLASSROOT data = NULL;
	PVARTEXT pvt = NULL;
	int added = 0;
	PLISTITEM pli;
	if( priorname )
	{
		pli = AddListItemEx( control, nLevel, priorname );
	}
	for( name = GetFirstRegisteredName( basename, &data );
		 name;
		  name = GetNextRegisteredName( &data ) )
	{
		pvt = VarTextCreate();
		vtprintf( pvt, WIDE("%s/%s"), basename, name );
		if( priorname &&
			( strcmp( name, WIDE( "button_create" ) ) == 0 ) )
		{
			// okay then add this one...
			//snprintf( newname, sizeof( newname ), WIDE("%s/%s"), basename, name );
			//if( NameHasBranches( &data ) )
			{
				// eat the first two parts - intershell/controls/
				// create the control name as that...
				CTEXTSTR controlpath = strchr( basename, '/' );
				if( controlpath )
				{
					controlpath++;
					controlpath = strchr( controlpath, '/' );
					if( controlpath )
						controlpath++;
				}
				//AddLink( &g.extra_types, StrDup( basename ) );
				added++;
				SetItemData( pli, (uintptr_t)StrDup( controlpath ) );
				break;
			}
		}
		else
		{
			if( NameHasBranches( &data ) )
			{
				added += FillControlsList( control, nLevel+1, GetText( VarTextPeek( pvt ) ), name );
			}
		}
	}
	if( !added )
		DeleteListItem( control, pli );
	VarTextDestroy( &pvt );
	return added;
}
Beispiel #2
0
int main ( void )
{
	genxWriter w;
	genxElement header;
	genxElement body;
   genxElement html;
	genxStatus status;
   int n;
	PVARTEXT pvt = VarTextCreate();


	w = genxNew(NULL,NULL,NULL);

	genxSetUserData( w, (void*)pvt );
	html = genxDeclareElement( w, NULL, (constUtf8)"HTML", &status );
	header = genxDeclareElement( w, NULL, (constUtf8)"header", &status );
   body = genxDeclareElement( w, NULL, (constUtf8)"body", &status );

	genxStartDocSender( w, &senderprocs );
	n = 	genxPI( w, "xml", "version=\"1.0\" encoding=\"UTF-8\"" );

	printf( "result:%d\n", n );
	genxStartElement( html );
	{
		genxStartElement( header );
		genxAddText( w, "Header Here" );
		genxEndElement( w );

		genxStartElement( body );
		genxAddText( w, "body Here" );
		genxEndElement( w );
	}
	genxEndElement( w );

	genxEndDocument( w );

	printf( "Result Document:\n\n" );
   printf( "%s", GetText( VarTextPeek( pvt ) ) );
   return 0;
}
Beispiel #3
0
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 );
			}
Beispiel #4
0
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;
}
Beispiel #5
0
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;
}