10a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner/* Copyright (C) 2011 The Android Open Source Project
20a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner**
30a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner** This software is licensed under the terms of the GNU General Public
40a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner** License version 2, as published by the Free Software Foundation, and
50a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner** may be copied, distributed, and modified under those terms.
60a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner**
70a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner** This program is distributed in the hope that it will be useful,
80a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner** but WITHOUT ANY WARRANTY; without even the implied warranty of
90a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
100a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner** GNU General Public License for more details.
110a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner*/
120a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner#ifndef _ANDROID_UTILS_LINEINPUT_H
130a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner#define _ANDROID_UTILS_LINEINPUT_H
140a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner
150a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner#include <stdio.h>
160a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner
17f0c747e01328e713891f2fa66c4f9df64f580dc2David 'Digit' Turner#include "android/utils/compiler.h"
18f0c747e01328e713891f2fa66c4f9df64f580dc2David 'Digit' Turner
19f0c747e01328e713891f2fa66c4f9df64f580dc2David 'Digit' TurnerANDROID_BEGIN_HEADER
20f0c747e01328e713891f2fa66c4f9df64f580dc2David 'Digit' Turner
210a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner/* A LineInput is used to read input text, one line at a time,
220a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner * into a temporary buffer owner by the LineInput object.
230a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner */
240a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turnertypedef struct LineInput LineInput;
250a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner
260a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner/* Create a LineInput object that reads from a FILE* object */
270a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' TurnerLineInput*  lineInput_newFromStdFile( FILE* file );
280a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner
290a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner/* Read next line from input. The result is zero-terminated with
300a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner * all newlines removed (\n, \r or \r\n) automatically.
310a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner *
320a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner * Returns NULL in case of error, or when the end of file is reached.
330a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner * See lineInput_isEof() and lineInput_getError()
340a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner *
350a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner * The returned string is owned by the LineInput object and its
360a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner * value will not persist any other call to any LineInput functions.
370a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner */
380a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turnerconst char* lineInput_getLine( LineInput* input );
390a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner
400a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner/* Same as lineInput_getLine(), but also returns the line size into
410a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner * '*pSize' to save you a strlen() call.
420a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner */
430a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turnerconst char* lineInput_getLineAndSize( LineInput* input, size_t *pSize );
440a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner
450a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner/* Returns the number of the last line read by lineInput_getLine */
460a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turnerint lineInput_getLineNumber( LineInput* input );
470a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner
480a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner/* Returns TRUE iff the end of file was reached */
490a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turnerint lineInput_isEof( LineInput* input );
500a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner
510a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner/* Return the error condition of a LineInput object.
520a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner * These are standard errno code for the last operation.
530a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner * Note: EOF corresponds to 0 here.
540a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner */
550a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turnerint lineInput_getError( LineInput* input );
560a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner
570a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner/* Free a LineInput object. */
580a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turnervoid lineInput_free( LineInput* input );
590a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner
60f0c747e01328e713891f2fa66c4f9df64f580dc2David 'Digit' TurnerANDROID_END_HEADER
61f0c747e01328e713891f2fa66c4f9df64f580dc2David 'Digit' Turner
620a879bf9ba318562e41a1bd4a6f9547f124a9831David 'Digit' Turner#endif /* _ANDROID_UTILS_LINEINPUT_H */
63