Пример #1
0
R_API char *r_cons_editor (const char *file) {
	char *line;
	_n = 0;
	free (path);
	if (file) {
		path = strdup (file);
		lines = r_file_slurp (file, &bytes);
		nlines = r_str_split (lines, '\n');
		eprintf ("Loaded %d lines on %d bytes\n", nlines-1, bytes);
	} else path = NULL;
	r_cons_new ();
	I->line->hist_up = up;
	I->line->hist_down = down;
	I->line->contents = I->line->buffer.data;
	for (;;) {
		setnewline (_n);
		snprintf (prompt, sizeof (prompt), "%d: ", _n);
		r_line_set_prompt (prompt);
		line = r_line_readline ();
		saveline (_n, line);
		_n++;
		if (!line) break;
	}
	filesave ();
	return NULL;
}
Пример #2
0
void Zsave_file(void)
{
	if (Argp)
		saveall(false);
	else
		filesave();
}
Пример #3
0
/*
 * Fancy quit command, as implemented by Norm. If the current buffer has
 * changed do a write current buffer and exit emacs, otherwise simply exit.
 */
globle int quickexit(
  void *theEnv,
  int f,
  int n)
  {
   if ((curbp->b_flag&BFCHG) != 0          /* Changed.             */
        && (curbp->b_flag&BFTEMP) == 0)         /* Real.                */
     filesave(theEnv,f, n);
   return(edquit(theEnv,f, n));                     /* conditionally quit   */
  }
Пример #4
0
/*
 * Fancy quit command, as implemented by Norm. If the any buffer has
 * changed do a write on that buffer and exit emacs, otherwise simply exit.
 */
int
quickexit(int f, int n)
{
    register BUFFER *bp;	/* scanning pointer to buffers */

    bp = bheadp;
    while (bp != NULL) {
	if ((bp->b_flag&BFCHG) != 0	/* Changed.             */
	    && (bp->b_flag&BFTEMP) == 0) {	/* Real.                */
	    curbp = bp;		/* make that buffer cur	*/
	    filesave(f, n);
	}
	bp = bp->b_bufp;			/* on to the next buffer */
    }
    return(wquit(f, n));                             /* conditionally quit   */
}
Пример #5
0
int filenext(f,n)
{	int s;
	extern int gargi,gargc;
	extern char **gargv;

	if (filesave(f,n) == FALSE)	/* save current file		*/
		return FALSE;
	if (gargi < gargc)		/* if more files on command line */
	{
		s = readin(gargv[gargi]);
		gargi++;
	}
	else				/* get file name from user	*/
		s = fileread(f,n);
	makename(curbp->b_bname,curbp->b_fname);
	return s;
}
Пример #6
0
/*
 * Fancy quit command, as implemented by Norm. If any buffer has changed
 * do a write on that buffer and exit emacs, otherwise simply exit.
 */
int quickexit(int f, int n)
{
  BUFFER *bp;			/* scanning pointer to buffers */

  bp = bheadp;
  while (bp != NULL)
    {
      if ((bp->b_flag & BFCHG) != 0 /* Changed */
	  && (bp->b_flag & BFTEMP) == 0)
	{			/* Real */
	  curbp = bp;		/* make that buffer current */
	  mlwrite("[Saving %s]", (int*)bp->b_fname);
	  filesave(f, n);
	}
      bp = bp->b_bufp;		/* on to the next buffer */
    }
  return quit(f, n);		/* conditionally quit */
}
Пример #7
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;
}
Пример #8
0
/*
 * This is the general command execution routine. It handles the fake binding
 * of all the keys to "self-insert". It also clears out the "thisflag" word,
 * and arranges to move it to the "lastflag", so that the next command can
 * look at it. Return the status of command.
 */
int execute(int c, int f, int n)
{
	int status;
	fn_t execfunc;

	/* if the keystroke is a bound function...do it */
	execfunc = getbind(c);
	if (execfunc != NULL) {
		thisflag = 0;
		status = (*execfunc) (f, n);
		lastflag = thisflag;
		return status;
	}

	/*
	 * If a space was typed, fill column is defined, the argument is non-
	 * negative, wrap mode is enabled, and we are now past fill column,
	 * and we are not read-only, perform word wrap.
	 */
	if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 &&
	    n >= 0 && getccol(FALSE) > fillcol &&
	    (curwp->w_bufp->b_mode & MDVIEW) == FALSE)
		execute(META | SPEC | 'W', FALSE, 1);

#if	PKCODE
	if ((c >= 0x20 && c <= 0x7E)	/* Self inserting.      */
#if	IBMPC
	    || (c >= 0x80 && c <= 0xFE)) {
#else
#if	VMS || BSD || USG	/* 8BIT P.K. */
	    || (c >= 0xA0 && c <= 0xFFFF)) {
#else
	    ) {
#endif
#endif
#else
	if ((c >= 0x20 && c <= 0xFF)) {	/* Self inserting.      */
#endif
		if (n <= 0) {	/* Fenceposts.          */
			lastflag = 0;
			return n < 0 ? FALSE : TRUE;
		}
		thisflag = 0;	/* For the future.      */

		/* if we are in overwrite mode, not at eol,
		   and next char is not a tab or we are at a tab stop,
		   delete a char forword                        */
		if (curwp->w_bufp->b_mode & MDOVER &&
		    curwp->w_doto < curwp->w_dotp->l_used &&
		    (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
		     (curwp->w_doto) % 8 == 7))
			ldelchar(1, FALSE);

		/* do the appropriate insertion */
		if (c == '}' && (curbp->b_mode & MDCMOD) != 0)
			status = insbrace(n, c);
		else if (c == '#' && (curbp->b_mode & MDCMOD) != 0)
			status = inspound();
		else
			status = linsert(n, c);

#if	CFENCE
		/* check for CMODE fence matching */
		if ((c == '}' || c == ')' || c == ']') &&
		    (curbp->b_mode & MDCMOD) != 0)
			fmatch(c);
#endif

		/* check auto-save mode */
		if (curbp->b_mode & MDASAVE)
			if (--gacount == 0) {
				/* and save the file if needed */
				upscreen(FALSE, 0);
				filesave(FALSE, 0);
				gacount = gasave;
			}

		lastflag = thisflag;
		return status;
	}
	TTbeep();
	mlwrite("(Key not bound)");	/* complain             */
	lastflag = 0;		/* Fake last flags.     */
	return FALSE;
}

/*
 * Fancy quit command, as implemented by Norm. If the any buffer has
 * changed do a write on that buffer and exit emacs, otherwise simply exit.
 */
int quickexit(int f, int n)
{
	struct buffer *bp;	/* scanning pointer to buffers */
	struct buffer *oldcb;	/* original current buffer */
	int status;

	oldcb = curbp;		/* save in case we fail */

	bp = bheadp;
	while (bp != NULL) {
		if ((bp->b_flag & BFCHG) != 0	/* Changed.             */
		    && (bp->b_flag & BFTRUNC) == 0	/* Not truncated P.K.   */
		    && (bp->b_flag & BFINVS) == 0) {	/* Real.                */
			curbp = bp;	/* make that buffer cur */
			mlwrite("(Saving %s)", bp->b_fname);
#if	PKCODE
#else
			mlwrite("\n");
#endif
			if ((status = filesave(f, n)) != TRUE) {
				curbp = oldcb;	/* restore curbp */
				return status;
			}
		}
		bp = bp->b_bufp;	/* on to the next buffer */
	}
	quit(f, n);		/* conditionally quit   */
	return TRUE;
}

static void emergencyexit(int signr)
{
	quickexit(FALSE, 0);
	quit(TRUE, 0);
}

/*
 * Quit command. If an argument, always quit. Otherwise confirm if a buffer
 * has been changed and not written out. Normally bound to "C-X C-C".
 */
int quit(int f, int n)
{
	int s;

	if (f != FALSE		/* Argument forces it.  */
	    || anycb() == FALSE	/* All buffers clean.   */
	    /* User says it's OK.   */
	    || (s =
		mlyesno("Modified buffers exist. Leave anyway")) == TRUE) {
#if	(FILOCK && BSD) || SVR4
		if (lockrel() != TRUE) {
			TTputc('\n');
			TTputc('\r');
			TTclose();
			TTkclose();
			exit(1);
		}
#endif
		vttidy();
		if (f)
			exit(n);
		else
			exit(GOOD);
	}
	mlwrite("");
	return s;
}

/*
 * Begin a keyboard macro.
 * Error if not at the top level in keyboard processing. Set up variables and
 * return.
 */
int ctlxlp(int f, int n)
{
	if (kbdmode != STOP) {
		mlwrite("%%Macro already active");
		return FALSE;
	}
	mlwrite("(Start macro)");
	kbdptr = &kbdm[0];
	kbdend = kbdptr;
	kbdmode = RECORD;
	return TRUE;
}

/*
 * End keyboard macro. Check for the same limit conditions as the above
 * routine. Set up the variables and return to the caller.
 */
int ctlxrp(int f, int n)
{
	if (kbdmode == STOP) {
		mlwrite("%%Macro not active");
		return FALSE;
	}
	if (kbdmode == RECORD) {
		mlwrite("(End macro)");
		kbdmode = STOP;
	}
	return TRUE;
}

/*
 * Execute a macro.
 * The command argument is the number of times to loop. Quit as soon as a
 * command gets an error. Return TRUE if all ok, else FALSE.
 */
int ctlxe(int f, int n)
{
	if (kbdmode != STOP) {
		mlwrite("%%Macro already active");
		return FALSE;
	}
	if (n <= 0)
		return TRUE;
	kbdrep = n;		/* remember how many times to execute */
	kbdmode = PLAY;		/* start us in play mode */
	kbdptr = &kbdm[0];	/*    at the beginning */
	return TRUE;
}

/*
 * Abort.
 * Beep the beeper. Kill off any keyboard macro, etc., that is in progress.
 * Sometimes called as a routine, to do general aborting of stuff.
 */
int ctrlg(int f, int n)
{
	TTbeep();
	kbdmode = STOP;
	mlwrite("(Aborted)");
	return ABORT;
}
Пример #9
0
void iDraw()
{
	int m,n;
	iClear();
	iSetcolor(1,1,1);
	iFilledRectangle(1,1,width-19,height-18);		//draw text box
	iSetcolor(0,0,0);
	iRectangle(1,1,width-19,height-19);				//draw text boundary

	if (selflag)
	{
		for (int l=selSI; l<=selEI; l++)
		{
			int sx = (l==selSI)?( (selSJ==0)?3:selSJ*charSpace) : 3;
			int sy = height - 17 - (l+1-s)*lineSpace - 5;
			int w;
			if (l==selSI)
				w = (selSI == selEI) ? selEJ-selSJ : strlen(str+l*charMax*sizeof(char))-selSJ;
			else if (l==selEI)
				w = selEJ;
			else
				w = (strlen(str+l*charMax*sizeof(char))==0)?1:strlen(str+l*charMax*sizeof(char));

			iSetcolor(.8,.8,.9);
			iFilledRectangle(sx,sy,w*charSpace,lineSpace);
		}
	}

	iSetcolor(0,0,0);
	for (m=height-17-lineSpace, n=s; n<=imax; m-=lineSpace, n++)
	{
		iText(3, m, str+n*charMax*sizeof(char),font);		//print text
	}

	if (fOpen)
	{
		fileopen();
		iSetcolor(0,0,0);
		iText((width-15)/2-135,(height-19)/2+62,subTemp+r);		//print file open text
	}
	else if (fsave)
	{
		filesave();
		iSetcolor(0,0,0);
		iText((width-15)/2-135,(height-19)/2+62,subTemp+r);	//print file save as text
	}
	else if (aboutR)
	{
		aboutRword();
	}

	cursor();							//draw cursor		

	iSetcolor(.9,.9,.9);
	iFilledRectangle(3,height-17,width-19,17);

	iSetcolor(0,0,0);
	iLine(2,height-18,width-19,height-18);

	iSetcolor(0,0,0);
	iText(5,height-12,"File",GLUT_BITMAP_HELVETICA_12);			

	iSetcolor(0,0,0);
	iText(45,height-12,"Edit",GLUT_BITMAP_HELVETICA_12);

	iSetcolor(0,0,0);
	iText(85,height-12,"Format",GLUT_BITMAP_HELVETICA_12);

	iSetcolor(0,0,0);
	iText(141,height-12,"Help",GLUT_BITMAP_HELVETICA_12);		//draw menus
		
	if (menuflag == 1)
	{
		fileMenu();					//draw file drop down menu
	}
	else if (menuflag == 2)
	{
		editMenu();					//draw edit drop down menu
	}
	else if (menuflag == 3)
	{
		formatMenu();				//draw format drop down menu
	}
	else if (menuflag == 4)
	{
		helpMenu();					//draw help drop down menu
	}


	if (fontflag)
	{
		fontlist();						//draw font list
	}
	else if (saveM)
	{
		saveMessage();			//message box while exitting
	}

	scrollbar();                  // draw scrollbar



	if (load)
		loading();				//load window
}