#include #import "REngine.h" #include #ifndef Win32 #include #endif #ifdef Win32 #include #else /* from Defn.h */ extern Rboolean R_Interactive; /* TRUE during interactive use*/ extern FILE* R_Consolefile; /* Console output file */ extern FILE* R_Outputfile; /* Output file */ extern char* R_TempDir; /* Name of per-session dir */ /* from src/unix/devUI.h */ extern void (*ptr_R_Suicide)(char *); extern void (*ptr_R_ShowMessage)(); extern int (*ptr_R_ReadConsole)(char *, unsigned char *, int, int); extern void (*ptr_R_WriteConsole)(char *, int); extern void (*ptr_R_ResetConsole)(); extern void (*ptr_R_FlushConsole)(); extern void (*ptr_R_ClearerrConsole)(); extern void (*ptr_R_Busy)(int); /* extern void (*ptr_R_CleanUp)(SA_TYPE, int, int); */ extern int (*ptr_R_ShowFiles)(int, char **, char **, char *, Rboolean, char *); extern int (*ptr_R_ChooseFile)(int, char *, int); extern void (*ptr_R_loadhistory)(SEXP, SEXP, SEXP, SEXP); extern void (*ptr_R_savehistory)(SEXP, SEXP, SEXP, SEXP); #endif int Re_ReadConsole(char *prompt, unsigned char *buf, int len, int addtohistory) { puts("**READ_CONSOLE**"); id replHandler=[[REngine mainEngine] getHandler]; if (replHandler!=nil) { NSString *s=[replHandler handleReadConsole: [NSString stringWithCString:prompt]]; if (s==nil) return -1; [s getCString:buf maxLength:len-1]; return 1; } return -1; } void Re_Busy(int which) { id replHandler=[[REngine mainEngine] getHandler]; if (replHandler!=nil) [replHandler handleBusy: which]; } void Re_WriteConsole(char *buf, int len) { id replHandler=[[REngine mainEngine] getHandler]; if (replHandler!=nil) [replHandler handleWriteConsole: [NSString stringWithCString:buf length:len]]; puts(buf); } /* Indicate that input is coming from the console */ void Re_ResetConsole() { } /* Stdio support to ensure the console file buffer is flushed */ void Re_FlushConsole() { } /* Reset stdin if the user types EOF on the console. */ void Re_ClearerrConsole() { } int Re_ChooseFile(int new, char *buf, int len) { int namelen; char *bufp; R_ReadConsole("Enter file name: ", (unsigned char *)buf, len, 0); namelen = strlen(buf); bufp = &buf[namelen - 1]; while (bufp >= buf && isspace((int)*bufp)) *bufp-- = '\0'; return strlen(buf); } void Re_ShowMessage(char *buf) { } void Re_read_history(char *buf) { } void Re_loadhistory(SEXP call, SEXP op, SEXP args, SEXP env) { SEXP sfile; char file[PATH_MAX], *p; /* checkArity(op, args); sfile = CAR(args); if (!isString(sfile) || LENGTH(sfile) < 1) errorcall(call, "invalid file argument"); p = R_ExpandFileName(CHAR(STRING_ELT(sfile, 0))); if(strlen(p) > PATH_MAX - 1) errorcall(call, "file argument is too long"); strcpy(file, p); */ } void Re_savehistory(SEXP call, SEXP op, SEXP args, SEXP env) { SEXP sfile; char file[PATH_MAX], *p; /* checkArity(op, args); sfile = CAR(args); if (!isString(sfile) || LENGTH(sfile) < 1) errorcall(call, "invalid file argument"); p = R_ExpandFileName(CHAR(STRING_ELT(sfile, 0))); if(strlen(p) > PATH_MAX - 1) errorcall(call, "file argument is too long"); strcpy(file, p); write_history(file); history_truncate_file(file, R_HistorySize); */ } /* R_CleanUp is invoked at the end of the session to give the user the option of saving their data. If ask == SA_SAVEASK the user should be asked if possible (and this option should not occur in non-interactive use). If ask = SA_SAVE or SA_NOSAVE the decision is known. If ask = SA_DEFAULT use the SaveAction set at startup. In all these cases run .Last() unless quitting is cancelled. If ask = SA_SUICIDE, no save, no .Last, possibly other things. */ /* void Re_CleanUp(SA_TYPE saveact, int status, int runLast) { unsigned char buf[1024]; char * tmpdir; if(saveact == SA_DEFAULT) saveact = SaveAction; if(saveact == SA_SAVEASK) { if(R_Interactive) { qask: R_ClearerrConsole(); R_FlushConsole(); R_ReadConsole("Save workspace image? [y/n/c]: ", buf, 128, 0); switch (buf[0]) { case 'y': case 'Y': saveact = SA_SAVE; break; case 'n': case 'N': saveact = SA_NOSAVE; break; case 'c': case 'C': jump_to_toplevel(); break; default: goto qask; } } else saveact = SaveAction; } switch (saveact) { case SA_SAVE: if(runLast) R_dot_Last(); if(R_DirtyImage) R_SaveGlobalEnv(); stifle_history(R_HistorySize); write_history(R_HistoryFile); break; case SA_NOSAVE: if(runLast) R_dot_Last(); break; case SA_SUICIDE: default: break; } R_RunExitFinalizers(); CleanEd(); if(saveact != SA_SUICIDE) KillAllDevices(); if((tmpdir = getenv("R_SESSION_TMPDIR"))) { snprintf((char *)buf, 1024, "rm -rf %s", tmpdir); R_system((char *)buf); } if(saveact != SA_SUICIDE && R_CollectWarnings) PrintWarnings(); fpu_setup(FALSE); exit(status); } void Rstd_Suicide(char *s) { REprintf("Fatal error: %s\n", s); R_CleanUp(SA_SUICIDE, 2, 0); } */ int Re_ShowFiles(int nfile, /* number of files */ char **file, /* array of filenames */ char **headers, /* the `headers' args of file.show. Printed before each file. */ char *wtitle, /* title for window = `title' arg of file.show */ Rboolean del, /* should files be deleted after use? */ char *pager) /* pager to be used */ { return 1; }