helpsys.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* $Id$
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1996 Greg Janson
  5. * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. // internal help system
  22. #include "mod.h"
  23. #include "cursor.h"
  24. #include <string.h>
  25. #include "scrdisp.h"
  26. #include <stdio.h>
  27. #include "meminter.h"
  28. #include "beep.h"
  29. #include "helpsys.h"
  30. #include "data.h"
  31. int context=72;//72="No" context link
  32. unsigned char far *help=NULL;
  33. int contexts[20];
  34. int curr_context=0;
  35. void set_context(int con) {
  36. contexts[curr_context++]=context;
  37. context=con;
  38. }
  39. void pop_context(void) {
  40. context=contexts[--curr_context];
  41. }
  42. void help_system(void) {
  43. FILE *fp;
  44. unsigned int t1,t2;
  45. unsigned char old_cmode=cursor_mode;
  46. long where;
  47. long offs;
  48. long size;
  49. char file[13];
  50. char file2[13];
  51. char label[20];
  52. //Reserve memory (24k)
  53. help=(char far *)farmalloc(24576);
  54. if(help==NULL) {
  55. //Try to free up mem
  56. free_sam_cache(1);
  57. help=(char far *)farmalloc(24576);
  58. if(help==NULL) {
  59. beep();
  60. return;
  61. }
  62. }
  63. //Search context links
  64. fp=fopen(help_file,"rb");
  65. if(fp==NULL) {
  66. beep();
  67. farfree(help);
  68. return;
  69. }
  70. fread(&t1,1,2,fp);
  71. fseek(fp,t1*21+4+context*12,SEEK_SET);
  72. //At proper context info
  73. fread(&where,1,4,fp);//Where file to load is
  74. fread(&size,1,4,fp);//Size of file to load
  75. fread(&offs,1,4,fp);//Offset within file of link
  76. //Jump to file
  77. fseek(fp,where,SEEK_SET);
  78. //Read it in
  79. fread(help,1,size,fp);
  80. //Display it
  81. cursor_off();
  82. labelled:
  83. help_display(help,offs,file,label);
  84. //File?
  85. if(file[0]) {
  86. //Yep. Search for file.
  87. fseek(fp,2,SEEK_SET);
  88. for(t2=0;t2<t1;t2++) {
  89. fread(file2,1,13,fp);
  90. if(!_fstricmp(file,file2)) break;
  91. fseek(fp,8,SEEK_CUR);
  92. }
  93. if(t2<t1) {
  94. //Found file.
  95. fread(&where,1,4,fp);
  96. fread(&size,1,4,fp);
  97. fseek(fp,where,SEEK_SET);
  98. fread(help,1,size,fp);
  99. //Search for label
  100. for(t2=0;t2<size;t2++) {
  101. if(help[t2]!=255) continue;
  102. if(help[t2+1]!=':') continue;
  103. if(!_fstricmp(&help[t2+3],label)) break;//Found label!
  104. }
  105. if(t2<size) {
  106. //Found label. t2 is offset.
  107. offs=t2;
  108. goto labelled;
  109. }
  110. }
  111. }
  112. //All done!
  113. fclose(fp);
  114. farfree(help);
  115. if(old_cmode==CURSOR_UNDERLINE) cursor_underline();
  116. else if(old_cmode==CURSOR_BLOCK) cursor_solid();
  117. }