/contrib/groff/src/libs/libgroff/lf.cpp

https://bitbucket.org/freebsd/freebsd-head/ · C++ · 63 lines · 40 code · 4 blank · 19 comment · 30 complexity · ce82daa26ca45fcfc31d0f8858da7249 MD5 · raw file

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