4
0

slang_chanlang.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_chanlang {
  19. struct slang_chanlang *next;
  20. char *chan;
  21. char *lang;
  22. };
  23. static struct slang_chanlang *chanlangs = NULL;
  24. static struct slang_chanlang *slang_chanlang_add(struct slang_chanlang *, char *, char *);
  25. //static int slang_chanlang_expmem(struct slang_chanlang *);
  26. static void slang_chanlang_free(struct slang_chanlang *);
  27. static char *slang_chanlang_get(struct slang_chanlang *, char *);
  28. static struct slang_chanlang *slang_chanlang_add(struct slang_chanlang *where, char *chan, char *lang)
  29. {
  30. struct slang_chanlang *item;
  31. for (item = where; item; item = item->next)
  32. if (!rfc_casecmp(item->chan, chan))
  33. break;
  34. if (!item) {
  35. item = nmalloc(sizeof(struct slang_chanlang));
  36. item->chan = nmalloc(strlen(chan) + 1);
  37. strcpy(item->chan, chan);
  38. item->lang = nmalloc(strlen(lang) + 1);
  39. strcpy(item->lang, lang);
  40. item->next = where;
  41. where = item;
  42. } else {
  43. Assert(item->lang);
  44. item->lang = nrealloc(item->lang, strlen(lang) + 1);
  45. strcpy(item->lang, lang);
  46. }
  47. return where;
  48. }
  49. /*
  50. static int slang_chanlang_expmem(struct slang_chanlang *what)
  51. {
  52. int size = 0;
  53. while (what) {
  54. Assert(what);
  55. Assert(what->chan);
  56. Assert(what->lang);
  57. size += sizeof(struct slang_chanlang);
  58. size += strlen(what->chan) + 1;
  59. size += strlen(what->lang) + 1;
  60. what = what->next;
  61. }
  62. return size;
  63. }
  64. */
  65. static void slang_chanlang_free(struct slang_chanlang *what)
  66. {
  67. struct slang_chanlang *next;
  68. while (what) {
  69. Assert(what);
  70. Assert(what->chan);
  71. Assert(what->lang);
  72. next = what->next;
  73. nfree(what->chan);
  74. nfree(what->lang);
  75. nfree(what);
  76. what = next;
  77. }
  78. }
  79. static char *slang_chanlang_get(struct slang_chanlang *where, char *chan)
  80. {
  81. while (where) {
  82. if (!rfc_casecmp(where->chan, chan))
  83. return where->lang;
  84. where = where->next;
  85. }
  86. return default_slang;
  87. }
  88. /* slang_getbynick():
  89. * tries to find an appropriate language for nick by searching
  90. * him on a channel and using the language of this channel.
  91. */
  92. static struct slang_header *slang_getbynick(struct slang_header *where, char *nick)
  93. {
  94. struct chanset_t *chan;
  95. #ifndef NO_EGG
  96. for (chan = chanset; chan; chan = chan->next)
  97. if (ismember(chan, nick))
  98. #if EGG_IS_MIN_VER(10500)
  99. return slang_find(where, slang_chanlang_get(chanlangs, chan->dname));
  100. #else
  101. return slang_find(where, slang_chanlang_get(chanlangs, chan->name));
  102. #endif
  103. #endif
  104. return slang_find(where, default_slang);
  105. }