summaryrefslogtreecommitdiff
path: root/Build/source/utils/mtx/mtx-0.60d/uptext.c
blob: eb5b2772e02624f785973fdb4034b55116461329 (plain)
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */
/* From input file "uptext.pas" */


#include "p2c.h"


#define UPTEXT_G
#include "uptext.h"


#ifndef GLOBALS_H
#include "globals.h"
#endif

#ifndef STRINGS_H
#include "strings.h"
#endif

#ifndef MTXLINE_H
#include "mtxline.h"
#endif

#ifndef UTILITY_H
#include "utility.h"
#endif


typedef struct uptext_info {
  short uptext, uptext_adjust, uptext_lcz;
  Char uptext_font[256];
} uptext_info;


Static uptext_info U[maxvoices];


short uptextLineNo(voice)
short voice;
{
  return (U[voice-1].uptext);
}


Void setUptextLineNo(voice, lno)
short voice, lno;
{
  U[voice-1].uptext = lno;
}


Void clearUptext()
{
  voice_index voice, FORLIM;

  FORLIM = nvoices;
  for (voice = 0; voice <= FORLIM - 1; voice++)
    U[voice].uptext = 0;
}


Void initUptext()
{
  voice_index voice, FORLIM;
  uptext_info *WITH;

  FORLIM = nvoices;
  for (voice = 0; voice <= FORLIM - 1; voice++) {
    WITH = &U[voice];
    WITH->uptext_adjust = 0;
    WITH->uptext_lcz = 3;
    *WITH->uptext_font = '\0';
  }
}


Static Void textTranslate(uptext, font)
Char *uptext, *font;
{
  short k;
  Char STR1[256], STR2[256], STR3[256], STR4[256];
  short FORLIM;

  if (*uptext == '\0')
    return;
  do {
    k = pos1('%', uptext);
    if (k > 0) {
      sprintf(STR4, "%s{\\mtxFlat}%s",
	      substr_(STR1, uptext, 1, k - 1),
	      substr_(STR3, uptext, k + 1, strlen(uptext) - k));
      strcpy(uptext, STR4);
    }
  } while (k != 0);
  do {
    k = pos1('#', uptext);
    if (k > 0) {
      sprintf(STR2, "%s{\\mtxSharp}%s",
	      substr_(STR1, uptext, 1, k - 1),
	      substr_(STR4, uptext, k + 1, strlen(uptext) - k));
      strcpy(uptext, STR2);
    }
  } while (k != 0);
  switch (uptext[0]) {

  case '<':
    if (!strcmp(uptext, "<"))
      strcpy(uptext, "\\mtxIcresc");
    else if (!strcmp(uptext, "<."))
      strcpy(uptext, "\\mtxTcresc");
    else {
      predelete(uptext, 1);
      sprintf(uptext, "\\mtxCresc{%s}", strcpy(STR4, uptext));
    }
    break;

  case '>':
    if (!strcmp(uptext, ">"))
      strcpy(uptext, "\\mtxIdecresc");
    else if (!strcmp(uptext, ">."))
      strcpy(uptext, "\\mtxTdecresc");
    else {
      predelete(uptext, 1);
      sprintf(uptext, "\\mtxDecresc{%s}", strcpy(STR1, uptext));
    }
    break;

  default:
    FORLIM = strlen(uptext);
    for (k = 0; k <= FORLIM - 1; k++) {
      if (pos1(uptext[k], "mpfzrs~") == 0)
	return;
    }
    break;
  }
  strcpy(font, "\\mtxPF");
}


#define default_        10
#define under           (-14)


/* Local variables for addUptext: */
struct LOC_addUptext {
  short voice;
  Char w[256];
  short adj;
} ;

Local Void adjustUptext(LINK)
struct LOC_addUptext *LINK;
{
  Char letter;
  boolean force = false;
  uptext_info *WITH1;

  delete1(LINK->w, 1);
  while (*LINK->w != '\0') {
/* p2c: uptext.pas: Note: Eliminated unused assignment statement [338] */
    letter = LINK->w[0];
    delete1(LINK->w, 1);
    WITH1 = &U[LINK->voice-1];
    switch (letter) {

    case '<':
      if (WITH1->uptext_lcz > 1)
	WITH1->uptext_lcz--;
      break;

    case '>':
      if (WITH1->uptext_lcz < 3)
	WITH1->uptext_lcz++;
      break;

    case '^':
      WITH1->uptext_adjust = 0;
      break;

    case 'v':
      WITH1->uptext_adjust = under;
      break;

    case '=':
      force = true;
      break;

    case '+':
    case '-':
      if (*LINK->w != '\0')
	getNum(LINK->w, &LINK->adj);
      else
	LINK->adj = 0;
      if (letter == '-')
	LINK->adj = -LINK->adj;
      if (force)
	WITH1->uptext_adjust = LINK->adj;
      else
	WITH1->uptext_adjust += LINK->adj;
      *LINK->w = '\0';
      break;

    default:
      error3(LINK->voice, "Unknown uptext adjustment");
      break;
    }
  }
  strcpy(LINK->w, "!");
}


Void addUptext(voice_, no_uptext, pretex)
short voice_;
boolean *no_uptext;
Char *pretex;
{
  struct LOC_addUptext V;
  Char font[256];
  static Char lcz[4] = "lcz";
  uptext_info *WITH;
  Char STR1[256], STR2[256], STR3[256];

  V.voice = voice_;
  WITH = &U[V.voice-1];
  if (WITH->uptext == 0)
    *no_uptext = true;
  if (*no_uptext)
    return;
  do {
    GetNextWord(V.w, P[WITH->uptext - 1], blank, dummy);
    sprintf(STR1, "%c", barsym);
    if (!strcmp(V.w, STR1) || *V.w == '\0')
      *no_uptext = true;
    sprintf(STR1, "%c", tilde);
    if (!strcmp(V.w, STR1) || *no_uptext)
      return;
    if (V.w[0] == '!') {
      strcpy(WITH->uptext_font, V.w);
      WITH->uptext_font[0] = '\\';
    }
    if (V.w[0] == '@')
      adjustUptext(&V);
  } while (V.w[0] == '!');   /* ! is a kludge, will get me in trouble later */
  strcpy(font, WITH->uptext_font);
  textTranslate(V.w, font);
  if (*font != '\0')
    sprintf(V.w, "%s{%s}", font, strcpy(STR1, V.w));
  switch (lcz[WITH->uptext_lcz - 1]) {

  case 'l':
    sprintf(V.w, "\\mtxLchar{%s}{%s}",
	    toString(STR1, default_ + WITH->uptext_adjust),
	    strcpy(STR3, V.w));
    break;

  case 'c':
    sprintf(V.w, "\\mtxCchar{%s}{%s}",
	    toString(STR1, default_ + WITH->uptext_adjust),
	    strcpy(STR2, V.w));
    break;

  case 'z':
    sprintf(V.w, "\\mtxZchar{%s}{%s}",
	    toString(STR1, default_ + WITH->uptext_adjust),
	    strcpy(STR3, V.w));
    break;
  }
  strcat(pretex, V.w);
}

#undef default_
#undef under




/* End. */