OBJ builtin_include(int numArgs){ if( numArgs != 1){ js_error("(include): expects 1 argument", js_nil); } OBJ arg1 = POP(); char *fileName; FILE *theFile; if( !ISSTRING(arg1) ){ js_error("(include): string arg expected:", arg1); } fileName = STRINGVAL(arg1); theFile = fopen(fileName, "r"); if( theFile == NULL){ js_error("(include): cannot open file:", arg1); } OBJ inputStream = newFileStream(theFile); #ifdef DEBUG if( PRINT_INCLUDE->state){ printIndent(indentLevelForInclude); fprintf(stdout, "<include file:" YEL " %s" RESET" >\n", fileName); indentLevelForInclude++; } if( CONTINUATION_PASSING->state){ enterTrampoline1(inputStream); } else{ OBJ expr = js_read(inputStream); OBJ result; while( expr != js_eof){ result = js_eval(globalEnvironment, expr); if(PRINT_INCLUDE->state){ printIndent(indentLevelForInclude); js_print(stdout, result,1); printf("\n"); } expr = js_read(inputStream); } } if( PRINT_INCLUDE->state){ indentLevelForInclude--; printIndent(indentLevelForInclude); fprintf(stdout, "<EOF:" YEL " %s" RESET" >\n", fileName); } #else enterTrampoline1(inputStream); #endif fclose( inputStream->u.fileStream.file ); free( inputStream); return js_void; }
VOIDPTRFUNC CP_jREPL2(){ //fprintf(stdout, "\nStack in CP_jREPL2:\n"); //printJStack(__FILE__,__LINE__,__FUNCTION__); DEBUGCODE(PRINT_STACK->state, printJStack(__FILE__,__LINE__,__FUNCTION__)); OBJ result = RETVAL; #ifdef DEBUG if( (SP <= 5) || PRINT_INCLUDE->state){ printIndent(indentLevelForInclude); #else if( (SP <= 5)) { #endif js_print(stdout, result, 1); // P rint printf("\n"); } // L oop OBJ inputStream = ARG(0); TAILCALL1((VOIDPTRFUNC)CP_jREPL, inputStream); } int main() { initSymbolTable(); initializeWellKnownObjects(); initJStack(); #ifdef DEBUG initDebugOptions(); initGlobalEnvironment(); setupInitialEnvironment(); setupBuiltinSyntax(); selftest(); #endif printf("hello friend...\n"); initGlobalEnvironment(); setupInitialEnvironment(); printf("Welcome to (JS)cheme\n"); if( setjmp(whereEverythingWasFine) ){ #ifdef DEBUG indentLevel = 0; indentLevelForInclude = 0; #endif // reset Stack index SP = 0; AP = 0; BP = 0; prompt_on(); printf("back in wonderland\n"); } printf("...starting a REPL for you.\n"); OBJ inputStream = newFileStream(stdin); #ifdef DEBUG if(CONTINUATION_PASSING->state){ CP_setupBuiltinSyntax(); enterTrampoline1(inputStream); }else{ setupBuiltinSyntax(); jREPL(inputStream); } #else //jREPL(inputStream); CP_setupBuiltinSyntax(); enterTrampoline1(inputStream); #endif return 0; }
InputStream openFTPStream(ParsedURL *pu, URLFile *uf) { Str tmp; int status; char *user = NULL; char *pass = NULL; Str uname = NULL; Str pwd = NULL; int add_auth_cookie_flag = FALSE; char *realpathname = NULL; if (!pu->host) return NULL; if (pu->user == NULL && pu->pass == NULL) { if (find_auth_user_passwd(pu, NULL, &uname, &pwd, 0)) { if (uname) user = uname->ptr; if (pwd) pass = pwd->ptr; } } if (user) /* do nothing */ ; else if (pu->user) user = pu->user; else user = "******"; if (current_ftp.host) { if (!strcmp(current_ftp.host, pu->host) && current_ftp.port == pu->port && !strcmp(current_ftp.user, user)) { ftp_command(¤t_ftp, "NOOP", NULL, &status); if (status != 200) ftp_close(¤t_ftp); else goto ftp_read; } else ftp_quit(¤t_ftp); } if (pass) /* do nothing */ ; else if (pu->pass) pass = pu->pass; else if (pu->user) { pwd = NULL; find_auth_user_passwd(pu, NULL, &uname, &pwd, 0); if (pwd == NULL) { if (fmInitialized) { term_raw(); pwd = Strnew_charp(inputLine("Password: "******"Password: "******"Password: "******"anonymous"); #else tmp = Strnew_charp("anonymous"); #endif /* __MINGW32_VERSION */ Strcat_char(tmp, '@'); pass = tmp->ptr; } if (!current_ftp.host) { current_ftp.host = allocStr(pu->host, -1); current_ftp.port = pu->port; current_ftp.user = allocStr(user, -1); current_ftp.pass = allocStr(pass, -1); if (!ftp_login(¤t_ftp)) return NULL; } if (add_auth_cookie_flag) add_auth_user_passwd(pu, NULL, uname, pwd, 0); ftp_read: ftp_command(¤t_ftp, "TYPE", "I", &status); if (ftp_pasv(¤t_ftp) < 0) { ftp_quit(¤t_ftp); return NULL; } if (pu->file == NULL || *pu->file == '\0' || pu->file[strlen(pu->file) - 1] == '/') goto ftp_dir; realpathname = file_unquote(pu->file); if (*realpathname == '/' && *(realpathname + 1) == '~') realpathname++; /* Get file */ uf->modtime = ftp_modtime(¤t_ftp, realpathname); ftp_command(¤t_ftp, "RETR", realpathname, &status); if (status == 125 || status == 150) return newFileStream(current_ftp.data, (void (*)())closeFTPdata); ftp_dir: pu->scheme = SCM_FTPDIR; return NULL; }