FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/r/session/RScriptCallbacks.cpp at master · pearsonca/rstudio · GitHub
pearsonca
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
r
/
session
/
RScriptCallbacks.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
111 lines (89 loc) · 2.73 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
r
/
session
/
RScriptCallbacks.cpp
Copy path
File metadata and controls
111 lines (89 loc) · 2.73 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* RScriptCallbacks.cpp
*
* Copyright (C) 2009-18 by RStudio, PBC
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
<
shared_core/Error.hpp
>
#
include
<
shared_core/SafeConvert.hpp
>
#
include
<
r/RExec.hpp
>
#
include
"
REmbedded.hpp
"
#
include
"
RInit.hpp
"
#
include
"
RScriptCallbacks.hpp
"
#
include
"
RStdCallbacks.hpp
"
using
namespace
rstudio
::core
;
namespace
rstudio
{
namespace
r
{
namespace
session
{
namespace
{
//
script to run, if any
std::string s_runScript;
}
//
anonymous namespace
void
setRunScript
(
const
std::string& runScript)
{
s_runScript = runScript;
}
//
variant of RReadConsole which reads a script instead of using an interactive console
int
RReadScript
(
const
char
*pmt,
CONSOLE_BUFFER_CHAR
* buf,
int
buflen,
int
hist)
{
if
(s_runScript.
empty
())
{
//
exit after we have consumed the script
return
0
;
}
//
sanity check buffer length
if
(buflen <
2
)
{
return
0
;
}
//
attempt to initialize
Error initError;
Error error = r::exec::executeSafely<Error>(initialize, &initError);
if
(error)
LOG_ERROR
(error);
if
(initError)
LOG_ERROR
(initError);
//
ensure input fits in buffer; we need two extra bytes -- one for the terminating newline and
//
one for the terminating null
if
(s_runScript.
length
() >
static_cast
<
size_t
>(buflen -
2
))
{
std::string msg =
"
Script too long (
"
+
safe_convert::numberToString
(s_runScript.
length
()) +
"
), max is
"
+
safe_convert::numberToString
(buflen -
2
) +
"
characters)
"
;
LOG_ERROR_MESSAGE
(msg);
rSuicide
(msg);
}
//
copy input into buffer
s_runScript.
copy
(
reinterpret_cast
<
char
*>(buf), s_runScript.
length
(),
0
);
//
append newline and terminating null
buf[s_runScript.
length
()] =
'
\n
'
;
buf[s_runScript.
length
() +
1
] =
'
\0
'
;
//
remove script
s_runScript.
clear
();
//
success
return
1
;
}
//
variant of RWriteConsoleEx which writes to standard out
void
RWriteStdout
(
const
char
*buf,
int
buflen,
int
otype)
{
std::cout << buf;
}
void
RScriptCleanUp
(
SA_TYPE
saveact,
int
status,
int
runLast)
{
//
override save action for script runs
stdInternalCallbacks
()->
cleanUp
(
SA_NOSAVE
, status, runLast);
}
}
//
namespace session
}
//
namespace r
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL