static IDL_VPTR IDL_CDECL IDL_mg_tout_pop(int argc, IDL_VPTR *argv) { char *output; IDL_VPTR result; IDL_ToutPop(); if (outf_buffer_size == 0) { fclose(outf_fp); return IDL_GettmpLong(-1); } else { output = (char *) malloc(outf_buffer_loc); strncpy(output, outf_buffer, outf_buffer_loc); output[outf_buffer_loc - 1] = '\0'; free(outf_buffer); outf_buffer_loc = 0; outf_buffer_size = 0; result = IDL_StrToSTRING(output); free(output); return(result); } }
static void IDL_CDECL IDL_mg_tout_push(int argc, IDL_VPTR *argv) { if (diverting) { IDL_ToutPop(); } else diverting = 1; if (argc > 0) { IDL_ENSURE_STRING(argv[0]); outf_fp = fopen(IDL_VarGetString(argv[0]), "w"); IDL_ToutPush(mg_tout_outf_file); } else { outf_buffer_loc = 0; outf_buffer_size = OUTF_BUFFER_BLOCKSIZE; outf_buffer = (char *) malloc(OUTF_BUFFER_BLOCKSIZE); IDL_ToutPush(mg_tout_outf_buffer); } }
int ridl_executeline(char *line, int flags) { int error = 0; // normal exit by hitting ^D if (line == NULL) { printf("\n"); return(IDL_Cleanup(IDL_FALSE)); }; // magic lines start with :, anything else is passed to IDL int firstcharIndex = ridl_firstchar(line); char firstchar = line[firstcharIndex]; if (firstchar == ':') { if ((firstcharIndex + 1 < strlen(line)) && (line[firstcharIndex + 1] == '!' || line[firstcharIndex + 1] == '^')) { // TODO: eventually this shouldn't be a magic command, but should be // activated when a space is entered char *expansion; int expansion_result; char *expansion_line = (char *)malloc(strlen(line) + 1); strcpy(expansion_line, line + firstcharIndex + 1); expansion_result = history_expand(expansion_line, &expansion); switch (expansion_result) { case -1: ridl_warning("error in expansion"); break; case 2: printf("%s\n", expansion); break; case 0: case 1: ridl_executestr(expansion, 1); break; } free(expansion_line); free(expansion); } else { int search_length; char *cmd = ridl_getnextword(line, firstcharIndex, &search_length); if (strcmp(cmd, ":colors") == 0) { use_colors = use_colors ? 0 : 1; if (use_colors) { printf("colors on\n"); } else { printf("colors off\n"); } } else if (strcmp(cmd, ":doc") == 0) { int search_length; char *routine = ridl_getnextword(line, firstcharIndex + 5, &search_length); char *man = (char *)malloc(8 + strlen(routine)); sprintf(man, "man, '%s'", routine); int error = IDL_ExecuteStr(man); free(man); free(routine); } else if (strcmp(cmd, ":notebook") == 0) { if (ridl_isnotebooking()) ridl_closenotebook(); int search_length; char *filename = ridl_getnextword(line, firstcharIndex + 9, &search_length); if (strlen(filename) == 0) { ridl_warning("must specify filename of notebook"); } else { ridl_setnotebooking(1); ridl_initnotebook(filename); } free(filename); } else if (strcmp(cmd, ":pref") == 0) { int search_length; char *has_args = ridl_getnextword(line, firstcharIndex + 5, &search_length); if (strlen(has_args) == 0) { ridl_printpreferences(); } else { char *pref_line = line + 6; ridl_process_pref_line(pref_line); } free(has_args); } else if (strcmp(cmd, ":log") == 0) { if (ridl_islogging()) ridl_closelog(); int search_length; char *filename = ridl_getnextword(line, firstcharIndex + 4, &search_length); if (strlen(filename) == 0) { ridl_warning("must specify filename of log"); } else { ridl_setlogging(1); ridl_initlog(filename); } free(filename); } else if (strcmp(cmd, ":unnotebook") == 0) { if (ridl_isnotebooking()) { ridl_closenotebook(); IDL_ToutPop(); ridl_setnotebooking(0); } else ridl_warning("not currently notebooking"); } else if (strcmp(cmd, ":unlog") == 0) { if (ridl_islogging()) { ridl_closelog(); IDL_ToutPop(); ridl_setlogging(0); } else ridl_warning("not currently logging"); } else if (strcmp(cmd, ":tee") == 0) { if (ridl_isteeing()) ridl_closelog(); int search_length; char *filename = ridl_getnextword(line, firstcharIndex + 4, &search_length); if (strlen(filename) == 0) { } else { ridl_setteeing(1); ridl_initlog(filename); } free(filename); } else if (strcmp(cmd, ":untee") == 0) { if (ridl_isteeing()) { ridl_closelog(); IDL_ToutPop(); ridl_setteeing(0); } else ridl_warning("not currently teeing"); } else if (strcmp(cmd, ":save_graphic") == 0) { if (ridl_isnotebooking()) { ridl_notebookgraphic(); } else { ridl_warning("turn on notebooking to save graphics"); } } else if (strcmp(cmd, ":time") == 0) { char *command = line + 6; ridl_magic_time(command); } else if (strcmp(cmd, ":help") == 0) { int f; int display_keybindings = ridl_magic_help(line, firstcharIndex); if (display_keybindings) { printf("\nrIDL keybindings:\n"); for(f = 0; f < N_FUNMAP_FUNCTIONS; f++) { ridl_printfunmap(funmap_function_names[f], funmap_functions[f]); } } } else if (strcmp(cmd, ":history") == 0) { ridl_magic_history(line, firstcharIndex); } else if (strcmp(cmd, ":histedit") == 0) { ridl_magic_histedit(line, firstcharIndex); } else if (strcmp(cmd, ":version") == 0) { ridl_printversion(); } else { ridl_warning("unknown magic command '%s'", cmd); error = 1; } } } else { if (line && *line) { // check for .edit if (firstchar == '.') { int search_length; char *cmd = ridl_getnextword(line, firstcharIndex, &search_length); if (strcmp(cmd, ".edit") == 0 || strcmp(cmd, ".edi") == 0 || strcmp(cmd, ".ed") == 0 || strcmp(cmd, ".e") == 0) { char *file = ridl_getnextword(line, firstcharIndex + strlen(cmd) + 1, &search_length); ridl_launcheditor(file); free(file); add_history(line); ridl_cmdnumber++; ridl_updateprompt(); } else { // execute standard executive commands error = ridl_executestr(line, 1); } free(cmd); } else { int lastcharIndex = ridl_lastchar(line); char lastchar = lastcharIndex == -1 ? ' ' : line[lastcharIndex]; if (lastchar == '?') { char cmd[1000]; char varname[1000]; strncpy(varname, line, lastcharIndex); varname[lastcharIndex] = '\0'; sprintf(cmd, "ridl_varhelp, %s", varname); int status = IDL_ExecuteStr(cmd); } else { // determine if line is continued char *line_continued = ridl_linecontinued(line); if (continued) { if (line_continued) { strcat(ridl_continuedline, line); } else { // execute IDL commands that were continued on several lines continued = 0; strcat(ridl_continuedline, line); error = ridl_executestr(ridl_continuedline, 1); } } else { if (line_continued) { continued = 1; strcpy(ridl_continuedline, line); } else { // execute normal IDL commands error = ridl_executestr(line, 1); } } } } } } return(error); }