The R Project SVN R

Rev

Rev 27421 | Rev 28991 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27421 Rev 28544
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  file console.c
3
 *  file console.c
4
 *  Copyright (C) 1998--2003  Guido Masarotto and Brian Ripley
4
 *  Copyright (C) 1998--2003  Guido Masarotto and Brian Ripley
-
 
5
 *  Copyright (C) 2004	      The R Foundation
5
 *
6
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *  (at your option) any later version.
Line 568... Line 569...
568
      for (; *ch; ch++) storekey(c, *ch);
569
      for (; *ch; ch++) storekey(c, *ch);
569
      for (i = max_pos; i > cur_pos; i--) storekey(c, CHARLEFT);
570
      for (i = max_pos; i > cur_pos; i--) storekey(c, CHARLEFT);
570
    }
571
    }
571
FVOIDEND
572
FVOIDEND
572
 
573
 
-
 
574
static int CleanTranscript(char *tscpt, char *cmds)
-
 
575
{
-
 
576
    /*
-
 
577
     * Filter R commands out of a string that contains
-
 
578
     * prompts, commands, and output.
-
 
579
     * Uses a simple algorithm that just looks for '>'
-
 
580
     * prompts and '+' continuation -- won't work when
-
 
581
     * other prompts are used (e.g., as in a debugging
-
 
582
     * session.)
-
 
583
     * Always return the length of the string required
-
 
584
     * to hold the filtered commands.
-
 
585
     * If cmds is a non-null pointer, write the commands
-
 
586
     * to cmds & terminate with null.
-
 
587
     */
-
 
588
    int incommand = 0, startofline = 1, len = 0;
-
 
589
    while (*tscpt) {
-
 
590
	if (startofline) {
-
 
591
	    while (*tscpt==' ' || *tscpt=='\t')
-
 
592
		tscpt++;
-
 
593
	    if (*tscpt=='>' || (incommand && *tscpt=='+')) {
-
 
594
		tscpt++;
-
 
595
		if (*tscpt==' ' || *tscpt=='\t') tscpt++;
-
 
596
		incommand = 1;
-
 
597
	    } else {
-
 
598
		incommand = 0;
-
 
599
	    }
-
 
600
	    startofline = 0;
-
 
601
	} else {
-
 
602
	    if (incommand) {
-
 
603
		if (cmds)
-
 
604
		    *(cmds++) = *tscpt;
-
 
605
		len++;
-
 
606
	    }
-
 
607
	    if (*tscpt=='\n')
-
 
608
		startofline = 1;
-
 
609
	    tscpt++;
-
 
610
	}
-
 
611
    }
-
 
612
    if (cmds) {
-
 
613
	/* seem to have to terminate with two nulls, otherwise
-
 
614
	   pasting empty commands doesn't work correctly (e.g.,
-
 
615
	   when clipboard contains 'XXX') */
-
 
616
	*cmds = '\0';
-
 
617
	*(cmds+1) = '\0';
-
 
618
    }
-
 
619
    return(len+2);
-
 
620
}
-
 
621
 
573
/* the following three routines are  system dependent */
622
/* the following four routines are system dependent */
574
void consolepaste(control c)
623
void consolepaste(control c)
575
FBEGIN
624
FBEGIN
576
    HGLOBAL hglb;
625
    HGLOBAL hglb;
577
    char *pc, *new = NULL;
626
    char *pc, *new = NULL;
578
    if (p->sel) {
627
    if (p->sel) {
Line 604... Line 653...
604
        GlobalUnlock(hglb);
653
        GlobalUnlock(hglb);
605
    }
654
    }
606
    CloseClipboard();
655
    CloseClipboard();
607
FVOIDEND
656
FVOIDEND
608
 
657
 
-
 
658
void consolepastecmds(control c)
-
 
659
FBEGIN
-
 
660
    HGLOBAL hglb;
-
 
661
    char *pc, *new = NULL;
-
 
662
    if (p->sel) {
-
 
663
	p->sel = 0;
-
 
664
	p->needredraw = 1;
-
 
665
	REDRAW;
-
 
666
     }
-
 
667
    if (p->kind == PAGER) FVOIDRETURN;
-
 
668
    if ( OpenClipboard(NULL) &&
-
 
669
         (hglb = GetClipboardData(CF_TEXT)) &&
-
 
670
         (pc = (char *)GlobalLock(hglb)))
-
 
671
    {
-
 
672
        if (p->clp) {
-
 
673
	    new = realloc((void *)p->clp, strlen(p->clp) + CleanTranscript(pc, 0));
-
 
674
        }
-
 
675
        else {
-
 
676
	    new = malloc(CleanTranscript(pc, 0)) ;
-
 
677
	    if (new) new[0] = '\0';
-
 
678
	    p->already = p->numkeys;
-
 
679
	    p->pclp = 0;
-
 
680
        }
-
 
681
        if (new) {
-
 
682
            p->clp = new;
-
 
683
	    /* copy just the commands from the clipboard */
-
 
684
	    for (; *new; ++new); /* append to the end of 'new' */
-
 
685
	    CleanTranscript(pc, new);
-
 
686
        }
-
 
687
        else {
-
 
688
	    R_ShowMessage("Not enough memory");
-
 
689
        }
-
 
690
        GlobalUnlock(hglb);
-
 
691
    }
-
 
692
    CloseClipboard();
-
 
693
FVOIDEND
-
 
694
 
609
static void consoletoclipboardHelper(control c, int x0, int y0, int x1, int y1)
695
static void consoletoclipboardHelper(control c, int x0, int y0, int x1, int y1)
610
FBEGIN
696
FBEGIN
611
    HGLOBAL hglb;
697
    HGLOBAL hglb;
612
    int ll, i, j;
698
    int ll, i, j;
613
    char ch, *s;
699
    char ch, *s;
Line 1184... Line 1270...
1184
int pagerMultiple = 1, haveusedapager = 0;
1270
int pagerMultiple = 1, haveusedapager = 0;
1185
int consolebufb = DIMLBUF, consolebufl = MLBUF;
1271
int consolebufb = DIMLBUF, consolebufl = MLBUF;
1186
 
1272
 
1187
void
1273
void
1188
setconsoleoptions(char *fnname,int fnsty, int fnpoints,
1274
setconsoleoptions(char *fnname,int fnsty, int fnpoints,
1189
                  int rows, int cols, int consx, int consy, 
1275
                  int rows, int cols, int consx, int consy,
1190
		  rgb nfg, rgb nufg, rgb nbg, rgb high,
1276
		  rgb nfg, rgb nufg, rgb nbg, rgb high,
1191
		  int pgr, int pgc, int multiplewindows, int widthonresize,
1277
		  int pgr, int pgc, int multiplewindows, int widthonresize,
1192
		  int bufbytes, int buflines)
1278
		  int bufbytes, int buflines)
1193
{
1279
{
1194
    char msg[LF_FACESIZE + 128];
1280
    char msg[LF_FACESIZE + 128];