Changeset 407 for trunk/user/ksh
- Timestamp:
- Nov 7, 2017, 3:08:12 PM (7 years ago)
- Location:
- trunk/user/ksh
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/ksh/Makefile
r246 r407 1 # 2 # Almos-MKH Shell3 # 1 ######################################################################### 2 # Makefile for the ALMOS-MKH "ksh" application on the TSAR architecture 3 ######################################################################### 4 4 5 5 CC = mipsel-unknown-elf-gcc … … 9 9 AR = mipsel-unknown-elf-ar 10 10 11 all: 12 $(CC) -W -o ksh ksh.c 11 LIBS = ../../libs 12 13 HAL = ../../hal 14 15 KERNEL = ../../kernel 16 17 CFLAGS = -Wall -ffreestanding -mno-gpopt -mips32 -g -O2 \ 18 -fno-delete-null-pointer-checks -fomit-frame-pointer 19 20 OBJS = ksh.o \ 21 $(LIBS)/build/stdlib.o \ 22 $(LIBS)/build/stdio.o \ 23 $(LIBS)/build/nostdio.o \ 24 $(LIBS)/build/string.o \ 25 $(LIBS)/build/malloc.o \ 26 $(LIBS)/build/pthread.o \ 27 $(LIBS)/build/hal_user.o 28 29 30 INCLUDES = -I. -I$(LIBS) -I$(KERNEL)/syscalls -I$(HAL)/generic 31 32 ksh.elf : $(OBJS) ksh.ld 33 $(LD) -o $@ -T ksh.ld $(OBJS) 34 $(DU) -D $@ > $@.txt 35 36 ksh.o : ksh.c 37 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 38 $(DU) -D $@ > $@.txt 39 40 $(LIBS)/build/hal_user.o : $(HAL)/tsar_mips32/core/hal_user.c $(HAL)/generic/hal_user.h 41 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 42 $(DU) -D $@ > $@.txt 43 44 $(LIBS)/build/stdlib.o : $(LIBS)/stdlib.c $(LIBS)/stdlib.h 45 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 46 $(DU) -D $@ > $@.txt 47 48 $(LIBS)/build/stdio.o : $(LIBS)/stdio.c $(LIBS)/stdio.h 49 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 50 $(DU) -D $@ > $@.txt 51 52 $(LIBS)/build/nostdio.o : $(LIBS)/nostdio.c $(LIBS)/nostdio.h 53 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 54 $(DU) -D $@ > $@.txt 55 56 $(LIBS)/build/string.o : $(LIBS)/string.c $(LIBS)/string.h 57 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 58 $(DU) -D $@ > $@.txt 59 60 $(LIBS)/build/malloc.o : $(LIBS)/malloc.c $(LIBS)/malloc.h 61 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 62 $(DU) -D $@ > $@.txt 63 64 $(LIBS)/build/pthread.o : $(LIBS)/pthread.c $(LIBS)/pthread.h 65 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 66 $(DU) -D $@ > $@.txt 13 67 14 68 clean: 15 rm ksh69 rm -f *.o *.elf *.txt core $(LIBS)/build/*.o $(LIBS)/build/*.txt 16 70 71 -
trunk/user/ksh/ksh.c
r230 r407 1 /* 2 * Authors: Clément Guérin and Alain Greiner (2015) 3 */ 4 1 /////////////////////////////////////////////////////////////////////////////// 2 // File : ksh.c 3 // Date : October 2017 4 // Author : Alain Greiner 5 /////////////////////////////////////////////////////////////////////////////// 6 // This single thread application implement a simple shell for ALMOS-MKH. 7 /////////////////////////////////////////////////////////////////////////////// 8 9 #include <nostdio.h> 5 10 #include <stdio.h> 6 11 #include <stdlib.h> 7 #include <unistd.h>8 12 #include <string.h> 9 #include <fcntl.h> 10 #include <dirent.h> 11 #include <sys/stat.h> 12 #include <sys/mman.h> 13 #include <sys/wait.h> 14 #include <signal.h> 15 #include <errno.h> 16 17 #define MAX_SIZE (128) // max number of characters in one command 18 #define LOG_DEPTH (128) // max number of commands in log 19 #define MAX_ARGS (32) // max number of arguments in a command 20 #define FIFO_SIZE (1024) // FIFO depth for recursive ls 21 22 #define __unused(a) (void)a 23 24 extern char **environ; 13 14 #define CMD_MAX_SIZE (256) // max number of characters in one command 15 #define LOG_DEPTH (256) // max number of registered commands 16 #define MAX_ARGS (32) // max number of arguments in a command 17 #define FIFO_SIZE (1024) // FIFO depth for recursive ls 18 19 //////////////////////////////////////////////////////////////////////////////// 20 // Structures 21 //////////////////////////////////////////////////////////////////////////////// 22 23 // one entry in the registered commands array 24 typedef struct log_entry_s 25 { 26 char buf[CMD_MAX_SIZE]; 27 unsigned int count; 28 } 29 log_entry_t; 30 31 // one entry in the supported command types array 32 typedef struct ksh_cmd_s 33 { 34 char * name; 35 char * desc; 36 void (*fn)( int , char ** ); 37 } 38 ksh_cmd_t; 39 25 40 26 41 //////////////////////////////////////////////////////////////////////////////// … … 28 43 //////////////////////////////////////////////////////////////////////////////// 29 44 30 struct { 31 char buf[MAX_SIZE]; 32 size_t count; 33 } log_entries[LOG_DEPTH]; 34 35 size_t ptw; // write pointer in log 36 size_t ptr; // read pointer in log 37 38 struct command_t { 39 char *name; 40 char *desc; 41 void (*fn)(int, char **); 42 }; 43 44 struct command_t cmd[]; 45 ksh_cmd_t cmd[]; // array of supported commands 46 47 log_entry_t log_entries[LOG_DEPTH]; // array of registered commands 48 49 unsigned int ptw; // write pointer in log_entries[] 50 unsigned int ptr; // read pointer in log_entries[] 45 51 46 52 //////////////////////////////////////////////////////////////////////////////// … … 48 54 //////////////////////////////////////////////////////////////////////////////// 49 55 50 static void cmd_cat(int argc, char **argv) 51 { 52 char *path, *buf = NULL; 53 struct stat st; 54 size_t size; 55 int fd; 56 57 if (argc != 2) { 56 ///////////////////////////////////////////// 57 static void cmd_cat( int argc , char **argv ) 58 { 59 char * path; 60 61 if (argc != 2) 62 { 58 63 printf("usage: cat pathname\n"); 59 64 return; 60 65 } 66 61 67 path = argv[1]; 62 68 63 /* open the file */ 64 fd = open(path, O_RDONLY, 0); 65 if (fd < 0) { 69 printf("error: not implemented yet\n"); 70 71 /* 72 // open the file 73 fd = open( path , O_RDONLY , 0 ); 74 if (fd < 0) 75 { 66 76 printf("error: cannot open %s\n", path); 67 77 goto exit; 68 78 } 69 79 70 /* get file size */ 71 if (stat(path, &st) == -1) { 80 // get file size 81 if (stat(path, &st) == -1) 82 { 72 83 printf("error: cannot stat %s\n", path); 73 84 goto exit; … … 79 90 size = st.st_size; 80 91 81 / * mmap the file */92 // mmap the file 82 93 buf = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); 83 94 if (buf == NULL || buf == (char *)-1) { … … 86 97 } 87 98 88 / * set terminating '0' XXX */99 // set terminating '0' XXX 89 100 buf[size-1] = 0; 90 101 91 / * display the file content */102 // display the file content 92 103 printf("%s", buf); 93 104 94 105 exit: 95 if (buf != NULL) 96 munmap(buf, size); 97 if (fd >= 0) 98 close(fd); 99 } 100 106 if (buf != NULL) munmap(buf, size); 107 if (fd >= 0) close(fd); 108 */ 109 110 } // end cmd_cat() 111 112 //////////////////////////////////////////// 113 static void cmd_cd( int argc , char **argv ) 114 { 115 char * path; 116 117 if (argc != 2) 118 { 119 printf("usage: cd pathname\n"); 120 return; 121 } 122 123 path = argv[1]; 124 125 printf("error: not implemented yet\n"); 126 /* 127 path = argv[1]; 128 129 if (chdir(path) == -1) 130 { 131 printf("error: cannot cd to %s\n", path); 132 } 133 */ 134 135 } // end cmd_cd() 136 137 ///////////////////////////////////////// 101 138 static void cmd_cp(int argc, char **argv) 102 139 { 103 int src_fd = -1, dst_fd = -1; 104 char *srcpath, *dstpath; 105 struct stat st; 106 size_t size, i; 107 char buf[1024]; 108 109 if (argc != 3) { 140 // int src_fd = -1, dst_fd = -1; 141 // char *srcpath, *dstpath; 142 // struct stat st; 143 // size_t size, i; 144 // char buf[1024]; 145 146 if (argc != 3) 147 { 110 148 printf("usage: cp src_pathname dst_pathname\n"); 111 149 return; 112 150 } 113 151 152 printf("error: not implemented yet\n"); 153 154 /* 114 155 srcpath = argv[1]; 115 156 dstpath = argv[2]; 116 157 117 / * open the src file */158 // open the src file 118 159 src_fd = open(srcpath, O_RDONLY, 0); 119 160 if (src_fd < 0) { … … 122 163 } 123 164 124 / * get file size */165 // get file size 125 166 if (stat(srcpath, &st) == -1) { 126 167 printf("error: cannot stat %s\n", srcpath); … … 133 174 size = st.st_size; 134 175 135 / * open the dst file */176 // open the dst file 136 177 dst_fd = open(dstpath, O_CREAT|O_TRUNC|O_RDWR, 0); 137 178 if (dst_fd < 0) { … … 155 196 ssize_t ret; 156 197 157 / * read the source */198 // read the source 158 199 ret = read(src_fd, buf, rlen); 159 200 if (ret == -1) { … … 163 204 rlen = (size_t)ret; 164 205 165 / * write to the destination */206 // write to the destination 166 207 ret = write(dst_fd, buf, rlen); 167 208 if (ret == -1) { … … 171 212 wlen = (size_t)ret; 172 213 173 / * check */214 // check 174 215 if (wlen != rlen) { 175 216 printf("error: cannot write on device\n"); … … 181 222 182 223 exit: 183 if (src_fd >= 0) 184 close(src_fd); 185 if (dst_fd >= 0) 186 close(dst_fd); 187 } 188 189 static void cmd_exec(int argc, char **argv) 190 { 191 pid_t pid, wpid; 192 int status; 193 char *path; 194 195 if (argc != 2) { 196 printf("usage: %s prog\n", argv[0]); 197 return; 198 } 199 200 path = argv[1]; 201 argv++; 202 224 if (src_fd >= 0) close(src_fd); 225 if (dst_fd >= 0) close(dst_fd); 226 */ 227 228 } // end cmd_cp() 229 230 ////////////////////////////////////////////// 231 static void cmd_help( int argc , char **argv ) 232 { 233 unsigned int i; 234 235 if (argc != 1) 236 { 237 printf("usage: %s\n", argv[0]); 238 return; 239 } 240 241 printf("available commands:\n"); 242 for (i = 0 ; cmd[i].name ; i++) 243 { 244 printf("\t%s\t : %s\n", cmd[i].name , cmd[i].desc); 245 } 246 } // end cmd_help() 247 248 ////////////////////////////////////////////// 249 static void cmd_kill( int argc , char **argv ) 250 { 251 unsigned int pid; 252 253 if (argc != 2) 254 { 255 printf("usage: %s pid\n", argv[0]); 256 return; 257 } 258 259 pid = atoi(argv[1]); 260 261 if( kill( pid , 9 ) ) // TODO replace 9 by SIGKILL 262 { 263 printf("error: unable to kill process %x\n", pid ); 264 } 265 } // end cmd_kill() 266 267 ////////////////////////////////////////////// 268 static void cmd_load( int argc , char **argv ) 269 { 270 unsigned int pid; 271 unsigned int error; 272 char * pathname; 273 274 if (argc != 2) 275 { 276 printf("usage: %s pathname \n", argv[0] ); 277 return; 278 } 279 280 pathname = argv[1]; 281 282 // fork system call 203 283 pid = fork(); 204 if (pid == 0) { 205 /* child process */ 206 if (execve(path, argv, environ) == -1) { 207 printf("error: unable to execve %s\n", path); 208 } 209 exit(EXIT_FAILURE); 210 } else if (pid < 0) { 211 /* error forking */ 212 printf("error: unable to fork\n"); 213 } else { 214 /* parent process */ 215 do { 216 wpid = waitpid(pid, &status, WUNTRACED); 217 } while (!WIFEXITED(status) && !WIFSIGNALED(status)); 218 } 219 } 220 221 static void cmd_help(int argc, char **argv) 222 { 223 size_t i; 224 __unused(argc); 225 __unused(argv); 226 printf("available commands:\n"); 227 for (i = 0; cmd[i].name; i++) { 228 printf("\t%s\t : %s\n", cmd[i].name , cmd[i].desc); 229 } 230 } 231 232 static void cmd_kill(int argc, char **argv) 233 { 234 pid_t pid; 235 236 if (argc != 2) { 237 printf("usage: %s pid\n", argv[0]); 238 return; 239 } 240 241 pid = (pid_t)atoi(argv[1]); 242 243 if (kill(pid, SIGKILL) == -1) { 244 printf("error: unable to kill %d\n", (int)pid); 245 } 246 } 247 248 static void cmd_log(int argc, char **argv) 249 { 250 size_t i; 251 __unused(argc); 252 __unused(argv); 284 285 if (pid == 0) // it is the child process 286 { 287 288 printf("\n[KSH_DBG] process %x before exec\n", getpid() ); 289 290 // exec system call 291 error = exec( pathname , NULL , NULL ); 292 293 printf("\n[KSH_DBG] process %x after exec / error = %d\n", getpid() , error ); 294 295 if( error ) 296 { 297 printf("error: new process unable to exec <%s>\n", pathname ); 298 // TODO exit(); 299 } 300 } 301 else if ( pid < 0 ) // it is a failure reported to parent 302 { 303 printf("error: unable to fork\n"); 304 } 305 else // it is a success reported to parent 306 { 307 308 printf("\n[KSH_DBG] process %x created for <%s>\n", pid, pathname ); 309 310 } 311 312 } // end cmd_load 313 314 ///////////////////////////////////////////// 315 static void cmd_log( int argc , char **argv ) 316 { 317 unsigned int i; 318 253 319 printf("--- registered commands ---\n"); 254 for (i = 0; i < LOG_DEPTH; i++) { 320 for (i = 0; i < LOG_DEPTH; i++) 321 { 255 322 printf(" - %zu\t: %s\n", i, &log_entries[i].buf); 256 323 } 257 324 } 258 325 259 static void cmd_ls(int argc, char **argv) 260 { 261 struct dirent *file; 262 char *path; 263 DIR *dir; 264 265 if (argc == 1) { 326 //////////////////////////////////////////// 327 static void cmd_ls( int argc , char **argv ) 328 { 329 char * path; 330 331 // struct dirent * file; 332 // DIR *dir; 333 334 if (argc == 1) 335 { 266 336 path = "."; 267 } else if (argc == 2) { 337 } 338 else if (argc == 2) 339 { 268 340 path = argv[1]; 269 } else { 341 } 342 else 343 { 270 344 printf("usage: ls [path]\n"); 271 345 return; 272 346 } 273 347 274 dir = opendir(path); 348 printf("error: not implemented yet\n"); 349 /* 350 dir = opendir( path ); 275 351 while ((file = readdir(dir)) != NULL) 276 352 { … … 278 354 } 279 355 closedir(dir); 280 } 281 282 static void cmd_mkdir(int argc, char **argv) 283 { 284 char *path; 285 286 if (argc != 2) { 356 */ 357 } 358 359 /////////////////////////////////////////////// 360 static void cmd_mkdir( int argc , char **argv ) 361 { 362 char * pathname; 363 364 if (argc != 2) 365 { 287 366 printf("usage: mkdir pathname\n"); 288 367 return; 289 368 } 290 369 291 path = argv[1]; 292 293 if (mkdir(path, 0700) == -1) { 370 pathname = argv[1]; 371 372 printf("error: not implemented yet\n"); 373 /* 374 if ( mkdir( path, 0x700) == -1 ) 375 { 294 376 printf("error: cannot create directory %s\n", path); 295 377 } 296 } 297 298 static void cmd_mv(int argc, char **argv) 299 { 300 #if 0 378 */ 379 } 380 381 //////////////////////////////////////////// 382 static void cmd_mv( int argc , char **argv ) 383 { 384 301 385 if (argc < 3) 302 386 { … … 305 389 } 306 390 391 printf("error: not implemented yet\n"); 392 393 /* 307 394 int ret = giet_fat_rename(argv[1], argv[2]); 308 395 if (ret < 0) … … 310 397 printf("error : cannot move %s to %s / err = %d\n", argv[1], argv[2], ret ); 311 398 } 312 #endif 313 } 314 315 static void cmd_rm(int argc, char **argv) 316 { 317 char *path; 318 319 if (argc != 2) { 399 */ 400 401 } 402 403 ///////////////////////////////////////////// 404 static void cmd_pwd( int argc , char **argv ) 405 { 406 char buf[1024]; 407 408 if (argc != 1) 409 { 410 printf("usage: pwd\n"); 411 return; 412 } 413 414 if ( getcwd( buf , 1024 ) ) 415 { 416 printf("error: unable to get current directory\n"); 417 } 418 else 419 { 420 printf("%s\n", buf); 421 } 422 } 423 424 //////////////////////////////////////////// 425 static void cmd_rm( int argc , char **argv ) 426 { 427 char * pathname; 428 429 if (argc != 2) 430 { 320 431 printf("usage: rm pathname\n"); 321 432 return; 322 433 } 323 434 324 path = argv[1]; 325 326 if (remove(path) == -1) { 435 pathname = argv[1]; 436 437 printf("error: not implemented yet\n"); 438 /* 439 if (remove(path) == -1) 440 { 327 441 printf("error: cannot remove %s\n", path); 328 442 } 329 } 330 331 static void cmd_rmdir(int argc, char **argv) 443 */ 444 445 } 446 447 /////////////////////////////////////////////// 448 static void cmd_rmdir( int argc , char **argv ) 332 449 { 333 450 cmd_rm(argc, argv); 334 451 } 335 452 336 static void cmd_cd(int argc, char **argv) 337 { 338 char *path; 339 340 if (argc != 2) { 341 printf("usage: cd pathname\n"); 342 return; 343 } 344 345 path = argv[1]; 346 347 if (chdir(path) == -1) { 348 printf("error: cannot cd to %s\n", path); 349 } 350 } 351 352 static void cmd_pwd(int argc, char **argv) 353 { 354 char buf[1024]; 355 356 if (argc != 1) { 357 printf("usage: pwd\n"); 358 return; 359 } 360 361 if (getcwd(buf, 1024) == NULL) { 362 printf("error: unable to get current directory\n"); 363 } else { 364 printf("%s\n", buf); 365 } 366 } 367 368 struct command_t cmd[] = 369 { 370 { "cat", "display file content", cmd_cat }, 371 { "cd", "change current directory", cmd_cd }, 372 { "cp", "replicate a file in file system", cmd_cp }, 373 { "exec", "start an application", cmd_exec }, 374 { "help", "list available commands", cmd_help }, 375 { "kill", "kill an application (all threads)", cmd_kill }, 376 { "log", "list registered commands", cmd_log }, 377 { "ls", "list directory entries", cmd_ls }, 453 /////////////////////////////////////////////// 454 static void cmd_sched( int argc , char **argv ) 455 { 456 unsigned int cxy; 457 unsigned int lid; 458 459 if (argc != 3) 460 { 461 printf("usage: sched cxy lid\n"); 462 return; 463 } 464 465 cxy = atoi(argv[1]); 466 lid = atoi(argv[2]); 467 468 if( get_sched( cxy , lid ) ) 469 { 470 printf("error: illegal arguments\n"); 471 } 472 } 473 474 ////////////////////////////////////////////////////////////////// 475 // Array of commands 476 ////////////////////////////////////////////////////////////////// 477 478 ksh_cmd_t cmd[] = 479 { 480 { "cat", "display file content", cmd_cat }, 481 { "cd", "change current directory", cmd_cd }, 482 { "cp", "replicate a file in file system", cmd_cp }, 483 { "load", "load an user application", cmd_load }, 484 { "help", "list available commands", cmd_help }, 485 { "kill", "kill an application (all threads)", cmd_kill }, 486 { "log", "list registered commands", cmd_log }, 487 { "ls", "list directory entries", cmd_ls }, 378 488 { "mkdir", "create a new directory", cmd_mkdir }, 379 { "mv", "move a file in file system", cmd_mv },380 { "pwd", "print current working directory", cmd_pwd },381 { "rm", "remove a file from file system", cmd_rm },489 { "mv", "move a file in file system", cmd_mv }, 490 { "pwd", "print current working directory", cmd_pwd }, 491 { "rm", "remove a file from file system", cmd_rm }, 382 492 { "rmdir", "remove a directory from file system", cmd_rmdir }, 383 { NULL, NULL, NULL } 493 { "sched", "display scheduler state", cmd_sched }, 494 { NULL, NULL, NULL } 384 495 }; 385 496 386 /////////////////////////////////////////////////////////////////// 387 // This function analyses one command (with arguments) 388 /////////////////////////////////////////////////////////////////// 497 //////////////////////////////////////////////////////////////////////////////////// 498 // This function analyses one command (with arguments), execute it, and return. 499 //////////////////////////////////////////////////////////////////////////////////// 389 500 static void parse(char *buf) 390 501 { … … 395 506 396 507 // build argc/argv 397 for (i = 0; i < len; i++) { 398 if (buf[i] == ' ') { 508 for (i = 0; i < len; i++) 509 { 510 if (buf[i] == ' ') 511 { 399 512 buf[i] = '\0'; 400 } else if (i == 0 || buf[i - 1] == '\0') { 401 if (argc < MAX_ARGS) { 513 } 514 else if (i == 0 || buf[i - 1] == '\0') 515 { 516 if (argc < MAX_ARGS) 517 { 402 518 argv[argc] = &buf[i]; 403 519 argc++; … … 406 522 } 407 523 408 if (argc > 0) { 524 if (argc > 0) 525 { 409 526 int found = 0; 410 527 411 528 argv[argc] = NULL; 412 529 413 // try to match typed command with built-ins 414 for (i = 0; cmd[i].name; i++) { 415 if (strcmp(argv[0], cmd[i].name) == 0) { 530 // try to match typed command 531 for (i = 0; cmd[i].name; i++) 532 { 533 if (strcmp(argv[0], cmd[i].name) == 0) 534 { 416 535 cmd[i].fn(argc, argv); 417 536 found = 1; … … 420 539 } 421 540 422 if (!found) { 541 if (!found) 542 { 423 543 printf("\n undefined command %s\n", argv[0]); 424 544 } … … 426 546 } 427 547 428 int main(int argc, char *argv[]) 429 { 430 char c; // read character 431 char buf[MAX_SIZE]; // buffer for one command432 size_t count = 0; // pointer in buf433 size_t i, j; // indexes for loops434 __unused(argc);435 __unused(argv); 436 437 enum fsm_states{548 /////////////////////////////////// 549 int main( int argc , char *argv[] ) 550 { 551 char c; // read character 552 char buf[CMD_MAX_SIZE]; // buffer for one command 553 unsigned int count = 0; // pointer in buf 554 unsigned int i; // index for loops 555 556 enum fsm_states 557 { 438 558 NORMAL, 439 559 ESCAPE, … … 441 561 }; 442 562 443 memset(&log_entries, 0, sizeof(log_entries)); 444 ptw = 0; 445 ptr = 0; 563 // log buffer initialisation 564 memset( &log_entries , 0, sizeof(log_entries)); 565 ptw = 0; 566 ptr = 0; 446 567 447 568 printf( "~~~ shell ~~~\n\n" ); 448 569 449 570 // command buffer initialisation 450 memset( buf, 0x20, sizeof(buf));571 memset( buf, 0x20 , sizeof(buf) ); 451 572 count = 0; 452 573 … … 460 581 // - ESC [ C : right arrow 461 582 // - ESC [ D : left arrow 462 // The th ee states have the following semantic:583 // The three states have the following semantic: 463 584 // - NORMAL : no (ESC) character has been found 464 585 // - ESCAPE : the character (ESC) has been found … … 466 587 unsigned int state = NORMAL; 467 588 589 // @@@ 590 parse("load /bin/user/sort.elf"); 591 // @@@ 592 468 593 while (1) 469 594 { 470 /* 471 * Certainly not a good idea to use getchar. The escape sequences won't 472 * be handled correctly. 473 */ 474 c = getchar(); 595 c = (char)getchar(); 596 597 if( c == 0 ) continue; 475 598 476 599 switch (state)
Note: See TracChangeset
for help on using the changeset viewer.