Changeset 26 for branches/1.0/src
- Timestamp:
- Apr 19, 2010, 5:34:31 PM (15 years ago)
- Location:
- branches/1.0/src
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/src/makefile.kmk
r23 r26 27 27 uni.def \ 28 28 uni.c \ 29 utils.c 29 utils.c \ 30 splpd.c 30 31 31 32 # english source -
branches/1.0/src/uni.c
r25 r26 1 1 #define LINT_ARGS /* argument checking enabled */ 2 2 3 #define INCL_DOS4 #define INCL_GPI5 #undef INCL_GPI6 #define INCL_DEV7 #define INCL_DOSMEMMGR /* Include standard OS/2 support */8 #define INCL_DOSMODULEMGR /* For DosLoadModule */9 #define INCL_DOSPROCESS10 #define INCL_GPILCIDS11 #define INCL_WINCOMMON /* Include Window Management support */12 #define INCL_WINDOWMGR13 #define INCL_WINSWITCHLIST14 #define INCL_WINPROGRAMLIST15 #define INCL_WINMENUS16 #define INCL_WINWINDOWMGR17 #define INCL_WINMESSAGEMGR18 #define INCL_WINDIALOGS19 #define INCL_WINSTATICS20 #define INCL_WINLISTBOXES21 #define INCL_WINMENUS22 #define INCL_WINSYS23 #define INCL_WINFRAMEMGR24 #define INCL_INCLWINACCELERATORS25 #define INCL_WINPOINTERS26 #define INCL_WINERRORS27 #define INCL_WINSHELLDATA28 29 #define INCL_WINTYPES30 #define INCL_WINACCELERATORS31 #define INCL_WINBUTTONS32 #define INCL_WINENTRYFIELDS33 #define INCL_WINRECTANGLES34 #define INCL_WINTIMER35 #define INCL_WINSCROLLBARS36 #define INCL_WINHEAP37 #define INCL_SHLERRORS38 #define INCL_WININPUT39 #define INCL_WINHELP40 #define INCL_WINSTDSPIN41 42 #define INCL_SPL43 #define INCL_SPLP44 #define INCL_SPLERRORS45 #define INCL_SHLERRORS46 #define INCL_DOSERRORS47 #define INCL_WINHOOKS48 3 49 4 int acrtused=1; /* Define variable to say this is a DLL */ 50 5 51 #include <os2.h>6 #include "uni.h" 52 7 53 8 #include <stdlib.h> … … 57 12 #include <stdio.h> 58 13 #include <stdlib.h> 59 #include <process.h>60 #include "uni.h"61 14 #include "utils.h" 62 15 63 //64 // If port driver is not defined in INI file yet65 // assume it exists in the boot drive's \OS2\DLL directory66 //67 68 CHAR szDefaultPortDrvPath[] = { PATH_UNI_PDR };69 70 71 //72 // Below definition of PORTNAMES structure should be defined in73 // common header file pmspl.h.74 //75 76 typedef struct _PORTNAMES77 {78 PSZ pszPortName; /* -> name of port(ie "LPT1) */79 PSZ pszPortDesc; /* -> description of port(ie "Parallel Port 1") */80 } PORTNAMES, *PPORTNAMES;81 82 /* Alex Taylor's new version of lprtok() that can handle missing fields */83 char * lprtok (char *string,char *control)84 {85 char *c;86 static char *next;87 88 if ( control == NULL ) return string;89 if ( string == NULL ) string = next;90 if ( string == NULL ) return NULL;91 92 if (( c = strpbrk( string, control )) == NULL ) {93 next = NULL;94 }95 else {96 next = c+1;97 *c = '\0';98 }99 100 return ( string );101 }102 16 MRESULT EXPENTRY CommDlg( HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2 ) 103 17 { 104 P LPRDATA pLprData;18 PUNIDATA pUniData; 105 19 ULONG ulTimeOut = 0 ; 106 20 CHAR szDesc[ STR_LEN_PORTDESC ]; … … 117 31 case WM_INITDLG: 118 32 // WinSendDlgItemMsg(hDlg,ID_BINARY,BM_SETCHECK,MPFROM2SHORT(1,0),NULL); 119 p LprData = (PLPRDATA)mp2;120 WinSetWindowULong (hDlg, QWL_USER, (ULONG)p LprData);33 pUniData = (PUNIDATA)mp2; 34 WinSetWindowULong (hDlg, QWL_USER, (ULONG)pUniData); 121 35 if (PrfQueryProfileString (HINI_SYSTEMPROFILE, 122 p LprData->pszAppName,36 pUniData->pszAppName, 123 37 KEY_DESCRIPTION, 124 38 NULL, … … 127 41 { 128 42 WinSetWindowText (WinWindowFromID (hDlg, (USHORT)IDD_UNI),szDesc); 129 rc = WinLoadString(p LprData->hAB,130 p LprData->hModule,43 rc = WinLoadString(pUniData->hAB, 44 pUniData->hModule, 131 45 PDR_ID_PROPERTIES, 132 46 STR_LEN_PORTDESC, szTemp); 133 47 if (rc) { 134 strcpy ( szTitle, p LprData->pszPortName );48 strcpy ( szTitle, pUniData->pszPortName ); 135 49 strcat ( szTitle, " - " ); 136 50 strcat ( szTitle, szTemp ); … … 139 53 } 140 54 if (PrfQueryProfileString (HINI_SYSTEMPROFILE, 141 p LprData->pszAppName,55 pUniData->pszAppName, 142 56 KEY_INITIALIZATION, 143 57 NULL, … … 171 85 172 86 case WM_COMMAND: 173 p LprData = (PLPRDATA)WinQueryWindowULong (hDlg, QWL_USER);87 pUniData = (PUNIDATA)WinQueryWindowULong (hDlg, QWL_USER); 174 88 switch (SHORT1FROMMP(mp1)) 175 89 { … … 178 92 /* Program */ 179 93 WinQueryDlgItemText (hDlg, ID_PROGRAM, sizeof(szTemp), szTemp ); 180 strcat(p LprData->szSaveLprSetting,szTemp);181 strcat(p LprData->szSaveLprSetting,"#");94 strcat(pUniData->szSaveLprSetting,szTemp); 95 strcat(pUniData->szSaveLprSetting,"#"); 182 96 183 97 if (strlen(szTemp) > 0) { … … 190 104 /* Parameters */ 191 105 WinQueryDlgItemText (hDlg, ID_PARAMETERS, sizeof(szTemp), szTemp ); 192 strcat(p LprData->szSaveLprSetting,szTemp);193 strcat(p LprData->szSaveLprSetting,"#");106 strcat(pUniData->szSaveLprSetting,szTemp); 107 strcat(pUniData->szSaveLprSetting,"#"); 194 108 195 109 if (strlen(szTemp) > 0) { … … 202 116 /* Working directory */ 203 117 WinQueryDlgItemText (hDlg, ID_DIRECTORY, sizeof(szTemp), szTemp ); 204 strcat(p LprData->szSaveLprSetting,szTemp);205 /* strcat(p LprData->szSaveLprSetting,"#"); */118 strcat(pUniData->szSaveLprSetting,szTemp); 119 /* strcat(pUniData->szSaveLprSetting,"#"); */ 206 120 207 121 /* if (strlen(szTemp) > 0) { … … 211 125 /* Username */ 212 126 /* WinQueryDlgItemText (hDlg, ID_USER, sizeof(szTemp), szTemp ); 213 strcat(p LprData->szSaveLprSetting,"#");214 strcat(p LprData->szSaveLprSetting,szTemp); */127 strcat(pUniData->szSaveLprSetting,"#"); 128 strcat(pUniData->szSaveLprSetting,szTemp); */ 215 129 /* Number of copies */ 216 130 /* WinQueryDlgItemText (hDlg, ID_COPIES, sizeof(szTemp), szTemp ); 217 strcat(p LprData->szSaveLprSetting,"#");218 strcat(p LprData->szSaveLprSetting,szTemp); */131 strcat(pUniData->szSaveLprSetting,"#"); 132 strcat(pUniData->szSaveLprSetting,szTemp); */ 219 133 /* Password - must be the last item! */ 220 134 /* WinQueryDlgItemText (hDlg, ID_PASSWORD, sizeof(szTemp), szTemp ); 221 strcat(p LprData->szSaveLprSetting,"#");135 strcat(pUniData->szSaveLprSetting,"#"); 222 136 strcpy(pwBuffer,szTemp); 223 137 encryptPassword(pwBuffer,szTemp); 224 strcat(p LprData->szSaveLprSetting,szTemp);138 strcat(pUniData->szSaveLprSetting,szTemp); 225 139 */ 226 140 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 227 p LprData->pszAppName,141 pUniData->pszAppName, 228 142 KEY_INITIALIZATION, 229 p LprData->szSaveLprSetting))143 pUniData->szSaveLprSetting)) 230 144 WinDismissDlg(hDlg, MBID_CANCEL); 231 145 232 146 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 233 147 APPNAME_PM_SPOOLER_PORT, 234 p LprData->pszPortName,235 p LprData->szSaveLprSetting))148 pUniData->pszPortName, 149 pUniData->szSaveLprSetting)) 236 150 WinDismissDlg(hDlg, MBID_CANCEL); 237 151 238 152 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 239 p LprData->pszAppName,153 pUniData->pszAppName, 240 154 KEY_DESCRIPTION, 241 155 szDesc )) … … 255 169 return FALSE; 256 170 } 257 ULONG CalcStructLength ( HAB hab,258 HMODULE hModule,259 USHORT usID )260 {261 ULONG cbRequired;262 CHAR chString[STR_LEN_PORTDESC];263 171 264 cbRequired = 0; 265 266 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chString); 267 cbRequired += strlen (chString) + 1; 268 WinLoadString(hab, hModule, (USHORT)(usID + 1), STR_LEN_PORTDESC, chString); 269 cbRequired += strlen (chString) + 1; 270 cbRequired += sizeof (PORTNAMES); 271 return(cbRequired); 272 } 273 274 ULONG CalcBufLength ( HAB hab, 275 HMODULE hModule ) 276 { 277 ULONG cbRequired; 278 USHORT usID; 279 280 cbRequired = 0; 281 282 /* 283 ** calculate length required to fit all the port info. 284 */ 285 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 286 { 287 cbRequired += CalcStructLength (hab, hModule, usID); 288 } 289 290 return(cbRequired); 291 } 292 293 ULONG NumPortsCanFit ( HAB hab, 294 HMODULE hModule, 295 ULONG cbBuf ) 296 { 297 ULONG cbRequired; 298 USHORT usID; 299 ULONG ulNumPort; 300 301 cbRequired = 0; 302 ulNumPort = 0; 303 304 /* 305 ** calculate how many ports we can fit in buf. 306 */ 307 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 308 { 309 cbRequired += CalcStructLength (hab, hModule, usID); 310 if (cbRequired > cbBuf) 311 { 312 return(ulNumPort); 313 } 314 ulNumPort++; 315 } 316 317 return(ulNumPort); 318 } 319 VOID CopyStruct ( HAB hab, 320 HMODULE hModule, 321 USHORT usID, 322 PCH pBuf, 323 PULONG pulBeginStruct, 324 PULONG pulBeginText ) 325 { 326 PPORTNAMES pPortNames; 327 328 pPortNames = (PPORTNAMES)(pBuf + *pulBeginStruct); 329 *pulBeginStruct += sizeof (PORTNAMES); 330 331 /* 332 ** copy port name in the structure 333 */ 334 pPortNames->pszPortName = pBuf + *pulBeginText; 335 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName); 336 *pulBeginText += strlen (pPortNames->pszPortName) + 1; 337 338 /* 339 ** copy port description to the structure 340 */ 341 pPortNames->pszPortDesc = pBuf + *pulBeginText; 342 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortDesc); 343 *pulBeginText += strlen (pPortNames->pszPortDesc) + 1; 344 } 345 VOID CopyNPorts ( HAB hab, 346 HMODULE hModule, 347 PCH pBuf, 348 ULONG ulReturned ) 349 { 350 USHORT usID; 351 ULONG ulBeginText; 352 ULONG ulBeginStruct; 353 354 ulBeginText = ulReturned * sizeof (PORTNAMES); 355 ulBeginStruct = 0; 356 357 for (usID = PORT_ID_FIRST; 358 usID <= PORT_ID_LAST && ulReturned; 359 usID += 2, --ulReturned) 360 { 361 CopyStruct (hab, hModule, usID, pBuf, &ulBeginStruct, &ulBeginText); 362 } 363 } 364 365 ULONG OpenLprPortDlg ( HAB hab, 172 ULONG OpenUniPortDlg ( HAB hab, 366 173 HMODULE hModule, 367 174 PSZ pszPortName, 368 175 PSZ pszAppName ) 369 176 { 370 LPRDATA LprData;177 UNIDATA UniData; 371 178 372 memset (& LprData, 0, sizeof (LPRDATA));373 LprData.hAB = hab;374 LprData.hModule = hModule;375 LprData.pszPortName = pszPortName;376 LprData.pszAppName = pszAppName;179 memset (&UniData, 0, sizeof (UNIDATA)); 180 UniData.hAB = hab; 181 UniData.hModule = hModule; 182 UniData.pszPortName = pszPortName; 183 UniData.pszAppName = pszAppName; 377 184 378 185 WinDlgBox (HWND_DESKTOP, … … 381 188 (HMODULE)hModule, 382 189 IDD_UNI, 383 & LprData);190 &UniData); 384 191 385 return LprData.lfModified; 386 } 387 BOOL GetPortDescription ( HAB hab, 388 HMODULE hModule, 389 PSZ pszPortName, 390 PSZ pszPortDesc ) 391 { 392 USHORT usID; 393 CHAR chBuf[STR_LEN_PORTDESC] = {0}; 394 395 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 396 { 397 WinLoadString(hab, hModule, usID, STR_LEN_PORTNAME, chBuf); 398 if (!strcmp (pszPortName, chBuf)) 399 { 400 if ( WinLoadString(hab, hModule, usID+1, STR_LEN_PORTDESC, chBuf) ) { 401 strcpy (pszPortDesc, chBuf); 402 return(TRUE); 403 } 404 break; 405 } 406 } 407 return(FALSE); 408 } 409 BOOL GenerateUniquePortName( PSZ pszPortName ) 410 { 411 BOOL fPortExists; 412 PSZ pszEndPortName; 413 USHORT i; 414 CHAR chPortData[STR_LEN_PORTNAME]; 415 416 /* 417 ** Generate a unique port name by adding numbers to the 418 ** end of pszPortName 419 */ 420 pszEndPortName = pszPortName + strlen( pszPortName ); 421 i = 1; 422 fPortExists = TRUE; 423 while ( (i < MAX_PORTS) && fPortExists ) 424 { 425 _itoa( i, pszEndPortName, 4); 426 fPortExists = PrfQueryProfileString (HINI_SYSTEMPROFILE, 427 APPNAME_PM_SPOOLER_PORT, 428 pszPortName, 429 NULL, 430 chPortData, 431 sizeof(chPortData) - 1); 432 i++; 433 } 434 return(!fPortExists); 435 } 436 APIRET APIENTRY SplPdEnumPort ( HAB hab, 437 PVOID pBuf, 438 ULONG cbBuf, 439 PULONG pulReturned, 440 PULONG pulTotal, 441 PULONG pcbRequired ) 442 443 { 444 HMODULE hModule; 445 ULONG ulBootDrive; 446 ULONG rcLoadMod; 447 CHAR szPathName[260]; 448 449 if (!pulReturned || 450 !pulTotal || 451 !pcbRequired) 452 { 453 return(ERROR_INVALID_PARAMETER); 454 } 455 456 if (!pBuf && cbBuf) 457 { 458 return(ERROR_INVALID_PARAMETER); 459 } 460 461 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, 462 sizeof (ULONG)); 463 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1); 464 465 PrfQueryProfileString (HINI_SYSTEMPROFILE, 466 "PM_PORT_DRIVER", 467 "UNI", 468 szDefaultPortDrvPath, 469 szPathName, 470 256 ); 471 472 rcLoadMod = DosLoadModule (NULL, 0, szPathName, &hModule); 473 474 if (cbBuf == 0L) 475 { 476 *pulReturned = 0; 477 *pcbRequired = CalcBufLength (hab, hModule); 478 *pulTotal = MAX_PORTS; 479 if (!rcLoadMod) 480 DosFreeModule (hModule); 481 return(ERROR_MORE_DATA); 482 } 483 484 /* 485 ** check number of ports info we can fit in supplied buffer 486 */ 487 *pulTotal = MAX_PORTS; 488 *pcbRequired = CalcBufLength (hab, hModule); 489 *pulReturned = NumPortsCanFit (hab, hModule, cbBuf); 490 491 /* 492 ** return error if we can not fit one port. 493 */ 494 if (!(*pulReturned)) 495 { 496 if (!rcLoadMod) 497 DosFreeModule (hModule); 498 return(ERROR_INSUFFICIENT_BUFFER); 499 } 500 501 /* 502 ** copy all the ports which we can store in the pBuf 503 */ 504 CopyNPorts (hab, hModule, (PCH)pBuf, *pulReturned); 505 506 /* 507 ** Free the module - we do not need it any more. 508 */ 509 if (!rcLoadMod) 510 DosFreeModule (hModule); 511 512 /* 513 ** copy all the ports which we can store in the pBuf 514 */ 515 if (*pulReturned < *pulTotal) 516 { 517 return(ERROR_MORE_DATA); 518 } 519 520 return(NO_ERROR); 521 } 522 APIRET APIENTRY SplPdInstallPort ( HAB hab, 523 PSZ pszPortName ) 524 { 525 CHAR chBuf[STR_LEN_PORTNAME]; 526 CHAR chPortDesc[STR_LEN_PORTDESC]; 527 ULONG ulBootDrive; 528 HMODULE hModule; 529 CHAR szPathName[260]; /* will contain full path to this port driver */ 530 531 if (!pszPortName) 532 { 533 return(ERROR_INVALID_PARAMETER); 534 } 535 strcpy(szDefaultPortDrvPath,PATH_UNI_PDR); 536 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, 537 sizeof (ULONG)); 538 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1); 539 strcpy( szPathName, szDefaultPortDrvPath ); 540 541 /* Make sure the port driver itself is installed */ 542 PrfWriteProfileString (HINI_SYSTEMPROFILE, 543 "PM_PORT_DRIVER", 544 "UNI", 545 szDefaultPortDrvPath); 546 547 /* Generate appname for "PM_UNIx" */ 548 strcpy (chBuf, APPNAME_LEAD_STR); 549 strcat (chBuf, pszPortName); 550 551 /* 552 ** Check for this being our default Port Name to install. 553 ** If so (pszPortName == "UNI") then generate a unique 554 ** port name so that we can install multiple UNI printers. 555 */ 556 if (!strcmp(pszPortName, DEF_PORTNAME)) 557 { 558 /* 559 ** Use chBuf to store the new portname to install 560 ** Must first increment past "PM_" in chBuf 561 */ 562 pszPortName = chBuf + 3; 563 GenerateUniquePortName( pszPortName ); 564 } 565 566 /* Get initial port description (fall back to portname if unavailable) */ 567 hModule = 0L ; /* Init module handle to null */ 568 DosLoadModule (NULL, 0, szPathName, &hModule); 569 if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc)) 570 { 571 strcpy( chPortDesc, pszPortName ); 572 } 573 DosFreeModule (hModule); 574 575 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 576 chBuf, 577 KEY_DESCRIPTION, 578 chPortDesc)) 579 { 580 return (WinGetLastError (hab)); 581 } 582 583 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 584 chBuf, 585 KEY_INITIALIZATION, 586 DEF_INITIALIZATION)) 587 { 588 return (WinGetLastError (hab)); 589 } 590 591 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 592 chBuf, 593 KEY_TERMINATION, 594 DEF_TERMINATION)) 595 { 596 return (WinGetLastError (hab)); 597 } 598 599 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 600 chBuf, 601 KEY_PORTDRIVER, 602 DEF_PORTDRIVER)) 603 { 604 return (WinGetLastError (hab)); 605 } 606 607 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 608 chBuf, 609 KEY_TIMEOUT, 610 DEF_TIMEOUT)) 611 { 612 return (WinGetLastError (hab)); 613 } 614 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 615 APPNAME_PM_SPOOLER_PORT, 616 pszPortName, 617 DEF_INITIALIZATION)) 618 { 619 return (WinGetLastError (hab)); 620 } 621 return(NO_ERROR); 622 } 623 BOOL APIENTRY SplPdGetPortIcon ( HAB hab, 624 PULONG idIcon ) 625 { 626 if (idIcon) 627 { 628 *idIcon = UNI_ICON; 629 } 630 return(TRUE); 631 } 632 APIRET APIENTRY SplPdQueryPort ( HAB hab, 633 PSZ pszPortName, 634 PVOID pBufIn, 635 ULONG cbBuf, 636 PULONG cItems ) 637 { 638 HMODULE hModule; 639 CHAR chString[STR_LEN_DESC]; 640 USHORT usNumLines; 641 USHORT usLineID; 642 USHORT usStrLength; 643 ULONG ulBootDrive; 644 PCH pBuf = pBufIn; 645 CHAR szPathName[260]; /* will contain full path to this port driver */ 646 647 if (!cItems) 648 { 649 return(ERROR_INVALID_PARAMETER); 650 } 651 652 if (!pBuf || !cbBuf) 653 { 654 return(ERROR_INVALID_PARAMETER); 655 } 656 657 658 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, 659 sizeof (ULONG)); 660 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1); 661 662 PrfQueryProfileString (HINI_SYSTEMPROFILE, 663 "PM_PORT_DRIVER", 664 "UNI", 665 szDefaultPortDrvPath, 666 szPathName, 667 256 ); 668 669 hModule = 0L ; 670 671 DosLoadModule (NULL, 0, szPathName, &hModule); 672 673 chString[0] = '\0' ; 674 675 WinLoadString(hab, hModule, (USHORT)ID_NUMBER_OF_DESC_LINES, STR_LEN_DESC, 676 chString); 677 usNumLines = (USHORT)atoi (chString); 678 usLineID = ID_FIRST_DESC_LINES; 679 for (*cItems = 0; *cItems < usNumLines; *cItems++) 680 { 681 WinLoadString(hab, hModule, usLineID, STR_LEN_DESC, chString); 682 if (cbBuf >= (usStrLength = (USHORT)(strlen (chString) + 1))) 683 { 684 strcpy (pBuf, chString); 685 pBuf += usStrLength; 686 cbBuf -= usStrLength; 687 } 688 else 689 { 690 DosFreeModule (hModule); 691 return(ERROR_INSUFFICIENT_BUFFER); 692 } 693 } 694 DosFreeModule (hModule); 695 return(NO_ERROR); 696 } 697 APIRET APIENTRY SplPdSetPort ( HAB hab, 698 PSZ pszPortName, 699 PULONG flModified ) 700 { 701 CHAR chBuf[STR_LEN_PORTNAME]; 702 CHAR chPortDriver[STR_LEN_PORTNAME]; 703 ULONG ulBootDrive; 704 HMODULE hModule; 705 CHAR szPathName[260]; /* will contain full path to this port driver */ 706 707 if (!pszPortName || !flModified) 708 { 709 return(ERROR_INVALID_PARAMETER); 710 } 711 712 strcpy (chBuf, APPNAME_LEAD_STR); 713 strcat (chBuf, pszPortName); 714 715 if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf, 716 KEY_PORTDRIVER, NULL, chPortDriver, 717 STR_LEN_PORTNAME))) 718 { 719 return(ERROR_INVALID_PARAMETER); 720 } 721 722 if (strcmp (chPortDriver, DEF_PORTDRIVER)) 723 { 724 return(ERROR_INVALID_PARAMETER); 725 } 726 727 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, 728 sizeof (ULONG)); 729 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1); 730 731 PrfQueryProfileString (HINI_SYSTEMPROFILE, 732 "PM_PORT_DRIVER", 733 "UNI", 734 szDefaultPortDrvPath, 735 szPathName, 736 256 ); 737 738 hModule = 0L ; /* Init module handle to null */ 739 740 DosLoadModule (NULL, 0, szPathName, &hModule); 741 742 *flModified = OpenLprPortDlg (hab, hModule, pszPortName, chBuf); 743 744 DosFreeModule (hModule); 745 return(NO_ERROR); 192 return UniData.lfModified; 746 193 } 747 194 748 749 APIRET APIENTRY SplPdRemovePort ( HAB hab,750 PSZ pszPortName )751 {752 CHAR chBuf[STR_LEN_PORTNAME];753 CHAR chPortDriver[STR_LEN_PORTNAME];754 755 if (!pszPortName)756 {757 return(ERROR_INVALID_PARAMETER);758 }759 760 strcpy (chBuf, APPNAME_LEAD_STR);761 strcat (chBuf, pszPortName);762 763 if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,764 KEY_PORTDRIVER, NULL, chPortDriver,765 STR_LEN_PORTNAME)))766 {767 return(ERROR_INVALID_PARAMETER);768 }769 770 if (strcmp (chPortDriver, DEF_PORTDRIVER))771 {772 return(ERROR_INVALID_PARAMETER);773 }774 775 PrfWriteProfileString (HINI_SYSTEMPROFILE, chBuf, NULL, NULL);776 777 PrfWriteProfileString (HINI_SYSTEMPROFILE,778 APPNAME_PM_SPOOLER_PORT,779 pszPortName,780 NULL);781 return(NO_ERROR);782 783 }784 ULONG APIENTRY SplPdOpen( PSZ pszPortName,785 PHFILE phFile,786 PULONG pDeviceFlags,787 PVOID pPrtOpenStruct)788 {789 APIRET rc;790 ULONG ulAction = 0; /* Action taken by DosOpen */791 ULONG ulBytesRead = 0; /* Number of bytes read by DosRead */792 ULONG ulWrote = 0; /* Number of bytes written by DosWrite */793 ULONG ulLocal = 0; /* File pointer position after DosSetFilePtr */794 char szTemp[ 256];795 char tmp[256];796 ULONG pcbWritten ;797 USHORT i;798 HFILE control;799 char filename[256];800 DATETIME dt;801 char spool_dir[256];802 PEAOP2 pEABuf = NULL;803 804 805 if (!phFile || !pDeviceFlags )806 {807 return(ERROR_INVALID_PARAMETER);808 }809 DosGetDateTime(&dt);810 rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,811 "PM_SPOOLER",812 "DIR",813 NULL,814 (PSZ)spool_dir,815 sizeof(spool_dir));816 spool_dir[ strlen(spool_dir) - 1] = '\0';817 sprintf(tmp,"%s\\UNI",spool_dir);818 DosCreateDir( tmp,pEABuf );819 sprintf(filename,"%s\\UNI\\%02d_%02d_%02d_%02d_%s",spool_dir,dt.hours,dt.minutes,dt.seconds,dt.hundredths,pszPortName);820 rc = DosOpen(filename,821 phFile, /* File handle */822 &ulAction, /* Action taken */823 100L, /* File primary allocation */824 FILE_ARCHIVED | FILE_NORMAL, /* File attribute */825 OPEN_ACTION_CREATE_IF_NEW |826 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */827 OPEN_FLAGS_NOINHERIT |828 OPEN_SHARE_DENYNONE |829 OPEN_ACCESS_READWRITE, /* Open mode of the file */830 0L); /* No extended attribute */831 /* DosWrite(*phFile,pszPSHeader,strlen(pszPSHeader),&cbHeader); */832 sprintf(szTemp,"PM_%s",pszPortName);833 if (PrfQueryProfileString (HINI_SYSTEMPROFILE,834 szTemp,835 KEY_INITIALIZATION,836 NULL,837 szTemp,838 sizeof(szTemp)))839 {840 sprintf(tmp ,"%s\\UNI\\%d.control",spool_dir,*phFile);841 rc = DosOpen( tmp ,842 &control, /* File handle */843 &ulAction, /* Action taken */844 strlen(szTemp), /* File primary allocation */845 FILE_ARCHIVED | FILE_NORMAL, /* File attribute */846 OPEN_ACTION_CREATE_IF_NEW |847 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */848 OPEN_FLAGS_NOINHERIT |849 OPEN_SHARE_DENYNONE |850 OPEN_ACCESS_READWRITE, /* Open mode of the file */851 0L); /* No extended attribute */852 rc = DosWrite( control,szTemp,strlen(szTemp),&pcbWritten);853 rc = DosWrite( control,"#",1,&pcbWritten);854 rc = DosWrite( control,filename,strlen(filename),&pcbWritten);855 rc = DosWrite( control,"@",1,&pcbWritten);856 rc = DosClose(control);857 }858 return rc;859 860 }861 ULONG APIENTRY SplPdQuery ( PSZ pszDeviceName,862 ULONG ulFlags,863 ULONG ulCommand,864 PVOID pInData,865 ULONG cbInData,866 PVOID pOutData,867 PULONG pcbOutData )868 {869 /* return ERROR_NOT_SUPPORTED; */870 return NO_ERROR;871 }872 ULONG APIENTRY SplPdSet ( PSZ pszDeviceName,873 ULONG ulFlags,874 ULONG ulCommand,875 PVOID pInData,876 ULONG cbInData )877 {878 /* return ERROR_NOT_SUPPORTED; */879 return NO_ERROR;880 }881 ULONG APIENTRY SplPdNewPage ( HFILE hFile, ULONG ulPageNumber )882 {883 return NO_ERROR;884 }885 ULONG APIENTRY SplPdAbortDoc( HFILE hFile,886 PVOID pchData,887 ULONG cbData,888 ULONG ulFlags )889 {890 return NO_ERROR;891 }892 ULONG APIENTRY SplPdClose( HFILE hFile )893 {894 APIRET rc;895 APIRET resp;896 USHORT i;897 USHORT j;898 RESULTCODES rc_child;899 ULONG nbr_lu;900 ULONG ulAction;901 char szTemp[256];902 HFILE control;903 char binfile[256];904 char arg[256];905 char j_parms[256] ;906 char *f_parms;907 char j_id[3];908 char parameters[256];909 char workingdir[256] ;910 char j_title[256];911 char j_copies[3];912 char j_options[8];913 char filename[256];914 char ip_add[256];915 char queue_name[256];916 char workgroup[256];917 char username[256];918 char password_enc[256];919 char password_dec[256];920 char errorstr[256];921 USHORT pos;922 char spool_dir[256];923 ULONG ulBootDrive;924 925 rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,926 "PM_SPOOLER",927 "DIR",928 NULL,929 (PSZ)spool_dir,930 sizeof(spool_dir));931 spool_dir[ strlen(spool_dir) - 1] = '\0';932 sprintf(szTemp,"%s\\UNI\\%d.control",spool_dir,hFile);933 rc = DosOpen(szTemp,934 &control,935 &ulAction,936 0L,937 FILE_ARCHIVED | FILE_NORMAL,938 OPEN_ACTION_CREATE_IF_NEW |939 OPEN_ACTION_OPEN_IF_EXISTS,940 OPEN_FLAGS_NOINHERIT |941 OPEN_SHARE_DENYNONE |942 OPEN_ACCESS_READWRITE,943 0L);944 rc = DosRead( control,szTemp,sizeof(szTemp),&nbr_lu);945 rc = DosClose( control );946 sprintf(filename,"%s\\UNI\\%d.control",spool_dir,hFile);947 DosDelete(filename);948 949 i = 0;950 j = 0;951 pos = 0;952 while (szTemp[i] != '@')953 {954 if (szTemp[i] == '#')955 {956 szTemp[i] = '\0';957 switch(j)958 {959 case 0:strcpy(binfile,&szTemp[pos]);960 break;961 case 1:strcpy(parameters,&szTemp[pos]);962 break;963 case 2:strcpy(workingdir,&szTemp[pos]);964 break;965 /* case 3:strcpy(username,&szTemp[pos]);966 break;967 case 4:strcpy(j_copies,&szTemp[pos]);968 break;969 case 5:strcpy(password_enc,&szTemp[pos]);970 break; */971 }972 pos = i+1;973 j++;974 }975 i++;976 }977 szTemp[i] = '\0';978 strcpy(filename,&szTemp[pos]);979 980 rc = DosClose( hFile );981 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,982 sizeof (ULONG));983 984 decryptPassword(password_enc,password_dec);985 986 // This is the soon to be obsolete description of smbspool987 // Usage: smbspool [DEVICE_URI] job-id user title copies options [file]988 989 990 f_parms = malloc((strlen(parameters) - strlen("%file%") + strlen(filename)) * sizeof(char));991 992 searchReplace("%file%", filename, parameters, f_parms);993 994 sprintf(j_parms,f_parms);995 free(f_parms);996 997 chdir(workingdir);998 rc = spawnlp(P_WAIT,binfile,binfile,j_parms,NULL);999 1000 while (rc != 0)1001 {1002 sprintf(errorstr,"Error during spooling %s to %s %s",queue_name,binfile,j_parms);1003 resp = WinMessageBox (HWND_DESKTOP,1004 HWND_DESKTOP,1005 errorstr,1006 "Universal Port driver error",1007 0L, MB_RETRYCANCEL | MB_WARNING | MB_MOVEABLE);1008 if (resp != MBID_CANCEL )1009 {1010 rc = spawnlp(P_WAIT,binfile,binfile,j_parms,NULL);1011 }1012 else rc = 0;1013 };1014 1015 strcpy(filename,&szTemp[pos]);1016 DosDelete(filename);1017 1018 /* We always have to return success to the spooler subsystem */1019 rc = NO_ERROR;1020 return rc;1021 }1022 ULONG APIENTRY SplPdWrite( HFILE hFile,1023 PVOID pchData,1024 ULONG cbData,1025 PULONG pcbWritten )1026 { APIRET rc;1027 1028 rc = DosWrite( hFile,pchData,cbData,pcbWritten);1029 rc = DosSleep(0);1030 return rc;1031 }1032 -
branches/1.0/src/uni.h
r20 r26 1 #define INCL_DOS 2 #define INCL_GPI 3 #undef INCL_GPI 4 #define INCL_DEV 5 #define INCL_DOSMEMMGR /* Include standard OS/2 support */ 6 #define INCL_DOSMODULEMGR /* For DosLoadModule */ 7 #define INCL_DOSPROCESS 8 #define INCL_GPILCIDS 9 #define INCL_WINCOMMON /* Include Window Management support */ 10 #define INCL_WINDOWMGR 11 #define INCL_WINSWITCHLIST 12 #define INCL_WINPROGRAMLIST 13 #define INCL_WINMENUS 14 #define INCL_WINWINDOWMGR 15 #define INCL_WINMESSAGEMGR 16 #define INCL_WINDIALOGS 17 #define INCL_WINSTATICS 18 #define INCL_WINLISTBOXES 19 #define INCL_WINMENUS 20 #define INCL_WINSYS 21 #define INCL_WINFRAMEMGR 22 #define INCL_INCLWINACCELERATORS 23 #define INCL_WINPOINTERS 24 #define INCL_WINERRORS 25 #define INCL_WINSHELLDATA 26 27 #define INCL_WINTYPES 28 #define INCL_WINACCELERATORS 29 #define INCL_WINBUTTONS 30 #define INCL_WINENTRYFIELDS 31 #define INCL_WINRECTANGLES 32 #define INCL_WINTIMER 33 #define INCL_WINSCROLLBARS 34 #define INCL_WINHEAP 35 #define INCL_SHLERRORS 36 #define INCL_WININPUT 37 #define INCL_WINHELP 38 #define INCL_WINSTDSPIN 39 40 #define INCL_SPL 41 #define INCL_SPLP 42 #define INCL_SPLERRORS 43 #define INCL_SHLERRORS 44 #define INCL_DOSERRORS 45 #define INCL_WINHOOKS 46 47 #include <os2.h> 48 1 49 #define PATH_UNI_PDR "?:\\OS2\\DLL\\UNI.PDR" 2 50 #define UNI_DLL "UNI.PDR" … … 175 223 #define ID_FIRST_DESC_LINES 8001 176 224 177 typedef struct _ LPRDATA225 typedef struct _UNIDATA 178 226 { 179 227 HAB hAB; … … 183 231 CHAR szSaveLprSetting[PORT_ENTRY_LEN+1]; 184 232 ULONG lfModified; 185 } LPRDATA, *PLPRDATA; 233 } UNIDATA, *PUNIDATA; 234 235 typedef struct _PORTNAMES 236 { 237 PSZ pszPortName; /* -> name of port(ie "LPT1) */ 238 PSZ pszPortDesc; /* -> description of port(ie "Parallel Port 1") */ 239 } PORTNAMES, *PPORTNAMES; 186 240 187 241 #define GB_UNICFG 206 -
branches/1.0/src/utils.c
r23 r26 1 #include <os2.h>1 #include "uni.h" 2 2 3 3 #include <stdlib.h> … … 100 100 } 101 101 102 /* Alex Taylor's new version of lprtok() that can handle missing fields */ 103 char * lprtok (char *string,char *control) 104 { 105 char *c; 106 static char *next; 107 108 if ( control == NULL ) return string; 109 if ( string == NULL ) string = next; 110 if ( string == NULL ) return NULL; 111 112 if (( c = strpbrk( string, control )) == NULL ) { 113 next = NULL; 114 } 115 else { 116 next = c+1; 117 *c = '\0'; 118 } 119 120 return ( string ); 121 } 122 123 ULONG CalcStructLength ( HAB hab, HMODULE hModule, USHORT usID ) 124 { 125 ULONG cbRequired; 126 CHAR chString[STR_LEN_PORTDESC]; 127 128 cbRequired = 0; 129 130 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chString); 131 cbRequired += strlen (chString) + 1; 132 WinLoadString(hab, hModule, (USHORT)(usID + 1), STR_LEN_PORTDESC, chString); 133 cbRequired += strlen (chString) + 1; 134 cbRequired += sizeof (PORTNAMES); 135 return(cbRequired); 136 } 137 138 ULONG CalcBufLength ( HAB hab, HMODULE hModule ) 139 { 140 ULONG cbRequired; 141 USHORT usID; 142 143 cbRequired = 0; 144 145 /* 146 ** calculate length required to fit all the port info. 147 */ 148 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 149 { 150 cbRequired += CalcStructLength (hab, hModule, usID); 151 } 152 153 return(cbRequired); 154 } 155 156 ULONG NumPortsCanFit ( HAB hab, HMODULE hModule, ULONG cbBuf ) 157 { 158 ULONG cbRequired; 159 USHORT usID; 160 ULONG ulNumPort; 161 162 cbRequired = 0; 163 ulNumPort = 0; 164 165 /* 166 ** calculate how many ports we can fit in buf. 167 */ 168 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 169 { 170 cbRequired += CalcStructLength (hab, hModule, usID); 171 if (cbRequired > cbBuf) 172 { 173 return(ulNumPort); 174 } 175 ulNumPort++; 176 } 177 178 return(ulNumPort); 179 } 180 VOID CopyStruct ( HAB hab, HMODULE hModule, USHORT usID, PCH pBuf, PULONG pulBeginStruct, PULONG pulBeginText ) 181 { 182 PPORTNAMES pPortNames; 183 184 pPortNames = (PPORTNAMES)(pBuf + *pulBeginStruct); 185 *pulBeginStruct += sizeof (PORTNAMES); 186 187 /* 188 ** copy port name in the structure 189 */ 190 pPortNames->pszPortName = pBuf + *pulBeginText; 191 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName); 192 *pulBeginText += strlen (pPortNames->pszPortName) + 1; 193 194 /* 195 ** copy port description to the structure 196 */ 197 pPortNames->pszPortDesc = pBuf + *pulBeginText; 198 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortDesc); 199 *pulBeginText += strlen (pPortNames->pszPortDesc) + 1; 200 } 201 VOID CopyNPorts ( HAB hab, HMODULE hModule, PCH pBuf, ULONG ulReturned ) 202 { 203 USHORT usID; 204 ULONG ulBeginText; 205 ULONG ulBeginStruct; 206 207 ulBeginText = ulReturned * sizeof (PORTNAMES); 208 ulBeginStruct = 0; 209 210 for (usID = PORT_ID_FIRST; 211 usID <= PORT_ID_LAST && ulReturned; 212 usID += 2, --ulReturned) 213 { 214 CopyStruct (hab, hModule, usID, pBuf, &ulBeginStruct, &ulBeginText); 215 } 216 } 217 218 BOOL GetPortDescription ( HAB hab, HMODULE hModule, PSZ pszPortName, PSZ pszPortDesc ) 219 { 220 USHORT usID; 221 CHAR chBuf[STR_LEN_PORTDESC] = {0}; 222 223 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 224 { 225 WinLoadString(hab, hModule, usID, STR_LEN_PORTNAME, chBuf); 226 if (!strcmp (pszPortName, chBuf)) 227 { 228 if ( WinLoadString(hab, hModule, usID+1, STR_LEN_PORTDESC, chBuf) ) { 229 strcpy (pszPortDesc, chBuf); 230 return(TRUE); 231 } 232 break; 233 } 234 } 235 return(FALSE); 236 } 237 238 BOOL GenerateUniquePortName( PSZ pszPortName ) 239 { 240 BOOL fPortExists; 241 PSZ pszEndPortName; 242 USHORT i; 243 CHAR chPortData[STR_LEN_PORTNAME]; 244 245 /* 246 ** Generate a unique port name by adding numbers to the 247 ** end of pszPortName 248 */ 249 pszEndPortName = pszPortName + strlen( pszPortName ); 250 i = 1; 251 fPortExists = TRUE; 252 while ( (i < MAX_PORTS) && fPortExists ) 253 { 254 _itoa( i, pszEndPortName, 4); 255 fPortExists = PrfQueryProfileString (HINI_SYSTEMPROFILE, 256 APPNAME_PM_SPOOLER_PORT, 257 pszPortName, 258 NULL, 259 chPortData, 260 sizeof(chPortData) - 1); 261 i++; 262 } 263 return(!fPortExists); 264 } 265 -
branches/1.0/src/utils.h
r23 r26 25 25 void decryptPassword(const char *pszCrypt, char *pszPlain); 26 26 void encryptPassword(const char *pszPlain, char *pszCrypt); 27 char * lprtok (char *string,char *control); 27 28 28 29 #endif // __UTILS__H
Note:
See TracChangeset
for help on using the changeset viewer.