Skip to content

Commit

Permalink
Preparing for release 0.3 (mainly configure fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
agordon committed Nov 3, 2013
1 parent abe3d35 commit 98a9cdf
Show file tree
Hide file tree
Showing 14 changed files with 698 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ EXTRA_DIST = reconf configure
SUBDIRS = m4 src doc tests

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = gtextutils-0.2.pc
pkgconfig_DATA = gtextutils-0.3.pc
16 changes: 14 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

AC_INIT([Gordon-Text_utils-Library],
[0.2],
[0.3],
[A. Gordon [email protected]],
[libgtextutils])
AC_CONFIG_AUX_DIR(config)
Expand Down Expand Up @@ -60,14 +60,26 @@ else
fi


dnl --enable-tuple-parser-check
AC_ARG_ENABLE(tuple-parser-check,
[ --enable-tuple-parser-check Enable Tuple Parser Check (default disabled, requires g++ > 4.3.2)],
[case "${enableval}" in
yes) tuple_parser_check=true ;;
no) tuple_parser_check=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-tuple-parser-check) ;;
esac],[tuple_parser_check=false])
AM_CONDITIONAL([TUPLE_PARSER_CHECK], [test x$tuple_parser_check = xtrue])



AC_CONFIG_FILES([
Makefile
README
doc/Makefile
m4/Makefile
src/Makefile
src/gtextutils/Makefile
gtextutils-0.2.pc
gtextutils-0.3.pc
tests/Makefile
])

Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/gtextutils/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


lib_LIBRARIES = libgtextutils-0.2.a
lib_LIBRARIES = libgtextutils-0.3.a

libgtextutils_0_2_a_SOURCES = stream_wrapper.cpp stream_wrapper.h \
libgtextutils_0_3_a_SOURCES = stream_wrapper.cpp stream_wrapper.h \
text_line_reader.cpp text_line_reader.h \
container_join.h \
natsort.h \
Expand All @@ -21,9 +21,9 @@ libgtextutils_0_2_a_SOURCES = stream_wrapper.cpp stream_wrapper.h \
inbuf1.hpp \
pipe_fitter.c pipe_fitter.h

libgtextutils_0_2_a_includedir = $(includedir)/gtextutils-0.2/gtextutils
libgtextutils_0_3_a_includedir = $(includedir)/gtextutils-$(VERSION)/gtextutils

libgtextutils_0_2_a_include_HEADERS = container_join.h \
libgtextutils_0_3_a_include_HEADERS = container_join.h \
text_line_reader.h \
stream_wrapper.h \
natsort.h \
Expand Down
145 changes: 145 additions & 0 deletions src/gtextutils/inbuf1.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
Gordon's Text-Utilities Library
Copyright (C) 2009 Assaf Gordon ([email protected])
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/

#ifndef __JOSUTTIS_FD_INBUF_H__
#define __JOSUTTIS_FD_INBUF_H__

/* The following code example is taken from the book
* "The C++ Standard Library - A Tutorial and Reference"
* by Nicolai M. Josuttis, Addison-Wesley, 1999
*
* (C) Copyright Nicolai M. Josuttis 1999.
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*
* Added by A. Gordon:
* The file is available as "io/inbuf1.hpp" in the examples tarball at
* http://www.josuttis.com/libbook/
*
* And in the book at Chapter 13, Page 678.
*
* Modifications:
* 1. Larger buffer, with vector<char>
* 2. Accepts input file descriptor in c'tor
*/

#include <cstdio>
#include <cstring>
#include <streambuf>
#include <vector>

// for read():
#ifdef _MSC_VER
# include <io.h>
#else
# include <unistd.h>
#endif

class josuttis_fd_inbuf : public std::streambuf {
protected:
/* data buffer:
* - at most, four characters in putback area plus
* - at most, six characters in ordinary read buffer
*/
static const int putBackSize = 4 ;
static const int bufferSize = putBackSize + 32768; // size of the data buffer
std::vector<char> buffer_vector ;
char* buffer;
int input_fd;

public:
/* constructor
* - initialize empty data buffer
* - no putback area
* => force underflow()
*/
josuttis_fd_inbuf( int _input_fd ) :
buffer_vector(bufferSize),
buffer(&buffer_vector[0]),
input_fd(_input_fd)
{
setg (buffer+putBackSize, // beginning of putback area
buffer+putBackSize, // read position
buffer+putBackSize); // end position
}
protected:
// insert new characters into the buffer
virtual int_type underflow () {

// is read position before end of buffer?
if (gptr() < egptr()) {
return traits_type::to_int_type(*gptr());
}

/* process size of putback area
* - use number of characters read
* - but at most four
*/
int numPutback;
numPutback = gptr() - eback();
if (numPutback > putBackSize) {
numPutback = putBackSize;
}

/* copy up to four characters previously read into
* the putback buffer (area of first four characters)
*/
std::memmove (buffer+(putBackSize-numPutback), gptr()-numPutback,
numPutback);

// read new characters
int num;
num = read (input_fd, buffer+putBackSize, bufferSize-putBackSize);
if (num <= 0) {
// ERROR or EOF
return EOF;
}

// reset buffer pointers
setg (buffer+(putBackSize-numPutback), // beginning of putback area
buffer+putBackSize, // read position
buffer+putBackSize+num); // end of buffer

// return next character
return traits_type::to_int_type(*gptr());
}
};

/*
* An output stream that uses the above inbuf
*
* Based on code example from page 673 (class fdostream)
*/

class josuttis_fdistream : public std::istream
{
private:
josuttis_fd_inbuf buf ;
public:
josuttis_fdistream ( int fd ) :
std::istream(0),
buf(fd)
{
rdbuf(&buf) ;
}
};


#endif
122 changes: 122 additions & 0 deletions src/gtextutils/pipe_fitter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
Gordon's Text-Utilities Library
Copyright (C) 2009 Assaf Gordon ([email protected])
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include <unistd.h>
#include <err.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <stdio.h>

#include "pipe_fitter.h"

int pipe_close ( int fd, pid_t pid )
{
int i, status ;
pid_t p;
int exit_code;

i = close(fd);
if ( fd == -1 )
err(1,"close(in pipe_close) failed");

p = waitpid(pid, &status, 0);
if (p==-1)
err(1,"waitpid(in pipe_close) failed");

if (!WIFEXITED(status))
errx(1,"child process terminated abnormally (in pipe_close), status=%08x", status);

exit_code = WEXITSTATUS(status);
if (exit_code != 0)
errx(1,"child process terminated with error code %d (in pipe_close)", exit_code);

return 0;
}

static int pipe_open (
const char* executable,
const char* filename,
int pipe_input,
pid_t* /*OUTPUT*/ child_pid )
{
int file_fd=-1;
pid_t pid;
int parent_pipe[2];

//Create the pipe descriptoers
if (pipe(parent_pipe)!=0)
err(1,"pipe (for '%s') failed", executable);

if (filename != NULL) {
file_fd = open(filename,
pipe_input?(O_RDONLY):(O_CREAT|O_WRONLY),
0666 ) ;

//create the file descriptor (input or output, based on function argument)
if ( file_fd == -1 )
err(1,"failed to %s file '%s'",
pipe_input?"open":"create",
filename ) ;
}

pid = fork();

if (pid == -1)
err(1,"Fork failed for '%s'", executable);


if (pid>0) {
/* The parent process */
*child_pid = pid;
close(file_fd); //the parent process doesn't need the file handle.
close(parent_pipe[ pipe_input?1:0 ]);
return (parent_pipe[ pipe_input?0:1 ]);
}

/* The child process */

if (pipe_input) {
dup2(parent_pipe[1], STDOUT_FILENO);
close(parent_pipe[0]);

if (file_fd != -1)
dup2(file_fd, STDIN_FILENO);
} else {
dup2(parent_pipe[0], STDIN_FILENO);
close(parent_pipe[1]);

if (file_fd!=-1)
dup2(file_fd, STDOUT_FILENO);
}

execlp(executable,executable,NULL);

//Should never get here...
err(1,"execlp(%s) failed",executable);
}

int pipe_output_command ( const char* command, const char* output_filename, pid_t* /*OUTPUT*/ child_pid )
{
return pipe_open ( command, output_filename, 0, child_pid ) ;
}

int pipe_input_command ( const char* command, const char* input_filename, pid_t* /*OUTPUT*/ child_pid )
{
return pipe_open ( command, input_filename, 1, child_pid ) ;
}
37 changes: 37 additions & 0 deletions src/gtextutils/pipe_fitter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Gordon's Text-Utilities Library
Copyright (C) 2009 Assaf Gordon ([email protected])
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/

#ifndef __PIPE_FITTER_H__
#define __PIPE_FITTER_H__


#ifdef __cplusplus
extern "C"
{
#endif

int pipe_output_command ( const char* command, const char* output_filename, pid_t* /*OUTPUT*/ child_pid );
int pipe_input_command ( const char* command, const char* input_filename, pid_t* /*OUTPUT*/ child_pid );

int pipe_close ( int fd, pid_t pid ) ;

#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit 98a9cdf

Please sign in to comment.