132
132
{Port,{data,Bytes}} ->
133
133
case get(shell) of
135
case string_chr(Bytes, [7,3]) of
135
server_loop(Port, queue:snoc(Q, Bytes));
137
case contains_ctrl_g_or_ctrl_c(Bytes) of
137
139
server_loop(Port, queue:snoc(Q, Bytes));
142
server_loop(Port, queue:snoc(Q, Bytes))
144
144
{io_request,From,ReplyAs,Request} when is_pid(From) ->
145
145
server_loop(Port, do_io_request(Request, From, ReplyAs, Port, Q));
342
342
get_chars_apply(State, M, F, Xa, Port, queue:snoc(Q, Bytes));
344
case string_chr(Bytes, [7,3]) of
344
case contains_ctrl_g_or_ctrl_c(Bytes) of
346
346
get_chars_apply(State, M, F, Xa, Port,
347
347
queue:snoc(Q, Bytes));
400
404
err_func(_, F, _) ->
403
%% Search for characters in a list or binary
404
string_chr(Bin, Characters) when is_binary(Bin), is_list(Characters) ->
405
string_chr_bin(0, Bin, Characters);
406
string_chr(List, Characters) when is_list(List), is_list(Characters) ->
407
string_chr_list(1, List, Characters).
409
string_chr_bin(I, B, Cs) when I < byte_size(B) ->
411
case string_chr_bin_check(I, B, Cs) of
415
string_chr_bin(J, B, Cs)
417
string_chr_bin(_, _, _) ->
420
string_chr_bin_check(I, B, [C|Cs]) ->
422
<<_:I/binary,C,_/binary>> ->
425
string_chr_bin_check(I, B, Cs)
427
string_chr_bin_check(_, _, []) ->
430
string_chr_list(I, [C|T], Cs) ->
431
case lists:member(C, Cs) of
435
string_chr_list(I+1, T, Cs)
437
string_chr_list(_, [], _) ->
407
%% using regexp reduces execution time by >50% compared to old code
408
%% running two regexps in sequence is much faster than \\x03|\\x07
409
contains_ctrl_g_or_ctrl_c(BinOrList)->
410
case {re:run(BinOrList, <<3>>),re:run(BinOrList, <<7>>)} of
411
{nomatch, nomatch} -> false;
440
415
%% Convert a buffer between list and binary