xref: /trunk/main/sal/workben/t_readline.c (revision 509a48ff)
1647f063dSAndrew Rist /**************************************************************
2647f063dSAndrew Rist  *
3647f063dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4647f063dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5647f063dSAndrew Rist  * distributed with this work for additional information
6647f063dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7647f063dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8647f063dSAndrew Rist  * "License"); you may not use this file except in compliance
9647f063dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10647f063dSAndrew Rist  *
11647f063dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12647f063dSAndrew Rist  *
13647f063dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14647f063dSAndrew Rist  * software distributed under the License is distributed on an
15647f063dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16647f063dSAndrew Rist  * KIND, either express or implied.  See the License for the
17647f063dSAndrew Rist  * specific language governing permissions and limitations
18647f063dSAndrew Rist  * under the License.
19647f063dSAndrew Rist  *
20647f063dSAndrew Rist  *************************************************************/
21647f063dSAndrew 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 
42*509a48ffSpfg     rtl_uString * pSystemPath = NULL;
43*509a48ffSpfg     rtl_uString * pFileUrl = NULL;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     rtl_uString_newFromAscii (&pSystemPath, argv[1]);
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     result = osl_getFileURLFromSystemPath (pSystemPath, &pFileUrl);
48*509a48ffSpfg     rtl_uString_release (pSystemPath), pSystemPath = NULL;
49cdf0e10cSrcweir     if (result != osl_File_E_None)
50cdf0e10cSrcweir       return (result);
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     result = osl_openFile (pFileUrl, &hFile, osl_File_OpenFlag_Read);
53*509a48ffSpfg     rtl_uString_release (pFileUrl), pFileUrl = NULL;
54cdf0e10cSrcweir     if (result == osl_File_E_None)
55cdf0e10cSrcweir     {
56*509a48ffSpfg       sal_Sequence * pBuffer = NULL;
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 
74*509a48ffSpfg       rtl_byte_sequence_release (pBuffer), pBuffer = NULL;
75cdf0e10cSrcweir       (void) osl_closeFile (hFile);
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir   }
78cdf0e10cSrcweir   return 0;
79cdf0e10cSrcweir }
80