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

« back to all changes in this revision

Viewing changes to .pc/kickOutGets.patch/dv_ansi.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
 
 
3
#define ESC "\x1b"
 
4
 
 
5
static char *pre_reset;
 
6
static char *pre[5];
 
7
 
 
8
/*------------------------------------*/
 
9
/*   ANSI-Terminal specific section   */
 
10
/*------------------------------------*/
 
11
 
 
12
static void menu_ansi(char **pre, BOOL *lc, char *txt, char *parstring)
 
13
{
 
14
  char code;
 
15
  char instring[41];
 
16
 
 
17
  if (interactflag) {
 
18
    printf("\n-------------------------------------------------------------\n");
 
19
    printf("Enter the text attributes for printing of >%s< residues:\n", txt);
 
20
    printf("Different letters specify renditions,\n"
 
21
           "lowercase choices mean lowercase residues:\n"
 
22
           "(N,n) normal    (B,b) bold   (U,u) underscore  (R,r) reverse\n"
 
23
           "(F,f) flashing  (E,e) reverse/bold (L,l) reverse/flashing\n\n"
 
24
           "choose from NnBbUuRrFfEeLl ( * %c * ) : ", parstring[0]);
 
25
    Fgets(instring, 41, stdin);
 
26
  } else
 
27
    *instring = '\0';
 
28
  if (*instring == '\0')
 
29
    code = parstring[0];
 
30
  else
 
31
    code = instring[0];
 
32
  if (strchr("NBURELF", toupper(code)) == NULL)
 
33
    code = 'N';
 
34
  *lc = islower(code);
 
35
  code = toupper(code);
 
36
  switch (code) {
 
37
    case 'N': *pre = ESC "[0m";     break;
 
38
    case 'B': *pre = ESC "[0;1m";   break;
 
39
    case 'U': *pre = ESC "[0;4m";   break;
 
40
    case 'R': *pre = ESC "[0;7m";   break;
 
41
    case 'E': *pre = ESC "[0;1;7m"; break;
 
42
    case 'L': *pre = ESC "[0;5;7m"; break;
 
43
    case 'F': *pre = ESC "[0;5m";   break;
 
44
  }
 
45
}
 
46
 
 
47
 
 
48
static void ask(char *term)
 
49
{
 
50
  char parstring[6];
 
51
 
 
52
  term_par(term);
 
53
  if (interactflag)
 
54
    printf("-------------------------------------------------------------\n");
 
55
  pre_reset = ESC "[0m";
 
56
  Fgets(parstring, 6, parfile);
 
57
  parstring[2] = '\0';
 
58
  menu_ansi(&pre[0], lc, "different", parstring);
 
59
  Fgets(parstring, 6, parfile);
 
60
  parstring[2] = '\0';
 
61
  menu_ansi(&pre[1], &lc[1], "identical", parstring);
 
62
  Fgets(parstring, 6, parfile);
 
63
  parstring[2] = '\0';
 
64
  if (simflag)
 
65
    menu_ansi(&pre[2], &lc[2], "similar", parstring);
 
66
  else {
 
67
    pre[2] = pre[0];
 
68
    lc[2] = lc[0];
 
69
  }
 
70
  Fgets(parstring, 6, parfile);
 
71
  parstring[2] = '\0';
 
72
  if (globalflag)
 
73
    menu_ansi(&pre[3], &lc[3], "conserved", parstring);
 
74
  else {
 
75
    pre[3] = pre[1];
 
76
    lc[3] = lc[1];
 
77
  }
 
78
  pre[4] = ESC "[0m";
 
79
  lc[4] = FALSE;
 
80
  if (!cloutflag) {
 
81
    printf("filename for %s-output (return for terminal)  : ", term);
 
82
    gets(outname);
 
83
  }
 
84
}
 
85
 
 
86
static void ask_vt(void) {
 
87
  ask("VT");
 
88
}
 
89
 
 
90
static void ask_ansi(void) {
 
91
  ask("ANSI");
 
92
}
 
93
 
 
94
/* ------------------- output functions */
 
95
 
 
96
static void VTinit(double *xpos, double *ypos) {
 
97
  if (*outname == '\0') {
 
98
    outfile.f = stdout;
 
99
    outfile.bin = FALSE;
 
100
  } else
 
101
    assert(outopen(&outfile, outname) != NULL);
 
102
  fputs(ESC "[2J" ESC "[0;0H", outfile.f);
 
103
  fputs(pre_reset, outfile.f);
 
104
  dev_minx = 0.0;
 
105
  dev_miny = 1.0;
 
106
  dev_maxx = 80.0;
 
107
  dev_maxy = 25.0;
 
108
  dev_xsize = 1.0;
 
109
  dev_ysize = 1.0;
 
110
  *xpos = dev_minx;
 
111
  *ypos = dev_miny;
 
112
}
 
113
 
 
114
static void VTsetcolor(int colno) {
 
115
  fputs(pre[colno], outfile.f);
 
116
}
 
117
 
 
118
static void VTcharout(char c, double *xpos, double *ypos) {
 
119
  putc(c, outfile.f);
 
120
  *xpos += dev_xsize;
 
121
}
 
122
 
 
123
static void VTnewline(double *xpos, double *ypos) {
 
124
  uwriteln(&outfile, pre_reset);
 
125
  *xpos = dev_minx;
 
126
  *ypos += dev_ysize;
 
127
}
 
128
 
 
129
static void VTnewpage(double *xpos, double *ypos) {
 
130
  printf("\007"); fflush(stdout);
 
131
  scanf("%*[^\n]");
 
132
  getchar();
 
133
  *xpos = dev_minx;
 
134
  *ypos = dev_miny;
 
135
}
 
136
 
 
137
static void VTexit(void) {
 
138
  uwriteln(&outfile, pre_reset);
 
139
  if (outfile.f != NULL && outfile.f != stdout)
 
140
    fclose(outfile.f);
 
141
  outfile.f = NULL;
 
142
}
 
143
 
 
144
GraphicsDevice Ansi = {
 
145
  "ANSI",
 
146
  ask_ansi,
 
147
  VTinit,
 
148
  VTsetcolor,
 
149
  VTcharout,
 
150
  GenericStringOut,
 
151
  VTnewline,
 
152
  VTnewpage,
 
153
  VTexit
 
154
};
 
155
 
 
156
GraphicsDevice Vt = {
 
157
  "VT100",
 
158
  ask_vt,
 
159
  VTinit,
 
160
  VTsetcolor,
 
161
  VTcharout,
 
162
  GenericStringOut,
 
163
  VTnewline,
 
164
  VTnewpage,
 
165
  VTexit
 
166
};
 
167