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