Commit 63b3a308 authored by Cecilia Akerlund's avatar Cecilia Akerlund

Initial commit 2

parent f301fd88
This diff is collapsed.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
# Makefile
ifdef OPT
OFLAGS = -O3
else
# Mac OS: uncomment if problems with linking libraries not compiled for 64 bits architecture
#OFLAGS = -m32 -g
OFLAGS = -g
endif
CXX = g++ #./our-g++
# CXXFLAGS = $(OFLAGS) -DGZLIB -Wall $(PG) ${DEFINES}
CXXFLAGS = $(OFLAGS) -Wall ${DEFINES}
CC = g++ #./our-g++
CFLAGS = $(OFLAGS) -Wall ${DEFINES}
OBJ1 = readtokens.o table.o
OBJ2 = format.o formatdispatch.o formatbinary.o formatdiscr.o formatcont.o formatsymbol.o formattime.o formatunknown.o
OBJ3 = data.o datafile.o datadispatch.o
all: libdataformat.a
makeformat: makeformat.o ${OBJ1} ${OBJ2} ${OBJ3}
libdataformat.a: ${OBJ1} ${OBJ2} ${OBJ3}
rm -f libdataformat.a
ar clq libdataformat.a $^
ranlib libdataformat.a
clean:
rm -f ${OBJ1} ${OBJ2} ${OBJ3}
depend:
rm -f make.depend
${CC} -MM *.cc ${CFLAGS} > make.depend
include make.depend
# Makefile
ifdef OPT
OFLAGS = -O3
else
# Mac OS: uncomment if problems with linking libraries not compiled for 64 bits architecture
#OFLAGS = -m32 -g
OFLAGS = -g
endif
CXX = ./our-g++
#CXXFLAGS = $(OFLAGS) -DGZLIB -DINTFLOAT_LONG -Wall $(PG) ${DEFINES}
CXXFLAGS = $(OFLAGS) -DINTFLOAT_LONG -Wall ${DEFINES}
CC = gcc
CFLAGS = $(OFLAGS) -Wall ${DEFINES}
OBJ1 = readtokens.o table.o
OBJ2 = format.o formatdispatch.o formatbinary.o formatdiscr.o formatcont.o formatsymbol.o formattime.o formatunknown.o
OBJ3 = data.o datafile.o datadispatch.o
all: libdataformat.a
makeformat: makeformat.o ${OBJ1} ${OBJ2} ${OBJ3}
libdataformat.a: ${OBJ1} ${OBJ2} ${OBJ3}
rm -f libdataformat.a
ar clq libdataformat.a $^
ranlib libdataformat.a
clean:
rm -f ${OBJ1} ${OBJ2} ${OBJ3}
depend:
rm -f make.depend
${CC} -MM *.cc ${CFLAGS} > make.depend
include make.depend
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef GZLIB
#include <zlib.h>
#endif
#include "readtokens.hh"
#include "format.hh"
#include "data.hh"
/*
class DataObject {
public:
DataObject();
DataObject(class Format* fr, const char* datafile = 0);
DataObject(class Format* fr, FILE* datafile);
DataObject(const char* formatfile, const char* datafile = 0);
virtual ~DataObject();
virtual void clear();
virtual void remove(int ind, int n = 1);
virtual union intfloat* newentry();
virtual int read(const char* datafile, int append = 0);
virtual int save(const char* datafile, int standard = 0);
virtual char* getname(int n);
virtual int findname(const char* str);
virtual int hasnames();
virtual void sort(int (*func)(union intfloat* v1, union intfloat* v2));
virtual union intfloat* operator[](int i) { if (i<(bl<0 ? num : num-1))
return (*data)[(bl<0 || bl>i ? i : i+1)];
return 0; };
virtual void block(int i) { bl = i; };
virtual int size() { return (bl<0 ? num : num-1); };
virtual int length() { return len; };
virtual class Format* format() { return form; };
virtual void setformat(Format* f, int own = 0) { if (!form) { form = f; len = f->length(); ownform = own; }};
protected:
virtual int read_file(FILE* f, int append = 0);
virtual int internal_read(FILE* f);
virtual int internal_save(FILE* f);
int bl;
int num;
int len;
Format* form;
int ownform;
class Growable<union intfloat* > *data;
};
*/
DataObject::DataObject()
{
num = 0;
len = 0;
bl = -1;
form = 0;
ownform = 0;
data = new Growable<intfloat*>(0, 128);
}
DataObject::DataObject(class Format* fr, const char* datafile)
{
num = 0;
bl = -1;
form = fr;
ownform = 0;
len = form->length();
data = new Growable<intfloat*>(0, 128);
if (datafile)
read(datafile);
}
DataObject::DataObject(class Format* fr, FILE* datafile)
{
num = 0;
bl = -1;
form = fr;
ownform = 0;
len = form->length();
data = new Growable<intfloat*>(0, 128);
if (datafile)
read_file(datafile);
}
DataObject::DataObject(const char* formatfile, const char* datafile)
{
num = 0;
bl = -1;
data = new Growable<intfloat*>(0, 128);
form = new Format();
ownform = 1;
form->read(formatfile);
len = form->length();
if (len == -1) {
fprintf(stderr, "Failed to read format file \"%s\"\n", formatfile);
return;
}
if (datafile)
read(datafile);
}
DataObject::~DataObject()
{
clear();
delete data;
if (ownform)
delete form;
}
void DataObject::clear()
{
intfloat* vec;
if (data) {
FORVEC(*data, vec)
delete [] vec;
data->remove(num);
num = 0;
}
}
void DataObject::remove(int ind, int n)
{
int i;
if (data) {
if (ind + n > num)
n = num - ind;
for (i=ind; i<n+ind; i++) {
delete [] (*data)[i];
(*data)[i] = (*data)[i+n];
}
for (; i<num-n; i++)
(*data)[i] = (*data)[i+n];
data->remove(n);
num -= n;
}
}
union intfloat* DataObject::newentry()
{
intfloat* vec;
vec = new intfloat[len];
(*data)[num++] = vec;
return vec;
}
int DataObject::read(const char* datafile, int append)
{
FILE* f;
if ((f = fopen(datafile, "r")) == 0) {
fprintf(stderr, "Failed to read data file \"%s\"\n", datafile);
return -1;
}
int status = read_file(f, append);
fclose(f);
return status;
}
int DataObject::read_file(FILE* f, int append) {
int status;
if (!append) {
clear();
}
status = internal_read(f);
return (status ? num : -1);
}
#ifdef GZLIB
extern FILE *gz_file;
extern gzFile gz_gzfile;
void getfirst(FILE *f)
{
int c = fgetc(f);
//printf("char1 = %d\n", c);
rewind(f);
if (c == 31) {
gz_gzfile = gzdopen(fileno(f), "rb");
//printf("gzf = %p\n", gz_gzfile);
gz_file = f;
} else {
gz_gzfile = NULL;
gz_file = NULL;
}
}
#endif
int DataObject::internal_read(FILE* f)
{
intfloat* vec;
TokenLink* row;
int* trans = 0;
int translen;
#ifdef GZLIB
getfirst(f);
#endif
row = readtokens(f);
if (form->check_header(row)) {
if (hasnames()) {
trans = form->get_translation(row, translen);
} else {
form->extract_header(row);
}
freetokens(row);
row = readtokens(f);
}
while (row) {
if (!*row->token && !row->next) {
freetokens(row);
row = readtokens(f);
continue;
}
vec = new intfloat[len];
if (trans)
form->insert_input_translated(row, vec, trans, translen);
else
form->insert_input(row, vec);
(*data)[num++] = vec;
freetokens(row);
row = readtokens(f);
}
if (trans) delete [] trans;
return 1;
}
int DataObject::save(const char* datafile, int standard)
{
FILE* f;
int status;
if (!data) {
fprintf(stderr, "No data to save\n");
return -1;
}
if ((f = fopen(datafile, "w")) == 0) {
fprintf(stderr, "Failed to save data to file \"%s\"\n", datafile);
return -1;
}
if (standard)
status = DataObject::internal_save(f);
else
status = internal_save(f);
fclose(f);
return (status ? 0 : -1);
}
int DataObject::internal_save(FILE* f)
{
intfloat* vec;
if (hasnames())
form->save_header(f);
FORVEC(*data, vec)
form->save_output(f, vec);
return 1;
}
char* DataObject::getname(int n)
{
FormatSpec* f;
f = form->nth(n);
if (f)
return f->name;
else
return 0;
}
int DataObject::findname(const char* str)
{
FormatSpec* f = form->nth(0);
int i = 0;
while (f && (!f->name || strcmp(str, f->name)))
f = f->next, i++;
return (f ? i : -1);
}
int DataObject::hasnames()
{
FormatSpec* f;
f = form->nth(0);
while (f && !f->name)
f = f->next;
return (f ? 1 : 0);
}
static int (*intern_sfunc)(union intfloat* v1, union intfloat* v2);
static int hfunc(const void* p1, const void* p2)
{
return intern_sfunc(*(intfloat**)p1, *(intfloat**)p2);
}
void DataObject::sort(int (*func)(union intfloat* v1, union intfloat* v2))
{
intern_sfunc = func;
qsort(data->vect(), num, sizeof(intfloat*), hfunc);
}
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#ifndef DATA_HH
#define DATA_HH
#include "growable.hh"
#include <stdio.h>
class DataObject {
public:
DataObject();
DataObject(class Format* fr, const char* datafile = 0);
DataObject(class Format* fr, FILE* datafile);
DataObject(const char* formatfile, const char* datafile = 0);
virtual ~DataObject();
virtual void clear();
virtual void remove(int ind, int n = 1);
virtual union intfloat* newentry();
virtual int read(const char* datafile, int append = 0);
virtual int save(const char* datafile, int standard = 0);
virtual char* getname(int n);
virtual int findname(const char* str);
virtual int hasnames();
virtual void sort(int (*func)(union intfloat* v1, union intfloat* v2));
virtual union intfloat* operator[](int i) { if (i<(bl<0 ? num : num-1))
return (*data)[(bl<0 || bl>i ? i : i+1)];
return 0; };
virtual void block(int i) { bl = i; };
virtual int size() { return (bl<0 ? num : num-1); };
virtual int length() { return len; };
virtual class Format* format() { return form; };
virtual void setformat(Format* f, int own = 0) { if (!form) { form = f; len = f->length(); ownform = own; }};
protected:
virtual int read_file(FILE* f, int append = 0);
virtual int internal_read(FILE* f);
virtual int internal_save(FILE* f);
int bl;
int num;
int len;
Format* form;
int ownform;
class Growable<union intfloat* > *data;
};
#endif /* DATA_HH */
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include "format.hh"
#include "data.hh"
#include "datadispatch.hh"
DataObject* read_data(char* datafile)
{
Format* format = new Format();
format->construct(datafile);
return new DataObject(format, datafile);
}
DataObject* read_data(class Format* fr, char* datafile)
{
return new DataObject(fr, datafile);
}
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
class DataObject* read_data(char* datafile);
class DataObject* read_data(class Format* fr, char* datafile);
/*
--------------------------------------------------------------------------
Copyright (C) 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#ifndef _MSC_VER // Microsoft Visual C++
#include <unistd.h>
#endif
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include "readtokens.hh"
#include "format.hh"
#include "data.hh"
#include "datafile.hh"
#ifdef _MSC_VER // Microsoft Visual C++
#include <io.h>
#define open _open
#define fdopen _fdopen
#endif
/*
class DataFileObject : public DataObject {
public:
DataFileObject(class Format* fr, const char* datafile) : DataObject(fr) { init(datafile); };
DataFileObject(const char* formatfile, const char* datafile) : DataObject(formatfile) { init(datafile); };
void init(const char* datafile);
virtual ~DataFileObject();
virtual void clear();
virtual void remove(int ind, int n = 1) {}; // Finns ej
virtual union intfloat* newentry() { return 0; }; // Finns ej
virtual int read(const char* datafile, int append = 0);
virtual int save(const char* datafile, int standard = 0) { return -1; }; // Finns ej
virtual void sort(int (*func)(union intfloat* v1, union intfloat* v2)) {}; // Inte n...
virtual union intfloat* operator[](int i);
protected:
virtual int read_start(const char* datafile);
virtual void read_stop();
virtual int read_one(off64_t pos, intfloat* vec);
class Growable<off64_t> *datapos;
off64_t lastpos;
int cachesize;
int* cacheind;
union intfloat** cachevec;
int currind;
int* trans;
int translen;
int fd;
FILE* fp;
int complete;
};
*/
void DataFileObject::init(const char* datafile)
{
int i;
datapos = new Growable<off64_t>(0, 1048576);
cachesize = 8;
cacheind = new int[cachesize];
cachevec = new intfloat*[cachesize];
for (i=0; i<cachesize; i++) {
cacheind[i] = -1;
cachevec[i] = new intfloat[len];
}
currind = -1;
trans = 0;
translen = 0;
fd = -1;
fp = 0;
complete = 1;
read_start(datafile);
}
DataFileObject::~DataFileObject()
{
int i;
if (!complete)
read_stop();
delete datapos;
delete [] cacheind;
for (i=0; i<cachesize; i++)
delete [] cachevec[i];
delete [] cachevec;
if (trans)
delete [] trans;
}
void DataFileObject::clear()
{
int i;
if (num) {
delete datapos;
datapos = new Growable<off64_t>(0, 1048576);
}
for (i=0; i<cachesize; i++) {
if (cachevec[i])
delete [] cachevec[i];
cachevec[i] = new intfloat[len];
cacheind[i] = -1;
}
currind = -1;
}
int DataFileObject::read(const char* datafile, int append)
{
int status;
clear(); // Ignore append - always clear
if (!complete)
read_stop();
status = read_start(datafile);
return (status ? num : -1);
}
int DataFileObject::read_start(const char* datafile)
{
TokenLink* row;
if ((fd = open(datafile, O_RDONLY | O_LARGEFILE)) == -1) {
fprintf(stderr, "Failed to open data file \"%s\"\n", datafile);
return -1;
}
fp = fdopen(fd, "r"); // Nu har vi samma fil bde som en fd och en FILE*, bda behvs
row = readtokens(fp);
if (form->check_header(row)) {
if (hasnames()) {
trans = form->get_translation(row, translen);
} else {
form->extract_header(row);
}
freetokens(row);
} else { // Ta hand om den oavsiktligt lsta dataraden
currind = (currind+1)%cachesize;
form->insert_input(row, cachevec[currind]);
(*datapos)[0] = 0;
num++;
freetokens(row);
}
lastpos = ftell(fp);
num++;
complete = 0;
return 1;
}
void DataFileObject::read_stop()
{
if (!complete) {
num -= 1;
fclose(fp);
complete = 1;
}
}
int DataFileObject::read_one(off64_t pos, intfloat* vec)
{
TokenLink* row;
fseek(fp, pos, SEEK_SET);
row = readtokens(fp);
if (!row || (!*row->token && !row->next)) {
if (row)
freetokens(row);
if (feof(fp)) {
clearerr(fp);
return -1;
} else
return 0;
}
if (ferror(fp)) {
freetokens(row);
return -1;
}
if (trans)
form->insert_input_translated(row, vec, trans, translen);
else
form->insert_input(row, vec);
freetokens(row);
return 1;
}
intfloat* DataFileObject::operator[](int i)
{
TokenLink* row;
int j;
if (i<0)
return 0;
if (bl >= 0 && bl <= i)
i += 1;
if (complete && i >= num)
return 0;
if (!complete && i >= num-1) {
fseek(fp, lastpos, SEEK_SET);
row = 0;
for (j=num-1; j<=i; j++) {
if (row)
freetokens(row);
row = readtokens(fp);
while (!row || (!*row->token && !row->next)) {
if (row)
freetokens(row);
if (feof(fp) || ferror(fp)) {
clearerr(fp);
num = j;
complete = 1;
return 0;
}
lastpos = ftell(fp);
row = readtokens(fp);
}
(*datapos)[j] = lastpos;
lastpos = ftell(fp);
}
currind = (currind+1)%cachesize;
if (trans)
form->insert_input_translated(row, cachevec[currind], trans, translen);
else
form->insert_input(row, cachevec[currind]);
cacheind[currind] = i;
num = i+2;
freetokens(row);
return cachevec[currind];
} else {
for (j=currind; j>=0; j--)
if (cacheind[j] == i)
return cachevec[j];
for (j=cachesize-1; j>currind; j--)
if (cacheind[j] == i)
return cachevec[j];
currind = (currind+1)%cachesize;
read_one((*datapos)[i], cachevec[currind]);
cacheind[currind] = i;
return cachevec[currind];
}
}
// Repetition
// Nr filen ppnas, kolla headrar och stt trans, om en rad lst stoppa in i cache
// Nr man accessar en rad:
// om den finns i cache, returnera
// om den finns i tabellen, anvnd read_one som hanterar cachen
// om inte complete, ls fram till rtt index, ha koll p filslut och stt complete
// annars skicka tillbaka 0
/*
--------------------------------------------------------------------------
Copyright (C) 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#ifdef __APPLE__
#include "TargetConditionals.h"
#if TARGET_OS_MAC
/* [PD] off64_t is not defined in BSD, and thus not in darwin (Mac OS X)
either. We can use off_t instead since it is 64-bit in BSD. */
#define off64_t off_t
/* [PD] O_LARGEFILE is not defined in darwin (Mac OS X), and apparently
not necessary. */
#define O_LARGEFILE 0
#endif
#endif
#ifdef PLATFORM_MSW // [PD] Tentatively only check for WIN32.
// I don't know what to do (if anything) on WIN64.
// [Arndt] _WIN32 doesn't work on cygwin; use our own
/* [PD] O_LARGEFILE is apparently not necessary on MS Windows. */
#define O_LARGEFILE 0
#ifdef _MSC_VER // Microsoft Visual C++
#include <sys/types.h> // off_t
#endif
#define off64_t off_t
#endif
class DataFileObject : public DataObject {
public:
DataFileObject(class Format* fr, const char* datafile) : DataObject(fr) { init(datafile); };
DataFileObject(const char* formatfile, const char* datafile) : DataObject(formatfile) { init(datafile); };
void init(const char* datafile);
virtual ~DataFileObject();
virtual void clear();
virtual void remove(int ind, int n = 1) {}; // Finns ej
virtual union intfloat* newentry() { return 0; }; // Finns ej
virtual int read(const char* datafile, int append = 0);
virtual int save(const char* datafile, int standard = 0) { return -1; }; // Finns ej
virtual void sort(int (*func)(union intfloat* v1, union intfloat* v2)) {}; // Inte n...
virtual union intfloat* operator[](int i);
protected:
virtual int read_start(const char* datafile);
virtual void read_stop();
virtual int read_one(off64_t pos, intfloat* vec);
class Growable<off64_t> *datapos;
off64_t lastpos;
int cachesize;
int* cacheind;
union intfloat** cachevec;
int currind;
int* trans;
int translen;
int fd;
FILE* fp;
int complete;
};
This diff is collapsed.
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#ifndef FORMAT_HH
#define FORMAT_HH
#include <stdio.h>
#include <string.h>
#include "intfloat.hh"
#include "growable.hh"
enum {FORMATSPEC_NYI = -1,
FORMATSPEC_UNKNOWN = 0,
FORMATSPEC_BINARY = 1,
FORMATSPEC_DISCR = 2,
FORMATSPEC_CONT = 3,
FORMATSPEC_SYMBOL = 4};
class FormatSpec {
friend class Format;
public:
FormatSpec(const char* nm = 0);
virtual ~FormatSpec() { if (name) delete [] name; };
virtual FormatSpec* copy() { return 0; };
virtual void init(struct TokenLink* row) {};
virtual void setname(const char* nm);
virtual char* stripname(struct TokenLink*& row);
virtual void printname(FILE* f);
virtual void add(const char* str) {};
virtual void save(FILE* f) {};
virtual intfloat interpret(const char* str) { intfloat r; r.i = -1; return r; };
virtual const char* represent(intfloat v) { return "?"; };
virtual int get_discr(int val) { return -1; };
virtual const char* get_symbol(int val) { return 0; };
virtual void usurp(class FormatSpecUnknown* ele) {};
virtual int type() { return FORMATSPEC_NYI; };
virtual int getnum() { return -1; };
char* name;
FormatSpec* next;
int unset;
};
class Format {
public:
Format();
~Format();
int read(const char* name);
int save(const char* name);
int simple_construct(const char* formcodes);
int construct(const char* name);
int check_header(TokenLink* row);
void extract_header(TokenLink* row);
int* get_translation(TokenLink* row, int& tl);
void add(FormatSpec* formspec);
int length() { return (unset ? -1 : len); };
FormatSpec* nth(int n) { FormatSpec* f; for(f=list; f&&n; n--,f=f->next); return f; };
FormatSpec* findcolumn(const char* name) { FormatSpec* f; for (f=list; f && (!f->name || strcmp(name, f->name)); f = f->next); return f; };
int findcolumnnr(const char* name) { int n; FormatSpec* f; for (f=list, n=0; f && (!f->name || strcmp(name, f->name)); f = f->next, n += 1); return n; };
void insert_input(TokenLink* tok, intfloat* vec);
void insert_input_translated(TokenLink* tok, intfloat* vec, int* trans, int tl);
void save_output(FILE* f, intfloat* vec);
void save_header(FILE* f);
int numsections();
int getsection(int n);
void newsection();
protected:
void internal_construct(TokenLink* row);
void internal_add(TokenLink* row, int ln);
void internal_guess();
int len;
int unset;
FormatSpec* list;
class Growable<int> *section_hints;
};
extern int global_format_quiet;
#endif
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include "readtokens.hh"
#include "format.hh"
#include "formatbinary.hh"
/*
class FormatSpecBinary : public FormatSpec {
public:
FormatSpecBinary(const char* nm = 0) : FormatSpec(nm) {};
virtual FormatSpec* copy() { FormatSpecBinary* fs = new FormatSpecBinary(name); fs->unset = unset; return fs; };
virtual void init(struct TokenLink* tok);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual const char* represent(intfloat v);
virtual int type() { return FORMATSPEC_BINARY; };
};
*/
void FormatSpecBinary::init(struct TokenLink* tok)
{
name = stripname(tok);
if (tok->next)
{ if (!global_format_quiet) fprintf(stderr, "Too many binary format arguments: %s ...\n", tok->token); }
}
void FormatSpecBinary::save(FILE* f)
{
printname(f);
fprintf(f, "binary:\n");
}
void FormatSpecBinary::add(const char* str)
{
IF_FLOAT val;
if (is_unknown(str))
;
else if (!is_cont(str) || ((val = get_cont(str)) < 0.0) || (val > 1.0))
{ if (!global_format_quiet) fprintf(stderr, "Bad binary value: %s\n", str); }
}
intfloat FormatSpecBinary::interpret(const char* str)
{
intfloat res;
if (is_unknown(str))
res.i = -1;
else if (is_cont(str))
res.f = get_cont(str);
else {
res.i = -1;
{ if (!global_format_quiet) fprintf(stderr, "Bad binary value: %s\n", str); }
}
return res;
}
const char* FormatSpecBinary::represent(intfloat v)
{
static char buf[12];
if (v.i == -1)
return "?";
else
return sprintf(buf, "%.5f", v.f), buf;
}
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
class FormatSpecBinary : public FormatSpec {
public:
FormatSpecBinary(const char* nm = 0) : FormatSpec(nm) {};
virtual FormatSpec* copy() { FormatSpecBinary* fs = new FormatSpecBinary(name); fs->unset = unset; return fs; };
virtual void init(struct TokenLink* tok);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual const char* represent(intfloat v);
virtual int type() { return FORMATSPEC_BINARY; };
};
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include "readtokens.hh"
#include "format.hh"
#include "formatunknown.hh"
#include "formatcont.hh"
/*
class FormatSpecCont : public FormatSpec {
public:
FormatSpecCont(const char* nm = 0) : FormatSpec(nm) { min = 0.0; max = 0.0; };
virtual FormatSpec* copy() { FormatSpecCont* fs = new FormatSpecCont(name); fs->min = min; fs->max = max; fs->unset = unset; return fs; };
virtual void init(struct TokenLink* row);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual const char* represent(intfloat v);
virtual void usurp(FormatSpecUnknown* ele);
virtual int type() { return FORMATSPEC_CONT; };
float min;
float max;
};
*/
void FormatSpecCont::init(struct TokenLink* tok)
{
name = stripname(tok);
tok = tok->next;
if (!tok)
;
else if (tok->next && !tok->next->next) {
if (is_cont(tok->token) &&
is_cont(tok->next->token)) {
unset = 0;
min = get_cont(tok->token);
max = get_cont(tok->next->token);
} else {
{ if (!global_format_quiet) fprintf(stderr, "Strange cont format arguments: %s %s\n",
tok->token, tok->next->token); }
}
}
else {
if (!tok->next)
{ if (!global_format_quiet) fprintf(stderr, "Bad number of cont format arguments: %s\n",
tok->token); }
else
{ if (!global_format_quiet) fprintf(stderr, "Bad number of cont format arguments: %s %s %s ...\n",
tok->token, tok->next->token, tok->next->next->token); }
}
}
void FormatSpecCont::save(FILE* f)
{
printname(f);
if (unset)
fprintf(f, "cont:\n");
else
fprintf(f, "cont:\t%g\t%g\n", min, max);
}
void FormatSpecCont::add(const char* str)
{
IF_FLOAT val;
if (is_unknown(str))
;
else if (is_cont(str)) {
val = get_cont(str);
if (unset) {
min = val;
max = val;
unset = 0;
}
else if (val < min) {
min = val;
}
else if (val > max) {
max = val;
}
}
else
{ if (!global_format_quiet) fprintf(stderr, "Bad cont value: %s\n", str); }
}
intfloat FormatSpecCont::interpret(const char* str)
{
intfloat res;
if (unset) {
unset = 0;
}
if (is_unknown(str))
res.i = -1;
else if (is_cont(str))
res.f = get_cont(str);
else {
res.i = -1;
{ if (!global_format_quiet) fprintf(stderr, "Bad cont value: %s\n", str); }
}
return res;
}
const char* FormatSpecCont::represent(intfloat v)
{
static char buf[20];
if (v.i == -1)
return "?";
else
return sprintf(buf, "%f", v.f), buf;
}
void FormatSpecCont::usurp(FormatSpecUnknown* ele)
{
if (!ele->unset) {
if (unset) {
unset = 0;
min = ele->min;
max = ele->max;
} else {
if (min > ele->min)
min = ele->min;
if (max < ele->max)
max = ele->max;
}
}
}
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
class FormatSpecCont : public FormatSpec {
public:
FormatSpecCont(const char* nm = 0) : FormatSpec(nm) { min = 0.0; max = 0.0; };
virtual FormatSpec* copy() { FormatSpecCont* fs = new FormatSpecCont(name); fs->min = min; fs->max = max; fs->unset = unset; return fs; };
virtual void init(struct TokenLink* row);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual const char* represent(intfloat v);
virtual void usurp(FormatSpecUnknown* ele);
virtual int type() { return FORMATSPEC_CONT; };
float min;
float max;
};
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include "readtokens.hh"
#include "format.hh"
#include "formatunknown.hh"
#include "formatdiscr.hh"
/*
class FormatSpecDiscr : public FormatSpec {
public:
FormatSpecDiscr(const char* nm = 0) : FormatSpec(nm) { offset = 0; num = 0; dynamic = 0; };
virtual FormatSpec* copy() { FormatSpecDiscr* fs = new FormatSpecDiscr(name); fs->offset = offset; fs->num = num; fs->dynamic = dynamic; fs->unset = unset; return fs; };
virtual void init(struct TokenLink* tok);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual const char* represent(intfloat v);
virtual int get_discr(int val);
virtual void usurp(FormatSpecUnknown* ele);
virtual int type() { return FORMATSPEC_DISCR; };
virtual int getnum() { return num; };
IF_INT offset;
IF_INT num;
int dynamic;
};
*/
void FormatSpecDiscr::init(struct TokenLink* tok)
{
name = stripname(tok);
tok = tok->next;
if (!tok)
;
else if (!tok->next) {
if (is_posint(tok->token)) {
unset = 0;
offset = 0;
num = get_posint(tok->token);
} else {
{ if (!global_format_quiet) fprintf(stderr, "Strange discr format argument: %s\n", tok->token); }
}
}
else if (!tok->next->next) {
if ((is_posint(tok->token) || is_negint(tok->token)) &&
is_posint(tok->next->token)) {
unset = 0;
offset = get_posint(tok->token);
num = get_posint(tok->next->token) - offset + 1;
} else {
{ if (!global_format_quiet) fprintf(stderr, "Strange discr format arguments: %s %s\n",
tok->token, tok->next->token); }
}
}
else {
{ if (!global_format_quiet) fprintf(stderr, "To many discr format arguments: %s %s %s ...\n",
tok->token, tok->next->token, tok->next->next->token); }
}
}
void FormatSpecDiscr::save(FILE* f)
{
printname(f);
if (unset)
fprintf(f, "discr:\n");
else if (offset == 0)
fprintf(f, "discr:\t%d\n", num);
else
fprintf(f, "discr:\t%d\t%d\n", offset,
num + offset - 1);
}
void FormatSpecDiscr::add(const char* str)
{
IF_INT val;
if (is_unknown(str))
;
else if (is_posint(str) || is_negint(str)) {
val = get_posint(str);
if (unset) {
offset = val;
num = 1;
unset = 0;
}
else if (val < offset && !dynamic) {
num += (offset - val);
offset = val;
}
else if (val >= num + offset) {
num = val - offset + 1;
}
}
else
{ if (!global_format_quiet) fprintf(stderr, "Bad discr value: %s\n", str); }
}
intfloat FormatSpecDiscr::interpret(const char* str)
{
intfloat res;
if (unset) {
unset = 0;
dynamic = 1;
}
if (is_unknown(str))
res.i = -1;
else if (is_posint(str) || (is_negint(str) && offset < 0)) {
res.i = get_posint(str) - offset;
if (dynamic && res.i >= num)
num = res.i + 1;
} else {
res.i = -1;
{ if (!global_format_quiet) fprintf(stderr, "Bad discr value: %s\n", str); }
}
return res;
}
const char* FormatSpecDiscr::represent(intfloat v)
{
static char buf[12];
if (v.i == -1)
return "?";
else
return sprintf(buf, "%lld", (long long)(v.i + offset)), buf;
}
int FormatSpecDiscr::get_discr(int val)
{
return val + offset;
}
void FormatSpecDiscr::usurp(FormatSpecUnknown* ele)
{
if (!ele->unset) {
if (unset) {
unset = 0;
offset = (int) ele->min;
num = (int) ele->max - offset + 1;
} else {
if (offset > (int) ele->min)
num += (offset - (int) ele->min), offset = (int) ele->min;
if (num + offset <= (int) ele->max)
num = (int) ele->max - offset + 1;
}
}
}
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
class FormatSpecDiscr : public FormatSpec {
public:
FormatSpecDiscr(const char* nm = 0) : FormatSpec(nm) { offset = 0; num = 0; dynamic = 0; };
virtual FormatSpec* copy() { FormatSpecDiscr* fs = new FormatSpecDiscr(name); fs->offset = offset; fs->num = num; fs->dynamic = dynamic; fs->unset = unset; return fs; };
virtual void init(struct TokenLink* tok);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual const char* represent(intfloat v);
virtual int get_discr(int val);
virtual void usurp(FormatSpecUnknown* ele);
virtual int type() { return FORMATSPEC_DISCR; };
virtual int getnum() { return num; };
int offset;
int num;
int dynamic;
};
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#include <string.h>
#include "format.hh"
#include "readtokens.hh"
#include "formatbinary.hh"
#include "formatdiscr.hh"
#include "formatcont.hh"
#include "formatsymbol.hh"
#include "formattime.hh"
#include "formatunknown.hh"
#include "formatignore.hh"
#include "formatdispatch.hh"
FormatSpec* format_create(TokenLink* tok)
{
if (*tok->token == '"' && tok->next)
tok = tok->next;
if (!strcmp(tok->token, "binary:"))
return new FormatSpecBinary;
else if (!strcmp(tok->token, "discr:"))
return new FormatSpecDiscr;
else if (!strcmp(tok->token, "cont:"))
return new FormatSpecCont;
else if (!strcmp(tok->token, "symbol:"))
return new FormatSpecSymbol;
else if (!strcmp(tok->token, "date:") || !strcmp(tok->token, "time:") ||
!strcmp(tok->token, "datetime:") || !strcmp(tok->token, "seconds:") ||
!strcmp(tok->token, "millisec:"))
return new FormatSpecDatetime;
else if (!strcmp(tok->token, "ignored:"))
return new FormatSpecIgnore;
else
return new FormatSpecUnknown;
}
FormatSpec* format_create(char ch)
{
FormatSpecDatetime* ret;
if (ch=='b')
return new FormatSpecBinary;
else if (ch=='d')
return new FormatSpecDiscr;
else if (ch=='c')
return new FormatSpecCont;
else if (ch=='s')
return new FormatSpecSymbol;
else if (ch=='D') {
ret = new FormatSpecDatetime;
ret->dtformbits = 2;
ret->dtformspec = 0;
return ret;
}
else if (ch=='t'){
ret = new FormatSpecDatetime;
ret->dtformbits = 1;
ret->dtformspec = 0;
return ret;
}
else if (ch=='T') {
ret = new FormatSpecDatetime;
ret->dtformbits = 3;
ret->dtformspec = 0;
return ret;
}
else if (ch=='-')
return new FormatSpecIgnore;
else
return new FormatSpecUnknown;
}
FormatSpec* format_guess(char* str, int force)
{
IF_FLOAT val;
/*
int fmt;
*/
int b;
const char* fs;
if (is_unknown(str) || is_posint(str)) {
if (force)
return new FormatSpecUnknown;
else
return 0;
} else if (is_cont(str)) {
if ((val = get_cont(str)) < 0.0 || val > 1.0)
return new FormatSpecCont;
else if (force)
return new FormatSpecUnknown;
else
return 0;
/*
} else if ((fmt = check_datetime(str))) {
FormatSpecDatetime* ret;
ret = new FormatSpecDatetime;
ret->dtform = fmt;
return ret;
*/
} else if (check_datetime(str, 27, b, fs)) {
FormatSpecDatetime* ret;
ret = new FormatSpecDatetime;
ret->dtformbits = b;
ret->dtformspec = fs;
return ret;
} else
return new FormatSpecSymbol;
}
FormatSpec* format_guess_unknown(class FormatSpecUnknown* ele)
{
if (ele->unset)
return 0;
else if ((ele->min == 0.0) && (ele->max == 1.0))
return new FormatSpecBinary;
else if ((ele->min <= 1.0) &&
(ele->min == (int) ele->min) &&
(ele->max == (int) ele->max) &&
(ele->max - ele->min <= ele->num))
return new FormatSpecDiscr;
else if ((ele->max - ele->min < 1.0) ||
((ele->max - ele->min >= 20) &&
(ele->num >= 15)))
return new FormatSpecCont;
else if (ele->num < 15)
return new FormatSpecSymbol;
else
return 0;
}
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
FormatSpec* format_create(struct TokenLink* tok);
FormatSpec* format_create(char ch);
FormatSpec* format_guess(char* str, int force);
FormatSpec* format_guess_unknown(class FormatSpecUnknown* ele);
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
class FormatSpecIgnore : public FormatSpec {
public:
FormatSpecIgnore(const char* nm = 0) : FormatSpec(nm) {};
virtual ~FormatSpecIgnore() {};
virtual FormatSpec* copy() { return new FormatSpecIgnore(name); };
virtual void init(struct TokenLink* tok) { name = stripname(tok); };
virtual void add(const char* str) { };
virtual void save(FILE* f) { printname(f); fprintf(f, "ignored:\n"); };
virtual intfloat interpret(const char* str) { intfloat res; res.i = -1; return res; };
virtual int type() { return 99; };
};
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include "readtokens.hh"
#include "table.hh"
#include "format.hh"
#include "formatunknown.hh"
#include "formatsymbol.hh"
/*
class FormatSpecSymbol : public FormatSpec {
public:
FormatSpecSymbol(const char* nm = 0);
virtual ~FormatSpecSymbol();
virtual FormatSpec* copy();
virtual void init(struct TokenLink* tok);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual const char* represent(intfloat v);
virtual const char* get_symbol(int val);
virtual void usurp(class FormatSpecUnknown* ele);
virtual int type() { return FORMATSPEC_SYMBOL; };
virtual int getnum() { return num; };
int num;
class IndexTable* table;
int dynamic;
};
*/
FormatSpecSymbol::FormatSpecSymbol(const char* nm)
: FormatSpec(nm)
{
num = 0;
table = new IndexTable;
dynamic = 0;
}
FormatSpecSymbol::~FormatSpecSymbol()
{
delete table;
}
FormatSpec* FormatSpecSymbol::copy()
{
FormatSpecSymbol* fs = new FormatSpecSymbol(name);
fs->num = num;
delete fs->table;
fs->table = table->copy();
fs->dynamic = dynamic;
fs->unset = unset;
return fs;
}
void FormatSpecSymbol::init(struct TokenLink* tok)
{
name = stripname(tok);
tok = tok->next;
if (tok) {
unset = 0;
num = 0;
while (tok) {
table->insert_last(tok->token);
num++;
tok = tok->next;
}
}
}
void FormatSpecSymbol::save(FILE* f)
{
printname(f);
if (unset)
fprintf(f, "symbol:\n");
else {
char* str;
fprintf(f, "symbol:");
table->reset();
while ((str = table->next()))
fprintf(f, "\t%s", str);
fprintf(f, "\n");
}
}
void FormatSpecSymbol::add(const char* str)
{
if (unset)
unset = 0;
if (is_unknown(str))
;
else if (table->get(str) < 0) {
table->insert(str);
num += 1;
}
}
intfloat FormatSpecSymbol::interpret(const char* str)
{
intfloat res;
if (unset) {
unset = 0;
dynamic = 1;
}
if (is_unknown(str))
res.i = -1;
else {
res.i = table->get(str);
if (res.i == -1) {
if (dynamic) {
table->insert_last(str);
res.i = num++;
} else
{ if (!global_format_quiet) fprintf(stderr, "Unknown symbol: %s\n", str); }
}
}
return res;
}
const char* FormatSpecSymbol::represent(intfloat v)
{
if (v.i == -1)
return "?";
else
return table->nth((int)v.i);
}
const char* FormatSpecSymbol::get_symbol(int val)
{
return table->nth(val);
}
void FormatSpecSymbol::usurp(FormatSpecUnknown* ele)
{
char* sym;
if (!ele->unset) {
if (unset) {
unset = 0;
num = 0;
table = new IndexTable;
}
ele->table->reset();
while ((sym = ele->table->next()))
if (table->get(sym) < 0) {
table->insert(sym);
num += 1;
}
}
}
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
class FormatSpecSymbol : public FormatSpec {
public:
FormatSpecSymbol(const char* nm = 0);
virtual ~FormatSpecSymbol();
virtual FormatSpec* copy();
virtual void init(struct TokenLink* tok);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual const char* represent(intfloat v);
virtual const char* get_symbol(int val);
virtual void usurp(class FormatSpecUnknown* ele);
virtual int type() { return FORMATSPEC_SYMBOL; };
virtual int getnum() { return num; };
int num;
class IndexTable* table;
int dynamic;
};
This diff is collapsed.
/*
--------------------------------------------------------------------------
Copyright (C) 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#ifndef FORMAT_TIME_HH
#define FORMAT_TIME_HH
class FormatSpecDatetime : public FormatSpec {
public:
FormatSpecDatetime(const char* nm = 0) : FormatSpec(nm) { dtformbits = 0; dtformspec = 0; first.i = last.i = -1; };
virtual ~FormatSpecDatetime() { if (dtformspec) delete [] dtformspec; };
virtual FormatSpec* copy() { FormatSpecDatetime* fs = new FormatSpecDatetime(name); fs->dtformbits = dtformbits; fs->dtformspec = (dtformspec ? strcpy(new char[strlen(dtformspec)+1], dtformspec): 0); fs->first = first; fs->last = last; fs->unset = unset; return fs; };
virtual void init(struct TokenLink* tok);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual const char* represent(intfloat v);
virtual void get_time(int val, int& h, int& mi, int& s);
virtual void get_date(int val, int& y, int& mo, int& d);
virtual void usurp(FormatSpecUnknown* ele);
virtual int type() { return 5; };
int dtformbits;
const char* dtformspec;
intfloat first, last;
};
extern int check_datetime(const char* str, int trybits, int& dtfbits, const char*& dtfspec);
extern int check_formated_datetime(const char*str, int dtfbits, const char* dtfspec);
#endif
This diff is collapsed.
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#define FormatSpecType -1
#define FormatSpecUnknownType 0
#define FormatSpecBinaryType 1
#define FormatSpecDiscrType 2
#define FormatSpecContType 3
#define FormatSpecSymbolType 4
#define FormatSpecDatetimeType 5
#define IsType(form, tp) (form->type() == tp##Type)
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include "readtokens.hh"
#include "table.hh"
#include "format.hh"
#include "formatunknown.hh"
/*
class FormatSpecUnknown : public FormatSpec {
public:
FormatSpecUnknown(const char* nm = 0) : FormatSpec(nm) {};
virtual ~FormatSpecUnknown();
virtual FormatSpec* copy();
virtual void init(struct TokenLink* tok);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual int type() { return 0; };
IF_FLOAT min;
IF_FLOAT max;
int num, nseen;
class IndexTable* table;
};
*/
FormatSpecUnknown::~FormatSpecUnknown()
{
delete table;
}
FormatSpec* FormatSpecUnknown::copy()
{
FormatSpecUnknown* fs = new FormatSpecUnknown(name);
fs->min = min;
fs->max = max;
fs->num = num;
fs->nseen = nseen;
fs->table = table->copy();
fs->unset = unset;
return fs;
}
void FormatSpecUnknown::init(struct TokenLink* tok)
{
name = stripname(tok);
if (tok != NULL)
{ if (!global_format_quiet) fprintf(stderr, "Unknown format type: %s\n", tok->token); }
else
{ if (!global_format_quiet) fprintf(stderr, "Unknown format type: %s\n", name); }
}
void FormatSpecUnknown::save(FILE* f)
{
printname(f);
if (unset)
fprintf(f, "unknown:\n");
else
fprintf(f, "unknown:\t%g\t%g\t%d\n", min, max, num);
{ if (!global_format_quiet) fprintf(stderr, "Unknown format type saved\n"); }
}
void FormatSpecUnknown::add(const char* str)
{
IF_FLOAT val;
if (is_unknown(str))
;
else if (unset) {
unset = 0;
min = max = get_cont(str);
num = nseen = 1;
table = new IndexTable;
table->insert(str);
} else {
val = get_cont(str);
if (val < min)
min = val;
else if (val > max)
max = val;
nseen += 1;
if (table->get(str) < 0) {
table->insert(str);
num += 1;
}
}
}
intfloat FormatSpecUnknown::interpret(const char* str)
{
intfloat res;
res.i = -1;
return res;
}
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
class FormatSpecUnknown : public FormatSpec {
public:
FormatSpecUnknown(const char* nm = 0) : FormatSpec(nm) {table = NULL;};
virtual ~FormatSpecUnknown();
virtual FormatSpec* copy();
virtual void init(struct TokenLink* tok);
virtual void add(const char* str);
virtual void save(FILE* f);
virtual intfloat interpret(const char* str);
virtual int type() { return 0; };
float min;
float max;
int num, nseen;
class IndexTable* table;
};
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#ifndef TEMPLATE_GROWABLE
#define TEMPLATE_GROWABLE
template<class T> class Growable {
public:
Growable(int sz = 0, int chunk = 64){
num = 0;
_size = 0;
_chunk = chunk;
vec = curr = 0;
resize(sz);
num = sz;
};
Growable(const Growable<T> &grow, int chunk = 64){
T *vec1, *vec2;
int i;
num = 0;
_size = 0;
vec = curr = 0;
resize(grow.num);
num = grow.num;
for (i=0, vec1=grow.vec, vec2=vec; i<num; i++, vec1++, vec2++)
*vec2 = *vec1;
};
~Growable() {delete [] vec;}
Growable<T>& operator=(Growable<T> &grow){
T *vec1, *vec2;
int i;
if (grow.num > _size) {
num = 0;
delete [] vec;
vec = 0;
resize(grow.num);
}
curr = vec;
num = grow.num;
for (i=0, vec1=grow.vec, vec2=vec; i<num; i++, vec1++, vec2++)
*vec2 = *vec1;
return *this;
};
T* vect() {return vec;}
Growable<T>& operator<<(T val) { int i=add(1); vec[i]=val; return *this;};
T& operator[](int i) {if (i>=num) add(i-num+1);
return *((curr = vec + i + 1) - 1);}
T& operator()() {return *curr++;}
Growable<T>& reset() {curr = vec; return *this;}
int end() {return (curr >= vec + num);}
int current() { return curr - vec; }
int size() {return num;}
int operator!() {return (num == 0);}
operator int() {return (num > 0);}
int add(int n = 1){
int tn = num;
if (num + n > _size)
resize(num + n);
num += n;
return tn;
};
int remove(int n = 1){
num -= n;
if (num < 0)
num = 0;
if (num < _size - 2*_chunk)
resize(num);
return num;
};
private:
void resize(int sz){
T *newvec, *vec1, *vec2;
int i, tcurr;
sz = ((sz - 1) / _chunk + 1) * _chunk;
if (_size != sz) {
_size = sz;
if (_size > 10 * _chunk) _chunk *= 2;
newvec = new T[_size];
num = (num > _size ? _size : num);
tcurr = (curr - vec);
tcurr = (tcurr > _size ? _size : tcurr);
for (i=0, vec1=newvec, vec2=vec; i<num; i++, vec1++, vec2++)
*vec1 = *vec2;
delete [] vec;
vec = newvec;
curr = vec + tcurr;
}
};
int _size;
int _chunk;
int num;
T *curr;
T *vec;
};
#define FORVEC( grow, var) for((grow).reset(); !((grow).end())&&((var=(grow)()),1); )
// #define FORGROW( grow, var, gop) for( gop=(grow).current(),(grow).reset(); ((grow).end()?((grow)[gop-1],0):((var=(grow)()),1)); )
#define FORGROW( grow, var, gop) for( gop=0; gop<(grow).size() && (var=(grow)[gop], 1); gop++ )
#endif
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#ifndef TEMPLATE_HASHTABLE
#define TEMPLATE_HASHTABLE
template<class T> class HTEle {
public:
HTEle(const char* str) { ind = strcpy(new char[strlen(str)+1], str); };
~HTEle() { delete [] ind; };
char* ind;
T val;
HTEle<T>* next;
};
template<class T> class HashTable {
public:
HashTable() {
num = 0;
_size = 0;
_blockresize = 0;
vec = 0;
currele = 0;
/* def = 0; */
resize(32);
};
HashTable(T d) {
num = 0;
_size = 0;
_blockresize = 0;
vec = 0;
currele = 0;
def = d;
resize(32);
};
~HashTable() {
HTEle<T> *ele, *ele2;
int i;
for (i=0; i<_size; i++)
for (ele=vec[i]; ele; ele=ele2) {
ele2 = ele->next;
delete ele;
}
delete [] vec;
};
T& operator()(const char* str) {
HTEle<T>* ele;
int h = hash(str);
for (ele=vec[h]; ele && strcmp(ele->ind, str); ele=ele->next);
if (!ele)
ele = add(h, str);
return ele->val;
};
void reset() {
currele = 0;
currhind = -1;
_blockresize = 1;
};
int end() {
if (currele && currele->next)
currele = currele->next;
else
for (currele=0; currhind<_size-1 && !(currele=vec[++currhind]); );
if (currele)
return 0;
else {
_blockresize = 0;
return 1;
}
};
T& currval() { return currele->val; }
char* currind() { return currele->ind; }
int size() { return num; }
int operator!() { return (num == 0); }
operator int() { return (num > 0); }
void setdefault(T d) { def = d; };
private:
int hash(const char* str) {
register int h = 0;
const unsigned char *p;
for (p=(const unsigned char*)str; *p; p++) {
h ^= *p;
h <<= 1;
h = (h >> _bits) ^ (h & (_size-1));
}
return h;
}
HTEle<T>* add(int h, const char* str) {
HTEle<T>* ele = new HTEle<T>(str);
ele->val = def;
ele->next = vec[h];
vec[h] = ele;
num++;
if (!_blockresize && num > _size*4)
resize(_size*8);
return ele;
};
void resize(int sz) {
HTEle<T>** oldvec;
HTEle<T> *ele, *ele2;
int hind;
int i;
int oldsize;
oldsize = _size;
oldvec = vec;
_size = sz;
for (_bits=-1; sz; _bits++, sz>>=1);
vec = new HTEle<T>*[_size];
num = 0;
for (i=0; i<_size; i++)
vec[i] = 0;
if (oldvec) {
for (i=0; i<oldsize; i++)
for (ele=oldvec[i]; ele; ele=ele2) {
ele2 = ele->next;
hind = hash(ele->ind);
ele->next = vec[hind];
vec[hind] = ele;
++num;
}
delete [] oldvec;
}
};
int _size;
int _bits;
int _blockresize;
int num;
T def;
HTEle<T> *currele;
int currhind;
HTEle<T>** vec;
};
#ifndef FORHASH
#define FORHASH( ht, var, str) for( (ht).reset(); !((ht).end())&&((var=(ht).currval()),(str=(ht).currind()),1); )
#endif
#endif
/*
--------------------------------------------------------------------------
Copyright (C) 1996, 2012, 2015 Anders Holst <aho@sics.se>
This code is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This code 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
#ifndef INTFLOAT
#define INTFLOAT
#ifdef IF_FLOAT
#error "Don't use IF_FLOAT, use INTFLOAT_LONG"
#endif
#ifdef INTFLOAT_LONG
#define IF_FLOAT double
#define IF_INT long long
#else
#define IF_FLOAT float
#define IF_INT int
#endif
union intfloat {
IF_INT i;
IF_FLOAT f;
intfloat() {};
intfloat(IF_FLOAT ff) { f = ff; };
intfloat(IF_INT ii) { i = ii; };
operator IF_FLOAT() { return f; };
operator IF_INT() { return i; };
};
#endif
data.o: data.cc readtokens.hh format.hh intfloat.hh growable.hh data.hh
datadispatch.o: datadispatch.cc format.hh intfloat.hh growable.hh data.hh
format.o: format.cc table.hh readtokens.hh format.hh intfloat.hh \
growable.hh formatunknown.hh formatdispatch.hh formattypes.hh
formatbinary.o: formatbinary.cc readtokens.hh format.hh intfloat.hh \
growable.hh formatbinary.hh
formatcont.o: formatcont.cc readtokens.hh format.hh intfloat.hh \
growable.hh formatunknown.hh formatcont.hh
formatdiscr.o: formatdiscr.cc readtokens.hh format.hh intfloat.hh \
growable.hh formatunknown.hh formatdiscr.hh
formatdispatch.o: formatdispatch.cc format.hh intfloat.hh growable.hh \
readtokens.hh formatbinary.hh formatdiscr.hh formatcont.hh \
formatsymbol.hh formatunknown.hh
formatsymbol.o: formatsymbol.cc readtokens.hh table.hh format.hh \
intfloat.hh growable.hh formatunknown.hh formatsymbol.hh
formatunknown.o: formatunknown.cc readtokens.hh table.hh format.hh \
intfloat.hh growable.hh formatunknown.hh
makeformat.o: makeformat.cc format.hh intfloat.hh growable.hh
readtokens.o: readtokens.cc readtokens.hh
selectcolumns.o: selectcolumns.cc readtokens.hh
table.o: table.cc table.hh
This diff is collapsed.
#! /bin/sh
# These warnings are not supported in g++ 4.2
WARNINGS44="-Wlogical-op -Wmissing-declarations"
# "uname -o" doesn't exist on Darwin.
OS=`uname`
if [ "$OS" = "Darwin" ];
then
WARNINGS44=
XCXXFLAGS="-DPLATFORM_MAC"
elif [ `expr substr $OS 1 6` = "CYGWIN" ];
then
WARNINGS44=
XCXXFLAGS="-DPLATFORM_MSW"
elif [ "$OS" = "Linux" ];
then
WARNINGS44="-Wmissing-declarations"
XCXXFLAGS="-DUSE_WCHAR -DPLATFORM_GTK"
elif [ "$OS" = "FreeBSD" ];
then
WARNINGS44=
XCXXFLAGS="-DPLATFORM_GTK"
else
echo "Error: unknown platform $OS - modifying our-g++ may help"
exit 1
fi
CXX=g++
#CXX=clang++
#CXX=/home/arndt/clang/llvm-3.3.src/Release+Asserts/bin/clang++
CXXFLAGS="-Wall -Wno-write-strings -Wextra -Wno-unused-parameter -Wmissing-noreturn -Wshadow -Wswitch-default $WARNINGS44 -g $XCXXFLAGS"
# Sometimes interesting: -O -fdiagnostics-show-option
# -O causes more semantic analysis to be done, so we may get more warnings
# -Wredundant-decls -Waggregate-return -Wunreachable-code react to wx.h
# -Wfloat-equal and -Wconversion triggers warnings in wx
# -Winline together with -O give a lot of warnings from wxWidgets
#echo $CXX $CXXFLAGS $@
if [ "$OS" = "Darwin" ];
then
# Mac OS: wxWidgets or others may not be compiled for 64 bits architecture
$CXX -m32 $CXXFLAGS $@
else
$CXX $CXXFLAGS $@
fi
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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