Skip to content

Commit 6150f01

Browse files
author
Colum Paget
committed
v2.1
1 parent f4c7771 commit 6150f01

File tree

6 files changed

+91
-38
lines changed

6 files changed

+91
-38
lines changed

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.1 (2025-02-12)
2+
----------------
3+
* If start and end patterns are defined, and -min or -max is used to exclude things by time, then exclude the entire block, rather than just lines within it.
4+
15
2.0 (2025-02-07)
26
----------------
37
* add `-fromstart` option to allow measuring timediffs from a 'start line' rather than from previous line

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
OBJ=common.o parse.o stats.o settings.o help.o
2-
FLAGS=-g -O2 -DPACKAGE_NAME=\"timediff\" -DPACKAGE_TARNAME=\"timediff\" -DPACKAGE_VERSION=\"2.0\" -DPACKAGE_STRING=\"timediff\ 2.0\" -DPACKAGE_BUGREPORT=\"[email protected]\" -DPACKAGE_URL=\"\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_LIBZ=1 -DHAVE_LIBUSEFUL_5_LIBUSEFUL_H=1 -DHAVE_LIBUSEFUL_5=1
2+
FLAGS=-g -O2 -DPACKAGE_NAME=\"timediff\" -DPACKAGE_TARNAME=\"timediff\" -DPACKAGE_VERSION=\"2.1\" -DPACKAGE_STRING=\"timediff\ 2.1\" -DPACKAGE_BUGREPORT=\"[email protected]\" -DPACKAGE_URL=\"\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_LIBZ=1 -DHAVE_LIBUSEFUL_5_LIBUSEFUL_H=1 -DHAVE_LIBUSEFUL_5=1
33
LIBS=-lUseful-5 -lz
44
STATIC_LIBS=
55
PREFIX=/usr/local

config.status

+5-5
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ exec 6>&1
373373
# report actual input values of CONFIG_FILES etc. instead of their
374374
# values after options handling.
375375
ac_log="
376-
This file was extended by timediff $as_me 2.0, which was
376+
This file was extended by timediff $as_me 2.1, which was
377377
generated by GNU Autoconf 2.71. Invocation command line was
378378
379379
CONFIG_FILES = $CONFIG_FILES
@@ -412,7 +412,7 @@ Report bugs to <[email protected]>."
412412

413413
ac_cs_config=''
414414
ac_cs_version="\
415-
timediff config.status 2.0
415+
timediff config.status 2.1
416416
configured by ./configure, generated by GNU Autoconf 2.71,
417417
with options \"$ac_cs_config\"
418418
@@ -595,7 +595,7 @@ S["LIBS"]="-lUseful-5 -lz "
595595
S["ECHO_T"]=""
596596
S["ECHO_N"]="-n"
597597
S["ECHO_C"]=""
598-
S["DEFS"]="-DPACKAGE_NAME=\\\"timediff\\\" -DPACKAGE_TARNAME=\\\"timediff\\\" -DPACKAGE_VERSION=\\\"2.0\\\" -DPACKAGE_STRING=\\\"timediff\\ 2.0\\\" -DPACKAGE_BUGREPORT=\\\"colums"\
598+
S["DEFS"]="-DPACKAGE_NAME=\\\"timediff\\\" -DPACKAGE_TARNAME=\\\"timediff\\\" -DPACKAGE_VERSION=\\\"2.1\\\" -DPACKAGE_STRING=\\\"timediff\\ 2.1\\\" -DPACKAGE_BUGREPORT=\\\"colums"\
599599
"[email protected]\\\" -DPACKAGE_URL=\\\"\\\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H"\
600600
"=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_LIBZ=1 -DHAVE_LIBUSEFUL_5_LIBUSEFUL_H=1 -DHAVE_LIBUSEFUL_5=1"
601601
S["mandir"]="${datarootdir}/man"
@@ -623,8 +623,8 @@ S["prefix"]="/usr/local"
623623
S["exec_prefix"]="${prefix}"
624624
S["PACKAGE_URL"]=""
625625
S["PACKAGE_BUGREPORT"]="[email protected]"
626-
S["PACKAGE_STRING"]="timediff 2.0"
627-
S["PACKAGE_VERSION"]="2.0"
626+
S["PACKAGE_STRING"]="timediff 2.1"
627+
S["PACKAGE_VERSION"]="2.1"
628628
S["PACKAGE_TARNAME"]="timediff"
629629
S["PACKAGE_NAME"]="timediff"
630630
S["PATH_SEPARATOR"]=":"

configure

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/sh
22
# Guess values for system-dependent variables and create Makefiles.
3-
# Generated by GNU Autoconf 2.71 for timediff 2.0.
3+
# Generated by GNU Autoconf 2.71 for timediff 2.1.
44
#
55
# Report bugs to <[email protected]>.
66
#
@@ -611,8 +611,8 @@ MAKEFLAGS=
611611
# Identity of this package.
612612
PACKAGE_NAME='timediff'
613613
PACKAGE_TARNAME='timediff'
614-
PACKAGE_VERSION='2.0'
615-
PACKAGE_STRING='timediff 2.0'
614+
PACKAGE_VERSION='2.1'
615+
PACKAGE_STRING='timediff 2.1'
616616
PACKAGE_BUGREPORT='[email protected]'
617617
PACKAGE_URL=''
618618

@@ -1264,7 +1264,7 @@ if test "$ac_init_help" = "long"; then
12641264
# Omit some internal or obsolete options to make the list less imposing.
12651265
# This message is too long to be a string in the A/UX 3.1 sh.
12661266
cat <<_ACEOF
1267-
\`configure' configures timediff 2.0 to adapt to many kinds of systems.
1267+
\`configure' configures timediff 2.1 to adapt to many kinds of systems.
12681268
12691269
Usage: $0 [OPTION]... [VAR=VALUE]...
12701270
@@ -1326,7 +1326,7 @@ fi
13261326

13271327
if test -n "$ac_init_help"; then
13281328
case $ac_init_help in
1329-
short | recursive ) echo "Configuration of timediff 2.0:";;
1329+
short | recursive ) echo "Configuration of timediff 2.1:";;
13301330
esac
13311331
cat <<\_ACEOF
13321332
@@ -1417,7 +1417,7 @@ fi
14171417
test -n "$ac_init_help" && exit $ac_status
14181418
if $ac_init_version; then
14191419
cat <<\_ACEOF
1420-
timediff configure 2.0
1420+
timediff configure 2.1
14211421
generated by GNU Autoconf 2.71
14221422
14231423
Copyright (C) 2021 Free Software Foundation, Inc.
@@ -1573,7 +1573,7 @@ cat >config.log <<_ACEOF
15731573
This file contains any messages produced by compilers while
15741574
running configure, to aid debugging if configure makes a mistake.
15751575
1576-
It was created by timediff $as_me 2.0, which was
1576+
It was created by timediff $as_me 2.1, which was
15771577
generated by GNU Autoconf 2.71. Invocation command line was
15781578
15791579
$ $0$ac_configure_args_raw
@@ -4575,7 +4575,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
45754575
# report actual input values of CONFIG_FILES etc. instead of their
45764576
# values after options handling.
45774577
ac_log="
4578-
This file was extended by timediff $as_me 2.0, which was
4578+
This file was extended by timediff $as_me 2.1, which was
45794579
generated by GNU Autoconf 2.71. Invocation command line was
45804580
45814581
CONFIG_FILES = $CONFIG_FILES
@@ -4630,7 +4630,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
46304630
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
46314631
ac_cs_config='$ac_cs_config_escaped'
46324632
ac_cs_version="\\
4633-
timediff config.status 2.0
4633+
timediff config.status 2.1
46344634
configured by $0, generated by GNU Autoconf 2.71,
46354635
with options \\"\$ac_cs_config\\"
46364636

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([timediff],[2.0],[[email protected]])
1+
AC_INIT([timediff],[2.1],[[email protected]])
22

33
AC_PROG_CC
44
AC_LANG([C])

main.c

+71-22
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ int ItemIncluded(const char *Line, double secs)
4747

4848

4949

50-
#define ITEM_NORMAL 0
51-
#define ITEM_START -1
52-
#define ITEM_END -2
50+
#define ITEM_NORMAL 0
51+
#define ITEM_START -1
52+
#define ITEM_END -2
53+
#define ITEM_EXCLUDE -3
5354

54-
int ProcessTimedItem(struct timeval *When, double Secs, const char *Line)
55+
int ProcessTimedItem(struct timeval *When, double Secs, const char *Line, char **Output)
5556
{
5657
const char *prefix="", *postfix="";
5758
char *Tempstr=NULL;
5859
int RetVal=ITEM_NORMAL;
5960

61+
//if a start is declared, and we have not encountered a start-line, or
62+
//are between a start-line and an end-line, then ignore this line
6063
if (Started)
6164
{
6265
if ((Settings.WarnTime > -1) && (Secs > Settings.WarnTime))
@@ -71,8 +74,8 @@ int ProcessTimedItem(struct timeval *When, double Secs, const char *Line)
7174
postfix=Settings.NormPostfix;
7275
}
7376

74-
if (Settings.Flags & FLAG_NANOSECS) printf("%s%14.6f%s %s\n", prefix, Secs, postfix, Line);
75-
else printf("%s%10.3f%s %s\n", prefix, Secs, postfix, Line);
77+
if (Settings.Flags & FLAG_NANOSECS) *Output=FormatStr(*Output, "%s%14.6f%s %s\n", prefix, Secs, postfix, Line);
78+
else *Output=FormatStr(*Output, "%s%10.3f%s %s\n", prefix, Secs, postfix, Line);
7679

7780
StatsInsert("default", When, Secs);
7881

@@ -92,28 +95,33 @@ int ProcessTimedItem(struct timeval *When, double Secs, const char *Line)
9295

9396

9497

95-
double ProcessLine(struct timeval *Prev, struct timeval *Curr, const char *Line)
98+
double ProcessLine(struct timeval *Prev, struct timeval *Curr, const char *Line, char **Output)
9699
{
97100
double secs=0;
98101
int result;
99102

100103
secs=CalcTimediff(Prev, Curr);
104+
105+
//if it's a 'Start' line, then we won't be calculating a difference between it
106+
//and the previous line. Also, if a start is declared, then we will ignore lines
107+
//before a start, or between a start and an end if an end is declared.
101108
if (InPatternList(Line, Settings.StartStrings, NULL))
102109
{
103110
//if we are in 'warn only' mode, where we only display items that have a time warning
104111
//then we want a 'start string' that matches the start of an interaction to be registered as the start time
105112
//but we don't want it displayed
106-
if (! (Settings.Flags & FLAG_WARN_ONLY)) printf("%s%10s%s %s\n", Settings.NormPrefix, " -- ", Settings.NormPostfix, Line);
113+
if (! (Settings.Flags & FLAG_WARN_ONLY)) *Output=FormatStr(*Output, "%s%10s%s %s\n", Settings.NormPrefix, " -- ", Settings.NormPostfix, Line);
107114
Started=TRUE;
108115
secs=ITEM_START;
109116
}
110117
else
111118
{
112119
if (ItemIncluded(Line, secs))
113120
{
114-
result=ProcessTimedItem(Curr, secs, Line);
121+
result=ProcessTimedItem(Curr, secs, Line, Output);
115122
if (result != ITEM_NORMAL) secs=(double) result;
116123
}
124+
else secs=ITEM_EXCLUDE;
117125
}
118126

119127
return(secs);
@@ -160,11 +168,52 @@ char *TimediffReadLine(char *RetStr, STREAM *S)
160168
}
161169

162170

171+
char *HandleStartEndBlock(char *RetStr, double secs, char *Line, struct timeval *PrevTime, struct timeval *CurrTime)
172+
{
173+
//if we aren't using start or end strings, then we will just output the current line
174+
//and PrevTime becomes the CurrTime. We don't use the OutputBuffer provided by RetStr
175+
if ( (! StrValid(Settings.StartStrings)) && (! StrValid(Settings.EndStrings)) )
176+
{
177+
memcpy(PrevTime, CurrTime, sizeof(struct timeval));
178+
printf("%s\n", Line);
179+
return(CopyStr(RetStr, ""));
180+
}
181+
182+
if (secs == ITEM_START)
183+
{
184+
// on a start we always start a new output block,
185+
// and set PrevTime to CurrTime
186+
memcpy(PrevTime, CurrTime, sizeof(struct timeval));
187+
RetStr=CopyStr(RetStr, Line);
188+
}
189+
else if (secs == ITEM_END)
190+
{
191+
//on an end we output the always buffered block of lines
192+
RetStr=CatStr(RetStr, Line);
193+
printf("%s\n", RetStr);
194+
RetStr=CopyStr(RetStr, "");
195+
}
196+
else if (secs != ITEM_EXCLUDE)
197+
{
198+
RetStr=CatStr(RetStr, Line);
199+
200+
//if we are measuring time from a start line, then we don't update PrevTime on every line
201+
if (! (Settings.Flags & FLAG_FROM_START)) memcpy(PrevTime, CurrTime, sizeof(struct timeval));
202+
if (! StrValid(Settings.EndStrings))
203+
{
204+
printf("%s\n", RetStr);
205+
RetStr=CopyStr(RetStr, "");
206+
}
207+
}
208+
209+
return(RetStr);
210+
}
211+
163212

164213
int main(int argc, const char *argv[])
165214
{
166215
STREAM *S;
167-
char *Tempstr=NULL;
216+
char *Tempstr=NULL, *InputLine=NULL, *Output=NULL;
168217
struct timeval Prev, Curr;
169218
double secs;
170219

@@ -178,21 +227,17 @@ int main(int argc, const char *argv[])
178227
S=STREAMOpen(Settings.Input, "r");
179228
if (S)
180229
{
181-
Tempstr=TimediffReadLine(Tempstr, S);
182-
while (Tempstr)
230+
InputLine=TimediffReadLine(InputLine, S);
231+
while (InputLine)
183232
{
184-
if (StrValid(Tempstr))
233+
if (StrValid(InputLine))
185234
{
186-
ParseDateTime(Tempstr, &Curr);
187-
secs=ProcessLine(&Prev, &Curr, Tempstr);
188-
189-
if (Settings.Flags & FLAG_FROM_START)
190-
{
191-
if (secs == ITEM_START) memcpy(&Prev, &Curr, sizeof(struct timeval));
192-
}
193-
else memcpy(&Prev, &Curr, sizeof(struct timeval));
235+
ParseDateTime(InputLine, &Curr);
236+
secs=ProcessLine(&Prev, &Curr, InputLine, &Tempstr);
237+
//actual printing of output happens in HandleStartEndBlock
238+
Output=HandleStartEndBlock(Output, secs, Tempstr, &Prev, &Curr);
194239
}
195-
Tempstr=TimediffReadLine(Tempstr, S);
240+
InputLine=TimediffReadLine(InputLine, S);
196241
}
197242
//Display stats before closing stream,
198243
//because the stream might be stdin/stdout
@@ -203,5 +248,9 @@ int main(int argc, const char *argv[])
203248
STREAMClose(S);
204249
}
205250

251+
Destroy(InputLine);
252+
Destroy(Tempstr);
253+
Destroy(Output);
254+
206255
return(0);
207256
}

0 commit comments

Comments
 (0)