Compare commits

..

23 Commits

Author SHA1 Message Date
25e114dbea Fix Github Workflow Badge:
* https://github.com/badges/shields/issues/8733
* https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge
2024-06-12 11:50:35 +02:00
740116c7ba bump version 2.0.20 2024-06-12 11:23:12 +02:00
5899bd646b bump version 2.0.19 2024-06-12 10:39:22 +02:00
1d33a81ad2 bump version 2.0.18 2024-06-12 10:37:54 +02:00
b58efae107 bump version 2.0.17 2024-06-12 10:33:51 +02:00
cc0dd9978f update and fix badges 2024-06-12 10:22:53 +02:00
4834f63a67 update and fix badges 2024-06-12 10:16:56 +02:00
1be78a2c5e Revert "update and fix badges"
This reverts commit f5581557bc.
2024-06-12 10:15:23 +02:00
f5581557bc update and fix badges 2024-06-12 10:14:51 +02:00
8cde88848b update and fix badges 2024-06-12 10:08:33 +02:00
0799513ea2 by default use codepage1252 for metadata including non-ascii characters while missing codepage info 2024-06-12 09:45:30 +02:00
effeee105c win32: replace timegm by _mkgmtime, bump version 2.0.15 2023-08-08 23:46:10 +02:00
ed5b366341 imc_channel.hpp: usage of iconv for unix only, bump version 2.0.15 2023-08-08 23:29:48 +02:00
9a520ddd9c bump version 2.0.14 2023-08-08 00:54:07 +02:00
2c43087d15 bump version 2.0.13 2023-08-08 00:52:27 +02:00
60ac1365a5 * imc_channel.hpp: usage of iconv for unix only
* IMCtermite.pyx: add codepage conversion for windows
* bump VERSION
2023-08-08 00:50:52 +02:00
57027e234e fix workflow pypi-deploy.yml for installing libiconv 2023-08-07 23:03:51 +02:00
887d5db635 add docu and fix github workflow pypi-deploy.yml for installing libiconv 2023-08-07 22:50:00 +02:00
ecbae3f79b install libiconv in github workflow for matrix.os windows-2019 2023-08-05 23:01:00 +02:00
b54979aa74 restructure includes and headers 2023-07-11 13:41:34 +02:00
724f3d0bb9 * bump version 2.0.9
* convert to UTF-8 for any non-empty codepage: fix buffer string
  conversion
2023-07-06 00:12:14 +02:00
06c5710412 convert to UTF-8 for any non-empty codepage (issue #23) 2023-07-05 23:47:44 +02:00
b45fae576f strictly stick to UTC/GMT for timestamp calculations (issue #23) 2023-06-27 00:57:11 +02:00
8 changed files with 157 additions and 16 deletions

View File

@@ -1,9 +1,9 @@
name: Build Python Wheels name: CI Build Wheel
on: on:
push: push:
#branches: [master] # branches: [master]
tags: ["v[0-9]+.[0-9]+.[0-9]+"] tags: ["v[0-9]+.[0-9]+.[0-9]+"]
jobs: jobs:

View File

@@ -1,10 +1,8 @@
[![Total alerts](https://img.shields.io/lgtm/alerts/g/RecordEvolution/IMCtermite.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/RecordEvolution/IMCtermite/alerts/)
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/RecordEvolution/IMCtermite.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/RecordEvolution/IMCtermite/context:cpp)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/RecordEvolution/IMCtermite.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/RecordEvolution/IMCtermite/context:python)
[![LICENSE](https://img.shields.io/github/license/RecordEvolution/IMCtermite)](https://img.shields.io/github/license/RecordEvolution/IMCtermite) [![LICENSE](https://img.shields.io/github/license/RecordEvolution/IMCtermite)](https://img.shields.io/github/license/RecordEvolution/IMCtermite)
[![STARS](https://img.shields.io/github/stars/RecordEvolution/IMCtermite)](https://img.shields.io/github/stars/RecordEvolution/IMCtermite) [![STARS](https://img.shields.io/github/stars/RecordEvolution/IMCtermite)](https://img.shields.io/github/stars/RecordEvolution/IMCtermite)
![Build Python Wheels](https://github.com/RecordEvolution/IMCtermite/actions/workflows/pypi-deploy.yml/badge.svg) ![CI Build Wheel](https://github.com/RecordEvolution/IMCtermite/actions/workflows/pypi-deploy.yml/badge.svg?branch=&event=push)
[![PYPI](https://img.shields.io/pypi/v/IMCtermite.svg)](https://pypi.org/project/IMCtermite/)
# IMCtermite # IMCtermite
@@ -233,3 +231,6 @@ can be found in the `python/examples` folder.
- https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun - https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- https://github.com/pypa/cibuildwheel/blob/main/examples/github-deploy.yml - https://github.com/pypa/cibuildwheel/blob/main/examples/github-deploy.yml
- https://cibuildwheel.readthedocs.io/en/stable/deliver-to-pypi/ - https://cibuildwheel.readthedocs.io/en/stable/deliver-to-pypi/
- https://www.gnu.org/software/libiconv/
- https://vcpkg.io/en/packages.html
- https://vcpkg.io/en/getting-started

View File

@@ -9,6 +9,12 @@
#include <math.h> #include <math.h>
#include <chrono> #include <chrono>
#include <ctime> #include <ctime>
#include <time.h>
#if defined(__linux__) || defined(__APPLE__)
#include <iconv.h>
#elif defined(__WIN32__) || defined(_WIN32)
#define timegm _mkgmtime
#endif
//---------------------------------------------------------------------------// //---------------------------------------------------------------------------//
@@ -142,6 +148,87 @@ namespace imc
return sumstr; return sumstr;
} }
#if defined(__linux__) || defined(__APPLE__)
// convert encoding of any descriptions, channel-names, units etc.
class iconverter
{
std::string in_enc_, out_enc_;
iconv_t cd_;
size_t out_buffer_size_;
public:
iconverter(std::string in_enc, std::string out_enc, size_t out_buffer_size = 1024) :
in_enc_(in_enc), out_enc_(out_enc), out_buffer_size_(out_buffer_size)
{
// allocate descriptor for character set conversion
// (https://man7.org/linux/man-pages/man3/iconv_open.3.html)
cd_ = iconv_open(out_enc.c_str(), in_enc.c_str());
if ( (iconv_t)-1 == cd_ )
{
if ( errno == EINVAL )
{
std::string errmsg = std::string("The encoding conversion from ") + in_enc
+ std::string(" to ") + out_enc + std::string(" is not supported by the implementation.");
throw std::runtime_error(errmsg);
}
}
}
void convert(std::string &astring)
{
if ( astring.empty() ) return;
std::vector<char> in_buffer(astring.begin(),astring.end());
char *inbuf = &in_buffer[0];
size_t inbytes = in_buffer.size();
std::vector<char> out_buffer(out_buffer_size_);
char *outbuf = &out_buffer[0];
size_t outbytes = out_buffer.size();
// perform character set conversion
// ( - https://man7.org/linux/man-pages/man3/iconv.3.html
// - https://www.ibm.com/docs/en/zos/2.2.0?topic=functions-iconv-code-conversion )
while ( inbytes > 0 )
{
size_t res = iconv(cd_,&inbuf,&inbytes,&outbuf,&outbytes);
if ( (size_t)-1 == res )
{
std::string errmsg;
if ( errno == EILSEQ )
{
errmsg = std::string("An invalid multibyte sequence is encountered in the input.");
throw std::runtime_error(errmsg);
}
else if ( errno == EINVAL )
{
errmsg = std::string("An incomplete multibyte sequence is encountered in the input")
+ std::string(" and the input byte sequence terminates after it.");
}
else if ( errno == E2BIG )
{
errmsg = std::string("The output buffer has no more room for the next converted character.");
}
throw std::runtime_error(errmsg);
}
}
std::string outstring(out_buffer.begin(),out_buffer.end()-outbytes);
astring = outstring;
}
};
#elif defined(__WIN32__) || defined(_WIN32)
class iconverter
{
public:
iconverter(std::string in_enc, std::string out_enc, size_t out_buffer_size = 1024) {}
void convert(std::string &astring) {}
};
#endif
// channel // channel
struct channel struct channel
{ {
@@ -301,9 +388,12 @@ namespace imc
double secs_int; double secs_int;
trigger_time_frac_secs_ = modf((double)secs,&secs_int); trigger_time_frac_secs_ = modf((double)secs,&secs_int);
tms.tm_sec = (int)secs_int; tms.tm_sec = (int)secs_int;
//tms.tm_isdst = -1;
// generate std::chrono::system_clock::time_point type // generate std::chrono::system_clock::time_point type
std::time_t ts = std::mktime(&tms); // ( - https://www.gnu.org/software/libc/manual/html_node/Broken_002ddown-Time.html
// - https://man7.org/linux/man-pages/man3/tzset.3.html )
std::time_t ts = timegm(&tms); //std::mktime(&tms);
trigger_time_ = std::chrono::system_clock::from_time_t(ts); trigger_time_ = std::chrono::system_clock::from_time_t(ts);
} }
@@ -313,6 +403,9 @@ namespace imc
// calculate absolute trigger-time // calculate absolute trigger-time
absolute_trigger_time_ = trigger_time_ + std::chrono::seconds(addtime_); absolute_trigger_time_ = trigger_time_ + std::chrono::seconds(addtime_);
// + std::chrono::nanoseconds((long int)(trigger_time_frac_secs_*1.e9)); // + std::chrono::nanoseconds((long int)(trigger_time_frac_secs_*1.e9));
// convert any non-UTF-8 codepage to UTF-8
convert_encoding();
} }
// convert buffer to actual datatype // convert buffer to actual datatype
@@ -400,6 +493,40 @@ namespace imc
} }
} }
// convert any description, units etc. to UTF-8 (by default)
void convert_encoding()
{
// actual input codepage
std::string cpn;
if ( !codepage_.empty() )
{
// construct iconv-compatible name for respective codepage
cpn = std::string("CP") + codepage_;
}
else {
// assume codepage 1252 by default
cpn = std::string("CP1252");
}
// set up converter
std::string utf = std::string("UTF-8");
iconverter conv(cpn,utf);
conv.convert(name_);
conv.convert(comment_);
conv.convert(origin_);
conv.convert(origin_comment_);
conv.convert(text_);
conv.convert(language_code_);
conv.convert(yname_);
conv.convert(yunit_);
conv.convert(xname_);
conv.convert(xunit_);
conv.convert(group_name_);
conv.convert(group_comment_);
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@@ -413,8 +540,8 @@ namespace imc
<<std::setw(width)<<std::left<<"comment:"<<comment_<<"\n" <<std::setw(width)<<std::left<<"comment:"<<comment_<<"\n"
<<std::setw(width)<<std::left<<"origin:"<<origin_<<"\n" <<std::setw(width)<<std::left<<"origin:"<<origin_<<"\n"
<<std::setw(width)<<std::left<<"description:"<<text_<<"\n" <<std::setw(width)<<std::left<<"description:"<<text_<<"\n"
<<std::setw(width)<<std::left<<"trigger-time-nt:"<<std::put_time(std::localtime(&tt),"%FT%T")<<"\n" <<std::setw(width)<<std::left<<"trigger-time-nt:"<<std::put_time(std::gmtime(&tt),"%FT%T")<<"\n"
<<std::setw(width)<<std::left<<"trigger-time:"<<std::put_time(std::localtime(&att),"%FT%T")<<"\n" <<std::setw(width)<<std::left<<"trigger-time:"<<std::put_time(std::gmtime(&att),"%FT%T")<<"\n"
<<std::setw(width)<<std::left<<"language-code:"<<language_code_<<"\n" <<std::setw(width)<<std::left<<"language-code:"<<language_code_<<"\n"
<<std::setw(width)<<std::left<<"codepage:"<<codepage_<<"\n" <<std::setw(width)<<std::left<<"codepage:"<<codepage_<<"\n"
<<std::setw(width)<<std::left<<"yname:"<<yname_<<"\n" <<std::setw(width)<<std::left<<"yname:"<<yname_<<"\n"
@@ -451,8 +578,8 @@ namespace imc
<<"\",\"comment\":\""<<comment_ <<"\",\"comment\":\""<<comment_
<<"\",\"origin\":\""<<origin_ <<"\",\"origin\":\""<<origin_
<<"\",\"description\":\""<<text_ <<"\",\"description\":\""<<text_
<<"\",\"trigger-time-nt\":\""<<std::put_time(std::localtime(&tt),"%FT%T") <<"\",\"trigger-time-nt\":\""<<std::put_time(std::gmtime(&tt),"%FT%T")
<<"\",\"trigger-time\":\""<<std::put_time(std::localtime(&att),"%FT%T") <<"\",\"trigger-time\":\""<<std::put_time(std::gmtime(&att),"%FT%T")
<<"\",\"language-code\":\""<<language_code_ <<"\",\"language-code\":\""<<language_code_
<<"\",\"codepage\":\""<<codepage_ <<"\",\"codepage\":\""<<codepage_
<<"\",\"yname\":\""<<prepjsonstr(yname_) <<"\",\"yname\":\""<<prepjsonstr(yname_)

View File

@@ -10,8 +10,11 @@ SRC = src/
LIB = lib/ LIB = lib/
PYT = python/ PYT = python/
# list headers # list headers and include directories
HPP = $(wildcard $(LIB)/*.hpp) HPP = $(wildcard $(LIB)/*.hpp)
IPP = $(shell find $(LIB) -type f -name '*.hpp')
KIB = $(shell find $(LIB) -type d)
MIB = $(foreach dir,$(KIB),-I $(dir))
# choose compiler and its options # choose compiler and its options
CC = g++ -std=c++17 CC = g++ -std=c++17
@@ -36,12 +39,12 @@ $(EXE): check-tags $(GVSN) main.o
$(CC) $(OPT) main.o -o $@ $(CC) $(OPT) main.o -o $@
# build main.cpp and include git version/commit tag # build main.cpp and include git version/commit tag
main.o: src/main.cpp $(HPP) main.o: src/main.cpp $(IPP)
@cp $< $<.cpp @cp $< $<.cpp
@sed -i 's/TAGSTRING/$(GTAG)/g' $<.cpp @sed -i 's/TAGSTRING/$(GTAG)/g' $<.cpp
@sed -i 's/HASHSTRING/$(GHSH)/g' $<.cpp @sed -i 's/HASHSTRING/$(GHSH)/g' $<.cpp
@sed -i 's/TIMESTAMPSTRING/$(TMS)/g' $<.cpp @sed -i 's/TIMESTAMPSTRING/$(TMS)/g' $<.cpp
$(CC) -c $(OPT) -I $(LIB) $<.cpp -o $@ $(CC) -c $(OPT) $(MIB) $<.cpp -o $@
@rm $<.cpp @rm $<.cpp
install: $(EXE) install: $(EXE)

View File

@@ -5,6 +5,16 @@ from IMCtermite cimport cppimctermite
import json as jn import json as jn
import decimal import decimal
import platform
# auxiliary function for codepage conversion
def get_codepage(chn) :
if platform == 'Windows' :
chndec = jn.loads(chn.decode(errors="ignore"))
chncdp = chndec["codepage"]
return 'utf-8' if chncdp is None else chncdp
else :
return 'utf-8'
cdef class imctermite: cdef class imctermite:
@@ -22,7 +32,7 @@ cdef class imctermite:
# get JSON list of channels # get JSON list of channels
def get_channels(self, bool include_data): def get_channels(self, bool include_data):
chnlst = self.cppimc.get_channels(True,include_data) chnlst = self.cppimc.get_channels(True,include_data)
chnlstjn = [jn.loads(chn.decode(errors="ignore")) for chn in chnlst] chnlstjn = [jn.loads(chn.decode(get_codepage(chn),errors="ignore")) for chn in chnlst]
return chnlstjn return chnlstjn
# print single channel/all channels # print single channel/all channels

View File

@@ -1 +1 @@
2.0.8 2.0.20