Kaydet (Commit) 3d318e6c authored tarafından deenafrancis's avatar deenafrancis Kaydeden (comit) Michael Meeks

fdo#70625 Add --cat parameter to make git diffs pretty

Change-Id: I309ca3e718a11ca97991686c229c79ab20e8c3d9
Reviewed-on: https://gerrit.libreoffice.org/10623Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 5794fcad
......@@ -2399,6 +2399,7 @@ void Desktop::OpenClients()
aRequest.aConversionParams = rArgs.GetConversionParams();
aRequest.aConversionOut = rArgs.GetConversionOut();
aRequest.aInFilter = rArgs.GetInFilter();
aRequest.bTextCat = rArgs.IsTextCat();
if ( !aRequest.aOpenList.empty() ||
!aRequest.aViewList.empty() ||
......
......@@ -190,6 +190,13 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier )
m_headless = true;
m_invisible = true;
}
else if ( oArg == "cat" )
{
m_textcat = true;
m_conversionparams = "txt:Text";
bOpenEvent = false;
bConversionEvent = true;
}
else if ( oArg == "quickstart" )
{
#if defined(ENABLE_QUICKSTART_APPLET)
......@@ -608,6 +615,7 @@ void CommandLineArgs::InitParamValues()
m_splashpipe = false;
m_bEmpty = true;
m_bDocumentArgs = false;
m_textcat = false;
}
......
......@@ -85,6 +85,7 @@ class CommandLineArgs: private boost::noncopyable
bool IsVersion() const { return m_version;}
bool HasModuleParam() const;
bool WantsToLoadDocument() const { return m_bDocumentArgs;}
bool IsTextCat() const { return m_textcat;}
OUString GetUnknown() const { return m_unknown;}
......@@ -145,6 +146,7 @@ class CommandLineArgs: private boost::noncopyable
bool m_helpbase;
bool m_version;
bool m_splashpipe;
bool m_textcat;
OUString m_unknown;
......
......@@ -124,7 +124,10 @@ namespace desktop
" Batch print files to file.\n"\
" If --outdir is not specified then current working dir is used as output_dir.\n"\
" Eg. --print-to-file *.doc\n"\
" --print-to-file --printer-name nasty_lowres_printer --outdir /home/user *.doc\n"\
" --print-to-file --printer-name nasty_lowres_printer --outdir /home/user *.doc\n" \
"--cat files\n"\
" Dump text content of the files to console\n"\
" Eg. --cat *.odt\n"\
"--pidfile file\n"\
" Store soffice.bin pid to file.\n"\
"-env:<VAR>[=<VALUE>]\n"\
......
......@@ -55,7 +55,10 @@
#include <vector>
#include <osl/thread.hxx>
#include <osl/file.hxx>
#include <osl/file.h>
#include <rtl/instance.hxx>
#include <iostream>
using namespace ::osl;
using namespace ::com::sun::star::uno;
......@@ -496,11 +499,12 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
else if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
aDispatchRequest.aRequestType == REQUEST_CONVERSION )
aDispatchRequest.aRequestType == REQUEST_CONVERSION ||
aDispatchRequest.aRequestType == REQUEST_CAT )
{
if ( xDoc.is() )
{
if ( aDispatchRequest.aRequestType == REQUEST_CONVERSION ) {
if ( aDispatchRequest.aRequestType == REQUEST_CONVERSION || aDispatchRequest.aRequestType == REQUEST_CAT ) {
Reference< XStorable > xStorable( xDoc, UNO_QUERY );
if ( xStorable.is() ) {
OUString aParam = aDispatchRequest.aPrinterName;
......@@ -531,6 +535,14 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
"/" +
aOutFilename.getName();
OUString fileForCat;
if( aDispatchRequest.aRequestType == REQUEST_CAT )
{
if( ::osl::FileBase::createTempFile(0, 0, &fileForCat) != ::osl::FileBase::E_None )
fprintf( stderr, "Error: Cannot create temporary file...\n" );
aOutFile = fileForCat;
}
if ( bGuess )
{
aFilter = impl_GuessFilter( aName, aOutFile );
......@@ -559,10 +571,13 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
OString aSource8 = OUStringToOString ( aTempName, RTL_TEXTENCODING_UTF8 );
FileBase::getSystemPathFromFileURL( aOutFile, aTempName );
OString aTargetURL8 = OUStringToOString(aTempName, RTL_TEXTENCODING_UTF8 );
printf("convert %s -> %s using %s\n", aSource8.getStr(), aTargetURL8.getStr(),
OUStringToOString( aFilter, RTL_TEXTENCODING_UTF8 ).getStr());
if( FStatHelper::IsDocument(aOutFile) )
printf("Overwriting: %s\n",OUStringToOString( aTempName, RTL_TEXTENCODING_UTF8 ).getStr() );
if( aDispatchRequest.aRequestType != REQUEST_CAT )
{
printf("convert %s -> %s using %s\n", aSource8.getStr(), aTargetURL8.getStr(),
OUStringToOString( aFilter, RTL_TEXTENCODING_UTF8 ).getStr());
if( FStatHelper::IsDocument( aOutFile ) )
printf("Overwriting: %s\n",OUStringToOString( aTempName, RTL_TEXTENCODING_UTF8 ).getStr() );
}
try
{
xStorable->storeToURL( aOutFile, conversionProperties );
......@@ -571,6 +586,36 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
{
fprintf( stderr, "Error: Please reverify input parameters...\n" );
}
if( aDispatchRequest.aRequestType == REQUEST_CAT )
{
osl::File aFile( fileForCat );
osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
if( aRC != osl::File::E_None )
{
fprintf( stderr, "Error: Cannot read from temp file\n" );
}
else
{
sal_Bool eof;
for( ;; )
{
aFile.isEndOfFile( &eof );
if( eof )
break;
rtl::ByteSequence bseq;
aFile.readLine( bseq );
unsigned const char * aStr = reinterpret_cast< unsigned char const * >( bseq.getConstArray() );
for( sal_Int32 i = 0; i < bseq.getLength(); i++ )
{
std::cout << aStr[i];
}
std::cout << "\n";
}
aFile.close();
osl::File::remove( fileForCat );
}
}
}
} else if ( aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ) {
OUString aParam = aDispatchRequest.aPrinterName;
......
......@@ -62,7 +62,8 @@ class DispatchWatcher : public ::cppu::WeakImplHelper1< ::com::sun::star::frame:
REQUEST_FORCENEW,
REQUEST_CONVERSION,
REQUEST_INFILTER,
REQUEST_BATCHPRINT
REQUEST_BATCHPRINT,
REQUEST_CAT
};
struct DispatchRequest
......
......@@ -975,14 +975,15 @@ static void AddConversionsToDispatchList(
const OUString& rParam,
const OUString& rPrinterName,
const OUString& rFactory,
const OUString& rParamOut )
const OUString& rParamOut,
const bool isTextCat )
{
DispatchWatcher::RequestType nType;
OUString aParam( rParam );
if( !rParam.isEmpty() )
{
nType = DispatchWatcher::REQUEST_CONVERSION;
nType = ( isTextCat ) ? DispatchWatcher::REQUEST_CAT : DispatchWatcher::REQUEST_CONVERSION;
aParam = rParam;
}
else
......@@ -1035,7 +1036,7 @@ bool OfficeIPCThread::ExecuteCmdLineRequests( ProcessDocumentsRequest& aRequest
AddToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aPrintToList, DispatchWatcher::REQUEST_PRINTTO, aRequest.aPrinterName, aRequest.aModule );
AddToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aForceOpenList, DispatchWatcher::REQUEST_FORCEOPEN, aEmpty, aRequest.aModule );
AddToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aForceNewList, DispatchWatcher::REQUEST_FORCENEW, aEmpty, aRequest.aModule );
AddConversionsToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aConversionList, aRequest.aConversionParams, aRequest.aPrinterName, aRequest.aModule, aRequest.aConversionOut );
AddConversionsToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aConversionList, aRequest.aConversionParams, aRequest.aPrinterName, aRequest.aModule, aRequest.aConversionOut, aRequest.bTextCat );
bool bShutdown( false );
if ( pGlobalOfficeIPCThread.is() )
......
......@@ -46,7 +46,7 @@ oslSignalAction SAL_CALL SalMainPipeExchangeSignal_impl(void* /*pData*/, oslSign
struct ProcessDocumentsRequest
{
ProcessDocumentsRequest(boost::optional< OUString > const & cwdUrl):
aCwdUrl(cwdUrl), pcProcessed( NULL ) {}
aCwdUrl(cwdUrl), pcProcessed( NULL ), bTextCat( false ) {}
boost::optional< OUString > aCwdUrl;
OUString aModule;
......@@ -63,6 +63,7 @@ struct ProcessDocumentsRequest
OUString aConversionOut;
std::vector< OUString > aInFilter;
::osl::Condition *pcProcessed; // pointer condition to be set when the request has been processed
bool bTextCat; // boolean flag indicating whether to dump text content to screen
};
class DispatchWatcher;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment