diff options
author | Oliver Bolte <obo@openoffice.org> | 2009-09-09 09:38:41 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2009-09-09 09:38:41 +0000 |
commit | b76cb86eaa0aec1d02c5ff29c5a43e1e7a675b27 (patch) | |
tree | 7575d750165f3bbad544795339d673b97bdb956b /sal/osl/all | |
parent | 78497fa4e72049611317dacf33cad591aca6a8db (diff) |
CWS-TOOLING: integrate CWS mhu20
2009-09-01 15:18:43 +0200 mhu r275662 : #i32526# Fixed missing includes, and a wrong cast
2009-08-28 13:30:05 +0200 mhu r275530 : #i32526# Fixed missing includes and remaining merge conflicts.
2009-08-28 13:28:45 +0200 mhu r275529 : #i32526# osl_readLine() now implemented in sal/osl/<platform>/file.cxx
2009-08-26 19:47:53 +0200 mhu r275445 : CWS-TOOLING: rebase CWS mhu20 to trunk@275331 (milestone: DEV300:m56)
2009-08-25 15:47:00 +0200 mhu r275365 : #i32526# Also maintain phys. file offset.
2009-08-25 15:24:56 +0200 mhu r275364 : #i32526# Added buffered file I/O; refactored file.cxx into multiple files.
2009-08-24 10:38:15 +0200 mhu r275294 : #i32526# Correct OpenFlags for osl_openFile().
2009-05-25 11:07:34 +0200 mhu r272225 : #i32526# Added support for non-seekable file handles (pipe et al.).
2009-05-25 11:01:50 +0200 mhu r272223 : #i32526# Add osl_readLine() test, cleanup obsolete tests.
2009-05-25 10:56:14 +0200 mhu r272221 : #i32526# Add missing include
2009-05-25 10:48:51 +0200 mhu r272220 : #i32526# Accept OpenJDK (IcedTea6) 1.6.0_0 version string
2009-05-15 19:18:20 +0200 mhu r271965 : #i32526# Initial osl/unx buffered file I/O implementation.
2009-05-15 17:41:57 +0200 mhu r271959 : CWS-TOOLING: rebase CWS mhu20 to trunk@271830 (milestone: DEV300:m48)
2009-03-26 17:28:53 +0100 mhu r270091 : CWS-TOOLING: rebase CWS mhu20 to trunk@270033 (milestone: DEV300:m45)
Diffstat (limited to 'sal/osl/all')
-rw-r--r-- | sal/osl/all/makefile.mk | 6 | ||||
-rw-r--r-- | sal/osl/all/readline.c | 311 |
2 files changed, 4 insertions, 313 deletions
diff --git a/sal/osl/all/makefile.mk b/sal/osl/all/makefile.mk index 6bed1c53cfaa..bbb46b89d44e 100644 --- a/sal/osl/all/makefile.mk +++ b/sal/osl/all/makefile.mk @@ -57,18 +57,20 @@ CXXFLAGS+= $(LFS_CFLAGS) SLOFILES= \ $(SLO)$/utility.obj\ - $(SLO)$/readline.obj\ $(SLO)$/filepath.obj\ $(SLO)$/debugbase.obj\ $(SLO)$/loadmodulerelative.obj +# $(SLO)$/readline.obj\ + #.IF "$(UPDATER)"=="YES" OBJFILES= \ $(OBJ)$/utility.obj\ - $(OBJ)$/readline.obj\ $(OBJ)$/filepath.obj\ $(OBJ)$/debugbase.obj\ $(OBJ)$/loadmodulerelative.obj + +# $(OBJ)$/readline.obj\ #.ENDIF # --- Targets ------------------------------------------------------ diff --git a/sal/osl/all/readline.c b/sal/osl/all/readline.c deleted file mode 100644 index 9fc4bced83aa..000000000000 --- a/sal/osl/all/readline.c +++ /dev/null @@ -1,311 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: readline.c,v $ - * $Revision: 1.9 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include <osl/diagnose.h> -#include <osl/file.h> -#include <rtl/byteseq.h> -#include <rtl/alloc.h> - - -/* Test cases: - - 1. A file without line ends - 2. A file with lines longer than the initial buffer size - 3. An empty file - 4. -*/ - -/** Some defines -*/ -#define CR 0x0D -#define LF 0x0A - -#define INITIAL_BUFF_SIZE 80 -#define BUFFER_GROW_FACTOR 2 -#define READ_BLOCK_SIZE (INITIAL_BUFF_SIZE - 1) - -/** Helper data and function -*/ - -struct _Buffer -{ - sal_Char* m_pMem; - sal_uInt64 m_Capacity; /* elements possible in buffer */ - sal_uInt64 m_Size; /* elements actually in buffer */ - sal_uInt64 m_ActiveSectionStart; /* buffer was lastly filled from here to - (m_Size - 1) */ -}; - -typedef struct _Buffer Buffer; - - -/** Allocate the memory of the buffer - @Returns sal_True on succes -*/ -static sal_Bool AllocateBuffer(Buffer* pBuffer, sal_uInt64 Capacity) -{ - sal_Bool rc = sal_False; - - OSL_ASSERT(pBuffer); - - pBuffer->m_pMem = (sal_Char*)rtl_allocateZeroMemory((sal_uInt32)Capacity); - if (pBuffer->m_pMem) - { - pBuffer->m_Capacity = Capacity; - pBuffer->m_Size = 0; - pBuffer->m_ActiveSectionStart = 0; - rc = sal_True; - } - - return rc; -} - -/** Release the memory occupied by the buffer -*/ -static void FreeBuffer(Buffer* pBuffer) -{ - OSL_ASSERT(pBuffer); - - rtl_freeMemory(pBuffer->m_pMem); - pBuffer->m_pMem = 0; - pBuffer->m_Capacity = 0; - pBuffer->m_Size = 0; - pBuffer->m_ActiveSectionStart = 0; -} - -/** Grow the buffer by the specified factor (usually doubling - the buffer size) - In case of failure, growing the buffer, the original buffer - stays untouched - - @Returns sal_True on success -*/ -static sal_Bool GrowBuffer(Buffer* pBuffer, size_t factor) -{ - sal_Bool rc = sal_False; - void* p; - - OSL_ASSERT(pBuffer); - - p = rtl_reallocateMemory( - pBuffer->m_pMem, (sal_uInt32)(pBuffer->m_Capacity * factor)); - if (p) - { - pBuffer->m_pMem = (sal_Char*)p; - pBuffer->m_Capacity *= factor; - rc = sal_True; - } - - return rc; -} - -/** Read n bytes from file into buffer, - grow the buffer if necessary - - @Returns osl_File_E_None on success else - an error code -*/ -static oslFileError ReadFromFile(oslFileHandle hFile, Buffer* pBuffer, sal_uInt64 Requested, sal_uInt64* pRead) -{ - oslFileError rc; - - OSL_ASSERT(pBuffer); - OSL_ASSERT(hFile); - OSL_ASSERT(pRead); - - if (((pBuffer->m_Size + Requested) > pBuffer->m_Capacity) && - !GrowBuffer(pBuffer, BUFFER_GROW_FACTOR)) - return osl_File_E_NOMEM; - - pBuffer->m_ActiveSectionStart = pBuffer->m_Size; - - rc = osl_readFile( - hFile, - pBuffer->m_pMem + pBuffer->m_ActiveSectionStart, - Requested, - pRead); - - if (osl_File_E_None == rc) - pBuffer->m_Size += *pRead; - - return rc; -} - -/** Makes a sequence from the given buffer and release the memory - occupied by the buffer -*/ -static void MakeSequenceFreeBuffer(sal_Sequence** ppSequence, Buffer* pBuffer, sal_uInt64 Length) -{ - OSL_ASSERT(ppSequence); - OSL_ASSERT(pBuffer); - OSL_ASSERT(Length <= pBuffer->m_Capacity); - - rtl_byte_sequence_constructFromArray(ppSequence, (sal_Int8*)pBuffer->m_pMem, (sal_Int32)Length); - FreeBuffer(pBuffer); -} - -/** Handle occurence of LF character: - construct a sequence from buffer - correct file pointer (maybe we have read more than necessary) - - @Returns osl_File_E_None on success else - an error code -*/ -static oslFileError HandleLFFreeBuffer(oslFileHandle hFile, sal_Sequence** ppSequence, Buffer* pBuffer, sal_uInt64 Pos) -{ - sal_Int64 offset = 0; - oslFileError rc = osl_File_E_None; - - OSL_ASSERT(hFile); - OSL_ASSERT(pBuffer); - OSL_ASSERT(LF == pBuffer->m_pMem[Pos]); - - /* correct file pointer pos in case we have read to far */ - offset = pBuffer->m_Size - (Pos + 1); - rc = osl_setFilePos(hFile, osl_Pos_Current, -offset); - - if (osl_File_E_None == rc) - MakeSequenceFreeBuffer(ppSequence, pBuffer, Pos); - else - FreeBuffer(pBuffer); - - return rc; -} - -/** Handle occurence of CR character - construct a sequence from buffer - correct file pointer (maybe we have read more than necessary) - - @Returns osl_File_E_None on success else - an error code -*/ -static oslFileError HandleCRFreeBuffer(oslFileHandle hFile, sal_Sequence** ppSequence, Buffer* pBuffer, sal_uInt64 Pos) -{ - sal_Int64 offset = 0; - sal_uInt64 nread = 0; - oslFileError rc = osl_File_E_None; - - OSL_ASSERT(hFile); - OSL_ASSERT(pBuffer); - OSL_ASSERT(CR == pBuffer->m_pMem[Pos]); - - if (Pos == (pBuffer->m_Size - 1)) - { - /* only need to check if the next byte is a LF - that's why reading only one byte from file */ - rc = ReadFromFile(hFile, pBuffer, 1, &nread); - - if (osl_File_E_None != rc) - { - FreeBuffer(pBuffer); - return rc; - } - else if (0 == nread) - { - MakeSequenceFreeBuffer(ppSequence, pBuffer, Pos); - return osl_File_E_None; - } - } - - if (LF == pBuffer->m_pMem[Pos + 1]) - Pos++; - - /* correct the file pointer */ - offset = pBuffer->m_Size - (Pos + 1); - rc = osl_setFilePos(hFile, osl_Pos_Current, -offset); - - if (osl_File_E_None == rc) - MakeSequenceFreeBuffer(ppSequence, pBuffer, Pos - 1); - else - FreeBuffer(pBuffer); - - return rc; -} - -/*************************************************************************** - osl_readLine (platform independent) - Reads a line from given file. The new line delimiter(s) are NOT returned! - Valid line ends: \n, \r\n or \r - - @param Handle [in] Handle to an open file. - @param ppSequence [in/out] a pointer to a valid sequence. - - @return osl_File_E_None on success otherwise one of the following errorcodes:<p> - - osl_File_E_INVAL the format of the parameters was not valid<br> - osl_File_E_NOMEM the necessary memory could not be allocated -****************************************************************************/ - -oslFileError SAL_CALL osl_readLine(oslFileHandle Handle, sal_Sequence** ppSeq) -{ - oslFileError rc; - sal_uInt64 nread = 0; - Buffer line_buffer; - sal_uInt64 pos; - - OSL_PRECOND(Handle, "invalid handle"); - OSL_PRECOND(ppSeq, "invalid parameter detected"); - - if (!AllocateBuffer(&line_buffer, INITIAL_BUFF_SIZE)) - return osl_File_E_NOMEM; - - for(;;) - { - rc = ReadFromFile(Handle, &line_buffer, READ_BLOCK_SIZE, &nread); - - if (osl_File_E_None != rc) - { - FreeBuffer(&line_buffer); - return rc; - } - else if (0 == nread) - { - /* EOF */ - nread = line_buffer.m_Size; - MakeSequenceFreeBuffer(ppSeq, &line_buffer, nread); - if (0 < nread) - return osl_File_E_None; - else - return osl_File_E_AGAIN; - } - - /* scan buffer for line end */ - for (pos = line_buffer.m_ActiveSectionStart; pos < line_buffer.m_Size; pos++) - { - switch(line_buffer.m_pMem[pos]) - { - case LF: - return HandleLFFreeBuffer(Handle, ppSeq, &line_buffer, pos); - case CR: - return HandleCRFreeBuffer(Handle, ppSeq, &line_buffer, pos); - } - } - } /* end for */ -} |