Tesseract  3.02
tesseract-ocr/cutil/listio.cpp
Go to the documentation of this file.
00001 /* -*-C-*-
00002 ################################################################################
00003 #
00004 # File:                                         listio.c
00005 # Description:                          List I/O processing procedures.
00006 # Author:                                       Mark Seaman, Software Productivity
00007 # Created:                                      Thu Jul 23 13:24:09 1987
00008 # Modified:     Fri May 17 17:33:30 1991 (Mark Seaman) marks@hpgrlt
00009 # Language:                                     C
00010 # Package:                                      N/A
00011 # Status:                                       Reusable Software Component
00012 #
00013 # (c) Copyright 1987, Hewlett-Packard Company.
00014 ** Licensed under the Apache License, Version 2.0 (the "License");
00015 ** you may not use this file except in compliance with the License.
00016 ** You may obtain a copy of the License at
00017 ** http://www.apache.org/licenses/LICENSE-2.0
00018 ** Unless required by applicable law or agreed to in writing, software
00019 ** distributed under the License is distributed on an "AS IS" BASIS,
00020 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021 ** See the License for the specific language governing permissions and
00022 ** limitations under the License.
00023 #
00024 ################################################################################
00025 
00026 This file contains the implementations of a set of general purpose
00027 list I/O routines.  For the interface definitions look in the file
00028 "listio.h".
00029 ---------------------------------------------------------------------------*/
00030 
00031 #include <stdio.h>
00032 #include <string.h>
00033 #include <stdlib.h>
00034 #include "listio.h"
00035 
00036 /*---------------------------------------------------------------------------
00037         Public Function Code
00038 ---------------------------------------------------------------------------*/
00039 /*************************************************************************
00040  *  R E A D   L I S T
00041  *
00042  *                                                      Read a list of strings from a file.  Return the string list to the
00043  *                                                      caller.
00044  *************************************************************************/
00045 LIST read_list(const char *filename) {
00046   FILE *infile;
00047   char s[CHARS_PER_LINE];
00048   LIST list;
00049   char *chopAt250();
00050 
00051   if ((infile = open_file (filename, "r")) == NULL)
00052     return (NIL_LIST);
00053 
00054   list = NIL_LIST;
00055   while (fgets (s, CHARS_PER_LINE, infile) != NULL) {
00056     s[CHARS_PER_LINE - 1] = '\0';
00057     if (strlen (s) > 0) {
00058       if (s[strlen (s) - 1] == '\n')
00059         s[strlen (s) - 1] = '\0';
00060       if (strlen (s) > 0) {
00061         list = push (list, (LIST) strsave (s));
00062       }
00063     }
00064   }
00065 
00066   fclose(infile);
00067   return (reverse_d (list));
00068 }