WriteInFile.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /******************************************************************************/
  2. /* */
  3. /* CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran) */
  4. /* */
  5. /* Copyright or or Copr. Laurent Debreu (Laurent.Debreu@imag.fr) */
  6. /* Cyril Mazauric (Cyril_Mazauric@yahoo.fr) */
  7. /* This software is governed by the CeCILL-C license under French law and */
  8. /* abiding by the rules of distribution of free software. You can use, */
  9. /* modify and/ or redistribute the software under the terms of the CeCILL-C */
  10. /* license as circulated by CEA, CNRS and INRIA at the following URL */
  11. /* "http://www.cecill.info". */
  12. /* */
  13. /* As a counterpart to the access to the source code and rights to copy, */
  14. /* modify and redistribute granted by the license, users are provided only */
  15. /* with a limited warranty and the software's author, the holder of the */
  16. /* economic rights, and the successive licensors have only limited */
  17. /* liability. */
  18. /* */
  19. /* In this respect, the user's attention is drawn to the risks associated */
  20. /* with loading, using, modifying and/or developing or reproducing the */
  21. /* software by the user in light of its specific status of free software, */
  22. /* that may mean that it is complicated to manipulate, and that also */
  23. /* therefore means that it is reserved for developers and experienced */
  24. /* professionals having in-depth computer knowledge. Users are therefore */
  25. /* encouraged to load and test the software's suitability as regards their */
  26. /* requirements in conditions enabling the security of their systems and/or */
  27. /* data to be ensured and, more generally, to use and operate it in the */
  28. /* same conditions as regards security. */
  29. /* */
  30. /* The fact that you are presently reading this means that you have had */
  31. /* knowledge of the CeCILL-C license and that you accept its terms. */
  32. /******************************************************************************/
  33. /* version 1.7 */
  34. /******************************************************************************/
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include "decl.h"
  39. /******************************************************************************/
  40. /* tofich_reste */
  41. /******************************************************************************/
  42. /* This subroutine is used to write the string s into the fileout */
  43. /******************************************************************************/
  44. void tofich_reste (FILE * filout, const char *s, int do_returnline)
  45. {
  46. const size_t line_length = 66;
  47. char temp[line_length+1];
  48. size_t s_length;
  49. s_length = strlen(s);
  50. if ( !strcmp(&s[strlen(s)-1], "\n") )
  51. s_length = strlen(s)-1;
  52. if ( s_length <= line_length )
  53. {
  54. if ( do_returnline ) fprintf(filout, " &%s\n", s);
  55. else fprintf(filout, "&%s", s);
  56. }
  57. else
  58. {
  59. strncpy(temp, s, line_length);
  60. temp[line_length] = '\0';
  61. if ( retour77 == 0 && (s_length-strlen(temp) > 0) )
  62. fprintf(filout, " &%s&\n", temp);
  63. else fprintf(filout, " &%s\n", temp);
  64. if ( s_length-strlen(temp) > 0 )
  65. tofich_reste(filout, (char *) &s[line_length], do_returnline);
  66. }
  67. }
  68. /******************************************************************************/
  69. /* tofich */
  70. /******************************************************************************/
  71. /* This subroutine is used to write the string s into the fileout */
  72. /******************************************************************************/
  73. void tofich (FILE * filout, const char *s, int do_returnline)
  74. {
  75. const size_t line_length = 66;
  76. char temp[line_length+1];
  77. size_t s_length;
  78. s_length = strlen(s);
  79. if ( !strcmp(&s[strlen(s)-1], "\n") )
  80. s_length = strlen(s)-1;
  81. if ( s_length <= line_length )
  82. {
  83. if ( do_returnline ) fprintf(filout, " %s\n", s);
  84. else fprintf(filout, "%s", s);
  85. }
  86. else
  87. {
  88. strncpy(temp, s, line_length);
  89. temp[line_length] = '\0';
  90. if ( retour77 == 0 ) fprintf(filout, " %s&\n", temp);
  91. else fprintf(filout, " %s\n", temp);
  92. tofich_reste(filout, (char *) &s[line_length], do_returnline);
  93. }
  94. }
  95. /******************************************************************************/
  96. /* tofich_blanc */
  97. /******************************************************************************/
  98. /* This subroutine is used to write size blank into the fileout */
  99. /******************************************************************************/
  100. void tofich_blanc (FILE * filout, int size)
  101. {
  102. const char* empty_char = " ";
  103. int i = 0;
  104. if (size <= 65)
  105. fprintf(filout, "%*s\n", size, empty_char);
  106. else
  107. {
  108. do
  109. {
  110. fprintf(filout, "%*s\n", 65, empty_char);
  111. i++;
  112. }
  113. while ( i <= size / 65 );
  114. fprintf(filout, "%*s\n", size%65, empty_char);
  115. }
  116. }
  117. /******************************************************************************/
  118. /* RemoveWordSET_0 */
  119. /******************************************************************************/
  120. /* This subroutine is used to remove a sentence in the file filout */
  121. /******************************************************************************/
  122. void RemoveWordSET_0(FILE * filout, long int position, int sizetoremove)
  123. {
  124. if ( inside_type_declare || firstpass ) return;
  125. fseek(filout, position, SEEK_SET);
  126. tofich_blanc(filout, sizetoremove);
  127. fseek(filout, position, SEEK_SET);
  128. }
  129. /******************************************************************************/
  130. /* RemoveWordCUR_0 */
  131. /******************************************************************************/
  132. /* This subroutine is used to remove a sentence in the file filout */
  133. /******************************************************************************/
  134. void RemoveWordCUR_0(FILE * filout, int sizetoremove)
  135. {
  136. if ( inside_type_declare || firstpass ) return;
  137. fseek(filout, (long int)(-sizetoremove), SEEK_CUR);
  138. tofich_blanc(filout, sizetoremove);
  139. fseek(filout, (long int)(-sizetoremove), SEEK_CUR);
  140. if ( strstr(fortran_text, "\n") ) fprintf(filout, "\n");
  141. }