summaryrefslogtreecommitdiff
path: root/fonts/utilities/mff-29/fgetword.c
blob: 7092af5ef80157dbfa0324bc27dfd8428850edd1 (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
/* fgetword.c 2.9.0 92/07/06 */
/* see strword(3) */

/* - Damian Cugley <pdc@prg.ox.ac.uk> Fri.  1 Mar. 1991
-----------------------------------------------------------------------
    This software module copyright (c) 1991 Damian Cugley.  
    It is provided for free on an "as-is" basis.
    See the file COPYING for more information.
-----------------------------------------------------------------------
*/

#include <ctype.h>
#include "xstdio.h"

char *
fgetword(buf, fp)
     char *buf;			/* result written here -- must be big enuf */
     FILE *fp;			/* read from this file */
{
  char *p; int ch;

  /*  Skip whitespace and '#' comments: */
  while ((ch = getc(fp)) != EOF)
    if (ch == '#')
      while ((ch = getc(fp)) != EOF && ch != '\n')
	;
    else if (!isspace(ch))
      break;
  if (ch == EOF) return (char *)0;
  p = buf;
  if (ch == '"')	
    {	
      while ((ch = getc(fp)) != EOF
	     && !(ch == '"' && (ch = getc(fp)) != '"'))
	*p++ = ch;
      if (ch != EOF && !isspace(ch)) ungetc(ch, fp);
    }
  else if (ch != EOF)
    do
      {
	*p++ = ch; 
      } while ((ch = getc(fp)) != EOF && !isspace(ch));
  *p = '\0';
  return buf;	
}