Esempio n. 1
0
static BOOL WriteDIB(
/************************************************************************/
LPBITMAPINFOHEADER lpInfo,
LPSTR lpImageFile)
{
DWORD lCount;
WORD wCount;
HPTR lpClipPtr;
BITMAPFILEHEADER bmhdr;
int ofh;

bmhdr.bfType = 0x4D42;
bmhdr.bfReserved1 = 0;
bmhdr.bfReserved2 = 0;
bmhdr.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
if (lpInfo->biBitCount == 8)
	bmhdr.bfOffBits += ( 256 * sizeof(RGBQUAD) );
else
if (lpInfo->biBitCount == 4)
	bmhdr.bfOffBits += ( 16 * sizeof(RGBQUAD) );
else
if (lpInfo->biBitCount == 1)
	bmhdr.bfOffBits += ( 2 * sizeof(RGBQUAD) );

lCount = bmhdr.bfOffBits + lpInfo->biSizeImage;
bmhdr.bfSize = lCount/2;

// write the winclip.bmp file
if ( (ofh = _lcreat( lpImageFile, 0 )) < 0 )
	{
	Message (IDS_EOPEN, lpImageFile);
	return(FALSE);
	}
if ( _lwrite( ofh, (LPSTR)&bmhdr, 14 ) != 14 )
	{
	Message (IDS_EWRITE, lpImageFile);
	_lclose(ofh);
	return(FALSE);
	}
lCount -= 14;
lpClipPtr = (HPTR)lpInfo;
while( lCount > 0L )
	{
	wCount = ( ( lCount > 65535L ) ? 65535 : lCount );
	if ( _lwrite( ofh, (LPSTR)lpClipPtr, wCount ) != wCount )
		{
		Message( IDS_EWRITE, lpImageFile );
		_lclose(ofh);
		return(FALSE);
		}
	lpClipPtr += wCount;
	lCount -= wCount;
	}
_lclose(ofh);
return(TRUE);
}
Esempio n. 2
0
void WriteResults(HFILE hFile)
{
    char szT[80];
    OSVERSIONINFO Win32VersionInformation;
    MEMORYSTATUS MemoryStatus;
    int i;
    char *pszOSName;

    /*
     * Write out the build information and current date.
     */
    Win32VersionInformation.dwOSVersionInfoSize = sizeof(Win32VersionInformation);
    if (GetVersionEx(&Win32VersionInformation))
    {
        switch (Win32VersionInformation.dwPlatformId)
        {
            case VER_PLATFORM_WIN32s:
                pszOSName = "WIN32S";
                break;
            case VER_PLATFORM_WIN32_WINDOWS:
                pszOSName = "Windows 95";
                break;
            case VER_PLATFORM_WIN32_NT:
                pszOSName = "Windows NT";
                break;
            default:
                pszOSName = "Windows ???";
                break;
        }
        wsprintf(szT, "%s Version %d.%d Build %d ", pszOSName,
               Win32VersionInformation.dwMajorVersion,
               Win32VersionInformation.dwMinorVersion,
               Win32VersionInformation.dwBuildNumber);
        _lwrite(hFile, szT, lstrlen(szT));

        MemoryStatus.dwLength = sizeof(MEMORYSTATUS);
        GlobalMemoryStatus(&MemoryStatus);
        wsprintf(szT, "Physical Memory = %dKB\n", MemoryStatus.dwTotalPhys/1024);
        _lwrite(hFile, szT, lstrlen(szT));
    }

    lstrcpy(szT, "Function\tTime Per Iteration (microseconds)\r\n\r\n");
    _lwrite(hFile, szT, lstrlen(szT));

    for (i = 0; i < gcbmi; i++) {

        wsprintf(szT, "%s\t%ld\r\n", (LPSTR)gabmi[i].pszBenchTitle,
            gabmi[i].usPerIteration);

        _lwrite(hFile, szT, lstrlen(szT));

    }
}
Esempio n. 3
0
void dbgv(
/***********************************************************************/
LPSTR 	lpFormat,
LPTR 	lpArguments)
{
char szBuffer[512];
static int hFile, debug;
static BOOL bReopen;

if ( !debug ) // First time in...
	debug = GetDefaultInt( "debug", -1 );
if ( debug <= 0 )
	return;

if ( lpFormat )
	{
	if ( !hFile )
		{
	 	lstrcpy( szBuffer, Control.ProgHome );
		lstrcat( szBuffer, "DEBUG.TXT" );
		if ( bReopen )
			{
			if ( (hFile = _lopen( szBuffer, OF_WRITE )) < 0 )
				hFile = 0;
			else	_llseek( hFile, 0L, 2 );
			}
		else	{
			if ( (hFile = _lcreat( szBuffer, 0 )) < 0 )
				hFile = 0;
			}
		}
	if ( hFile )
		{
 	   	wvsprintf( szBuffer, lpFormat, (LPSTR)lpArguments );
    		lstrcat(szBuffer, "\r\n");
		_lwrite( hFile, szBuffer, lstrlen(szBuffer) );
		if (debug > 1)
			OutputDebugString(szBuffer);
		}
	}
else
if ( hFile )
	{
	lstrcpy( szBuffer, "---------- CLOSED ----------\r\n" );
	_lwrite( hFile, szBuffer, lstrlen(szBuffer) );
	_lclose( hFile );
	bReopen = YES;
	hFile = 0;
	}
}
Esempio n. 4
0
//************************************************************************
BOOL CDib::WriteFile( LPCSTR lpFileName )
//************************************************************************
{
	BITMAPFILEHEADER	hdr;
	HFILE				fh;
	OFSTRUCT			of;
	DWORD				dwSize, dwDibSize;

	if ( (fh = OpenFile( lpFileName, &of, OF_CREATE|OF_READWRITE )) < 0 )
		return FALSE;

	dwSize = GetSizeImage();

	dwDibSize = sizeof(BITMAPINFOHEADER) + (256*sizeof(RGBQUAD));
	hdr.bfType		= BFT_BITMAP;
	hdr.bfSize		= (DWORD)sizeof(BITMAPFILEHEADER) + dwDibSize + dwSize;
	hdr.bfReserved1 = 0;
	hdr.bfReserved2 = 0;
	hdr.bfOffBits	= (DWORD)sizeof(BITMAPFILEHEADER) + dwDibSize;

	_lwrite( fh, (LPCSTR)(LPVOID)&hdr, sizeof(BITMAPFILEHEADER) );
	_hwrite( fh, (LPCSTR)(LPVOID)&m_bmiHeader, sizeof(m_bmiHeader) );
	_hwrite( fh, (LPCSTR)(LPVOID)&m_rgbQuad, sizeof(m_rgbQuad) );
	_hwrite( fh, (LPCSTR)(LPVOID)m_lp, dwSize );
	_lclose( fh );
	return TRUE;
}
Esempio n. 5
0
int ZRead1Byte(PFileVar fv, PZVar zv, PComVar cv, LPBYTE b)
{
	char *s;

	if (CommRead1Byte(cv, b) == 0)
		return 0;

	if (fv->LogFlag) {
		if (fv->LogState == 0) {
			// 残りのASCII表示を行う
			fv->FlushLogLineBuf = 1;
			FTLog1Byte(fv, 0);
			fv->FlushLogLineBuf = 0;

			show_sendbuf(fv);

			fv->LogState = 1;
			fv->LogCount = 0;
			s = "\015\012<<< Received\015\012";
			_lwrite(fv->LogFile, s, strlen(s));
		}
		FTLog1Byte(fv, *b);
	}
	/* ignore 0x11, 0x13, 0x81 and 0x83 */
	if (((*b & 0x7F) == 0x11) || ((*b & 0x7F) == 0x13))
		return 0;
	return 1;
}
Esempio n. 6
0
int ZWrite(PFileVar fv, PZVar zv, PComVar cv, PCHAR B, int C)
{
	int i, j;
	char *s;

	i = CommBinaryOut(cv, B, C);

	if (fv->LogFlag && (i > 0)) {
		if (fv->LogState != 0) {
			// 残りのASCII表示を行う
			fv->FlushLogLineBuf = 1;
			FTLog1Byte(fv, 0);
			fv->FlushLogLineBuf = 0;

			show_recvbuf(fv);

			fv->LogState = 0;
			fv->LogCount = 0;
			s = "\015\012Sending >>>\015\012";
			_lwrite(fv->LogFile, s, strlen(s));
		}
		for (j = 0; j <= i - 1; j++)
			FTLog1Byte(fv, B[j]);
	}
	return i;
}
Esempio n. 7
0
void sLogMessage(char msg[])
{ 
#ifdef	LOG_ENABLED

#ifdef	WIN32
HFILE file;
OFSTRUCT of;

if (OpenFile("mm_sfwcam.log",&of,OF_EXIST)==HFILE_ERROR)
    file = OpenFile("mm_sfwcam.log",&of,OF_CREATE|OF_WRITE);
else
    file = OpenFile("mm_sfwcam.log",&of,OF_WRITE);

_llseek(file,0,FILE_END);
_lwrite(file,msg,lstrlen(msg));
_lclose(file);

#else
FILE     *fp;
  
fp = fopen("mm_sfwcam.log", "a+");
if (fp != NULL)
    {
    fprintf(fp, "%s\n", msg);
    fclose(fp);
    }
#endif

#endif

return;
}
Esempio n. 8
0
void TelWriteLog(PCHAR Buf, int C)
{
  int i;

  _lwrite(tr.LogFile,"\015\012>",3);
  for (i = 0 ; i<= C-1 ; i++)
    TelWriteLog1(Buf[i]);
}
Esempio n. 9
0
static void show_sendbuf(PFileVar fv)
{
	char *s;

	s = sendbuf;
	strncat_s(sendbuf, sizeof(sendbuf), "\015\012", _TRUNCATE);
	_lwrite(fv->LogFile, s, strlen(s));

	memset(sendbuf, 0, sizeof(sendbuf));
}
Esempio n. 10
0
BOOL My__lwrite()
{
	HFILE hFile=NULL;
	LPCSTR lpBuffer=NULL;
	UINT uBytes=NULL;
	UINT returnVal_Real = NULL;
	UINT returnVal_Intercepted = NULL;

	DWORD error_Real = 0;
	DWORD error_Intercepted = 0;
	__try{
	disableInterception();
	returnVal_Real = _lwrite (hFile,lpBuffer,uBytes);
	error_Real = GetLastError();
	enableInterception();
	returnVal_Intercepted = _lwrite (hFile,lpBuffer,uBytes);
	error_Intercepted = GetLastError();
	}__except(puts("in filter"), 1){puts("exception caught");}
	return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted));
}
Esempio n. 11
0
BOOL NEAR  Flush(LPSTR FileName)
{
    int written;

    written = _lwrite (hFileDoc, pszBufferDoc, dwOffsetDoc);
    if (written == -1)
          return ErrorBox(ERR_File_Write, (LPSTR)FileName);;
    if (written < dwOffsetDoc)
          return ErrorBox(ERR_File_Disk_Full, (LPSTR)FileName);
    return TRUE;
}                                       /* Flush() */
Esempio n. 12
0
BOOL CopyFile1(
/************************************************************************/
LPSTR 	lpInFile,
LPSTR	lpOutFile,
BOOL 	bClock,
BOOL	bEscapable)
{
int i, ifp, ofp;
char Buffer[2048];
int	nTotal, nCount;

nTotal = FileSize(lpInFile) / 2048;
lstrcpy( Buffer, lpInFile );
if ((ifp = _lopen( Buffer, OF_READ )) < 0)
	return( FALSE );
lstrcpy( Buffer, lpOutFile );
if ((ofp = _lcreat( Buffer, 0 )) < 0)
	{
	_lclose( ifp );
	return( FALSE );
	}

i = sizeof(Buffer);
nCount = 0;
while( 1 )
	{
	if (bClock)
		{
		if (AstralClockCursor(nCount, nTotal, bEscapable))
			{
			_lclose( ifp );
			_lclose( ofp );
			lstrcpy( Buffer, lpOutFile );
			unlink(Buffer);
			return( FALSE );
			}
		}
	if ( (i = _lread(ifp, Buffer, i)) <= 0 )
		{
		_lclose( ifp );
		_lclose( ofp );
		return( i == 0 );
		}
	if ( _lwrite(ofp, Buffer, i) != i )
		{
		_lclose( ifp );
		_lclose( ofp );
		lstrcpy( Buffer, lpOutFile );
		unlink(Buffer);
		return( FALSE );
		}
	++nCount;
	}
}
Esempio n. 13
0
BOOL WriteDIB (
    LPSTR szFile,
    HANDLE hdib)
{
    BITMAPFILEHEADER    hdr;
    LPBITMAPINFOHEADER  lpbi;
    HFILE               fh;
    OFSTRUCT            of;

    if (!hdib)
        return FALSE;

    fh = OpenFile(szFile, &of, (UINT)OF_CREATE|OF_READWRITE);
    if (fh == -1)
        return FALSE;

    lpbi = (VOID FAR *)GlobalLock (hdib);

    /* Fill in the fields of the file header */
    hdr.bfType          = BFT_BITMAP;
    hdr.bfSize          = GlobalSize (hdib) + SIZEOF_BITMAPFILEHEADER_PACKED;
    hdr.bfReserved1     = 0;
    hdr.bfReserved2     = 0;
    hdr.bfOffBits       = (DWORD) (SIZEOF_BITMAPFILEHEADER_PACKED + lpbi->biSize +
                          PaletteSize(lpbi));

    /* Write the file header */

    /* write bfType*/
    _lwrite(fh, (LPSTR)&hdr.bfType, (UINT)sizeof (WORD));
    /* now pass over extra word, and only write next 3 DWORDS!*/
    _lwrite(fh, (LPSTR)&hdr.bfSize, sizeof(DWORD) * 3);

    /* this struct already DWORD aligned!*/
    /* Write the DIB header and the bits */
    _lwrite (fh, (LPSTR)lpbi, GlobalSize (hdib));

    GlobalUnlock (hdib);
    _lclose(fh);
    return TRUE;
}
Esempio n. 14
0
DWORD PASCAL CJpegFile::MyWrite(int iFileHandle, VOID FAR *lpBuffer, DWORD dwBytes)
{
	DWORD dwBytesTmp = dwBytes;       // Save # of bytes for return value
	BYTE *hpBuffer = (BYTE *)lpBuffer;   // make a huge pointer to the data
	
	/*
	 * Write out the data in 32767 byte chunks.
     */
	
	while (dwBytes > 32767)
	{
		if (_lwrite(iFileHandle, (LPSTR)hpBuffer, (WORD)32767) != 32767)
			return 0;
		dwBytes -= 32767;
		hpBuffer += 32767;
	}
	
	/* Write out the last chunk (which is < 32767 bytes) */
	if (_lwrite(iFileHandle, (LPSTR)hpBuffer, (WORD)dwBytes) != (WORD)dwBytes)
		return 0;
	return dwBytesTmp;
}
Esempio n. 15
0
UINT
DIAMONDAPI
SpdFdiWrite(
    IN int   Handle,
    IN PVOID pv,
    IN UINT  ByteCount
    )

/*++

Routine Description:

    Callback used by FDICopy to write to a file.

Arguments:

    Handle - supplies handle to open file to be written to.

    pv - supplies pointer to buffer containing bytes to write.

    ByteCount - supplies number of bytes to write.

Return Value:

    Number of bytes written (ByteCount) or -1 if an error occurs.

--*/

{
    UINT rc;

    rc = _lwrite((HFILE)Handle,pv,ByteCount);

    if(rc == HFILE_ERROR) {

        DiamondLastIoError = (GetLastError() == ERROR_DISK_FULL) ? LZERROR_WRITE : LZERROR_BADOUTHANDLE;

    } else {

        if(rc != ByteCount) {
            //
            // let caller interpret return value but record last error just in case
            //
            DiamondLastIoError = LZERROR_WRITE;
        }
    }

    return(rc);
}
Esempio n. 16
0
void EXPORT KppLogSendMessage(ATOMID idMethod, ATOMID idObj, BOOL bExit)
{
    WORD wLen = sprintf(return_buffer, "%4d : ", wLogCount++);
        
    wLen += KppGetAtomName(idMethod, return_buffer + wLen,
                           RET_BUFFER_LEN - wLen);
    strcpy(return_buffer + wLen, "->");
    wLen += 2;
    wLen += KppGetAtomName(idObj, return_buffer + wLen,
                           RET_BUFFER_LEN - wLen);
    strcpy(return_buffer + wLen, bExit ? "  )" : "  (");
    strcpy(return_buffer + wLen + 3, "\r\n");
    
    _lwrite(hLogFile, return_buffer, wLen + 5);
}
Esempio n. 17
0
/*-------------------------------------------
	save log data
---------------------------------------------*/
void Log(const char* msg)
{
	SYSTEMTIME st;
	char s[160];
	int count, index;

	GetLocalTime(&st);
	wsprintf(s, "%02d/%02d %02d:%02d:%02d ",
		st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
	strcat(s, msg);

	// save to listbox
	count = SendMessage(hwndSNTPLog, LB_GETCOUNT, 0, 0);
	if(count > 100)
		SendMessage(hwndSNTPLog, LB_DELETESTRING, 0, 0);
	index = SendMessage(hwndSNTPLog, LB_ADDSTRING, 0, (LPARAM)s);
	SendMessage(hwndSNTPLog, LB_SETCURSEL, index, 0);

	// save to file
	if(GetMyRegLong("SNTP", "SaveLog", TRUE))
	{
		HFILE hf;
		char fname[MAX_PATH];

		strcpy(fname, g_mydir);
		add_title(fname, "SNTP.txt");
		hf = _lopen(fname, OF_WRITE);
		if(hf == HFILE_ERROR)
			hf = _lcreat(fname, 0);
		if(hf == HFILE_ERROR) return;
		_llseek(hf, 0, 2);
		_lwrite(hf, s, strlen(s));
		_lwrite(hf, "\x0d\x0a", 2);
		_lclose(hf);
	}
}
Esempio n. 18
0
/******************************Public*Routine******************************\
* VcdPlyerCaptureImage
*
\**************************************************************************/
BOOL
VcdPlyerCaptureImage(
    LPCSTR szFile
    )
{
    if(pMpegMovie)
    {
        BYTE* lpCurrImage = NULL;

        if(pMpegMovie->GetCurrentImage(&lpCurrImage) == S_OK)
        {
            BITMAPFILEHEADER    hdr;
            HFILE               fh;
            OFSTRUCT            of;
            DWORD               dwSize;
            PDIB                pdib = (PDIB)lpCurrImage;

            fh = OpenFile(szFile,&of,OF_CREATE|OF_READWRITE);

            if(fh == -1)
                return FALSE;

            dwSize = DibSize(pdib);

            hdr.bfType          = BFT_BITMAP;
            hdr.bfSize          = dwSize + sizeof(BITMAPFILEHEADER);
            hdr.bfReserved1     = 0;
            hdr.bfReserved2     = 0;
            hdr.bfOffBits       = (DWORD)sizeof(BITMAPFILEHEADER) + pdib->biSize +
                DibPaletteSize(pdib);

            _lwrite(fh,(LPCSTR)(LPVOID)&hdr,sizeof(BITMAPFILEHEADER));
            _hwrite(fh,(LPCSTR)(LPVOID)pdib,dwSize);

            _lclose(fh);

            CoTaskMemFree(lpCurrImage);

            TCHAR szText[128], szDir[MAX_PATH];
            GetCurrentDirectory(MAX_PATH, szDir);
            wsprintf(szText, TEXT("Captured current image to %s\\%s."), szDir, szFile);
            MessageBox(hwndApp, szText, TEXT("Captured bitmap"), MB_OK);
            return TRUE;
        }
    }

    return FALSE;
}
Esempio n. 19
0
int		FileWrite (
LPFILEBUF	ofd,	/* control block */
LPTR		buf,	/* buffer containing data */
int			len)	/* number of bytes to write */
{
    int		i;

/* null write? */
    if (len == 0)
	return (0);

/* no write if error condition set */
    if (ofd->err)
	return (-1);

/* will all data will fit in buffer? */
    if (ofd->offset + len < ofd->bsiz) {
	for (i = 0; i < len; i++)
	    ofd->buf [ofd->offset++] = *buf++;
	return (len);
    }

/* all data won't fit, flush the buffer */
    if (FileFlush (ofd) == -1)
	return (-1);

/* will all data now will fit in buffer? */
    if (ofd->offset + len < ofd->bsiz) {
	for (i = 0; i < len; i++)
	    ofd->buf [ofd->offset++] = *buf++;
	return (len);
    }

/* just write the data directly from the callers buffer */
    if (_lwrite (ofd->fh, (LPSTR)buf, len) != len) {
	ofd->err = -1;
	return (-1);
    }

/* set byte offset for first byte in buffer */
    ofd->pos = _llseek (ofd->fh, 0L, 1);

    return (len);
}
Esempio n. 20
0
int XRead1Byte(PFileVar fv, PXVar xv, PComVar cv, LPBYTE b)
{
	if (CommRead1Byte(cv, b) == 0)
		return 0;

	if (fv->LogFlag) {
		if (fv->LogState == 0) {
			// 残りのASCII表示を行う
			fv->FlushLogLineBuf = 1;
			FTLog1Byte(fv, 0);
			fv->FlushLogLineBuf = 0;

			fv->LogState = 1;
			fv->LogCount = 0;
			_lwrite(fv->LogFile, "\015\012<<<\015\012", 7);
		}
		FTLog1Byte(fv, *b);
	}
	return 1;
}
Esempio n. 21
0
int		FileFlush (LPFILEBUF ofd)
{
/* just report an error, if one has happened */
    if (ofd->err)
	return (-1);

/* if mode is write, write any data in buffer */
    if (ofd->mode) {
	if (ofd->offset) {
	    if (_lwrite (ofd->fh, (LPSTR)ofd->buf, ofd->offset) != ofd->offset)
		ofd->err = -1;
	}
    }

/* set byte offset for first byte in buffer */
    ofd->pos += ofd->offset;

/* set next location in buffer to use */
    ofd->offset = 0;
    return (ofd->err);
}
Esempio n. 22
0
void TelWriteLog1(BYTE b)
{
  BYTE Temp[3];
  BYTE Ch;

  Temp[0] = 0x20;
  Ch = b / 16;
  if (Ch <= 9)
    Ch = Ch + 0x30;
  else
    Ch = Ch + 0x37;
  Temp[1] = Ch;

  Ch = b & 15;
  if (Ch <= 9)
    Ch = Ch + 0x30;
  else
    Ch = Ch + 0x37;
  Temp[2] = Ch;
  _lwrite(tr.LogFile,Temp,3);
}
Esempio n. 23
0
int XWrite(PFileVar fv, PXVar xv, PComVar cv, PCHAR B, int C)
{
	int i, j;

	i = CommBinaryOut(cv, B, C);
	if (fv->LogFlag && (i > 0)) {
		if (fv->LogState != 0) {
			// 残りのASCII表示を行う
			fv->FlushLogLineBuf = 1;
			FTLog1Byte(fv, 0);
			fv->FlushLogLineBuf = 0;

			fv->LogState = 0;
			fv->LogCount = 0;
			_lwrite(fv->LogFile, "\015\012>>>\015\012", 7);
		}
		for (j = 0; j <= i - 1; j++)
			FTLog1Byte(fv, B[j]);
	}
	return i;
}
Esempio n. 24
0
void dbglog ( char* szFormat ... )
{
	va_list ap;
	char str [100000];

	va_start ( ap, szFormat );
	vsprintf ( str, szFormat, ap );
	strcat (str, "\r\n");
	va_end (ap);

	int file = _lopen ( DBGLOG_FILENAME, OF_WRITE );

	if ( file == -1 )
	{
		file = _lcreat ( DBGLOG_FILENAME, 0 );
	}

	_llseek ( file, 0, FILE_END );
	_lwrite ( file, str, lstrlen (str) );
	FlushFileBuffers ((HANDLE)file);
	_lclose ( file );
}
Esempio n. 25
0
static UINT GRPFILE_WriteWithChecksum(HFILE file, LPCSTR str, UINT size)
{
	UINT i;
	if (GRPFILE_checksum_half_word) {
		GRPFILE_checksum -= GRPFILE_checksum_last_byte;
	}
	for (i=0; i < size; i++) {
		if (GRPFILE_checksum_half_word) {
			GRPFILE_checksum -= str[i] << 8;
		} else {
			GRPFILE_checksum -= str[i];
		}
		GRPFILE_checksum_half_word ^= 1;
	}

	if (GRPFILE_checksum_half_word) {
		GRPFILE_checksum_last_byte = str[size-1];
		GRPFILE_checksum += GRPFILE_checksum_last_byte;
	}

	return _lwrite(file, str, size);
}
Esempio n. 26
0
void ParseTel(BOOL *Size, int *nx, int *ny)
{
  BYTE b;
  int c;

  c = CommReadRawByte(&cv,&b);

  while ((c>0) && (cv.TelMode))
  {
    if (tr.LogFile!=0)
    {
      if (TelStatus==TelIAC)
      {
	_lwrite(tr.LogFile,"\015\012<",3);
	TelWriteLog1(0xff);
      }
      TelWriteLog1(b);
    }

    tr.ChangeWinSize = FALSE;

    switch (TelStatus) {
      case TelIAC: ParseTelIAC(b); break;
      case TelSB: ParseTelSB(b); break;
      case TelWill: ParseTelWill(b); break;
      case TelWont: ParseTelWont(b); break;
      case TelDo: ParseTelDo(b); break;
      case TelDont: ParseTelDont(b); break;
      case TelNop: TelStatus = TelIdle; break;
    }
    if (TelStatus == TelIdle) cv.TelMode = FALSE;

    if (cv.TelMode) c = CommReadRawByte(&cv,&b);
  }

  *Size = tr.ChangeWinSize;
  *nx = tr.WinSize.x;
  *ny = tr.WinSize.x;
}
void CTWainHelper::LogMessage(char msg[])
{
#ifdef _DEBUG
	
	HFILE file = NULL;
	OFSTRUCT of;
	
	memset(&of, 0, sizeof(OFSTRUCT));
	
	if (OpenFile("c:\\twainapp.log", &of, OF_EXIST) == HFILE_ERROR)
	{
		//create if no exist
		file = OpenFile("c:\\twainapp.log", &of, OF_CREATE|OF_WRITE|OF_SHARE_DENY_NONE);
	}
	else
	{
		file = OpenFile("c:\\twainapp.log", &of, OF_WRITE|OF_SHARE_DENY_NONE);
	}
	
	//附加模式
	if (_llseek(file,0,FILE_END)==-1)
	{
		OutputDebugString("LogMessage _llseek failed\n");
	}
	
	if (_lwrite(file,msg,lstrlen(msg))==-1)
	{
		OutputDebugString("LogMessage _lwrite failed\n");
	}
	
	if (_lclose(file)==-1) 
	{
		OutputDebugString("LogMessage _lclose failed\n");
	}
	
#endif
	return;
}
Esempio n. 28
0
  _WCRTLINK int write( int handle, const void *buffer, unsigned len )
#endif
/**********************************************************************/
{
    unsigned    iomode_flags;
    char        *buf;
    unsigned    buf_size;
    unsigned    len_written, i, j;
#if defined(__NT__)
    HANDLE      h;
    LONG        cur_ptr_low;
    LONG        cur_ptr_high;
    DWORD       rc1;
#else
    tiny_ret_t  rc1;
#endif
    int         rc2;

    __handle_check( handle, -1 );
    iomode_flags = __GetIOMode( handle );
    if( iomode_flags == 0 ) {
#if defined(__WINDOWS__) || defined(__WINDOWS_386__)
        // How can we write to the handle if we never opened it? JBS
        return( _lwrite( handle, buffer, len ) );
#else
        __set_errno( EBADF );
        return( -1 );
#endif
    }
    if( !(iomode_flags & _WRITE) ) {
        __set_errno( EACCES );     /* changed from EBADF to EACCES 23-feb-89 */
        return( -1 );
    }

#if defined(__NT__)
    h = __getOSHandle( handle );
#endif

    // put a semaphore around our writes

    _AccessFileH( handle );
    if( (iomode_flags & _APPEND) && !(iomode_flags & _ISTTY) ) {
#if defined(__NT__)
        if( GetFileType( h ) == FILE_TYPE_DISK ) {
            cur_ptr_low = 0;
            cur_ptr_high = 0;
            rc1 = SetFilePointer( h, cur_ptr_low, &cur_ptr_high, FILE_END );
            if( rc1 == INVALID_SET_FILE_POINTER ) { // this might be OK so
                if( GetLastError() != NO_ERROR ) {
                    _ReleaseFileH( handle );
                    return( __set_errno_nt() );
                }
            }
        }
#elif defined(__OS2__)
        {
            unsigned long       dummy;
            rc1 = DosChgFilePtr( handle, 0L, SEEK_END, &dummy );
            // should we explicitly ignore ERROR_SEEK_ON_DEVICE here?
        }
#else
        rc1 = TinySeek( handle, 0L, SEEK_END );
#endif
#if !defined(__NT__)
        if( TINY_ERROR( rc1 ) ) {
            _ReleaseFileH( handle );
            return( __set_errno_dos( TINY_INFO( rc1 ) ) );
        }
#endif
    }

    len_written = 0;
    rc2 = 0;

    // Pad the file with zeros if necessary
    if( iomode_flags & _FILEEXT ) {
        // turn off file extended flag
        __SetIOMode_nogrow( handle, iomode_flags&(~_FILEEXT) );

        // It is not required to pad a file with zeroes on an NTFS file system;
        // unfortunately it is required on FAT (and probably FAT32). (JBS)
        rc2 = zero_pad( handle );
    }

    if( rc2 == 0 ) {
        if( iomode_flags & _BINARY ) {  /* if binary mode */
            rc2 = os_write( handle, buffer, len, &len_written );
            /* end of binary mode part */
        } else {    /* text mode */
            i = stackavail();
            if( i < 0x00b0 ) {
                __STKOVERFLOW();    /* not enough stack space */
            }
            buf_size = 512;
            if( i < (512 + 48) ) {
                buf_size = 128;
            }
#if defined(__AXP__) || defined(__PPC__)
            buf = alloca( buf_size );
#else
            buf = __alloca( buf_size );
#endif
            j = 0;
            for( i = 0; i < len; ) {
                if( ((const char*)buffer)[i] == '\n' ) {
                    buf[j] = '\r';
                    ++j;
                    if( j == buf_size ) {
                        rc2 = os_write( handle, buf, buf_size, &j );
                        if( rc2 == -1 )
                            break;
                        len_written += j;
                        if( rc2 == ENOSPC )
                            break;
                        len_written = i;
                        j = 0;
                    }
                }
                buf[j] = ((const char*)buffer)[i];
                ++i;
                ++j;
                if( j == buf_size ) {
                    rc2 = os_write( handle, buf, buf_size, &j );
                    if( rc2 == -1 )
                        break;
                    len_written += j;
                    if( rc2 == ENOSPC )
                        break;
                    len_written = i;
                    j = 0;
                }
            }
            if( j ) {
                rc2 = os_write( handle, buf, j, &i );
                if( rc2 == ENOSPC ) {
                    len_written += i;
                } else {
                    len_written = len;
                }
            }
            /* end of text mode part */
        }
    }
    _ReleaseFileH( handle );
    if( rc2 == -1 ) {
        return( rc2 );
    } else {
        return( len_written );
    }
}
Esempio n. 29
0
int FAR PASCAL ApfDumpData (LPSTR lpszDumpFile)
{
    int hFile;
    static char achBuf[200];
    OFSTRUCT OfStruct;
    DWORD cChar;
    WORD iApi;


    hFile = OpenFile (lpszDumpFile, &OfStruct,
		      OF_CREATE+OF_SHARE_COMPAT+OF_WRITE);
    if (hFile < 0) {
	return 1;
    }

    // print data table header
    //
    cChar = wsprintf(achBuf, "%s:  Api profile of %s.\r\n",
		     lpszDumpFile, MODULE_NAME);
    _lwrite(hFile, achBuf, cChar);

    cChar = wsprintf(achBuf, "All times are in microseconds (us)\r\n");
    _lwrite(hFile, achBuf, cChar);

#ifdef CALIBDBG
    cChar = wsprintf(achBuf, "Excess Timer Overhead = %lu us (%lu)\r\n",
		     ApfData[I_CALIBRATE].ulMinTime, ApfData[I_CALIBRATE].ulMaxTime);
#else
    cChar = wsprintf(achBuf, "Excess Timer Overhead = %lu us\r\n",
		     ApfData[I_CALIBRATE].ulMinTime);
#endif
    _lwrite(hFile, achBuf, cChar);
	
    cChar = wsprintf(achBuf,
		     "First Time is not included in Max/Min computation\r\n\r\n\r\n");
    _lwrite(hFile, achBuf, cChar);

    cChar = wsprintf(achBuf,
		    "%-32s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\r\n\r\n",
                    "API Name",
                    "Num Calls",
                    "Total Time",
                    "Time/Call",
                    "First Time",
                    "Max Time",
                    "Min Time",
                    "Not Timed");
    _lwrite(hFile, achBuf, cChar);

    // roll out the data
    //
    for (iApi = 0; iApi < API_COUNT; iApi++) {
        if (ApfData[iApi].cCalls > 1) {
            cChar = wsprintf(achBuf,
                 "%-32s\t%10lu\t%10lu\t%10lu\t%10lu\t%10lu\t%10lu\t%10lu\r\n",
                 aszApiNames[iApi],
                 ApfData[iApi].cCalls,
                 ApfData[iApi].ulTotalTime,
                 ApfData[iApi].ulTotalTime / ApfData[iApi].cCalls,
                 ApfData[iApi].ulFirstTime,
                 ApfData[iApi].ulMaxTime,
                 ApfData[iApi].ulMinTime,
                 ApfData[iApi].cTimingErrors);
        	_lwrite(hFile, achBuf, cChar);

	}
        else if (ApfData[iApi].cCalls == 1) {
            cChar = wsprintf(achBuf,
                 "%-32s\t%10lu\t%10lu\t%10lu\t%10lu\t%10s\t%10s\t%10lu\r\n",
                 aszApiNames[iApi],
                 ApfData[iApi].cCalls,
                 ApfData[iApi].ulTotalTime,
                 ApfData[iApi].ulTotalTime / ApfData[iApi].cCalls,
                 ApfData[iApi].ulFirstTime,
                 "n/a",
                 "n/a",
                 ApfData[iApi].cTimingErrors);
        	_lwrite(hFile, achBuf, cChar);
	}
    }
    _lclose(hFile);

    return 0;

} /* ApfDumpData () */
Esempio n. 30
0
File: Tmsrpt04.c Progetto: ems/TMS
BOOL FAR TMSRPT04(TMSRPTPassedDataDef *pPassedData)
{
  GenerateTripDef GTResults;
  REPORTPARMSDef REPORTPARMS;
  HFILE hfOutputFile;
  BOOL  bKeepGoing = FALSE;
  BOOL  bRC;
  char  routeNumber[ROUTES_NUMBER_LENGTH + 1];
  char  serviceName[SERVICES_NAME_LENGTH + 1];
  char  outputString[512];
  long  statbarTotal;
  int   nI;
  int   nJ;
  int   nK;
  int   nL;
  int   rcode2;

  pPassedData->nReportNumber = 3;
  pPassedData->numDataFiles = 1;
//
//  See what he wants
//
  REPORTPARMS.nReportNumber = pPassedData->nReportNumber;
  REPORTPARMS.ROUTESrecordID = m_RouteRecordID;
  REPORTPARMS.SERVICESrecordID = m_ServiceRecordID;
  REPORTPARMS.COMMENTSrecordID = NO_RECORD;
  REPORTPARMS.pRouteList = NULL;
  REPORTPARMS.pServiceList = NULL;
  REPORTPARMS.flags = RPFLAG_ROUTES | RPFLAG_SERVICES | RPFLAG_COMMENTS;
  bRC = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_RPTPARMS),
        hWndMain, (DLGPROC)RPTPARMSMsgProc, (LPARAM)&REPORTPARMS);
  if(!bRC)
  {
    return(FALSE);
  }
//
//  Check the list of routes and services
//
  if(REPORTPARMS.numRoutes == 0 || REPORTPARMS.numServices == 0)
  {
    goto deallocate;
  }
//
//  Open the output file
//
  strcpy(tempString, szReportsTempFolder);
  strcat(tempString, "\\tmsrpt04.txt");
  hfOutputFile = _lcreat(tempString, 0);
  if(hfOutputFile == HFILE_ERROR)
  {
    LoadString(hInst, ERROR_202, szFormatString, sizeof(szFormatString));
    sprintf(szarString, szFormatString, tempString);
    MessageBeep(MB_ICONSTOP);
    MessageBox((HWND)NULL, szarString, TMS, MB_ICONSTOP);
    goto deallocate;
  }
  strcpy(pPassedData->szReportDataFile[0], tempString);
//
//  Loop through the routes
//
  LoadString(hInst, TEXT_117, tempString, TEMPSTRING_LENGTH);
  StatusBarStart(hWndMain, tempString);
  statbarTotal = REPORTPARMS.numRoutes * REPORTPARMS.numServices;
  for(nI = 0; nI < REPORTPARMS.numRoutes; nI++)
  {
    if(StatusBarAbort())
    {
      bKeepGoing = FALSE;
      goto deallocate;
    }
    ROUTESKey0.recordID = REPORTPARMS.pRouteList[nI];
    rcode2 = btrieve(B_GETEQUAL, TMS_ROUTES, &ROUTES, &ROUTESKey0, 0);
    if(rcode2 != 0)
    {
      continue;
    }
    strncpy(routeNumber, ROUTES.number, ROUTES_NUMBER_LENGTH);
    trim(routeNumber, ROUTES_NUMBER_LENGTH);
//
//  Loop through the services
//
    for(nJ = 0; nJ < REPORTPARMS.numServices; nJ++)
    {
      if(StatusBarAbort())
      {
        bKeepGoing = FALSE;
        goto deallocate;
      }
      SERVICESKey0.recordID = REPORTPARMS.pServiceList[nJ];
      rcode2 = btrieve(B_GETEQUAL, TMS_SERVICES, &SERVICES, &SERVICESKey0, 0);
      if(rcode2 != 0)
      {
        continue;
      }
      strncpy(serviceName, SERVICES.name, SERVICES_NAME_LENGTH);
      trim(serviceName, SERVICES_NAME_LENGTH);
      LoadString(hInst, TEXT_118, szarString, sizeof(szarString));
      sprintf(tempString, szarString, routeNumber, serviceName);
      StatusBarText(tempString);
      StatusBar((long)(nI * REPORTPARMS.numServices + nJ), (long)statbarTotal);
      if(StatusBarAbort())
      {
        bKeepGoing = FALSE;
        goto deallocate;
      }
//
//  Loop through the directions
//
      for(nK = 0; nK < 2; nK++)
      {
        if(StatusBarAbort())
        {
          bKeepGoing = FALSE;
          goto deallocate;
        }
        if(ROUTES.DIRECTIONSrecordID[nK] == NO_RECORD)
        {
          continue;
        }
        DIRECTIONSKey0.recordID = ROUTES.DIRECTIONSrecordID[nK];
        rcode2 = btrieve(B_GETEQUAL, TMS_DIRECTIONS, &DIRECTIONS, &DIRECTIONSKey0, 0);
        if(rcode2 != 0)
        {
          continue;
        }
        m_bEstablishRUNTIMES = TRUE;
//
//  Get all the trips
//
        TRIPSKey1.ROUTESrecordID = REPORTPARMS.pRouteList[nI];
        TRIPSKey1.SERVICESrecordID = REPORTPARMS.pServiceList[nJ];
        TRIPSKey1.directionIndex = nK;
        TRIPSKey1.tripSequence = NO_TIME;
        rcode2 = btrieve(B_GETGREATEROREQUAL, TMS_TRIPS, &TRIPS, &TRIPSKey1, 1);
        while(rcode2 == 0 &&
              TRIPS.ROUTESrecordID == REPORTPARMS.pRouteList[nI] &&
              TRIPS.SERVICESrecordID == REPORTPARMS.pServiceList[nJ] &&
              TRIPS.directionIndex == nK)
        {
//
//  Generate the trip
//
          GenerateTrip(TRIPS.ROUTESrecordID, TRIPS.SERVICESrecordID,
                TRIPS.directionIndex, TRIPS.PATTERNNAMESrecordID,
                TRIPS.timeAtMLP, GENERATETRIP_FLAG_DISPLAYERRORS, &GTResults);
//
//  Set up the output string
//
          strcpy(outputString, "");
          for(nL = 0; nL < NUMCOLS; nL++)
          {
            switch(nL)
            {
//
//  Route number
//
              case 0:
                strncpy(tempString, ROUTES.number, ROUTES_NUMBER_LENGTH);
                tempString[ROUTES_NUMBER_LENGTH] = '\0';
                sprintf(szarString, "\"%s\"", tempString);
                break;
//
//  Route name
//
              case 1:
                strncpy(tempString, ROUTES.name, ROUTES_NAME_LENGTH);
                tempString[ROUTES_NAME_LENGTH] = '\0';
                sprintf(szarString, "\"%s\"", tempString);
                break;
//
//  Service Name
//
              case 2:
                strncpy(tempString, SERVICES.name, SERVICES_NAME_LENGTH);
                tempString[SERVICES_NAME_LENGTH] = '\0';
                sprintf(szarString, "\"%s\"", tempString);
                break;
//
//  Direction
//
              case 3:
                strncpy(tempString, DIRECTIONS.longName, DIRECTIONS_LONGNAME_LENGTH);
                tempString[DIRECTIONS_LONGNAME_LENGTH] = '\0';
                sprintf(szarString, "\"%s\"", tempString);
                break;
//
//  Trip time (in minutes)
//
              case 4:
                sprintf(szarString, "%ld", GTResults.lastNodeTime - GTResults.firstNodeTime);
                break;
//
//  Distance
//
              case 5:
                sprintf(szarString, "%7.2f", GTResults.tripDistance);
                break;
            }  // End of switch
            strcat(outputString, szarString);
            strcat(outputString, nL == NUMCOLS - 1 ? "\r\n" : "\t");
          }  // nL
          _lwrite(hfOutputFile, outputString, strlen(outputString));
          rcode2 = btrieve(B_GETNEXT, TMS_TRIPS, &TRIPS, &TRIPSKey1, 1);
        }  // while
      }  // nK
    }  // nJ
  }  // nI
  bKeepGoing = TRUE;
//
//  Free allocated memory
//
  deallocate:
    TMSHeapFree(REPORTPARMS.pRouteList);
    TMSHeapFree(REPORTPARMS.pServiceList);
    _lclose(hfOutputFile);
    StatusBarEnd();
    if(!bKeepGoing)
    {
      return(FALSE);
    }
//
//  All done
//
  return(TRUE);
}