summaryrefslogtreecommitdiffstats
path: root/wsdl2c/codewriter.c
blob: 7f46b7fa0a9a69e1e628b0c29eab02039ce85715 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "codewriter.h"
#include <xsd2c/tr.h>
#include <xsd2c/obj.h>

#include <stdio.h>

static FILE *header;
static FILE *source;
static char* ns = "impl";

static int openSourceFile(const char* filename);
static void closeSourceFile();

static int openHeaderFile(const char* filename);
static void closeHeaderFile();

static void writeOperation(struct CallFunc *call)
{
  struct CallVar_List* var;

  fprintf(header, "%s %s_%s(", trXSD2C(call->out->type), ns, call->name);
  
  var = CallFunc_Get_in(call);

  while (var) {
    fprintf(header, "const %s %s", trXSD2C(var->value->type), var->value->name);
    var = var->next;
    if (var) fprintf(header, ",");
  }

  fprintf(header, ")");
}

void codeWriteStubHeader(struct CallList *cl, const char* filename)
{
  struct CallFunc_List *call;
  struct CallVar_List* var;
  HCOMPLEXTYPE ct;

  openHeaderFile(filename);

  fprintf(header, "#ifndef __TEST_SOAP_H__\n#define __TEST_SOAP_H__\n\n");

  /* Find header files */
  call = CallList_Get_operation(cl);
  while (call) {
    var = CallFunc_Get_in(call->value);
    while (var) {
      ct = objRegistryGetComplexType(var->value->type);
      if (ct /* TODO: && not in written before  */)
      fprintf(header, "#include \"%s.h\"\n", trXSDParseNs(var->value->type)); /* _xsd*/
      var = var->next;
    }
    call = call->next;
  }

  fprintf(header, "\n");
  call = CallList_Get_operation(cl);
  while (call) {
    
    writeOperation(call->value);
    fprintf(header, ";\n");
    call = call->next;
  }

  fprintf(header, "\n\n#endif\n");

  closeHeaderFile();
}


void codeWriteStubSource(struct CallList *cl, const char* filename)
{
  struct CallFunc_List *call;

  openSourceFile(filename);
  
  fprintf(source, "#include \"test_stub.h\"\n\n");

  call = CallList_Get_operation(cl);
  while (call) {
    
    writeOperation(call->value);
/*    fwrite(source, "\n{\n\t*/
    call = call->next;
  }
  

  fprintf(source, "\n");

  closeSourceFile();
}



static 
int openSourceFile(const char* filename)
{
  source = fopen(filename, "w");
  if (!source) return 0;
  return 1;
}

static 
void closeSourceFile()
{
  fclose(source);
}

static 
int openHeaderFile(const char* filename)
{
  header= fopen(filename, "w");
  if (!header) return 0;
  return 1;
}


static 
void closeHeaderFile()
{
  fclose(header);
}