Index: kgv_miniwidget.cpp =================================================================== RCS file: /home/kde/kdegraphics/kghostview/kgv_miniwidget.cpp,v retrieving revision 1.146.2.1 retrieving revision 1.146.2.2 diff -u -5 -d -p -r1.146.2.1 -r1.146.2.2 --- kgv_miniwidget.cpp 2002/09/26 22:20:04 1.146.2.1 +++ kgv_miniwidget.cpp 2002/10/01 20:22:52 1.146.2.2 @@ -832,33 +832,43 @@ void KGVMiniWidget::setMagnification( do bool KGVMiniWidget::convertFromPDF( const QString& saveFileName, unsigned int firstPage, unsigned int lastPage ) { - QString cmd = QString( "gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pswrite " - "-sOutputFile=\"%1\" -dFirstPage=%2 -dLastPage=%3 -c save " - "pop -f \"%4\"" ) - .arg( QFile::encodeName( saveFileName ) ) - .arg( firstPage ) - .arg( lastPage ) - .arg( QFile::encodeName( _pdfFileName ) ); - - /* - QString cmd = QString( "pdftops -f %1 -l %2 \"%3\" \"%4\"" ) - .arg( firstPage ) - .arg( lastPage ) - .arg( QFile::encodeName( _pdfFileName ) ) - .arg( QFile::encodeName( saveFileName ) ); - */ - // TODO -- timeout/fail on this conversion (it can hang on a bad pdf) // TODO -- use output from gs (leave out -q) to drive a progress bar - kdDebug(4500) << "Executing command: " << cmd.local8Bit() << endl; - int r = system( cmd.local8Bit() ); + KProcess process; + process << _interpreterPath + << "-q" + << "-dNOPAUSE" + << "-dBATCH" + << "-dSAFER" + << "-sDEVICE=pswrite" + << ( QCString("-sOutputFile=")+QFile::encodeName(saveFileName) ) + << ( QString("-dFirstPage=")+QString::number( firstPage ) ) + << ( QString("-dLastPage=")+QString::number( lastPage ) ) + << "-c" + << "save" + << "pop" + << "-f" + << QFile::encodeName(_pdfFileName); - if( r ) { + /*QValueList args = process.args(); + QValueList::Iterator it = args.begin(); + for ( ; it != args.end() ; ++it ) + kdDebug() << ( *it ) << endl;*/ + + if( !process.start( KProcess::Block ) ) + { + kdError() << "convertFromPDF: Couldn't start gs process" << endl; + // TODO -- error message (gs not found?) + return false; + } + if ( !process.normalExit() || process.exitStatus() != 0 ) + { + kdError() << "convertFromPDF: normalExit=" << process.normalExit() << " exitStatus=" << process.exitStatus() << endl; // TODO -- error message (can't open, strerr()) return false; } return true; Index: dscparse.cpp =================================================================== RCS file: /home/kde/kdegraphics/kghostview/dscparse.cpp,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -5 -d -p -r1.4 -r1.4.2.1 --- dscparse.cpp 2002/02/15 11:37:50 1.4 +++ dscparse.cpp 2002/09/26 22:20:04 1.4.2.1 @@ -971,13 +971,17 @@ dsc_read_line(CDSC *dsc) * ::= Hex | Binary | ASCII (Type of data) * ::= Bytes | Lines (Read in bytes or lines) */ char begindata[MAXSTR+1]; int cnt; - const char *numberof, *bytesorlines; - memcpy(begindata, dsc->line, dsc->line_length); - begindata[dsc->line_length] = '\0'; + unsigned int num; + const char *numberof, *bytesorlines; + if ((num = dsc->line_length) >= sizeof(begindata)-1) + num = sizeof(begindata)-1; + + memcpy(begindata, dsc->line, num); + begindata[num] = '\0'; numberof = strtok(begindata+12, " \r\n"); strtok(NULL, " \r\n"); /* dump type */ bytesorlines = strtok(NULL, " \r\n"); if (bytesorlines == NULL) bytesorlines = "Bytes"; Index: kgv_miniwidget.cpp =================================================================== RCS file: /home/kde/kdegraphics/kghostview/kgv_miniwidget.cpp,v retrieving revision 1.146 retrieving revision 1.146.2.1 diff -u -5 -d -p -r1.146 -r1.146.2.1 --- kgv_miniwidget.cpp 2002/03/17 23:01:47 1.146 +++ kgv_miniwidget.cpp 2002/09/26 22:20:04 1.146.2.1 @@ -1144,11 +1144,12 @@ bool KGVMiniWidget::psCopyDoc( const QSt here = ftell( from ); if( pages_written || pages_atend ) { free( comment ); continue; } - sscanf( comment + length("%%Pages:" ), "%s", text ); + sscanf( comment + length("%%Pages:" ), "%256s", text ); + text[256] = 0; // Just in case of an overflow if( strcmp( text, "(atend)" ) == 0 ) { fputs( comment, to ); pages_atend = true; } else { Index: ps.c =================================================================== RCS file: /home/kde/kdegraphics/kghostview/ps.c,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -5 -d -p -r1.12 -r1.12.2.1 --- ps.c 2002/01/28 10:52:09 1.12 +++ ps.c 2002/09/26 22:20:04 1.12.2.1 @@ -69,13 +69,15 @@ pscopy(from, to, begin, end) fputs(line, to); if (!(DSCcomment(line) && iscomment(line+2, "Begin"))) { /* Do nothing */ } else if (iscomment(line+7, "Data:")) { + int rc = 0; text[0] = '\0'; - if (sscanf(line+length("%%BeginData:"), - "%d %*s %s", &num, text) >= 1) { + rc = sscanf(line+length("%%BeginData:"), "%d %*s %256s", &num,text); + text[256] = '\0'; + if (rc >= 1) { if (strcmp(text, "Lines") == 0) { for (i=0; i < num; i++) { fgets(line, sizeof line, from); fputs(line, to); } @@ -146,13 +148,15 @@ pscopyuntil(from, to, begin, end, commen } fputs(line, to); if (!(DSCcomment(line) && iscomment(line+2, "Begin"))) { /* Do nothing */ } else if (iscomment(line+7, "Data:")) { + int rc = 0; text[0] = '\0'; - if (sscanf(line+length("%%BeginData:"), - "%d %*s %s", &num, text) >= 1) { + rc = sscanf(line+length("%%BeginData:"), "%d %*s %256s", &num,text); + text[256] = '\0'; + if (rc >= 1) { if (strcmp(text, "Lines") == 0) { for (i=0; i < num; i++) { fgets(line, sizeof line, from); fputs(line, to); }