📄 beam.c
字号:
/* -*-Mode:C; tab-width:4; indent-tabs-mode:t; c-file-style:"stroustrup";-*- *//* beam.c * Copyright (c) 2001 Philippe Caillaud <pcaillaud@free.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "beam.h"#include "progect.h"// Call-back procedure prototypesErr readProc(void* dataP, UInt32* sizeP, void* userDataP);Err writeProc (const void* dataP, UInt32* sizeP, void* userDataP);Boolean deleteProc(const char* nameP, UInt16 version, UInt16 cardNo, LocalID dbID, void* userDataP);/****************************************************** * Name: SendDB * Desc: send a database thanks to the Exchange Manager * Parm: -> the database name, the file name extension, * and the creator ID * Out : <- error code * Auth: PhC, May 2001. *****************************************************/Err SendDB(UInt32 CrID, const Char* dbName, const Char* FileNameExt, const Char* descr){ ExgSocketType mySocket; UInt32 FileNameLen = StrLen(dbName) + StrLen(FileNameExt) + 1; Char* FileName = (Char*) MemPtrNew(FileNameLen); const UInt16 cardNo = 0; LocalID dbID = DmFindDatabase(cardNo, dbName); Err err = DmGetLastErr(); if(!dbID) { MemPtrFree(FileName); return err; } MemSet(&mySocket, sizeof(mySocket), 0); mySocket.target = CrID; mySocket.description = descr; if(FileName) { SafeCopy(FileName, dbName,FileNameLen); StrNCat(FileName, FileNameExt,FileNameLen); mySocket.name = FileName; } if((err = ExgPut(&mySocket))) { MemPtrFree(FileName); return err; } err = ExgDBWrite(writeProc, &mySocket, dbName, dbID, cardNo); err = ExgDisconnect(&mySocket, err); MemPtrFree(FileName); return err;} /* Err SendDB(UInt32 CrID, const Char* dbName, cont Char* FileNameExt, const Char* descr) *//***************************************************** * Name: RecvDB * Desc: Receives a database from the Exchange Manager * Parm: -> the socket to read from * Out : <- error code * Auth: PhC, May 2001 *****************************************************/Err RecvDB(ExgSocketPtr socketP) { Err err; LocalID dbID; UInt16 cardNo = 0; Boolean needReset, keepDates = true; if((err = ExgAccept(socketP))) return err; err = ExgDBRead(&readProc, &deleteProc, socketP, &dbID, cardNo, &needReset, keepDates); return ExgDisconnect(socketP, err);} /* Err RecvDB(ExgSocketPtr socketP) *//************************ * Call-back procedures * ************************/Err writeProc (const void* dataP, UInt32* sizeP, void* userDataP){ Err err; *sizeP = ExgSend((ExgSocketPtr) userDataP, dataP, *sizeP, &err); return err;} /* Err writeProc (const void* dataP, UInt32* sizeP, void* userDataP) */ Err readProc (void* dataP, UInt32* sizeP, void* userDataP){ Err err; *sizeP = ExgReceive((ExgSocketPtr) userDataP, dataP, *sizeP, &err); return err;} /* Err ReadProc (void* dataP, UInt32* sizeP, void* userDataP) */Boolean deleteProc (const char* nameP, UInt16 version, UInt16 cardNo, LocalID dbID, void* userDataP){ // Ignore the received DB... return false;} /* Boolean deleteProc (const char* nameP, UInt16 version, UInt16 cardNo, LocalID dbID, void* userDataP) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -