MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / main

Function main

tools/tool.c:63–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61extern int mainXSC(int argc, char* argv[]) ;
62
63int main(int argc, char* argv[])
64{
65 int error = 0;
66 if ((argc > 1) && !strcmp(argv[1], "cp")) {
67#ifdef XSTOOLS
68 char buffer[1024];
69 FILE* src = NULL;
70 FILE* dst = NULL;
71 size_t srcSize;
72 size_t dstSize;
73
74 src = fopen(argv[2], "rb");
75 if (!src) { error = errno; goto END; };
76 dst = fopen(argv[3], "wb");
77 if (!dst) { error = errno; goto END; };
78 for (;;) {
79 srcSize = fread(buffer, 1, sizeof(buffer), src);
80 if (!srcSize)
81 break;
82 dstSize = fwrite(buffer, 1, srcSize, dst);
83 if (srcSize != dstSize) { error = errno; goto END; };
84 }
85 END:
86 if (dst)
87 fclose(dst);
88 if (src)
89 fclose(src);
90#endif
91 }
92 else if ((argc > 1) && !strcmp(argv[1], "xsa")) {
93#ifdef XSTOOLS
94 error = mainXSA(argc - 1, &argv[1]);
95#endif
96 }
97 else if ((argc > 1) && !strcmp(argv[1], "xsc")) {
98#ifdef XSTOOLS
99 error = mainXSC(argc - 1, &argv[1]);
100#endif
101 }
102 else {
103 xsMachine* machine = fxPrepareMachine(NULL, xsPreparation(), "tool", NULL, NULL);
104 xsBeginHost(machine);
105 {
106 xsVars(2);
107 {
108 xsTry {
109 if (argc > 1) {
110 int argi;
111 xsVar(0) = xsNewArray(0);
112 for (argi = 1; argi < argc; argi++) {
113 xsSetAt(xsVar(0), xsInteger(argi - 1), xsString(argv[argi]));
114 }
115 xsVar(1) = xsAwaitImport(argv[1], XS_IMPORT_DEFAULT);
116 fxPush(xsVar(1));
117 fxNew(the);
118 fxPush(xsVar(0));
119 fxRunCount(the, 1);
120 xsResult = fxPop();

Callers

nothing calls this directly

Calls 3

fxPrepareMachineFunction · 0.85
fxNewFunction · 0.85
fxRunCountFunction · 0.85

Tested by

no test coverage detected