/* Test of filtering of data through a subprocess.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009-2011 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2009.
This program is free software: you can redistribute it and/or modify
#include "pipe-filter.h"
-#include <stdio.h>
-#include <stdlib.h>
-
#include "binary-io.h"
#include "c-ctype.h"
#include "read-file.h"
#include "progname.h"
-
-#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- fflush (stderr); \
- abort (); \
- } \
- } \
- while (0)
+#include "macros.h"
-/* Pipe a text file through 'tr a-z A-Z', which converts ASCII characters from
- lower case to upper case. */
+/* Pipe a text file through 'tr "[a-z]" "[A-Z]"', which converts ASCII
+ characters from lower case to upper case. */
struct locals
{
{
/* Handle conversion NL -> CRLF possibly done by the child process. */
if (!(O_BINARY && *q == '\r'))
- {
- char orig = *p;
- char expected = c_toupper (orig);
- ASSERT (*q == expected);
- p++;
- }
+ {
+ char orig = *p;
+ char expected = c_toupper (orig);
+ ASSERT (*q == expected);
+ p++;
+ }
}
l->nread = p - l->input;
}
int
main (int argc, char *argv[])
{
+ const char *tr_program;
const char *input_filename;
size_t input_size;
char *input;
set_program_name (argv[0]);
- ASSERT (argc == 2);
+ ASSERT (argc == 3);
+
+ tr_program = argv[1];
/* Read some text from a file. */
- input_filename = argv[1];
+ input_filename = argv[2];
input = read_binary_file (input_filename, &input_size);
ASSERT (input != NULL);
l.nwritten = 0;
l.nread = 0;
- argv[0] = "tr";
- argv[1] = "a-z";
- argv[2] = "A-Z";
+ argv[0] = tr_program;
+ argv[1] = "[a-z]";
+ argv[2] = "[A-Z]";
argv[3] = NULL;
- result = pipe_filter_ii_execute ("tr", "tr", argv, false, true,
- prepare_write, done_write,
- prepare_read, done_read,
- &l);
+ result = pipe_filter_ii_execute ("tr", tr_program, argv, false, true,
+ prepare_write, done_write,
+ prepare_read, done_read,
+ &l);
ASSERT (result == 0);
ASSERT (l.nwritten == input_size);
ASSERT (l.nread == input_size);