Browse Source

Add support for configurations that have leading white space

Georgi Chorbadzhiyski 6 years ago
parent
commit
8308faadb3
5 changed files with 212 additions and 2 deletions
  1. 1
    0
      ChangeLog
  2. 7
    2
      cmd.c
  3. 129
    0
      test/input-r2.txt
  4. 3
    0
      test/run
  5. 72
    0
      test/test-r2.ok

+ 1
- 0
ChangeLog View File

@@ -2,6 +2,7 @@
2 2
 xxxx-xx-xx : Version -dev
3 3
  * Add parsing support for CONFIGURATION command
4 4
  * Add support for input that contains Windows style line endings
5
+ * Add support for input that have leading white space
5 6
  * Ignore 'END PRELUDE' command
6 7
 
7 8
 2014-12-08 : Version 2.0

+ 7
- 2
cmd.c View File

@@ -193,6 +193,8 @@ bool parse_command(struct videohub_data *d, char *cmd) {
193 193
 	}
194 194
 
195 195
 	if (!v) {
196
+		if (cmd[0] == '\n') // Do not report 'empty' commands
197
+			return false;
196 198
 		q("WARNING: Videohub sent unknown command!\n");
197 199
 		q("         Please report this command to author's email: georgi@unixsol.org\n");
198 200
 		q("         You may use -q or --quiet to suppress the message.\n");
@@ -343,10 +345,13 @@ bool parse_command(struct videohub_data *d, char *cmd) {
343 345
 int parse_text_buffer(struct videohub_data *d, char *_cmd_buffer) {
344 346
 	int r, cmd_buffer_pos = 0, cmd_len = strlen(_cmd_buffer);
345 347
 	char *cmd_buffer = xzalloc(cmd_len + 1);
346
-	// Clean \r from output because it breaks parsing
348
+	// Clean input
349
+	char last_char = '\0';
347 350
 	for (r = 0; r < cmd_len; r++) {
348
-		if (_cmd_buffer[r] == '\r') continue;
351
+		if (_cmd_buffer[r] == '\r') continue; // Remove windows style line endings
352
+		if (last_char == '\n' && _cmd_buffer[r] == ' ') continue; // Trim leading white space from each line
349 353
 		cmd_buffer[cmd_buffer_pos++] = _cmd_buffer[r];
354
+		last_char = _cmd_buffer[r];
350 355
 	}
351 356
 	// The buffer contains only one command, no splitting is needed
352 357
 	if (!strstr(cmd_buffer, "\n\n")) {

+ 129
- 0
test/input-r2.txt View File

@@ -0,0 +1,129 @@
1
+PROTOCOL PREAMBLE:
2
+                  Version: 2.7
3
+
4
+                              VIDEOHUB DEVICE:
5
+                                              Device present: true
6
+                                                                  Model name: Blackmagic Smart Videohub 20 x 20
7
+                                                                                                               Friendly name:      (2)            @
8
+                                                                                                                                                   Unique ID: XXXXXXXXXXXX
9
+                                                                                                                                                                          Video inputs: 20
10
+                                                                                                                                                                                          Video processing units: 0
11
+                                                                                                                                                                                                                   Video outputs: 20
12
+       Video monitoring outputs: 0
13
+                                  Serial ports: 0
14
+
15
+                                                 INPUT LABELS:
16
+                                                              0 Input 1
17
+                                                                       1 Input 2
18
+                                                                                2 Input 3
19
+                                                                                         3 Input 4
20
+                                                                                                  4 Input 5
21
+                                                                                                           5 Input 6
22
+                                                                                                                    6 Input 7
23
+                                                                                                                             7 Input 8
24
+                                                                                                                                      8 Input 9
25
+                                                                                                                                               9 Input 10
26
+                                                                                                                                                         10 Input 11
27
+                                                                                                                                                                    11 Input 12
28
+                                                                                                                                                                               12 Input 13
29
+                                                                                                                                                                                          13 Input 14
30
+                                                                                                                                                                                                     14 Input 15
31
+                                                                                                                                                                                                                15 Input 16
32
+                                                                                                                                                                                                                           16 Input 17
33
+         17 Input 18
34
+                    18 Input 19
35
+                               19 Input 20
36
+
37
+                                          OUTPUT LABELS:
38
+                                                        0 Output 1
39
+                                                                  1 Output 2
40
+                                                                            2 Output 3
41
+                                                                                      3 Output 4
42
+                                                                                                4 Output 5
43
+                                                                                                          5 Output 6
44
+                                                                                                                    6 Output 7
45
+                                                                                                                              7 Output 8
46
+                                                                                                                                        8 Output 9
47
+                                                                                                                                                  9 Output 10
48
+                                                                                                                                                             10 Output 11
49
+                                                                                                                                                                         11 Output 12
50
+                                                                                                                                                                                     12 Output 13
51
+                                                                                                                                                                                                 13 Output 14
52
+                                                                                                                                                                                                             14 Output 15
53
+                                                                                                                                                                                                                         15 Output 16
54
+        16 Output 17
55
+                    17 Output 18
56
+                                18 Output 19
57
+                                            19 Output 20
58
+
59
+                                                        VIDEO OUTPUT LOCKS:
60
+                                                                           0 U
61
+                                                                              1 U
62
+                                                                                 2 U
63
+                                                                                    3 U
64
+                                                                                       4 U
65
+                                                                                          5 U
66
+                                                                                             6 U
67
+                                                                                                7 U
68
+                                                                                                   8 U
69
+                                                                                                      9 U
70
+                                                                                                         10 U
71
+                                                                                                             11 U
72
+                                                                                                                 12 U
73
+                                                                                                                     13 U
74
+                                                                                                                         14 U
75
+                                                                                                                             15 U
76
+                                                                                                                                 16 U
77
+                                                                                                                                     17 U
78
+                                                                                                                                         18 U
79
+                                                                                                                                             19 U
80
+
81
+                                                                                                                                                 VIDEO OUTPUT ROUTING:
82
+                                                                                                                                                                      0 4
83
+                                                                                                                                                                         1 4
84
+                                                                                                                                                                            2 2
85
+                                                                                                                                                                               3 3
86
+                                                                                                                                                                                  4 4
87
+                                                                                                                                                                                     5 4
88
+                                                                                                                                                                                        6 4
89
+                                                                                                                                                                                           7 4
90
+                                                                                                                                                                                              8 14
91
+                                                                                                                                                                                                  9 9
92
+                                                                                                                                                                                                     10 10
93
+                                                                                                                                                                                                          11 11
94
+                                                                                                                                                                                                               12 8
95
+                                                                                                                                                                                                                   13 8
96
+                                                                                                                                                                                                                       14 14
97
+                                                                                                                                                                                                                            1
98
+5 4
99
+   16 16
100
+        17 17
101
+             18 14
102
+                  19 19
103
+
104
+                       CONFIGURATION:
105
+                                     Take Mode: true
106
+
107
+                                                    END PRELUDE:
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+

+ 3
- 0
test/run View File

@@ -160,3 +160,6 @@ check test/test-19 "Test --list-frames option output"
160 160
 
161 161
 videohubctrl --test-input test/input-r.txt $@ &> test/test-r.out
162 162
 check test/test-r "Test input with windows line endings"
163
+
164
+videohubctrl --test-input test/input-r2.txt $@ &> test/test-r2.out
165
+check test/test-r2 "Test input with leading whitespace and windows line endings"

+ 72
- 0
test/test-r2.ok View File

@@ -0,0 +1,72 @@
1
+Device info
2
+  -------------------------------------------------------------------
3
+  | Device address             | sdi-matrix                         |
4
+  | Device port                | 9990                               |
5
+  | Model name                 | Blackmagic Smart Videohub 20 x     |
6
+  | Friendly name              |      (2)            @              |
7
+  | Unique ID                  | XXXXXXXXXXXX                       |
8
+  | Protocol                   | 2.7                                |
9
+  | Video inputs               | 20                                 |
10
+  | Video outputs              | 20                                 |
11
+  -------------------------------------------------------------------
12
+
13
+Video inputs
14
+  ----------------------------------------------------------------------
15
+  | ### | Video input name         | nn | Routed to output         | s |
16
+  ----------------------------------------------------------------------
17
+  |   1 | Input 1                  |  0 | -                        |   |
18
+  |   2 | Input 2                  |  0 | -                        |   |
19
+  |   3 | Input 3                  |  1 | Output 3                 |   |
20
+  |   4 | Input 4                  |  1 | Output 4                 |   |
21
+  |   5 | Input 5                  |  6 | Output 1                 |   |
22
+  |     |                          |    | Output 2                 |   |
23
+  |     |                          |    | Output 5                 |   |
24
+  |     |                          |    | Output 6                 |   |
25
+  |     |                          |    | Output 7                 |   |
26
+  |     |                          |    | Output 8                 |   |
27
+  |   6 | Input 6                  |  0 | -                        |   |
28
+  |   7 | Input 7                  |  0 | -                        |   |
29
+  |   8 | Input 8                  |  0 | -                        |   |
30
+  |   9 | Input 9                  |  2 | Output 13                |   |
31
+  |     |                          |    | Output 14                |   |
32
+  |  10 | Input 10                 |  1 | Output 10                |   |
33
+  |  11 | Input 11                 |  1 | Output 11                |   |
34
+  |  12 | Input 12                 |  1 | Output 12                |   |
35
+  |  13 | Input 13                 |  0 | -                        |   |
36
+  |  14 | Input 14                 |  0 | -                        |   |
37
+  |  15 | Input 15                 |  3 | Output 9                 |   |
38
+  |     |                          |    | Output 15                |   |
39
+  |     |                          |    | Output 19                |   |
40
+  |  16 | Input 16                 |  0 | -                        |   |
41
+  |  17 | Input 17                 |  1 | Output 17                |   |
42
+  |  18 | Input 18                 |  1 | Output 18                |   |
43
+  |  19 | Input 19                 |  0 | -                        |   |
44
+  |  20 | Input 20                 |  1 | Output 20                |   |
45
+  ----------------------------------------------------------------------
46
+
47
+Video outputs
48
+  ---------------------------------------------------------------------
49
+  | ### | x | Video output name        | Connected video input    | s |
50
+  ---------------------------------------------------------------------
51
+  |   1 |   | Output 1                 | Input 5                  |   |
52
+  |   2 |   | Output 2                 | Input 5                  |   |
53
+  |   3 |   | Output 3                 | Input 3                  |   |
54
+  |   4 |   | Output 4                 | Input 4                  |   |
55
+  |   5 |   | Output 5                 | Input 5                  |   |
56
+  |   6 |   | Output 6                 | Input 5                  |   |
57
+  |   7 |   | Output 7                 | Input 5                  |   |
58
+  |   8 |   | Output 8                 | Input 5                  |   |
59
+  |   9 |   | Output 9                 | Input 15                 |   |
60
+  |  10 |   | Output 10                | Input 10                 |   |
61
+  |  11 |   | Output 11                | Input 11                 |   |
62
+  |  12 |   | Output 12                | Input 12                 |   |
63
+  |  13 |   | Output 13                | Input 9                  |   |
64
+  |  14 |   | Output 14                | Input 9                  |   |
65
+  |  15 |   | Output 15                | Input 15                 |   |
66
+  |  16 |   | Output 16                |                          |   |
67
+  |  17 |   | Output 17                | Input 17                 |   |
68
+  |  18 |   | Output 18                | Input 18                 |   |
69
+  |  19 |   | Output 19                | Input 15                 |   |
70
+  |  20 |   | Output 20                | Input 20                 |   |
71
+  ---------------------------------------------------------------------
72
+

Loading…
Cancel
Save