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>
74 #include "Highlight.hpp"
77 extern "C" int rl_display_fixed
;
78 extern "C" int _rl_vis_botlin
;
79 extern "C" int _rl_last_c_pos
;
80 extern "C" int _rl_last_v_pos
;
82 typedef std::complex<int> CYCursor
;
84 static CYCursor current_
;
88 unsigned CYDisplayWidth() {
90 if (ioctl(1, TIOCGWINSZ
, &info
) != -1)
92 return tgetnum(const_cast<char *>("co"));
95 void CYDisplayOutput_(bool display
, const char *&data
) {
98 if (next
== '\0' || next
== CYIgnoreEnd
)
105 CYCursor
CYDisplayOutput(bool display
, int width
, const char *data
, ssize_t offset
= 0) {
106 CYCursor
point(current_
);
111 switch (char next
= *data
++) {
117 CYDisplayOutput_(display
, data
);
125 current_
+= CYCursor(0, 1);
126 if (current_
.imag() != width
)
128 current_
= CYCursor(current_
.real() + 1, 0);
134 current_
= CYCursor(current_
.real() + 1, 4);
149 void CYDisplayMove_(char *negative
, char *positive
, int offset
) {
151 putp(tparm(negative
, -offset
));
153 putp(tparm(positive
, offset
));
156 void CYDisplayMove(CYCursor target
) {
157 CYCursor
offset(target
- current_
);
159 CYDisplayMove_(parm_up_cursor
, parm_down_cursor
, offset
.real());
161 if (char *parm
= tparm(column_address
, target
.imag()))
164 CYDisplayMove_(parm_left_cursor
, parm_right_cursor
, offset
.imag());
169 void CYDisplayUpdate() {
170 current_
= CYCursor(_rl_last_v_pos
, _rl_last_c_pos
);
172 const char *prompt(rl_display_prompt
);
174 std::ostringstream stream
;
175 CYLexerHighlight(rl_line_buffer
, rl_end
, stream
, true);
176 std::string
string(stream
.str());
177 const char *buffer(string
.c_str());
179 int width(CYDisplayWidth());
180 if (width_
!= width
) {
181 current_
= CYCursor();
182 CYDisplayOutput(false, width
, prompt
);
183 current_
= CYDisplayOutput(false, width
, buffer
, point_
);
186 CYDisplayMove(CYCursor());
187 CYDisplayOutput(true, width
, prompt
);
188 CYCursor
target(CYDisplayOutput(true, width
, stream
.str().c_str(), rl_point
));
190 _rl_vis_botlin
= current_
.real();
192 if (current_
.imag() == 0)
193 CYDisplayOutput(true, width
, " ");
196 CYDisplayMove(target
);
199 _rl_last_v_pos
= current_
.real();
200 _rl_last_c_pos
= current_
.imag();
206 static volatile enum {
214 static jmp_buf ctrlc_
;
216 static void sigint(int) {
239 void Setup(CYDriver
&driver
) {
243 driver
.strict_
= true;
246 void Setup(CYOutput
&out
, CYDriver
&driver
, CYOptions
&options
, bool lower
) {
247 out
.pretty_
= pretty_
;
249 driver
.Replace(options
);
254 virtual CYUTF8String
Run(CYPool
&pool
, CYUTF8String code
) = 0;
256 inline CYUTF8String
Run(CYPool
&pool
, const std::string
&code
) {
257 return Run(pool
, CYUTF8String(code
.c_str(), code
.size()));
261 class CYLocalRemote
:
265 virtual CYUTF8String
Run(CYPool
&pool
, CYUTF8String code
) {
271 json
= CYExecute(CYGetJSContext(), pool
, code
);
281 return CYUTF8String(json
, size
);
285 class CYSocketRemote
:
292 CYSocketRemote(const char *host
, const char *port
) {
293 struct addrinfo hints
;
294 memset(&hints
, 0, sizeof(hints
));
295 hints
.ai_family
= AF_UNSPEC
;
296 hints
.ai_socktype
= SOCK_STREAM
;
297 hints
.ai_protocol
= 0;
300 struct addrinfo
*infos
;
301 _syscall(getaddrinfo(host
, port
, &hints
, &infos
));
303 _assert(infos
!= NULL
); try {
304 for (struct addrinfo
*info(infos
); info
!= NULL
; info
= info
->ai_next
) {
305 socket_
= _syscall(socket(info
->ai_family
, info
->ai_socktype
, info
->ai_protocol
)); try {
306 _syscall(connect(socket_
, info
->ai_addr
, info
->ai_addrlen
));
309 _syscall(close(socket_
));
319 virtual CYUTF8String
Run(CYPool
&pool
, CYUTF8String code
) {
325 _assert(CYSendAll(socket_
, &size
, sizeof(size
)));
326 _assert(CYSendAll(socket_
, code
.data
, code
.size
));
328 _assert(CYRecvAll(socket_
, &size
, sizeof(size
)));
329 if (size
== _not(uint32_t)) {
333 char *temp(new(pool
) char[size
+ 1]);
334 _assert(CYRecvAll(socket_
, temp
, size
));
340 return CYUTF8String(json
, size
);
344 void InjectLibrary(pid_t
, std::ostream
&stream
, int, const char *const []);
346 class CYInjectRemote
:
353 CYInjectRemote(int pid
) :
359 virtual CYUTF8String
Run(CYPool
&pool
, CYUTF8String code
) {
360 std::ostringstream stream
;
361 const char *args
[2] = {"-e", code
.data
};
362 InjectLibrary(pid_
, stream
, 2, args
);
363 std::string
json(stream
.str());
364 if (!json
.empty() && json
[json
.size() - 1] == '\n')
365 json
.resize(json
.size() - 1);
366 return CYUTF8String(strdup(json
.c_str()), json
.size());
370 static std::ostream
*out_
;
372 static void Output(CYUTF8String json
, std::ostream
*out
, bool reparse
= false) {
376 CYStream
stream(json
.data
, json
.data
+ json
.size
);
377 CYDriver
driver(pool
, stream
);
378 if (driver
.Parse(CYMarkExpression
))
382 CYOutput
out(str
, options
);
384 out
<< *driver
.context_
;
385 std::string
data(str
.str());
386 json
= CYPoolUTF8String(pool
, data
);
391 const char *data(json
.data
);
392 size_t size(json
.size
);
394 if (size
== 0 || out
== NULL
)
397 CYLexerHighlight(data
, size
, *out
);
401 int (*append_history$
)(int, const char *);
403 static std::string command_
;
405 static CYRemote
*remote_
;
407 static CYUTF8String
Run(CYPool
&pool
, const std::string
&code
) {
408 return remote_
->Run(pool
, code
);
411 static char **Complete(const char *word
, int start
, int end
) {
412 rl_attempted_completion_over
= ~0;
413 std::string
line(rl_line_buffer
, start
);
414 char **values(CYComplete(word
, command_
+ line
, &Run
));
419 // need char *, not const char *
420 static char name_
[] = "cycript";
421 static char break_
[] = " \t\n\"\\'`@><=;|&{(" ")}" ".:[]";
425 std::string histfile_
;
429 History(std::string histfile
) :
433 read_history(histfile_
.c_str());
435 for (HIST_ENTRY
*history((history_set_pos(0), current_history())); history
; history
= next_history())
436 for (char *character(history
->line
); *character
; ++character
)
437 if (*character
== '\x01') *character
= '\n';
441 for (HIST_ENTRY
*history((history_set_pos(0), current_history())); history
; history
= next_history())
442 for (char *character(history
->line
); *character
; ++character
)
443 if (*character
== '\n') *character
= '\x01';
445 if (append_history$
!= NULL
) {
446 int fd(_syscall(open(histfile_
.c_str(), O_CREAT
| O_WRONLY
, 0600)));
448 _assert((*append_history$
)(histlines_
, histfile_
.c_str()) == 0);
450 _assert(write_history(histfile_
.c_str()) == 0);
452 } catch (const CYException
&error
) {
454 std::cout
<< error
.PoolCString(pool
) << std::endl
;
457 void operator +=(std::string command
) {
458 if (HIST_ENTRY
*entry
= history_get(where_history()))
459 if (command
== entry
->line
)
461 add_history(command
.c_str());
466 template <typename Type_
>
467 static Type_
*CYmemrchr(Type_
*data
, Type_ value
, size_t size
) {
469 if (data
[--size
] == value
)
474 static void _lblcall(int (*command
)(int, int), int count
, int key
) {
475 int last(_rl_last_c_pos
);
476 // rl_rubout crashes in _rl_erase_at_end_of_line if _rl_last_c_pos != 0
477 if (command
== &rl_rubout
)
479 for (int i(0); i
!= count
; ++i
)
480 if (command(1, key
) != 0)
482 _rl_last_c_pos
= last
;
485 static int CYConsoleKeyReturn(int count
, int key
) {
486 if (rl_point
!= rl_end
) {
487 if (memchr(rl_line_buffer
, '\n', rl_end
) == NULL
) {
488 _lblcall(&rl_newline
, count
, key
);
493 char *before(CYmemrchr(rl_line_buffer
, '\n', rl_point
));
495 before
= rl_line_buffer
;
497 int space(before
+ 1 - rl_line_buffer
);
498 while (space
!= rl_point
&& rl_line_buffer
[space
] == ' ')
501 int adjust(rl_line_buffer
+ space
- 1 - before
);
502 if (space
== rl_point
&& adjust
!= 0)
503 _lblcall(&rl_rubout
, adjust
, '\b');
505 _lblcall(&rl_insert
, count
, '\n');
507 _lblcall(&rl_insert
, adjust
, ' ');
513 if (rl_line_buffer
[0] == '?')
516 std::string
command(rl_line_buffer
, rl_end
);
518 std::stringbuf
stream(command
);
520 size_t last(std::string::npos
);
521 for (size_t i(0); i
!= std::string::npos
; i
= command
.find('\n', i
+ 1))
525 CYDriver
driver(pool
, stream
);
526 if (driver
.Parse() || !driver
.errors_
.empty())
527 for (CYDriver::Errors::const_iterator
error(driver
.errors_
.begin()); error
!= driver
.errors_
.end(); ++error
) {
528 if (error
->location_
.begin
.line
!= last
+ 1)
537 _lblcall(&rl_newline
, count
, key
);
541 // XXX: this was the most obvious fix, but is seriously dumb
545 static int CYConsoleKeyUp(int count
, int key
) {
546 for (; count
!= 0; --count
) {
547 char *after(CYmemrchr(rl_line_buffer
, '\n', rl_point
));
549 if (int value
= rl_get_previous_history(1, key
))
554 char *before(CYmemrchr(rl_line_buffer
, '\n', after
- rl_line_buffer
));
556 before
= rl_line_buffer
- 1;
558 ptrdiff_t offset(rl_line_buffer
+ rl_point
- after
);
559 if (offset
> after
- before
)
560 rl_point
= after
- rl_line_buffer
;
562 rl_point
= before
+ offset
- rl_line_buffer
;
568 static int CYConsoleKeyDown(int count
, int key
) {
569 for (; count
!= 0; --count
) {
570 char *after(static_cast<char *>(memchr(rl_line_buffer
+ rl_point
, '\n', rl_end
- rl_point
)));
572 int where(where_history());
573 if (int value
= rl_get_next_history(1, key
))
575 if (where
!= where_history()) {
576 char *first(static_cast<char *>(memchr(rl_line_buffer
, '\n', rl_end
)));
578 rl_point
= first
- 1 - rl_line_buffer
;
583 char *before(CYmemrchr(rl_line_buffer
, '\n', rl_point
));
585 before
= rl_line_buffer
- 1;
587 char *next(static_cast<char *>(memchr(after
+ 1, '\n', rl_line_buffer
+ rl_end
- after
- 1)));
589 next
= rl_line_buffer
+ rl_end
;
591 ptrdiff_t offset(rl_line_buffer
+ rl_point
- before
);
592 if (offset
> next
- after
)
593 rl_point
= next
- rl_line_buffer
;
595 rl_point
= after
+ offset
- rl_line_buffer
;
601 static int CYConsoleLineBegin(int count
, int key
) {
602 while (rl_point
!= 0 && rl_line_buffer
[rl_point
- 1] != '\n')
607 static int CYConsoleLineEnd(int count
, int key
) {
608 while (rl_point
!= rl_end
&& rl_line_buffer
[rl_point
] != '\n')
610 if (rl_point
!= rl_end
&& rl_editing_mode
== 0)
615 static int CYConsoleKeyBack(int count
, int key
) {
616 for (; count
!= 0; --count
) {
620 char *before(CYmemrchr(rl_line_buffer
, '\n', rl_point
));
621 if (before
== NULL
) {
622 int adjust(std::min(count
, rl_point
));
623 _lblcall(&rl_rubout
, adjust
, key
);
628 int start(before
+ 1 - rl_line_buffer
);
629 if (start
== rl_point
) rubout
: {
630 _lblcall(&rl_rubout
, 1, key
);
634 for (int i(start
); i
!= rl_point
; ++i
)
635 if (rl_line_buffer
[i
] != ' ')
637 _lblcall(&rl_rubout
, (rl_point
- start
) % 4 ?: 4, key
);
643 static int CYConsoleKeyTab(int count
, int key
) {
644 char *before(CYmemrchr(rl_line_buffer
, '\n', rl_point
));
645 if (before
== NULL
) complete
:
646 return rl_complete_internal(rl_completion_mode(&CYConsoleKeyTab
));
647 int start(before
+ 1 - rl_line_buffer
);
648 for (int i(start
); i
!= rl_point
; ++i
)
649 if (rl_line_buffer
[i
] != ' ')
651 _lblcall(&rl_insert
, 4 - (rl_point
- start
) % 4, ' ');
655 static void CYConsoleRemapBind(Keymap map
, rl_command_func_t
*from
, rl_command_func_t
*to
) {
656 char **keyseqs(rl_invoking_keyseqs_in_map(from
, map
));
659 for (char **keyseq(keyseqs
); *keyseq
!= NULL
; ++keyseq
) {
660 rl_bind_keyseq_in_map(*keyseq
, to
, map
);
666 static void CYConsoleRemapKeys(Keymap map
) {
667 CYConsoleRemapBind(map
, &rl_beg_of_line
, &CYConsoleLineBegin
);
668 CYConsoleRemapBind(map
, &rl_end_of_line
, &CYConsoleLineEnd
);
670 CYConsoleRemapBind(map
, &rl_get_previous_history
, &CYConsoleKeyUp
);
671 CYConsoleRemapBind(map
, &rl_get_next_history
, &CYConsoleKeyDown
);
673 CYConsoleRemapBind(map
, &rl_rubout
, &CYConsoleKeyBack
);
674 CYConsoleRemapBind(map
, &rl_complete
, &CYConsoleKeyTab
);
677 static void CYConsolePrepTerm(int meta
) {
678 rl_prep_terminal(meta
);
680 CYConsoleRemapKeys(emacs_standard_keymap
);
681 CYConsoleRemapKeys(emacs_meta_keymap
);
682 CYConsoleRemapKeys(emacs_ctlx_keymap
);
683 CYConsoleRemapKeys(vi_insertion_keymap
);
684 CYConsoleRemapKeys(vi_movement_keymap
);
687 static void CYOutputRun(const std::string
&code
, bool reparse
= false) {
689 Output(Run(pool
, code
), &std::cout
, reparse
);
692 static void Console(CYOptions
&options
) {
695 basedir
= "/data/local/tmp";
697 if (const char *home
= getenv("HOME"))
701 if (const char *username
= getenv("LOGNAME"))
702 passwd
= getpwnam(username
);
704 passwd
= getpwuid(getuid());
705 basedir
= passwd
->pw_dir
;
709 basedir
+= "/.cycript";
710 mkdir(basedir
.c_str(), 0700);
713 rl_readline_name
= name_
;
715 History
history(basedir
+ "/history");
724 rl_completer_word_break_characters
= break_
;
725 rl_attempted_completion_function
= &Complete
;
727 if (cur_term
!= NULL
) {
728 rl_redisplay_function
= CYDisplayUpdate
;
729 rl_prep_term_function
= CYConsolePrepTerm
;
735 struct sigaction action
;
736 sigemptyset(&action
.sa_mask
);
737 action
.sa_handler
= &sigint
;
739 sigaction(SIGINT
, &action
, NULL
);
741 if (setjmp(ctrlc_
) != 0) {
748 rl_bind_key('\r', &rl_newline
);
749 rl_bind_key('\n', &rl_newline
);
751 rl_bind_key('\r', &CYConsoleKeyReturn
);
752 rl_bind_key('\n', &CYConsoleKeyReturn
);
756 char *line(readline("cy# "));
764 std::string
command(line
);
770 if (command
[0] == '?') {
771 std::string
data(command
.substr(1));
772 if (data
== "bypass") {
774 *out_
<< "bypass == " << (bypass
? "true" : "false") << std::endl
;
775 } else if (data
== "debug") {
777 *out_
<< "debug == " << (debug
? "true" : "false") << std::endl
;
778 } else if (data
== "destroy") {
780 } else if (data
== "gc") {
781 *out_
<< "collecting... " << std::flush
;
782 CYGarbageCollect(CYGetJSContext());
783 *out_
<< "done." << std::endl
;
784 } else if (data
== "exit") {
786 } else if (data
== "lower") {
788 *out_
<< "lower == " << (lower
? "true" : "false") << std::endl
;
789 } else if (data
== "reparse") {
791 *out_
<< "reparse == " << (reparse
? "true" : "false") << std::endl
;
801 std::stringbuf
stream(command
);
804 CYDriver
driver(pool
, stream
);
807 if (driver
.Parse() || !driver
.errors_
.empty()) {
808 for (CYDriver::Errors::const_iterator
error(driver
.errors_
.begin()); error
!= driver
.errors_
.end(); ++error
) {
809 CYPosition
begin(error
->location_
.begin
);
810 CYPosition
end(error
->location_
.end
);
812 /*if (begin.line != lines2.size()) {
814 std::cerr << lines2[begin.line - 1] << std::endl;
818 for (size_t i(0); i
!= begin
.column
; ++i
)
820 if (begin
.line
!= end
.line
|| begin
.column
== end
.column
)
822 else for (size_t i(0), e(end
.column
- begin
.column
); i
!= e
; ++i
)
824 std::cerr
<< std::endl
;
827 std::cerr
<< error
->message_
<< std::endl
;
835 if (driver
.script_
== NULL
)
839 CYOutput
out(str
, options
);
840 Setup(out
, driver
, options
, lower
);
841 out
<< *driver
.script_
;
843 } catch (const CYException
&error
) {
845 std::cout
<< error
.PoolCString(pool
) << std::endl
;
851 CYLexerHighlight(code
.c_str(), code
.size(), std::cout
);
852 std::cout
<< std::endl
;
855 CYOutputRun(code
, reparse
);
859 static uint64_t CYGetTime() {
861 return mach_absolute_time();
863 struct timespec spec
;
864 clock_gettime(CLOCK_MONOTONIC
, &spec
);
865 return spec
.tv_sec
* UINT64_C(1000000000) + spec
.tv_nsec
;
869 int Main(int argc
, char * const argv
[], char const * const envp
[]) {
870 bool tty(isatty(STDIN_FILENO
));
875 append_history$
= (int (*)(int, const char *)) (dlsym(RTLD_DEFAULT
, "append_history"));
877 pid_t
pid(_not(pid_t
));
879 const char *host(NULL
);
880 const char *port(NULL
);
882 const char *argv0(argv
[0]);
887 int option(getopt_long(argc
, argv
,
894 , (const struct option
[]) {
895 {NULL
, no_argument
, NULL
, 'c'},
896 {NULL
, required_argument
, NULL
, 'g'},
897 {NULL
, required_argument
, NULL
, 'n'},
898 {NULL
, required_argument
, NULL
, 'p'},
899 {NULL
, required_argument
, NULL
, 'r'},
900 {NULL
, no_argument
, NULL
, 's'},
901 {0, 0, 0, 0}}, NULL
));
910 "usage: cycript [-c]"
913 " [<script> [<arg>...]]\n"
921 fprintf(stderr
, "only one of -[cpr] may be used at a time\n");
932 else if (strcmp(optarg
, "rename") == 0)
933 options
.verbose_
= true;
934 else if (strcmp(optarg
, "bison") == 0)
936 else if (strcmp(optarg
, "timing") == 0)
939 fprintf(stderr
, "invalid name for -g\n");
946 else if (strcmp(optarg
, "minify") == 0)
949 fprintf(stderr
, "invalid name for -n\n");
955 size_t size(strlen(optarg
));
958 pid
= strtoul(optarg
, &end
, 0);
959 if (optarg
+ size
!= end
) {
960 // XXX: arg needs to be escaped in some horrendous way of doom
961 // XXX: this is a memory leak now because I just don't care enough
963 int writ(asprintf(&command
, "ps axc|sed -e '/^ *[0-9]/{s/^ *\\([0-9]*\\)\\( *[^ ]*\\)\\{3\\} *-*\\([^ ]*\\)/\\3 \\1/;/^%s /{s/^[^ ]* //;q;};};d'", optarg
));
966 if (FILE *pids
= popen(command
, "r")) {
971 size_t read(fread(value
+ size
, 1, sizeof(value
) - size
, pids
));
976 if (size
== sizeof(value
))
984 if (value
[size
- 1] == '\n') {
990 size
= strlen(value
);
991 pid
= strtoul(value
, &end
, 0);
992 if (value
+ size
!= end
) fail
:
994 _syscall(pclose(pids
));
997 if (pid
== _not(pid_t
)) {
998 fprintf(stderr
, "unable to find process `%s' using ps\n", optarg
);
1005 //size_t size(strlen(optarg));
1007 char *colon(strrchr(optarg
, ':'));
1008 if (colon
== NULL
) {
1009 fprintf(stderr
, "missing colon in hostspec\n");
1014 port = strtoul(colon + 1, &end, 10);
1015 if (end != optarg + size) {
1016 fprintf(stderr, "invalid port in hostspec\n");
1040 if (pid
!= _not(pid_t
) && argc
> 1) {
1041 fprintf(stderr
, "-p cannot set argv\n");
1049 if (strcmp(script
, "-") == 0)
1056 // XXX: const_cast?! wtf gcc :(
1057 CYSetArgs(argv0
, script
, argc
, const_cast<const char **>(argv
));
1060 if (remote_
== NULL
&& pid
!= _not(pid_t
))
1061 remote_
= new CYInjectRemote(pid
);
1063 if (remote_
== NULL
&& host
!= NULL
&& port
!= NULL
)
1064 remote_
= new CYSocketRemote(host
, port
);
1066 if (remote_
== NULL
)
1067 remote_
= new CYLocalRemote();
1069 if (script
== NULL
&& tty
)
1072 std::istream
*stream
;
1073 if (script
== NULL
) {
1077 stream
= new std::fstream(script
, std::ios::in
| std::ios::binary
);
1078 _assert(!stream
->fail());
1082 std::stringbuf buffer
;
1083 stream
->get(buffer
, '\0');
1084 _assert(!stream
->fail());
1088 uint64_t start(CYGetTime());
1091 stream
= new std::istringstream(buffer
.str());
1094 CYDriver
driver(pool
, *stream
->rdbuf(), script
);
1097 uint64_t begin(CYGetTime());
1099 uint64_t end(CYGetTime());
1103 average
+= (end
- begin
- average
) / ++samples
;
1105 uint64_t now(CYGetTime());
1108 else if ((now
- start
) / 1000000000 >= 1)
1109 std::cout
<< std::fixed
<< average
<< '\t' << (end
- begin
) << '\t' << samples
<< std::endl
;
1115 stream
= new std::istringstream(buffer
.str());
1120 CYDriver
driver(pool
, *stream
->rdbuf(), script
);
1123 bool failed(driver
.Parse());
1125 if (failed
|| !driver
.errors_
.empty()) {
1126 for (CYDriver::Errors::const_iterator
i(driver
.errors_
.begin()); i
!= driver
.errors_
.end(); ++i
)
1127 std::cerr
<< i
->location_
.begin
<< ": " << i
->message_
<< std::endl
;
1129 } else if (driver
.script_
!= NULL
) {
1131 CYOutput
out(str
, options
);
1132 Setup(out
, driver
, options
, true);
1133 out
<< *driver
.script_
;
1134 std::string
code(str
.str());
1138 CYUTF8String
json(Run(pool
, code
));
1139 if (CYStartsWith(json
, "throw ")) {
1140 CYLexerHighlight(json
.data
, json
.size
, std::cerr
);
1141 std::cerr
<< std::endl
;
1151 _visible
int main(int argc
, char * const argv
[], char const * const envp
[]) {
1153 return Main(argc
, argv
, envp
);
1154 } catch (const CYException
&error
) {
1156 fprintf(stderr
, "%s\n", error
.PoolCString(pool
));