[go: up one dir, main page]

File: faces.c

package info (click to toggle)
a2ps 1%3A4.14-1.3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,324 kB
  • sloc: ansic: 26,966; sh: 11,844; lex: 2,286; perl: 1,156; yacc: 757; makefile: 609; 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 (199 lines) | stat: -rw-r--r-- 4,384 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
/*
 * faces.h
 *
 * definition of the faces used by a2ps
 * Copyright (c) 1988, 89, 90, 91, 92, 93 Miguel Santana
 * Copyright (c) 1995, 96, 97, 98 Akim Demaille, Miguel Santana
 * $Id: faces.c,v 1.1.1.1.2.1 2007/12/29 01:58:17 mhatta Exp $
 */

/*
 * 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 "a2ps.h"
#include "faces.h"
#include "routines.h"
#include "jobs.h"

extern const char * program_name;

/* List of the faces that must be checked */
enum face_e base_faces [] = {
  Plain,
  Keyword,
  Keyword_strong,
  Label,
  Label_strong,
  String,
  Symbol,
  Error,
  Comment,
  Comment_strong,
  No_face
};

struct face_and_name {
  const char * name;
  enum face_e face;
};

static const struct face_and_name face_and_name [] = {
  { "NoFace", No_face },
  { "Plain", Plain },
  { "Keyword", Keyword },
  { "Keyword_strong", Keyword_strong },
  { "Label", Label },
  { "Label_strong", Label_strong },
  { "String", String },
  { "Symbol", Symbol },
  { "Error", Error },
  { "Comment", Comment },
  { "Comment_strong", Comment_strong },
  { NULL, No_face }
};

enum face_e
string_to_face (const char * string)
{
  int i;

  for (i = 0 ; face_and_name[i].name ; i++)
    if (strequ (string, face_and_name[i].name))
      return face_and_name[i].face;
  
  return No_face;
}

static inline const char *
_face_to_string (enum face_e face)
{
  int i;
  
  for (i = 0 ; face_and_name[i].name ; i++)
    if (face == face_and_name[i].face)
      return face_and_name[i].name;
  
  return "UnknownFace";
}

const char *
face_to_string (enum face_e face)
{
  return _face_to_string (face);
}

/*
 * Report the face
 */
void
face_self_print (enum face_e face, FILE * stream)
{
  fputs (_face_to_string (face), stream);
}

/* convertion from a font to the postscript function */
const char *
face_eo_ps (enum face_e face)
{
  switch (face) {
  case Plain:
    return "p";
  case Symbol:
    return "sy";
  case Keyword:
    return "k";
  case Keyword_strong:
    return "K";
  case Comment:
    return "c";
  case Comment_strong:
    return "C";
  case Label:
    return "l";
  case Label_strong:
    return "L";
  case String:
    return "str";
  case Error:
    return "e";
  default:
    error (1, 0, "face_eo_ps: %d", face);
  }
  return 0; /* For -Wall */
}

/* Check that the face_eo_font knowldge is complete */
void
check_face_eo_font (struct a2ps_job * job)
{
  int i;
  int err = false;

  for (i = 0 ; base_faces [i] != No_face ; i++)
    if (!job->face_eo_font [base_faces [i]]) {
      err = true;
      fprintf (stderr, "%s: face `", program_name);
      face_self_print (base_faces [i], stderr);
      fprintf (stderr, "' (%d) has no specified font\n", base_faces [i]);
    }
  if (err)
    error (1, 0, _("incomplete knowledge of faces"));
}

/*
 * Return true if the faces are known, false otherwise
 */
int
face_eo_font_is_set (struct a2ps_job * job)
{
  enum face_e f;
  int res = true;

  for (f = First_face ; f <= Last_face ; f++)
    if (!job->face_eo_font [f])
      res = false;

  return res;
}

/* Initialize the face_font_to_font array to non acceptable values */
void
init_face_eo_font (struct a2ps_job * job)
{
  enum face_e f;
  for (f = First_face ; f <= Last_face ; f++)
    job->face_eo_font [f] = NULL;
}

void
face_eo_font_free (char * face_eo_font [NB_FACES])
{
  enum face_e f;
  for (f = First_face ; f <= Last_face ; f++)
    /* Xfree because it may not have been initialized if no printing
     * was done (e.g. --help) */
    XFREE (face_eo_font [f]);
}

void
face_set_font (struct a2ps_job * job, enum face_e face, const char * font_name)
{
  XFREE (job->face_eo_font [face]);
  job->face_eo_font [face] = xstrdup (font_name);
}