/src/liblouis/liblouis/commonTranslationFunctions.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* liblouis Braille Translation and Back-Translation Library |
2 | | |
3 | | Based on the Linux screenreader BRLTTY, copyright (C) 1999-2006 by The |
4 | | BRLTTY Team |
5 | | |
6 | | Copyright (C) 2004, 2005, 2006 ViewPlus Technologies, Inc. www.viewplus.com |
7 | | Copyright (C) 2004, 2005, 2006 JJB Software, Inc. www.jjb-software.com |
8 | | Copyright (C) 2016 Mike Gray, American Printing House for the Blind |
9 | | Copyright (C) 2016 Davy Kager, Dedicon |
10 | | |
11 | | This file is part of liblouis. |
12 | | |
13 | | liblouis is free software: you can redistribute it and/or modify it |
14 | | under the terms of the GNU Lesser General Public License as published |
15 | | by the Free Software Foundation, either version 2.1 of the License, or |
16 | | (at your option) any later version. |
17 | | |
18 | | liblouis is distributed in the hope that it will be useful, but |
19 | | WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
21 | | Lesser General Public License for more details. |
22 | | |
23 | | You should have received a copy of the GNU Lesser General Public |
24 | | License along with liblouis. If not, see <http://www.gnu.org/licenses/>. |
25 | | */ |
26 | | |
27 | | #include <config.h> |
28 | | |
29 | | #include <string.h> |
30 | | #include "internal.h" |
31 | | |
32 | | static int passVariables[NUMVAR]; |
33 | | |
34 | | void EXPORT_CALL |
35 | 132 | _lou_resetPassVariables(void) { |
36 | 132 | memset(passVariables, 0, sizeof(passVariables[0]) * NUMVAR); |
37 | 132 | } |
38 | | |
39 | | int EXPORT_CALL |
40 | 496 | _lou_handlePassVariableTest(const widechar *instructions, int *IC, int *itsTrue) { |
41 | 496 | switch (instructions[*IC]) { |
42 | 192 | case pass_eq: |
43 | 192 | if (passVariables[instructions[*IC + 1]] != instructions[*IC + 2]) *itsTrue = 0; |
44 | 192 | *IC += 3; |
45 | 192 | return 1; |
46 | | |
47 | 304 | case pass_lt: |
48 | 304 | if (passVariables[instructions[*IC + 1]] >= instructions[*IC + 2]) *itsTrue = 0; |
49 | 304 | *IC += 3; |
50 | 304 | return 1; |
51 | | |
52 | 0 | case pass_gt: |
53 | 0 | if (passVariables[instructions[*IC + 1]] <= instructions[*IC + 2]) *itsTrue = 0; |
54 | 0 | *IC += 3; |
55 | 0 | return 1; |
56 | | |
57 | 0 | case pass_lteq: |
58 | 0 | if (passVariables[instructions[*IC + 1]] > instructions[*IC + 2]) *itsTrue = 0; |
59 | 0 | *IC += 3; |
60 | 0 | return 1; |
61 | | |
62 | 0 | case pass_gteq: |
63 | 0 | if (passVariables[instructions[*IC + 1]] < instructions[*IC + 2]) *itsTrue = 0; |
64 | 0 | *IC += 3; |
65 | 0 | return 1; |
66 | | |
67 | 0 | default: |
68 | 0 | return 0; |
69 | 496 | } |
70 | 496 | } |
71 | | |
72 | | int EXPORT_CALL |
73 | 27.6k | _lou_handlePassVariableAction(const widechar *instructions, int *IC) { |
74 | 27.6k | switch (instructions[*IC]) { |
75 | 193 | case pass_eq: |
76 | 193 | passVariables[instructions[*IC + 1]] = instructions[*IC + 2]; |
77 | 193 | *IC += 3; |
78 | 193 | return 1; |
79 | | |
80 | 20 | case pass_hyphen: |
81 | 20 | passVariables[instructions[*IC + 1]] -= 1; |
82 | 20 | if (passVariables[instructions[*IC + 1]] < 0) |
83 | 20 | passVariables[instructions[*IC + 1]] = 0; |
84 | 20 | *IC += 2; |
85 | 20 | return 1; |
86 | | |
87 | 23.0k | case pass_plus: |
88 | 23.0k | passVariables[instructions[*IC + 1]] += 1; |
89 | 23.0k | *IC += 2; |
90 | 23.0k | return 1; |
91 | | |
92 | 4.31k | default: |
93 | 4.31k | return 0; |
94 | 27.6k | } |
95 | 27.6k | } |