| 1 | #include <stdlib.h> | 
|---|
| 2 | #include <stdio.h> | 
|---|
| 3 | #include <string.h> | 
|---|
| 4 |  | 
|---|
| 5 | #define INCL_PM | 
|---|
| 6 | #include <os2.h> | 
|---|
| 7 |  | 
|---|
| 8 | #include "Viewer.h" | 
|---|
| 9 | #include "log.h" | 
|---|
| 10 |  | 
|---|
| 11 | char* pszViewerFilename = "view.exe"; | 
|---|
| 12 | char* OWN_HELP_MARKER = "[NVHELP]"; | 
|---|
| 13 |  | 
|---|
| 14 | BOOL StartViewer( char* pszParameters, | 
|---|
| 15 | HWND hTerminateNotify, | 
|---|
| 16 | HWND hAppWindow, | 
|---|
| 17 | HAB hab ) | 
|---|
| 18 | { | 
|---|
| 19 | PROGDETAILS Details; | 
|---|
| 20 | char pszMessageCaption[ 1024 ]; | 
|---|
| 21 | HAPP hApplication; | 
|---|
| 22 | BOOL result; | 
|---|
| 23 |  | 
|---|
| 24 | Details.Length                      = sizeof(PROGDETAILS); | 
|---|
| 25 | Details.progt.progc                 = PROG_PM; | 
|---|
| 26 | Details.progt.fbVisible             = SHE_VISIBLE; | 
|---|
| 27 | Details.pszTitle                    = "Help Viewer"; | 
|---|
| 28 | Details.pszExecutable               = pszViewerFilename; | 
|---|
| 29 | Details.pszParameters               = pszParameters; | 
|---|
| 30 | Details.pszStartupDir               = ""; | 
|---|
| 31 | Details.pszIcon                     = NULL; // default app icon | 
|---|
| 32 | Details.pszEnvironment              = NULL; | 
|---|
| 33 | Details.swpInitial.fl               = SWP_ACTIVATE; | 
|---|
| 34 | Details.swpInitial.cy               = 0; | 
|---|
| 35 | Details.swpInitial.cx               = 0; | 
|---|
| 36 | Details.swpInitial.y                = 0; | 
|---|
| 37 | Details.swpInitial.x                = 0; | 
|---|
| 38 | Details.swpInitial.hwndInsertBehind = HWND_TOP; | 
|---|
| 39 | Details.swpInitial.hwnd             = hAppWindow; | 
|---|
| 40 | Details.swpInitial.ulReserved1      = 0; | 
|---|
| 41 | Details.swpInitial.ulReserved2      = 0; | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | LogEvent( "Launching: %s %s", | 
|---|
| 45 | Details.pszExecutable, | 
|---|
| 46 | pszParameters ); | 
|---|
| 47 |  | 
|---|
| 48 | hApplication = | 
|---|
| 49 | WinStartApp( hTerminateNotify,    // window to be notified of termination | 
|---|
| 50 | & Details,           // details | 
|---|
| 51 | NULL,                // parameters - used Details | 
|---|
| 52 | NULL,                // reserved | 
|---|
| 53 | SAF_INSTALLEDCMDLINE ); // options | 
|---|
| 54 |  | 
|---|
| 55 | if ( hApplication == NULL ) | 
|---|
| 56 | { | 
|---|
| 57 | LogEvent( "  Failed to launch viewer, rc=%8X", | 
|---|
| 58 | WinGetLastError( hab ) ); | 
|---|
| 59 | sprintf( pszMessageCaption, | 
|---|
| 60 | "Unable to start help viewer %s", | 
|---|
| 61 | pszViewerFilename ); | 
|---|
| 62 | WinMessageBox( HWND_DESKTOP, // parent | 
|---|
| 63 | hAppWindow,   // owner | 
|---|
| 64 | pszMessageCaption, | 
|---|
| 65 | "Help Error", // title | 
|---|
| 66 | 0,            // ID | 
|---|
| 67 | MB_OK | MB_WARNING | MB_MOVEABLE ); | 
|---|
| 68 | result = FALSE; | 
|---|
| 69 | } | 
|---|
| 70 | else | 
|---|
| 71 | { | 
|---|
| 72 | result = TRUE; | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | free( pszParameters ); | 
|---|
| 76 | return result; | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | // appends the given filenames to the output string, | 
|---|
| 80 | // replace spaces between filenames with a + | 
|---|
| 81 | // and stripping redundant spaces. | 
|---|
| 82 | void ModifyFilenames( char* Filenames, | 
|---|
| 83 | char* Output ) | 
|---|
| 84 | { | 
|---|
| 85 | BOOL First; | 
|---|
| 86 | BOOL InQuote; | 
|---|
| 87 | char QuoteChar; | 
|---|
| 88 |  | 
|---|
| 89 | First = TRUE; | 
|---|
| 90 | InQuote = FALSE; | 
|---|
| 91 | while ( *Filenames != 0 ) | 
|---|
| 92 | { | 
|---|
| 93 | // skip spaces | 
|---|
| 94 | while (    *Filenames != 0 | 
|---|
| 95 | && *Filenames == ' ' ) | 
|---|
| 96 | Filenames ++; | 
|---|
| 97 |  | 
|---|
| 98 | // add a plus sign (+), after first word | 
|---|
| 99 | if (    ! First | 
|---|
| 100 | && *Filenames != 0 ) | 
|---|
| 101 | { | 
|---|
| 102 | * Output = '+'; | 
|---|
| 103 | Output ++; | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | First = FALSE; | 
|---|
| 107 | // copy non-space characters | 
|---|
| 108 | // or all characters if in quotes | 
|---|
| 109 | while (    *Filenames != 0 | 
|---|
| 110 | && ( *Filenames != ' ' || InQuote ) ) | 
|---|
| 111 | { | 
|---|
| 112 | * Output = *Filenames; | 
|---|
| 113 | if ( ! InQuote ) | 
|---|
| 114 | { | 
|---|
| 115 | if (    *Filenames == '\'' | 
|---|
| 116 | || *Filenames == '\"' ) | 
|---|
| 117 | { | 
|---|
| 118 | InQuote = TRUE; | 
|---|
| 119 | QuoteChar = *Filenames; | 
|---|
| 120 | * Output = '\"'; // change singles to doubles | 
|---|
| 121 | } | 
|---|
| 122 | } | 
|---|
| 123 | else | 
|---|
| 124 | { | 
|---|
| 125 | if ( *Filenames == QuoteChar ) | 
|---|
| 126 | { | 
|---|
| 127 | InQuote = FALSE; | 
|---|
| 128 | * Output = '\"'; // change singles to doubles | 
|---|
| 129 | } | 
|---|
| 130 | } | 
|---|
| 131 |  | 
|---|
| 132 | Output ++; | 
|---|
| 133 | Filenames ++; | 
|---|
| 134 | } | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | // null terminate | 
|---|
| 138 | *Output = 0; | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 | BOOL ViewHelpFile( char* pszHelpFileName, | 
|---|
| 142 | char* pszWindowTitle, | 
|---|
| 143 | HWND hHelpWindow, | 
|---|
| 144 | HWND hAppWindow, | 
|---|
| 145 | HAB hab ) | 
|---|
| 146 | { | 
|---|
| 147 | char* pszParameters; | 
|---|
| 148 |  | 
|---|
| 149 | // set up viewer parameters: | 
|---|
| 150 | // <helpfilename> /hm:<helpwindow> | 
|---|
| 151 | // currently not used: /owner:<ownerwindow> | 
|---|
| 152 |  | 
|---|
| 153 | pszParameters = (char*) malloc(   strlen( pszHelpFileName ) | 
|---|
| 154 | + strlen( pszWindowTitle ) | 
|---|
| 155 | + 512 ); | 
|---|
| 156 |  | 
|---|
| 157 | sprintf( pszParameters, | 
|---|
| 158 | "/hm:%u ", | 
|---|
| 159 | hHelpWindow ); | 
|---|
| 160 |  | 
|---|
| 161 | if ( pszHelpFileName != NULL ) | 
|---|
| 162 | { | 
|---|
| 163 | // add (modified) filenames to parameters | 
|---|
| 164 | ModifyFilenames( pszHelpFileName, | 
|---|
| 165 | pszParameters + strlen( pszParameters ) ); | 
|---|
| 166 | } | 
|---|
| 167 |  | 
|---|
| 168 | if ( pszWindowTitle != NULL ) | 
|---|
| 169 | { | 
|---|
| 170 | // add window title parameter | 
|---|
| 171 | strcat( pszParameters, " \"/title:" ); | 
|---|
| 172 | strcat( pszParameters, pszWindowTitle ); | 
|---|
| 173 | strcat( pszParameters, "\"" ); | 
|---|
| 174 | } | 
|---|
| 175 |  | 
|---|
| 176 | return StartViewer( pszParameters, | 
|---|
| 177 | hHelpWindow, | 
|---|
| 178 | hAppWindow, | 
|---|
| 179 | hab ); | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 | void ViewHelpOnHelp( HAB hab ) | 
|---|
| 183 | { | 
|---|
| 184 | StartViewer( OWN_HELP_MARKER, | 
|---|
| 185 | NULL, | 
|---|
| 186 | NULL, | 
|---|
| 187 | hab ); | 
|---|
| 188 | } | 
|---|
| 189 |  | 
|---|