xref: /aoo41x/main/sal/workben/t_readline.c (revision 647f063d)
1*647f063dSAndrew Rist /**************************************************************
2*647f063dSAndrew Rist  *
3*647f063dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*647f063dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*647f063dSAndrew Rist  * distributed with this work for additional information
6*647f063dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*647f063dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*647f063dSAndrew Rist  * "License"); you may not use this file except in compliance
9*647f063dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*647f063dSAndrew Rist  *
11*647f063dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*647f063dSAndrew Rist  *
13*647f063dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*647f063dSAndrew Rist  * software distributed under the License is distributed on an
15*647f063dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647f063dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*647f063dSAndrew Rist  * specific language governing permissions and limitations
18*647f063dSAndrew Rist  * under the License.
19*647f063dSAndrew Rist  *
20*647f063dSAndrew Rist  *************************************************************/
21*647f063dSAndrew Rist 
22cdf0e10cSrcweir /*
23cdf0e10cSrcweir  * t_readline.c
24cdf0e10cSrcweir  */
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "osl/file.h"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "osl/diagnose.h"
29cdf0e10cSrcweir #include "rtl/ustring.h"
30cdf0e10cSrcweir #include "rtl/byteseq.h"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <stdio.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir /* main */
main(int argc,char ** argv)35cdf0e10cSrcweir int main (int argc, char ** argv)
36cdf0e10cSrcweir {
37cdf0e10cSrcweir   if (argc > 1)
38cdf0e10cSrcweir   {
39cdf0e10cSrcweir     oslFileError  result;
40cdf0e10cSrcweir     oslFileHandle hFile = 0;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     rtl_uString * pSystemPath = 0;
43cdf0e10cSrcweir     rtl_uString * pFileUrl = 0;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     rtl_uString_newFromAscii (&pSystemPath, argv[1]);
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     result = osl_getFileURLFromSystemPath (pSystemPath, &pFileUrl);
48cdf0e10cSrcweir     rtl_uString_release (pSystemPath), pSystemPath = 0;
49cdf0e10cSrcweir     if (result != osl_File_E_None)
50cdf0e10cSrcweir       return (result);
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     result = osl_openFile (pFileUrl, &hFile, osl_File_OpenFlag_Read);
53cdf0e10cSrcweir     rtl_uString_release (pFileUrl), pFileUrl = 0;
54cdf0e10cSrcweir     if (result == osl_File_E_None)
55cdf0e10cSrcweir     {
56cdf0e10cSrcweir       sal_Sequence * pBuffer = 0;
57cdf0e10cSrcweir       for ( ;; )
58cdf0e10cSrcweir       {
59cdf0e10cSrcweir         sal_Int32 i, n;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         result = osl_readLine (hFile, &pBuffer);
62cdf0e10cSrcweir         if (result != osl_File_E_None)
63cdf0e10cSrcweir           break;
64cdf0e10cSrcweir #if 0
65cdf0e10cSrcweir         if (pBuffer->elements[0] == 0)
66cdf0e10cSrcweir           /* @@@ cannot distinguish empty line from EOF @@@ */
67cdf0e10cSrcweir           break;
68cdf0e10cSrcweir #endif
69cdf0e10cSrcweir         for (i = 0, n = pBuffer->nElements; i < n; i++)
70cdf0e10cSrcweir           printf ("%c", (char)(pBuffer->elements[i]));
71cdf0e10cSrcweir         printf("\n");
72cdf0e10cSrcweir       }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir       rtl_byte_sequence_release (pBuffer), pBuffer = 0;
75cdf0e10cSrcweir       (void) osl_closeFile (hFile);
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir   }
78cdf0e10cSrcweir   return 0;
79cdf0e10cSrcweir }
80