You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
2.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "codewriter.h"
  2. #include <xsd2c/tr.h>
  3. #include <xsd2c/obj.h>
  4. #include <stdio.h>
  5. static FILE *header;
  6. static FILE *source;
  7. static char* ns = "impl";
  8. static int openSourceFile(const char* filename);
  9. static void closeSourceFile();
  10. static int openHeaderFile(const char* filename);
  11. static void closeHeaderFile();
  12. static void writeOperation(struct CallFunc *call)
  13. {
  14. struct CallVar_List* var;
  15. fprintf(header, "%s %s_%s(", trXSD2C(call->out->type), ns, call->name);
  16. var = CallFunc_Get_in(call);
  17. while (var) {
  18. fprintf(header, "const %s %s", trXSD2C(var->value->type), var->value->name);
  19. var = var->next;
  20. if (var) fprintf(header, ",");
  21. }
  22. fprintf(header, ")");
  23. }
  24. void codeWriteStubHeader(struct CallList *cl, const char* filename)
  25. {
  26. struct CallFunc_List *call;
  27. struct CallVar_List* var;
  28. HCOMPLEXTYPE ct;
  29. openHeaderFile(filename);
  30. fprintf(header, "#ifndef __TEST_SOAP_H__\n#define __TEST_SOAP_H__\n\n");
  31. /* Find header files */
  32. call = CallList_Get_operation(cl);
  33. while (call) {
  34. var = CallFunc_Get_in(call->value);
  35. while (var) {
  36. ct = objRegistryGetComplexType(var->value->type);
  37. if (ct /* TODO: && not in written before */)
  38. fprintf(header, "#include \"%s.h\"\n", trXSDParseNs(var->value->type)); /* _xsd*/
  39. var = var->next;
  40. }
  41. call = call->next;
  42. }
  43. fprintf(header, "\n");
  44. call = CallList_Get_operation(cl);
  45. while (call) {
  46. writeOperation(call->value);
  47. fprintf(header, ";\n");
  48. call = call->next;
  49. }
  50. fprintf(header, "\n\n#endif\n");
  51. closeHeaderFile();
  52. }
  53. void codeWriteStubSource(struct CallList *cl, const char* filename)
  54. {
  55. struct CallFunc_List *call;
  56. openSourceFile(filename);
  57. fprintf(source, "#include \"test_stub.h\"\n\n");
  58. call = CallList_Get_operation(cl);
  59. while (call) {
  60. writeOperation(call->value);
  61. /* fwrite(source, "\n{\n\t*/
  62. call = call->next;
  63. }
  64. fprintf(source, "\n");
  65. closeSourceFile();
  66. }
  67. static
  68. int openSourceFile(const char* filename)
  69. {
  70. source = fopen(filename, "w");
  71. if (!source) return 0;
  72. return 1;
  73. }
  74. static
  75. void closeSourceFile()
  76. {
  77. fclose(source);
  78. }
  79. static
  80. int openHeaderFile(const char* filename)
  81. {
  82. header= fopen(filename, "w");
  83. if (!header) return 0;
  84. return 1;
  85. }
  86. static
  87. void closeHeaderFile()
  88. {
  89. fclose(header);
  90. }