/* Generated by the NeXT Project Builder 
   NOTE: Do NOT change this file -- Project Builder maintains it.
*/

#import <stdlib.h>
#import <sys/param.h>
#import <objc/NXBundle.h>

#include <kpathsea/progname.h>
#import "TeXviewApp.h"


void main(int argc, char *argv[]) {
    char	path[MAXPATHLEN+1];
	string sdir;
	FILE *f;
	char buf[256];
	int n;
		
    kpse_set_progname(argv[0]);

/* GH: To override teTeX's SELFAUTO*, we have to set the 
 *     environment variable TETEXDIR.
 *     - If TETEXDIR is already set (by the user), don't change.
 *     - Run "kpsexpand '$TETEXDIR'" and set TETEXDIR to its output.
 *     - If there was no output, finally set TETEXDIR hardcoded.
 */

	sdir = getenv("TETEXDIR");
	if (!sdir) {
		f=popen("csh -c \"kpsexpand '\\$TETEXDIR'\"","r");
		n=fread(buf,1,256,f);
		if (n>0) {
			buf[n-1]=0;
			sdir=xstrdup(buf);
		} else {
			sdir=xstrdup("/usr/local/tex");
		}
	}
//	fprintf(stderr,"TeXview-kp: SELFAUTODIR was set to %s\n",sdir);
	xputenv("TETEXDIR", sdir);

    
    NXApp = [TeXviewApp new];
    if ([[NXBundle mainBundle] getPath:path forResource:"HyperTeXview" ofType:"nib"])
	if ([NXApp loadNibFile:path owner:NXApp withNames:NO fromZone:[NXApp zone]])
	    [NXApp run];
    [NXApp free];
    exit(0);
}
