|
|
@ -1,3 +1,23 @@
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* This file is part of the KDE libraries
|
|
|
|
|
|
|
|
* Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
|
|
|
|
|
|
|
|
* Copyright (c) 2014 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
|
|
|
* License version 2 as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU Library General Public License
|
|
|
|
|
|
|
|
* along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
@ -11,8 +31,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "driverparse.h"
|
|
|
|
#include "driverparse.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define PROCESS_PPD_FILE_CONTENTS \
|
|
|
|
|
|
|
|
memset(value,0,256); \
|
|
|
|
|
|
|
|
c1 = strchr(line,':'); \
|
|
|
|
|
|
|
|
if (c1) \
|
|
|
|
|
|
|
|
{ \
|
|
|
|
|
|
|
|
c2 = strchr(c1,'"'); \
|
|
|
|
|
|
|
|
if (c2) \
|
|
|
|
|
|
|
|
{ \
|
|
|
|
|
|
|
|
c2++; \
|
|
|
|
|
|
|
|
c1 = strchr(c2,'"'); \
|
|
|
|
|
|
|
|
if (c1) strlcpy(value,c2,c1-c2+1); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
else \
|
|
|
|
|
|
|
|
{ \
|
|
|
|
|
|
|
|
c1++; \
|
|
|
|
|
|
|
|
while (*c1 && isspace(*c1)) \
|
|
|
|
|
|
|
|
c1++; \
|
|
|
|
|
|
|
|
if (!*c1) \
|
|
|
|
|
|
|
|
continue; \
|
|
|
|
|
|
|
|
c2 = line+strlen(line)-1; /* point to \n */ \
|
|
|
|
|
|
|
|
while (*c2 && isspace(*c2)) \
|
|
|
|
|
|
|
|
c2--; \
|
|
|
|
|
|
|
|
strlcpy(value,c1,c2-c1+2); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
count++; \
|
|
|
|
|
|
|
|
if (strncmp(line,"*Manufacturer:",14) == 0) fprintf(output_file,"MANUFACTURER=%s\n",value); \
|
|
|
|
|
|
|
|
else if (strncmp(line,"*ShortNickName:",15) == 0) fprintf(output_file,"MODEL=%s\n",value); \
|
|
|
|
|
|
|
|
else if (strncmp(line,"*ModelName:",11) == 0) fprintf(output_file,"MODELNAME=%s\n",value); \
|
|
|
|
|
|
|
|
else if (strncmp(line,"*NickName:",10) == 0) strncat(desc,value,255-strlen(desc)); \
|
|
|
|
|
|
|
|
else if (strncmp(line,"*pnpManufacturer:",17) == 0) fprintf(output_file,"PNPMANUFACTURER=%s\n",value); \
|
|
|
|
|
|
|
|
else if (strncmp(line,"*pnpModel:",10) == 0) fprintf(output_file,"PNPMODEL=%s\n",value); \
|
|
|
|
|
|
|
|
else if (strncmp(line,"*LanguageVersion:",17) == 0) strncat(langver,value,63-strlen(langver)); \
|
|
|
|
|
|
|
|
else count--; \
|
|
|
|
|
|
|
|
/* Either we got everything we needed, or we encountered an "OpenUI" directive \
|
|
|
|
|
|
|
|
* and it's reasonable to assume that there's no needed info further in the file, \
|
|
|
|
|
|
|
|
* just stop here */ \
|
|
|
|
|
|
|
|
if (count >= 7 || strncmp(line, "*OpenUI", 7) == 0) \
|
|
|
|
|
|
|
|
{ \
|
|
|
|
|
|
|
|
if (strlen(langver) > 0) \
|
|
|
|
|
|
|
|
{ \
|
|
|
|
|
|
|
|
strncat(desc, " [", 255-strlen(desc)); \
|
|
|
|
|
|
|
|
strncat(desc, langver, 255-strlen(desc)); \
|
|
|
|
|
|
|
|
strncat(desc, "]", 255-strlen(desc)); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
if (strlen(desc) > 0) \
|
|
|
|
|
|
|
|
fprintf(output_file, "DESCRIPTION=%s\n", desc); \
|
|
|
|
|
|
|
|
break; \
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void initPpd(const char *dirname)
|
|
|
|
void initPpd(const char *dirname)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
struct stat stat_res;
|
|
|
|
|
|
|
|
if (stat(dirname, &stat_res) == -1) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Can't open drivers directory : %s\n", dirname);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (S_ISDIR(stat_res.st_mode)) {
|
|
|
|
DIR *dir = opendir(dirname);
|
|
|
|
DIR *dir = opendir(dirname);
|
|
|
|
struct dirent *entry;
|
|
|
|
struct dirent *entry;
|
|
|
|
char buffer[4096] = {0};
|
|
|
|
char buffer[4096] = {0};
|
|
|
@ -49,7 +126,7 @@ void initPpd(const char *dirname)
|
|
|
|
snprintf(drFile, 255, "ppd:%s", buffer);
|
|
|
|
snprintf(drFile, 255, "ppd:%s", buffer);
|
|
|
|
if (c && strncmp(c,".ppd",4) == 0)
|
|
|
|
if (c && strncmp(c,".ppd",4) == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
addFile(drFile);
|
|
|
|
addFile(drFile, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c && strncmp(c, ".gz", 3) == 0)
|
|
|
|
else if (c && strncmp(c, ".gz", 3) == 0)
|
|
|
|
{ /* keep also compressed driver files */
|
|
|
|
{ /* keep also compressed driver files */
|
|
|
@ -59,7 +136,7 @@ void initPpd(const char *dirname)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*c == '.' && strncmp(c, ".ppd",4) == 0)
|
|
|
|
if (*c == '.' && strncmp(c, ".ppd",4) == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
addFile(drFile);
|
|
|
|
addFile(drFile, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -68,8 +145,49 @@ void initPpd(const char *dirname)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (access(dirname, X_OK) != -1) {
|
|
|
|
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
int n = strlen(dirname)+strlen(" list");
|
|
|
|
|
|
|
|
filename = (char*)malloc(n*sizeof(char)+1);
|
|
|
|
|
|
|
|
memset(filename,0,n);
|
|
|
|
|
|
|
|
strcat(filename, dirname);
|
|
|
|
|
|
|
|
strcat(filename, " list");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FILE* file = popen(filename, "r");
|
|
|
|
|
|
|
|
if (file) {
|
|
|
|
|
|
|
|
char * line = NULL;
|
|
|
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
ssize_t read;
|
|
|
|
|
|
|
|
while ((read = getline(&line, &len, file)) != -1) {
|
|
|
|
|
|
|
|
char * pos1 = strstr(line, "\"");
|
|
|
|
|
|
|
|
if (pos1 >= 0) {
|
|
|
|
|
|
|
|
char * pos2 = strstr(pos1 + 1, "\"");
|
|
|
|
|
|
|
|
if (pos2 >= 0) {
|
|
|
|
|
|
|
|
*pos2 = 0;
|
|
|
|
|
|
|
|
addFile(line+1, dirname);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line) {
|
|
|
|
|
|
|
|
free(line);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pclose(file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
fprintf(stderr, "Can't execute compressed driver handler : %s\n", dirname);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int parsePpdFile(const char *filename, FILE *output_file)
|
|
|
|
free(filename);
|
|
|
|
|
|
|
|
filename = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
fprintf(stderr, "Can't open drivers directory : %s\n", dirname);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int parsePpdFile(const char *filename, const char *origin, FILE *output_file)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gzFile ppd_file;
|
|
|
|
gzFile ppd_file;
|
|
|
|
char line[4096], value[256], langver[64] = {0}, desc[256] = {0};
|
|
|
|
char line[4096], value[256], langver[64] = {0}, desc[256] = {0};
|
|
|
@ -86,64 +204,60 @@ int parsePpdFile(const char *filename, FILE *output_file)
|
|
|
|
|
|
|
|
|
|
|
|
while (gzgets(ppd_file,line,4095) != Z_NULL)
|
|
|
|
while (gzgets(ppd_file,line,4095) != Z_NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
memset(value,0,256);
|
|
|
|
PROCESS_PPD_FILE_CONTENTS
|
|
|
|
c1 = strchr(line,':');
|
|
|
|
|
|
|
|
if (c1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
c2 = strchr(c1,'"');
|
|
|
|
|
|
|
|
if (c2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
c2++;
|
|
|
|
|
|
|
|
c1 = strchr(c2,'"');
|
|
|
|
|
|
|
|
if (c1) strlcpy(value,c2,c1-c2+1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
c1++;
|
|
|
|
|
|
|
|
while (*c1 && isspace(*c1))
|
|
|
|
|
|
|
|
c1++;
|
|
|
|
|
|
|
|
if (!*c1)
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
c2 = line+strlen(line)-1; /* point to \n */
|
|
|
|
|
|
|
|
while (*c2 && isspace(*c2))
|
|
|
|
|
|
|
|
c2--;
|
|
|
|
|
|
|
|
strlcpy(value,c1,c2-c1+2);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(output_file,"\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gzclose(ppd_file);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (strncmp(line,"*Manufacturer:",14) == 0) fprintf(output_file,"MANUFACTURER=%s\n",value);
|
|
|
|
int parseCompressedPpdFile(const char *ppdfilename, const char *origin, FILE *output_file)
|
|
|
|
else if (strncmp(line,"*ShortNickName:",15) == 0) fprintf(output_file,"MODEL=%s\n",value);
|
|
|
|
|
|
|
|
else if (strncmp(line,"*ModelName:",11) == 0) fprintf(output_file,"MODELNAME=%s\n",value);
|
|
|
|
|
|
|
|
else if (strncmp(line,"*NickName:",10) == 0) strncat(desc,value,255-strlen(desc));
|
|
|
|
|
|
|
|
else if (strncmp(line,"*pnpManufacturer:",17) == 0) fprintf(output_file,"PNPMANUFACTURER=%s\n",value);
|
|
|
|
|
|
|
|
else if (strncmp(line,"*pnpModel:",10) == 0) fprintf(output_file,"PNPMODEL=%s\n",value);
|
|
|
|
|
|
|
|
else if (strncmp(line,"*LanguageVersion:",17) == 0) strncat(langver,value,63-strlen(langver));
|
|
|
|
|
|
|
|
else count--;
|
|
|
|
|
|
|
|
/* Either we got everything we needed, or we encountered an "OpenUI" directive
|
|
|
|
|
|
|
|
* and it's reasonable to assume that there's no needed info further in the file,
|
|
|
|
|
|
|
|
* just stop here */
|
|
|
|
|
|
|
|
if (count >= 7 || strncmp(line, "*OpenUI", 7) == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (strlen(langver) > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
strncat(desc, " [", 255-strlen(desc));
|
|
|
|
char value[256], langver[64] = {0}, desc[256] = {0};
|
|
|
|
strncat(desc, langver, 255-strlen(desc));
|
|
|
|
char *c1, *c2;
|
|
|
|
strncat(desc, "]", 255-strlen(desc));
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
int n = strlen(origin)+strlen(" cat ")+strlen(ppdfilename);
|
|
|
|
|
|
|
|
filename = (char*)malloc(n*sizeof(char)+1);
|
|
|
|
|
|
|
|
memset(filename,0,n);
|
|
|
|
|
|
|
|
strcat(filename, origin);
|
|
|
|
|
|
|
|
strcat(filename, " cat ");
|
|
|
|
|
|
|
|
strcat(filename, ppdfilename);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FILE* file = popen(filename, "r");
|
|
|
|
|
|
|
|
if (file) {
|
|
|
|
|
|
|
|
char * line = NULL;
|
|
|
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
ssize_t read;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(output_file,"FILE=foomatic-db-compressed-ppds:%s\n",ppdfilename);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while ((read = getline(&line, &len, file)) != -1) {
|
|
|
|
|
|
|
|
PROCESS_PPD_FILE_CONTENTS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strlen(desc) > 0)
|
|
|
|
if (line) {
|
|
|
|
fprintf(output_file, "DESCRIPTION=%s\n", desc);
|
|
|
|
free(line);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pclose(file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
fprintf(stderr, "Can't open driver file : %s\n", ppdfilename);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(output_file,"\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gzclose(ppd_file);
|
|
|
|
free(filename);
|
|
|
|
|
|
|
|
filename = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
registerHandler("ppd:", initPpd, parsePpdFile);
|
|
|
|
registerHandler("ppd:", initPpd, parsePpdFile);
|
|
|
|
|
|
|
|
registerHandler("foomatic-db-compressed-ppds:", initPpd, parseCompressedPpdFile);
|
|
|
|
initFoomatic();
|
|
|
|
initFoomatic();
|
|
|
|
return execute(argc, argv);
|
|
|
|
return execute(argc, argv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|