// rdtextfile.cpp // // Spawn an external text file viewer. // // (C) Copyright 2002-2018 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // #include #include #include #include #include #include "rdapplication.h" #include "rdconf.h" #include "rd.h" #include "rdtempdirectory.h" #include bool RDTextFile(const QString &data,bool delete_on_exit) { char tmpfile[256]; QString editor=RD_LINUX_EDITOR; char cmd[PATH_MAX]; char *args[64]; if(!rda->station()->reportEditorPath().trimmed().isEmpty()) { editor=rda->station()->reportEditorPath(); } memset(args,0,sizeof(args)); QStringList f0=editor.split(" ",QString::SkipEmptyParts); if(f0.size()>64) { QMessageBox::warning(NULL,"File Error", "Too many arguments to report editor!"); return false; } strncpy(cmd,f0.at(0).toUtf8(),PATH_MAX); QStringList f1=f0.at(0).split("/"); args[0]=(char *)malloc(f1.back().toUtf8().size()+1); strcpy(args[0],f1.back().toUtf8()); for(int i=1;iaddTempFile(tmpfile); } args[f0.size()]=(char *)malloc(strlen(tmpfile)+1); strcpy(args[f0.size()],tmpfile); args[f0.size()+1]=(char *)NULL; if(fork()==0) { execvp(cmd,args); _exit(1); } return true; } bool RDTextViewer(const QString &filename) { QString editor=RD_LINUX_EDITOR; char cmd[PATH_MAX]; char *args[64]; if(!rda->station()->reportEditorPath().trimmed().isEmpty()) { editor=rda->station()->reportEditorPath(); } memset(args,0,sizeof(args)); QStringList f0=editor.split(" ",QString::SkipEmptyParts); if(f0.size()>64) { QMessageBox::warning(NULL,"File Error", "Too many arguments to report editor!"); return false; } strncpy(cmd,f0.at(0).toUtf8(),PATH_MAX); QStringList f1=f0.at(0).split("/"); args[0]=(char *)malloc(f1.back().toUtf8().size()+1); strcpy(args[0],f1.back().toUtf8()); for(int i=1;istation()->browserPath(); if(editor.isEmpty()) { QMessageBox::warning(NULL,"Error", "No web browser configured!"); return false; } memset(args,0,sizeof(args)); QStringList f0=editor.split(" ",QString::SkipEmptyParts); if(f0.size()>64) { QMessageBox::warning(NULL,"Error", "Too many arguments to web browser!"); return false; } strncpy(cmd,f0.at(0).toUtf8(),PATH_MAX); QStringList f1=f0.at(0).split("/"); args[0]=(char *)malloc(f1.back().toUtf8().size()+1); strcpy(args[0],f1.back().toUtf8()); for(int i=1;i