lf.cpp revision 114402
12116Sjkh// -*- C++ -*-
22116Sjkh/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
32116Sjkh     Written by James Clark (jjc@jclark.com)
42116Sjkh
52116SjkhThis file is part of groff.
62116Sjkh
72116Sjkhgroff is free software; you can redistribute it and/or modify it under
82116Sjkhthe terms of the GNU General Public License as published by the Free
92116SjkhSoftware Foundation; either version 2, or (at your option) any later
102116Sjkhversion.
118870Srgrimes
122116Sjkhgroff is distributed in the hope that it will be useful, but WITHOUT ANY
132116SjkhWARRANTY; without even the implied warranty of MERCHANTABILITY or
142116SjkhFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
152116Sjkhfor more details.
16176451Sdas
17176451SdasYou should have received a copy of the GNU General Public License along
182116Sjkhwith groff; see the file COPYING.  If not, write to the Free Software
192116SjkhFoundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
202116Sjkh
212116Sjkh#include <string.h>
222116Sjkh#include <ctype.h>
2397413Salfred#include "cset.h"
2497413Salfred#include "stringclass.h"
252116Sjkh
2697413Salfredextern void change_filename(const char *);
2797413Salfredextern void change_lineno(int);
282116Sjkh
292116Sjkhint interpret_lf_args(const char *p)
302116Sjkh{
312116Sjkh  while (*p == ' ')
322116Sjkh    p++;
33121590Sdas  if (!csdigit(*p))
342116Sjkh    return 0;
352116Sjkh  int ln = 0;
362116Sjkh  do {
372116Sjkh    ln *= 10;
382116Sjkh    ln += *p++ - '0';
392116Sjkh  } while (csdigit(*p));
402116Sjkh  if (*p != ' ' && *p != '\n' && *p != '\0')
412116Sjkh    return 0;
422116Sjkh  while (*p == ' ')
432116Sjkh    p++;
44  if (*p == '\0' || *p == '\n')  {
45    change_lineno(ln);
46    return 1;
47  }
48  const char *q;
49  for (q = p;
50       *q != '\0' && *q != ' ' && *q != '\n' && *q != '\\';
51       q++)
52    ;
53  string tem(p, q - p);
54  while (*q == ' ')
55    q++;
56  if (*q != '\n' && *q != '\0')
57    return 0;
58  tem += '\0';
59  change_filename(tem.contents());
60  change_lineno(ln);
61  return 1;
62}
63