thesaurus.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include "dict.h"
  5. void
  6. thesprintentry(Entry e, int cmd)
  7. {
  8. char *p, *pe;
  9. int c, i;
  10. p = e.start;
  11. pe = e.end;
  12. while(p < pe) {
  13. c = *p++;
  14. if(cmd == 'r') {
  15. outchar(c);
  16. continue;
  17. }
  18. switch(c) {
  19. case '*':
  20. c = *p++;
  21. if(cmd == 'h' && c != 'L') {
  22. outnl(0);
  23. return;
  24. }
  25. if(c == 'L' && cmd != 'h')
  26. outnl(0);
  27. if(c == 'S') {
  28. outchar('(');
  29. outchar(*p++);
  30. outchar(')');
  31. }
  32. break;
  33. case '#':
  34. c = *p++;
  35. i = *p++ - '0' - 1;
  36. if(i < 0 || i > 4)
  37. break;
  38. switch(c) {
  39. case 'a': outrune(L"áàâäa"[i]); break;
  40. case 'e': outrune(L"éèêëe"[i]); break;
  41. case 'o': outrune(L"óòôöo"[i]); break;
  42. case 'c': outrune(L"ccccç"[i]); break;
  43. default: outchar(c); break;
  44. }
  45. break;
  46. case '+':
  47. case '<':
  48. break;
  49. case ' ':
  50. if(cmd == 'h' && *p == '*') {
  51. outnl(0);
  52. return;
  53. }
  54. default:
  55. outchar(c);
  56. }
  57. }
  58. outnl(0);
  59. }
  60. long
  61. thesnextoff(long fromoff)
  62. {
  63. long a;
  64. char *p;
  65. a = Bseek(bdict, fromoff, 0);
  66. if(a < 0)
  67. return -1;
  68. for(;;) {
  69. p = Brdline(bdict, '\n');
  70. if(!p)
  71. break;
  72. if(p[0] == '*' && p[1] == 'L')
  73. return (Boffset(bdict)-Blinelen(bdict));
  74. }
  75. return -1;
  76. }
  77. void
  78. thesprintkey(void)
  79. {
  80. Bprint(bout, "No key\n");
  81. }