Changeset 747 for soft/giet_vm/applications/shell
- Timestamp:
- Dec 15, 2015, 4:29:02 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/shell/shell.c
r712 r747 11 11 #include "malloc.h" 12 12 13 #define BUF_SIZE (256) 14 #define MAX_ARGS (32) 13 #define BUF_SIZE (256) // buffer for one command 14 #define MAX_ARGS (32) // max number of arguments in a command 15 15 16 16 … … 69 69 while (giet_fat_readdir(fd, &entry) == 0) 70 70 { 71 if (entry.is_dir) 72 giet_tty_printf("dir "); 73 else 74 giet_tty_printf("file"); 75 76 giet_tty_printf(" | size = %d \t| cluster = %X \t| %s\n", 71 if (entry.is_dir) giet_tty_printf("dir "); 72 else giet_tty_printf("file"); 73 74 giet_tty_printf(" | size = %d \t| cluster = %x \t| %s\n", 77 75 entry.size, entry.cluster, entry.name ); 78 76 } … … 307 305 } 308 306 307 ///////////////////////////////////////////// 308 static void cmd_cat(int argc, char** argv) 309 { 310 if (argc < 2) 311 { 312 giet_tty_printf(" usage : %s <path_name> \n", argv[0] ); 313 return; 314 } 315 316 unsigned int x,y,p; // processor coordinates 317 unsigned int fd; // file descriptor 318 fat_file_info_t info; // file info 319 unsigned int size; // buffer size (file_size + 1) 320 unsigned int len; // number of read bytes from file 321 char* buf; // temporary buffer 322 323 // get processor coordinates 324 giet_proc_xyp( &x , &y , &p ); 325 326 // open the file to display 327 fd = giet_fat_open( argv[1] , O_RDONLY ); 328 if (fd < 0) 329 { 330 giet_tty_printf(" error : cannot open %s\n", argv[1]); 331 goto exit; 332 } 333 334 // get file size 335 giet_fat_file_info( fd, &info ); 336 if ( info.is_dir ) 337 { 338 giet_tty_printf(" error : %s is a directory\n", argv[1] ); 339 goto exit; 340 } 341 size = info.size; 342 343 // allocate a temporary buffer for the file 344 heap_init( x , y ); 345 buf = (char*)malloc( size ); 346 if( buf == NULL ) 347 { 348 giet_tty_printf(" error : cannot allocate buffer with size = %d\n", size ); 349 goto exit; 350 } 351 // load the file and set terminating '0' 352 len = giet_fat_read( fd , buf , size ); 353 if ( len != size ) 354 { 355 giet_tty_printf(" error : cannot load file %s / size = %d / len = %d\n", 356 argv[1] , size , len ); 357 goto exit; 358 } 359 buf[size] = 0; 360 361 // display the file content 362 giet_tty_printf("\n%s", buf ); 363 364 exit: 365 if ( fd >= 0 ) giet_fat_close( fd ); 366 if ( buf != NULL ) free( buf ); 367 } 309 368 310 369 //////////////////////////////////////////////////////////////////// 311 370 struct command_t cmd[] = 312 371 { 372 { "cat", "display file content", cmd_cat }, 373 { "context", "display a thread context", cmd_context }, 374 { "cp", "replicate a file in file system", cmd_cp }, 375 { "exec", "start an application", cmd_exec }, 313 376 { "help", "list available commands", cmd_help }, 314 { " time", "return current date", cmd_time},377 { "kill", "kill an application (all threads)", cmd_kill }, 315 378 { "ls", "list content of a directory", cmd_ls }, 316 379 { "mkdir", "create a new directory", cmd_mkdir }, 317 { "cp", "replicate a file in file system", cmd_cp }, 380 { "mv", "move a file in file system", cmd_mv }, 381 { "pause", "pause a thread", cmd_pause }, 382 { "ps", "list all mapped applications status", cmd_ps }, 383 { "resume", "resume a thread", cmd_resume }, 318 384 { "rm", "remove a file from file system", cmd_rm }, 319 385 { "rmdir", "remove a directory from file system", cmd_rmdir }, 320 { "mv", "move a file in file system", cmd_mv }, 321 { "exec", "start an application", cmd_exec }, 322 { "kill", "kill an application (all threads)", cmd_kill }, 323 { "ps", "list all mapped applications status", cmd_ps }, 324 { "pause", "pause a thread", cmd_pause }, 325 { "resume", "resume a thread", cmd_resume }, 326 { "context", "display a thread context", cmd_context }, 386 { "time", "return current date", cmd_time }, 327 387 { NULL, NULL, NULL } 328 388 }; … … 330 390 // shell 331 391 332 //////////////////////////// 392 /////////////////////////////////////////////////////////////////// 393 // This function analyses one command (with arguments) 394 /////////////////////////////////////////////////////////////////// 333 395 static void parse(char *buf) 334 396 { … … 405 467 switch (c) 406 468 { 407 case '\b': // backspace469 case '\b': // backspace 408 470 if (count > 0) 409 471 { … … 412 474 } 413 475 break; 414 case '\n': // new line476 case '\n': // new line 415 477 giet_tty_printf("\n"); 416 478 if (count > 0) … … 422 484 count = 0; 423 485 break; 424 case '\t': // tabulation486 case '\t': // tabulation 425 487 // do nothing 426 488 break; 427 case '\03': // ^C489 case '\03': // ^C 428 490 giet_tty_printf("^C\n"); 429 491 prompt(); 430 492 count = 0; 431 493 break; 432 default: // regular character494 default: // regular character 433 495 if (count < sizeof(buf) - 1) 434 496 {
Note: See TracChangeset
for help on using the changeset viewer.