1*cdf0e10cSrcweir /* 2*cdf0e10cSrcweir * t_readline.c 3*cdf0e10cSrcweir */ 4*cdf0e10cSrcweir 5*cdf0e10cSrcweir #include "osl/file.h" 6*cdf0e10cSrcweir 7*cdf0e10cSrcweir #include "osl/diagnose.h" 8*cdf0e10cSrcweir #include "rtl/ustring.h" 9*cdf0e10cSrcweir #include "rtl/byteseq.h" 10*cdf0e10cSrcweir 11*cdf0e10cSrcweir #include <stdio.h> 12*cdf0e10cSrcweir 13*cdf0e10cSrcweir /* main */ 14*cdf0e10cSrcweir int main (int argc, char ** argv) 15*cdf0e10cSrcweir { 16*cdf0e10cSrcweir if (argc > 1) 17*cdf0e10cSrcweir { 18*cdf0e10cSrcweir oslFileError result; 19*cdf0e10cSrcweir oslFileHandle hFile = 0; 20*cdf0e10cSrcweir 21*cdf0e10cSrcweir rtl_uString * pSystemPath = 0; 22*cdf0e10cSrcweir rtl_uString * pFileUrl = 0; 23*cdf0e10cSrcweir 24*cdf0e10cSrcweir rtl_uString_newFromAscii (&pSystemPath, argv[1]); 25*cdf0e10cSrcweir 26*cdf0e10cSrcweir result = osl_getFileURLFromSystemPath (pSystemPath, &pFileUrl); 27*cdf0e10cSrcweir rtl_uString_release (pSystemPath), pSystemPath = 0; 28*cdf0e10cSrcweir if (result != osl_File_E_None) 29*cdf0e10cSrcweir return (result); 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir result = osl_openFile (pFileUrl, &hFile, osl_File_OpenFlag_Read); 32*cdf0e10cSrcweir rtl_uString_release (pFileUrl), pFileUrl = 0; 33*cdf0e10cSrcweir if (result == osl_File_E_None) 34*cdf0e10cSrcweir { 35*cdf0e10cSrcweir sal_Sequence * pBuffer = 0; 36*cdf0e10cSrcweir for ( ;; ) 37*cdf0e10cSrcweir { 38*cdf0e10cSrcweir sal_Int32 i, n; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir result = osl_readLine (hFile, &pBuffer); 41*cdf0e10cSrcweir if (result != osl_File_E_None) 42*cdf0e10cSrcweir break; 43*cdf0e10cSrcweir #if 0 44*cdf0e10cSrcweir if (pBuffer->elements[0] == 0) 45*cdf0e10cSrcweir /* @@@ cannot distinguish empty line from EOF @@@ */ 46*cdf0e10cSrcweir break; 47*cdf0e10cSrcweir #endif 48*cdf0e10cSrcweir for (i = 0, n = pBuffer->nElements; i < n; i++) 49*cdf0e10cSrcweir printf ("%c", (char)(pBuffer->elements[i])); 50*cdf0e10cSrcweir printf("\n"); 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir rtl_byte_sequence_release (pBuffer), pBuffer = 0; 54*cdf0e10cSrcweir (void) osl_closeFile (hFile); 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir return 0; 58*cdf0e10cSrcweir } 59