⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memotransfer.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 4 页
字号:
					err = DmSetRecordInfo(dbP, indexNew, &attr, NULL);
				}
			}

			PrvMemoImportFinishRecord(dbP, indexNew, &newRecordH, &newRecordSize, inputStream);
			numRecordsReceived++;

			// save the uniqueID of the first record we loaded
			// we will goto this record when we are done (after sorting)
			if (!firstRecordID)
			{
				// Store the information necessary to navigate to the record inserted.
				DmRecordInfo(dbP, indexNew, NULL, &firstRecordID, NULL);
			}

			// Now that the record is imported check if we need to import any more

			// Stop if there isn't any more input
			if (bufferLength == 0)
				break;

			// Stop if the boundary is followed by "--"
			if ((*boundaryString != nullChr)
				&& bufferLength >= StrLen(boundaryString) + 2
				&& StrNCompareAscii(&buffer[StrLen(boundaryString)], "--", 2) == 0)
				break;

		} while (true);	// end of segment parser
	}	// end of Try

	ErrCatch(inErr)
	{
		// PREVIEW Aba
		if (descriptionP)
			return false;

		// Remove any incomplete record
		if (inErr && indexNew != dmMaxRecordIndex)
			DmRemoveRecord(dbP, indexNew);

		// if we got at least one record, sort and set goto parameters...
		if (firstRecordID)
		{
			MemoSort(dbP);
			PrvMemoSetGoToParams (dbP, PrvStreamSocket(inputStream), firstRecordID);
		}
	
		// return number of records received
		*numRecordsReceivedP = numRecordsReceived;
	
		if ( inErr != exgMemError )
			PrvMemoImportMimeCleanup(dbP, firstRecordID, inputStream, numRecordsReceived, numRecordsReceivedP);

		ErrThrow(inErr);
	} ErrEndCatch

	PrvMemoImportMimeCleanup(dbP, firstRecordID, inputStream, numRecordsReceived, numRecordsReceivedP);

	return false;
}


/***********************************************************************
 *
 * FUNCTION:    MemoSendRecord
 *
 * DESCRIPTION: Beam or send a record.
 *
 * PARAMETERS:		dbP - pointer to the database to add the record to
 * 					recordNum - the record to send
 *					prefix - the scheme with ":" suffix and optional "?" prefix
 *
 * RETURNED:    true if the record is found and sent
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         roger   5/9/97   Initial Revision
 *		   dje     4/21/00	Add Send support
 *         dje     4/24/00  Don't specify target creator ID
 *
 ***********************************************************************/
extern void MemoSendRecord (DmOpenRef dbP, Int16 recordNum, const Char * const prefix)
{
	MemoDBRecordPtr recordP;
	MemHandle recordH;
	MemHandle descriptionH;
	Err error;
	ExgSocketType exgSocket;
	MemHandle nameH;


	// important to init structure to zeros...
	MemSet(&exgSocket, sizeof(exgSocket), 0);

	// Form a description of what's being sent.  This will be displayed
	// by the system send dialog on the sending and receiving devices.
	recordH = DmQueryRecord (dbP, recordNum);
	recordP = (MemoDBRecordType *) MemHandleLock(recordH);

	// Set the description to be the beginning of the memo
	descriptionH = NULL;
	exgSocket.description = NULL;

	// Set the exg description to the record's description.
	PrvSetDescriptionAndFilename(&recordP->note, &exgSocket.description,
							  &descriptionH, &exgSocket.name, &nameH, prefix);

	// ABa: Clean superfluous '.' characters
	PrvTransferCleanFileName(exgSocket.name);

	exgSocket.length = MemHandleSize(recordH);		// rough guess
	//exgSocket.target = sysFileCMemo;		// commented out 4/24/00 dje
	exgSocket.type = (Char *)memoMIMEType;
	error = ExgPut(&exgSocket);   // put data to destination
	if (!error)
	{
		error = PrvMemoSendRecordTryCatch(dbP, recordNum, recordP, &exgSocket);

		ExgDisconnect(&exgSocket, error);
	}


	// Clean up
	if (descriptionH)
	{
		MemHandleUnlock (descriptionH);
		if (MemHandleDataStorage (descriptionH))
			DmReleaseResource(descriptionH);	// DOLATER dje - this shouldn't be possible any more
		else
			MemHandleFree(descriptionH);
	}
	if (nameH)
	{
		MemHandleUnlock (nameH);
		if (MemHandleDataStorage (nameH))
			DmReleaseResource(nameH);		// DOLATER dje - this shouldn't be possible any more
		else
			MemHandleFree(nameH);
	}
	MemHandleUnlock(recordH);


	return;
}


/***********************************************************************
 *
 * FUNCTION:    MemoSendCategory
 *
 * DESCRIPTION: Beam or send all visible records in a category.
 *
 * PARAMETERS:		 dbP - pointer to the database to add the record to
 * 					 categoryNum - the category of records to send
 *					 prefix - the scheme with ":" suffix and optional "?" prefix
 *					 noDataAlertID - alert to put up if there is nothing to send
 *
 * RETURNED:    true if any records are found and sent
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         roger   5/9/97   Initial Revision
 *		   dje     4/21/00	Add Send support
 *         dje     4/24/00  Don't specify target creator ID
 *
 ***********************************************************************/
extern void MemoSendCategory (DmOpenRef dbP, UInt16 categoryNum, const Char * const prefix, UInt16 noDataAlertID)
{
	Err error;
	Char description[dmCategoryLength];
	UInt16 index;
	Boolean foundAtLeastOneRecord;
	ExgSocketType exgSocket;
	UInt16 mode;
	LocalID dbID;
	UInt16 cardNo;
	Boolean databaseReopened;


	// If the database was opened to show secret records, reopen it to not see
	// secret records.  The idea is that secret records are not sent when a
	// category is sent.  They must be explicitly sent one by one.
	DmOpenDatabaseInfo(dbP, &dbID, NULL, &mode, &cardNo, NULL);
	if (mode & dmModeShowSecret)
	{
		dbP = DmOpenDatabase(cardNo, dbID, dmModeReadOnly);
		databaseReopened = true;
	}
	else
		databaseReopened = false;


	// important to init structure to zeros...
	MemSet(&exgSocket, sizeof(exgSocket), 0);

	// Make sure there is at least one record in the category.
	index = 0;
	foundAtLeastOneRecord = false;
	while (true)
	{
		if (DmSeekRecordInCategory(dbP, &index, 0, dmSeekForward, categoryNum) != 0)
			break;

		foundAtLeastOneRecord = DmQueryRecord(dbP, index) != 0;
		if (foundAtLeastOneRecord)
			break;


		index++;
	}


	// We should send the category because there's at least one record to send.
	if (foundAtLeastOneRecord)
	{
		// Form a description of what's being sent.  This will be displayed
		// by the system send dialog on the sending and receiving devices.
		CategoryGetName (dbP, categoryNum, description);
		exgSocket.description = description;

		// Now form a file name
		exgSocket.name = MemPtrNew(StrLen(prefix) + StrLen(description) + StrLen(memoSuffix) + sizeOf7BitChar('\0'));
		if (exgSocket.name)
		{
			StrCopy(exgSocket.name, prefix);
			StrCat(exgSocket.name, description);
			StrCat(exgSocket.name, memoSuffix);
		}

		// ABa: Clean superfluous '.' characters
		PrvTransferCleanFileName(exgSocket.name);

		exgSocket.length = 0;		// rough guess
		//exgSocket.target = sysFileCMemo;		// commented out 4/24/00 dje
		exgSocket.type = (Char *)memoMIMEType;
		error = ExgPut(&exgSocket);   // put data to destination

		if (!error)
		{
			error = PrvMemoSendCategoryTryCatch (dbP, categoryNum, &exgSocket, index);

			ExgDisconnect(&exgSocket, error);
		}

		// Clean up
		if (exgSocket.name)
			MemPtrFree(exgSocket.name);
	}
	else
		FrmAlert(noDataAlertID);

	if (databaseReopened)
		DmCloseDatabase(dbP);

	return;
}


/***********************************************************************
 *
 * FUNCTION:		MemoReceiveData
 *
 * DESCRIPTION:		Receives data into the output field using the Exg API
 *
 * PARAMETERS:		dbP - database to put received memos in
 *						exgSocketP - socket from the app code sysAppLaunchCmdExgReceiveData
 *						numRecordsReceivedP - number of records received is returned here
 *
 * RETURNED:		error code or zero for no error.
 *
 *	REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			grant	6/25/99	Keep count of received records and return in numRecordsReceivedP
 *
 ***********************************************************************/
extern Err MemoReceiveData(DmOpenRef dbP, ExgSocketPtr exgSocketP, UInt16 *numRecordsReceivedP)
{
	volatile Err err;
	UInt16 numRecordsReceived;
	StreamType stream;

	// initialize new record count
	ErrNonFatalDisplayIf(numRecordsReceivedP == NULL, "NULL numRecordsReceivedP");
	*numRecordsReceivedP = 0;

	PrvStreamInit( &stream, exgSocketP);

	// accept will open a progress dialog and wait for your receive commands
	err = ExgAccept(exgSocketP);

	if (!err)
	{
		// Catch errors receiving records.  The import routine will clean up the
		// incomplete record.  This routine displays an error message.
		ErrTry
		{
			// Keep importing records until it can't
			while (MemoImportMime(dbP, &stream, PrvReadFunction, false, false, &numRecordsReceived, NULL, 0))
			{
				*numRecordsReceivedP += numRecordsReceived;
			};

// catch the records from the final MemoImportMime
			*numRecordsReceivedP += numRecordsReceived;
		}

		ErrCatch(inErr)
		{
			err = inErr;
		} ErrEndCatch

		// Aba: A record has been added in the Database iff the GoTo
		// uniqueID parameter != 0.
		// In the case no record is added, return an error
		if (err == errNone && exgSocketP->goToParams.uniqueID == 0)
			err = exgErrBadData;
	
		ExgDisconnect(exgSocketP, err); // closes transfer dialog
		err = errNone;	// error was reported, so don't return it
	}

	return err;
}


/************************************************************
 *
 * FUNCTION: MemoExportMime
 *
 * DESCRIPTION: Export a record as a Imc Mime record
 *
 * PARAMETERS:
 *			dbP - pointer to the database to export the records from
 *			index - the record number to export
 *			recordP - whether the begin statement has been read
 *			outputStream - pointer to where to export the record to
 *			outputFunc - function to send output to the stream
 *			writeUniqueIDs - true to write the record's unique id
 *
 * RETURNS: nothing
 *
 *	REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			rsf		8/6/97		Initial Revision
 *			vsm		12/3/02		If the note is encoded in anything other than
 *								usAscii, then send the correct charset rather
 *								than ISO-8859-1.
 *
 *************************************************************/

void MemoExportMime(DmOpenRef UNUSED_PARAM(dbP), Int16 UNUSED_PARAM(index), MemoDBRecordType * recordP,
					void * outputStream, WriteFunctionF outputFunc, Boolean UNUSED_PARAM(writeUniqueIDs),
					Boolean outputMimeInfo)
{
	Char * c;
	Char * eolP;
	UInt32 len;
	CharEncodingType	curEncoding;


	// Write out all of the memo.  All linefeeds must be replaced with CRLF combos.
	c = &recordP->note;

	if (outputMimeInfo)
	{
		if ((curEncoding = TxtStrEncoding((Char const *)c)) != charEncodingAscii)
		{
			outputFunc(outputStream, "Content-Type: Text/plain; charset=" , stringZLen);
			outputFunc(outputStream, TxtEncodingName(curEncoding), stringZLen);
			outputFunc(outputStream, crlf, stringZLen);
		}

		outputFunc(outputStream, crlf, stringZLen);
	}

	while (*c != '\0')
	{
		eolP = StrChr(c, linefeedChr);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -