|
32 | 32 | #define MAXARG_sJ ((1 << SIZE_sJ) - 1) |
33 | 33 | #else |
34 | 34 | #define MAXARG_sJ INT_MAX |
| 35 | +--- lua/loslib.c |
| 36 | ++++ lua/loslib.c |
| 37 | +@@ -134,6 +134,57 @@ |
| 38 | + #if defined(LUA_USE_IOS) |
| 39 | + /* Despite claiming to be ISO C, iOS does not implement 'system'. */ |
| 40 | + #define l_system(cmd) ((cmd) == NULL ? 0 : -1) |
| 41 | ++ |
| 42 | ++/* DOS interrupt version of 'system' to avoid clib bloat */ |
| 43 | ++#elif defined(_M_I86) && defined(_DOS) |
| 44 | ++ |
| 45 | ++#include <dos.h> |
| 46 | ++ |
| 47 | ++typedef struct ExecParamRec { |
| 48 | ++ unsigned short int envseg; /* Segment address of environment block */ |
| 49 | ++ char far *cmdline; /* Pointer to command line string (ES:BX) */ |
| 50 | ++ unsigned short int fcb1; /* Reserved */ |
| 51 | ++ unsigned short int fcb2; |
| 52 | ++} ExecParamRec; |
| 53 | ++ |
| 54 | ++static int l_system(const char *str) { |
| 55 | ++ size_t l; |
| 56 | ++ char *p, command[128]; |
| 57 | ++ union REGS regs; |
| 58 | ++ struct SREGS sregs; |
| 59 | ++ ExecParamRec exec; |
| 60 | ++ |
| 61 | ++ if (!str || (l = 4 + strlen(str)) > 127) /* Maximum cmdline under DOS */ |
| 62 | ++ return -1; |
| 63 | ++ |
| 64 | ++ if (!(p = getenv("COMSPEC"))) |
| 65 | ++ p = "COMMAND.COM"; |
| 66 | ++ |
| 67 | ++/* Copy Lua string onto command.com */ |
| 68 | ++ command[0] = (unsigned char) l; |
| 69 | ++ memcpy(&command[1], " /C ", 4); |
| 70 | ++ memcpy(&command[5], str, strlen(str)); |
| 71 | ++ command[l + 1] = '\r'; |
| 72 | ++ |
| 73 | ++/* Clear registers and structures */ |
| 74 | ++ memset(&exec, 0, sizeof(ExecParamRec)), memset(®s, 0, sizeof(union REGS)), memset(&sregs, 0, sizeof(struct SREGS)); |
| 75 | ++ exec.cmdline = command; |
| 76 | ++ |
| 77 | ++ regs.x.ax = 0x4b00; /* Exec + load */ |
| 78 | ++ regs.x.dx = FP_OFF(p); /* Offset of the command path string (DS:DX) */ |
| 79 | ++ sregs.ds = FP_SEG(p); /* Segment of the command path string (DS:DX) */ |
| 80 | ++ regs.x.bx = FP_OFF(&exec); /* Offset of the ExecParamRec structure (ES:BX) */ |
| 81 | ++ sregs.es = FP_SEG(&exec); /* Segment of the ExecParamRec structure (ES:BX) */ |
| 82 | ++ intdosx(®s, ®s, &sregs); /* 0x21 Send it! */ |
| 83 | ++ |
| 84 | ++ if (regs.x.cflag) |
| 85 | ++ return -1; |
| 86 | ++ |
| 87 | ++ regs.x.ax = 0x4D00; |
| 88 | ++ intdos(®s, ®s); |
| 89 | ++ return regs.x.ax & 0xFF; |
| 90 | ++} |
| 91 | ++ |
| 92 | + #else |
| 93 | + #define l_system(cmd) system(cmd) /* default definition */ |
| 94 | + #endif |
35 | 95 | --- lua/luaconf.h |
36 | 96 | +++ lua/luaconf.h |
37 | 97 | @@ -95,7 +95,12 @@ |
|
0 commit comments