NB. Some functions to manage the sysadmin database. NB. A database is a list of boxed items, called records. NB. A record is list of 6 boxed items: NB. problem-date (format yyyymmdd) NB. problem-source (initials of the person who reports the problem) NB. problem-completion-date (format yyyymmdd) NB. problem-solver (initials of person who solves the problem) NB. problem-name (brief phrase describing problem; potential search key) NB. problem-description (detailed text describing problem) NB. database file-name sysadmin.db NB. db_create, usage: db_create 'db-file-name' db_create =: monad def 0 '' write_list y. ) NB. add_record, usage: 'yyyymmdd' add_record 'initials-of-problem-source' add_record =: dyad def 0 'ProblemName'write'prob-name' 'ProblemDescription'write'prob-desc' vi'prob-name' vi'prob-desc' ((read_list 'sysadmin.db'), < x. ; y. ; 'wwww' ; 'xx' ; (_1 }. read'prob-name') ; _1 }. read'prob-desc')write_list 'sysadmin.db' ) NB. edit_record, usage: field edit_record record-number edit_record =: dyad def 0 db =. read_list 'sysadmin.db' record =. y. { > db (> x. { record) write'temp' vi'temp' new_record =. (< _1 }. read'temp') x. } record (( db (write_record & x.)"1 > db ) NB. make_todo_list, usage: make_todo_list 'db-file-name' (usually sysadmin.db) make_todo_list =: 'sysadmin-todo'&write_txt NB. write_append, usage j-item write_append 'existing-file-name' write_append =: dyad def 'x. 1 !: 3 < y.' NB. write_record write_record =: dyad def 0 nl =. 10{a. (,format > 0 { x. ) write_append y. ' ' write_append y. (,format > 1 { x. ) write_append y. ' ' write_append y. (,format > 2 { x. ) write_append y. ' ' write_append y. (,format > 3 { x. ) write_append y. ' ' write_append y. (,format > 4 { x. ) write_append y. nl write_append y. (,format > 5 { x. ) write_append y. nl write_append y. (format > 6 { x.) write_append y. (nl,'------------------------------------------------') write_append y. nl write_append y. ) NB. Record field name definitions prob_date =: 0 prob_source =: 1 completion_date =: 2 prob_solver =: 3 prob_name =: 4 prob_description =: 5 NB. Key Definitions get_keys =: dyad def '(x.&{) "1 > read_list y.' NB. Key accessor functions, usage: key-fn 'db-file-name' get_prob_date =: prob_date&get_keys get_prob_source =: prob_source&get_keys get_completion_date =: completion_date&get_keys get_prob_solver =: prob_solver&get_keys get_prob_name =: prob_name&get_keys get_prob_description =: prob_description&get_keys NB. Handy utility to show record numbers of various problems NB. by prob_description NB. record_no, usage: record_no 'db-file-name' (usually sysadmin.db) record_no =: monad def 0 t =. > get_prob_name y. t =. t,. ' ',. > get_prob_date y. t =. t,. ' ',. > get_prob_source y. t =. t,. ' ',. > get_completion_date y. t =. t,. ' ',. > get_prob_solver y. ((system'date'),10{a.),,((format i. (#t),1),.' ',.t),.10{a. ) NB. Handy utility to show record numbers of various problems NB. by prob_description to be used in a J cgi script NB. to build a web page with links to generated web pages. NB. record_no_web, usage: record_no_web 'db-file-name' (usually sysadmin.db) record_no_web =: dyad def 0 t =. > get_prob_name y. t =. t,. '<' t =. t,. '/' t =. t,. 'a' t =. t,. '>' t =. t,. ' ',. > get_prob_date y. t =. t,. ' ',. > get_prob_source y. t =. t,. ' ',. > get_completion_date y. t =. t,. ' ',. > get_prob_solver y. u =. ' ' ,. t) ,. 10{a. ) NB. locate_all (build db of all records matching a given key) NB. usage: locate_all field-name ; 'search-text' ; 'db-file-name' NB. A useful command to build incomplete.db (database of incomplete problems) NB. (locate_all completion_date ; 'wwww' ; 'sysadmin.db')write_list 'incomplete.db' locate_all =: monad def 0 ('x' ; 'y' ; 'db') =. y. ((< y) -: "0 x get_keys db) # read_list db ) NB. locate (get record of first match of a given key) NB. usage: locate field-name ; 'search-text' ; 'db-file-name' locate =: (>@ {.)@ locate_all NB. Print DB stuff NB. usage: print_db '' (ignores argument) print_db =: monad def 0 (locate_all completion_date ; 'wwww' ; 'sysadmin.db')write_list 'incomplete.db' (record_no 'incomplete.db') write 'problem-incomplete' 'sysadmin-incomplete' write_txt 'incomplete.db' (record_no 'sysadmin.db') write 'problem-sysadmin' 'sysadmin-todo' write_txt 'sysadmin.db' system'mpage -4 problem-incomplete sysadmin-incomplete problem-sysadmin sysadmin-todo sysadmin-db.js | lpr -P portia' ) NB. Edit the prob_description, completion_date and prob_solver fields NB. of a record. edit_all =: monad def 0 NB. prob_date edit_record y. NB. prob_name edit_record y. NB. prob_source edit_record y. prob_description edit_record y. completion_date edit_record y. prob_solver edit_record y. ) run=: 4 : 0 'p o i'=. 2!:2 x. y. 1!:2 i 1!:22 i 2!:3 p z=. 1!:1 o 1!:22 o z ) grep_description =: dyad def '-. 0= # (''grep -i '',x.) run > 5{ > y.' search_description =: monad def 'y. grep_description " _ 0 read_list ''sysadmin.db'''