Changeset 409 for trunk/user/ksh
- Timestamp:
- Dec 20, 2017, 4:51:09 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/ksh/ksh.c
r408 r409 61 61 if (argc != 2) 62 62 { 63 printf(" usage: cat pathname\n");63 printf(" usage: cat pathname\n"); 64 64 return; 65 65 } … … 67 67 path = argv[1]; 68 68 69 printf(" error: not implemented yet\n");69 printf(" error: not implemented yet\n"); 70 70 71 71 /* … … 74 74 if (fd < 0) 75 75 { 76 printf(" error: cannot open %s\n", path);76 printf(" error: cannot open %s\n", path); 77 77 goto exit; 78 78 } … … 81 81 if (stat(path, &st) == -1) 82 82 { 83 printf(" error: cannot stat %s\n", path);83 printf(" error: cannot stat %s\n", path); 84 84 goto exit; 85 85 } 86 86 if (S_ISDIR(st.st_mode)) { 87 printf(" error: %s is a directory\n", path);87 printf(" error: %s is a directory\n", path); 88 88 goto exit; 89 89 } … … 93 93 buf = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); 94 94 if (buf == NULL || buf == (char *)-1) { 95 printf(" error: cannot map %s\n", path);95 printf(" error: cannot map %s\n", path); 96 96 goto exit; 97 97 } … … 117 117 if (argc != 2) 118 118 { 119 printf(" usage: cd pathname\n");119 printf(" usage: cd pathname\n"); 120 120 return; 121 121 } … … 123 123 path = argv[1]; 124 124 125 printf(" error: not implemented yet\n");125 printf(" error: not implemented yet\n"); 126 126 /* 127 127 path = argv[1]; … … 129 129 if (chdir(path) == -1) 130 130 { 131 printf(" error: cannot cd to %s\n", path);131 printf(" error: cannot cd to %s\n", path); 132 132 } 133 133 */ … … 146 146 if (argc != 3) 147 147 { 148 printf(" usage: cp src_pathname dst_pathname\n");149 return; 150 } 151 152 printf(" error: not implemented yet\n");148 printf(" usage: cp src_pathname dst_pathname\n"); 149 return; 150 } 151 152 printf(" error: not implemented yet\n"); 153 153 154 154 /* … … 159 159 src_fd = open(srcpath, O_RDONLY, 0); 160 160 if (src_fd < 0) { 161 printf(" error: cannot open %s / err = %d\n", srcpath, errno);161 printf(" error: cannot open %s / err = %d\n", srcpath, errno); 162 162 goto exit; 163 163 } … … 165 165 // get file size 166 166 if (stat(srcpath, &st) == -1) { 167 printf(" error: cannot stat %s\n", srcpath);167 printf(" error: cannot stat %s\n", srcpath); 168 168 goto exit; 169 169 } 170 170 if (S_ISDIR(st.st_mode)) { 171 printf(" error: %s is a directory\n", srcpath);171 printf(" error: %s is a directory\n", srcpath); 172 172 goto exit; 173 173 } … … 177 177 dst_fd = open(dstpath, O_CREAT|O_TRUNC|O_RDWR, 0); 178 178 if (dst_fd < 0) { 179 printf(" error: cannot open %s / err = %d\n", dstpath, errno);179 printf(" error: cannot open %s / err = %d\n", dstpath, errno); 180 180 goto exit; 181 181 } 182 182 if (stat(dstpath, &st) == -1) { 183 printf(" error: cannot stat %s\n", dstpath);183 printf(" error: cannot stat %s\n", dstpath); 184 184 goto exit; 185 185 } 186 186 if (S_ISDIR(st.st_mode)) { 187 printf(" error: %s is a directory\n", dstpath);187 printf(" error: %s is a directory\n", dstpath); 188 188 goto exit; 189 189 } … … 199 199 ret = read(src_fd, buf, rlen); 200 200 if (ret == -1) { 201 printf(" error: cannot read from file %s\n", srcpath);201 printf(" error: cannot read from file %s\n", srcpath); 202 202 goto exit; 203 203 } … … 207 207 ret = write(dst_fd, buf, rlen); 208 208 if (ret == -1) { 209 printf(" error: cannot write to file %s\n", dstpath);209 printf(" error: cannot write to file %s\n", dstpath); 210 210 goto exit; 211 211 } … … 214 214 // check 215 215 if (wlen != rlen) { 216 printf(" error: cannot write on device\n");216 printf(" error: cannot write on device\n"); 217 217 goto exit; 218 218 } … … 235 235 if (argc != 1) 236 236 { 237 printf(" usage: %s\n", argv[0]);237 printf(" usage: %s\n", argv[0]); 238 238 return; 239 239 } … … 253 253 if (argc != 2) 254 254 { 255 printf(" usage: %s pid\n", argv[0]);255 printf(" usage: %s pid\n", argv[0]); 256 256 return; 257 257 } … … 261 261 if( kill( pid , 9 ) ) // TODO replace 9 by SIGKILL 262 262 { 263 printf(" error: unable to kill process %x\n", pid );263 printf(" error: unable to kill process %x\n", pid ); 264 264 } 265 265 } // end cmd_kill() … … 274 274 if (argc != 2) 275 275 { 276 printf(" usage: %s pathname \n", argv[0] );276 printf(" usage: %s pathname \n", argv[0] ); 277 277 return; 278 278 } … … 285 285 if (pid == 0) // it is the child process 286 286 { 287 printf("CHILD\n");288 exit(0);289 290 287 // exec system call 291 //error = exec( pathname , NULL , NULL );292 293 //if( error )294 //{295 // printf("error: new process unable to exec <%s>\n", pathname );296 // exit();297 //}288 error = exec( pathname , NULL , NULL ); 289 290 if( error ) 291 { 292 printf(" error: new process unable to exec <%s>\n", pathname ); 293 exit(0); 294 } 298 295 } 299 296 else if ( pid < 0 ) // it is a failure reported to parent 300 297 { 301 printf(" error: unable to fork\n");298 printf(" error: unable to fork\n"); 302 299 } 303 else // it is a success reported to parent304 {305 printf("PARENT\n");306 exit(0);307 }308 309 300 } // end cmd_load 310 301 … … 339 330 else 340 331 { 341 printf(" usage: ls [path]\n");342 return; 343 } 344 345 printf(" error: not implemented yet\n");332 printf(" usage: ls [path]\n"); 333 return; 334 } 335 336 printf(" error: not implemented yet\n"); 346 337 /* 347 338 dir = opendir( path ); … … 361 352 if (argc != 2) 362 353 { 363 printf(" usage: mkdir pathname\n");354 printf(" usage: mkdir pathname\n"); 364 355 return; 365 356 } … … 367 358 pathname = argv[1]; 368 359 369 printf(" error: not implemented yet\n");360 printf(" error: not implemented yet\n"); 370 361 /* 371 362 if ( mkdir( path, 0x700) == -1 ) 372 363 { 373 printf(" error: cannot create directory %s\n", path);364 printf(" error: cannot create directory %s\n", path); 374 365 } 375 366 */ … … 386 377 } 387 378 388 printf(" error: not implemented yet\n");379 printf(" error: not implemented yet\n"); 389 380 390 381 /* … … 392 383 if (ret < 0) 393 384 { 394 printf(" error : cannot move %s to %s / err = %d\n", argv[1], argv[2], ret );385 printf(" error : cannot move %s to %s / err = %d\n", argv[1], argv[2], ret ); 395 386 } 396 387 */ … … 405 396 if (argc != 1) 406 397 { 407 printf(" usage: pwd\n");398 printf(" usage: pwd\n"); 408 399 return; 409 400 } … … 411 402 if ( getcwd( buf , 1024 ) ) 412 403 { 413 printf(" error: unable to get current directory\n");404 printf(" error: unable to get current directory\n"); 414 405 } 415 406 else … … 426 417 if (argc != 2) 427 418 { 428 printf(" usage: rm pathname\n");419 printf(" usage: rm pathname\n"); 429 420 return; 430 421 } … … 432 423 pathname = argv[1]; 433 424 434 printf(" error: not implemented yet\n");425 printf(" error: not implemented yet\n"); 435 426 /* 436 427 if (remove(path) == -1) 437 428 { 438 printf(" error: cannot remove %s\n", path);429 printf(" error: cannot remove %s\n", path); 439 430 } 440 431 */ … … 456 447 if (argc != 3) 457 448 { 458 printf(" usage: sched cxy lid\n");449 printf(" usage: sched cxy lid\n"); 459 450 return; 460 451 } … … 465 456 if( get_sched( cxy , lid ) ) 466 457 { 467 printf(" error: illegal arguments\n");458 printf(" error: illegal arguments\n"); 468 459 } 469 460 } … … 584 575 unsigned int state = NORMAL; 585 576 577 586 578 // @@@ 587 parse("load /bin/user/sort.elf");579 // parse("load /bin/user/sort.elf"); 588 580 // @@@ 589 590 581 591 582
Note: See TracChangeset
for help on using the changeset viewer.