tesseract
3.04.00
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
listio.cpp
Go to the documentation of this file.
1
/* -*-C-*-
2
################################################################################
3
#
4
# File: listio.c
5
# Description: List I/O processing procedures.
6
# Author: Mark Seaman, Software Productivity
7
# Created: Thu Jul 23 13:24:09 1987
8
# Modified: Fri May 17 17:33:30 1991 (Mark Seaman) marks@hpgrlt
9
# Language: C
10
# Package: N/A
11
# Status: Reusable Software Component
12
#
13
# (c) Copyright 1987, Hewlett-Packard Company.
14
** Licensed under the Apache License, Version 2.0 (the "License");
15
** you may not use this file except in compliance with the License.
16
** You may obtain a copy of the License at
17
** http://www.apache.org/licenses/LICENSE-2.0
18
** Unless required by applicable law or agreed to in writing, software
19
** distributed under the License is distributed on an "AS IS" BASIS,
20
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
** See the License for the specific language governing permissions and
22
** limitations under the License.
23
#
24
################################################################################
25
26
This file contains the implementations of a set of general purpose
27
list I/O routines. For the interface definitions look in the file
28
"listio.h".
29
---------------------------------------------------------------------------*/
30
31
#include <stdio.h>
32
#include <string.h>
33
#include <stdlib.h>
34
#include "
listio.h
"
35
36
/*---------------------------------------------------------------------------
37
Public Function Code
38
---------------------------------------------------------------------------*/
39
/*************************************************************************
40
* R E A D L I S T
41
*
42
* Read a list of strings from a file. Return the string list to the
43
* caller.
44
*************************************************************************/
45
LIST
read_list
(
const
char
*
filename
) {
46
FILE *infile;
47
char
s[
CHARS_PER_LINE
];
48
LIST
list;
49
50
if
((infile =
open_file
(filename,
"r"
)) ==
NULL
)
51
return
(
NIL_LIST
);
52
53
list =
NIL_LIST
;
54
while
(fgets (s,
CHARS_PER_LINE
, infile) !=
NULL
) {
55
s[
CHARS_PER_LINE
- 1] =
'\0'
;
56
if
(strlen (s) > 0) {
57
if
(s[strlen (s) - 1] ==
'\n'
)
58
s[strlen (s) - 1] =
'\0'
;
59
if
(strlen (s) > 0) {
60
list =
push
(list, (
LIST
)
strsave
(s));
61
}
62
}
63
}
64
65
fclose(infile);
66
return
(
reverse_d
(list));
67
}
open_file
FILE * open_file(const char *filename, const char *mode)
Definition:
cutil.cpp:82
push
LIST push(LIST list, void *element)
Definition:
oldlist.cpp:323
NULL
#define NULL
Definition:
host.h:144
strsave
#define strsave(s)
Definition:
cutil.h:111
list_rec
Definition:
oldlist.h:127
CHARS_PER_LINE
#define CHARS_PER_LINE
Definition:
cutil.h:57
listio.h
read_list
LIST read_list(const char *filename)
Definition:
listio.cpp:45
NIL_LIST
#define NIL_LIST
Definition:
oldlist.h:126
tesseract-c_api-demo.filename
string filename
Definition:
tesseract-c_api-demo.py:29
reverse_d
LIST reverse_d(LIST list)
Definition:
oldlist.cpp:371
cutil
listio.cpp
Generated by
1.8.11