~ubuntu-branches/ubuntu/raring/boxshade/raring-proposed

« back to all changes in this revision

Viewing changes to .pc/kickOutGets.patch/dv_html.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille, David Paleino, Andreas Tille
  • Date: 2011-01-14 08:27:01 UTC
  • Revision ID: james.westby@ubuntu.com-20110114082701-etwd13n9n7nz8h78
Tags: 3.3.1-5
[ David Paleino ]
* Removed myself from Uploaders

[ Andreas Tille ]
* debian/control
  - Standards-Version: 3.9.1 (no changes needed)
  - Debhelper 7
  - Fix spelling of Debian Med in maintainer address
* debian/rules: s/dh_clean -k/dh_prep/
* debian/source/format: 3.0 (quilt)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "dv_all.h"
 
2
#include "version.h"
 
3
#include <math.h>
 
4
#include <time.h>
 
5
#include <stdarg.h>
 
6
 
 
7
/*----------------------------------------*/
 
8
/*   POSTSCRIPT  specific section         */
 
9
/*----------------------------------------*/
 
10
 
 
11
typedef struct {
 
12
  double r, g, b;
 
13
} RGB;
 
14
 
 
15
typedef struct {
 
16
  RGB fg, bg;
 
17
} HTMLrecord;
 
18
 
 
19
 
 
20
static HTMLrecord html[5];   /* POSTSCRIPT-specifics*/
 
21
static int open_TR = FALSE;
 
22
static int open_TABLE = FALSE;
 
23
static int Col;
 
24
 
 
25
static void Gray(RGB *rgb, double gray) {
 
26
  rgb->r = gray;
 
27
  rgb->g = gray;
 
28
  rgb->b = gray;
 
29
}
 
30
 
 
31
static void Rgb(RGB *rgb, double r, double g, double b) {
 
32
  rgb->r = r;
 
33
  rgb->g = g;
 
34
  rgb->b = b;
 
35
}
 
36
 
 
37
static void Code2Color(char code, RGB *rgb) {
 
38
  switch (code) {
 
39
    case 'W': Gray(rgb, 1.0); break;
 
40
    case '1':
 
41
    case '5': Gray(rgb, 0.8);
 
42
              break;
 
43
    case '2':
 
44
    case '6': Gray(rgb, 0.6);
 
45
              break;
 
46
    case '3':
 
47
    case '7': Gray(rgb, 0.4);
 
48
              break;
 
49
    case '4':
 
50
    case '8': Gray(rgb, 0.2);
 
51
              break;
 
52
    case 'B': Gray(rgb, 0.0); break;
 
53
    case 'R': Rgb(rgb, 1.0, 0.0, 0.0); break;
 
54
    case 'G': Rgb(rgb, 0.0, 1.0, 0.0); break;
 
55
    case 'L': Rgb(rgb, 0.0, 0.0, 1.0); break;
 
56
    case 'Y': Rgb(rgb, 1.0, 1.0, 0.0); break;
 
57
    case 'M': Rgb(rgb, 1.0, 0.0, 1.0); break;
 
58
    case 'C': Rgb(rgb, 0.0, 1.0, 1.0); break;
 
59
  }
 
60
}
 
61
 
 
62
static void menu_HTML(HTMLrecord *html, BOOL *lc, char *txt, char *parstring)
 
63
{
 
64
  char code;
 
65
  char instring[41];
 
66
 
 
67
  if (interactflag) {
 
68
    printf("\n----------------------------------------------------------------\n"
 
69
           "Enter the text attributes for printing of **>%s<** residues:\n", txt);
 
70
    printf("First choose the color/gray-value of the letter **>background<**\n"
 
71
           "Different letters specify different colors,\n"
 
72
           "(B) Black, (W) white (1,2,3,4) 4 different gray values, 4 is darkest\n"
 
73
           "(R) Red, (G) Green, (L) Blue, (Y) Yellow, (M) Magenta, (C) Cyan\n\n"
 
74
           "choose from  BWRGLYMC1234 ( * %c * ) : ", parstring[0]);
 
75
    Fgets(instring, 41, stdin);
 
76
  } else
 
77
    *instring = '\0';
 
78
  if (*instring == '\0')
 
79
    code = parstring[0];
 
80
  else
 
81
    code = instring[0];
 
82
  code = toupper(code);
 
83
  if (strchr( "BWRGLYMC1234", code) == NULL)
 
84
    code = 'W';
 
85
 
 
86
  Code2Color(code, &(html->bg));
 
87
 
 
88
  if (interactflag) {
 
89
    printf("\n\nNow choose the color/gray-value of the letter **>foreground<**\n"
 
90
           "lowercase choices mean lowercase letters in the sequence:\n"
 
91
           "(B,b) black  (W,w) white  (1,2,3,4) 4 different gray values, 4 is darkest\n"
 
92
           "(R,r) red    (G,g) green  (5,6,7,8) same, but lowercase letters\n"
 
93
           "(L,l) blue   (Y,y) yellow (M,m) magenta   (C,c) cyan\n\n"
 
94
           "choose from  BbWwRrGgLlYyMmCc12345678 ( * %c * ) : ", parstring[1]);
 
95
    Fgets(instring, 41, stdin);
 
96
  } else
 
97
    *instring = '\0';
 
98
  if (*instring == '\0')
 
99
    code = parstring[1];
 
100
  else
 
101
    code = instring[0];
 
102
  if (strchr("BbWwRrGgLlYyMmCc12345678", code) == NULL)
 
103
    code = 'B';
 
104
 
 
105
  switch (code) {
 
106
    case '1' :
 
107
    case '2' :
 
108
    case '3' :
 
109
    case '4' : *lc = FALSE;
 
110
               break;
 
111
    case '5' :
 
112
    case '6' :
 
113
    case '7' :
 
114
    case '8' : *lc = TRUE;
 
115
               break;
 
116
    default  : *lc = islower(code);
 
117
               break;
 
118
  }
 
119
 
 
120
  code = toupper(code);
 
121
 
 
122
  Code2Color(code, &(html->fg));
 
123
}
 
124
 
 
125
static void Ask(void)
 
126
{
 
127
  char parstring[6];
 
128
 
 
129
  if (interactflag)
 
130
    printf("----------------------------------------------------------------\n");
 
131
  term_par("HTML");
 
132
  Fgets(parstring, 6, parfile);
 
133
  parstring[2] = '\0';
 
134
  menu_HTML(&html[0], &lc[0], "different", parstring);
 
135
  Fgets(parstring, 6, parfile);
 
136
  parstring[2] = '\0';
 
137
  menu_HTML(&html[1], &lc[1], "identical", parstring);
 
138
  Fgets(parstring, 6, parfile);
 
139
  parstring[2] = '\0';
 
140
  if (simflag)
 
141
    menu_HTML(&html[2], &lc[2], "similar", parstring);
 
142
  else {
 
143
    html[2] = html[0];
 
144
    lc[2] = lc[0];
 
145
  }
 
146
  Fgets(parstring, 6, parfile);
 
147
  parstring[2] = '\0';
 
148
  if (globalflag)
 
149
    menu_HTML(&html[3], &lc[3], "conserved", parstring);
 
150
  else {
 
151
    html[3] = html[1];
 
152
    lc[3] = lc[1];
 
153
  }
 
154
  Gray(&html[4].bg, 1.0);
 
155
  Gray(&html[4].fg, 0.0);
 
156
  lc[4] = FALSE;
 
157
 
 
158
  if (!cloutflag) 
 
159
    do {
 
160
      printf("filename for HTML-output  : ");
 
161
      gets(outname);
 
162
    } while (*outname == '\0');
 
163
}
 
164
 
 
165
#define col255(cv) ((int)(255.0*(cv)))
 
166
 
 
167
static void ColWrite(RGB *rgb) {
 
168
  fprintf(outfile.f, "\"#%02X%02X%02X\"", col255(rgb->r), col255(rgb->g),  col255(rgb->b));
 
169
}
 
170
 
 
171
static int coleq(RGB *c1, RGB *c2) {
 
172
  return    (col255(c1->r) == col255(c2->r))
 
173
         && (col255(c1->g) == col255(c2->g))
 
174
         && (col255(c1->b) == col255(c2->b));
 
175
}
 
176
 
 
177
#define isBG(rgb) coleq((rgb),&html[4].bg)
 
178
#define isTC(rgb) coleq((rgb),&html[4].fg)
 
179
 
 
180
static void StartTR(void) {
 
181
  if (!open_TR) {
 
182
    uwriteln(&outfile, "<tr align=center>");
 
183
    open_TR = TRUE;
 
184
  }
 
185
}
 
186
 
 
187
static void CloseTR(void) {
 
188
  if (open_TR) {
 
189
    uwriteln(&outfile, "</tr>");
 
190
    open_TR = FALSE;
 
191
  }
 
192
}
 
193
 
 
194
static void StartTable(void) {
 
195
  uwriteln(&outfile, "<table border=0 cellspacing=0 CELLPADDING=0>");
 
196
  open_TR = FALSE;
 
197
  open_TABLE = TRUE;
 
198
}
 
199
 
 
200
static void CloseTable(void) {
 
201
  CloseTR();
 
202
  if (open_TABLE) {
 
203
    uwriteln(&outfile, "</table>");
 
204
    open_TABLE = FALSE;
 
205
  }
 
206
}
 
207
 
 
208
static void dv_Init(double *xpos, double *ypos) {
 
209
  dev_minx = 0.0;
 
210
  dev_miny = 0.0;
 
211
  dev_maxx = 1000.0;
 
212
  dev_maxy = 10000.0;
 
213
  dev_xsize = 1.0;
 
214
  dev_ysize = 1.0;
 
215
  *xpos = dev_minx;
 
216
  *ypos = dev_maxy - dev_ysize;
 
217
  lines_per_page = (int)((dev_maxy - dev_miny) / dev_ysize);
 
218
  assert( outopen(&outfile, outname) != NULL);
 
219
 
 
220
  uwriteln(&outfile, "<html>");
 
221
  uwriteln(&outfile, "<head>");
 
222
  uwriteln(&outfile, "<title>BoxShade " BOXSHADE_ver " Output</title>");
 
223
  uwriteln(&outfile, "</head>");
 
224
  fprintf(outfile.f, "<body BGCOLOR=");
 
225
    ColWrite(&html[4].bg);
 
226
    fprintf(outfile.f, " TEXT=");
 
227
    ColWrite(&html[4].fg);
 
228
  uwriteln(&outfile, ">");
 
229
}
 
230
 
 
231
static void Setcolor(int colno) {
 
232
  Col = colno;
 
233
}
 
234
 
 
235
static void StrgChar(int ch, char *s, double *xpos, double *ypos) {
 
236
  char *fc = "";
 
237
  if (!open_TABLE) StartTable();
 
238
  StartTR();
 
239
  fprintf(outfile.f, "<td%s", (s != NULL ? " align=left": "") );
 
240
  if (!isBG(&html[Col].bg)) {
 
241
    fprintf(outfile.f, " BGCOLOR=");
 
242
    ColWrite(&html[Col].bg);
 
243
  } 
 
244
  fprintf(outfile.f, ">");
 
245
  if (!isTC(&html[Col].fg)) {
 
246
    fprintf(outfile.f, "<FONT COLOR="); 
 
247
    ColWrite(&html[Col].fg);
 
248
    fprintf(outfile.f, ">");
 
249
    fc = "</FONT>";
 
250
  }
 
251
  if (s == NULL) {
 
252
    if (ch != ' ') fprintf(outfile.f, "%c%s", ch, fc);
 
253
              else fprintf(outfile.f, "&nbsp;%s", fc);
 
254
    *xpos += dev_xsize;
 
255
  } else {
 
256
    fprintf(outfile.f, "%s%s&nbsp;&nbsp;&nbsp;", s, fc);
 
257
    *xpos += strlen(s)*dev_xsize;
 
258
  }
 
259
  uwriteln(&outfile, "</TD>");
 
260
}
 
261
 
 
262
static void Charout(char c, double *xpos, double *ypos) {
 
263
  StrgChar(c, NULL, xpos, ypos);
 
264
}
 
265
 
 
266
static void Stringout(char *s, double *xpos, double *ypos) {
 
267
  StrgChar('\0', s, xpos, ypos);
 
268
}
 
269
 
 
270
static void Newline(double *xpos, double *ypos) {
 
271
  if (!open_TR) {
 
272
    StartTR();
 
273
    uwriteln(&outfile, "<td>&nbsp;</td>");
 
274
  }
 
275
  CloseTR();
 
276
  *xpos = dev_minx;
 
277
  *ypos -= dev_ysize;
 
278
}
 
279
 
 
280
static void Newpage(double *xpos, double *ypos) {
 
281
  Newline(xpos, ypos);
 
282
  *xpos = dev_minx;
 
283
  *ypos = dev_maxy - dev_ysize;
 
284
}
 
285
 
 
286
static void dv_Exit(void) {
 
287
  CloseTR();
 
288
  CloseTable();
 
289
  uwriteln(&outfile, "</body>");
 
290
  uwriteln(&outfile, "</html>");
 
291
  if (outfile.f != NULL)
 
292
    fclose(outfile.f);
 
293
  outfile.f = NULL;
 
294
}
 
295
 
 
296
GraphicsDevice Html = {
 
297
  "HTML",
 
298
  Ask,
 
299
  dv_Init,
 
300
  Setcolor,
 
301
  Charout,
 
302
  Stringout,
 
303
  Newline,
 
304
  Newpage,
 
305
  dv_Exit
 
306
};