Ejemplo n.º 1
0
// Audio CD
static Boolean AudioCDTabSave() {
	ControlType *cck3P;
	FieldType *fld2P, *fld3P;
	ListType *list1P, *list2P;
	UInt16 firstTrack;
	FormPtr frmP;

	frmP = FrmGetActiveForm();

	cck3P = (ControlType *)GetObjectPtr(TabAudioCDMP3Checkbox);
	fld2P = (FieldType *)GetObjectPtr(TabAudioCDLengthSecsField);
	fld3P = (FieldType *)GetObjectPtr(TabAudioCDFirstTrackField);
	list1P = (ListType *)GetObjectPtr(TabAudioCDDriverList);
	list2P = (ListType *)GetObjectPtr(TabAudioCDFormatList);

	firstTrack = StrAToI(FldGetTextPtr(fld3P));
	if (firstTrack < 1 || firstTrack > 999) {
		TabSetActive(frmP, myTabP, 2);
		FrmSetFocus(frmP, FrmGetObjectIndex(frmP, TabAudioCDFirstTrackField));
		FrmCustomAlert(FrmErrorAlert, "Invalid track value (1...999)", 0, 0);
		return false;
	}

	gameInfoP->musicInfo.sound.CD = CtlGetValue(cck3P);

	gameInfoP->musicInfo.sound.drvCD = LstGetSelection(list1P);
	gameInfoP->musicInfo.sound.frtCD = LstGetSelection(list2P);

	gameInfoP->musicInfo.sound.defaultTrackLength = StrAToI(FldGetTextPtr(fld2P));
	gameInfoP->musicInfo.sound.firstTrack = firstTrack;

	return true;
}
Ejemplo n.º 2
0
static void ImportAltitude(const char *line, AltReferenceType *ar, UInt16 *alt) {

	switch (line[0]) {

	case 'A':
		*ar = altAmsl;
		break;

	case 'G':
		*ar = altAgl;
		break;

	case 'F':
		*ar = altFL;
		break;

	case 'B':
		*ar = altNotam;
		break;

	}

	*alt = (UInt16)StrAToI(&line[1]);

}
Ejemplo n.º 3
0
long strtol(const char *s, char **endptr, int base) {
    // WARNING : only base = 10 supported
    long val = StrAToI(s);

    if (endptr) {
        Char str[maxStrIToALen];
        StrIToA(str, val);

        if (StrNCompare(s, str, StrLen(str)) == 0)
            *endptr = (char *)s + StrLen(str);
    }

    return val;
}
Ejemplo n.º 4
0
// Music
static Boolean MusicTabSave() {
	ControlType *cck1P, *cck2P;
	ListType *list1P, *list2P, *list3P;
	FieldType *fld1P;
	UInt16 tempo;
	FormPtr frmP;

	frmP = FrmGetActiveForm();

	cck1P = (ControlType *)GetObjectPtr(TabMusicMusicCheckbox);
	cck2P = (ControlType *)GetObjectPtr(TabMusicMultiMidiCheckbox);

	list1P = (ListType *)GetObjectPtr(TabMusicDriverList);
	list2P = (ListType *)GetObjectPtr(TabMusicRateList);
	list3P = (ListType *)GetObjectPtr(TabMusicQualityList);

	fld1P = (FieldType *)GetObjectPtr(TabMusicTempoField);

	tempo = StrAToI(FldGetTextPtr(fld1P));
	if (tempo < 50 || tempo > 200) {
		TabSetActive(frmP, myTabP, 0);
		FrmSetFocus(frmP, FrmGetObjectIndex(frmP, TabMusicTempoField));
		FrmCustomAlert(FrmErrorAlert, "Invalid tempo value (50...200)", 0, 0);
		return false;
	}

	gameInfoP->musicInfo.sound.music = CtlGetValue(cck1P);
	gameInfoP->musicInfo.sound.multiMidi = CtlGetValue(cck2P);

	gameInfoP->musicInfo.sound.drvMusic = LstGetSelection(list1P);
	gameInfoP->musicInfo.sound.rate = LstGetSelection(list2P);
	gameInfoP->fmQuality = LstGetSelection(list3P);
	gameInfoP->musicInfo.sound.tempo = tempo;

	return true;
}
Ejemplo n.º 5
0
static AirspaceType *ImportRecord(PFFileRef f, Int16 *lat1, Int16 *lon1, Int16 *lat3, Int16 *lon3,
		void (*cb)(const char *)) {

	char line[256], name[256];
	char *description = PFMalloc(4096);
	char *segStr = PFMalloc(2400);
	Int16 segCount;
	AirspaceType *as = PFMalloc(2400+2400*sizeof(LineSegmentType));
	void *segStart = PFMalloc(2400*sizeof(LineSegmentType));
	void *segPtr   = segStart;
	void *writePtr;
	double blat1, blon1, blat2, blon2;

	LOGENTRY;
	ModErrThrowIf(!description);
	ModErrThrowIf(!segStr);
	ModErrThrowIf(!as);
	ModErrThrowIf(!segStart);

	/*
	 * type & class:
	 *
	 * A-G = class A to G
	 *
	 * S[ADMPRTW]= Special Use (SUAS)
	 *
	 * W[LHB] = Airway, (L)ow level, (H)igh level or Both
	 *
	 * O= Other
	 *
	 */

	if (!PFReadLine(f,line)) {

		PFMemFree(as);
		PFMemFree(description);
		PFMemFree(segStart);
		PFMemFree(segStr);

		LOGEXIT;
		return NULL;

	}

	switch (line[0]) {

	case 'A': as->type = asTypeClassA; break;
	case 'B': as->type = asTypeClassB;break;
	case 'C': as->type = asTypeClassC;break; 
	case 'D': as->type = asTypeClassD;break;
	case 'E': as->type = asTypeClassE;break;
	case 'F': as->type = asTypeClassF;break;
	case 'G': as->type = asTypeClassG;break;

	case 'S':
		switch (line[1]) {

		case 'A': as->type = suasAlert;
			  break;
		case 'D': as->type = suasDanger;
			  break;
		case 'M': as->type = suasMoa;
			  break;
		case 'P': as->type = suasProhibited;
			  break;
		case 'R': as->type = suasRestricted;
			  break;
		case 'T': as->type = suasTra;
			  break;
		case 'W': as->type = suasWarning;
			  break;

		}
		as->type |= asTypeSUAS;
		break;

	case 'W':
		switch(line[1]) {

		case 'L': as->type = asTypeLowAirway;
			  break;

		case 'H': as->type = asTypeHighAirway;
			  break;

		case 'B': as->type = asTypeHighAirway | asTypeLowAirway;
			  break;

		default:ErrThrow(113);
			break;

		}
		break;

	case 'O':
		as->type = asTypeOther;
		break;

	default:
		ErrThrow(114);
		break;

	}

	LOGINT16(as->type);

	/*
	 * name
	 *
	 */

	PFReadLine(f, line);
	StrCopy(name, line);

	(*cb)(name);

	/*
	 * description
	 *
	 */

	*description = 0;
	while (line[0] != '-') {

		StrCat(description, line);
		StrCat(description, "\n");
		PFReadLine(f, line);
		LOGSTR(line);

	}

	/*
	 * frequency or RNP
	 *
	 */

	PFReadLine(f,line);

	if (as->type & asTypeAirway) {

		as->extra = StrAToI(line);

	} else {
		
		as->extra = (StrAToI(line)*256+StrAToI(&line[4]));

	}
	LOGINT16(as->extra);

	/*
	 * lower & upper altitude
	 * 
	 */

	PFReadLine(f,line);
	ImportAltitude(line, &as->lowerAltRef, &as->lowerAlt);

	PFReadLine(f,line);
	ImportAltitude(line, &as->upperAltRef, &as->upperAlt); 

	LOGINT16(as->lowerAlt);
	LOGINT16(as->upperAlt);
	
	/*
	 * boundary segments follow:
	 *
	 * L = Line:
	 *
	 * L<lat> <lon>
	 *
	 * A = Arc:
	 *
	 * A[LR]<lat2> <lon2> <lat3> <lon3> <lat1> <lon1>
	 *
	 * (L=left arc, R=right arc)
	 *
	 * (point 1 is centre, 2 and 3 are start and end points)
	 *
	 * C = Circle:
	 *
	 * C<lat> <lon> <radius>
	 *
	 * segStr is built and the bounding limits of the airspace (blat1 etc)
	 * are updated as the segments are read and processed
	 *
	 */

	blat1 = -PI/2;
	blon1 = -PI;
	blat2 = PI/2;
	blon2 = PI;

	segCount = 0;

	PFReadLine(f,line);

	while (line[0] != 'X') {

		const char *s = line+1;

		if (line[0] == 'L') {

			LineSegmentType l;
			double lat, lon;

			lat = StrToDouble(s);
			l.lat = DEG_TO_INT32(lat);

			SKIP_FIELD(s);
			lon = 0-StrToDouble(s);
			l.lon = DEG_TO_INT32(lon);

			//LOGINT32(l.lat); LOGINT32(l.lon);

			segStr[segCount] = 'l';
			*(LineSegmentType*)segPtr = l;
			segPtr += sizeof(LineSegmentType);

			blat1 = MAX(blat1, DEG_TO_RAD(lat));
			blon1 = MAX(blon1, DEG_TO_RAD(lon));
			blat2 = MIN(blat2, DEG_TO_RAD(lat));
			blon2 = MIN(blon2, DEG_TO_RAD(lon));

		} else if (line[0] == 'A') {

			double lat1, lon1;
			double lat2, lon2;
			double lat3, lon3;
			double radius,bearing;

			ArcSegmentType ar;

			s+=1;

			/*
			 * end points
			 *
			 */

			lat2 = DEG_TO_RAD(StrToDouble(s));
			SKIP_FIELD(s);
			lon2 = 0-DEG_TO_RAD(StrToDouble(s));
			SKIP_FIELD(s);
			lat3 = DEG_TO_RAD(StrToDouble(s));
			SKIP_FIELD(s);
			lon3 = 0-DEG_TO_RAD(StrToDouble(s));

			/*
			 * centre
			 *
			 */
			
			SKIP_FIELD(s);
			lat1 = DEG_TO_RAD(StrToDouble(s));
			SKIP_FIELD(s);
			lon1 = 0-DEG_TO_RAD(StrToDouble(s));

			ar.lat = RAD_TO_INT32(lat1);
			ar.lon = RAD_TO_INT32(lon1);

			/*
			 * note to self:
			 *
			 * Because 0 < bearing < 2*PI (check AvCalcs),
			 * RAD_TO_INT16(bearing) can return under/overflow Int16 but
			 * luckily it doesn't matter - only under PalmOS though! Under
			 * CygWin it definetely needs handling.
			 *
			 * During the porting process, this should be addressed
			 *
			 */

			bearing = AvCalcGreatCircleCourse(lat1, lon1, lat2, lon2, &radius);
			ar.radius = RAD_TO_INT32(radius); 
			ar.start  = RAD_TO_INT16(bearing); 
			bearing = AvCalcGreatCircleCourse(lat1, lon1, lat3, lon3, &radius); 
			ar.end    = RAD_TO_INT16(bearing);

			if (line[1] == 'L') ar.radius = -ar.radius;

			//LOGINT32(ar.radius);
			//LOGINT16(ar.start);
			//LOGINT16(ar.end);

			segStr[segCount] = 'a';
			*(ArcSegmentType*)segPtr = ar;
			segPtr += sizeof(ArcSegmentType);

			/*
			 * assume arc is a complete circle, and calculate
			 * bounding box accordingly
			 *
			 * latitude limits are easy - just add the
			 * radian-radius, and limit the max to +-90 degrees
			 *
			 */

			blat1 = MAX(blat1, MIN(PI/2, lat1+radius));
			blat2 = MIN(blat2, MAX(-PI/2,lat1-radius));

			/*
			 * longitude is more complicated, as it needs to wrap
			 * around.
			 *
			 * scale the radius according to our latitude
			 *
			 * remember west is +ve!!!
			 *
			 * Wrap around at 180deg W/E
			 *
			 */

			radius /= cos(lat1);

			lon1 += radius;
			if (lon1 > PI) lon1 -= 2*PI;
			blon1 = MAX(blon1, lon1);
			blon2 = MIN(blon2, lon1);

			lon1 -= 2*radius;
			if (lon1 < -PI) lon1 += 2*PI;
			blon1 = MAX(blon1, lon1);
			blon2 = MIN(blon2, lon1);

		} else if (line[0] == 'C') {

			double lat1, lon1;
			double radius;

			ArcSegmentType ar;

			/*
			 * centre
			 *
			 */
			
			lat1 = DEG_TO_RAD(StrToDouble(s));
			SKIP_FIELD(s);
			lon1 = 0-DEG_TO_RAD(StrToDouble(s));

			ar.lat = RAD_TO_INT32(lat1);
			ar.lon = RAD_TO_INT32(lon1);

			/*
			 * radius in nm
			 *
			 */

			SKIP_FIELD(s);
			radius = NM_TO_RAD(StrToDouble(s));
			ar.radius = RAD_TO_INT32(radius);
			ar.start  = 0;
			ar.end    = 0;

			//LOGINT32(ar.lat);LOGINT32(ar.lon);
			//LOGINT32(ar.radius);

			segStr[segCount] = 'a';
			*(ArcSegmentType*)segPtr = ar;
			segPtr += sizeof(ArcSegmentType);

			/*
			 * latitude limits are easy - just add the
			 * radian-radius, and limit the max to +-90 degrees
			 *
			 */

			blat1 = MAX(blat1, MIN(PI/2, lat1+radius));
			blat2 = MIN(blat2, MAX(-PI/2,lat1-radius));

			/*
			 * longitude is more complicated, as it needs to wrap
			 * around.
			 *
			 * scale the radius according to our latitude
			 *
			 * remember west is +ve!!!
			 *
			 * Wrap around at 180deg W/E
			 *
			 */

			radius /= cos(lat1);

			lon1 += radius;
			if (lon1 > PI) lon1 -= 2*PI;
			blon1 = MAX(blon1, lon1);
			blon2 = MIN(blon2, lon1);

			lon1 -= 2*radius;
			if (lon1 < -PI) lon1 += 2*PI;
			blon1 = MAX(blon1, lon1);
			blon2 = MIN(blon2, lon1);

		}

		segCount++;
		PFReadLine(f,line);

	}
	segStr[segCount] = 0;
	
	LOGINT16(segPtr - segStart);

	/*
	 * adjust length of strings so that the segment records
	 * start on an even byte boundary
	 *
	 */

	if ( (segCount+1 + StrLen(description) + 1) & 1 ) {

		LOGTAG("Adjusting length");
		StrCat(description,"\n");

	}
	
	/*
	 * add the segment string, name, auth and segment records to the
	 * airspace record
	 *
	 */

	LOGLINE;

	writePtr = (void*)&as->segmentCode;
	PFMemMove(writePtr, segStr, segCount+1);
	writePtr += segCount+1;
	PFMemMove(writePtr, description, StrLen(description)+1);
	writePtr += StrLen(description)+1;

	PFMemMove(writePtr, segStart, segPtr - segStart);
	writePtr += segPtr - segStart;

	LOGSTR(GetStringFromList(as->segmentCode,1));

	PFMallocResize(as, writePtr-(void*)as);

	LOGINT16(PFMallocSize(as));


	/*
	 * adjust the longitude limits if the span is > 180 degrees by
	 * swapping lon1 and lon2 around
	 *
	 */

	if (fabs(blon1 - blon2) > PI) {

		double tmp = blon1;

		blon1 = blon2;
		blon2 = tmp;

	}

	*lat1 = RAD_TO_INT16(blat1);
	*lon1 = RAD_TO_INT16(blon1);
	*lat3 = RAD_TO_INT16(blat2);
	*lon3 = RAD_TO_INT16(blon2);
	 
	PFMemFree(description);
	PFMemFree(segStart);
	PFMemFree(segStr);

	LOGEXIT;
	return as;

}
Ejemplo n.º 6
0
Archivo: draw.c Proyecto: docwhat/cwimp
void DialogVarients() {
    FormPtr prevForm, frm;
    Word hitButton;
    Word fldIndex;
    Char tmpString[3];
    CharPtr text;

    // Save previous form
    prevForm = FrmGetActiveForm();
    // Init new form
    frm = FrmInitForm( frmVariants );

    // Set it
    FrmSetActiveForm(frm);
    FrmDrawForm(frm);

    // Set Controls
    CtlSetValue( GetObjectPtr(check_Bump     ), stor.flags & flag_Bump      );
    CtlSetValue( GetObjectPtr(check_Eclipse  ), stor.flags & flag_Eclipse   );
    CtlSetValue( GetObjectPtr(check_Sampler  ), stor.flags & flag_Sampler   );
    CtlSetValue( GetObjectPtr(check_nTW      ), stor.flags & flag_nTW       );
    CtlSetValue( GetObjectPtr(check_FullHouse), stor.flags & flag_FullHouse );
    CtlSetValue( GetObjectPtr(check_Suspend  ), stor.flags & flag_Suspend   );

    // Fill in WinScore with previous value.
    StrIToA( tmpString, stor.nTrainWrecks );
    SetFieldTextFromStr( fldnTrainWrecks, tmpString );

    StrIToA( tmpString, stor.nSuspend );
    SetFieldTextFromStr( fldnSuspend, tmpString );

    // Set the focus to this field so the user can just start typing.
    fldIndex =  FrmGetObjectIndex(frm, fldnTrainWrecks);
    FrmSetFocus( frm, fldIndex );

    // Set the handler
    FrmSetEventHandler(frm, DialogVariantsHandleEvent);

    hitButton = FrmDoDialog(frm);

    // Get Controls
    text = FldGetTextPtr( FrmGetObjectPtr( frm, fldIndex ) );
    if( text != NULL ) {
        stor.nTrainWrecks = StrAToI( text );
    } else {
        stor.nTrainWrecks = 3;
    }

    fldIndex =  FrmGetObjectIndex(frm, fldnSuspend);
    text = FldGetTextPtr( FrmGetObjectPtr( frm, fldIndex ) );
    if( text != NULL ) {
        stor.nSuspend = StrAToI( text );
    } else {
        stor.nSuspend = 10;
    }

    // Delete the form, we're not using it
    FrmDeleteForm(frm);

    // Restore previous form.
    if (prevForm) {
        FrmSetActiveForm(prevForm);
    }

}
Ejemplo n.º 7
0
Archivo: draw.c Proyecto: docwhat/cwimp
void DialogNewGame() {
    FormPtr prevForm, frm;
    Word hitButton;
    Char tmpString[5];
    CharPtr text;
    Word  fldIndex;
    Int x;

    // Save previous form
    prevForm = FrmGetActiveForm();
    // Init new form
    frm = FrmInitForm( frmNewGame );

    // Set it
    FrmSetActiveForm(frm);
    FrmDrawForm(frm);

    // Set Controls
    // cbtnVal & pbtnVal
    stor.tmpplayers = stor.numplayers;
    stor.tmpcomputers = stor.numcomputers;
    if ( stor.numplayers > 0 ) {
        x = stor.numplayers;
    } else {
        x = 1;
    }
    CtlSetValue( GetObjectPtr( pbtnVal[x - 1] ), true );

    if ( stor.numcomputers > 0 ) {
        x = stor.numcomputers;
    } else {
        x = 0;
    }
    CtlSetValue( GetObjectPtr( cbtnVal[x] ), true );

    // Fill in WinScore with previous value.
    if ( stor.winscore > 9999 ) { // Sanity check...
        stor.winscore = 300;
    }
    StrIToA( tmpString, stor.winscore );
    SetFieldTextFromStr( fld_winscore, tmpString );
    // Set the focus to this field so the user can just start typing.
    fldIndex =  FrmGetObjectIndex(frm, fld_winscore);
    FrmSetFocus( frm, fldIndex );

    // Set the handler
    FrmSetEventHandler(frm, DialogNewGameHandleEvent);

    hitButton = FrmDoDialog(frm);

    if ( hitButton == btn_OK_frmNewGame ) {
        text = FldGetTextPtr( FrmGetObjectPtr (frm, fldIndex) );
        if ( text != NULL ) {
            stor.winscore = StrAToI( text );
        } else {
            stor.winscore = 300;
        }

        stor.numplayers = stor.tmpplayers;
        stor.numcomputers = stor.tmpcomputers;
    }

    // Delete the form, we're not using it
    FrmDeleteForm(frm);

    // Restore previous form.
    if (prevForm) {
        FrmSetActiveForm(prevForm);
    }


    if ( hitButton == btn_OK_frmNewGame ) {
        NewGame();
    }


    DrawState();
}
Ejemplo n.º 8
0
/*!
 * \brief the create button is pressed in the new city form
 */
static void
cnCreateButtonPressed(void)
{
	char *pGameName;
	FormPtr form;
	UInt8 level = 0;
	UInt8 width;
	UInt8 height;
	FieldPtr fp;
	MemHandle mh;
	MemPtr mp;

	InitGameStruct();

	form = FrmGetActiveForm();
	if (FrmGetControlValue(form, FrmGetObjectIndex(form, buttonID_Easy)))
		level = 0;
	if (FrmGetControlValue(form, FrmGetObjectIndex(form, buttonID_Medium)))
		level = 1;
	if (FrmGetControlValue(form, FrmGetObjectIndex(form, buttonID_Hard)))
		level = 2;
	setDifficultyLevel(level);

	if (FrmGetControlValue(form, FrmGetObjectIndex(form,
	    buttonID_dis_off)))
		level = 0;
	if (FrmGetControlValue(form, FrmGetObjectIndex(form,
	    buttonID_dis_one)))
		level = 1;
	if (FrmGetControlValue(form, FrmGetObjectIndex(form,
	    buttonID_dis_two)))
		level = 2;
	if (FrmGetControlValue(form, FrmGetObjectIndex(form,
	    buttonID_dis_three)))
		level = 3;
	setDisasterLevel(level);

	fp = (FieldPtr)GetObjectPtr(form, fieldID_width);
	mh = FldGetTextHandle(fp);
	mp = MemHandleLock(mh);
	width = (UInt8)StrAToI(mp);
	MemHandleUnlock(mh);
	fp = (FieldPtr)GetObjectPtr(form, fieldID_height);
	mh = FldGetTextHandle(fp);
	mp = MemHandleLock(mh);
	height = (UInt8)StrAToI(mp);
	MemHandleUnlock(mh);
	setMapSize(width, height);
	ConfigureNewGame();

	pGameName = FldGetTextPtr((FieldPtr)GetObjectPtr(form,
	    fieldID_newGameName));
	if (pGameName != NULL) {
		MemSet(game.cityname, CITYNAMELEN, '\0');
		StrNCopy((char *)game.cityname, pGameName, CITYNAMELEN);
		while (GameExists((char *)game.cityname)) {
			UInt16 slen = StrLen((char *)game.cityname);
			if (slen < CITYNAMELEN-1) {
				game.cityname[slen-1] = '0' - 1;
				game.cityname[slen] = '\0';
				slen++;
			}
			game.cityname[slen - 1]++;
		}
		SaveGameByName((char *)game.cityname);
		CleanSaveGameList();
		if (LoadGameByName((char *)game.cityname) != -1) {
			FrmEraseForm(form);
			form = FrmGetFormPtr(formID_files);
			if (form != NULL) {
				FrmEraseForm(form);
				FrmDeleteForm(form);
			}
			FrmGotoForm(formID_pocketCity);
		} else {
			UpdateSaveGameList();
		}
	} else {
		game.cityname[0] = '\0';
		WriteLog("No name specified\n");
	}
}
Ejemplo n.º 9
0
void DialogNewGame() {
    FormPtr prevForm, frm;
    UInt16 hitButton;
    Char tmpString[5];
    Char *text;
    UInt16 x;
    UInt16 num;

    // Save previous form
    prevForm = FrmGetActiveForm();
    FrmSetFocus( prevForm, noFocus );

    // Init new form
    frm = FrmInitForm( frmNewGame );

    // Set it
    FrmSetActiveForm(frm);
    FrmDrawForm(frm);

    for( x = 0; x < MaxPlayers; x++ )
    {
        tmppref[x].type = GetPlayerType( x );
        StrCopy( tmppref[x].hname, pref.player[x].hname );
        StrCopy( tmppref[x].aname, pref.player[x].aname );

        DrawUserType( x, tmppref[x].type );

        NewGameSetPlayerName( fldNGname0+x, x );
    }

    // Fill in WinScore with previous value.
    if ( pref.winscore > 9999 ) { // Sanity check...
        pref.winscore = DEFAULT_WINSCORE;
    }
    StrIToA( tmpString, pref.winscore );
    SetFieldTextFromStr( fld_winscore, tmpString );

    // Fill in Opening Roll with previous value.
    if ( pref.openingroll > pref.winscore || pref.openingroll <= 0 ) {
        // Sanity check...
        pref.openingroll = DEFAULT_OPENINGROLL;
    }
    StrIToA( tmpString, pref.openingroll );
    SetFieldTextFromStr( fld_openingroll, tmpString );

    SetFocus( fld_openingroll );

    // Set the handler
    FrmSetEventHandler(frm, DialogNewGameHandleEvent);

    hitButton = FrmDoDialog(frm);

    FrmSetFocus( frm, noFocus );

    if ( hitButton == btn_OK_frmNewGame ) {

        /* Get the score needed to win */
        pref.winscore = DEFAULT_WINSCORE;
        text = FldGetTextPtr( GetObjectPtr( fld_winscore ) );
        if ( text != NULL ) {
            num = StrAToI( text );
            if( num <= 9999 && num >= 50 ) {
                pref.winscore = num;
            }
        }

        /* Get the score needed to open game */
        pref.openingroll = DEFAULT_OPENINGROLL;
        text = FldGetTextPtr( GetObjectPtr( fld_openingroll ) );
        if ( text != NULL ) {
            num = StrAToI( text );
            if( num <= pref.winscore && num >= 0 ) {
                pref.openingroll = num;
            }
        }


        pref.totalplayers = 0;
        for( x = 0; x < MaxPlayers; x++ )
        {
            pref.player[x].type = tmppref[x].type;

            NewGameGetPlayerName( fldNGname0 + x, x );

            StrCopy( pref.player[x].hname,
                     tmppref[x].hname );
            StrCopy( pref.player[x].aname,
                     tmppref[x].aname );

            if( tmppref[x].type != PlayerNone )
            {
                pref.totalplayers++;
            }

        }

        if( pref.totalplayers > 0 )
        {
            NewGame();
        }
    }

    // Delete the form, we're not using it
    FrmDeleteForm(frm);

    // Restore previous form.
    if (prevForm) {
        FrmSetActiveForm(prevForm);
    }

    DrawState();
}
Ejemplo n.º 10
0
/*-----------------------------------------------CIRexxApp::addRecordsToIndex-+
|                                                                             |
+----------------------------------------------------------------------------*/
void CIRexxApp::addRecordsToIndex(CArray<ScriptRecord *> & records, CDatabase * db, UInt16 cat, char * dbi)
{
   UInt16 index = 0;
   UInt32 rowId;
   MemHandle hMem;
   Int16 recordPosition = 0;
   CHash<unsigned int, Int16> recordPositionBySegmentId;
   ScriptRecord * scriptRecord;

   if (db == 0) { return; }
   while ((hMem = db->QueryNextInCategory(index, cat))) {
      db->GetRecordUniqueID(index, rowId);
      UInt32 size = MemHandleSize(hMem);
      const char * pMem = (char *)MemHandleLock(hMem);
      /*
      | FORMAT:
      | %6s #segment.<no>#\ndate() time() <id>\nTitle: <tit>\nCategory: <cat>
      */
      char * scanner;
      if (                    // if it's segmented, combine the segments
         (scanner = StrStr(pMem, "#segment.")) &&
         (scanner = StrChr(scanner + 1, '#'))
      ) {
         char segmentNoAsString[5];
         memcpy(segmentNoAsString, scanner - 4, 4);
         segmentNoAsString[4] = '\0';
         int segmentNo = StrAToI(segmentNoAsString);
         ++scanner;
         int peditHeaderSize = size - (scanner - pMem);
         if (peditHeaderSize > ScriptRecord::MAX_PEDITHEADERLEN) {
            peditHeaderSize = ScriptRecord::MAX_PEDITHEADERLEN;
         }
         RexxString header(scanner, peditHeaderSize);
         RexxString segmentIdAsString;
         segmentIdAsString.wordAt(header, 3);
         unsigned int segmentId = hex2uint(
            (char const *)segmentIdAsString, segmentIdAsString.length()
         );
         int titWordNo = RexxString("Title:").wordpos(header, 1);
         int catWordNo = RexxString("Category:").wordpos(header, 1);
         RexxString title;
         title.subword(header, titWordNo + 1, catWordNo - (titWordNo + 1));
         // create the script record
         Int16 * psegmentedRecordPosition = (Int16 *)recordPositionBySegmentId.Lookup(segmentId);
         // if this segment has already been encountered, then create a chain of segments
         if (psegmentedRecordPosition) {
            ScriptRecord * sr = records[*psegmentedRecordPosition];
            sr->m_indexes.Insert(sr->m_indexes.GetCount(), index);
            sr->m_segments.Insert(sr->m_segments.GetCount(), segmentNo);
         // otherwise just add it
         }else {
            scriptRecord = new ScriptRecord(db, dbi, title, index, segmentNo);
            recordPositionBySegmentId.SetAt(segmentId, recordPosition);
            records.Insert(recordPosition++, scriptRecord);
         }
      }else { // otherwise just add it
         unsigned int i;
         for (i=0; pMem[i] && pMem[i] != linefeedChr && i < ScriptRecord::MAX_TITLELEN; ++i) {
            ;
         }
         char * t = new char[i + 1];
         memcpy(t, pMem, i);
         t[i] = '\0';
         RexxString title(t);
         scriptRecord = new ScriptRecord(db, dbi, title, index);
         delete [] t;
         records.Insert(recordPosition++, scriptRecord);
      }
      MemHandleUnlock(hMem);
      ++index;
   }
}
Ejemplo n.º 11
0
/***********************************************************************
 *
 * FUNCTION:    RepeatSetUIValues
 *
 * DESCRIPTION: This routine sets the current repeat settings of the
 *              ui gadgets in the repeat dialog box
 *
 * PARAMETERS:  frm     - pointer to the Repeat Dialog
 *              repeatP - pointer to a RepeatInfoType structure.
 *
 * RETURNED:    nothing
 *
 ***********************************************************************/
void RepeatSetUIValues(FormType* frm, RepeatInfoType* repeatP) {
  UInt16 i;
  UInt16 id;
  UInt16 oldFreq;
  MemHandle freqH;
  Char* freqP = NULL;
  Boolean on = false;
  FieldType* fld = NULL;
  const Int8 startOfWeek = PrefGetPreference(prefWeekStartDay);

  /* Set the selection of the "repeat type" push button group. */
  id = repeatP->repeatType + RepeatNone;
  if (repeatP->repeatType > repeatMonthlyByDay)
    id--;
  FrmSetControlGroupSelection (frm, RepeatTypeGroup, id);


  /* Set the frequency field */
  if (repeatP->repeatType != repeatNone) {
    fld = GetObjectPointer(frm, RepeatFrequenceField);
    freqH = FldGetTextHandle(fld);
    if (freqH) {
      freqP = MemHandleLock(freqH);
      oldFreq = StrAToI(freqP);
    } else {
      freqH = MemHandleNew(maxFrequenceFieldLen);
      ASSERT(freqH);
      freqP = MemHandleLock(freqH);
      oldFreq = 0;
    }

    if (oldFreq != repeatP->repeatFrequency) {
      StrIToA(freqP, repeatP->repeatFrequency);
      FldSetTextHandle(fld, freqH);
      if (FrmVisible(frm)) {
	FldEraseField(fld);
	FldDrawField(fld);
      }
    }
    MemHandleUnlock (freqH);
  }

  /* Set the selection of the "repeat on" push button groups. */
  if (repeatP->repeatType == repeatWeekly) {
    /*
    ** If the appointment has a different start-day-of-week than
    ** the dialog-box's current start-day-of-week, rearrange the
    ** labels on the days-of-week push buttons.
    ** Note that this will only handle button-label shifts of one day.
    */
    if (startOfWeek != d.repeat_start_of_week) {
      const Char* sundayLabel = CtlGetLabel(GetObjectPointer(frm, RepeatDayOfWeek1PushButton));
      for (id = RepeatDayOfWeek1PushButton; id < RepeatDayOfWeek7PushButton; id++)
	CtlSetLabel(GetObjectPointer(frm, id), CtlGetLabel(GetObjectPointer(frm, id + 1)));

      CtlSetLabel(GetObjectPointer(frm, RepeatDayOfWeek7PushButton), sundayLabel);
      d.repeat_start_of_week = startOfWeek;
    }

    /* Turn on the push buttons for the days the appointment repeats on. */
    for (i = 0; i < daysInWeek; i++) {
      on = ((repeatP->repeatOn & (1 << i) ) != 0);
      id = RepeatDayOfWeek1PushButton +
	((i - startOfWeek + daysInWeek) % daysInWeek);
      CtlSetValue(GetObjectPointer(frm, id), on);
    }
  }

  /* Set the selection of the "repeat by" push button groups. */
  if (repeatP->repeatType == repeatMonthlyByDate)
    FrmSetControlGroupSelection(frm, RepeatByGroup, RepeatByDatePushButton);
  else
    FrmSetControlGroupSelection(frm, RepeatByGroup, RepeatByDayPushButton);
  
  /* Set the "end on" trigger label and popup list selection. */
  if (repeatP->repeatType != repeatNone)
    RepeatSetDateTrigger(repeatP->repeatEndDate);
}
Ejemplo n.º 12
0
/***********************************************************************
 *
 * FUNCTION:    RepeatGetUIValues
 *
 * DESCRIPTION: This routine gets the current repeat settings of the
 *              ui gadgets in the repeat dialog box
 *
 *
 * PARAMETERS:  frm     - pointer to the repeat dialog
 *              repeatP - RepeatInfoType structure (fill-in by this routine)
 *
 * RETURNED:    nothing
 *
 ***********************************************************************/
void RepeatGetUIValues (FormType* frm, RepeatInfoType* repeatP) {
  UInt16 freq;
  UInt16 i;
  UInt16 id;
  UInt16 index;
  Char* str = NULL;

  /* Get the repeat type. */
  index = FrmGetControlGroupSelection(frm, RepeatTypeGroup);
  id = FrmGetObjectId(frm, index);
  if (id == RepeatYearly) {
    repeatP->repeatType = repeatYearly;
  } else if (id <= RepeatWeekly) {
    repeatP->repeatType = (RepeatType) (id - RepeatNone);
  } else {
    index = FrmGetControlGroupSelection(frm, RepeatByGroup);
    id = FrmGetObjectId(frm, index);
    if (id == RepeatByDayPushButton)
      repeatP->repeatType = repeatMonthlyByDay;
    else
      repeatP->repeatType = repeatMonthlyByDate;
  }
  
  /* Get the repeat end date. */
  repeatP->repeatEndDate = d.repeat_end_date;

  /* Get the repeat frequency. */
  str = FldGetTextPtr(GetObjectPointer(frm, RepeatFrequenceField));
  if (str) 
    freq = StrAToI(str);
  else 
    freq = 0;

  if (freq)
    repeatP->repeatFrequency = freq;
  else
    repeatP->repeatFrequency = 1;

  /*
  ** Get the start day of week.  If the original repeat type, that is the
  ** repeat type when the dialog was first displayed, is weekly then
  ** use the start date in the repeat info (the unedit data), otherwise
  ** use the current start of week.
  */
  if (repeatP->repeatType == repeatWeekly) {
    if (d.tmp_repeat.repeatType == repeatWeekly)
      repeatP->repeatStartOfWeek = d.tmp_repeat.repeatStartOfWeek;
    else
      repeatP->repeatStartOfWeek = PrefGetPreference(prefWeekStartDay);
  } else {
    /* For all other repeat types, the repeatStartOfWeek field is meaningless. */
    repeatP->repeatStartOfWeek = 0;
  }

  /* If the repeat type is weekly, get the day of the week the event repeats on. */
  if (repeatP->repeatType == repeatWeekly) {
    repeatP->repeatOn = 0;
    index = FrmGetObjectIndex(frm, RepeatDayOfWeek1PushButton);
    for (i = 0; i < daysInWeek ; i++) {
      if (FrmGetControlValue(frm, 
			     index + ((i - d.repeat_start_of_week + daysInWeek) % daysInWeek)))
	repeatP->repeatOn |= (1 << i);
    }
  } else if (repeatP->repeatType == repeatMonthlyByDay) {
    /*
    ** If the repeat type is monthly by day, get the day of the month (ex:
    ** first Friday) of the start date of the event.
    */
    if (d.tmp_repeat.repeatType == repeatMonthlyByDay)
      repeatP->repeatOn = d.tmp_repeat.repeatOn;
    else
      repeatP->repeatOn = DayOfMonth (d.frm_date.month,
				      d.frm_date.day,
				      d.frm_date.year);
  } else {
    /* For all other repeat types, the repeatOn field is meaningless. */
    repeatP->repeatOn = 0;
  }
}
Ejemplo n.º 13
0
Int16 AnalizeOneRecord(UInt16 addrattr, Char* src,
                  HappyDays* hd, Boolean *ignore)
{
    Char *p, *q;
    UInt16 index;
    Int16 err;
    Int16 year, month, day;
    Int16 nth[20];
    Int16 count = 0;

	while (*src == ' ' || *src == '\t') src++;    // skip white space

    // ignore record with exclamation mark
    if (*src == '!') {
        if (gPrefsR.ignoreexclamation) return 0;
        else src++;
    }


    if ((q = StrChr(src, '['))) {
        // [ 이 있는 경우 duration으로 판단 
        p = q;

        q = StrChr(src, ']');
        if (q) *q = 0;
        else return 0;

        do {
            p++;
            nth[count++] = StrAToI(p);
            if (count >= 20) break;
        } while ((p = StrChr(p, ',')));
    }
    
    if (*src == '*') {
        
        // this is multiple event
        hd->flag.bits.multiple_event = true;
        if ((p = StrChr(src, ' '))) *p = 0;
        else goto ErrHandler;
    
        if ( *(src+1) != 0 ) {                       // if src have 'custom' tag
            hd->custom = src+1;
            UnderscoreToSpace(src+1);
        }
		else hd->custom = 0;

        src = p+1;
        while (*src == ' ' || *src == '\t') src++;     // skip white space

        if ((p = StrChr(src, ' '))) *p = 0;
        else goto ErrHandler;

        if (*src == '.') {
            hd->name1 = src+1;
            hd->name2 = 0;
        }
        else {
            hd->name2 = src;
        }
        
        UnderscoreToSpace(src);
        
        src = p+1;
        while (*src == ' ' || *src == '\t') src++;     // skip white space
    }
    
    if (!AnalysisHappyDays(src, &hd->flag,
                           &year, &month, &day)) goto ErrHandler;

    // convert into date format
    //
    if (hd->flag.bits.year) {
        if ((year < 1904) || (year > 2031) ) goto ErrHandler;
        else hd->date.year = year - 1904; 
    }
    else hd->date.year = 0;
        
    hd->date.month = month;
    hd->date.day = day;

    // maintain address book order(name order)
    //      list order is determined by sort
    err = HDNewRecord(MainDB, hd, &index);
    if (!err) {
        UInt16 attr;
        // set the category of the new record to the category
        // it belongs in
        DmRecordInfo(MainDB, index, &attr, NULL, NULL);
        attr &= ~dmRecAttrCategoryMask;
        attr |= addrattr;

        DmSetRecordInfo(MainDB, index, &attr, NULL);

        DmReleaseRecord(MainDB, index, true);
    }

    if (count > 0) {
        Int16 i;
        HappyDays hdr;

        for (i = 0; i < count; i++) {
            MemMove(&hdr, hd, sizeof(hdr));

            hdr.flag.bits.nthdays = 1;
            hdr.nth = nth[i];

            if (!hdr.flag.bits.year) goto ErrHandler;
            
            err = HDNewRecord(MainDB, &hdr, &index);
            if (!err) {
                UInt16 attr;
                // set the category of the new record to the category
                // it belongs in
                DmRecordInfo(MainDB, index, &attr, NULL, NULL);
                attr &= ~dmRecAttrCategoryMask;
                attr |= addrattr;

                DmSetRecordInfo(MainDB, index, &attr, NULL);

                DmReleaseRecord(MainDB, index, true);
            }
        }
    }
    
    return 0;

 ErrHandler:
    if (*ignore) return 0;
                
    switch (FrmCustomAlert(InvalidFormat,
                           ((!hd->name2) ?
                            ((!hd->name1) ? " " : hd->name1)
                            : hd->name2),
                               " ", " ")) {
    case 0:                 // EDIT
        if (!GotoAddress(hd->addrRecordNum)) return -1;
    case 2:                 // Ignore all
        *ignore = true;
    case 1:  
    	break;              // Ignore
    }
    return 0;
}
Ejemplo n.º 14
0
Boolean AnalysisHappyDays(const char* field,
                          HappyDaysFlag *flag,
                          Int16* dYear, Int16* dMonth, Int16* dDay)
{
    Char * s = (Char *)field;
    Char * p;
    Char numOfDelimeter = 0;
    Int16 num[3], numIdx = 0;
    Int16 year=0, month=0, day=0;
    Char delimeter = '/';
    Char priorityName1 = flag->bits.priority_name1;
    
    while (*s == ' ' || *s == '\t') s++;     // skip white space
    StrNCopy(gAppErrStr, s, AppErrStrLen);

    s = gAppErrStr;

    // initalize flag except priority_name1;
    flag->allBits = 0; flag->bits.priority_name1 = priorityName1;
    
    if ((p = StrChr(s, ')')))  {    // exist
        if (*s == '-') flag->bits.lunar = 1;
        else if (*s == '#') flag->bits.lunar_leap = 1;
        else return false;
        s = p+1;
    }
    else flag->bits.solar = 1;   // default is solar

    switch (gPrefdfmts) {
    case dfDMYWithDots:          // 31.12.95
    case dfYMDWithDots:          // 95.12.31
        delimeter = '.';
        break;
    case dfDMYWithDashes:        // 31-12-95
    case dfYMDWithDashes:        // 95-12-31
        delimeter = '-';
        break;
    case dfYMDWithSlashes:       // 95/12/31
    case dfDMYWithSlashes:       // 31/12/95
    case dfMDYWithSlashes:       // 12/31/95
    default:
        delimeter = '/';
        break;
    }
    
    p = s;
    // find the number of delimeter
    while ((p = StrChr(p, delimeter))) {
        numOfDelimeter++;
        p++;
    }
    
    p = s;
    if (numOfDelimeter < 1 || numOfDelimeter > 2) return false;
    else if (numOfDelimeter == 2) {
        p = StrChr(p, delimeter); *p = 0; p++;
        num[numIdx++] = StrAToI(s);
        s = p;
    }
    
    p = StrChr(s, delimeter); *p = 0; p++;
    num[numIdx++] = StrAToI(s);
    s = p;
    
	if (*s == 0) flag->bits.year = 0;
	else {
		flag->bits.year = 1;
		num[numIdx] = StrAToI(s);
	}

    if (numOfDelimeter == 1) {
        flag->bits.year = 0;
    }

    switch (gPrefdfmts) {
    case dfDMYWithSlashes:       // 31/12/95
    case dfDMYWithDots:          // 31.12.95
    case dfDMYWithDashes:        // 31-12-95
        if (numOfDelimeter == 2) {
            year = num[numIdx--];
        }
        month = num[numIdx--];
        day = num[numIdx];
        break;
    case dfYMDWithSlashes:       // 95/12/31
    case dfYMDWithDots:          // 95.12.31
    case dfYMDWithDashes:        // 95-12-31
        day = num[numIdx--];
        month = num[numIdx--];

        if (numOfDelimeter == 2) {
            year = num[numIdx];
        }
        break;
    case dfMDYWithSlashes:       // 12/31/95
    default:
        if (numOfDelimeter == 2) {
            year = num[numIdx--];
        }
        day = num[numIdx--];
        month = num[numIdx];
        break;
    }

    if (month < 1 || month > 12)
        return false;
    if (day < 1 || day > 31)
        return false;

    if (flag->bits.year) {
        if (year >= 0 && year <= 31) *dYear = year + 2000;          // 2000
        else if (year > 31 && year <= 99) *dYear = year + 1900;     // 1900
        else if (year >= 1900) *dYear = year;
        else return false;

        if (flag->bits.lunar || flag->bits.lunar_leap) {
            int syear, smonth, sday; 
            Err err;
            
            err = lunarL2S(lunarRefNum, *dYear, month, day, flag->bits.lunar_leap, &syear, &smonth, &sday);
            if (err != errNone) {
				return false;
			}
        }
    }
    *dMonth = month; *dDay = day;

    return true;
}