ftp.nice.ch/pub/next/text/framemaker/filters/la2mml.tar.gz#/main.c

This is main.c in view mode; [Download] [Up]

/* main.c */

/*
 * Copyright (c) 1991  R. Nigel Horspool.
 * All rights reserved.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

/*
    AUTHOR:
	R. Nigel Horspool

    ADDRESS:
	Dept. of Computer Science
	University of Victoria
	P.O. Box 3055
	BC, Canada  V8W 3P6

	nigelh@csr.uvic.ca   nigelh@uvunix.bitnet

    TELEPHONE:
	(604) 721 7227

    FAX:
	(604) 721 7292

*/


#include <stdio.h>
#ifdef THINK_C
#include <stdlib.h>
#include <console.h>
#define TEMP1 ".temp1"
#else
extern char *malloc(unsigned int), *strcpy(char *,char *),
	*mktemp(char *);
#define TEMP1 "/tmp/LAaXXXXXX"
#endif
#include "tables.h"
#include "lexer.h"
#include "output.h"
#include "mml-defs.h"
#include "la2mml.h"

static char *pgmname;


BOOL check_file( char *fname, char *printname ) {
    if (fname != NULL) {
	f = fopen( fname, "r" );
	if (f == NULL) {
	    FPR(stderr, "Unable to open file: %s\n", fname );
	    numreports++;
	    return FALSE;
	}
    } else
	f = stdin;
    filename = printname;

    linenum = 0;  ch = '\n';
    while( ch != EOF)
	match_grouping( EOFCMD );
    if (f != stdin)
	(void)fclose(f);
    return TRUE;
}


void setsuffix( char *inname, char *newsuffix ) {
    register char *cp;
    char *outp;
    char *dotpos = NULL;

    outp = outputfilename =
	malloc( strlen(inname) + strlen(newsuffix) + 1 );
    
    for( cp = inname;  *cp != '\0';  cp++ ) {
	if (*cp == '/') {
	    outp = outputfilename;
	    dotpos = NULL;
	    continue;
	}
	if (*cp == '.') dotpos = outp;
	*outp++ = *cp;
    }
    if (dotpos != NULL) outp = dotpos;
    for( cp = newsuffix;  *outp++ = *cp++;  )
	;
    
}


void usage() {
    FPR(stderr, "Usage:  %s [-A] [-U] [filename]\n", pgmname );
    FPR(stderr, "    -A\tforce all paragraph styles to be defined\n" );
    FPR(stderr, "    -U\tlist unconverted LaTeX commands on stderr\n" );
    FPR(stderr, "*or*\n        %s -v\n", pgmname );
    FPR(stderr, "    Display version number and exit\n" );
    exit(1);
}


void main( int argc, char *argv[] ) {
    register int i;
    register char *cp;
    char *fn = NULL;
    int exitcode;
    BOOL alldefs = FALSE;
    FILE *TF;
    char *tempf;

#ifdef THINK_C
    argc = ccommand( &argv );
#endif
    pgmname = argv[0];

    initialize_lexer();

    for( i = 1;  i < argc;  i++ ) {
	cp = argv[i];
	if (cp[0] == '-') {
	    if (cp[1] == 'A') {	/* force out all paragraph formats */
		alldefs = TRUE;
		continue;
	    }
	    if (cp[1] == 'U') {	/* output unprocessed command names */
		unknowns = TRUE;
		continue;
	    }
	    if (cp[1] == 'v') { /* output version number and quit */
		FPR(stderr, "La2MML Version %s\n", VERSION );
		exit(0);
	    }
	    usage();
	}
	if (fn != NULL)
	    usage();
	else
	    fn = cp;
    }

    /* perform translation, send result to a temporary file */
    tempf = malloc( strlen(TEMP1)+1 );
    (void)strcpy( tempf, TEMP1 );
#ifndef THINK_C
    (void)mktemp( tempf );
#endif
    OF = fopen( tempf, "w+" );
    if (OF == NULL) OOPS( tempf );

    curr_matching_mode = PARA;
    (void)GProc( "%<Body>" );
    exitcode = check_file( fn, fn == NULL? "<stdin>" : fn );

    close_tempfile();
    rewind(OF);
    TF = OF;

    if (fn == NULL) {
	OF = stdout;
	outputfilename = "<<stdout>>";
    } else {
	setsuffix( fn, ".mml" );
	OF = fopen( outputfilename, "w" );
	if (OF == NULL)
	    OOPS(outputfilename);
    }

    /* write para & char format definitions to output file */
    write_header( OF );
    write_defs( OF, alldefs );

    /* transfer translated material to output file */
    for( ; ; ) {
	register int ch;
	ch = getc(TF);
	if (ch == EOF) break;
	putc(ch, OF );
    }
    fclose(OF);
    fclose(TF);
    unlink(tempf);

    exit( exitcode == FALSE );
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.