void consoleintr(int (*getc)(void)) { int c; acquire(&input.lock); while((c = getc()) >= 0){ switch(c){ case C('P'): // Process listing. procdump(); break; case C('U'): // Kill line. while(input.e != input.w && input.buf[(input.e-1) % INPUT_BUF] != '\n'){ input.e--; consputc(BACKSPACE); } break; case C('H'): case '\x7f': // Backspace if(input.e != input.w){ input.e--; consputc(BACKSPACE); } break; case 'C': input.w = input.e; input.buf[input.e++ % INPUT_BUF] = 'c'; input.w = input.e; wakeup(&input.r); break; case 'Q': input.w = input.e; input.buf[input.e++ % INPUT_BUF] = 'q'; input.w = input.e; wakeup(&input.r); break; default: if(c != 0 && input.e-input.r < INPUT_BUF){ c = (c == '\r') ? '\n' : c; input.buf[input.e++ % INPUT_BUF] = c; consputc(c); if(c == '\n' || c == C('D') || input.e == input.r+INPUT_BUF){ input.w = input.e; wakeup(&input.r); } } break; } } release(&input.lock); }
void noprocpanic(char *msg) { /* * setting exiting will make hzclock() on each processor call exit(0). * clearing our bit in machs avoids calling exit(0) from hzclock() * on this processor. */ lock(&active); active.machs &= ~(1<<m->machno); active.exiting = 1; unlock(&active); procdump(); delay(1000); panic(msg); }
void consoleintr(int (*getc)(void)) { int c, doprocdump = 0; acquire(&cons.lock); while((c = getc()) >= 0){ switch(c){ case C('P'): // Process listing. // procdump() locks cons.lock indirectly; invoke later doprocdump = 1; break; case C('U'): // Kill line. while(input.e != input.w && input.buf[(input.e-1) % INPUT_BUF] != '\n'){ input.e--; consputc(BACKSPACE); } break; case C('H'): case '\x7f': // Backspace if(input.e != input.w){ input.e--; consputc(BACKSPACE); } break; default: if(c != 0 && input.e-input.r < INPUT_BUF){ c = (c == '\r') ? '\n' : c; input.buf[input.e++ % INPUT_BUF] = c; consputc(c); if(c == '\n' || c == C('D') || input.e == input.r+INPUT_BUF){ input.w = input.e; wakeup(&input.r); } } break; } } release(&cons.lock); if(doprocdump) { procdump(); // now call procdump() wo. cons.lock held } }
void consoleintr(int (*getc)(void)) { int c; acquire(&input.lock); while((c = getc()) >= 0){ switch(c){ case C('P'): // Process listing. procdump(); break; case C('U'): // Kill line. while(input.e != input.w && input.buf[(input.e-1) % INPUT_BUF] != '\n'){ input.e--; consputc(BACKSPACE); } break; case C('H'): case '\x7f': // Backspace if(input.f != input.w){ input.e--; input.f--; consputc(BACKSPACE); } break; case KEY_LF: // Key Left { if(input.f != input.w) { input.f--; cgaputc(KEY_LF); } break; } case KEY_RT: // Key Right { int IsCanRight = input.e - input.f; if(IsCanRight > 0) { input.f++; cgaputc(KEY_RT); } break; } case KEY_UP: // Key Up { int NextHistoryPos = (HistoryPos + MAX_HISTORY_LENGTH - 1) % MAX_HISTORY_LENGTH; if(NextHistoryPos < MaxHistoryPos) { HistoryPos = NextHistoryPos; SelectFromHistory(); } break; } case KEY_DN: // Key Down { if(HistoryPos < MaxHistoryPos) { HistoryPos = (HistoryPos + 1) % MAX_HISTORY_LENGTH; SelectFromHistory(); } break; } default: if(c != 0 && input.e-input.r < INPUT_BUF) { c = (c == '\r') ? '\n' : c; if(c == '\n' || c == C('D') || input.e == input.r+INPUT_BUF) { // Insert Command To History if(input.e > input.w) // if command exist { int j; for(j = 0; input.w+j<input.e; ++j) { History[HistoryWrite][j] = input.buf[(input.w +j) % INPUT_BUF]; } History[HistoryWrite][j] = '\0'; HistoryWrite = (HistoryWrite + 1) % MAX_HISTORY_LENGTH; MaxHistoryPos = (MaxHistoryPos == MAX_HISTORY_LENGTH) ? MAX_HISTORY_LENGTH : (MaxHistoryPos + 1); HistoryPos = HistoryWrite; } input.buf[input.e++ % INPUT_BUF] = c; input.f = input.e; consputc(c); input.w = input.e; wakeup(&input.r); } else { input.buf[input.f++ % INPUT_BUF] = c; if(input.f > input.e) { input.e = input.f; } consputc(c); } } break; } // cprintf("buf %s, read %d, write %d, edit %d\n final %d\n",input.buf,input.r,input.w,input.e, input.f); } release(&input.lock); }
void consoleintr(int (*getc)(void)) { int c; int i; acquire(&input.lock); while((c = getc()) >= 0){ switch(c){ case C('P'): // Process listing. procdump(); break; case C('U'): // Kill line. while(input.e != input.w && input.buf[(input.e-1) % INPUT_BUF] != '\n'){ input.e--; consputc(BACKSPACE); } break; case C('H'): case '\x7f': // Backspace if(input.e != input.w){ input.e--; consputc(BACKSPACE); //added roy -> shift all the chars back when backspace used within the buffer if(left_count>0){ for( i=0 ; i<=left_count; i++ ){ input.buf[input.e+i % INPUT_BUF]= input.buf[input.e+i+1 % INPUT_BUF]; } } } break; //added roy case RIGHT: if(left_count>0){ move_cursor(1); left_count--; } break; //added roy case LEFT: if(input.e != input.w){ left_count++; move_cursor(-1); } break; //changed roy-> updated buffer allows to insert/remove chars within the buffer, (memory) default: if(c != 0 && input.e-input.r < INPUT_BUF){ c = (c == '\r') ? '\n' : c; consputc(c); if(c == '\n' || c == C('D') || input.e == input.r+INPUT_BUF){ input.e= input.e+left_count; input.buf[input.e++ % INPUT_BUF] = c; input.w = input.e; left_count=0; wakeup(&input.r); }else{ if(left_count>0){ for( i=0 ; i<=left_count; i++ ){ input.buf[input.e+(left_count-i)+1 % INPUT_BUF]= input.buf[input.e+(left_count-i) % INPUT_BUF]; } } input.buf[input.e++ % INPUT_BUF] = c; } } break; } } release(&input.lock); }
int sys_getpinfo(void){ //this calls something else that I may or may not quite understand procdump(); return 0; }
static void echo(char *buf, int n) { static int ctrlt, pid; char *e, *p; if (n == 0) return; e = buf + n; for (p = buf; p < e; p++) { switch (*p) { #if 0 case 0x10: /* ^P */ if (cpuserver && !kbd.ctlpoff) { active.exiting = 1; return; } break; #endif case 0x14: /* ^T */ ctrlt++; if (ctrlt > 2) ctrlt = 2; continue; } if (ctrlt != 2) continue; /* ^T escapes */ ctrlt = 0; switch (*p) { #if 0 case 'S': { int8_t x = 0; disable_irqsave(&x); dumpstack(); procdump(); enable_irqsave(&x); return; } #endif case 's': dumpstack(); return; #if 0 case 'x': xsummary(); ixsummary(); mallocsummary(); memorysummary(); pagersummary(); return; case 'd': if (consdebug == NULL) consdebug = rdb; else consdebug = NULL; printd("consdebug now %#p\n", consdebug); return; case 'D': if (consdebug == NULL) consdebug = rdb; consdebug(); return; case 'p': x = spllo(); procdump(); splx(x); return; case 'q': scheddump(); return; case 'k': killbig("^t ^t k"); return; #endif case 'r': exit(0); return; } } qproduce(kbdq, buf, n); if (kbd.raw) return; kmesgputs(buf, n); if (screenputs != NULL) echoscreen(buf, n); if (serialoq) echoserialoq(buf, n); }
void consoleintr(int (*getc)(void)) { int c, doprocdump = 0; // int historyInd = 1; //when arr not full we should put here the last command written, most cases, when full davka should be 15 acquire(&cons.lock); int tmp; while ((c = getc()) >= 0) { switch (c) { case C('P'): // Process listing. doprocdump = 1; // procdump() locks cons.lock indirectly; invoke later break; case C('U'): // Kill line. kill_line(); break; case C('H'): case '\x7f': // Backspace if (input.e != input.w) { //regular caret input.e--; input.f--; if (input.e < input.f) { // middle caret midflag = input.f - input.e; int i = input.e; while (i < input.f) { input.buf[i % INPUT_BUF] = input.buf[(i + 1) % INPUT_BUF]; i++; } } consputc(BACKSPACE); midflag = 0; } break; case KEY_LEFT: // Left arrow if (input.e != input.w) { input.e--; consputc(KEY_LEFT); } break; case KEY_RIGHT: // Right arrow if (input.f > input.e) { input.e++; consputc(KEY_RIGHT); } break; case KEY_UP: // Key Up if (historyInd != 0) kill_line(); if (historyList.size > 0) { char buffer[INPUT_BUF]; tmp = (historyInd - 1) % historyList.size; if (tmp > -1) { historyInd = tmp; if (history(buffer, historyInd) == 0) { setHistory(buffer); } else panic("history"); } } break; case KEY_DOWN: // Key Down kill_line(); if (historyInd < historyList.size - 1) { char buffer[INPUT_BUF]; historyInd = (historyInd + 1) % MAX_HISTORY; if (historyInd < historyList.size) { if (history(buffer, historyInd) == 0) { setHistory(buffer); } else panic("history"); } else kill_line(); } else if (historyInd == historyList.size - 1) kill_line(); break; default: if (c != 0 && input.f - input.r < INPUT_BUF) { c = (c == '\r') ? '\n' : c; if (c == '\n') { // if any command is currently written, first record it in the history books if (input.f >= input.w) { updateHistory(); } } //*** regular caret *** if (input.e >= input.f) { input.buf[input.e++ % INPUT_BUF] = c; consputc(c); } //*** middle caret *** else { if (c == '\n') { input.buf[input.f % INPUT_BUF] = c; input.e = input.f + 1; consputc(c); } else { int index = input.f; while (index > input.e) { // first shift by one each char in buffer from caret to the end input.buf[index % INPUT_BUF] = input.buf[(index - 1) % INPUT_BUF]; index--; } input.buf[input.e % INPUT_BUF] = c; // Write new char in buffer int i = input.e; index = input.f + 1; while (i < index) // Print those chars from buffer to console consputc(input.buf[i++ % INPUT_BUF]); i = input.e; index = input.f; while (i < index) { // move caret back to it's place after the new character consputc(KEY_LEFT); i++; } input.e++; } } input.f++; if (c == '\n' || c == C('D') || input.f == input.r + INPUT_BUF) { input.w = input.f; input.e = input.f; wakeup(&input.r); } } break; } } release(&cons.lock); if (doprocdump) { procdump(); // now call procdump() wo. cons.lock held } }
void consoleintr(int (*getc)(void)) { int i,j; int c; acquire(&input.lock); while((c = getc()) >= 0){ switch(c){ case C('P'): // Process listing. procdump(); break; case C('U'): // Kill line. while(input.e != input.w && input.buf[(input.e-1) % INPUT_BUF] != '\n'){ input.e--; input.rm--; consputc(BACKSPACE); } break; //------------------- PATCH ------------------// case C('H'): case '\x7f': // Backspace if(input.e != input.w){ consputc(BACKSPACE); input.e--; input.rm--; if(input.e < input.rm){ //if cursor is not at end of sentance for (i=input.e; i<=input.rm; i++){ input.buf[i % INPUT_BUF] = input.buf[i+1 %INPUT_BUF]; } for(i = input.e; i <=input.rm; i++) consputc(input.buf[i %INPUT_BUF]); for(i = input.e; i <=input.rm; ++i) consputc(LEFTARROW); } } break; case UPARROW: if(numOentries >= MAX_HISTORY_LENGTH){ if(input.w < input.rm){ for(i=input.e ; i<=input.rm; i++){ consputc(RIGHTARROW); } for(i=input.rm ; i>=input.w; i--){ consputc(BACKSPACE); } input.e = input.w; input.rm = input.e; } hstryPos--; if (hstryPos < 0){ // if hstrypos is under zero hstryPos = MAX_HISTORY_LENGTH -1; } for(i = input.w,j=0; j<(strlen(history[hstryPos % MAX_HISTORY_LENGTH])); i++,j++){ input.buf[i] = history[hstryPos % MAX_HISTORY_LENGTH][j]; } j = strlen(history[hstryPos % MAX_HISTORY_LENGTH]); input.e += j; input.rm = input.e; for(i = input.w; i< input.e; i++){ consputc(input.buf[i]); } } else{ if((hstryPos % MAX_HISTORY_LENGTH) > 0){ if(input.w < input.rm){ for(i=input.e ; i<=input.rm; i++){ consputc(RIGHTARROW); } for(i=input.rm ; i>=input.w; i--){ consputc(BACKSPACE); } input.e = input.w; input.rm = input.e; } hstryPos--; for(i = input.w,j=0; j<(strlen(history[hstryPos % MAX_HISTORY_LENGTH])); i++,j++){ input.buf[i] = history[hstryPos % MAX_HISTORY_LENGTH][j]; } j = strlen(history[hstryPos % MAX_HISTORY_LENGTH]); input.e += j; input.rm = input.e; for(i = input.w; i< input.e; i++){ consputc(input.buf[i]); } } } break; case DOWNARROW: if(numOentries >= MAX_HISTORY_LENGTH){ if(input.w < input.rm){ for(i=input.rm ; i>input.w; i--){ consputc(BACKSPACE); } input.e = input.w; input.rm = input.e; } hstryPos++; if (hstryPos == MAX_HISTORY_LENGTH){ hstryPos = 0; } for(i = input.w,j=0; j<(strlen(history[hstryPos % MAX_HISTORY_LENGTH])); i++,j++){ input.buf[i] = history[hstryPos % MAX_HISTORY_LENGTH][j]; } j = strlen(history[hstryPos % MAX_HISTORY_LENGTH]); input.e += j; input.rm = input.e; for(i = input.w; i< input.e; i++){ consputc(input.buf[i]); } } else{ if((hstryPos % MAX_HISTORY_LENGTH) < (hstryNext % MAX_HISTORY_LENGTH)){ if(input.w < input.rm){ for(i=input.rm ; i>input.w; i--){ consputc(BACKSPACE); } input.e = input.w; input.rm = input.e; } hstryPos++; for(i = input.w,j=0; j<(strlen(history[hstryPos % MAX_HISTORY_LENGTH])); i++,j++){ input.buf[i] = history[hstryPos % MAX_HISTORY_LENGTH][j]; } j = strlen(history[hstryPos % MAX_HISTORY_LENGTH]); input.e += j; input.rm = input.e; for(i = input.w; i< input.e; i++){ consputc(input.buf[i]); } } } break; case RIGHTARROW: if(input.e < input.rm){ input.e++; consputc(RIGHTARROW); } break; case LEFTARROW: if(input.e != input.w){ input.e--; consputc(LEFTARROW); } break; //------------------- PATCH ------------------// default: if(c != 0 && input.e-input.r < INPUT_BUF){ c = (c == '\r') ? '\n' : c; if((c == '\n')&&(input.e<input.rm)){ // case of enter in mid of sentance input.e = input.rm; input.buf[input.e++ % INPUT_BUF] = c; consputc(c); //cprintf("buf enter after left:%s\n",input.buf); }else{ for (i=input.rm; i>input.e; i--){ //put letter in middle of sentance input.buf[i % INPUT_BUF] = input.buf[i-1 %INPUT_BUF]; } input.buf[input.e++ % INPUT_BUF] = c; consputc(c); for(i = input.e; i <= input.rm; ++i) consputc(input.buf[i]); input.rm++; for(i = input.e; i < input.rm; ++i) consputc(LEFTARROW); } if(c == '\n' || c == C('D') || input.e == input.r+INPUT_BUF){ //cprintf("buf:%s\n",input.buf); input.w = input.e; input.rm = input.e; // j =0; char command[INPUT_BUF]; memset(&command[0], 0, sizeof(command)); for (i=input.r; i < input.rm-1; i++) { command[j] = input.buf[i %INPUT_BUF]; j++; //cprintf("buf:%s\n",input.buf); } // cprintf("command is:%s",command); //command[j-1] = '\n'; if (command[0] != '\0'){ // cprintf("command:'%s'\n",command); strncpy(history[hstryNext % MAX_HISTORY_LENGTH],command,strlen(command)); hstryNext = ((hstryNext+1) % MAX_HISTORY_LENGTH); hstryPos = hstryNext; numOentries++; } //cprintf("next:%d\n",hstryNext); // for (i=0; i < hstryNext; i++) { // cprintf("history:%s\n",history[i]); // } wakeup(&input.r); } } break; } } release(&input.lock); }
//print a list of process and their states int sys_procstat(void) { procdump(); return 0; }
void echo(char *buf, int n) { static int ctrlt; int x; char *e, *p; if(n == 0) return; e = buf+n; for(p = buf; p < e; p++){ switch(*p){ case 0x10: /* ^P */ if(cpuserver && !kbd.ctlpoff){ active.exiting = 1; return; } break; case 0x14: /* ^T */ ctrlt++; if(ctrlt > 2) ctrlt = 2; continue; } if(ctrlt != 2) continue; /* ^T escapes */ ctrlt = 0; switch(*p){ case 'S': x = splhi(); dumpstack(); procdump(); splx(x); return; case 's': dumpstack(); return; case 'x': xsummary(); ixsummary(); mallocsummary(); // memorysummary(); pagersummary(); return; case 'd': if(consdebug == nil) consdebug = rdb; else consdebug = nil; print("consdebug now 0x%p\n", consdebug); return; case 'D': if(consdebug == nil) consdebug = rdb; consdebug(); return; case 'p': x = spllo(); procdump(); splx(x); return; case 'q': scheddump(); return; case 'k': killbig("^t ^t k"); return; case 'r': exit(0); return; } } qproduce(kbdq, buf, n); if(kbd.raw) return; kmesgputs(buf, n); if(screenputs != nil) echoscreen(buf, n); uartecho(buf, n); // Plan 9 VX }