Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libcurses/director tests/libcurses: extract functi...



details:   https://anonhg.NetBSD.org/src/rev/9b7bff8fe83e
branches:  trunk
changeset: 951953:9b7bff8fe83e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Feb 08 19:35:21 2021 +0000

description:
tests/libcurses: extract function 'delay_millis' from the grammar

diffstat:

 tests/lib/libcurses/director/testlang_parse.y |  61 +++++++++++++++-----------
 1 files changed, 34 insertions(+), 27 deletions(-)

diffs (90 lines):

diff -r 17850e27fc0c -r 9b7bff8fe83e tests/lib/libcurses/director/testlang_parse.y
--- a/tests/lib/libcurses/director/testlang_parse.y     Mon Feb 08 19:28:08 2021 +0000
+++ b/tests/lib/libcurses/director/testlang_parse.y     Mon Feb 08 19:35:21 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: testlang_parse.y,v 1.37 2021/02/08 19:28:08 rillig Exp $       */
+/*     $NetBSD: testlang_parse.y,v 1.38 2021/02/08 19:35:21 rillig Exp $       */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -139,6 +139,7 @@
 static void    compare_streams(const char *, bool);
 static void    do_function_call(size_t);
 static void    check(void);
+static void    delay_millis(const char *);
 static void    save_slave_output(bool);
 static void    validate_type(data_enum_t, ct_data_t *, int);
 static void    set_var(data_enum_t, const char *, void *);
@@ -292,32 +293,9 @@
                ;
 
 delay          : DELAY numeric {
-       /* set the inter-character delay */
-       if (sscanf($2, "%d", &input_delay) == 0)
-               err(1, "%s:%zu: Delay specification %s must be an int",
-                   cur_file, line, $2);
-       if (verbose) {
-               fprintf(stderr, "Set input delay to %d ms\n", input_delay);
-       }
-
-       if (input_delay < DELAY_MIN)
-               input_delay = DELAY_MIN;
-       /*
-        * Fill in the timespec structure now ready for use later.
-        * The delay is specified in milliseconds so convert to timespec
-        * values
-        */
-       delay_spec.tv_sec = input_delay / 1000;
-       delay_spec.tv_nsec = (input_delay - 1000 * delay_spec.tv_sec) * 1000;
-       if (verbose) {
-               fprintf(stderr, "set delay to %jd.%jd\n",
-                   (intmax_t)delay_spec.tv_sec,
-                   (intmax_t)delay_spec.tv_nsec);
-       }
-
-       init_parse_variables(0);
- }
-       ;
+                       delay_millis($2);
+               }
+               ;
 
 input          : INPUT STRING {
        if (input_str != NULL) {
@@ -1369,6 +1347,35 @@
        init_parse_variables(0);
 }
 
+static void
+delay_millis(const char *millis)
+{
+       /* set the inter-character delay */
+       if (sscanf(millis, "%d", &input_delay) == 0)
+               err(1, "%s:%zu: Delay specification %s must be an int",
+                   cur_file, line, millis);
+       if (verbose) {
+               fprintf(stderr, "Set input delay to %d ms\n", input_delay);
+       }
+
+       if (input_delay < DELAY_MIN)
+               input_delay = DELAY_MIN;
+       /*
+        * Fill in the timespec structure now ready for use later.
+        * The delay is specified in milliseconds so convert to timespec
+        * values
+        */
+       delay_spec.tv_sec = input_delay / 1000;
+       delay_spec.tv_nsec = (input_delay - 1000 * delay_spec.tv_sec) * 1000;
+       if (verbose) {
+               fprintf(stderr, "set delay to %jd.%jd\n",
+                   (intmax_t)delay_spec.tv_sec,
+                   (intmax_t)delay_spec.tv_nsec);
+       }
+
+       init_parse_variables(0);
+}
+
 /*
  * Initialise the command structure - if initial is non-zero then just set
  * everything to sane values otherwise free any memory that was allocated



Home | Main Index | Thread Index | Old Index