/* * This is equivalent to filevisit from file.c. * Look around to see if we can find the file in another buffer; if we * can't find it, create a new buffer, read in the text, and switch to * the new buffer. *scratch*, *grep*, *compile* needs to be handled * differently from other buffers which have "filenames". */ int loadbuffer(char *bname) { struct buffer *bufp; char *adjf; /* check for special buffers which begin with '*' */ if (bname[0] == '*') { if ((bufp = bfind(bname, FALSE)) != NULL) { curbp = bufp; return (showbuffer(bufp, curwp, WFFULL)); } else { return (FALSE); } } else { if ((adjf = adjustname(bname, TRUE)) == NULL) return (FALSE); if ((bufp = findbuffer(adjf)) == NULL) return (FALSE); } curbp = bufp; if (showbuffer(bufp, curwp, WFFULL) != TRUE) return (FALSE); if (bufp->b_fname[0] == '\0') { if (readin(adjf) != TRUE) { killbuffer(bufp); return (FALSE); } } return (TRUE); }
/* ARGSUSED */ int d_rename(int f, int n) { char frname[NFILEN], toname[NFILEN], *bufp; int ret; size_t off; struct buffer *bp; if (d_makename(curwp->w_dotp, frname, sizeof(frname)) != FALSE) { ewprintf("Not a file"); return (FALSE); } off = strlcpy(toname, curbp->b_fname, sizeof(toname)); if (off >= sizeof(toname) - 1) { /* can't happen, really */ ewprintf("Directory name too long"); return (FALSE); } if ((bufp = eread("Rename %s to: ", toname, sizeof(toname), EFDEF | EFNEW | EFCR, basename(frname))) == NULL) return (ABORT); else if (bufp[0] == '\0') return (FALSE); ret = (rename(frname, toname) >= 0) ? TRUE : FALSE; if (ret != TRUE) return (ret); bp = dired_(curbp->b_fname); return (showbuffer(bp, curwp, WFFULL | WFMODE)); }
void blend_out_rle(int x, int y, RLE_SPRITE* pict,unsigned short frames) { for (int i=0; i<256; i++) { draw_lit_rle_sprite(buffer,pict,x,y,i); for(int j=frames; j>0; j--) vsync(); showbuffer(); } }
/* ARGSUSED */ int dired(int f, int n) { char dname[NFILEN], *bufp, *slash; struct buffer *bp; if (curbp->b_fname && curbp->b_fname[0] != '\0') { (void)strlcpy(dname, curbp->b_fname, sizeof(dname)); if ((slash = strrchr(dname, '/')) != NULL) { *(slash + 1) = '\0'; } } else { if (getcwd(dname, sizeof(dname)) == NULL) dname[0] = '\0'; } if ((bufp = eread("Dired: ", dname, NFILEN, EFDEF | EFNEW | EFCR)) == NULL) return (ABORT); if (bufp[0] == '\0') return (FALSE); if ((bp = dired_(bufp)) == NULL) return (FALSE); curbp = bp; return (showbuffer(bp, curwp, WFFULL | WFMODE)); }
void blend_in_rle(int x, int y, RLE_SPRITE* pict,unsigned char frames) { for (int i=255; i>0; i--) { draw_lit_rle_sprite(buffer,pict,x,y,i); for(int j=frames; j>0; j--) vsync(); showbuffer(); } }
/* ARGSUSED */ int filevisitalt(int f, int n) { struct buffer *bp; char fname[NFILEN], *bufp, *adjf; int status; if (getbufcwd(fname, sizeof(fname)) != TRUE) fname[0] = '\0'; bufp = eread("Find alternate file: ", fname, NFILEN, EFNEW | EFCR | EFFILE | EFDEF); if (bufp == NULL) return (ABORT); else if (bufp[0] == '\0') return (FALSE); status = killbuffer(curbp); if (status == ABORT || status == FALSE) return (ABORT); adjf = adjustname(fname, TRUE); if (adjf == NULL) return (FALSE); if ((bp = findbuffer(adjf)) == NULL) return (FALSE); curbp = bp; if (showbuffer(bp, curwp, WFFULL) != TRUE) return (FALSE); if (bp->b_fname[0] == '\0') { if ((status = readin(adjf)) != TRUE) killbuffer(bp); return (status); } return (TRUE); }
int do_filevisitalt(char *fn) { struct buffer *bp; int status; char *adjf; status = killbuffer(curbp); if (status == ABORT || status == FALSE) return (ABORT); adjf = adjustname(fn, TRUE); if (adjf == NULL) return (FALSE); if (fisdir(adjf) == TRUE) return (do_dired(adjf)); if ((bp = findbuffer(adjf)) == NULL) return (FALSE); curbp = bp; if (showbuffer(bp, curwp, WFFULL) != TRUE) return (FALSE); if (bp->b_fname[0] == '\0') { if ((status = readin(adjf)) != TRUE) killbuffer(bp); return (status); } return (TRUE); }
/* * The adjusted file name refers to a directory, so open dired mode. */ int do_dired(char *adjf) { struct buffer *bp; if ((bp = dired_(adjf)) == FALSE) return (FALSE); curbp = bp; return (showbuffer(bp, curwp, WFFULL | WFMODE)); }
/*ARGSUSED*/ filevisit(f, n) { register BUFFER *bp; int s; char fname[NFILEN]; char *adjf; if ((s=ereply("Find file: ", fname, NFILEN)) != TRUE) return s; adjf = adjustname(fname); if ((bp = findbuffer(adjf)) == NULL) return FALSE; curbp = bp; if (showbuffer(bp, curwp, WFHARD) != TRUE) return FALSE; if (bp->b_fname[0] == 0) return readin(adjf); /* Read it in. */ return TRUE; }
/* Switch to the named buffer. * If no name supplied, switch to the default (alternate) buffer. */ int usebufname(const char *bufp) { struct buffer *bp = NULL; if (bufp == NULL) { if ((bp = bfind("*scratch*", TRUE)) == NULL) return(FALSE); } else if (bufp[0] == '\0' && curbp->b_altb != NULL) bp = curbp->b_altb; else if ((bp = bfind(bufp, TRUE)) == NULL) return (FALSE); /* and put it in current window */ curbp = bp; return (showbuffer(bp, curwp, WFFRAME | WFFULL)); }
int main_loop() { for (int i=0;i<256;i++) solid[i] = i != 0; //sync = 0; while(1) { //do {al_poll_duh(current_track);} while (sync<=0);//render music while waiting for next frame al_poll_duh(current_track); int stat = logic_loop(); render_loop(); showbuffer(); //sync--; switch (stat) { default: case 0: break; case 1: return 1; } } }
/* * Pop the buffer we got passed onto the screen. * Returns a status. */ struct mgwin * popbuf(struct buffer *bp, int flags) { struct mgwin *wp; if (bp->b_nwnd == 0) { /* Not on screen yet. */ /* * Pick a window for a pop-up. * If only one window, split the screen. * Flag the new window as ephemeral */ if (wheadp->w_wndp == NULL && splitwind(FFOTHARG, flags) == FALSE) return (NULL); /* * Pick the uppermost window that isn't * the current window. An LRU algorithm * might be better. Return a pointer, or NULL on error. */ wp = wheadp; while (wp != NULL && wp == curwp) wp = wp->w_wndp; } else { for (wp = wheadp; wp != NULL; wp = wp->w_wndp) if (wp->w_bufp == bp) { wp->w_rflag |= WFFULL | WFFRAME; return (wp); } } if (!wp) return (NULL); if (showbuffer(bp, wp, WFFULL) != TRUE) return (NULL); return (wp); }
/* ARGSUSED */ int d_findfile(int f, int n) { struct buffer *bp; int s; char fname[NFILEN]; if ((s = d_makename(curwp->w_dotp, fname, sizeof(fname))) == ABORT) return (FALSE); if (s == TRUE) bp = dired_(fname); else bp = findbuffer(fname); if (bp == NULL) return (FALSE); curbp = bp; if (showbuffer(bp, curwp, WFFULL) != TRUE) return (FALSE); if (bp->b_fname[0] != 0) return (TRUE); return (readin(fname)); }
/* ARGSUSED */ int d_create_directory(int f, int n) { char tocreate[MAXPATHLEN], *bufp; size_t off; struct buffer *bp; off = strlcpy(tocreate, curbp->b_fname, sizeof(tocreate)); if (off >= sizeof(tocreate) - 1) return (FALSE); if ((bufp = eread("Create directory: ", tocreate, sizeof(tocreate), EFDEF | EFNEW | EFCR)) == NULL) return (ABORT); else if (bufp[0] == '\0') return (FALSE); if (mkdir(tocreate, 0755) == -1) { ewprintf("Creating directory: %s, %s", strerror(errno), tocreate); return (FALSE); } bp = dired_(curbp->b_fname); return (showbuffer(bp, curwp, WFFULL | WFMODE)); }
int main(int argc, char **argv) { char *cp, *init_fcn_name = NULL; PF init_fcn = NULL; int o, i, nfiles; int nobackups = 0; struct buffer *bp = NULL; #ifdef MRUBY mrb_mg_init(); int noinitfile = 0; #endif /* MRUBY */ while ((o = getopt(argc, argv, "nf:q")) != -1) switch (o) { case 'n': nobackups = 1; break; case 'f': if (init_fcn_name != NULL) errx(1, "cannot specify more than one " "initial function"); init_fcn_name = optarg; break; case 'q': noinitfile = 1; break; default: usage(); } argc -= optind; argv += optind; maps_init(); /* Keymaps and modes. */ funmap_init(); /* Functions. */ /* * This is where we initialize standalone extensions that should * be loaded dynamically sometime in the future. */ { extern void grep_init(void); extern void theo_init(void); extern void cmode_init(void); extern void dired_init(void); dired_init(); grep_init(); theo_init(); cmode_init(); #ifdef UTF8 utf8_init(); #endif /* UTF8 */ } if (init_fcn_name && (init_fcn = name_function(init_fcn_name)) == NULL) errx(1, "Unknown function `%s'", init_fcn_name); vtinit(); /* Virtual terminal. */ dirinit(); /* Get current directory. */ edinit(bp); /* Buffers, windows. */ ttykeymapinit(); /* Symbols, bindings. */ /* * doing update() before reading files causes the error messages from * the file I/O show up on the screen. (and also an extra display of * the mode line if there are files specified on the command line.) */ update(); /* user startup file */ #ifdef MRUBY if (noinitfile == 0 && (cp = startupfile(NULL)) != NULL) mrb_mg_load(cp); #else if ((cp = startupfile(NULL)) != NULL) (void)load(cp); #endif /* MRUBY */ /* * Now ensure any default buffer modes from the startup file are * given to any files opened when parsing the startup file. * Note *scratch* will also be updated. */ for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { bp->b_flag = defb_flag; for (i = 0; i <= defb_nmodes; i++) { bp->b_modes[i] = defb_modes[i]; } } /* Force FFOTHARG=1 so that this mode is enabled, not simply toggled */ if (init_fcn) init_fcn(FFOTHARG, 1); if (nobackups) makebkfile(FFARG, 0); for (nfiles = 0, i = 0; i < argc; i++) { if (argv[i][0] == '+' && strlen(argv[i]) >= 2) { long long lval; const char *errstr; lval = strtonum(&argv[i][1], INT_MIN, INT_MAX, &errstr); if (argv[i][1] == '\0' || errstr != NULL) goto notnum; startrow = lval; } else { notnum: cp = adjustname(argv[i], FALSE); if (cp != NULL) { if (nfiles == 1) splitwind(0, 1); if ((curbp = findbuffer(cp)) == NULL) { vttidy(); errx(1, "Can't find current buffer!"); } (void)showbuffer(curbp, curwp, 0); if (readin(cp) != TRUE) killbuffer(curbp); else { /* Ensure enabled, not just toggled */ if (init_fcn_name) init_fcn(FFOTHARG, 1); nfiles++; } } } } if (nfiles > 2) listbuffers(0, 1); /* fake last flags */ thisflag = 0; for (;;) { if (epresf == KCLEAR) eerase(); if (epresf == TRUE) epresf = KCLEAR; if (winch_flag) { do_redraw(0, 0, TRUE); winch_flag = 0; } update(); lastflag = thisflag; thisflag = 0; switch (doin()) { case TRUE: break; case ABORT: ewprintf("Quit"); /* FALLTHRU */ case FALSE: default: ttbeep(); macrodef = FALSE; } } }
int insertfile(char *fname, char *newname, int replacebuf) { struct buffer *bp; struct line *lp1, *lp2; struct line *olp; /* line we started at */ struct mgwin *wp; int nbytes, s, nline = 0, siz, x, x2; int opos; /* offset we started at */ int oline; /* original line number */ char *dp; if (replacebuf == TRUE) x = undo_enable(FFRAND, 0); else x = undo_enabled(); lp1 = NULL; if (line == NULL) { line = malloc(NLINE); if (line == NULL) panic("out of memory"); linesize = NLINE; } /* cheap */ bp = curbp; if (newname != NULL) { (void)strlcpy(bp->b_fname, newname, sizeof(bp->b_fname)); dp = xdirname(newname); (void)strlcpy(bp->b_cwd, dp, sizeof(bp->b_cwd)); (void)strlcat(bp->b_cwd, "/", sizeof(bp->b_cwd)); free(dp); } /* hard file open */ if ((s = ffropen(fname, (replacebuf == TRUE) ? bp : NULL)) == FIOERR) goto out; if (s == FIOFNF) { /* file not found */ if (newname != NULL) ewprintf("(New file)"); else ewprintf("(File not found)"); goto out; } else if (s == FIODIR) { /* file was a directory */ if (replacebuf == FALSE) { ewprintf("Cannot insert: file is a directory, %s", fname); goto cleanup; } killbuffer(bp); if ((bp = dired_(fname)) == NULL) return (FALSE); undo_enable(FFRAND, x); curbp = bp; return (showbuffer(bp, curwp, WFFULL | WFMODE)); } else { dp = xdirname(fname); (void)strlcpy(bp->b_cwd, dp, sizeof(bp->b_cwd)); (void)strlcat(bp->b_cwd, "/", sizeof(bp->b_cwd)); free(dp); } opos = curwp->w_doto; oline = curwp->w_dotline; /* * Open a new line at dot and start inserting after it. * We will delete this newline after insertion. * Disable undo, as we create the undo record manually. */ x2 = undo_enable(FFRAND, 0); (void)lnewline(); olp = lback(curwp->w_dotp); undo_enable(FFRAND, x2); nline = 0; siz = 0; while ((s = ffgetline(line, linesize, &nbytes)) != FIOERR) { retry: siz += nbytes + 1; switch (s) { case FIOSUC: /* FALLTHRU */ case FIOEOF: ++nline; if ((lp1 = lalloc(nbytes)) == NULL) { /* keep message on the display */ s = FIOERR; undo_add_insert(olp, opos, siz - nbytes - 1 - 1); goto endoffile; } bcopy(line, <ext(lp1)[0], nbytes); lp2 = lback(curwp->w_dotp); lp2->l_fp = lp1; lp1->l_fp = curwp->w_dotp; lp1->l_bp = lp2; curwp->w_dotp->l_bp = lp1; if (s == FIOEOF) { undo_add_insert(olp, opos, siz - 1); goto endoffile; } break; case FIOLONG: { /* a line too long to fit in our buffer */ char *cp; int newsize; newsize = linesize * 2; if (newsize < 0 || (cp = malloc(newsize)) == NULL) { ewprintf("Could not allocate %d bytes", newsize); s = FIOERR; goto endoffile; } bcopy(line, cp, linesize); free(line); line = cp; s = ffgetline(line + linesize, linesize, &nbytes); nbytes += linesize; linesize = newsize; if (s == FIOERR) goto endoffile; goto retry; } default: ewprintf("Unknown code %d reading file", s); s = FIOERR; break; } } endoffile: /* ignore errors */ ffclose(NULL); /* don't zap an error */ if (s == FIOEOF) { if (nline == 1) ewprintf("(Read 1 line)"); else ewprintf("(Read %d lines)", nline); } /* set mark at the end of the text */ curwp->w_dotp = curwp->w_markp = lback(curwp->w_dotp); curwp->w_marko = llength(curwp->w_markp); curwp->w_markline = oline + nline + 1; /* * if we are at the end of the file, ldelnewline is a no-op, * but we still need to decrement the line and markline counts * as we've accounted for this fencepost in our arithmetic */ if (lforw(curwp->w_dotp) == curwp->w_bufp->b_headp) { curwp->w_bufp->b_lines--; curwp->w_markline--; } else (void)ldelnewline(); curwp->w_dotp = olp; curwp->w_doto = opos; curwp->w_dotline = oline; if (olp == curbp->b_headp) curwp->w_dotp = lforw(olp); if (newname != NULL) bp->b_flag |= BFCHG | BFBAK; /* Need a backup. */ else bp->b_flag |= BFCHG; /* * If the insert was at the end of buffer, set lp1 to the end of * buffer line, and lp2 to the beginning of the newly inserted text. * (Otherwise lp2 is set to NULL.) This is used below to set * pointers in other windows correctly if they are also at the end of * buffer. */ lp1 = bp->b_headp; if (curwp->w_markp == lp1) { lp2 = curwp->w_dotp; } else { /* delete extraneous newline */ (void)ldelnewline(); out: lp2 = NULL; } for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_bufp == curbp) { wp->w_flag |= WFMODE | WFEDIT; if (wp != curwp && lp2 != NULL) { if (wp->w_dotp == lp1) wp->w_dotp = lp2; if (wp->w_markp == lp1) wp->w_markp = lp2; if (wp->w_linep == lp1) wp->w_linep = lp2; } } } bp->b_lines += nline; cleanup: undo_enable(FFRAND, x); /* return FALSE if error */ return (s != FIOERR); }
int killbuffer(struct buffer *bp) { struct buffer *bp1; struct buffer *bp2; struct mgwin *wp; int s; struct undo_rec *rec; /* * Find some other buffer to display. Try the alternate buffer, * then the first different buffer in the buffer list. If there's * only one buffer, create buffer *scratch* and make it the alternate * buffer. Return if *scratch* is only buffer... */ if ((bp1 = bp->b_altb) == NULL) { /* only one buffer. see if it's *scratch* */ if (bp == bfind("*scratch*", FALSE)) return (TRUE); /* create *scratch* for alternate buffer */ if ((bp1 = bfind("*scratch*", TRUE)) == NULL) return (FALSE); } if ((s = bclear(bp)) != TRUE) return (s); for (wp = wheadp; bp->b_nwnd > 0; wp = wp->w_wndp) { if (wp->w_bufp == bp) { bp2 = bp1->b_altb; /* save alternate buffer */ if (showbuffer(bp1, wp, WFMODE | WFFRAME | WFFULL)) bp1->b_altb = bp2; else bp1 = bp2; } } if (bp == curbp) curbp = bp1; free(bp->b_headp); /* Release header line. */ bp2 = NULL; /* Find the header. */ bp1 = bheadp; while (bp1 != bp) { if (bp1->b_altb == bp) bp1->b_altb = (bp->b_altb == bp1) ? NULL : bp->b_altb; bp2 = bp1; bp1 = bp1->b_bufp; } bp1 = bp1->b_bufp; /* Next one in chain. */ if (bp2 == NULL) /* Unlink it. */ bheadp = bp1; else bp2->b_bufp = bp1; while (bp1 != NULL) { /* Finish with altb's */ if (bp1->b_altb == bp) bp1->b_altb = (bp->b_altb == bp1) ? NULL : bp->b_altb; bp1 = bp1->b_bufp; } while ((rec = TAILQ_FIRST(&bp->b_undo))) { TAILQ_REMOVE(&bp->b_undo, rec, next); free_undo_record(rec); } free(bp->b_bname); /* Release name block */ free(bp); /* Release buffer block */ return (TRUE); }
int main(int argc, char **argv) { char *cp, *init_fcn_name = NULL; PF init_fcn = NULL; int o, i, nfiles; struct buffer *bp = NULL; while ((o = getopt(argc, argv, "f:")) != -1) switch (o) { case 'f': if (init_fcn_name != NULL) errx(1, "cannot specify more than one " "initial function"); init_fcn_name = optarg; break; default: usage(); } argc -= optind; argv += optind; setlocale(LC_CTYPE, ""); maps_init(); /* Keymaps and modes. */ funmap_init(); /* Functions. */ if (init_fcn_name && (init_fcn = name_function(init_fcn_name)) == NULL) errx(1, "Unknown function `%s'", init_fcn_name); vtinit(); /* Virtual terminal. */ dirinit(); /* Get current directory. */ edinit(bp); /* Buffers, windows. */ bellinit(); /* Audible and visible bell. */ /* * doing update() before reading files causes the error messages from * the file I/O show up on the screen. (and also an extra display of * the mode line if there are files specified on the command line.) */ update(CMODE); /* Force FFOTHARG=1 so that this mode is enabled, not simply toggled */ if (init_fcn) init_fcn(FFOTHARG, 1); for (nfiles = 0, i = 0; i < argc; i++) { if (argv[i][0] == '+' && strlen(argv[i]) >= 2) { long lval; char *end; lval = strtol(&argv[i][1], &end, 0); if (argv[i][1] == '\0' || *end != '\0') goto notnum; startrow = lval; } else { notnum: cp = adjustname(argv[i], FALSE); if (cp != NULL) { if (nfiles == 1) splitwind(0, 1); if ((curbp = findbuffer(cp)) == NULL) { vttidy(); errx(1, "Can't find current buffer!"); } (void)showbuffer(curbp, curwp, 0); if (readin(cp) != TRUE) killbuffer(curbp); else { /* Ensure enabled, not just toggled */ if (init_fcn_name) init_fcn(FFOTHARG, 1); nfiles++; } } } } if (nfiles > 2) listbuffers(0, 1); /* fake last flags */ thisflag = 0; for (;;) { if (epresf == KCLEAR) eerase(); if (epresf == TRUE) epresf = KCLEAR; if (winch_flag) { do_redraw(0, 0, TRUE); winch_flag = 0; } update(CMODE); lastflag = thisflag; thisflag = 0; switch (doin()) { case TRUE: break; case ABORT: ewprintf("Quit"); /* FALLTHRU */ case FALSE: default: macrodef = FALSE; } } }