#include <display/QtViewer/QtApp.h>
#include <plotms/Gui/PlotMSPlotter.qo.h>
#include <plotms/PlotMS/PlotMS.h>
#if ! defined(WITHOUT_DBUS)
#include <plotms/PlotMS/PlotMSDBusApp.h>
#include <casadbus/utilities/Diagnostic.h>
#else
#include <plotms/PlotMS/grpcPlotMSAdaptor.qo.h>
#endif
#include <casacore/casa/System/AppState.h>
#include <algorithm>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <plotms/Plots/PlotMSPlotParameterGroups.h>
#include <plotms/Plots/PlotMSPlot.h>
#ifndef NO_CRASH_REPORTER
#include <stdcasa/StdCasa/CrashReporter.h>
#endif
#include <signal.h>
#include <QDebug>
#include <casa/namespace.h>
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#else
std::string read_link( const std::string &path ) {
int buffer_size = 128;
char *buffer = new char[buffer_size+1];
int nchars = readlink( path.c_str( ), buffer, buffer_size );
while ( nchars == buffer_size ) {
buffer_size *= 2;
delete [] buffer;
buffer = new char[buffer_size+1];
nchars = readlink( path.c_str( ), buffer, buffer_size );
}
std::string result;
if ( nchars > 0 ) {
buffer[nchars] = '\0';
char *exe = realpath(buffer,NULL);
result = exe;
free(exe);
}
delete [] buffer;
return result;
}
#endif
static std::string executable_path( ) {
#if defined(__APPLE__)
uint32_t size = PATH_MAX;
char *buffer = (char *) malloc(sizeof(char)*size);
if ( _NSGetExecutablePath(buffer, &size) == -1 ) {
++size;
buffer = (char *) realloc(buffer,sizeof(char)*size);
if ( _NSGetExecutablePath(buffer, &size) != 0 ) {
free(buffer);
fprintf( stderr, "cannot discover path to executable...\n" );
return "";
}
}