list.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #define _GNU_SOURCE 1
  2. #include <stdio.h>
  3. #include <stdlib.h> // malloc/calloc
  4. #include <stdbool.h>
  5. #include <regex.h>
  6. #include <string.h>
  7. #include <assert.h>
  8. #define MAX_VARIABLE_NAME 16
  9. #define MAX_LINE_LENGTH 128
  10. #define VARIABLE_BASE_LENGTH 6
  11. //struct declarations
  12. //2 dimensional nodes
  13. // aka node1 -> node2 -> node3 -> node4 -> etc.
  14. // || || || ||
  15. // \/ \/ \/ \/
  16. // node1 node2 node2 node3
  17. typedef struct d2node * d2nodeptr;
  18. typedef struct d2node {
  19. bool multiple_variables;
  20. struct d2node * right; // the next node
  21. struct d2node * left;
  22. struct d2node * bottom; // this is the start of another linear list. Each item in the list contains a reference to the variable name
  23. struct d2node * top; //this is how one can crawl back up the 2 dimensional node
  24. char variable_name [MAX_VARIABLE_NAME];
  25. } d2node;
  26. /* technically this is just lazy code. but who cares? */
  27. void * xmalloc (size_t size);
  28. d2nodeptr allocate_new_d2node ();
  29. /* this returns the address of the first created
  30. d2node.
  31. */
  32. d2nodeptr address_of_first_d2node (d2nodeptr nodep);
  33. /* Returns the start of the variable name
  34. ** input: "int purple = 5;"
  35. ** return: pointer to ^
  36. */
  37. // this function could probably be replace by a regex
  38. //THIS function is also NOT working. So that's annoying
  39. //It also causes length_of_varable name to not work either
  40. char * start_of_variable_name (char * line);
  41. /* Returns the end of the variable name
  42. ** input: "int purple = 5;"
  43. ** return: pointer to ^
  44. */
  45. char * end_of_variable_name (char * line);
  46. int length_of_variable_name (char * start, char * end);
  47. /* This function checks the string against our common
  48. * variable name bases. If we have seen this variable's
  49. * base name (the first 6 letters) before, then we
  50. * return the pointer to the beginning of the column
  51. * where it exists
  52. * ie: if variable name is purple_7 and the 2 dimensional
  53. * nodes look like
  54. * blacke => greens => purple
  55. * || || ||
  56. * \/ \/ \/
  57. * blacke_s greens_a purple_1
  58. *
  59. * then this function will return the d2nodeptr to the
  60. * "purple" node
  61. **/
  62. d2nodeptr is_this_variable_base_unique (char * string);
  63. /* */
  64. void add_new_variable_base (char * string, int length);
  65. /*
  66. * this function should be called after is_this_variable_base_unique
  67. * this function checks the current
  68. *
  69. */
  70. d2nodeptr is_this_a_new_variable (char * string, int length);
  71. void store_c_file_common_variables (FILE * input_file_stream);
  72. void print_common_base_name_variables ();
  73. /*
  74. ** This function should be called after, store_c_file_common_variables
  75. **
  76. ** It prints all the variable names in the 2deminsional datastructure.
  77. **
  78. ** It is a naive implementation. nodep ends up pointing at the end of the
  79. ** datastructure. So you cannot call this function twice
  80. **
  81. ** THE PROBLEM IS HERE. FIXME! The store variables datastrure is storing data
  82. ** fine. BUT THIS function is NOT PRINTING THEM!
  83. **
  84. */
  85. void print_c_file_common_variables ();