#ifdef MSDOS
#include "stdio.h"
#else
#include <stdio.h>
#endif
#define TRUE 1
#define FALSE 0
main(argc,argv)
int argc;char *argv[];
{
  int lrmode=TRUE,punct=FALSE,mathmode=FALSE; /* lrmode FALSE for Hebrew */
  int cur,delimiter,j;
  char temp[255];
  FILE *fin,*fout;
  if ( argc ^= 2 ) return;
  fin = fopen(*++argv,"r");
  if ( fin == NULL ) return;
  fout = fopen("hebtext.tex","w");
  if (fout == NULL) return;
  printf("This is PreTeX Version 0.9.\n");
  strcpy(temp,"");

#ifdef VMS
while (feof(fin) == NULL) {
     cur = getc(fin);
#else
while((cur=getc(fin)) != EOF) {
#endif
     if (lrmode) { putc(cur,fout); /* This is L2R text */
                   if (cur == '|') lrmode = TRUE - lrmode; }
     else {
            delimiter = TRUE; punct = TRUE;
            switch(cur) {  /* Scan for delimiter */
            case ' ':  punct=FALSE;break;
            case ',':  break;
            case '.':  break;
            case '\\': punct=FALSE;break; /* TeX's backslash */
            case '\n': punct=FALSE;break; /* New line */
            case '|':  punct=FALSE;break;
            case '$':  punct=FALSE;break;
            case ';':  break;
            case '?':  break;
            case '!':  break;
            case ':':  break;
            case '(':  break;
            case ')':  break;
            case '{':  break;
            case '}':  break;
            case '[':  break;
            case ']':  break;
            case '"':  punct=FALSE;break;
            default: delimiter = FALSE; } /* end Switch */


            if (delimiter) { if (punct) { j=strlen(temp); temp[j++]=cur;
                                         temp[j]=0;cur=' ';}

                                  if (strlen(temp) > 0)
                                  { if (mathmode==FALSE) reverse(temp);
                                    for (j=0; j<strlen(temp); j++)
                                               putc(temp[j],fout);
      if ((cur != '\\') && (cur != '\n')) putc('\n',fout);
                                    strcpy(temp,"");}
                                    if(cur != ' ') putc(cur,fout); /* anyway */
                             if (cur == '|') lrmode = TRUE-lrmode; }
               else {j=strlen(temp);temp[j++]=cur;temp[j]=0;}/*Store*/
      if (cur == '$') mathmode= TRUE - mathmode;
                  } }
fclose(fout);
fclose(fin);
return; } /* End main */

reverse(s)
char s[];{int c,i,j;for(i=0,j=strlen(s)-1;i<j;i++,j--){c=s[i];s[i]=s[j];
s[j]=c;}}
