File: read.c

package info (click to toggle)
a2ps 1%3A4.14-1.1%2Bdeb6u1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 12,324 kB
  • ctags: 4,908
  • sloc: ansic: 26,659; sh: 13,155; lex: 2,286; perl: 1,156; yacc: 757; makefile: 605; lisp: 398; ada: 263; objc: 189; f90: 109; ml: 85; sql: 74; pascal: 57; modula3: 33; haskell: 32; sed: 30; java: 29; python: 24
file content (206 lines) | stat: -rw-r--r-- 5,306 bytes parent folder | download | duplicates (8)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * read.c --- routines of input with no style sheets
 *
 * Copyright (c) 1988-1993 Miguel Santana
 * Copyright (c) 1995-2000 Akim Demaille, Miguel Santana
 *
 */

/*
 * This file is part of a2ps.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "main.h"
#include "buffer.h"


/*-------------------------------------------------------.
| Returns a single char (EOF for end-of-file).           |
|                                                        |
| Does the nroff's replacement for underline, bold etc.  |
`-------------------------------------------------------*/

static int
plain_getc (buffer_t * buffer, enum face_e *face)
{
  uchar c;

  if (buffer_is_empty (buffer))
    {
      buffer_get (buffer);

      /* We don't trust liba2ps for the line numbers, because if a2ps
	 skips some lines (e.g., --strip-level, or INVISIBLE), liba2ps
	 will number upon output lines, not imput lines, which is what
	 is expected.  */
      (CURRENT_FILE (job))->lines = buffer->line;

      if (buffer->len == 0)
	return EOF;
    }

  *face = Plain;
  c = buffer->content[(buffer->curr)++];

  /* Check if it is a special nroff'ed sequence */
  if (buffer->content[buffer->curr] == '\b')
    {
      /* We might be dealing with misceleanous nroff'ed pages. */
      const uchar *input = buffer->content + buffer->curr + 1;

      /* This might be a bolding sequence.  The bad news is that some
	 strange systems build the bold sequences with only one
	 rewriting, not the 3 usuals.

	 Super strong `_', seen in Sun's mpeg_rc doc.  */
      if (c	== input[0] &&
	  '\b'	== input[1] &&
	  c	== input[2] &&
	  '\b'	== input[3] &&
	  c	== input[4] &&
	  '\b'	== input[5] &&
	  c	== input[6])
	{
	  *face = Label_strong;
	  buffer->curr += 8;
	}
      else if (c     == input[0] &&
	       '\b'  == input[1] &&
	       c     == input[2] &&
	       '\b'  == input[3] &&
	       c     == input[4])
	{
	  *face = Keyword_strong;
	  buffer->curr += 6;
	}
      else if  (c    == input[0] &&
		'\b' == input[1] &&
		c    == input[2])
	{
	  *face = Keyword_strong;
	  buffer->curr += 4;
	}
      else if  (c == input[0])
	{
	  *face = Keyword_strong;
	  buffer->curr += 2;
	}
      /* If C is `_', then set font to italic and move to next char.
	 */
      else if (c == '_')
	{
	  char c2 = input[0];
	  /* Winner of the cup: mpeg_rc, from Sun, where it tries both
	     to underline, and to boldize.  */
	  if	('\b' == input[1] &&
		 c2   == input[2] &&
		 '\b' == input[3] &&
		 c2   == input[4] &&
		 '\b' == input[5] &&
		 c2   == input[6])
	    {
	      *face = Label_strong;
	      c = c2;
	      buffer->curr += 8;
	    }
	  else
	    {
	      *face = Keyword;
	      c = input[0];
	      buffer->curr += 2;
	    }
	}
      /* Seen in gcc.1: o;\b;+, seen in cccp.1: +;\b;o to have an
	 itemizing symbol.  */
      else if (('o' == c &&
		'+' == input[0])
	       || ('+' == c &&
		   'o' == input[0]))
	{
	  *face = Symbol;
	  buffer->curr += 2;
	  c = 0305; /* \oplus in LaTeX */
	}
      /* Seen in groff.1 : c;\b;O, for copyright */
      else if ('c' == c &&
	       'O' == input[0])
	{
	  *face = Symbol;
	  buffer->curr += 2;
	  c = 0343; /* \copyright. */
	}
      /* Seen in gtroff.1 : +;\b;_, for plus or minus */
      else if ('+' == c &&
	       '_' == input[0])
	{
	  *face = Symbol;
	  buffer->curr += 2;
	  c = 0261;
	}
      /* Seen in geqn.1 : ~;\b>;\b;_ for greater or equal */
      else if ('~'  == c &&
	       '>'  == input[0] &&
	       '\b' == input[1] &&
	       '_'  == input[2])
	{
	  *face = Symbol;
	  buffer->curr += 4;
	  c = 0263;
	}
      /* Less than or equal to. */
      else if ('~'  == c &&
	       '<'  == input[0] &&
	       '\b' == input[1] &&
	       '_'  == input[2])
	{
	  *face = Symbol;
	  buffer->curr += 4;
	  c = 0243;
	}
      /* Underlined: x;\b;_ . Note that we have a conflict here in the
	 case x == '+' (see above).  This choice seems the best.  */
      else if ('_' == input[0])
	{
	  *face = Keyword;
	  buffer->curr += 2;
	}
      /* (Should be last). In some case, headers or footers too big,
	 nroff backslashes so that both chars. are superimposed.  We
	 decided to keep only the first one.  */
      else if (((CURRENT_FILE (job)->lines + 3) % 66 == 0)
	       || ((CURRENT_FILE (job)->lines - 4) % 66 == 0))
	{
	  buffer->curr += 2;
	}
      /* else: treate the backslash as a special characters */
    }
  return c;
}

/*
 * Print a file to postscript (no style)
 */
void
plain_print_postscript (a2ps_job * Job, buffer_t * buffer)
{
  enum face_e face = Plain;
  int c;

  while ((c = plain_getc (buffer, &face)) != EOF)
    ps_print_char (Job, c, face);
}