# # KEHOME/src/command.icn # Richard H. McCullough Nov/13/2005 Jul/20/2009 Dec/1/2014 Apr/11/2015 link array link check link clock ###link dir link hfun link hierarchy link integrate link random link relation link shell link variable link interaction link window link test # select_problem() link hocommand # hodo_command() global TDATA global ARGINFO global ProNoun global wininput,winconcept,mywin global CurrentDirectory,CurrentFile,CurrentFD global COMMAND,legal_command,kecommand,shcommand global WEXPLORE global cyc_command global EXIT global PATH $include "../parser/yyinclude.h" $include "keparam.h" # single-argument functions are listed in hfun.icn # procedures #===========# # add_command() # command2arglist(symbol) # do_command(verb,cmd,pplist) # do_stv(cmd) # init_command() # substitute_filename(x) # unknown_command(cmd,line,symbol,stype) # 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; # hdo hdocmd from concept to concept with path; # vdo vdocmd od concept with path; hdo_init() # HDO_ACTION := set(...) # hdo.icn vdo_init() # VDO_ACTION := set(...) # context.icn kecommand := set([ "nvtable", "alias", "definition", "gsu", "ambiguity", "list table", "list tables", "write table", "write array", "write hierarchy", "write relation", "write gdbm", "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", "cd", "check", "clock", "close cyc", "close tap", "dbclose", "dbopen", "dbprint", "delete", # do delete od uname from cname in hierarchy; do delete od uname in array; ##### "delete/gdbm", "dump", ##### "dump gdbm", "dump argtable", "ged", "write ged", "dump ged", "read ged","print gedlist", "gedlist", "gedchar", "gedtree", "dump hidden", "dump nvstack", "empty", # empties list or set "entropy", "exec", # execute proposition list "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", "import", "interpret_line", "last-name", "load", "load ged", "kbcheck", "kbwrite", "ls", "list member", "max", "merge", # do merge od uname,... to destination; "middle-name", "min", "mkdir", "mount hierarchy", "move", # do move od uname,... from source to destination; "move unit", # do move unit od uname,... from source to destination; #"name", # attribute #"new group", # NO: use: gname is gtype of utype #"nickname", # attribute "open cyc", "open tap", "parse list", #"path2list", # function -- see hfun.icn "print", "print context", "print definition", "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 top", "set universe", "sh", "shuffle","deal", # deck "simplify lattice", "type", "ctype", "gtype", "utype", "ptype", "size", "size_genus", "size_species", "size_unit", "size_list", "size_set", "size_array", "size_hierarchy", "size_relation", "size_table", "SubL", "suffix-name", "sum", "surname", "title-name", "unique", #"vdo", # vdo exec od {sentence};/ #"vfind", # vdo find od wildcard; "vpop", "vpush", "webdir", "write", "vwrite", "year", "month", "day", "ymd", "dmy", "mdy" ]) # ! 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 # attributes & verbs & actions which are also commands legal_command := COMMAND ++ legal_function legal_command ++:= set([ "differentiate","integrate" ]) legal_command ++:= set([ "measure","classify" ]) end procedure add_command() #====================== # declare commands local atab,cmd local fdebug static prog,b,colon,yyprefix initial { prog := "add_command: " b := " " colon := ":" } fdebug := mylog yyprefix := yylineno||colon||yywordno||b||yyformat||b||prog every cmd := ! COMMAND do { if cmd == ("command"|"COMMAND"|"") then { write(fdebug,yyprefix,"FAIL: cmd = (",cmd,")") } else { add_species(cmd,"COMMAND") # hop.icn ke_putchar("do "||cmd||" =","") # kechar.icn } } 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; # SYMBOL(Dcd, svalue) # do cmdlist pplist; # SYMBOL(Dcpd,svalue) # vdo cmdlist pplist; # 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 ...; # # verb ::= # do | hdo | vdo | ! # cmd ::= # phrase # reduce to # qword # isverb => isd,isi local subhierarchy,nlevel local source,destination local top,hotable,tname local line,head local xname,xt,tsize,gt local aname 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 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 local fdebug,q,charkey 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: " error := "ERROR: " ierror := "Internal ERROR: " warning := "WARNING: " /TDATA := table() /ARGINFO := table() /BOOT := table() /CHIT := table() /KNIT := table() /ALIAS := table() /ProNoun := table() } fdebug := mylog yyprefix := yylineno||colon||yywordno||b||KFORMAT||b||prog /cmdfd := &output verb := unparse(verb) cmd := unparse(cmd) line := verb||b||cmd||unparse(pplist)||s if DEBUG == "COMMAND" then write(fdebug,yyprefix,"verb = (",image(verb),") cmd = (",image(cmd),") pplist = (",unparse(pplist),")") push(SaveStack,KFORMAT) NCOMMAND +:= 1 NkuSENTENCE +:= 1 NPROPOSITION +:= 1 if DEBUG=="TIME" then write(fdebug,"## ",&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: " write(fdebug,yyprefix,head||"cmd = (",cmd,") pplist = (",showparse(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 ?; # without "ke" ke_question("ke","hdo") # kechar.icn ke_question("ke","do") # kechar.icn next } "!": { # ! ?; # without "sh" write(cmdfd,"sh !") every write(cmdfd,"\t",!sort(shcommand)) write(cmdfd,";") 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(fdebug,yyprefix,"before substitution: pplist = (",showparse(pplist),")") pplist := replace_dollar_symbol(pplist) # replace.icn write(fdebug,yyprefix,"after dollar substitution: pplist = (",showparse(pplist),")") pplist := replace_pronoun_symbol(pplist) # replace.icn write(fdebug,yyprefix,"after pronoun substitution: pplist = (",showparse(pplist),")") if DEBUG == ("COMMAND"|"MEANING") then { head := cinfo||"after dollar substitution: " write(fdebug,yyprefix,head||"cmd = (",cmd,") pplist = (",showparse(pplist),")") } #=========================# # echo after substitution # #=========================# echoline := doword||b||cmd||b if is_ppnull(pplist) then { } else { echoline ||:= unparse(pplist) } echoline ||:= b||";" if DEBUG == "DOLLAR" then { write(fdebug,"# 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(directobject,c) infile := ppobj.ppfrom outfile := ppobj.ppto array := ppobj.ppin product := ppobj.ppout } else { write(fdebug,yyprefix,"empty ppobject: pplist = (",showparse(pplist),")") } # end if } # end if /arg := [] if DEBUG == ("ARG"|"ARGLIST"|"PPLIST"|"COMMAND") then write(fdebug,yyprefix,"cmd = (",cmd,") arg = (",showparse(arg),") pplist = (",showparse(pplist),")") # 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 { write(fdebug,yyprefix,info||"executing exline (",exline,")") } ctype := get_ctype(cmd) # look for methods #=================# if ctype == "method" then { write(fdebug,exline,info||"executing method (",exline,")") 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; 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; dval := vdo(cmd,ppobj,echoline) # context.icn # look for hdo commands (hwalk) #=============================# } else if doword == "hdo" then { # hdo action od concept with path in hierarchy; action := cmd cname := unparse(directobject) path := unparse(option) if *path = 0 then path := "-" if DEBUG == "HDO" then { write(fdebug,yyprefix,"action = (",action,")") write(fdebug,yyprefix,"cname = (",cname,")") write(fdebug,yyprefix,"path = (",path,")") } dval := hdo(action,cname,path) # hdo.icn # look for interactions #====================== } else if doword == "happens" then { # happens interaction pplist; interaction := cmd dval := do_interaction( # interaction.icn doword, interaction, pplist ) } else { # "do"|"hdo"|"vdo" ??? # "can"|"must"|"shall"|"ought" ??? # do cmd pplist; # continue below case cmd of { #===========# default: { if member(kecommand,cmd) then { write(&errout,yyprefix,warning||"not implemented (",exline,")") write(fdebug, yyprefix,warning||"not implemented (",exline,")") } else { unknown_command(cmd,exline,[],stype) } } # end default ("set top"|"set universe"): { # do set top od top in hotable; top := unparse(directobject) hotable := unparse(array) set_top(hotable,top) # mkr_table.icn } "ambiguity": { # ambig := do ambiguity od hierarchy; # ambig := do ambiguity od concept in hierarchy: # ambig := do ambiguity od sentence in hierarchy: directobject := csv_list(directobject)[1] array := unparse(array) dval := ho_ambiguity(directobject,array) # hierarchy.icn return dval } "webdir": { # do webdir [with all] od url; url := unparse(directobject) option := unparse(option) dval := [] every line := webdir(url,option) do { put(dval,line) write(&output,line) } } # write_table() is in KEHOME/parser/unparse.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 := *NewPhrase; head := "NewPhrase" ||"("||tsize||")"; write(&output,head) tsize := *ALIAS; head := "ALIAS" ||"("||tsize||")"; write(&output,head) tsize := *KNIT; head := "KNIT" ||"("||tsize||")"; write(&output,head) tsize := *CHIT; head := "CHIT" ||"("||tsize||")"; write(&output,head) tsize := *BOOT; head := "BOOT" ||"("||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 := ttype(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 } "NewPhrase": { tsize := *NewPhrase; head := xname||"("||tsize||")"; write_table(&output,NewPhrase, xname,,head); return xname } ("alias"|"ALIAS"): { tsize := *ALIAS; head := xname||"("||tsize||")"; write_table(&output,ALIAS, xname,,head); return xname } ("knit"|"KNIT"): { tsize := *KNIT; head := xname||"("||tsize||")"; write_table(&output,KNIT, xname,,head); return xname } ("chit"|"CHIT"): { tsize := *CHIT; head := xname||"("||tsize||")"; write_table(&output,CHIT, xname,,head); return xname } ("boot"|"BOOT"): { tsize := *BOOT; head := xname||"("||tsize||")"; write_table(&output,BOOT, xname,,head); return xname } } # end case xname if member(ARGINFO,xname) then { ct := unparse(get_ctype(xname)) ##### if (ct == "relation") & (tname := nrel_tname(xname)) then { ##### tsize := *tname # nrel_size(xname) ##### head := "relation "||xname||"("||tsize||")" ##### write_table(&output,tname,xname,,head) ##### } if (ct == "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 } "hodisplay": { # do hodisplay od concept,nlevel in hname; if DEBUG == ("HO"|"HIERARCHY"|"HODISPLAY") then { write(&output,yyprefix,"cmd = (",cmd, ") arg = (",showparse(arg), ") directobject = (",showparse(directobject), ") array = (",showparse(array),")") } xname := unparse(array) if /xname | (*xname = 0) then xname := HIERARCHY tname := new_ho(xname) concept := unparse(arg[1]) nlevel := unparse(arg[2]) write(&output,yyprefix,"hodisplay: ","concept = (",concept,") nlevel = (",nlevel,") xname = (",xname,") tname = (",image(tname),")") dval := hodisplay(concept,nlevel,tname) } # commands in hocommand.icn #========================== "hobottom": { # do hobottom od object from source; hodo_command(verb,cmd,pplist) } "hodelete":{ # do hodelete od object from source; hodo_command(verb,cmd,pplist) } "hofind": { # do hofind od object from source; hodo_command(verb,cmd,pplist) } "hoload": { # load view from directory; hodo_command(verb,cmd,pplist) } "homatch": { # do homatch od object from source; hodo_command(verb,cmd,pplist) } "homove": { # do homove od object from source to destination; hodo_command(verb,cmd,pplist) } ##### "hoprint": { ##### # do hoprint od object from source to destination; ##### hodo_command(verb,cmd,pplist) ##### } "hosave": { # save view to directory; hodo_command(verb,cmd,pplist) } "hotop": { # do hotop od object from source; hodo_command(verb,cmd,pplist) } "remove bracket": { # do remove bracket od x; x := unparse(directobject) dval := remove_bracket(x) } "remove paren": { # do remove paren od x; x := unparse(directobject) dval := remove_paren(x) } "remove brace": { # do remove brace od x; x := unparse(directobject) dval := remove_brace(x) } "remove angle": { # do remove angle od x; x := unparse(directobject) dval := remove_angle(x) } "select": { # do select od args from inrel to outrel with condition; # outrel := do select od args from inrel with condition; writes_all([]) writes_type_all(line,cinfo||"line") args := list_unparse(directobject) ##### nvcondition := list_unparse(nvoption,";",psep) if DEBUG == "SELECT" then { writes_type(fdebug,args,cinfo||"args") writes_type(fdebug,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) q := new_nrel(outrel) 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; # 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; dval := cyc_close() } #####"open tap": { ##### # do open tap od kbdata with option to kbfile; ##### # 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; ##### dval := tap_close() ##### } ##### "size/gdbm": { ##### # do size/gdbm od gdbmtable,...; ##### 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,...; dval := [] viewlist := list_unparse(directobject) if *viewlist == 0 then viewlist := [["tabula rasa"]] # default every view := !viewlist do { view := !view dbdir := DBDIR dbfile := dbdir||"/*.dir" kline := "! ls "||squote||dbdir||squote||";" write(fdebug,"##### view = ",view," #####") write(&output,"##### view = ",view," #####") interpret_line(kline) } # end every view } "size": { # do size od x; dval := [] every x := !list_unparse(directobject) do { #####x := !x if DEBUG==("VALUE"|"VARIABLE") then { writes_type(fdebug,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) } "ALIAS": { num := *ALIAS 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_genus": { return *hoget_genus(cname) } "size_species": { return *hoget_species(cname) } "size_unit": { return *hoget_unit(cname) } "size_list": { } "size_set": { } "size_array": { return *new_array(cname) } "size_hierarchy": { return *new_ho(cname) } "size_relation": { return *new_nrel(cname) } "size_table": { return *new_table(cname) } "hload": { # do hload from file to boot; kfile := unparse(infile) btable := unparse(outfile) nconcept := hload(kfile) dval := nconcept } "hdump": { # do hdump from boot to file; write(&errout,TypeComment||warning||"not implemented") } "hget": { # do hget od concept from boot; concept := unparse(directobject) btable := unparse(infile) if node := hget(concept,,"user") then { ###writes_type(fdebug,node,info||"node") delete(BOOT,concept) every kline := !node do dval := interpret_line(kline) } # end if } "hput": { # do hput od concept to boot; write(&errout,TypeComment||warning||"not implemented") } ##### "dump gdbm": { ##### # array stored in GDBM database ##### # do dump/gdbm od cname... with translation to outfile; ##### 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; 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; ##### # 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; # 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; s := unparse(directobject) sep := unparse(option) dval := parse_csv(s,sep) } "quote": { # qs := do quote od s; # enclose string in dquote s := unparse(directobject) dval := dquote||s||dquote } "dquote": { # qs := do dquote od s; # enclose string in dquote s := unparse(directobject) dval := dquote||s||dquote } "squote": { # qs := do squote od s; # enclose string in squote s := unparse(directobject) dval := squote||s||squote } "dequote": { # s := do dequote od qs; # remove quotemarks from string s := unparse(directobject) dval := dequote(s) # convert.icn } "empty": { # do empty od x; # 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; 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; #writes_type(fdebug,directobject,info||"directobject") #writes_type(fdebug,infile,info||"infile") #writes_type(fdebug,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(fdebug,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(fdebug,uinfile,cwarning||"ignoring from") #### } #### if *outfile = 0 then { #### uoutfile := unparse(outfile) #### writes_type(&errout,uoutfile,cwarning||"missing to") #### writes_type(fdebug,uoutfile,cwarning||"missing to") #### } #### } else { #### uinfile := unparse(infile) #### if *infile > 2 then { #### writes_type(&errout,uinfile,cwarning||"extra agument in from") #### writes_type(fdebug,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(fdebug,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(fdebug,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(fdebug,iy,cerror||"non-numeric index in to") #### } #### } # end if *outfile #### dval := [mem] } "random": { dval := random(directobject) } # utility.icn "shuffle": { # do shuffle od deck; # 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; # 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(fdebug,ncard,info||"ncard") writes_type(fdebug,ndiscard,info||"ndiscard") writes_type(fdebug,deck,info||"deck") writes_type(fdebug,hand,info||"hand") writes_type(fdebug,discard,info||"discard") writes_type(fdebug,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(fdebug,yyprefix,"dbclose: ","arg = (",showparse(arg),")") dval := dbclose ! arg # hoio.icn } "dbopen": { # do dbopen od xname,xtype,mode,pat,init,top; ##write(&output,yyprefix,"directobject = (",showparse(directobject),")") write(fdebug,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; ##### namespace := unparse(directobject) ##### url := unparse(infile) ##### dval := do_import_namespace(namespace,url) # xml.icn ##### } #####"ExtractData": { ##### # do ExtractData od letter from letter.html; ##### # do ExtractData od letter,letter.html; ##### letter := directobject[1][1] ##### htmlfile := directobject[1][2] | infile[1][1] ##### dval := xdletter(letter,htmlfile) ##### } "exec": { # do exec od {proplist}; # execute proposition list proplist := unparse(directobject," ") # string proplist := remove_brace(proplist) #proplist := trim(proplist,";") # semicolon now required if DEBUG=="EXEC" then { writes_type(fdebug,directobject,info||"exec: directobject") writes_type(fdebug,proplist,info||"exec: proplist") writes_type(fdebug,directobject,info||"exec: directobject") writes_type(fdebug,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; <<== 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; dval := write(&errout,exline,info||"executing command") } # end "input relation" "update relation": { # do update relation od rname from infile to outfile; # do read od rname from infile; # do input relation od rname; # do write od rname to outfile; dval := write(&errout,exline,info||"executing command") } # end "update relation" "delete": { # do delete od uname from cname in hierarchy; # do delete od uname in array; uname := csv_list(directobject) cname := csv_list(infile) aname := unparse(array) | "hogenus" if *aname = 0 then aname := "hogenus" if DEBUG == "DELETE" then write(&output,yyprefix,"delete: ","uname = (",showparse(uname),") cname = (",showparse(cname),") aname = (",aname,")") if (type(cname) == "null") | (*cname = 0) then { ##### uname := "["||trim(uname,'[]',0)||"]" # array key always includes brackets dval := hodelete_concept(uname,aname) # hierarchy.icn } else { dval := delete_unit(uname,cname,aname) # hop.icn dval := delete_species(uname,cname,aname) # hop.icn ###dval := delete_member(uname,cname) # hop.icn ###dval := delete_alternative(uname,cname) # hop.icn } # end if } # end "delete" "merge": { # do merge od uname,... to destination; uname := csv_list(directobject) destination := outfile dval := merge_species(uname,destination) # hop.icn } # end "merge" "move": { # do move od uname,... from source to destination; uname := csv_list(directobject) source := infile destination := outfile dval := move_species(uname,source,destination) # hop.icn } # end "move" "move unit": { # do move od uname,... from source to destination; uname := csv_list(directobject) source := infile destination := outfile dval := move_unit(uname,source,destination) # hop.icn } # end "move unit" "replace": { # product := do replace od subject,pattern,replacement; if DEBUG == "HWALK" then writes_type(fdebug,directobject,info||"replace directobject") subject := !directobject[1] pattern := !directobject[2] replacement := !directobject[3] dval := replace_pattern(subject,pattern,replacement) } # end "replace" "hwalk": { # do hwalk od cname,action,path; # howalk(concept,level,direction,tname,act,maxlevel,option) tname := new_table(HIERARCHY) if DEBUG == "HWALK" then { writes_type(fdebug,directobject,info||"hwalk directobject") writes_type(fdebug,directobject,info||"hwalk directobject") } directobject := delete_separator(directobject) cname := unparse(directobject[1]) action := unparse(directobject[2]) path := unparse(directobject[3]) every concept := !keylist(tname) do hoVisit[concept] := 0 dval := howalk(cname,0,path,tname,action) } # end "hwalk" "interpret_line": { # do interpret_line od proposition list; if DEBUG == "PARSE" then writes_type(fdebug,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; 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; dval := [] every cname := ! directobject do { cname := unparse(cname) cname := dequote(cname) put(dval, dump_hidden(cmdfd,cname)) # concept.icn } } # end "dump/hidden" "ged": { dval := dump_ged(cmd,arg,pplist) } # ged_write.icn "dump ged": { dval := dump_ged(cmd,arg,pplist) } # ged_write.icn "write ged": { dval := dump_ged(cmd,arg,pplist) } # ged_write.icn "load ged": { dval := load_ged(cmd,arg,pplist) } # ged_write.icn "read ged": { dval := load_ged(cmd,arg,pplist) } # ged_write.icn "print gedlist": { dval := print_gedlist(,unparse(arg[1])) } # ged_read.icn "gedlist": { dval := gedlist(unparse(arg[1])) } # ged_read.icn "gedchar": { dval := gedchar(unparse(arg[1])) } # ged_read.icn "gedtree": { dval := gedtree() } # ged_read.icn "dump nvstack": { dval := ns_dump(cmdfd) } "clock": { # ke.icn dval := clock ! directobject } "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; case KBMODE of { "cycws": { dval := cycws_SubL(unparse(directobject)) } default: { writes_type(&errout,KBMODE,warning||cmd||" not available for kbmode") writes_type(fdebug,KBMODE,warning||cmd||" not available for kbmode") } } # end case KBMODE } "find": { # do find od pattern [with value] 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": { dval := wsget_concept(pattern,option) # cyc_ws.icn } default: { dval := wild_find(cmd,pattern,subhierarchy,xname,option) # mywildcard.icn } } # end case KBMODE } "vpush":{ every vname := ! directobject do dval := vpush(unparse(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; 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; 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,c) pline := trim(qline,squote++dquote,0) rline := replace_dollar_line(pline) if DEBUG == "PRINT" then { write(fdebug,yyprefix,"print: ","qline = (",qline,")") write(fdebug,yyprefix,"print: ","pline = (",pline,")") write(fdebug,yyprefix,"print: ","rline = (",rline,")") } put(dval, write(pfd,rline)) case pfile of { default: { close(\pfd) } "": { } "output": { } } # end case pfile } # end "print" "print context": { # do print context; #-------------# outfile := unparse(outfile) if /outfile | (*outfile = 0) then outfile := &output print_context(outfile) # context.icn } "print definition": { # do print context; #----------------# cname := unparse(directobject) print_definition(&output,cname) } #---------------------------------------------------------------# ("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(fdebug,"# INFO: ",rc," = system(\"",cmdobj,"\")") } # end "dir" "getenv": { #---------# # do getenv od variable; 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; proplist := get_proposition() # context.icn dval := proplist } "import proposition": { # proposition isc* ?; # do get proposition from view; proplist := get_proposition() # context.icn dval := interpret_line(proplist) # mkr_parser.y } #========================================================# # emulate UNIX commands "pwd": { #-----# # do pwd; dval := do_pwd() # shell.icn if *dval > 0 then write(&output,dval) } "cd": { #-----# # do cd od directory; directobject := unparse(directobject) dval := do_cd(directobject) # shell.icn write(&output,dval) } #========================================================# # special Windows commands ("delete comment"|"deletecomment"): { # do deletecomment od infile to outfile; # ke and sh command writes_type(fdebug,line,info||"executing as sh command") dval := shell(cmd,directobject,option,outfile) } # end "deletecomment" "explorer": { # do explorer od directory; # execute Windows Explorer # ke and sh command writes_type(fdebug,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(fdebug,sline,info||"explorer: success: system") } else if dval := shell(sline) then { writes_type(fdebug,sline,info||"explorer: success: shell") } else { dval := "" writes_type(fdebug,sline,warning||"explorer: FAILED") } } # end "explorer" #========================================================# # special Icon commands -- only in Icon 9.3.2 ##### "ftype": { ##### #--------# ##### # do ftype od file; ##### # 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; ##### # 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; ##### # 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; ##### dmozformat := "rdf" ##### if DEBUG==("DMOZ"|"GOOGLE") then { ##### writes_type(fdebug,option,cinfo||"option") ##### writes_type(fdebug,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(fdebug,DBMODE,cinfo||"DBMODE") ##### writes_type(fdebug,UniqueName,cinfo||"UniqueName") ##### writes_type(fdebug,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(fdebug,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; # 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 ##### # ; ##### # tapformat ::= mcf | rdf | daml ##### if DEBUG==("TAP"|"RDF"|"MCF"|"DAML") then { ##### writes_type(fdebug,option,cinfo||"option") ##### writes_type(fdebug,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(fdebug,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(fdebug,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; ##### # 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; ##### # 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; 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; 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(fdebug,dval,cinfo||"dval") } } # end if ctype=="method" #=================================================# } # end every cmd if DEBUG=="PRODUCT" then writes_type(fdebug,dval,info||"dval") if /dval then { ##### writes(&errout,"\n") ##### writes_type(&errout,exline,ierror||"$Command not set for line") writes(fdebug,"\n") writes_type(fdebug,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 local fdebug static prog,b,colon,yyprefix static info,error,ierror,warning initial { prog := "unknown_command: " b := " " colon := ":" info := "INFO: " error := "ERROR: " ierror := "Internal ERROR: " warning := "WARNING: " } fdebug := mylog yyprefix := yylineno||colon||yywordno||b||yyformat||b||prog if member(HDO_ACTION,cmd) then { write(&errout,yyprefix,warning,"use hdo for this command (",cmd,")") } else { write(&errout,yyprefix,warning,"line = (",line,")") write(fdebug,yyprefix,warning,"line = (",line,")") } dval := [] put_dollar("Command",dval) put_dollar("Sentence",dval) NCOMMAND -:= 1 add_statement(line,symbol,"newstatement") end #