modules.cc 20.2 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
/*
  This file is part of CDO. CDO is a collection of Operators to
  manipulate and analyse Climate model Data.

Uwe Schulzweida's avatar
Uwe Schulzweida committed
5
  Copyright (C) 2003-2019 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
6
7
8
9
10
11
12
13
14
15
16
17
  See COPYING file for copying and redistribution conditions.

  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
  the Free Software Foundation; version 2 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
*/

18
#include "modules.h"
19
#include "util_string.h"
20
#include "cdo_output.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
21

22
#include <cstring>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
23
#include <algorithm>  // for std::sort()
24
25

/* removes '-' from operator string and returns copy of parameter operatorCommand */
Oliver Heidmann's avatar
Oliver Heidmann committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/***
  vector for library handles for loaded custom modules
  */
std::vector<void *> custom_modules_lib_handles;

/***
  Maps operator names to their module names
 */
std::map<std::string, std::string> modules_map;

/***
  Contains added modules as values and their names as key
  */
std::map<std::string, module_t> modules;

/***
  Key: operator alias / Value: operator original name
 */
std::map<std::string, std::string> aliases;
45
static const char *
46
47
getOperatorName(const char *operatorCommand)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
48
  char *operatorName = nullptr;
49
50
51
52
53

  if (operatorCommand)
    {
      if (operatorCommand[0] == '-') operatorCommand++;
      const char *commapos = strchr(operatorCommand, ',');
54
      const size_t len = (commapos != nullptr) ? (size_t)(commapos - operatorCommand) : strlen(operatorCommand);
55
56
57

      operatorName = (char *) malloc(len + 1);

58
59
60
61
62
      if (operatorName != nullptr)
        {
          memcpy(operatorName, operatorCommand, len);
        }
      else{return nullptr;}
63
64
65
66
67
68
      operatorName[len] = '\0';
    }

  return operatorName;
}

69
70
71
72
73
74
75
76
/**
 * @param a pointer to a string/substring
 * @param b pointer to a string/substring
 * @param alen length of string a
 * @param blen lenght of string b
 * @retval true if a is similar to b
 * @retval false if a is not similar to b
 *
77
 * Recursive function for finding substrings of a operator name that match other operators.
78
 */
79
80
81
82
static bool
similar(const char *a, const char *b, unsigned long alen, unsigned long blen)
{
  if (alen > 2 && blen > 2 && strstr(b, a)) return true;
83

84
85
86
87
  while (*a && *b && *a == *b)
    {
      a++;
      b++;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
    }
89
90
91
92
  if (!*a && !*b) return true;
  /*
    printf("%d %d %s %s\n", alen, blen, a, b);
  */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
93
  if (alen >= 2 && blen >= 1 && *a && similar(a + 1, b, alen - 2, blen - 1)) return true;
94

Uwe Schulzweida's avatar
Uwe Schulzweida committed
95
  if (alen >= 1 && blen >= 2 && *b && similar(a, b + 1, alen - 1, blen - 2)) return true;
96

97
  return false;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
98
99
}

100
101
102
103
104
105
106
107
/**
 * @param original string tested for similarity to \p other
 * @param other string that \p original will be compared to
 * @retval true if original and other are similar
 * @retval false if not
 *
 * Wrapper function for #similar() to parse c++ strings to c strings
 */
108
109
110
static bool
similar(std::string original, std::string other)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
111
  return (similar(original.c_str(), other.c_str(), original.size(), other.size()));
112
}
113

114
115
116
117
118
/**
 * @param operatorName operator name
 * @retval true if #modules_map contains \p operatorName
 * @retval false if not
 */
119
static bool
120
operator_name_exists(const std::string &operatorName)
121
{
122
123
124
125
  if (modules_map.find(operatorName) != modules_map.end()) return true;

  if (aliases.find(operatorName) != aliases.end()) return true;

126
  return false;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
127
128
}

129
130
131
132
133
/**
 * @param moduleName module name
 * @retval true if #modules contains \a moduleName
 * @retval false if not
 */
134
/*
135
136
137
138
139
140
141
142
143
static bool
module_map_contains(std::string moduleName)
{
  if (modules.find(moduleName) != modules.end())
    {
      return true;
    }
  else
    {
144
      cdoAbort("Module %s not found", moduleName.c_str());
145
146
    }
  return false;
147
}
148
*/
149
150
151
152
153
154
/***
 * function for finding similar operator names for the given string
 * @param operatorName operator name to find similar operators for
 * @returns A string with all found names. The string is seqmented into lines
 * with a max lenght of 75 characters
 */
155
156
157
158
159
160
static std::string
find_similar(std::string operatorName)
{
  std::string found_similar_operators = "";
  unsigned long lines = 1;
  unsigned long line_length = 105;
161

162
163
164
  if (operatorName != "")
    {
      // Searching for simlar operator names in operator to module map
165
      for (const auto &str : modules_map)
166
        {
167
          if (similar(stringToLower(operatorName), str.first))
168
            {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
169
              if (found_similar_operators.size() + str.first.size() > lines * line_length)
170
171
172
                {
                  found_similar_operators += "\n";
                  lines++;
173
                }
174
175
              found_similar_operators += str.first;
              found_similar_operators += " ";
176
177
            }
        }
178
      // Searching for similar operator names in aliases to original map
179
      for (const auto &str : aliases)
180
        {
181
          if (similar(stringToLower(operatorName), str.first))
182
            {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
183
              if (found_similar_operators.size() + str.first.size() > lines * line_length)
184
185
186
                {
                  found_similar_operators += "\n";
                  lines++;
187
                }
188
189
              found_similar_operators += str.first;
              found_similar_operators += " ";
190
191
192
            }
        }
    }
193

194
  return found_similar_operators;
195
}
196

197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**
 * @param operatorName operator name.
 * @retval true if \p operatorName exists.
 * @retval false if \p operatorName is not in #modules_map
 *
 * Checks if given \p operatorName is in #modules_map. Else returns false.

 * Checks if \p operatorName is not a file.

 * If no matching operator is found checks for similar operators using
 find_similar().
 *
 *  \note If \p operatorName is a file name the program will exit.
 */
211
static bool
212
check_operator(const std::string &operatorName)
213
214
215
216
217
218
{
  if (operator_name_exists(operatorName))
    {
      return true;
    }
  else if (operatorName == "")
Uwe Schulzweida's avatar
Uwe Schulzweida committed
219
    {
220
      cdoAbort("Operator name missing!");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
221
    }
222
223
224
225
226
227
228
  else
    {
      // Checking if the operatorname is an existing file name
      FILE *fp = fopen(operatorName.c_str(), "r");
      if (fp)
        {
          fclose(fp);
229
          fprintf(stderr, "Use commandline option -h for help.\n");
230
          cdoAbort("Operator missing, %s is a file on disk!", operatorName.c_str());
231
        }
232
233
234
235
236
      // Operator is no filename
      // Checking for similar operators
      fprintf(stderr, "Operator >%s< not found!\n", operatorName.c_str());
      fprintf(stderr, "Similar operators are:\n");
      std::string found_similar_operators = find_similar(operatorName);
237

238
239
      if (found_similar_operators.size() > 0)
        {
240
          std::cerr << found_similar_operators << std::endl;
241
242
243
        }
      else
        {
244
245
          fprintf(stderr, "(not found)\n");
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
246

247
      exit(EXIT_FAILURE);
248
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
249

250
  return false;
251
}
252

Oliver Heidmann's avatar
Oliver Heidmann committed
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
void
registerOperatorsFromModules()
{
  for (auto &x : modules)
    {
      for (auto y : x.second.operators)
        {
          if (!operator_name_exists(y))
            {
              modules_map[y] = x.first;
            }
          else
            {
              cdoAbort("Tried to add operator but the operator name already exists");
            }
        }
    }
}

272
273
274
275
276
277
278
/***
 * Adds a module and its operators to cdo.
 * Adds the module to modules
 * Adds the operators of modules to modules_map
 * @param new_module newly constructed module
 * @note: if an error happens while adding the new module cdo will exit.
 */
279
void
280
add_module(const std::string &module_name, const module_t new_module)
281
282
283
284
{
  if (modules.find(module_name) == modules.end())
    {
      modules[module_name] = new_module;
285
      for (const std::string &operatorName : new_module.operators)
286
287
288
289
290
291
292
293
        {
          // if the operator name is not already in the map or in the aliases
          if (!operator_name_exists(operatorName))
            {
              modules_map[operatorName] = module_name;
            }
          else
            {
294
              cdoAbort("Tried to add operator but the operator name already exists");
295
296
            }
        }
297
298
299
    }
  else
    {
300
      cdoAbort("Module %s name already exists", module_name.c_str());
301
302
    }
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
303

304
/**
305
 * adds an key value pair to #modules_map with alias as key and originals name as value
306
307
308
 * @param alias new alias to be added
 * @param original original operator name
 */
309
int
310
add_alias(const std::string &alias, const std::string &original)
311
312
313
{
  auto iter_original = modules_map.find(original);
  auto iter_alias = aliases.find(alias);
314

315
316
  if (iter_alias != aliases.end())
    {
317
      printf("WARNING: alias %s could not be added: it already exists", alias.c_str());
318
      return -1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
319
320
    }

321
322
  if (iter_original == modules_map.end())
    {
323
      printf("ERROR: alias %s could not be added: operator %s does not exist", alias.c_str(), original.c_str());
324
      return -2;
325
    }
326

327
328
  if (modules_map.find(alias) != modules_map.end())
    {
329
330
      printf("ERROR alias %s could not be added: alias name already exists as an operator", alias.c_str());
      return -3;
331
    }
332

333
  aliases[alias] = original;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
334

335
  return 0;
336
337
338
339
340
341
342
343
344
345
}

/***
 * returns the module of given operator
 *
 * parameters:
 *      std::string operatorName -> name of the operator
 * return value:
 *      std::string -> name of the operators module
 */
346
static std::string
347
get_module_name_to(const std::string &operatorName)
348
349
350
351
352
353
354
355
356
357
358
{
  // if not true the programm will exit in function check_operator
  if (check_operator(operatorName))
    {
      if (modules_map.count(operatorName) > 0)
        {
          return modules_map[operatorName];
        }
      else if (aliases.count(operatorName) > 0)
        {
          return modules_map[aliases[operatorName]];
359
360
        }
    }
361
362
363
364
  else
    {
      // TODO: see if depricated since no operator can be added without a
      // module
365
      cdoAbort("Module for >%s< not installed", operatorName.c_str());
366
367
368
    }
  // Only to quell the warning. Function should never reach this.
  return "";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
369
370
}

371
372
373
374
375
/**
 * @fn void *(*operatorModule(const char *operatorName))(void *)

 * returns the function of the module of \a operatorName
 * @param operatorName name of the operator
376
 * @returns the function of the #module_t of \a operatorName
377
 */
378
/* not used
379
380
381
382
void *(*operatorModule(const char *operatorName))(void *)
{
  std::string operator_name = std::string(operatorName);
  return modules[get_module_name_to(operator_name)].func;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
383
}
384
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
385

386
387
388
389
390
391
/***
 * returns help for given operator name
 * if there is no help a empty vector will be returned
 * @param operatorName operator name
 * @return vector of strings containing the help
 */
392
std::vector<std::string>
393
operatorHelp(const std::string &operatorName)
394
{
395
  return modules[get_module_name_to(operatorName)].help;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
396
397
}

398
/***
399
400
401
402
403
 * Returns the number of input streams a operator takes.
 * returns -1 for a unlimited number of input streams.
 * @param operatorName operator name
 * @retval short
 */
404
/* not used
405
406
407
408
409
int
operatorStreamInCnt(const char *operatorName)
{
  std::string operator_name = std::string(operatorName);
  return modules[get_module_name_to(operator_name)].streamInCnt;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
410
}
411
*/
412
413
414
415
416
417
418
/***
 * Returns the number of output streams a given operator has.
 * returns -1 if obase is used
 * @param operatorName operator name
 * @return 1 for CDI_REAL, 2 for CDI_COMP (complex), 3 for CDI_REAL and CDI_COMP
 * @retval short
 */
419
/* not used
420
421
422
423
424
int
operatorStreamOutCnt(const char *operatorName)
{
  std::string operator_name = std::string(operatorName);
  return modules[get_module_name_to(operator_name)].streamOutCnt;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
425
}
426
*/
427
/***
428
429
430
431
 * Returns the number type this operator works with
 * @param operatorName operator name
 * @reval short
 */
432
433
434
435
436
int
operatorStreamNumber(const char *operatorName)
{
  std::string operator_name = std::string(operatorName);
  return modules[get_module_name_to(operator_name)].number;
437
438
439
}

/***
440
 * Creates a sorted vector with all operator names and alisases excluding all modules that are marked as internal
441
442
 * @return a sorted std::vector containing all operator names and aliases
 * excluding all operators which modules are marked as internal
443
 */
444
445
446
static std::vector<std::string>
get_sorted_operator_name_list()
{
447

448
  std::vector<std::string> names;
449
  for (const std::pair<std::string, std::string> &operator_module_names_pair : modules_map)
450
451
452
453
    {
      if (modules[operator_module_names_pair.second].mode == 1)
        {
          names.push_back(operator_module_names_pair.first);
454
455
        }
    }
456
  // adding operators names from alias_map
457
  for (const std::pair<std::string, std::string> &alias : aliases)
458
459
    {
      names.push_back(alias.first);
460
    }
461
  std::sort(names.begin(), names.end());
Uwe Schulzweida's avatar
Uwe Schulzweida committed
462

463
  return names;
464
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
465

466
467
std::vector<std::string>
get_no_output_operator_list()
468
{
469
  std::vector<std::string> names;
470
  for (const std::pair<std::string, std::string> &operator_module_names_pair : modules_map)
471
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
472
      if (modules[operator_module_names_pair.second].mode == 1 && modules[operator_module_names_pair.second].streamOutCnt == 0)
473
        {
474
          names.push_back(operator_module_names_pair.first);
475
476
        }
    }
477
478
  // adding operators names from alias_map
  std::string original;
479
  for (const std::pair<std::string, std::string> &alias : aliases)
480
481
    {
      original = alias.second;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
482
      if (modules[modules_map[original]].mode == 1 && modules[modules_map[original]].streamOutCnt == 0)
483
484
        {
          names.push_back(alias.first);
485
486
        }
    }
487
  std::sort(names.begin(), names.end());
Uwe Schulzweida's avatar
Uwe Schulzweida committed
488

489
  return names;
490
491
}

492
493
494
495
496
497
498
void
operatorPrintAll(void)
{
  int number_of_chars = 0;
  std::string tab = "   ";
  int tab_width = tab.size();
  // using a set because it sorts the operators alphabetically on its own
Uwe Schulzweida's avatar
Uwe Schulzweida committed
499
  std::vector<std::string> sorted_operator_names = get_sorted_operator_name_list();
500
501

  std::cout << tab;
502
  for (const auto &operatorName : sorted_operator_names)
503
504
505
506
507
    {
      if (number_of_chars > 85)
        {
          number_of_chars = tab_width;
          std::cerr << std::endl << tab;
508
509
        }

510
511
      std::cerr << " " << operatorName;
      number_of_chars += 1 + operatorName.size();
Uwe Schulzweida's avatar
Uwe Schulzweida committed
512
    }
513

514
  std::cerr << std::endl;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
515
}
516

517
518
519
520
521
#ifdef CUSTOM_MODULES
/***
  loads all custom modules in a specified folder
  @param folder_path custom modules folder
*/
522
523
524
525
526
527
void
load_custom_modules(std::string folder_path)
{
  DIR *dir = opendir(folder_path.c_str());
  std::string file_path;
  std::regex library_regex("(.*\\.so)");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
528
  if (dir != nullptr)
529
530
    {
      struct dirent *ent = readdir(dir);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
531
      while (ent != nullptr)
532
533
534
535
536
        {
          if (std::regex_match(ent->d_name, library_regex))
            {
              file_path = folder_path + "/" + ent->d_name;
              load_custom_module(file_path);
537
            }
538
          ent = readdir(dir);
539
        }
540
541
542
    }
  else
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
543
      std::cerr << "Could not find " << folder_path << "for loading custom modules" << std::endl;
544
545
546
547
548
549
550
551
552
    }
}

/***
 * Loads a custom module from given path.
 * Modules must contain a (TODO: rename function) init_custom_module function
 * Program exits if a module could not be loaded.
 * @param module file path
 */
553
554
555
556
557
558
559
560
561
562
void
load_custom_module(std::string file_path)
{
  void (*init_custom_module)();
  void *lib_handle = dlopen(file_path.c_str(), RTLD_LAZY);
  custom_modules_lib_handles.push_back(lib_handle);
  if (!lib_handle)
    {
      std::cerr << "Cannot open library: " << dlerror() << std::endl;
      return;
563
564
    }

565
566
567
  dlerror();
  init_custom_module = (void (*)()) dlsym(lib_handle, "init_custom_module");
  const char *dlsym_error = dlerror();
568

569
570
  if (dlsym_error)
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
571
      std::cerr << "Cannot load symbol 'init_custom_module': " << dlsym_error << std::endl;
572
573
      dlclose(lib_handle);
      return;
574
    }
575

576
577
  init_custom_module();
  std::cout << "loaded custom module from '" << file_path << "'" << std::endl;
578
}
579

580
581
582
/***
  closes the handles for the loaded custum modules
*/
583
584
585
586
587
588
void
close_library_handles()
{
  for (unsigned long i = 0; i < custom_modules_lib_handles.size(); i++)
    {
      dlclose(custom_modules_lib_handles[i]);
589
590
591
    }
}
#endif
592

593
// helper function for setting the spacing in operatorPrintList
594
595
static std::string
get_spacing_for(int p_space, const std::string &str)
596
597
{
  std::string spacing = "";
598
  for (int i = str.size(); i <= p_space; i++) spacing += " ";
599
  return spacing;
600
}
601

602
603
static std::string
get_operator_description(const std::string &p_current_op_name, const std::vector<std::string> &help)
604
{
605
606
607
608
609
610
611
612
613
614
615
616
617
618
  std::string description = "";
  unsigned long cur_help_idx;
  bool help_contains_name;
  std::string line;
  unsigned long operator_section = 0;

  cur_help_idx = 0;
  // search for operator section
  while (operator_section == 0 && cur_help_idx < help.size() - 1)
    {
      line = help[++cur_help_idx];
      if (line.find("OPERATORS") != std::string::npos)
        {
          operator_section = cur_help_idx;
619
620
        }
    }
621
622
623
624
625
626
627
628
629
630
631
632
633
634
  // if no operator section is found
  if (operator_section == 0)
    {
      cur_help_idx = 0;
      line = help[0];
      std::string name_section = help[0];
      help_contains_name = false;
      // search for the operator name in the description
      while (!line.empty())
        {
          line = help[++cur_help_idx];
          if (line.find(p_current_op_name) != std::string::npos)
            {
              help_contains_name = true;
635
            }
636
          name_section += line;
637
        }
638
639
640
      // if the name was found save description for later use
      if (help_contains_name)
        {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
641
          description = name_section.substr(name_section.find_first_of('-') + 2, name_section.size());
642
        }
643
644
645
    }
  else
    {
646

647
648
      line = help.at(++operator_section);
      // search the operator section for current operator line
Uwe Schulzweida's avatar
Uwe Schulzweida committed
649
      while (line.find(p_current_op_name + " ") == std::string::npos && !line.empty() && operator_section < help.size() - 1)
650
651
        {
          line = help.at(++operator_section);
652
        }
653
      // if operator line found save description for later use
Uwe Schulzweida's avatar
Uwe Schulzweida committed
654
      if (!line.empty() && line.find(p_current_op_name + " ") != std::string::npos)
655
656
        {
          auto op_name_start = line.find_first_not_of(" \t");
657

Uwe Schulzweida's avatar
Uwe Schulzweida committed
658
          description = line.substr(line.find_first_not_of(" \t", op_name_start + p_current_op_name.size()), line.size());
659
660
        }
    }
661
  return description;
662
}
663

664
665
666
667
668
669
670
/***
 * Prints all operator names and their short descriptions
 * Aliases are listed and point to their original operator name.
 * If the module is not documented the description is empty
 * If a module has only one operator the short module description is listed
 * If the operator is not documented the description is empty
 */
671
672
673
674
675
void
operatorPrintList(bool print_no_output)
{
  std::vector<std::string> output_list;
  if (print_no_output)
676
    {
677
      output_list = get_no_output_operator_list();
678
    }
679
  else
680
    {
681
      output_list = get_sorted_operator_name_list();
682
    }
683

684
685
  unsigned long list_length = output_list.size();
  module_t *current_module;
686

687
  // help variables
688

Uwe Schulzweida's avatar
Uwe Schulzweida committed
689
  for (unsigned long out_list_idx = 0; out_list_idx < list_length; out_list_idx++)
690
691
692
693
694
    {
      std::string current_op_name = output_list[out_list_idx];
      current_module = &modules[get_module_name_to(current_op_name)];
      if (aliases.find(current_op_name) != aliases.end())
        {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
695
          output_list[out_list_idx] += std::string(get_spacing_for(16, current_op_name) + "--> " + aliases[current_op_name]);
696
        }
697
698
699
      else if (!current_module->help.empty())
        {
          // add spaceing and saving output line to the output list
Uwe Schulzweida's avatar
Uwe Schulzweida committed
700
701
          std::string description = get_operator_description(current_op_name, current_module->help);
          output_list[out_list_idx] += get_spacing_for(16, current_op_name) + description;
702
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
703
704
      std::string in_out_info
          = "(" + std::to_string(current_module->streamInCnt) + "|" + std::to_string(current_module->streamOutCnt) + ")";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
705
      output_list[out_list_idx] += get_spacing_for(90, output_list[out_list_idx]) + in_out_info;
706
    }
707
  // print generated output list
708
  for (const std::string &str : output_list)
709
710
    {
      std::cout << str << std::endl;
711
    }
712
}
713

714
static bool
715
is_alias(const char *operatorName)
716
{
717
  return (aliases.find(std::string(operatorName)) != aliases.end());
718
719
}

720
721
const char *
get_original(const char *operatorName)
722
{
723
724
  const char *name = getOperatorName(operatorName);
  if (is_alias(name))
725
    {
726
727
      std::string opName = aliases[std::string(name)];
      char *original = (char *) malloc(opName.size() + 1);
728
      strcpy(original, opName.c_str());
729
      return original;
730
    }
731
  return name;
732
}
733

734
735
module_t &
getModule(const std::string &operator_name)
736
{
737
  return modules[get_module_name_to(operator_name)];
738
}