Package: recutils / 1.7-1.1

evaluation-of-sexes.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
From: Jose E. Marchesi <jemarch@gnu.org>
Subject: fix evaluation of sexes containing #NAME expressions
Origin: upstream, http://git.savannah.gnu.org/cgit/recutils.git/commit/?id=43008ea39d48cc68c3114360b1771396ad8391ec

--- recutils-1.7.orig/src/rec-sex-ast.c
+++ recutils-1.7/src/rec-sex-ast.c
@@ -7,7 +7,7 @@
  *
  */
 
-/* Copyright (C) 2010-2013 Jose E. Marchesi */
+/* Copyright (C) 2010-2014 Jose E. Marchesi */
 
 /* This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -403,4 +403,35 @@ rec_sex_ast_name_p (rec_sex_ast_t ast,
                                idx);
 }
 
+static bool
+rec_sex_ast_hash_name_p_1 (rec_sex_ast_node_t node,
+                           const char *name)
+{
+  if (node)
+    {
+      size_t i = 0;
+
+      if ((node->type == REC_SEX_OP_SHA)
+          && (node->num_children == 1)
+          && (node->children[0]->type == REC_SEX_NAME)
+          && (strcmp (name, node->children[0]->val.name[0]) == 0))
+        return true;
+
+      for (i = 0; i < node->num_children; i++)
+        if (rec_sex_ast_hash_name_p_1 (node->children[i], name))
+          return true;
+    }
+
+  return false;
+}
+
+bool
+rec_sex_ast_hash_name_p (rec_sex_ast_t ast,
+                         const char *name)
+{
+  /* Traverse the AST looking for any name node NAME whose father is a
+     REC_SEX_OP_SHA.  */
+  return rec_sex_ast_hash_name_p_1 (ast->top, name);
+}
+
 /* End of rec-sex-ast.c */
--- recutils-1.7.orig/src/rec-sex-ast.h
+++ recutils-1.7/src/rec-sex-ast.h
@@ -7,7 +7,7 @@
  *
  */
 
-/* Copyright (C) 2010-2013 Jose E. Marchesi */
+/* Copyright (C) 2010-2014 Jose E. Marchesi */
 
 /* This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -126,6 +126,11 @@ char *rec_sex_ast_node_fixed_val (rec_se
    REC_SEX_NAME where NAME.name == NAME and NAME.idx <= IDX.  */
 bool rec_sex_ast_name_p (rec_sex_ast_t ast, const char *name, size_t idx);
 
+/* This function returns 'true' if there is a node on AST of type
+   REC_SEX_NAME where NAME.name == NAME and the parent of the node is
+   of type REC_SEX_OP_SHA, i.e. it recognizes #NAME in the source.  */
+bool rec_sex_ast_hash_name_p (rec_sex_ast_t ast, const char *name);
+
 #endif /* rec-sex-ast.h */
 
 
--- recutils-1.7.orig/src/rec-sex.c
+++ recutils-1.7/src/rec-sex.c
@@ -223,7 +223,8 @@ rec_sex_eval (rec_sex_t sex,
       nf = rec_record_get_num_fields_by_name (record, rec_field_name (field));
       if ((nf > 1)
           && (rec_record_field_mark (record, field) == 0)
-          && (rec_sex_ast_name_p (sex->ast, rec_field_name (field), nf)))
+          && (rec_sex_ast_name_p (sex->ast, rec_field_name (field), nf))
+          && (!rec_sex_ast_hash_name_p (sex->ast, rec_field_name (field))))
         {
           for (j = 0; j < nf; j++)
             {
--- recutils-1.7.orig/torture/utils/recsel.sh
+++ recutils-1.7/torture/utils/recsel.sh
@@ -128,6 +128,15 @@ field2: value22
 field3: value23
 '
 
+test_declare_input_file recurrent-fields-2 \
+'Name: foo
+Index: 5
+Index: 9
+
+Name: bar
+Index: 7
+'
+
 test_declare_input_file dates \
 'Date: Tue Nov 30 12:00:00 CET 2002
 
@@ -991,6 +1000,14 @@ field2: value121
 field2: value122
 '
 
+test_tool recsel-sex-sharp-multiple-2 ok \
+ recsel \
+ '-e "#Index = 1"' \
+ recurrent-fields-2 \
+'Name: bar
+Index: 7
+'
+
 test_tool recsel-sex-sharp-subname ok \
           recsel \
           '-t Package -j Maintainer -e "#Maintainer.URL" -P Maintainer.URL' \