home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
text
/
jemtex-2.00.lha
/
JemTeX
/
sources
/
jem2tex.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-21
|
48KB
|
1,318 lines
/* -mt -f -A -K -G -O -w */
/* Compile with Turbo-C 2.0 */
/*
This program translates a .JEM file into a .TeX file
Author: Francois Jalbert
'
Date: November 1990
Version: 1.0
Date: January 1991
Version: 1.01
Modifications: - Added \hskip0pt plus0.1em between all Japanese symbols which
improved dramatically line breaks and inter-sentence spacing
since [La]TeX could only add glue between whole Japanese
sentences.
- Extra space after punctuation is now an option since it is
not desirable with MuTeX when the text is to go under the
staff.
- Font names now use only small letters to be compatible with
the fontlib program supplied with emTeX.
- Command line parameters now supported.
- Run-time parameters now supported.
- Updated and improved run-time messages.
Date: April 1991
Version: 2.00
Modifications: - Added four kanjis.
- If desired, only standard JIS '83 characters are allowed.
- If desired, a % is added at each Japanese end of line.
- Three file name extensions .JEM .JPN .JAP now supported.
- Default extension is .JEM and the program has been renamed.
- Three run-time parameter flags now supported.
- Japanese comments not translated anymore for reference.
- Hyphenation and glue handled separately for better control.
- More clever algorithm for Japanese hyphenation.
- Space after some punctuation now obtained with \eeee.
- Small space around some punctuation introduced with \eee.
- Tiny space between Japanese characters with \ee.
- Space between Japanese and Roman with \eeee and \eee.
- Symbols separated only by [La]TeX comments are now
recognized as consecutive.
- MS-kanji (Shift-JIS) now supported.
Error Levels: 0 - Normal termination.
1 - Error.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifdef __TURBOC__
#include <process.h>
#endif
#define True 1
#define False 0
/* Highest Bitmap number in JIS24 */
#define BitmapMax 7806
/* Highest font number */
#define FontMax 60 /* Floor of 7806 Div 128 */
/* Highest size number */
#define SizeMax 7 /* magsteps are 0, 0.5, 1, 2, 3, 4, 5 */
/* DOS file name length */
#define FileNameDOS 250 /* includes path */
#define ExtensionDOS 4 /* includes . */
#define TotalNameDOS 254
/* File name extensions in priority order */
char Extension1[]=".jem";
char Extension2[]=".jpn";
char Extension3[]=".jap";
/* Run-time flag of all the same length */
char RunFlag1[]="JEM2TEX";
char RunFlag2[]="JPN2TEX";
char RunFlag3[]="JAP2TEX";
/* Parameter flag */
#define Flag1 '/' /* DOS style */
#define Flag2 '-' /* UNIX style */
/* Parameter keywords in approximate decreasing length order */
#define ParamMax 12
char Space1[]="EXTRASPACE";
char Space2[]="EXTRA";
char Space3[]="SPACE";
char NoSpace1[]="NOEXTRASPACE";
char NoSpace2[]="NOEXTRA";
char NoSpace3[]="NOSPACE";
char Percent1[]="COMMENT";
char Percent2[]="PERCENT";
char Percent3[]="EOL";
char NoPercent1[]="NOCOMMENT";
char NoPercent2[]="NOPERCENT";
char NoPercent3[]="NOEOL";
char EUC1[]="EUC";
char NoEUC1[]="MSKANJI";
char NoEUC2[]="SHIFTJIS";
char Extended1[]="EXTENDED";
char Standard1[]="STANDARD";
char LaTeX1[]="LATEX";
char TeX1[]="MUTEX";
char TeX2[]="TEX";
char One1[]="1000";
char Two1[]="1095";
char Three1[]="1200";
char Four1[]="1440";
char Five1[]="1728";
char Six1[]="2074";
char Seven1[]="2488";
char One2[]="0.0";
char Two2[]="0.5";
char Three2[]="1.0";
char Four2[]="2.0";
char Five2[]="3.0";
char Six2[]="4.0";
char Seven2[]="5.0";
char One3[]="0";
char Three3[]="1";
char Four3[]="2";
char Five3[]="3";
char Six3[]="4";
char Seven3[]="5";
/* Comment line maximum length */
#define CommentLineMax 254
typedef char FileNameType[FileNameDOS+1];
typedef char ExtensionType[ExtensionDOS+1];
typedef char TotalNameType[TotalNameDOS+1];
typedef char ParamType[ParamMax+1];
typedef int FontType[FontMax+1];
typedef FontType FontsType[SizeMax+1];
typedef char CommentLineType[CommentLineMax+2]; /* note the 2 used */
/* Run time parameters */
struct RunTimeType {
FileNameType FileName;
ExtensionType Extension;
int ExtraSpace,Percent,LaTeX,EUC,Extended;
int Size;
};
/* Japanese punctuation information */
struct PunctuationType {
/* Indicates .,!? present */
int OldMajorEOL,NewMajorEOL;
/* Indicates :; present */
int OldMinorEOL,NewMinorEOL;
/* Indicates `"([< and other openings present */
int OldOpening,NewOpening;
/* Indicates '")]> and other closings present */
int OldClosing,NewClosing;
/* Indicates Japanese center dot present */
int OldCenterDot,NewCenterDot;
/* Indicates Hiragana, Katakana, or Kanji present */
int OldJapanese,NewJapanese;
};
/* Scanning Information */
struct ScanningType {
/* Current pass terminated */
int Done;
/* Indicates the current pass must produce output */
int Echo;
/* Indicates the current line is a comment */
int Comment;
/* Indicates current Bitmap immediately followed previous one */
int Immediate;
/* Indicates the last Roman character was a letter or digit */
int WasLetter;
/* Used for glue after a bitmap and before a roman */
int RomanMajorEOL,RomanMinorEOL,RomanOpening;
/* Non-comment Bitmap found */
int Found;
/* Processing the first character on the line which could be % */
int First;
/* Comment line which may contain Bitmaps */
CommentLineType CommentLine;
/* Current JIS24 Bitmap number */
int Bitmap;
/* Roman or first part of Bitmap read */
unsigned char Data1;
};
void Delete(char *String, int Length)
/* Delete the first Length characters of String */
{
int Index;
Index=0;
do String[Index]=String[Index+Length];
while (String[++Index]!='\0');
}
/*----------------------------- EchoParameters ------------------------------*/
void EchoParameters(FILE *EchoFile, struct RunTimeType *RunTime)
/* Echoes the current parameters in EchoFile */
{
fprintf(EchoFile,"File=%s",RunTime->FileName);
if (RunTime->ExtraSpace) fprintf(EchoFile," Space");
else fprintf(EchoFile," No Space");
if (RunTime->Percent) fprintf(EchoFile," Added %%");
else fprintf(EchoFile," No Added %%");
if (RunTime->LaTeX) fprintf(EchoFile," LaTeX");
else fprintf(EchoFile," TeX");
if (RunTime->EUC) fprintf(EchoFile," EUC");
else fprintf(EchoFile," MS-kanji");
if (RunTime->Extended) fprintf(EchoFile," Extended");
else fprintf(EchoFile," Standard");
fprintf(EchoFile," Font Size=");
switch (RunTime->Size) {
case 1:fprintf(EchoFile,"1000"); break;
case 2:fprintf(EchoFile,"1095"); break;
case 3:fprintf(EchoFile,"1200"); break;
case 4:fprintf(EchoFile,"1440"); break;
case 5:fprintf(EchoFile,"1728"); break;
case 6:fprintf(EchoFile,"2074"); break;
case 7:fprintf(EchoFile,"2488"); break;
}
fprintf(EchoFile,".\n");
if (ferror(EchoFile)) exit(1);
}
/*------------------------------ GetParameters ------------------------------*/
void SimpleQuery(char Title[], char ChoiceA[], char ChoiceB[], int *Answer)
{
char JChar[2];
int Valid;
do {
Valid=True;
printf("%s:\n",Title);
printf(" a) %s\n",ChoiceA);
printf(" b) %s\n",ChoiceB);
printf("Your choice? ");
if (ferror(stdout)) exit(1);
if (gets(JChar)==NULL) exit(1);
if (strlen(JChar)>1) exit(1);
JChar[0]=toupper(JChar[0]);
if (JChar[0]=='A') *Answer=True;
else
if (JChar[0]=='B') *Answer=False;
else {
Valid=False;
if (putchar('\7')==EOF) exit(1);
}
} while (!Valid);
printf("\n");
if (ferror(stdout)) exit(