MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / ParseLine

Function ParseLine

Applications/LSh/main.cpp:144–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144void ParseLine(){
145 if(!ln.length()){
146 return;
147 }
148
149 int argc = 0;
150 char* argv[128];
151
152 char* lnC = strdup(ln.c_str());
153
154 if(!lnC){
155 return;
156 }
157
158 char* tok = strtok(lnC, " \t\n");
159 argv[argc++] = tok;
160
161 while((tok = strtok(NULL, " \t\n")) && argc < 128){
162 argv[argc++] = tok;
163 }
164
165 for(builtin_t builtin : builtins){
166 if(strcmp(builtin.name, argv[0]) == 0){
167 builtin.func(argc, argv);
168 return;
169 }
170 }
171
172 int fd;
173 if(strchr(argv[0], '/') && (fd = open(currentDir, O_RDONLY | O_DIRECTORY))){
174 pid_t pid = lemon_spawn(argv[0], argc, argv, 1);
175 if(pid > 0){
176 syscall(SYS_WAIT_PID, pid, 0, 0, 0, 0);
177 }
178
179 close(fd);
180
181 if(lnC)
182 free(lnC);
183
184 close(fd);
185
186 return;
187 } else for(std::string path : path){
188 if((fd = open(path.c_str(), O_RDONLY | O_DIRECTORY)) > 0){
189 lemon_dirent_t dirent;
190
191 int i = 0;
192 while (lemon_readdir(fd, i++, &dirent)){
193 // Check exact filenames and try omitting extension of .lef files
194 if(strcmp(argv[0], dirent.name) == 0 || (strcmp(dirent.name + strlen(dirent.name) - 4, ".lef") == 0 && strncmp(argv[0], dirent.name, strlen(dirent.name) - 4) == 0)){
195 path = path + "/" + dirent.name;
196
197 pid_t pid = lemon_spawn(path.c_str(), argc, argv, 1);
198
199 if(pid){
200 syscall(SYS_WAIT_PID, pid, 0, 0, 0, 0);
201 } else {

Callers 1

mainFunction · 0.85

Calls 9

strdupFunction · 0.85
strtokFunction · 0.85
strcmpFunction · 0.85
strchrFunction · 0.85
lemon_spawnFunction · 0.85
lemon_readdirFunction · 0.85
strlenFunction · 0.85
strncmpFunction · 0.85
lengthMethod · 0.80

Tested by

no test coverage detected