Skip to content

Commit ab39b86

Browse files
author
Tom Szczesny
committed
fix #461: Shebang script support (merge from pahihu)
1 parent 7aec474 commit ab39b86

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ S fBreak = "t";
2929

3030
void boilerplate()
3131
{
32-
if(!isatty(STDOUT) || !isatty(STDIN)) R;
32+
if(!isatty(STDOUT) || !isatty(STDIN)) R;
3333
O("K Console - Enter \\ for help\n\n");
3434
prompt(0);
3535
}

src/kc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#ifndef WIN32
1515
#include <netinet/tcp.h>
1616
#include <pthread.h>
17-
#if !defined(PTHREAD_MUTEX_RECURSIVE) && defined(PTHREAD_MUTEX_RECURSIVE_NP)
17+
#ifndef PTHREAD_MUTEX_RECURSIVE
1818
#define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
1919
#endif
2020
#else
@@ -241,8 +241,9 @@ I check() { //in suspended execution mode: allows checking of state at time
241241
fCheck=ofCheck;
242242
R 0; }
243243

244+
static I fln=0;
244245
I lines(FILE*f) {
245-
S a=0;I n=0;PDA p=0; while(-1!=line(f,&a,&n,&p)){} R 0;}
246+
S a=0;I n=0;PDA p=0; fln=1; while(-1!=line(f,&a,&n,&p)){fln=0;} R 0;}
246247
//You could put lines(stdin) in main() to have not-multiplexed command-line-only input
247248

248249
I line(FILE*f, S*a, I*n, PDA*p) { //just starting or just executed: *a=*n=*p=0, intermediate is non-zero
@@ -252,6 +253,7 @@ I line(FILE*f, S*a, I*n, PDA*p) { //just starting or just executed: *a=*n=*p=0,
252253
I o = isatty(STDIN); //display results to stdout?
253254

254255
if(-1==(c=getline_(&s,&m,f))) GC;
256+
if(fln&&(s[0]=='#' && s[1]=='!')) GC;
255257
if(s[0]=='\\' && s[1]=='\n') {
256258
if(!fCheck&&fLoad) { c=-1; GC; } //escape file load
257259
if(fCheck) { fCheck--;R 0; } //escape suspended execution with single backslash
@@ -409,6 +411,7 @@ I attend() { //K3.2 uses fcntl somewhere
409411
if(pthread_create(&thread, NULL, timer_thread, NULL)){
410412
perror("Create timer thread"); abort(); }
411413

414+
fln=1;
412415
for(;;) { // main loop
413416
scrLim = 0;
414417
read_fds = master; // copy it
@@ -421,6 +424,7 @@ I attend() { //K3.2 uses fcntl somewhere
421424
if (FD_ISSET(i, &read_fds)) {
422425
if(i==STDIN) {
423426
nbytes=line(stdin,&a,&n,&q);
427+
fln=0;
424428
if(nbytes<=0){
425429
if(!IPC_PORT && !HTTP_PORT) exit(0); //Catch CTRL+D
426430
else FD_CLR(i,&master);} }

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
int main(int argc,S*argv)
55
{
66
kinit();
7-
boilerplate();
87
args(argc,argv);
8+
boilerplate();
99
attend(); //loop on stdin/inet
1010
R 0;
1111
}

0 commit comments

Comments
 (0)