Commit 6374cd23 authored by Thuy Nguyen's avatar Thuy Nguyen Committed by Alexandre Julliard

Replaced a static ten element array with a dynamic pointer array.

parent 40320f3e
...@@ -8,7 +8,8 @@ MODULE = winspool ...@@ -8,7 +8,8 @@ MODULE = winspool
SPEC_SRCS = winspool.spec SPEC_SRCS = winspool.spec
C_SRCS = \ C_SRCS = \
info.c info.c \
wspool.c
all: $(MODULE).o all: $(MODULE).o
......
...@@ -15,13 +15,12 @@ ...@@ -15,13 +15,12 @@
#include "winreg.h" #include "winreg.h"
#include "debugtools.h" #include "debugtools.h"
#include "heap.h" #include "heap.h"
#include "commctrl.h"
DEFAULT_DEBUG_CHANNEL(winspool) DEFAULT_DEBUG_CHANNEL(winspool)
CRITICAL_SECTION PRINT32_RegistryBlocker; CRITICAL_SECTION PRINT32_RegistryBlocker;
#define NUM_PRINTER_MAX 10
typedef struct _OPENEDPRINTERA typedef struct _OPENEDPRINTERA
{ {
LPSTR lpsPrinterName; LPSTR lpsPrinterName;
...@@ -29,28 +28,18 @@ typedef struct _OPENEDPRINTERA ...@@ -29,28 +28,18 @@ typedef struct _OPENEDPRINTERA
LPPRINTER_DEFAULTSA lpDefault; LPPRINTER_DEFAULTSA lpDefault;
} OPENEDPRINTERA, *LPOPENEDPRINTERA; } OPENEDPRINTERA, *LPOPENEDPRINTERA;
/* The OpenedPrinter Table dynamic array */
static HDPA pOpenedPrinterDPA = NULL;
/* Initialize the structure OpenedPrinter Table */ extern HDPA (WINAPI* WINSPOOL_DPA_CreateEx) (INT, HANDLE);
static OPENEDPRINTERA OpenedPrinterTableA[NUM_PRINTER_MAX] = extern LPVOID (WINAPI* WINSPOOL_DPA_GetPtr) (const HDPA, INT);
{ extern INT (WINAPI* WINSPOOL_DPA_InsertPtr) (const HDPA, INT, LPVOID);
{NULL, -1, NULL},
{NULL, -1, NULL},
{NULL, -1, NULL},
{NULL, -1, NULL},
{NULL, -1, NULL},
{NULL, -1, NULL},
{NULL, -1, NULL},
{NULL, -1, NULL},
{NULL, -1, NULL},
{NULL, -1, NULL}
};
static char Printers[] = static char Printers[] =
"System\\CurrentControlSet\\control\\Print\\Printers\\"; "System\\CurrentControlSet\\control\\Print\\Printers\\";
static char Drivers[] = static char Drivers[] =
"System\\CurrentControlSet\\control\\Print\\Environments\\Wine\\Drivers\\"; "System\\CurrentControlSet\\control\\Print\\Environments\\Wine\\Drivers\\";
/****************************************************************** /******************************************************************
* WINSPOOL_GetOpenedPrinterEntryA * WINSPOOL_GetOpenedPrinterEntryA
* Get the first place empty in the opened printer table * Get the first place empty in the opened printer table
...@@ -58,12 +47,51 @@ static char Drivers[] = ...@@ -58,12 +47,51 @@ static char Drivers[] =
static LPOPENEDPRINTERA WINSPOOL_GetOpenedPrinterEntryA() static LPOPENEDPRINTERA WINSPOOL_GetOpenedPrinterEntryA()
{ {
int i; int i;
for( i=0; i< NUM_PRINTER_MAX; i++) LPOPENEDPRINTERA pOpenedPrinter;
if (OpenedPrinterTableA[i].hPrinter == -1)
{ /*
OpenedPrinterTableA[i].hPrinter = i + 1; * Create the opened printers' handle dynamic array.
return &OpenedPrinterTableA[i]; */
} if (!pOpenedPrinterDPA)
{
pOpenedPrinterDPA = WINSPOOL_DPA_CreateEx(10, GetProcessHeap());
for (i = 0; i < 10; i++)
{
pOpenedPrinter = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(OPENEDPRINTERA));
pOpenedPrinter->hPrinter = -1;
WINSPOOL_DPA_InsertPtr(pOpenedPrinterDPA, i, pOpenedPrinter);
}
}
/*
* Search for a handle not yet allocated.
*/
for (i = 0; i < pOpenedPrinterDPA->nItemCount; i++)
{
pOpenedPrinter = WINSPOOL_DPA_GetPtr(pOpenedPrinterDPA, i);
if (pOpenedPrinter->hPrinter == -1)
{
pOpenedPrinter->hPrinter = i + 1;
return pOpenedPrinter;
}
}
/*
* Didn't find one, insert new element in the array.
*/
if (i == pOpenedPrinterDPA->nItemCount)
{
pOpenedPrinter = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(OPENEDPRINTERA));
pOpenedPrinter->hPrinter = i + 1;
WINSPOOL_DPA_InsertPtr(pOpenedPrinterDPA, i, pOpenedPrinter);
return pOpenedPrinter;
}
return NULL; return NULL;
} }
...@@ -73,9 +101,15 @@ static LPOPENEDPRINTERA WINSPOOL_GetOpenedPrinterEntryA() ...@@ -73,9 +101,15 @@ static LPOPENEDPRINTERA WINSPOOL_GetOpenedPrinterEntryA()
*/ */
static LPOPENEDPRINTERA WINSPOOL_GetOpenedPrinterA(int printerHandle) static LPOPENEDPRINTERA WINSPOOL_GetOpenedPrinterA(int printerHandle)
{ {
if((printerHandle <=0) || (printerHandle > (NUM_PRINTER_MAX + 1))) LPOPENEDPRINTERA pOpenedPrinter;
return NULL;
return &OpenedPrinterTableA[printerHandle -1]; if((printerHandle <=0) ||
(printerHandle > (pOpenedPrinterDPA->nItemCount - 1)))
return NULL;
pOpenedPrinter = WINSPOOL_DPA_GetPtr(pOpenedPrinterDPA, printerHandle);
return pOpenedPrinter;
} }
/****************************************************************** /******************************************************************
...@@ -1012,7 +1046,12 @@ BOOL WINAPI ClosePrinter(HANDLE hPrinter) ...@@ -1012,7 +1046,12 @@ BOOL WINAPI ClosePrinter(HANDLE hPrinter)
{ {
LPOPENEDPRINTERA lpOpenedPrinter; LPOPENEDPRINTERA lpOpenedPrinter;
if ((hPrinter != -1) && (hPrinter < NUM_PRINTER_MAX + 1)) TRACE("Handle %d\n", hPrinter);
if (!pOpenedPrinterDPA)
return FALSE;
if ((hPrinter != -1) && (hPrinter < (pOpenedPrinterDPA->nItemCount - 1)))
{ {
lpOpenedPrinter = WINSPOOL_GetOpenedPrinterA(hPrinter); lpOpenedPrinter = WINSPOOL_GetOpenedPrinterA(hPrinter);
HeapFree(GetProcessHeap(), 0, lpOpenedPrinter->lpsPrinterName); HeapFree(GetProcessHeap(), 0, lpOpenedPrinter->lpsPrinterName);
...@@ -1031,7 +1070,7 @@ BOOL WINAPI ClosePrinter(HANDLE hPrinter) ...@@ -1031,7 +1070,7 @@ BOOL WINAPI ClosePrinter(HANDLE hPrinter)
} }
lpOpenedPrinter->hPrinter = -1; lpOpenedPrinter->hPrinter = -1;
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
......
name winspool name winspool
type win32 type win32
init WINSPOOL_EntryPoint
101 stub ADVANCEDSETUPDIALOG 101 stub ADVANCEDSETUPDIALOG
102 stub AbortPrinter 102 stub AbortPrinter
......
/******************************************************************************
* Print Spooler Functions
*
*
* Copyright 1999 Thuy Nguyen
*/
#include "commctrl.h"
#include "debugtools.h"
DEFAULT_DEBUG_CHANNEL(winspool)
HINSTANCE hcomctl32 = 0;
HDPA (WINAPI* WINSPOOL_DPA_CreateEx)(INT, HANDLE);
LPVOID (WINAPI* WINSPOOL_DPA_GetPtr)(const HDPA, INT);
INT (WINAPI* WINSPOOL_DPA_InsertPtr)(const HDPA, INT, LPVOID);
/******************************************************************************
* WINSPOOL_EntryPoint
*
* Winspool entry point.
*
*/
BOOL WINAPI WINSPOOL_EntryPoint(HINSTANCE hInstance,
DWORD reason,
LPVOID lpReserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
hcomctl32 = LoadLibraryA("COMCTL32.DLL");
WINSPOOL_DPA_CreateEx = (void*)GetProcAddress(hcomctl32, (LPCSTR)340L);
WINSPOOL_DPA_GetPtr = (void*)GetProcAddress(hcomctl32, (LPCSTR)332L);
WINSPOOL_DPA_InsertPtr = (void*)GetProcAddress(hcomctl32, (LPCSTR)334L);
break;
case DLL_PROCESS_DETACH:
FreeLibrary(hcomctl32);
break;
}
return TRUE;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment