| 14 | Lemon::GUI::Button* okButton; |
| 15 | |
| 16 | void Run(){ |
| 17 | std::string& text = textbox->contents.front(); |
| 18 | std::vector<char*> args; |
| 19 | |
| 20 | size_t argPos; |
| 21 | while((argPos = text.find(" ")) != std::string::npos){ |
| 22 | std::string arg = text.substr(0, argPos); |
| 23 | |
| 24 | args.push_back(strdup(arg.c_str())); |
| 25 | |
| 26 | text.erase(0, argPos + 1); |
| 27 | } |
| 28 | args.push_back(strdup(text.c_str())); |
| 29 | |
| 30 | if(!strchr(args.front(), '/')){ |
| 31 | for(char* p : path){ |
| 32 | DIR* dirp = opendir(p); |
| 33 | while(auto dent = readdir(dirp)){ |
| 34 | if(!strcmp(dent->d_name, args.front()) || (strstr(dent->d_name, ".lef") && !strncmp(dent->d_name, args.front(), strlen(dent->d_name) - 4))){ // try ommiting any .lef |
| 35 | char* execPath = (char*)malloc(strlen(p) + strlen(dent->d_name) + 1); // Path + arg + separator |
| 36 | strcpy(execPath, p); |
| 37 | strcat(execPath, "/"); |
| 38 | strcat(execPath, dent->d_name); |
| 39 | |
| 40 | free(args.front()); |
| 41 | args.front() = execPath; |
| 42 | |
| 43 | auto pid = lemon_spawn(args.front(), args.size(), args.data()); |
| 44 | |
| 45 | if(!pid){ |
| 46 | goto err; |
| 47 | } else { |
| 48 | delete window; |
| 49 | |
| 50 | exit(0); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } else { // We have been given a path |
| 56 | auto pid = lemon_spawn(args.front(), args.size(), args.data()); |
| 57 | |
| 58 | if(!pid){ |
| 59 | goto err; |
| 60 | } else { |
| 61 | delete window; |
| 62 | |
| 63 | exit(0); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | err: |
| 68 | char buf[512]; |
| 69 | snprintf(buf, 512, "Failed to run '%s'", args.front()); |
| 70 | Lemon::GUI::DisplayMessageBox("Failed to run!", buf); |
| 71 | |
| 72 | for(char* s : args){ |
| 73 | free(s); |