cvs: php4 /ext/printer php_printer.h printer.c printer.php
| From: | Daniel Beulshausen | Date: | Thu, 16 Nov 2000 22:16:48 +0000 |
| Subject: | cvs: php4 /ext/printer php_printer.h printer.c printer.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-2647@lists.php.net to get a copy of this message | ||
dbeu Thu Nov 16 14:16:48 2000 EDT
Added files:
/php4/ext/printer printer.php
Modified files:
/php4/ext/printer php_printer.h printer.c
Log:
- fixed bug which crashed printer_write
- fixed bug which crashed get_default_printer() in case
no printer was detected
- added option "devicename" to printer_get_option()
to retrive the printer name ( similiar to printer_name() )
Index: php4/ext/printer/php_printer.h
diff -u php4/ext/printer/php_printer.h:1.4 php4/ext/printer/php_printer.h:1.5
--- php4/ext/printer/php_printer.h:1.4 Mon Nov 6 05:58:12 2000
+++ php4/ext/printer/php_printer.h Thu Nov 16 14:16:47 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_printer.h,v 1.4 2000/11/06 13:58:12 dbeu Exp $ */
+/* $Id: php_printer.h,v 1.5 2000/11/16 22:16:47 dbeu Exp $ */
#ifndef PHP_PRINTER_H
#define PHP_PRINTER_H
Index: php4/ext/printer/printer.c
diff -u php4/ext/printer/printer.c:1.6 php4/ext/printer/printer.c:1.7
--- php4/ext/printer/printer.c:1.6 Mon Nov 6 05:58:12 2000
+++ php4/ext/printer/printer.c Thu Nov 16 14:16:47 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: printer.c,v 1.6 2000/11/06 13:58:12 dbeu Exp $ */
+/* $Id: printer.c,v 1.7 2000/11/16 22:16:47 dbeu Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -25,6 +25,8 @@
#include "ext/standard/info.h"
#include "ext/standard/php_math.h"
+#ifdef HAVE_PRINTER
+
#include "php_printer.h"
#ifdef ZTS
@@ -47,7 +49,7 @@
int get_pen_style(char *style);
int get_hatch_style(char *hatch);
static void destroy_ressources(zend_rsrc_list_entry *resource);
-int _print_enumvalue(char * EnumStr);
+DWORD _print_enumvalue(char * EnumStr);
function_entry printer_functions[] = {
@@ -99,10 +101,12 @@
PHP_MINFO_FUNCTION(printer)
{
+ char *default_printer = get_default_printer();
php_info_print_table_start();
php_info_print_table_row(2, "Printer Support", "enabled");
- php_info_print_table_row(2, "Default printing device", get_default_printer());
- php_info_print_table_row(2, "RCS Version", "$Id: printer.c,v 1.6 2000/11/06
13:58:12 dbeu Exp $");
+ php_info_print_table_row(2, "Default printing device", default_printer ? default_printer
: "<b>not detected</b>");
+ php_info_print_table_row(2, "Module state", "experimental");
+ php_info_print_table_row(2, "RCS Version", "$Id: printer.c,v 1.7 2000/11/16
22:16:47 dbeu Exp $");
php_info_print_table_end();
}
@@ -208,11 +212,12 @@
/* reflect DOCINFO to DOC_INFO_1 */
resource->info1.pDocName = estrdup(resource->info.lpszDocName);
resource->info1.pDatatype = estrdup(resource->info.lpszDatatype);
+ resource->info1.pOutputFile = NULL;
sd = StartDocPrinter(resource->handle, 1, (LPSTR)&resource->info1);
sp = StartPagePrinter(resource->handle);
- if( sd != 0 || !sp ) {
+ if( sd && sp ) {
WritePrinter(resource->handle, resource->data, strlen(resource->data), (unsigned
long*)&recieved);
EndPagePrinter(resource->handle);
EndDocPrinter(resource->handle);
@@ -256,15 +261,14 @@
PRINTER_INFO_2 *P2;
PRINTER_INFO_4 *P4;
PRINTER_INFO_5 *P5;
- DWORD bNeeded, cReturned, i;
- int argc, EnumVal, Level=1;
+ DWORD bNeeded = sizeof(InfoBuffer), cReturned, i, EnumVal;
+ int argc = ZEND_NUM_ARGS(), Level=1;
int LevvelsAllowed[] = {0, 1, 1, 0, 1, 1};
-
- argc = ARG_COUNT(ht);
- if(zend_get_parameters_ex(ht, argc, &arg1, &arg2, &arg3) == FAILURE) {
+ if(zend_get_parameters_ex(argc, &arg1, &arg2, &arg3) == FAILURE) {
WRONG_PARAM_COUNT;
}
+
convert_to_string_ex(arg1);
EnumVal = _print_enumvalue((*arg1)->value.str.val);
if (argc > 1) {
@@ -280,7 +284,6 @@
RETURN_FALSE;
}
}
-
EnumPrinters(EnumVal, Name, Level, (LPBYTE)InfoBuffer, sizeof(InfoBuffer), &bNeeded,
&cReturned);
@@ -470,6 +473,9 @@
else if(!strcmp((*arg2)->value.str.val,"scale")) {
RETURN_LONG(resource->device->dmScale);
}
+ else if(!strcmp((*arg2)->value.str.val,"devicename")) {
+ RETURN_STRING(resource->name,1);
+ }
else {
php_error(E_WARNING,"unknown option passed to printer_get_option()");
RETURN_FALSE;
@@ -938,17 +944,34 @@
}
/* }}} */
-
/* get the default printer */
char *get_default_printer(void)
{
PRINTER_INFO_2 *printer;
- DWORD need = sizeof(printer), received;
+ DWORD need, received;
+ char *printer_name = NULL, *strtok_buf = NULL, buffer[250];
- EnumPrinters(PRINTER_ENUM_DEFAULT, NULL, 2, (LPBYTE)printer, need, &need, &received);
- return printer->pPrinterName;
+ /* nt/2000 */
+ if(GetVersion() < 0x80000000){
+ GetProfileString("windows", "device", ",,,", buffer, 250);
+ php_strtok_r(buffer, ",", &strtok_buf);
+ printer_name = estrdup(buffer);
+ }
+ /* 9.x/me */
+ else {
+ EnumPrinters(PRINTER_ENUM_DEFAULT, NULL, 2, NULL, 0, &need, &received);
+ if(need > 0) {
+ printer = (PRINTER_INFO_2 *)emalloc(need+1);
+ EnumPrinters(PRINTER_ENUM_DEFAULT, NULL, 2, (LPBYTE)printer, need, &need, &received);
+ printer_name = printer->pDriverName;
+ efree(printer);
+ }
+ }
+
+ return printer_name;
}
+
#define hex2dec(a) (a>='A')?a-'A'+10:a-'0'
/* convert a hexadecimal number to the rgb colorref */
@@ -999,17 +1022,17 @@
}
/* get enumval of input, defaults to local */
-int _print_enumvalue(char * EnumStr)
+DWORD _print_enumvalue(char * EnumStr)
{
- int EV = PRINTER_ENUM_LOCAL;
+ DWORD EV = PRINTER_ENUM_LOCAL;
php_strtoupper(EnumStr, strlen(EnumStr));
if(!strcmp(EnumStr, "PRINTER_ENUM_LOCAL")) EV = PRINTER_ENUM_LOCAL;
- if(!strcmp(EnumStr, "PRINTER_ENUM_NAME")) EV = PRINTER_ENUM_NAME;
- if(!strcmp(EnumStr, "PRINTER_ENUM_SHARED")) EV = PRINTER_ENUM_SHARED;
- if(!strcmp(EnumStr, "PRINTER_ENUM_DEFAULT")) EV = PRINTER_ENUM_DEFAULT;
- if(!strcmp(EnumStr, "PRINTER_ENUM_CONNECTIONS")) EV = PRINTER_ENUM_CONNECTIONS;
- if(!strcmp(EnumStr, "PRINTER_ENUM_NETWORK")) EV = PRINTER_ENUM_NETWORK;
- if(!strcmp(EnumStr, "PRINTER_ENUM_REMOTE")) EV = PRINTER_ENUM_REMOTE;
+ else if(!strcmp(EnumStr, "PRINTER_ENUM_NAME")) EV = PRINTER_ENUM_NAME;
+ else if(!strcmp(EnumStr, "PRINTER_ENUM_SHARED")) EV = PRINTER_ENUM_SHARED;
+ else if(!strcmp(EnumStr, "PRINTER_ENUM_DEFAULT")) EV = PRINTER_ENUM_DEFAULT;
+ else if(!strcmp(EnumStr, "PRINTER_ENUM_CONNECTIONS")) EV = PRINTER_ENUM_CONNECTIONS;
+ else if(!strcmp(EnumStr, "PRINTER_ENUM_NETWORK")) EV = PRINTER_ENUM_NETWORK;
+ else if(!strcmp(EnumStr, "PRINTER_ENUM_REMOTE")) EV = PRINTER_ENUM_REMOTE;
return EV;
}
@@ -1022,6 +1045,7 @@
#endif
+#endif
/*
* Local variables:
* tab-width: 4
Index: php4/ext/printer/printer.php
+++ php4/ext/printer/printer.php
<?
/* open connection to the std printer */
$handle = printer_open();
/* build a string which containtains the devicename and driverversion */
$string = sprintf("device name: \"%s\"\ndriver version: \"%s\"",
printer_get_option($handle, "devicename"),
printer_get_option($handle, "driverversion"));
/* handle data to the printer */
printer_write($handle, $string);
/* close connection */
printer_close($handle);
?>