DictList.m 914 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #import "qedefs.h"
  2. @implementation DictList
  3. //
  4. // Read in variable # of objects from FILE *
  5. //
  6. - initListFromFile:(FILE *)fp
  7. {
  8. id d;
  9. [super init];
  10. do
  11. {
  12. d = [(Dict *)[Dict alloc] initFromFile:fp];
  13. if (d != NULL)
  14. [self addObject:d];
  15. } while(d != NULL);
  16. [d free];
  17. return self;
  18. }
  19. //
  20. // Write out list file
  21. //
  22. - writeListFile:(char *)filename
  23. {
  24. FILE *fp;
  25. int i;
  26. id obj;
  27. fp = fopen(filename,"w+t");
  28. if (fp == NULL)
  29. return NULL;
  30. fprintf(fp,"// Object List written by QuakeEd\n");
  31. for (i = 0;i < maxElements;i++)
  32. {
  33. obj = [self objectAt:i];
  34. [obj writeBlockTo:fp];
  35. }
  36. fclose(fp);
  37. return self;
  38. }
  39. //
  40. // Find the keyword in all the Dict objects
  41. //
  42. - (id) findDictKeyword:(char *)key
  43. {
  44. int i;
  45. dict_t *d;
  46. id dict;
  47. for (i = 0;i < maxElements;i++)
  48. {
  49. dict = [self objectAt:i];
  50. d = [(Dict *)dict findKeyword:key];
  51. if (d != NULL)
  52. return dict;
  53. }
  54. return NULL;
  55. }
  56. @end