Пример #1
0
/* This function maps to two in the AxxPac API:
   axxPacFindFirst and axxPacFindNext */
Err vfsDirEntryEnumerate(FileRef dirRef, UInt32 *dirEntryIteratorP, 
        FileInfoType *infoP)
{
    static axxPacFileInfo axxFileInfo;
    file_rec_t axxFileRec;
    Char symb[2] = "*\0";
    Err ret;
  
    if (*dirEntryIteratorP == vfsIteratorStart) {
        if (GetFileProperties (dirRef,&axxFileRec)!=errNone)
               return vfsErrFileBadRef;
        /* Use the wildcar '*' after the dir name to use as a pattern to
           search */
        StrCat(axxFileRec.name, symb);

        /* assumption: there is only one directory enumerated at a time */
        ret = axxPacFindFirst(LibRef, axxFileRec.name, &axxFileInfo,
                  FIND_FILES_ONLY);
        if (ret == 0) {
            infoP->attributes = axxFileInfo.attrib ;
            /* nameP will store the file name only if it is not null */
            if (infoP->nameP != NULL)
                StrNCopy(infoP->nameP, axxFileInfo.name,
                    min(256, infoP->nameBufLen)); 
        }
        else {
            if (0 < ret) {
                *dirEntryIteratorP = vfsIteratorStop;
                return expErrEnumerationEmpty;
            }
            else {
                /* error should be mapped but... */
                return vfsErrFileBadRef;
            }
        }
        ret = axxPacFindNext (LibRef, &axxFileInfo);
        if (0 < ret)
            *dirEntryIteratorP = vfsIteratorStop;
        else if (ret == 0)
            *dirEntryIteratorP = (Int32)&axxFileInfo;

        return errNone;
    }
    else {
        /* assumption: a call with vfsIteratorStart has been made before */
        infoP->attributes = axxFileInfo.attrib ;
        /* nameP will store the file name only if it is not null */
        if (infoP->nameP != NULL)
            StrNCopy(infoP->nameP, axxFileInfo.name,
                min(infoP->nameBufLen, 256));
        ret=axxPacFindNext (LibRef, &axxFileInfo);
        if (0 < ret)
            *dirEntryIteratorP = vfsIteratorStop;
        else if ( ret == 0 )
            *dirEntryIteratorP = (Int32)&axxFileInfo;

        return errNone;
    }
}
Пример #2
0
Char* AdjustNote(Int16 iconNumber, Char* note)
{
    extern Char gAppErrStr[];
    Char *p, *q;

    noteTempBuffer[0] = 0;
    
    if (!note) {
        // 지금 가지고 있는 게 없을 경우
        StrPrintF(noteTempBuffer, "ICON: %d\n#AN\n", iconNumber);
    }
    else {
        // note field에 내용이 있는 경우
        if ( (p= StrStr(note, "#AN\n")) ) {
            // AN string을 가지고 있는 경우
            
            if (iconNumber < 0) {
                // 있는 ICON: 을 제거
                q = StrStr(note, "ICON:");

                if (q == note) {
                    q = StrStr(p, "\n");
                    StrNCopy(noteTempBuffer, q+1, 4096);
                }
                else {
                    StrNCopy(noteTempBuffer, note, q-note);
                    q = StrStr(q, "\n");
                    StrNCat(noteTempBuffer, q+1, 4096);
                }
            }
            else {
                // 있는 ICON: 변경
                q = StrStr(note, "ICON:");
                if (q) {
                    StrNCopy(noteTempBuffer, note, q-note);
                    q = StrStr(q, "\n") + 1;
                }
                else {
                    StrNCopy(noteTempBuffer, note, p-note);
                    q = p;
                }

                StrPrintF(gAppErrStr, "ICON: %d\n", iconNumber);
                StrNCat(noteTempBuffer, gAppErrStr, 4096);

                StrNCat(noteTempBuffer, q, 4096);
            }
        }
        else {
            StrPrintF(noteTempBuffer, "ICON: %d\n#AN\n", iconNumber);
            StrNCat(noteTempBuffer, note, 4096);
        }
        
        
    }
    return noteTempBuffer;
}
Пример #3
0
/* Return info for last openned document */
DocumentInfo* GetLastDocInfo( void )
{
    DocumentInfo* docInfo;

    docInfo = NULL;

    if ( plkrDocList == NULL ) {
        plkrDocList = DmOpenDatabaseByTypeCreator( PlkrDocListType, ViewerAppID,
                        dmModeReadWrite );
    }
    if ( plkrDocList != NULL ) {
        DocumentData*   recordPtr;
        MemHandle       handle;

        ErrTry {
            /* assign doc info values for document */
            handle = FindDocData( Prefs()->docName, ALL_ELEMENTS, NULL );
            if ( handle != NULL ) {
                recordPtr = MemHandleLock( handle );

                StrNCopy( lastDocInfo.name, recordPtr->name, dmDBNameLength );
                lastDocInfo.cardNo      = recordPtr->cardNo;
                lastDocInfo.created     = recordPtr->created;
                lastDocInfo.attributes  = recordPtr->attributes;
                lastDocInfo.size        = recordPtr->size;
                lastDocInfo.categories  = recordPtr->categories;
                lastDocInfo.location    = recordPtr->location;
                lastDocInfo.timestamp   = recordPtr->timestamp;
                if ( lastDocInfo.location != RAM ) {
                    UInt16 fileLength;

                    ReleaseLastDocInfo();

                    fileLength              = StrLen( recordPtr->data ) + 1;
                    lastDocInfo.filename    = SafeMemPtrNew( fileLength );
                    StrNCopy( lastDocInfo.filename, recordPtr->data,
                        fileLength );
                    lastDocInfo.volumeRef   = FindVolRefNum( recordPtr->data +
                                                             fileLength );
                }
                MemHandleUnlock( handle );
                CloseRecord( handle, false );

                CloseDocList();

                docInfo = &lastDocInfo;
            }
        }
        ErrCatch( UNUSED_PARAM( err ) ) {
        } ErrEndCatch

        CloseDocList();
    }
Пример #4
0
void get_default_username(Char *buf, Short max_len)
{
  Char *tmp, *first_wspace;
  VoidHand h;
  tmp = md_malloc(sizeof(Char) * (dlkMaxUserNameLength + 1));
  DlkGetSyncInfo(NULL, NULL, NULL, tmp, NULL, NULL);
  /* if it's too long, use the first name only */
  //  if (StrLen(tmp) > max_len-1) {
  if (StrLen(tmp) > 8) {
    first_wspace = StrChr(tmp, spaceChr);
    if (first_wspace)
      *(first_wspace) = '\0';
    else
      tmp[max_len-1] = '\0';
  }
  if (StrLen(tmp))
    StrNCopy(buf, tmp, max_len);
  else {
    Short t = rund(3);
    switch(t) {
    case 0:  StrPrintF(buf, "Noman"); break;
    case 1:  StrPrintF(buf, "Outis"); break; // "no man" in greek, says the web
    default: StrPrintF(buf, "Metis"); break; // "no one"/"cunning" pun in greek
    }
  }
  h = MemPtrRecoverHandle(tmp);
  if (h) MemHandleFree(h);  
}
Пример #5
0
UInt32 buffer_to_gb2312(gb2312_table& table, const unsigned char* buf, unsigned char* gb_buf, UInt32 len, Int8 coding)
{
	LOG("buffer_to_gb2312::starting");
	
	int k = 0;
	Boolean isNeedDecode = true;
	char* basePointer = (char *) buf;
	UInt32 resultLen = len;
	
	if (coding == -1) {
		for(k = 0; k < len; k ++) {
			if((*basePointer > 127) || *basePointer < 32)
				break;
			basePointer++;
		}
		if (k == len) isNeedDecode = false;
	} else if (coding == kTelSmsUCS2Encoding) {
		isNeedDecode = true;
	} else {
		isNeedDecode = false;
	}


	if (isNeedDecode) {
		resultLen = ucs2_to_gb2312(table, buf, gb_buf, len);
	} else {
		StrNCopy((char *) gb_buf, (const char *) buf, len);
	}

	LOG("buffer_to_gb2312::left");
	
	return resultLen;
}
Boolean SaveFlightDialogHandleEvent(EventPtr event) {

	Boolean handled = false;
	Boolean savedOk = false;
	char *inputName;

	switch (PFEventGetType(event)) {

	case frmOpenEvent:
		InitDialog();
		GUIFormDraw();		handled = true;
		break;

	case ctlSelectEvent:

		switch (PFEventGetControlSelectID(event)) {

		case SaveFlightOKButton: 
			inputName = GUIFieldGetText(SaveFlightFileNameField);
			if (inputName && StrLen(inputName)) {

				savedOk = FlightDBSaveFlight(GUIFieldGetText(SaveFlightFileNameField), FlightPlan, FpStackPeek(FlightPlanStackB, 0), false);

				if (!savedOk && GUIAlertShow(FlightExistsAlert) == 0) {

					savedOk = FlightDBSaveFlight(GUIFieldGetText(SaveFlightFileNameField), FlightPlan, FpStackPeek(FlightPlanStackB,0), true);

					if (!savedOk) ErrThrow(1966);

				}

			}

			if (savedOk) {

				StrNCopy(Preferences.FlightPlanName, inputName, sizeof(Preferences.FlightPlanName));
				GUIFormReturn();

			}

			handled = true;
			break;

		case SaveFlightCancelButton:
			handled = true;
			GUIFormReturn();
			break;
			
		}

		break;
			

	default:
		break;
	}

	return handled;

}
Пример #7
0
/* Retrieve search string */
void GetSearchString
    (
    Char* string    /* string pointer to store result */
    )
{
    Int8    i;
    Char*   entry;

    MemSet( string, MAX_PATTERN_LEN + 1, 0 );

    ReadSearchPatterns();

    if ( patterns != NULL ) {
        entry = patterns;
        for ( i = 0; i < pref.searchEntries - 1; i++ )
            entry += StrLen( entry ) + 1;
        StrNCopy( string, entry, MAX_PATTERN_LEN );

        SafeMemPtrFree( patterns );
        patterns = NULL;
    }
    else {
        pref.searchEntries = 0;
        StrCopy( string, "" );
    }
}
Пример #8
0
Boolean DoRenameFigure(void)
{
    FormPtr prevFrm = FrmGetActiveForm();
    int numFigures = TFigurerecordGetCount();
    if ((currentFigure != noListSelection) && (currentFigure < numFigures)) {
	TFigure_type *t1 = TFigurerecordGet(currentFigure);
	if (t1) {
	    FormPtr frm = FrmInitForm(formRenameFigure);
	    FieldPtr field = (FieldPtr) FrmGetObjectPtr(frm,
							FrmGetObjectIndex
							(frm,
							 fieldFigureName));
	    MemHandle oldhText=FldGetTextHandle(field);
	    MemHandle hText = MemHandleNew(DESCSIZE);
	    char *titleptr = (char *) MemHandleLock(hText);
	    StrNCopy(titleptr, t1->name, DESCSIZE);
	    titleptr[DESCSIZE - 1] = 0;

	    MemPtrUnlock(titleptr);
	    FldSetTextHandle(field, (MemHandle) hText);
	    if (oldhText!=NULL) {
	      MemHandleFree(oldhText);
	    }

	    if (FrmDoDialog(frm) == buttonRFOK) {
		hText = FldGetTextHandle(field);
		titleptr = (char *) MemHandleLock(hText);
		if ((titleptr) && StrLen(titleptr) > 0) {

		    StrNCopy(t1->name, titleptr, DESCSIZE);
		    t1->name[DESCSIZE - 1] = 0;
		    TFigurerecordChange(currentFigure, t1);
		}
		MemPtrUnlock(titleptr);
	    }

	    TFigureFree(t1);
	    if (prevFrm)
		FrmSetActiveForm(prevFrm);
	    FrmDeleteForm(frm);
	}
	return true;
    }

    return false;
}
Пример #9
0
static void SetTriggerText(UInt16 selected)
{
	FormPtr frmP = FrmGetActiveForm();
	if (FormIsNot(frmP, FormReply)) return;
	char* str = (char *)CtlGetLabel ((ControlPtr) GetObjectPtr (frmP, TriggerGroup));	
	StrNCopy(str, GetDisplayString(selected), 19);
	CtlDrawControl((ControlPtr) GetObjectPtr (frmP, TriggerGroup));
}
Пример #10
0
void PrvPrepareTags(FlickrPrefs& prefs)
{
    if (prefs.registered)
        return;

    StrNCopy(prefs.tags, flickrDefaultTag, prefs.maxTagsLength);
    prefs.tags[prefs.maxTagsLength] = chrNull;
    return;
}
Пример #11
0
void PrvPrepareDescriptionText(FlickrPrefs& prefs)
{
    if (prefs.registered)
        return;

    StrNCopy(prefs.description, "Sent from ", prefs.maxDescriptionLength);
    PrvFillDeviceName(prefs.description, prefs.maxDescriptionLength);
    StrNCat(prefs.description," using ArsLexis InfoMan (" INFOMAN_WWW_LINK ").", prefs.maxDescriptionLength);
    prefs.description[prefs.maxDescriptionLength] = chrNull;
    return;
}
Пример #12
0
static void PrvFillBuffer(char* buffer, UInt16 length, const char* text1, const char* text2)
{
    UInt16 len1 = StrLen(text1);
    UInt16 len2 = StrLen(text2);

    buffer[length - 1] =chrNull;
    StrNCopy(buffer, text1, length - 1);
    StrNCat(buffer, text2, length - 1);
    if (len1 + len2 > length - 1)
        buffer[length - 2] = chrEllipsis;
}
Пример #13
0
void CClientSocket::OnReceive(int nErrorCode) 
{
	char buff[DataBufLength];
	int nRead;
	CString sIP;
	UINT nPort;
	
	nRead = ReceiveFrom(buff,DataBufLength,sIP,nPort);
	
	if (nRead != SOCKET_ERROR && nRead != 0 )
	{	
		if(StrNSame(buff,m_szResponseMsg,nRead-4,m_szrLength))
		{				
			DWORD Index=*((DWORD*)(buff+nRead-4));				
			if(Index<=CheckBufLength)
			{		
				m_arBuf[Index]=1;				
				return;
			}
		}		
		
		CData* pData=new CData;
		
		StrNCopy(pData->szBuf,buff,nRead);			
		pData->num=nRead;
		pData->nPort=nPort;
		pData->tarIP=inet_addr(sIP);
		
		if(pData->LoadFromBuf())
		{			
			StrNCopy(m_szResponseMsg+m_szrLength,(char*)&pData->This,sizeof(DWORD));
			SendTo(m_szResponseMsg,m_szrLength+sizeof(DWORD),nPort,sIP);
			if(pData->wIndex>=0&&pData->wIndex<RecvWndNumber&&m_apRecvWnd[pData->wIndex]!=NULL)
			{
				m_apRecvWnd[pData->wIndex]->PostMessage(WM_RECIEVE_MSG,(WPARAM)pData,0);
			}
			TRACE2("Recv a Data index: %d This: %d\n",pData->index,pData->This);
		}
	}	
}
Пример #14
0
void parseArgs(char *dstStr, char *srcStr, int startChar, int len, 
			   int maxLen)
{
	if(len <= 0){
		dstStr[0] = 0;
		return;
	} else if(len > maxLen - 1){
		len = maxLen - 1;
	}

	StrNCopy(dstStr, &srcStr[startChar], len);
	dstStr[len] = 0;
}
Пример #15
0
int AppendField( FieldPtr fld, CharPtr str, UInt len )
{
	Err err=0;
	CharPtr  s;
	VoidHand h;
	UInt prevlen;

	h=(VoidHand)FldGetTextHandle(fld);

	if(h==NULL) {
		h=MemHandleNew(len+1);
		if(h==NULL) return(-1);
		s=MemHandleLock(h);
		StrNCopy(s, str, len);
		s[len]=0;
		MemHandleUnlock(h);
	} else {
		prevlen=FldGetTextLength(fld);

		FldSetTextHandle(fld, NULL);

		if( MemHandleSize(h)<=(prevlen+len)) {
			err=MemHandleResize( h, prevlen+len+1 );
		}
		if( err!=0 ) return(-1);

		s=MemHandleLock(h);
		StrNCopy(s+prevlen, str, len);
		s[len+prevlen]=0;
		MemHandleUnlock(h);
	}

	FldSetTextHandle(fld, (Handle)h);
	/* FldDrawField(fld); */

	return( 0 );
}
Пример #16
0
extern Err vfsVolumeGetLabel(UInt16 volRefNum, Char *labelP, UInt16 bufLen)
{
    axxPacCardInfo cardinfo;
    Int32 ret;

    /* If the label was already retrieved, return it directly */
    if ( StrLen( label ) != 0 ) {
        StrNCopy( labelP, label, min( bufLen, 32 ) );
        return errNone;
    }

    ret = axxPacGetCardInfo(LibRef, &cardinfo);

    if ( ret == 0 ) {
        StrNCopy(labelP, cardinfo.vendor_name, min(bufLen, 16));
        StrNCat (labelP, cardinfo.device_name, bufLen) ;
        /* Keep the value for faster future accesses */
        StrNCat (label, labelP, min(bufLen, 32));
        return errNone;
    }
    else {
        return vfsErrVolumeBadRef;  
    }
}
Пример #17
0
static void ListDrawDataFunc(Int16 itemNum, RectangleType *bounds, Char **itemsText)
{
	char string[20];
	
	StrNCopy(string, GetDisplayString(itemNum), 19);

	WinSetUnderlineMode(noUnderline);
	FntSetFont(stdFont);
	Int16 width = bounds->extent.x;
	Int16 len = StrLen(string);
	Boolean noFit = false;
	FntCharsInWidth(string, &width, &len, &noFit);

	WinEraseRectangle(bounds, 0);
	WinDrawChars(string, len, bounds->topLeft.x, bounds->topLeft.y);
}
Пример #18
0
/* Rename document name in document list */
void UpdateDocumentName
    (
    UInt16      index,  /* record index */
    const Char* name,   /* new document name */
    const Char* filename  /* new filename */
    )
    /* THROWS */
{
    MemHandle       handle;
    DocumentData*   handlePtr;

    THROW_IF( name == NULL || *name == '\0', errNoDocumentName );

    handle = OpenRecord( plkrDocList, index );
    THROW_IF( handle == NULL, DmGetLastErr() );

    handlePtr = MemHandleLock( handle );
    DmWrite( handlePtr, OFFSETOF( DocumentData, name ),
        name, StrLen( name ) + 1 );
    if ( handlePtr->location != RAM ) {
        DocumentData*   dataPtr;
        UInt16          infoSize;
        UInt16          dataSize;
        Char            volumeLabel[ LABEL_LEN ];
        UInt16          fileLength;
        UInt16          volumeLabelLength;

        fileLength          = StrLen( handlePtr->data ) + 1;
        volumeLabelLength   = StrLen( handlePtr->data + fileLength ) + 1;
        StrNCopy( volumeLabel, handlePtr->data + fileLength,
            volumeLabelLength );

        MemHandleUnlock( handle );

        infoSize = sizeof *dataPtr;
        dataSize = StrLen( filename ) + StrLen( volumeLabel ) + 2;

        handle  = ResizeRecord( plkrDocList, index, infoSize + dataSize );
        dataPtr = MemHandleLock( handle );
        DmWrite( dataPtr, infoSize, filename, StrLen( filename ) + 1 );
        DmWrite( dataPtr, infoSize + StrLen( filename ) + 1, volumeLabel,
            StrLen( volumeLabel ) + 1 );
    }
    MemHandleUnlock( handle );
    CloseRecord( handle, true );
    DmInsertionSort( plkrDocList, CompareDocumentNames, 0 );
}
Пример #19
0
/*
** GetPlugString
*/
static void GetPlugString(Int16 plugindex, UInt16 rscID, Char* chrP) {
  SysDBListItemType* pluglistP = MemHandleLock(d.xfer.pluglistH);
  DmOpenRef dbR = DmOpenDatabase(pluglistP[plugindex].cardNo,
				 pluglistP[plugindex].dbID, dmModeReadOnly);
  MemHandle plugH = DmGet1Resource('BooG', rscID);

  ASSERT(dbR);
  ASSERT(plugH);

  if (!plugH) {
    StrCopy(chrP, "");
  } else {
    StrNCopy(chrP, MemHandleLock(plugH), 48); // FIXME constant should be symbolic
    MemHandleUnlock(plugH);
  }

  /* Clean up */
  MemHandleUnlock(d.xfer.pluglistH);
  DmCloseDatabase(dbR);
}
Пример #20
0
static void ListDrawDataFunc(Int16 itemNum, RectangleType *bounds, Char **itemsText)
{
	char string[50];
	
	if (itemNum < g_PhoneGroups.size()) {
		PhoneGroupPtr group = g_PhoneGroups[itemNum];
		StrNCopy(string, group->GetGroupName(), 49);
	} else {
		StrCopy(string, "");
	}

	WinSetUnderlineMode(noUnderline);
	FntSetFont(stdFont);
	Int16 width = bounds->extent.x;
	Int16 len = StrLen(string);
	Boolean noFit = false;
	FntCharsInWidth(string, &width, &len, &noFit);

	WinEraseRectangle(bounds, 0);
	WinDrawChars(string, len, bounds->topLeft.x, bounds->topLeft.y);
}
Пример #21
0
Err vfsFileRename (UInt16 volRefNum,  Char *pathNameP,  Char *newNameP)
{
    Int32 ret;
    Char newName[256];
    Int16 i;
    Int16 srclen;

    i = srclen = StrLen(pathNameP);
    /* in the AxxPac the Rename function can change the path. The new
       name must contain the original path */
    while ((1 < i) && (pathNameP[i - 1] != '/'))
        i--;
    StrNCopy(newName, pathNameP, i);
    newName[i] = chrNull;
    StrCat(newName, newNameP);
    ret = axxPacRename(LibRef, pathNameP, newName);
    if (ret < 0)
        return expErrNotOpen;
    else
        return errNone;
}
Пример #22
0
// ExgLibControl
Err FlickrControl(UInt16 libRefNum, UInt16 op, void *valueP, UInt16 *valueLenP)
{
    DMSG("FlickrControl() enter, op: ");DNUM(op);DMSG("; *valueLenP: ");DNUM(*valueLenP);DENDL
    FlickrDbOpen dbOpen;
    FlickrGlobalsPtr globals(libRefNum);
    switch (op)
    {
        case exgLibCtlGetTitle:
        {
            DMSG("FlickrControl(): exgLibCtlGetTitle\n");
            if (NULL == valueLenP)
                return exgErrBadParam;
            UInt16 len = StrLen(FlickrTitle);
            if (0 == *valueLenP || NULL == valueP)
            {
                *valueLenP = len;
                return errNone;
            }
            if (*valueLenP - 1 < len)
            {
                StrNCopy((char*)valueP, FlickrTitle, *valueLenP - 1);
                ((char*)valueP)[*valueLenP - 1] = chrNull;
            }
            else
            {
                StrCopy((char*)valueP, FlickrTitle);
                *valueLenP = len + 1;
            }
            return errNone;
        }
        case exgLibCtlGetVersion:
        {
            DMSG("FlickrControl(): exgLibCtlGetVersion\n");
            if (NULL == valueP || NULL == valueLenP || *valueLenP < 2)
                return exgErrBadParam;
            UInt16* ver = (UInt16*)valueP;
            *ver = exgLibAPIVersion;
            *valueLenP = 2;
            return errNone;
        }
        case exgLibCtlGetPreview:
            DMSG("FlickrControl(): exgLibCtlGetPreview\n");
            return exgErrNotSupported;

        case flickrCtlLibraryVersion:
        {
            DMSG("FlickrControl(): flickrCtlLibraryVersion\n");
            if (NULL == valueP || NULL == valueLenP || *valueLenP < 2)
                return exgErrBadParam;
            UInt16* ver = (UInt16*)valueP;
            *ver = FlickrVersion;
            *valueLenP = 2;
            return errNone;
        }         
        
        case flickrCtlInitializePrefs:
        {
            DMSG("FlickrControl(): flickrCtlInitializePrefs\n");
            FlickrPrefs* prefs = new FlickrPrefs;
            if (NULL == prefs)
                return memErrNotEnoughSpace;
            
            MemSet(prefs, sizeof(*prefs), 0);
            UInt16 size = sizeof(*prefs);
            Int16 ver = PrefGetAppPreferences(FlickrCreatorID, flickrPrefsResourceID, prefs, &size, true);
            if (noPreferenceFound != ver)
                goto Finish;
                
            PrvPrepareDescriptionText(*prefs);
            PrvPrepareTags(*prefs);
            FlickrSavePrefs(*prefs);
Finish:
            delete prefs;            
            return errNone;
        }   
    }
    return exgErrNotSupported;
}
Пример #23
0
static Boolean
ExamDetailsFormSave(void)
{
  MemHandle newExam=NULL;
  UInt16 index = dmMaxRecordIndex;
  ListType *course;
  ControlType *course_tr, *date_tr, *time_tr;
  Char *room;
  Char empty[1]={'\0'};
  FieldType *fldRoom;

  course = GetObjectPtr(LIST_exd_course);
  course_tr = GetObjectPtr(LIST_exd_course_trigger);
  date_tr = GetObjectPtr(SELECTOR_exd_date);
  time_tr = GetObjectPtr(SELECTOR_exd_time);

  fldRoom = GetObjectPtr(FIELD_exd_room);
  room = FldGetTextPtr(fldRoom);
  if (room == NULL)  room=empty;

  if (gExamsLastSelRowUID == 0) {
    // New record
    newExam = DmNewRecord(DatabaseGetRefN(DB_MAIN), &index, sizeof(ExamDBRecord));
  } else {
    // Load record
    DmFindRecordByID(DatabaseGetRefN(DB_MAIN), gExamsLastSelRowUID, &index);
    newExam = DmGetRecord(DatabaseGetRefN(DB_MAIN), index);
  }
  if (! newExam) {
    // Could not create entry
    FrmAlert(ALERT_nomem);
    return false;
  } else {
    UInt16 attr=0;
    ExamDBRecord ex, *ep;

    ep = (ExamDBRecord *)MemHandleLock(newExam);

    ex.type=TYPE_EXAM;
    ex.course=gExamDetailsItemIDs[LstGetSelection(course)];
    ex.note = (gExamsLastSelRowUID == 0) ? 0 : ep->note;
    ex.date.year = gExamDetailsDate.year;
    ex.date.month = gExamDetailsDate.month;
    ex.date.day = gExamDetailsDate.day;
    ex.begin.hours = gExamDetailsBegin.hours;
    ex.begin.minutes = gExamDetailsBegin.minutes;
    ex.end.hours = gExamDetailsEnd.hours;
    ex.end.minutes = gExamDetailsEnd.minutes;
    ex.flags = 0x0000;
    StrNCopy(ex.room, room, sizeof(ex.room));

    DmWrite(ep, 0, &ex, sizeof(ExamDBRecord));
    MemHandleUnlock(newExam);
    DmReleaseRecord(DatabaseGetRef(), index, false);
    DmRecordInfo(DatabaseGetRef(), index, &attr, NULL, NULL);
    attr |= DatabaseGetCat();
    DmSetRecordInfo(DatabaseGetRef(), index, &attr, NULL);

    DatabaseSort();
  } 

  AlarmReset(DatabaseGetRef());
  return true;
}
Пример #24
0
static void
ExamDetailsFormInit(FormType *frm)
{
  UInt16 selectedCourse=0;
  ListType *course;
  ControlType *course_tr, *date_tr, *time_tr;

  course = GetObjectPtr(LIST_exd_course);
  course_tr = GetObjectPtr(LIST_exd_course_trigger);
  date_tr = GetObjectPtr(SELECTOR_exd_date);
  time_tr = GetObjectPtr(SELECTOR_exd_time);

  gExamDetailsNumCourses = CountCourses();

  gExamDetailsItemList = (Char **) MemPtrNew(gExamDetailsNumCourses * sizeof(Char *));
  gExamDetailsItemIDs = (UInt16 *) MemPtrNew(gExamDetailsNumCourses * sizeof(UInt16));
  gExamDetailsItemInd = (UInt16 *) MemPtrNew(gExamDetailsNumCourses * sizeof(UInt16));

  if (gExamsLastSelRowUID == 0) {
    // ADD
    DateTimeType dt;

    selectedCourse = CourseListGen(gExamDetailsItemList, gExamDetailsItemIDs, gExamDetailsItemInd, gExamDetailsNumCourses, 0, CLIST_SEARCH_INDEX);

    TimSecondsToDateTime(TimGetSeconds(), &dt);
    gExamDetailsDate.year=dt.year-MAC_SHIT_YEAR_CONSTANT;

    gExamDetailsDate.month=dt.month;
    gExamDetailsDate.day=dt.day;

    gExamDetailsBegin.hours=14;
    gExamDetailsBegin.minutes=0;

    gExamDetailsEnd.hours=15;
    gExamDetailsEnd.minutes=30;

  } else {
    MemHandle mex, mRoom, old;
    ExamDBRecord *ex;
    UInt16 index=0;
    Char *buffer;
    FieldType *fldRoom;

    fldRoom=GetObjectPtr(FIELD_exd_room);

    DmFindRecordByID(DatabaseGetRefN(DB_MAIN), gExamsLastSelRowUID, &index);

    mex = DmQueryRecord(DatabaseGetRefN(DB_MAIN), index);
    ex = (ExamDBRecord *)MemHandleLock(mex);

    selectedCourse = CourseListGen(gExamDetailsItemList, gExamDetailsItemIDs, gExamDetailsItemInd, gExamDetailsNumCourses, ex->course, CLIST_SEARCH_ID);

    gExamDetailsDate.year=ex->date.year;
    gExamDetailsDate.month=ex->date.month;
    gExamDetailsDate.day=ex->date.day;

    gExamDetailsBegin.hours=ex->begin.hours;
    gExamDetailsBegin.minutes=ex->begin.minutes;

    gExamDetailsEnd.hours=ex->end.hours;
    gExamDetailsEnd.minutes=ex->end.minutes;

    // Copy contents to the memory handle
    mRoom=MemHandleNew(StrLen(ex->room)+1);
    buffer=(Char *)MemHandleLock(mRoom);
    MemSet(buffer, MemPtrSize(buffer), 0);
    StrNCopy(buffer, ex->room, StrLen(ex->room));
    MemHandleUnlock(mRoom);

    // Load fields
    old = FldGetTextHandle(fldRoom);
    FldSetTextHandle(fldRoom, mRoom);
    if (old != NULL)    MemHandleFree(old); 

    MemHandleUnlock(mex);
  }


  LstSetListChoices(course, gExamDetailsItemList, gExamDetailsNumCourses);
  if (gExamDetailsNumCourses < 5)  LstSetHeight(course, gExamDetailsNumCourses);
  else                 LstSetHeight(course, 5);
  LstSetSelection(course, selectedCourse);
  CtlSetLabel(course_tr, LstGetSelectionText(course, selectedCourse));

  ExamDetailsSetTriggers(date_tr, time_tr);
  EditTimeSetSelectorText(time_tr, &gExamDetailsBegin, &gExamDetailsEnd, gExamDetailsTimeTrigger);

}
Пример #25
0
/* Populate list with bookmarks, return number of bookmarks in list */
static UInt16 InitBookmarkList
    (
    ListType* list  /* pointer to list */
    )
{
    UInt16      recordNum;
    UInt16      numRecords;
    UInt16      extEntries;
    UInt16      bookmarks;
    UInt16      extraListItems;
    UInt16      index;
    UInt16      i;

    if ( isPopupList ) {
#ifdef SUPPORT_ANNOTATION
        extraListItems  = 3;
#else
        extraListItems  = 2;
#endif
    }
    else {
        extraListItems  = 0;   
    }

    ReleaseBookmarkList();

    extEntries  = CountExtBookmarks();
    bookmarks   = CountBookmarks();
    numRecords  = GetNumberOfAnnotations();

    numEntries  = extraListItems + extEntries + bookmarks;

    if ( numEntries == 0 ) {
        LstSetListChoices( list, nameList, NO_BOOKMARKS );
        LstSetDrawFunction( list, DrawListItem );

        return NO_BOOKMARKS;
    }

    bookmarkList = SafeMemPtrNew( numEntries *
                            sizeof( BookmarkListEntry* ) );

    for ( i = 0 ; i < numEntries ; i++ ) {
         bookmarkList[ i ] = SafeMemPtrNew( sizeof( BookmarkListEntry ) );
         MemSet( bookmarkList[ i ], sizeof( BookmarkListEntry ), 0 );
    }

    /* Allocate arrays for name list */
    nameList = SafeMemPtrNew( numEntries * sizeof( Char* ) );

    if ( isPopupList ) {
        SysCopyStringResource( addBookmark, strMainAddBookmark );
        nameList[ ADD_BOOKMARK ] = addBookmark;
        bookmarkList[ ADD_BOOKMARK ]->kind = BOOKMARK_ADD_BOOKMARK;
#ifdef SUPPORT_ANNOTATION
        SysCopyStringResource( addAnnotation, strMainAddAnnotation );
        nameList[ ADD_ANNOTATION ] = addAnnotation;
        bookmarkList[ ADD_ANNOTATION ]->kind = BOOKMARK_ADD_ANNOTATION;
#endif
        SysCopyStringResource( editBookmark, strMainViewBookmark );
        nameList[ EDIT_BOOKMARK ] = editBookmark;
        bookmarkList[ EDIT_BOOKMARK ]->kind = BOOKMARK_EDIT_BOOKMARK;
    }

    if ( 0 < extEntries ) {
        InitExtBookmarkList( nameList, extraListItems );
        for ( i = extraListItems ; i < extraListItems + extEntries ; i++ ) {
             bookmarkList[ i ]->kind      = BOOKMARK_EXT_BOOKMARK;
             bookmarkList[ i ]->recordNum = i - extraListItems;
        }
    }
    
    index = extraListItems + extEntries;
    
    for ( recordNum = 0 ; recordNum < numRecords && index < numEntries ;
          recordNum++ ) {

         MemHandle h;
         
         h = GetAnnotationByRecordNum( recordNum );
         
         if ( h != NULL ) {
             AnnotationEntry* entryP;

             entryP = MemHandleLock( h );
             
             if ( 1 < entryP->dataLength &&
                  ! ( ! ( entryP->flags & ANNOTATION_BOOKMARK ) &&
                    Prefs()->noAnnotationsInBookmarkList ) ) {
                 UInt32 labelSize;

                 labelSize = entryP->dataLength - 1;

                 if ( MAX_BOOKMARK_ENTRY_LENGTH < labelSize )
                     labelSize = MAX_BOOKMARK_ENTRY_LENGTH;

                 bookmarkList[ index ]->text = MemPtrNew( labelSize + 1 );

                 if ( bookmarkList[ index ]->text != NULL ) {
                     bookmarkList[ index ]->kind =
                         ( entryP->flags & ANNOTATION_BOOKMARK ) ?
                                BOOKMARK_BOOKMARK :
                                BOOKMARK_ANNOTATION;
                     bookmarkList[ index ]->recordNum = recordNum;

                     StrNCopy( bookmarkList[ index ]->text,
                         ( Char* )entryP + entryP->dataOffset, labelSize + 1 );
                     bookmarkList[ index ]->text[ labelSize ] = 0;

                     nameList[ index ] = bookmarkList[ index ]->text;

                     index++;
                 }
             }

             MemHandleUnlock( h );
         }
    }
    
    numEntries = index;

    LstSetListChoices( list, nameList, numEntries );
    LstSetDrawFunction( list, DrawListItem );

    if ( isPopupList )
        LstSetHeight( list, numEntries );

    return numEntries;
}
Пример #26
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");
	}
}
Пример #27
0
Boolean MapAirspaceCreate(const AirspaceType *as, MapAirspaceType *mas, AirspaceIDType id, UInt16 altUnits) {

	const char *segmentCode;
	const void *segRecordPtr;
	Int16 segNum = 0;
	LineType /*@relnull@*/ *lines = NULL;
	Int16 maxLines,j;

	LOGTIMESTART;

	mas->id   = id;
	mas->type = as->type;
	mas->clipCount = 0;

	segmentCode = as->segmentCode;

	/*
	 * altitude labels for airspace.
	 *
	 */

	AsDecodeAltitude(mas->upperAltString, &mas->upperAlt, altUnits, as->upperAltRef,
			as->upperAlt);
	AsDecodeAltitude(mas->lowerAltString, &mas->lowerAlt, altUnits, as->lowerAltRef,
			as->lowerAlt);

	/*
	 * if upper & lower altitudes are AGL, then set effective limits to 0-99999
	 * - otherwise above code will leave both limits at 99999 which will cause
	 *   filtering of the airspace
	 *
	 */

	if (as->lowerAltRef == altAgl) {

		mas->lowerAlt = 0;

	} 

	if (as->upperAltRef == altAgl) {

		mas->upperAlt = 99999;

	}

	if (as->type & asTypeAirway) {

		StrNCopy(mas->airwayIdent, GetStringFromList(as->segmentCode, 1), MAX_AIRWAY_CHARS);

		for (j=0;j<MAX_AIRWAY_CHARS;j++) {

			if (mas->airwayIdent[j] == 10) mas->airwayIdent[j] = 0;

		}

	}

	/*
	 * locate start of segment record, after end of two null-terminated
	 * strings (segmentCode and description)
	 *
	 */
	
	LOGSTR(segmentCode);
	segRecordPtr = segmentCode;
	while (*(char*)segRecordPtr != 0) segRecordPtr ++;
	segRecordPtr++;
	LOGSTR(segRecordPtr);
	while (*(char*)segRecordPtr != 0) segRecordPtr ++;
	segRecordPtr++;

	/*
	 * count the number of line we're likely to need
	 *
	 */

	maxLines = 0;

	for (j=0;segmentCode[j]!=0;j++) 
		maxLines += segmentCode[j] == 'l' ? 1 : 48;

	ModErrThrowIf(!maxLines);
	PFSafeMalloc(lines, sizeof(LineType)*maxLines);

	/*
	 * loop through the segments, adding them to the Boundary 
	 *
	 */

	mas->numLines = 0;

	while (mas->numLines < maxLines && *segmentCode != 0) {

		if ( *segmentCode == 'l' ) {

			LineSegmentType *l = (LineSegmentType*)segRecordPtr;
			Coord x, y;

			LOGLINE;
			y = (Coord) (((l->lat - latRef)) / latScale);
			x = (Coord) ((-l->lon - lonRef) / lonScale);

			if (segNum > 0) {
				
				BoundaryDrawLine(lines,mas->numLines,x,y);

			} else {

				BoundarySetCursor(x,y);

			}

			LOGLINE;
			segRecordPtr += sizeof(LineSegmentType);

		} else if ( *segmentCode == 'a' ) {

			ArcSegmentType *a = (ArcSegmentType*)segRecordPtr;
			Coord cx,cy, r;
			Int32 sn,cs;
			Int16 stepSize = 32768/24;
			Int32 radius = a->radius > 0 ? a->radius : - a->radius;
			const Coord referenceRadius = 80;

			cy = (Coord) ((a->lat - latRef) / latScale);
			cx = (Coord) ((-a->lon - lonRef) / lonScale);
			r  = (Coord) ((radius+(latScale/2))  / latScale);

			/*
			 * adjust the step-size according to radius
			 *
			 */
			
			if (r < referenceRadius) {

				if (r < referenceRadius / 2) {

					if (r < referenceRadius / 4)

						stepSize = 32768/8;

					else

						stepSize = 32768/12;

				} else {

					stepSize = 32768/16;

				}

			}

			if (a->start == a->end) {

				/* 
				 * arc is a circle
				 *
				 */

				Int16 angle = 0;
				Coord lastox, lastoy;
				
				lastox = 0;
				lastoy = r;
				for (angle = stepSize; angle <= 32768/4;angle += stepSize) {

					Coord ox, oy;
					IntSinCos(angle, &sn, &cs);

					ox = (Coord) ((sn*r + (COSINEZERO/2)) / COSINEZERO);
					oy = (Coord) ((cs*r + (COSINEZERO/2)) / COSINEZERO);

					/*
					 * top, right, bottom, left, in pairs
					 *
					 */

					BoundaryAddLine(lines,mas->numLines,cx + lastox, cy + lastoy, cx+ox, cy+oy);
					BoundaryAddLine(lines,mas->numLines,cx-ox, cy+oy, cx - lastox, cy + lastoy);
					
					BoundaryAddLine(lines,mas->numLines,cx+oy, cy+ox, cx + lastoy, cy + lastox);
					BoundaryAddLine(lines,mas->numLines,cx + lastoy, cy - lastox, cx+oy, cy-ox);

					BoundaryAddLine(lines,mas->numLines,cx+ox, cy-oy, cx + lastox, cy - lastoy);
					BoundaryAddLine(lines,mas->numLines,cx - lastox, cy - lastoy, cx-ox, cy-oy);

					BoundaryAddLine(lines,mas->numLines,cx - lastoy, cy + lastox, cx-oy, cy+ox);
					BoundaryAddLine(lines,mas->numLines,cx-oy, cy-ox, cx - lastoy, cy - lastox);

					lastox = ox;
					lastoy = oy;
				}

			} else {

				Coord ox, oy;
				Int32 angle = (Int32)a->start;

				if (segNum == 0) {

					/*
					 * first segment, position cursor to start
					 * of arc
					 *
					 */

					IntSinCos(a->start, &sn, &cs);

					ox = (Coord) ((sn*r + ROUND(sn)) / COSINEZERO);
					oy = (Coord) ((cs*r + ROUND(cs)) / COSINEZERO);
					BoundarySetCursor(cx+ox, cy+oy);

				}

				if (a->radius > 0 ) {

					/*
					 * clockwise arc
					 *
					 */

					if (a->end < a->start) {

						/*
						 * must draw arc in two
						 * parts - draw up to
						 * 180 degrees first
						 *
						 */

						for ( ; angle < 32767; angle += stepSize) {

							IntSinCos((Int16)angle, &sn, &cs);

							ox = (Coord) ((sn*r + ROUND(sn)) / COSINEZERO);
							oy = (Coord) ((cs*r + ROUND(cs)) / COSINEZERO);
							BoundaryDrawLine(lines,mas->numLines,cx+ox, cy+oy);

						}

						angle -= 65536;

					}

					for (; angle < a->end; angle += stepSize) {

						IntSinCos((Int16)angle, &sn, &cs);

						ox = (Coord) ((sn*r + ROUND(sn)) / COSINEZERO);
						oy = (Coord) ((cs*r + ROUND(cs)) / COSINEZERO);
						BoundaryDrawLine(lines,mas->numLines,cx+ox, cy+oy);

					}

					angle += stepSize;

				} else {

					/*
					 * anti-clockwise arc
					 *
					 */

					if (a->end > a->start) {

						/*
						 * must draw arc in two
						 * parts - draw up to
						 * 180 degrees first
						 *
						 */

						for ( ; angle > -32768; angle -= stepSize) {

							IntSinCos((Int16)angle, &sn, &cs);

							ox = (Coord) ((sn*r + ROUND(sn)) / COSINEZERO);
							oy = (Coord) ((cs*r + ROUND(cs)) / COSINEZERO);
							BoundaryDrawLine(lines,mas->numLines,cx+ox, cy+oy);

						}

						angle = angle + 65536;

					}

					for (; angle > a->end; angle -= stepSize) {

						IntSinCos(angle, &sn, &cs);

						ox = (Coord) ((sn*r + ROUND(sn)) / COSINEZERO);
						oy = (Coord) ((cs*r + ROUND(cs)) / COSINEZERO);
						BoundaryDrawLine(lines,mas->numLines,cx+ox, cy+oy);

					}

					angle -= stepSize;

				}

				IntSinCos(a->end, &sn, &cs);

				ox = (Coord) ((sn*r + ROUND(sn)) / COSINEZERO);
				oy = (Coord) ((cs*r + ROUND(cs)) / COSINEZERO);
				BoundaryDrawLine(lines,mas->numLines,cx+ox, cy+oy);

			}

			segRecordPtr += sizeof(ArcSegmentType);

		} else {

			ModErrThrow();

		}

			LOGLINE;
		segmentCode++;
		segNum++;

	}

	LOGINT16(mas->numLines);

	/*
	 * if airspace has some line segments, then calculate its bounding
	 * box and label hint position
	 *
	 */

	LOGTIMESTOP;

	if (mas->numLines) {

		Coord minx = 32000, miny = 32000;
		Coord maxx = -32000, maxy = -32000;
		Int32 range, minRange = 2147483647;
		Int16 closestPoint = 0;
		Boolean locked = false;

		Coord xmid, ymid;
		Coord xvec, yvec;
		Int32 sf;
		Int16 j;

		mas->lines = PFMalloc(mas->numLines*sizeof(LineType));

		PFMemMove(mas->lines, lines, mas->numLines*sizeof(LineType));

		for (j=0;j<mas->numLines;j++) {

			Coord xmid, ymid;

			minx = MIN(minx, lines[j].x1);
			miny = MIN(miny, lines[j].y1);
			minx = MIN(minx, lines[j].x2);
			miny = MIN(miny, lines[j].y2);

			maxx = MAX(maxx, lines[j].x1);
			maxy = MAX(maxy, lines[j].y1);
			maxx = MAX(maxx, lines[j].x2);
			maxy = MAX(maxy, lines[j].y2);

			xmid = lines[j].x1 + (lines[j].x2 - lines[j].x1)/2;
			ymid = lines[j].y1 + (lines[j].y2 - lines[j].y1)/2;

			if (!locked) {

				range = (Int32)xmid*(Int32)xmid + (Int32)ymid*(Int32)ymid;
				if (range < minRange) {

					minRange = range;
					closestPoint = j;

				}

			}

		}

#ifdef XXXX
		if (maxx - minx < 30 && maxy-miny < 30) {

			PFMemFree(mas->lines);
			PFMemFree(lines);
			return false;

		}
#endif

		PFScreenRectangleSet(&mas->bounds, minx, miny, maxx, maxy);

		/*
		 * the hint is half way along the middle line of the boundary.
		 * we'll use j as the pointer to it.
		 *
		 */

		j = closestPoint;
		
		/*
		 * initialise vector, then scale it to length 12 (or 24 for
		 * high density) pixels
		 *
		 */
		
		xvec = (lines[j].x2 - lines[j].x1)/2;
		yvec = (lines[j].y2 - lines[j].y1)/2;
		xmid = xvec + lines[j].x1;
		ymid = yvec + lines[j].y1;
		
		/*
		 * label airspace inside the boundary. label airways
		 * across the segment.
		 *
		 */

		if (as->type & asTypeAirspace) {

			sf = (24 * 32768) / (Int32)sqrt(MAX(1,xvec*xvec + yvec*yvec));

			xvec = (Coord) (((Int32)xvec * sf) / 32768);
			yvec = (Coord) (((Int32)yvec * sf) / 32768);
			
			/*
			 * note the rotation by 90 degrees:
			 *
			 * 	xn = xcos + ysin, yn = ycos - xsin
			 * 
			 * Sin(90) = 1 and Cos(90) = 0 therefore xn = y, yn = -x
			 *
			 */

			mas->labelHint.x = xmid + yvec;
			mas->labelHint.y = ymid - xvec;

		} else {

			mas->labelHint.x = xmid;
			mas->labelHint.y = ymid;

		}

		PFMemFree(lines);
		return true;

	}

	/*
	 * airspace has no segments on screen
	 *
	 */

	PFMemFree(lines);

	return false;

}
Пример #28
0
Int16 StrVPrintF(Char * s, const Char* formatStr, _Palm_va_list arg)
{
	Char *		curFormatP;
	Char *		startOfBlockP;
	Char *		dstP;
	const Char* formatP;
	Int32		   numberToConvert;
	Char *	   strP;
	WChar			wideChar;
	Char			wideStr[maxCharBytes + 1];
	Int16		   minimumSize = 0;
	Char		   signFlag = 0;
	Boolean     leftJustify = false;
	Boolean     zeroPad = false;
	SizeModifierType sizeModifier;

	
	// Check for err
	ErrNonFatalDisplayIf(s == NULL || formatStr == NULL, "NULL string passed");
	
	// Init vars.
	formatP = formatStr;
	dstP=s;													//Save the front of the string
	
	// Look for next format specification
	while(*formatP) {
		// If no more %'s, print the rest
		curFormatP = StrChr(formatP, '%');
		if (!curFormatP)
		 	{
			StrCopy(dstP, formatP); //Move the rest of the format string into the destination string.
			break;
			}
			
		// If there is another %, print everything up to it
		//Move all the characters before the % sign into the destination string
		StrNCopy(dstP, formatP, curFormatP - formatP);
		dstP += curFormatP - formatP;
		*dstP = '\0';
		
		// point to format character
		formatP = curFormatP+1;




		/********* Flags ************
			'+'  Flag will cause a plus or a minus sign to be printed ahead of the number 
			Example:
				printf("%+d  %+d",4,-5);
			Outputs:
					+4  -5
			' '  Flag will cause a space or a minus sign to be printed ahead of the number
			Example:
				printf("% d  % d",4,-5);
			Output:
				 4  -5
			'-'  Flag will cause the result of the conversion to be left justified
			Example:
				printf("%5d%-5d%d",6,9,8);
			Output:
				    69    8
		*/
		
		while ( true )	
			{
			 if(formatP[0] == '+')
				{
				signFlag = '+';
				formatP++;
				}
			 else if(formatP[0] ==' ')
			 	{
				if(signFlag != '+')
					signFlag =' ';
				formatP++;
				}
			else if(formatP[0] =='-')
				{
				leftJustify = true;
				formatP++;	
				}
			else if(formatP[0] == '0')
				{
				zeroPad = true;
				formatP++;
				}
			else
				break;
			}



		/********** Minimum Field Width **************
			'*' modifier will casue the next argument on the list to be taken in and used as
			 the field width.
			 Example:
			 	printf("%*d%d",4,8,5);
			 Output:
			 	8   5
			 Placing a number between the % and the conversion will cause at least that number of 
			 spaces to be placed in the result string for that conversion
			 Example:
			 	printf("%d%5d",4,3);
			 Output:
			 	4    3		
		*/
	   if (formatP[0] == '*')						// MemHandle variable length padding
			{
			minimumSize = va_arg(arg,int);
			formatP++;
			}
		else
			{
			
		    while(formatP[0] <='9' && formatP[0] >= '0')  // MemHandle fixed padding
Пример #29
0
void PrivDrawCell(void* table, Int16 row, Int16 column, RectanglePtr bounds)
{
	char string[50];
	FontID font = stdFont;

	if (g_CurrentRow != row) {
		if (g_CurrentMemHandle) {
			MemHandleUnlock(g_CurrentMemHandle);
			g_CurrentMemHandle = NULL;
		}
	}
	if (g_CurrentMemHandle == NULL) {
		Err err = GetSMSRecord(g_SmsDb, g_SelectedCategory, row + g_CurrentPage * TABLE_PAGE_SIZE, 
			g_CurrentRecord, g_CurrentMemHandle, true);
		if (err) return;
		g_CurrentRow = row;
	}
		
	switch(column) {
		case 0:
			StrCopy(string, "");
			if (g_SelectedCategory == CAT_INBOX) {
				if (IsRecordRead(&g_CurrentRecord)) {
					StrCopy(string, "");
				} else {
					font = symbolFont;
					StrCopy(string, "\020");
				}
			} else if (g_SelectedCategory == CAT_SENT) {
				if (IsRecordRequestReport(&g_CurrentRecord)) {
					font = symbolFont;
					if (IsRecordDelivered(&g_CurrentRecord)) {
						StrCopy(string, "\026");
					} else {
						StrCopy(string, "\024");
					}
				}
			}
			break;
		case 1:
			StrNCopy(string, g_CurrentRecord.personName, 48);
			if (StrLen(string) == 0) {
				StrNCopy(string, g_CurrentRecord.phoneNumber, 48);
			}
			break;
		case 2:
			StrNCopy(string, g_CurrentRecord.content, 48);
			break;
		case 3:
			{
				DateTimeType smsDatetime;
				TimSecondsToDateTime(g_CurrentRecord.time, &smsDatetime);

				UInt32 nowSeconds = TimGetSeconds();
				DateTimeType nowDatetime;
				TimSecondsToDateTime(nowSeconds, &nowDatetime);
				
				if ((nowDatetime.year == smsDatetime.year) && 
					(nowDatetime.month == smsDatetime.month) &&
					(nowDatetime.day == smsDatetime.day)) {
					TimeToAscii(smsDatetime.hour, smsDatetime.minute, tfColon24h, string);
				} else {
					StrCopy(string, DayOfWeekInChinese[DayOfWeek(smsDatetime.month, smsDatetime.day, smsDatetime.year)]);
					DateTemplateToAscii(" ^3z-^0z", smsDatetime.month, smsDatetime.day, smsDatetime.year, string + 2, 47);
				}
				MemHandleUnlock(g_CurrentMemHandle);
				g_CurrentMemHandle = NULL;
			}
			break;
		default:
			StrCopy(string, "");
	}

	WinPushDrawState();
	
	RGBColorType foreColor, backColor;

	foreColor.index = 0;
	backColor.index = 0;
	if ((row == g_CurrentSelection) && (column != 0)) {
		foreColor.r = 255;
		foreColor.g = 255;
		foreColor.b = 255;
		
		backColor.r = 10;
		backColor.g = 36;
		backColor.b = 106;
	} else if (row % 2 == 0) {
		backColor.r = 255;
		backColor.g = 255;
		backColor.b = 255;
		
		foreColor.r = 0;
		foreColor.g = 0;
		foreColor.b = 0;
	} else {
		backColor.r = 220;
		backColor.g = 220;
		backColor.b = 220;
		
		foreColor.r = 0;
		foreColor.g = 0;
		foreColor.b = 0;
	}
	WinSetForeColorRGB(&foreColor, NULL);
	WinSetTextColorRGB(&foreColor, NULL);
	WinSetBackColorRGB(&backColor, NULL);
	
	WinSetUnderlineMode(noUnderline);
		
	FntSetFont(font);

	Int16 width = bounds->extent.x - 2;
	Int16 len = StrLen(string);
	Boolean noFit = false;
	FntCharsInWidth(string, &width, &len, &noFit);
	
	UInt16 x = bounds->topLeft.x;
	UInt16 y = bounds->topLeft.y;
	
	bounds->topLeft.x += - 1;
	bounds->topLeft.y += 0;
	bounds->extent.x += 2;
	bounds->extent.y += 0;
	
	WinEraseRectangle(bounds, 0);
	WinDrawGrayLine(
		bounds->topLeft.x + bounds->extent.x - 2, 
		bounds->topLeft.y,
		bounds->topLeft.x + bounds->extent.x - 2, 
		bounds->topLeft.y + bounds->extent.y);// - 2);
		
	WinDrawChars(string, len, x, y);
	
	WinPopDrawState();
}
Пример #30
0
UInt inshop()
{
  Short roomno = inroom(you.ux,you.uy);

  /* Did we just leave a shop? */
  if (you.uinshop &&
      (you.uinshop != roomno + 1 || shlevel != dlevel || !shopkeeper)) {
    if (shopkeeper) {
      if (ESHK(shopkeeper)->billct) {
	if (inroom(shopkeeper->mx, shopkeeper->my) 
	    == you.uinshop - 1)	/* ab@unido */
	  message("Somehow you escaped the shop without paying!");
	addupbill();
	StrPrintF(ScratchBuffer,"You stole for a total worth of %ld zorkmids.",
		  total);
	message(ScratchBuffer);
	ESHK(shopkeeper)->robbed += total;
	setpaid();
	if ((rooms[ESHK(shopkeeper)->shoproom].rtype == GENERAL)
	    == (rund(3) == 0))
	  ESHK(shopkeeper)->following = true;
      }
      shopkeeper = NULL;
      shlevel = 0;
    }
    you.uinshop = 0;
  }

  /* Did we just enter a zoo of some kind? */
  if (roomno >= 0) {
    Short rt = rooms[roomno].rtype;
    monst_t *mtmp;
    if (rt == ZOO) {
      message("Welcome to David's treasure zoo!");
    } else
      if (rt == SWAMP) {
	message("It looks rather muddy down here.");
      } else
	if (rt == MORGUE) {
	  if (midnight())
	    message("Go away! Go away!");
	  else
	    message("You get an uncanny feeling ...");
	} else
	  rt = 0;
    if (rt != 0) {
      rooms[roomno].rtype = 0;
      for (mtmp = fmon ; mtmp ; mtmp = mtmp->nmon)
	if (rt != ZOO || !rund(3))
	  mtmp->bitflags &= ~M_IS_ASLEEP;
    }
  }

  /* Did we just enter a shop? */
  if (roomno >= 0 && rooms[roomno].rtype >= 8) {
    if (shlevel != dlevel || !shopkeeper
	|| ESHK(shopkeeper)->shoproom != roomno)
      findshk(roomno);
    if (!shopkeeper) {
      rooms[roomno].rtype = 0;
      you.uinshop = 0;
    } else if (!you.uinshop) {
      if (!ESHK(shopkeeper)->visitct ||
	  StrNCompare(ESHK(shopkeeper)->customer, plname, PL_NSIZ)) {

	/* He seems to be new here */
	ESHK(shopkeeper)->visitct = 0;
	ESHK(shopkeeper)->following = false;
	StrNCopy(ESHK(shopkeeper)->customer, plname, PL_NSIZ);
	shopkeeper->bitflags |= M_IS_PEACEFUL; // NOTANGRY(shopkeeper) = 1;
      }
      if (!ESHK(shopkeeper)->following) {
	Boolean box, pick;

	StrPrintF(ScratchBuffer, "Hello %s! Welcome%sto %s's %s shop!",
		  plname,
		  ESHK(shopkeeper)->visitct++ ? " again " : " ",
		  shkname(shopkeeper),
		  shopnam[rooms[ESHK(shopkeeper)->shoproom].rtype - 8] );
	message(ScratchBuffer);
	box = carrying(ICE_BOX);
	pick = carrying(PICK_AXE);
	if (box || pick) {
	  if (do_chug(shopkeeper)) {
	    you.uinshop = 0;	/* he died moving */
	    return 0;
	  }
	  StrPrintF(ScratchBuffer, "Will you please leave your %s outside?",
		    (box && pick) ? "box and pick-axe" :
		    box ? "box" : "pick-axe");
	  message(ScratchBuffer);
	}
      }
      you.uinshop = roomno + 1; // (0 is "not in shop")
    }
  }
  return you.uinshop;
}