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 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
|
/*********************************************************
This file is part of the OpusTeX system.
You are not allowed to change this file.
For distribution see the copyright notice in 00readme.txt
*********************************************************/
#define VERSION "0.84"
#define MYVERSION "/4.8ae\0"
/****************************************************************************
Line breaking program for OpusTeX.
Ross Mitchell, August 1992.
Andreas Egler, since February 1993.
- enabled endline signature changes, May 1993
- enabled \zbar, March 1994
- enabled \leftrightrepeat at eoline, April 1994
- converted to (TURBO/PURBO/Pure)C, thanks to MiSi for compiling, June 1994
remark: this is my very first attempt using C, if your harddisk crushes
or your computer blows up -> Your problem !
- MusiXFlex now gives back a number to the parent process (batch, shell, o.s.e.)
0 -> OK
3 -> error (free to be changed in error_exit())
- introduced \raggedstoppiece, August 1994
- introduced barno for more transparence of .ox2, September 1994
- introduced (reluctant) the use of 'hard' offsets, September 1994
therefore the computing of mean space factor changed
- introduced \leftrepeat, September 1994
- enabled moretimes use of \startpiece, September 1994
- added logfile for bughunting, September 1994
- added test of versionnumber from MusiXTeX, September 1994
- renamed MuFlex to musixflx (as suggested by DT), October 1994
- adapted ANSI coding (as suggested by CLARY Olivier), February 1995
- added some safeties for weird situations, March 1995
- added again safeties for those, who can't read the doc, April 1995
- introduced \sectionlines, April 1995
- changed \left- and \leftrightrepeat, August 1995
- added errno.h (as suggested by Steven Hall), September 1995
- renamed musixflx to opusflex (as suggested by M.Filgueras), March 1996
- fixed bug: \hardspace immediately behind \startpiece, January 1997
- enabled use of \medmusicsize, January 1997
- fixed bug: leading dots will not be cut (Erwin Achermann), August 1997
- fixed bug: file name without extension causes trouble on
some C-implementations (Robert Storlind), October 1997
- fixed bug: \raggedendpiece and \finisgregoriana, January 1998
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#define TRUE 1
#define FALSE 0
/* attention: every \changecontext reports a change of \sig@skip */
#define MAX_SIGNS 128 /* max signature changes */
#define MAX_SECTIONS 128 /* max sections */
#define MAX_BARS 1024 /* max number of bars in one section */
#define GETLINE fgets(linebuf, (int) sizeof(linebuf), infile)
void error_exit(int error_number);
int zbar[MAX_BARS], lr_repeat[MAX_BARS], raggedline[MAX_BARS],
l_repeat[MAX_BARS], barno[MAX_BARS], bars[MAX_SECTIONS],
mulooseness[MAX_SECTIONS], signchange[MAX_SIGNS],
sectionlines[MAX_SECTIONS];
double hardbarlength[MAX_BARS], softbarlength[MAX_BARS],
leftrightrepeat[3], leftrepeat[3],
eff_hardlength[MAX_SECTIONS], eff_softlength[MAX_SECTIONS],
oldsignskip[MAX_SIGNS], signskip[MAX_SIGNS];
FILE *infile, *outfile, *logfile;
char linebuf[128], n_o_f[128];
void error_exit(error_number)
int error_number;
{
switch (error_number){
case 0:
printf("\nFile error: Disk full ?\n"); break;
case 1:
printf("\nUsage: opusflex filename [d|f|s] (optional for debug modes)\n");
break;
case 2:
printf("\nThis shouldn't happen ! Forgotten \\bar ?\n"); break;
case 3:
printf("\nThis shouldn't happen ! Too less bars in section !\n"); break;
case 4:
printf("\nMissing endmark ! Forgotten \\stop[end]piece ?\n"); break;
case 5:
printf("\nDivision by zero ! Ask a wizard !\n"); break;
default:
printf("!!! Can't go on !!!\n");}
remove(n_o_f); exit(3);}
int main(argc, argv)
int argc;
char **argv;
{
register int i, j, bar;
int dbug= FALSE,
dbug_lines= FALSE,
dbug_logfile= FALSE,
showresult= FALSE,
detectraggedline= FALSE,
currentline= 1,
samechapter= TRUE,
line_number= 0,
chapterno= 1,
musicsize= 0,
detect_end, typ, jbar, sign, all_section, section, mark, lines,
lastbarnumber, barsinline, lastbarno, firstbarno, line_in_section;
double lthick=.4,
flexit, linewidth, parindent, x, spc_factor, elemskip, cor_elemskip,
afterrule, cor_afterrule, lastbar, eff_linewidth, fill_length,
hardlength, softlength, clefskip;
char name_of_file [128], n_o_logfile[128], OpusFlexVersion[6];
leftrightrepeat[0]=10.8;
leftrepeat[0]=6.4;
leftrightrepeat[1]=13.5;
leftrepeat[1]=7.9;
leftrightrepeat[2]=13.5;
leftrepeat[2]=7.9;
printf("\n <<< opusflex %s%s >>>\n", VERSION, MYVERSION);
printf("\n ... decode command line\n");
if (argc<2 || argc>3) error_exit(1);
/*********************************
debugging
d debug informations on screen
f debug informations to file .oxl
s show computed lines on screen
**********************************/
if (argc==3){
if (!strcmp("d",argv[2])) dbug=TRUE;
if (!strcmp("m",argv[2])) dbug_lines=TRUE;
if (!strcmp("f",argv[2])){dbug=TRUE; dbug_logfile=TRUE; dbug_lines=TRUE;}
if (!strcmp("s",argv[2])) showresult=TRUE;}
/******************************************
search for '.', cut string, add '.ox1'
'.' may be allowed within path
we have to search for ".???" at the end of
the given file name, and cut ONLY that
*******************************************/
strcpy (name_of_file, argv[1]);
{ int length = strlen(name_of_file);
char *ext = strrchr(name_of_file,'.');
if ((length >= 5) && ext && (strlen(ext) < 5)) {
/* we found something of form ".???" -- "." */
ext[0] = '\0'; /* cut it */
}
}
strcpy(n_o_f, name_of_file);
strcat(name_of_file, ".ox1");
/*****************************************************
Open the .ox1 file containing bar length information.
******************************************************/
printf(" ... open <%s> for input\n", name_of_file);
infile = fopen(name_of_file, "r");
if (!infile){
printf("\nFile not found: %s\n", name_of_file); exit(3);}
/***********************
test versionnumber
and stop if they differ
************************/
strcpy(OpusFlexVersion, VERSION);
strcat(OpusFlexVersion, "\n");
printf(" ... test versionnumber\n");
++currentline;
if (GETLINE && strcmp(linebuf, OpusFlexVersion)){
printf("\n!!! Wrong version !!!\n\nOpusTeX : %s",linebuf);
printf("OpusFlex : %s\n",OpusFlexVersion); error_exit(99);}
/*********************
Open the output file.
**********************/
strcpy (n_o_logfile, n_o_f);
strcat (n_o_f, ".ox2");
printf(" ... open <%s> for output\n",n_o_f);
outfile = fopen(n_o_f, "w" );
if (!outfile) {printf("\nCan't create: %s\n",n_o_f); exit(3);}
/******************
Open the log file.
*******************/
if (dbug_logfile){
strcat (n_o_logfile, ".oxl");
printf(" ... open <%s> for debugging\n",n_o_logfile);
logfile = fopen(n_o_logfile, "w" );
if (!logfile) {printf("\nCan't create: %s\n",n_o_logfile); exit(3);}
fprintf(logfile,"Version %s", OpusFlexVersion);}
/*******************
skip startindicator
********************/
if (GETLINE && strcmp(linebuf,"S\n")){
printf("\nCorrupted <%s>\n", name_of_file); error_exit(99);}
/*****************************
do...while loop for
moretimes call of \startpiece
>>>>>>>>>>>>>>>>>>>>>>>>>>>
******************************/
GETLINE;
do {
/****************
reset all arrays
*****************/
if (dbug) printf("\n------- Chapter %d -------\n\n", chapterno);
if (dbug_logfile)
fprintf(logfile, "\n------- Chapter %d -------\n\n", chapterno);
for (i=0; i<MAX_SIGNS; ++i){
signchange[i]=-1;
oldsignskip[i]=0;
signskip[i]=0;}
for (i=0; i<MAX_BARS; ++i){
hardbarlength[i]=0;
softbarlength[i]=0;
lr_repeat[i]=FALSE;
l_repeat[i]=FALSE;
zbar[i]=FALSE;
raggedline[i]=FALSE;
barno[i]=0;}
for (i=0; i<MAX_SECTIONS; ++i){
eff_hardlength[i]=0;
eff_softlength[i]=0;
bars[i]=0;
mulooseness[i]=0;
sectionlines[i]=0;}
/*****************************
Read and decode header items:
1. Linewidth;
2. Parindent;
3. Beforeruleskip;
4. Afterruleskip;
5. Elemskip;
6. Clefskip;
7. Signskip;
8. Musicsize
******************************/
linewidth = atof(linebuf); ++currentline;
GETLINE; parindent = atof(linebuf); ++currentline;
GETLINE; afterrule = atof(linebuf); ++currentline;
GETLINE; elemskip = atof(linebuf); ++currentline;
GETLINE; clefskip = atof(linebuf); ++currentline;
GETLINE; signskip[0]= atof(linebuf); ++currentline;
GETLINE; musicsize = (int)atol(linebuf); ++currentline;
/******************************************************************
Read the records specifying contributions to bar length.
Lengths are of two types:
(a) Hard or unscaleable, eg barlines, clef or meter changes (typ=0).
(b) Soft or scaleable, eg noteboxes which scale with \elemskip (typ=1).
Note that \afterruleskip is considered soft.
*******************************************************************/
jbar=-1;
i = 0;
sign = 0;
all_section = 0;
printf(" ... read\n");
while (samechapter && GETLINE )
{
++currentline;
switch (linebuf[0])
{
/***************
'\startpiece'
stop reading,
compute,
write
and start again
****************/
case 'S':
samechapter=FALSE;
break;
/*********************************************************
End of section. Action:
Right justify the material ending at the previous bar.
Read the number following the *, which is the 'looseness'
parameter of the section just ended.
Reset the bar test integer to JUNK in case the bar number
was reset between sections.
***********************************************************/
case '*':
mulooseness[all_section]=(int) atol (strchr(linebuf,' '));
sectionlines[all_section]=(int) atol (strrchr(linebuf, ' '));
++all_section;
if (all_section>(MAX_SECTIONS-1)){
printf("\nToo many sections, maximum number of sections: %d\n",
MAX_SECTIONS); exit(3);}
jbar=-1;
break;
/******************************************************
found a raggedline, let's set a flag
I think, I'll hardly get a Nobel-Award for coding this
What a pity! :-(
but perhaps a Pulitzer-Award for my comments. :-)
*******************************************************/
case 'r': raggedline[i]=TRUE; break;
/*************************************
found \zbar, set flag and store barno
**************************************/
case 'z': zbar[i]=TRUE;
barno[i]= (int) atol(strrchr(linebuf, ' '));
break;
/*******************************
found leftrightrepeat, set flag
********************************/
case 'l': lr_repeat[i]=TRUE; break;
/**************************
found leftrepeat, set flag
***************************/
case 'L': l_repeat[i]=TRUE; break;
/***********
store barno
************/
case 'b':
barno[i]= (int) atol(strrchr(linebuf, ' '));
break;
/**********************************
enabling the use of 'hard' offsets
advance current hardwith
reduce current softwidth
***********************************/
case 'h':
if (jbar==-1) ++i;
x = atof(strrchr(linebuf, ' '));
softbarlength[i] -= x;
hardbarlength[i] += x;
eff_softlength[all_section] -= x;
eff_hardlength[all_section] += x;
if (jbar==-1) --i;
break;
/***************************************************************
This record began with 's' and specifies a key signature change
store the signskip, s.b.
***************************************************************/
case 's':
++sign;
signchange[sign]=i;
signskip[sign]=atof(strchr(linebuf,' '));
oldsignskip[sign]=hardbarlength[i];
break;
/* comment */
case '%': break;
/********************************************************************
This is an `ordinary' line, listing a contribution to the barlength.
*********************************************************************/
default:
if (!isdigit(linebuf[0])){
printf("\nError in <%s> line %d \n", name_of_file, currentline);
error_exit(99);}
bar= (int) atol(linebuf);
typ= (int) atol(strchr(linebuf, ' '));
x=atof(strrchr(linebuf, ' '));
if (typ) eff_softlength[all_section] += x;
else eff_hardlength[all_section] += x;
/**************************************
Increment bar number if the bar number
read from the file has changed.
Accumulate current bar length.
***************************************/
if (bar>jbar){
++i;
++bars[all_section];
if(i>MAX_BARS){
printf("\nToo many bars, maximum number of bars: %d\n", MAX_BARS);
exit(3);}}
if (typ) softbarlength[i] += x; else hardbarlength[i] += x;
jbar=bar;
} /* eo switch */
} /* eo while */
/**************************************************************
Decrement the number of sections if the final section is void.
This will be the usual case where the input file ends with
an end of section record.
If this record has been omitted, stop going on to avoid
'You can't use \raise....'.
***************************************************************/
if (!bars[all_section])
--all_section;
else
error_exit(4);
/********************************
Summarize sectioning information.
*********************************/
if (dbug){
printf("\nNumber of sections : %d\n\n",all_section+1);
for (section=0; section<=all_section; ++section){
printf("Section : %d\n",section+1);
printf("Number of bars in section : %d\n",bars[section]);
printf("Length(hard) of section %d : %f\n",
section+1, eff_hardlength[section]);
printf("Length(soft) of section %d : %f\n",
section+1, eff_softlength[section]);
printf("Looseness of section : %d\n",mulooseness[section]);
if (sectionlines[section]>0)
printf("Choosen lines : %d\n",sectionlines[section]);
getchar();}}
if (dbug_logfile){
fprintf(logfile, "\nNumber of sections : %d\n\n",
all_section+1);
for (section=0; section<=all_section; ++section){
fprintf(logfile, "Section : %d\n",
section+1);
fprintf(logfile, "Number of bars in section : %d\n",
bars[section]);
fprintf(logfile, "Length(hard) of section %d : %f\n",
section+1, eff_hardlength[section]);
fprintf(logfile, "Length(soft) of section %d : %f\n",
section+1, eff_softlength[section]);
fprintf(logfile, "Looseness of section : %d\n",
mulooseness[section]);
if (sectionlines[section]>0)
fprintf(logfile, "Choosen lines : %d\n",
sectionlines[section]);}}
/*************************************************
Loop over the sections defined in the input file.
Each section must be right justified.
LAST is the absolute number of the last bar
in the current section.
**************************************************/
sign = 0;
mark = 0;
lastbarnumber = 0;
for(section=0; section<=all_section; ++section){
line_in_section=1;
lastbarnumber += bars[section];
/*************************************
Find number of lines to work towards.
**************************************/
lines=((eff_hardlength[section]+eff_softlength[section]+parindent)/
(linewidth-(clefskip+signskip[sign])))+.5;
if (!lines) lines=1; /* safety */
printf(" ... compute lines: %d choosen lines: ", lines);
lines += mulooseness[section];
if (lines<1){lines=1; printf("Don't stress \\mulooseness to much !!!\n");}
if (bars[section]<2) lines=1; /* safety */
/*******************************************
Override number of lines by user definition
********************************************/
if (sectionlines[section] > 0 && mulooseness[section] != 0){
printf("\n! Found use of \\sectionlines and \\mulooseness in one");
printf(" section.\nCheck it out!\n");}
if (sectionlines[section]>0) lines=sectionlines[section];
printf("%d\n", lines);
if (dbug){
printf("Section number : %d\n", section+1);
printf("Last bar in this section : %d\n", lastbarnumber);
printf("Number of bars : %d\n", bars[section]);
printf("Natural number of lines : %d\n", lines-mulooseness[section]);
printf("Chosen number of lines : %d\n\n", lines);}
if (dbug_logfile){
fprintf(logfile, "Section number : %d\n", section+1);
fprintf(logfile, "Last bar in this section : %d\n", lastbarnumber);
fprintf(logfile, "Number of bars : %d\n", bars[section]);
fprintf(logfile, "Natural number of lines : %d\n",
lines-mulooseness[section]);
fprintf(logfile, "Chosen number of lines : %d\n\n", lines);}
if (bars[section]<1) error_exit(3);
/**************************************************************
fill_length is the length of 'bar' material (ie excluding
signature space) required to fill the remainder
of the piece. This value will not be exact if there are
sign changes within the section. However,
fill_length is used only to keep track of the mean scale factor
for the remainder of the piece, as opposed to individual lines.
Loop over lines, working out number of bars
and revised \elemskip for each line.
added correct computing of fill_length
****************************************************************/
for (j=1; j<=lines; ++j, ++line_in_section){
++line_number;
fill_length=(lines-j+1)*(linewidth-(clefskip+signskip[sign]));
/****************************************************
Work out mean element skip over remaining bars
in the current section.
eff_linewidth is the effective line width once
key signature have been written.
Set parindent to zero after it has been used for the
first line of the first section.
****************************************************/
if (!eff_softlength[section]) error_exit(5);
spc_factor=(fill_length-eff_hardlength[section])/eff_softlength[section];
eff_linewidth=linewidth-(clefskip+signskip[sign])-parindent;
parindent=0;
/****************************************************
Fill the current line by adding bars until overflow.
*****************************************************/
i=mark;
firstbarno=barno[mark+1];
hardlength= 0;
softlength = 0;
x = 0;
detect_end= FALSE;
while (x<eff_linewidth){
if (detect_end) break;
++i;
/*********************
Check for raggedline.
**********************/
if (raggedline[i]) detectraggedline=TRUE;
/*******************************************
Check for key signature change at this bar.
********************************************/
if (i==signchange[sign+1]) ++sign;
lastbar = hardbarlength[i]+spc_factor*softbarlength[i];
x += lastbar;
/*********************************************
Enforce termination at last bar and last line
**********************************************/
if (i==lastbarnumber) detect_end=TRUE;
else if (line_in_section==lines){detect_end=FALSE; x=0;}
hardlength += hardbarlength[i];
softlength += softbarlength[i];}
/************************************************
If the overhang is less than half the barlength,
include the latest bar in the line,
and shrink the line accordingly.
*************************************************/
if ((x-eff_linewidth)<(lastbar/2)){
barsinline=i-mark;
mark=i;
lastbarno=barno[mark];
/********************************************
last bar in line a zbar?
if true -> add to the first bar in next line
the amount of afterruleskip
*********************************************/
if (zbar[mark]){
softbarlength[i+1] += afterrule;
eff_softlength[section] += afterrule;}
/********************************************
last bar in line a leftrightrepeat?
if true -> reduce hardwidth of current line
advance the hardwidth of next bar
advance the softwidth of next bar
*********************************************/
if (lr_repeat[mark]){
hardlength -= (leftrightrepeat[musicsize]-leftrepeat[musicsize]);
eff_hardlength[section] +=
(leftrightrepeat[musicsize]-leftrepeat[musicsize]);
hardbarlength[i+1] += leftrepeat[musicsize];
softbarlength[i+1] += afterrule/2;
eff_softlength[section] += afterrule/2;}
/********************************************
last bar in line a leftrepeat?
if true -> reduce hardwidth of current line
advance the hardwidth of next bar
advance the softwidth of next bar
*********************************************/
if (l_repeat[mark]){
hardlength -= (leftrepeat[musicsize]-lthick);
hardbarlength[i+1] += leftrepeat[musicsize];
softbarlength[i+1] += afterrule/2;
eff_softlength[section] += afterrule/2;}
if (signchange[sign+1]==mark+1){ /* s.b. */
++sign;
hardlength += oldsignskip[sign];
hardbarlength[mark+1] -= oldsignskip[sign];}}
/*********************************************
Exclude the latest bar, and stretch the line.
**********************************************/
else{
barsinline=i-1-mark;
if (barsinline<1) error_exit(2);
mark=i-1;
lastbarno=barno[mark];
hardlength -= hardbarlength[i];
softlength -= softbarlength[i];
if (zbar[mark]) softbarlength[i] += afterrule;
if (lr_repeat[mark]){
hardlength -= (leftrightrepeat[musicsize]-leftrepeat[musicsize]);
eff_hardlength[section] +=
(leftrightrepeat[musicsize]-leftrepeat[musicsize]);
hardbarlength[i] += leftrepeat[musicsize];
softbarlength[i] += afterrule/2;
eff_softlength[section] += afterrule/2;}
if (l_repeat[mark]){
hardlength -= (leftrepeat[musicsize]-lthick);
hardbarlength[i] += leftrepeat[musicsize];
softbarlength[i] += afterrule/2;
eff_softlength[section] += afterrule/2;}
/*********************************************************************
Error (o/u-hbox) occurs only when signature change start in next line
-> look for signature change in next line
if true then advance the hardwidth of current line
reduce next hard barlength by signature change
**********************************************************************/
if (signchange[sign]==mark+1){
hardlength += oldsignskip[sign];
hardbarlength[mark+1] -= oldsignskip[sign];}}
/***********************************************
Define a flex factor for this line as the ratio
of soft part of the specified line width,
to soft width in the approximate line.
************************************************/
if (!softlength) error_exit(5);
flexit=(eff_linewidth-hardlength)/softlength;
/***********************************************
Check for raggedline:
************************************************/
if (detectraggedline && flexit >= 1) flexit=1;
detectraggedline=FALSE;
cor_elemskip = elemskip * flexit;
cor_afterrule = afterrule * flexit;
if (dbug){
printf("Line number : %d\n",line_number);
printf("Fill length : %f\n",fill_length);
printf("Effective length : %f\n",
eff_softlength[section]+eff_hardlength[section]);
printf("Mean space factor : %f\n",spc_factor);
printf("Bars in line : %d\n",barsinline);
printf("Effective linewidth : %f\n",eff_linewidth);
printf("Uncorrected hard length : %f\n",hardlength);
printf("Uncorrected soft length : %f\n",softlength);
printf("Flex factor (soft) : %f\n",flexit);
printf("Corrected elemskip : %f\n",cor_elemskip);
printf("Corrected afterrule : %f\n",cor_afterrule);
getchar();}
if (dbug_logfile){
fprintf(logfile, "Line number : %d\n",line_number);
fprintf(logfile, "Fill length : %f\n",fill_length);
fprintf(logfile, "Effective length : %f\n",
eff_softlength[section]+eff_hardlength[section]);
fprintf(logfile, "Mean space factor : %f\n",spc_factor);
fprintf(logfile, "Bars in line : %d\n",barsinline);
fprintf(logfile, "Effective linewidth : %f\n",eff_linewidth);
fprintf(logfile, "Uncorrected hard length : %f\n",hardlength);
fprintf(logfile, "Uncorrected soft length : %f\n",softlength);
fprintf(logfile, "Flex factor (soft) : %f\n",flexit);
fprintf(logfile, "Corrected elemskip : %f\n",cor_elemskip);
fprintf(logfile, "Corrected afterrule : %f\n",cor_afterrule);}
eff_hardlength[section] -= hardlength;
eff_softlength[section] -= softlength;
fill_length -= eff_linewidth;
/**********************************
Write a record to the output file.
***********************************/
fprintf(outfile, "\\lineset");
if (line_number<10)
fprintf(outfile, "%d",line_number);
else
fprintf(outfile, "{%d}",line_number);
if (barsinline<10)
fprintf(outfile, "%d",barsinline);
else
fprintf(outfile, "{%d}",barsinline);
fprintf(outfile, "{%.5f}", cor_elemskip);
if (cor_afterrule!=0)
fprintf(outfile, "{%.5f}", cor_afterrule);
else
fprintf(outfile, "0");
fprintf(outfile, "%% %d - %d\n", firstbarno, lastbarno);
if (showresult){
printf(
"\\lineset{%d}{%d}{%.5f}{%.5f}%% %d - %d\n",
line_number, barsinline, cor_elemskip, cor_afterrule,
firstbarno, lastbarno);}
if (dbug_lines) printf(" ... write line : %d\r", line_number);
if (dbug_logfile)
fprintf(logfile, " ... write line : %d\n", line_number);
} /*eo for lines */
} /* eo for sections */
if (dbug_lines) printf("\n");
/*********
<<<<<<<<<
eo do
**********/
samechapter=TRUE;
++chapterno;
} while(GETLINE);
/*************
closing files
**************/
fclose(infile);
if (dbug_logfile){
fclose(logfile);
if (!logfile) error_exit(0);}
fclose(outfile);
if (!outfile) error_exit(0);
printf(" ... thats all, bye\n");
return(0);
}
/*** eof ***/
|