source: trunk/src/peldr/pe.cpp@ 4

Last change on this file since 4 was 4, checked in by ktk, 26 years ago

Import

File size: 3.7 KB
Line 
1/* $Id: pe.cpp,v 1.1 1999-05-24 20:19:57 ktk Exp $ */
2
3/*
4 *
5 * Project Odin Software License can be found in LICENSE.TXT
6 *
7 */
8/*
9 * PELDR main exe loader code
10 *
11 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
12 *
13 */
14#define INCL_DOSFILEMGR /* File Manager values */
15#define INCL_DOSERRORS /* DOS Error values */
16#define INCL_DOSPROCESS /* DOS Process values */
17#define INCL_DOSMISC /* DOS Miscellanous values */
18#define INCL_WIN
19#include <os2.h>
20#include <stdio.h>
21#include <string.h>
22#include <stdlib.h>
23#include <string.h>
24#include <assert.h>
25#include "win32type.h"
26#include "misc.h"
27#include "winexe.h"
28#include "windll.h"
29
30char INFO_BANNER[] = "Usage: PE winexe commandline";
31char szErrorTitle[] = "Win32 for OS/2";
32char szMemErrorMsg[] = "Memory allocation failure";
33char szFileErrorMsg[] = "File IO error";
34char szPEErrorMsg[] = "Not a valid win32 exe. (perhaps 16 bits windows)";
35char szCPUErrorMsg[] = "Executable doesn't run on x86 machines";
36char szExeErrorMsg[] = "File isn't an executable";
37char szInteralErrorMsg[]= "Internal Error";
38
39char fullpath[CCHMAXPATH];
40
41void UpCase(char *mixedcase);
42
43int main(int argc, char *argv[])
44{
45 HAB hab; /* PM anchor block handle */
46 HMQ hmq; /* Message queue handle */
47 char *szCmdLine;
48 char exeName[CCHMAXPATH];
49 PPIB ppib;
50 PTIB ptib;
51 Win32Exe *WinExe;
52 APIRET rc;
53
54 if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
55 return(1);
56
57 hmq = WinCreateMsgQueue(hab, 0);
58
59 if(argc < 2) {
60 WinMessageBox(HWND_DESKTOP, NULL, INFO_BANNER, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
61 return(0);
62 }
63
64 strcpy(exeName, argv[1]);
65 UpCase(exeName);
66 if(strstr(exeName, ".EXE") == NULL) {
67 strcat(exeName, ".EXE");
68 }
69 WinExe = new Win32Exe(exeName);
70 if(WinExe == NULL) {
71 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
72 return(1);
73 }
74 rc = DosGetInfoBlocks(&ptib, &ppib);
75 if(rc) {
76 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szInteralErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
77 delete WinExe;
78 return(1);
79 }
80 szCmdLine = ppib->pib_pchcmd;
81 while(*szCmdLine == ' ' && *szCmdLine ) //skip leading spaces
82 szCmdLine++;
83 while(*szCmdLine != ' ' && *szCmdLine ) //skip pe (.exe)
84 szCmdLine++;
85 while(*szCmdLine == ' ' && *szCmdLine ) //skip spaces
86 szCmdLine++;
87
88 ULONG curdisk, curlogdisk, flength = CCHMAXPATH;
89
90 DosQueryCurrentDisk(&curdisk, &curlogdisk);
91 DosQueryCurrentDir(curdisk, &fullpath[3], &flength);
92 fullpath[0] = 'A' + (curdisk-1);
93 fullpath[1] = ':';
94 fullpath[2] = '\\';
95 strcat(fullpath, "\\");
96 strcat(fullpath, exeName);
97 WinExe->setFullPath(fullpath);
98 WinExe->setCommandLine(szCmdLine);
99
100 if(WinExe->init() == FALSE) {
101 delete WinExe;
102 return(1);
103 }
104 WinExe->start();
105 delete WinExe;
106
107 if(hmq) WinDestroyMsgQueue( hmq ); /* Tidy up... */
108 WinTerminate( hab ); /* Terminate the application */
109 return(0);
110}
111//******************************************************************************
112//******************************************************************************
113void UpCase(char *mixedcase)
114{
115 int i;
116
117 for(i=0;i<strlen(mixedcase);i++) {
118 if(mixedcase[i] >= 'a' && mixedcase[i] <= 'z') {
119 mixedcase[i] += 'A' - 'a';
120 }
121 }
122}
123//******************************************************************************
124//******************************************************************************
Note: See TracBrowser for help on using the repository browser.