void pmcupdate(Mach *m) { PmcCtr *p; int i, maxct, wk; PmcWait *w; return; maxct = pmcnregs(); for (i = 0; i < maxct; i++) { p = &m->pmc[i]; ilock(&m->pmclock); if(p->ctrset & PmcSet) setctr(p->ctr, i); if(p->ctlset & PmcSet) setctl(&p->PmcCtl, i); p->ctr = getctr(i); getctl(&p->PmcCtl, i); p->ctrset = PmcIgn; p->ctlset = PmcIgn; wk = p->stale; p->stale = 0; if(wk){ for(w = p->wq; w != nil; w = w->next){ p->wq = w->next; wakeup(&w->rend); pmcwclose(w); } } iunlock(&m->pmclock); } }
/* * Handle ANSI escape-extended commands (with "ESC [" or "ESC O" prefix) */ int extendedcmd (int f, int n) { int (*cmd)(); int c; c = getctl(); switch (c) { case 'A': cmd = backline; break; /* up arrow */ case 'B': cmd = forwline; break; /* down arrow */ case 'C': cmd = forwchar; break; /* right arrow */ case 'D': cmd = backchar; break; /* left arrow */ case 'H': cmd = gotobol; break; /* usually home */ case 'W': cmd = gotoeol; break; /* maybe end */ case 'F': cmd = gotoeol; break; /* maybe end */ case '3': cmd = forwdel; getctl(); break; /* maybe delete */ case '5': cmd = backpage; getctl(); break; case '6': cmd = forwpage; getctl(); break; case '7': cmd = gotobob; getctl(); break; case '8': cmd = gotoeob; getctl(); break; default: mlwrite ("\007[Key not bound]"); return (FALSE); } return cmd(f, n); }
/* * Handle ANSI escape-extended commands (with "ESC [" or "ESC O" prefix) */ int extendedcmd(int f, int n) { int (*cmd)(); int c; c = getctl(); switch (c) { case 'A': cmd = backline; break; case 'B': cmd = forwline; break; case 'C': cmd = forwchar; break; case 'D': cmd = backchar; break; case 'H': cmd = gotobob; break; case 'W': cmd = gotoeob; break; case '5': cmd = pageup; getctl(); break; case '6': cmd = pagedown; getctl(); break; case '7': cmd = gotobob; getctl(); break; case '8': cmd = gotoeob; getctl(); break; default: mlwrite("\007[Key not bound]"); return (FALSE); } return cmd(f, n); }
/* * Read in a key. Do the standard keyboard preprocessing. Convert the keys to * the internal character set. */ int getkey () { int c; c = (*term.t_getchar) (); if (c == METACH) { /* Apply M- prefix */ c = getctl (); return (META | c); } if (c >= 0x00 && c <= 0x1F) /* C0 control -> C- */ c = CTRL | (c + '@'); return (c); }
int pmcanyenab(void) { int i; PmcCtl p; for (i = 0; i < pmcnregs(); i++) { if (getctl(&p, i) < 0) return -1; if (p.enab) return 1; } return 0; }
/* * Read in a key. * Do the standard keyboard preprocessing. Convert the keys to the internal * character set. */ globle int getkey() { register int c; c = (*term.t_getchar)(); if ((c & META) == META) return(c); #if WIN_MVC || WIN_GCC if (c > 255) { switch (c) { case UP_ARROW : return (COTL | 'P'); case DOWN_ARROW : return (COTL | 'N'); case LEFT_ARROW : return (COTL | 'B'); case RIGHT_ARROW : return (COTL | 'F'); case PGUP_KEY : return (META | 'V'); case PGDN_KEY : return (COTL | 'V'); case HOME_KEY : return (META | '<'); case END_KEY : return (META | '>'); case COTL_LEFT_ARROW : return (META | 'B'); case COTL_RIGHT_ARROW : return (META | 'F'); case COTL_AT_SIGN : return (COTL | '@'); default : return (COTL | 'G'); } } #endif if (c == METACH) { /* Apply M- prefix */ c = getctl(); return (META | c); } if (c>=0x00 && c<=0x1F) /* C0 control -> C- */ c = COTL | (c+'@'); return (c); }
int pmcgetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno) { PmcCtr *p; Mach *mp; if(coreno == machp()->machno) return getctl(pctl, regno); mp = sys->machptr[coreno]; p = &mp->pmc[regno]; ilock(&mp->pmclock); p->ctlset |= PmcGet; if(shouldipi(mp)){ waitnotstale(mp, p); ilock(&mp->pmclock); } memmove(pctl, &p->PmcCtl, sizeof(PmcCtl)); iunlock(&mp->pmclock); return 0; }
int pmcgetctl(u32int coreno, PmcCtl *pctl, u32int regno) { PmcCtr *p; Mach *mp; if(coreno == m->machno) return getctl(pctl, regno); mp = sys->machptr[coreno]; p = &mp->pmc[regno]; ilock(&mp->pmclock); p->ctlset |= PmcGet; p->stale = 1; if(mp->proc != nil || mp->nixtype != NIXAC){ waitnotstale(mp, p); ilock(&mp->pmclock); } memmove(pctl, &p->PmcCtl, sizeof(PmcCtl)); iunlock(&mp->pmclock); return 0; }
int buffermenu(int f, int n) { BUFFER *bp; BUFFER *org_bp = curbp; int c,k; int bufptr; int bufcount = 0; bufptr = 1; start: listbuffers(f,n); swbuffer(blistp); onlywind(0,0); bufcount = count_buffers(); if (bufptr > bufcount) bufptr = bufcount; if (bufcount > 0) forwline(0, bufptr + 1); else forwline(0, 2); for (;;) { mlwrite("Buffer Menu: 1,2,s,v,k,q "); update(); c = ttgetc(); /* if no buffers, only allow exit */ if (bufcount == 0) { switch (c) { case 'q': case 'Q': case 'x': case 'X': break; default: (*term.t_beep) (); continue; } } /* * pre process escape sequence to get up/down arrows * convert to CTRL+N, CTRL+P */ if (c == ESC) { k = getctl(); if (k == '[') { k = getctl(); switch(k) { case 'A': c = CTRL_P; break; case 'B': c = CTRL_N; break; default: (*term.t_beep)(); continue; } } else { k = getctl(); (*term.t_beep) (); continue; } } /* if ESC */ switch (c) { case 'n': case 'N': case CTRL_N: if (bufcount == bufptr) { (*term.t_beep) (); break; } forwline(0,1); bufptr++; break; case 'p': case 'P': case CTRL_P: if (bufptr == 1) { (*term.t_beep) (); break; } backline(0,1); bufptr--; break; case '1': bp = get_buffer(bufptr); swbuffer(bp); onlywind(0,0); mlerase(); return TRUE; case '2': bp = get_buffer(bufptr); swbuffer(bp); onlywind(0,0); /* need to check or is still valid */ if (valid_buf(org_bp) == TRUE && bufcount > 1) { splitwind(0,0); swbuffer(org_bp); nextwind(0,0); } mlerase(); return TRUE; /* save file */ case 's': case 'S': bp = get_buffer(bufptr); if (bp != NULL) { curbp = bp; (void)filesave(0,0); curbp = blistp; goto start; } break; /* toggle read only */ case 'v': case 'V': case '%': bp = get_buffer(bufptr); if (bp != NULL) /* be defensive */ bp->b_flag ^= BFRO; goto start; break; /* kill buffer */ case 'k': case 'K': bp = get_buffer(bufptr); if (bp != NULL) zotbuf(bp); goto start; break; /* exit buffer menu */ case 'q': case 'Q': case 'x': case 'X': if (bufcount == 0) { bp = get_scratch(); swbuffer(bp); onlywind(0,0); mlerase(); return TRUE; } if (valid_buf(org_bp) == TRUE) swbuffer(org_bp); else swbuffer(bheadp); onlywind(0,0); mlerase(); return TRUE; /* any other key */ default: (*term.t_beep) (); break; } } mlerase(); return TRUE; }
int main (int argc, char *argv[]) { BUFFER *bp; char bname[NBUFN]; /* buffer name of file to read */ int c, f, n; int ffile; /* first file flag */ int carg; /* current arg to scan */ if (argc == 2 && 0 == strcmp("--version", argv[1])) { printf("%s\n", version); exit(0); } /* initialize the editor and process the startup file */ getwinsize(); /* find out the "real" screen size */ strncpy (bname, "*scratch*", 10); /* default buffer name */ edinit (bname); /* Buffers, windows */ vtinit (); /* Displays */ ffile = TRUE; /* no file to edit yet */ update (); /* let the user know we are here */ /* scan through the command line and get the files to edit */ for (carg = 1; carg < argc; ++carg) { /* set up a buffer for this file */ makename (bname, argv[carg]); /* if this is the first file, read it in */ if (ffile) { bp = curbp; makename (bname, argv[carg]); strncpy (bp->b_bname, bname, NBUFN); strncpy (bp->b_fname, argv[carg], NFILEN); if (readin (argv[carg]) == ABORT) { strncpy (bp->b_bname, "main", 5); strncpy (bp->b_fname, "", 1); } bp->b_dotp = bp->b_linep; bp->b_doto = 0; ffile = FALSE; } else { /* set this to inactive */ bp = bfind (bname, TRUE, 0); strncpy (bp->b_fname, argv[carg], NFILEN); bp->b_active = FALSE; } } /* setup to process commands */ lastflag = 0; /* Fake last flags */ curwp->w_flag |= WFMODE; /* and force an update */ loop: update (); /* Fix up the screen */ c = getkey (TRUE); if (mpresf != FALSE) { mlerase (); update (); } f = FALSE; n = 1; if (c == (CTRL | 'X')) /* ^X is a prefix */ c = CTLX | getctl (); if (kbdmip != NULL) { /* Save macro strokes */ if (c != (CTLX | ')') && kbdmip > &kbdm[NKBDM - 6]) { ctrlg (FALSE, 0); goto loop; } if (f != FALSE) { *kbdmip++ = (CTRL | 'U'); *kbdmip++ = n; } *kbdmip++ = c; } execute (c, f, n); /* Do it */ goto loop; }
static void PerformEditCommand( void *theEnv) { register int c; register int f; register int n; register int mflag; register int rtn_flag; char bname[NBUFN]; int num_a; char *fileName = NULL; DATA_OBJECT arg_ptr; /*====================*/ /* Get the file name. */ /*====================*/ if ((num_a = EnvArgCountCheck(theEnv,"edit",NO_MORE_THAN,1)) == -1) return; if (num_a == 1) { if (EnvArgTypeCheck(theEnv,"edit",1,SYMBOL_OR_STRING,&arg_ptr) == FALSE) return; fileName = DOToString(arg_ptr); } if(bheadp == NULL) { /**********************************************/ /* Initial entry, set up buffers and pointers */ /**********************************************/ genstrcpy(bname, "main"); /* Work out the name of */ if (num_a > 0) /* the default buffer. */ makename(bname,fileName); edinit(theEnv,bname); /* Buffers, windows. */ vtinit(theEnv); /* Displays. */ if (num_a > 0) { update(); /* You have to update */ readin(theEnv,fileName); /* in case "[New file]" */ } init_cmp_router(theEnv); /* Prepare the compile */ EnvDeactivateRouter(theEnv,"cmp_router"); /* router. */ } else { /**********************************************************/ /* Return from temporary exit, reset necessary stuff only */ /**********************************************************/ (*term.t_open)(); if (num_a > 0) { filevisit_guts(theEnv,fileName); } } sgarbf = TRUE; /* Force screen update */ lastbufn[0] = '\0'; /* Make sure last name */ /* is cleared out */ lastflag = 0; /* Fake last flags. */ loop: update(); /* Fix up the screen */ c = getkey(); if (mpresf != FALSE) { mlerase(); update(); if (c == ' ') /* ITS EMACS does this */ goto loop; } f = FALSE; n = 1; if (c == (COTL|'U')) { /* ^U, start argument */ f = TRUE; n = 4; /* with argument of 4 */ mflag = 0; /* that can be discarded. */ mlwrite("Arg: 4"); while ((((c=getkey()) >='0') && (c<='9')) || (c==(COTL|'U')) || (c=='-')){ if (c == (COTL|'U')) n = n*4; /* * If dash, and start of argument string, set arg. * to -1. Otherwise, insert it. */ else if (c == '-') { if (mflag) break; n = 0; mflag = -1; } /* * If first digit entered, replace previous argument * with digit and set sign. Otherwise, append to arg. */ else { if (!mflag) { n = 0; mflag = 1; } n = 10*n + c - '0'; } mlwrite("Arg: %d", (mflag >=0) ? n : (n ? -n : -1)); } /* * Make arguments preceded by a minus sign negative and change * the special argument "^U -" to an effective "^U -1". */ if (mflag == -1) { if (n == 0) n++; n = -n; } } if (c == (COTL|'X')) /* ^X is a prefix */ c = CTLX | getctl(); if (kbdmip != NULL) { /* Save macro strokes. */ if (c!=(CTLX|')') && kbdmip>&kbdm[NKBDM-6]) { ctrlg(theEnv,FALSE, 0); goto loop; } if (f != FALSE) { *kbdmip++ = (COTL|'U'); *kbdmip++ = n; } *kbdmip++ = c; } rtn_flag = execute(theEnv,c, f, n); /* Do it. */ if(rtn_flag == EXIT) return; else goto loop; }
int main(int argc, char *argv[]) { BUFFER *bp; char bname[NBUFN]; /* buffer name of file to read */ int c, f, n, mflag; int ffile; /* first file flag */ int basec; /* c stripped of meta character */ /* initialize the editor and process the startup file */ getwinsize(); /* find out the "real" screen size */ strncpy(bname, "main", 5); /* default buffer name */ edinit(bname); /* Buffers, windows */ vtinit(); /* Displays */ ffile = TRUE; /* no file to edit yet */ update(); /* let the user know we are here */ /* scan through the command line and get the files to edit */ if (argc > 2) { (void) fprintf(stderr, "Can only edit one file at a time\n"); exit(1); } else if (argc == 2) { /* set up a buffer for this file */ makename(bname, argv[1]); /* if this is the first file, read it in */ if (ffile) { bp = curbp; makename(bname, argv[1]); strncpy(bp->b_bname, bname, NBUFN); strncpy(bp->b_fname, argv[1], NFILEN); if (readin(argv[1]) == ABORT) { strncpy(bp->b_bname, "main", 5); strncpy(bp->b_fname, "", 1); } bp->b_dotp = bp->b_linep; bp->b_doto = 0; ffile = FALSE; } else { /* set this to inactive */ bp = bfind(bname, TRUE, 0); strncpy(bp->b_fname, argv[1], NFILEN); bp->b_active = FALSE; } } /* setup to process commands */ lastflag = 0; /* Fake last flags */ curwp->w_flag |= WFMODE; /* and force an update */ loop: update(); /* Fix up the screen */ c = getkey(); if (mpresf != FALSE) { mlerase(); update(); } f = FALSE; n = 1; /* do META-# processing if needed */ basec = c & ~META; /* strip meta char off if there */ if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) { f = TRUE; /* there is a # arg */ n = 0; /* start with a zero default */ mflag = 1; /* current minus flag */ c = basec; /* strip the META */ while ((c >= '0' && c <= '9') || (c == '-')) { if (c == '-') { /* already hit a minus or digit? */ if ((mflag == -1) || (n != 0)) break; mflag = -1; } else n = n * 10 + (c - '0'); if ((n == 0) && (mflag == -1)) /* lonely - */ mlwrite("Arg:"); else mlwrite("Arg: %d", n * mflag); c = getkey(); /* get the next key */ } n = n * mflag; /* figure in the sign */ } /* do ^U repeat argument processing */ if (c == (CTRL | 'U')) { /* ^U, start argument */ f = TRUE; n = 4; /* with argument of 4 */ mflag = 0; /* that can be discarded */ mlwrite("Arg: 4"); while (((c = getkey ()) >= '0') && ((c <= '9') || (c == (CTRL | 'U')) || (c == '-'))) { if (c == (CTRL | 'U')) n = n * 4; /* * If dash, and start of argument string, set arg. * to -1. Otherwise, insert it. */ else if (c == '-') { if (mflag) break; n = 0; mflag = -1; } /* * If first digit entered, replace previous argument * with digit and set sign. Otherwise, append to arg. */ else { if (!mflag) { n = 0; mflag = 1; } n = 10 * n + c - '0'; } mlwrite("Arg: %d", (mflag >= 0) ? n : (n ? -n : -1)); } /* * Make arguments preceded by a minus sign negative and change * the special argument "^U -" to an effective "^U -1". */ if (mflag == -1) { if (n == 0) n++; n = -n; } } if (c == (CTRL | 'X')) /* ^X is a prefix */ c = CTLX | getctl (); if (kbdmip != NULL) { /* Save macro strokes */ if (c != (CTLX | ')') && kbdmip > &kbdm[NKBDM - 6]) { ctrlg(FALSE, 0); goto loop; } if (f != FALSE) { *kbdmip++ = (CTRL | 'U'); *kbdmip++ = n; } *kbdmip++ = c; } execute(c, f, n); /* Do it */ goto loop; }