PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/API/c_api_v1/functions.h

https://github.com/sapandiwakar/Multilanguage-Transliteration
C Header | 207 lines | 61 code | 75 blank | 71 comment | 0 complexity | d566d05b2acce831cf36e591b6f63b75 MD5 | raw file
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <regex.h>
  4. #include <glib-2.0/glib.h>
  5. #include <stdlib.h>
  6. #include "structures.h"
  7. node * create_tree();
  8. /*returns the root node pointer of the new tree*/
  9. node * create_node (node *parent);
  10. /*returns the node pointer created*/
  11. node * create_node_with_attr(char tkn[], char tag[], char fs[], node *parent);
  12. /*creates a node with attributes mentioned and returns its pointer*/
  13. or_node * create_or_node ();
  14. /*creates a new or_node and returns its pointer*/
  15. fs_struct *create_fs_struct();
  16. /*creates a new fs_struct and returns its pointer*/
  17. void int_to_str(int num,char *str);
  18. /*converts the integer num to a string str*/
  19. void read_ssf_from_file (node *tree, char filename[]);
  20. /*reads the from file into node tree. */
  21. void read_ssf(node *tree, FILE *f);
  22. /*reads the SSF from the file specified by f*/
  23. or_node * read_or_node( char str[]);
  24. /* Builts the or_node form string str and returns it */
  25. fs_struct *read_fs( char str[]);
  26. /* Builts the fs_struct from string str and returns it */
  27. char * make_or_node_to_string ( or_node *OR);
  28. /*convert or_node OR to string format and returns the string */
  29. char *make_fs_struct_to_string ( fs_struct *fs);
  30. /*convert fs_struct fs to string format and returns the string */
  31. char *get_fields (node *N );
  32. /* Gives all the fields in string format and returns the string */
  33. void print_tree_to_file( node *tree, char file[]);
  34. /*Prints the node "tree" in SSF format with index starting from 1 to the file*/
  35. void print_tree_to_fileptr(node *tree, FILE *f);
  36. /*prints the tree to fileptr*/
  37. void print_tree(node *tree);
  38. /*Prints the node "tree" in SSF format with index starting from 1*/
  39. void print_node_without_index(node *N);
  40. /*prints the node "N" without index*/
  41. void print_node(node *tree ,char ind[]);
  42. /*Prints the node "tree" in ssf format with index starting from ind */
  43. void print_node_to_file(node *tree ,char ind[], FILE *f);
  44. /*Prints the node "tree" in ssf format with index starting from ind to the file pointed by f*/
  45. void print_attr_of_node(node *N);
  46. /*Prints the attributes of node "N" */
  47. void print_attr_of_or_node(or_node *OR);
  48. /*Prints the attributes of OR node */
  49. int insert_node_into_position(node *parent, node *child, int position);
  50. /*inserts the child at the given position.
  51. *If posistion > (parent->child_count) it will insert be inserted at the end*/
  52. char *get_field(node *N, int n );
  53. /*Gives a nth field of a given node.*/
  54. node *get_nth_child(node *N, int n);
  55. /*returns the nth child of the node N*/
  56. node *get_next_node(node *N);
  57. /*Returns next sibling of a given node.*/
  58. node *get_parent(node *N);
  59. /*Returns parent of a given node.*/
  60. node *get_previous_node(node *N);
  61. /*Returns previous sibling of a given node.*/
  62. int modify_field(node *N, int number,char str[]);
  63. /*Modifies a particular field of a given node.
  64. *returns 1 on success and 0 on failure
  65. *You can also modify or_node here */
  66. int delete_node(node *N);
  67. /*returns 1 on succefull delition else 0 */
  68. list_of_nodes * create_list_of_nodes(int size);
  69. /* creates list of nodes and returns its pointer*/
  70. list_of_or_nodes * create_list_of_or_nodes(int size);
  71. /* creates list of or_nodes*/
  72. list_of_fs_structs *create_list_of_fs_structs(int size);
  73. /*creates list of fs structures */
  74. int match(const char *string, char *pattern);
  75. /*returns 1 if pattern matches string else 0 */
  76. list_of_nodes *make_list_of_nodes_from_glist(GList *L);
  77. /*Creates list of nodes from list L */
  78. list_of_nodes *getchildren( node *Node );
  79. /*returns a lsit containing childrens of this node */
  80. GList *tmp_getleaves(node *Node, GList *L);
  81. /*gets leaves to List L...Internal function....users can ignore*/
  82. list_of_nodes *getleaves (node *Node);
  83. /*gets all leaves of this node and returns a list_of_nodes containing leaves */
  84. int tmp_count_leaf_nodes(node *tree, int sum);
  85. /*a recursive function used by count)leaf_nodes */
  86. int count_leaf_nodes(node *tree);
  87. /*Counts the number of leaf nodes of the node "tree" */
  88. list_of_nodes *getleaves_child (node *Node );
  89. /*gets the childs which are also the leaves of the node*/
  90. GList *tmp_get_nodes(int num, char str[], node *tree, GList *L) ;
  91. /* internal function to get a list of nodes with particular field value
  92. *Note:implemented using Depth first search*/
  93. list_of_nodes *get_nodes(int fieldnumber, char str[], node *tree);
  94. /*gets nodes which have particular field values in a tree/sub tree
  95. *--Note Feature structure is "NOT INCLUDED" here*/
  96. GList *tmp_get_pattern (int num, char pattern[], node *tree, GList *L);
  97. /*recusive function used by get_pattern. Returns a list of nodes with specified field matching the pattern*/
  98. list_of_nodes *get_pattern(int fieldnumber, char pattern[], node *tree);
  99. /*gets nodes of the node "tree" with the specified field matching the pattern
  100. *--Note Feature structure is "INCLUDED" here*/
  101. /*Note: For the below functions
  102. *attribute "af" case is not specially handled.
  103. *To do operations that include the attr "af" the user should deal with indvidual attributes that are encoded in "af"*/
  104. int add_attr_val(or_node *OR, char attr[], char value[]);
  105. /*Inserts attr values in all the fs's present in or_node
  106. *if any fs is already having attr then it is updated.
  107. *Returns 0 on failure and 1 on success.*/
  108. int add_attr_val_2(fs_struct *fs, char attr[], char value[]);
  109. /*This inserts attr in a particular fs
  110. *If fs already contains attr, then 0 (error) is returned.
  111. *Else attr is inserted & 1 is returned.*/
  112. int update_attr_val(or_node *OR, char attr[], char value[]);
  113. /*This updates the "attr" in all the fs's of the or_node "OR" which contains the key "attr"*/
  114. int update_attr_val_2(fs_struct *fs, char attr[], char value[]);
  115. /*update attr value in the fs.
  116. *If fs does not contain attr 0 is returned.*/
  117. int del_attr(or_node *OR, char attr[]);
  118. /*Deletes attr from all the fs's of or_node*/
  119. int delete_attr_2(fs_struct *fs, char attr[]);
  120. /*Deletes attr from fs_struct.
  121. *if no key with attr is found 0 is returned. */
  122. char *get_attr_val(fs_struct *fs, char attr[]);
  123. /* Get the attr value */
  124. GList * tmp_get_nodes_with_attr_val(node *N, char attr[], char val[], GList *tmp);
  125. /*a recursive call used by get_nodes_with_attr_val().
  126. Returns a list of nodes satisfying the condition*/
  127. list_of_nodes *get_nodes_with_attr_val(node *N, char attr[], char val[]);
  128. /*get a list of nodes with or_node (fs) attrs equal to val */
  129. void delete_fs_struct_from_or_node(or_node *OR, int n);
  130. /* Deletes nth fs from or_node */
  131. void add_fs_struct_to_or_node (or_node *OR, fs_struct *fs);
  132. /* add the fs_struct fs to or_node */