/// Function name : duplicateParameterArray // Description : Create a duplicate of a parameter array, also duplicating the parameters within // // CONST PARAMETER_ARRAY* pArray : [in] ParameterArray to duplicate // // Return Value : New ParameterArray, you are responsible for destroying it // PARAMETER_ARRAY* duplicateParameterArray(CONST PARAMETER_ARRAY* pArray) { PARAMETER_ARRAY* pCopy; // Array being created // Create new array pCopy = utilCreateEmptyObject(PARAMETER_ARRAY); // Allocate enough storage for all parameters pCopy->pItems = utilCreateEmptyObjectArray(PARAMETER*, pArray->iSize); // Copy properties pCopy->iSize = pArray->iSize; pCopy->iCount = pArray->iCount; // Duplicate parameters for (UINT i = 0; i < pArray->iSize; i++) { if (pArray->pItems[i]) pCopy->pItems[i] = duplicateParameter(pArray->pItems[i]); } // Return new copy of object return pCopy; }
QString PostscriptDialog::buildTempfile() { // build command m_program = "pstops"; // default m_param = ""; switch (m_PostscriptDialog.m_cbTask->currentIndex()) { case PS_A5_EMPTY: m_param = "1:0L(29.7cm,0cm)"; break; case PS_A5_DUPLICATE: m_param = "1:0L(29.7cm,0cm)+0L(29.7cm,14.85cm)"; break; case PS_2xA5: m_param = "2:0L(29.7cm,0cm)+1L(29.7cm,14.85cm)"; break; case PS_2xA5L: break; case PS_4xA5: m_param = "4:[email protected](0cm,8.7cm)" "[email protected](10.5cm,8.7cm)" "[email protected](0cm,-6.15cm)" "[email protected](10.5cm,-6.15cm)"; break; case PS_A4_EMPTY: m_param = "1:[email protected](21cm,0cm)"; break; case PS_A4_DUPLICATE: m_param = "1:[email protected](21cm,0cm)[email protected](21cm,14.85cm)"; break; case PS_2xA4: m_param = "2:[email protected](21cm,0cm)[email protected](21cm,14.85cm)"; break; case PS_2xA4L: m_param = "2:[email protected](0cm,29.7cm)[email protected](0cm,14.85cm)"; break; case PS_EVEN: m_program = "psselect"; m_param = "-e"; break; case PS_ODD: m_program = "psselect"; m_param = "-o"; break; case PS_EVEN_REV: m_program = "psselect"; m_param = "-e -r"; break; case PS_ODD_REV: m_program = "psselect"; m_param = "-o -r"; break; case PS_REVERSE: m_program = "psselect"; m_param = "-r"; break; case PS_COPY_SORTED: m_program = "psselect"; m_param = "-p" + duplicateParameter("1-"); break; case PS_COPY_UNSORTED: m_param = "1:" + duplicateParameter("0"); break; case PS_PSTOPS_FREE: m_param = m_PostscriptDialog.m_edParameter->text(); break; case PS_PSSELECT_FREE: m_program = "psselect"; m_param = m_PostscriptDialog.m_edParameter->text(); break; } // create a temporary file QTemporaryFile temp; //code was temp.setSuffix(".sh"); //Add to constructor and adapt if necessay: QDir::tempPath() + QLatin1String("/myapp_XXXXXX") + QLatin1String(".sh") temp.setAutoRemove(false); if(!temp.open()) { KILE_DEBUG_MAIN << "Could not create tempfile in QString PostscriptDialog::buildTempfile()" ; return QString(); } QString tempname = temp.fileName(); QTextStream stream(&temp); stream << "#! /bin/sh" << endl; // accept only ".ps" or ".ps.gz" as an input file QFileInfo fi(m_PostscriptDialog.m_edInfile->lineEdit()->text()); bool zipped_psfile = (fi.completeSuffix() == "ps.gz") ? true : false; // there are four possible cases // outfile view // 1) + + pstops/psselect + okular // 2) + - pstops/psselect // 3) - + pstops/psselect | okular (nur Shell) // 4) - - error (already detected by checkParameter()) // some files, which are used QString command = m_program + " \"" + m_param + "\""; QString inputfile = "\"" + m_PostscriptDialog.m_edInfile->lineEdit()->text() + "\""; QString outputfile = "\"" + m_PostscriptDialog.m_edOutfile->lineEdit()->text() + "\""; bool viewer = m_PostscriptDialog.m_cbView->isChecked(); bool equalfiles = false; if (inputfile == outputfile) { outputfile = tempname + ".tmp"; equalfiles = true; } if (!zipped_psfile) { // unzipped ps files if (m_PostscriptDialog.m_edOutfile->lineEdit()->text().isEmpty()) { // pstops/psselect | okular stream << command << " " << inputfile << " | okular -" << endl; viewer = false; } else { // pstops/psselect stream << command << " " << inputfile << " " << outputfile << endl; } } else { // zipped ps files if (m_PostscriptDialog.m_edOutfile->lineEdit()->text().isEmpty()) { // pstops/psselect | okular stream << "gunzip -c " << inputfile << " | " << command << " | okular -" << endl; viewer = false; } else { stream << "gunzip -c " << inputfile // pstops/psselect << " | " << command << " > " << outputfile << endl; } } // check, if we should stop if ( equalfiles || viewer ) { stream << "if [ $? != 0 ]; then" << endl; stream << " exit 1" << endl; stream << "fi" << endl; } // replace the original file if ( equalfiles ) { stream << "rm " << inputfile << endl; stream << "mv " << outputfile << " " << inputfile << endl; } // viewer if ( viewer ) { // viewer: okular stream << "okular" << " " << ((equalfiles) ? inputfile : outputfile) << endl; } // everything is prepared to do the job temp.close(); return(tempname); }