# # KEHOME/src/command.icn # Richard H. McCullough Nov/13/2005 Jul/20/2009 Sep/8/2014 $include "../parser/yyinclude.h" $include "keparam.h" global AADATA global GDBMDATA global HODATA global NRELDATA global ARGINFO link check link clock link dir link hfun link hierarchy link integrate link random link relation link shell link variable global wininput,winconcept,mywin global CurrentDirectory,CurrentFile,CurrentFD global COMMAND,legal_command,kecommand,shcommand global cyc_command global EXIT global PATH # single-argument functions are listed in hfun.icn # string procedure substitute_filename(x) #=============================== # $variables local y,z static info initial { info := "INFO: substitute_filename: " } #####writes_type(mylog,x,info||"input x") y := dequote(x) z := substitute(y) # replace.icn #####writes_type(mylog,z,info||"output z") return z end procedure do_stv(cmd) #==================== local top static c,stv_stack initial { c := "," stv_stack := list() } case cmd of { "init": { stv_stack := list() } "push": { push(stv_stack,[SPACE,TIME,VIEW]) if DEBUG=="STV" then write(mylog," STV push(",SPACE||c||TIME||c||VIEW,")") } "pop": { top := pop(stv_stack) SPACE := top[1] TIME := top[2] VIEW := top[3] if DEBUG=="STV" then write(mylog," STV pop(",SPACE||c||TIME||c||VIEW,")") } } # end case end procedure init_command() #======================= # define command names # do kecommand pplist done # hdo hdocmd from concept to concept with path done; # vdo vdocmd od concept with path done; hdo_init() # HDO_ACTION := set(...) # hdo.icn vdo_init() # VDO_ACTION := set(...) # context.icn kecommand := set([ "ambiguity", "list table", "list tables", "write table", "write array", "write gdbm", "write hierarchy", "write relation", "push_stv", "pop_stv", "init_stv", "command", # generic name for grammar examples "COMMAND", # generic name for grammar examples "create context", "import context", "export context", # also sh command "delete comment","deletecomment",# also sh command "explorer", # also sh command "select_problem", "ExtractData", #"begin", # begin group x; "cd", "check", "clock", "close cyc", "close tap", "dbclose", "dbopen", "dbprint", "delete", # do delete od uname,... from cname done; ##### "delete/gdbm", "dump", "vsave", ##### "dump/gdbm", "dump/argtable", "dump/ged", "dump/hidden", "dump/nvstack", "empty", # empties list or set #"end", # end group x "entropy", "exec", # execute proposition list #"exit", # control structure "export", "find", "first-name", "factsize", "fsize", # file "fstatus", # file "ftype", # file "getenv", "get proposition", "import proposition", "given-name", "hload","hdump","hget","hput", "hobottom", # hocommand.icn "hodelete", # hocommand.icn "hodisplay", # hocommand.icn "hofind", # hocommand.icn "hoload", # hocommand.icn "homatch", # hocommand.icn "homove", # hocommand.icn "hoprint", # hocommand.icn "hosave", # hocommand.icn "hotop", # hocommand.icn "hwalk", # "hdo", <<== built-in verb "import", #"input relation", "interpret_line", "last-name", "load", "vload", "load/ged", "kbcheck", "kbwrite", "ls", "list member", "max", "menu", "concept menu", "merge", # do merge od uname,... to cname done; "middle-name", "min", "mkdir", "mount hierarchy", #"name", # attribute #"new group", # NO: use: gname is gtype of utype #"nickname", # attribute "nvtab", "open cyc", "open tap", "parse list", #"path2list", # function -- see hfun.icn "print", "pwd", "quote","dquote","squote", "dequote", "random", "read", "read directory", # recursive ##"read_dmoz", ##"read html", ##"read htm", "read input", ##"read mcf", ##"read owl", ##"read rdf", ##"read tap", "remove bracket","remove brace","remove angle", "remove quote", "replace", "reverse list", "rmdir", "select", "set htop", "sh", "shuffle","deal", # deck "simplify lattice", "size", "size/list", "size/infon", ##### "size/gdbm", "SubL", "suffix-name", "sum", "surname", "title-name", "unique", #"update relation", #"vdo", # vdo exec od {sentence} done;/ #"vfind", # vdo find od wildcard done; "vpop", "vpush", "year", "month", "day", "ymd", "dmy", "mdy", "write", "vwrite", "write directory" # recursive ]) # ! shcommand # out product # of domain # with option # od directobject # from infile # to outfile # done; shcommand := set([ # also ke command "deletecomment", "explorer", # UNIX commands "cat", "cd", "date", "dir", "grep", "head", "lf", "ls", "mkdir", "pwd", "rmdir", "tail", "wc" ]) cyc_command := set([ "write-image", "generate-phrase", "cyc-create", "CYC-CREATE", "CYC-FIND-OR-CREATE", "CYC-RENAME", "CYC-ASSERT", "CYC-UNASSERT", "CYC-QUERY", "CYC-KILL", "CYC-MERGE", "CYC-EDIT", "CYC-RECREATE", "CYC-REWRITE" ]) COMMAND := kecommand ++ shcommand ++ cyc_command # define function names # function is single-argument command init_function() # hfun.icn COMMAND ++:= FUNCTION legal_command := COMMAND ++ legal_function # verbs & actions which are also commands legal_command ++:= set([ "differentiate","integrate" ]) legal_command ++:= set([ "measure","classify" ]) end procedure add_command() #====================== # declare commands local atab,cmd #####atab := KNIT[new_concept("ke")].act atab := MKE.act every cmd := ! COMMAND do { if cmd == ("command"|"COMMAND") then { } else { add_species(cmd,"COMMAND") # cmd isu COMMAND insert(atab,cmd,[]) # ke do cmd done } } end # list procedure command2arglist(symbol) #================================ # build arglist in standard order from atlist & pplist # NOTE: physically deletes pplist from symbol (copy problem ???) local pplist,arglist local ppod,ppfrom,ppto static prog,b,colon,yyprefix static info initial { prog := "command2arglist: " b := " " colon := ":" info := "INFO: "||prog } yyprefix := yylineno||colon||yywordno||b||KFORMAT||b||prog pplist := find_stype("pplist",symbol) ppod := get_pp("od",pplist) ppfrom := get_pp("from",pplist) ppto := get_pp("to",pplist) arglist := [pp_object(ppod)] ||| [pp_object(ppfrom)] ||| [pp_object(ppto)] if DEBUG==("ARGLIST"|"PPLIST") then { write(mylog,yyprefix,"symbol = (", showparse(symbol),")") write(mylog,yyprefix,"arglist = (",showparse(arglist),")") } return arglist end # list procedure do_command(verb,cmd,pplist) #==================================== # called by xx() in sentence.icn # do cmdlist done; # SYMBOL(Dcd, svalue) # do cmdlist pplist done; # SYMBOL(Dcpd,svalue) # vdo cmdlist pplist done; # pp can be od {sentence} # # cmdlist ::= nvobject # nvobject ::= SYMBOL("nvobject",nvlist) # pplist ::= # at space,time => not used # of cmd part => not used # with cmd characteristic => with option # od directobject => od directobject # from initial characteristic => from infile # to final characteristic => to outfile # in ??? => in ??? # out product => product := do ... done # # verb ::= # do | hdo | vdo | ! # cmd ::= # phrase # reduce to # qword # isverb => isd,isi local subhierarchy local top,hotable local line,head local xname,xt,tsize,gt local cmdfd local word, nline local t,st,stype local variable local args,inrel,outrel,condition local nvoption,nvcondition local ShProduct,ppShProduct local node,array local nconcept,btable local tname local d,num local L local interaction local program,world,date local doword,cmdlist,exline,ctype,outfd,namespace local url,uname,subject,pattern,replacement,action,path local pfile,pfd,pline,qline,rline local varlist,value,sline,fname local dmozformat,dmozfile,tapformat,tapfile,fsdir local echoline local ppobj local context,part,product,option,directobject,infile,outfile local concept,directory local dval,sentence local ppstring,wildcard,newlist,newcmd local ct,fd,kbfile,kbdata local arg,vname,cname,cmdobj,rc,dir local kfile,newfd,kfilelist local proplist local letter, htmlfile local saveUniqueName,saveDBMODE local cyccmd,preprocessor,postprocessor local ncard,ndiscard local deck,hand,stock,discard, handi,i local qdeck,qhand,qstock,qdiscard, qhandi local mem,x,ix,qx,y,iy,qy local udirectobject,uinfile,uoutfile local sep local translation local viewlist,view, dbdir,dbfile, kline local cinfo,cerror,cwarning static prog,b,c,s,colon,yyprefix static info,error,ierror,warning static squote,dquote,lsep,psep static SaveStack initial { /SaveStack := [] prog := "do_command: " b := " " c := "," s := ";" colon := ":" lsep := "," psep := " " squote := "\'" dquote := "\"" info := "INFO: "||prog error := "ERROR: "||prog ierror := "Internal ERROR: "||prog warning := "WARNING: "||prog /AADATA := table() /GDBMDATA := table() /HODATA := table() /NRELDATA := table() /ARGINFO := table() /BOOT := table() /CHIT := table() /KNIT := table() /unique := table() } /cmdfd := &output yyprefix := yylineno||colon||yywordno||b||KFORMAT||b||prog verb := unparse(verb) cmd := unparse(cmd) line := verb||b||cmd||unparse(pplist)||s if yydebug = 1 then write(&output,yyprefix,"verb = (",image(verb),") cmd = (",image(cmd),") pplist = (",unparse(pplist),")") push(SaveStack,KFORMAT) NCOMMAND +:= 1 NkuSENTENCE +:= 1 NPROPOSITION +:= 1 if DEBUG=="TIME" then write(mylog,"## ",&time," ## command: begin ##") doword := verb cmdlist := [cmd] #---------------------------------------------------------------- #----------------------------------------------------------------- every cmd := !cmdlist do { ##### #=================================================# ##### cmd := unparse(cmd,b) cinfo := info||cmd||": " cerror := error||cmd||": " cwarning := warning||cmd||": " if DEBUG == "COMMAND" then { head := cinfo||"before dollar substitution: " writes_type(mylog,cmd,head||"cmd") writes_type(mylog,pplist,head||"pplist") } case cmd of { "push_stv": { do_stv("push"); next } "pop_stv": { do_stv("pop"); next } "init_stv": { do_stv("init"); next } "?": { NCOMMAND -:= 1 NQUESTION +:= 1 case doword of { default: { # do ? done; # without "ke" dval := write_char(cmdfd,"ke","act") next } "!": { # ! ? done; # without "sh" write(cmdfd,"sh !") every write(cmdfd,"\t",!sort(shcommand)) write(cmdfd,"done;") write(cmdfd,"# INFO: command: many other shell commands are available") next } } # end case doword } ("command"|"COMMAND"): { # generic name for grammar examples ##newcmd := unique_name(cmd) write(&errout,TypeComment||warning|| "generic command name (",cmd,") ignored: line (",line,")") ##cmd := newcmd next } } # end case cmd #=============================# # substitute dollar variables # #=============================# # NOTE: # dot variables replaced by dollar variables Oct/27/2002 # MKR variables have values "$.","$..","$..." # external files are ".",".." # so it's OK to substitute MKR dot variables # cmd $ substitution for shell commands cmd := replace_dollar_line(cmd) # replace.icn write(mylog,yyprefix,"before substitution: pplist = (",showparse(pplist),")") pplist := replace_dollar_symbol(pplist) # replace.icn write(mylog,yyprefix,"after dollar substitution: pplist = (",showparse(pplist),")") pplist := replace_pronoun_symbol(pplist) # replace.icn write(mylog,yyprefix,"after pronoun substitution: pplist = (",showparse(pplist),")") if DEBUG == ("COMMAND"|"MEANING") then { head := cinfo||"after dollar substitution: " writes_type(mylog,cmd,head||"cmd") writes_type(mylog,pplist,head||"pplist") } #=========================# # echo after substitution # #=========================# echoline := doword||b||cmd if is_ppnull(pplist) then { } else { echoline ||:= b||unparse(pplist) } echoline ||:= b||"done;" if DEBUG=="DOLLAR" then { write(mylog,"# command (",echoline,")") } if ECHO == "on" then { write(&output,"# command (",echoline,")") } case cmd of { "dbopen": { } # don't do db_add_unit() default: { #####add_statement(echoline,symbol,"command",,"later") # newword.icn add_statement(echoline,[],"command") # newword.icn } } # end case cmd flush(&output) # because of shell commands flush(&errout) # because of shell commands ############################### # make ppobj for later use ############################### if ppobj := get_ppobject(pplist) # pplist.icn then { if *ppobj > 0 then { context := ppobj.ppat part := ppobj.ppof option := ppobj.ppwith directobject := ppobj.ppod; arg := list_unparse(csv_list(find_record("CSV",directobject)),c) infile := ppobj.ppfrom outfile := ppobj.ppto array := ppobj.ppin product := ppobj.ppout } else { write(&errout,yyprefix,"empty ppobjct: pplist = (",showparse(pplist),")") } # end if } # end if # declare files #==============# #####case cmd of { #####"cat": { every x := !arg do add_unit(unparse(x[1]),"file") } #####"cd": { every x := !arg do add_unit(unparse(x[1]),"file") } #####"fsize": { every x := !arg do add_unit(unparse(x[1]),"file") } #####"fstatus": { every x := !arg do add_unit(unparse(x[1]),"file") } #####"ftype": { every x := !arg do add_unit(unparse(x[1]),"file") } #####"import": { every x := !infile do add_unit(unparse(x[1]),"file") } #####"export": { every x := !outfile do add_unit(unparse(x[1]),"file") } #####"ls": { every x := !arg do add_unit(unparse(x[1]),"file") } #####"read": { every x := !infile do add_unit(unparse(x[1]),"file") } #####"write": { every x := !outfile do add_unit(unparse(x[1]),"file") } #####"read directory": { every x := !infile do add_unit(unparse(x[1]),"directory") } #####"write directory": { every x := !outfile do add_unit(unparse(x[1]),"directory") } #####default: { } #####} exline := echoline if DEBUG=="COMMAND" then { writes_type(mylog,exline,info||"executing") writes_type(mylog,exline,info||"executing") } ctype := get_ctype(cmd) # look for methods #=================# if ctype == "method" then { writes_type(mylog,exline,info||"executing method") if DEBUG=="METHOD" then writes_type(mylog,exline,info||"executing method") dval := do_method(cmd,directobject,pplist,[],ppobj) # method.icn # look for functions #===================# } else if member(legal_function,cmd) then { add_word(exline,[],stype) # file newwords dval := do_function(cmd,directobject,cmdfd) # hfun.icn # look for sh commands #=====================# } else if doword == "!" then { # ShProduct := ! cmd with option od directobject from infile to outfile done; add_unit(cmd,"sh command") ShProduct := new_ShProduct() add_unit(ShProduct,"file") put_vtype(ShProduct,"attribute") ppShProduct := new_pp("out",ShProduct) put_product(ppobj,ShProduct) dval := shell(cmd,ppobj) # shell.icn ##write(&output,unparse(dval)) # look for cyc commands #======================# } else if member(cyc_command,cmd) then { dval := do_cyc_command(cmd,directobject, option,product,infile,outfile) # cyc.icn # look for vdo commands #=====================# } else if doword == "vdo" then { # vdo cmd pplist done dval := vdo(cmd,ppobj,echoline) # context.icn # look for hdo commands (hwalk) #=============================# } else if doword == "hdo" then { # hdo action od concept with path done # hdo action with path from concept done action := cmd cname := unparse(directobject) path := unparse(option) if *path = 0 then path := "ISC" if DEBUG == "HDO" then { writes_type(&errout,action,info||"action") writes_type(&errout,path,info||"path") writes_type(&errout,cname,info||"concept") } dval := hwalk( # hwalk.icn cname, # concept action, # action path # path ) # look for interactions #====================== } else if doword == "happens" then { # happens interaction pplist done; interaction := cmd dval := do_interaction( # interaction.icn doword, interaction, pplist ) } else { # "do"|"hdo"|"vdo" ??? # "can"|"must"|"shall"|"ought" ??? # do cmd pplist done # continue below case cmd of { #===========# default: { if member(kecommand,cmd) then { writes_type(&errout,exline,warning||"not implemented") writes_type(mylog,exline,warning||"not implemented") } else { unknown_command(cmd,exline,[],stype) } } # end default "set htop": { # do set htop od top in hotable; top := unparse(directobject) hotable := unparse(array) set_htop(hotable,top) # mkr_table.icn } "ambiguity": { # ambig := do ambiguity od xname; xname := unparse(directobject) dval := ho_ambiguity(xname) # hierarchy.icn return dval } # write_table() in KEHOME/parser/unparser.icn ("list table"|"list tables"): { # do list table; dval := "list_table" tsize := *ARGINFO; head := "relation or method ("||tsize||")"; write_table(&output,ARGINFO, "ARGINFO",, head) write(&output) tsize := *TDATA; head := "mkrTable" ||"("||tsize||")"; write(&output,head) tsize := *mkrKeyword; head := "mkrKeyword" ||"("||tsize||")"; write(&output,head) tsize := *userKeyword;head := "userKeyword"||"("||tsize||")"; write(&output,head) tsize := *ProNoun; head := "ProNoun" ||"("||tsize||")"; write(&output,head) tsize := *NewWord; head := "NewWord" ||"("||tsize||")"; write(&output,head) tsize := *BOOT; head := "BOOT" ||"("||tsize||")"; write(&output,head) tsize := *CHIT; head := "CHIT" ||"("||tsize||")"; write(&output,head) tsize := *KNIT; head := "KNIT" ||"("||tsize||")"; write(&output,head) tsize := *unique; head := "unique" ||"("||tsize||")"; write(&output,head) return dval } "write table": { # do write table od xname; xname := unparse(directobject) case xname of { default: { if member(TDATA,xname) then { t := new_table(xname); xt := xtype(xname); tsize := *t head := xt||b||xname||"("||tsize||")"; write_table(&output,t, xname,,head); return xname } } "mkrTable": { tsize := *TDATA; head := xname||"("||tsize||")"; write_table(&output,TDATA, xname,,head); return xname } "mkrKeyword": { tsize := *mkrKeyword; head := xname||"("||tsize||")"; write_table(&output,mkrKeyword, xname,,head); return xname } "userKeyword":{ tsize := *userKeyword;head := xname||"("||tsize||")"; write_table(&output,userKeyword,xname,,head); return xname } "ProNoun": { tsize := *ProNoun; head := xname||"("||tsize||")"; write_table(&output,ProNoun, xname,,head); return xname } "NewWord": { tsize := *NewWord; head := xname||"("||tsize||")"; write_table(&output,NewWord, xname,,head); return xname } "BOOT": { tsize := *BOOT; head := xname||"("||tsize||")"; write_table(&output,BOOT, xname,,head); return xname } "CHIT": { tsize := *CHIT; head := xname||"("||tsize||")"; write_table(&output,CHIT, xname,,head); return xname } "KNIT": { tsize := *KNIT; head := xname||"("||tsize||")"; write_table(&output,KNIT, xname,,head); return xname } "unique": { tsize := *unique; head := xname||"("||tsize||")"; write_table(&output,unique, xname,,head); return xname } } # end case xname if member(ARGINFO,xname) then { gt := unparse(get_gtype(xname)) ##### if (gt == "relation") & (tname := nrel_tname(xname)) then { ##### tsize := *tname # nrel_size(xname) ##### head := "relation "||xname||"("||tsize||")" ##### write_table(&output,tname,xname,,head) ##### } if (gt == "method") & (tname := method_tname(xname)) then { tsize := *tname # method_size(xname) head := "method "||xname||"("||tsize||")" write_table(&output,tname,xname,,head) } } dval := "write_table "||xname } "write array": { # do write array od xname; xname := unparse(directobject) write_array(&output,xname) dval := "write_array "||xname } "write gdbm": { # do write gdbm od xname; xname := unparse(directobject) t := new_table(xname) head := "gdbm "||xname||")"||*t||")" write_table(fd,t,xname,,head) dval := "write_gdbm "||xname } "write hierarchy": { # do write hierarchy od xname from concept with option; xname := unparse(directobject) concept := unparse(infile) option := unparse(option) ###write(&output,yyprefix,"write hierarchy: ","xname = (",xname,") concept = (",concept,")") write_ho(&output,xname,concept,option) dval := "write_ho "||xname||" from "||concept||" with "||option } "write relation": { # do write relation od xname; xname := unparse(directobject) write_nrel(&output,xname) dval := "write_nrel "||xname } # commands in hocommand.icn #========================== "hobottom": { # do hobottom od object from source done; hodo_command(verb,cmd,pplist) } "hodelete":{ # do hodelete od object from source done; hodo_command(verb,cmd,pplist) } "hofind": { # do hofind od object from source done; hodo_command(verb,cmd,pplist) } "hoload": { # load view from directory done; hodo_command(verb,cmd,pplist) } "homatch": { # do homatch od object from source done; hodo_command(verb,cmd,pplist) } "homove": { # do homove od object from source to destination done; hodo_command(verb,cmd,pplist) } "hoprint": { # do hoprint od object from source to destination done; hodo_command(verb,cmd,pplist) } "hosave": { # save view to directory done; hodo_command(verb,cmd,pplist) } "hotop": { # do hotop od object from source done; hodo_command(verb,cmd,pplist) } "remove bracket": { # do remove bracket od x done; x := unparse(directobject) dval := remove_bracket(x) } "remove brace": { # do remove brace od x done; x := unparse(directobject) dval := remove_brace(x) } "remove angle": { # do remove angle od x done; x := unparse(directobject) dval := remove_angle(x) } "select": { # do select od args from inrel to outrel with condition done; # outrel := do select od args from inrel with condition done; writes_all([]) writes_type_all(line,cinfo||"line") args := list_unparse(directobject) nvcondition := list_unparse(nvoption,";",psep) if DEBUG == "SELECT" then { writes_type(mylog,args,cinfo||"args") writes_type(mylog,nvcondition,cinfo||"nvcondition") } ##nvcondition := replace(nvcondition,"=","is") ##nvcondition := replace(nvcondition,",",";") inrel := unparse(infile) outrel := unparse(outfile) if outrel == "[]" then outrel := unparse(product) if (type(outrel) == "null") | (*outrel = 0) then { outrel := inrel||unique_name("select") } argdef_copy(inrel,outrel,args,nvcondition) nrel_copy(inrel,outrel,args,nvcondition) dval := [outrel] } "create context": { dval := knit_init(cmd,ppobj) # knit.icn } ("import"|"import context"): { dval := import_knit(cmd,ppobj) # knit.icn } ("export"|"export context"): { dval := export_knit(cmd,ppobj) # knit.icn } "open cyc": { # do open cyc od context with option from world done; # option ::= "write" | "quiet" option := unparse(option) context := unparse(directobject) world := unparse(infile) #####dval := do_opencyc(option,world,context) # cyc.icn dval := cyc_open(option,context,world) # cyc.icn } "close cyc": { # do close cyc done; dval := cyc_close() } #####"open tap": { ##### # do open tap od kbdata with option to kbfile done; ##### # option ::= "write" | "quiet" ##### option := unparse(option) ##### kbdata := unparse(directobject) ##### kbfile := unparse(outfile) ##### dval := tap_open(option,kbdata,kfile) # tap.icn ##### } #####"close tap": { ##### # do close tap done; ##### dval := tap_close() ##### } ##### "size/gdbm": { ##### # do size/gdbm od gdbmtable,... done; ##### dval := [] ##### every x := !list_unparse(directobject) do { ##### x := !x ##### if d := gdbm_open(x) then { ##### num := *d ##### put(dval,num) ##### write(cmdfd,num) ##### close(d) ##### } else { ##### head := "# ERROR: size/gdbm: can't open GDBM table: " ##### writes(&errout,[head,x]) ##### } ##### } # end every x ##### } "list tables": { # do list tables od view,... done; dval := [] viewlist := list_unparse(directobject) if *viewlist == 0 then viewlist := [["tabula rasa"]] # default every view := !viewlist do { view := !view dbdir := KEDB||"/"||view dbfile := dbdir||"/*.dir" kline := "! ls "||squote||dbdir||squote||" done;" write(mylog,"##### view = ",view," #####") write(&output,"##### view = ",view," #####") interpret_line(kline) } # end every view } "size": { # do size od x done; dval := [] every x := !list_unparse(directobject) do { #####x := !x if DEBUG==("VALUE"|"VARIABLE") then { writes_type(mylog,x,cinfo||"x[value]") } case type(x) of { default: { writes_type(&errout,x,warning||"size not implemented for") } "string": { case x of { default: { writes_type(&errout,x,warning||"size not implemented for") } # global "MKE": { num := *MKE put(dval,num) write(cmdfd,num) } "BOOT": { num := *BOOT put(dval,num) write(cmdfd,num) } "context_table": { num := *context_table put(dval,num) write(cmdfd,num) } # per view "KNIT": { num := *KNIT put(dval,num) write(cmdfd,num) } "CHIT": { num := *CHIT put(dval,num) write(cmdfd,num) } "AMBIG": { num := *AMBIG put(dval,num) write(cmdfd,num) } "unique": { num := *unique put(dval,num) write(cmdfd,num) } "nick": { num := *nick put(dval,num) write(cmdfd,num) } "HIDDEN": { num := *HIDDEN put(dval,num) write(cmdfd,num) } } } # end "string" ("list"|"infon"): { num := list_size(x) # array.icn put(dval,num) write(cmdfd,num) } # end "list" "table": { num := *x put(dval,num) write(cmdfd,num) } # end "table" "SYMBOL": { writes_type(&errout,x,warning||"size not implemented for") } # end "SYMBOL" } # end case t } # end every x } ( "size/list"| "size/infon" ): { # do size od infon,... done; dval := [] every x := !list_unparse(directobject) do { x := !x if DEBUG==("VALUE"|"VARIABLE") then { writes_type(mylog,x,cinfo||"x[value]") } num := list_size(x) # array.icn put(dval,num) write(cmdfd,num) } # end every x } "hload": { # do hload from file to boot done; kfile := unparse(infile) btable := unparse(outfile) nconcept := hload(kfile) dval := nconcept } "hdump": { # do hdump from boot to file done; write(&errout,TypeComment||warning||"not implemented") } "hget": { # do hget od concept from boot done; concept := unparse(directobject) btable := unparse(infile) if node := hget(concept,,"user") then { ###writes_type(mylog,node,info||"node") delete(BOOT,concept) every kline := !node do dval := interpret_line(kline) } # end if } "hput": { # do hput od concept to boot done; write(&errout,TypeComment||warning||"not implemented") } ##### "dump/gdbm": { ##### # array stored in GDBM database ##### # do dump/gdbm od cname... with translation to outfile done; ##### translation := unparse(option) ##### if *outfile > 0 then { ##### outfile := unparse(outfile) ##### fd := open(outfile,"w") ##### } else { ##### fd := cmdfd ##### } # end if ##### every cname := !arg do { ##### cname := !cname ##### if tname := gdbm_open(cname) then { # myio.icn ##### db_dump(fd,tname,cname,translation) # database.icn ##### } else { ##### writes_type(&errout,cname,cerror|| ##### "can't open GDBM table for cname") ##### } # end if ##### } # end every cname ##### if *outfile > 0 then { ##### close(fd) ##### } # end if ##### } "dump/argtable": { # array stored in argtable member of relation/method # do dump/argtable od cname to outfile done; outfile := unparse(outfile) if *outfile > 0 then { fd := open(outfile,"w") } else { fd := cmdfd } # end if every cname := !arg do { cname := !cname if tname := ARGINFO[new_argdef(cname)].argtable then { # myio.icn write_table(fd,tname,cname) } else { writes_type(&errout,cname,cerror|| "can't access argtable for cname") } # end if } # end every cname if *outfile > 0 then { close(fd) } # end if } ##### "delete/gdbm": { ##### # do delete/gdbm od uname... from cname done; ##### # array stored in GDBM database ##### cname := unparse(infile) ##### every uname := !list_unparse(directobject) do { ##### uname := !uname ##### if tname := gdbm_open(cname) then { # myio.icn ##### db_delete(tname,uname) # database.icn ##### } else { ##### writes_type(&errout,cname,cerror|| ##### "can't open GDBM table for cname") ##### } # end if ##### } # end every uname ##### } "delete/argtable": { # do delete/argtable od uname... from cname done; # array stored in argtable member of relation/method cname := unparse(infile) every uname := !list_unparse(directobject) do { uname := !uname if tname := ARGINFO[new_argdef(cname)].argtable then { # myio.icn delete(tname,uname) # database.icn } else { writes_type(&errout,cname,cerror|| "can't access argtable for cname") } # end if } # end every uname } "parse list": { # do parse list od string with separator done; s := unparse(directobject) sep := unparse(option) dval := parse_csv(s,sep) } "quote": { # qs := do quote od s done; # enclose string in dquote s := unparse(directobject) dval := dquote||s||dquote } "dquote": { # qs := do dquote od s done; # enclose string in dquote s := unparse(directobject) dval := dquote||s||dquote } "squote": { # qs := do squote od s done; # enclose string in squote s := unparse(directobject) dval := squote||s||squote } "dequote": { # s := do dequote od qs done; # remove quotemarks from string s := unparse(directobject) dval := dequote(s) # convert.icn } "empty": { # do empty od x done; # empties list/set/alternation/... every x := !directobject do { x := unparse(x) delete_member_all(x) # hop.icn delete_alternative_all(x) # hop.icn } } "reverse list": { # do reverse list od x done; every x := !directobject do { qx := new_concept(x) KNIT[qx].member := reverse(KNIT[qx].member) dval := KNIT[qx].member } } "list member": { # do list member od mem from x,ix to y,iy done; #writes_type(mylog,directobject,info||"directobject") #writes_type(mylog,infile,info||"infile") #writes_type(mylog,outfile,info||"outfile") dval := list_member(directobject,infile,outfile) # arrayref.icn #### mem := "" #### if *directobject > 0 then { #### if *directobject > 1 then { #### udirectobject := unparse(directobject) #### writes_type(&errout,udirectobject,cwarning||"ignoring extra member in od") #### writes_type(mylog,udirectobject,cwarning||"ignoring extra member in od") #### } #### mem := unparse(directobject[1]) #### if *infile > 0 then { #### uinfile := unparse(infile) #### writes_type(&errout,uinfile,cwarning||"ignoring from") #### writes_type(mylog,uinfile,cwarning||"ignoring from") #### } #### if *outfile = 0 then { #### uoutfile := unparse(outfile) #### writes_type(&errout,uoutfile,cwarning||"missing to") #### writes_type(mylog,uoutfile,cwarning||"missing to") #### } #### } else { #### uinfile := unparse(infile) #### if *infile > 2 then { #### writes_type(&errout,uinfile,cwarning||"extra agument in from") #### writes_type(mylog,uinfile,cwarning||"extra agument in from") #### } #### x := unparse(infile[1]) #### ix := unparse(infile[2]) #### if numeric(ix) then { #### qx := new_concept(x) #### mem := KNIT[qx].member[ix] #### } else { #### writes_type(&errout,ix,cerror||"non-numeric index in from") #### writes_type(mylog,ix,cerror||"non-numeric index in from") #### } #### } # end if *directobject #### if *outfile > 0 then { #### uoutfile := unparse(outfile) #### if *outfile > 2 then { #### writes_type(&errout,uoutfile,cwarning||"extra agument in to") #### writes_type(mylog,uoutfile,cwarning||"extra agument in to") #### } #### y := unparse(outfile[1]) #### iy := unparse(outfile[2]) #### if numeric(iy) then { #### qy := new_concept(y) #### KNIT[qy].member[iy] := mem #### } else { #### writes_type(&errout,iy,cerror||"non-numeric index in to") #### writes_type(mylog,iy,cerror||"non-numeric index in to") #### } #### } # end if *outfile #### dval := [mem] } "random": { dval := random(directobject) } # utility.icn "shuffle": { # do shuffle od deck done; # deck is list of card; deck := unparse(directobject[1]) qdeck := new_concept(deck) randomize() shuffle(KNIT[qdeck].member) dval := KNIT[qdeck].member } "deal": { # do deal od ncard,ndiscard from deck to hand,stock,discard done; # ncard,ndiscard isu integer; # deck isu list of card; # hand iss set of card; # stock isu list of card; # discard isu list of card; # arglist ::= [deck,hand,stock,discard] ncard := unparse(directobject[1]) ndiscard := unparse(directobject[2]) deck := unparse(infile[1]) hand := unparse(outfile[1]) discard := unparse(outfile[2]) stock := unparse(outfile[3]) if DEBUG == "DEAL" then { writes_type(mylog,ncard,info||"ncard") writes_type(mylog,ndiscard,info||"ndiscard") writes_type(mylog,deck,info||"deck") writes_type(mylog,hand,info||"hand") writes_type(mylog,discard,info||"discard") writes_type(mylog,stock,info||"stock") } qdeck := new_concept(deck) qhand := new_concept(hand) qdiscard := new_concept(discard) qstock := new_concept(stock) # delete previous handi and discard KNIT[qstock].member := copy_list(KNIT[qdeck].member) every handi := !KNIT[qhand].unit do { qhandi := new_concept(handi) KNIT[qhandi].member := [] } KNIT[qdiscard].member := [] # deal ncard cards per hand and ndiscard cards per discard every i := 1 to ncard do { every handi := !KNIT[qhand].unit do { qhandi := new_concept(handi) put(KNIT[qhandi].member,get(KNIT[qstock].member)) KNIT[qhandi].member := set(KNIT[qhandi].member) KNIT[qhandi].member := set2list(KNIT[qhandi].member) } } every i := 1 to ndiscard do { put(KNIT[qdiscard].member,get(KNIT[qstock].member)) } } "select_problem": { dval := select_problem(directobject) } # test.icn "simplify lattice": { dval := simplify_lattice(directobject) } # integrate.icn "dbclose": { # do dbclose od xname; ##write(&output,yyprefix,"directobject = (",showparse(directobject),")") write(mylog,yyprefix,"dbclose: ","arg = (",showparse(arg),")") dval := dbclose ! arg # hoio.icn } "dbopen": { # do dbopen od xname,xtype,tmode,tpat,tinit,htop; ##write(&output,yyprefix,"directobject = (",showparse(directobject),")") write(mylog,yyprefix,"dbopen: ","arg = (",showparse(arg),")") dval := dbopen ! arg # hoio.icn } "dbprint": { # do dbprint od xname; xname := unparse(directobject) t := new_table(xname) option := "decode" dval := write_table(&output,t,xname,,,,option) } "mount hierarchy": { mount_hierarchy(directobject) } # mount.icn "kbcheck": { dval := check_kb(outfd) } # ke.icn "kbwrite": { dval := write_kb(outfd) } # ke.icn #####("import ontology"|"import"): { ##### # do import ontology od namespace from url done ##### namespace := unparse(directobject) ##### url := unparse(infile) ##### dval := do_import_namespace(namespace,url) # xml.icn ##### } #####"ExtractData": { ##### # do ExtractData od letter from letter.html done ##### # do ExtractData od letter,letter.html done ##### letter := directobject[1][1] ##### htmlfile := directobject[1][2] | infile[1][1] ##### dval := xdletter(letter,htmlfile) ##### } "exec": { # do exec od {proplist} done # execute proposition list proplist := unparse(directobject," ") # string proplist := remove_brace(proplist) #proplist := trim(proplist,";") # semicolon now required if DEBUG=="EXEC" then { writes_type(mylog,directobject,info||"exec: directobject") writes_type(mylog,proplist,info||"exec: proplist") writes_type(mylog,directobject,info||"exec: directobject") writes_type(mylog,proplist,info||"exec: proplist") } dval := interpret_line(proplist) } # end "exec" #####"new group": { ##### # gname is gtype of utype <<== much better ##### # do new group od gname, gtype of utype done <<== NO ##### # create new group of units ##### gname := directobject[1][1] ##### gtype := directobject[2][1] ##### utype := part[1][1] ##### dval := new_group(gname,gtype,utype) ##### } # end "new" "input relation": { # do input relation od rname done dval := write(&errout,exline,info||"executing command") } # end "input relation" "update relation": { # do update relation od rname from infile to outfile done # do read od rname from infile done # do input relation od rname done # do write od rname to outfile done dval := write(&errout,exline,info||"executing command") } # end "update relation" "delete": { # do delete od uname,... from cname done uname := directobject cname := infile dval := delete_unit(uname,cname) # hop.icn dval := delete_species(uname,cname) # hop.icn ###dval := delete_member(uname,cname) # hop.icn ###dval := delete_alternative(uname,cname) # hop.icn } # end "delete" "merge": { # do merge od uname,... to cname done; uname := directobject cname := outfile dval := merge_species(uname,cname) # hop.icn } # end "merge" "replace": { # product := do replace od subject,pattern,replacement done if DEBUG == "HWALK" then writes_type(mylog,directobject,info||"replace directobject") subject := !directobject[1] pattern := !directobject[2] replacement := !directobject[3] dval := replace_pattern(subject,pattern,replacement) } # end "replace" #####"hdo": { ##### # do hdo od action with path from cname done; ##### # ==>> hdo action with path from cname done; ##### # see action.icn ##### if DEBUG == "HWALK" then { ##### writes_type(mylog,directobject,info||"hwalk directobject") ##### writes_type(mylog,directobject,info||"hwalk directobject") ##### } ##### directobject := delete_separator(directobject) ##### action := unparse(directobject) ##### path := unparse(option) ##### cname := unparse(infile) ##### dval := hwalk(cname,action,path) ##### } # end "hwalk" "hwalk": { # do hwalk od cname,action,path done; if DEBUG == "HWALK" then { writes_type(mylog,directobject,info||"hwalk directobject") writes_type(mylog,directobject,info||"hwalk directobject") } directobject := delete_separator(directobject) cname := unparse(directobject[1]) action := unparse(directobject[2]) path := unparse(directobject[3]) dval := hwalk(cname,action,path) } # end "hwalk" "interpret_line": { # do interpret_line od proposition list done if DEBUG == "PARSE" then writes_type(mylog,directobject,info||"interpret_line directobject") proplist := directobject[1][1] dval := interpret_line(proplist) } # end "interpret_line" #####"scroll": { ######=======# ##### dval := scroll(mycon,myscroll,"scroll") ##### } "dump": { #-----# # do dump od directobject from array done dval := [] infile := unparse(infile) case infile of { "BOOT": { BOOTprint(directobject) } default: { every cname := ! directobject do { cname := unparse(cname) #####cname := dequote(cname) put(dval, dump_concept(cmdfd,cname)) # concept.icn } # end every } # end default } # end case } # end "dump" "dump/hidden": { #-----# # do dump od directobject done dval := [] every cname := ! directobject do { cname := unparse(cname) cname := dequote(cname) put(dval, dump_hidden(cmdfd,cname)) # concept.icn } } # end "dump/hidden" "dump/ged": { dval := dump_ged(cmd,directobject,pplist) } # ged.icn "load/ged": { dval := load_ged(cmd,directobject,pplist) } # ged.icn "dump/nvstack": { dval := ns_dump(cmdfd) } "vsave": { # do vsave od view to directory done; dval := save_view(directobject) # ke.icn } "vload": { # do vload od view from directory done; dval := load_view(directobject) # ke.icn } "clock": { # ke.icn dval := clock ! directobject } ("menu"|"concept menu"): { # do menu done; # do concept menu od concept done; # MENUWINDOW ::= "input" | "concept" | "console" | "scroll" case MENU of { ("no"|"NO"): { writes_type(mylog,MENU,cinfo||"menu disabled: MENU") } default: { case SYSTYPE of { ( "Linux" | "Mac" | "Cygwin" | "Interix" | "WinXP" | "Win98" | "Windows" ): { wininput := mywopen("input") winconcept := mywopen("concept") case cmd of { "menu": { MENUWINDOW := "input" mywin := wininput dval := menu_input(wininput) # menu_input.icn } "concept menu": { MENUWINDOW := "concept" mywin := winconcept concept := unparse(directobject) if concept == "[]" then concept := DOT1 if DEBUG=="MENU" then writes_type(mylog,concept,cinfo||"concept") dval := concept_menu_input(winconcept,concept) # menu_concept.icn } } case dval of { default: { } "Close": { } "Exit": { do_exit() } } # end case dval case MENUWINDOW of { default: { } "input": { mywclose(wininput) } "concept": { mywclose(winconcept) } "console": { } } # end case MENUWINDOW mywclose(wininput) mywclose(winconcept) } # end default default: { dval := "" writes_type(&errout,SYSTYPE,warning||cmd||" not available for systype") writes_type(mylog,SYSTYPE,warning||cmd||" not available for systype") } } # end case SYSTYPE } # end "menu" } # end default } # end case MENU "unique": { dval := write(cmdfd,unique_name(directobject[1][1])) } # newid.icn "measure": { dval := do_measure(cmd,directobject,option) } # view.icn "classify": { dval := do_classify(cmd,directobject,option,outfile) } # view.icn #---------------------------------------------------------------- "SubL": { # do SubL od exp done; case KBMODE of { "cycws": { dval := cycws_SubL(unparse(directobject)) } default: { writes_type(&errout,KBMODE,warning||cmd||" not available for kbmode") writes_type(mylog,KBMODE,warning||cmd||" not available for kbmode") } } # end case KBMODE } "find": { # do find od pattern in xname from subhierarchy with option; pattern := unparse(directobject) xname := unparse(array) subhierarchy := unparse(infile) option := unparse(option) ##if DEBUG == "FIND" then write(&output,yyprefix,"pattern = (",pattern,") xname = (",xname,") subhierarchy = (",subhierarchy,") option = (",option,")") case KBMODE of { "cycws": { wsget_concept(pattern,option) # cyc_ws.icn } default: { # do find od pattern in xname from subhierarchy done; dval := wild_find(cmd,pattern,subhierarchy,xname,option) # mywildcard.icn } } # end case KBMODE } "vpush":{ every vname := ! directobject do dval := vpush(vname) } # context.icn "vpop": { dval := vpop() } # context.icn #---------------------------------------------------------------- ("differentiate"):{ dval := do_differentiate(cmd,directobject,option) # view.icn } ("integrate"):{ dval := do_integrate(cmd,directobject,option) # view.icn } #---------------------------------------------------------------- "check": { #-----# # do check od arg done; case *arg of { default: { dval := [] every x := !arg do { put(dval,check(&output,x)) # check.icn } } 0: { dval := check(&output,"") } # check.icn } # end case } # end "check" "print":{ #-----# # do print to outfile od directobject done; head := info||"print: " pfile := unparse(outfile) | "" case pfile of { default: { pfd := open(pfile,"a") } "": { pfd := &output } "output": { pfd := &output } } # end case pfile dval := [] qline := unparse(directobject,b) pline := trim(qline,squote++dquote,0) rline := replace_dollar_line(pline) if DEBUG == "PRINT" then { write(mylog,yyprefix,"print: ","qline = (",qline,")") write(mylog,yyprefix,"print: ","pline = (",pline,")") write(mylog,yyprefix,"print: ","rline = (",rline,")") } put(dval, write(pfd,rline)) case pfile of { default: { close(\pfd) } "": { } "output": { } } # end case pfile } # end "print" #---------------------------------------------------------------# ("name"|"nickname"| "given-name"|"surname"| "title-name"|"suffix-name"| "first-name"|"middle-name"|"last-name"): { #--------------------------------------# every cname := !directobject do { dval := write(cmdfd,get_name(cname,cmd)) # alias.icn } } "average": { dval := write(cmdfd,list_average(directobject)) # utility.icn } ("min"|"max"|"sum"): { #-----------------# dval := write(cmdfd,get_numeric(cmd,directobject)) # utility.icn } ("year"|"month"|"day"|"ymd"|"dmy"|"mdy"): { #--------------------------------------# date := directobject[1][1] date := unparse(date) dval := write(cmdfd,get_date(cmd,date)) # utility.icn } "dir": { #----# # DOS dir command - list files in directory if *directobject > 0 then cmdobj := cmd ||" "||directobject[1] else cmdobj := cmd rc := system(cmdobj) dval := write(mylog,"# INFO: ",rc," = system(\"",cmdobj,"\")") } # end "dir" "getenv": { #---------# # do getenv od variable done varlist := directobject[1] every variable := !varlist do { if value := getenv(variable) then { } else { value := "not found" } write(&output,"set ",variable," = ",value) } # end every do } # end "getenv" "get proposition": { # proposition isc* ?; # do get proposition from view done; proplist := get_proposition() # context.icn dval := proplist } "import proposition": { # proposition isc* ?; # do get proposition from view done; proplist := get_proposition() # context.icn dval := interpret_line(proplist) # mkr_parser.y } #========================================================# # emulate UNIX commands "pwd": { #-----# # do pwd done dval := do_pwd() # shell.icn if *dval > 0 then write(&output,dval) } "cd": { #-----# # do cd od directory done directobject := unparse(directobject) dval := do_cd(directobject) # shell.icn write(&output,dval) } "ls": { #-----# # do ls with option od directobject done directobject := list_unparse(directobject) dval := do_ls(directobject,option) # shell.icn every write(&output,!dval) } "mkdir": { #--------# # do mkdir od directory done directobject := list_unparse(directobject) dval := do_mkdir(directobject) # shell.icn write(&output,dval) } "rmdir": { #--------# # do rmdir od directory done directobject := list_unparse(directobject) dval := do_rmdir(directobject) # shell.icn write(&output,dval) } #========================================================# # special Windows commands ("delete comment"|"deletecomment"): { # do deletecomment od infile to outfile done; # ke and sh command writes_type(mylog,line,info||"executing as sh command") dval := shell(cmd,directobject,option,outfile) } # end "deletecomment" "explorer": { # do explorer od directory done # execute Windows Explorer # ke and sh command writes_type(mylog,line,info||"executing as ke command") cmd := WEXPLORE # set by init.icn directory := directobject[1][1] | "" dir := map(directory,"/","\\") # windows path sline := cmd if *dir > 0 then { sline ||:= " "||dir } if dval := system(sline) then { writes_type(mylog,sline,info||"explorer: success: system") } else if dval := shell(sline) then { writes_type(mylog,sline,info||"explorer: success: shell") } else { dval := "" writes_type(mylog,sline,warning||"explorer: FAILED") } } # end "explorer" #========================================================# # special Icon commands -- only in Icon 9.3.2 "ftype": { #--------# # do ftype od file done # get type of file # ftype ::= - b c d l p fname := directobject[1][1] dval := get_ftype(fname) # shell.icn write(&output,dval) } # end "ftype" "fstatus": { #----------# # do fstatus od file done # get status of file # fstatus ::= -rwxrwxrwx fname := directobject[1][1] dval := get_fstatus(fname) # shell.icn write(&output,dval) } # end "fstatus" "fsize": { #--------# # do fsize od file done # get size of file # fsize ::= bytes fname := directobject[1][1] dval := get_fsize(fname) # shell.icn write(&output,dval) } # end "fsize" #========================================================# # special ke commands #####"read_dmoz": { ######-----------------# ##### # do read_dmoz from dmozfile done; ##### dmozformat := "rdf" ##### if DEBUG==("DMOZ"|"GOOGLE") then { ##### writes_type(mylog,option,cinfo||"option") ##### writes_type(mylog,infile[1][1],cinfo||"infile[1][1]") ##### } ##### dmozfile := unparse(infile[1][1]) ##### dmozfile := substitute_filename(dmozfile) # command.icn $variables ##### add_unit(dmozfile,"file") ##### ##### saveUniqueName := UniqueName; UniqueName := "rootname" ##### writes_type(mylog,DBMODE,cinfo||"DBMODE") ##### writes_type(mylog,UniqueName,cinfo||"UniqueName") ##### writes_type(mylog,DisplayName,cinfo||"DisplayName") ##### ######====================================================================== ##### # code adapted from "read" command ##### if dmozfile == "input" then { ##### fd := &input ##### } else if fd := keopen(dmozfile,"r") then { ##### } else { ##### KERROR +:= 1 ##### writes_type(&errout,dmozfile,cerror||"can't open input file") ##### writes_type(mylog,dmozfile,cerror||"can't open input file") ##### fail ##### } # end if dmozfile == "input" ##### file_init(dmozfile,"begin") # includes dmozfile isu file; ##### CurrentFD := fd ##### get_file_parameter(dmozfile,directobject,pplist,"read") # fparam.icn ##### #OLDcomplete("_BeginRead_") ##### ##### dval := read_tap(fd,dmozfile,"rdf") # dmoz.icn ##### ##### #OLDcomplete("_EndRead_") ##### NEWcomplete("_restart_") # nesting stack ##### file_init(dmozfile,"end") ##### CurrentFD := FD ##### if dmozfile == "input" then { } else { ##### close(fd) ##### } ######=================================================================== ##### ##### UniqueName := saveUniqueName ##### ##### } # end "read_dmoz" "read input": { # do read input done; # read line from standard input if dval := read(&input) then { } else { fail } # end if } #####( #####"read html"| #####"read htm"| #####"read mcf"| #####"read owl"| #####"read rdf"| #####"read tap" #####): { ######-----------------# ##### # do read tap from tapfile ##### # with tapformat=tf # defaults to rdf ##### # done; ##### # tapformat ::= mcf | rdf | daml ##### if DEBUG==("TAP"|"RDF"|"MCF"|"DAML") then { ##### writes_type(mylog,option,cinfo||"option") ##### writes_type(mylog,infile[1][1],cinfo||"infile[1][1]") ##### } ##### if *option = 0 then ##### option := [["tapformat","=","rdf"]] ##### name := unparse(option[1][1]) ##### tapformat := unparse(option[1][3]) ##### if name == "tapformat" then { } else { ##### writes_type(&errout,name,cwarning||"name not tapformat") ##### writes_type(mylog,name,cwarning||"name not tapformat") ##### } ##### tapfile := unparse(infile[1][1]) ##### tapfile := substitute_filename(tapfile) # command.icn $variables ##### ######====================================================================== ##### # code adapted from "read" command ##### if tapfile == "input" then { ##### fd := &input ##### } else if fd := keopen(tapfile,"r") then { ##### } else { ##### KERROR +:= 1 ##### writes_type(&errout,tapfile,cerror||"can't open input file") ##### writes_type(mylog,tapfile,cerror||"can't open input file") ##### fail ##### } # end if tapfile == "input" ##### file_init(tapfile,"begin") # includes tapfile isu file; ##### CurrentFD := fd ##### get_file_parameter(tapfile,directobject,pplist,"read") # fparam.icn ##### #OLDcomplete("_BeginRead_") ##### ##### case cmd of { ##### "read mcf": { dval := read_mcf(fd,tapfile) } # tap.icn ##### "read html":{ dval := read_tap(fd,tapfile) } # tap.icn ##### "read htm": { dval := read_tap(fd,tapfile) } # tap.icn ##### "read owl": { dval := read_tap(fd,tapfile) } # tap.icn ##### "read rdf": { dval := read_tap(fd,tapfile) } # tap.icn ##### "read tap": { dval := read_tap(fd,tapfile,tapformat) } # tap.icn ##### } ##### ##### #OLDcomplete("_EndRead_") ##### NEWcomplete("_restart_") # nesting stack ##### file_init(tapfile,"end") ##### CurrentFD := FD ##### if tapfile == "input" then { } else { ##### close(fd) ##### } ######=================================================================== ##### ##### } # end "read tap" "read directory": { #-----------------# # do read directory od concept from directory done; # recursive read from file system to knit saveUniqueName := UniqueName UniqueName := "rootname" option := option[1][1] cname := directobject[1][1] fsdir := infile[1][1] fsdir := substitute_filename(fsdir) # command.icn $variables #add_unit(cname,"hierarchy") dval := read_directory(cname,fsdir,option) # dir.icn UniqueName := saveUniqueName NEWcomplete("_restart_") # nesting stack } # end "read directory" "write directory": { #------------------# # do write directory od concept to directory done; # recursive write from knit to file system option := option[1][1] cname := directobject[1][1] fsdir := outfile[1][1] fsdir := substitute_filename(fsdir) # command.icn $variables #add_unit(cname,"hierarchy") dval := write_directory(cname,fsdir,option) # dir.icn } # end "write directory" #========================================================# # "read": { #-------# do read from kfile done; kfile := unparse(infile) kfile := substitute_filename(kfile) # command.icn $variables dval := read_knit(,kfile) # mkr_io.icn } # end "read" "write": { #-------# do write od line to kfile done; line := unparse(directobject) kfile := unparse(outfile) kfile := substitute_filename(kfile) # command.icn $variables if fd := keopen(kfile,"w") then { dval := write(fd,line) keclose(fd) } else { write(&errout,yyprefix,"can't open file (",kfile,") for writing"); fail } # end if } # end "write" #####"entropy": { ######-------# ##### # count file ##### if *directobject > 0 then { ##### kfile := unparse(directobject) ##### kfile := substitute_filename(kfile) # command.icn $variables ##### get_file_parameter(kfile,directobject,pplist,"read") # fparam.icn ##### ##if fd := open(kfile,"r") then { ##### if fd := keopen(kfile,"r") then { ##### dval := count_file(fd,kfile) # entropy.icn ##### close(fd) ##### } else { ##### write(&errout,"# ERROR: can't open: ",kfile) ##### } # end if fd := open() ##### } else { ##### unknown_command(cmd,exline,[],stype) ##### return dval ##### } # end if *directobject > 0 ##### } # end count } # end case cmd #---------------------------------------------------------------- add_word(exline,cmd) add_word(exline,pplist) if DEBUG==("DOLLAR"|"MEANING"|"PRODUCT") then { writes_type(mylog,dval,cinfo||"dval") } } # end if ctype=="method" #=================================================# } # end every cmd if DEBUG=="PRODUCT" then writes_type(mylog,dval,info||"dval") if /dval then { writes(&errout,"\n") writes_type(&errout,exline,ierror||"$Command not set for line") writes(mylog,"\n") writes_type(mylog,exline,ierror||"$Command not set for line") dval := "'***** UNKNOWN *****'" } put_dollar("Command",dval) put_dollar("Sentence",dval) KFORMAT := pop(SaveStack) return dval end #---------------------------------------------------------------# procedure unknown_command(cmd,line,symbol,stype) #==================================================== local dval static info,error,ierror,warning initial { info := "INFO: unknown_command: " error := "ERROR: unknown_command: " ierror := "Internal ERROR: unknown_command: " warning := "WARNING: unknown_command: " } if member(HDO_ACTION,cmd) then { writes_type(&errout,cmd,warning||"use hdo for this command") } else { writes_type(&errout,line,warning||"line") writes_type(mylog,line,warning||"line") } dval := [] put_dollar("Command",dval) put_dollar("Sentence",dval) NCOMMAND -:= 1 add_statement(line,symbol,"newstatement") end #