🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.stats.s
Article #16161

history function SPLUS/DOS

#16161
From: /C=USA/ADMD=TELEMAIL/O=OMNET/SN=...
Date: Fri, 24 Jan 1992 22:13
127 lines
6357 bytes
Here is a history function for SPLUS for DOS 2.0 that I modified from
the history function for SPLUS for Unix.  It presents a menu of past
commands.  You can edit a command and it will be executed and saved in another
file called audit.ed in you HOME directory as I was not able to write to the
 _audit file.  The menu gives you by default 10 commands
from the _audit file and 10 commands from the audit.ed file.
This is certainly not as good as a command line editor like in DOS 5.0.
But it does give you access to past commands.
Hope there are'nt too many bugs.  Good luck.
 
 
 
function(pattern, evaluate = T, maxn = 10, maxe = 10, edit = F, menu.ask = T,
        where = 1)
{
 
#pattern is a character string of commands to search for that can
# contain * and ?.
#maxn is the number of past commands to display from the _audit file
#maxe is the number of past commands to display from the audit.ed file
#you must create an ascii file named audit.ed in you HOME directory before
#using the history function.
#edit is a logical variable that indicates whether you want to edit the
#selected command.
#if menu.ask is F then the last command in the _audit file will be executed
#where can be a character string indicating the directory in which to search
#for _audit, or it can be numeric in which case it is the number of the
#directory in your search path.
#you must change the name of the DOS editor to whatever you use(the line is 
#indicated below in the function.
#
        sys <- T
        if(is.numeric(where)) {
                if(where > 1) {
                        dir <- search()[where]
                        audit2 <- scan(file = paste(dir, "\\_audit", sep = ""),
                                what = "", sep = "\n")
                        cdir <- substring(dir, 1:nchar(dir), 1:nchar(dir))
                        posd <- grep("_", cdir)
                        if(length(posd) > 1)
                                posd <- posd[length(posd)]
                        dirw <- substring(search()[where], 1, posd - 1)
                        audit3 <- scan(file = paste(dirw, "\\audit.ed", sep = 
                                ""), what = "", sep = "\n")
                }
                else {
                        audit2 <- scan(file = paste(getenv("HOME"), 
                                "\\_data\\_audit", sep = ""), what = "", sep
                                 = "\n")
                        audit3 <- scan(file = "audit.ed", what = "", sep = 
                                "\n")
                }
        }
        else {
                audit2 <- scan(file = paste(where, "\\_audit", sep = ""),
                        what = "", sep = "\n")
                cdir <- substring(where, 1:nchar(where), 1:nchar(where))
                posd <- grep("_", cdir)
                if(length(posd) > 1)
                        posd <- posd[length(posd)]
                dirw <- substring(where, 1, posd - 1)
                audit3 <- scan(file = paste(dirw, "\\audit.ed", sep = ""),
                        what = "", sep = "\n")
        }
        n <- length(audit2)
        breaks <- (1:n)[audit2 == "#~"]
        items <- audit2[breaks + 1]
        items <- items[items != "audit()"]
        items <- items[items != "again()"]
        if(!missing(pattern)) {
                items <- items[grep(pattern, items)]
                audit3 <- audit3[grep(pattern, audit3)]
                items <- c(items[(max(1, length(items) + 1 - maxn)):length(
                        items)], audit3[(max(1, length(audit3) + 1 - maxe)):
                        length(audit3)])
        }
        else {
                items <- c(items, audit3[(max(1, length(audit3) + 1 - maxe)):
                        length(audit3)])        #        browser()
                items <- items[(max(1, length(items) + 1 - maxn - maxe)):
                        length(items)]
        }
        if(menu.ask && length(items) > 0) {
                cat(" Enter a number from the menu or 0 to exit\n")
                answer <- items[menu(items)]
        }
        else if(length(items) > 0) {
                answer <- items[length(items)]
        }
        else cat("No match for pattern= ", pattern, "\n")
        n <- length(answer)
        if(n > 0) {
                if(charmatch(".System", as.character(answer), nomatch = -1
                        ) == 1) O|                        edit <- T
                        sys <- F
                        cat(
                                "calls to .System must be changed so that all slashes are / ",
                                "\n")
                        cat("hit return to continue")
                        readline()
                }
        }
        if(edit && n > 0) {
                cat(answer, "\n", file = "temp")        
#***********************************************
#in this line ne is the name of the DOS editor. 
# Change this to the  editor you use.
 
                unix("ne temp", output = F)
                answer <- scan(file = "temp", what = "", sep = "\n")
                if(sys)
                        cat(answer, file = "audit.ed", sep = "\n", append = T)
                        
                cat(answer, sep = "\n")
                if(evaluate && n > 0)
                        eval(parse(text = answer, n = 1), local = F)
        }
        else {
                cat(answer, sep = "\n")
                if(evaluate && n > 0)
                        eval(parse(text = answer, n = n), local = F)
                else if(n > 0)
                        invisible(parse(text = answer, n = n))
        }
}
D
Technical Details
Message-ID: <9201242121.AA25047@hermes.stat.wisc.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!uniwa!dmsperth!dmssyd.syd.dms.CSIRO.AU!news

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fa931,ab1b8a0f43b6fbd0,start
X-Google-Attributes: gidfa931,public
X-Google-ArrivalTime: 1992-01-24 15:03:26 PST
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!uniwa!dmsperth!dmssyd.syd.dms.CSIRO.AU!news
From: /C=USA/ADMD=TELEMAIL/O=OMNET/SN=TURNOCK/FN=JACK/%TELEMAIL@intermail.isi.edu
Newsgroups: aus.stats.s
Subject: history function SPLUS/DOS
Message-ID: <9201242121.AA25047@hermes.stat.wisc.edu>
Date: 24 Jan 92 22:13:04 GMT
Sender: daemon@syd.dms.CSIRO.AU
Organization: CSIRO Div. Maths & Stats, CSIRO Div. Applied Physics
Lines: 126
X-Gateway: dmssyd.syd.dms.CSIRO.AU