Initial import of CVS-v2_8_branch

This commit is contained in:
Fred Gleason
2014-08-12 15:13:02 -04:00
commit afd67c7af8
1508 changed files with 405304 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
## automake.am
##
## Automake.am for rivendell/utils/rdcollect
##
## (C) Copyright 2002-2010 Fred Gleason <fredg@paravelsystems.com>
##
## $Id: Makefile.am,v 1.2.8.2 2012/12/03 16:53:46 cvs Exp $
##
## 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.
##
## Use automake to process this into a Makefile.in
AM_CPPFLAGS = -Wall -DPREFIX=\"$(prefix)\" -DQTDIR=\"@QT_DIR@\" @QT_CXXFLAGS@
INCLUDES = -I$(top_srcdir)/lib
LIBS = @QT_LIBS@ -L$(top_srcdir)/lib
MOC = @QT_MOC@
# The dependency for qt's Meta Object Compiler (moc)
moc_%.cpp: %.h
$(MOC) $< -o $@
bin_PROGRAMS = rdcollect
dist_rdcollect_SOURCES = rdcollect.cpp rdcollect.h
rdcollect_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
EXTRA_DIST = rdcollect.pro
CLEANFILES = *~\
*.exe\
*.idb\
*ilk\
*.obj\
*.pdb\
*.qm\
moc_*
MAINTAINERCLEANFILES = *~\
*.tar.gz\
aclocal.m4\
configure\
Makefile.in\
moc_*

View File

@@ -0,0 +1,214 @@
// rdcollect.cpp
//
// Collect and combine log exports into a single file.
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: rdcollect.cpp,v 1.2.8.1 2012/08/01 19:21:09 cvs Exp $
//
// 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 <stdlib.h>
#include <errno.h>
#include <qapplication.h>
#include <qdir.h>
#include <rdcmd_switch.h>
#include <rdconf.h>
#include <rdcollect.h>
MainObject::MainObject(QObject *parent,const char *name)
:QObject(parent,name)
{
bool ok;
int err;
std::vector<unsigned> line_index;
hours_offset=0;
minutes_offset=3;
seconds_offset=6;
//
// Read Command Options
//
RDCmdSwitch *cmd=
new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdcollect",RDCOLLECT_USAGE);
for(unsigned i=0;i<cmd->keys();i++) {
if(cmd->key(i)=="--source-file") {
source_files.push_back(cmd->value(i));
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--destination-file") {
destination_file=cmd->value(i);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--hours-offset") {
hours_offset=cmd->value(i).toUInt(&ok);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--minutes-offset") {
minutes_offset=cmd->value(i).toUInt(&ok);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--seconds-offset") {
seconds_offset=cmd->value(i).toUInt(&ok);
cmd->setProcessed(i,true);
}
}
if(!cmd->allProcessed()) {
fprintf(stderr,"rdcollect: unknown option\n");
exit(256);
}
if(source_files.size()==0) {
fprintf(stderr,"rdcollect: missing --source-file argument\n");
exit(256);
}
if(destination_file.isEmpty()) {
fprintf(stderr,"rdcollect: missing --destination-file argument\n");
exit(256);
}
//
// Process Data
//
QStringList src_lines;
for(unsigned i=0;i<source_files.size();i++) {
QStringList src_dirs=GetDirectoryList(source_files[i]);
LoadSourceFiles(RDGetBasePart(source_files[i]),src_dirs,&src_lines);
}
SortLines(&src_lines,&line_index);
if((err=WriteOutputFile(destination_file,src_lines,&line_index))!=0) {
fprintf(stderr,"rdollect: %s\n",strerror(err));
exit(256);
}
exit(0);
}
QStringList MainObject::GetDirectoryList(const QString &src_file)
{
QStringList ret;
QString base_dir=RDGetPathPart(src_file);
base_dir=base_dir.left(base_dir.length()-1);
QDir dir(base_dir);
dir.setFilter(QDir::Dirs);
ret.push_back(dir.path());
AddDirs(base_dir,&ret);
return ret;
}
void MainObject::LoadSourceFiles(const QString &src_name,
const QStringList &dirs,QStringList *lines)
{
for(unsigned i=0;i<dirs.size();i++) {
LoadSourceFile(dirs[i]+"/"+src_name,lines);
}
}
void MainObject::LoadSourceFile(const QString &filename,QStringList *lines)
{
Q_LONG n;
QString line;
QFile file(filename);
if(!file.open(IO_ReadOnly|IO_Translate)) {
return;
}
while((n=file.readLine(line,1024))>0) {
lines->push_back(line.left(line.length()-1));
}
file.close();
}
void MainObject::SortLines(QStringList *lines,std::vector<unsigned> *index)
{
std::vector<QTime> start_times;
//
// Initialize Index
//
for(unsigned i=0;i<lines->size();i++) {
index->push_back(i);
start_times.push_back(ReadTime((*lines)[i]));
}
//
// Sort
//
bool modified=true;
while(modified) {
modified=false;
for(unsigned i=1;i<lines->size();i++) {
if(start_times[i-1]>start_times[i]) {
QTime time=start_times[i-1];
start_times[i-1]=start_times[i];
start_times[i]=time;
unsigned line=index->at(i-1);
index->at(i-1)=index->at(i);
index->at(i)=line;
modified=true;
}
}
}
}
int MainObject::WriteOutputFile(const QString &filename,
const QStringList &lines,
std::vector<unsigned> *index)
{
FILE *f=NULL;
if((f=fopen(filename,"w"))==NULL) {
return errno;
}
for(unsigned i=0;i<lines.size();i++) {
fprintf(f,"%s\n",(const char *)lines[index->at(i)]);
}
fclose(f);
return 0;
}
void MainObject::AddDirs(const QString &path,QStringList *dirs)
{
QDir dir(path);
dir.setFilter(QDir::Dirs);
QStringList list=dir.entryList();
for(unsigned i=0;i<list.size();i++) {
if((list[i]!=".")&&(list[i]!="..")) {
dirs->push_back(path+"/"+list[i]);
AddDirs(path+"/"+list[i],dirs);
}
}
}
QTime MainObject::ReadTime(const QString &line)
{
return QTime(line.mid(hours_offset,2).toInt(),
line.mid(minutes_offset,2).toInt(),
line.mid(seconds_offset,2).toInt());
}
int main(int argc,char *argv[])
{
QApplication a(argc,argv,false);
new MainObject(NULL,"main");
return a.exec();
}

View File

@@ -0,0 +1,57 @@
// rdcollect.h
//
// Collect and combine log exports into a single file.
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id:
//
// 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.
//
#ifndef RDCOLLECT_H
#define RDCOLLECT_H
#include <vector>
#include <qobject.h>
#include <qstringlist.h>
#define RDCOLLECT_USAGE "[options]\n\nCollect and combine log exports from a set of directories into a single file.\n\n--source-file=<file-name>\n Name of source file. The path part of this value will be taken as the\n top of the directory tree to recurse, while the name part will be used as\n the name of the source file(s) to search for. This option may be given\n multiple times.\n\n--destination-file=<file-name>\n Name of file to which to send output.\n\n--hours-offset=<offset>\n Start position of the hours field on a data line\n\n--minutes-offset=<offset>\n Start position of the minutes field on a data line\n\n--seconds-offset=<offset>\n Start position of the seconds field on a data line\n"
class MainObject : public QObject
{
public:
MainObject(QObject *parent=0,const char *name=0);
private:
QStringList GetDirectoryList(const QString &src_file);
void LoadSourceFiles(const QString &src_name,const QStringList &dirs,
QStringList *lines);
void LoadSourceFile(const QString &filename,QStringList *lines);
void SortLines(QStringList *lines,std::vector<unsigned> *index);
int WriteOutputFile(const QString &filename,const QStringList &lines,
std::vector<unsigned> *index);
void AddDirs(const QString &path,QStringList *dirs);
QTime ReadTime(const QString &line);
QStringList source_files;
QString destination_file;
unsigned hours_offset;
unsigned minutes_offset;
unsigned seconds_offset;
};
#endif // RDCOLLECT_H

View File

@@ -0,0 +1,44 @@
# rdcollect.pro
#
# The utils/rdcollect QMake project file for Rivendell
#
# (C) Copyright 2003-2007 Fred Gleason <fredg@paravelsystems.com>
#
# $Id: rdcollect.pro,v 1.2 2010/07/29 19:32:39 cvs Exp $
#
# 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.
TEMPLATE = app
TARGET = rdcollect
win32 {
DEFINES += WIN32
DEFINES += VERSION=\"$$[VERSION]\"
DEFINES += PACKAGE=\"rivendell\"
DEFINES += PACKAGE_VERSION=\"$$[VERSION]\"
DEFINES += PACKAGE_NAME=\"rivendell\"
DEFINES += PACKAGE_BUGREPORT=\"fredg@paravelsystems.com\"
}
SOURCES += rdcollect.cpp
HEADERS += rdcollect.h
RES_FILE += ..\..\icons\rivendell.res
INCLUDEPATH += ..\..\..\libradio\radio ..\..\lib
LIBS = -lqui -L..\..\..\libradio\radio -lradio -L..\..\lib -llib
CONFIG += qt