filesxx.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Hey EMACS -*- linux-c -*- */
  2. /* $Id: filesxx.c 3227 2007-02-26 19:40:27Z roms $ */
  3. /* libtifiles - file format library, a part of the TiLP project
  4. * Copyright (C) 1999-2006 Romain Liévin
  5. * Copyright (C) 2007 Kevin Kofler
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (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
  15. * GNU 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. /*
  22. This unit contains a TI file independant API
  23. */
  24. #include <assert.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <time.h>
  29. #include "tifiles.h"
  30. #include "error.h"
  31. #include "files9x.h"
  32. #define tifiles_calc_is_ti9x(model) 1
  33. /**
  34. * tifiles_content_create_flash:
  35. * @model: a calculator model (compulsory).
  36. *
  37. * Allocates a #FlashContent structure.
  38. *
  39. * Return value: the allocated block.
  40. **/
  41. TIEXPORT2 FlashContent* TICALL tifiles_content_create_flash(CalcModel model)
  42. {
  43. FlashContent* content = calloc(1, sizeof(FlashContent));
  44. content->model = model;
  45. if(tifiles_calc_is_ti9x(content->model))
  46. {
  47. time_t tt;
  48. struct tm *lt;
  49. time(&tt);
  50. lt = localtime(&tt);
  51. content->revision_major = 1;
  52. content->revision_minor = 0;
  53. content->flags = 0;
  54. content->object_type = 0;
  55. content->revision_day = lt->tm_mday;
  56. content->revision_month = lt->tm_mon;
  57. content->revision_year = lt->tm_year + 1900;
  58. }
  59. return content;
  60. }
  61. /**
  62. * tifiles_content_delete_flash:
  63. *
  64. * Free the whole content of a #FlashContent structure.
  65. *
  66. * Return value: none.
  67. **/
  68. TIEXPORT2 int TICALL tifiles_content_delete_flash(FlashContent *content)
  69. {
  70. int i;
  71. assert(content != NULL);
  72. {
  73. FlashContent *ptr;
  74. free(content->data_part);
  75. ptr = content->next;
  76. while (ptr != NULL)
  77. {
  78. FlashContent *next = ptr->next;
  79. free(ptr->data_part);
  80. free(ptr);
  81. for(i = 0; i < content->num_pages; i++)
  82. {
  83. free(content->pages[i]->data);
  84. free(content->pages[i]);
  85. }
  86. free(content->pages);
  87. ptr = next;
  88. }
  89. free(content);
  90. }
  91. return 0;
  92. }
  93. /**
  94. * tifiles_file_read_flash:
  95. * @filename: name of FLASH file to open.
  96. * @content: where to store the file content.
  97. *
  98. * Load the FLASH file into a FlashContent structure.
  99. *
  100. * Structure content must be freed with #tifiles_content_delete_flash when
  101. * no longer used.
  102. *
  103. * Return value: an error code, 0 otherwise.
  104. **/
  105. TIEXPORT2 int tifiles_file_read_flash(const char *filename, FlashContent *content)
  106. {
  107. if (tifiles_calc_is_ti9x(tifiles_file_get_model(filename)) || tifiles_file_is_tib(filename))
  108. return ti9x_file_read_flash(filename, content);
  109. else
  110. return ERR_BAD_CALC;
  111. return 0;
  112. }