diff options
-rw-r--r-- | tdeprint/cups/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tdeprint/cups/Makefile.am | 4 | ||||
-rw-r--r-- | tdeprint/cups/make_driver_db_cups.cpp (renamed from tdeprint/cups/make_driver_db_cups.c) | 145 | ||||
-rw-r--r-- | tdeprint/driverparse.c | 18 | ||||
-rw-r--r-- | tdeprint/driverparse.h | 4 | ||||
-rw-r--r-- | tdeprint/lpr/make_driver_db_lpr.c | 4 |
6 files changed, 131 insertions, 48 deletions
diff --git a/tdeprint/cups/CMakeLists.txt b/tdeprint/cups/CMakeLists.txt index aa882ca7e..6e2751c41 100644 --- a/tdeprint/cups/CMakeLists.txt +++ b/tdeprint/cups/CMakeLists.txt @@ -72,12 +72,12 @@ tde_add_kpart( ${target} AUTOMOC set( target make_driver_db_cups ) set( ${target}_SRCS - make_driver_db_cups.c + make_driver_db_cups.cpp ) tde_add_executable( ${target} SOURCES ${${target}_SRCS} - LINK driverparse-static tdefakes-shared ${ZLIB_LIBRARIES} ${DL_LIBRARIES} + LINK driverparse-static tdefakes-shared ${ZLIB_LIBRARIES} ${DL_LIBRARIES} ${TQT_LIBRARIES} DESTINATION ${BIN_INSTALL_DIR} ) diff --git a/tdeprint/cups/Makefile.am b/tdeprint/cups/Makefile.am index 8932dbdcb..789a32093 100644 --- a/tdeprint/cups/Makefile.am +++ b/tdeprint/cups/Makefile.am @@ -26,8 +26,8 @@ noinst_HEADERS = cupsinfos.h ipprequest.h kmcupsjobmanager.h kmcupsmanager.h kmc kmwother.h ippreportdlg.h kptagspage.h bin_PROGRAMS = make_driver_db_cups cupsdoprint -make_driver_db_cups_SOURCES = make_driver_db_cups.c -make_driver_db_cups_LDADD = ../libdriverparse.a $(top_builddir)/tdecore/libtdefakes.la $(LIBDL) $(LIBZ) +make_driver_db_cups_SOURCES = make_driver_db_cups.cpp +make_driver_db_cups_LDADD = ../libdriverparse.a $(top_builddir)/tdecore/libtdefakes.la $(LIBDL) $(LIBZ) $(LIB_QT) make_driver_db_cups_LDFLAGS = $(all_libraries) cupsdoprint_SOURCES = cupsdoprint.c diff --git a/tdeprint/cups/make_driver_db_cups.c b/tdeprint/cups/make_driver_db_cups.cpp index 0a0160275..021c77b95 100644 --- a/tdeprint/cups/make_driver_db_cups.c +++ b/tdeprint/cups/make_driver_db_cups.cpp @@ -29,7 +29,12 @@ #include <ctype.h> #include <zlib.h> -#include "driverparse.h" +#include <tqstringlist.h> +#include <tqlocale.h> + +extern "C" { + #include "driverparse.h" +} #define PROCESS_PPD_FILE_CONTENTS \ memset(value,0,256); \ @@ -126,7 +131,7 @@ void initPpd(const char *dirname) snprintf(drFile, 255, "ppd:%s", buffer); if (c && strncmp(c,".ppd",4) == 0) { - addFile(drFile, ""); + addFile(drFile, "", ""); } else if (c && strncmp(c, ".gz", 3) == 0) { /* keep also compressed driver files */ @@ -136,7 +141,7 @@ void initPpd(const char *dirname) } if (*c == '.' && strncmp(c, ".ppd",4) == 0) { - addFile(drFile, ""); + addFile(drFile, "", ""); } } } @@ -160,19 +165,19 @@ void initPpd(const char *dirname) ssize_t read; while ((read = getline(&line, &len, file)) != -1) { char * pos1 = strstr(line, "\""); - if (pos1 >= 0) { + if (pos1 != NULL) { char * pos2 = strstr(pos1 + 1, "\""); - if (pos2 >= 0) { + if (pos2 != NULL) { *pos2 = 0; char * pos3 = strstr(pos1 + 1, ":"); - if (pos3 >= 0) { + if (pos3 != NULL) { char *ppduri; int n2 = strlen("compressed-ppd:")+strlen(pos3+1); ppduri = (char*)malloc(n2*sizeof(char)+1); memset(ppduri,0,n2); strcat(ppduri, "compressed-ppd:"); strcat(ppduri, pos3+1); - addFile(ppduri, dirname); + addFile(ppduri, dirname, pos2+1); free(ppduri); ppduri = NULL; } @@ -198,7 +203,7 @@ void initPpd(const char *dirname) } } -int parsePpdFile(const char *filename, const char *origin, FILE *output_file) +int parsePpdFile(const char *filename, const char *origin, const char *metadata, FILE *output_file) { gzFile ppd_file; char line[4096], value[256], langver[64] = {0}, desc[256] = {0}; @@ -223,44 +228,116 @@ int parsePpdFile(const char *filename, const char *origin, FILE *output_file) return 1; } -int parseCompressedPpdFile(const char *ppdfilename, const char *origin, FILE *output_file) +int parseCompressedPpdFile(const char *ppdfilename, const char *origin, const char *metadata, FILE *output_file) { char value[256], langver[64] = {0}, desc[256] = {0}; char *c1, *c2; 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); + bool useFallbackExtractionMethod = false; - FILE* file = popen(filename, "r"); - if (file) { - char * line = NULL; - size_t len = 0; - ssize_t read; + if (strlen(metadata) > 0) { + TQString metadataProcessed(metadata); + metadataProcessed = metadataProcessed.stripWhiteSpace(); + TQStringList metadataList = TQStringList::split(" ", metadataProcessed, TRUE); + TQLocale ppdLanguage(metadataList[0]); + TQString languageVersion = TQLocale::languageToString(ppdLanguage.language()); + metadataList = TQStringList::split("\" \"", metadataProcessed, TRUE); + TQString description = metadataList[1]; - fprintf(output_file,"FILE=compressed-ppd:%s:%s\n", origin, ppdfilename); + int pos = metadataProcessed.find("MFG:"); + if (pos < 0) { + pos = metadataProcessed.find("MANUFACTURER:"); + } + if (pos >= 0) { + TQString manufacturer; + TQString model; + TQString modelName; + TQString pnpManufacturer; + TQString pnpModel; + TQString driver; + TQStringList metadataList = TQStringList::split(";", metadataProcessed.mid(pos), TRUE); + for (TQStringList::Iterator it = metadataList.begin(); it != metadataList.end(); ++it) { + TQStringList kvPair = TQStringList::split(":", *it, TRUE); + if ((kvPair[0].upper() == "MFG") || (kvPair[0].upper() == "MANUFACTURER")) { + manufacturer = kvPair[1]; + } + else if ((kvPair[0].upper() == "MDL") ||(kvPair[0].upper() == "MODEL")) { + modelName = kvPair[1]; + } +// else if (kvPair[0].upper() == "PNPMANUFACTURER") { +// pnpManufacturer = kvPair[1]; +// } +// else if (kvPair[0].upper() == "PNPMODEL") { +// pnpModel = kvPair[1]; +// } + else if ((kvPair[0].upper() == "DRV") || (kvPair[0].upper() == "DRIVER")) { + driver = kvPair[1]; + } + } + + TQStringList driverList = TQStringList::split(",", driver, TRUE); + driver = driverList[0]; + if (driver.startsWith("D")) { + driver = driver.mid(1); + } + model = manufacturer + " " + modelName + " " + driver; + description = description + " [" + languageVersion + "]"; - while ((read = getline(&line, &len, file)) != -1) { - PROCESS_PPD_FILE_CONTENTS + fprintf(output_file,"FILE=compressed-ppd:%s:%s\n", origin, ppdfilename); + + fprintf(output_file,"MANUFACTURER=%s\n",manufacturer.ascii()); + fprintf(output_file,"MODELNAME=%s\n",modelName.ascii()); + fprintf(output_file,"MODEL=%s\n",model.ascii()); + if (pnpManufacturer.length() > 0) { + fprintf(output_file,"PNPMANUFACTURER=%s\n",pnpManufacturer.ascii()); + } + if (pnpModel.length() > 0) { + fprintf(output_file,"PNPMODEL=%s\n",pnpModel.ascii()); + } + if (description.length() > 0) { + fprintf(output_file,"DESCRIPTION=%s\n",description.ascii()); + } } - if (line) { - free(line); + else { + useFallbackExtractionMethod = true; } - - pclose(file); - } - else { - fprintf(stderr, "Can't open driver file : %s\n", ppdfilename); - return 0; } - free(filename); - filename = NULL; + if (useFallbackExtractionMethod) { + 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=compressed-ppd:%s:%s\n", origin, ppdfilename); + + while ((read = getline(&line, &len, file)) != -1) { + PROCESS_PPD_FILE_CONTENTS + } + if (line) { + free(line); + } + + pclose(file); + } + else { + fprintf(stderr, "Can't open driver file : %s\n", ppdfilename); + return 0; + } + + free(filename); + filename = NULL; + } return 1; } diff --git a/tdeprint/driverparse.c b/tdeprint/driverparse.c index 8d850b837..4f733588a 100644 --- a/tdeprint/driverparse.c +++ b/tdeprint/driverparse.c @@ -30,13 +30,14 @@ char **files = NULL; char **fileorigins = NULL; +char **filemetadata = NULL; int nfiles = 0, maxfiles = 0; int nhandlers = 0, maxhandlers = 0; int nlibs = 0, maxlibs = 0; typedef struct { void (*init)(const char*); - int (*parse)(const char*, const char*, FILE*); + int (*parse)(const char*, const char*, const char*, FILE*); char *name; int namelen; } handler; @@ -60,7 +61,7 @@ void freeHandlers(void) free(handlers); } -void registerHandler(const char *name, void(*initf)(const char*), int(*parsef)(const char*, const char*, FILE*)) +void registerHandler(const char *name, void(*initf)(const char*), int(*parsef)(const char*, const char*, const char*, FILE*)) { handler *h = (handler*)malloc(sizeof(handler)); h->init = initf; @@ -110,6 +111,7 @@ void initFiles(void) maxfiles = 100; files = (char**)malloc(sizeof(char*) * maxfiles); fileorigins = (char**)malloc(sizeof(char*) * maxfiles); + filemetadata = (char**)malloc(sizeof(char*) * maxfiles); } void freeFiles(void) @@ -118,8 +120,10 @@ void freeFiles(void) for (i=0; i<nfiles; i++) free(files[i]); free(fileorigins[i]); + free(filemetadata[i]); free(files); free(fileorigins); + free(filemetadata); } void checkSize(void) @@ -129,16 +133,18 @@ void checkSize(void) maxfiles += 100; files = (char**)realloc(files, sizeof(char*) * maxfiles); fileorigins = (char**)realloc(fileorigins, sizeof(char*) * maxfiles); + filemetadata = (char**)realloc(filemetadata, sizeof(char*) * maxfiles); } } -void addFile(const char *filename, const char *origin) +void addFile(const char *filename, const char *origin, const char *metadata) { if (maxfiles == 0) initFiles(); checkSize(); files[nfiles] = strdup(filename); fileorigins[nfiles] = strdup(origin); + filemetadata[nfiles] = strdup(metadata); nfiles++; } @@ -273,7 +279,7 @@ int getMaticPrinterInfos(const char *base, const char *id, char *make, char *mod return 1; } -int parseMaticFile(const char *driver, const char *origin, FILE *output) +int parseMaticFile(const char *driver, const char *origin, const char *metadata, FILE *output) { FILE *drFile; char name[32] = {0}, @@ -377,7 +383,7 @@ void initMatic(const char *base) continue; else if (!S_ISREG(st.st_mode)) continue; - addFile(drFile, ""); + addFile(drFile, "", ""); } closedir(foodir); } @@ -443,7 +449,7 @@ int execute(int argc, char *argv[]) for (hi=0; hi<nhandlers; hi++) if (strncmp(files[i], handlers[hi]->name, handlers[hi]->namelen) == 0) { - handlers[hi]->parse(files[i]+handlers[hi]->namelen, fileorigins[i], dbFile); + handlers[hi]->parse(files[i]+handlers[hi]->namelen, fileorigins[i], filemetadata[i], dbFile); break; } fprintf(stdout, "%d\n", i); diff --git a/tdeprint/driverparse.h b/tdeprint/driverparse.h index 3e0d5d2fd..32c997f8c 100644 --- a/tdeprint/driverparse.h +++ b/tdeprint/driverparse.h @@ -23,9 +23,9 @@ #include <stdio.h> -void registerHandler(const char *name, void(*initf)(const char*), int(*parsef)(const char*, const char*, FILE*)); +void registerHandler(const char *name, void(*initf)(const char*), int(*parsef)(const char*, const char*, const char*, FILE*)); void initFoomatic(void); int execute(int argc, char *argv[]); -void addFile(const char *filename, const char *origin); +void addFile(const char *filename, const char *origin, const char *metadata); #endif diff --git a/tdeprint/lpr/make_driver_db_lpr.c b/tdeprint/lpr/make_driver_db_lpr.c index 17fa25bf5..8febe4c2b 100644 --- a/tdeprint/lpr/make_driver_db_lpr.c +++ b/tdeprint/lpr/make_driver_db_lpr.c @@ -114,7 +114,7 @@ void initAps(const char *base) gsversion = 1; } snprintf(drFile, 256, "apsfilter:%s/%s", base, d->d_name); - addFile(drFile, ""); + addFile(drFile, "", ""); } closedir(apsdir); } @@ -199,7 +199,7 @@ void initIfhp(const char *base) snprintf(path, 255, "lprngtool:%s/printerdb", base); if (access(path+10, R_OK) == 0) { - addFile(path, ""); + addFile(path, "", ""); } } |