Skip to content

Commit 7891af5

Browse files
committed
Add time extension providing gettimeofday and sleep.
1 parent 18e7a62 commit 7891af5

20 files changed

+417
-48
lines changed

ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2012-06-10 Andrew J. Schorr <[email protected]>
2+
3+
* gawkapi.c (api_update_ERRNO_string): Treat boolean true as a request
4+
for TRANSLATE, and false as DONT_TRANSLATE.
5+
16
2012-06-06 Arnold D. Robbins <[email protected]>
27

38
* cint_array.c (tree_print, leaf_print): Add additional casts

awklib/eg/lib/gettime.awk

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# gettimeofday.awk --- get the time of day in a usable format
1+
# getlocaltime.awk --- get the time of day in a usable format
22
#
33
# Arnold Robbins, [email protected], Public Domain, May 1993
44
#
@@ -25,7 +25,7 @@
2525
# time["weeknum"] -- week number, Sunday first day
2626
# time["altweeknum"] -- week number, Monday first day
2727

28-
function gettimeofday(time, ret, now, i)
28+
function getlocaltime(time, ret, now, i)
2929
{
3030
# get time once, avoids unnecessary system calls
3131
now = systime()

awklib/eg/prog/alarm.awk

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# alarm.awk --- set an alarm
22
#
3-
# Requires gettimeofday() library function
3+
# Requires getlocaltime() library function
44
#
55
# Arnold Robbins, [email protected], Public Domain
66
# May 1993
@@ -53,7 +53,7 @@ BEGIN \
5353
minute = atime[2] + 0 # force numeric
5454

5555
# get current broken down time
56-
gettimeofday(now)
56+
getlocaltime(now)
5757

5858
# if time given is 12-hour hours and it's after that
5959
# hour, e.g., `alarm 5:30' at 9 a.m. means 5:30 p.m.,

doc/ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2012-06-10 Andrew J. Schorr <[email protected]>
2+
3+
* gawk.texi: Rename gettimeofday function to getlocaltime, since
4+
the new time extension will provide gettimeofday.
5+
16
2012-05-24 Andrew J. Schorr <[email protected]>
27

38
* gawk.texi, gawk.1: Replace references to dlload with dl_load.

doc/gawk.info

+19-19
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ texts being (a) (see below), and with the Back-Cover Texts being (b)
398398
* Ordinal Functions:: Functions for using characters as numbers
399399
and vice versa.
400400
* Join Function:: A function to join an array into a string.
401-
* Gettimeofday Function:: A function to get formatted times.
401+
* Getlocaltime Function:: A function to get formatted times.
402402
* Data File Management:: Functions for managing command-line data
403403
files.
404404
* Filetrans Function:: A function for handling data file
@@ -15487,7 +15487,7 @@ programming use.
1548715487
* Ordinal Functions:: Functions for using characters as numbers and
1548815488
vice versa.
1548915489
* Join Function:: A function to join an array into a string.
15490-
* Gettimeofday Function:: A function to get formatted times.
15490+
* Getlocaltime Function:: A function to get formatted times.
1549115491

1549215492

1549315493
File: gawk.info, Node: Strtonum Function, Next: Assert Function, Up: General Functions
@@ -15833,7 +15833,7 @@ tests such as used here prohibitively expensive.
1583315833
extensions, you can simplify `_ord_init' to loop from 0 to 255.
1583415834

1583515835

15836-
File: gawk.info, Node: Join Function, Next: Gettimeofday Function, Prev: Ordinal Functions, Up: General Functions
15836+
File: gawk.info, Node: Join Function, Next: Getlocaltime Function, Prev: Ordinal Functions, Up: General Functions
1583715837

1583815838
13.2.6 Merging an Array into a String
1583915839
-------------------------------------
@@ -15880,7 +15880,7 @@ concatenation. The lack of an explicit operator for concatenation
1588015880
makes string operations more difficult than they really need to be.
1588115881

1588215882

15883-
File: gawk.info, Node: Gettimeofday Function, Prev: Join Function, Up: General Functions
15883+
File: gawk.info, Node: Getlocaltime Function, Prev: Join Function, Up: General Functions
1588415884

1588515885
13.2.7 Managing the Time of Day
1588615886
-------------------------------
@@ -15891,11 +15891,11 @@ with the time of day in human readable form. While `strftime()' is
1589115891
extensive, the control formats are not necessarily easy to remember or
1589215892
intuitively obvious when reading a program.
1589315893

15894-
The following function, `gettimeofday()', populates a user-supplied
15894+
The following function, `getlocaltime()', populates a user-supplied
1589515895
array with preformatted time information. It returns a string with the
1589615896
current time formatted in the same way as the `date' utility:
1589715897

15898-
# gettimeofday.awk --- get the time of day in a usable format
15898+
# getlocaltime.awk --- get the time of day in a usable format
1589915899

1590015900
# Returns a string in the format of output of date(1)
1590115901
# Populates the array argument time with individual values:
@@ -15919,7 +15919,7 @@ current time formatted in the same way as the `date' utility:
1591915919
# time["weeknum"] -- week number, Sunday first day
1592015920
# time["altweeknum"] -- week number, Monday first day
1592115921

15922-
function gettimeofday(time, ret, now, i)
15922+
function getlocaltime(time, ret, now, i)
1592315923
{
1592415924
# get time once, avoids unnecessary system calls
1592515925
now = systime()
@@ -15958,7 +15958,7 @@ current time formatted in the same way as the `date' utility:
1595815958
The string indices are easier to use and read than the various
1595915959
formats required by `strftime()'. The `alarm' program presented in
1596015960
*note Alarm Program::, uses this function. A more general design for
15961-
the `gettimeofday()' function would have allowed the user to supply an
15961+
the `getlocaltime()' function would have allowed the user to supply an
1596215962
optional timestamp value to use instead of the current time.
1596315963

1596415964

@@ -18389,8 +18389,8 @@ prints the message on the standard output. In addition, you can give it
1838918389
the number of times to repeat the message as well as a delay between
1839018390
repetitions.
1839118391

18392-
This program uses the `gettimeofday()' function from *note
18393-
Gettimeofday Function::.
18392+
This program uses the `getlocaltime()' function from *note
18393+
Getlocaltime Function::.
1839418394

1839518395
All the work is done in the `BEGIN' rule. The first part is argument
1839618396
checking and setting of defaults: the delay, the count, and the message
@@ -18405,7 +18405,7 @@ Statement::), but the processing could be done with a series of
1840518405

1840618406
# alarm.awk --- set an alarm
1840718407
#
18408-
# Requires gettimeofday() library function
18408+
# Requires getlocaltime() library function
1840918409
# usage: alarm time [ "message" [ count [ delay ] ] ]
1841018410

1841118411
BEGIN \
@@ -18461,7 +18461,7 @@ alarm:
1846118461
minute = atime[2] + 0 # force numeric
1846218462

1846318463
# get current broken down time
18464-
gettimeofday(now)
18464+
getlocaltime(now)
1846518465

1846618466
# if time given is 12-hour hours and it's after that
1846718467
# hour, e.g., `alarm 5:30' at 9 a.m. means 5:30 p.m.,
@@ -27030,7 +27030,7 @@ Index
2703027030
(line 6)
2703127031
* functions, library, managing data files: Data File Management.
2703227032
(line 6)
27033-
* functions, library, managing time: Gettimeofday Function.
27033+
* functions, library, managing time: Getlocaltime Function.
2703427034
(line 6)
2703527035
* functions, library, merging arrays into strings: Join Function.
2703627036
(line 6)
@@ -27185,6 +27185,8 @@ Index
2718527185
* getline command, variants: Getline Summary. (line 6)
2718627186
* getline statement, BEGINFILE/ENDFILE patterns and: BEGINFILE/ENDFILE.
2718727187
(line 54)
27188+
* getlocaltime() user-defined function: Getlocaltime Function.
27189+
(line 16)
2718827190
* getopt() function (C library): Getopt Function. (line 15)
2718927191
* getopt() user-defined function: Getopt Function. (line 108)
2719027192
* getpwent() function (C library): Passwd Functions. (line 16)
@@ -27196,8 +27198,6 @@ Index
2719627198
* gettext library: Explaining gettext. (line 6)
2719727199
* gettext library, locale categories: Explaining gettext. (line 80)
2719827200
* gettext() function (C library): Explaining gettext. (line 62)
27199-
* gettimeofday() user-defined function: Gettimeofday Function.
27200-
(line 16)
2720127201
* GMP: Arbitrary Precision Arithmetic.
2720227202
(line 6)
2720327203
* GNITS mailing list: Acknowledgments. (line 52)
@@ -27446,7 +27446,7 @@ Index
2744627446
(line 6)
2744727447
* libraries of awk functions, managing, data files: Data File Management.
2744827448
(line 6)
27449-
* libraries of awk functions, managing, time: Gettimeofday Function.
27449+
* libraries of awk functions, managing, time: Getlocaltime Function.
2745027450
(line 6)
2745127451
* libraries of awk functions, merging arrays into strings: Join Function.
2745227452
(line 6)
@@ -28296,13 +28296,13 @@ Index
2829628296
* tilde (~), ~ operator: Regexp Usage. (line 19)
2829728297
* time, alarm clock example program: Alarm Program. (line 9)
2829828298
* time, localization and: Explaining gettext. (line 115)
28299-
* time, managing: Gettimeofday Function.
28299+
* time, managing: Getlocaltime Function.
2830028300
(line 6)
2830128301
* time, retrieving: Time Functions. (line 17)
2830228302
* timeout, reading input: Read Timeout. (line 6)
2830328303
* timestamps: Time Functions. (line 6)
2830428304
* timestamps, converting dates to: Time Functions. (line 74)
28305-
* timestamps, formatted: Gettimeofday Function.
28305+
* timestamps, formatted: Getlocaltime Function.
2830628306
(line 6)
2830728307
* tolower() function: String Functions. (line 523)
2830828308
* toupper() function: String Functions. (line 529)
@@ -28822,7 +28822,7 @@ Ref: Ordinal Functions-Footnote-1652320
2882228822
Ref: Ordinal Functions-Footnote-2652572
2882328823
Node: Join Function652781
2882428824
Ref: Join Function-Footnote-1654552
28825-
Node: Gettimeofday Function654752
28825+
Node: Getlocaltime Function654752
2882628826
Node: Data File Management658467
2882728827
Node: Filetrans Function659099
2882828828
Node: Rewind Function663238

doc/gawk.texi

+12-12
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ particular records in a file and perform operations upon them.
597597
* Ordinal Functions:: Functions for using characters as numbers
598598
and vice versa.
599599
* Join Function:: A function to join an array into a string.
600-
* Gettimeofday Function:: A function to get formatted times.
600+
* Getlocaltime Function:: A function to get formatted times.
601601
* Data File Management:: Functions for managing command-line data
602602
files.
603603
* Filetrans Function:: A function for handling data file
@@ -20608,7 +20608,7 @@ programming use.
2060820608
* Ordinal Functions:: Functions for using characters as numbers and
2060920609
vice versa.
2061020610
* Join Function:: A function to join an array into a string.
20611-
* Gettimeofday Function:: A function to get formatted times.
20611+
* Getlocaltime Function:: A function to get formatted times.
2061220612
@end menu
2061320613

2061420614
@node Strtonum Function
@@ -21133,7 +21133,7 @@ be nice if @command{awk} had an assignment operator for concatenation.
2113321133
The lack of an explicit operator for concatenation makes string operations
2113421134
more difficult than they really need to be.}
2113521135

21136-
@node Gettimeofday Function
21136+
@node Getlocaltime Function
2113721137
@subsection Managing the Time of Day
2113821138

2113921139
@cindex libraries of @command{awk} functions, managing, time
@@ -21147,14 +21147,14 @@ in human readable form. While @code{strftime()} is extensive, the control
2114721147
formats are not necessarily easy to remember or intuitively obvious when
2114821148
reading a program.
2114921149

21150-
The following function, @code{gettimeofday()}, populates a user-supplied array
21150+
The following function, @code{getlocaltime()}, populates a user-supplied array
2115121151
with preformatted time information. It returns a string with the current
2115221152
time formatted in the same way as the @command{date} utility:
2115321153

21154-
@cindex @code{gettimeofday()} user-defined function
21154+
@cindex @code{getlocaltime()} user-defined function
2115521155
@example
2115621156
@c file eg/lib/gettime.awk
21157-
# gettimeofday.awk --- get the time of day in a usable format
21157+
# getlocaltime.awk --- get the time of day in a usable format
2115821158
@c endfile
2115921159
@ignore
2116021160
@c file eg/lib/gettime.awk
@@ -21187,7 +21187,7 @@ time formatted in the same way as the @command{date} utility:
2118721187
# time["weeknum"] -- week number, Sunday first day
2118821188
# time["altweeknum"] -- week number, Monday first day
2118921189

21190-
function gettimeofday(time, ret, now, i)
21190+
function getlocaltime(time, ret, now, i)
2119121191
@{
2119221192
# get time once, avoids unnecessary system calls
2119321193
now = systime()
@@ -21229,7 +21229,7 @@ The string indices are easier to use and read than the various formats
2122921229
required by @code{strftime()}. The @code{alarm} program presented in
2123021230
@ref{Alarm Program},
2123121231
uses this function.
21232-
A more general design for the @code{gettimeofday()} function would have
21232+
A more general design for the @code{getlocaltime()} function would have
2123321233
allowed the user to supply an optional timestamp value to use instead
2123421234
of the current time.
2123521235

@@ -24521,8 +24521,8 @@ it prints the message on the standard output. In addition, you can give it
2452124521
the number of times to repeat the message as well as a delay between
2452224522
repetitions.
2452324523

24524-
This program uses the @code{gettimeofday()} function from
24525-
@ref{Gettimeofday Function}.
24524+
This program uses the @code{getlocaltime()} function from
24525+
@ref{Getlocaltime Function}.
2452624526

2452724527
All the work is done in the @code{BEGIN} rule. The first part is argument
2452824528
checking and setting of defaults: the delay, the count, and the message to
@@ -24541,7 +24541,7 @@ Here is the program:
2454124541
@c file eg/prog/alarm.awk
2454224542
# alarm.awk --- set an alarm
2454324543
#
24544-
# Requires gettimeofday() library function
24544+
# Requires getlocaltime() library function
2454524545
@c endfile
2454624546
@ignore
2454724547
@c file eg/prog/alarm.awk
@@ -24613,7 +24613,7 @@ is how long to wait before setting off the alarm:
2461324613
minute = atime[2] + 0 # force numeric
2461424614

2461524615
# get current broken down time
24616-
gettimeofday(now)
24616+
getlocaltime(now)
2461724617

2461824618
# if time given is 12-hour hours and it's after that
2461924619
# hour, e.g., `alarm 5:30' at 9 a.m. means 5:30 p.m.,

extension/ChangeLog

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2012-06-10 Andrew J. Schorr <[email protected]>
2+
3+
* Makefile.am: Add time extension.
4+
* configure.ac: To support time extension, check for some headers
5+
and functions that are needed.
6+
* time.c: New file implementing sleep and gettimeofday.
7+
18
2012-06-10 Andrew J. Schorr <[email protected]>
29

310
* Makefile.am: Remove comment referring to deleted test extensions

extension/Makefile.am

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ pkgextension_LTLIBRARIES = \
3535
filefuncs.la \
3636
fork.la \
3737
ordchr.la \
38-
readfile.la
38+
readfile.la \
39+
time.la
3940

4041
MY_MODULE_FLAGS = -module -avoid-version -no-undefined
4142

@@ -47,6 +48,8 @@ ordchr_la_SOURCES = ordchr.c
4748
ordchr_la_LDFLAGS = $(MY_MODULE_FLAGS)
4849
readfile_la_SOURCES = readfile.c
4950
readfile_la_LDFLAGS = $(MY_MODULE_FLAGS)
51+
time_la_SOURCES = time.c
52+
time_la_LDFLAGS = $(MY_MODULE_FLAGS)
5053
#rwarray_la_SOURCES = rwarray.c
5154
#rwarray_la_LDFLAGS = $(MY_MODULE_FLAGS)
5255

extension/Makefile.in

+15-6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ readfile_la_OBJECTS = $(am_readfile_la_OBJECTS)
154154
readfile_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
155155
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
156156
$(readfile_la_LDFLAGS) $(LDFLAGS) -o $@
157+
time_la_LIBADD =
158+
am_time_la_OBJECTS = time.lo
159+
time_la_OBJECTS = $(am_time_la_OBJECTS)
160+
time_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
161+
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(time_la_LDFLAGS) \
162+
$(LDFLAGS) -o $@
157163
DEFAULT_INCLUDES = -I.@am__isrc@
158164
depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp
159165
am__depfiles_maybe = depfiles
@@ -168,9 +174,9 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
168174
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
169175
$(LDFLAGS) -o $@
170176
SOURCES = $(filefuncs_la_SOURCES) $(fork_la_SOURCES) \
171-
$(ordchr_la_SOURCES) $(readfile_la_SOURCES)
177+
$(ordchr_la_SOURCES) $(readfile_la_SOURCES) $(time_la_SOURCES)
172178
DIST_SOURCES = $(filefuncs_la_SOURCES) $(fork_la_SOURCES) \
173-
$(ordchr_la_SOURCES) $(readfile_la_SOURCES)
179+
$(ordchr_la_SOURCES) $(readfile_la_SOURCES) $(time_la_SOURCES)
174180
am__can_run_installinfo = \
175181
case $$AM_UPDATE_INFO_DIR in \
176182
n|no|NO) false;; \
@@ -317,15 +323,13 @@ AM_CPPFLAGS = -I$(srcdir)/..
317323
# correctly after changing configure.ac
318324
ACLOCAL_AMFLAGS = -I m4
319325

320-
# The arrayparm, zaxxon (dl), and testarg libraries do not do anything useful,
321-
# so do not build or install them.
322-
323326
# Note: rwarray does not currently compile.
324327
pkgextension_LTLIBRARIES = \
325328
filefuncs.la \
326329
fork.la \
327330
ordchr.la \
328-
readfile.la
331+
readfile.la \
332+
time.la
329333

330334
MY_MODULE_FLAGS = -module -avoid-version -no-undefined
331335
filefuncs_la_SOURCES = filefuncs.c
@@ -336,6 +340,8 @@ ordchr_la_SOURCES = ordchr.c
336340
ordchr_la_LDFLAGS = $(MY_MODULE_FLAGS)
337341
readfile_la_SOURCES = readfile.c
338342
readfile_la_LDFLAGS = $(MY_MODULE_FLAGS)
343+
time_la_SOURCES = time.c
344+
time_la_LDFLAGS = $(MY_MODULE_FLAGS)
339345
#rwarray_la_SOURCES = rwarray.c
340346
#rwarray_la_LDFLAGS = $(MY_MODULE_FLAGS)
341347
EXTRA_DIST = \
@@ -441,6 +447,8 @@ ordchr.la: $(ordchr_la_OBJECTS) $(ordchr_la_DEPENDENCIES) $(EXTRA_ordchr_la_DEPE
441447
$(ordchr_la_LINK) -rpath $(pkgextensiondir) $(ordchr_la_OBJECTS) $(ordchr_la_LIBADD) $(LIBS)
442448
readfile.la: $(readfile_la_OBJECTS) $(readfile_la_DEPENDENCIES) $(EXTRA_readfile_la_DEPENDENCIES)
443449
$(readfile_la_LINK) -rpath $(pkgextensiondir) $(readfile_la_OBJECTS) $(readfile_la_LIBADD) $(LIBS)
450+
time.la: $(time_la_OBJECTS) $(time_la_DEPENDENCIES) $(EXTRA_time_la_DEPENDENCIES)
451+
$(time_la_LINK) -rpath $(pkgextensiondir) $(time_la_OBJECTS) $(time_la_LIBADD) $(LIBS)
444452

445453
mostlyclean-compile:
446454
-rm -f *.$(OBJEXT)
@@ -452,6 +460,7 @@ distclean-compile:
452460
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fork.Plo@am__quote@
453461
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordchr.Plo@am__quote@
454462
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readfile.Plo@am__quote@
463+
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Plo@am__quote@
455464

456465
.c.o:
457466
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<

0 commit comments

Comments
 (0)