xref: /netbsd-src/external/gpl2/groff/dist/src/libs/libgroff/lf.cpp (revision 89a07cf815a29524268025a1139fac4c5190f765)
1 /*	$NetBSD: lf.cpp,v 1.1.1.1 2016/01/13 18:41:48 christos Exp $	*/
2 
3 // -*- C++ -*-
4 /* Copyright (C) 1989, 1990, 1991, 1992, 2004 Free Software Foundation, Inc.
5      Written by James Clark (jjc@jclark.com)
6 
7 This file is part of groff.
8 
9 groff is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
12 version.
13 
14 groff is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License along
20 with groff; see the file COPYING.  If not, write to the Free Software
21 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
22 
23 #include <ctype.h>
24 
25 #include "lib.h"
26 #include "cset.h"
27 #include "stringclass.h"
28 
29 extern void change_filename(const char *);
30 extern void change_lineno(int);
31 
interpret_lf_args(const char * p)32 int interpret_lf_args(const char *p)
33 {
34   while (*p == ' ')
35     p++;
36   if (!csdigit(*p))
37     return 0;
38   int ln = 0;
39   do {
40     ln *= 10;
41     ln += *p++ - '0';
42   } while (csdigit(*p));
43   if (*p != ' ' && *p != '\n' && *p != '\0')
44     return 0;
45   while (*p == ' ')
46     p++;
47   if (*p == '\0' || *p == '\n')  {
48     change_lineno(ln);
49     return 1;
50   }
51   const char *q;
52   for (q = p;
53        *q != '\0' && *q != ' ' && *q != '\n' && *q != '\\';
54        q++)
55     ;
56   string tem(p, q - p);
57   while (*q == ' ')
58     q++;
59   if (*q != '\n' && *q != '\0')
60     return 0;
61   tem += '\0';
62   change_filename(tem.contents());
63   change_lineno(ln);
64   return 1;
65 }
66