Esempio n. 1
0
void zCmdParseCommandLine( int argc, char **argv, ZHashTable &hash ) {
	int nonOptionArgCount=0;
	for( int i=0; i<argc; i++ ) {
		if( argv[i][0] == '-' ) {
			// Does the option have a value assignment?
			char *valPtr = 0;
			for( int j=0; argv[i][j]; j++ ) {
				if( argv[i][j] == '=' ) {
					valPtr = &argv[i][j+1];
					argv[i][j] = 0;
					break;
				}
			}

			hash.putS( argv[i], valPtr ? valPtr : (char *)"*novalue*" );

			int len = strlen( argv[i] );
			char *indexKey = new char[len + 16];
			strcpy( indexKey, argv[i] );
			strcat( indexKey, "-index" );

			hash.putI( indexKey, i );
		}
		else {
			char key[32];
			sprintf( key, "nonOptionArg%d", nonOptionArgCount++ ); 
			hash.putS( key, argv[i] );
		}
	}
}
Esempio n. 2
0
void startup() {
	// get the compartments definition from the .cfg file,
	// we expect it to be a series of halftime:maxLoad pairs
	// separated by commas (e.g. 120:90,60:80,45:50 etc)
	char *compartDef = options.getS( "compartments" );
	if( !compartDef ) {
		compartDef = "120:90,60:80,45:50,30:30,20:20,15:15,10:10";
		trace( "no comparments defined; using builtin values.\n" );
	}
	trace( "compartments set to: %s\n", compartDef );
	char *tok = strtok( compartDef, "," );
	while( tok ) {
		int htime;
		double maxload;
		sscanf( tok, "%d:%lf", &htime, &maxload );
		//maxload *= 3.2808399;
			// convert meters to feet
		//maxload /= 10.0;	
			// convert meters of seawater to bars
		
		Compartment *c = new Compartment( htime, maxload );
		compartments.add( c );

		trace( "New compartment added: time %d minutes, maxload %g fsw\n", htime, maxload );

		tok = strtok( NULL, "," );
	}

	zglFontLoad( "verdana60", zlabCorePath( "verdana.ttf" ), 60 );


	/*
	ZUI *zui = ZUI::factory( 0, "ZUIVar" );
	zui->putS( "text", "Depth" );
	zui->putS( "val", "1.0" );
	ZUI *plug = ZUI::zuiFindByName( "pluginPanel" );
	if( plug ) {
		zui->attachTo( plug );
	}
	*/
}
Esempio n. 3
0
int main() {
	char *test1[] = {
		"A bunch of,stuff,divided by,commas",
		"A line with no commas",
		"A line with one field and an empty trailing field,",
		",A line with trailing field",
		",,A,B",
		",,,",
		",",
		"",
		NULL
	};
	int test1Lens[] = { 4, 1, 2, 2, 4, 4, 2, 1, 1 };

	char *test2[] = {
		"This is a test",
		"This   is   a test",
		"This   is   a test    ",
		"   ",
		"",
		NULL,
	};

	for( int i=0; i<sizeof(test1)/sizeof(test1[0]); i++ ) {
		ZStr *z = zStrSplit( ",", test1[i] );
		assert( zStrCount( z ) == test1Lens[i] );
		char *join = zStrJoin(",",z);
		assert( !test1[i] || !strcmp( join, test1[i] ) );
	}

	for( i=0; i<sizeof(test2)/sizeof(test2[0]); i++ ) {
		ZStr *z = zStrSplit( " +", test2[i] );
		switch( i ) {
			case 0:
			case 1:
				assert( z && !strcmp( *z, "This" ) ); z=z->next;
				assert( z && !strcmp( *z, "is" ) ); z=z->next;
				assert( z && !strcmp( *z, "a" ) ); z=z->next;
				assert( z && !strcmp( *z, "test" ) ); z=z->next;
				assert( !z );
				break;
			case 2:
				assert( z && !strcmp( *z, "This" ) ); z=z->next;
				assert( z && !strcmp( *z, "is" ) ); z=z->next;
				assert( z && !strcmp( *z, "a" ) ); z=z->next;
				assert( z && !strcmp( *z, "test" ) ); z=z->next;
				assert( z && !strcmp( *z, "" ) ); z=z->next;
				assert( !z );
				break;
			case 3:
				assert( z && !strcmp( *z, "" ) ); z=z->next;
				assert( z && !strcmp( *z, "" ) ); z=z->next;
				assert( !z );
				break;
			case 4:
			case 5:
				assert( z && !strcmp( *z, "" ) ); z=z->next;
				assert( !z );
				break;
		}
	}

	char *test3[] = {
		"key1=val1 key2=val2",
		"key1=val1",
		"",
		"=",
		"key1",
		"key1='val1'",
		"key1='val1' key2='val2' key3 = 'val3'",
		"key1='val1' key2=\"val2\" key3 = \"val3\"",
		"'key1'=val1 \"key2\"=\"val2\" key3 = \"val3\"",
	};

	for( i=0; i<sizeof(test3)/sizeof(test3[0]); i++ ) {
		ZHashTable hash;
		zStrHashSplit( test3[i], &hash );
		char *v1 = hash.get( "key1" );
		char *v2 = hash.get( "key2" );
		char *v3 = hash.get( "key3" );
		char *_v1, *_v2, *_v3;
		switch( i ) {
			case 0: _v1="val1"; _v2="val2"; _v3=""; break;
			case 1: _v1="val1"; _v2=""; _v3=""; break;
			case 2: _v1=""; _v2=""; _v3=""; break;
			case 3: _v1=""; _v2=""; _v3=""; break;
			case 4: _v1=""; _v2=""; _v3=""; break;
			case 5: _v1="val1"; _v2=""; _v3=""; break;
			case 6: _v1="val1"; _v2="val2"; _v3="val3"; break;
			case 7: _v1="val1"; _v2="val2"; _v3="val3"; break;
			case 8: _v1="val1"; _v2="val2"; _v3="val3"; break;
		}
		assert( (!v1 || !strcmp(v1,_v1)) && (!v2 || !strcmp(v2,_v2)) && (!v3 || !strcmp(v3,_v3)) );
	}

	return 0;
}
Esempio n. 4
0
int main( int argc, char **argv ) {
	ZHashTable options;

//ZHashTable test;
//test.putS( "type", "Login" );
//zHashTablePack( test );

	// LOAD options
	zConfigLoadFile( "diwos.cfg", options );
	zCmdParseCommandLine( argc, argv, options );
		// cmdline may override .cfg files

	loadAll();

	int listenPort = options.getI("--port",59997);
	if( listenPort ) {
		trace( "Server listening on port: %d\n", listenPort );

		ZMsgZocket test;

		// OPEN the listening zocket
		ZMsgZocket *server = new ZMsgZocket( ZTmpStr("tcp://*:%d", listenPort), ZO_LISTENING );
		assert( server && server->isOpen() );
	}

	zMsgSetHandler( "default", ZMsgZocket::dispatch );

	int cmdLen = 0;
	char cmd[1024] = {0,};

	zconsoleCharMode();

	while( 1 ) {
		zMsgDispatch();

		ZMsgZocket::wait( 1000, 1 );
		ZMsgZocket::readList();
		update();

		if( zconsoleKbhit() ) {
			char c = zconsoleGetch();

			if( cmdLen < sizeof(cmd)-1 ) {
				if( c == '\r' || c == '\n' ) {
					cmdLen = 0;

					ZMsg *z = new ZMsg;
					z->putS( "type", "Command" );
					z->putS( "cmd", cmd );
					zMsgQueue( z );

					printf( "\n" );
				}
				else {
					cmd[cmdLen++] = c;
					cmd[cmdLen] = 0;
				}
			}
		}
	}

	return 0;
}
Esempio n. 5
0
void GUIAttrEdit::render() {
	GUIPanel::render();

	float lineH = getLineH();
	int scroll = getAttrI( "scroll" );

	glDisable( GL_BLEND );
	float y = myH - lineH;

	for( int extra=scroll; extra<0; extra++ ) {
		y -= lineH;
		if( y < 0 ) break;
	}

	int textColor = getAttrI( "textColor" );
	int selectedTextColor = getAttrI( "selectedTextColor" );
	int highlightedTextColor = getAttrI( "highlightedTextColor" );

	ZHashTable *hash = (ZHashTable *)attributeTable->getp( "hashPtr" );
	if( !hash ) return;

	for( int i=0; i<view.count; i++ ) {
		int highlighted = (i == mouseOver && mouseWasInside);
	
		if( i == selected ) {
			setColorI( selectedTextColor );
		}
		else if( highlighted ) {
			setColorI( highlightedTextColor );
		}
		else {
			setColorI( textColor );
		}

		if( i >= scroll ) {
			char buf[1024];
			char *val = hash->getS( view[i] );
			sprintf( buf, "%s = %s", view[i], val );
			print( buf, 12, y );
			y -= lineH;
		}

		if( y <= 0 ) {
			break;
		}
	}

	if( !optMenuUp && selected != -1 ) {
		glDisable( GL_LINE_SMOOTH );
		glLineWidth( 1.f );
		glColor3ub( 0xff, 0, 0 );
		glBegin( GL_LINES );
			glVertex2f( selectX, selectY );
			glVertex2f( selectX, mouseY );

			float sign = mouseY > selectY ? -1.f : 1.f;
			glVertex2f( selectX, mouseY );
			glVertex2f( selectX-5, mouseY + sign*5 );

			glVertex2f( selectX, mouseY );
			glVertex2f( selectX+5, mouseY + sign*5 );
		glEnd();
	}
}
Esempio n. 6
0
void GUIAttrEdit::handleMsg( ZMsg *msg ) {
	float lineH = getLineH();

	int scroll = getAttrI( "scroll" );

	float x = zmsgF(localX);
	float y = zmsgF(localY);

	if( zmsgIs(type,Key) && zmsgIs(which,wheelforward) ) {
		if( contains(x,y) ) {
			scroll-=2;
			scroll = max( -10, scroll );
			scroll = min( view.count-5, scroll );
			setAttrI( "scroll", scroll );
			mouseOver = (int)( (myH-y) / lineH );
			mouseOver += scroll;
			mouseOver = selected > view.count-1 ? view.count-1 : mouseOver;
			zMsgUsed();
		}
	}
	else if( zmsgIs(type,Key) && zmsgIs(which,wheelbackward) ) {
		if( contains(x,y) ) {
			scroll+=2;
			scroll = max( -10, scroll );
			scroll = min( view.count-5, scroll );
			setAttrI( "scroll", scroll );
			mouseOver = (int)( (myH-y) / lineH );
			mouseOver += scroll;
			mouseOver = selected > view.count-1 ? view.count-1 : mouseOver;
			zMsgUsed();
		}
	}
	else if( zmsgIs(type,MouseMove) ) {
		mouseOver = (int)( (myH-y) / lineH );
		mouseOver += scroll;
		mouseOver = selected > view.count-1 ? view.count-1 : mouseOver;
	}

	else if( zmsgIs(type,MouseClickOn) && zmsgIs(dir,D) && zmsgI(ctrl) && zmsgI(shift) ) {
		//ADJUST the linIncrement
		if( zmsgIs(which,L) ) {
			linIncrement *= 2.f;
		}
		else if( zmsgIs(which,R) ) {
			linIncrement /= 2.f;
		}
	}
	else if( zmsgIs(type,MouseClickOn) && zmsgIs(dir,D) && zmsgIs(which,L) ) {
		selected = (int)( (myH-y) / lineH );
		selected += scroll;
		selected = selected > view.count-1 ? view.count-1 : selected;

		ZHashTable *hash = (ZHashTable *)getAttrp( "hashPtr" );
		if( !hash ) return;
		char *val = hash->getS( view[selected] );

		char *end;
		double valD = strtod( val, &end );
		if( end != val ) {
			// This is a number that can be manipulated

//			if( zmsgI(shift) && !zmsgI(ctrl) ) {
//				linMode = 0;
//				zMsgQueue( "type=GUIAttrEdit_CreateOptionMenu key=%s val=%lf toGUI=%s", selectVarPtr->name, selectVarPtr->getDouble(), getAttrS("name") );
//			}
//			else {
				if( zmsgI(ctrl) && !zmsgI(shift) ) {
					linMode = 1;
				}
				else {
					linMode = 0;
				}
				selectX = x;
				selectY = y;
				mouseX = x;
				mouseY = y;
				startVal = valD;
				requestExclusiveMouse( 1, 1 );
//			}
		}
		else {
			selected = -1;
		}


/*
		ZVarPtr *selectVarPtr = getSelectedVar( selected );
		if( selectVarPtr ) {
			if( zmsgI(shift) && !zmsgI(ctrl) ) {
				linMode = 0;
				zMsgQueue( "type=GUIAttrEdit_CreateOptionMenu key=%s val=%lf toGUI=%s", selectVarPtr->name, selectVarPtr->getDouble(), getAttrS("name") );
			}
			else {
				if( zmsgI(ctrl) && !zmsgI(shift) ) {
					linMode = 1;
				}
				else {
					linMode = 0;
				}
				selectX = x;
				selectY = y;
				mouseX = x;
				mouseY = y;
				switch( selectVarPtr->type ) {
					case zVarTypeINT:    startVal = (double)*(int    *)selectVarPtr->ptr + 0.4; break;
					case zVarTypeSHORT:  startVal = (double)*(short  *)selectVarPtr->ptr + 0.4; break;
					case zVarTypeFLOAT:  startVal = (double)*(float  *)selectVarPtr->ptr; break;
					case zVarTypeDOUBLE: startVal = (double)*(double *)selectVarPtr->ptr; break;
				}
				requestExclusiveMouse( 1, 1 );
			}
		}
*/
		zMsgUsed();
		return;
	}
	else if( zmsgIs(type,MouseReleaseDrag) ) {
		if( selected >= 0 ) {
//			ZVarPtr *selectVarPtr = getSelectedVar( selected );
//			if( selectVarPtr ) {
//				zMsgQueue( "type=GUIAttrEdit_VarDoneChange key=%s val=%lf", selectVarPtr->name, selectVarPtr->getDouble() );
//			}
		}

		requestExclusiveMouse( 1, 0 );
		selected = -1;
		zMsgUsed();
		return;
	}
	else if( zmsgIs(type,MouseDrag) && zmsgI(l) ) {
		int last = -1;
		int count = 0;
		//while( count++ != selected+1 && zVarsEnum( last, selectVarPtr, regExp ) );

		ZHashTable *hash = (ZHashTable *)getAttrp( "hashPtr" );
		double val = hash->getD( view[selected] );
		mouseX = x;
		mouseY = y;
		if( linMode ) {
			val = startVal + (mouseY-selectY) * linIncrement;
		}
		else{
			val = startVal * exp( (mouseY-selectY) / 50.0 );
		}
		hash->putS( view[selected], ZTmpStr("%4.3le",val) );
	}
	else if( zmsgIs(type,MouseClickOn) && zmsgIs(dir,D) && zmsgIs(which,R) ) {
		selectX = x;
		selectY = y;
		startScroll = scroll;
		requestExclusiveMouse( 1, 1 );
		zMsgUsed();
		return;
	}
	else if( zmsgIs(type,MouseDrag) && zmsgI(r) ) {
		scroll = (int)( startScroll + ( y - selectY ) / lineH );
		scroll = max( -10, scroll );
		scroll = min( view.count-5, scroll );
		setAttrI( "scroll", scroll );
	}
	else if( zmsgIs(type,GUIAttrEdit_Clear) ) {
		clearView();
	}
//	else if( zmsgIs(type,GUIAttrEdit_Add) ) {
//		if( zmsgHas(regexp) ) {
//			addVarsByRegExp( zmsgS(regexp) );
//		}
//		else if( zmsgHas(name) ) {
//			addVar( zmsgS(name) );
//		}
//	}
	else if( zmsgIs(type,GUIAttrEdit_Sort) ) {
		if( zmsgIs(which,name) ) {
			sortViewByName();
		}
//		else if( zmsgIs(which,order) ) {
//			sortViewByDeclOrder();
//		}
	}
	else if( zmsgIs(type,GUIAttrEdit_CreateOptionMenu) ) {
		ZHashTable hash;
		hash.putS( "who", getAttrS("name") );
		hash.putS( "key", zmsgS(key) );
		hash.putS( "val", ZTmpStr("%1.2e", zmsgF(val)) );
		createOptionMenu( &hash );
		optMenuUp = 1;
		zMsgQueue( "type=GUILayout toGUI=varEditOptMenu" );
		zMsgQueue( "type=GUIMoveNear who=%s where=T x=4 y=%f toGUI=varEditOptMenu", getAttrS("name"), -(mouseOver-scroll)*lineH );
		zMsgQueue( "type=GUISetModal val=1 toGUI=varEditOptMenu" );
	}
	else if( zmsgIs(type,GUIAttrEdit_CreateOptionMenuDone) ) {
		optMenuUp = 0;
		selected = -1;
	}
	else if( zmsgIs(type,GUIAttrEdit_CreateOptionMenuDirectEntry) ) {
		GUIObject *obj = guiFind( zmsgS(fromGUI) );
		if( obj ) {
			zMsgQueue( "type=SetVar key=%s val=%f", zmsgS(key), atof(obj->getAttrS("text")) );
		}
	}
//	else if( zmsgIs(type,GUIAttrEdit_ResetAll) ) {
//		for( int i=0; i<view.count; i++ ) {
//			ZVarPtr *v = zVarsLookup( varsView.vec[i] );
//			v->resetDefault();
//		}
//	}
	else if( zmsgIs(type,GUIAttrEdit_Clear) ) {
		clearView();
	}
	else if( zmsgIs(type,GUIAttrEdit_Add) ) {
		addVar( zmsgS(key) );
	}
	else if( zmsgIs(type,GUIAttrEdit_ViewAll) ) {
		if( zmsgI(clear) ) {
			clearView();
		}
		addAllVars();
	}
	GUIPanel::handleMsg( msg );
}