1 /* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "cycript.hpp"
25 #include "JavaScript.hpp"
33 #ifdef HAVE_READLINE_H
36 #include <readline/readline.h>
42 #include <readline/history.h>
51 #include <sys/socket.h>
52 #include <sys/types.h>
57 #include <sys/ioctl.h>
58 #include <sys/types.h>
59 #include <sys/socket.h>
60 #include <netinet/in.h>
68 #include <mach/mach_time.h>
73 #include "Highlight.hpp"
76 extern "C" int rl_display_fixed
;
77 extern "C" int _rl_vis_botlin
;
78 extern "C" int _rl_last_c_pos
;
79 extern "C" int _rl_last_v_pos
;
81 typedef std::complex<int> CYCursor
;
83 static CYCursor current_
;
87 unsigned CYDisplayWidth() {
89 if (ioctl(1, TIOCGWINSZ
, &info
) != -1)
91 return tgetnum(const_cast<char *>("co"));
94 void CYDisplayOutput_(bool display
, const char *&data
) {
97 if (next
== '\0' || next
== CYIgnoreEnd
)
104 CYCursor
CYDisplayOutput(bool display
, int width
, const char *data
, ssize_t offset
= 0) {
105 CYCursor
point(current_
);
110 switch (char next
= *data
++) {
116 CYDisplayOutput_(display
, data
);
124 current_
+= CYCursor(0, 1);
125 if (current_
.imag() != width
)
127 current_
= CYCursor(current_
.real() + 1, 0);
133 current_
= CYCursor(current_
.real() + 1, 4);
148 void CYDisplayMove_(char *negative
, char *positive
, int offset
) {
150 putp(tparm(negative
, -offset
));
152 putp(tparm(positive
, offset
));
155 void CYDisplayMove(CYCursor target
) {
156 CYCursor
offset(target
- current_
);
158 CYDisplayMove_(parm_up_cursor
, parm_down_cursor
, offset
.real());
160 if (char *parm
= tparm(column_address
, target
.imag()))
163 CYDisplayMove_(parm_left_cursor
, parm_right_cursor
, offset
.imag());
168 void CYDisplayUpdate() {
169 current_
= CYCursor(_rl_last_v_pos
, _rl_last_c_pos
);
171 const char *prompt(rl_display_prompt
);
173 std::ostringstream stream
;
174 CYLexerHighlight(rl_line_buffer
, rl_end
, stream
, true);
175 std::string
string(stream
.str());
176 const char *buffer(string
.c_str());
178 int width(CYDisplayWidth());
179 if (width_
!= width
) {
180 current_
= CYCursor();
181 CYDisplayOutput(false, width
, prompt
);
182 current_
= CYDisplayOutput(false, width
, buffer
, point_
);
185 CYDisplayMove(CYCursor());
186 CYDisplayOutput(true, width
, prompt
);
187 CYCursor
target(CYDisplayOutput(true, width
, stream
.str().c_str(), rl_point
));
189 _rl_vis_botlin
= current_
.real();
191 if (current_
.imag() == 0)
192 CYDisplayOutput(true, width
, " ");
195 CYDisplayMove(target
);
198 _rl_last_v_pos
= current_
.real();
199 _rl_last_c_pos
= current_
.imag();
205 static volatile enum {
213 static jmp_buf ctrlc_
;
215 static void sigint(int) {
238 void Setup(CYDriver
&driver
) {
242 driver
.strict_
= true;
245 void Setup(CYOutput
&out
, CYDriver
&driver
, CYOptions
&options
, bool lower
) {
246 out
.pretty_
= pretty_
;
248 driver
.Replace(options
);
251 static CYUTF8String
Run(CYPool
&pool
, int client
, CYUTF8String code
) {
258 json
= CYExecute(CYGetJSContext(), pool
, code
);
270 _assert(CYSendAll(client
, &size
, sizeof(size
)));
271 _assert(CYSendAll(client
, code
.data
, code
.size
));
273 _assert(CYRecvAll(client
, &size
, sizeof(size
)));
274 if (size
== _not(uint32_t))
277 char *temp(new(pool
) char[size
+ 1]);
278 _assert(CYRecvAll(client
, temp
, size
));
285 return CYUTF8String(json
, size
);
288 static CYUTF8String
Run(CYPool
&pool
, int client
, const std::string
&code
) {
289 return Run(pool
, client
, CYUTF8String(code
.c_str(), code
.size()));
292 static std::ostream
*out_
;
294 static void Output(CYUTF8String json
, std::ostream
*out
, bool expand
= false) {
295 const char *data(json
.data
);
296 size_t size(json
.size
);
298 if (data
== NULL
|| out
== NULL
)
302 data
[0] != '@' && data
[0] != '"' && data
[0] != '\'' ||
303 data
[0] == '@' && data
[1] != '"' && data
[1] != '\''
305 CYLexerHighlight(data
, size
, *out
);
306 else for (size_t i(0); i
!= size
; ++i
)
309 else switch(data
[++i
]) {
310 case '\0': goto done
;
311 case '\\': *out
<< '\\'; break;
312 case '\'': *out
<< '\''; break;
313 case '"': *out
<< '"'; break;
314 case 'b': *out
<< '\b'; break;
315 case 'f': *out
<< '\f'; break;
316 case 'n': *out
<< '\n'; break;
317 case 'r': *out
<< '\r'; break;
318 case 't': *out
<< '\t'; break;
319 case 'v': *out
<< '\v'; break;
320 default: *out
<< '\\'; --i
; break;
327 int (*append_history$
)(int, const char *);
329 static std::string command_
;
333 static CYUTF8String
Run(CYPool
&pool
, const std::string
&code
) {
334 return Run(pool
, client_
, code
);
337 static char **Complete(const char *word
, int start
, int end
) {
338 rl_attempted_completion_over
= ~0;
339 std::string
line(rl_line_buffer
, start
);
340 char **values(CYComplete(word
, command_
+ line
, &Run
));
345 // need char *, not const char *
346 static char name_
[] = "cycript";
347 static char break_
[] = " \t\n\"\\'`@><=;|&{(" ")}" ".:[]";
351 std::string histfile_
;
355 History(std::string histfile
) :
359 read_history(histfile_
.c_str());
361 for (HIST_ENTRY
*history((history_set_pos(0), current_history())); history
; history
= next_history())
362 for (char *character(history
->line
); *character
; ++character
)
363 if (*character
== '\x01') *character
= '\n';
367 for (HIST_ENTRY
*history((history_set_pos(0), current_history())); history
; history
= next_history())
368 for (char *character(history
->line
); *character
; ++character
)
369 if (*character
== '\n') *character
= '\x01';
371 if (append_history$
!= NULL
) {
372 int fd(_syscall(open(histfile_
.c_str(), O_CREAT
| O_WRONLY
, 0600)));
374 _assert((*append_history$
)(histlines_
, histfile_
.c_str()) == 0);
376 _assert(write_history(histfile_
.c_str()) == 0);
378 } catch (const CYException
&error
) {
380 std::cout
<< error
.PoolCString(pool
) << std::endl
;
383 void operator +=(std::string command
) {
384 add_history(command
.c_str());
389 template <typename Type_
>
390 static Type_
*CYmemrchr(Type_
*data
, Type_ value
, size_t size
) {
392 if (data
[--size
] == value
)
397 static void _lblcall(int (*command
)(int, int), int count
, int key
) {
398 int last(_rl_last_c_pos
);
399 // rl_rubout crashes in _rl_erase_at_end_of_line if _rl_last_c_pos != 0
400 if (command
== &rl_rubout
)
402 for (int i(0); i
!= count
; ++i
)
403 if (command(1, key
) != 0)
405 _rl_last_c_pos
= last
;
408 static int CYConsoleKeyReturn(int count
, int key
) {
409 if (rl_point
!= rl_end
) {
410 if (memchr(rl_line_buffer
, '\n', rl_end
) == NULL
) {
411 _lblcall(&rl_newline
, count
, key
);
416 char *before(CYmemrchr(rl_line_buffer
, '\n', rl_point
));
418 before
= rl_line_buffer
;
420 int space(before
+ 1 - rl_line_buffer
);
421 while (space
!= rl_point
&& rl_line_buffer
[space
] == ' ')
424 int adjust(rl_line_buffer
+ space
- 1 - before
);
425 if (space
== rl_point
&& adjust
!= 0)
426 _lblcall(&rl_rubout
, adjust
, '\b');
428 _lblcall(&rl_insert
, count
, '\n');
430 _lblcall(&rl_insert
, adjust
, ' ');
436 if (rl_line_buffer
[0] == '?')
439 std::string
command(rl_line_buffer
, rl_end
);
441 std::stringbuf
stream(command
);
443 size_t last(std::string::npos
);
444 for (size_t i(0); i
!= std::string::npos
; i
= command
.find('\n', i
+ 1))
448 CYDriver
driver(pool
, stream
);
449 if (driver
.Parse() || !driver
.errors_
.empty())
450 for (CYDriver::Errors::const_iterator
error(driver
.errors_
.begin()); error
!= driver
.errors_
.end(); ++error
) {
451 if (error
->location_
.begin
.line
!= last
+ 1)
460 _lblcall(&rl_newline
, count
, key
);
464 // XXX: this was the most obvious fix, but is seriously dumb
468 static int CYConsoleKeyUp(int count
, int key
) {
469 for (; count
!= 0; --count
) {
470 char *after(CYmemrchr(rl_line_buffer
, '\n', rl_point
));
472 if (int value
= rl_get_previous_history(1, key
))
477 char *before(CYmemrchr(rl_line_buffer
, '\n', after
- rl_line_buffer
));
479 before
= rl_line_buffer
- 1;
481 ptrdiff_t offset(rl_line_buffer
+ rl_point
- after
);
482 if (offset
> after
- before
)
483 rl_point
= after
- rl_line_buffer
;
485 rl_point
= before
+ offset
- rl_line_buffer
;
491 static int CYConsoleKeyDown(int count
, int key
) {
492 for (; count
!= 0; --count
) {
493 char *after(static_cast<char *>(memchr(rl_line_buffer
+ rl_point
, '\n', rl_end
- rl_point
)));
495 int where(where_history());
496 if (int value
= rl_get_next_history(1, key
))
498 if (where
!= where_history()) {
499 char *first(static_cast<char *>(memchr(rl_line_buffer
, '\n', rl_end
)));
501 rl_point
= first
- 1 - rl_line_buffer
;
506 char *before(CYmemrchr(rl_line_buffer
, '\n', rl_point
));
508 before
= rl_line_buffer
- 1;
510 char *next(static_cast<char *>(memchr(after
+ 1, '\n', rl_line_buffer
+ rl_end
- after
- 1)));
512 next
= rl_line_buffer
+ rl_end
;
514 ptrdiff_t offset(rl_line_buffer
+ rl_point
- before
);
515 if (offset
> next
- after
)
516 rl_point
= next
- rl_line_buffer
;
518 rl_point
= after
+ offset
- rl_line_buffer
;
524 static int CYConsoleLineBegin(int count
, int key
) {
525 while (rl_point
!= 0 && rl_line_buffer
[rl_point
- 1] != '\n')
530 static int CYConsoleLineEnd(int count
, int key
) {
531 while (rl_point
!= rl_end
&& rl_line_buffer
[rl_point
] != '\n')
533 if (rl_point
!= rl_end
&& rl_editing_mode
== 0)
538 static int CYConsoleKeyBack(int count
, int key
) {
539 for (; count
!= 0; --count
) {
543 char *before(CYmemrchr(rl_line_buffer
, '\n', rl_point
));
544 if (before
== NULL
) {
545 int adjust(std::min(count
, rl_point
));
546 _lblcall(&rl_rubout
, adjust
, key
);
551 int start(before
+ 1 - rl_line_buffer
);
552 if (start
== rl_point
) rubout
: {
553 _lblcall(&rl_rubout
, 1, key
);
557 for (int i(start
); i
!= rl_point
; ++i
)
558 if (rl_line_buffer
[i
] != ' ')
560 _lblcall(&rl_rubout
, (rl_point
- start
) % 4 ?: 4, key
);
566 static int CYConsoleKeyTab(int count
, int key
) {
567 char *before(CYmemrchr(rl_line_buffer
, '\n', rl_point
));
568 if (before
== NULL
) complete
:
569 return rl_complete_internal(rl_completion_mode(&CYConsoleKeyTab
));
570 int start(before
+ 1 - rl_line_buffer
);
571 for (int i(start
); i
!= rl_point
; ++i
)
572 if (rl_line_buffer
[i
] != ' ')
574 _lblcall(&rl_insert
, 4 - (rl_point
- start
) % 4, ' ');
578 static void CYConsoleRemapBind(Keymap map
, rl_command_func_t
*from
, rl_command_func_t
*to
) {
579 char **keyseqs(rl_invoking_keyseqs_in_map(from
, map
));
582 for (char **keyseq(keyseqs
); *keyseq
!= NULL
; ++keyseq
) {
583 rl_bind_keyseq_in_map(*keyseq
, to
, map
);
589 static void CYConsoleRemapKeys(Keymap map
) {
590 CYConsoleRemapBind(map
, &rl_beg_of_line
, &CYConsoleLineBegin
);
591 CYConsoleRemapBind(map
, &rl_end_of_line
, &CYConsoleLineEnd
);
593 CYConsoleRemapBind(map
, &rl_get_previous_history
, &CYConsoleKeyUp
);
594 CYConsoleRemapBind(map
, &rl_get_next_history
, &CYConsoleKeyDown
);
596 CYConsoleRemapBind(map
, &rl_rubout
, &CYConsoleKeyBack
);
597 CYConsoleRemapBind(map
, &rl_complete
, &CYConsoleKeyTab
);
600 static void CYConsolePrepTerm(int meta
) {
601 rl_prep_terminal(meta
);
603 CYConsoleRemapKeys(emacs_standard_keymap
);
604 CYConsoleRemapKeys(emacs_meta_keymap
);
605 CYConsoleRemapKeys(emacs_ctlx_keymap
);
606 CYConsoleRemapKeys(vi_insertion_keymap
);
607 CYConsoleRemapKeys(vi_movement_keymap
);
610 static void CYOutputRun(const std::string
&code
, bool expand
= false) {
612 Output(Run(pool
, client_
, code
), &std::cout
, expand
);
615 static void Console(CYOptions
&options
) {
618 basedir
= "/data/local/tmp";
620 if (const char *home
= getenv("HOME"))
624 if (const char *username
= getenv("LOGNAME"))
625 passwd
= getpwnam(username
);
627 passwd
= getpwuid(getuid());
628 basedir
= passwd
->pw_dir
;
632 basedir
+= "/.cycript";
633 mkdir(basedir
.c_str(), 0700);
636 rl_readline_name
= name_
;
638 History
history(basedir
+ "/history");
647 rl_completer_word_break_characters
= break_
;
648 rl_attempted_completion_function
= &Complete
;
650 if (cur_term
!= NULL
) {
651 rl_redisplay_function
= CYDisplayUpdate
;
652 rl_prep_term_function
= CYConsolePrepTerm
;
657 struct sigaction action
;
658 sigemptyset(&action
.sa_mask
);
659 action
.sa_handler
= &sigint
;
661 sigaction(SIGINT
, &action
, NULL
);
664 if (setjmp(ctrlc_
) != 0) {
671 rl_bind_key('\r', &rl_newline
);
672 rl_bind_key('\n', &rl_newline
);
674 rl_bind_key('\r', &CYConsoleKeyReturn
);
675 rl_bind_key('\n', &CYConsoleKeyReturn
);
679 char *line(readline("cy# "));
687 std::string
command(line
);
693 if (command
[0] == '?') {
694 std::string
data(command
.substr(1));
695 if (data
== "bypass") {
697 *out_
<< "bypass == " << (bypass
? "true" : "false") << std::endl
;
698 } else if (data
== "debug") {
700 *out_
<< "debug == " << (debug
? "true" : "false") << std::endl
;
701 } else if (data
== "destroy") {
703 } else if (data
== "gc") {
704 *out_
<< "collecting... " << std::flush
;
705 CYGarbageCollect(CYGetJSContext());
706 *out_
<< "done." << std::endl
;
707 } else if (data
== "exit") {
709 } else if (data
== "expand") {
711 *out_
<< "expand == " << (expand
? "true" : "false") << std::endl
;
712 } else if (data
== "lower") {
714 *out_
<< "lower == " << (lower
? "true" : "false") << std::endl
;
724 std::stringbuf
stream(command
);
727 CYDriver
driver(pool
, stream
);
730 if (driver
.Parse() || !driver
.errors_
.empty()) {
731 for (CYDriver::Errors::const_iterator
error(driver
.errors_
.begin()); error
!= driver
.errors_
.end(); ++error
) {
732 CYPosition
begin(error
->location_
.begin
);
733 CYPosition
end(error
->location_
.end
);
735 /*if (begin.line != lines2.size()) {
737 std::cerr << lines2[begin.line - 1] << std::endl;
741 for (size_t i(0); i
!= begin
.column
; ++i
)
743 if (begin
.line
!= end
.line
|| begin
.column
== end
.column
)
745 else for (size_t i(0), e(end
.column
- begin
.column
); i
!= e
; ++i
)
747 std::cerr
<< std::endl
;
750 std::cerr
<< error
->message_
<< std::endl
;
758 if (driver
.script_
== NULL
)
762 CYOutput
out(str
, options
);
763 Setup(out
, driver
, options
, lower
);
764 out
<< *driver
.script_
;
766 } catch (const CYException
&error
) {
768 std::cout
<< error
.PoolCString(pool
) << std::endl
;
774 CYLexerHighlight(code
.c_str(), code
.size(), std::cout
);
775 std::cout
<< std::endl
;
778 CYOutputRun(code
, expand
);
782 void InjectLibrary(pid_t
, int, const char *const []);
784 static uint64_t CYGetTime() {
786 return mach_absolute_time();
788 struct timespec spec
;
789 clock_gettime(CLOCK_MONOTONIC
, &spec
);
790 return spec
.tv_sec
* UINT64_C(1000000000) + spec
.tv_nsec
;
794 int Main(int argc
, char * const argv
[], char const * const envp
[]) {
795 bool tty(isatty(STDIN_FILENO
));
800 append_history$
= (int (*)(int, const char *)) (dlsym(RTLD_DEFAULT
, "append_history"));
803 pid_t
pid(_not(pid_t
));
806 const char *host(NULL
);
807 const char *port(NULL
);
812 int option(getopt_long(argc
, argv
,
821 , (const struct option
[]) {
822 {NULL
, no_argument
, NULL
, 'c'},
823 {NULL
, required_argument
, NULL
, 'g'},
824 {NULL
, required_argument
, NULL
, 'n'},
826 {NULL
, required_argument
, NULL
, 'p'},
828 {NULL
, required_argument
, NULL
, 'r'},
829 {NULL
, no_argument
, NULL
, 's'},
830 {0, 0, 0, 0}}, NULL
));
839 "usage: cycript [-c]"
844 " [<script> [<arg>...]]\n"
852 fprintf(stderr
, "only one of -[c"
856 "r] may be used at a time\n");
867 else if (strcmp(optarg
, "rename") == 0)
868 options
.verbose_
= true;
869 else if (strcmp(optarg
, "bison") == 0)
871 else if (strcmp(optarg
, "timing") == 0)
874 fprintf(stderr
, "invalid name for -g\n");
881 else if (strcmp(optarg
, "minify") == 0)
884 fprintf(stderr
, "invalid name for -n\n");
891 size_t size(strlen(optarg
));
894 pid
= strtoul(optarg
, &end
, 0);
895 if (optarg
+ size
!= end
) {
896 // XXX: arg needs to be escaped in some horrendous way of doom
897 // XXX: this is a memory leak now because I just don't care enough
899 int writ(asprintf(&command
, "ps axc|sed -e '/^ *[0-9]/{s/^ *\\([0-9]*\\)\\( *[^ ]*\\)\\{3\\} *-*\\([^ ]*\\)/\\3 \\1/;/^%s /{s/^[^ ]* //;q;};};d'", optarg
));
902 if (FILE *pids
= popen(command
, "r")) {
907 size_t read(fread(value
+ size
, 1, sizeof(value
) - size
, pids
));
912 if (size
== sizeof(value
))
920 if (value
[size
- 1] == '\n') {
926 size
= strlen(value
);
927 pid
= strtoul(value
, &end
, 0);
928 if (value
+ size
!= end
) fail
:
930 _syscall(pclose(pids
));
933 if (pid
== _not(pid_t
)) {
934 fprintf(stderr
, "unable to find process `%s' using ps\n", optarg
);
942 //size_t size(strlen(optarg));
944 char *colon(strrchr(optarg
, ':'));
946 fprintf(stderr
, "missing colon in hostspec\n");
951 port = strtoul(colon + 1, &end, 10);
952 if (end != optarg + size) {
953 fprintf(stderr, "invalid port in hostspec\n");
978 if (pid
!= _not(pid_t
) && argc
> 1) {
979 fprintf(stderr
, "-p cannot set argv\n");
988 // XXX: const_cast?! wtf gcc :(
989 CYSetArgs(argc
- 1, const_cast<const char **>(argv
+ 1));
992 if (strcmp(script
, "-") == 0)
997 if (pid
== _not(pid_t
))
1015 } server(_syscall(socket(PF_UNIX
, SOCK_STREAM
, 0)));
1017 struct sockaddr_un address
;
1018 memset(&address
, 0, sizeof(address
));
1019 address
.sun_family
= AF_UNIX
;
1022 #if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
1023 tmp
= "/Library/Caches";
1028 sprintf(address
.sun_path
, "%s/.s.cy.%u", tmp
, getpid());
1029 unlink(address
.sun_path
);
1034 File(const char *path
) :
1042 } file(address
.sun_path
);
1044 _syscall(bind(server
, reinterpret_cast<sockaddr
*>(&address
), sizeof(address
)));
1045 _syscall(chmod(address
.sun_path
, 0777));
1047 _syscall(listen(server
, 1));
1048 const char *const argv
[] = {address
.sun_path
, NULL
};
1049 InjectLibrary(pid
, 1, argv
);
1050 client_
= _syscall(accept(server
, NULL
, NULL
));
1056 if (client_
== -1 && host
!= NULL
&& port
!= NULL
) {
1057 struct addrinfo hints
;
1058 memset(&hints
, 0, sizeof(hints
));
1059 hints
.ai_family
= AF_UNSPEC
;
1060 hints
.ai_socktype
= SOCK_STREAM
;
1061 hints
.ai_protocol
= 0;
1064 struct addrinfo
*infos
;
1065 _syscall(getaddrinfo(host
, port
, &hints
, &infos
));
1067 _assert(infos
!= NULL
); try {
1068 for (struct addrinfo
*info(infos
); info
!= NULL
; info
= info
->ai_next
) {
1069 int client(_syscall(socket(info
->ai_family
, info
->ai_socktype
, info
->ai_protocol
))); try {
1070 _syscall(connect(client
, info
->ai_addr
, info
->ai_addrlen
));
1074 _syscall(close(client
));
1079 freeaddrinfo(infos
);
1084 if (script
== NULL
&& tty
)
1087 std::istream
*stream
;
1088 if (script
== NULL
) {
1092 stream
= new std::fstream(script
, std::ios::in
| std::ios::binary
);
1093 _assert(!stream
->fail());
1097 std::stringbuf buffer
;
1098 stream
->get(buffer
, '\0');
1099 _assert(!stream
->fail());
1103 uint64_t start(CYGetTime());
1106 stream
= new std::istringstream(buffer
.str());
1109 CYDriver
driver(pool
, *stream
->rdbuf(), script
);
1112 uint64_t begin(CYGetTime());
1114 uint64_t end(CYGetTime());
1118 average
+= (end
- begin
- average
) / ++samples
;
1120 uint64_t now(CYGetTime());
1123 else if ((now
- start
) / 1000000000 >= 1)
1124 std::cout
<< std::fixed
<< average
<< '\t' << (end
- begin
) << '\t' << samples
<< std::endl
;
1130 stream
= new std::istringstream(buffer
.str());
1135 CYDriver
driver(pool
, *stream
->rdbuf(), script
);
1138 bool failed(driver
.Parse());
1140 if (failed
|| !driver
.errors_
.empty()) {
1141 for (CYDriver::Errors::const_iterator
i(driver
.errors_
.begin()); i
!= driver
.errors_
.end(); ++i
)
1142 std::cerr
<< i
->location_
.begin
<< ": " << i
->message_
<< std::endl
;
1144 } else if (driver
.script_
!= NULL
) {
1146 CYOutput
out(str
, options
);
1147 Setup(out
, driver
, options
, true);
1148 out
<< *driver
.script_
;
1149 std::string
code(str
.str());
1153 CYUTF8String
json(Run(pool
, client_
, code
));
1154 if (CYStartsWith(json
, "throw ")) {
1155 CYLexerHighlight(json
.data
, json
.size
, std::cerr
);
1156 std::cerr
<< std::endl
;
1166 int main(int argc
, char * const argv
[], char const * const envp
[]) {
1168 return Main(argc
, argv
, envp
);
1169 } catch (const CYException
&error
) {
1171 fprintf(stderr
, "%s\n", error
.PoolCString(pool
));