summaryrefslogtreecommitdiff
path: root/fonts/utilities/mff-29/al_file.c
blob: 220d709702cf2aee5e3845a79160ea9b9268ff14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* al_file.c 2.9.0 92/07/06 -- split-off part of argloop.c
 *
-----------------------------------------------------------------------
    This software module copyright (c) 1990, 1991 Damian Cugley.  
    It is provided for free on an "as-is" basis.
    See the file COPYING for more information.
    See argloop(3) for more information on this software module.
-----------------------------------------------------------------------
 */

#include "config.h"
#include "xstdio.h"		/* <stdio.h> plus prototypes */
#include "strmisc.h"		/* inludes <string(s).h> */
#include "argloop.h"

struct file
{
  FILE *fp;
  char buf[1024];		/* maximum sized word this allows */
};

static const char *
file_word(st)
     struct file *st;
{
  return fgetword(st->buf, st->fp);
}

void
file_free(st)
     struct file *st;
{
  fclose(st->fp);
  xfree(st);
}

Argloop_context *
al_file(fp)
     FILE *fp;
{
  struct file *st = (struct file *)xmalloc(sizeof (struct file));
  Argloop_context *cxt = (Argloop_context *)xmalloc(sizeof (Argloop_context));
  
  st->fp = fp;
  cxt->data = (char *)st;
  cxt->word = file_word;
  cxt->free = file_free;
  cxt->first = (char *)0;
  return cxt;
}