| 106 | } |
| 107 | |
| 108 | static void _EmscriptenGetTxtFileArgs(int &argc, char** argv, int maxargc) |
| 109 | { |
| 110 | argc = 0; |
| 111 | |
| 112 | const U32 kMaxTextLen = 2048; |
| 113 | |
| 114 | U32 textLen; |
| 115 | |
| 116 | char* text = new char[kMaxTextLen]; |
| 117 | |
| 118 | // Open the file, kick out if we can't |
| 119 | File cmdfile; |
| 120 | |
| 121 | File::Status err = cmdfile.open("EmscriptenCmdLine.txt", cmdfile.Read); |
| 122 | |
| 123 | // Re-organise function to handle memory deletion better |
| 124 | if (err == File::Ok) |
| 125 | { |
| 126 | // read in the first kMaxTextLen bytes, kick out if we get errors or no data |
| 127 | err = cmdfile.read(kMaxTextLen-1, text, &textLen); |
| 128 | |
| 129 | if (((err == File::Ok || err == File::EOS) || textLen > 0)) |
| 130 | { |
| 131 | // Null terminate |
| 132 | text[textLen++] = '\0'; |
| 133 | |
| 134 | // Truncate to the 1st line of the file |
| 135 | for(int i = 0; i < textLen; i++) |
| 136 | { |
| 137 | if( text[i] == '\n' || text[i] == '\r' ) |
| 138 | { |
| 139 | text[i] = '\0'; |
| 140 | textLen = i+1; |
| 141 | break; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // Tokenize the args with nulls, save them in argv, count them in argc |
| 146 | char* tok; |
| 147 | |
| 148 | for(tok = dStrtok(text, " "); tok && argc < maxargc; tok = dStrtok(NULL, " ")) |
| 149 | argv[argc++] = tok; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // Close file and delete memory before returning |
| 154 | cmdfile.close(); |
| 155 | |
| 156 | delete[] text; |
| 157 | |
| 158 | text = NULL; |
| 159 | } |
| 160 | |
| 161 | int main(int argc, char **argv) |
| 162 | { |