Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. /* write_terminal(int32_tfd, const void*buf, int32_t nbytes)
  2. * DESCRIPTION: Should output a string to the terminal
  3. * INPUTS: file descriptor, buffer, and number of bytes read from buffer
  4. * OUTPUTS: Number of bytes written or -1 on fail
  5. */
  6. int32_t write_terminal(int32_t fd, const void * buf, int32_t nbytes){
  7. int32_t written=0; int32_t i=0;
  8. //create temp buffer of size of 1 byte
  9. uint8_t *temp_buf=(uint8_t *)buf;
  10. int count;
  11.  
  12. // check if we previously have had 19 bytes (Starting 391 SHell\n)
  13. // also check if we have printed 1 instance of 391OS>
  14. if(prev_nbytes==LEN_PROMPT && prev_buf[0]=='S' && prev_buf[1]=='t' && _391OS_count==1){
  15. _391OS_count=0; // reset the flags
  16. return 0;
  17. }
  18. else{
  19. _391OS_count=1; // reset the flags
  20. }
  21.  
  22. // if buff is NULL or nothing to be copied or less than 0 is requested copy, return
  23. if(buf==NULL || nbytes<0){
  24. return -1;
  25. }
  26. //cli();
  27. for(i=0; i<nbytes; i++){
  28. //print each character starting from index 0 to nbytes
  29. putc(temp_buf[i]);
  30. position(0,0,1);
  31. written++;
  32. }
  33. //sti();
  34. if(nbytes==written){
  35. // make sure to copy the right number of bytes to the prev_buf for checking
  36. // and not to overflow it
  37. if(nbytes<LEN_PROMPT){
  38. count=nbytes;
  39. }
  40. else{
  41. count=LEN_PROMPT;
  42. }
  43. // update the prev_buf to contain whatever was last entered
  44. for(i=0; i<count; i++){
  45. prev_buf[i]=temp_buf[i];
  46. }
  47. prev_nbytes=nbytes; // update prev_nbytes
  48. return nbytes;
  49. }
  50. else{
  51. prev_nbytes=-1;
  52. return -1;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement