diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..af437a6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src diff --git a/autogen b/autogen new file mode 100755 index 0000000..104cc53 --- /dev/null +++ b/autogen @@ -0,0 +1,9 @@ +echo "aclocal..." +aclocal +echo "autoheader..." +autoheader +echo "autoconf..." +autoconf +echo "automake..." +automake -a +echo "ok." diff --git a/configure.in b/configure.in new file mode 100644 index 0000000..773a20d --- /dev/null +++ b/configure.in @@ -0,0 +1,172 @@ +dnl Copyright (C) 2004-2005 Glenn ROLLAND. +dnl +dnl This program is free software; you can redistribute it and/or modify +dnl it under the terms of the GNU General Public License as published by +dnl the Free Software Foundation; either version 2 of the License, or +dnl (at your option) any later version. +dnl +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +dnl GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License +dnl along with this program; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +dnl + +## Autoconf requirements +AC_INIT([eyd], [0.1], [glenux@fr.st]) +AC_PREREQ(2.50) + +AC_CANONICAL_HOST +AC_CANONICAL_TARGET + + +AM_INIT_AUTOMAKE([eyd],[0.1]) + +#AC_CANONICAL_SYSTEM + + + +AM_CONFIG_HEADER(src/config.h) +AC_CONFIG_SRCDIR([src/lib/eyd.hh]) +AC_PROG_INSTALL + +## information on the package +## ## checks for programs +## checks for libraries +## checks for header files +## checks for types +## checks for structures +## checks for compiler characteristics +## checks for library functions +## checks for system services + +AM_CONFIG_HEADER(config.h) +## required for c sources + +AC_ISC_POSIX +AC_PROG_CC +## required for c++ sources +AC_PROG_CXX +AC_PROG_CPP +# AC_PROG_RANLIB obsoleted bu LIBTOOL + +AC_LANG_SAVE +AC_LANG_CPLUSPLUS + +# AC_PROG_YACC +# AC_PROG_LEX +# AM_PROG_LEX + +dnl Checks for library functions. +AC_HEADER_STDC([]) + +#TODO: uncomment +AC_CHECK_HEADERS([vector set map iostream sstream string algorithm list memory iterator exception utility],, + AC_MSG_ERROR([You need to have the libstdc++ headers installed])) + + + +dnl *************************************************************************** +dnl Gettext stuff. +dnl *************************************************************************** + +#GETTEXT_PACKAGE=yalag-0.1 +#AC_SUBST(GETTEXT_PACKAGE) +#AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.]) + +#ALL_LINGUAS="fr" +#AM_GLIB_GNU_GETTEXT + + +dnl Check for programs + +dnl Check for build configuration. +#AC_PROG_INTLTOOL + +AM_PROG_LIBTOOL + +dnl Checks for header files. + +#AC_MSG_NOTICE([checking presence of SQLite]) +#AC_CHECK_HEADERS([sqlite.h],[], +# [ +# AC_MSG_NOTICE([*** Please install/upgrade SQLite before proceeding]) +# AC_MSG_NOTICE([*** with Unlost Memories installation.]) +# AC_MSG_ERROR([cannot find sqlite.h]) +# ]) + +#sqlite_deps="sqlite3 >= 3.0" +#PKG_CHECK_MODULES(SQLITE3,$sqlite_deps,build_sqlite=yes,build_sqlite=no) +#AC_SUBST(SQLITE3_CFLAGS) +#AC_SUBST(SQLITE3_LIBS) + +glib_deps="glib-2.0 >= 2.0" +PKG_CHECK_MODULES(GLIB2,$glib_deps, build_glib=yes, build_glib=no) +AC_SUBST(GLIB2_CFLAGS) +AC_SUBST(GLIB2_LIBS) + +########## +# Figure out where to get the READLINE header files. +# +AC_MSG_CHECKING([readline header files]) +found=no +if test "$config_TARGET_READLINE_INC" != ""; then + TARGET_READLINE_INC=$config_TARGET_READLINE_INC + found=yes +fi +if test "$found" = "yes"; then + AC_MSG_RESULT($TARGET_READLINE_INC) +else + AC_MSG_RESULT(not specified: still searching...) + AC_CHECK_HEADER(readline.h, [found=yes]) +fi +if test "$found" = "no"; then + for dir in /usr /usr/local /usr/local/readline /usr/contrib /mingw; do + AC_CHECK_FILE($dir/include/readline.h, found=yes) + if test "$found" = "yes"; then + TARGET_READLINE_INC="-I$dir/include" + break + fi + AC_CHECK_FILE($dir/include/readline/readline.h, found=yes) + if test "$found" = "yes"; then + TARGET_READLINE_INC="-I$dir/include/readline" + break + fi + done +fi +if test "$found" = "yes"; then + if test "$TARGET_READLINE_LIBS" = ""; then + TARGET_HAVE_READLINE=0 + else + TARGET_HAVE_READLINE=1 + fi +else + TARGET_HAVE_READLINE=0 +fi +AC_SUBST(TARGET_READLINE_INC) +AC_SUBST(TARGET_HAVE_READLINE) + +#libxml2_deps="libxml-2.0 >= 2.4.1" +#PKG_CHECK_MODULES(LIBXML2,$libxml2_deps, build_libxml2=yes, build_libxml2=no) +#AC_SUBST(LIBXML2_CFLAGS) +#AC_SUBST(LIBXML2_LIBS) + +#if test $build_libxml2 == yes ; then +# AC_DEFINE(HAVE_LIBXML2_H,1,[Vaut 1 lorsque l'on utilise LIBXML2.]) +#else +# AC_DEFINE(HAVE_LIBXML2_H,0,[Vaut 1 lorsque l'on utilise LIBXML2.]) +#fi + +#libxmlpp_deps="libxml++-2.6 >= 2.8" +#PKG_CHECK_MODULES(LIBXMLPP,$libxmlpp_deps, build_libxmlpp=yes, build_libxmlpp=no) +#AC_SUBST(LIBXMLPP_CFLAGS) +#AC_SUBST(LIBXMLPP_LIBS) + + +AC_CONFIG_FILES([Makefile src/Makefile src/lib/Makefile src/tools/Makefile]) +AC_OUTPUT + +dnl configure.in ends here diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..16f2e66 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = lib tools + diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am new file mode 100644 index 0000000..bc519d1 --- /dev/null +++ b/src/lib/Makefile.am @@ -0,0 +1,21 @@ +SUBDIRS = . + +lib_LTLIBRARIES = libeyd.la + +#bin_PROGRAMS = libulm.o + +libeyd_la_SOURCES = eyd_bitreader.cpp \ + eyd_bitwriter.cpp \ + eyd_bitgroup.cpp + +libeyd_la_CFLAGS = -DTRACE -static +libeyd_la_LDFLAGS = -version-info 3:12:1 + +#INCLUDES= SQLITE3_CFLAGS@ \ +# LIBXMLPP_CFLAGS@ \ +# -I./ + +#libxionfs_a_LDFLAGS= @LDFLAGS@ + +#SQLITE3_LIBS@ LIBPCRE_LIBS@ + diff --git a/src/lib/eyd.hh b/src/lib/eyd.hh new file mode 100644 index 0000000..dbe1bc8 --- /dev/null +++ b/src/lib/eyd.hh @@ -0,0 +1,8 @@ +#ifndef _EYD_HH +#define _EYD_HH 1 + +#include "eyd_global.hh" +#include "eyd_iface.hh" +#include "eyd_proto.hh" + +#endif diff --git a/src/lib/eyd_bitgroup.cpp b/src/lib/eyd_bitgroup.cpp new file mode 100644 index 0000000..c137b27 --- /dev/null +++ b/src/lib/eyd_bitgroup.cpp @@ -0,0 +1,137 @@ + +#include "eyd_bitgroup.hh" + +namespace EydLib { + BitGroup::BitGroup(){ + this->init(4); /* default size */ + } + + BitGroup::BitGroup(int size){ + this->init(size); + } + + int BitGroup::size(){ + return this->_group_size; + } + + void BitGroup::copy(const BitGroup &original){ + int i; + int size_of_int = 8 * sizeof(unsigned int); + int nb_int = (original._group_size / size_of_int) + 1; + this->init(original._group_size); + for (i=0; i < nb_int; i++){ + this->_bitgroup[i] = original._bitgroup[i]; + } + } + + bool BitGroup::operator==(const BitGroup &original){ + bool identity = true; + if (this->_group_size == original._group_size){ + int size_of_int = 8 * sizeof(unsigned int); + int nb_int = (original._group_size / size_of_int) + 1; + for (int i=0; i < nb_int; i++){ + if (this->_bitgroup[i] != original._bitgroup[i]){ + // not the same content + identity = false; + break; + } + } + } else { + // not the same length + identity=false; + } + return identity; + } + + BitGroup BitGroup::operator=(BitGroup &original){ + this->copy(original); + return (*this); + } + + BitGroup BitGroup::operator=(const BitGroup &original){ + this->copy(original); + return (*this); + } + + BitGroup::BitGroup(const BitGroup &original){ + this->copy(original); + } + + BitGroup::~BitGroup(){ + delete(this->_bitgroup); + } + + void BitGroup::init(int size){ + int i; + int size_of_int = 8 * sizeof(unsigned int); + int nb_int = (size / size_of_int) + 1; + this->_bitgroup = new unsigned int[nb_int]; + this->_group_size = size; + for (i=0; i < nb_int; i++){ + this->_bitgroup[i] = 0; + } + } + + void BitGroup::setBitAt(int position, bool value){ + if (position > this->_group_size){ + throw eBitGroupOutOfBound(); + } else { + int i; + int size_of_int = 8 * sizeof(int); + int index_of_int = position / size_of_int; + int shift_of_int = position % size_of_int; + unsigned int mask_fill; + unsigned int mask_hole; + mask_fill = 0; + mask_hole = 0; + for (i=0; i< size_of_int; i++){ + mask_fill = (mask_fill << 1) | 1; + if (shift_of_int == i){ + mask_hole = ( mask_hole << 1 ) | 0; + } else { + mask_hole = ( mask_hole << 1 ) | 1; + } + } + if (value){ + this->_bitgroup[index_of_int] = ((this->_bitgroup[index_of_int] ^ mask_fill) & mask_hole ) ^ mask_fill; + } else { + this->_bitgroup[index_of_int] = this->_bitgroup[index_of_int] & mask_hole; + } + //printf("0x%u\n",this->_bitgroup[index_of_int]); + } + } + + bool BitGroup::getBitAt(int position){ + if (position > this->_group_size){ + //FIXME: throw exception + throw eBitGroupOutOfBound(); + } else { + int i; + int size_of_int = 8 * sizeof(unsigned int); + int index_of_int = position / size_of_int; + int shift_of_int = position % size_of_int; + unsigned int reader = this->_bitgroup[index_of_int]; + if (shift_of_int > 0){ reader = reader << shift_of_int; reader = reader >> shift_of_int; } + reader = reader >> (size_of_int - shift_of_int - 1 ); + return reader; + } + } + + void BitGroup::setValue(unsigned long int value){ + + } + + unsigned long int BitGroup::getValue(){ + } + + std::string BitGroup::toString(){ + // faire un nouveau string + std::string s; + int i; + for (i=0; i_group_size; i++){ + s += (this->getBitAt(i)?"1":"0"); + } + return s; + } + +} diff --git a/src/lib/eyd_bitgroup.hh b/src/lib/eyd_bitgroup.hh new file mode 100644 index 0000000..a7599c6 --- /dev/null +++ b/src/lib/eyd_bitgroup.hh @@ -0,0 +1,42 @@ +#ifndef _EYD_BITGROUP_HH +#define _EYD_BITGROUP_HH + +#include "stdio.h" +#include +#include + +namespace EydLib { + class eBitGroupOutOfBound : public std::exception { }; + + class BitGroup { + private: + unsigned int * _bitgroup; + int _group_size; + void copy(const BitGroup &original); + + public: + BitGroup(); + BitGroup(int size); + BitGroup(const BitGroup &original); + ~BitGroup(); + + void BitGroup::init(int size); + void setBitAt(int pos, bool value); + bool getBitAt(int pos); + + void setValue(unsigned long value); + unsigned long getValue(); + + int size(); + + std::string toString(); + BitGroup operator=(BitGroup &original); + BitGroup operator=(const BitGroup &original); + bool operator==(const BitGroup &original); + + // comparer les groupes + }; + +} + +#endif diff --git a/src/lib/eyd_bitreader.cpp b/src/lib/eyd_bitreader.cpp new file mode 100644 index 0000000..7ae2127 --- /dev/null +++ b/src/lib/eyd_bitreader.cpp @@ -0,0 +1,110 @@ +#define DEBUG 0 + +#include "eyd_bitreader.hh" + +namespace EydLib { + /* + * int _group_pos; + int _fd; + */ + + BitReader::BitReader(int size, int buffer_size = 1024){ + // tous les groupes de bits seront de la taille donnée + this->_bitgroup_size = size; + this->_wanted_buffer_size = buffer_size; + this->_real_buffer_size = 0; + this->_read_buffer = new char[this->_wanted_buffer_size]; + this->_file_desc = -1; + this->_current_bit_position = (8 * buffer_size) + 1; // on dépasse volontairement + } + + BitReader::~BitReader(){ + delete(this->_read_buffer); + } + + void BitReader::open(std::string filename){ + this->_file_desc = ::open(filename.c_str(), O_RDONLY); + this->_eof = false; + } + + /* + BitGroup * BitReader::read(int size){ + int i; + BitGroup * result = new BitGroup[size]; + + for (i=0; iread_once(); + } + return result; + } + */ + + bool BitReader::getBitAt(int position){ + // on attrappe la bonne case du tableau + // on shift dans le bon sens + // on retourne la valeur du bit. + int size_of_char = 8 * sizeof(char); + int i; + int index_of_char = position / size_of_char; + int shift_of_char = position % size_of_char; + + char reader; + if (position > this->_real_buffer_size * size_of_char){ + //FIXME: throw exception + } else { + reader = this->_read_buffer[index_of_char]; + if (shift_of_char > 0){ reader = reader << shift_of_char; reader = reader >> shift_of_char; } + reader = reader >> (size_of_char - shift_of_char - 1 ); + printf("->%c<- shift %d = %d\n",this->_read_buffer[index_of_char], shift_of_char, reader); + } + return reader; + } + + BitGroup BitReader::read(){ + int i; + bool bitValue; + int size_of_char = 8 * sizeof(char); + BitGroup result(this->_bitgroup_size); + if (this->_eof) { throw eBitReaderEndOfFile(); } + if (this->_file_desc < 0){ throw eBitReaderBadFileDescriptor(); } + + for (i=0; i < this->_bitgroup_size; i++){ + if (this->_current_bit_position >= (this->_wanted_buffer_size * 8)){ + // on charge un nouveau bout de fichier + this->_real_buffer_size = ::read(this->_file_desc, this->_read_buffer, this->_wanted_buffer_size); + printf("BitReader::read / read() -> buffer()\n"); + printf("READ BUFFER(%d): %s\n",this->_real_buffer_size, this->_read_buffer); + this->_current_bit_position = 0; + } + if (this->_current_bit_position < this->_real_buffer_size * 8){ + //printf("TMP result = %s",result.toString().c_str()); + bitValue = this->getBitAt(this->_current_bit_position); + result.setBitAt(i, bitValue); + } else { + // dans le cas ou on dépasse la fin du fichier avec un mauvais alignement + this->_eof = true; + if (i==0){ // on est sur le premier caractère + throw eBitReaderEndOfFile(); + } else { + BitGroup eof_bg(i); + printf("SMALLER BITGROUP ! (%d)\n",i); + for (int j=0; j_current_bit_position += 1; + } + printf("END result = %s",result.toString().c_str()); + return result; + } + + void BitReader::close(){ + ::close(this->_file_desc); + } + +} diff --git a/src/lib/eyd_bitreader.hh b/src/lib/eyd_bitreader.hh new file mode 100644 index 0000000..745c82a --- /dev/null +++ b/src/lib/eyd_bitreader.hh @@ -0,0 +1,43 @@ +#ifndef _EYD_BITREADER_HH +#define _EYD_BITREADER_HH + +#include +#include +#include +#include +#include + +#include "eyd_bitgroup.hh" + +#include "eyd_global.hh" +#include "eyd_iface.hh" + + +namespace EydLib { + class eBitReaderEndOfFile : public std::exception { }; + class eBitReaderBadFileDescriptor : public std::exception { }; + + class BitReader { + private: + char * _read_buffer; + int _real_buffer_size; + int _wanted_buffer_size; + int _bitgroup_size; + int _current_bit_position; + int _file_desc; + bool _eof; + + bool getBitAt(int position); + + public: + BitReader(int size, int buffer_size); + ~BitReader(); + + void open(std::string filename); + /* BitGroup * BitReader::read(int size); */ + BitGroup BitReader::read(); + void close(); + }; +} + +#endif diff --git a/src/lib/eyd_bitwriter.cpp b/src/lib/eyd_bitwriter.cpp new file mode 100644 index 0000000..1e9600f --- /dev/null +++ b/src/lib/eyd_bitwriter.cpp @@ -0,0 +1,130 @@ + +#include "eyd_bitwriter.hh" + +#define DEBUG 0 +namespace EydLib { + /* + * int _group_pos; + int _fd; + */ + + BitWriter::BitWriter(int size, int buffer_size = 1024){ + // tous les groupes de bits seront de la taille donnée + this->_bitgroup_size = size; + this->_wanted_buffer_size = buffer_size; + this->_write_buffer = new char[this->_wanted_buffer_size]; + this->_file_desc = -1; + this->_ready = false; + } + + BitWriter::~BitWriter(){ + delete(this->_write_buffer); + } + + void BitWriter::open(std::string filename){ + this->_file_desc = ::open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + if (this->_file_desc < 0){ + throw eBitWriterBadFileDescriptor(); + } + + this->_real_buffer_size_in_bits = 0; + this->_current_bit_position = 0; + this->_ready = true; + } + + + void BitWriter::setBitAt(int position, bool value){ + // on attrappe la bonne case du tableau + // on shift dans le bon sens + // on retourne la valeur du bit. + int size_of_char = 8 * sizeof(char); + int i; + int index_of_char = position / size_of_char; + int shift_of_char = position % size_of_char; + + char writer; + printf("BitWriter::setBitAt / pos %d - size %d\n", position, this->_real_buffer_size_in_bits ); + + if (position >= this->_real_buffer_size_in_bits){ + throw eBitWriterOutOfBound(); + } else { + unsigned char mask_fill; + unsigned char mask_hole; + for (i=0; i < size_of_char; i++){ + mask_fill = (mask_fill << 1) | 1; + if (shift_of_char == i){ + mask_hole = (mask_hole << 1) | 0; + } else { + mask_hole = (mask_hole << 1) | 1; + } + } + writer = this->_write_buffer[index_of_char]; + if (value){ + writer = ((writer ^ mask_fill) & mask_hole) ^ mask_fill; + } else { + writer = writer & mask_hole; + } + this->_write_buffer[index_of_char] = writer; + } + } + + void BitWriter::flush(){ + int nb_chars; + int size_of_char = 8 * sizeof(char); + int right_bit_len; + //nb_chars = ((this->_real_buffer_size_in_bits) / size_of_char); + // au pire on fait un write de trop + // donc la derniere "bonne valeur" se situe à + right_bit_len = this->_real_buffer_size_in_bits; + nb_chars = (right_bit_len / size_of_char); + + // sauf qu'il reste de quoi finir un octet + if (nb_chars > this->_wanted_buffer_size) { + nb_chars = this->_wanted_buffer_size; + } + + if ((this->_real_buffer_size_in_bits - 1) > this->_bitgroup_size) { + // on flush seulement si on a écrit + de 1 bitgroup dans le nouveau + // buffer + printf("BitWriter::write / buffer() -> write()\n"); + printf("WRITE_BUFFER(%d chars) = %s\n",nb_chars, this->_write_buffer); + + ::write(this->_file_desc, this->_write_buffer, nb_chars); + } + this->_current_bit_position = 0; + this->_real_buffer_size_in_bits=1; + } + + void BitWriter::write(BitGroup data){ + int i; + bool bitValue; + int size_of_char = 8 * sizeof(char); + + if (this->_file_desc < 0){ + throw eBitWriterBadFileDescriptor(); + } + + for (i=0; i < this->_bitgroup_size; i++){ + if (i < data.size()){ + bitValue = data.getBitAt(i); + this->_real_buffer_size_in_bits += 1; + if (this->_real_buffer_size_in_bits > (this->_wanted_buffer_size * size_of_char)){ + this->flush(); + } + this->setBitAt(this->_current_bit_position, bitValue); + this->_current_bit_position += 1; + } + } + return; + } + + void BitWriter::close(){ + // on vide le dernier buffer jusqu'a la position réelle... + printf("Remaining %d\n",this->_real_buffer_size_in_bits); + this->flush(); + ::close(this->_file_desc); + } + +} +#undef DEBUG diff --git a/src/lib/eyd_bitwriter.hh b/src/lib/eyd_bitwriter.hh new file mode 100644 index 0000000..1fe920e --- /dev/null +++ b/src/lib/eyd_bitwriter.hh @@ -0,0 +1,43 @@ +#ifndef _EYD_BITWRITER_HH +#define _EYD_BITWRITER_HH + +#include +#include +#include +#include +#include +#include "eyd_bitgroup.hh" + +#include "eyd_global.hh" +#include "eyd_iface.hh" + + +namespace EydLib { + class eBitWriterOutOfBound : public std::exception { }; + class eBitWriterBadFileDescriptor : public std::exception { }; + + class BitWriter { + private: + int _bitgroup_size; + int _real_buffer_size_in_bits; + int _wanted_buffer_size; + char * _write_buffer; + int _file_desc; + int _current_bit_position; + bool _ready; + + void setBitAt(int position, bool value); + + public: + BitWriter(int size, int buffer_size); + ~BitWriter(); + + void init(int size); + void open(std::string filename); + void write(BitGroup data); + void flush(); + void close(); + }; +} + +#endif diff --git a/src/lib/eyd_global.hh b/src/lib/eyd_global.hh new file mode 100644 index 0000000..8a1013e --- /dev/null +++ b/src/lib/eyd_global.hh @@ -0,0 +1,34 @@ +#ifndef _EYD_GLOBAL_HH +#define _EYD_GLOBAL_HH 1 + +#include "../config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define COLOR_GREEN "\x1B[33m" +#define COLOR_NORMAL "\x1B[0m" + +#define COLOR_GREEN "\x1B[33m" +#define COLOR_NORMAL "\x1B[0m" + +#define EYD_DEBUG 0 + +#define pDEBUG(x,...) if (DEBUG | EYD_DEBUG){ \ + printf("%s:%d/ %s",x,__LINE__,COLOR_GREEN); \ + printf(__VA_ARGS__); \ + printf("%s",COLOR_NORMAL); } + +#endif diff --git a/src/lib/eyd_iface.hh b/src/lib/eyd_iface.hh new file mode 100644 index 0000000..3c79ab1 --- /dev/null +++ b/src/lib/eyd_iface.hh @@ -0,0 +1,7 @@ +#ifndef _EYD_IFACE_HH +#define _EYD_IFACE_HH 1 + +/* user def types ... */ + +#endif + diff --git a/src/lib/eyd_proto.hh b/src/lib/eyd_proto.hh new file mode 100644 index 0000000..36a8894 --- /dev/null +++ b/src/lib/eyd_proto.hh @@ -0,0 +1,16 @@ +#ifndef _EYD_PROTO_HH +#define _EYD_PROTO_HH 1 + +/*#include "regexptree.hh" +#include "transition.hh" +#include "state.hh" +#include "stateclass.hh" +#include "automata.hh" +*/ + +#include "eyd_bitgroup.hh" +#include "eyd_bitreader.hh" +#include "eyd_bitwriter.hh" + +#endif + diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am new file mode 100644 index 0000000..3a140e2 --- /dev/null +++ b/src/tools/Makefile.am @@ -0,0 +1,35 @@ +#AM_YFLAGS = -d -v + +SUBDIRS = . + +bin_PROGRAMS = eyd bittest bitcopy + +eyd_SOURCES = eyd_console.cpp eyd_init.cpp +eyd_LDADD = -leyd +eyd_LDFLAGS = @LDFLAGS@ -L../lib -L../lib/.libs + + +#eyd_SOURCES += parser.hh \ +# source_lexer.hh + +eyd_SOURCES += eyd_console.hh + +INCLUDES= -I../lib/ -I./ @GLIB2_CFLAGS@ @TARGET_READLINE_INC@ + +#BUILT_SOURCES = source_parser.h source_lexer.cc + + +# LEXLIB@ +# libyalag.la + +#eyd_INCLUDE = + + +bittest_SOURCES = bittest.cpp +bittest_LDADD = -leyd +bittest_LDFLAGS = @LDFLAGS@ -L../lib -L../lib/.libs + +bitcopy_SOURCES = bitcopy.cpp +bitcopy_LDADD = -leyd +bitcopy_LDFLAGS = @LDFLAGS@ -L../lib -L../lib/.libs + diff --git a/src/tools/bitcopy.cpp b/src/tools/bitcopy.cpp new file mode 100644 index 0000000..4d3a8ab --- /dev/null +++ b/src/tools/bitcopy.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +void usage(){ + printf("usage : bitcopy \n"); +} + +int main(int argc, char ** argv){ + if (argc<2){ usage(); exit(-1); } + int size = atoi(argv[1]); + std::string original = argv[2]; + std::string copy = original + ".copy"; + + EydLib::BitReader bitread(size, 256); + bitread.open(original); + + EydLib::BitWriter bitwrite(size,256); + bitwrite.open(copy); + + printf("File opened\n"); + + bool done=false; + EydLib::BitGroup bg; + while(!done){ + try{ + bg = bitread.read(); + printf("read = %s \n",bg.toString().c_str()); + bitwrite.write(bg); + } catch (EydLib::eBitReaderEndOfFile& e) { + done = true; + } catch (std::exception& e){ + printf("ERROR\n"); + } + } + printf("copy done\n"); + + bitread.close(); + bitwrite.close(); + + printf("file closed\n"); +} diff --git a/src/tools/bittest.cpp b/src/tools/bittest.cpp new file mode 100644 index 0000000..062e2ac --- /dev/null +++ b/src/tools/bittest.cpp @@ -0,0 +1,14 @@ +#include +#include +#include + +int main(int argc, char ** argv){ + printf("hop\n"); + int size = atoi(argv[1]); + int pos = atoi(argv[2]); + EydLib::BitGroup bg(size); + printf("bits = %s\n", bg.toString().c_str()); + bg.setBitAt(pos,1); + //bg.setBit(2,1); + printf("bits = %s\n", bg.toString().c_str()); +} diff --git a/src/tools/eyd_console.cpp b/src/tools/eyd_console.cpp new file mode 100644 index 0000000..6e480ce --- /dev/null +++ b/src/tools/eyd_console.cpp @@ -0,0 +1,102 @@ +#include "eyd.hh" + +using namespace std; + + + +int main(int argc, char **argv){ + /* + std::string *servermsgold, *usermsg, *userparam; + int ret; + char * tmp_c_string; + ftp_cmd_t ftp_cmd; + + ftp_connection_state_t cnx_state; + FtpConfig * client_conf = NULL; + + servermsgold = NULL; + usermsg = NULL; + userparam = NULL; + cnx_state = FTP_STATE_DISCONNECTED; + + client_conf = new FtpConfig(); + ret = miniftp_args(client_conf, argc, argv); + if (ret < 0) { return EXIT_FAILURE; } + + printf("Connecting to %s:%d\n... ", + client_conf->server_conf->host->c_str(), + client_conf->server_conf->port); + fflush(stdout); + + XionFS::XSock *cmdXSock; // *dataXSock; + + cmdXSock = new XionFS::XSock(XionFS::CLIENT,XionFS::TCP); + cmdXSock->port(client_conf->server_conf->port); + cmdXSock->dns(client_conf->server_conf->host->c_str()); + + cmdXSock->launch(); + printf(" fait\n"); + client_conf->cmd_xsocket = cmdXSock; + + // init sequence + MiniFtp::ServerMsg * servermsg; +// ("220 hophop"); + servermsg = ftp_cmd_recv(client_conf); + + if ((servermsg->getStatus()/10) == 22){ + cnx_state = FTP_STATE_CONNECTED; + } else { + cout << "ERROR\n"; + return EXIT_FAILURE; // event system + } + delete(servermsg); + // init + + cout <<"Auth...\n"; + while(cnx_state == FTP_STATE_CONNECTED){ + + tmp_c_string = readline("Login...: "); + usermsg = new std::string(tmp_c_string); + ftp_cmd_send(client_conf, FTP_CMD_USER, (char*)usermsg->c_str()); + free(tmp_c_string); + delete(usermsg); + + servermsg = ftp_cmd_recv(client_conf); + if (servermsg->getStatus() != 331){ + continue; + } + delete(servermsg); + + tmp_c_string = readline("Password: "); + usermsg = new std::string(tmp_c_string); + ftp_cmd_send(client_conf, FTP_CMD_PASS, (char*)usermsg->c_str()); + delete(usermsg); + + servermsg = ftp_cmd_recv(client_conf); + if ((servermsg->getStatus() / 10) == 23){ + cnx_state = FTP_STATE_LOGGED_IN; + } + delete(usermsg); + + } + while(cnx_state == FTP_STATE_LOGGED_IN){ + tmp_c_string = readline("ftp> "); + usermsg = new std::string(tmp_c_string); + //userparam = (char *) malloc(sizeof(char) * CLIENTQUERY_MAX_LENGTH); + ftp_cmd = ftp_cmd_parse(usermsg, &userparam); + //Think to keep FTP filesystem tree somewhere + ftp_cmd_send(client_conf, ftp_cmd, userparam); + if (ftp_cmd == FTP_CMD_QUIT){ + printf("Disconnecting...\n"); + cnx_state = FTP_STATE_DISCONNECTED; + } + free(userparam); + delete(usermsg); + free(tmp_c_string); + } + + // on le garde dans un coin au chaud en attendant + // dataXSock->launch(); + */ + return 0; +} diff --git a/src/tools/eyd_console.hh b/src/tools/eyd_console.hh new file mode 100644 index 0000000..e69de29 diff --git a/src/tools/eyd_init.cpp b/src/tools/eyd_init.cpp new file mode 100644 index 0000000..d538fe6 --- /dev/null +++ b/src/tools/eyd_init.cpp @@ -0,0 +1,34 @@ +#include "eyd.hh" + +/* +int miniftp_args(MiniFtp::FtpConfig * client_conf, int argc, char ** argv){ // GOOD + int i; + + for (i = 1; i + 1 < argc; i = i + 2){ + char * opt = argv[i]; //GOOD + char * val = argv[i+1]; //GOOD + if ( (strcmp(opt, "--port") == 0) || (strcmp(opt,"-p") == 0) ){ + client_conf->setServerPort(atoi(val)); + continue; + } + if ( (strcmp(opt, "--host") == 0) || (strcmp(opt,"-h") == 0) ){ + client_conf->setServerHost(std::string(val)); + continue; + } + + // printf("Option = %s, ",argv[i]); + // printf("value = %s\n",argv[i+1]); + } + + if (!client_conf->hasServerHost() + || !client_conf->hasServerPort()) { + printf("\nUsage: %s \n", argv[0]); + printf("\nWhere options could be:\n"); + printf("-p, --port Port to connect on host\n"); + printf("-h, --host DNS or IP address of the FTP host\n"); + return -1; + } + + return 1; +} +*/