
/*
 *   T E X 2 A S C . H
 *                   
 */

/*
 *   Copyright (C) 1993 Konrad Schroder.
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 1, or (at your option)
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef TEX2ASC_H_
#define TEX2ASC_H_

#include <stdio.h>

struct Option {
     int gutenberg;      /* conform to the Gutenberg standard */
     int apply_codes;    /* 0 = strip, 1 = ANSI, 2 = ASCII, 3 = IBM_ANSI */
     int footnote;       /* 0 = strip, 1 = leave, 2 = file, 3 = at end */
     int number_lines;   /* only if mode.countlines */
     int number_sec;     /* 0 = strip, 1 = leave */
     int character_set;  /* 0 = unknown, 1 = IBM, 2 = Mac, 3 = Latin1 */
     int few_cr;         /* 1 = don't end lines with a CR/LF/whatever */
     int greek;          /* 0 = ASCII, 1 = GreekKeys, 2 = WinGreek */
};

enum CODES {
     strip_codes,
     ansi_codes,
     ascii_codes,
     ibm_ansi_codes,
     rtf_codes,
     html_codes,
     html_plus_codes
};

enum GREEK {
     ascii_greek,
     greek_keys,
     win_greek
};

enum FEET {
     strip_notes,
     leave_notes,
     file_notes,
     end_notes
};

enum CHARS {
     ascii_chars,
     ibm_pc_chars,
     mac_chars,
     latin1_chars,
     html_chars
};

enum FONTS {
     ROMAN=0,
     ITALICS=1,
     BOLD=2,
     UNDERLINE=4,
     TELETYPE=8,
     GREEK=16,
     LATIN=32
};

struct k_str {
    unsigned char *str;
    long len;
};

struct direc_and_last {
     int c;
     struct k_str direc;
};

typedef struct Mode {
     int obeylines;
     int countlines;     /* yes implies add line numbers */
     int font;           /* ITALICS | BOLD | GREEK | UNDERLINE; ROMAN=0 */
     int underline;      /* 1 or 0 */
     int superscript;    /* unimplemented */
     int subscript;      /* unimplemented */
     int math_mode;      /* currently pointless */
     int foot_mode;      /* is non-zero in the body of footnotes */
     int tabs[50];       /* positions of tab stops */
     int tab_mode;       /* is non-zero inside tabbed environments */
     int margin;         /* the current margin; usu. either 60 or 75 */
     int leftmargin;     /* usu. zero */
     int chapcount;      /* chapter number */
     int seccount;       /* section number */
     int iseccount;      /* chapter-independent section number */
     int linecount;      /* line number */
} MODE;

struct hash {
     char word[20];
     int val;
     char replace_word[20];
     int has_params;
};

#define ML 1024
#define GOOD_MAL 10240
#define VERSION 1
#define SUBVERSION 3
#define streq(A,B) (strcmp((A),(B))==0)

#define TIE         0x81
#define NOPRINT     0x82
#define NOINDENT    0x83
#define NUMBER      0x84
#define SP_PAR      0x85
#define DISC_NL     0x86
#define RSQ         0x87
#define FLUSH       0x88
#define TEX_CR      0x89
#define TEX_HASH    0x8a

#if (defined __MSDOS__ || defined MSDOS  || defined __TURBOC__)
# define DOS
#endif

#if (defined __THINK__)
# define MAC
# include "MacStuff.h"
# define exit(n) ExitToShell()
# define unlink(X) remove(X)
# define malloc(X) NewPtr(X)
# define free(X)   DisposPtr(X)
#endif

#define is_html() (option.apply_codes==html_codes\
                   || option.apply_codes==html_plus_codes)
#define is_html_plus() (option.apply_codes==html_plus_codes)

int do_file(char *);
void k_zero(struct k_str *);
void output_line(unsigned char *, FILE *, int);
void output(unsigned char *, FILE *);
void resize(struct k_str *);
void output_paragraph(struct k_str *,  FILE *);
char *accent(char, char);
char *chapter(MODE *);
char *section(MODE *);
char *independent_section(MODE *);
void add_str(struct k_str *, unsigned char *);
void cleanup(MODE, MODE, struct k_str *);
int  get_next_char(void);
void add_char(struct k_str *, char);
void c_print(char *);
unsigned char *read_frame(MODE *, int, char);
void usage(void);
int main(int argc, char **argv);
int do_file(char *);

enum DIRECTIVES
{
     D__,
     D_aa,
     D_AA,
     D_ae,
     D_AE,
     D_backslash,
     D_beginsection,
     D_bf,
     D_bigskip,
     D_bye,
     D_centerline,
     D_cr,
     D_dag,
     D_ddag,
     D_end,
     D_footnote,
     D_halign,
     D_hsize,
     D_hskip,
     D_i,
     D_input,
     D_it,
     D_j,
     D_kern,
     D_l,
     D_L,
     D_langle,
     D_ldots,
     D_leftline,
     D_medskip,
     D_noindent,
     D_o,
     D_O,
     D_obeylines,
     D_oe,
     D_OE,
     D_P,
     D_parindent,
     D_parskip,
     D_qquad,
     D_quad,
     D_rangle,
     D_rightline,
     D_rm,
     D_S,
     D_settabs,
     D_sl,
     D_ss,
     D_TeX,
     D_tt,
     D_underbar,
     D_vfill,
     D_vsize,
     D_vskip,
     D_alpha,
     D_beta,
     D_gamma,
     D_delta,
     D_epsilon,
     D_zeta,
     D_eta,
     D_theta,
     D_iota,
     D_kappa,
     D_lambda,
     D_mu,
     D_nu,
     D_xi,
     D_omicron,
     D_pi,
     D_rho,
     D_sigma,
     D_tau,
     D_upsilon,
     D_phi,
     D_chi,
     D_psi,
     D_omega,
     D_Gamma,
     D_Delta,
     D_Theta,
     D_Lambda,
     D_Xi,
     D_Pi,
     D_Sigma,
     D_Upsilon,
     D_Phi,
     D_Psi,
     D_Omega,

     S_chap,
     S_docversion,
     S_eg,
     S_emdash,
     S_endash,
     S_fnote,
     S_grbf,
     S_greek,
     S_head,
     S_introsec,
     S_isec,
     S_lbf,
     S_linesbyfive,
     S_lit,
     S_lrm,
     S_note,
     S_personae,
     S_poetrysize,
     S_pounds,      /* pounds is a legitimate TeX symbol---but not an */
                    /* escape sequence.                               */
     S_sec,
     S_section,
     S_subsec,
     S_subhead,
     S_superhead,
     S_xref,

     NONE_SUCH
};

#endif /* TEX2ASC_H_ */








