aboutsummaryrefslogtreecommitdiff
path: root/src/output_source.c
blob: d319f72122365e13248413aa06a840d0b6221007 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* $Header$ */

#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cctk.h"
#include "cctk_Arguments.h"
#include "cctk_Parameters.h"



struct sourceinfo
{
  char const * data;
  size_t length;
  char const * arrangement;
  char const * thorn;
};

extern struct sourceinfo const * const cactus_source [];
extern size_t const cactus_source_length;



int
Formaline_OutputSource (void);



int
Formaline_OutputSource (void)
{
  DECLARE_CCTK_PARAMETERS;
  
  char filename [10000];
  FILE * file;
  int count;
  
  if (CCTK_MyProc (0) != 0) return 0;
  
  { CCTK_PRINTSEPARATOR }
  CCTK_VInfo (CCTK_THORNSTRING,
              "Writing tarballs with the Cactus sources into the directory \"%s/%s\"",
              out_dir, output_source_subdirectory);
  
  snprintf (filename, sizeof filename,
            "%s/%s", out_dir, output_source_subdirectory);
  CCTK_CreateDirectory (0755, filename);
  
  /* Output all thorns' tarballs */
  for (count = 0; count < cactus_source_length; ++ count)
  {
    snprintf (filename, sizeof filename,
              "%s/%s/Cactus-source-%s.tar.gz",
              out_dir, output_source_subdirectory,
              cactus_source[count]->thorn);
    file = fopen (filename, "w");
    assert (file);
    fwrite (cactus_source[count]->data,
            sizeof * cactus_source[count]->data,
            cactus_source[count]->length,
            file);
    fclose (file);
  }
  
  /* Add a README */
  snprintf (filename, sizeof filename,
            "%s/%s/README", out_dir, output_source_subdirectory);
  file = fopen (filename, "w");
  assert (file);
  fprintf (file,
"README for the Cactus source tree\n"
"\n"
"This directory contains a complete Cactus source tree in several tarballs.\n"
"(A tarball is a file with a suffix like \".tar.gz\".)\n"
"The tarballs were created by the thorn AEIThorns/Formaline when the\n"
"corresponding executable was produced, and were stored in the executable.\n"
"Thorn AEIThorns/Formaline contains more information about this feature.\n"
"\n"
"In order to fully recreate the Cactus source tree, unpack all tarballs\n"
"in this directory, e.g. with commands like\n"
"\ttar xzf cactus-source-Cactus.tar.gz\n"
"for all tarballs.  All tarballs should be unpacked into the same directory.\n"
"\n"
"The files \"config-info\" and \"ThornList\" that were used to build the\n"
"executable can then be found in the \"configs\" subdirectory.\n"
           );
  fclose (file);
  
  return 0;
}