basic_functions.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /**
  2. * @file basic_functions.c
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include <stdlib.h>
  30. #include <misc/expstring.h>
  31. #include <misc/bsize.h>
  32. #include <misc/ascii_utils.h>
  33. #include <ncd/NCDValGenerator.h>
  34. #include <ncd/NCDValParser.h>
  35. #include <ncd/module_common.h>
  36. #include <generated/blog_channel_ncd_basic_functions.h>
  37. // Trivial functions.
  38. static void error_eval (NCDCall call)
  39. {
  40. FunctionLog(&call, BLOG_ERROR, "error: failing");
  41. }
  42. static void identity_eval (NCDCall call)
  43. {
  44. if (NCDCall_ArgCount(&call) != 1) {
  45. return FunctionLog(&call, BLOG_ERROR, "identity: need one argument");
  46. }
  47. NCDCall_SetResult(&call, NCDCall_EvalArg(&call, 0, NCDCall_ResMem(&call)));
  48. }
  49. // Logical functions.
  50. static void if_eval (NCDCall call)
  51. {
  52. if (NCDCall_ArgCount(&call) != 3) {
  53. return FunctionLog(&call, BLOG_ERROR, "if: need three arguments");
  54. }
  55. NCDValRef cond = NCDCall_EvalArg(&call, 0, NCDCall_ResMem(&call));
  56. if (NCDVal_IsInvalid(cond)) {
  57. return;
  58. }
  59. int cond_val;
  60. if (!ncd_read_boolean(cond, &cond_val)) {
  61. return FunctionLog(&call, BLOG_ERROR, "if: bad condition");
  62. }
  63. int eval_arg = 2 - cond_val;
  64. NCDCall_SetResult(&call, NCDCall_EvalArg(&call, eval_arg, NCDCall_ResMem(&call)));
  65. }
  66. static void ifel_eval (NCDCall call)
  67. {
  68. size_t count = NCDCall_ArgCount(&call);
  69. if (count % 2 == 0) {
  70. return FunctionLog(&call, BLOG_ERROR, "ifel: need an odd number of arguments");
  71. }
  72. NCDValRef value;
  73. size_t j = 0;
  74. while (1) {
  75. NCDValRef arg = NCDCall_EvalArg(&call, j, NCDCall_ResMem(&call));
  76. if (NCDVal_IsInvalid(arg)) {
  77. return;
  78. }
  79. if (j == count - 1) {
  80. value = arg;
  81. break;
  82. }
  83. NCDValRef arg2 = NCDCall_EvalArg(&call, j + 1, NCDCall_ResMem(&call));
  84. if (NCDVal_IsInvalid(arg2)) {
  85. return;
  86. }
  87. int arg_val;
  88. if (!ncd_read_boolean(arg, &arg_val)) {
  89. return FunctionLog(&call, BLOG_ERROR, "ifel: bad condition");
  90. }
  91. if (arg_val) {
  92. value = arg2;
  93. break;
  94. }
  95. j += 2;
  96. }
  97. NCDCall_SetResult(&call, value);
  98. }
  99. static void bool_not_eval (NCDCall call, int negate, char const *name)
  100. {
  101. if (NCDCall_ArgCount(&call) != 1) {
  102. return FunctionLog(&call, BLOG_ERROR, "%s: need one argument", name);
  103. }
  104. NCDValRef arg = NCDCall_EvalArg(&call, 0, NCDCall_ResMem(&call));
  105. if (NCDVal_IsInvalid(arg)) {
  106. return;
  107. }
  108. int arg_val;
  109. if (!ncd_read_boolean(arg, &arg_val)) {
  110. return FunctionLog(&call, BLOG_ERROR, "%s: bad argument", name);
  111. }
  112. int res = (arg_val != negate);
  113. NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res, NCDCall_Iparams(&call)->string_index));
  114. }
  115. static void bool_eval (NCDCall call) { return bool_not_eval(call, 0, "bool"); }
  116. static void not_eval (NCDCall call) { return bool_not_eval(call, 1, "not"); }
  117. static void and_or_eval (NCDCall call, int is_and, char const *name)
  118. {
  119. size_t count = NCDCall_ArgCount(&call);
  120. int res = is_and;
  121. for (size_t i = 0; i < count; i++) {
  122. NCDValRef arg = NCDCall_EvalArg(&call, i, NCDCall_ResMem(&call));
  123. if (NCDVal_IsInvalid(arg)) {
  124. return;
  125. }
  126. int arg_val;
  127. if (!ncd_read_boolean(arg, &arg_val)) {
  128. return FunctionLog(&call, BLOG_ERROR, "%s: bad argument", name);
  129. }
  130. if (arg_val != is_and) {
  131. res = !is_and;
  132. break;
  133. }
  134. }
  135. NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res, NCDCall_Iparams(&call)->string_index));
  136. }
  137. static void and_eval (NCDCall call) { return and_or_eval(call, 1, "and"); }
  138. static void or_eval (NCDCall call) { return and_or_eval(call, 0, "or"); }
  139. static void imp_eval (NCDCall call)
  140. {
  141. if (NCDCall_ArgCount(&call) != 2) {
  142. return FunctionLog(&call, BLOG_ERROR, "imp: need two arguments");
  143. }
  144. int res = 0;
  145. for (size_t i = 0; i < 2; i++) {
  146. NCDValRef arg = NCDCall_EvalArg(&call, i, NCDCall_ResMem(&call));
  147. if (NCDVal_IsInvalid(arg)) {
  148. return;
  149. }
  150. int arg_val;
  151. if (!ncd_read_boolean(arg, &arg_val)) {
  152. return FunctionLog(&call, BLOG_ERROR, "imp: bad argument");
  153. }
  154. if (arg_val == i) {
  155. res = 1;
  156. break;
  157. }
  158. }
  159. NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res, NCDCall_Iparams(&call)->string_index));
  160. }
  161. // Value comparison functions.
  162. typedef int (*value_compare_func) (int cmp);
  163. static void value_compare_eval (NCDCall call, value_compare_func func)
  164. {
  165. if (NCDCall_ArgCount(&call) != 2) {
  166. return FunctionLog(&call, BLOG_ERROR, "value_compare: need two arguments");
  167. }
  168. NCDValRef vals[2];
  169. for (int i = 0; i < 2; i++) {
  170. vals[i] = NCDCall_EvalArg(&call, i, NCDCall_ResMem(&call));
  171. if (NCDVal_IsInvalid(vals[i])) {
  172. return;
  173. }
  174. }
  175. int res = func(NCDVal_Compare(vals[0], vals[1]));
  176. NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res, NCDCall_Iparams(&call)->string_index));
  177. }
  178. #define DEFINE_VALUE_COMPARE(name, expr) \
  179. static int value_compare_##name##_func (int cmp) { return expr; } \
  180. static void value_compare_##name##_eval (NCDCall call) { return value_compare_eval(call, value_compare_##name##_func); }
  181. DEFINE_VALUE_COMPARE(lesser, (cmp < 0))
  182. DEFINE_VALUE_COMPARE(greater, (cmp > 0))
  183. DEFINE_VALUE_COMPARE(lesser_equal, (cmp <= 0))
  184. DEFINE_VALUE_COMPARE(greater_equal, (cmp >= 0))
  185. DEFINE_VALUE_COMPARE(equal, (cmp == 0))
  186. DEFINE_VALUE_COMPARE(different, (cmp != 0))
  187. // Concatenation functions.
  188. static int concat_recurser (ExpString *estr, NCDValRef arg, NCDCall const *call)
  189. {
  190. if (NCDVal_IsString(arg)) {
  191. if (!ExpString_AppendBinaryMr(estr, NCDVal_StringMemRef(arg))) {
  192. FunctionLog(call, BLOG_ERROR, "ExpString_AppendBinaryMr failed");
  193. return 0;
  194. }
  195. } else if (NCDVal_IsList(arg)) {
  196. size_t count = NCDVal_ListCount(arg);
  197. for (size_t i = 0; i < count; i++) {
  198. if (!concat_recurser(estr, NCDVal_ListGet(arg, i), call)) {
  199. return 0;
  200. }
  201. }
  202. } else {
  203. FunctionLog(call, BLOG_ERROR, "concat: value is not a string or list");
  204. return 0;
  205. }
  206. return 1;
  207. }
  208. static void concat_eval (NCDCall call)
  209. {
  210. ExpString estr;
  211. if (!ExpString_Init(&estr)) {
  212. FunctionLog(&call, BLOG_ERROR, "ExpString_Init failed");
  213. goto fail0;
  214. }
  215. size_t count = NCDCall_ArgCount(&call);
  216. for (size_t i = 0; i < count; i++) {
  217. NCDValRef arg = NCDCall_EvalArg(&call, i, NCDCall_ResMem(&call));
  218. if (NCDVal_IsInvalid(arg)) {
  219. goto fail1;
  220. }
  221. if (!concat_recurser(&estr, arg, &call)) {
  222. goto fail1;
  223. }
  224. }
  225. NCDCall_SetResult(&call, NCDVal_NewStringBinMr(NCDCall_ResMem(&call), ExpString_GetMr(&estr)));
  226. fail1:
  227. ExpString_Free(&estr);
  228. fail0:
  229. return;
  230. }
  231. static void concatlist_eval (NCDCall call)
  232. {
  233. NCDValRef args_list;
  234. if (!ncd_eval_func_args(&call, NCDCall_ResMem(&call), &args_list)) {
  235. return;
  236. }
  237. size_t arg_count = NCDVal_ListCount(args_list);
  238. bsize_t elem_count = bsize_fromsize(0);
  239. for (size_t i = 0; i < arg_count; i++) {
  240. NCDValRef arg = NCDVal_ListGet(args_list, i);
  241. if (!NCDVal_IsList(arg)) {
  242. return FunctionLog(&call, BLOG_ERROR, "concatlist: argument is not a list");
  243. }
  244. elem_count = bsize_add(elem_count, bsize_fromsize(NCDVal_ListCount(arg)));
  245. }
  246. if (elem_count.is_overflow) {
  247. return FunctionLog(&call, BLOG_ERROR, "concatlist: count overflow");
  248. }
  249. NCDValRef res = NCDVal_NewList(NCDCall_ResMem(&call), elem_count.value);
  250. if (NCDVal_IsInvalid(res)) {
  251. return;
  252. }
  253. for (size_t i = 0; i < arg_count; i++) {
  254. NCDValRef arg = NCDVal_ListGet(args_list, i);
  255. size_t arg_list_count = NCDVal_ListCount(arg);
  256. for (size_t j = 0; j < arg_list_count; j++) {
  257. NCDValRef copy = NCDVal_NewCopy(NCDCall_ResMem(&call), NCDVal_ListGet(arg, j));
  258. if (NCDVal_IsInvalid(copy)) {
  259. return;
  260. }
  261. if (!NCDVal_ListAppend(res, copy)) {
  262. return;
  263. }
  264. }
  265. }
  266. NCDCall_SetResult(&call, res);
  267. }
  268. // Integer comparison functions.
  269. typedef int (*integer_compare_func) (uintmax_t n1, uintmax_t n2);
  270. static void integer_compare_eval (NCDCall call, integer_compare_func func)
  271. {
  272. if (NCDCall_ArgCount(&call) != 2) {
  273. return FunctionLog(&call, BLOG_ERROR, "integer_compare: need two arguments");
  274. }
  275. uintmax_t ints[2];
  276. for (int i = 0; i < 2; i++) {
  277. NCDValRef arg = NCDCall_EvalArg(&call, i, NCDCall_ResMem(&call));
  278. if (NCDVal_IsInvalid(arg)) {
  279. return;
  280. }
  281. if (!ncd_read_uintmax(arg, &ints[i])) {
  282. return FunctionLog(&call, BLOG_ERROR, "integer_compare: wrong value");
  283. }
  284. }
  285. int res = func(ints[0], ints[1]);
  286. NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res, NCDCall_Iparams(&call)->string_index));
  287. }
  288. #define DEFINE_INT_COMPARE(name, expr) \
  289. static int integer_compare_##name##_func (uintmax_t n1, uintmax_t n2) { return expr; } \
  290. static void integer_compare_##name##_eval (NCDCall call) { return integer_compare_eval(call, integer_compare_##name##_func); }
  291. DEFINE_INT_COMPARE(lesser, (n1 < n2))
  292. DEFINE_INT_COMPARE(greater, (n1 > n2))
  293. DEFINE_INT_COMPARE(lesser_equal, (n1 <= n2))
  294. DEFINE_INT_COMPARE(greater_equal, (n1 >= n2))
  295. DEFINE_INT_COMPARE(equal, (n1 == n2))
  296. DEFINE_INT_COMPARE(different, (n1 != n2))
  297. // Integer operators.
  298. typedef int (*integer_operator_func) (uintmax_t n1, uintmax_t n2, uintmax_t *out, NCDCall const *call);
  299. static void integer_operator_eval (NCDCall call, integer_operator_func func)
  300. {
  301. if (NCDCall_ArgCount(&call) != 2) {
  302. return FunctionLog(&call, BLOG_ERROR, "integer_operator: need two arguments");
  303. }
  304. uintmax_t ints[2];
  305. for (int i = 0; i < 2; i++) {
  306. NCDValRef arg = NCDCall_EvalArg(&call, i, NCDCall_ResMem(&call));
  307. if (NCDVal_IsInvalid(arg)) {
  308. return;
  309. }
  310. if (!ncd_read_uintmax(arg, &ints[i])) {
  311. return FunctionLog(&call, BLOG_ERROR, "integer_operator: wrong value");
  312. }
  313. }
  314. uintmax_t res;
  315. if (!func(ints[0], ints[1], &res, &call)) {
  316. return;
  317. }
  318. NCDCall_SetResult(&call, ncd_make_uintmax(NCDCall_ResMem(&call), res));
  319. }
  320. #define DEFINE_INT_OPERATOR(name, expr, check_expr, check_err_str) \
  321. static int integer_operator_##name##_func (uintmax_t n1, uintmax_t n2, uintmax_t *out, NCDCall const *call) \
  322. { \
  323. if (check_expr) { \
  324. FunctionLog(call, BLOG_ERROR, check_err_str); \
  325. return 0; \
  326. } \
  327. *out = expr; \
  328. return 1; \
  329. } \
  330. static void integer_operator_##name##_eval (NCDCall call) { return integer_operator_eval(call, integer_operator_##name##_func); }
  331. DEFINE_INT_OPERATOR(add, (n1 + n2), (n1 > UINTMAX_MAX - n2), "addition overflow")
  332. DEFINE_INT_OPERATOR(subtract, (n1 - n2), (n1 < n2), "subtraction underflow")
  333. DEFINE_INT_OPERATOR(multiply, (n1 * n2), (n2 != 0 && n1 > UINTMAX_MAX / n2), "multiplication overflow")
  334. DEFINE_INT_OPERATOR(divide, (n1 / n2), (n2 == 0), "division quotient is zero")
  335. DEFINE_INT_OPERATOR(modulo, (n1 % n2), (n2 == 0), "modulo modulus is zero")
  336. DEFINE_INT_OPERATOR(min, (n1 < n2 ? n1 : n2), (0), "")
  337. DEFINE_INT_OPERATOR(max, (n1 > n2 ? n1 : n2), (0), "")
  338. // Encode and decode value.
  339. static void encode_value_eval (NCDCall call)
  340. {
  341. if (NCDCall_ArgCount(&call) != 1) {
  342. return FunctionLog(&call, BLOG_ERROR, "encode_value: need one argument");
  343. }
  344. NCDValRef arg = NCDCall_EvalArg(&call, 0, NCDCall_ResMem(&call));
  345. if (NCDVal_IsInvalid(arg)) {
  346. return;
  347. }
  348. char *str = NCDValGenerator_Generate(arg);
  349. if (!str) {
  350. return FunctionLog(&call, BLOG_ERROR, "encode_value: NCDValGenerator_Generate failed");
  351. }
  352. NCDCall_SetResult(&call, NCDVal_NewString(NCDCall_ResMem(&call), str));
  353. free(str);
  354. }
  355. static void decode_value_eval (NCDCall call)
  356. {
  357. if (NCDCall_ArgCount(&call) != 1) {
  358. return FunctionLog(&call, BLOG_ERROR, "decode_value: need one argument");
  359. }
  360. // Evaluate the string to a temporary mem, not ResMem.
  361. // Otherwise the ResMem could get resized while we're
  362. // parsing a string within it, and boom.
  363. NCDValMem temp_mem;
  364. NCDValMem_Init(&temp_mem);
  365. NCDValRef arg = NCDCall_EvalArg(&call, 0, &temp_mem);
  366. if (NCDVal_IsInvalid(arg)) {
  367. goto fail1;
  368. }
  369. if (!NCDVal_IsString(arg)) {
  370. FunctionLog(&call, BLOG_ERROR, "decode_value: argument not a string");
  371. goto fail1;
  372. }
  373. NCDValRef value;
  374. int res = NCDValParser_Parse(NCDVal_StringMemRef(arg), NCDCall_ResMem(&call), &value);
  375. if (!res) {
  376. FunctionLog(&call, BLOG_ERROR, "decode_value: NCDValParser_Parse failed");
  377. goto fail1;
  378. }
  379. NCDCall_SetResult(&call, value);
  380. fail1:
  381. NCDValMem_Free(&temp_mem);
  382. }
  383. // ASCII case conversion
  384. typedef char (*perchar_func) (char ch);
  385. static void perchar_eval (NCDCall call, perchar_func func)
  386. {
  387. if (NCDCall_ArgCount(&call) != 1) {
  388. return FunctionLog(&call, BLOG_ERROR, "tolower: need one argument");
  389. }
  390. NCDValRef arg = NCDCall_EvalArg(&call, 0, NCDCall_ResMem(&call));
  391. if (NCDVal_IsInvalid(arg)) {
  392. return;
  393. }
  394. if (!NCDVal_IsString(arg)) {
  395. return FunctionLog(&call, BLOG_ERROR, "tolower: argument not a string");
  396. }
  397. NCDValRef value = NCDVal_NewStringUninitialized(NCDCall_ResMem(&call), NCDVal_StringLength(arg));
  398. if (NCDVal_IsInvalid(value)) {
  399. return;
  400. }
  401. char *out_data = (char *)NCDVal_StringData(value);
  402. MEMREF_LOOP_CHARS(NCDVal_StringMemRef(arg), i, ch, {
  403. out_data[i] = func(ch);
  404. })
  405. NCDCall_SetResult(&call, value);
  406. }
  407. #define DEFINE_PERCHAR(name, expr) \
  408. static char perchar_##name##_func (char ch) { return expr; } \
  409. static void perchar_##name##_eval (NCDCall call) { return perchar_eval(call, perchar_##name##_func); }
  410. DEFINE_PERCHAR(tolower, b_ascii_tolower(ch))
  411. DEFINE_PERCHAR(toupper, b_ascii_toupper(ch))
  412. static struct NCDModuleFunction const functions[] = {
  413. {
  414. .func_name = "error",
  415. .func_eval = error_eval
  416. }, {
  417. .func_name = "identity",
  418. .func_eval = identity_eval
  419. }, {
  420. .func_name = "if",
  421. .func_eval = if_eval
  422. }, {
  423. .func_name = "ifel",
  424. .func_eval = ifel_eval
  425. }, {
  426. .func_name = "bool",
  427. .func_eval = bool_eval
  428. }, {
  429. .func_name = "not",
  430. .func_eval = not_eval
  431. }, {
  432. .func_name = "and",
  433. .func_eval = and_eval
  434. }, {
  435. .func_name = "or",
  436. .func_eval = or_eval
  437. }, {
  438. .func_name = "imp",
  439. .func_eval = imp_eval
  440. }, {
  441. .func_name = "val_lesser",
  442. .func_eval = value_compare_lesser_eval
  443. }, {
  444. .func_name = "val_greater",
  445. .func_eval = value_compare_greater_eval
  446. }, {
  447. .func_name = "val_lesser_equal",
  448. .func_eval = value_compare_lesser_equal_eval
  449. }, {
  450. .func_name = "val_greater_equal",
  451. .func_eval = value_compare_greater_equal_eval
  452. }, {
  453. .func_name = "val_equal",
  454. .func_eval = value_compare_equal_eval
  455. }, {
  456. .func_name = "val_different",
  457. .func_eval = value_compare_different_eval
  458. }, {
  459. .func_name = "concat",
  460. .func_eval = concat_eval
  461. }, {
  462. .func_name = "concatlist",
  463. .func_eval = concatlist_eval
  464. }, {
  465. .func_name = "num_lesser",
  466. .func_eval = integer_compare_lesser_eval
  467. }, {
  468. .func_name = "num_greater",
  469. .func_eval = integer_compare_greater_eval
  470. }, {
  471. .func_name = "num_lesser_equal",
  472. .func_eval = integer_compare_lesser_equal_eval
  473. }, {
  474. .func_name = "num_greater_equal",
  475. .func_eval = integer_compare_greater_equal_eval
  476. }, {
  477. .func_name = "num_equal",
  478. .func_eval = integer_compare_equal_eval
  479. }, {
  480. .func_name = "num_different",
  481. .func_eval = integer_compare_different_eval
  482. }, {
  483. .func_name = "num_add",
  484. .func_eval = integer_operator_add_eval
  485. }, {
  486. .func_name = "num_subtract",
  487. .func_eval = integer_operator_subtract_eval
  488. }, {
  489. .func_name = "num_multiply",
  490. .func_eval = integer_operator_multiply_eval
  491. }, {
  492. .func_name = "num_divide",
  493. .func_eval = integer_operator_divide_eval
  494. }, {
  495. .func_name = "num_modulo",
  496. .func_eval = integer_operator_modulo_eval
  497. }, {
  498. .func_name = "num_min",
  499. .func_eval = integer_operator_min_eval
  500. }, {
  501. .func_name = "num_max",
  502. .func_eval = integer_operator_max_eval
  503. }, {
  504. .func_name = "encode_value",
  505. .func_eval = encode_value_eval
  506. }, {
  507. .func_name = "decode_value",
  508. .func_eval = decode_value_eval
  509. }, {
  510. .func_name = "tolower",
  511. .func_eval = perchar_tolower_eval
  512. }, {
  513. .func_name = "toupper",
  514. .func_eval = perchar_toupper_eval
  515. }, {
  516. .func_name = NULL
  517. }
  518. };
  519. const struct NCDModuleGroup ncdmodule_basic_functions = {
  520. .functions = functions
  521. };