Changeset 708 for soft/giet_vm/applications/shell/shell.c
- Timestamp:
- Oct 1, 2015, 4:09:25 PM (9 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/shell/shell.c
r707 r708 1 1 /////////////////////////////////////////////////////////////////////////////////////// 2 // File : main.c (for shell application)2 // File : shell.c 3 3 // Date : july 2015 4 4 // author : Clément Guérin … … 17 17 { 18 18 char *name; 19 char *desc; 19 20 void (*fn)(int, char**); 20 21 }; … … 35 36 for (i = 0; cmd[i].name; i++) 36 37 { 37 giet_tty_printf("\t%s\ n", cmd[i].name);38 } 39 } 40 41 /////////////////////////////////////////// ////42 static void cmd_ proctime(int argc, char** argv)43 { 44 giet_tty_printf("% u\n", giet_proctime());38 giet_tty_printf("\t%s\t : %s\n", cmd[i].name , cmd[i].desc ); 39 } 40 } 41 42 /////////////////////////////////////////// 43 static void cmd_time(int argc, char** argv) 44 { 45 giet_tty_printf("%d\n", giet_proctime()); 45 46 } 46 47 … … 52 53 53 54 if (argc < 2) 54 fd = giet_fat_opendir("/"); 55 else 56 fd = giet_fat_opendir(argv[1]); 55 { 56 giet_tty_printf(" usage : %s <pathname>\n", argv[0]); 57 return; 58 } 59 60 fd = giet_fat_opendir(argv[1]); 57 61 58 62 if (fd < 0) 59 63 { 60 giet_tty_printf(" can't list directory (err=%d)\n", fd);64 giet_tty_printf(" error : cannot open %s / err = %d)\n", argv[1], fd); 61 65 return; 62 66 } … … 81 85 if (argc < 2) 82 86 { 83 giet_tty_printf(" %s <path>\n", argv[0]);87 giet_tty_printf(" usage : %s <path>\n", argv[0]); 84 88 return; 85 89 } 86 90 87 91 int ret = giet_fat_mkdir(argv[1]); 92 88 93 if (ret < 0) 89 94 { 90 giet_tty_printf(" can't create directory (err=%d)\n", ret);95 giet_tty_printf(" error : cannot create directory %s / err = %d\n", argv[1], ret); 91 96 } 92 97 } … … 97 102 if (argc < 3) 98 103 { 99 giet_tty_printf(" %s <src> <dst>\n", argv[0]);104 giet_tty_printf(" usage : %s <src> <dst>\n", argv[0]); 100 105 return; 101 106 } … … 111 116 if (src_fd < 0) 112 117 { 113 giet_tty_printf(" can't open %s (err=%d)\n", argv[1], src_fd);118 giet_tty_printf(" error : cannot open %s / err = %d\n", argv[1], src_fd); 114 119 goto exit; 115 120 } 116 121 117 122 giet_fat_file_info(src_fd, &info); 123 118 124 if (info.is_dir) 119 125 { 120 giet_tty_printf(" can't copy a directory\n");126 giet_tty_printf(" error : %s is a directory\n", argv[1] ); 121 127 goto exit; 122 128 } 129 123 130 size = info.size; 124 131 125 132 dst_fd = giet_fat_open( argv[2] , O_CREATE | O_TRUNC ); 133 126 134 if (dst_fd < 0) 127 135 { 128 giet_tty_printf(" can't open %s (err=%d)\n", argv[2], dst_fd);136 giet_tty_printf(" error : cannot open %s / err = %d\n", argv[2], dst_fd); 129 137 goto exit; 130 138 } 131 139 132 140 giet_fat_file_info(dst_fd, &info); 141 133 142 if (info.is_dir) 134 143 { 135 giet_tty_printf(" can't copy to a directory\n");// TODO144 giet_tty_printf("error : %s is a directory\n", argv[2] ); // TODO 136 145 goto exit; 137 146 } … … 149 158 if (wlen != len) 150 159 { 151 giet_tty_printf(" \nwrite error\n");160 giet_tty_printf(" error : cannot write on device\n"); 152 161 goto exit; 153 162 } … … 168 177 if (argc < 2) 169 178 { 170 giet_tty_printf(" %s <file>\n", argv[0]);179 giet_tty_printf(" usage : %s <file>\n", argv[0]); 171 180 return; 172 181 } 173 182 174 183 int ret = giet_fat_remove(argv[1], 0); 184 175 185 if (ret < 0) 176 186 { 177 giet_tty_printf(" can't remove %s (err=%d)\n", argv[1], ret);187 giet_tty_printf(" error : cannot remove %s / err = %d\n", argv[1], ret ); 178 188 } 179 189 } … … 184 194 if (argc < 2) 185 195 { 186 giet_tty_printf(" %s <path>\n", argv[0]);196 giet_tty_printf(" usage : %s <pathname>\n", argv[0]); 187 197 return; 188 198 } … … 191 201 if (ret < 0) 192 202 { 193 giet_tty_printf(" can't remove %s (err=%d)\n", argv[1], ret);203 giet_tty_printf(" error : cannot remove %s / err = %d\n", argv[1], ret ); 194 204 } 195 205 } … … 200 210 if (argc < 3) 201 211 { 202 giet_tty_printf(" %s <src> <dst>\n", argv[0]);212 giet_tty_printf(" usage : %s <src> <dst>\n", argv[0]); 203 213 return; 204 214 } … … 207 217 if (ret < 0) 208 218 { 209 giet_tty_printf(" can't move %s to %s (err=%d)\n", argv[1], argv[2], ret);219 giet_tty_printf("error : cannot move %s to %s / err = %d\n", argv[1], argv[2], ret ); 210 220 } 211 221 } … … 216 226 if (argc < 2) 217 227 { 218 giet_tty_printf(" %s <pathname>\n", argv[0]);228 giet_tty_printf(" usage : %s <vspace_name>\n", argv[0]); 219 229 return; 220 230 } … … 223 233 if ( ret == -1 ) 224 234 { 225 giet_tty_printf(" \nerror : %s not found\n", argv[1] );235 giet_tty_printf(" error : %s not found\n", argv[1] ); 226 236 } 227 237 } … … 232 242 if (argc < 2) 233 243 { 234 giet_tty_printf(" %s <pathname>\n", argv[0]);244 giet_tty_printf(" usage : %s <vspace_name>\n", argv[0]); 235 245 return; 236 246 } … … 239 249 if ( ret == -1 ) 240 250 { 241 giet_tty_printf(" \nerror : %s not found\n", argv[1] );251 giet_tty_printf(" error : %s not found\n", argv[1] ); 242 252 } 243 253 if ( ret == -2 ) 244 254 { 245 giet_tty_printf(" \nerror : %s cannot be killed\n", argv[1] );246 } 247 } 248 249 ///////////////////////////////////////// //////255 giet_tty_printf(" error : %s cannot be killed\n", argv[1] ); 256 } 257 } 258 259 ///////////////////////////////////////// 250 260 static void cmd_ps(int argc, char** argv) 251 261 { 252 giet_tasks_status(); 253 } 254 255 /////////////////////////////////////////////// 256 static void cmd_sleep(int argc, char** argv) 257 { 258 int start = giet_proctime(); 259 260 if (argc < 2) 261 { 262 giet_tty_printf("%s <cycles>\n", argv[0]); 263 return; 264 } 265 266 while (giet_proctime() < start + atoi(argv[1])); 267 } 262 giet_applications_status(); 263 } 264 265 //////////////////////////////////////////// 266 static void cmd_pause(int argc, char** argv) 267 { 268 if (argc < 3) 269 { 270 giet_tty_printf(" usage : %s <vspace_name> <thread_name>\n", argv[0] ); 271 return; 272 } 273 274 int ret = giet_pthread_pause( argv[1] , argv[2] ); 275 276 if ( ret == -1 ) 277 { 278 giet_tty_printf(" error : vspace %s not found\n", argv[1] ); 279 } 280 if ( ret == -2 ) 281 { 282 giet_tty_printf(" error : thread %s not found\n", argv[2] ); 283 } 284 } 285 286 ///////////////////////////////////////////// 287 static void cmd_resume(int argc, char** argv) 288 { 289 if (argc < 3) 290 { 291 giet_tty_printf(" usage : %s <vspace_name> <thread_name>\n", argv[0] ); 292 return; 293 } 294 295 int ret = giet_pthread_resume( argv[1] , argv[2] ); 296 297 if ( ret == -1 ) 298 { 299 giet_tty_printf(" error : vspace %s not found\n", argv[1] ); 300 } 301 if ( ret == -2 ) 302 { 303 giet_tty_printf(" error : thread %s not found\n", argv[2] ); 304 } 305 } 306 307 ///////////////////////////////////////////// 308 static void cmd_context(int argc, char** argv) 309 { 310 if (argc < 3) 311 { 312 giet_tty_printf(" usage : %s <vspace_name> <thread_name>\n", argv[0] ); 313 return; 314 } 315 316 int ret = giet_pthread_context( argv[1] , argv[2] ); 317 318 if ( ret == -1 ) 319 { 320 giet_tty_printf(" error : vspace %s not found\n", argv[1] ); 321 } 322 if ( ret == -2 ) 323 { 324 giet_tty_printf(" error : thread %s not found\n", argv[2] ); 325 } 326 } 327 268 328 269 329 //////////////////////////////////////////////////////////////////// 270 330 struct command_t cmd[] = 271 331 { 272 { "help", cmd_help }, 273 { "proctime", cmd_proctime }, 274 { "ls", cmd_ls }, 275 { "mkdir", cmd_mkdir }, 276 { "cp", cmd_cp }, 277 { "rm", cmd_rm }, 278 { "rmdir", cmd_rmdir }, 279 { "mv", cmd_mv }, 280 { "exec", cmd_exec }, 281 { "kill", cmd_kill }, 282 { "ps", cmd_ps }, 283 { "sleep", cmd_sleep }, 284 { NULL, NULL } 332 { "help", "list available commands", cmd_help }, 333 { "time", "return current date", cmd_time }, 334 { "ls", "list content of a directory", cmd_ls }, 335 { "mkdir", "create a new directory", cmd_mkdir }, 336 { "cp", "replicate a file in file system", cmd_cp }, 337 { "rm", "remove a file from file system", cmd_rm }, 338 { "rmdir", "remove a directory from file system", cmd_rmdir }, 339 { "mv", "move a file in file system", cmd_mv }, 340 { "exec", "start an application", cmd_exec }, 341 { "kill", "kill an application (all threads)", cmd_kill }, 342 { "ps", "list all mapped applications status", cmd_ps }, 343 { "pause", "pause a thread", cmd_pause }, 344 { "resume", "resume a thread", cmd_resume }, 345 { "context", "display a thread context", cmd_context }, 346 { NULL, NULL, NULL } 285 347 }; 286 348 287 349 // shell 288 350 289 //////////////////////////// ///////////351 //////////////////////////// 290 352 static void parse(char *buf) 291 353 { … … 351 413 // get a private TTY 352 414 giet_tty_alloc( 0 ); 353 giet_tty_printf( "~~~ shell ~~~\n " );415 giet_tty_printf( "~~~ shell ~~~\n\n" ); 354 416 355 417 // display first prompt
Note: See TracChangeset
for help on using the changeset viewer.