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 *************************************************************************/
read_list(const char * filename)45 LIST read_list(const char *filename) {
46 FILE *infile;
47 char s[CHARS_PER_LINE];
48 LIST list;
49 char *chopAt250();
50
51 if ((infile = open_file (filename, "r")) == NULL)
52 return (NIL);
53
54 list = NIL;
55 while (fgets (s, CHARS_PER_LINE, infile) != NULL) {
56 s[CHARS_PER_LINE - 1] = '\0';
57 if (strlen (s) > 0) {
58 if (s[strlen (s) - 1] == '\n')
59 s[strlen (s) - 1] = '\0';
60 if (strlen (s) > 0) {
61 list = push (list, (LIST) strsave (s));
62 }
63 }
64 }
65
66 fclose(infile);
67 return (reverse_d (list));
68 }
69