const para_mix_t mix_para_net[] = { MIX_PARA_NET(NULL, false, config_version, TYPE_U32, 0, 0, NULL, NULL), MIX_PARA_EXT_NET("DEFRULE", true, default_rule,input , TYPE_U8 | TYPE_ITEM, sizeof(filter_strategy) / 4, 0, filter_strategy, NULL), MIX_PARA_EXT_NET("DEFRULE", true, default_rule,forward , TYPE_U8 | TYPE_ITEM, sizeof(filter_strategy) / 4, 0, filter_strategy, NULL), MIX_PARA_EXT_NET("DEFRULE", true, default_rule,output , TYPE_U8 | TYPE_ITEM, sizeof(filter_strategy) / 4, 0, filter_strategy, NULL), MIX_PARA_EXT_NET("RINPUT1", true, input[0],action , TYPE_U8 | TYPE_ITEM, sizeof(filter_strategy) / 4, 0, filter_strategy, NULL), MIX_PARA_EXT_NET("RINPUT1", true, input[0],protol , TYPE_U8 | TYPE_ITEM, sizeof(filter_type) / 4, 0, filter_type, NULL), MIX_PARA_STR_NET("RINPUT1", true, input[0], src_addr), MIX_PARA_EXT_NET("RINPUT1", true, input[0], src_port, TYPE_U16, 0, 65535, NULL, NULL), MIX_PARA_STR_NET("RINPUT1", true, input[0], dest_addr), MIX_PARA_EXT_NET("RINPUT1", true, input[0], dest_port, TYPE_U16, 0, 65535, NULL, NULL), MIX_PARA_EXT_NET("RINPUT2", true, input[0],action , TYPE_U8 | TYPE_ITEM, sizeof(filter_strategy) / 4, 0, filter_strategy, NULL), MIX_PARA_EXT_NET("RINPUT2", true, input[0],protol , TYPE_U8 | TYPE_ITEM, sizeof(filter_type) / 4, 0, filter_type, NULL), MIX_PARA_STR_NET("RINPUT2", true, input[0], src_addr), MIX_PARA_EXT_NET("RINPUT2", true, input[0], src_port, TYPE_U16, 0, 65535, NULL, NULL), MIX_PARA_STR_NET("RINPUT2", true, input[0], dest_addr), MIX_PARA_EXT_NET("RINPUT2", true, input[0], dest_port, TYPE_U16, 0, 65535, NULL, NULL), };能将后面两个优化为1个吗?使用类似循环的方式
时间: 2024-03-27 08:40:25 浏览: 127
Test_aconst_null.rar_aconst_null_back
可以使用循环的方式将后面两个参数优化为一个。具体实现方法如下:
```
int input_num = 2; // 输入的个数
char input_name[2][16] = {"RINPUT1", "RINPUT2"}; // 每个输入的名称
para_mix_t input_para[2][5] = {
{
MIX_PARA_EXT_NET("RINPUT1", true, input[0], action, TYPE_U8 | TYPE_ITEM, sizeof(filter_strategy) / 4, 0, filter_strategy, NULL),
MIX_PARA_EXT_NET("RINPUT1", true, input[0], protol, TYPE_U8 | TYPE_ITEM, sizeof(filter_type) / 4, 0, filter_type, NULL),
MIX_PARA_STR_NET("RINPUT1", true, input[0], src_addr),
MIX_PARA_EXT_NET("RINPUT1", true, input[0], src_port, TYPE_U16, 0, 65535, NULL, NULL),
MIX_PARA_STR_NET("RINPUT1", true, input[0], dest_addr),
MIX_PARA_EXT_NET("RINPUT1", true, input[0], dest_port, TYPE_U16, 0, 65535, NULL, NULL)
},
{
MIX_PARA_EXT_NET("RINPUT2", true, input[0], action, TYPE_U8 | TYPE_ITEM, sizeof(filter_strategy) / 4, 0, filter_strategy, NULL),
MIX_PARA_EXT_NET("RINPUT2", true, input[0], protol, TYPE_U8 | TYPE_ITEM, sizeof(filter_type) / 4, 0, filter_type, NULL),
MIX_PARA_STR_NET("RINPUT2", true, input[0], src_addr),
MIX_PARA_EXT_NET("RINPUT2", true, input[0], src_port, TYPE_U16, 0, 65535, NULL, NULL),
MIX_PARA_STR_NET("RINPUT2", true, input[0], dest_addr),
MIX_PARA_EXT_NET("RINPUT2", true, input[0], dest_port, TYPE_U16, 0, 65535, NULL, NULL)
}
};
para_mix_t mix_para_net[] = {
MIX_PARA_NET(NULL, false, config_version, TYPE_U32, 0, 0, NULL, NULL),
MIX_PARA_EXT_NET("DEFRULE", true, default_rule, input, TYPE_U8 | TYPE_ITEM, sizeof(filter_strategy) / 4, 0, filter_strategy, NULL),
MIX_PARA_EXT_NET("DEFRULE", true, default_rule, forward, TYPE_U8 | TYPE_ITEM, sizeof(filter_strategy) / 4, 0, filter_strategy, NULL),
MIX_PARA_EXT_NET("DEFRULE", true, default_rule, output, TYPE_U8 | TYPE_ITEM, sizeof(filter_strategy) / 4, 0, filter_strategy, NULL)
};
for (int i = 0; i < input_num; i++) {
for (int j = 0; j < 6; j++) {
mix_para_net[3 + i * 6 + j] = input_para[i][j];
mix_para_net[3 + i * 6 + j].name = input_name[i];
}
}
```
这样就可以用循环的方式将后面两个参数优化为一个,同时也保证了每个参数的正确性。
阅读全文