Back to index

tetex-bin  3.0
winmain.c
Go to the documentation of this file.
00001 /*
00002  * dvips - winmain.c
00003  *   This module is Copyright 1992 by Russell Lang and Maurice Castro.
00004  *   This file may be freely copied and modified.
00005  */
00006 
00007 #include <windows.h>
00008 #include <dos.h>
00009 #include <stdio.h>
00010 #include <string.h>
00011 
00012 /* local */
00013 #define MAXSTR 255
00014 HWND FAR hwndeasy;
00015 static char FAR szAppName[] = "dvips";
00016 char winline[MAXSTR];       /* command line for MS-Windows */
00017 int wargc;           /* argc for windows */
00018 char *wargv[32];     /* argv for windows */
00019 
00020 /* external */
00021 extern void help();  /* in dvips.c */
00022 extern void error(); /* in dvips.c */
00023 
00024 /* EasyWin */
00025 extern POINT _ScreenSize;
00026 
00027 int main(int argc, char *argv[], char *env[]);
00028 
00029 /* A fake system() for Microsoft Windows */
00030 int
00031 system(command)
00032 char *command;
00033 {
00034 char str[MAXSTR];
00035    strcpy(str,"Windows can't do system(\042");
00036    if (command) {
00037      strncat(str,command,MAXSTR-strlen(str));
00038    }
00039    strncat(str,"\042);",MAXSTR-strlen(str));
00040    error(str);
00041    return(1);  /* error */
00042 }
00043 
00044 /* Get a new command line */
00045 void
00046 winargs()
00047 {
00048    fputs("Options: ",stdout);
00049    fgets(winline,MAXSTR,stdin);
00050    wargc=1;
00051    if ( (wargv[1] = strtok(winline," \n")) != (char *)NULL ) {
00052       wargc=2;
00053       while ( ((wargv[wargc] = strtok((char *)NULL," \n")) != (char *)NULL)
00054             && (wargc < 31) )
00055          wargc++;
00056    }
00057    wargv[wargc] = (char *)NULL;
00058 }
00059 
00060 int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
00061               LPSTR lpszCmdLine, int cmdShow)
00062 {
00063        char modulename[MAXSTR];
00064 
00065         /* start up the text window */
00066        _ScreenSize.y = 50;
00067        _InitEasyWin();
00068 
00069        /* fix up the EasyWindows window provided by Borland */
00070        GetModuleFileName(hInstance, (LPSTR) modulename, MAXSTR);
00071        hwndeasy = FindWindow("BCEasyWin", modulename);
00072        SetWindowText(hwndeasy, szAppName);            /* change title */
00073        SetClassWord(hwndeasy, GCW_HICON, LoadIcon(hInstance, "RadicalEye")); /* change icon */
00074 
00075        if (_argc==1) {
00076               /* get new command line if no options or filenames */
00077               help();
00078               winargs();
00079               wargv[0] = _argv[0];
00080               _argc=wargc;
00081               _argv=wargv;
00082        }
00083 
00084        main(_argc, _argv, environ);
00085        /* unfortunately dvips doesn't return from main(), it exits */
00086        /* so the following code is never executed */
00087        DestroyWindow(hwndeasy);
00088        return 0;
00089 }