2016-07-20 Fred Gleason <fredg@paravelsystems.com>

* Added a 'save' command to rdclilogedit(1) in
	'utils/rdclilogedit/rdclilogedit.cpp' and
	'utils/rdclilogedit/rdclilogedit.h'.
	* Added a 'saveas' command to rdclilogedit(1) in
	'utils/rdclilogedit/rdclilogedit.cpp' and
	'utils/rdclilogedit/rdclilogedit.h'.
This commit is contained in:
Fred Gleason
2016-07-20 18:00:03 -04:00
parent 60ce6c966d
commit 8e0d803ba3
4 changed files with 116 additions and 9 deletions

View File

@@ -15311,3 +15311,10 @@
* Added a 'setcart' command to rdclilogedit(1) in
'utils/rdclilogedit/rdclilogedit.cpp' and
'utils/rdclilogedit/rdclilogedit.h'.
2016-07-20 Fred Gleason <fredg@paravelsystems.com>
* Added a 'save' command to rdclilogedit(1) in
'utils/rdclilogedit/rdclilogedit.cpp' and
'utils/rdclilogedit/rdclilogedit.h'.
* Added a 'saveas' command to rdclilogedit(1) in
'utils/rdclilogedit/rdclilogedit.cpp' and
'utils/rdclilogedit/rdclilogedit.h'.

View File

@@ -27,7 +27,8 @@ void MainObject::Help(const QStringList &cmds) const
if(cmds.size()==1) {
printf("\n");
printf("The following commands are available:\n");
printf("?, bye, exit, help, list, listlogs, load, quit, unload\n");
printf("?, bye, exit, help, list, listlogs, load, quit, save, saveas,\n");
printf("setcart, unload\n");
printf("\n");
printf("Enter \"? <cmd-name>\" for specific help.\n");
printf("\n");
@@ -67,6 +68,22 @@ void MainObject::Help(const QStringList &cmds) const
printf("\n");
processed=true;
}
if(verb=="save") {
printf("\n");
printf(" save\n");
printf("\n");
printf("Save the contents of the edit buffer.\n");
printf("\n");
processed=true;
}
if(verb=="saveas") {
printf("\n");
printf(" saveas <log-name>\n");
printf("\n");
printf("Save the contents of the edit buffer to new log <log-name>.\n");
printf("\n");
processed=true;
}
if(verb=="setcart") {
printf("\n");
printf(" setcart <line> <cart-num>\n");

View File

@@ -30,6 +30,7 @@
#include <rdcmd_switch.h>
#include <rdconf.h>
#include <rdcreate_log.h>
#include <rdescape_string.h>
#include "rdclilogedit.h"
@@ -189,25 +190,87 @@ void MainObject::List()
}
void MainObject::Save()
{
if(edit_log_event==NULL) {
fprintf(stderr,"save: no log loaded\n");
return;
}
if(edit_user->arrangeLog()) {
edit_log_event->save();
edit_log->
setModifiedDatetime(QDateTime(QDate::currentDate(),QTime::currentTime()));
}
else {
fprintf(stderr,"save: insufficient privileges [Rearrange Log Items]\n");
}
}
void MainObject::Saveas(const QString &logname)
{
QString sql;
RDSqlQuery *q;
if(edit_log_event==NULL) {
fprintf(stderr,"save: no log loaded\n");
return;
}
if(edit_user->arrangeLog()) {
RDLog *log=new RDLog(logname);
if(!log->exists()) {
sql=QString("insert into LOGS set ")+
"NAME=\""+RDEscapeString(logname)+"\","+
"TYPE=0,"+
"DESCRIPTION=\""+"Copy of "+RDEscapeString(edit_log->name())+"\","+
"ORIGIN_USER=\""+RDEscapeString(edit_user->name())+"\","+
"ORIGIN_DATETIME=now(),"+
"LINK_DATETIME=now(),"+
"MODIFIED_DATETIME=now(),"+
"SERVICE=\""+edit_log->service()+"\"";
q=new RDSqlQuery(sql);
delete q;
RDCreateLogTable(RDLog::tableName(logname));
edit_log_event->setLogName(RDLog::tableName(logname));
edit_log_event->save();
delete edit_log;
edit_log=log;
}
else {
fprintf(stderr,"saveas: log already exists\n");
delete log;
}
}
else {
fprintf(stderr,"saveas: insufficient privileges [Rearrange Log Items]\n");
}
}
void MainObject::Setcart(int line,unsigned cartnum)
{
if(edit_log_event==NULL) {
fprintf(stderr,"setcart: no log loaded\n");
return;
}
RDLogLine *logline=edit_log_event->logLine(line);
if(logline!=NULL) {
if((logline->type()==RDLogLine::Cart)||
(logline->type()==RDLogLine::Macro)) {
logline->setCartNumber(cartnum);
edit_log_event->refresh(line);
if(edit_user->arrangeLog()) {
RDLogLine *logline=edit_log_event->logLine(line);
if(logline!=NULL) {
if((logline->type()==RDLogLine::Cart)||
(logline->type()==RDLogLine::Macro)) {
logline->setCartNumber(cartnum);
edit_log_event->refresh(line);
}
else {
fprintf(stderr,"setcart: incompatible event type\n");
}
}
else {
fprintf(stderr,"setcart: incompatible event type\n");
fprintf(stderr,"setcart: no such line\n");
}
}
else {
fprintf(stderr,"setcart: no such line\n");
fprintf(stderr,"setcart: insufficient privileges [Rearrange Log Items]\n");
}
}
@@ -284,6 +347,24 @@ void MainObject::DispatchCommand(const QString &cmd)
processed=true;
}
if(verb=="save") {
Save();
processed=true;
}
if(verb=="saveas") {
if(cmds.size()==2) {
if(cmds[1].length()>64) {
fprintf(stderr,"saveas: log name too long\n");
}
Saveas(cmds[1]);
}
else {
fprintf(stderr,"saveas: invalid command arguments\n");
}
processed=true;
}
if(verb=="unload") {
Unload();
processed=true;

View File

@@ -50,6 +50,8 @@ class MainObject : public QObject
void ListLogs() const;
void Load(const QString &logname);
void List();
void Save();
void Saveas(const QString &logname);
void Setcart(int line,unsigned cartnum);
void Unload();
void DispatchCommand(const QString &cmd);