/* * Enter 16-bit integer value, 5 digits. */ unsigned short get_short (unsigned short init_val) { small_uint_t i, first_touch, cmd; unsigned long val; printf (&debug, "%d", init_val); if (init_val > 9999) i = 5; else if (init_val > 999) i = 4; else if (init_val > 99) i = 3; else if (init_val > 9) i = 2; else if (init_val > 0) i = 1; else { i = 0; putchar (&debug, '\b'); } first_touch = 1; val = init_val; for (;;) { cmd = getchar (&debug); if (cmd >= '0' && cmd <= '9') { if (first_touch) { first_touch = 0; while (i-- > 0) puts (&debug, "\b \b"); i = 0; val = 0; } if (i == 5) { err: putchar (&debug, 7); continue; } val = val * 10 + cmd - '0'; if (val > 0xffff) { val /= 10; goto err; } putchar (&debug, cmd); ++i; continue; } first_touch = 0; if (cmd == CTL('[') || cmd == '[') continue; if (cmd == CTL('C')) return init_val; if (cmd == '\n' || cmd == '\r') return val; if (cmd == CTL('H') || cmd == 0177) { if (i == 0) goto err; printf (&debug, "\b \b"); --i; val /= 10; continue; } goto err; } }
int sh(char *tty) { int fd; char *arg0; char *args[2] = { NULL, NULL }; size_t len; struct termios term; /* Detach from initial controlling TTY */ vhangup(); fd = open(tty, O_RDWR); if (fd < 0) err(1, "Failed opening %s", tty); dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); if (ioctl(STDIN_FILENO, TIOCSCTTY, 1) < 0) warn("Failed TIOCSCTTY"); /* The getty process is usually responsible for the UTMP login record */ utmp_set_login(tty, NULL); /* Set up TTY, re-enabling ISIG et al. */ stty(fd, B0); close(fd); /* Start /bin/sh as a login shell, i.e. with a prefix '-' */ len = strlen(_PATH_BSHELL) + 2; arg0 = malloc(len); if (!arg0) err(1, "Failed allocating memory"); snprintf(arg0, len, "-%s", _PATH_BSHELL); args[0] = arg0; /* Reenable Ctrl-D and Ctrl-C, and ... */ if (!tcgetattr(STDIN_FILENO, &term)) { term.c_lflag |= ISIG; term.c_cc[VEOF] = CTL('D'); term.c_cc[VINTR] = CTL('C'); tcsetattr(STDIN_FILENO, TCSANOW, &term); } /* ... unblock signals in general */ sig_unblock(); return execv(_PATH_BSHELL, args); }
/* * Read a character from the terminal */ int screen_getc(void) { int c; c = getch(); switch (c) { case PADSLASH: c = OP_DIV; break; case PADSTAR: c = OP_MUL; break; case PADPLUS: c = OP_ADD; break; case PADMINUS: c = OP_SUB; break; case PADENTER: c = '\n'; break; #ifdef KEY_RESIZE case KEY_RESIZE: set_screensize(); ungetch(CTL('L')); break; #endif } return (c); }
inline void LocalTrrkKernel ( UpperOrLower uplo, Orientation orientationOfA, Orientation orientationOfB, T alpha, const DistMatrix<T,STAR,MC >& A, const DistMatrix<T,MR, STAR>& B, T beta, DistMatrix<T,MC, MR >& C ) { #ifndef RELEASE PushCallStack("LocalTrrkKernel"); CheckInput( orientationOfA, orientationOfB, A, B, C ); #endif const Grid& g = C.Grid(); DistMatrix<T,STAR,MC> AL(g), AR(g); DistMatrix<T,MR,STAR> BT(g), BB(g); DistMatrix<T,MC,MR> CTL(g), CTR(g), CBL(g), CBR(g); DistMatrix<T,MC,MR> DTL(g), DBR(g); const int half = C.Height()/2; ScaleTrapezoid( beta, LEFT, uplo, 0, C ); LockedPartitionRight( A, AL, AR, half ); LockedPartitionDown ( B, BT, BB, half ); PartitionDownDiagonal ( C, CTL, CTR, CBL, CBR, half ); DTL.AlignWith( CTL ); DBR.AlignWith( CBR ); DTL.ResizeTo( CTL.Height(), CTL.Width() ); DBR.ResizeTo( CBR.Height(), CBR.Width() ); //------------------------------------------------------------------------// if( uplo == LOWER ) internal::LocalGemm ( orientationOfA, orientationOfB, alpha, AR, BT, T(1), CBL ); else internal::LocalGemm ( orientationOfA, orientationOfB, alpha, AL, BB, T(1), CTR ); internal::LocalGemm ( orientationOfA, orientationOfB, alpha, AL, BT, T(0), DTL ); AxpyTriangle( uplo, T(1), DTL, CTL ); internal::LocalGemm ( orientationOfA, orientationOfB, alpha, AR, BB, T(0), DBR ); AxpyTriangle( uplo, T(1), DBR, CBR ); //------------------------------------------------------------------------// #ifndef RELEASE PopCallStack(); #endif }
int v_setmodefixed(struct v_board_t *board) { int iob=board->io_base; int tmp; #ifdef SAVEVGA v_savetextmode(board); #endif v1k_softreset(board); /* switching to native mode */ v_out8(iob+MODEREG, NATIVE_MODE); /* flipping some bytes */ v_out8(iob+MEMENDIAN, MEMENDIAN_HW); /* try programming 1024x768@70 in highcolor */ tmp=v_in32(iob+DRAMCTL)&0xdfff; /* reset bit 13 */ v_out32(iob+DRAMCTL, tmp|DEFAULT_WREFRESH); /* program pixel clock */ if (board->chip == V1000_DEVICE) { set_PLL(iob, combineNMP(21, 55, 0)); } else { tmp = (~0x1800) & v_in32(iob+DRAMCTL); v_out32(iob+DRAMCTL, tmp); v_out32(iob+PCLKPLL, v2kcombineNMP(2, 21, 2)); } usleep(500); v_initdac(board, 16, 0); v_out32(iob+CRTCHORZ, HORZ(24, 136, 144, 1024)); v_out32(iob+CRTCVERT, VERT(3, 6, 29, 768)); board->mode.screenwidth=1024; board->mode.virtualwidth=1024; board->mode.bitsperpixel=16; board->mode.fifosize=128; board->init=1; v_setframebase(board, 0); v_out32(iob+CRTCCTL, CTL(0, 0, 0) |V_PIXFMT_565 |CRTCCTL_VIDEOFIFOSIZE128 |CRTCCTL_HSYNCENABLE |CRTCCTL_VSYNCENABLE |CRTCCTL_VIDEOENABLE); return 0; }
void throttleAllCPUs(PState* p) { dbg("Starting throttle with CTL 0x%x\n", CTL(p->Frequency, p->Voltage)); IOSimpleLockLock(Lock); mp_rendezvous(disableInterrupts, throttleCPU, enableInterrupts, p); IODelay(p->Latency); // maybe wait longer? totalThrottles++; IOSimpleLockUnlock(Lock); dbg("Throttle done.\n"); }
static void kbinitmap(VOID) { (void)Memset((void*)&keymap[0],(int)KEYBOARD_UNKNOWN,sizeof(keymap)); keymap[(unsigned)'b'] = KEYBOARD_PGUP; keymap[(unsigned)'B'] = KEYBOARD_PGUP; keymap[(unsigned)META('V')] = KEYBOARD_PGUP; /* Emacs scroll-down */ keymap[(unsigned)'\r'] = KEYBOARD_DOWN; /* the less and more pagers bind */ keymap[(unsigned)'\n'] = KEYBOARD_DOWN; /* these keys to KEYBOARD_DOWN */ keymap[(unsigned)'d'] = KEYBOARD_DOWN; keymap[(unsigned)'D'] = KEYBOARD_DOWN; keymap[(unsigned)CTL('N')] = KEYBOARD_DOWN; /* Emacs next-line*/ keymap[(unsigned)'e'] = KEYBOARD_END; keymap[(unsigned)'E'] = KEYBOARD_END; keymap[(unsigned)META('>')] = KEYBOARD_END; /* Emacs end-of-buffer */ keymap[(unsigned)'>'] = KEYBOARD_END; keymap[(unsigned)'f'] = KEYBOARD_PGDN; keymap[(unsigned)'F'] = KEYBOARD_PGDN; keymap[(unsigned)' '] = KEYBOARD_PGDN; keymap[(unsigned)CTL('V')] = KEYBOARD_PGDN; /* Emacs scroll-up */ keymap[(unsigned)'h'] = KEYBOARD_HELP; keymap[(unsigned)'H'] = KEYBOARD_HELP; keymap[(unsigned)'?'] = KEYBOARD_HELP; keymap[(unsigned)CH_BACKSPACE] = KEYBOARD_HELP; /* Emacs help */ keymap[(unsigned)CH_ESCAPE] = KEYBOARD_QUIT; /* ESCape gets out */ keymap[(unsigned)'q'] = KEYBOARD_QUIT; keymap[(unsigned)'Q'] = KEYBOARD_QUIT; keymap[(unsigned)'.'] = KEYBOARD_AGAIN; keymap[(unsigned)'r'] = KEYBOARD_AGAIN; keymap[(unsigned)'R'] = KEYBOARD_AGAIN; keymap[(unsigned)CTL('L')] = KEYBOARD_AGAIN; /* Emacs recenter */ keymap[(unsigned)'t'] = KEYBOARD_HOME; keymap[(unsigned)'T'] = KEYBOARD_HOME; keymap[(unsigned)META('<')] = KEYBOARD_HOME; /* Emacs beginning-of-buffer */ keymap[(unsigned)'<'] = KEYBOARD_HOME; keymap[(unsigned)CTL('R')] = KEYBOARD_SEARCH_BACKWARD; /* Emacs */ keymap[(unsigned)'\\'] = KEYBOARD_SEARCH_BACKWARD; keymap[(unsigned)CTL('S')] = KEYBOARD_SEARCH_FORWARD; /* Emacs */ keymap[(unsigned)'/'] = KEYBOARD_SEARCH_FORWARD; keymap[(unsigned)'u'] = KEYBOARD_UP; keymap[(unsigned)'U'] = KEYBOARD_UP; keymap[(unsigned)CTL('P')] = KEYBOARD_UP; /* Emacs previous-line */ keymap[(unsigned)'['] = KEYBOARD_UP_PARAGRAPH; keymap[(unsigned)']'] = KEYBOARD_DOWN_PARAGRAPH; keymap[(unsigned)'{'] = KEYBOARD_UP_PARAGRAPH; keymap[(unsigned)'}'] = KEYBOARD_DOWN_PARAGRAPH; }
Bool is_end_char(int c) { switch (c) { case CTL('E'): #ifdef KEY_END case KEY_END: #endif return TRUE; default: return FALSE; } }
Bool is_home_char(int c) { switch (c) { case CTL('A'): #ifdef KEY_HOME case KEY_HOME: #endif return TRUE; default: return FALSE; } }
static el_status_t exchange(void) { int c; if ((c = tty_get()) != CTL('X')) return c == EOF ? CSeof : el_ring_bell(); if ((c = rl_mark) <= rl_end) { rl_mark = rl_point; rl_point = c; return CSmove; } return CSstay; }
Bool is_left_char(int c) { switch (c) { case CTL('B'): /* only used in editing comments */ case VI_LEFT: #ifdef KEY_LEFT case KEY_LEFT: #endif return TRUE; default: return FALSE; } }
Bool is_right_char(int c) { switch (c) { case CTL('F'): /* only used in editing comments */ case VI_RIGHT: #ifdef KEY_RIGHT case KEY_RIGHT: #endif return TRUE; default: return FALSE; } }
/* * Handle the process of a GETTY. */ static void do_getty(char *tty, char *name, size_t len) { int ch; char *np; /* * Clean up tty name. */ if (!strncmp(tty, _PATH_DEV, strlen(_PATH_DEV))) tty += 5; /* * Display prompt. */ ch = ' '; *name = '\0'; while (ch != '\n') { do_issue(tty); np = name; while ((ch = readch(tty)) != '\n') { if (ch == CTL('U')) { while (np > name) { (void)write(1, "\b \b", 3); np--; } continue; } if (np < name + len) *np++ = ch; } *np = '\0'; if (*name == '\0') ch = ' '; /* blank line typed! */ } name[len - 1] = 0; }
void throttleCPU(void *t) { uint64_t msr; PState p; uint32_t newfreq, oldfreq; bcopy(t,&p,sizeof(PState)); // get the ctl we want msr = rdmsr64(INTEL_MSR_PERF_STS); // read current MSR // For clock recalibration oldfreq = FID_to_Hz(FID(msr)); // blank out last 32 bits and put our ctl there msr = (msr & 0xffffffffffff0000ULL) | CTL(p.Frequency, p.Voltage); newfreq = FID_to_Hz(FID(msr)); // after setting ctl in msr //if (RtcFixKernel && !ConstantTSC) { //rtc_clock_stepping(newfreq, oldfreq); //} wrmsr64(INTEL_MSR_PERF_CTL, msr); // and write it to the processor //if (RtcFixKernel && !ConstantTSC) //rtc_clock_stepped(newfreq, oldfreq); }
int v_setmode(struct v_board_t *board, struct v_modeinfo_t *mode) { int tmp; int doubleclock=0; int M, N, P; int iob=board->io_base; /* switching to native mode */ v_out8(iob+MODEREG, NATIVE_MODE|VESA_MODE); /* flipping some bytes */ /* Must be something better to do than this -- FIX */ switch (mode->bitsperpixel) { case 32: v_out8(iob+MEMENDIAN, MEMENDIAN_NO); break; case 16: v_out8(iob+MEMENDIAN, MEMENDIAN_HW); break; case 8: v_out8(iob+MEMENDIAN, MEMENDIAN_END); break; } if (OFLG_ISSET(OPTION_OVERCLOCK_MEM, &vga256InfoRec.options)) { /* increase Mem/Sys clock to avoid nasty artifacts */ if (board->chip != V1000_DEVICE) { v_out32(iob+SCLKPLL, 0xa484d); /* mclk=110 sclk=55 */ /* M/N/P/P = 77/5/2/4 */ usleep(500); } } /* this has something to do with memory */ tmp=v_in32(iob+DRAMCTL)&0xdfff; /* reset bit 13 */ v_out32(iob+DRAMCTL, tmp|0x330000); /* program pixel clock */ if (board->chip == V1000_DEVICE) { if (110.0 < V1000CalcClock(mode->clock/1000.0, &M, &N, &P)) { P++; doubleclock=1; } set_PLL(iob, combineNMP(N, M, P)); } else { tmp = (~0x1800) & v_in32(iob+DRAMCTL); v_out32(iob+DRAMCTL, tmp); V2200CalcClock(mode->clock/1000.0, &M, &N, &P); v_out32(iob+PCLKPLL, v2kcombineNMP(N, M, P)); } usleep(500); /* init the ramdac */ v_initdac(board, mode->bitsperpixel, doubleclock); v_out32(iob+CRTCHORZ, HORZ(mode->hsyncstart-mode->hdisplay, mode->hsyncend-mode->hsyncstart, mode->htotal-mode->hsyncend, mode->hdisplay)); v_out32(iob+CRTCVERT, VERT(mode->vsyncstart-mode->vdisplay, mode->vsyncend-mode->vsyncstart, mode->vtotal-mode->vsyncend, mode->vdisplay)); /* fill in the mode parameters */ memcpy(&(board->mode), mode, sizeof(struct v_modeinfo_t)); board->mode.fifosize=128; board->mode.pll_m=M; board->mode.pll_n=N; board->mode.pll_p=P; board->mode.doubleclock=doubleclock; if (0 == board->mode.virtualwidth) board->mode.virtualwidth=board->mode.screenwidth; board->init=1; v_setframebase(board, 0); /* Need to fix up syncs */ /* enable the display */ v_out32(iob+CRTCCTL, CTL(0, mode->hsynchi, mode->vsynchi) |mode->pixelformat |CRTCCTL_VIDEOFIFOSIZE128 |CRTCCTL_HSYNCENABLE |CRTCCTL_VSYNCENABLE |CRTCCTL_VIDEOENABLE); return 0; }
/* Maximum tree depth. */ #define CTL_MAX_DEPTH 6 #define NAME(n) true, {.named = {n #define CHILD(c) sizeof(c##_node) / sizeof(ctl_node_t), c##_node}}, NULL #define CTL(c) 0, NULL}}, c##_ctl /* * Only handles internal indexed nodes, since there are currently no external * ones. */ #define INDEX(i) false, {.indexed = {i##_index}}, NULL #ifdef JEMALLOC_TCACHE static const ctl_node_t tcache_node[] = { {NAME("flush"), CTL(tcache_flush)} }; #endif static const ctl_node_t thread_node[] = { {NAME("arena"), CTL(thread_arena)} #ifdef JEMALLOC_STATS , {NAME("allocated"), CTL(thread_allocated)}, {NAME("allocatedp"), CTL(thread_allocatedp)}, {NAME("deallocated"), CTL(thread_deallocated)}, {NAME("deallocatedp"), CTL(thread_deallocatedp)} #endif }; static const ctl_node_t config_node[] = {
/* 16: F7 */ KEYSYM_NOP, /* 17: F8 */ KEYSYM_NOP, /* 18: F9 */ KEYSYM_NOP, /* 19: Alt_L */ KEYSYM_SETMOD | KBMOD_ALT_L, /* 20: T5_Up */ KEYSYM_NOP, /* 21: R1/Pause */ KEYSYM_NOP, /* 22: R2/Print */ KEYSYM_NOP, /* 23: R3/Break */ KEYSYM_NOP, /* 24: T5_Left */ KEYSYM_NOP, /* 25: L3/Props */ KEYSYM_NOP, /* 26: L4/Undo */ KEYSYM_NOP, /* 27: T5_Down */ KEYSYM_NOP, /* 28: T5_Right */ KEYSYM_NOP, /* 29: Esc */ 0x1b, /* 30: 1 */ KEYSYM_NOP, /* 31: 2 */ CTL('@'), /* 32: 3 */ KEYSYM_NOP, /* 33: 4 */ KEYSYM_NOP, /* 34: 5 */ KEYSYM_NOP, /* 35: 6 */ CTL('^'), /* 36: 7 */ KEYSYM_NOP, /* 37: 8 */ KEYSYM_NOP, /* 38: 9 */ KEYSYM_NOP, /* 39: 0 */ KEYSYM_NOP, /* 40: minus _ */ CTL('_'), /* 41: equal */ KEYSYM_NOP, /* 42: grave/tilde */ CTL('~'), /* 43: BackSpace */ '\b', /* 44: */ KEYSYM_HOLE, /* 45: R4/KP_Equal */ KEYSYM_NOP, /* 46: R5/KP_Div */ KEYSYM_NOP,
#define NAME(n) {true}, n #define CHILD(t, c) \ sizeof(c##_node) / sizeof(ctl_##t##_node_t), \ (ctl_node_t *)c##_node, \ NULL #define CTL(c) 0, NULL, c##_ctl /* * Only handles internal indexed nodes, since there are currently no external * ones. */ #define INDEX(i) {false}, i##_index static const ctl_named_node_t tcache_node[] = { {NAME("enabled"), CTL(thread_tcache_enabled)}, {NAME("flush"), CTL(thread_tcache_flush)} }; static const ctl_named_node_t thread_node[] = { {NAME("arena"), CTL(thread_arena)}, {NAME("allocated"), CTL(thread_allocated)}, {NAME("allocatedp"), CTL(thread_allocatedp)}, {NAME("deallocated"), CTL(thread_deallocated)}, {NAME("deallocatedp"), CTL(thread_deallocatedp)}, {NAME("tcache"), CHILD(named, tcache)} }; static const ctl_named_node_t config_node[] = { {NAME("debug"), CTL(config_debug)}, {NAME("dss"), CTL(config_dss)},
/* * expanded search comparison * returns 1 if match, 0 if not */ static int srch_cmp(void) { int tq; /* q-reg name for ^EGq */ struct qp tqp; /* pointer to read q reg */ /* what is search character */ switch (mapch_l[sm.p->ch[sm.c & 0xFF] & 0xFF]) { /* match anything but following construct */ case CTL('N'): /* don't read past end of string */ if (sm.dot >= sm.z) { ERROR(E_ISS); } /* skip the ^N */ fwdc(&sm); return(!srch_cmp()); /* match any character */ case CTL('X'): return(1); /* take next char literally */ case CTL('Q'): case CTL('R'): /* don't read past end of string */ if (sm.dot >= sm.z) { ERROR(E_ISS); } /* skip the ^Q */ fwdc(&sm); return(*(pmap + sb.p->ch[sb.c]) == *(pmap + sm.p->ch[sm.c])); /* match any nonalphanumeric */ case CTL('S'): return(!isalnum(sb.p->ch[sb.c])); case CTL('E'): /* don't read past end of string */ if (sm.dot >= sm.z) ERROR(E_ISS); /* skip the ^E */ fwdc(&sm); switch (mapch_l[sm.p->ch[sm.c & 0xFF] & 0xFF]) { /* match any alpha */ case 'a': return(isalpha(sb.p->ch[sb.c])); /* match any nonalpha */ case 'b': return(!isalnum(sb.p->ch[sb.c])); /* rad50 symbol constituent */ case 'c': return(!isalnum(sb.p->ch[sb.c]) || (sb.p->ch[sb.c] == '$') || (sb.p->ch[sb.c] == '.')); /* digit */ case 'd': return(isdigit(sb.p->ch[sb.c])); /* line terminator LF, VT, FF, CR */ case 'l': return((sb.p->ch[sb.c] == LF) || (sb.p->ch[sb.c] == FF) || (sb.p->ch[sb.c] == CR) || (sb.p->ch[sb.c] == VT)); /* alphanumeric */ case 'r': return(isalnum(sb.p->ch[sb.c])); /* lower case */ case 'v': return(islower(sb.p->ch[sb.c])); /* upper case */ case 'w': return(isupper(sb.p->ch[sb.c])); /* any non-null string of spaces or tabs */ case 's': /* failure */ if (((sb.p->ch[sb.c]&0177) != ' ') && ((sb.p->ch[sb.c]&0177) != TAB)) { return(0); } /* skip remaining spaces or tabs */ for ( fwdc(&sb); ((sb.p->ch[sb.c]&0177) == ' ') || ((sb.p->ch[sb.c]&0177) == TAB); fwdc(&sb) ) { ; } /* * Back up one char (calling routine will * skip it) */ backc(&sb); return(1); /* success */ /* any char in specified q register */ case 'g': /* don't read past end of string */ if (sm.dot >= sm.z) { ERROR(E_ISS); } /* get to the next char */ fwdc(&sm); /* read q-reg spec */ tq = getqspec(1, sm.p->ch[sm.c]); for (tqp.dot = tqp.c = 0, tqp.p = qreg[tq].f; tqp.dot < qreg[tq].z; fwdc(&tqp)) { /* match */ if (*(pmap + tqp.p->ch[tqp.c]) == *(pmap + sb.p->ch[sb.c])) { return(1); } } return(0); /* fail */ default: ERROR(E_ISS); } default: return(*(pmap + sb.p->ch[sb.c]) == *(pmap + sm.p->ch[sm.c])); } }
/* * routine to read in a string with string-build characters * used for search, tag, file name operations * returns 0 if empty string entered, nonzero otherwise * * lbuff - addr of q-reg header */ int build_string(struct qh *lbuff) { int count; /* char count */ struct buffcell *tp; /* pointer to temporary string */ char c; /* temp character */ /* read terminator */ term_char = (atflag) ? getcmdc(trace_sw) : ESC; count = atflag = 0; /* initialize char count */ /* if string is not empty */ if (!peekcmdc(term_char)) { /* * Create a temporary string and read chars into * it until the terminator */ for (tp = bb.p = get_bcell(), bb.c = 0; (c = getcmdc(trace_sw)) != term_char; ) { /* read next char as CTL */ if ((c == '^') && !(ed_val & ED_CARET)) { if ((c = getcmdc(trace_sw)) == term_char) { ERROR(msp <= &mstack[0] ? E_UTC : E_UTM); } c &= 0x1f; } /* if a control char */ if ((c &= 0177) < ' ') { switch (c) { /* take next char literally */ case CTL('Q'): case CTL('R'): if ((c = getcmdc(trace_sw)) == term_char) { ERROR((msp <= &mstack[0]) ? E_UTC : E_UTM); } /* fetch character and go store */ break; /* take next char as lower case */ case CTL('V'): if (getcmdc(trace_sw) == term_char) { ERROR((msp <= &mstack[0]) ? E_UTC : E_UTM); } c = mapch_l[cmdc & 0xFF]; break; /* take next char as upper case */ case CTL('W'): if ((c = getcmdc(trace_sw)) == term_char) { ERROR((msp <= &mstack[0]) ? E_UTC : E_UTM); } if (islower(c)) { c = toupper(c); } break; /* expanded constructs */ case CTL('E'): if (getcmdc(trace_sw) == term_char) { ERROR((msp <= &mstack[0]) ? E_UTC : E_UTM); } switch (mapch_l[cmdc & 0xFF]) { /* use char in q-reg */ case 'u': if (getcmdc(trace_sw) == term_char) ERROR((msp <= &mstack[0]) ? E_UTC : E_UTM); c = qreg[getqspec(1, cmdc)].v & 0x7f; break; /* use string in q-reg */ case 'q': if (getcmdc(trace_sw) == term_char) { ERROR((msp <= &mstack[0]) ? E_UTC : E_UTM); } /* read the reg spec */ ll = getqspec(1, cmdc); /* set a pointer to it */ aa.p = qreg[ll].f; aa.c = 0; for (mm = 0; mm < qreg[ll].z; mm++) { /* store char */ bb.p->ch[bb.c] = aa.p->ch[aa.c]; /* store next char */ fwdcx(&bb); fwdc(&aa); ++count; } /* * Repeat loop without * storing */ continue; default: /* not special: store the ^E */ bb.p->ch[bb.c] = CTL('E'); fwdcx(&bb); ++count; /* * And go store the following * char */ c = cmdc; break; } } } /* store character */ bb.p->ch[bb.c] = c; /* advance pointer */ fwdcx(&bb); /* count characters */ ++count; } free_blist(lbuff->f); /* return old buffer */ lbuff->f = tp; /* put in new one */ lbuff->f->b = (struct buffcell *) lbuff; /* store count of chars in string */ lbuff->z = count; } else { /* empty string: consume terminator */ getcmdc(trace_sw); } /* return char count */ return(count); }
el_status_t do_suspend(void) { puts("Abort!"); return CSstay; } int main(int ac __attribute__ ((unused)), char *av[] __attribute__ ((unused))) { char *line; char *prompt = "cli> "; /* Setup callbacks */ rl_set_complete_func(&my_rl_complete); rl_set_list_possib_func(&my_rl_list_possib); el_bind_key('?', list_possible); el_bind_key(CTL('C'), do_break); el_bind_key(CTL('D'), do_exit); el_bind_key(CTL('Z'), do_suspend); read_history(HISTORY); while ((line = readline(prompt)) != NULL) { printf("\t\t\t|%s|\n", line); free(line); } write_history(HISTORY); return 0; }
void menu() { small_uint_t cmd; int full_duplex; printf(&debug, "Free memory: %d bytes\n", mem_available(&pool)); printf(&debug, "Ethernet: %s", eth_get_carrier(ð) ? "Cable OK" : "No cable"); if (eth_get_speed(ð, &full_duplex)) { printf(&debug, ", %s", full_duplex ? "Full Duplex" : "Half Duplex"); } printf(&debug, ", %u interrupts\n", eth.intr); printf(&debug, "Transmit: %ld packets, %ld collisions, %ld errors\n", eth.netif.out_packets, eth.netif.out_collisions, eth.netif.out_errors); printf(&debug, "Receive: %ld packets, %ld errors, %ld lost\n", eth.netif.in_packets, eth.netif.in_errors, eth.netif.in_discards); printf(&debug, "\n 1. Transmit 1 packet"); printf(&debug, "\n 2. Transmit 2 packets"); printf(&debug, "\n 3. Transmit 8 packets"); printf(&debug, "\n 4. Run send/receive test"); printf(&debug, "\n 5. Packet size: %d bytes", packet_size); printf(&debug, "\n 6. Local loopback: %s", local_loop ? "Enabled" : "Disabled"); puts(&debug, "\n\n"); for (;;) { /* Ввод команды. */ puts(&debug, "Command: "); while (peekchar (&debug) < 0) timer_delay(&timer, 50); cmd = getchar(&debug); putchar(&debug, '\n'); if (cmd == '\n' || cmd == '\r') break; if (cmd == '1') { send_packets(1); break; } if (cmd == '2') { send_packets(2); break; } if (cmd == '3') { send_packets(8); break; } if (cmd == '4') { run_test(); break; } if (cmd == '5') { try_again: printf(&debug, "Enter packet size (1-1518): "); packet_size = get_short(packet_size); if (packet_size <= 0 || packet_size > 1518) { printf(&debug, "Invalid value, try again."); goto try_again; } putchar(&debug, '\n'); data_pattern = mem_realloc(data_pattern, packet_size); if (!data_pattern) { printf(&debug, "No memory for data_pattern\n"); uos_halt(1); } int i; for (i = 0; i < packet_size; i++) data_pattern[i] = i; if (packet_size >= 6) memset(data_pattern, 0xFF, 6); if (packet_size >= 12) memcpy(data_pattern + 6, eth.netif.ethaddr, 6); break; } if (cmd == '6') { local_loop = !local_loop; eth_set_loop(ð, local_loop); break; } if (cmd == CTL('E')) { /* Регистры Ethernet. */ putchar(&debug, '\n'); eth_debug(ð, &debug); putchar(&debug, '\n'); continue; } if (cmd == CTL('T')) { /* Список задач uOS. */ printf(&debug, "\nFree memory: %u bytes\n\n", mem_available(&pool)); task_print(&debug, 0); task_print(&debug, (task_t*) stack_console); task_print(&debug, (task_t*) stack_test); task_print(&debug, (task_t*) eth.stack); putchar(&debug, '\n'); continue; } } }
* shared by all alternative "Bindings" to save space. However, if the * modifier flag is set only by a LYE_SETMn lynxeditaction, this table can have * effect only for those Bindings that map a lynxkeycode to LYE_SETMn. ( This * doesn't apply if the modifier is already being set in LYgetch(). ) - kw */ static LYEditCode Mod1Binding[KEYMAP_SIZE]; /* Two more tables here, but currently they are all the same. In other words, we are cheating to save space, until there is a need for different tables. - kw */ static LYEditCode *Mod2Binding = Mod1Binding; static LYEditCode *Mod3Binding = Mod1Binding; static const LYEditInit initMod1Binding[] = { {CTL('A'), LYE_BOL}, {CTL('B'), LYE_BACKW}, {CTL('C'), LYE_UNMOD}, {CTL('D'), LYK_NEXT_LINK | LYE_FORM_LAC}, {CTL('E'), LYK_EDITTEXTAREA | LYE_FORM_LAC}, {CTL('F'), LYE_FORWW}, {CTL('G'), LYE_ABORT}, {CTL('H'), LYE_DELPW}, {CTL('I'), LYE_UNMOD}, {CTL('J'), LYE_ENTER}, {CTL('K'), LYK_LPOS_NEXT_LINK | LYE_FORM_LAC}, {CTL('L'), LYE_FORM_PASS}, {CTL('M'), LYE_ENTER}, {CTL('N'), LYE_FORWW}, {CTL('O'), LYE_UNMOD}, {CTL('P'), LYE_BACKW},
ac = argify(p, &av); if (Repeat != NO_ARG) s = Repeat < ac ? insert_string(av[Repeat]) : el_ring_bell(); else s = ac ? insert_string(av[ac - 1]) : CSstay; if (av) free(av); free(p); return s; } static el_keymap_t Map[64] = { { CTL('@'), mk_set }, { CTL('A'), beg_line }, { CTL('B'), bk_char }, { CTL('D'), del_char }, { CTL('E'), end_line }, { CTL('F'), fd_char }, { CTL('G'), el_ring_bell }, { CTL('H'), bk_del_char }, { CTL('I'), c_complete }, { CTL('J'), accept_line }, { CTL('K'), kill_line }, { CTL('L'), redisplay }, { CTL('M'), accept_line }, { CTL('N'), h_next }, { CTL('O'), el_ring_bell }, { CTL('P'), h_prev },
void dedtype(RING * gbl, char *name, int inlist, int binary, int stripped, int isdir) { int had_eof; int c; int count, /* ...and repeat-count */ y, /* current line-in-screen */ shift = COLS / 4, /* amount of left/right shift */ done = FALSE, shown = FALSE, infile = -1; /* # of lines processed */ OFF_T skip = 0; tabstop = 8; Shift = 0; UsePattern = FALSE; OptBinary = binary; OptStripped = stripped; if (isdir && !OptBinary) { DIR *dp; DirentT *de; char bfr[MAXPATHLEN]; # define INO_FMT "%5lu" if ((InFile = tmpfile()) == 0) { warn(gbl, "tmp-file"); return; } if ((dp = opendir(name)) != 0) { while ((de = readdir(dp)) != NULL) { (void) ded2string(gbl, bfr, (int) NAMLEN(de), de->d_name, FALSE); FPRINTF(InFile, INO_FMT, (unsigned long) de->d_ino); FPRINTF(InFile, " %s\n", bfr); } (void) closedir(dp); rewind(InFile); } else { warn(gbl, "opendir"); FCLOSE(InFile); return; } } else InFile = fopen(name, "r"); in_dedtype = TRUE; /* disable clearing of workspace via A/a cmd */ if (InFile) { int jump = 0; dlog_comment("type \"%s\" (%s %s)\n", name, OptBinary ? "binary" : "text", isdir ? "directory" : "file"); to_work(gbl, FALSE); dyn_init(&my_text, BUFSIZ); dyn_init(&my_over, BUFSIZ); max_lines = -1; MarkLine(&infile); while (!done) { if (jump) { #if defined(HAVE_WSCRL) && defined(HAVE_WSETSCRREG) /* * If we're doing single-line scrolling past * the point we've read in the file, try to * cache pointers so that the scrolling logic * will go more smoothly. */ if (jump > 0 && jump < NumP(1) && infile + NumP(1) >= max_lines) { int line = infile; (void) StartPage(&line, TRUE, &had_eof); } #endif (void) JumpBackwards(&infile, jump); jump = 0; } markC(gbl, TRUE); y = StartPage(&infile, (int) skip, &had_eof); if (skip && !was_interrupted) { if (feof(InFile)) { skip = 0; jump = NumP(1); } else { IgnorePage(infile); skip--; } continue; } if (had_eof) { int blank; infile = TopOfPage(infile, &blank); (void) JumpToLine(infile); y = StartPage(&infile, 0, &had_eof); } shown |= FinishPage(gbl, inlist, infile, y); jump = NumP(1); reset_catcher(); switch (c = dlog_char(gbl, &count, 1)) { case CTL('K'): deddump(gbl); break; case 'w': retouch(gbl, 0); break; case '\t': if (OptBinary) { beep(); } else { tabstop = (count <= 1) ? (tabstop == 8 ? 4 : 8) : count; } break; case 'q': done = TRUE; break; case KEY_HOME: case '^': jump = infile; break; case KEY_END: case '$': infile = max_lines; skip = MaxP(); break; case KEY_PPAGE: case '\b': case 'b': if (AtTop(infile)) { beep(); } else { jump += NumP(count); } break; case KEY_NPAGE: case '\n': case ' ': case 'f': jump = 0; skip = count - 1; break; case '<': case CTL('L'): LeftOrRight(-shift * count); break; case '>': case CTL('R'): LeftOrRight(shift * count); break; case KEY_LEFT: case 'h': LeftOrRight(-count); break; case KEY_DOWN: case 'j': jump = NumP(1) - count; if ((infile - jump) > max_lines) { skip = (-jump + NumP(1) - 1) / NumP(1); jump = 0; } break; case KEY_UP: case 'k': if (AtTop(infile)) { beep(); } else { jump += count; } break; case KEY_RIGHT: case 'l': LeftOrRight(count); break; /* move work-area marker */ case 'A': count = -count; jump -= count; /*FALLTHRU */ case 'a': markset(gbl, (unsigned) (mark_W + count)); break; case '/': case '?': case 'n': case 'N': FindPattern(gbl, &infile, c); break; default: beep(); } } FCLOSE(InFile); if (shown) (void) reshow(gbl, (unsigned) inlist); showMARK(gbl->Xbase); showC(gbl); } else warn(gbl, name); in_dedtype = FALSE; }