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)  

autosp.c
Go to the documentation of this file.
1 char version[12] = "2021-01-07";
2 
3 /* Copyright (C) 2014-21 R. D. Tennent School of Computing,
4  * Queen's University, rdt@cs.queensu.ca
5  *
6  * This program is free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General
8  * Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will
13  * be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A
15  * PARTICULAR PURPOSE. See the GNU General Public License
16  * for more details.
17  *
18  * You should have received a copy of the GNU General
19  * Public License along with this program; if not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street,
21  * Fifth Floor, Boston, MA 02110-1301, USA.
22  */
23 
24 /* autosp - preprocessor to generate note-spacing commands for MusiXTeX scores */
25 
26 /* Usage: autosp [-v | --version | -h | --help]
27  * autosp [-d | --dotted] [-l | --log] infile[.aspc] [outfile[.tex]]
28  *
29  * Options
30  * --dotted (-d) suppresses extra spacing for dotted beam notes.
31  * --log (-l) generate a log file
32  *
33  *
34  *
35  * Key functions:
36  *
37  * process_command, which processes commands
38  * \instrumentnumber
39  * \nbinstrument
40  * \setstaffs
41  * \startpiece
42  * \TransformNotes
43  * \def\vnotes
44  * \def\atnextbar
45  * \anotes etc.
46  * \bar
47  * \endpiece etc.
48  *
49  * analyze_notes, which determines pointers notes[i] and
50  * characters terminator[i] for each staff; '$' is used
51  * as the terminator for the last staff.
52  *
53  * generate_notes, which repeatedly uses spacing_note (i) to
54  * determine spacings[i] of the next spacing note in
55  * each staff; the current spacing is then the smallest
56  * of these. If necessary, the current notes command
57  * is terminated by terminate_notes() and a new notes
58  * command initiated by initialize_notes(). The current global
59  * skip and note commands for each staff are then copied to
60  * outstrings[i] using output_notes (i). When necessary,
61  * vspacing[i] is set to generate subsequent skips.
62  * Appoggiaturas and xtuplets are treated separately.
63  *
64  * spacing_note (i), which searches for the next spacing note
65  * in the i'th staff, unless a "virtual note" (skip) is
66  * needed.
67  *
68  * output_notes (i), which copies a global_skip string and
69  * outstrings[i] to output, using filter_output (i) to discard
70  * commas and global and large skips, and insert collective-coding
71  * prefixes and closing braces.
72  *
73  * terminate_notes, which copies outstrings[i] to output,
74  * in the order determined by TransformNotes2.
75  *
76  * Spacing values are expressed as sums of binary multiples of
77  * SMALL_NOTE (by default, 1/256th); for example, half-note
78  * spacing = SP(2) = SMALL_NOTE/2. Special small or large
79  * values are used for appoggiaturas and bar-rests.
80  *
81  */
82 
83 # include "utils.h"
84 
85 #ifdef HAVE_CONFIG_H /* for TeXLive */
86 #include <config.h>
87 #endif
88 
89 # ifdef KPATHSEA
90 # include <kpathsea/getopt.h>
91 # else
92 # include <getopt.h>
93 # endif
94 
95 # ifdef HAVE_STDBOOL_H
96 # include <stdbool.h>
97 # else
98 # ifndef HAVE__BOOL
99 # define _Bool signed char
100 # endif
101 # define bool _Bool
102 # define true 1
103 # define false 0
104 # endif
105 
106 # define PRIVATE static
107 
108 # define SHORT_LEN 256
109 
117 
118 
119 void process_score ();
120 
121 PRIVATE void
123 {
124  printf ("Usage: autosp [-v | --version | -h | --help]\n");
125  printf (" autosp [-d | --dotted] [-l | --log] infile[.aspc] [outfile[.tex]]\n");
126  printf (" autosp [-d | --dotted] [-l | --log] infile.tex outfile[.tex]\n");
127 }
128 
129 
130 bool dottedbeamnotes = false; /* dotted beam notes ignored? */
131 bool debug = false;
132 
133 int main (int argc, char *argv[])
134 {
135  int c;
136 # define NOPTS 5
137  struct option longopts[NOPTS] =
138  { { "help", 0, NULL, 'h'},
139  { "version", 0, NULL, 'v'},
140  { "dotted", 0, NULL, 'd'},
141  { "log", 0, NULL, 'l'},
142  { NULL, 0, NULL, 0}
143  };
144 
145  printf ("This is autosp, version %s.\n", version);
146  printf ("Copyright (C) 2014-20 R. D. Tennent\n" );
147  printf ("School of Computing, Queen's University, rdt@cs.queensu.ca\n" );
148  printf ("License GNU GPL version 2 or later <http://gnu.org/licences/gpl.html>.\n" );
149  printf ("There is NO WARRANTY, to the extent permitted by law.\n\n" );
150 
151  c = getopt_long (argc, argv, "hvdl", longopts, NULL);
152  while (c != -1)
153  {
154  switch (c)
155  {
156  case 'h':
157  usage ();
158  printf ("Please report bugs to rdt@cs.queensu.ca.\n" );
159  exit (0);
160  case 'v':
161  exit (0);
162  case 'd':
163  dottedbeamnotes = true;
164  break;
165  case 'l':
166  debug = true;
167  break;
168  case '?':
169  exit (EXIT_FAILURE);
170  default:
171  printf ("Function getopt returned character code 0%o.\n",
172  (unsigned int) c);
173  exit (EXIT_FAILURE);
174  }
175  c = getopt_long (argc, argv, "hvd", longopts, NULL);
176  }
177 
178  infilename[0] = '\0';
180  if (optind < argc)
182  if (!suffix (".aspc", infilename))
183  append (infilename, &infilename_n, ".aspc", sizeof (infilename));
184  }
185  else
186  { usage();
187  exit (EXIT_FAILURE);
188  }
189  infile = fopen (infilename, "r");
190  if (infile == NULL )
191  { printf ("Can't open %s\n", infilename);
192  exit (EXIT_FAILURE);
193  }
194 
195  printf ("Reading from %s.", infilename);
196 
197  optind++;
198  outfilename[0] = '\0';
200  if (optind < argc) /* user-provided outfilename */
201  {
203  if (!suffix (".tex", outfilename))
204  append (outfilename, &outfilename_n, ".tex", sizeof (outfilename));
205  }
206  else if (suffix (".aspc", infilename) )
207  { /* output to infile.tex */
209  outfilename_n -= 4;
210  *outfilename_n = '\0';
211  append (outfilename, &outfilename_n, "tex", sizeof (outfilename));
212  }
213 
214  if (*outfilename == '\0')
215  {
216  printf ("\nPlease provide a filename for the output.\n\n");
217  exit (EXIT_FAILURE);
218  }
219  else
220  {
221  outfile = fopen (outfilename, "w");
222  if (outfile == NULL)
223  { printf ("Can't open %s\n", outfilename);
224  exit (EXIT_FAILURE);
225  }
226  printf (" Writing to %s.", outfilename);
227  }
228 
229  logfilename[0] = '\0';
232  if (suffix (".aspc", infilename) )
233  logfilename_n -= 4;
234  else
235  logfilename_n -= 3;
236  *logfilename_n = '\0';
237  append (logfilename, &logfilename_n, "alog", sizeof (logfilename));
238  if (debug)
239  { logfile = fopen (logfilename, "w");
240  if (logfile == NULL)
241  { printf ("Can't open %s\n", logfilename);
242  exit (EXIT_FAILURE);
243  }
244  printf (" Log file %s.", logfilename);
245  }
246  printf ("\n\n");
247 
248  fprintf (outfile, "%% Generated by autosp (%s).\n", version);
249 
250  process_score ();
251 
252  return 0;
253 }
#define SHORT_LEN
Definition: autosp.c:108
int main(int argc, char *argv[])
Definition: autosp.c:133
#define NOPTS
char outfilename[256]
Definition: autosp.c:112
char * logfilename_n
Definition: autosp.c:115
signed char dottedbeamnotes
Definition: autosp.c:130
char logfilename[256]
Definition: autosp.c:114
char version[12]
Definition: autosp.c:1
#define PRIVATE
Definition: autosp.c:106
static void usage()
Definition: autosp.c:122
signed char debug
Definition: autosp.c:131
FILE * logfile
Definition: autosp.c:116
char * outfilename_n
Definition: autosp.c:113
void process_score()
Definition: process_score.c:49
FILE * outfile
Definition: autosp.c:116
char infilename[256]
Definition: autosp.c:110
char * infilename_n
Definition: autosp.c:111
FILE * infile
Definition: autosp.c:116
#define fopen
Definition: xxstdio.h:21
int printf()
#define c(n)
Definition: gpos-common.c:150
#define EXIT_FAILURE
Definition: cdjpeg.h:169
#define NULL
Definition: ftobjs.h:61
void exit()
int optind
Definition: getopt.c:39
int getopt_long()
#define fprintf
Definition: mendex.h:64
const char * suffix
Definition: pkg_icu.cpp:27
static struct option longopts[]
Definition: main.c:385
Definition: getopt.h:95
#define FILE
Definition: t1stdio.h:34
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269
#define append(a, b)
Definition: y.tab.c:257