w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

process_command.c
Go to the documentation of this file.
1 
2 # include "process_score.h"
3 
4 # define APPOGG_SPACING SP(64)+SP(256) /* not a legitimate spacing */
5 # define notespp "\\vnotes2.95\\elemskip"
6 # define Notespp "\\vnotes3.95\\elemskip"
7 # define NOtespp "\\vnotes4.95\\elemskip"
8 # define NOTespp "\\vnotes6.95\\elemskip"
9 # define NOTEsp "\\vnotes9.52\\elemskip"
10 # define APPOGG_NOTES "\\vnotes1.45\\elemskip"
11 
12 char terminator[MAX_STAFFS]; /* one of '&' "|', '$' */
13 
14 char *notes[MAX_STAFFS]; /* note segment for ith staff */
16 
17 int spacings[MAX_STAFFS]; /* spacing for ith staff */
18 
19 int vspacing[MAX_STAFFS]; /* virtual-note (skip) spacing */
20 bool vspacing_active[MAX_STAFFS]; /* virtual-note spacing active? */
21  /* used to preclude unnecessary pre-accidental skips */
22 
23 bool nonvirtual_notes; /* used to preclude output of *only* virtual notes */
24 
25 int cspacing[MAX_STAFFS]; /* nominal collective-note spacing */
27  /* prefixes for collective note sequences */
29 
30 char deferred_bar[SHORT_LEN]; /* deferred \bar (or \endpiece etc.) */
31 
32 int beaming[MAX_STAFFS]; /* spacing for beamed notes */
34 int semiauto_beam_notes[MAX_STAFFS]; /* semi-automatic beam notes */
35 
36 int spacing_staff; /* staff that determines current spacing */
37 
38 /* save-restore state for a staff; used in process_xtuplet */
39 int beamingi;
40 char *currenti;
45 
46 int xtuplet[MAX_STAFFS]; /* x for xtuplet in staff i */
47 
49 
51  /* accumulate commands to be output */
53 
55  /* = 1, 2, 3, or 4 for (non-standard) commands \QQsk \HQsk \TQsk \Qsk */
56  /* = 5 for five commas and double-flat accidental spacing */
57  /* = 6 for six commas */
58 
59 
60 char s[SHORT_LEN]; /* string for ps() */
61 char *s_n;
62 char *ps(int spacing);
63 void note_segment (char *s);
64 void status (int i);
65 void status_spacing (void);
66 void status_all (void);
67 void status_collective (int i);
68 void status_beam (int i);
69 
70 
71 int spacing_note (int i);
72 void output_notes (int i);
73 void initialize_notes ();
74 void process_xtuplet (void);
75 
76 PRIVATE
77 void analyze_notes (char **ln)
78 /* divide material from *ln to \en into notes[i] segments
79  and initialize terminator[i] etc. */
80 {
81  int i; char *s; char *t;
82  int instr=1;
83  int newlines = 0;
84  s = *ln+1; /* skip "/" */
85  while (isalpha(*s)) {s++;} /* skip rest of the initial command */
86  while (true)
87  { /* look for \en */
88  t = strstr(s, "\\en");
89  if (t != NULL) break;
90  /* replace EOL by a blank and append another line of input */
91  { char new_line[LINE_LEN];
92  char *nl;
93  if (fgets (new_line, LINE_LEN, infile) == NULL)
94  error ("Unexpected EOF.");
95  if (strlen (new_line) == LINE_LEN-1)
96  error ("Line too long.");
97  nl = new_line;
98  while (*nl == ' ') nl++; /* avoid spaces */
99  t = strpbrk (s, "\n%");
100  if (t == NULL) error ("Missing EOL.");
101  if (*t == '\n')
102  { *t = ' '; t++;}
103  *t = '\0';
104  if (append (line, &t, nl, LINE_LEN) >= LINE_LEN)
105  error ("Line too long.");
106  newlines++;
107  }
108  }
109  /* t -> "\en" */
110  if ( prefix("\\enotes", t) ) *ln = t+7;
111  else *ln = t+3;
112  *t = '$'; /* replace '\' by '$' (a distinctive terminating character) */
113  for (i=1; i <= nstaffs; i++)
114  { char *tt;
115  while (*s == ' ') s++; /* skip spaces */
116  if (active[i])
117  { notes[i] = s;
118  current[i] = s;
119  }
120  tt = strpbrk (s, "|&$");
121  if (tt == NULL) error ("can't parse note-spacing command.");
122  s = tt;
123  terminator[i] = *s;
124  staff_instr[i] = instr;
125  if (terminator[i] == '&') instr++;
126  if (*s != '$') s++;
127  }
128  lineno = lineno + newlines;
129 
130  /* initialize: */
133  appoggiatura = false;
134  global_skip = 0;
135  for (i=1; i <= nstaffs; i++)
136  {
137  if (active[i])
138  { n_outstrings[i] = outstrings[i];
139  *n_outstrings[i] = '\0';
140  vspacing[i] = 0;
141  vspacing_active[i] = false;
142  collective[i][0] = '\0';
143  cspacing[i] = MAX_SPACING;
144  first_collective[i] = false;
145  xtuplet[i] = 1;
146  }
147  }
148  if (debug)
149  { fprintf (logfile, "\nAfter analyze_notes:\n");
150  status_all ();
151  }
152 }
153 
154 PRIVATE
155 void checkc (char *s, char c)
156 { if (*s != c)
157  {
158  printf ("Error on line %d: Expected %c but found %d:\n%s\n", lineno, c, *s, line);
159  exit (EXIT_FAILURE);
160  }
161 }
162 
163 PRIVATE
164 void checkn (char *s)
165 { if (strpbrk (s, "0123456789") != s)
166  {
167  printf ("Error on line %d: Expected digit but found %c:\n%s\n", lineno, *s, line);
168  exit (EXIT_FAILURE);
169  }
170 }
171 
172 PRIVATE
173 void filter_output (int i)
174 { /* discard \sk \bsk \Qsk \TQsk \HQsk \QQsk \Cp and \Cpause */
175  char *s = notes[i];
176  while (s < current[i])
177  { char *t;
178  t = strpbrk (s+1, "\\&|$");
179  if (t == NULL || t > current[i]) t = current[i];
180  if (!prefix ("\\sk", s)
181  && !prefix ("\\bsk", s)
182  && !prefix ("\\Cpause", s)
183  && !prefix ("\\Cp", s)
184  && !prefix ("\\Qsk", s)
185  && !prefix ("\\HQsk", s)
186  && !prefix ("\\TQsk", s)
187  && !prefix ("\\QQsk", s)
188  && !prefix ("\\Triolet", s)
189  && !prefix ("\\Xtuplet", s) )
190  {
191  while (s < t)
192  { while (*s == ',') s++; /* global skips */
193  *n_outstrings[i] = *s;
194  n_outstrings[i]++; s++;
195  }
196  *(n_outstrings[i]) = '\0';
197  }
198  s = t;
199  }
200  notes[i] = s;
201 }
202 
203 void output_notes (int i)
204 /* append from notes[i] up to current[i] to outstrings[i] */
205 { if (debug)
206  { fprintf (logfile, "\nEntering output_notes:\n");
207  status (i);
208  }
209  if (debug)
210  {
211  fprintf (logfile, "\nAppending %s for global_skip=%i\n", global_skip_str[global_skip], global_skip);
212  }
214  if (vspacing[i] > 0)
215  {
216  if (nonvirtual_notes)
217  append (outstrings[i], &(n_outstrings[i]), "\\sk", LINE_LEN);
218  vspacing[i] = vspacing[i] - spacing;
219  }
220  else if (collective[i][0])
221  {
222  if (debug)
223  { fprintf (logfile, "\nBefore outputting collective note:\n");
224  status (i);
226  }
227  if (!first_collective[i])
229  first_collective[i] = false;
230  filter_output (i);
231  append (outstrings[i], &(n_outstrings[i]), "}", LINE_LEN);
232  if (*notes[i] == '}')
233  { collective[i][0] = '\0';
234  cspacing[i] = 0;
235  notes[i]++;
236  }
237  if (*notes[i] == '}') /* close of {\tinynotesize..{}}? */
238  { append (outstrings[i], &(n_outstrings[i]), "}", LINE_LEN);
239  notes[i]++;
240  }
241  if (debug)
242  { fprintf (logfile, "\nAfter outputting collective note:\n");
243  status (i);
245  }
246  }
247  else
248  filter_output (i);
249  if (debug)
250  { fprintf (logfile, "\nAfter output_notes:\n");
251  status (i);
252  status_spacing ();
253  }
254 }
255 
256 
257 int spacing_note (int i);
258 /* Search from current[i] for the next spacing note in the ith staff.
259  * Returns the spacing value and updates current[i].
260  */
261 
262 PRIVATE void
264 { /* outputs a multi-bar rest and the deferred_bar command */
265  int i;
266  fprintf ( outfile, "\\NOTes\\sk\\en%%\n" );
267  fprintf (outfile, "\\def\\atnextbar{\\znotes");
268  if (restbars == 1)
269  fprintf ( outfile, "\\centerpause" );
270  else
271  fprintf ( outfile, "\\centerHpause{%d}", restbars );
272  fprintf (outfile, "\\en}%%\n");
273  if (Changeclefs) /* \Changeclefs has to be output after \def\atnextbar... */
274  {
275  fprintf ( outfile, "\\Changeclefs%%\n");
276  Changeclefs = false;
277  }
278  if (restbars > 1)
279  fprintf ( outfile, "\\advance\\barno%d%%\n", restbars-1 );
280  restbars = 0;
281  for (i=1; i <= nstaffs; i++) bar_rest[i] = false;
282  fprintf ( outfile, "%s%%\n", deferred_bar);
283  deferred_bar[0] = '\0';
284 }
285 
287 { int i;
288  if (debug)
289  { fprintf (logfile, "\nEntering initialize_notes\n");
290  status_all ();
291  }
292  if ( nastaffs == 1 && spacing != MAX_SPACING && restbars > 0)
293  output_rests ();
294 
295  fprintf (outfile, "\\scale");
296  if (debug)
297  fprintf (logfile, "spacing_staff = %i, staff_instr[spacing_staff] = %i, instrument_size[staff_instr[spacing_staff]] = %s\n",
301 
302  if (spacing == MAX_SPACING)
303  fprintf (outfile, "\\znotes");
304  else if (spacing == SP(1)+SP(2) || spacing == SP(1)+SP(2)+SP(4))
305  fprintf (outfile, NOTEsp);
306  else if (spacing == SP(1))
307  fprintf (outfile, "\\NOTEs");
308  else if (spacing == SP(2)+SP(4)+SP(8))
309  fprintf (outfile, "%s", NOTespp);
310  else if (spacing == SP(2)+SP(4) )
311  fprintf (outfile, "\\NOTesp");
312  else if (spacing == SP(2))
313  fprintf (outfile, "\\NOTes");
314  else if (spacing == SP(4)+SP(8) )
315  fprintf (outfile, "\\NOtesp");
316  else if (spacing == SP(4)+SP(8)+SP(16) )
317  fprintf (outfile, "%s", NOtespp);
318  else if (spacing == SP(4))
319  fprintf (outfile, "\\NOtes");
320  else if (spacing == SP(8)+SP(16) )
321  fprintf (outfile, "\\Notesp");
322  else if (spacing == SP(8)+SP(16)+SP(32))
323  fprintf (outfile, "%s", Notespp);
324  else if (spacing == SP(8))
325  fprintf (outfile, "\\Notes");
326  else if (spacing == SP(16)+SP(32)+SP(64))
328  else if (spacing == SP(16)+SP(32) )
329  fprintf (outfile, "\\notesp");
330  else if (spacing == SP(16) || spacing == SP(32)+SP(64) || spacing == SP(32)+SP(64)+SP(128))
331  fprintf (outfile, "\\notes");
332  else if (spacing == SP(32) || spacing == SP(64)+SP(128) || spacing == SP(64)+SP(128)+SP(256))
333  fprintf (outfile, "\\nnotes");
334  else if (spacing == SP(64) )
335  fprintf (outfile, "\\nnnotes");
336  else if (spacing == APPOGG_SPACING)
337  fprintf (outfile, "%s", APPOGG_NOTES);
338  else
339  { printf ("Error on line %d: spacing %s not recognized.\n", lineno, ps(spacing));
340  exit (EXIT_FAILURE);
341  }
342  if (debug)
343  { fprintf (logfile, "\noutputting \\Notes command for spacing=%s.\n", ps(spacing));
344  status_all();
345  }
346  for (i=1; i <= nstaffs; i++)
347  { if (active[i])
348  { n_outstrings[i] = outstrings[i];
349  *n_outstrings[i] = '\0';
350  }
351  }
352 }
353 
354 PRIVATE
356 { int i;
357  char *s, *t;
358  if (debug)
359  { fprintf (logfile, "\nEntering terminate_notes:\n");
360  status_all ();
361  }
362  t = TransformNotes2;
363  while (true)
364  { s = strchr (t, '#');
365  if (s == NULL)
366  break;
367  while (t < s) /* output any initial \transpose etc. */
368  { putc (*t, outfile); t++; }
369  t++; /* skip # */
370  i = atoi (t) -1; t++;
371  if (spacing == MAX_SPACING)
372  { /* output any commands left in notes[i] */
373  filter_output (i);
374  }
375  fprintf (outfile, "%s", outstrings[i]);
376  if (debug) fprintf (logfile, "\noutputting %s from outstrings[%d].\n", outstrings[i], i);
377  outstrings[i][0] = '\0';
379  if (spacing < MAX_SPACING && spacing > 2 * old_spacing)
380  { /* add extra space *before* much longer notes */
381  fprintf (outfile, "\\hqsk");
382  if (debug) fprintf (logfile, "\nExtra half-notehead space before longer notes.\n");
383  }
384  if (*t != '\0')
385  { putc (*t, outfile); t++; } /* terminator */
386  }
387  if (spacing == MAX_SPACING && old_spacing < SP(8) )
388  { /* add extra space before \en */
389  fprintf (outfile, "\\hqsk");
390  if (debug) fprintf (logfile, "\nExtra half-notehead space before \\en.\n");
391  }
392  fprintf (outfile, "\\en");
393  if (debug)
394  { fprintf (logfile, "\noutputting \\en\n");
395  fprintf (logfile, "\nAfter terminate_notes:\n");
396  status_all ();
397  }
398 }
399 
400 PRIVATE
401 void process_appogg (void)
402 { int i;
403  if (debug)
404  { fprintf (logfile, "\nEntering process_appogg:\n");
405  status_all();
406  }
407 
408  if (old_spacing < MAX_SPACING)
409  { char *s, *t;
410  if (debug) fprintf (logfile, "Terminate current notes command:\n");
411  t = TransformNotes2;
412  while (true)
413  { s = strchr (t, '#');
414  if (s == NULL) break;
415  while (t < s) /* output any initial \transpose etc. */
416  { putc (*t, outfile); t++; }
417  t++; /* skip # */
418  i = atoi (t) - 1; t++;
419  fprintf (outfile, "%s", outstrings[i]);
420  if (debug) fprintf (logfile, "\noutputting %s from outstrings[%d].\n", outstrings[i], i);
421  outstrings[i][0] = '\0';
423  if (*t != '\0')
424  { putc (*t, outfile); t++; } /* terminator */
425  }
426  fprintf (outfile, "\\en");
427  if (debug)
428  { fprintf (logfile, "\\en");
429  fprintf (logfile, "\nAfter termination of notes command:\n");
430  status_all ();
431  }
432  }
433 
434  if (debug) fprintf (logfile, "\nCreate a new notes command for the appoggiatura:\n");
436  initialize_notes ();
438  for (i=1; i <= nstaffs; i++)
439  if (active[i])
440  {
441  if (spacings[i] == APPOGG_SPACING )
442  {
443  output_notes (i);
444  spacings[i] = spacing_note (i);
445  }
446  if (spacings[i] < spacing)
447  spacing = spacings[i];
448  }
449  appoggiatura = false;
450  nonvirtual_notes = true;
452  if (debug)
453  { fprintf (logfile, "\nAfter process_appogg:\n");
454  status_all ();
455  }
456  return;
457 }
458 
459 
460 PRIVATE
462 { int i;
463  bool xtuplet_flag;
464  while (true)
465  { old_spacing = spacing;
467  spacing_staff = 0;
468  global_skip = 0;
469  nonvirtual_notes = false;
470  if (debug)
471  { fprintf (logfile, "\nIn generate_notes:\n");
472  status_all ();
473  }
474  for (i=1; i <= nstaffs; i++)
475  if (active[i])
476  {
477  spacings[i] = spacing_note (i);
478  if (spacings[i] < spacing)
479  {
480  spacing = spacings[i];
481  spacing_staff = i;
482  }
483  else if (spacings[i] == spacing &&
484  (vspacing[spacing_staff] > 0 ||
485  /* for staffs with equal spacing, use the one with larger instrument size */
487  spacing_staff = i;
488  }
489  if (appoggiatura)
490  {
491  process_appogg ();
492  }
493  xtuplet_flag = false;
494  for (i=1; i <= nstaffs; i++)
495  if (xtuplet[i] > 1) xtuplet_flag = true;
496  if (xtuplet_flag)
497  {
498  process_xtuplet ();
499  continue;
500  }
501 
503  {
504  if (old_spacing < MAX_SPACING)
505  terminate_notes ();
506  if (spacing == MAX_SPACING || nonvirtual_notes == false)
507  {
508  if (debug)
509  { fprintf (logfile, "\nAfter generate_notes:\n");
510  status_all ();
511  }
512  return;
513  }
514  if (old_spacing < MAX_SPACING) putc ('\n', outfile);
515 
516  initialize_notes ();
517  }
518 
519  for (i=1; i <= nstaffs; i++) /* append current notes to outstrings */
520  if (active[i])
521  output_notes (i);
522  for (i=1; i <= nstaffs; i++)
523  {
524  /* virtual notes needed? */
525  if (active[i] && spacings[i] != MAX_SPACING && spacings[i] != spacing && vspacing[i] == 0 )
526  {
527  vspacing[i] = spacings[i];
528  vspacing_active[i] = true;
529  vspacing[i] = vspacing[i] - spacing;
530  if (debug)
531  { fprintf (logfile, "\nAfter vspacing initialization:\n");
532  status (i);
533  }
534  }
535  }
536  }
537 }
538 
539 
540 void process_command (char **ln)
541 { char *s, *t;
542 
543  if (debug)
544  { fprintf (logfile, "\nProcessing command:%s\n", *ln);
545  fflush (logfile);
546  }
547  if ( prefix("\\instrumentnumber", *ln) )
548  {
549  s = strpbrk (*ln, "123456789");
550  if ( s == NULL ) error ("\\instrumentnumber command unreadable.");
551  ninstr = atoi (s);
552  while (*ln <= s) { putc (**ln, outfile); (*ln)++;}
553  }
554 
555  if ( prefix("\\def\\nbinstrument", *ln) )
556  {
557  s = strpbrk (*ln, "123456789");
558  if ( s == NULL ) error ("\\def\\nbinstrument command unreadable.");
559  ninstr = atoi (s);
560  while (*ln <= s) { putc (**ln, outfile); (*ln)++;}
561  }
562 
563  else if ( prefix("\\setstaffs", *ln) )
564  { /* for now, just record in staffs[i] */
565  int n, p;
566  s = strpbrk (*ln, "123456789");
567  if ( s == NULL ) error ("\\setstaffs command unreadable.");
568  n = (int)(*s) - (int)('0'); /* instrument number */
569  s = strpbrk (s+1, "123456789");
570  if ( s == NULL ) error ("\\setstaffs command unreadable.");
571  p = (int)(*s) - (int)('0'); /* number of staffs */
572  staffs[n] = p;
573  while (*ln <= s) { putc (**ln, outfile); (*ln)++;}
574  }
575 
576  else if ( prefix("\\setsize", *ln) )
577  { int n; char *p;
578  s = strpbrk (*ln, "123456789");
579  if ( s == NULL ) error ("\\setsize command unreadable.");
580  n = (int)(*s) - (int)('0'); /* instrument number */
581  s++;
582  if (*s == '}') s++;
583  if (*s == '{') s++;
584  t = strpbrk (s, " }\n");
585  if ( t == NULL ) error ("\\setsize command unreadable.");
586  instrument_size[n][0] = '\0';
587  p = instrument_size[n];
588  while (s < t)
589  { *p = *s;
590  p++; s++;
591  }
592  *p = '\0';
593  if (debug)
594  {
595  fprintf (logfile, "instrument_size[%d] = %s\n", n, instrument_size[n]);
596  fflush (logfile);
597  }
598  /* determine numerical instrument size to allow numerical comparison */
599  if (prefix ("\\normalvalue", instrument_size[n]))
600  instr_numsize[n] = 1.0;
601  else if (prefix ("\\smallvalue", instrument_size[n]))
602  instr_numsize[n] = 0.8;
603  else if (prefix ("\\tinyvalue", instrument_size[n]))
604  instr_numsize[n] = 0.64;
605  else if (prefix ("\\largevalue", instrument_size[n]))
606  instr_numsize[n] = 1.2;
607  else if (prefix ("\\Largevalue", instrument_size[n]))
608  instr_numsize[n] = 1.44;
609  else
610  error ("\\setsize argument unreadable.");
611  if (debug)
612  {
613  fprintf (logfile, "instr_numsize[%d] = %f\n", n, instr_numsize[n]);
614  fflush (logfile);
615  }
616  while (*ln <= s) { putc (**ln, outfile); (*ln)++;}
617  }
618 
619  else if ( prefix("\\startpiece", *ln) )
620  {
621  if (!TransformNotesDefined) /* create default TransformNotes2: */
622  { int i, j;
623  t = TransformNotes2;
624  nstaffs = 1;
625  sprintf (t, "#%1i", nstaffs+1); t = t+2;
626  for (j=2; j <= staffs[1]; j++)
627  { nstaffs++; sprintf (t, "|#%1i", nstaffs+1); t = t+3;
628  active[nstaffs] = true;
629  }
630  for (i=2; i <= ninstr; i++)
631  { nstaffs++; sprintf (t, "&#%1i", nstaffs+1); t = t+3;
632  for (j=2; j <= staffs[i]; j++)
633  { nstaffs++; sprintf (t, "|#%1i", nstaffs+1); t = t+3;
634  active[nstaffs] = true;
635  }
636  }
637  nastaffs = nstaffs;
638  if (debug)
639  fprintf (logfile, "default TransformNotes2=%s\n", TransformNotes2);
640  }
641  if (nstaffs == 1) fprintf (outfile, "\\nostartrule\n");
642  if (debug)
643  {
644  int j;
645  fprintf (logfile, "ninstr=%d nstaffs=%d nastaffs=%d\n", ninstr, nstaffs, nastaffs);
646  for (j=1; j <= nstaffs; j++)
647  fprintf (logfile, "active[%d]=%d\n", j, active[j]);
648  }
649  fprintf (outfile, "\\startpiece");
650  t = strpbrk (*ln+1, "\\%\n");
651  *ln = t;
652  }
653 
654  else if ( prefix("\\startextract", *ln) )
655  {
656  if (!TransformNotesDefined) /* create default TransformNotes2: */
657  { int i, j;
658  t = TransformNotes2;
659  nstaffs = 1;
660  sprintf (t, "#%1i", nstaffs+1); t = t+2;
661  for (j=2; j <= staffs[1]; j++)
662  { nstaffs++; sprintf (t, "|#%1i", nstaffs+1); t = t+3;
663  active[nstaffs] = true;
664  }
665  for (i=2; i <= ninstr; i++)
666  { nstaffs++; sprintf (t, "&#%1i", nstaffs+1); t = t+3;
667  for (j=2; j <= staffs[i]; j++)
668  { nstaffs++; sprintf (t, "|#%1i", nstaffs+1); t = t+3;
669  active[nstaffs] = true;
670  }
671  }
672  nastaffs = nstaffs;
673  if (debug)
674  fprintf (logfile, "default TransformNotes2=%s\n", TransformNotes2);
675  }
676  if (nstaffs == 1) fprintf (outfile, "\\nostartrule\n");
677  fprintf (outfile, "\\startextract");
678  t = strpbrk (*ln+1, "\\%\n");
679  *ln = t;
680  }
681 
682  else if ( prefix("\\TransformNotes", *ln) )
683  { /* determine ninstr, nstaffs, nastaffs, staffs[i], and active[i] */
684  int i;
685  s = *ln + 16; /* first parameter */
686  ninstr = 0;
687  nstaffs = 0;
688  while (true)
689  { ninstr++; nstaffs++;
690  staffs[ninstr] = 1;
691  checkc (s, '#'); s++;
692  checkn (s); s++;
693  while (*s == '|')
694  { staffs[ninstr]++; nstaffs++;
695  s++;
696  checkc (s, '#'); s++;
697  checkn (s); s++;
698  }
699  if (*s != '&') break;
700  s++;
701  }
702  checkc (s, '}'); s++;
703  s = strchr (s, '{');
704  if (s == NULL) error ("Can't parse \\TransformNotes");
705  s++;
706  /* determine TransformNotes2: */
707  t = TransformNotes2;
708  do { *t = *s; t++; s++; }
709  while (*s != '}');
710  *t = '\0'; /* terminate TransformNotes2 */
711  TransformNotesDefined = true;
712  if (debug)
713  fprintf (logfile, "defined TransformNotes2=%s\n", TransformNotes2);
714 
715  /* determine active staffs: */
716  for (i=1; i <= nstaffs; i++) active[i] = false;
717  nastaffs = 0;
718  t = strpbrk (TransformNotes2, "#}"); /* may have \transpose etc. before # */
719  if (t == NULL) error ("Can't parse second argument of \\TransformNotes");
720  while (*t == '#')
721  { if (sscanf (t, "#%d", &i) != 1)
722  error ("sscanf for argument number fails");
723  active[i-1] = true; /* parameters start at 2 */
724  nastaffs++;
725  t = strpbrk (t+1, "#}");
726  if (t == NULL) break;
727  }
728  if (debug)
729  {
730  int j;
731  fprintf (logfile, "ninstr=%d nstaffs=%d nastaffs=%d\n", ninstr, nstaffs, nastaffs);
732  for (j=1; j <= nstaffs; j++)
733  fprintf (logfile, "active[%d]=%d\n", j, active[j]);
734  }
735 
736  /* output \TransformNotes... as a comment: */
737  putc ('%', outfile);
738  while (*ln <= s)
739  { putc (**ln, outfile); (*ln)++; }
740  }
741 
742  else if (prefix("\\def\\atnextbar{\\znotes", *ln))
743  { /* whole-bar or multi-bar rest? */
744  int i;
745  bool centerpause = false;
746  *ln = *ln + 15; /* skip "\def\atnextbar{" */
747  analyze_notes(ln);
748  for (i=1; i <= nstaffs; i++)
749  {
750  if (active[i])
751  { char *t;
752  char *s;
753  t = strpbrk (notes[i], "&|$");
754  if (t == NULL) t = notes[i] + strlen (notes[i]);
755  s = strstr (notes[i], "\\centerpause");
756  if (s != NULL && s < t && nastaffs == 1)
757  {
758  bar_rest[i] = true;
759  centerpause = true;
760  }
761  break;
762  }
763  }
764  if (!centerpause) /* generate transformed \znotes ... \en */
765  {
766  fprintf ( outfile, "\\def\\atnextbar{\\znotes");
767  t = TransformNotes2;
768  while (true)
769  {
770  /* output TransformNotes2 prefix (\transpose etc.): */
771  s = strchr (t, '#');
772  if (s == NULL) break;
773  while (t < s)
774  { putc (*t, outfile); t++; }
775  t++; /* skip '#' */
776  /* output notes: */
777  i = atoi (t) - 1; t++;
778  s = notes[i];
779  while (*s != '&' && *s != '|' && *s != '$')
780  { putc (*s, outfile); s++; }
781  if (*t != '\0')
782  { putc (*t, outfile); t++; } /* output terminator */
783  }
784  fprintf (outfile, "\\en}%%\n");
785  }
786  t = strchr (*ln, '}');
787  if (t == NULL) error ("Can't find }.");
788  *ln = t+1;
789  t = strpbrk (*ln, "%\\");
790  if (t == NULL ) t = *ln + strlen(*ln);
791  *ln = t;
792  }
793 
794  else if ( prefix("\\def", *ln) ) /* copy to output */
795  { t = *ln + strlen(*ln);
796  while (*ln < t)
797  { fputc (**ln, outfile);
798  (*ln)++;
799  }
800  }
801 
802  else if ( prefix("\\anotes", *ln) )
803  { if (debug)
804  { fprintf (logfile, "\nProcessing %s", *ln);
805  fprintf (logfile, "lineno=%d\n", lineno);
806  fflush (logfile);
807  }
808  analyze_notes (ln);
809  if (debug)
810  { fprintf (logfile, "\nBefore generate_notes *ln=%s\n", *ln);
811  fflush (logfile);
812  }
813  generate_notes ();
814  if (debug)
815  { fprintf (logfile, "\nAfter generate_notes *ln=%s\n", *ln);
816  fflush (logfile);
817  }
818  t = strpbrk (*ln, "%\\\n");
819  if (t == NULL) t = *ln + strlen (*ln);
820  if (*t == '\n') putc ('%', outfile);
821  *ln = t;
822  }
823  else if ( prefix("\\nnnotes", *ln) ||
824  prefix("\\nnnotes", *ln) ||
825  prefix("\\nnotes", *ln) ||
826  prefix("\\notes", *ln) ||
827  prefix("\\Notes", *ln) ||
828  prefix("\\NOtes", *ln) ||
829  prefix("\\NOTes", *ln) ||
830  prefix("\\NOTEs", *ln) ||
831  prefix("\\znotes", *ln) )
832  {
833  char *s, *t;
834  int nstaff;
835  if (debug)
836  { fprintf (logfile, "\nProcessing %s", *ln);
837  fprintf (logfile, "lineno=%d\n", lineno);
838  fflush (logfile);
839  }
840  if (nastaffs == 1 && restbars > 0)
841  output_rests ();
842  t = *ln+1;
843  while ( isalpha (*t) ) t++;
844  s = *ln;
845  while (s < t) { putc (*s, outfile); s++; }
846 
847  analyze_notes (ln);
848 
849  t = TransformNotes2;
850  while (true)
851  {
852  /* output TransformNotes2 prefix (\transpose etc.): */
853  s = strchr (t, '#');
854  if (s == NULL) break;
855  while (t < s)
856  { putc (*t, outfile); t++; }
857 
858  t++; /* skip '#' */
859 
860  /* output notes: */
861  nstaff = atoi (t) - 1; t++;
862  s = notes[nstaff];
863  while (*s != '&' && *s != '|' && *s != '$')
864  { putc (*s, outfile); s++; }
865  if (*t != '\0')
866  { putc (*t, outfile); t++; } /* output terminator */
867  }
868  fprintf (outfile, "\\en\n");
869 
870  t = strpbrk (*ln, "%\\\n");
871  if (t == NULL) t = *ln + strlen (*ln);
872  if (*t == '\n') putc ('%', outfile);
873  *ln = t;
874  }
875 
876  else if (prefix("\\vnotes", *ln) )
877  {
878  char *s, *t;
879  int nstaff;
880  if (debug)
881  { fprintf (logfile, "\nProcessing %s", *ln);
882  fprintf (logfile, "lineno=%d\n", lineno);
883  fflush (logfile);
884  }
885  s = *ln;
886  t = strchr (*ln+1, '\\'); /* find \elemskip */
887  *ln = t;
888  t = t + 9;
889  while (s < t) { putc (*s, outfile); s++; }
890 
891 
892  analyze_notes (ln);
893 
894  t = TransformNotes2;
895  while (true)
896  {
897  /* output TransformNotes2 prefix (\transpose etc.): */
898  s = strchr (t, '#');
899  if (s == NULL) break;
900  while (t < s)
901  { putc (*t, outfile); t++; }
902 
903  t++; /* skip '#' */
904 
905  /* output notes: */
906  nstaff = atoi (t) - 1; t++;
907  s = notes[nstaff];
908  while (*s != '&' && *s != '|' && *s != '$')
909  { putc (*s, outfile); s++; }
910  if (*t != '\0')
911  { putc (*t, outfile); t++; } /* output terminator */
912  }
913  fprintf (outfile, "\\en\n");
914 
915  t = strpbrk (*ln, "%\\\n");
916  if (t == NULL) t = *ln + strlen (*ln);
917  if (*t == '\n') putc ('%', outfile);
918  *ln = t;
919  }
920 
921  else if ( prefix ("\\bar", *ln) && !prefix ("\\barno", *ln))
922  { int i;
923  char *s, *t;
924  bool atnextbar = false;
925  for (i=1; i <= nstaffs; i++)
926  if (active[i] && bar_rest[i])
927  { atnextbar = true; break; }
928  if (nastaffs == 1 && atnextbar)
929  { restbars++;
930  sprintf (deferred_bar, "\\bar");
931  if (debug) fprintf (logfile, "\nrestbars increased to %d\n", restbars);
932  for (i=1; i<= nstaffs; i++)
933  bar_rest[i] = false;
934  *ln = *ln+4;
935  t = strpbrk (*ln, "\\\n");
936  if (t == NULL) t = *ln + strlen (*ln);
937  if (*t == '\n') putc ('%', outfile);
938  *ln = t;
939  }
940  else
941  { if (atnextbar)
942  { fprintf (outfile, "\\def\\atnextbar{\\znotes");
943  t = TransformNotes2;
944  while (true)
945  {
946  s = strchr (t, '#');
947  if (s == NULL)
948  break;
949  while (t < s) /* output any initial \transpose etc. */
950  { putc (*t, outfile); t++; }
951  t++; /* skip # */
952  i = atoi (t) -1; t++;
953  if (active[i])
954  {
955  if (bar_rest[i])
956  fprintf (outfile, "\\centerpause");
957  bar_rest[i] = false;
958  }
959  if (*t != '\0')
960  { putc (*t, outfile); t++; } /* terminator */
961  }
962  fprintf (outfile, "\\en}%%\n");
963  }
964  if (Changeclefs) /* \Changeclefs has to be output after \def\atnextbar... */
965  {
966  fprintf ( outfile, "\\Changeclefs%%\n");
967  Changeclefs = false;
968  }
969  t = strpbrk (*ln+1, "%\\\n");
970  while (*ln < t)
971  { fputc (**ln, outfile);
972  (*ln)++;
973  }
974  if (*t == '\n') putc ('%', outfile);
975  *ln = t;
976  }
977  if (debug)
978  { fprintf (logfile, "\nAfter \\bar processing, *ln=%s\n", *ln);
979  fflush (logfile);
980  }
981  }
982 
983  else if ( prefix ("\\endpiece", *ln)
984  || prefix ("\\Endpiece", *ln)
985  || prefix ("\\endextract", *ln)
986  || prefix ("\\stoppiece", *ln)
987  || prefix ("\\raggedstoppiece", *ln)
988  || prefix ("\\rightrepeat", *ln)
989  || prefix ("\\leftrepeat", *ln)
990  || prefix ("\\alaligne", *ln)
991  || prefix ("\\alapage", *ln)
992  || prefix ("\\changecontext", *ln)
993  || prefix ("\\Changecontext", *ln)
994  || prefix ("\\zchangecontext", *ln)
995  || prefix ("\\zalaligne", *ln)
996  || prefix ("\\zalapage", *ln) )
997  { int i;
998  bool atnextbar = false;
999  for (i=1; i <= nstaffs; i++)
1000  if (active[i] && bar_rest[i])
1001  { atnextbar = true; break; }
1002  if (nastaffs == 1 && atnextbar)
1003  { restbars++;
1004  sprintf (deferred_bar, "%s", *ln);
1005  output_rests ();
1006  t = strpbrk (*ln+1, "%\\\n");
1007  if (*t == '\n') putc ('%', outfile);
1008  *ln = t;
1009  }
1010  else if (atnextbar)
1011  {
1012  fprintf (outfile, "\\def\\atnextbar{\\znotes");
1013  t = TransformNotes2;
1014  while (true)
1015  {
1016  s = strchr (t, '#');
1017  if (s == NULL)
1018  break;
1019  while (t < s) /* output any initial \transpose etc. */
1020  { putc (*t, outfile); t++; }
1021  t++; /* skip # */
1022  i = atoi (t) -1; t++;
1023  if (active[i])
1024  {
1025  if (bar_rest[i])
1026  fprintf (outfile, "\\centerpause");
1027  bar_rest[i] = false;
1028  }
1029  if (*t != '\0')
1030  { putc (*t, outfile); t++; } /* terminator */
1031  }
1032  fprintf (outfile, "\\en}%%\n");
1033  if (Changeclefs) /* \Changeclefs has to be output after \def\atnextbar... */
1034  {
1035  fprintf ( outfile, "\\Changeclefs%%\n");
1036  Changeclefs = false;
1037  }
1038  t = strpbrk (*ln+1, "%\\\n");
1039  while (*ln < t)
1040  { fputc (**ln, outfile);
1041  (*ln)++;
1042  }
1043  if (*t == '\n') putc ('%', outfile);
1044  *ln = t;
1045  }
1046  else
1047  { if (nastaffs == 1 && restbars > 0)
1048  output_rests ();
1049  t = strpbrk (*ln+1, "%\\\n");
1050  while (*ln < t)
1051  { fputc (**ln, outfile);
1052  (*ln)++;
1053  }
1054  if (*t == '\n') putc ('%', outfile);
1055  *ln = t;
1056  }
1057  if (debug)
1058  { fprintf (logfile, "\nAfter \\bar processing, *ln=%s\n", *ln);
1059  fflush (logfile);
1060  }
1061  }
1062 
1063  else if ( prefix ("\\znotes", *ln) )
1064  {
1065  if (nastaffs == 1 && restbars > 0)
1066  output_rests ();
1067  fputs (*ln, outfile);
1068  *ln = *ln + strlen(*ln);
1069  }
1070 
1071  else if ( prefix ("\\Changeclefs", *ln) )
1072  { /* defer till after \def\atnextbar ... */
1073  Changeclefs = true;
1074  *ln = *ln + strlen(*ln);
1075  }
1076 
1077  else if ( prefix ("\\documentclass", *ln) )
1078  {
1079 
1080  if ( suffix( ".tex", outfilename) )
1081  { char newoutfilename[SHORT_LEN];
1082  char *newoutfilename_n = newoutfilename;
1083  append (newoutfilename, &newoutfilename_n, infilename, sizeof (newoutfilename));
1084  newoutfilename_n -= 4;
1085  *newoutfilename_n = '\0';
1086  append (newoutfilename, &newoutfilename_n, "ltx", sizeof (newoutfilename));
1087  if (rename ( outfilename, newoutfilename) > 0)
1088  { printf ("Can't rename %s as %s\n", outfilename, newoutfilename);
1089  exit (EXIT_FAILURE);
1090  }
1091  printf ("\\documentclass detected; now writing to %s.", newoutfilename);
1092  printf ("\n\n");
1093 
1094  }
1095  fputs (*ln, outfile);
1096  *ln = *ln + strlen(*ln);
1097  }
1098 
1099  else if ( prefix ("\\end ", *ln)
1100  || prefix ("\\end%", *ln)
1101  || prefix ("\\end\n", *ln)
1102  || prefix ("\\end{document}", *ln) )
1103  {
1104  fprintf (outfile, "%s", *ln);
1105  exit(0);
1106  }
1107 
1108  else if ( prefix ("\\startmuflex", *ln) )
1109  {
1110  fputs ("\\startmuflex", outfile);
1111  *ln = *ln + 12;
1112  }
1113 
1114  else /* everything else */
1115  {
1116  fputs (*ln, outfile);
1117  *ln = *ln + strlen(*ln);
1118  }
1119 }
1120 
int nl
Definition: afm2tfm.c:885
static int lineno
Definition: aftopl.c:19
#define active
Definition: aptex-macros.h:325
#define SHORT_LEN
Definition: autosp.c:108
FILE * logfile
Definition: autosp.c:116
char infilename[256]
Definition: autosp.c:110
char *__cdecl strpbrk(char const *_Str, char const *_Control)
#define n
Definition: t4ht.c:1290
#define fflush
Definition: xxstdio.h:24
#define fgets
Definition: xxstdio.h:29
int sscanf()
int printf()
#define error(a)
Definition: dviinfo.c:48
#define t
Definition: afcover.h:96
voice_index0 instr[15]
#define c(n)
Definition: gpos-common.c:150
#define strchr
Definition: gsftopk.c:59
#define putc
Definition: jbib.h:20
#define EXIT_FAILURE
Definition: cdjpeg.h:169
static char * outfilename
Definition: cjpeg.c:137
static FILE * infile
Definition: rdjpgcom.c:61
static FILE * outfile
Definition: wrjpgcom.c:80
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
void exit()
int atoi(const char *)
#define LINE_LEN
Definition: utils.c:42
#define debug
Definition: pdfparse.c:41
char * strstr()
#define fputs
Definition: mendex.h:67
#define fprintf
Definition: mendex.h:64
#define new_line
Definition: ctangleboot.c:89
#define prefix
Definition: cwebboot.c:154
#define sprintf
Definition: snprintf.c:44
const char * suffix
Definition: pkg_icu.cpp:27
logical rename
Definition: pmxab.c:724
#define PRIVATE
Definition: pnmtoddif.c:70
static void analyze_notes(char **ln)
static void checkc(char *s, char c)
int semiauto_beam_notes[9]
int cspacing[9]
void process_xtuplet(void)
Definition: xtuplet.c:44
static void checkn(char *s)
void process_command(char **ln)
char s[256]
char * s_n
int beamingi
int spacing_note(int i)
Definition: spacing_note.c:186
char terminator[9]
char * ps(int spacing)
Definition: status.c:3
char * n_outstrings[9]
int spacings[9]
void status(int i)
Definition: status.c:38
#define Notespp
char collective[9][256]
static void output_rests(void)
char deferred_bar[256]
void output_notes(int i)
char collectivei[256]
int spacing_staff
signed char first_collective[9]
signed char appoggiatura
void status_beam(int i)
Definition: status.c:83
int xtuplet[9]
signed char nonvirtual_notes
#define NOTEsp
#define APPOGG_SPACING
static void generate_notes()
int cspacingi
int global_skip
#define NOTespp
void note_segment(char *s)
Definition: status.c:28
int vspacingi
#define NOtespp
signed char vspacing_active[9]
char outstrings[9][1024]
char * notes[9]
static void terminate_notes()
int vspacing[9]
void status_collective(int i)
Definition: status.c:73
int beaming[9]
signed char first_collectivei
static void process_appogg(void)
char * currenti
void status_all(void)
Definition: status.c:62
void initialize_notes()
#define APPOGG_NOTES
char * current[9]
#define notespp
static void filter_output(int i)
int new_beaming
void status_spacing(void)
Definition: status.c:53
int spacing
Definition: process_score.c:12
signed char bar_rest[9]
Definition: process_score.c:11
int oldspacing_staff
Definition: process_score.c:19
int nstaffs
Definition: process_score.c:16
#define SP(note)
Definition: process_score.c:6
#define MAX_SPACING
Definition: process_score.c:8
int ninstr
Definition: process_score.c:15
int old_spacing
Definition: process_score.c:18
int staff_instr[9]
Definition: process_score.c:27
#define MAX_STAFFS
Definition: process_score.c:3
int staffs[9]
Definition: process_score.c:9
char TransformNotes2[256]
Definition: process_score.c:21
char global_skip_str[7][16]
Definition: process_score.c:14
signed char Changeclefs
Definition: process_score.c:20
float instr_numsize[9]
Definition: process_score.c:25
signed char TransformNotesDefined
Definition: process_score.c:22
char instrument_size[9][256]
Definition: process_score.c:23
int restbars
Definition: process_score.c:13
int nastaffs
Definition: process_score.c:17
#define isalpha(ch)
Definition: utype.h:82
Definition: bdf.c:133
Definition: dvips.h:235
int j
Definition: t4ht.c:1589
*job_name strlen((char *) job_name) - 4)
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
#define append(a, b)
Definition: y.tab.c:257