Ticket #56381: 2nd_macports_append_history.patch

File 2nd_macports_append_history.patch, 3.1 KB (added by ylluminarious (George Plymale II), 6 years ago)
  • src/pextlib1.0/readline.c

    diff --git a/src/pextlib1.0/readline.c b/src/pextlib1.0/readline.c
    index e955f8e7..c2049c25 100644
    a b int ReadlineCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_ 
    267267                add line
    268268                read filename
    269269                write filename
     270                append filename
    270271                stifle max
    271272                unstifle
    272273*/
    int RLHistoryCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl 
    277278        char* s = NULL;
    278279        int i = 0;
    279280        Tcl_Obj *tcl_result;
     281        FILE *hist_file;
    280282#endif
    281283
    282284        if (objc < 2) {
    int RLHistoryCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl 
    309311                }
    310312                s = Tcl_GetString(objv[2]);
    311313                write_history(s);
     314        }  else if (0 == strcmp("append", action)) {
     315                if (objc != 3) {
     316                        Tcl_WrongNumArgs(interp, 1, objv, "append filename");
     317                        return TCL_ERROR;
     318                }
     319                s = Tcl_GetString(objv[2]);
     320
     321                hist_file = fopen(s, "a");
     322                fprintf(hist_file, "%s\n", current_history()->line);
     323                fclose(hist_file);
    312324        } else if (0 == strcmp("stifle", action)) {
    313325                if (objc != 3) {
    314326                        Tcl_WrongNumArgs(interp, 1, objv, "stifle maxlines");
  • src/port/port.tcl

    diff --git a/src/port/port.tcl b/src/port/port.tcl
    index 73a3a7e9..5d1b52b3 100755
    a b proc attempt_completion { text word start end } { 
    48024802}
    48034803
    48044804
    4805 proc get_next_cmdline { in out use_readline prompt linename } {
     4805proc get_next_cmdline { in out use_readline prompt linename history_file } {
    48064806    upvar $linename line
    48074807
    48084808    set line ""
    proc get_next_cmdline { in out use_readline prompt linename } { 
    48284828        set line [string trim $line]
    48294829
    48304830        if { $use_readline && $line ne "" } {
     4831            # Create macports user directory if it does not exist yet
     4832            if {![file isdirectory $macports::macports_user_dir]} {
     4833                file mkdir $macports::macports_user_dir
     4834
     4835                # Also write the history file if this is the case (this sets
     4836                # the cookie at the top of the file and perhaps other things)
     4837                rl_history write $history_file
     4838            }
     4839
     4840            # Add history item to memory...
    48314841            rl_history add $line
     4842            # ... and then append that item to the history file
     4843            rl_history append $history_file
    48324844        }
    48334845    }
    48344846
    proc process_command_file { in } { 
    48704882        }
    48714883
    48724884        # Get a command line
    4873         if { [get_next_cmdline $in stdout $use_readline $prompt line] <= 0  } {
     4885        if { [get_next_cmdline $in stdout $use_readline $prompt line $history_file] <= 0  } {
    48744886            puts ""
    48754887            break
    48764888        }
    proc process_command_file { in } { 
    48854897        }
    48864898    }
    48874899
    4888     # Create macports user directory if it does not exist yet
    4889     if {$use_readline && ![file isdirectory $macports::macports_user_dir]} {
    4890         file mkdir $macports::macports_user_dir
    4891     }
    4892     # Save readine history
    4893     if {$use_readline && [file isdirectory $macports::macports_user_dir]} {
    4894         rl_history write $history_file
    4895     }
    4896 
    48974900    # Say goodbye
    48984901    if { $noisy } {
    48994902        puts "Goodbye"