ttsetname.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /******************************************************************************
  2. *
  3. * project name: TI-68k Developer Utilities
  4. * file name: ttsetname.c
  5. * initial date: 18/10/2002
  6. * author: thomas.nussbaumer@@gmx.net
  7. * description: sets oncalc name and folder
  8. *
  9. ******************************************************************************/
  10. /*
  11. This file is part of TI-68k Developer Utilities.
  12. This file is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU Lesser General Public
  14. License as published by the Free Software Foundation; either
  15. version 2.1 of the License, or (at your option) any later version.
  16. As a special exception, UNMODIFIED copies of ttsetname may also be
  17. redistributed or sold without source code, for any purpose. (The Lesser
  18. General Public License restrictions do apply in other respects; for example,
  19. they cover modification of the program.) This exception notice must be
  20. removed on modified copies of this file.
  21. This program is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. Lesser General Public License for more details.
  25. You should have received a copy of the GNU Lesser General Public
  26. License along with this library; if not, write to the Free Software
  27. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <stdlib.h>
  32. #include "ttversion.h"
  33. #include "revtools.h"
  34. #include "tt.h"
  35. #include "strhead.h"
  36. #ifdef FILE_REVISION
  37. #undef FILE_REVISION
  38. #endif
  39. #define FILE_REVISION "1.2"
  40. //=============================================================================
  41. // outputs usage information of this tool
  42. //=============================================================================
  43. void PrintUsage() {
  44. PRINT_ID("TTSetName");
  45. fprintf(USAGE_OUT, "Usage: ttsetname [flags] file\n\n" \
  46. " -quit ... don't output standard messages\n" \
  47. " -name string ... set oncalc name to given string (max. 8 chars)\n" \
  48. " -folder string ... set oncalc folder to given string (max. 8 chars)\n\n"\
  49. " sets oncalc name and folder of given TI89/TI92p file\n");
  50. }
  51. //=============================================================================
  52. // ... just a stupid main ...
  53. //=============================================================================
  54. int main(int argc,char *argv[]) {
  55. char* file = NULL;
  56. char* folder = NULL;
  57. char* name = NULL;
  58. FILE* fp;
  59. int n;
  60. int quiet = 0;
  61. StrHeader buffer;
  62. // parse arguments
  63. for (n=1; n<argc; n++) {
  64. if (!strcmp(argv[n], "-quiet")) quiet = 1;
  65. else if (!strcmp(argv[n], "-folder")) {
  66. if (n == argc -1) {
  67. fprintf(stderr,"ERROR: missing parameter for option '-folder'\n");
  68. return 1;
  69. }
  70. if (strlen(argv[n+1])>8) {
  71. fprintf(stderr,"ERROR: folder too long (max. 8 characters)\n");
  72. return 1;
  73. }
  74. folder = argv[n+1];
  75. n++;
  76. }
  77. else if (!strcmp(argv[n], "-name")) {
  78. if (n == argc -1) {
  79. fprintf(stderr,"ERROR: missing parameter for option '-name'\n");
  80. return 1;
  81. }
  82. if (strlen(argv[n+1])>8) {
  83. fprintf(stderr,"ERROR: name too long (max. 8 characters)\n");
  84. return 1;
  85. }
  86. name = argv[n+1];
  87. n++;
  88. }
  89. else if (argv[n][0] == '-') {
  90. fprintf(stderr,"ERROR: invalid option %s",argv[n]);
  91. return 1;
  92. }
  93. else if (!file) file = argv[n];
  94. else {
  95. PrintUsage();
  96. return 1;
  97. }
  98. }
  99. // check if all necessary arguments are supplied
  100. if (!file || (!name && !folder)) {
  101. PrintUsage();
  102. return 1;
  103. }
  104. if (!quiet) PRINT_ID("TTBin2OTH");
  105. if (!(fp = fopen(file,"rb+"))) {
  106. fprintf(stderr,"ERROR: cannot open file %s\n",file);
  107. return 1;
  108. }
  109. if (fread(&buffer,sizeof(StrHeader),1,fp) != 1) {
  110. fprintf(stderr,"ERROR: cannot read signature\n");
  111. fclose(fp);
  112. return 1;
  113. }
  114. if (strncmp(buffer.signature,SIGNATURE_TI89,8) && strncmp(buffer.signature,SIGNATURE_TI92P,8)) {
  115. fprintf(stderr,"ERROR: neither TI89 nor TI92p file\n");
  116. fclose(fp);
  117. return 1;
  118. }
  119. if (name) {
  120. memset(buffer.name,0,8);
  121. strncpy(buffer.name,name,8);
  122. }
  123. if (folder) {
  124. memset(buffer.folder,0,8);
  125. strncpy(buffer.folder,folder,8);
  126. }
  127. rewind(fp);
  128. if (fwrite(&buffer,sizeof(StrHeader),1,fp) != 1) {
  129. fprintf(stderr,"ERROR: cannot write to %s\n",file);
  130. fclose(fp);
  131. return 1;
  132. }
  133. fclose(fp);
  134. if (!quiet) {
  135. if (name) {
  136. fprintf(stderr,"file %s: new oncalc name = %s\n",file,name);
  137. }
  138. if (folder) {
  139. fprintf(stderr,"file %s: new oncalc folder = %s\n",file,folder);
  140. }
  141. }
  142. return 0;
  143. }
  144. //#############################################################################
  145. //###################### NO MORE FAKES BEYOND THIS LINE########################
  146. //#############################################################################
  147. //
  148. //=============================================================================
  149. // Revision History
  150. //=============================================================================
  151. //
  152. // Revision 1.2 2009/01/25 Lionel Debroux
  153. // Initial import in the TI-68k Developer Utilities (this tool used to be in TI-Chess)
  154. // Adapt to new version display (revtools.h).
  155. //