4
0

slang_facts.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2000,2001 Florian Sander
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. struct slang_facts {
  19. struct slang_facts *next;
  20. int sorting;
  21. struct slang_facts_place *places;
  22. };
  23. static struct slang_facts *slang_facts_add(struct slang_facts *, int, int, char *);
  24. //static int slang_facts_expmem(struct slang_facts *);
  25. static void slang_facts_free(struct slang_facts *);
  26. static int slang_facts_selectfirst(struct slang_facts *);
  27. static int slang_facts_selectnext();
  28. //static char *slang_facts_getfirst();
  29. //static char *slang_facts_getnext();
  30. static char *slang_facts_get(int);
  31. static struct slang_facts *slang_facts_add(struct slang_facts *where, int sorting, int place, char *text)
  32. {
  33. struct slang_facts *newitem, *target;
  34. newitem = NULL;
  35. if (where) {
  36. for (newitem = where; newitem; newitem = newitem->next)
  37. if (newitem->sorting == sorting)
  38. break;
  39. }
  40. if (!newitem) {
  41. newitem = nmalloc(sizeof(struct slang_facts));
  42. newitem->next = NULL;
  43. newitem->sorting = sorting;
  44. newitem->places = NULL;
  45. for (target = where; target && target->next; target = target->next);
  46. if (target)
  47. target->next = newitem;
  48. else
  49. where = newitem;
  50. }
  51. newitem->places = slang_facts_place_add(newitem->places, place, text);
  52. return where;
  53. }
  54. /*static int slang_facts_expmem(struct slang_facts *what)
  55. {
  56. int size = 0;
  57. for (; what; what = what->next) {
  58. size += sizeof(struct slang_facts);
  59. size += slang_facts_place_expmem(what->places);
  60. }
  61. return size;
  62. }*/
  63. static void slang_facts_free(struct slang_facts *what)
  64. {
  65. struct slang_facts *next;
  66. while (what) {
  67. next = what->next;
  68. slang_facts_place_free(what->places);
  69. nfree(what);
  70. what = next;
  71. }
  72. }
  73. static struct slang_facts *glob_fact;
  74. static int slang_facts_selectfirst(struct slang_facts *what)
  75. {
  76. int itype, pitype;
  77. locstats *ls;
  78. if (!glob_globstats)
  79. return 0;
  80. if (!glob_globstats->local)
  81. return 0;
  82. for (glob_fact = what; glob_fact; glob_fact = glob_fact->next) {
  83. sortstats(glob_globstats, glob_fact->sorting, S_DAILY);
  84. itype = glob_fact->sorting;
  85. glob_sorting = itype;
  86. if (itype >= 0) {
  87. if (!glob_globstats->slocal[S_TODAY][itype]->values[S_TODAY][itype])
  88. continue;
  89. } else {
  90. pitype = (itype * -1) + (TOTAL_TYPES - 1);
  91. ls = glob_globstats->slocal[S_TODAY][pitype];
  92. if ((itype == T_WPL) && (!ls->values[S_DAILY][T_WORDS]
  93. || !ls->values[S_DAILY][T_LINES]))
  94. continue;
  95. else if ((itype == T_IDLE) && (!ls->values[S_DAILY][T_MINUTES]
  96. || !ls->values[S_DAILY][T_LINES]))
  97. continue;
  98. else if ((itype == T_VOCABLES) && !ls->vocables)
  99. continue;
  100. }
  101. return 1;
  102. }
  103. return 0;
  104. }
  105. static int slang_facts_selectnext()
  106. {
  107. int itype, pitype;
  108. locstats *ls;
  109. if (!glob_fact)
  110. return 0;
  111. for (glob_fact = glob_fact->next; glob_fact; glob_fact = glob_fact->next) {
  112. sortstats(glob_globstats, glob_fact->sorting, S_DAILY);
  113. itype = glob_fact->sorting;
  114. glob_sorting = itype;
  115. if (itype >= 0) {
  116. if (!glob_globstats->slocal[S_TODAY][itype]->values[S_TODAY][itype])
  117. continue;
  118. } else {
  119. pitype = (itype * -1) + (TOTAL_TYPES - 1);
  120. ls = glob_globstats->slocal[S_TODAY][pitype];
  121. if ((itype == T_WPL) && (!ls->values[S_DAILY][T_WORDS]
  122. || !ls->values[S_DAILY][T_LINES]))
  123. continue;
  124. else if ((itype == T_IDLE) && (!ls->values[S_DAILY][T_MINUTES]
  125. || !ls->values[S_DAILY][T_LINES]))
  126. continue;
  127. else if ((itype == T_VOCABLES) && !ls->vocables)
  128. continue;
  129. }
  130. return 1;
  131. }
  132. return 0;
  133. }
  134. /*
  135. static char *slang_facts_getfirst()
  136. {
  137. Assert(glob_fact);
  138. return slang_facts_place_getfirst(glob_fact->places);
  139. }
  140. static char *slang_facts_getnext()
  141. {
  142. return slang_facts_place_getnext();
  143. }
  144. */
  145. static char *slang_facts_get(int place)
  146. {
  147. return slang_facts_place_get(glob_fact->places, glob_fact->sorting, place);
  148. }