@@ -44,6 +44,7 @@
#include <time.h>
#include "time-core.h"
#include "time-io.h"
#include "prchunk.h"


#if defined __INTEL_COMPILER
@@ -98,15 +99,13 @@ main(int argc, char *argv[])
}
} else {
/* read from stdin */
FILE *fp = stdin;
char *line;
size_t lno = 0;
struct tgrep_atom_s __nstk[16], *needle = __nstk;
size_t nneedle = countof(__nstk);
struct tgrep_atom_soa_s ndlsoa;
void *pctx;

/* no threads reading this stream */
__io_setlocking_bycaller(fp);
__io_setlocking_bycaller(stdout);

/* lest we overflow the stack */
@@ -118,35 +117,40 @@ main(int argc, char *argv[])
/* and now build the needles */
ndlsoa = build_tneedle(needle, nneedle, fmt, nfmt);

for (line = NULL; !__io_eof_p(fp); lno++) {
ssize_t n;
size_t len;
struct dt_t_s t;
const char *sp = NULL;
const char *ep = NULL;
/* using the prchunk reader now */
pctx = init_prchunk(STDIN_FILENO);
while (prchunk_fill(pctx) >= 0) {
for (char *line; prchunk_haslinep(pctx); lno++) {
size_t llen;
struct dt_t_s t;
const char *sp = NULL;
const char *ep = NULL;

n = getline(&line, &len, fp);
if (n < 0) {
break;
}
/* check if line matches */
t = dt_io_find_strpt2(
line, &ndlsoa, (char**)&sp, (char**)&ep);
if (t.s >= 0) {
if (argi->sed_mode_given) {
llen = prchunk_getline(pctx, &line);
/* check if line matches */
t = dt_io_find_strpt2(
line, &ndlsoa,
(char**)&sp, (char**)&ep);

/* finish with newline again */
line[llen] = '\n';

if (t.s >= 0 && argi->sed_mode_given) {
/* what's this t.s >= 0 condition? */
dt_io_write_sed(
t, ofmt, line, n, sp, ep);
} else {
t, ofmt,
line, llen + 1, sp, ep);
} else if (t.s >= 0) {
dt_io_write(t, ofmt);
} else if (argi->sed_mode_given) {
__io_write(line, llen + 1, stdout);
} else if (!argi->quiet_given) {
dt_io_warn_strpt(line);
}
} else if (argi->sed_mode_given) {
__io_write(line, n, stdout);
} else if (!argi->quiet_given) {
dt_io_warn_strpt(line);
}
}
/* get rid of resources */
free(line);
free_prchunk(pctx);
if (needle != __nstk) {
free(needle);
}
@@ -44,6 +44,7 @@
#include <time.h>
#include "time-core.h"
#include "time-io.h"
#include "prchunk.h"

#if !defined UNUSED
# define UNUSED(_x) __attribute__((unused)) _x
@@ -121,35 +122,33 @@ main(int argc, char *argv[])
}
} else {
/* read from stdin */
FILE *fp = stdin;
char *line;
size_t lno = 0;
void *pctx;

/* no threads reading this stream */
__io_setlocking_bycaller(fp);
__io_setlocking_bycaller(stdout);

for (line = NULL; !__io_eof_p(fp); lno++) {
ssize_t n;
size_t len;
struct dt_t_s t2;
/* using the prchunk reader now */
pctx = init_prchunk(STDIN_FILENO);
while (prchunk_fill(pctx) >= 0) {
for (char *line; prchunk_haslinep(pctx); lno++) {
size_t UNUSED(llen);
struct dt_t_s t2;

n = getline(&line, &len, fp);
if (n < 0) {
break;
}
/* terminate the string accordingly */
line[n - 1] = '\0';
/* perform addition now */
if ((t2 = dt_io_strpt(line, fmt, nfmt)).s >= 0) {
struct dt_t_s dur = dt_tdiff(t, t2);
tdiff_prnt(dur, ofmt);
} else if (!argi->quiet_given) {
dt_io_warn_strpt(line);
llen = prchunk_getline(pctx, &line);

/* perform addition now */
if ((t2 = dt_io_strpt(
line, fmt, nfmt)).s >= 0) {
struct dt_t_s dur = dt_tdiff(t, t2);
tdiff_prnt(dur, ofmt);
} else if (!argi->quiet_given) {
dt_io_warn_strpt(line);
}
}
}
/* get rid of resources */
free(line);
free_prchunk(pctx);
goto out;
}

@@ -44,6 +44,7 @@
#include <time.h>
#include "time-core.h"
#include "time-io.h"
#include "prchunk.h"

typedef uint32_t oper_t;

@@ -228,15 +229,13 @@ main(int argc, char *argv[])
o = o ?: OP_EQ;
{
/* read from stdin */
FILE *fp = stdin;
char *line;
size_t lno = 0;
struct tgrep_atom_s __nstk[16], *needle = __nstk;
size_t nneedle = countof(__nstk);
struct tgrep_atom_soa_s ndlsoa;
void *pctx;

/* no threads reading this stream */
__io_setlocking_bycaller(fp);
__io_setlocking_bycaller(stdout);

/* lest we overflow the stack */
@@ -248,32 +247,37 @@ main(int argc, char *argv[])
/* and now build the needle */
ndlsoa = build_tneedle(needle, nneedle, fmt, nfmt);

for (line = NULL; !__io_eof_p(fp); lno++) {
ssize_t n;
size_t len;
struct dt_t_s t;
const char *sp = NULL;
const char *ep = NULL;
/* using the prchunk reader now */
pctx = init_prchunk(STDIN_FILENO);
while (prchunk_fill(pctx) >= 0) {
for (char *line; prchunk_haslinep(pctx); lno++) {
size_t llen;
struct dt_t_s t;
char *sp = NULL;
char *ep = NULL;

n = getline(&line, &len, fp);
if (n < 0) {
break;
}
/* check if line matches,
* there is currently no way to specify NEEDLE */
t = dt_io_find_strpt2(
line, &ndlsoa, (char**)&sp, (char**)&ep);
if (t.s >= 0 && matchp(t, reft, o)) {
if (!argi->only_matching_given) {
sp = line;
ep = line + n - 1;
llen = prchunk_getline(pctx, &line);

/* check if line matches,
* there's currently no way to specify NEEDLE */
t = dt_io_find_strpt2(line, &ndlsoa, &sp, &ep);

/* finish with newline again */
line[llen] = '\n';

if (t.s >= 0 && matchp(t, reft, o)) {
const size_t msz = sizeof(*line);
if (argi->only_matching_given) {
line = sp;
llen = ep - sp;
*ep = '\n';
}
fwrite(line, msz, llen + 1, stdout);
}
fwrite(sp, sizeof(*sp), ep - sp, stdout);
fputc('\n', stdout);
}
}
/* get rid of resources */
free(line);
free_prchunk(pctx);
if (needle != __nstk) {
free(needle);
}