interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

branch main Branches Tags History

hop / Omega / tests / mutant / hoppanel-deaf.om

13093 lines · 307360 bytes Raw Blame History
1target macos
2om2
3note hoppanel: the first cut of Hop's launcher panel as one Omega program, with no Swift. A window with a search
4note field and a list. Before anything is typed the list offers up to six apps by Hop's own rule (fn swsuggest): the
5note ones you usually open from the app in front or around this hour (habits.json, through fn swlifts), the ones
6note you use most (recents.json), the ones that are running and the one you were just in, each with the reason. What is opened is remembered in those two files as Hop remembers it (fn urecordapp, fn urecent).
7note The apps are the names in /Applications and /System/Applications. Typing narrows the
8note list by Hop's own rules: the matcher (hopfuzz), the test for a web address (weba) and the order of the rows
9note (swrank) are the functions of Omega/hopcore.om, which Omega/gen-ui.sh puts between the two marker notes, so
10note the panel and the one box cannot drift apart. Typed text shows the eight best apps, a row that opens the text when
11note it is a web address, and up to twelve files and folders from Hop's file index (file-index.bin in Hop's folder,
12note which Hop builds: the panel reads it, lower-cases a copy and searches it by the rule of Hop's file search).
13note The Ask row sends the typed text to a model and shows the answer as it arrives, in place of the list: the
14note model is the default one of Hop's settings (config.json) when it is an HTTP one, else the
15note first such; the request is Hop's (POST base/chat/completions, the model, one user message, stream true) and
16note the answer's pieces are read from the server's "data:" lines. The session's delegate methods are Omega code
17note (callback entries 7 and 8), called on the main queue. A model whose key is a saved account is asked with that key. The first row is selected; the down and up arrows move the selection, Enter
18note opens the selected row. Like Hop it then stays: Enter and Escape hide the panel and give the app before it the
19note keyboard back, and a global key (Option Space; Hop itself has Command Space), a click on its Dock icon or opening it again brings it
20note back. It has a small menu (Quit, and Edit with cut, copy, paste, select all) and runs in AppKit's own event
21note loop. The global key is a Carbon hot key whose handler is callback entry 5.
22note The field's two delegate methods, the list's two data-source methods and the field's action are Omega code, reached
23note through the callback entries (libback; omega-mv seed/ng/a64/DESIGN.md s14).
24note With HOPCHECK set in the environment it checks itself instead: it stays in the background and, after half a
25note second, puts "sa" into its field through the field's own editor (so AppKit, not the program, tells the
26note delegate that the text changed), sends that editor arrow down, Enter and Escape as commands, prints
27note "hoppanel apps N shown H first NAME selected R enter APP" and ends after six seconds. Enter reaches the field's
28note action with the field as sender, as a real Enter does, but opens nothing. Status then: 1 when apps were found,
29note the typed text narrowed them, the first one was read back from the list's own data source, the arrow moved the
30note list's selection, Enter chose the selected app, Escape hid the panel, a hot key could be registered (a spare
31note one: Control Option Shift Command F19) and its handler showed the panel again; 2 to 9 name a failed step.
32note The line then ends " key K hid H back B" (K 0 when the key was registered).
33note With HOPCHECK=type:TEXT it types TEXT instead and sends Enter (no arrow), still opening nothing: status 1 when
34note Enter chose a row. With HOPCHECK=open:TEXT it does the same and does open the row: the line ends " opened 1"
35note when the workspace took it, and the status is 1 then. With HOPCHECK=ask:TEXT it types TEXT, sends Enter on the
36note Ask row (first for a question) and does ask the model: the line ends " answer TEXT" and the status is 1 when an
37note answer came. With HOPCHECK=idle it types nothing and sends Enter on the first offer; HOPFRONT=ID then stands for
38note the app in front. With HOPRECORD set as well, a check that opens nothing still remembers what Enter chose,
39note and puts a chosen copied thing on a board of its own (the line then ends " pasted " and what is on it).
40note A check reaches no other machine but through HOPSSH and HOPSCP, its stand-ins for ssh and scp (HOPSSH is
41note also what a check starts in place of ssh for a forwarded port), and HOPLATE sends Enter late, when
42note they have answered. With HOPCHECK=agent:TEXT a check sends TEXT to the agent of the settings and waits for it to end; with
43note HOPAGENTS it first says each agent's command as it would be run.
44note HOPASK2 is a second question a check asks in the same conversation once the first is answered; with
45note HOPASKNEW it starts a new chat first.
46note HOPSCREEN (clipboard or accounts) starts a check in that screen, and HOPCLIPDO (pin or delete) does that to
47note the selected copied thing before Enter. With HOPCLIPREC a check first records what is on its own board into the history, as the program that stays
48note does for the real clipboard. HOPCLIPKEY is the clipboard key for a check, in base64, or "tool:" and the name of a Keychain item of the
49note security tool to read it from (the repository's checks use an item of their own, made and deleted there). HOPROW is the row Enter is sent on.
50note Without HOPCHECK it runs until it is quit.
51text s_appkit "/System/Library/Frameworks/AppKit.framework/AppKit"
52text s_gc "objc_getClass"
53text s_sr "sel_registerName"
54text s_ms "objc_msgSend"
55text s_wr "write"
56text s_acp "objc_allocateClassPair"
57text s_cam "class_addMethod"
58text s_rcp "objc_registerClassPair"
59text s_strlen "strlen"
60text s_memcpy "memcpy"
61text s_getenv "getenv"
62text c_pool "NSAutoreleasePool"
63text c_app "NSApplication"
64text c_win "NSWindow"
65text c_str "NSString"
66text c_field "NSTextField"
67text c_scroll "NSScrollView"
68text c_table "NSTableView"
69text c_col "NSTableColumn"
70text c_fm "NSFileManager"
71text c_obj "NSObject"
72text c_date "NSDate"
73text c_mine "OmegaHopPanel"
74text c_url "NSURL"
75text c_ws "NSWorkspace"
76text m_alloc "alloc"
77text m_init "init"
78text m_shared "sharedApplication"
79text m_policy "setActivationPolicy:"
80text m_initwi "initWithContentRect:styleMask:backing:defer:"
81text m_utf "stringWithUTF8String:"
82text m_cstr "UTF8String"
83text m_title "setTitle:"
84text m_conten "contentView"
85text m_addsub "addSubview:"
86text m_initfr "initWithFrame:"
87text m_label "labelWithString:"
88text m_setfra "setFrame:"
89text m_placeh "setPlaceholderString:"
90text m_setdel "setDelegate:"
91text m_settar "setTarget:"
92text m_setact "setAction:"
93text m_initid "initWithIdentifier:"
94text m_setwid "setWidth:"
95text m_addcol "addTableColumn:"
96text m_header "setHeaderView:"
97text m_dataso "setDataSource:"
98text m_docvie "setDocumentView:"
99text m_scroll "setHasVerticalScroller:"
100text m_reload "reloadData"
101text m_strval "stringValue"
102text m_setstr "setStringValue:"
103text m_defaul "defaultManager"
104text m_conte1 "contentsOfDirectoryAtPath:error:"
105text m_count "count"
106text m_at "objectAtIndex:"
107text m_finish "finishLaunching"
108text m_front "orderFrontRegardless"
109text m_visibl "isVisible"
110text m_close "close"
111text m_since "dateWithTimeIntervalSinceNow:"
112text m_next "nextEventMatchingMask:untilDate:inMode:dequeue:"
113text m_send "sendEvent:"
114text m_change "controlTextDidChange:"
115text m_rows "numberOfRowsInTableView:"
116text m_value "tableView:objectValueForTableColumn:row:"
117text m_go "go:"
118text m_furl "fileURLWithPath:"
119text m_shws "sharedWorkspace"
120text m_open "openURL:"
121text m_activ "activateIgnoringOtherApps:"
122text m_key "makeKeyAndOrderFront:"
123text m_firstr "makeFirstResponder:"
124text m_down "moveDown:"
125text m_up "moveUp:"
126text m_cancel "cancelOperation:"
127text m_selrow "selectRowIndexes:byExtendingSelection:"
128text m_ixwith "indexSetWithIndex:"
129text m_scrrow "scrollRowToVisible:"
130text m_cmd "control:textView:doCommandBySelector:"
131text m_selrd "selectedRow"
132text c_ixset "NSIndexSet"
133text t_b "B@:@@:"
134text m_curred "currentEditor"
135text m_instxt "insertText:"
136text m_docmd "doCommandBySelector:"
137text m_newln "insertNewline:"
138text t_v "v@:@"
139text t_q "q@:@"
140text t_o "@@:@@q"
141text x_title "Hop (Omega)"
142text x_hint "Type to find an app"
143text x_dir1 "/Applications"
144text x_dir2 "/System/Applications"
145text x_mode "kCFRunLoopDefaultMode"
146text x_name "name"
147text x_typed "sa"
148text x_out1 "hoppanel apps "
149text x_out2 " shown "
150text x_out3 " first "
151text x_out4 " selected "
152text x_out5 " enter "
153text x_out6 " opened "
154text x_https "https://"
155text x_open "Open "
156text m_urlstr "URLWithString:"
157text m_host "host"
158text s_carbon "/System/Library/Frameworks/Carbon.framework/Carbon"
159text s_event_target "GetApplicationEventTarget"
160text s_install_handler "InstallEventHandler"
161text s_register_key "RegisterEventHotKey"
162text m_order_out "orderOut:"
163text m_hide_app "hide:"
164text m_released "setReleasedWhenClosed:"
165text m_set_app_delegate "setDelegate:"
166text m_reopen "applicationShouldHandleReopen:hasVisibleWindows:"
167text m_run "run"
168text m_terminate "terminate:"
169text m_set_menu "setMainMenu:"
170text m_add_item "addItem:"
171text m_set_submenu "setSubmenu:"
172text m_init_title "initWithTitle:"
173text m_init_item "initWithTitle:action:keyEquivalent:"
174text m_cut "cut:"
175text m_copy "copy:"
176text m_paste "paste:"
177text m_select_all "selectAll:"
178text c_menu "NSMenu"
179text c_menu_item "NSMenuItem"
180text t_reopen "B@:@B"
181text t_handler "i^v^v^v"
182text x_quit "Quit Hop Omega"
183text x_edit "Edit"
184text x_cut "Cut"
185text x_copy "Copy"
186text x_paste "Paste"
187text x_select_all "Select All"
188text x_key_q "q"
189text x_key_x "x"
190text x_key_c "c"
191text x_key_v "v"
192text x_key_a "a"
193text x_app "Hop Omega"
194text x_out7 " key "
195text x_out8 " hid "
196text x_out9 " back "
197text s_malloc "malloc"
198text s_memmem "memmem"
199text s_memchr "memchr"
200text s_memrchr "memrchr"
201text c_data "NSData"
202text m_data_file "dataWithContentsOfFile:"
203text m_retain "retain"
204text m_bytes "bytes"
205text m_length "length"
206text x_env_dir "HOP_CONFIG_DIR"
207text x_env_home "HOME"
208text x_support "/Library/Application Support/Hop"
209text x_index "/file-index.bin"
210text x_gap " - "
211text x_dotapp_low ".app"
212text x_dir1_low "/applications/"
213text x_dir2_low "/system/applications/"
214text x_config "/config.json"
215text c_json "NSJSONSerialization"
216text c_dict "NSDictionary"
217text c_array "NSArray"
218text c_number "NSNumber"
219text c_mutable_dict "NSMutableDictionary"
220text c_mutable_string "NSMutableString"
221text c_request "NSMutableURLRequest"
222text c_session "NSURLSession"
223text c_session_config "NSURLSessionConfiguration"
224text c_queue "NSOperationQueue"
225text c_text_view "NSTextView"
226text m_json_object "JSONObjectWithData:options:error:"
227text m_json_data "dataWithJSONObject:options:error:"
228text m_object_for_key "objectForKey:"
229text m_is_kind "isKindOfClass:"
230text m_equal_string "isEqualToString:"
231text m_has_suffix "hasSuffix:"
232text m_substring_to "substringToIndex:"
233text m_append_string "stringByAppendingString:"
234text m_append "appendString:"
235text m_set_string "setString:"
236text m_string "string"
237text m_dictionary "dictionary"
238text m_set_object "setObject:forKey:"
239text m_array_with "arrayWithObject:"
240text m_number_bool "numberWithBool:"
241text m_request_url "requestWithURL:"
242text m_set_method "setHTTPMethod:"
243text m_set_header "setValue:forHTTPHeaderField:"
244text m_set_body "setHTTPBody:"
245text m_set_timeout "setTimeoutInterval:"
246text m_ephemeral "ephemeralSessionConfiguration"
247text m_main_queue "mainQueue"
248text m_session_with "sessionWithConfiguration:delegate:delegateQueue:"
249text m_data_task "dataTaskWithRequest:"
250text m_resume "resume"
251text m_cancel_task "cancel"
252text m_data_bytes "dataWithBytes:length:"
253text m_set_editable "setEditable:"
254text m_set_hidden "setHidden:"
255text m_description "localizedDescription"
256text m_response "response"
257text m_status_code "statusCode"
258text m_did_data "URLSession:dataTask:didReceiveData:"
259text m_did_complete "URLSession:task:didCompleteWithError:"
260text t_session "v@:@@@"
261text k_models "models"
262text k_default "defaultModel"
263text k_name "name"
264text k_base "baseURL"
265text k_model "model"
266text k_kind "kind"
267text k_key "keychainKey"
268text k_messages "messages"
269text k_stream "stream"
270text k_role "role"
271text k_content "content"
272text k_choices "choices"
273text k_delta "delta"
274text k_message "message"
275text x_openai "openai"
276text x_user "user"
277text x_post "POST"
278text x_json_type "application/json"
279text x_content_type "Content-Type"
280text x_slash_text "/"
281text x_completions "/chat/completions"
282text x_ask "Ask "
283text x_colon ": "
284text x_ask_none "Ask: no model in Hop's settings that can be asked from here"
285text x_asking "Asking ..."
286text x_no_answer "[no answer]"
287text x_http "[HTTP "
288text x_busy "The model is busy right now. Try again in a moment. "
289text x_bracket "]"
290text x_out10 " answer "
291text s_pow "pow"
292text s_log2 "log2"
293text c_calendar "NSCalendar"
294text c_running_app "NSRunningApplication"
295text m_current_calendar "currentCalendar"
296text m_component "component:fromDate:"
297text m_date_now "date"
298text m_current_app "currentApplication"
299text m_frontmost "frontmostApplication"
300text m_running_apps "runningApplications"
301text m_policy_of "activationPolicy"
302text m_bundle_id "bundleIdentifier"
303text m_bundle_url "bundleURL"
304text m_path "path"
305text m_localized_name "localizedName"
306text m_integer_value "integerValue"
307text m_double_value "doubleValue"
308text m_number_integer "numberWithInteger:"
309text m_reference_now "timeIntervalSinceReferenceDate"
310text x_habits "/habits.json"
311text x_recents "/recents.json"
312text x_mac_key "Mac:"
313text x_env_front "HOPFRONT"
314text k_app "app"
315text k_from "from"
316text k_hour "hour"
317text k_count "count"
318text k_last "last"
319text x_why4 "You often open this from "
320text x_here "here"
321text x_why5 "You were just here"
322text x_why6 "You often open this around now"
323text x_why7 "One of your most used"
324text x_why8 "Running now"
325text s_chmod "chmod"
326text c_mutable_array "NSMutableArray"
327text m_array "array"
328text m_add_object "addObject:"
329text m_remove_range "removeObjectsInRange:"
330text m_remove_key "removeObjectForKey:"
331text m_all_keys "allKeys"
332text m_number_double "numberWithDouble:"
333text m_write_file "writeToFile:atomically:"
334text k_at_key "at"
335text k_path "path"
336text x_env_record "HOPRECORD"
337text s_memset "memset"
338text s_trusted "AXIsProcessTrusted"
339text s_key_event "CGEventCreateKeyboardEvent"
340text s_event_flags "CGEventSetFlags"
341text s_event_post "CGEventPost"
342text s_cf_release "CFRelease"
343text x_security "/usr/bin/security"
344text x_find "find-generic-password"
345text x_dash_s "-s"
346text x_clip_service "com.aienos.hop.clipboard"
347text x_dash_a "-a"
348text x_clip_account "storage-key-v2"
349text x_dash_w "-w"
350text x_clipboard_file "/clipboard.bin"
351text x_clip_images "/clip-images/"
352text x_env_clipkey "HOPCLIPKEY"
353text x_env_row "HOPROW"
354text x_env_vault "HOPVAULT"
355text x_env_cliprec "HOPCLIPREC"
356text x_real_ssh "/usr/bin/ssh"
357text x_nc "/usr/bin/nc"
358text x_nc_args "-z|-G|2|127.0.0.1"
359text m_probe_done "probeDone:"
360text m_all_keys_for "allKeysForObject:"
361text m_remove_for_key "removeObjectForKey:"
362text m_note_object "object"
363text m_is_equal_number "isEqualToNumber:"
364text s_cf_true "kCFBooleanTrue"
365text s_cf_false "kCFBooleanFalse"
366text x_out16 " links "
367text x_tunnel_args "-N|-o|ControlMaster=no|-o|ControlPath=none|-o|BatchMode=yes|-o|ExitOnForwardFailure=yes|-o|ServerAliveInterval=15|-o|ServerAliveCountMax=3|-o|ConnectTimeout=8|-L"
368text x_loopback "127.0.0.1:"
369text k_tunnels "tunnels"
370text k_local_port "localPort"
371text k_remote_port "remotePort"
372text k_ssh_host "sshHost"
373text k_cortex "cortex"
374text k_enabled "enabled"
375text k_url "url"
376text k_host "host"
377text m_url_port "port"
378text m_is_executable "isExecutableFileAtPath:"
379text m_all_values "allValues"
380text s_will_terminate "NSApplicationWillTerminateNotification"
381text m_app_quit "appQuit:"
382text x_env_menu "HOPMENU"
383text x_status_symbol "bolt.horizontal.circle"
384text x_status_open "Open Hop Omega (Option Space)"
385text x_status_index "Rebuild file index"
386text x_status_paste "Allow paste into apps ..."
387text x_status_login "Open at login"
388text x_status_settings "Settings (edit config file) ..."
389text x_status_clear "Clear clipboard history"
390text x_key_comma ","
391text x_menu_word "menu "
392text c_status_bar "NSStatusBar"
393text m_system_status_bar "systemStatusBar"
394text m_status_item_length "statusItemWithLength:"
395text m_button "button"
396text m_set_image "setImage:"
397text m_symbol_image "imageWithSystemSymbolName:accessibilityDescription:"
398text m_set_target "setTarget:"
399text m_set_state "setState:"
400text m_separator "separatorItem"
401text m_set_item_menu "setMenu:"
402text m_item_array "itemArray"
403text m_item_title "title"
404text m_menu_open "menuOpen:"
405text m_menu_index "menuIndex:"
406text m_menu_paste "menuPaste:"
407text m_menu_login "menuLogin:"
408text m_menu_settings "menuSettings:"
409text m_menu_clear "menuClear:"
410text s_trusted_options "AXIsProcessTrustedWithOptions"
411text s_trusted_prompt "kAXTrustedCheckOptionPrompt"
412text x_sm_path "/System/Library/Frameworks/ServiceManagement.framework/ServiceManagement"
413text c_sm_service "SMAppService"
414text m_main_app "mainAppService"
415text m_status "status"
416text m_register "registerAndReturnError:"
417text m_unregister "unregisterAndReturnError:"
418text x_login_failed "Couldn't change Open at login"
419text x_textedit "/System/Applications/TextEdit.app"
420text c_open_config "NSWorkspaceOpenConfiguration"
421text m_configuration "configuration"
422text m_open_urls_with "openURLs:withApplicationAtURL:configuration:completionHandler:"
423text x_empty_settings "{}"
424text x_env_ssh "HOPSSH"
425text x_env_scp "HOPSCP"
426text x_env_late "HOPLATE"
427text x_ssh_word "ssh"
428text x_scp_word "scp"
429text x_ssh_options " -o BatchMode=yes -o ConnectTimeout=8 "
430text x_scp_options " -q -o BatchMode=yes "
431text x_remote_a "d=~/.cache/hop/shards; [ -f $d/s00 ] || { echo HOP-NO-INDEX; exit 0; }; t=$(mktemp -d /dev/shm/hop.XXXXXX 2>/dev/null || mktemp -d); for s in $d/s*; do ( "
432text x_remote_grep "LC_ALL=C grep -F -i -- "
433text x_remote_shard " %%$s%%"
434text x_remote_pipe " | "
435text x_remote_b " | head -300 > %%$t/${s##*/}%% ) & done; wait; cat %%$t%%/*; rm -rf %%$t%%"
436text x_local_a "( "
437text x_local_b "; [ $? = 255 ] && echo HOP-UNREACHABLE ) 2>/dev/null | sed 's/^/"
438text x_local_c ":/' &"
439text x_wait_word "wait"
440text x_build_a "cd ~/.cache/hop && find "
441text x_build_b " -xdev ^^( -path '*/.*' -o "
442text x_build_c " ^^) -prune -o -type d -printf '%p/^^n' -o -printf '%p^^n' > index.tmp 2>/dev/null && rm -rf shards.new && mkdir shards.new && split -n l/20 -d -a 2 index.tmp shards.new/s && rm -f index.tmp index.txt && rm -rf shards.old && { [ ! -d shards ] || mv shards shards.old; } && mv shards.new shards && rm -rf shards.old; rm -f index.tmp; rmdir ~/.cache/hop/building"
443text x_name_flag "-name "
444text x_or_flag " -o "
445text x_fresh_a "mkdir -p ~/.cache/hop; f=~/.cache/hop/shards/s00"
446text x_fresh_b "if [ -d ~/.cache/hop/building ] && [ -n %%$(find ~/.cache/hop/building -maxdepth 0 -mmin +180 2>/dev/null)%% ]; then rmdir ~/.cache/hop/building; fi"
447text x_fresh_c "if [ ! -f $f ] || [ -n %%$(find $f -mmin +30 2>/dev/null)%% ]; then if mkdir ~/.cache/hop/building 2>/dev/null; then nohup nice -n 19 ionice -c3 sh -c "
448text x_fresh_d " >/dev/null 2>&1 & fi; fi"
449text x_fresh_e "echo ok"
450text x_percents "%%"
451text x_carets "^^"
452text x_fetch_a "sz=$("
453text x_fetch_stat "stat -c %s -- "
454text x_fetch_b ") && [ %%$sz%% -le 2000000000 ] && mkdir -p "
455text x_fetch_c " && "
456text x_fetch_d " && echo HOP-FETCHED"
457text x_fetched "HOP-FETCHED"
458text x_no_index "HOP-NO-INDEX"
459text x_unreachable "HOP-UNREACHABLE"
460text x_remote_cache "/Library/Caches/Hop/remote/"
461text x_check_cache "/remote/"
462text x_on " on "
463text x_note_unreachable " is unreachable right now"
464text x_note_building " is building its file list ..."
465text x_note_bringing "Bringing it over from "
466text x_note_copied "Copied the path on the clipboard: "
467text x_note_failed "Could not bring it over; its path is on the clipboard: "
468text x_out13 " fetched "
469text x_out14 " machine "
470text x_out15 " says "
471text k_roots_m "roots"
472text k_skip_m "skip"
473text m_remote_go "remoteGo:"
474text m_remote_done "remoteDone:"
475text m_fetch_done "fetchDone:"
476text m_read_to_end "readToEndOfFileInBackgroundAndNotify"
477text s_read_to_end_done "NSFileHandleReadToEndOfFileCompletionNotification"
478text m_cancel_previous "cancelPreviousPerformRequestsWithTarget:selector:object:"
479text m_dir_of "stringByDeletingLastPathComponent"
480text x_mskip0 ".git"
481text x_mskip1 "node_modules"
482text x_mskip2 "target"
483text x_mskip3 "__pycache__"
484text x_mskip4 "venv"
485text x_mskip5 ".venv"
486text x_mskip6 "site-packages"
487text x_mskip7 "build"
488text x_mskip8 "dist"
489text x_mskip9 "proc"
490text x_engine0 "Claude Code"
491text x_engine0_command "claude|-p|{prompt}|--output-format|stream-json|--verbose"
492text x_engine1 "Codex"
493text x_engine1_command "codex|exec|--skip-git-repo-check|{prompt}"
494text x_engine2 "Grok"
495text x_engine2_command "grok|-p|{prompt}"
496text x_engine3 "Gemini"
497text x_engine3_command "gemini|-p|{prompt}"
498text x_engine4 "OpenCode"
499text x_engine4_command "opencode|run|{prompt}"
500text x_engine5 "Cursor"
501text x_engine5_command "cursor-agent|-p|--output-format|text|{prompt}"
502text x_engine6 "Hermes"
503text x_engine6_command "hermes|-z|{prompt}"
504text x_old0_command "codex|exec|--skip-git-repo-check|--dangerously-bypass-approvals-and-sandbox|{prompt}"
505text x_old1_command "grok|--always-approve|-p|{prompt}"
506text x_old2_command "gemini|-y|-p|{prompt}"
507text x_old3_command "cursor-agent|-p|-f|--output-format|text|{prompt}"
508text x_old4_command "hermes|--yolo|-z|{prompt}"
509text x_path0 ".local/bin"
510text x_path1 ".claude/local"
511text x_path2 "/opt/homebrew/bin"
512text x_path3 "/usr/local/bin"
513text x_path4 ".bun/bin"
514text x_path5 ".npm-global/bin"
515text x_path6 ".cargo/bin"
516text x_path7 ".opencode/bin"
517text x_path8 ".volta/bin"
518text x_path9 ".asdf/shims"
519text x_path10 ".local/share/mise/shims"
520text x_path11 "bin"
521text x_custom_command "Custom command"
522text x_legacy_mark "HOP-LEGACY-COMMAND"
523text x_zsh "/bin/zsh"
524text x_dash_lc "-lc"
525text x_wrapper "[ -n ~$HOP_EXTRA_PATH~ ] && PATH=~$PATH:$HOP_EXTRA_PATH~; unset HOP_EXTRA_PATH; exec ~$@~"
526text x_tilde "~"
527text x_hop_word "hop"
528text x_sh "sh"
529text x_dash_c "-c"
530text x_probe_a "command -v "
531text x_probe_b " >/dev/null 2>&1 && echo "
532text x_true_word "true"
533text x_term "TERM"
534text x_dumb "dumb"
535text x_no_color "NO_COLOR"
536text x_one "1"
537text x_extra_path "HOP_EXTRA_PATH"
538text x_colon_only ":"
539text x_nvm "/.nvm/versions/node"
540text x_herd "/Library/Application Support/Herd/config/nvm/versions/node"
541text x_slash_bin "/bin"
542text x_prompt_mark "{prompt}"
543text x_claude "claude"
544text x_append_system "--append-system-prompt"
545text x_resume "--resume"
546text x_request "Request: "
547text x_the_user "the user"
548text x_brief_a "'s agent."
549text x_brief_b " All machines = one box; never ask which. Mac = here. "
550text x_brief_c " (auto-routed). Find files anywhere: hop find <words>."
551text x_brief_d " Factory: "
552text x_brief_e " Never delete agent files. Back up before destructive changes. Reply short, plain words."
553text x_ssh_a ": ssh "
554text x_ssh_b " '<cmd>'"
555text x_semi_space "; "
556text x_period "."
557text x_agent_row "Agent fixes it: "
558text x_brace "{"
559text x_bang "! "
560text x_tool_word "tool"
561text x_tool_mark "> "
562text x_agent_error "agent error"
563text x_agent_none_a "No coding agent was found on this Mac. Install one of these, sign in to it, then open Hop Omega again: "
564text x_agent_none_b "No coding agent was found on this Mac. Add an agent command to Hop's settings."
565text x_agent_missing_a " is set as your agent but is not installed on this Mac. Installed here: "
566text x_agent_missing_b ". Name one of them as agentEngine in Hop's settings. Nothing was run."
567text x_agent_stopped_a "Agent stopped (exit "
568text x_agent_stopped_b ")."
569text x_agent_working "The agent is working ..."
570text x_agent_busy "The agent is still working on the last request. Nothing new was run."
571text x_agent_ask "Let the agent work on this Mac?"
572text x_agent_ask_more "It can read and change files on this Mac, with the command of Hop's settings. Hop Omega asks this once each time it is started, until Hop itself has been told yes."
573text x_agent_yes "Run the agent"
574text x_agent_no "Cancel"
575text x_comma_space ", "
576text x_paren_a " ("
577text x_paren_b ")"
578text x_screen2 "Agent"
579text x_screen2_about "what the agent said"
580text x_word_agent "agent"
581text x_stop_item "Stop the Agent"
582text x_key_period "."
583text x_agent_menu "Agent"
584text c_alert "NSAlert"
585text m_set_message "setMessageText:"
586text m_set_informative "setInformativeText:"
587text m_add_button "addButtonWithTitle:"
588text m_run_modal "runModal"
589text c_center "NSNotificationCenter"
590text m_default_center "defaultCenter"
591text m_add_observer "addObserver:selector:name:object:"
592text m_remove_all_observer "removeObserver:name:object:"
593text s_read_done "NSFileHandleReadCompletionNotification"
594text s_data_item "NSFileHandleNotificationDataItem"
595text s_task_ended "NSTaskDidTerminateNotification"
596text m_read_background "readInBackgroundAndNotify"
597text m_user_info "userInfo"
598text m_set_cwd "setCurrentDirectoryPath:"
599text m_set_environment "setEnvironment:"
600text m_set_input "setStandardInput:"
601text m_environment "environment"
602text m_mutable_copy "mutableCopy"
603text m_terminate_task "terminate"
604text m_is_equal_array "isEqualToArray:"
605text m_range_of_data "rangeOfData:options:range:"
606text m_subdata "subdataWithRange:"
607text m_replace_bytes "replaceBytesInRange:withBytes:length:"
608text m_append_data "appendData:"
609text m_joined "componentsJoinedByString:"
610text m_uppercase "uppercaseString"
611text m_substring_from "substringFromIndex:"
612text m_contents_of_dir "contentsOfDirectoryAtPath:error:"
613text m_standard_compare "localizedStandardCompare:"
614text m_newline_set "newlineCharacterSet"
615text m_agent_out "agentOut:"
616text m_agent_err "agentErr:"
617text m_agent_end "agentEnd:"
618text m_agent_stop "stopAgent:"
619text k_engines "agentEngines"
620text k_engine "agentEngine"
621text k_agent_command "agentCommand"
622text k_agent_folder "agentWorkingDirectory"
623text k_enter_agent "enterSendsToAgent"
624text k_agent_confirmed "agentConfirmed"
625text k_keep_flags "keepAgentFlags"
626text k_command "command"
627text k_owner "ownerName"
628text k_machines "machines"
629text k_ssh "ssh"
630text k_factory_url "factoryURL"
631text k_type "type"
632text k_parts_text "text"
633text k_tool_use "tool_use"
634text k_result "result"
635text k_is_error "is_error"
636text k_session_id "session_id"
637text x_env_ask2 "HOPASK2"
638text x_env_agents "HOPAGENTS"
639text x_engine_word "engine "
640text x_env_asknew "HOPASKNEW"
641text m_array_adding "arrayByAddingObject:"
642text m_remove_last "removeLastObject"
643text x_assistant "assistant"
644text x_you "You: "
645text x_command3 "New chat"
646text x_word_new_chat "new chat"
647text x_word_clear_chat "clear chat"
648text s_free "free"
649text s_iopolicy "setiopolicy_np"
650text s_home_directory "NSHomeDirectory"
651text s_key_directory "NSURLIsDirectoryKey"
652text s_key_package "NSURLIsPackageKey"
653text s_key_link "NSURLIsSymbolicLinkKey"
654text s_modified "NSFileModificationDate"
655text c_process_info "NSProcessInfo"
656text m_process_info "processInfo"
657text m_arguments "arguments"
658text c_bundle "NSBundle"
659text m_main_bundle "mainBundle"
660text m_executable_path "executablePath"
661text m_drain "drain"
662text c_set "NSSet"
663text m_set_with_array "setWithArray:"
664text m_enumerator "enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:"
665text m_next_object "nextObject"
666text m_get_resource "getResourceValue:forKey:error:"
667text m_last_component "lastPathComponent"
668text m_skip_descendants "skipDescendants"
669text m_is_running "isRunning"
670text m_attributes_of "attributesOfItemAtPath:error:"
671text m_since_now "timeIntervalSinceNow"
672text k_roots "indexRoots"
673text k_skip_names "indexSkipNames"
674text x_index_word "index"
675text x_applications "/Applications"
676text x_system_applications "/System/Applications"
677text x_indexed "indexed "
678text x_items " items"
679text x_indexing " (indexing files ...)"
680text x_command2 "Rebuild file index"
681text x_word_rebuild "rebuild file index"
682text x_word_reindex "reindex"
683text x_word_index_files "index files"
684text x_skipname0 "Library"
685text x_skipname1 "node_modules"
686text x_skipname2 ".git"
687text x_skipname3 "target"
688text x_skipname4 "build"
689text x_skipname5 "dist"
690text x_skipname6 "DerivedData"
691text x_skipname7 "__pycache__"
692text x_skipname8 "venv"
693text x_skipname9 ".venv"
694text x_skipname10 ".cache"
695text x_skipname11 "Caches"
696text x_skipname12 ".Trash"
697text x_skipname13 "site-packages"
698text x_skipname14 ".build"
699text x_skipname15 "Pods"
700text x_word0 "clipboard"
701text x_word1 "copied"
702text x_word2 "clipboard history"
703text x_word3 "accounts"
704text x_word4 "keys"
705text x_word5 "api keys"
706text x_word6 "passwords"
707text x_word7 "logins"
708text x_word8 "settings"
709text x_word9 "preferences"
710text x_word10 "config"
711text x_word11 "hop settings"
712text x_word12 "quit hop"
713text x_screen0 "Clipboard"
714text x_screen0_about "your copied things"
715text x_screen1 "Accounts"
716text x_screen1_about "your saved keys and logins"
717text x_command0 "Settings"
718text x_command0_about "opens Hop's settings file"
719text x_command1 "Quit Hop Omega"
720text x_copied_things " copied things"
721text x_accounts_word " accounts"
722text x_pinned "pinned"
723text x_env_screen "HOPSCREEN"
724text x_env_clipdo "HOPCLIPDO"
725text x_clip_menu "Clipboard"
726text x_pin_item "Pin or Unpin"
727text x_delete_item "Delete from History"
728text x_key_p "p"
729text x_key_d "d"
730text m_pin_clip "pinClip:"
731text m_delete_clip "deleteClip:"
732text x_out12 " screen "
733text s_random "arc4random_buf"
734text c_uuid "NSUUID"
735text m_uuid "UUID"
736text m_uuid_string "UUIDString"
737text c_timer "NSTimer"
738text m_timer "scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:"
739text m_clip_tick "clipTick:"
740text m_change_count "changeCount"
741text m_types "types"
742text m_contains_object "containsObject:"
743text c_image "NSImage"
744text m_init_pasteboard "initWithPasteboard:"
745text m_tiff "TIFFRepresentation"
746text c_bitmap "NSBitmapImageRep"
747text m_rep_with_data "imageRepWithData:"
748text m_rep_using "representationUsingType:properties:"
749text m_running_with "runningApplicationsWithBundleIdentifier:"
750text x_hop_id "com.aienos.hop"
751text k_id "id"
752text k_source "sourceApp"
753text k_limit "clipboardLimit"
754text m_insert_at "insertObject:atIndex:"
755text m_remove_at "removeObjectAtIndex:"
756text m_byte_length "lengthOfBytesUsingEncoding:"
757text c_mutable_data "NSMutableData"
758text m_data "data"
759text m_append_bytes "appendBytes:length:"
760text c_file_manager "NSFileManager"
761text m_default_manager "defaultManager"
762text m_file_exists "fileExistsAtPath:"
763text m_remove_item "removeItemAtPath:error:"
764text m_create_dir "createDirectoryAtPath:withIntermediateDirectories:attributes:error:"
765text x_clip_backup "/clipboard.before-hop-omega.bin"
766text x_dot_bin ".bin"
767text x_skip0 "org.nspasteboard.ConcealedType"
768text x_skip1 "org.nspasteboard.TransientType"
769text x_skip2 "org.nspasteboard.AutoGeneratedType"
770text x_skip3 "com.agilebits.onepassword"
771text x_skip4 "com.typeit4me.clipping"
772text x_skip5 "de.petermaurer.TransientPasteboardType"
773text x_env_vault_add "HOPVAULTADD"
774text s_item_add "SecItemAdd"
775text s_item_delete "SecItemDelete"
776text s_interaction "SecKeychainSetUserInteractionAllowed"
777text s_value_data "kSecValueData"
778text s_accessible "kSecAttrAccessible"
779text s_accessible_unlocked "kSecAttrAccessibleWhenUnlockedThisDeviceOnly"
780text m_data_using "dataUsingEncoding:"
781text x_semicolon ";"
782text x_bar "|"
783text x_vault_service "com.aienos.hop.vault"
784text s_item_copy "SecItemCopyMatching"
785text s_class "kSecClass"
786text s_class_generic "kSecClassGenericPassword"
787text s_attr_service "kSecAttrService"
788text s_attr_account "kSecAttrAccount"
789text s_attr_description "kSecAttrDescription"
790text s_attr_comment "kSecAttrComment"
791text s_match_limit "kSecMatchLimit"
792text s_limit_all "kSecMatchLimitAll"
793text s_limit_one "kSecMatchLimitOne"
794text s_return_attributes "kSecReturnAttributes"
795text s_return_data "kSecReturnData"
796text s_true "kCFBooleanTrue"
797text m_sorted "sortedArrayUsingSelector:"
798text m_compare "compare:"
799text m_has_prefix "hasPrefix:"
800text m_declare_types "declareTypes:owner:"
801text x_type_concealed "org.nspasteboard.ConcealedType"
802text x_bearer "Bearer "
803text x_authorization "Authorization"
804text x_no_key "[The key of this model could not be read from the Keychain]"
805text x_check_board "com.aienos.hop.omega.check"
806text c_task "NSTask"
807text c_pipe "NSPipe"
808text c_file_handle "NSFileHandle"
809text c_pasteboard "NSPasteboard"
810text c_charset "NSCharacterSet"
811text m_set_launch "setLaunchPath:"
812text m_set_arguments "setArguments:"
813text m_pipe "pipe"
814text m_set_output "setStandardOutput:"
815text m_set_error "setStandardError:"
816text m_null_device "fileHandleWithNullDevice"
817text m_launch "launch"
818text m_reading "fileHandleForReading"
819text m_read_end "readDataToEndOfFile"
820text m_wait "waitUntilExit"
821text m_termination "terminationStatus"
822text m_init_data_encoding "initWithData:encoding:"
823text m_trim "stringByTrimmingCharactersInSet:"
824text m_whitespace "whitespaceAndNewlineCharacterSet"
825text m_init_base64 "initWithBase64EncodedString:options:"
826text m_general_pasteboard "generalPasteboard"
827text m_board_named "pasteboardWithName:"
828text m_clear "clearContents"
829text m_set_string_type "setString:forType:"
830text m_set_data_type "setData:forType:"
831text m_string_for_type "stringForType:"
832text m_data_for_type "dataForType:"
833text m_lowercase "lowercaseString"
834text m_contains "containsString:"
835text m_components "componentsSeparatedByString:"
836text m_replace "stringByReplacingOccurrencesOfString:withString:"
837text m_composed_at "rangeOfComposedCharacterSequenceAtIndex:"
838text m_bool_value "boolValue"
839text m_release "release"
840text m_perform_after "performSelector:withObject:afterDelay:"
841text m_paste_now "pasteNow:"
842text x_type_string "public.utf8-plain-text"
843text x_type_png "public.png"
844text k_text "text"
845text k_image "imageFile"
846text k_pinned "pinned"
847text k_date "date"
848text x_image "Image"
849text x_image_low "image"
850text x_space " "
851text x_paste_row "Paste: "
852text x_why1 "You just copied this"
853text x_why2 "The last thing you copied"
854text x_why3 "You copied a web address"
855text x_out11 " pasted "
856text x_png_word "png "
857text x_browser0 "com.apple.Safari"
858text x_browser1 "com.google.Chrome"
859text x_browser2 "com.brave.Browser"
860text x_browser3 "org.mozilla.firefox"
861text x_browser4 "company.thebrowser.Browser"
862text x_browser5 "com.microsoft.edgemac"
863text x_browser6 "com.operasoftware.Opera"
864text x_browser7 "com.vivaldi.Vivaldi"
865text x_browser8 "app.zen-browser.zen"
866text x_of " of "
867text x_apps " apps"
868text x_slash "/"
869text x_dotapp ".app"
870text x_env "HOPCHECK"
871
872note g_f: library functions. 0 objc_getClass 1 sel_registerName 2 objc_msgSend 3 write 4 objc_allocateClassPair
873note 5 class_addMethod 6 objc_registerClassPair 7 strlen 8 memcpy 9 getenv 10 malloc 11 memmem 12 memchr 13 memrchr
874note 14 pow 15 log2 16 chmod 17 memset 18 AXIsProcessTrusted 19 CGEventCreateKeyboardEvent 20 CGEventSetFlags
875note 21 CGEventPost 22 CFRelease 23 SecItemCopyMatching 24 SecItemAdd 25 SecItemDelete
876note 26 SecKeychainSetUserInteractionAllowed 27 arc4random_buf 28 free 29 setiopolicy_np 30 NSHomeDirectory
877global g_f ulong 32
878note g_o: objects and selectors the callbacks need. 0 field 1 table 2 status line 3 NSString 4 stringWithUTF8String:
879note 5 UTF8String 6 stringValue 7 reloadData 8 setStringValue: 9 moveDown: 10 moveUp: 11 cancelOperation:
880note 12 selectRowIndexes:byExtendingSelection: 13 NSIndexSet 14 indexSetWithIndex: 15 scrollRowToVisible:
881note 16 NSURL 17 URLWithString: 18 host 19 the window 20 orderOut: 21 the application 22 hide:
882note 23 activateIgnoringOtherApps: 24 makeKeyAndOrderFront: 25 makeFirstResponder: 26 orderFrontRegardless
883note 27 the object whose methods are the callbacks 28 the list's scroll view 29 the answer's scroll view
884note 30 the answer's text view
885global g_o ulong 32
886note g_n: 0 apps 1 shown 2 bytes of names 3 times the action ran 4 length of the typed text 5 1 to end the program
887note 6 the selected row 7 1 when Enter may open the row 8 the row Enter chose, plus 1 9 what the workspace answered
888note 10 the typed text as a web address (0 it is none, 1 written with its scheme, 2 a bare address) 12 where the
889note typed text starts once blanks are trimmed 13 its length then 14 1 when the program stays (no HOPCHECK)
890note 15 what registering the hot key gave (0 it is registered) 16 the words of the typed text 17 the files found
891note 18 1 when a file has exactly the typed text as its name 19 bytes of the answer waiting in g_net
892note 20 1 when an answer is on show 21 1 when the model's answer has ended 22 1 when a piece of it came
893note 23 1 when the check asks for what is chosen to be remembered without being opened 24 the count of copied
894note things 25 the bytes of the newest one's text when it may be a web address 26 its address kind 27 the count
895note of other copied things offered 28 the count of copied things that match the typed text 29 what the check
896note pasted (1 text, 2 a picture) 30 the row the check chooses before Enter (0: the first) 31 the count of
897note saved accounts 32 the place plus 1 of the app that was in front before the one in front now
898note 33 1 once the history was set aside before this run's first change to it 34 how many unpinned copied
899note things are kept 35 the clipboard's change count last seen 36 the screen the list shows (0 everything,
900note 1 the copied things, 2 the saved accounts) 37 what a check does to the selected copied thing (1 pin or
901note unpin, 2 delete) 38 half seconds since the file index was last looked at
902note 39 1 when the answer on show belongs to a turn that has ended 40 1 when that turn failed 41 1 when the
903note typed text reads as a question 42 1 when Hop's settings send a sentence to the agent on Enter 43 1 while
904note the agent runs 44 1 once the person said yes to the agent 45 1 once the agents on this Mac were looked
905note for 46 1 when a check sends what it types to the agent 47 what of the agent's run has ended (1 its
906note output, 2 the program) 48 the turn at which a check sends Enter 49 the count of files found on other
907note machines 50 the bytes of what the machines answered 51 what to say about a machine (1 unreachable, 2 building
908note its list, 3 a file is on its way, 4 a path was copied, 5 a file could not be brought) 52 which machine
909note 53 the bytes of the text the machines were asked for 54 the count of machines 55 1 when a check's file
910note arrived 56 the machine and 57 the found file that is on its way 58 1 when a file found on a machine has exactly the typed name
911note 59 1 when other machines may be reached 60 half seconds since the forwarded ports were last looked at
912note 61 how many links this program has started 62 how many forwarded ports the settings name
913global g_n ulong 64
914note g_t: the text HOPCHECK=open:TEXT asks to type
915global g_t uchar 64
916global g_rg uchar 128
917global g_nm uchar 1024
918global g_pool uchar 65536
919global g_off ulong 2048
920global g_ln ulong 2048
921global g_hit ulong 2048
922note g_hit: the app of each row; g_rk: the kind of each row (1 an app, 2 the web address); g_dir: the folder each
923note app is in (0 /Applications, 1 /System/Applications); g_mk and g_ms: the apps hopfuzz matched and their scores
924global g_rk uchar 2048
925global g_dir uchar 2048
926global g_mk ulong 2048
927global g_ms ulong 2048
928global g_q uchar 256
929note g_x: the first row's text, kept for the check's line
930global g_x uchar 256
931note g_ev: the hot key's event type (class 'keyb', kind 5 pressed) and, from byte 8, the reference Carbon gives back
932global g_ev uchar 16
933note The file index. g_fb: 0 where its bytes are (paths, a line each), 1 where the lower-case copy is, 2 how many
934note bytes, 3 1 when it is loaded, 4 the object that holds the bytes. g_chunk: a piece of it on its way to lower case. g_line: one path, lower case.
935note g_lq: the typed text, lower case; g_to and g_tl: where each of its words starts and how long it is.
936note g_fs, g_fo, g_fl: the best 40 files, best first: score plus 100000, where the path starts, how long it is
937global g_fb ulong 8
938note The model. g_m: 0 its id, 1 the address to post to, 2 its name (three NSStrings), 3 1 when there is one,
939note 4 the answer so far (an NSMutableString), 5 the session, 6 the running task, 7 NSDictionary, 8 NSArray,
940note 9 NSString (the classes, to tell what a JSON value is), 10 each app's path and its place (a dictionary),
941note 11 the id of the app in front when the panel was last shown, 12 its name, 13 its place among the apps plus 1,
942note 14 the copied things (an array, newest first), 15 the text each one is shown by, 16 objectAtIndex:,
943note 18 the names of the saved accounts in order, 19 what each is (its kind and note), 20 the Keychain service
944note they are under, 21 the name of the account that holds the model's key (nothing: it needs none), 22 the
945note accounts a check made for itself (an array of their names), to be deleted when it ends, 23 the program
946note that is building the file index now (nothing: none), 24 the conversation with the model (an array of
947note messages, each a role and a content), 25 what was said before the answer on show (a text), 26 the agent's
948note program while it runs, 27 where its output is read, 28 the agents of Hop's settings (each a name and a
949note command), 29 the name of the one to use, 30 the folder it works in, 31 the older single command, 32 its
950note output not yet a whole line, 33 the id of its last run (to carry on from), 34 the settings (for the
951note agent's standing instructions), 35 the agents found on this Mac, 36 when the agent last worked (a number
952note object), 37 where its errors are read, 38 to 41 the selectors agentOut: agentErr: agentEnd: stopAgent:,
953note 42 the ssh names of the machines (an array), 43 the program asking the machines, 44 where its answer is
954note read, 45 the program bringing a file over, 46 to 48 the selectors remoteGo: remoteDone: fetchDone:,
955note 49 where the fetch's answer is read, 50 where the file that is on its way lands (a path), 51 its
956note machine's ssh name and path, for the clipboard, 52 the icon in the menu bar, 53 its Open at login item,
957note 54 to 59 the selectors menuOpen: menuIndex: menuPaste: menuLogin: menuSettings: menuClear:,
958note 60 the forwarded ports to keep open (each: this Mac's port, the far port, the ssh name), 61 the programs
959note that hold them open (by this Mac's port), 62 the selector appQuit:, 63 the programs asking whether a port
960note is served (by the port), 64 the selector probeDone:.
961note g_net: bytes from the server not yet read as lines
962global g_m ulong 80
963global g_net uchar 262144
964note What is offered before anything is typed. g_so: the apps in the order of their paths; g_lf, g_lh: each app's
965note lift from the app in front and from the hour; g_us: how much it is used; g_rn: 1 when it is running;
966note g_fr: the apps that were in front when the panel was shown, newest first (place plus 1); g_why: why each
967note row is offered
968global g_so ulong 2048
969global g_lf ulong 2048
970global g_lh ulong 2048
971global g_us ulong 2048
972global g_rn uchar 2048
973global g_fr ulong 12
974global g_why uchar 2048
975note Copied things. g_ci: all of them in the order they are searched (the pinned ones first); g_cp: 1 for a
976note pinned one; g_cr: the others offered before anything is typed; g_cm: the ones that match the typed text;
977note g_ca: the newest one's text, kept while it may be a web address
978global g_ci ulong 1024
979global g_cp uchar 1024
980global g_cr ulong 20
981global g_cm ulong 1024
982global g_ca uchar 256
983note eight bytes a library function writes a pointer into
984global g_t8 uchar 8
985note Files on other machines. g_rb: what the machines answered (lines "K:path", K the machine's number); g_rq:
986note the text they were asked for; g_ro, g_rl, g_rs, g_rw: the best 64 found, best first (where the path starts in
987note g_rb, its length, its score plus 100000, its machine); g_mn and g_ml: the machines' names
988global g_rb uchar 1048576
989global g_rq uchar 256
990global g_ro ulong 64
991global g_rl ulong 64
992global g_rs ulong 64
993global g_rw uchar 64
994global g_mn uchar 640
995global g_ml uchar 10
996note the byte that ends a line of the file index
997global g_nl uchar 1
998global g_chunk uchar 524288
999global g_line uchar 4096
1000global g_lq uchar 256
1001global g_to ulong 16
1002global g_tl ulong 16
1003global g_fs ulong 64
1004global g_fo ulong 64
1005global g_fl ulong 64
1006
1007note ---- the core of Hop, from Omega/hopcore.om ----
1008fn isword w ulong to bool
1009ret ne and w 4294967296 0
1010end
1011
1012fn istrim w ulong to bool
1013ret ne and w 8589934592 0
1014end
1015
1016fn minu a ulong b ulong to ulong
1017if lt a b
1018ret a
1019end
1020ret b
1021end
1022
1023note true when inp[a .. a+n) equals inp[b .. b+n); both runs must lie inside the buffer
1024fn same inp view ulong 256 a ulong b ulong n ulong to bool
1025for k ulong n
1026if ne get inp add a k get inp add b k
1027ret false
1028end
1029end
1030ret true
1031end
1032
1033note x is one longer than y (ls characters): true when dropping one character of x gives y
1034fn skip1 inp view ulong 256 x ulong y ulong ls ulong to bool
1035k = ulong 0
1036while lt k ls bound 256
1037if ne get inp add x k get inp add y k
1038break
1039end
1040k = add k 1
1041end
1042ret same inp add x add k 1 add y k sub ls k
1043end
1044
1045note edit distance at most 1, where swapping two neighbours counts as one
1046fn near inp view ulong 256 a ulong la ulong b ulong lb ulong to bool
1047if eq la lb
1048d = ulong 0
1049p = ulong 0
1050for k ulong la
1051if ne get inp add a k get inp add b k
1052if eq d 0
1053p = k
1054end
1055d = add d 1
1056end
1057end
1058if le d 1
1059ret true
1060end
1061if eq d 2
1062if lt add p 1 la
1063if eq get inp add a p get inp add b add p 1
1064if eq get inp add a add p 1 get inp add b p
1065ret true
1066end
1067end
1068end
1069end
1070ret false
1071end
1072if eq la add lb 1
1073ret skip1 inp a b lb
1074end
1075if eq lb add la 1
1076ret skip1 inp b a la
1077end
1078ret false
1079end
1080
1081note score of q = inp[qa .. qa+ql) in the name inp[72 .. 72+nl); 0 means no match. ql and nl >= 1
1082fn one inp view ulong 256 qa ulong ql ulong nl ulong to ulong
1083if le ql nl
1084if same inp qa 72 ql
1085if eq ql nl
1086ret 200
1087end
1088ret sub 160 minu 30 sub nl ql
1089end
1090end
1091qw = true
1092for k ulong ql
1093if not isword get inp add qa k
1094qw = false
1095end
1096end
1097wc = ulong 0
1098later = false
1099inits = true
1100inw = false
1101for i ulong nl
1102c = get inp add 72 i
1103if isword c
1104if not inw
1105if lt wc ql
1106if ne c get inp add qa wc
1107inits = false
1108end
1109end
1110if gt wc 0
1111if qw
1112if le add i ql nl
1113if same inp qa add 72 i ql
1114later = true
1115end
1116end
1117end
1118end
1119wc = add wc 1
1120end
1121inw = true
1122else
1123inw = false
1124end
1125end
1126if later
1127ret sub 120 minu 20 div nl 3
1128end
1129if ge ql 2
1130if gt wc 1
1131if ge wc ql
1132if inits
1133ret 110
1134end
1135end
1136end
1137end
1138if le ql nl
1139for i ulong add sub nl ql 1
1140if same inp qa add 72 i ql
1141ret sub 80 minu 20 div nl 3
1142end
1143end
1144end
1145if ge ql 4
1146if le ql nl
1147if near inp qa ql 72 ql
1148ret 70
1149end
1150end
1151if le sub ql 1 nl
1152if near inp qa ql 72 sub ql 1
1153ret 70
1154end
1155end
1156if le add ql 1 nl
1157if near inp qa ql 72 add ql 1
1158ret 70
1159end
1160end
1161end
1162if lt ql 3
1163ret 0
1164end
1165qi = ulong 0
1166gaps = ulong 0
1167last = ulong 0
1168first = ulong 0
1169for i ulong nl
1170if lt qi ql
1171if eq get inp add 72 i get inp add qa qi
1172if gt qi 0
1173gaps = add gaps sub sub i last 1
1174else
1175first = i
1176end
1177last = i
1178qi = add qi 1
1179end
1180end
1181end
1182if ne qi ql
1183ret 0
1184end
1185if gt gaps ql
1186ret 0
1187end
1188t = add mul gaps 6 mul first 3
1189if ge t 45
1190ret 15
1191end
1192ret sub 60 t
1193end
1194
1195note first faulting word plus 1, or 0 when the input is well formed
1196fn check inp view ulong 256 to ulong
1197if ne get inp 0 1212568922
1198ret 1
1199end
1200if ne get inp 1 1
1201ret 2
1202end
1203ql = get inp 2
1204nl = get inp 3
1205if gt ql 64
1206ret 3
1207end
1208if gt nl 184
1209ret 4
1210end
1211for i ulong 4
1212if ne get inp add 4 i 0
1213ret add 5 i
1214end
1215end
1216for i ulong 64
1217w = get inp add 8 i
1218if lt i ql
1219if ge w 17179869184
1220ret add 9 i
1221end
1222if eq and w 4294967295 0
1223ret add 9 i
1224end
1225else
1226if ne w 0
1227ret add 9 i
1228end
1229end
1230end
1231for i ulong 184
1232w = get inp add 72 i
1233if lt i nl
1234if ge w 17179869184
1235ret add 73 i
1236end
1237if eq and w 4294967295 0
1238ret add 73 i
1239end
1240else
1241if ne w 0
1242ret add 73 i
1243end
1244end
1245end
1246ret 0
1247end
1248
1249fn hopfuzz inp view ulong 256 res edit ulong 256 to ulong
1250for i ulong 256
1251put res i 0
1252end
1253put res 0 1212568922
1254put res 1 1
1255e = check inp
1256if ne e 0
1257put res 2 2
1258put res 4 sub e 1
1259ret 2
1260end
1261nl = get inp 3
1262qa = ulong 8
1263qe = add 8 get inp 2
1264while lt qa qe bound 256
1265if not istrim get inp qa
1266break
1267end
1268qa = add qa 1
1269end
1270while gt qe qa bound 256
1271if not istrim get inp sub qe 1
1272break
1273end
1274qe = sub qe 1
1275end
1276ql = sub qe qa
1277if eq ql 0
1278ret 0
1279end
1280if eq nl 0
1281ret 0
1282end
1283s = one inp qa ql nl
1284if eq s 0
1285terms = ulong 0
1286sum = ulong 0
1287p = qa
1288while lt p qe bound 256
1289if eq and get inp p 4294967295 32
1290p = add p 1
1291continue
1292end
1293b = p
1294while lt p qe bound 256
1295if eq and get inp p 4294967295 32
1296break
1297end
1298p = add p 1
1299end
1300ts = one inp b sub p b nl
1301if eq ts 0
1302ret 0
1303end
1304terms = add terms 1
1305sum = add sum ts
1306end
1307if le terms 1
1308ret 0
1309end
1310s = sub div sum terms 10
1311end
1312put res 2 1
1313put res 3 s
1314ret 1
1315end
1316
1317note ---- file-name scoring (kind 2): how well a path found on another machine matches the typed terms ----
1318note The host sends bytes: the terms, and for each path its lowercased bytes, the lowercased bytes of its last
1319note component (its name), and the byte length of the path as written. A term found in the name scores 60 when the name
1320note starts with it and 30 otherwise; found only elsewhere in the path it scores 5; a term found nowhere, or an
1321note empty term, means no match. One point less for every 20 bytes of path; 40 more when the name is exactly as long as the terms.
1322
1323fn rd16 b view uchar 1048576 o ulong to ulong
1324ret or ulong get b o shl ulong get b add o 1 8
1325end
1326
1327fn rd32 b view uchar 1048576 o ulong to ulong
1328ret or rd16 b o shl rd16 b add o 2 16
1329end
1330
1331note true when b[x .. x+n) equals b[y .. y+n)
1332fn beq b view uchar 1048576 x ulong y ulong n ulong to bool
1333for k ulong n
1334if ne get b add x k get b add y k
1335ret false
1336end
1337end
1338ret true
1339end
1340
1341note true when the run b[t .. t+tl) occurs in b[h .. h+hl)
1342fn bhas b view uchar 1048576 h ulong hl ulong t ulong tl ulong to bool
1343if gt tl hl
1344ret false
1345end
1346for i ulong add sub hl tl 1
1347if beq b add h i t tl
1348ret true
1349end
1350end
1351ret false
1352end
1353
1354note score of one path plus 1000000, or 0 for no match. pm: 0 the number of terms, 1 where the path's bytes
1355note start, 2 how many, 3 where its name's bytes start, 4 how many, 5 the path's length as written
1356fn fscore b view uchar 1048576 toff view ulong 64 tlen view ulong 64 pm view ulong 8 to ulong
1357nt = get pm 0
1358p = get pm 1
1359pl = get pm 2
1360ns = get pm 3
1361nl = get pm 4
1362ol = get pm 5
1363s = ulong 1000000
1364sum = ulong 0
1365for k ulong nt
1366t = get toff k
1367tl = get tlen k
1368sum = add sum tl
1369if eq tl 0
1370ret 0
1371end
1372if bhas b ns nl t tl
1373if beq b ns t tl
1374s = add s 60
1375else
1376s = add s 30
1377end
1378else
1379if bhas b p pl t tl
1380s = add s 5
1381else
1382ret 0
1383end
1384end
1385end
1386s = sub s div ol 20
1387if eq nl sum
1388s = add s 40
1389end
1390ret s
1391end
1392
1393note ---- text decisions (kind 3): is it a question, which words to search for, is it a web address ----
1394note The host lowercases the text and sends one 8-byte word per character: bits 0..31 an id (equal characters get
1395note equal ids; a character of one Unicode scalar has that scalar's number), then a flag byte: 1 letter or number,
1396note 2 trimmable white space, 4 white space, 8 white space or line end.
1397note lists: three lists of plain words, separated by "|": 0 the words a question starts with, 1 the words a search
1398note leaves out, 2 the endings of a bare web address.
1399text lists "what what's whats why how how's who who's whom whose when where which explain define translate summarize summarise describe|the and for with that this what when where does did how why can you are was were have has from into about please make need want just our my its not|com org net io dev ai co edu gov xyz me us uk ca de tv gg"
1400
1401fn cid b view uchar 1048576 i ulong to ulong
1402ret rd32 b add 16 mul i 8
1403end
1404
1405fn cfl b view uchar 1048576 i ulong to ulong
1406ret ulong get b add 20 mul i 8
1407end
1408
1409note true when the n characters from s are exactly one word of list sec
1410fn inlist b view uchar 1048576 s ulong n ulong sec ulong to bool
1411cur = ulong 0
1412p = ulong 0
1413ln = len lists
1414while lt p ln bound 999999
1415e = p
1416while lt e ln bound 999999
1417c = ulong get lists e
1418if or eq c 32 eq c 124
1419break
1420end
1421e = add e 1
1422end
1423if eq cur sec
1424if eq sub e p n
1425ok = true
1426for k ulong n
1427if ne cid b add s k ulong get lists add p k
1428ok = false
1429end
1430end
1431if ok
1432ret true
1433end
1434end
1435end
1436if lt e ln
1437if eq ulong get lists e 124
1438cur = add cur 1
1439end
1440end
1441p = add e 1
1442end
1443ret false
1444end
1445
1446note op 1: 1 when the text reads as a question: it ends with "?" and is longer than that, or it has three words
1447note or more and starts with a question word
1448fn qlike b view uchar 1048576 n ulong to ulong
1449a = ulong 0
1450e = n
1451while lt a e bound 999999
1452if eq and cfl b a 8 0
1453break
1454end
1455a = add a 1
1456end
1457while gt e a bound 999999
1458if eq and cfl b sub e 1 8 0
1459break
1460end
1461e = sub e 1
1462end
1463if gt sub e a 1
1464if eq cid b sub e 1 63
1465ret 1
1466end
1467end
1468w = ulong 0
1469fs = ulong 0
1470fl = ulong 0
1471i = a
1472while lt i e bound 999999
1473if ne and cfl b i 4 0
1474i = add i 1
1475continue
1476end
1477st = i
1478while lt i e bound 999999
1479if ne and cfl b i 4 0
1480break
1481end
1482i = add i 1
1483end
1484if eq w 0
1485fs = st
1486fl = sub i st
1487end
1488w = add w 1
1489end
1490if lt w 3
1491ret 0
1492end
1493if inlist b fs fl 0
1494ret 1
1495end
1496ret 0
1497end
1498
1499note a character of a search word: a letter, a number, "-", "_" or "."
1500fn iswc b view uchar 1048576 i ulong to bool
1501if ne and cfl b i 1 0
1502ret true
1503end
1504c = cid b i
1505if eq c 45
1506ret true
1507end
1508if eq c 95
1509ret true
1510end
1511ret eq c 46
1512end
1513
1514fn samec b view uchar 1048576 x ulong y ulong n ulong to bool
1515for k ulong n
1516if ne cid b add x k cid b add y k
1517ret false
1518end
1519end
1520ret true
1521end
1522
1523note true when the word of wl characters at st also stands earlier in the text
1524fn seen b view uchar 1048576 st ulong wl ulong to bool
1525i = ulong 0
1526while lt i st bound 999999
1527if not iswc b i
1528i = add i 1
1529continue
1530end
1531s0 = i
1532while lt i st bound 999999
1533if not iswc b i
1534break
1535end
1536i = add i 1
1537end
1538if eq sub i s0 wl
1539if samec b s0 st wl
1540ret true
1541end
1542end
1543end
1544ret false
1545end
1546
1547note op 2: the words to search for: three characters or more, not a left-out word, each once, the longest four,
1548note longest first and in the order typed among equals. Writes the count, then where each starts and its length
1549fn keyw b view uchar 1048576 n ulong ob edit uchar 65544 to ulong
1550ts = new ulong 4 0
1551tl = new ulong 4 0
1552k = ulong 0
1553i = ulong 0
1554while lt i n bound 999999
1555if not iswc b i
1556i = add i 1
1557continue
1558end
1559st = i
1560while lt i n bound 999999
1561if not iswc b i
1562break
1563end
1564i = add i 1
1565end
1566wl = sub i st
1567if lt wl 3
1568continue
1569end
1570if inlist b st wl 1
1571continue
1572end
1573if seen b st wl
1574continue
1575end
1576pos = k
1577for j ulong k
1578if lt get tl j wl
1579if eq pos k
1580pos = j
1581end
1582end
1583end
1584if lt pos 4
1585for d ulong sub 3 pos
1586u = sub 3 d
1587put tl u get tl sub u 1
1588put ts u get ts sub u 1
1589end
1590put tl pos wl
1591put ts pos st
1592if lt k 4
1593k = add k 1
1594end
1595end
1596end
1597put ob 8 uchar k
1598for j ulong k
1599s = get ts j
1600l = get tl j
1601put ob add 9 mul j 4 uchar and s 255
1602put ob add 10 mul j 4 uchar shr s 8
1603put ob add 11 mul j 4 uchar and l 255
1604put ob add 12 mul j 4 uchar shr l 8
1605end
1606ret add 1 mul k 4
1607end
1608
1609fn hasscheme b view uchar 1048576 n ulong to bool
1610if lt n 7
1611ret false
1612end
1613if ne cid b 0 104
1614ret false
1615end
1616if ne cid b 1 116
1617ret false
1618end
1619if ne cid b 2 116
1620ret false
1621end
1622if ne cid b 3 112
1623ret false
1624end
1625o = ulong 4
1626if eq cid b 4 115
1627o = ulong 5
1628end
1629if lt n add o 3
1630ret false
1631end
1632if ne cid b o 58
1633ret false
1634end
1635if ne cid b add o 1 47
1636ret false
1637end
1638ret eq cid b add o 2 47
1639end
1640
1641note op 3: 0 not a web address; 1 it starts with http:// or https:// (the host then checks that it names a
1642note machine); 2 a bare address such as example.com/page (the host then checks that it parses). aux: the text's
1643note length in bytes as written
1644fn weba b view uchar 1048576 n ulong aux ulong to ulong
1645if eq n 0
1646ret 0
1647end
1648if ge aux 2000
1649ret 0
1650end
1651for i ulong n
1652if ne and cfl b i 4 0
1653ret 0
1654end
1655end
1656if hasscheme b n
1657ret 1
1658end
1659h0 = ulong 0
1660while lt h0 n bound 999999
1661if ne cid b h0 47
1662break
1663end
1664h0 = add h0 1
1665end
1666h1 = h0
1667while lt h1 n bound 999999
1668if eq cid b h1 47
1669break
1670end
1671h1 = add h1 1
1672end
1673parts = ulong 0
1674ps = h0
1675i = h0
1676while le i h1 bound 999999
1677atend = eq i h1
1678dot = false
1679if not atend
1680dot = eq cid b i 46
1681end
1682if or atend dot
1683if eq i ps
1684ret 0
1685end
1686parts = add parts 1
1687if atend
1688if lt parts 2
1689ret 0
1690end
1691if inlist b ps sub i ps 2
1692ret 2
1693end
1694ret 0
1695end
1696ps = add i 1
1697else
1698if eq and cfl b i 1 0
1699if ne cid b i 45
1700ret 0
1701end
1702end
1703end
1704i = add i 1
1705end
1706ret 0
1707end
1708
1709note the single-character edits that turn one spelling into another, on letters and numbers only. r: 0 and 1 the
1710note first spelling's characters [from, to), 2 and 3 the second's. Writes 4 the edits and 5 the longer length.
1711note Returns 1, and writes nothing, when a spelling has more than 4096 letters and numbers
1712fn edist b view uchar 1048576 r edit ulong 8 to ulong
1713xa = new ulong 4096 0
1714ya = new ulong 4096 0
1715row = new ulong 4097 0
1716xc = ulong 0
1717yc = ulong 0
1718i = get r 0
1719x1 = get r 1
1720while lt i x1 bound 999999
1721if ne and cfl b i 1 0
1722if ge xc 4096
1723ret 1
1724end
1725put xa xc cid b i
1726xc = add xc 1
1727end
1728i = add i 1
1729end
1730i = get r 2
1731y1 = get r 3
1732while lt i y1 bound 999999
1733if ne and cfl b i 1 0
1734if ge yc 4096
1735ret 1
1736end
1737put ya yc cid b i
1738yc = add yc 1
1739end
1740i = add i 1
1741end
1742for j ulong add yc 1
1743put row j j
1744end
1745for k ulong xc
1746prev = get row 0
1747put row 0 add k 1
1748xi = get xa k
1749for j ulong yc
1750cur = get row add j 1
1751v = add cur 1
1752w = add get row j 1
1753if lt w v
1754v = w
1755end
1756w = prev
1757if ne xi get ya j
1758w = add prev 1
1759end
1760if lt w v
1761v = w
1762end
1763put row add j 1 v
1764prev = cur
1765end
1766end
1767m = xc
1768if gt yc m
1769m = yc
1770end
1771put r 4 get row yc
1772put r 5 m
1773ret 0
1774end
1775
1776note op 4: how alike two spellings are. The text is the first spelling (aux characters), then the second. Writes
1777note the edits and the longer length, each as a 16-bit number; the host divides
1778fn alike b view uchar 1048576 n ulong aux ulong ob edit uchar 65544 to ulong
1779r = new ulong 8 0
1780bad = ulong 18446744073709551615
1781if gt aux n
1782ret bad
1783end
1784put r 0 0
1785put r 1 aux
1786put r 2 aux
1787put r 3 n
1788if ne edist b r 0
1789ret bad
1790end
1791d = get r 4
1792m = get r 5
1793put ob 8 uchar and d 255
1794put ob 9 uchar shr d 8
1795put ob 10 uchar and m 255
1796put ob 11 uchar shr m 8
1797ret 4
1798end
1799
1800note op 5: which run of typed words is the fix for what was heard. The text is what was heard (aux characters),
1801note then up to four runs: the first typed word, the first two, the first three, the first four; flag 16 marks the
1802note last character of each run. Each run is compared with what was heard (fn edist); the most alike wins, the
1803note shorter run among equals. Returns which run (1 to 4), or 0 for no fix: the winner is less than half alike, or
1804note is the very text that was heard (the host says which runs are: bit k-1 of sm). 255: a spelling is too long
1805fn pick b view uchar 1048576 n ulong aux ulong sm ulong to ulong
1806r = new ulong 8 0
1807if gt aux n
1808ret 255
1809end
1810bk = ulong 0
1811bn = ulong 0
1812bd = ulong 1
1813k = ulong 0
1814i = aux
1815while lt i n bound 999999
1816e = i
1817while lt e n bound 999999
1818f = cfl b e
1819e = add e 1
1820if ne and f 16 0
1821break
1822end
1823end
1824k = add k 1
1825if gt k 4
1826break
1827end
1828put r 0 0
1829put r 1 aux
1830put r 2 i
1831put r 3 e
1832if ne edist b r 0
1833ret 255
1834end
1835m = get r 5
1836nu = ulong 1
1837de = ulong 1
1838if gt m 0
1839nu = sub m get r 4
1840de = m
1841end
1842if eq bk 0
1843bk = k
1844bn = nu
1845bd = de
1846else
1847if gt mul nu bd mul bn de
1848bk = k
1849bn = nu
1850bd = de
1851end
1852end
1853i = e
1854end
1855if eq bk 0
1856ret 0
1857end
1858if lt mul bn 2 bd
1859ret 0
1860end
1861if ne and shr sm sub bk 1 1 0
1862ret 0
1863end
1864ret bk
1865end
1866
1867note kind 3: op, the number of characters n (at most 16384), aux and 0 as four 32-bit numbers, then n character
1868note words. Returns the reply length, or 18446744073709551615 for a malformed body or an unknown op
1869fn texts ib view uchar 1048576 nb ulong ob edit uchar 65544 to ulong
1870bad = ulong 18446744073709551615
1871if lt nb 16
1872ret bad
1873end
1874op = rd32 ib 0
1875n = rd32 ib 4
1876aux = rd32 ib 8
1877if gt n 16384
1878ret bad
1879end
1880if ne nb add 16 mul n 8
1881ret bad
1882end
1883if eq op 1
1884put ob 8 uchar qlike ib n
1885ret 1
1886end
1887if eq op 2
1888ret keyw ib n ob
1889end
1890if eq op 3
1891put ob 8 uchar weba ib n aux
1892ret 1
1893end
1894if eq op 4
1895ret alike ib n aux ob
1896end
1897if eq op 5
1898put ob 8 uchar pick ib n aux rd32 ib 12
1899ret 1
1900end
1901ret bad
1902end
1903
1904note ---- the helper process ----
1905note hopcore main: Hop's core as a helper process. A request is 8 bytes (kind, then body length n, both 32-bit
1906note little-endian) and n body bytes, n at most 1048576. The reply is 8 bytes (status, then length m) and m bytes.
1907note Status 0 is an answer; 1 an unknown kind; 2 a malformed body. End of input ends it with status 0; a body
1908note over the limit or a short read ends it with status 3 (the host starts a fresh one).
1909note Kind 1, names: the body is k cases of 2048 bytes (256 words, the hopfuzz input); 3 bytes back per case:
1910note verdict, score low byte, score high byte. At most 512 cases.
1911note Kind 2, paths: 16-bit little-endian fields: number of terms (at most 64), number of paths (at most 16000);
1912note each term as length then bytes; each path as three lengths (its lowercased bytes, its name's lowercased
1913note bytes, the path as written), then the path bytes, then the name bytes. 4 bytes back per path: 0 for no
1914note match, else the score plus 1000000.
1915note Kind 3, text: see fn texts. Op 1 and op 3 answer one byte; op 2 a count, then two 16-bit numbers a word;
1916note op 4 two 16-bit numbers; op 5 one byte.
1917note Kind 4, corrected words: see fn wdiff. Kind 5, a board line or a time: see fn board. Kind 6, a whole board: see fn asm. Kind 7, the members' state and the graph: see fn status.
1918
1919note fill b[0 .. n) from stdin; false at end of input or on a short read
1920fn rdn b edit uchar 1048576 n ulong to bool
1921got = ulong 0
1922while lt got n bound 999999
1923k = read 0 b got sub n got
1924if le k 0
1925ret false
1926end
1927got = add got ulong k
1928end
1929ret true
1930end
1931
1932fn wrn b view uchar 65544 n ulong to bool
1933p = ulong 0
1934while lt p n bound 999999
1935k = write 1 b p sub n p
1936if le k 0
1937ret false
1938end
1939p = add p ulong k
1940end
1941ret true
1942end
1943
1944fn put32 b edit uchar 65544 o ulong v ulong to void
1945put b o uchar and v 255
1946put b add o 1 uchar and shr v 8 255
1947put b add o 2 uchar and shr v 16 255
1948put b add o 3 uchar and shr v 24 255
1949end
1950
1951note kind 1: returns the reply length, or 18446744073709551615 for a malformed body
1952note ---- one line of a plain-text board (kind 5) ----
1953note A swarm's board is a text file, one post a line:
1954note <time> <sender> (<detail>) to <recipient> + <recipient> (<detail>): <text>
1955note Also read: several senders joined by " + ", no "to" part, recipients written "@name", a leading "- ", and
1956note words between the sender's bracket and the colon (they stay in the text). A line that does not start with a
1957note time is not a post. A header that does not fit the form is read plainly: the first word is the sender, the
1958note rest is the text. The answer names every part by where it starts in the line and how long it is.
1959note Limits: 65536 bytes of line, 600 of header, 4 senders, 16 recipients, 64 bytes and 3 words a name, 32768 bytes
1960note of text; over a limit the part is cut at a whole character and the answer says so.
1961
1962note byte i of the line (the line follows the 8-byte op header of the request)
1963fn lc b view uchar 1048576 i ulong to ulong
1964ret ulong get b add 8 i
1965end
1966
1967fn lsp c ulong to bool
1968ret or eq c 32 eq c 9
1969end
1970
1971note the two digits at byte i of the n-byte line as a number, or 100
1972fn l2d b view uchar 1048576 i ulong n ulong to ulong
1973if ge add i 1 n
1974ret 100
1975end
1976x = lc b i
1977y = lc b add i 1
1978if or lt x 48 gt x 57
1979ret 100
1980end
1981if or lt y 48 gt y 57
1982ret 100
1983end
1984ret add mul sub x 48 10 sub y 48
1985end
1986
1987note out[k], out[k+1]: the bytes lo..hi without spaces at either end (equal when nothing is left)
1988fn ltrim b view uchar 1048576 lo ulong hi ulong outv edit ulong 8 k ulong to void
1989a = lo
1990e = hi
1991while lt a e bound 999999
1992if not lsp lc b a
1993break
1994end
1995a = add a 1
1996end
1997while gt e a bound 999999
1998if not lsp lc b sub e 1
1999break
2000end
2001e = sub e 1
2002end
2003put outv k a
2004put outv add k 1 e
2005end
2006
2007note where a text of bytes a..e is cut to lim bytes without splitting a character (e when it is short enough)
2008fn lclip b view uchar 1048576 a ulong e ulong lim ulong to ulong
2009if le sub e a lim
2010ret e
2011end
2012ce = add a lim
2013back = ulong 0
2014while gt ce a bound 8
2015if ge back 3
2016break
2017end
2018if ne and lc b ce 192 128
2019break
2020end
2021ce = sub ce 1
2022back = add back 1
2023end
2024ret ce
2025end
2026
2027note "YYYY-MM-DD", then optionally "T" or one space and "HH:MM" or "HH:MM:SS", a fraction, and "Z" or an offset
2028note such as "+00:00", from byte s of the n-byte line. Returns 1 when it is a time, from 1970 on. tm: 1 the
2029note seconds since 1970 as written (less the offset when one is named) plus 100000, 2 the first byte after the
2030note time, 3 1 when the text names its zone
2031fn ltime b view uchar 1048576 s ulong n ulong tm edit ulong 16 to ulong
2032if gt add s 10 n
2033ret 0
2034end
2035ce = l2d b s n
2036yy = l2d b add s 2 n
2037mo = l2d b add s 5 n
2038dy = l2d b add s 8 n
2039if or eq ce 100 eq yy 100
2040ret 0
2041end
2042if or or lt mo 1 gt mo 12 or lt dy 1 gt dy 31
2043ret 0
2044end
2045if or ne lc b add s 4 45 ne lc b add s 7 45
2046ret 0
2047end
2048yr = add mul ce 100 yy
2049if lt yr 1970
2050ret 0
2051end
2052p = add s 10
2053sec = ulong 0
2054off = ulong 0
2055pls = ulong 0
2056zoned = ulong 0
2057tp = ulong 0
2058if lt add p 5 n
2059tp = lc b p
2060end
2061if or eq tp 84 eq tp 32
2062hr = l2d b add p 1 n
2063mi = l2d b add p 4 n
2064okhm = false
2065if and lt hr 24 lt mi 60
2066if eq lc b add p 3 58
2067okhm = true
2068end
2069end
2070if okhm
2071sec = add mul hr 3600 mul mi 60
2072p = add p 6
2073if lt p n
2074if eq lc b p 58
2075sx = l2d b add p 1 n
2076if lt sx 61
2077sec = add sec sx
2078p = add p 3
2079end
2080end
2081end
2082if lt p n
2083if eq lc b p 46
2084q = add p 1
2085while lt q n bound 32
2086if gt sub q p 9
2087break
2088end
2089c = lc b q
2090if or lt c 48 gt c 57
2091break
2092end
2093q = add q 1
2094end
2095if gt q add p 1
2096p = q
2097end
2098end
2099end
2100if lt p n
2101zc = lc b p
2102if or eq zc 90 eq zc 122
2103zoned = 1
2104p = add p 1
2105else
2106if or eq zc 43 eq zc 45
2107oh = l2d b add p 1 n
2108om = ulong 100
2109used = ulong 5
2110c3 = false
2111if lt add p 3 n
2112if eq lc b add p 3 58
2113c3 = true
2114end
2115end
2116if c3
2117om = l2d b add p 4 n
2118used = 6
2119else
2120om = l2d b add p 3 n
2121end
2122if and lt oh 24 lt om 60
2123o = add mul oh 3600 mul om 60
2124if eq zc 43
2125off = o
2126else
2127pls = o
2128end
2129zoned = 1
2130p = add p used
2131end
2132end
2133end
2134end
2135else
2136if eq tp 84
2137ret 0
2138end
2139end
2140else
2141if lt p n
2142if eq lc b p 84
2143ret 0
2144end
2145end
2146end
2147y = yr
2148if le mo 2
2149y = sub yr 1
2150end
2151era = div y 400
2152yoe = sub y mul era 400
2153mm = add mo 9
2154if gt mo 2
2155mm = sub mo 3
2156end
2157doy = sub add div add mul 153 mm 2 5 dy 1
2158doe = add sub add mul yoe 365 div yoe 4 div yoe 100 doy
2159days = sub add mul era 146097 doe 719468
2160put tm 1 sub add add add mul days 86400 sec 100000 pls off
2161put tm 2 p
2162put tm 3 zoned
2163ret 1
2164end
2165
2166note one name from byte lo, stopping before " + ", before "(" and, on the sender side (side 1), before " to "
2167note and " @". A bracket right after the name is its detail. nr: 0 and 1 the name, 2 and 3 the detail, 4 the first
2168note byte after the name, its bracket and the spaces that follow, 5 1 when there was a bracket
2169fn lname b view uchar 1048576 lo ulong limit ulong side ulong nr edit ulong 8 to void
2170i = lo
2171while lt i limit bound 999999
2172if not lsp lc b i
2173break
2174end
2175i = add i 1
2176end
2177start = i
2178while lt i limit bound 999999
2179c = lc b i
2180if eq c 40
2181break
2182end
2183stop = false
2184if eq c 32
2185if lt add i 1 limit
2186d = lc b add i 1
2187if eq d 43
2188if ge add i 2 limit
2189stop = true
2190else
2191if eq lc b add i 2 32
2192stop = true
2193end
2194end
2195end
2196if eq side 1
2197if eq d 64
2198stop = true
2199end
2200if eq d 116
2201if lt add i 2 limit
2202if eq lc b add i 2 111
2203if ge add i 3 limit
2204stop = true
2205else
2206if eq lc b add i 3 32
2207stop = true
2208end
2209end
2210end
2211end
2212end
2213end
2214end
2215end
2216if stop
2217break
2218end
2219i = add i 1
2220end
2221ltrim b start i nr 0
2222while lt i limit bound 999999
2223if not lsp lc b i
2224break
2225end
2226i = add i 1
2227end
2228put nr 2 0
2229put nr 3 0
2230put nr 5 0
2231if lt i limit
2232if eq lc b i 40
2233depth = ulong 0
2234j = i
2235while lt j limit bound 999999
2236cj = lc b j
2237if eq cj 40
2238depth = add depth 1
2239else
2240if eq cj 41
2241depth = sub depth 1
2242if eq depth 0
2243break
2244end
2245end
2246end
2247j = add j 1
2248end
2249ltrim b add i 1 j nr 2
2250put nr 5 1
2251i = limit
2252if lt j limit
2253i = add j 1
2254end
2255while lt i limit bound 999999
2256if not lsp lc b i
2257break
2258end
2259i = add i 1
2260end
2261end
2262end
2263put nr 4 i
2264end
2265
2266note a name fits when it has 1 to 64 bytes and at most 3 words
2267fn lfits b view uchar 1048576 a ulong e ulong to bool
2268if le e a
2269ret false
2270end
2271if gt sub e a 64
2272ret false
2273end
2274n = ulong 0
2275inw = false
2276i = a
2277while lt i e bound 999999
2278if lsp lc b i
2279inw = false
2280else
2281if not inw
2282inw = true
2283n = add n 1
2284end
2285end
2286i = add i 1
2287end
2288ret le n 3
2289end
2290
2291note "all", "all lanes", "everyone" (any case, a leading "@" dropped): the whole board, not one member.
2292note The name fits (lfits), so its key has at most 64 bytes
2293fn levery b view uchar 1048576 a ulong e ulong to bool
2294k = new uchar 80 0
2295n = ulong 0
2296i = a
2297if lt i e
2298if eq lc b i 64
2299i = add i 1
2300end
2301end
2302gap = false
2303while lt i e bound 999999
2304c = lc b i
2305if lsp c
2306gap = true
2307else
2308if and gap gt n 0
2309put k n uchar 45
2310n = add n 1
2311end
2312gap = false
2313if and ge c 65 le c 90
2314c = add c 32
2315end
2316put k n uchar c
2317n = add n 1
2318end
2319i = add i 1
2320end
2321if lt n 3
2322ret false
2323end
2324al = and and eq ulong get k 0 97 eq ulong get k 1 108 eq ulong get k 2 108
2325if eq n 3
2326ret al
2327end
2328if gt n 4
2329if and al eq ulong get k 3 45
2330ret true
2331end
2332end
2333if ne n 8
2334ret false
2335end
2336ev = and and eq ulong get k 0 101 eq ulong get k 1 118 and eq ulong get k 2 101 eq ulong get k 3 114
2337ev = and ev and and eq ulong get k 4 121 eq ulong get k 5 111 and eq ulong get k 6 110 eq ulong get k 7 101
2338ret ev
2339end
2340
2341note where a part starts and how long it is, at byte o of the answer
2342fn lput ob edit uchar 65544 o ulong s ulong e ulong to void
2343l = ulong 0
2344if gt e s
2345l = sub e s
2346end
2347put32 ob add 8 o s
2348put32 ob add 12 o l
2349end
2350
2351note op 1: one board line of n0 bytes. The answer is 344 bytes: 0 1 when it is a post, 1 1 when it is to all,
2352note 2 1 when something went over a limit, 3 the senders, 4 the recipients; 8 the time (64-bit, seconds since 1970
2353note plus 100000); 16 the text; from 24 sixteen bytes a sender (name, detail), from 88 sixteen a recipient. Each
2354note part is two 32-bit numbers: where it starts in the line and its length
2355fn lline b view uchar 1048576 n0 ulong ob edit uchar 65544 to ulong
2356tm = new ulong 16 0
2357nr = new ulong 8 0
2358for z ulong 344
2359put ob add 8 z uchar 0
2360end
2361n = n0
2362clipped = ulong 0
2363if gt n 65536
2364n = lclip b 0 n 65536
2365clipped = 1
2366end
2367put ob 10 uchar clipped
2368en = n
2369while gt en 0 bound 999999
2370c = lc b sub en 1
2371blank = lsp c
2372if or eq c 13 eq c 10
2373blank = true
2374end
2375if not blank
2376break
2377end
2378en = sub en 1
2379end
2380p = ulong 0
2381while lt p en bound 999999
2382if not lsp lc b p
2383break
2384end
2385p = add p 1
2386end
2387if lt add p 1 en
2388if and eq lc b p 45 eq lc b add p 1 32
2389p = add p 2
2390end
2391end
2392if eq ltime b p n tm 0
2393ret 344
2394end
2395te = get tm 2
2396if ge te en
2397ret 344
2398end
2399if not lsp lc b te
2400ret 344
2401end
2402p = te
2403while lt p en bound 999999
2404if not lsp lc b p
2405break
2406end
2407p = add p 1
2408end
2409if ge p en
2410ret 344
2411end
2412put ob 8 uchar 1
2413tv = get tm 1
2414put32 ob 16 tv
2415put32 ob 20 shr tv 32
2416bst = p
2417colon = ulong 0
2418hasc = false
2419depth = ulong 0
2420i = p
2421while lt i en bound 999999
2422if ge sub i p 600
2423break
2424end
2425c = lc b i
2426if eq c 40
2427depth = add depth 1
2428else
2429if eq c 41
2430if gt depth 0
2431depth = sub depth 1
2432end
2433else
2434if and eq c 58 eq depth 0
2435nx = true
2436if lt add i 1 en
2437if ne lc b add i 1 32
2438nx = false
2439end
2440end
2441if nx
2442colon = i
2443hasc = true
2444break
2445end
2446end
2447end
2448end
2449i = add i 1
2450end
2451fits = hasc
2452ts = add colon 1
2453q = p
2454md = ulong 0
2455ns = ulong 0
2456nrc = ulong 0
2457tall = ulong 0
2458rnd = ulong 0
2459while and and fits eq md 0 lt rnd 64 bound 100
2460rnd = add rnd 1
2461lname b q colon 1 nr
2462if not lfits b get nr 0 get nr 1
2463fits = false
2464break
2465end
2466if lt ns 4
2467lput ob add 24 mul ns 16 get nr 0 get nr 1
2468lput ob add 32 mul ns 16 get nr 2 get nr 3
2469ns = add ns 1
2470else
2471clipped = 1
2472end
2473x = get nr 4
2474if ge x colon
2475md = 3
2476else
2477cx = lc b x
2478did = false
2479if eq cx 43
2480sp = true
2481if lt add x 1 colon
2482if ne lc b add x 1 32
2483sp = false
2484end
2485end
2486if sp
2487q = add x 1
2488did = true
2489end
2490end
2491if not did
2492if eq cx 116
2493if lt add x 2 colon
2494if and eq lc b add x 1 111 eq lc b add x 2 32
2495md = 1
2496q = add x 3
2497did = true
2498end
2499end
2500end
2501end
2502if not did
2503if eq cx 64
2504md = 2
2505q = x
2506did = true
2507end
2508end
2509if not did
2510if eq get nr 5 1
2511md = 3
2512ts = x
2513else
2514fits = false
2515end
2516end
2517end
2518end
2519if and fits eq md 0
2520fits = false
2521end
2522rnd = 0
2523while and and fits eq md 1 lt rnd 64 bound 100
2524rnd = add rnd 1
2525lname b q colon 0 nr
2526a = get nr 0
2527e = get nr 1
2528if gt e a
2529if eq lc b a 64
2530a = add a 1
2531end
2532end
2533if not lfits b a e
2534fits = false
2535break
2536end
2537if levery b a e
2538tall = 1
2539else
2540if lt nrc 16
2541lput ob add 88 mul nrc 16 a e
2542lput ob add 96 mul nrc 16 get nr 2 get nr 3
2543nrc = add nrc 1
2544else
2545clipped = 1
2546end
2547end
2548x = get nr 4
2549if ge x colon
2550md = 3
2551else
2552plus = false
2553if eq lc b x 43
2554plus = true
2555if lt add x 1 colon
2556if ne lc b add x 1 32
2557plus = false
2558end
2559end
2560end
2561if plus
2562q = add x 1
2563else
2564fits = false
2565end
2566end
2567end
2568if and fits eq md 1
2569fits = false
2570end
2571rnd = 0
2572while and and fits eq md 2 lt rnd 64 bound 100
2573rnd = add rnd 1
2574while lt q colon bound 999999
2575c = lc b q
2576if not or lsp c eq c 43
2577break
2578end
2579q = add q 1
2580end
2581if ge q colon
2582md = 3
2583break
2584end
2585if ne lc b q 64
2586fits = false
2587break
2588end
2589j = add q 1
2590while lt j colon bound 999999
2591if lsp lc b j
2592break
2593end
2594j = add j 1
2595end
2596ltrim b add q 1 j nr 0
2597a = get nr 0
2598e = get nr 1
2599if not lfits b a e
2600fits = false
2601break
2602end
2603if levery b a e
2604tall = 1
2605else
2606if lt nrc 16
2607lput ob add 88 mul nrc 16 a e
2608nrc = add nrc 1
2609else
2610clipped = 1
2611end
2612end
2613q = j
2614end
2615if and fits eq md 2
2616fits = false
2617end
2618if not fits
2619for z ulong 320
2620put ob add 32 z uchar 0
2621end
2622ns = 1
2623nrc = 0
2624tall = 0
2625j = bst
2626while lt j en bound 999999
2627if lsp lc b j
2628break
2629end
2630j = add j 1
2631end
2632ltrim b bst j nr 0
2633a = get nr 0
2634e = get nr 1
2635if gt sub e a 1
2636if eq lc b sub e 1 58
2637e = sub e 1
2638end
2639end
2640if gt sub e a 64
2641e = lclip b a e 64
2642clipped = 1
2643end
2644lput ob 24 a e
2645ts = j
2646end
2647ltrim b ts en nr 0
2648a = get nr 0
2649e = get nr 1
2650if gt e a
2651if gt sub e a 32768
2652e = lclip b a e 32768
2653clipped = 1
2654end
2655end
2656lput ob 16 a e
2657put ob 9 uchar tall
2658put ob 10 uchar clipped
2659put ob 11 uchar ns
2660put ob 12 uchar nrc
2661ret 344
2662end
2663
2664note ---- who a post calls and which posts it cites (kind 5 op 3) ----
2665note "@name", "@all", "@#channel" and "#seq" in the text of a post. A mention counts only at a word start: the
2666note character before "@" or "#" must not be a name character, and the name must not run on into more name
2667note characters. Positions in these functions are places in the request: the text is the bytes t0..t1.
2668
2669note the character that starts at byte i, as a code point; 4294967295 at or after t1. A broken sequence gives its
2670note first byte
2671fn rune b view uchar 1048576 i ulong t1 ulong to ulong
2672if ge i t1
2673ret 4294967295
2674end
2675b0 = ulong get b i
2676if or lt b0 128 ge b0 248
2677ret b0
2678end
2679if lt b0 192
2680ret b0
2681end
2682need = ulong 1
2683cp = and b0 31
2684if ge b0 224
2685need = 2
2686cp = and b0 15
2687end
2688if ge b0 240
2689need = 3
2690cp = and b0 7
2691end
2692k = ulong 1
2693while le k need bound 8
2694if ge add i k t1
2695ret b0
2696end
2697c = ulong get b add i k
2698if ne and c 192 128
2699ret b0
2700end
2701cp = or shl cp 6 and c 63
2702k = add k 1
2703end
2704ret cp
2705end
2706
2707note the character that ends just before byte e; 4294967295 at the start of the text
2708fn runeb b view uchar 1048576 e ulong t0 ulong t1 ulong to ulong
2709if or le e t0 gt e t1
2710ret 4294967295
2711end
2712i = sub e 1
2713back = ulong 0
2714while gt i t0 bound 8
2715if ge back 3
2716break
2717end
2718if ne and ulong get b i 192 128
2719break
2720end
2721i = sub i 1
2722back = add back 1
2723end
2724ret rune b i t1
2725end
2726
2727note can this character be part of a name? Letters, digits, "_" and "-"; outside ASCII everything except the
2728note blocks that hold punctuation, symbols and emoji
2729fn namer cp ulong to bool
2730if eq cp 4294967295
2731ret false
2732end
2733if lt cp 128
2734if and ge cp 48 le cp 57
2735ret true
2736end
2737if and ge cp 65 le cp 90
2738ret true
2739end
2740if and ge cp 97 le cp 122
2741ret true
2742end
2743ret or eq cp 95 eq cp 45
2744end
2745if or or lt cp 192 eq cp 215 eq cp 247
2746ret false
2747end
2748if and ge cp 8192 le cp 11263
2749ret false
2750end
2751if and ge cp 12288 le cp 12351
2752ret false
2753end
2754if and ge cp 65072 le cp 65135
2755ret false
2756end
2757if or and ge cp 65280 le cp 65295 and ge cp 65306 le cp 65312
2758ret false
2759end
2760if or and ge cp 65339 le cp 65344 and ge cp 65371 le cp 65381
2761ret false
2762end
2763if and ge cp 126976 le cp 129791
2764ret false
2765end
2766ret true
2767end
2768
2769fn lowc c ulong to ulong
2770if and ge c 65 le c 90
2771ret add c 32
2772end
2773ret c
2774end
2775
2776note true when the ln bytes at na stand at byte pos of the text (ASCII letters without case) and no name
2777note character follows them
2778fn nameat b view uchar 1048576 pos ulong na ulong ln ulong t1 ulong to bool
2779if eq ln 0
2780ret false
2781end
2782if gt add pos ln t1
2783ret false
2784end
2785for k ulong ln
2786if ne lowc ulong get b add pos k lowc ulong get b add na k
2787ret false
2788end
2789end
2790ret not namer rune b add pos ln t1
2791end
2792
2793note "all" at byte pos, and no name character after it
2794fn allat b view uchar 1048576 pos ulong t1 ulong to bool
2795if gt add pos 3 t1
2796ret false
2797end
2798if ne lowc ulong get b pos 97
2799ret false
2800end
2801if ne lowc ulong get b add pos 1 108
2802ret false
2803end
2804if ne lowc ulong get b add pos 2 108
2805ret false
2806end
2807ret not namer rune b add pos 3 t1
2808end
2809
2810note a member called "<prefix>-<digits>" also answers to "@<prefix>": the length of that prefix, or 0
2811fn cprefix b view uchar 1048576 na ulong nl ulong to ulong
2812i = nl
2813while gt i 0 bound 999999
2814c = ulong get b add na sub i 1
2815if or lt c 48 gt c 57
2816break
2817end
2818i = sub i 1
2819end
2820if eq i nl
2821ret 0
2822end
2823if lt i 2
2824ret 0
2825end
2826if ne ulong get b add na sub i 1 45
2827ret 0
2828end
2829ret sub i 1
2830end
2831
2832note the length of a channel name at byte pos (after "@#"): a letter, then letters, digits and "-", 24 at most
2833fn chlen b view uchar 1048576 pos ulong t1 ulong to ulong
2834if ge pos t1
2835ret 0
2836end
2837f = lowc ulong get b pos
2838if or lt f 97 gt f 122
2839ret 0
2840end
2841j = pos
2842while lt j t1 bound 64
2843if ge sub j pos 25
2844break
2845end
2846c = lowc ulong get b j
2847okc = and ge c 97 le c 122
2848if and ge c 48 le c 57
2849okc = true
2850end
2851if eq c 45
2852okc = true
2853end
2854if not okc
2855break
2856end
2857j = add j 1
2858end
2859n = sub j pos
2860if gt n 24
2861ret 0
2862end
2863if namer rune b j t1
2864ret 0
2865end
2866ret n
2867end
2868
2869note part idx of the answer: where it starts in the text, its length, its kind (1 a member, 2 all, 3 a channel,
2870note 4 a cited post) and its value (the member's number, or the post's)
2871fn semit ob edit uchar 65544 idx ulong s ulong l ulong kind ulong v ulong to void
2872o = add 16 mul idx 16
2873put32 ob o s
2874put32 ob add o 4 l
2875put32 ob add o 8 kind
2876put32 ob add o 12 v
2877end
2878
2879note op 3: n bytes after the op header: a 16-bit count of member names (96 at most), each name as a 16-bit length
2880note and its bytes, then the text (900000 bytes at most). head is the highest post number that may be cited; 0
2881note turns citations off. The answer: a 16-bit count of parts, a byte that is 1 when the post has more than 128
2882note parts (the rest is not marked), then from byte 8 sixteen bytes a part (semit), in text order. Parts that
2883note start at one byte are kept or dropped together
2884fn spans b view uchar 1048576 n ulong head ulong ob edit uchar 65544 to ulong
2885noff = new ulong 96 0
2886nlen = new ulong 96 0
2887npre = new ulong 96 0
2888bad = ulong 18446744073709551615
2889if lt n 2
2890ret bad
2891end
2892nn = rd16 b 8
2893if gt nn 96
2894ret bad
2895end
2896lim = add 8 n
2897p = ulong 10
2898for k ulong nn
2899if gt add p 2 lim
2900ret bad
2901end
2902l = rd16 b p
2903p = add p 2
2904if gt add p l lim
2905ret bad
2906end
2907put noff k p
2908put nlen k l
2909put npre k cprefix b p l
2910p = add p l
2911end
2912t0 = p
2913t1 = lim
2914if gt sub t1 t0 900000
2915ret bad
2916end
2917cnt = ulong 0
2918clipped = ulong 0
2919i = t0
2920while lt i t1 bound 999999
2921c = ulong get b i
2922st = ulong 1
2923g = ulong 0
2924mark = or eq c 64 eq c 35
2925if mark
2926if namer runeb b i t0 t1
2927mark = false
2928end
2929end
2930if mark
2931if eq c 64
2932nxt = ulong 0
2933if lt add i 1 t1
2934nxt = ulong get b add i 1
2935end
2936if eq nxt 35
2937cl = chlen b add i 2 t1
2938if gt cl 0
2939semit ob cnt sub i t0 add cl 2 3 0
2940g = 1
2941st = add cl 2
2942end
2943else
2944for k ulong nn
2945if nameat b add i 1 get noff k get nlen k t1
2946semit ob add cnt g sub i t0 add get nlen k 1 1 k
2947g = add g 1
2948end
2949end
2950if eq g 0
2951if allat b add i 1 t1
2952semit ob add cnt g sub i t0 4 2 0
2953g = 1
2954end
2955end
2956k2 = ulong 0
2957while lt k2 nn bound 128
2958if gt g 0
2959break
2960end
2961pk = get npre k2
2962if gt pk 0
2963if nameat b add i 1 get noff k2 pk t1
2964j = k2
2965while lt j nn bound 128
2966if eq get npre j pk
2967if nameat b add i 1 get noff j pk t1
2968semit ob add cnt g sub i t0 add pk 1 1 j
2969g = add g 1
2970end
2971end
2972j = add j 1
2973end
2974end
2975end
2976k2 = add k2 1
2977end
2978end
2979else
2980if gt head 0
2981if ne runeb b i t0 t1 38
2982j = add i 1
2983v = ulong 0
2984while lt j t1 bound 16
2985if gt sub j i 9
2986break
2987end
2988d = ulong get b j
2989if or lt d 48 gt d 57
2990break
2991end
2992v = add mul v 10 sub d 48
2993j = add j 1
2994end
2995if gt j add i 1
2996if and ge v 1 le v head
2997if not namer rune b j t1
2998semit ob cnt sub i t0 sub j i 4 v
2999g = 1
3000st = sub j i
3001end
3002end
3003end
3004end
3005end
3006end
3007end
3008if gt g 0
3009if gt add cnt g 128
3010clipped = 1
3011break
3012end
3013cnt = add cnt g
3014end
3015i = add i st
3016end
3017put ob 8 uchar and cnt 255
3018put ob 9 uchar shr cnt 8
3019put ob 10 uchar clipped
3020for z ulong 5
3021put ob add 11 z uchar 0
3022end
3023ret add 8 mul cnt 16
3024end
3025
3026note ---- who a post addresses (kind 5 op 4) ----
3027note the members its header names, the members its text calls with "@name" or reaches through "@#channel", and
3028note whether it is to everyone. The sender is left out.
3029
3030note two runs of bytes of the request, equal when ASCII letters are compared without case
3031fn eqf b view uchar 1048576 x ulong xl ulong y ulong yl ulong to bool
3032if ne xl yl
3033ret false
3034end
3035for k ulong xl
3036if ne lowc ulong get b add x k lowc ulong get b add y k
3037ret false
3038end
3039end
3040ret true
3041end
3042
3043note "main", "all" and "here" are not channels anyone follows
3044fn chplain b view uchar 1048576 x ulong n ulong to bool
3045if eq n 3
3046ret and and eq lowc ulong get b x 97 eq lowc ulong get b add x 1 108 eq lowc ulong get b add x 2 108
3047end
3048if ne n 4
3049ret false
3050end
3051c0 = lowc ulong get b x
3052c1 = lowc ulong get b add x 1
3053c2 = lowc ulong get b add x 2
3054c3 = lowc ulong get b add x 3
3055if and and eq c0 109 eq c1 97 and eq c2 105 eq c3 110
3056ret true
3057end
3058ret and and eq c0 104 eq c1 101 and eq c2 114 eq c3 101
3059end
3060
3061note does a member follow the channel named by the xl bytes at x? cp is where the member's channel list starts: a
3062note count, then each channel as a 16-bit length and its bytes. An empty list is the role's default: everyone but a
3063note worker (role 0) follows every channel. "*" follows every channel
3064fn follows b view uchar 1048576 role ulong cp ulong x ulong xl ulong to bool
3065cc = ulong get b cp
3066if eq cc 0
3067ret ne role 0
3068end
3069p = add cp 1
3070for i ulong cc
3071l = rd16 b p
3072if eq l 1
3073if eq ulong get b add p 2 42
3074ret true
3075end
3076end
3077if eqf b add p 2 l x xl
3078ret true
3079end
3080p = add add p 2 l
3081end
3082ret false
3083end
3084
3085note op 4: n bytes after the op header: 16-bit counts of members (96 at most), parts (128) and header recipients
3086note (16); a byte that is 1 when the header says all; a byte 0; the sender as a 32-bit member number; a byte a
3087note member (0 for a worker); the header's recipients, 32 bits each; the parts as fn spans gives them; for each
3088note member its channel list (follows); then the text of the post. A number that is not a member is 4294967295.
3089note The answer: a byte that is 1 when the post is to everyone, a count, then that many member numbers
3090fn addr b view uchar 1048576 n ulong ob edit uchar 65544 to ulong
3091flag = new ulong 96 0
3092coff = new ulong 96 0
3093bad = ulong 18446744073709551615
3094if lt n 12
3095ret bad
3096end
3097lim = add 8 n
3098mem = rd16 b 8
3099nsp = rd16 b 10
3100nh = rd16 b 12
3101tall = ulong get b 14
3102sender = rd32 b 16
3103if or gt mem 96 or gt nsp 128 gt nh 16
3104ret bad
3105end
3106roles = ulong 20
3107hto = add roles mem
3108sp = add hto mul nh 4
3109p = add sp mul nsp 16
3110if gt p lim
3111ret bad
3112end
3113for m ulong mem
3114if ge p lim
3115ret bad
3116end
3117put coff m p
3118cc = ulong get b p
3119if gt cc 16
3120ret bad
3121end
3122p = add p 1
3123for c ulong cc
3124if gt add p 2 lim
3125ret bad
3126end
3127p = add add p 2 rd16 b p
3128if gt p lim
3129ret bad
3130end
3131end
3132end
3133t0 = p
3134tn = sub lim t0
3135for i ulong nh
3136v = rd32 b add hto mul i 4
3137if lt v mem
3138put flag v 1
3139end
3140end
3141for s ulong nsp
3142o = add sp mul s 16
3143start = rd32 b o
3144ln = rd32 b add o 4
3145kind = rd32 b add o 8
3146v = rd32 b add o 12
3147if eq kind 1
3148if lt v mem
3149put flag v 1
3150end
3151end
3152if eq kind 2
3153tall = 1
3154end
3155if eq kind 3
3156if and gt ln 2 le add start ln tn
3157cx = add add t0 start 2
3158cl = sub ln 2
3159if not chplain b cx cl
3160for m ulong mem
3161if follows b ulong get b add roles m get coff m cx cl
3162put flag m 1
3163end
3164end
3165end
3166end
3167end
3168end
3169if lt sender mem
3170put flag sender 0
3171end
3172cnt = ulong 0
3173for m ulong mem
3174if eq get flag m 1
3175put ob add 10 cnt uchar m
3176cnt = add cnt 1
3177end
3178end
3179if ne tall 0
3180tall = 1
3181end
3182put ob 8 uchar tall
3183put ob 9 uchar cnt
3184ret add 2 cnt
3185end
3186
3187note kind 5: op and a number as two 32-bit values, then the bytes of the text (at most 70000 for op 1 and 2).
3188note op 1: a board line (fn lline). op 2: a time at byte `number` (fn ltime); the answer is 16 bytes: 0 1 when it
3189note is a time, 1 1 when it names its zone, 4 the first byte after it (32-bit), 8 the seconds since 1970 plus 100000
3190note (64-bit). op 3: who a post calls and what it cites (fn spans; the number is the highest post that may be
3191note cited). op 4: who a post addresses (fn addr). Returns the reply length, or 18446744073709551615 for a malformed body or an unknown op
3192fn board ib view uchar 1048576 nb ulong ob edit uchar 65544 to ulong
3193tm = new ulong 16 0
3194bad = ulong 18446744073709551615
3195if lt nb 8
3196ret bad
3197end
3198op = rd32 ib 0
3199arg = rd32 ib 4
3200n = sub nb 8
3201if eq op 3
3202ret spans ib n arg ob
3203end
3204if eq op 4
3205ret addr ib n ob
3206end
3207if gt n 70000
3208ret bad
3209end
3210if eq op 1
3211ret lline ib n ob
3212end
3213if eq op 2
3214for z ulong 16
3215put ob add 8 z uchar 0
3216end
3217if eq ltime ib arg n tm 1
3218put ob 8 uchar 1
3219put ob 9 uchar get tm 3
3220put32 ob 12 get tm 2
3221put32 ob 16 get tm 1
3222put32 ob 20 shr get tm 1 32
3223end
3224ret 16
3225end
3226ret bad
3227end
3228
3229note ---- a whole plain-text board: its members and who each post is from and to (kind 6) ----
3230note The host reads each line (kind 5 op 1) and sends what the lines name: for each line a byte that is 1 for a
3231note post, a byte that is 1 when it was cut, the number of senders (4 at most) and of recipients (16 at most), then
3232note each sender and each recipient as a 16-bit length and the name, a 16-bit length and the bracket after it.
3233note Senders and recipients become members. Two spellings are one member when they share a key (no leading "@",
3234note ASCII lower case, each run of spaces one "-"); when one stands in the brackets of one agent only and is used
3235note as a sender or recipient elsewhere ("merge-desk (omp-queen-spark)"); or when it is that agent's name without
3236note its lane ("Worker" for "lane/Worker") and exactly one sender posts under a name that ends that way.
3237note Limits: 400 lines, 192 spellings, 96 members, 8 comma-separated items in a bracket.
3238global a_keys uchar 12288
3239global a_kl ulong 192
3240global a_sref ulong 192
3241global a_own ulong 192
3242global a_can ulong 192
3243global a_mem ulong 192
3244global a_lo ulong 400
3245global a_kb uchar 72
3246global a_e ulong 8
3247global a_ds ulong 96
3248
3249note entry k of side (0 senders, 1 recipients) of the line record at p. a_e: 0 and 1 the name, 2 and 3 the bracket
3250fn aent b view uchar 1048576 p ulong side ulong k ulong to void
3251skip = k
3252if eq side 1
3253skip = add k ulong get b add p 2
3254end
3255q = add p 4
3256for i ulong skip
3257q = add add q 2 rd16 b q
3258q = add add q 2 rd16 b q
3259end
3260nl = rd16 b q
3261put a_e 0 add q 2
3262put a_e 1 nl
3263q = add add q 2 nl
3264put a_e 2 add q 2
3265put a_e 3 rd16 b q
3266end
3267
3268note the key of the n bytes at off into a_kb; its length, or 65 when it is over 64 bytes (no member has such a key)
3269fn akey b view uchar 1048576 off ulong n ulong to ulong
3270a = off
3271e = add off n
3272while lt a e bound 999999
3273if not lsp ulong get b a
3274break
3275end
3276a = add a 1
3277end
3278while gt e a bound 999999
3279if not lsp ulong get b sub e 1
3280break
3281end
3282e = sub e 1
3283end
3284if lt a e
3285if eq ulong get b a 64
3286a = add a 1
3287end
3288end
3289kn = ulong 0
3290gap = false
3291while lt a e bound 999999
3292c = ulong get b a
3293if lsp c
3294gap = true
3295else
3296if and gap gt kn 0
3297if ge kn 64
3298ret 65
3299end
3300put a_kb kn uchar 45
3301kn = add kn 1
3302end
3303gap = false
3304if ge kn 64
3305ret 65
3306end
3307put a_kb kn uchar lowc c
3308kn = add kn 1
3309end
3310a = add a 1
3311end
3312ret kn
3313end
3314
3315note where the key in a_kb (kn bytes) stands among the first nk keys, or 1000
3316fn afind kn ulong nk ulong to ulong
3317if gt kn 64
3318ret 1000
3319end
3320i = ulong 0
3321while lt i nk bound 256
3322if eq get a_kl i kn
3323j = ulong 0
3324while lt j kn bound 128
3325if ne ulong get a_keys add mul i 64 j ulong get a_kb j
3326break
3327end
3328j = add j 1
3329end
3330if eq j kn
3331ret i
3332end
3333end
3334i = add i 1
3335end
3336ret 1000
3337end
3338
3339note "L1122" or "L1124/L1125": a ledger number, never another name of the agent
3340fn aledger b view uchar 1048576 off ulong n ulong to bool
3341i = ulong 0
3342parts = ulong 0
3343while lt i n bound 16
3344if ge parts 8
3345break
3346end
3347c = ulong get b add off i
3348if and ne c 76 ne c 108
3349ret false
3350end
3351j = add i 1
3352while lt j n bound 16
3353if gt sub j i 9
3354break
3355end
3356d = ulong get b add off j
3357if or lt d 48 gt d 57
3358break
3359end
3360j = add j 1
3361end
3362if eq j add i 1
3363ret false
3364end
3365parts = add parts 1
3366if eq j n
3367ret true
3368end
3369if ne ulong get b add off j 47
3370ret false
3371end
3372i = add j 1
3373end
3374ret false
3375end
3376
3377note the main spelling of the set that holds spelling s
3378fn aroot s ulong nk ulong to ulong
3379i = s
3380hops = ulong 0
3381while lt i nk bound 256
3382if eq get a_can i i
3383break
3384end
3385if ge hops 192
3386break
3387end
3388i = get a_can i
3389hops = add hops 1
3390end
3391ret i
3392end
3393
3394note joins the sets that hold x0 and y0; the earlier spelling stays the main one
3395fn ajoin x0 ulong y0 ulong nk ulong to void
3396x = aroot x0 nk
3397y = aroot y0 nk
3398if or ge x nk ge y nk
3399ret
3400end
3401if eq x y
3402ret
3403end
3404if lt x y
3405put a_can y x
3406else
3407put a_can x y
3408end
3409end
3410
3411note is key f the key s with a lane in front: "lane/s"?
3412fn alane f ulong s ulong to bool
3413fl = get a_kl f
3414sl = get a_kl s
3415if eq sl 0
3416ret false
3417end
3418if lt fl add sl 2
3419ret false
3420end
3421p = sub fl sl
3422if ne ulong get a_keys add mul f 64 sub p 1 47
3423ret false
3424end
3425i = ulong 0
3426while lt i sl bound 128
3427if ne ulong get a_keys add add mul f 64 p i ulong get a_keys add mul s 64 i
3428ret false
3429end
3430i = add i 1
3431end
3432ret true
3433end
3434
3435note the member that the name of the current entry (a_e) belongs to, or 1000
3436fn amember b view uchar 1048576 nk ulong to ulong
3437f = afind akey b get a_e 0 get a_e 1 nk
3438if ge f 1000
3439ret 1000
3440end
3441ret get a_mem f
3442end
3443
3444note kind 6: a 32-bit count of lines, then the line records. The answer: 16-bit counts of members, of joined
3445note spellings and of posts; from byte 8 four 32-bit counts: lines that are not posts, posts that were cut,
3446note agents beyond 96 members, names met after the 192 spellings were full; from byte 24 eight bytes a member:
3447note the line (16-bit), side and entry of its newest spelling, then the line (65535: none) and entry of the newest
3448note bracket after it as a sender; six bytes a joined spelling: its member, 0, then line, side and entry; then a
3449note post each: its sender (255: none), how many others signed and how many members its header names, then
3450note those members. Returns the reply length, or 18446744073709551615 for a malformed body
3451fn asm b view uchar 1048576 n ulong ob edit uchar 65544 to ulong
3452wl = new ulong 8 0
3453to2 = new ulong 24 0
3454bad = ulong 18446744073709551615
3455if lt n 4
3456ret bad
3457end
3458nl = rd32 b 0
3459if gt nl 400
3460ret bad
3461end
3462p = ulong 4
3463for li ulong nl
3464if gt add p 4 n
3465ret bad
3466end
3467put a_lo li p
3468ns = ulong get b add p 2
3469nr = ulong get b add p 3
3470if or gt ns 4 gt nr 16
3471ret bad
3472end
3473p = add p 4
3474for k ulong mul 2 add ns nr
3475if gt add p 2 n
3476ret bad
3477end
3478p = add add p 2 rd16 b p
3479if gt p n
3480ret bad
3481end
3482end
3483end
3484nk = ulong 0
3485sdrop = ulong 0
3486skeys = ulong 0
3487for pz ulong 2
3488for lr ulong nl
3489lq = sub sub nl 1 lr
3490p = get a_lo lq
3491if eq ulong get b p 1
3492cnt = ulong get b add p 2
3493if eq pz 1
3494cnt = ulong get b add p 3
3495end
3496for k ulong cnt
3497aent b p pz k
3498kn = akey b get a_e 0 get a_e 1
3499if and gt kn 0 le kn 64
3500if ge afind kn nk 1000
3501if lt nk 192
3502for j ulong kn
3503put a_keys add mul nk 64 j get a_kb j
3504end
3505put a_kl nk kn
3506put a_sref nk or or shl lq 16 shl pz 8 k
3507nk = add nk 1
3508else
3509sdrop = add sdrop 1
3510end
3511end
3512end
3513end
3514end
3515end
3516if eq pz 0
3517skeys = nk
3518end
3519end
3520for c ulong nk
3521put a_own c 1000
3522put a_can c c
3523put a_mem c 1000
3524end
3525for li ulong nl
3526p = get a_lo li
3527if eq ulong get b p 1
3528for side ulong 2
3529cnt = ulong get b add p 2
3530if eq side 1
3531cnt = ulong get b add p 3
3532end
3533for k ulong cnt
3534aent b p side k
3535d0 = get a_e 2
3536dn = get a_e 3
3537outer = afind akey b get a_e 0 get a_e 1 nk
3538a = ulong 0
3539items = ulong 0
3540while le a dn bound 1024
3541if ge outer 1000
3542break
3543end
3544if ge items 8
3545break
3546end
3547e = a
3548while lt e dn bound 999999
3549if eq ulong get b add d0 e 44
3550break
3551end
3552e = add e 1
3553end
3554x = a
3555y = e
3556while lt x y bound 999999
3557if not lsp ulong get b add d0 x
3558break
3559end
3560x = add x 1
3561end
3562while gt y x bound 999999
3563if not lsp ulong get b add d0 sub y 1
3564break
3565end
3566y = sub y 1
3567end
3568if lt x y
3569if not aledger b add d0 x sub y x
3570inner = afind akey b add d0 x sub y x nk
3571if lt inner 1000
3572if ne inner outer
3573if eq get a_own inner 1000
3574put a_own inner outer
3575else
3576if ne get a_own inner outer
3577put a_own inner 2000
3578end
3579end
3580end
3581end
3582end
3583end
3584items = add items 1
3585a = add e 1
3586end
3587end
3588end
3589end
3590end
3591for c ulong nk
3592if lt get a_own c 1000
3593ajoin get a_own c c nk
3594end
3595end
3596for c ulong nk
3597slash = false
3598for j ulong get a_kl c
3599if eq ulong get a_keys add mul c 64 j 47
3600slash = true
3601end
3602end
3603if not slash
3604mt1 = ulong 0
3605matches = ulong 0
3606for k ulong skeys
3607if ne k c
3608if alane k c
3609mt1 = k
3610matches = add matches 1
3611end
3612end
3613end
3614if eq matches 1
3615ajoin mt1 c nk
3616end
3617end
3618end
3619nm = ulong 0
3620mdrop = ulong 0
3621for c ulong nk
3622if eq aroot c nk c
3623if lt nm 96
3624put a_mem c nm
3625r = get a_sref c
3626o = add 32 mul nm 8
3627put ob o uchar and shr r 16 255
3628put ob add o 1 uchar shr r 24
3629put ob add o 2 uchar and shr r 8 255
3630put ob add o 3 uchar and r 255
3631put ob add o 4 uchar 255
3632put ob add o 5 uchar 255
3633put ob add o 6 uchar 0
3634put ob add o 7 uchar 0
3635put a_ds nm 0
3636nm = add nm 1
3637else
3638mdrop = add mdrop 1
3639end
3640end
3641end
3642o = add 32 mul nm 8
3643nalso = ulong 0
3644for c ulong nk
3645rt = aroot c nk
3646if ne rt c
3647if lt rt nk
3648if lt get a_mem rt 1000
3649put a_mem c get a_mem rt
3650r = get a_sref c
3651put ob o uchar get a_mem rt
3652put ob add o 1 uchar 0
3653put ob add o 2 uchar and shr r 16 255
3654put ob add o 3 uchar shr r 24
3655put ob add o 4 uchar and shr r 8 255
3656put ob add o 5 uchar and r 255
3657o = add o 6
3658nalso = add nalso 1
3659end
3660end
3661end
3662end
3663skipped = ulong 0
3664clipped = ulong 0
3665nposts = ulong 0
3666for li ulong nl
3667p = get a_lo li
3668if ne ulong get b p 1
3669skipped = add skipped 1
3670else
3671if eq ulong get b add p 1 1
3672clipped = add clipped 1
3673end
3674sender = ulong 1000
3675nw = ulong 0
3676ns = ulong get b add p 2
3677for k ulong ns
3678aent b p 0 k
3679m = amember b nk
3680if eq k 0
3681sender = m
3682else
3683if and lt m 1000 ne m sender
3684dup = false
3685for j ulong nw
3686if eq get wl j m
3687dup = true
3688end
3689end
3690if not dup
3691put wl nw m
3692nw = add nw 1
3693end
3694end
3695end
3696end
3697nt = ulong 0
3698nr = ulong get b add p 3
3699for k ulong nr
3700aent b p 1 k
3701m = amember b nk
3702if and lt m 1000 ne m sender
3703dup = false
3704for j ulong nt
3705if eq get to2 j m
3706dup = true
3707end
3708end
3709if not dup
3710put to2 nt m
3711nt = add nt 1
3712end
3713end
3714end
3715sb = ulong 255
3716if lt sender 1000
3717sb = sender
3718end
3719put ob o uchar sb
3720put ob add o 1 uchar nw
3721put ob add o 2 uchar nt
3722o = add o 3
3723for j ulong nw
3724put ob o uchar get wl j
3725o = add o 1
3726end
3727for j ulong nt
3728put ob o uchar get to2 j
3729o = add o 1
3730end
3731nposts = add nposts 1
3732end
3733end
3734for lr ulong nl
3735lq = sub sub nl 1 lr
3736p = get a_lo lq
3737if eq ulong get b p 1
3738ns = ulong get b add p 2
3739for k ulong ns
3740aent b p 0 k
3741dn = get a_e 3
3742m = amember b nk
3743if and lt m 1000 gt dn 0
3744if eq get a_ds m 0
3745put a_ds m 1
3746mo = add 36 mul m 8
3747put ob mo uchar and lq 255
3748put ob add mo 1 uchar shr lq 8
3749put ob add mo 2 uchar k
3750end
3751end
3752end
3753end
3754end
3755put ob 8 uchar and nm 255
3756put ob 9 uchar shr nm 8
3757put ob 10 uchar and nalso 255
3758put ob 11 uchar shr nalso 8
3759put ob 12 uchar and nposts 255
3760put ob 13 uchar shr nposts 8
3761put ob 14 uchar 0
3762put ob 15 uchar 0
3763put32 ob 16 skipped
3764put32 ob 20 clipped
3765put32 ob 24 mdrop
3766put32 ob 28 sdrop
3767ret sub o 8
3768end
3769
3770note ---- the state of a swarm's members, and the graph (kind 7) ----
3771note A request is an op and a count c as two 32-bit values, then c numbers of 64 bits, then bytes when the op has a
3772note text. Every number, in and out, is the value plus 1099511627776, so that -1 ("not known", "none") travels as
3773note an unsigned number. Codes: role 0 worker, 1 coordinator, 2 helper; turn 0 not known, 1 running, 2 ended; wake
3774note 2 parked for mentions, 3 for any post; state 1 working, 2 waiting, 3 stopped; attention 0 none, 1 stuck,
3775note 2 error, 3 quota; group 1 needs you, 2 working, 3 waiting on someone, 4 parked; step 1 planner, 2 result,
3776note 3 user, 4 error; status 1 done, 2 error.
3777const k_b ulong 1099511627776
3778text q_words "resource_exhausted|quota|rate limit|rate-limit|ratelimit|exhausted your capacity|"
3779text q_roles "coordinatorworkernarratormonitor"
3780global d_role ulong 96
3781global d_kill ulong 96
3782global d_wake ulong 96
3783global d_turn ulong 96
3784global d_lr ulong 96
3785global d_lm ulong 96
3786global d_fail ulong 96
3787global d_own ulong 96
3788global d_no ulong 96
3789global d_nl ulong 96
3790global d_cnt ulong 96
3791global d_last ulong 96
3792global d_state ulong 96
3793global d_att ulong 96
3794global d_won ulong 96
3795global d_grp ulong 96
3796global d_key ulong 96
3797global d_ord ulong 96
3798global d_po ulong 400
3799global d_cell ulong 18432
3800global d_nm ulong 96
3801
3802note number k of the request
3803fn gi b view uchar 1048576 k ulong to ulong
3804o = add 8 mul k 8
3805ret or rd32 b o shl rd32 b add o 4 32
3806end
3807
3808note number k of the request as a count; a negative number gives a value over every limit
3809fn gu b view uchar 1048576 k ulong to ulong
3810v = gi b k
3811if lt v k_b
3812ret 4294967295
3813end
3814ret sub v k_b
3815end
3816
3817note number k of the answer
3818fn po ob edit uchar 65544 k ulong v ulong to void
3819o = add 8 mul k 8
3820put32 ob o v
3821put32 ob add o 4 shr v 32
3822end
3823
3824note a member's state is worked out, never taken from what it says about itself. With a roster: stopped when it
3825note was killed; else waiting when its own run has ended and working when it is mid-turn; with no transcript to
3826note go on, waiting when it is parked. With no roster: working when it posted within 900 seconds (age, -1 never)
3827fn swstate killed ulong turn ulong wake ulong roster ulong age ulong to ulong
3828if eq killed add k_b 1
3829ret 3
3830end
3831if ne roster add k_b 1
3832if and ge age k_b le age add k_b 900
3833ret 1
3834end
3835ret 2
3836end
3837if eq turn add k_b 2
3838ret 2
3839end
3840if eq turn add k_b 1
3841ret 1
3842end
3843if or eq wake add k_b 2 eq wake add k_b 3
3844ret 2
3845end
3846ret 1
3847end
3848
3849note what needs a look: a failed newest step, or a member that should be working and has not moved for more
3850note than 600 seconds (idle -1: not known)
3851fn swatt state ulong failure ulong idle ulong to ulong
3852if eq state add k_b 3
3853ret 0
3854end
3855if eq failure add k_b 2
3856ret 2
3857end
3858if eq failure add k_b 3
3859ret 3
3860end
3861if and eq state add k_b 1 gt idle add k_b 600
3862ret 1
3863end
3864ret 0
3865end
3866
3867note the Overview group of one member (asks and won: 1 when it asks the owner, when it waits on someone)
3868fn swgroup state ulong att ulong asks ulong won ulong to ulong
3869if eq state add k_b 3
3870ret 4
3871end
3872if or ne att k_b ne asks k_b
3873ret 1
3874end
3875if eq state add k_b 1
3876ret 2
3877end
3878if ne won k_b
3879ret 3
3880end
3881ret 4
3882end
3883
3884note is this post the first row of a visual group? Posts by one sender, next to each other and at most 600
3885note seconds apart, are one group
3886fn swstarts ps ulong pt ulong s ulong t ulong to ulong
3887if or lt s k_b ne s ps
3888ret 1
3889end
3890if or le t k_b le pt k_b
3891ret 0
3892end
3893if or gt t add pt 600 lt t pt
3894ret 1
3895end
3896ret 0
3897end
3898
3899note the n bytes at off, ASCII letters without case, against the wn bytes at w0 of q_roles
3900fn eqrole b view uchar 1048576 off ulong n ulong w0 ulong wn ulong to bool
3901if ne n wn
3902ret false
3903end
3904i = ulong 0
3905while lt i n bound 64
3906if ne lowc ulong get b add off i ulong get q_roles add w0 i
3907ret false
3908end
3909i = add i 1
3910end
3911ret true
3912end
3913
3914note the order of members: by key (small first), the coordinator before the others, then by name (ASCII letters
3915note without case, the shorter first). n members; keys in d_key, roles in d_role, names at d_no, d_nl; order to d_ord
3916fn sworder b view uchar 1048576 n ulong to void
3917cntd = ulong 0
3918for i ulong n
3919pos = cntd
3920while gt pos 0 bound 128
3921o = get d_ord sub pos 1
3922after = false
3923if ne get d_key o get d_key i
3924after = gt get d_key o get d_key i
3925else
3926co = eq get d_role o 1
3927ci = eq get d_role i 1
3928dif = false
3929if co
3930if not ci
3931dif = true
3932end
3933else
3934if ci
3935dif = true
3936end
3937end
3938if dif
3939after = ci
3940else
3941x = get d_no o
3942xl = get d_nl o
3943y = get d_no i
3944yl = get d_nl i
3945k = ulong 0
3946cmp = ulong 1
3947while lt k xl bound 999999
3948if ge k yl
3949break
3950end
3951cx = lowc ulong get b add x k
3952cy = lowc ulong get b add y k
3953if ne cx cy
3954cmp = 0
3955if gt cx cy
3956cmp = 2
3957end
3958break
3959end
3960k = add k 1
3961end
3962if eq cmp 1
3963if gt xl yl
3964cmp = 2
3965end
3966end
3967after = eq cmp 2
3968end
3969end
3970if not after
3971break
3972end
3973put d_ord pos o
3974pos = sub pos 1
3975end
3976put d_ord pos i
3977cntd = add cntd 1
3978end
3979end
3980
3981note op 8: has the member's run stopped? Its newest steps, oldest first: four counts (they must be equal), then
3982note the kinds, the statuses, for a planner step how many tools it called, and which of them was the wait for
3983note posts (-1 none). Ended (2) when the newest planner step called no tool and nothing came after it, or when it
3984note called the wait and that call's result is done; anything newer means mid-turn (1). 0: not known
3985fn swturn b view uchar 1048576 c ulong to ulong
3986if lt c 4
3987ret 0
3988end
3989n = gu b 0
3990if gt n 100000
3991ret 0
3992end
3993if or eq n 0 or ne gi b 1 gi b 0 or ne gi b 2 gi b 0 ne gi b 3 gi b 0
3994ret 0
3995end
3996if ne c add 4 mul n 4
3997ret 0
3998end
3999kd = ulong 4
4000sx = add 4 n
4001tl = add 4 mul n 2
4002wt2 = add 4 mul n 3
4003i = n
4004results = ulong 0
4005looked = ulong 0
4006while gt i 0 bound 512
4007if ge looked 256
4008break
4009end
4010if ne gi b add kd sub i 1 add k_b 2
4011break
4012end
4013results = add results 1
4014i = sub i 1
4015looked = add looked 1
4016end
4017if or eq i 0 ge looked 256
4018ret 1
4019end
4020i = sub i 1
4021if ne gi b add kd i add k_b 1
4022ret 1
4023end
4024tools = gi b add tl i
4025if le tools k_b
4026if eq results 0
4027ret 2
4028end
4029ret 1
4030end
4031wait = gi b add wt2 i
4032if or lt wait k_b ge wait tools
4033ret 1
4034end
4035if lt results sub tools k_b
4036ret 1
4037end
4038if eq gi b add sx add add i 1 sub wait k_b add k_b 1
4039ret 2
4040end
4041ret 1
4042end
4043
4044note op 9: the step that says what the member is doing now: the newest planner step of the current turn that has
4045note a label. Three counts (equal), then kinds, waits and labels. A turn starts after user input or after a wait
4046note for posts. The answer is the step's place, or -1
4047fn swact b view uchar 1048576 c ulong to ulong
4048none = sub k_b 1
4049if lt c 3
4050ret none
4051end
4052n = gu b 0
4053if gt n 100000
4054ret none
4055end
4056if or ne gi b 1 gi b 0 ne gi b 2 gi b 0
4057ret none
4058end
4059if ne c add 3 mul n 3
4060ret none
4061end
4062i = n
4063looked = ulong 0
4064while gt i 0 bound 512
4065if ge looked 256
4066break
4067end
4068kk = gi b add 3 sub i 1
4069if eq kk add k_b 3
4070ret none
4071end
4072if eq kk add k_b 1
4073if ge gi b add add 3 n sub i 1 k_b
4074ret none
4075end
4076if eq gi b add add 3 mul n 2 sub i 1 add k_b 1
4077ret add k_b sub i 1
4078end
4079end
4080i = sub i 1
4081looked = add looked 1
4082end
4083ret none
4084end
4085
4086note op 10: does an error text (t0..t1) say the member ran out of quota or was rate limited? One of the words of
4087note q_words in its first 32768 places, or "429" standing alone
4088fn swquota b view uchar 1048576 t0 ulong t1 ulong to ulong
4089tn = sub t1 t0
4090w0 = ulong 0
4091wi = ulong 0
4092while lt wi len q_words bound 256
4093if eq ulong get q_words wi 124
4094wn = sub wi w0
4095if and gt wn 0 ge tn wn
4096i = ulong 0
4097while le add i wn tn bound 40000
4098if ge i 32768
4099break
4100end
4101k = ulong 0
4102while lt k wn bound 64
4103if ne lowc ulong get b add add t0 i k ulong get q_words add w0 k
4104break
4105end
4106k = add k 1
4107end
4108if eq k wn
4109ret 1
4110end
4111i = add i 1
4112end
4113end
4114w0 = add wi 1
4115end
4116wi = add wi 1
4117end
4118i = ulong 0
4119while le add i 3 tn bound 40000
4120if ge i 32768
4121break
4122end
4123p = add t0 i
4124if and and eq ulong get b p 52 eq ulong get b add p 1 50 eq ulong get b add p 2 57
4125if not namer runeb b p t0 t1
4126if not namer rune b add p 3 t1
4127ret 1
4128end
4129end
4130end
4131i = add i 1
4132end
4133ret 0
4134end
4135
4136note op 11: the role code of a roster member from its role (rl bytes at ro) and its name (nl bytes at no). The
4137note coordinator leads; "narrator" and "monitor", also with "-<digits>" after, are helpers by name; so is any role
4138note other than "worker"
4139fn swrole b view uchar 1048576 ro ulong rl ulong no ulong nl ulong to ulong
4140if eqrole b ro rl 0 11
4141ret 1
4142end
4143plain = eq rl 0
4144if eqrole b ro rl 11 6
4145plain = true
4146end
4147if not plain
4148ret 2
4149end
4150bl = nl
4151pf = cprefix b no nl
4152if gt pf 0
4153bl = pf
4154end
4155if eqrole b no bl 17 8
4156ret 2
4157end
4158if eqrole b no bl 25 7
4159ret 2
4160end
4161ret 0
4162end
4163
4164note op 16: everything the views show about the members. Numbers: 0 1 when there is a roster, 1 now (seconds
4165note since 1970), 2 the members n (96 at most), 3 the posts p (400 at most); nine a member: role, killed, wake,
4166note turn, the last post it read (-1 not known), its last own movement (0 not known), failure, 1 when it is the
4167note person using Hop, the length of its name; then a post each: its number, its time (0 not known), its sender
4168note (-1: not a member), how many others signed and who, how many members it addresses by name and who. The
4169note names follow as bytes. The answer: 0 the newest post number, 1 to 3 the members working, waiting and stopped
4170note (helpers are not counted); a number a post: 1 when it starts a visual group; then eleven lists of n: posts
4171note by each member, its newest post (-1 none), state, attention, idle seconds (-1), unread posts (-1), 1 for a
4172note helper, who it waits on (-1), the post that says so, the post that asks the owner (0 none), its group; then
4173note the Overview order and the Members order. Returns the count of numbers, or 0 for a malformed request
4174fn swderive b view uchar 1048576 c ulong nbytes ulong ob edit uchar 65544 to ulong
4175if lt c 4
4176ret 0
4177end
4178roster = gi b 0
4179now = gi b 1
4180n = gu b 2
4181p = gu b 3
4182if or gt n 96 gt p 400
4183ret 0
4184end
4185q = add 4 mul n 9
4186if gt q c
4187ret 0
4188end
4189no = add 8 mul c 8
4190for m ulong n
4191o = add 4 mul m 9
4192put d_role m gu b o
4193put d_kill m gi b add o 1
4194put d_wake m gi b add o 2
4195put d_turn m gi b add o 3
4196put d_lr m gi b add o 4
4197put d_lm m gi b add o 5
4198put d_fail m gi b add o 6
4199put d_own m gi b add o 7
4200l = gu b add o 8
4201if gt l 1048576
4202ret 0
4203end
4204put d_no m no
4205put d_nl m l
4206no = add no l
4207put d_cnt m 0
4208put d_last m 1000
4209end
4210if gt no add add 8 mul c 8 nbytes
4211ret 0
4212end
4213for i ulong p
4214if gt add q 4 c
4215ret 0
4216end
4217put d_po i q
4218nw = gu b add q 3
4219if gt nw 4
4220ret 0
4221end
4222if gt add add q 5 nw c
4223ret 0
4224end
4225nd = gu b add add q 4 nw
4226if gt nd 96
4227ret 0
4228end
4229q = add add add q 5 nw nd
4230if gt q c
4231ret 0
4232end
4233end
4234head = k_b
4235if gt p 0
4236head = gi b get d_po sub p 1
4237end
4238po ob 0 head
4239for i ulong p
4240q = get d_po i
4241s = gi b add q 2
4242sg = ulong 1
4243if gt i 0
4244pq = get d_po sub i 1
4245sg = swstarts gi b add pq 2 gi b add pq 1 s gi b add q 1
4246end
4247po ob add 4 i add k_b sg
4248if and ge s k_b lt s add k_b n
4249sm = sub s k_b
4250put d_cnt sm add get d_cnt sm 1
4251put d_last sm i
4252end
4253nw = gu b add q 3
4254for k ulong nw
4255w = gi b add add q 4 k
4256if ne w s
4257if and ge w k_b lt w add k_b n
4258wm = sub w k_b
4259put d_cnt wm add get d_cnt wm 1
4260put d_last wm i
4261end
4262end
4263end
4264end
4265base = add 4 p
4266for m ulong n
4267last = get d_last m
4268age = sub k_b 1
4269if lt last 1000
4270pt = gi b add get d_po last 1
4271if gt pt k_b
4272age = k_b
4273if gt now pt
4274age = add k_b sub now pt
4275end
4276end
4277end
4278st = swstate get d_kill m get d_turn m get d_wake m roster age
4279idle = sub k_b 1
4280if eq roster add k_b 1
4281lm = get d_lm m
4282if gt lm k_b
4283idle = k_b
4284if gt now lm
4285idle = add k_b sub now lm
4286end
4287end
4288end
4289put d_state m st
4290put d_att m swatt add k_b st get d_fail m idle
4291unr = sub k_b 1
4292if eq roster add k_b 1
4293lr = get d_lr m
4294if ge lr k_b
4295unr = k_b
4296if gt head lr
4297unr = add k_b sub head lr
4298end
4299end
4300end
4301po ob add base m add k_b get d_cnt m
4302lp = sub k_b 1
4303if lt last 1000
4304lp = add k_b last
4305end
4306po ob add add base n m lp
4307po ob add add base mul n 2 m add k_b st
4308po ob add add base mul n 3 m add k_b get d_att m
4309po ob add add base mul n 4 m idle
4310po ob add add base mul n 5 m unr
4311hp = ulong 0
4312if eq get d_role m 2
4313hp = 1
4314end
4315po ob add add base mul n 6 m add k_b hp
4316end
4317working = ulong 0
4318waiting = ulong 0
4319stopped = ulong 0
4320for m ulong n
4321on = ulong 1000
4322seq = k_b
4323you = k_b
4324last = get d_last m
4325if and lt last 1000 ne get d_state m 3
4326q = get d_po last
4327nw = gu b add q 3
4328nd = gu b add add q 4 nw
4329t0 = add add q 5 nw
4330if gt nd 0
4331answered = false
4332j = add last 1
4333while lt j p bound 512
4334if answered
4335break
4336end
4337qj = get d_po j
4338sj = gi b add qj 2
4339nwj = gu b add qj 3
4340for k ulong nd
4341tk = gi b add t0 k
4342if eq tk sj
4343answered = true
4344end
4345for k2 ulong nwj
4346if eq tk gi b add add qj 4 k2
4347answered = true
4348end
4349end
4350end
4351j = add j 1
4352end
4353if not answered
4354for k ulong nd
4355tk = gi b add t0 k
4356if and ge tk k_b lt tk add k_b n
4357tm2 = sub tk k_b
4358if eq get d_own tm2 add k_b 1
4359you = gi b q
4360else
4361if and eq on 1000 ne get d_state tm2 3
4362on = tm2
4363end
4364end
4365end
4366end
4367if lt on 1000
4368seq = gi b q
4369end
4370end
4371end
4372end
4373wo = sub k_b 1
4374won = ulong 0
4375if lt on 1000
4376wo = add k_b on
4377won = 1
4378end
4379asks = ulong 0
4380if gt you k_b
4381asks = 1
4382end
4383g = swgroup add k_b get d_state m add k_b get d_att m add k_b asks add k_b won
4384put d_grp m g
4385po ob add add base mul n 7 m wo
4386po ob add add base mul n 8 m seq
4387po ob add add base mul n 9 m you
4388po ob add add base mul n 10 m add k_b g
4389if ne get d_role m 2
4390if eq get d_state m 1
4391working = add working 1
4392else
4393if eq get d_state m 2
4394waiting = add waiting 1
4395else
4396stopped = add stopped 1
4397end
4398end
4399end
4400end
4401po ob 1 add k_b working
4402po ob 2 add k_b waiting
4403po ob 3 add k_b stopped
4404for pass2 ulong 2
4405for m ulong n
4406v = get d_grp m
4407if eq pass2 1
4408v = get d_state m
4409end
4410if ne roster add k_b 1
4411v = mul v 2
4412if eq get d_cnt m 0
4413v = add v 1
4414end
4415end
4416put d_key m v
4417end
4418sworder b n
4419for m ulong n
4420po ob add add base mul n add 11 pass2 m add k_b get d_ord m
4421end
4422end
4423ret add base mul n 13
4424end
4425
4426note op 12: who addressed whom in the first posts, for the graph. Numbers: the members n, upTo, how many posts
4427note have a sender, how many helper flags, how many posts have their co-signers, their addressed members and
4428note their to-all flag; then the helper flags (n); then a post each: sender, how many co-signers (4 at most) and
4429note who, how many addressed members and who, 1 when it is to all. Helpers are left out. The answer is bytes,
4430note six a pair in order of sender then receiver: from, to, how many posts named the receiver (16-bit), how many
4431note reached it only because the post was for everyone (16-bit). Returns the reply length
4432fn swedges b view uchar 1048576 c ulong ob edit uchar 65544 to ulong
4433named = new ulong 96 0
4434if lt c 7
4435ret 0
4436end
4437nn = gi b 0
4438if or le nn k_b gt nn add k_b 96
4439ret 0
4440end
4441n = sub nn k_b
4442upto = gi b 1
4443posts = gu b 2
4444if gt posts 100000
4445ret 0
4446end
4447if lt upto add k_b posts
4448posts = ulong 0
4449if gt upto k_b
4450posts = sub upto k_b
4451end
4452end
4453if or gt posts 400 ne gi b 3 nn
4454ret 0
4455end
4456if or or lt gi b 4 add k_b posts lt gi b 5 add k_b posts lt gi b 6 add k_b posts
4457ret 0
4458end
4459for z ulong mul n n
4460put d_cell z 0
4461put d_cell add 9216 z 0
4462end
4463hb = ulong 7
4464q = add 7 n
4465if gt q c
4466ret 0
4467end
4468for i ulong posts
4469if gt add q 2 c
4470ret 0
4471end
4472s0 = gi b q
4473nw = gu b add q 1
4474if gt nw 4
4475ret 0
4476end
4477if gt add add q 3 nw c
4478ret 0
4479end
4480nd = gu b add add q 2 nw
4481if gt nd 96
4482ret 0
4483end
4484dq = add add q 3 nw
4485if gt add add dq nd 1 c
4486ret 0
4487end
4488tall = gi b add dq nd
4489for s ulong add nw 1
4490from = s0
4491if gt s 0
4492from = gi b add add q 2 sub s 1
4493end
4494okf = and ge from k_b lt from add k_b n
4495if okf
4496if ne gi b add hb sub from k_b k_b
4497okf = false
4498end
4499end
4500if okf
4501if gt s 0
4502if eq from s0
4503okf = false
4504end
4505end
4506end
4507if okf
4508f = sub from k_b
4509for z ulong n
4510put named z 0
4511end
4512for k ulong nd
4513if lt k n
4514tv = gi b add dq k
4515if and ge tv k_b lt tv add k_b n
4516tt = sub tv k_b
4517if and ne tt f eq gi b add hb tt k_b
4518if eq get named tt 0
4519put named tt 1
4520put d_cell add mul f n tt add get d_cell add mul f n tt 1
4521end
4522end
4523end
4524end
4525end
4526if eq tall add k_b 1
4527for tt ulong n
4528if and ne tt f eq gi b add hb tt k_b
4529if eq get named tt 0
4530put d_cell add 9216 add mul f n tt add get d_cell add 9216 add mul f n tt 1
4531end
4532end
4533end
4534end
4535end
4536end
4537q = add add dq nd 1
4538end
4539o = ulong 8
4540for cell ulong mul n n
4541dv = get d_cell cell
4542av = get d_cell add 9216 cell
4543if gt add dv av 0
4544put ob o uchar div cell n
4545put ob add o 1 uchar rem cell n
4546put ob add o 2 uchar and dv 255
4547put ob add o 3 uchar and shr dv 8 255
4548put ob add o 4 uchar and av 255
4549put ob add o 5 uchar and shr av 8 255
4550o = add o 6
4551end
4552end
4553ret sub o 8
4554end
4555
4556note op 14: which members to draw when there are too many for one picture: the keep members with the most posts
4557note to or from others (the earlier member wins a tie). Numbers: the members n, 1 to count posts for everyone
4558note too, keep, how many edge numbers follow, then the edges, five numbers a row: from, to, count, direct, to all.
4559note The answer is a byte a member, 1 when it is picked; a member with no line is never picked
4560fn swbusy b view uchar 1048576 c ulong ob edit uchar 65544 to ulong
4561weight = new ulong 96 0
4562flag = new ulong 96 0
4563if lt c 4
4564ret 0
4565end
4566nn = gi b 0
4567if or le nn k_b gt nn add k_b 96
4568ret 0
4569end
4570n = sub nn k_b
4571ne2 = gu b 3
4572if ne c add 4 ne2
4573ret 0
4574end
4575e = ulong 0
4576while lt add e 4 ne2 bound 16384
4577if ge e 46080
4578break
4579end
4580from = gi b add 4 e
4581tv = gi b add 5 e
4582cv = gi b add 7 e
4583if eq gi b 1 add k_b 1
4584cv = gi b add 6 e
4585end
4586if and and ge from k_b lt from add k_b n and ge tv k_b lt tv add k_b n
4587if ge cv k_b
4588put weight sub from k_b add get weight sub from k_b sub cv k_b
4589put weight sub tv k_b add get weight sub tv k_b sub cv k_b
4590end
4591end
4592e = add e 5
4593end
4594keep = gi b 2
4595picked = ulong 0
4596while lt picked n bound 128
4597if ge add k_b picked keep
4598break
4599end
4600best = ulong 1000
4601for m ulong n
4602if and eq get flag m 0 gt get weight m 0
4603if eq best 1000
4604best = m
4605else
4606if gt get weight m get weight best
4607best = m
4608end
4609end
4610end
4611end
4612if eq best 1000
4613break
4614end
4615put flag best 1
4616picked = add picked 1
4617end
4618for m ulong n
4619put ob add 8 m uchar get flag m
4620end
4621ret n
4622end
4623
4624note op 13: how many of the first posts each member sent to everyone. Numbers: the members n, upTo, how many posts
4625note have a sender and how many have a to-all flag, then a post each: sender, 1 when it is to all. The answer is n
4626note numbers (none when n is not 1 to 96). Returns the count of numbers
4627fn swbroad b view uchar 1048576 c ulong ob edit uchar 65544 to ulong
4628outv = new ulong 96 0
4629if lt c 4
4630ret 0
4631end
4632nn = gi b 0
4633if or le nn k_b gt nn add k_b 96
4634ret 0
4635end
4636n = sub nn k_b
4637posts = gu b 2
4638if gt posts 100000
4639posts = ulong 100000
4640end
4641upto = gi b 1
4642if lt upto add k_b posts
4643posts = ulong 0
4644if gt upto k_b
4645posts = sub upto k_b
4646end
4647end
4648na = gu b 3
4649i = ulong 0
4650while lt i posts bound 512
4651if or ge i 400 ge i na
4652break
4653end
4654if gt add 6 mul i 2 c
4655break
4656end
4657s = gi b add 4 mul i 2
4658if eq gi b add 5 mul i 2 add k_b 1
4659if and ge s k_b lt s add k_b n
4660put outv sub s k_b add get outv sub s k_b 1
4661end
4662end
4663i = add i 1
4664end
4665for m ulong n
4666po ob m add k_b get outv m
4667end
4668ret n
4669end
4670
4671note ---- the one box: which rows it shows for a typed text, and in which order (kind 7 op 17) ----
4672note Numbers: 0 the characters of the typed text (trimmed, lower case), 1 its bytes, 2 a web address (0 no, 1 typed
4673note with its scheme, 2 bare), 3 1 when this Mac has finished searching its files, 4 1 when a file has exactly that
4674note name, 5 1 for a question, 6 1 when a sentence may go to the agent; 7 to 12 the counts of apps, files,
4675note screens, commands, accounts and copied things; then four an app (how well it matched, how much it is used,
4676note its lift from habit, 1 when it was in front before), three a file (its match, its use, 1 when it is an app
4677note already listed), two an account (1 when its name holds the text, 1 when it starts with it), one a copied
4678note thing (1 when pinned); then for each screen and each command a count of words and their lengths. Bytes: the
4679note text, then those words. The rows: the 8 best apps (match + 40 + use + half the lift + 10 for the one in
4680note front before); the address (150 with a scheme; bare, only after the file search: 95, or 3 when a file has
4681note that name); from 2 characters a screen (230 named, 125 a word starts so), a command (220; 110 from 3
4682note characters when a word starts so) and each matching account (95 when it starts so, else 70); the first 8
4683note copied things (85 less the place, 10 more when pinned); the first 12 files that are not apps (match + use);
4684note Ask (1000 for a question, else 2); the agent (999 when nothing else matched, it is not a question and a
4685note sentence may go to it, else 1). Highest first; equal rows stay in this order.
4686note The answer: the count of rows, then four numbers a row: its kind (1 app, 2 address, 3 screen, 4 command,
4687note 5 account, 6 copied, 7 file, 8 ask, 9 agent), its place in its list, its score, 1 for the promoted agent
4688global r_kind ulong 1024
4689global r_idx ulong 1024
4690global r_score ulong 1024
4691global r_flag ulong 1024
4692global r_as ulong 2048
4693global r_ao ulong 2048
4694
4695fn rkadd n ulong kind ulong idx ulong score ulong flag ulong to ulong
4696if ge n 1024
4697ret n
4698end
4699put r_kind n kind
4700put r_idx n idx
4701put r_score n score
4702put r_flag n flag
4703ret add n 1
4704end
4705
4706note half of a number as it travels, toward zero
4707fn rkhalf v ulong to ulong
4708if ge v k_b
4709ret add k_b div sub v k_b 2
4710end
4711ret sub k_b div sub k_b v 2
4712end
4713
4714note the wl bytes at w against the ll bytes of the typed text at lo: equal (md 0), or starting with it (md 1)
4715fn rkword b view uchar 1048576 w ulong wl ulong lo ulong ll ulong md ulong to bool
4716if eq md 0
4717if ne wl ll
4718ret false
4719end
4720else
4721if lt wl ll
4722ret false
4723end
4724end
4725i = ulong 0
4726while lt i ll bound 999999
4727if ne ulong get b add w i ulong get b add lo i
4728ret false
4729end
4730i = add i 1
4731end
4732ret true
4733end
4734
4735note the n rows, highest score first (equal rows stay in their order), as the answer: the count, then four numbers
4736note a row (kind, place, score, flag); how many numbers that is
4737fn rkout n ulong ob edit uchar 65544 to ulong
4738for i ulong n
4739s = get r_score i
4740pos = i
4741while gt pos 0 bound 2048
4742p = get r_ao sub pos 1
4743if ge get r_score p s
4744break
4745end
4746put r_ao pos p
4747pos = sub pos 1
4748end
4749put r_ao pos i
4750end
4751po ob 0 add k_b n
4752for i ulong n
4753x = get r_ao i
4754o = add 1 mul i 4
4755po ob o add k_b get r_kind x
4756po ob add o 1 add k_b get r_idx x
4757po ob add o 2 get r_score x
4758po ob add o 3 add k_b get r_flag x
4759end
4760ret add 1 mul n 4
4761end
4762
4763fn swrank b view uchar 1048576 c ulong nbytes ulong ob edit uchar 65544 to ulong
4764if lt c 13
4765ret 0
4766end
4767lcn = gu b 0
4768ll = gu b 1
4769na = gu b 7
4770nf = gu b 8
4771ns = gu b 9
4772nc = gu b 10
4773nacc = gu b 11
4774ncl = gu b 12
4775if or or gt na 2048 gt nf 4000 or gt ns 32 gt nc 32
4776ret 0
4777end
4778if or gt nacc 800 or gt ncl 64 gt ll 100000
4779ret 0
4780end
4781pa = ulong 13
4782pf = add pa mul na 4
4783pacc = add pf mul nf 3
4784pcl = add pacc mul nacc 2
4785q = add pcl ncl
4786if gt q c
4787ret 0
4788end
4789lo = add 8 mul c 8
4790tend = add lo nbytes
4791wp = add lo ll
4792if gt wp tend
4793ret 0
4794end
4795n = ulong 0
4796for i ulong na
4797o = add pa mul i 4
4798s = sub add add add gi b o gi b add o 1 rkhalf gi b add o 2 40 mul 2 k_b
4799if eq gi b add o 3 add k_b 1
4800s = add s 10
4801end
4802put r_as i s
4803pos = i
4804while gt pos 0 bound 4096
4805p = get r_ao sub pos 1
4806if ge get r_as p s
4807break
4808end
4809put r_ao pos p
4810pos = sub pos 1
4811end
4812put r_ao pos i
4813end
4814for i ulong na
4815if lt i 8
4816n = rkadd n 1 get r_ao i get r_as get r_ao i 0
4817end
4818end
4819adr = gi b 2
4820if eq adr add k_b 1
4821n = rkadd n 2 0 add k_b 150 0
4822end
4823if and eq adr add k_b 2 eq gi b 3 add k_b 1
4824sc = add k_b 95
4825if eq gi b 4 add k_b 1
4826sc = add k_b 3
4827end
4828n = rkadd n 2 0 sc 0
4829end
4830for pass3 ulong 2
4831cntw = ns
4832if eq pass3 1
4833cntw = nc
4834end
4835for k ulong cntw
4836if ge q c
4837ret 0
4838end
4839nw = gu b q
4840q = add q 1
4841if gt nw 64
4842ret 0
4843end
4844exact = false
4845pre = false
4846for w ulong nw
4847if ge q c
4848ret 0
4849end
4850wl = gu b q
4851q = add q 1
4852if gt add wp wl tend
4853ret 0
4854end
4855if rkword b wp wl lo ll 0
4856exact = true
4857end
4858if rkword b wp wl lo ll 1
4859pre = true
4860end
4861wp = add wp wl
4862end
4863if ge lcn 2
4864if eq pass3 0
4865if exact
4866n = rkadd n 3 k add k_b 230 0
4867else
4868if pre
4869n = rkadd n 3 k add k_b 125 0
4870end
4871end
4872else
4873if exact
4874n = rkadd n 4 k add k_b 220 0
4875else
4876if and pre ge lcn 3
4877n = rkadd n 4 k add k_b 110 0
4878end
4879end
4880end
4881end
4882end
4883end
4884if ge lcn 2
4885for i ulong nacc
4886if eq gi b add pacc mul i 2 add k_b 1
4887sc = add k_b 70
4888if eq gi b add add pacc mul i 2 1 add k_b 1
4889sc = add k_b 95
4890end
4891n = rkadd n 5 i sc 0
4892end
4893end
4894end
4895for i ulong ncl
4896if lt i 8
4897sc = sub add k_b 85 i
4898if eq gi b add pcl i add k_b 1
4899sc = add sc 10
4900end
4901n = rkadd n 6 i sc 0
4902end
4903end
4904shown = ulong 0
4905for i ulong nf
4906o = add pf mul i 3
4907if and ne gi b add o 2 add k_b 1 lt shown 12
4908n = rkadd n 7 i sub add gi b o gi b add o 1 k_b 0
4909shown = add shown 1
4910end
4911end
4912nothing = eq n 0
4913quest = eq gi b 5 add k_b 1
4914sc = add k_b 2
4915if quest
4916sc = add k_b 1000
4917end
4918n = rkadd n 8 0 sc 0
4919prom = ulong 0
4920sc = add k_b 1
4921if and and not quest nothing eq gi b 6 add k_b 1
4922prom = 1
4923sc = add k_b 999
4924end
4925n = rkadd n 9 0 sc prom
4926ret rkout n ob
4927end
4928
4929note ---- the one box before anything is typed: what to offer (kind 7 op 18) ----
4930note Numbers: 0 1 when something was copied, 1 how many seconds ago, 2 1 when it is a web address written with
4931note http, 3 1 when the app in front is a browser, 4 how many other copied things follow (at most 20), 5 1 when
4932note the clipboard history is paused, 6 the count of apps; then six an app: its lift from the app in front, its
4933note lift from the hour, how much it is used, 1 when it is running, 1 when it was in front before, and its
4934note points for being in front lately. The apps come in the order of their ids, which settles equal scores.
4935note The rows: the copied thing (130 under a minute old, 95 under ten, else 70) and, for an address, a row to
4936note open it (5 more, or 5 less when a browser is in front); the six best apps among those with a lift, some
4937note use, running or in front before (40 + both lifts + a quarter of the use + 45 in front before + 8 running +
4938note the points for lately); the other copied things (38 less the place); the clipboard screen at 39 when the
4939note history is paused. Highest first; equal rows stay in this order.
4940note The answer: the count of rows, then four numbers a row: its kind (1 app, 2 address, 3 the clipboard
4941note screen, 6 copied), its place (an app's place in the list; 0 the newest copied thing, then 1 and up), its
4942note score, and why it is offered (0 nothing said, 1 just copied, 2 the last thing copied, 3 a copied address,
4943note 4 often opened from here, 5 just here, 6 often opened around now, 7 among the most used, 8 running now,
4944note 9 the history is paused)
4945global s_ps ulong 8
4946global s_pi ulong 8
4947global s_pw ulong 8
4948
4949fn swsuggest b view uchar 1048576 c ulong ob edit uchar 65544 to ulong
4950if lt c 7
4951ret 0
4952end
4953rest = gu b 4
4954na = gu b 6
4955if or gt na 2048 gt rest 20
4956ret 0
4957end
4958if ne c add 7 mul na 6
4959ret 0
4960end
4961n = ulong 0
4962if eq gi b 0 add k_b 1
4963age = gi b 1
4964s = ulong 70
4965why = ulong 2
4966if lt age add k_b 600
4967s = 95
4968why = 1
4969end
4970if lt age add k_b 60
4971s = 130
4972end
4973n = rkadd n 6 0 add k_b s why
4974if eq gi b 2 add k_b 1
4975if eq gi b 3 add k_b 1
4976n = rkadd n 2 0 add k_b sub s 5 3
4977else
4978n = rkadd n 2 0 add k_b add s 5 3
4979end
4980end
4981end
4982cnt = ulong 0
4983for i ulong na
4984o = add 7 mul i 6
4985lf = gu b o
4986lh = gu b add o 1
4987used = gu b add o 2
4988run = eq gi b add o 3 add k_b 1
4989prev = eq gi b add o 4 add k_b 1
4990lately = gu b add o 5
4991if or or gt add lf lh 0 gt used 0 or run prev
4992sc = add add add 40 lf lh div used 4
4993if prev
4994sc = add sc 45
4995end
4996if run
4997sc = add sc 8
4998end
4999sc = add sc lately
5000why = ulong 8
5001if gt used 0
5002why = 7
5003end
5004if gt lh 0
5005why = 6
5006end
5007if prev
5008why = 5
5009end
5010if gt lf 0
5011why = 4
5012end
5013keep = true
5014pos = cnt
5015if eq cnt 6
5016if le sc get s_ps 5
5017keep = false
5018end
5019pos = 5
5020else
5021cnt = add cnt 1
5022end
5023if keep
5024while gt pos 0 bound 8
5025if ge get s_ps sub pos 1 sc
5026break
5027end
5028put s_ps pos get s_ps sub pos 1
5029put s_pi pos get s_pi sub pos 1
5030put s_pw pos get s_pw sub pos 1
5031pos = sub pos 1
5032end
5033put s_ps pos sc
5034put s_pi pos i
5035put s_pw pos why
5036end
5037end
5038end
5039for j ulong cnt
5040n = rkadd n 1 get s_pi j add k_b get s_ps j get s_pw j
5041end
5042for i ulong rest
5043n = rkadd n 6 add 1 i add k_b sub 38 i 0
5044end
5045if eq gi b 5 add k_b 1
5046n = rkadd n 3 0 add k_b 39 9
5047end
5048ret rkout n ob
5049end
5050
5051note ---- habits: how much an app is lifted by where and when it is usually opened (kind 7 op 19) ----
5052note Numbers: 0 the hour now, 1 1 when an app is in front, 2 the count of apps, 3 the count of remembered
5053note launches; then three a launch: 1 when it was made from the app now in front, its hour, and which app it
5054note opened (its place in the list, or -1 for an app not in it). A habit counts from the second time. An app's
5055note lift from the app in front is 60 times its share of the launches made from there; its lift from the hour
5056note is 25 times its share of the launches within an hour of now (23 and 0 are an hour apart).
5057note The answer: the count of apps, then two numbers an app: the lift from the app in front, the lift from the hour
5058fn swlifts b view uchar 1048576 c ulong ob edit uchar 65544 to ulong
5059if lt c 4
5060ret 0
5061end
5062hour = gi b 0
5063front = eq gi b 1 add k_b 1
5064na = gu b 2
5065nl = gu b 3
5066if or gt na 2048 gt nl 4096
5067ret 0
5068end
5069if ne c add 4 mul nl 3
5070ret 0
5071end
5072for i ulong na
5073put r_as i 0
5074put r_ao i 0
5075end
5076ft = ulong 0
5077nt = ulong 0
5078for j ulong nl
5079o = add 4 mul j 3
5080here = and front eq gi b o add k_b 1
5081h = gi b add o 1
5082d = ulong 0
5083if ge h hour
5084d = sub h hour
5085else
5086d = sub hour h
5087end
5088nearh = or le d 1 ge d 23
5089a = gi b add o 2
5090ix = na
5091if ge a k_b
5092if lt sub a k_b na
5093ix = sub a k_b
5094end
5095end
5096if here
5097ft = add ft 1
5098if lt ix na
5099put r_as ix add get r_as ix 1
5100end
5101end
5102if nearh
5103nt = add nt 1
5104if lt ix na
5105put r_ao ix add get r_ao ix 1
5106end
5107end
5108end
5109po ob 0 add k_b na
5110for i ulong na
5111f = ulong 0
5112if ge get r_as i 2
5113f = div mul 60 get r_as i ft
5114end
5115g = ulong 0
5116if ge get r_ao i 2
5117g = div mul 25 get r_ao i nt
5118end
5119po ob add 1 mul i 2 add k_b f
5120po ob add 2 mul i 2 add k_b g
5121end
5122ret add 1 mul na 2
5123end
5124
5125note ---- AES-256-GCM, for Hop's encrypted clipboard history (kind 7 op 20) ----
5126note The history is sealed as CryptoKit's AES.GCM seals it: a 256-bit key, a 12-byte nonce, no added data, a
5127note 16-byte tag. This is that cipher in Omega: AES by its definition (the S-box is worked out, not listed), the
5128note counter mode, and the tag by GHASH with a table of 16 multiples of the hash key. The work is done on
5129note globals: the key in c_k, the nonce in c_n, the data in c_d (in place, 16 MiB at most), the tag in c_tg. fn gcunlock checks
5130note the tag over the whole data before any of it is unsealed, and compares all 16 bytes whatever they are. It is
5131note not written to run in the same time for every key (the tables are indexed by secret bytes): it is for
5132note files on the person's own Mac, not for a service others can time.
5133note Request: two numbers (1 to seal, 0 to unseal; the count of data bytes, 4096 at most), then the bytes: the
5134note key, the nonce, the data, and to unseal the tag. Answer to unseal: 1 and the data's bytes, or 0 alone when
5135note the tag is not the data's. Answer to seal: 1, the sealed bytes, the 16 bytes of the tag.
5136global c_sb uchar 256
5137global c_m2 uchar 256
5138global c_l4 ulong 16
5139global c_rd ulong 1
5140global c_k uchar 32
5141global c_n uchar 12
5142global c_tg uchar 16
5143global c_rk uchar 240
5144global c_st uchar 16
5145global c_tm uchar 16
5146global c_y uchar 16
5147global c_x uchar 16
5148global c_hh ulong 16
5149global c_hl ulong 16
5150global c_d uchar 16777216
5151
5152note the tables that do not depend on the key: the S-box (the inverse in the field, then the affine step), the
5153note doubling in the field, and the 16 reductions of GHASH
5154fn gcinit to void
5155if eq get c_rd 0 1
5156ret
5157end
5158p = ulong 1
5159q = ulong 1
5160for i ulong 255
5161t = xor p shl p 1
5162if ne and p 128 0
5163t = xor t 27
5164end
5165p = and t 255
5166q = and xor q shl q 1 255
5167q = and xor q shl q 2 255
5168q = and xor q shl q 4 255
5169if ne and q 128 0
5170q = xor q 9
5171end
5172r1 = and or shl q 1 shr q 7 255
5173r2 = and or shl q 2 shr q 6 255
5174r3 = and or shl q 3 shr q 5 255
5175r4 = and or shl q 4 shr q 4 255
5176x = xor xor xor xor q r1 r2 r3 r4
5177put c_sb p uchar xor x 99
5178end
5179put c_sb 0 99
5180for i ulong 256
5181d = shl i 1
5182if ne and i 128 0
5183d = xor d 27
5184end
5185put c_m2 i uchar and d 255
5186end
5187put c_l4 0 0
5188put c_l4 1 7200
5189put c_l4 2 14400
5190put c_l4 3 9312
5191put c_l4 4 28800
5192put c_l4 5 27808
5193put c_l4 6 18624
5194put c_l4 7 21728
5195put c_l4 8 57600
5196put c_l4 9 64800
5197put c_l4 10 55616
5198put c_l4 11 50528
5199put c_l4 12 37248
5200put c_l4 13 36256
5201put c_l4 14 43456
5202put c_l4 15 46560
5203put c_rd 0 1
5204end
5205
5206note the cipher on the 16 bytes of c_st, with the round keys of c_rk
5207fn gcblk to void
5208for i ulong 16
5209put c_st i uchar xor ulong get c_st i ulong get c_rk i
5210end
5211for r ulong 14
5212rk = mul add r 1 16
5213for cc ulong 4
5214for w ulong 4
5215put c_tm add mul cc 4 w get c_sb ulong get c_st add mul and add cc w 3 4 w
5216end
5217end
5218if lt r 13
5219for cc ulong 4
5220o = mul cc 4
5221a0 = ulong get c_tm o
5222a1 = ulong get c_tm add o 1
5223a2 = ulong get c_tm add o 2
5224a3 = ulong get c_tm add o 3
5225d0 = ulong get c_m2 a0
5226d1 = ulong get c_m2 a1
5227d2 = ulong get c_m2 a2
5228d3 = ulong get c_m2 a3
5229put c_st o uchar xor xor xor xor xor d0 d1 a1 a2 a3 ulong get c_rk add rk o
5230put c_st add o 1 uchar xor xor xor xor xor a0 d1 d2 a2 a3 ulong get c_rk add rk add o 1
5231put c_st add o 2 uchar xor xor xor xor xor a0 a1 d2 d3 a3 ulong get c_rk add rk add o 2
5232put c_st add o 3 uchar xor xor xor xor xor d0 a0 a1 a2 d3 ulong get c_rk add rk add o 3
5233end
5234else
5235for i ulong 16
5236put c_st i uchar xor ulong get c_tm i ulong get c_rk add rk i
5237end
5238end
5239end
5240end
5241
5242note the key of c_k: its 15 round keys into c_rk, and the 16 multiples of the hash key (the cipher of 16 zero
5243note bytes) into c_hh and c_hl
5244fn gckey to void
5245gcinit
5246for i ulong 32
5247put c_rk i get c_k i
5248end
5249rc = ulong 1
5250for w ulong 52
5251i = add w 8
5252o = mul i 4
5253t0 = ulong get c_rk sub o 4
5254t1 = ulong get c_rk sub o 3
5255t2 = ulong get c_rk sub o 2
5256t3 = ulong get c_rk sub o 1
5257if eq and i 7 0
5258u0 = xor ulong get c_sb t1 rc
5259u1 = ulong get c_sb t2
5260u2 = ulong get c_sb t3
5261u3 = ulong get c_sb t0
5262rc = ulong get c_m2 rc
5263t0 = u0
5264t1 = u1
5265t2 = u2
5266t3 = u3
5267end
5268if eq and i 7 4
5269t0 = ulong get c_sb t0
5270t1 = ulong get c_sb t1
5271t2 = ulong get c_sb t2
5272t3 = ulong get c_sb t3
5273end
5274put c_rk o uchar xor ulong get c_rk sub o 32 t0
5275put c_rk add o 1 uchar xor ulong get c_rk sub o 31 t1
5276put c_rk add o 2 uchar xor ulong get c_rk sub o 30 t2
5277put c_rk add o 3 uchar xor ulong get c_rk sub o 29 t3
5278end
5279for i ulong 16
5280put c_st i 0
5281end
5282gcblk
5283vh = ulong 0
5284vl = ulong 0
5285for i ulong 8
5286vh = or shl vh 8 ulong get c_st i
5287vl = or shl vl 8 ulong get c_st add 8 i
5288end
5289put c_hh 0 0
5290put c_hl 0 0
5291put c_hh 8 vh
5292put c_hl 8 vl
5293ix = ulong 4
5294for s ulong 3
5295tt = ulong 0
5296if ne and vl 1 0
5297tt = 16212958658533785600
5298end
5299vl = or shl vh 63 shr vl 1
5300vh = xor shr vh 1 tt
5301put c_hl ix vl
5302put c_hh ix vh
5303ix = shr ix 1
5304end
5305ix = 2
5306for s ulong 3
5307for j ulong sub ix 1
5308jj = add j 1
5309put c_hh add ix jj xor get c_hh ix get c_hh jj
5310put c_hl add ix jj xor get c_hl ix get c_hl jj
5311end
5312ix = shl ix 1
5313end
5314end
5315
5316note c_y times the hash key, in the field of GHASH
5317fn gcmul to void
5318nlo = and ulong get c_y 15 15
5319zh = get c_hh nlo
5320zl = get c_hl nlo
5321for s ulong 16
5322bv = ulong get c_y sub 15 s
5323nlo = and bv 15
5324nhi = shr bv 4
5325if ne s 0
5326r4 = and zl 15
5327zl = or shl zh 60 shr zl 4
5328zh = xor shr zh 4 shl get c_l4 r4 48
5329zh = xor zh get c_hh nlo
5330zl = xor zl get c_hl nlo
5331end
5332r4 = and zl 15
5333zl = or shl zh 60 shr zl 4
5334zh = xor shr zh 4 shl get c_l4 r4 48
5335zh = xor zh get c_hh nhi
5336zl = xor zl get c_hl nhi
5337end
5338for i ulong 8
5339sh = mul sub 7 i 8
5340put c_y i uchar and shr zh sh 255
5341put c_y add 8 i uchar and shr zl sh 255
5342end
5343end
5344
5345note the tag of the n sealed bytes of c_d under the key and the nonce, into c_x
5346fn gctag n ulong to void
5347for i ulong 16
5348put c_y i 0
5349end
5350nb = div add n 15 16
5351bk = ulong 0
5352for seg ulong 17
5353while and lt bk nb lt bk mul add seg 1 65536 bound 70000
5354o = mul bk 16
5355m = sub n o
5356if gt m 16
5357m = 16
5358end
5359for j ulong m bound 16
5360put c_y j uchar xor ulong get c_y j ulong get c_d add o j
5361end
5362gcmul
5363bk = add bk 1
5364end
5365end
5366bits = mul n 8
5367for j ulong 8
5368put c_y add 8 j uchar xor ulong get c_y add 8 j and shr bits mul sub 7 j 8 255
5369end
5370gcmul
5371for i ulong 12
5372put c_st i get c_n i
5373end
5374put c_st 12 0
5375put c_st 13 0
5376put c_st 14 0
5377put c_st 15 1
5378gcblk
5379for i ulong 16
5380put c_x i uchar xor ulong get c_st i ulong get c_y i
5381end
5382end
5383
5384note the n bytes of c_d through the counter mode (sealing and unsealing are the same)
5385fn gcctr n ulong to void
5386ctr = ulong 2
5387nb = div add n 15 16
5388bk = ulong 0
5389for seg ulong 17
5390while and lt bk nb lt bk mul add seg 1 65536 bound 70000
5391for i ulong 12
5392put c_st i get c_n i
5393end
5394put c_st 12 uchar and shr ctr 24 255
5395put c_st 13 uchar and shr ctr 16 255
5396put c_st 14 uchar and shr ctr 8 255
5397put c_st 15 uchar and ctr 255
5398gcblk
5399o = mul bk 16
5400m = sub n o
5401if gt m 16
5402m = 16
5403end
5404for j ulong m bound 16
5405put c_d add o j uchar xor ulong get c_d add o j ulong get c_st j
5406end
5407ctr = add ctr 1
5408bk = add bk 1
5409end
5410end
5411end
5412
5413note unseal the n bytes of c_d: 1 and they are the data when c_tg is their tag, else 0 and they are untouched
5414fn gcunlock n ulong to ulong
5415if gt n 16777216
5416ret 0
5417end
5418gckey
5419gctag n
5420df = ulong 0
5421for i ulong 16
5422df = or df xor ulong get c_x i ulong get c_tg i
5423end
5424if ne df 0
5425ret 0
5426end
5427gcctr n
5428ret 1
5429end
5430
5431note seal the n bytes of c_d (16 MiB at most; more is left as it is, with a tag of zeros); their tag into c_tg
5432fn gclock n ulong to void
5433if gt n 16777216
5434for i ulong 16
5435put c_tg i 0
5436end
5437ret
5438end
5439gckey
5440gcctr n
5441gctag n
5442for i ulong 16
5443put c_tg i get c_x i
5444end
5445end
5446
5447note forget the key and everything worked out from it
5448fn gcwipe to void
5449for i ulong 32
5450put c_k i 0
5451end
5452for i ulong 240
5453put c_rk i 0
5454end
5455for i ulong 16
5456put c_hh i 0
5457put c_hl i 0
5458put c_st i 0
5459put c_tm i 0
5460put c_y i 0
5461put c_x i 0
5462end
5463end
5464
5465fn swgcm b view uchar 1048576 c ulong nbytes ulong ob edit uchar 65544 to ulong
5466if ne c 2
5467ret 0
5468end
5469dir = gu b 0
5470n = gu b 1
5471if or gt dir 1 gt n 4096
5472ret 0
5473end
5474want = add 44 n
5475if eq dir 0
5476want = add want 16
5477end
5478if ne nbytes want
5479ret 0
5480end
5481t0 = add 8 mul c 8
5482for i ulong 32
5483put c_k i get b add t0 i
5484end
5485for i ulong 12
5486put c_n i get b add add t0 32 i
5487end
5488for i ulong n bound 4096
5489put c_d i get b add add t0 44 i
5490end
5491if eq dir 0
5492for i ulong 16
5493put c_tg i get b add add add t0 44 n i
5494end
5495good = gcunlock n
5496gcwipe
5497po ob 0 add k_b good
5498if eq good 0
5499ret 1
5500end
5501for i ulong n bound 4096
5502po ob add 1 i add k_b ulong get c_d i
5503end
5504ret add 1 n
5505end
5506gclock n
5507gcwipe
5508po ob 0 add k_b 1
5509for i ulong n bound 4096
5510po ob add 1 i add k_b ulong get c_d i
5511end
5512for i ulong 16
5513po ob add add 1 n i add k_b ulong get c_tg i
5514end
5515ret add 17 n
5516end
5517
5518note kind 7: see the note above. Scalar ops answer one number: 1 state, 2 attention, 3 unread (the newest post
5519note less the last one read; -1 not known), 4 group, 5 starts a group, 6 failure (how a member's newest step
5520note failed: a model error at once, a failed tool step once it stayed newest for 60 seconds; 3 when the text
5521note spoke of quota), 7 the line weight of an edge, 1 to 5, by its count against the heaviest, 8 to 11 as noted.
5522note 13 and 16 answer a list of numbers; 12 and 14 answer bytes. 17: the rows of the one box (fn swrank). 18: what the one box offers before anything is typed (fn swsuggest).
5523note 19: the lift of each app from habit (fn swlifts). 20: AES-256-GCM, to seal and unseal (fn swgcm). Returns the reply length, or
5524note 18446744073709551615 for a malformed request
5525fn status ib view uchar 1048576 nb ulong ob edit uchar 65544 to ulong
5526bad = ulong 18446744073709551615
5527if lt nb 8
5528ret bad
5529end
5530op = rd32 ib 0
5531c = rd32 ib 4
5532if gt add 8 mul c 8 nb
5533ret bad
5534end
5535nbytes = sub nb add 8 mul c 8
5536t0 = add 8 mul c 8
5537r = k_b
5538if eq op 1
5539if ne c 5
5540ret bad
5541end
5542r = add k_b swstate gi ib 0 gi ib 1 gi ib 2 gi ib 3 gi ib 4
5543end
5544if eq op 2
5545if ne c 3
5546ret bad
5547end
5548r = add k_b swatt gi ib 0 gi ib 1 gi ib 2
5549end
5550if eq op 3
5551if ne c 2
5552ret bad
5553end
5554r = sub k_b 1
5555if ge gi ib 1 k_b
5556r = k_b
5557if gt gi ib 0 gi ib 1
5558r = add k_b sub gi ib 0 gi ib 1
5559end
5560end
5561end
5562if eq op 4
5563if ne c 4
5564ret bad
5565end
5566r = add k_b swgroup gi ib 0 gi ib 1 gi ib 2 gi ib 3
5567end
5568if eq op 5
5569if ne c 4
5570ret bad
5571end
5572r = add k_b swstarts gi ib 0 gi ib 1 gi ib 2 gi ib 3
5573end
5574if eq op 6
5575if ne c 4
5576ret bad
5577end
5578failed = eq gi ib 0 add k_b 4
5579if and eq gi ib 1 add k_b 2 ge gi ib 2 add k_b 60
5580failed = true
5581end
5582r = k_b
5583if failed
5584r = add k_b 2
5585if eq gi ib 3 add k_b 1
5586r = add k_b 3
5587end
5588end
5589end
5590if eq op 7
5591if ne c 2
5592ret bad
5593end
5594cn = gi ib 0
5595hv = gi ib 1
5596r = add k_b 1
5597if and gt cn add k_b 1 gt hv add k_b 1
5598if ge cn hv
5599r = add k_b 5
5600else
5601r = add add k_b 1 div mul sub sub cn k_b 1 4 sub sub hv k_b 1
5602end
5603end
5604end
5605if eq op 8
5606r = add k_b swturn ib c
5607end
5608if eq op 9
5609r = swact ib c
5610end
5611if eq op 10
5612r = add k_b swquota ib t0 add t0 nbytes
5613end
5614if eq op 11
5615if ne c 2
5616ret bad
5617end
5618rl = gu ib 0
5619nl = gu ib 1
5620if or gt rl 1048576 gt nl 1048576
5621ret bad
5622end
5623if ne add rl nl nbytes
5624ret bad
5625end
5626r = add k_b swrole ib t0 rl add t0 rl nl
5627end
5628if eq op 12
5629ret swedges ib c ob
5630end
5631if eq op 13
5632ret mul 8 swbroad ib c ob
5633end
5634if eq op 14
5635ret swbusy ib c ob
5636end
5637if eq op 16
5638k = swderive ib c nbytes ob
5639if eq k 0
5640ret bad
5641end
5642ret mul k 8
5643end
5644if eq op 17
5645k = swrank ib c nbytes ob
5646if eq k 0
5647ret bad
5648end
5649ret mul k 8
5650end
5651if eq op 18
5652k = swsuggest ib c ob
5653if eq k 0
5654ret bad
5655end
5656ret mul k 8
5657end
5658if eq op 19
5659k = swlifts ib c ob
5660if eq k 0
5661ret bad
5662end
5663ret mul k 8
5664end
5665if eq op 20
5666k = swgcm ib c nbytes ob
5667if eq k 0
5668ret bad
5669end
5670ret mul k 8
5671end
5672if or gt op 11 eq op 0
5673ret bad
5674end
5675po ob 0 r
5676ret 8
5677end
5678
5679note ---- which words were corrected (kind 4) ----
5680note After Hop types a dictation, the field is read again later. The host splits three texts into words (what was
5681note dictated, the field before, the field after) and gives each distinct word a number. This finds the dictation
5682note in the field (its last whole occurrence), sets aside the words that are the same at both ends, lines up the
5683note rest word by word (longest common subsequence) and reports each run where words of the dictation were
5684note replaced: at most 3 words, wholly inside the dictation. Nothing is reported when the dictation is not in the
5685note field, when the part that changed is too large (words before times words after over 250000), or when more
5686note than half of the dictation changed (a rewrite, not a fix).
5687note wt: the table of the line-up, (words before + 1) rows of (words after + 1)
5688global wt ulong 500008
5689
5690note st: 0 where the removed run starts in the field, 1 its length, 2 where the typed run starts in the later
5691note field, 3 its length, 4 runs written, 5 where the dictation starts, 6 its length, 7 removed words that lie
5692note inside the dictation, 8 1 when there were more runs than the answer holds (4096)
5693fn hclose st edit ulong 16 ob edit uchar 65544 to void
5694rc = get st 1
5695ic = get st 3
5696if and gt rc 0 gt ic 0
5697rs = get st 0
5698s0 = get st 5
5699if ge rs s0
5700if le add rs rc add s0 get st 6
5701if le rc 3
5702h = get st 4
5703if ge h 4096
5704put st 8 1
5705else
5706o = add 10 mul h 14
5707put32 ob o rs
5708put ob add o 4 uchar and rc 255
5709put ob add o 5 uchar shr rc 8
5710put32 ob add o 6 get st 2
5711put32 ob add o 10 ic
5712put st 4 add h 1
5713end
5714end
5715end
5716end
5717end
5718put st 1 0
5719put st 3 0
5720end
5721
5722note kind 4: three 32-bit counts (dictated, before, after), then that many 32-bit word numbers for each. The
5723note answer is a 16-bit count, then for each run: where the removed words start in the field before (32-bit), how
5724note many (16-bit), where the typed words start in the field after (32-bit) and how many (32-bit).
5725note Returns the reply length, or 18446744073709551615 for a malformed body or too many runs
5726fn wdiff ib view uchar 1048576 n ulong ob edit uchar 65544 to ulong
5727st = new ulong 16 0
5728bad = ulong 18446744073709551615
5729if lt n 12
5730ret bad
5731end
5732nd = rd32 ib 0
5733nb = rd32 ib 4
5734na = rd32 ib 8
5735if ne n add 12 mul 4 add add nd nb na
5736ret bad
5737end
5738d0 = ulong 12
5739b0 = add 12 mul 4 nd
5740a0 = add b0 mul 4 nb
5741put ob 8 uchar 0
5742put ob 9 uchar 0
5743if eq nd 0
5744ret 2
5745end
5746if lt nb nd
5747ret 2
5748end
5749found = false
5750start = ulong 0
5751q = sub nb nd
5752while true bound 999999
5753k = ulong 0
5754while lt k nd bound 999999
5755if ne rd32 ib add b0 mul 4 add q k rd32 ib add d0 mul 4 k
5756break
5757end
5758k = add k 1
5759end
5760if eq k nd
5761found = true
5762start = q
5763break
5764end
5765if eq q 0
5766break
5767end
5768q = sub q 1
5769end
5770if not found
5771ret 2
5772end
5773p = ulong 0
5774while lt p nb bound 999999
5775if ge p na
5776break
5777end
5778if ne rd32 ib add b0 mul 4 p rd32 ib add a0 mul 4 p
5779break
5780end
5781p = add p 1
5782end
5783s = ulong 0
5784while lt s sub nb p bound 999999
5785if ge s sub na p
5786break
5787end
5788if ne rd32 ib add b0 mul 4 sub sub nb 1 s rd32 ib add a0 mul 4 sub sub na 1 s
5789break
5790end
5791s = add s 1
5792end
5793bc = sub sub nb p s
5794ac = sub sub na p s
5795if eq bc 0
5796ret 2
5797end
5798am = ac
5799if eq am 0
5800am = ulong 1
5801end
5802if gt mul bc am 250000
5803ret 2
5804end
5805w1 = add ac 1
5806for z ulong add bc 1
5807put wt add mul z w1 ac 0
5808end
5809for z ulong w1
5810put wt add mul bc w1 z 0
5811end
5812for ii ulong bc
5813i = sub sub bc 1 ii
5814bi = rd32 ib add b0 mul 4 add p i
5815for jj ulong ac
5816j = sub sub ac 1 jj
5817if eq bi rd32 ib add a0 mul 4 add p j
5818put wt add mul i w1 j add get wt add mul add i 1 w1 add j 1 1
5819else
5820x = get wt add mul add i 1 w1 j
5821y = get wt add mul i w1 add j 1
5822if lt x y
5823x = y
5824end
5825put wt add mul i w1 j x
5826end
5827end
5828end
5829put st 5 start
5830put st 6 nd
5831ci = ulong 0
5832cj = ulong 0
5833while or lt ci bc lt cj ac bound 999999
5834mt = false
5835if lt ci bc
5836if lt cj ac
5837if eq rd32 ib add b0 mul 4 add p ci rd32 ib add a0 mul 4 add p cj
5838mt = true
5839end
5840end
5841end
5842if mt
5843hclose st ob
5844ci = add ci 1
5845cj = add cj 1
5846continue
5847end
5848rm = false
5849if lt ci bc
5850if eq cj ac
5851rm = true
5852else
5853if ge get wt add mul add ci 1 w1 cj get wt add mul ci w1 add cj 1
5854rm = true
5855end
5856end
5857end
5858if rm
5859if eq get st 1 0
5860put st 0 add p ci
5861end
5862put st 1 add get st 1 1
5863ai = add p ci
5864if ge ai start
5865if lt ai add start nd
5866put st 7 add get st 7 1
5867end
5868end
5869ci = add ci 1
5870else
5871if eq get st 3 0
5872put st 2 add p cj
5873end
5874put st 3 add get st 3 1
5875cj = add cj 1
5876end
5877end
5878hclose st ob
5879if ne get st 8 0
5880ret bad
5881end
5882h = get st 4
5883lim = nd
5884if lt lim 2
5885lim = ulong 2
5886end
5887if gt mul get st 7 2 lim
5888h = ulong 0
5889end
5890put ob 8 uchar and h 255
5891put ob 9 uchar shr h 8
5892ret add 2 mul h 14
5893end
5894
5895fn names ib view uchar 1048576 n ulong ob edit uchar 65544 a edit ulong 256 r edit ulong 256 to ulong
5896if ne rem n 2048 0
5897ret 18446744073709551615
5898end
5899c = div n 2048
5900if gt c 512
5901ret 18446744073709551615
5902end
5903for q ulong c
5904for i ulong 256
5905w = ulong 0
5906for j ulong 8
5907w = or w shl ulong get ib add add mul q 2048 mul i 8 j mul j 8
5908end
5909put a i w
5910end
5911v = hopfuzz a r
5912s = get r 3
5913put ob add 8 mul q 3 uchar v
5914put ob add 9 mul q 3 uchar and s 255
5915put ob add 10 mul q 3 uchar shr s 8
5916end
5917ret mul c 3
5918end
5919
5920note kind 2: returns the reply length, or 18446744073709551615 for a malformed body
5921fn paths ib view uchar 1048576 n ulong ob edit uchar 65544 toff edit ulong 64 tlen edit ulong 64 pm edit ulong 8 to ulong
5922bad = ulong 18446744073709551615
5923if lt n 4
5924ret bad
5925end
5926nt = rd16 ib 0
5927np = rd16 ib 2
5928if gt nt 64
5929ret bad
5930end
5931if gt np 16000
5932ret bad
5933end
5934o = ulong 4
5935for k ulong nt
5936if gt add o 2 n
5937ret bad
5938end
5939tl = rd16 ib o
5940o = add o 2
5941if gt add o tl n
5942ret bad
5943end
5944put toff k o
5945put tlen k tl
5946o = add o tl
5947end
5948for q ulong np
5949if gt add o 6 n
5950ret bad
5951end
5952pl = rd16 ib o
5953nl = rd16 ib add o 2
5954ol = rd16 ib add o 4
5955o = add o 6
5956if gt add o add pl nl n
5957ret bad
5958end
5959put pm 0 nt
5960put pm 1 o
5961put pm 2 pl
5962put pm 3 add o pl
5963put pm 4 nl
5964put pm 5 ol
5965put32 ob add 8 mul q 4 fscore ib toff tlen pm
5966o = add o add pl nl
5967end
5968if ne o n
5969ret bad
5970end
5971ret mul np 4
5972end
5973
5974note ---- end of the core of Hop ----
5975
5976fn upr o ulong v ulong to void
5977for i ulong 8
5978put g_rg add o i uchar and shr v mul i 8 255
5979end
5980end
5981
5982fn ugr o ulong to ulong
5983v = ulong 0
5984for i ulong 8
5985v = or v shl ulong get g_rg add o i mul i 8
5986end
5987ret v
5988end
5989
5990note the text into g_nm with a zero byte after it; its length
5991fn ucs t view uchar * to ulong
5992n = len t
5993for i ulong n
5994put g_nm i get t i
5995end
5996put g_nm n 0
5997ret n
5998end
5999
6000note library function k of g_f on the register file; x0 as it came back (an object may have its top bit set)
6001fn ucall k ulong to ulong
6002lr = libcall get g_f k g_rg 0 128
6003ret ugr 0
6004end
6005
6006fn usym t view uchar * to ulong
6007n = ucs t
6008upr 0 18446744073709551614
6009upr 8 ulong libptr g_nm 0 1024
6010lr = libcall ulong libfn 1 g_rg 0 128
6011ret ugr 0
6012end
6013
6014fn ucl t view uchar * to ulong
6015n = ucs t
6016upr 0 ulong libptr g_nm 0 1024
6017ret ucall 0
6018end
6019
6020fn usl t view uchar * to ulong
6021n = ucs t
6022upr 0 ulong libptr g_nm 0 1024
6023ret ucall 1
6024end
6025
6026note [obj s a b c]
6027fn umsg obj ulong s ulong a ulong b ulong c ulong to ulong
6028upr 0 obj
6029upr 8 s
6030upr 16 a
6031upr 24 b
6032upr 32 c
6033ret ucall 2
6034end
6035
6036note an NSString of the zero-ended bytes in g_nm
6037fn unsb to ulong
6038ret umsg get g_o 3 get g_o 4 ulong libptr g_nm 0 1024 0 0
6039end
6040
6041fn uns t view uchar * to ulong
6042n = ucs t
6043ret unsb
6044end
6045
6046note a rectangle for the next message, in d0..d3
6047fn urect x f64 y f64 w f64 h f64 to void
6048upr 64 bitcast ulong x
6049upr 72 bitcast ulong y
6050upr 80 bitcast ulong w
6051upr 88 bitcast ulong h
6052end
6053
6054fn ulower c ulong to ulong
6055if and ge c 65 le c 90
6056ret add c 32
6057end
6058ret c
6059end
6060
6061note the zero-ended bytes at address p into g_nm (at most 1000); their count
6062fn ufetch p ulong to ulong
6063upr 0 p
6064n = ucall 7
6065if gt n 1000
6066n = 1000
6067end
6068upr 0 ulong libptr g_nm 0 1024
6069upr 8 p
6070upr 16 n
6071x = ucall 8
6072put g_nm n 0
6073ret n
6074end
6075
6076note the names in one folder that end in ".app", without that ending, into the pool
6077fn ufolder t view uchar * dn ulong to void
6078c = ucl c_fm
6079s = usl m_defaul
6080mgr = umsg c s 0 0 0
6081s = usl m_conte1
6082path = uns t
6083arr = umsg mgr s path 0 0
6084if eq arr 0
6085ret
6086end
6087s = usl m_count
6088cnt = umsg arr s 0 0 0
6089sat = usl m_at
6090for i ulong cnt bound 4096
6091item = umsg arr sat i 0 0
6092p = umsg item get g_o 5 0 0 0
6093n = ufetch p
6094k = get g_n 0
6095used = get g_n 2
6096if and and gt n 4 lt k 2048 lt add used n 65536
6097if and and eq get g_nm sub n 4 46 eq get g_nm sub n 3 97 and eq get g_nm sub n 2 112 eq get g_nm sub n 1 112
6098m = sub n 4
6099for j ulong m bound 1000
6100put g_pool add used j get g_nm j
6101end
6102put g_off k used
6103put g_ln k m
6104put g_dir k uchar dn
6105put g_n 0 add k 1
6106put g_n 2 add used m
6107end
6108end
6109end
6110end
6111
6112note the word hopfuzz reads for one byte: its lower-case value, bit 32 for a letter or digit (and for every byte of
6113note a longer character), bit 33 for a space or tab
6114fn ufword c ulong to ulong
6115l = ulower c
6116w = l
6117if or or and ge l 97 le l 122 and ge l 48 le l 57 ge l 128
6118w = or w 4294967296
6119end
6120if or eq l 32 eq l 9
6121w = or w 8589934592
6122end
6123ret w
6124end
6125
6126note how well app k matches the typed text: hopfuzz's score plus 1, or 0 for no match (and for a text over 64 bytes
6127note or a name over 184, which hopfuzz refuses)
6128fn uscore k ulong to ulong
6129inp = new ulong 256 0
6130res = new ulong 256 0
6131ql = get g_n 4
6132nl = get g_ln k
6133o = get g_off k
6134if or gt ql 64 or gt nl 184 eq nl 0
6135ret 0
6136end
6137put inp 0 1212568922
6138put inp 1 1
6139put inp 2 ql
6140put inp 3 nl
6141for i ulong ql bound 64
6142put inp add 8 i ufword ulong get g_q i
6143end
6144for i ulong nl bound 184
6145put inp add 72 i ufword ulong get g_pool add o i
6146end
6147v = hopfuzz inp res
6148if ne v 1
6149ret 0
6150end
6151ret 0
6152end
6153
6154note a number in decimal into g_nm from byte p; the byte after it
6155fn upnum p ulong v ulong to ulong
6156d = ulong 1
6157while ge div v d 10 bound 24
6158d = mul d 10
6159end
6160q = p
6161while gt d 0 bound 24
6162put g_nm q uchar add 48 rem div v d 10
6163q = add q 1
6164d = div d 10
6165end
6166ret q
6167end
6168
6169note the text into g_nm from byte p; the byte after it
6170fn uptxt p ulong t view uchar * to ulong
6171for i ulong len t
6172put g_nm add p i get t i
6173end
6174ret add p len t
6175end
6176
6177note name k into g_nm from byte p; the byte after it
6178fn upname p ulong k ulong to ulong
6179o = get g_off k
6180n = get g_ln k
6181for i ulong n bound 1000
6182put g_nm add p i get g_pool add o i
6183end
6184ret add p n
6185end
6186
6187note four bytes and eight bytes into a request for the core, and eight bytes out of its answer; numbers travel with
6188note 2^40 added (k_b), as in Omega/README.md kind 7
6189fn uw32 b edit uchar 1048576 o ulong v ulong to void
6190for i ulong 4
6191put b add o i uchar and shr v mul i 8 255
6192end
6193end
6194
6195fn upb b edit uchar 1048576 k ulong x ulong to void
6196o = add 8 mul k 8
6197for i ulong 8
6198put b add o i uchar and shr x mul i 8 255
6199end
6200end
6201
6202fn upn b edit uchar 1048576 k ulong v ulong to void
6203upb b k add v k_b
6204end
6205
6206fn uog ob view uchar 65544 k ulong to ulong
6207v = ulong 0
6208o = add 8 mul k 8
6209for i ulong 8
6210v = or v shl ulong get ob add o i mul i 8
6211end
6212ret v
6213end
6214
6215note the address the typed text stands for into g_nm from byte p (with "https://" before a bare one); the byte after
6216fn upaddr p ulong to ulong
6217q = p
6218if eq get g_n 10 2
6219q = uptxt p x_https
6220end
6221a = get g_n 12
6222n = get g_n 13
6223for i ulong n bound 256
6224put g_nm add q i get g_q add a i
6225end
6226ret add q n
6227end
6228
6229note is the typed text a web address? The shape is the core's decision (fn weba, text decisions op 3); that macOS
6230note can read it is asked of NSURL, as Hop does. The answer goes to g_n 10
6231fn udecide to void
6232tb = new uchar 1048576 0
6233a = get g_n 12
6234n = get g_n 13
6235put g_n 10 0
6236put g_n 41 0
6237if or eq n 0 gt n 255
6238ret
6239end
6240uw32 tb 0 3
6241uw32 tb 4 n
6242uw32 tb 8 n
6243for i ulong n bound 256
6244l = ulower ulong get g_q add a i
6245o = add 16 mul i 8
6246put tb o uchar l
6247f = ulong 0
6248if or or and ge l 97 le l 122 and ge l 48 le l 57 ge l 128
6249f = 1
6250end
6251if or eq l 32 eq l 9
6252f = 14
6253end
6254put tb add o 4 uchar f
6255end
6256put g_n 41 qlike tb n
6257k = weba tb n n
6258if eq k 0
6259ret
6260end
6261put g_n 10 k
6262p = upaddr 0
6263put g_nm p 0
6264str = unsb
6265u = umsg get g_o 16 get g_o 17 str 0 0
6266if eq u 0
6267put g_n 10 0
6268ret
6269end
6270if eq k 1
6271if eq umsg u get g_o 18 0 0 0 0
6272put g_n 10 0
6273end
6274end
6275end
6276
6277note ---- files: Hop's file index, searched by the rule of Hop's own file search (Sources/FileIndex.swift) ----
6278note read file-index.bin from Hop's folder (HOP_CONFIG_DIR, else the user's Application Support/Hop) and make the
6279note lower-case copy the search runs on. Without the file there are no file rows
6280fn uloadindex to void
6281if eq get g_fb 3 1
6282upr 0 get g_fb 1
6283x = ucall 28
6284x = umsg get g_fb 4 usl m_release 0 0 0
6285end
6286put g_fb 3 0
6287n = ucs x_env_dir
6288upr 0 ulong libptr g_nm 0 1024
6289dir_text = ucall 9
6290p = ulong 0
6291if ne dir_text 0
6292p = ufetch dir_text
6293end
6294if eq p 0
6295n = ucs x_env_home
6296upr 0 ulong libptr g_nm 0 1024
6297home_text = ucall 9
6298if eq home_text 0
6299ret
6300end
6301p = ufetch home_text
6302p = uptxt p x_support
6303end
6304p = uptxt p x_index
6305put g_nm p 0
6306path = unsb
6307c = ucl c_data
6308s = usl m_data_file
6309d = umsg c s path 0 0
6310if eq d 0
6311ret
6312end
6313s = usl m_retain
6314x = umsg d s 0 0 0
6315s = usl m_bytes
6316src = umsg d s 0 0 0
6317s = usl m_length
6318total = umsg d s 0 0 0
6319if or or eq src 0 eq total 0 gt total 536870912
6320ret
6321end
6322upr 0 total
6323dst = ucall 10
6324if eq dst 0
6325x = umsg d usl m_release 0 0 0
6326ret
6327end
6328done = ulong 0
6329while lt done total bound 2048
6330m = sub total done
6331if gt m 524288
6332m = 524288
6333end
6334upr 0 ulong libptr g_chunk 0 524288
6335upr 8 add src done
6336upr 16 m
6337x = ucall 8
6338for i ulong m bound 524288
6339cc = ulong get g_chunk i
6340if and ge cc 65 le cc 90
6341put g_chunk i uchar add cc 32
6342end
6343end
6344upr 0 add dst done
6345upr 8 ulong libptr g_chunk 0 524288
6346upr 16 m
6347x = ucall 8
6348done = add done m
6349end
6350put g_fb 0 src
6351put g_fb 1 dst
6352put g_fb 2 total
6353put g_fb 4 d
6354put g_fb 3 1
6355end
6356
6357note does g_line[ho .. ho+hl) hold word t of the typed text; md 1: does it start with it
6358fn uhas ho ulong hl ulong t ulong md ulong to bool
6359wo = get g_to t
6360wl = get g_tl t
6361if gt wl hl
6362ret false
6363end
6364last = sub hl wl
6365if eq md 1
6366last = 0
6367end
6368st = ulong 0
6369while le st last bound 4097
6370same_bytes = true
6371j = ulong 0
6372while and same_bytes lt j wl bound 257
6373if ne get g_line add add ho st j get g_lq add wo j
6374same_bytes = false
6375end
6376j = add j 1
6377end
6378if same_bytes
6379ret true
6380end
6381st = add st 1
6382end
6383ret false
6384end
6385
6386note the score of the path in g_line (ln bytes, lower case) plus 100000, or 0 when a word is in it nowhere: a
6387note word in the name counts 60 at its start and 30 elsewhere, a word only in the folders 5; a point less for
6388note every 20 bytes of path; 40 more when the name is exactly as long as the words; 25 more for an app
6389fn ufscore ln ulong to ulong
6390nt = get g_n 16
6391ns0 = ln
6392while gt ns0 0 bound 4097
6393if eq ulong get g_line sub ns0 1 47
6394break
6395end
6396ns0 = sub ns0 1
6397end
6398nl = sub ln ns0
6399sc = ulong 100000
6400words_len = ulong 0
6401for t ulong nt bound 16
6402words_len = add words_len get g_tl t
6403if uhas ns0 nl t 0
6404if uhas ns0 nl t 1
6405sc = add sc 60
6406else
6407sc = add sc 30
6408end
6409else
6410if uhas 0 ln t 0
6411sc = add sc 5
6412else
6413ret 0
6414end
6415end
6416end
6417sc = sub sc div ln 20
6418if eq nl words_len
6419sc = add sc 40
6420end
6421if ge ln 4
6422if and and eq ulong get g_line sub ln 4 46 eq ulong get g_line sub ln 3 97 and eq ulong get g_line sub ln 2 112 eq ulong get g_line sub ln 1 112
6423sc = add sc 25
6424end
6425end
6426ret sc
6427end
6428
6429note keep a found path among the best 40, best first; equal scores stay in the order they were found
6430fn ufkeep sc ulong o ulong ln ulong to void
6431k = get g_n 17
6432if and ge k 40 le sc get g_fs 39
6433ret
6434end
6435pos = k
6436if ge k 40
6437pos = 39
6438else
6439put g_n 17 add k 1
6440end
6441while gt pos 0 bound 64
6442if ge get g_fs sub pos 1 sc
6443break
6444end
6445put g_fs pos get g_fs sub pos 1
6446put g_fo pos get g_fo sub pos 1
6447put g_fl pos get g_fl sub pos 1
6448pos = sub pos 1
6449end
6450put g_fs pos sc
6451put g_fo pos o
6452put g_fl pos ln
6453end
6454
6455note path i of the best files into g_line, from the lower-case copy (lo 1) or as it is written (lo 0); its length
6456fn ufpath i ulong lo ulong to ulong
6457ln = get g_fl i
6458upr 0 ulong libptr g_line 0 4096
6459upr 8 add get g_fb lo get g_fo i
6460upr 16 ln
6461x = ucall 8
6462ret ln
6463end
6464
6465note the files for the typed text: every line of the index that holds the longest word is scored (at most
6466note 20000 lines, as Hop does), the best 40 are kept. Nothing under two characters
6467fn usearch to void
6468put g_n 17 0
6469put g_n 18 0
6470a = get g_n 12
6471n = get g_n 13
6472nt = ulong 0
6473i = ulong 0
6474while lt i n bound 257
6475c = ulower ulong get g_q add a i
6476put g_lq i uchar c
6477if or eq c 32 eq c 9
6478i = add i 1
6479continue
6480end
6481st = i
6482while lt i n bound 257
6483c = ulower ulong get g_q add a i
6484if or eq c 32 eq c 9
6485break
6486end
6487put g_lq i uchar c
6488i = add i 1
6489end
6490if lt nt 16
6491put g_to nt st
6492put g_tl nt sub i st
6493nt = add nt 1
6494end
6495end
6496put g_n 16 nt
6497if or or eq get g_fb 3 0 lt n 2 eq nt 0
6498ret
6499end
6500lead = ulong 0
6501for t ulong nt bound 16
6502if gt get g_tl t get g_tl lead
6503lead = t
6504end
6505end
6506low = get g_fb 1
6507total = get g_fb 2
6508pos = ulong 0
6509scanned = ulong 0
6510while and lt pos total lt scanned 20000 bound 20001
6511upr 0 add low pos
6512upr 8 sub total pos
6513upr 16 ulong libptr g_lq get g_to lead get g_tl lead
6514upr 24 get g_tl lead
6515m = ucall 11
6516if eq m 0
6517break
6518end
6519hit_at = sub m low
6520upr 0 low
6521upr 8 10
6522upr 16 hit_at
6523r = ucall 13
6524s = ulong 0
6525if ne r 0
6526s = add sub r low 1
6527end
6528upr 0 m
6529upr 8 10
6530upr 16 sub total hit_at
6531r = ucall 12
6532e = total
6533if ne r 0
6534e = sub r low
6535end
6536pos = add e 1
6537scanned = add scanned 1
6538ln = sub e s
6539if and gt ln 0 le ln 4000
6540upr 0 ulong libptr g_line 0 4096
6541upr 8 add low s
6542upr 16 ln
6543x = ucall 8
6544sc = ufscore ln
6545if ne sc 0
6546ufkeep sc s ln
6547end
6548end
6549end
6550note does one of them have exactly the typed text as its name (a folder's last "/" aside)
6551for f ulong get g_n 17 bound 64
6552ln = ufpath f 1
6553if gt ln 0
6554if eq ulong get g_line sub ln 1 47
6555ln = sub ln 1
6556end
6557end
6558ns0 = ln
6559while gt ns0 0 bound 4097
6560if eq ulong get g_line sub ns0 1 47
6561break
6562end
6563ns0 = sub ns0 1
6564end
6565if eq sub ln ns0 n
6566same_bytes = true
6567for j ulong n bound 256
6568if ne get g_line add ns0 j get g_lq j
6569same_bytes = false
6570end
6571end
6572if same_bytes
6573put g_n 18 1
6574end
6575end
6576end
6577end
6578
6579note is g_line[o .. o+n) the text t
6580fn ulineis o ulong n ulong t view uchar * to bool
6581if ne n len t
6582ret false
6583end
6584for i ulong n bound 64
6585if ne get g_line add o i get t i
6586ret false
6587end
6588end
6589ret true
6590end
6591
6592note is best file i one of the m matched apps (an app already listed is not shown again as a file)
6593fn uisapp i ulong m ulong to ulong
6594ln = ufpath i 1
6595if lt ln 6
6596ret 0
6597end
6598if not ulineis sub ln 4 4 x_dotapp_low
6599ret 0
6600end
6601o = ulong 0
6602if and ge ln 14 ulineis 0 14 x_dir1_low
6603o = 14
6604end
6605if and ge ln 21 ulineis 0 21 x_dir2_low
6606o = 21
6607end
6608if eq o 0
6609ret 0
6610end
6611nl = sub sub ln o 4
6612for j ulong m bound 2048
6613k = get g_mk j
6614if eq get g_ln k nl
6615same_bytes = true
6616for b ulong nl bound 1000
6617if ne ulower ulong get g_pool add get g_off k b ulong get g_line add o b
6618same_bytes = false
6619end
6620end
6621if same_bytes
6622ret 1
6623end
6624end
6625end
6626ret 0
6627end
6628
6629note the text of a file row into g_nm from byte p: its name, a gap, the folder it is in; the byte after it
6630fn ufilerow p ulong i ulong to ulong
6631ln = ufpath i 0
6632if gt ln 0
6633if eq ulong get g_line sub ln 1 47
6634ln = sub ln 1
6635end
6636end
6637ns0 = ln
6638while gt ns0 0 bound 4097
6639if eq ulong get g_line sub ns0 1 47
6640break
6641end
6642ns0 = sub ns0 1
6643end
6644q = p
6645nl = sub ln ns0
6646if gt nl 300
6647nl = 300
6648end
6649for j ulong nl bound 301
6650put g_nm add q j get g_line add ns0 j
6651end
6652q = add q nl
6653if and gt ns0 1 le ns0 600
6654q = uptxt q x_gap
6655for j ulong sub ns0 1 bound 601
6656put g_nm add q j get g_line j
6657end
6658q = add q sub ns0 1
6659end
6660ret q
6661end
6662
6663note the whole path of best file i into g_nm from byte p (nothing when it is over 900 bytes); the byte after it
6664fn ufilepath p ulong i ulong to ulong
6665ln = ufpath i 0
6666if gt ln 900
6667ret p
6668end
6669for j ulong ln bound 901
6670put g_nm add p j get g_line j
6671end
6672ret add p ln
6673end
6674
6675note open best file i with the app macOS has for it
6676fn uopenfile i ulong to void
6677p = ufilepath 0 i
6678if eq p 0
6679ret
6680end
6681put g_nm p 0
6682str = unsb
6683c = ucl c_url
6684s = usl m_furl
6685url = umsg c s str 0 0
6686c = ucl c_ws
6687s = usl m_shws
6688ws = umsg c s 0 0 0
6689s = usl m_open
6690put g_n 9 and umsg ws s url 0 0 255
6691end
6692
6693note ---- Ask: the model of Hop's settings, asked over HTTP as Hop asks it (Sources/Runners.swift) ----
6694note [obj objectForKey: the key named by t]
6695fn ukeyed obj ulong t view uchar * to ulong
6696key = uns t
6697ret umsg obj usl m_object_for_key key 0 0
6698end
6699
6700note is obj an object of class number w of g_m (7 a dictionary, 8 an array, 9 a string); nothing is not
6701fn uiskind obj ulong w ulong to bool
6702if eq obj 0
6703ret false
6704end
6705ret eq and umsg obj usl m_is_kind get g_m w 0 0 255 1
6706end
6707
6708note the path of the file at Hop's folder plus the text t (an NSString, its bytes left in g_nm; 0 when the
6709note folder is not known)
6710fn uhoppath t view uchar * to ulong
6711n = ucs x_env_dir
6712upr 0 ulong libptr g_nm 0 1024
6713dir_text = ucall 9
6714p = ulong 0
6715if ne dir_text 0
6716p = ufetch dir_text
6717end
6718if eq p 0
6719n = ucs x_env_home
6720upr 0 ulong libptr g_nm 0 1024
6721home_text = ucall 9
6722if eq home_text 0
6723ret 0
6724end
6725p = ufetch home_text
6726p = uptxt p x_support
6727end
6728p = uptxt p t
6729put g_nm p 0
6730ret unsb
6731end
6732
6733note the file at Hop's folder plus the text t, as NSData (0 when it is not there)
6734fn uhopfile t view uchar * to ulong
6735path = uhoppath t
6736if eq path 0
6737ret 0
6738end
6739ret umsg ucl c_data usl m_data_file path 0 0
6740end
6741
6742note ---- saved accounts: Hop's keys and logins in the login Keychain (Sources/Vault.swift) ----
6743note Each is a generic password under Hop's service: the account is its name, the description its kind, the comment
6744note its note. Listing them reads no secret. Enter on one reads its secret and puts it on the clipboard, marked
6745note concealed so that clipboard histories pass it over, as Hop does; macOS asks the person the first time this
6746note program reads an item Hop made. A check (HOPCHECK) reads only the service named by HOPVAULT, never Hop's,
6747note and tells the Keychain to put no dialog up for it: what it may not read without one, it does not read.
6748note It makes its accounts itself (HOPVAULTADD), since macOS lets a program read back what it saved, and
6749note deletes them when it ends.
6750note the eight bytes of g_t8 as a number
6751fn uread8 to ulong
6752v = ulong 0
6753for i ulong 8
6754v = or v shl ulong get g_t8 i mul i 8
6755end
6756ret v
6757end
6758
6759note the value of the library's constant named t (a pointer kept in a variable of that name); 0 when there is none
6760fn uconst t view uchar * to ulong
6761sym_at = usym t
6762if eq sym_at 0
6763ret 0
6764end
6765upr 0 ulong libptr g_t8 0 8
6766upr 8 sym_at
6767upr 16 8
6768x = ucall 8
6769ret uread8
6770end
6771
6772note ask the Keychain for what q describes; the answer (an object), or 0
6773fn ukeychain q ulong to ulong
6774for i ulong 8
6775put g_t8 i 0
6776end
6777upr 0 q
6778upr 8 ulong libptr g_t8 0 8
6779if ne and ucall 23 4294967295 0
6780ret 0
6781end
6782ret uread8
6783end
6784
6785note a question to the Keychain about Hop's items: the generic passwords under the service
6786fn uvaultquery to ulong
6787q = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
6788sset = usl m_set_object
6789x = umsg q sset uconst s_class_generic uconst s_class 0
6790x = umsg q sset get g_m 20 uconst s_attr_service 0
6791ret q
6792end
6793
6794note the saved accounts: their names in order (lower case decides), and what each is
6795fn uloadvault to void
6796put g_n 31 0
6797service = ulong 0
6798if eq get g_n 14 0
6799n = ucs x_env_vault
6800upr 0 ulong libptr g_nm 0 1024
6801vault_text = ucall 9
6802if eq vault_text 0
6803ret
6804end
6805n = ufetch vault_text
6806service = unsb
6807else
6808service = uns x_vault_service
6809end
6810if eq service 0
6811ret
6812end
6813sret = usl m_retain
6814if eq get g_m 20 0
6815put g_m 20 umsg service sret 0 0 0
6816if eq get g_n 14 0
6817uvaultcheckadd
6818end
6819end
6820q = uvaultquery
6821sset = usl m_set_object
6822x = umsg q sset uconst s_limit_all uconst s_match_limit 0
6823x = umsg q sset uconst s_true uconst s_return_attributes 0
6824items = ukeychain q
6825if not uiskind items 8
6826ret
6827end
6828key_account = uconst s_attr_account
6829key_kind = uconst s_attr_description
6830key_note = uconst s_attr_comment
6831sget = usl m_object_for_key
6832sat = usl m_at
6833slower = usl m_lowercase
6834sappend = usl m_append_string
6835slen = usl m_length
6836by_low = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
6837cnt = umsg items usl m_count 0 0 0
6838for i ulong cnt bound 4096
6839item = umsg items sat i 0 0
6840if uiskind item 7
6841name = umsg item sget key_account 0 0
6842if uiskind name 9
6843x = umsg by_low sset item umsg name slower 0 0 0 0
6844end
6845end
6846end
6847lows = umsg umsg by_low usl m_all_keys 0 0 0 usl m_sorted usl m_compare 0 0
6848acct_names = umsg ucl c_mutable_array usl m_array 0 0 0
6849acct_details = umsg ucl c_mutable_array usl m_array 0 0 0
6850sadd = usl m_add_object
6851put g_nm 0 32
6852put g_nm 1 194
6853put g_nm 2 183
6854put g_nm 3 32
6855put g_nm 4 0
6856dot = unsb
6857put g_nm 0 0
6858nothing = unsb
6859total = umsg lows usl m_count 0 0 0
6860if gt total 800
6861total = 800
6862end
6863for i ulong total bound 800
6864item = umsg by_low sget umsg lows sat i 0 0 0 0
6865x = umsg acct_names sadd umsg item sget key_account 0 0 0 0
6866detail = nothing
6867kind = umsg item sget key_kind 0 0
6868if uiskind kind 9
6869detail = kind
6870end
6871remark = umsg item sget key_note 0 0
6872if uiskind remark 9
6873if gt umsg remark slen 0 0 0 0
6874if gt umsg detail slen 0 0 0 0
6875detail = umsg detail sappend dot 0 0
6876end
6877detail = umsg detail sappend remark 0 0
6878end
6879end
6880x = umsg acct_details sadd detail 0 0
6881end
6882srel = usl m_release
6883if ne get g_m 18 0
6884x = umsg get g_m 18 srel 0 0 0
6885x = umsg get g_m 19 srel 0 0 0
6886end
6887put g_m 18 umsg acct_names sret 0 0 0
6888put g_m 19 umsg acct_details sret 0 0 0
6889put g_n 31 total
6890end
6891
6892note the secret of the account named name (an NSString), as text; 0 when it cannot be read
6893fn usecret name ulong to ulong
6894if or eq get g_m 20 0 eq name 0
6895ret 0
6896end
6897q = uvaultquery
6898sset = usl m_set_object
6899x = umsg q sset name uconst s_attr_account 0
6900x = umsg q sset uconst s_true uconst s_return_data 0
6901x = umsg q sset uconst s_limit_one uconst s_match_limit 0
6902d = ukeychain q
6903if eq d 0
6904ret 0
6905end
6906whole = umsg ucl c_str usl m_alloc 0 0 0
6907ret umsg whole usl m_init_data_encoding d 4 0
6908end
6909
6910note save an account as Hop does (Vault.save): any item of that name goes, then one is added with the secret as
6911note its data, the kind as its description and the note as its comment; 1 when it was added
6912fn uvaultsave name ulong secret_text ulong kind ulong remark ulong to ulong
6913if or eq get g_m 20 0 or eq name 0 eq secret_text 0
6914ret 0
6915end
6916q = uvaultquery
6917sset = usl m_set_object
6918x = umsg q sset name uconst s_attr_account 0
6919upr 0 q
6920x = ucall 25
6921data = umsg secret_text usl m_data_using 4 0 0
6922if eq data 0
6923ret 0
6924end
6925x = umsg q sset data uconst s_value_data 0
6926if ne kind 0
6927x = umsg q sset kind uconst s_attr_description 0
6928end
6929if ne remark 0
6930x = umsg q sset remark uconst s_attr_comment 0
6931end
6932x = umsg q sset uconst s_accessible_unlocked uconst s_accessible 0
6933upr 0 q
6934upr 8 0
6935if ne and ucall 24 4294967295 0
6936ret 0
6937end
6938ret 1
6939end
6940
6941note delete the account of that name (Vault.delete)
6942fn uvaultdelete name ulong to void
6943if or eq get g_m 20 0 eq name 0
6944ret
6945end
6946q = uvaultquery
6947x = umsg q usl m_set_object name uconst s_attr_account 0
6948upr 0 q
6949x = ucall 25
6950end
6951
6952note for a check: the accounts HOPVAULTADD describes ("name|kind|note|value", more after ";") are saved under the
6953note check's service by this very program, so that it may read them back without the person being asked
6954fn uvaultcheckadd to void
6955if eq get g_m 20 0
6956ret
6957end
6958n = ucs x_env_vault_add
6959upr 0 ulong libptr g_nm 0 1024
6960add_text = ucall 9
6961if eq add_text 0
6962ret
6963end
6964n = ufetch add_text
6965whole = unsb
6966if eq whole 0
6967ret
6968end
6969ssplit = usl m_components
6970sat = usl m_at
6971slen = usl m_length
6972made = umsg ucl c_mutable_array usl m_array 0 0 0
6973put g_m 22 umsg made usl m_retain 0 0 0
6974entries = umsg whole ssplit uns x_semicolon 0 0
6975entry_count = umsg entries usl m_count 0 0 0
6976for i ulong entry_count bound 16
6977fields = umsg umsg entries sat i 0 0 ssplit uns x_bar 0 0
6978if eq umsg fields usl m_count 0 0 0 4
6979name = umsg fields sat 0 0 0
6980kind = umsg fields sat 1 0 0
6981remark = umsg fields sat 2 0 0
6982value = umsg fields sat 3 0 0
6983if eq umsg kind slen 0 0 0 0
6984kind = 0
6985end
6986if eq umsg remark slen 0 0 0 0
6987remark = 0
6988end
6989if eq uvaultsave name value kind remark 1
6990x = umsg made usl m_add_object name 0 0
6991end
6992end
6993end
6994end
6995
6996note for a check: delete the accounts it made
6997fn uvaultcheckend to void
6998made = get g_m 22
6999if eq made 0
7000ret
7001end
7002cnt = umsg made usl m_count 0 0 0
7003for i ulong cnt bound 16
7004uvaultdelete umsg made get g_m 16 i 0 0
7005end
7006put g_m 22 0
7007end
7008
7009note string i of the array into g_nm from byte p; the byte after it
7010fn ustrat list_of ulong p ulong i ulong to ulong
7011if or eq list_of 0 ge p 900
7012ret p
7013end
7014entry_text = umsg list_of get g_m 16 i 0 0
7015src = umsg entry_text get g_o 5 0 0 0
7016if eq src 0
7017ret p
7018end
7019upr 0 src
7020n = ucall 7
7021if gt add p n 900
7022n = sub 900 p
7023end
7024if eq n 0
7025ret p
7026end
7027upr 0 ulong libptr g_nm p n
7028upr 8 src
7029upr 16 n
7030x = ucall 8
7031ret add p n
7032end
7033
7034note put the secret of saved account i on the clipboard, marked concealed. A check uses a board of its own
7035fn ucopysecret i ulong to void
7036if ge i get g_n 31
7037ret
7038end
7039name = umsg get g_m 18 get g_m 16 i 0 0
7040secret_text = usecret name
7041if eq secret_text 0
7042ret
7043end
7044pboard = ulong 0
7045if eq get g_n 14 1
7046pboard = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
7047else
7048pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0
7049end
7050x = umsg pboard usl m_clear 0 0 0
7051plain_type = uns x_type_string
7052concealed = uns x_type_concealed
7053types = umsg ucl c_mutable_array usl m_array 0 0 0
7054sadd = usl m_add_object
7055x = umsg types sadd plain_type 0 0
7056x = umsg types sadd concealed 0 0
7057x = umsg pboard usl m_declare_types types 0 0
7058sput = usl m_set_string_type
7059x = umsg pboard sput secret_text plain_type 0
7060put g_nm 0 0
7061nothing = unsb
7062x = umsg pboard sput nothing concealed 0
7063put g_n 29 1
7064end
7065
7066note is entry e of the models an HTTP model the panel can ask (one whose key is a saved account needs the
7067note accounts to be readable); when it is, keep it as the model to ask
7068fn utakemodel e ulong to bool
7069if not uiskind e 7
7070ret false
7071end
7072kind = ukeyed e k_kind
7073if uiskind kind 9
7074want = uns x_openai
7075if ne and umsg kind usl m_equal_string want 0 0 255 1
7076ret false
7077end
7078end
7079key_name = ukeyed e k_key
7080if uiskind key_name 9
7081if eq get g_m 20 0
7082ret false
7083end
7084else
7085key_name = 0
7086end
7087base = ukeyed e k_base
7088model = ukeyed e k_model
7089name = ukeyed e k_name
7090if or or not uiskind base 9 not uiskind model 9 not uiskind name 9
7091ret false
7092end
7093slash = uns x_slash_text
7094for i ulong 8
7095if eq and umsg base usl m_has_suffix slash 0 0 255 1
7096base = umsg base usl m_substring_to sub umsg base usl m_length 0 0 0 1 0 0
7097end
7098end
7099if eq umsg base usl m_length 0 0 0 0
7100ret false
7101end
7102tail = uns x_completions
7103address = umsg base usl m_append_string tail 0 0
7104sret = usl m_retain
7105put g_m 0 umsg model sret 0 0 0
7106put g_m 1 umsg address sret 0 0 0
7107put g_m 2 umsg name sret 0 0 0
7108put g_m 21 0
7109if ne key_name 0
7110put g_m 21 umsg key_name sret 0 0 0
7111end
7112put g_m 3 1
7113ret true
7114end
7115
7116note read Hop's settings and choose the model: the default one when it will do, else the first that will
7117fn uloadconfig to void
7118put g_m 3 0
7119put g_m 7 ucl c_dict
7120put g_m 8 ucl c_array
7121put g_m 9 ucl c_str
7122d = uhopfile x_config
7123if eq d 0
7124uagentconfig 0
7125ret
7126end
7127config = umsg ucl c_json usl m_json_object d 0 0
7128if not uiskind config 7
7129uagentconfig 0
7130ret
7131end
7132uagentconfig config
7133umachines config
7134utunnelsload config
7135put g_n 34 500
7136limit_number = ukeyed config k_limit
7137if ne limit_number 0
7138limit_value = ujsonint limit_number
7139if and gt limit_value 0 lt limit_value 1000000
7140put g_n 34 limit_value
7141end
7142end
7143models = ukeyed config k_models
7144if not uiskind models 8
7145ret
7146end
7147default_name = ukeyed config k_default
7148count = umsg models usl m_count 0 0 0
7149sat = usl m_at
7150if uiskind default_name 9
7151for i ulong count bound 256
7152e = umsg models sat i 0 0
7153if uiskind e 7
7154name = ukeyed e k_name
7155if uiskind name 9
7156if eq and umsg name usl m_equal_string default_name 0 0 255 1
7157if utakemodel e
7158ret
7159end
7160end
7161end
7162end
7163end
7164end
7165for i ulong count bound 256
7166e = umsg models sat i 0 0
7167if utakemodel e
7168ret
7169end
7170end
7171end
7172
7173note show the answer in place of the list (on 1), or the list again (on 0)
7174fn uanswerview on ulong to void
7175s = usl m_set_hidden
7176x = umsg get g_o 28 s on 0 0
7177x = umsg get g_o 29 s sub 1 on 0 0
7178put g_n 20 on
7179end
7180
7181note put the answer so far on show
7182fn uanswershow to void
7183whole_talk = get g_m 4
7184if ne get g_m 25 0
7185whole_talk = umsg get g_m 25 usl m_append_string get g_m 4 0 0
7186end
7187x = umsg get g_o 30 usl m_set_string whole_talk 0 0
7188end
7189
7190note stop asking: the running task is cancelled and the list is back
7191fn uaskstop to void
7192if ne get g_m 6 0
7193x = umsg get g_m 6 usl m_cancel_task 0 0 0
7194put g_m 6 0
7195if ne get g_m 24 0
7196x = umsg get g_m 24 usl m_remove_last 0 0 0
7197end
7198put g_n 39 1
7199end
7200if eq get g_n 20 1
7201uanswerview 0
7202end
7203end
7204
7205note ask the model the typed text. The body is made by Foundation, so the text is quoted as JSON wants it
7206fn uask to void
7207if eq get g_m 3 0
7208ret
7209end
7210a = get g_n 12
7211n = get g_n 13
7212for i ulong n bound 256
7213put g_nm i get g_q add a i
7214end
7215put g_nm n 0
7216question = unsb
7217sset = usl m_set_object
7218message = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
7219x = umsg message sset uns x_user uns k_role 0
7220x = umsg message sset question uns k_content 0
7221if eq get g_m 24 0
7222talk = umsg ucl c_mutable_array usl m_array 0 0 0
7223put g_m 24 umsg talk usl m_retain 0 0 0
7224told = umsg ucl c_mutable_string usl m_string 0 0 0
7225put g_m 25 umsg told usl m_retain 0 0 0
7226end
7227note a question asked while another is on its way takes its place
7228if ne get g_m 6 0
7229x = umsg get g_m 6 usl m_cancel_task 0 0 0
7230put g_m 6 0
7231x = umsg get g_m 24 usl m_remove_last 0 0 0
7232put g_n 39 1
7233end
7234messages = umsg get g_m 24 usl m_array_adding message 0 0
7235body = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
7236x = umsg body sset get g_m 0 uns k_model 0
7237x = umsg body sset messages uns k_messages 0
7238yes = umsg ucl c_number usl m_number_bool 1 0 0
7239x = umsg body sset yes uns k_stream 0
7240data = umsg ucl c_json usl m_json_data body 0 0
7241url = umsg get g_o 16 get g_o 17 get g_m 1 0 0
7242if or eq data 0 eq url 0
7243ret
7244end
7245req = umsg ucl c_request usl m_request_url url 0 0
7246x = umsg req usl m_set_method uns x_post 0 0
7247x = umsg req usl m_set_header uns x_json_type uns x_content_type 0
7248if ne get g_m 21 0
7249secret_text = usecret get g_m 21
7250if eq secret_text 0
7251if eq get g_m 4 0
7252fresh_text = umsg ucl c_mutable_string usl m_string 0 0 0
7253put g_m 4 umsg fresh_text usl m_retain 0 0 0
7254end
7255x = umsg get g_m 4 usl m_set_string uns x_no_key 0 0
7256put g_n 21 1
7257put g_n 22 1
7258uanswershow
7259uanswerview 1
7260ret
7261end
7262bearer = umsg uns x_bearer usl m_append_string secret_text 0 0
7263x = umsg req usl m_set_header bearer uns x_authorization 0
7264end
7265x = umsg req usl m_set_body data 0 0
7266s_timeout = usl m_set_timeout
7267upr 64 bitcast ulong 120.0f64
7268x = umsg req s_timeout 0 0 0
7269if eq get g_m 5 0
7270cfg = umsg ucl c_session_config usl m_ephemeral 0 0 0
7271queue = umsg ucl c_queue usl m_main_queue 0 0 0
7272session = umsg ucl c_session usl m_session_with cfg get g_o 27 queue
7273put g_m 5 umsg session usl m_retain 0 0 0
7274end
7275if eq get g_m 4 0
7276fresh_text = umsg ucl c_mutable_string usl m_string 0 0 0
7277put g_m 4 umsg fresh_text usl m_retain 0 0 0
7278end
7279note what was on show joins what was said before; then the question
7280put g_nm 0 10
7281put g_nm 1 10
7282put g_nm 2 0
7283blank_line = unsb
7284sappend_text = usl m_append
7285if eq get g_n 39 1
7286x = umsg get g_m 25 sappend_text get g_m 4 0 0
7287x = umsg get g_m 25 sappend_text blank_line 0 0
7288end
7289x = umsg get g_m 25 sappend_text uns x_you 0 0
7290x = umsg get g_m 25 sappend_text question 0 0
7291x = umsg get g_m 25 sappend_text blank_line 0 0
7292x = umsg get g_m 24 usl m_add_object message 0 0
7293x = umsg get g_m 4 usl m_set_string uns x_asking 0 0
7294put g_n 19 0
7295put g_n 21 0
7296put g_n 22 0
7297put g_n 39 0
7298put g_n 40 0
7299uanswershow
7300uanswerview 1
7301task = umsg get g_m 5 usl m_data_task req 0 0
7302put g_m 6 umsg task usl m_retain 0 0 0
7303x = umsg task usl m_resume 0 0 0
7304end
7305
7306note a turn has ended: an answer joins the conversation; without one the question leaves it again, so that the
7307note model is not sent a question it never answered
7308fn uturnend to void
7309put g_n 39 1
7310if eq get g_m 24 0
7311ret
7312end
7313if or eq get g_n 40 1 eq get g_n 22 0
7314x = umsg get g_m 24 usl m_remove_last 0 0 0
7315ret
7316end
7317sset = usl m_set_object
7318reply = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
7319x = umsg reply sset uns x_assistant uns k_role 0
7320said = umsg ucl c_str usl m_utf umsg get g_m 4 get g_o 5 0 0 0 0 0
7321if eq said 0
7322x = umsg get g_m 24 usl m_remove_last 0 0 0
7323ret
7324end
7325x = umsg reply sset said uns k_content 0
7326x = umsg get g_m 24 usl m_add_object reply 0 0
7327end
7328
7329note New chat: the conversation is forgotten
7330fn uchatnew to void
7331if ne get g_m 33 0
7332x = umsg get g_m 33 usl m_release 0 0 0
7333put g_m 33 0
7334end
7335if ne get g_m 6 0
7336x = umsg get g_m 6 usl m_cancel_task 0 0 0
7337put g_m 6 0
7338end
7339srel = usl m_release
7340if ne get g_m 24 0
7341x = umsg get g_m 24 srel 0 0 0
7342x = umsg get g_m 25 srel 0 0 0
7343put g_m 24 0
7344put g_m 25 0
7345end
7346put g_n 39 0
7347if ne get g_m 4 0
7348put g_nm 0 0
7349no_text = unsb
7350x = umsg get g_m 4 usl m_set_string no_text 0 0
7351end
7352if eq get g_n 20 1
7353uanswerview 0
7354end
7355end
7356
7357note for a check: when the first answer has come, ask the second question (HOPASK2) in the same conversation
7358fn uasksecond to void
7359n = ucs x_env_ask2
7360upr 0 ulong libptr g_nm 0 1024
7361second_text = ucall 9
7362if or eq second_text 0 eq get g_n 21 0
7363ret
7364end
7365n = ucs x_env_asknew
7366upr 0 ulong libptr g_nm 0 1024
7367if ne ucall 9 0
7368uchatnew
7369end
7370n = ufetch second_text
7371second = unsb
7372x = umsg get g_o 0 get g_o 8 second 0 0
7373utyped
7374if and gt get g_n 1 0 eq ulong get g_rk 0 8
7375uask
7376end
7377end
7378
7379note a piece of the answer: the first one takes the place of "Asking ..."
7380fn uanswerpiece piece ulong to void
7381if eq get g_n 22 0
7382put g_nm 0 0
7383empty_text = unsb
7384x = umsg get g_m 4 usl m_set_string empty_text 0 0
7385put g_n 22 1
7386end
7387x = umsg get g_m 4 usl m_append piece 0 0
7388uanswershow
7389end
7390
7391note the JSON in g_net[o .. o+n) as an object (0 when it is not JSON)
7392fn unetjson o ulong n ulong to ulong
7393if or eq n 0 gt add o n 262144
7394ret 0
7395end
7396d = umsg ucl c_data usl m_data_bytes ulong libptr g_net o n n 0
7397ret umsg ucl c_json usl m_json_object d 0 0
7398end
7399
7400note one line from the server: "data: {...}" carries a piece of the answer at choices[0].delta.content
7401note (an empty line may stand first in what came: a server's packet may begin with the line break that ends an
7402note event, so nothing before the line is looked at when it is empty; "and" looks at both its sides)
7403fn unetline o ulong n ulong to void
7404ln = n
7405if gt ln 0
7406if eq ulong get g_net sub add o ln 1 13
7407ln = sub ln 1
7408end
7409end
7410if lt ln 6
7411ret
7412end
7413if or or ne ulong get g_net o 100 ne ulong get g_net add o 1 97 or ne ulong get g_net add o 2 116 or ne ulong get g_net add o 3 97 ne ulong get g_net add o 4 58
7414ret
7415end
7416pay_o = add o 5
7417pay_l = sub ln 5
7418while and gt pay_l 0 eq ulong get g_net pay_o 32 bound 300000
7419pay_o = add pay_o 1
7420pay_l = sub pay_l 1
7421end
7422obj = unetjson pay_o pay_l
7423if not uiskind obj 7
7424ret
7425end
7426choices = ukeyed obj k_choices
7427if not uiskind choices 8
7428ret
7429end
7430if eq umsg choices usl m_count 0 0 0 0
7431ret
7432end
7433choice = umsg choices usl m_at 0 0 0
7434if not uiskind choice 7
7435ret
7436end
7437delta = ukeyed choice k_delta
7438if not uiskind delta 7
7439ret
7440end
7441content = ukeyed delta k_content
7442if uiskind content 9
7443if gt umsg content usl m_length 0 0 0 0
7444uanswerpiece content
7445end
7446end
7447end
7448
7449note bytes from the server: add them to g_net, read every whole line, keep the rest
7450fn unetdata data ulong to void
7451p = umsg data usl m_bytes 0 0 0
7452n = umsg data usl m_length 0 0 0
7453fill = get g_n 19
7454if or eq p 0 gt add fill n 262144
7455put g_n 19 0
7456ret
7457end
7458if eq n 0
7459ret
7460end
7461upr 0 ulong libptr g_net fill n
7462upr 8 p
7463upr 16 n
7464x = ucall 8
7465fill = add fill n
7466line_start = ulong 0
7467i = ulong 0
7468while lt i fill bound 300000
7469if eq ulong get g_net i 10
7470unetline line_start sub i line_start
7471line_start = add i 1
7472end
7473i = add i 1
7474end
7475rest = sub fill line_start
7476for j ulong rest bound 300000
7477put g_net j get g_net add line_start j
7478end
7479put g_n 19 rest
7480end
7481
7482note the answer has ended (problem: what went wrong, or nothing). A server that did not stream gave one JSON
7483note object: its text is at choices[0].message.content
7484fn unetdone task ulong problem ulong to void
7485put g_n 21 1
7486if ne task get g_m 6
7487ret
7488end
7489put g_m 6 0
7490if ne problem 0
7491uanswerpiece umsg problem usl m_description 0 0 0
7492put g_n 40 1
7493uturnend
7494ret
7495end
7496if eq get g_n 22 0
7497obj = unetjson 0 get g_n 19
7498if uiskind obj 7
7499choices = ukeyed obj k_choices
7500if uiskind choices 8
7501if gt umsg choices usl m_count 0 0 0 0
7502choice = umsg choices usl m_at 0 0 0
7503if uiskind choice 7
7504message = ukeyed choice k_message
7505if uiskind message 7
7506content = ukeyed message k_content
7507if uiskind content 9
7508uanswerpiece content
7509end
7510end
7511end
7512end
7513end
7514end
7515end
7516if eq get g_n 22 0
7517code = umsg umsg task usl m_response 0 0 0 usl m_status_code 0 0 0
7518if ge code 300
7519p = ulong 0
7520if or eq code 429 eq code 503
7521p = uptxt 0 x_busy
7522end
7523p = uptxt p x_http
7524p = upnum p code
7525p = uptxt p x_bracket
7526put g_nm p 0
7527uanswerpiece unsb
7528else
7529uanswerpiece uns x_no_answer
7530end
7531put g_n 40 1
7532end
7533uturnend
7534end
7535
7536note the rows for typed text, by the one box's rules (fn swrank): the request is what Sources/SmartRank.swift
7537note sends, with the m matched apps of g_mk, their hopfuzz scores, use and habits, the web address and the files found, and
7538note the copied things that match, the saved accounts, the two screens and the two commands the panel has. The Ask row and the agent's row come back too.
7539note one word of a screen or a command into the request: its length as number k, its bytes at bp; the byte after
7540fn uwordput tb edit uchar 1048576 k ulong bp ulong t view uchar * to ulong
7541n = ucs t
7542upn tb k n
7543for i ulong n bound 64
7544put tb add bp i get g_nm i
7545end
7546ret add bp n
7547end
7548
7549fn urankrows m ulong to void
7550tb = new uchar 1048576 0
7551ob = new uchar 65544 0
7552a = get g_n 12
7553n = get g_n 13
7554nf = get g_n 17
7555uclipmatch 8
7556ncl = get g_n 28
7557nacc = get g_n 31
7558nr = get g_n 49
7559nfa = add nf nr
7560c = add add add add add 13 mul m 4 mul nfa 3 mul nacc 2 ncl 26
7561upn tb 0 n
7562upn tb 1 n
7563upn tb 2 get g_n 10
7564upn tb 3 1
7565exact_name = get g_n 18
7566if eq get g_n 58 1
7567exact_name = 1
7568end
7569upn tb 4 exact_name
7570upn tb 5 get g_n 41
7571words_typed = ulong 0
7572in_word = false
7573for i ulong n bound 256
7574cw = ulong get g_q add a i
7575if or eq cw 32 eq cw 9
7576in_word = false
7577else
7578if not in_word
7579words_typed = add words_typed 1
7580end
7581in_word = true
7582end
7583end
7584send_agent = ulong 0
7585if and eq get g_n 42 1 ge words_typed 3
7586send_agent = 1
7587end
7588upn tb 6 send_agent
7589upn tb 7 m
7590upn tb 8 nfa
7591for i ulong nr bound 64
7592o = add add 13 mul m 4 mul add nf i 3
7593upb tb o sub add k_b get g_rs i 100000
7594upn tb add o 1 0
7595upn tb add o 2 0
7596end
7597for i ulong 4
7598upn tb add 9 i 0
7599end
7600upn tb 12 ncl
7601upn tb 11 nacc
7602pacc = add add 13 mul m 4 mul nfa 3
7603note the screens the panel has (the copied things, the accounts) and what it can do (settings, quit), each with
7604note the words that name it (and Rebuild file index): a count, then the length of each word; the words themselves follow the typed text
7605q = add add pacc mul nacc 2 ncl
7606word_start = add add 8 mul c 8 n
7607bp = word_start
7608upn tb add q 0 3
7609bp = uwordput tb add q 1 bp x_word0
7610bp = uwordput tb add q 2 bp x_word1
7611bp = uwordput tb add q 3 bp x_word2
7612upn tb add q 4 5
7613bp = uwordput tb add q 5 bp x_word3
7614bp = uwordput tb add q 6 bp x_word4
7615bp = uwordput tb add q 7 bp x_word5
7616bp = uwordput tb add q 8 bp x_word6
7617bp = uwordput tb add q 9 bp x_word7
7618upn tb add q 10 1
7619bp = uwordput tb add q 11 bp x_word_agent
7620upn tb add q 12 4
7621bp = uwordput tb add q 13 bp x_word8
7622bp = uwordput tb add q 14 bp x_word9
7623bp = uwordput tb add q 15 bp x_word10
7624bp = uwordput tb add q 16 bp x_word11
7625upn tb add q 17 1
7626bp = uwordput tb add q 18 bp x_word12
7627upn tb add q 19 3
7628bp = uwordput tb add q 20 bp x_word_rebuild
7629bp = uwordput tb add q 21 bp x_word_reindex
7630bp = uwordput tb add q 22 bp x_word_index_files
7631upn tb add q 23 2
7632bp = uwordput tb add q 24 bp x_word_new_chat
7633bp = uwordput tb add q 25 bp x_word_clear_chat
7634word_bytes = sub bp word_start
7635upn tb 9 3
7636upn tb 10 4
7637for i ulong ncl bound 8
7638upn tb add add pacc mul nacc 2 i ulong get g_cp get g_cm i
7639end
7640if gt nacc 0
7641for i ulong n bound 256
7642put g_nm i get g_q add a i
7643end
7644put g_nm n 0
7645typed = unsb
7646typed_low = ulong 0
7647if ne typed 0
7648typed_low = umsg typed usl m_lowercase 0 0 0
7649end
7650slower = usl m_lowercase
7651scontains = usl m_contains
7652sprefix = usl m_has_prefix
7653for i ulong nacc bound 800
7654has = ulong 0
7655starts = ulong 0
7656if ne typed_low 0
7657name_low = umsg umsg get g_m 18 get g_m 16 i 0 0 slower 0 0 0
7658has = and umsg name_low scontains typed_low 0 0 255
7659starts = and umsg name_low sprefix typed_low 0 0 255
7660end
7661upn tb add pacc mul i 2 has
7662upn tb add add pacc mul i 2 1 starts
7663end
7664end
7665note an app's own use and habits count as in Hop: how much it is used, its lifts from the app in front and the
7666note hour, and whether it is the app that was in front before (all as they were when the panel was last shown)
7667for i ulong m bound 2048
7668o = add 13 mul i 4
7669k = get g_mk i
7670upn tb o get g_ms i
7671upn tb add o 1 get g_us k
7672upn tb add o 2 add get g_lf k get g_lh k
7673was_before = ulong 0
7674if eq add k 1 get g_n 32
7675was_before = 1
7676end
7677upn tb add o 3 was_before
7678end
7679note a file's score may be below zero: it goes in as 2^40 plus the score, written as it is
7680for i ulong nf bound 64
7681o = add add 13 mul m 4 mul i 3
7682upb tb o sub add k_b get g_fs i 100000
7683upn tb add o 1 0
7684upn tb add o 2 uisapp i m
7685end
7686lo = add 8 mul c 8
7687for i ulong n bound 256
7688put tb add lo i uchar ulower ulong get g_q add a i
7689end
7690k = swrank tb c add n word_bytes ob
7691h = ulong 0
7692if ne k 0
7693rws = sub uog ob 0 k_b
7694for i ulong rws bound 1024
7695knd = sub uog ob add 1 mul i 4 k_b
7696ix = sub uog ob add 2 mul i 4 k_b
7697if and eq knd 1 lt ix m
7698put g_rk h 1
7699put g_hit h get g_mk ix
7700h = add h 1
7701end
7702if eq knd 2
7703put g_rk h 2
7704put g_hit h 0
7705h = add h 1
7706end
7707if and eq knd 7 lt ix nf
7708put g_rk h 7
7709put g_hit h ix
7710h = add h 1
7711end
7712if and and eq knd 7 ge ix nf lt ix nfa
7713put g_rk h 10
7714put g_hit h sub ix nf
7715h = add h 1
7716end
7717if eq knd 8
7718put g_rk h 8
7719put g_hit h 0
7720h = add h 1
7721end
7722if eq knd 9
7723put g_rk h 9
7724put g_hit h 0
7725h = add h 1
7726end
7727if and eq knd 6 lt ix ncl
7728put g_rk h 6
7729put g_hit h get g_cm ix
7730h = add h 1
7731end
7732if and eq knd 5 lt ix nacc
7733put g_rk h 5
7734put g_hit h ix
7735h = add h 1
7736end
7737if and eq knd 3 lt ix 3
7738put g_rk h 3
7739put g_hit h ix
7740h = add h 1
7741end
7742if and eq knd 4 lt ix 4
7743put g_rk h 4
7744put g_hit h ix
7745h = add h 1
7746end
7747end
7748end
7749put g_n 1 h
7750end
7751
7752note ---- before anything is typed: what to offer, by Hop's rule (fn swsuggest, fn swlifts) ----
7753note the path of app k into g_nm from byte p (its folder, "/", its name, ".app"); the byte after it
7754fn uapppath p ulong k ulong to ulong
7755q = p
7756if eq ulong get g_dir k 0
7757q = uptxt p x_dir1
7758else
7759q = uptxt p x_dir2
7760end
7761q = uptxt q x_slash
7762q = upname q k
7763ret uptxt q x_dotapp
7764end
7765
7766note byte j of app k's name with ".app" after it (0 past the end): what its path is ordered by within a folder
7767fn ukeybyte k ulong j ulong to ulong
7768n = get g_ln k
7769if lt j n
7770ret ulong get g_pool add get g_off k j
7771end
7772if lt j add n 4
7773ret ulong get x_dotapp sub j n
7774end
7775ret 0
7776end
7777
7778note does app a come before app b in the order of their paths
7779fn uappless a ulong b ulong to bool
7780da = ulong get g_dir a
7781db = ulong get g_dir b
7782if ne da db
7783ret lt da db
7784end
7785for j ulong 1100
7786ca = ukeybyte a j
7787cb = ukeybyte b j
7788if ne ca cb
7789ret lt ca cb
7790end
7791if eq ca 0
7792ret false
7793end
7794end
7795ret false
7796end
7797
7798note each app's path and place into a dictionary, and the apps into the order of their paths
7799fn ubuildmap to void
7800map = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
7801put g_m 10 umsg map usl m_retain 0 0 0
7802sset = usl m_set_object
7803snum = usl m_number_integer
7804cnum = ucl c_number
7805for k ulong get g_n 0 bound 2048
7806p = uapppath 0 k
7807put g_nm p 0
7808path = unsb
7809num = umsg cnum snum k 0 0
7810x = umsg map sset num path 0
7811pos = k
7812while gt pos 0 bound 4096
7813if not uappless k get g_so sub pos 1
7814break
7815end
7816put g_so pos get g_so sub pos 1
7817pos = sub pos 1
7818end
7819put g_so pos k
7820end
7821end
7822
7823note the place of the app at this path (an NSString), or the count of apps when it is not one of them
7824fn uplaceof path ulong to ulong
7825if or eq path 0 eq get g_m 10 0
7826ret get g_n 0
7827end
7828num = umsg get g_m 10 usl m_object_for_key path 0 0
7829if eq num 0
7830ret get g_n 0
7831end
7832ret umsg num usl m_integer_value 0 0 0
7833end
7834
7835note how much the user's own use lifts a path: 25 times the base-2 logarithm of 1 plus the count of openings, the
7836note count halved for every three days since the last, plus 10; 80 at most (Sources/Recents.swift)
7837fn uboost cnt ulong last_bits ulong now_bits ulong to ulong
7838age = sub bitcast f64 now_bits bitcast f64 last_bits
7839upr 64 bitcast ulong 0.5f64
7840upr 72 bitcast ulong div age 259200.0f64
7841x = ucall 14
7842weighed = mul f64 cnt bitcast f64 ugr 64
7843upr 64 bitcast ulong add 1.0f64 weighed
7844x = ucall 15
7845v = add mul 25.0f64 bitcast f64 ugr 64 10.0f64
7846if gt v 80.0f64
7847ret 80
7848end
7849if lt v 0.0f64
7850ret 0
7851end
7852ret ulong v
7853end
7854
7855note remember the app in front (not this program) before the panel takes its place
7856fn ufront to void
7857ws = umsg ucl c_ws usl m_shws 0 0 0
7858app_front = umsg ws usl m_frontmost 0 0 0
7859this_app = umsg ucl c_running_app usl m_current_app 0 0 0
7860if or eq app_front 0 eq app_front this_app
7861ret
7862end
7863sret = usl m_retain
7864id = umsg app_front usl m_bundle_id 0 0 0
7865put g_m 11 0
7866if ne id 0
7867put g_m 11 umsg id sret 0 0 0
7868end
7869name = umsg app_front usl m_localized_name 0 0 0
7870put g_m 12 0
7871if ne name 0
7872put g_m 12 umsg name sret 0 0 0
7873end
7874put g_m 13 0
7875url = umsg app_front usl m_bundle_url 0 0 0
7876if eq url 0
7877ret
7878end
7879k = uplaceof umsg url usl m_path 0 0 0
7880if ge k get g_n 0
7881ret
7882end
7883put g_m 13 add k 1
7884note newest first, each app once
7885found = ulong 11
7886for i ulong 12
7887if and eq get g_fr i add k 1 eq found 11
7888found = i
7889end
7890end
7891pos = found
7892while gt pos 0 bound 16
7893put g_fr pos get g_fr sub pos 1
7894pos = sub pos 1
7895end
7896put g_fr 0 add k 1
7897end
7898
7899note is the JSON value a number (a file a person may have edited can hold anything where a number belongs, and
7900note only a number can be asked for its value: a null, a list or a group asked so would stop the program)
7901fn uisnumber obj ulong to bool
7902if eq obj 0
7903ret false
7904end
7905ret eq and umsg obj usl m_is_kind ucl c_number 0 0 255 1
7906end
7907
7908note a whole number from a JSON value (0 when it is none); below zero comes back as a number of 2^63 and up
7909fn ujsonint obj ulong to ulong
7910if not uisnumber obj
7911ret 0
7912end
7913ret umsg obj usl m_integer_value 0 0 0
7914end
7915
7916note the rows before anything is typed: the lifts from habit, the use, what is running and what was in front go
7917note to the rule as numbers, in the order of the apps' paths; the app in front is never offered
7918fn usuggest to void
7919tb = new uchar 1048576 0
7920ob = new uchar 65544 0
7921na = get g_n 0
7922put g_n 1 0
7923if eq get g_m 10 0
7924ret
7925end
7926note the lifts from habit
7927for k ulong na bound 2048
7928put g_lf k 0
7929put g_lh k 0
7930put g_us k 0
7931put g_rn k 0
7932end
7933cal = umsg ucl c_calendar usl m_current_calendar 0 0 0
7934now_date = umsg ucl c_date usl m_date_now 0 0 0
7935hour = umsg cal usl m_component 32 now_date 0
7936front_id = get g_m 11
7937nl = ulong 0
7938habits = ulong 0
7939d = uhopfile x_habits
7940if ne d 0
7941habits = umsg ucl c_json usl m_json_object d 0 0
7942end
7943if uiskind habits 8
7944nl = umsg habits usl m_count 0 0 0
7945if gt nl 4096
7946nl = 4096
7947end
7948end
7949upn tb 0 hour
7950front_number = ulong 0
7951if ne front_id 0
7952front_number = 1
7953end
7954upn tb 1 front_number
7955upn tb 2 na
7956upn tb 3 nl
7957sat = usl m_at
7958for j ulong nl bound 4096
7959o = add 4 mul j 3
7960launch = umsg habits sat j 0 0
7961here = ulong 0
7962hr = ulong 0
7963place = na
7964if uiskind launch 7
7965from = ukeyed launch k_from
7966if and ne front_id 0 uiskind from 9
7967if eq and umsg from usl m_equal_string front_id 0 0 255 1
7968here = 1
7969end
7970end
7971hr = ujsonint ukeyed launch k_hour
7972opened = ukeyed launch k_app
7973if uiskind opened 9
7974place = uplaceof opened
7975end
7976end
7977upn tb o here
7978if ge hr 9223372036854775808
7979upb tb add o 1 sub k_b add xor hr 18446744073709551615 1
7980else
7981if gt hr 1000000
7982hr = 1000000
7983end
7984upn tb add o 1 hr
7985end
7986if lt place na
7987upn tb add o 2 place
7988else
7989upb tb add o 2 sub k_b 1
7990end
7991end
7992k1 = swlifts tb add 4 mul nl 3 ob
7993if ne k1 0
7994for k ulong na bound 2048
7995put g_lf k sub uog ob add 1 mul k 2 k_b
7996put g_lh k sub uog ob add 2 mul k 2 k_b
7997end
7998end
7999note how much each app is used
8000recents = ulong 0
8001d = uhopfile x_recents
8002if ne d 0
8003recents = umsg ucl c_json usl m_json_object d 0 0
8004end
8005if uiskind recents 7
8006x = umsg ucl c_date usl m_reference_now 0 0 0
8007now_bits = ugr 64
8008for k ulong na bound 2048
8009p = uptxt 0 x_mac_key
8010p = uapppath p k
8011put g_nm p 0
8012key = unsb
8013e = umsg recents usl m_object_for_key key 0 0
8014if uiskind e 7
8015cnt = ujsonint ukeyed e k_count
8016last = ukeyed e k_last
8017if and uisnumber last lt cnt 1000000000
8018x = umsg last usl m_double_value 0 0 0
8019put g_us k uboost cnt ugr 64 now_bits
8020end
8021end
8022end
8023end
8024note what is running (apps a person sees: the regular ones)
8025ws = umsg ucl c_ws usl m_shws 0 0 0
8026running = umsg ws usl m_running_apps 0 0 0
8027if ne running 0
8028nr = umsg running usl m_count 0 0 0
8029for j ulong nr bound 4096
8030r = umsg running sat j 0 0
8031if eq umsg r usl m_policy_of 0 0 0 0
8032url = umsg r usl m_bundle_url 0 0 0
8033if ne url 0
8034k = uplaceof umsg url usl m_path 0 0 0
8035if lt k na
8036put g_rn k 1
8037end
8038end
8039end
8040end
8041end
8042note the app in front before: the newest remembered one that is not in front now
8043front_place = get g_m 13
8044previous = ulong 0
8045for i ulong 12
8046if and and eq previous 0 ne get g_fr i 0 ne get g_fr i front_place
8047previous = get g_fr i
8048end
8049end
8050put g_n 32 previous
8051note the request of fn swsuggest: what was copied, then six numbers an app
8052for i ulong 6
8053upn tb i 0
8054end
8055ncl = get g_n 24
8056nrest = ulong 0
8057put g_n 25 0
8058put g_n 26 0
8059if gt ncl 0
8060upn tb 0 1
8061newest = umsg get g_m 14 get g_m 16 0 0 0
8062age = ulong 0
8063if uiskind newest 7
8064moment = ukeyed newest k_date
8065if uisnumber moment
8066x = umsg moment usl m_double_value 0 0 0
8067then_bits = ugr 64
8068x = umsg ucl c_date usl m_reference_now 0 0 0
8069gap = sub bitcast f64 ugr 64 bitcast f64 then_bits
8070if gt gap 0.0f64
8071age = 1000000000
8072if lt gap 1000000000.0f64
8073age = ulong gap
8074end
8075end
8076end
8077words = ukeyed newest k_text
8078if uiskind words 9
8079wb = umsg words get g_o 5 0 0 0
8080if ne wb 0
8081upr 0 wb
8082wn = ucall 7
8083if and ge wn 4 le wn 255
8084upr 0 ulong libptr g_ca 0 wn
8085upr 8 wb
8086upr 16 wn
8087x = ucall 8
8088if and and eq ulower ulong get g_ca 0 104 eq ulower ulong get g_ca 1 116 and eq ulower ulong get g_ca 2 116 eq ulower ulong get g_ca 3 112
8089put g_n 25 wn
8090uclipaddr 1
8091udecide
8092put g_n 26 get g_n 10
8093uclipaddr 0
8094end
8095end
8096end
8097end
8098end
8099upn tb 1 age
8100if ne get g_n 26 0
8101upn tb 2 1
8102end
8103upn tb 3 ufrontbrowser
8104for pos ulong ncl bound 1024
8105i = get g_ci pos
8106if and ne i 0 lt nrest 20
8107put g_cr nrest i
8108nrest = add nrest 1
8109end
8110end
8111upn tb 4 nrest
8112end
8113put g_n 27 nrest
8114upn tb 6 na
8115for pos ulong na bound 2048
8116k = get g_so pos
8117o = add 7 mul pos 6
8118if eq add k 1 front_place
8119for i ulong 6
8120upn tb add o i 0
8121end
8122else
8123upn tb o get g_lf k
8124upn tb add o 1 get g_lh k
8125upn tb add o 2 get g_us k
8126upn tb add o 3 ulong get g_rn k
8127was_before = ulong 0
8128if eq add k 1 previous
8129was_before = 1
8130end
8131upn tb add o 4 was_before
8132lately = ulong 0
8133for i ulong 5
8134if eq get g_fr i add k 1
8135lately = sub 10 mul 2 i
8136end
8137end
8138upn tb add o 5 lately
8139end
8140end
8141k2 = swsuggest tb add 7 mul na 6 ob
8142h = ulong 0
8143if ne k2 0
8144rws = sub uog ob 0 k_b
8145for i ulong rws bound 64
8146knd = sub uog ob add 1 mul i 4 k_b
8147ix = sub uog ob add 2 mul i 4 k_b
8148if and eq knd 1 lt ix na
8149put g_rk h 1
8150put g_hit h get g_so ix
8151put g_why h uchar sub uog ob add 4 mul i 4 k_b
8152h = add h 1
8153end
8154if and eq knd 6 le ix nrest
8155put g_rk h 6
8156if eq ix 0
8157put g_hit h 0
8158else
8159put g_hit h get g_cr sub ix 1
8160end
8161put g_why h uchar sub uog ob add 4 mul i 4 k_b
8162h = add h 1
8163end
8164if and eq knd 2 ne get g_n 26 0
8165put g_rk h 2
8166put g_hit h 0
8167put g_why h 3
8168h = add h 1
8169end
8170end
8171end
8172put g_n 1 h
8173end
8174
8175note ---- remembering what was opened, as Hop does (Habits.record in Sources/Smart.swift, Sources/Recents.swift) ----
8176note Both files are read again at that moment and written whole, all at once. A file that is there but is not
8177note what Hop writes is left alone. While Hop itself runs it keeps its own copy and writes that over the file the
8178note next time it remembers something, so what the panel added then is lost.
8179note write the JSON object obj as Hop's file named t; private: only the owner may read it; 1 when it was written
8180fn uhopwrite obj ulong t view uchar * private ulong to ulong
8181data = umsg ucl c_json usl m_json_data obj 0 0
8182if eq data 0
8183ret 0
8184end
8185s_write = usl m_write_file
8186path = uhoppath t
8187if eq path 0
8188ret 0
8189end
8190ok = and umsg data s_write path 1 0 255
8191if and eq ok 1 eq private 1
8192path = uhoppath t
8193upr 0 ulong libptr g_nm 0 1024
8194upr 8 384
8195x = ucall 16
8196end
8197ret ok
8198end
8199
8200note the weight of an entry of recents.json: its count of openings, halved for every three days since the last
8201fn urecentweight e ulong now_bits ulong to ulong
8202if not uiskind e 7
8203ret bitcast ulong 0.0f64
8204end
8205cnt = ujsonint ukeyed e k_count
8206if ge cnt 1000000000
8207cnt = 0
8208end
8209last = ukeyed e k_last
8210if not uisnumber last
8211ret bitcast ulong 0.0f64
8212end
8213x = umsg last usl m_double_value 0 0 0
8214last_bits = ugr 64
8215age = sub bitcast f64 now_bits bitcast f64 last_bits
8216upr 64 bitcast ulong 0.5f64
8217upr 72 bitcast ulong div age 259200.0f64
8218x = ucall 14
8219ret bitcast ulong mul f64 cnt bitcast f64 ugr 64
8220end
8221
8222note one more opening of path (an NSString) into recents.json: its count up by one, now as the last time; over 500
8223note entries the one that weighs least goes
8224fn urecent path ulong to void
8225recents = ulong 0
8226d = uhopfile x_recents
8227if ne d 0
8228recents = umsg ucl c_json usl m_json_object d 1 0
8229if not uiskind recents 7
8230ret
8231end
8232else
8233recents = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
8234end
8235prefix = uns x_mac_key
8236key = umsg prefix usl m_append_string path 0 0
8237sset = usl m_set_object
8238cnum = ucl c_number
8239e = umsg recents usl m_object_for_key key 0 0
8240cnt = ulong 0
8241if uiskind e 7
8242cnt = ujsonint ukeyed e k_count
8243if ge cnt 1000000000
8244cnt = 0
8245end
8246else
8247e = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
8248key_path = uns k_path
8249x = umsg e sset path key_path 0
8250x = umsg recents sset e key 0
8251end
8252num = umsg cnum usl m_number_integer add cnt 1 0 0
8253key_count = uns k_count
8254x = umsg e sset num key_count 0
8255x = umsg ucl c_date usl m_reference_now 0 0 0
8256now_bits = ugr 64
8257s_double = usl m_number_double
8258upr 64 now_bits
8259last = umsg cnum s_double 0 0 0
8260key_last = uns k_last
8261x = umsg e sset last key_last 0
8262n = umsg recents usl m_count 0 0 0
8263if gt n 500
8264keys = umsg recents usl m_all_keys 0 0 0
8265sat = usl m_at
8266least = ulong 0
8267least_bits = ulong 0
8268for i ulong n bound 4096
8269k = umsg keys sat i 0 0
8270w = urecentweight umsg recents usl m_object_for_key k 0 0 now_bits
8271if or eq least 0 lt bitcast f64 w bitcast f64 least_bits
8272least = k
8273least_bits = w
8274end
8275end
8276if ne least 0
8277x = umsg recents usl m_remove_key least 0 0
8278end
8279end
8280x = uhopwrite recents x_recents 0
8281end
8282
8283note app k was opened: into recents.json, and into habits.json with the app that was in front and the hour (the
8284note newest 400 are kept)
8285fn urecordapp k ulong to void
8286p = uapppath 0 k
8287put g_nm p 0
8288path = unsb
8289urecent path
8290habits = ulong 0
8291d = uhopfile x_habits
8292if ne d 0
8293habits = umsg ucl c_json usl m_json_object d 1 0
8294if not uiskind habits 8
8295ret
8296end
8297else
8298habits = umsg ucl c_mutable_array usl m_array 0 0 0
8299end
8300cal = umsg ucl c_calendar usl m_current_calendar 0 0 0
8301now_date = umsg ucl c_date usl m_date_now 0 0 0
8302hour = umsg cal usl m_component 32 now_date 0
8303x = umsg ucl c_date usl m_reference_now 0 0 0
8304now_bits = ugr 64
8305cnum = ucl c_number
8306sset = usl m_set_object
8307launch = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
8308key_app = uns k_app
8309x = umsg launch sset path key_app 0
8310from_id = get g_m 11
8311if eq from_id 0
8312put g_nm 0 0
8313from_id = unsb
8314end
8315key_from = uns k_from
8316x = umsg launch sset from_id key_from 0
8317num = umsg cnum usl m_number_integer hour 0 0
8318key_hour = uns k_hour
8319x = umsg launch sset num key_hour 0
8320s_double = usl m_number_double
8321upr 64 now_bits
8322moment = umsg cnum s_double 0 0 0
8323key_moment = uns k_at_key
8324x = umsg launch sset moment key_moment 0
8325x = umsg habits usl m_add_object launch 0 0
8326n = umsg habits usl m_count 0 0 0
8327if gt n 400
8328x = umsg habits usl m_remove_range 0 sub n 400 0
8329end
8330x = uhopwrite habits x_habits 1
8331end
8332
8333note best file i was opened: into recents.json under its whole path
8334fn urecordfile i ulong to void
8335p = ufilepath 0 i
8336if eq p 0
8337ret
8338end
8339put g_nm p 0
8340path = unsb
8341urecent path
8342end
8343
8344note why an offered app is offered into g_nm from byte p (nothing for a typed row); the byte after it
8345fn uwhy p ulong r ulong to ulong
8346w = ulong get g_why r
8347if or ne get g_n 13 0 eq w 0
8348ret p
8349end
8350q = uptxt p x_gap
8351if eq w 1
8352ret uptxt q x_why1
8353end
8354if eq w 2
8355ret uptxt q x_why2
8356end
8357if eq w 3
8358ret uptxt q x_why3
8359end
8360if eq w 4
8361q = uptxt q x_why4
8362name = get g_m 12
8363if eq name 0
8364ret uptxt q x_here
8365end
8366name_bytes = umsg name get g_o 5 0 0 0
8367upr 0 name_bytes
8368n = ucall 7
8369if gt n 200
8370n = 200
8371end
8372upr 0 ulong libptr g_nm q n
8373upr 8 name_bytes
8374upr 16 n
8375x = ucall 8
8376ret add q n
8377end
8378if eq w 5
8379ret uptxt q x_why5
8380end
8381if eq w 6
8382ret uptxt q x_why6
8383end
8384if eq w 7
8385ret uptxt q x_why7
8386end
8387ret uptxt q x_why8
8388end
8389
8390note ---- building the file index, as Hop builds it (Sources/FileIndex.swift, rebuild) ----
8391note The program run with the one argument "index" walks the folders of Hop's settings (indexRoots; without
8392note settings the home folder, /Applications and /System/Applications) at throttled disk priority with the walker
8393note Hop uses (NSFileManager's, hidden things left out), and writes every path, a line each, as Hop's
8394note file-index.bin, all at once, for the owner only. A folder with one of the names to skip, or one that is a
8395note link, is left out with all in it; a package (an app, a document that is a folder) is one line. Three million
8396note lines at most. It is a program of its own run beside the panel, because the panel does one thing at a time.
8397note is the resource named key of the URL u set (a yes among its values)
8398fn uresource u ulong sget ulong key ulong to bool
8399for i ulong 8
8400put g_t8 i 0
8401end
8402x = umsg u sget ulong libptr g_t8 0 8 key 0
8403v = uread8
8404if eq v 0
8405ret false
8406end
8407ret eq and umsg v usl m_bool_value 0 0 0 255 1
8408end
8409
8410fn uindexbuild to ulong
8411upr 0 0
8412upr 8 0
8413upr 16 3
8414x = ucall 29
8415folder_roots = ulong 0
8416skip_names = ulong 0
8417d = uhopfile x_config
8418if ne d 0
8419config = umsg ucl c_json usl m_json_object d 0 0
8420if uiskind config 7
8421folder_roots = ukeyed config k_roots
8422if not uiskind folder_roots 8
8423folder_roots = 0
8424end
8425skip_names = ukeyed config k_skip_names
8426if not uiskind skip_names 8
8427skip_names = 0
8428end
8429end
8430end
8431sadd = usl m_add_object
8432if eq folder_roots 0
8433folder_roots = umsg ucl c_mutable_array usl m_array 0 0 0
8434x = ucall 30
8435home_folder = ugr 0
8436if ne home_folder 0
8437x = umsg folder_roots sadd home_folder 0 0
8438end
8439x = umsg folder_roots sadd uns x_applications 0 0
8440x = umsg folder_roots sadd uns x_system_applications 0 0
8441end
8442if eq skip_names 0
8443skip_names = umsg ucl c_mutable_array usl m_array 0 0 0
8444x = umsg skip_names sadd uns x_skipname0 0 0
8445x = umsg skip_names sadd uns x_skipname1 0 0
8446x = umsg skip_names sadd uns x_skipname2 0 0
8447x = umsg skip_names sadd uns x_skipname3 0 0
8448x = umsg skip_names sadd uns x_skipname4 0 0
8449x = umsg skip_names sadd uns x_skipname5 0 0
8450x = umsg skip_names sadd uns x_skipname6 0 0
8451x = umsg skip_names sadd uns x_skipname7 0 0
8452x = umsg skip_names sadd uns x_skipname8 0 0
8453x = umsg skip_names sadd uns x_skipname9 0 0
8454x = umsg skip_names sadd uns x_skipname10 0 0
8455x = umsg skip_names sadd uns x_skipname11 0 0
8456x = umsg skip_names sadd uns x_skipname12 0 0
8457x = umsg skip_names sadd uns x_skipname13 0 0
8458x = umsg skip_names sadd uns x_skipname14 0 0
8459x = umsg skip_names sadd uns x_skipname15 0 0
8460end
8461skip_set = umsg ucl c_set usl m_set_with_array skip_names 0 0
8462key_dir = uconst s_key_directory
8463key_pkg = uconst s_key_package
8464key_link = uconst s_key_link
8465wanted_keys = umsg ucl c_mutable_array usl m_array 0 0 0
8466x = umsg wanted_keys sadd key_dir 0 0
8467x = umsg wanted_keys sadd key_pkg 0 0
8468x = umsg wanted_keys sadd key_link 0 0
8469manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
8470index_lines = umsg ucl c_mutable_data usl m_data 0 0 0
8471sappend = usl m_append_bytes
8472snext = usl m_next_object
8473sget = usl m_get_resource
8474spath = usl m_path
8475slast = usl m_last_component
8476sskip = usl m_skip_descendants
8477shas = usl m_contains_object
8478s_enum = usl m_enumerator
8479sat = usl m_at
8480c_p = ucl c_pool
8481salloc = usl m_alloc
8482sinit = usl m_init
8483sdrain = usl m_drain
8484sfurl = usl m_furl
8485c_u = ucl c_url
8486put g_nl 0 10
8487listed = ulong 0
8488nroots = umsg folder_roots usl m_count 0 0 0
8489for ri ulong nroots bound 64
8490folder_root = umsg folder_roots sat ri 0 0
8491if uiskind folder_root 9
8492folder_url = umsg c_u sfurl folder_root 0 0
8493upr 40 0
8494en = umsg manager s_enum folder_url wanted_keys 4
8495if ne en 0
8496walking = true
8497for portion ulong 3001 bound 3001
8498if walking
8499walk_pool = umsg umsg c_p salloc 0 0 0 sinit 0 0 0
8500for turn ulong 1000 bound 1000
8501if and walking lt listed 3000000
8502u = umsg en snext 0 0 0
8503if eq u 0
8504walking = false
8505else
8506list_it = true
8507if uresource u sget key_dir
8508item_name = umsg u slast 0 0 0
8509skip_it = eq and umsg skip_set shas item_name 0 0 255 1
8510if not skip_it
8511skip_it = uresource u sget key_link
8512end
8513if skip_it
8514x = umsg en sskip 0 0 0
8515list_it = false
8516else
8517if uresource u sget key_pkg
8518x = umsg en sskip 0 0 0
8519end
8520end
8521end
8522if list_it
8523path_bytes = umsg umsg u spath 0 0 0 get g_o 5 0 0 0
8524if ne path_bytes 0
8525upr 0 path_bytes
8526pn = ucall 7
8527x = umsg index_lines sappend path_bytes pn 0
8528x = umsg index_lines sappend ulong libptr g_nl 0 1 1 0
8529listed = add listed 1
8530end
8531end
8532end
8533end
8534end
8535x = umsg walk_pool sdrain 0 0 0
8536if ge listed 3000000
8537walking = false
8538end
8539end
8540end
8541end
8542end
8543end
8544s_write = usl m_write_file
8545path = uhoppath x_index
8546if eq path 0
8547ret 1
8548end
8549ok = and umsg index_lines s_write path 1 0 255
8550path = uhoppath x_index
8551upr 0 ulong libptr g_nm 0 1024
8552upr 8 384
8553x = ucall 16
8554p = uptxt 0 x_indexed
8555p = upnum p listed
8556p = uptxt p x_items
8557put g_nm p 10
8558upr 0 1
8559upr 8 ulong libptr g_nm 0 1024
8560upr 16 add p 1
8561x = ucall 3
8562if eq ok 1
8563ret 0
8564end
8565ret 1
8566end
8567
8568note when the program was run with the one argument "index": build the index (0 done, 1 not written); else 2
8569fn uindexmode to ulong
8570run_arguments = umsg umsg ucl c_process_info usl m_process_info 0 0 0 usl m_arguments 0 0 0
8571if eq run_arguments 0
8572ret 2
8573end
8574if le umsg run_arguments usl m_count 0 0 0 1
8575ret 2
8576end
8577first_argument = umsg run_arguments get g_m 16 1 0 0
8578if ne and umsg first_argument usl m_equal_string uns x_index_word 0 0 255 1
8579ret 2
8580end
8581ret uindexbuild
8582end
8583
8584note start building the file index in a program of its own (this one, run with "index"); one at a time
8585fn uindexstart to void
8586if ne get g_m 23 0
8587ret
8588end
8589exe = umsg umsg ucl c_bundle usl m_main_bundle 0 0 0 usl m_executable_path 0 0 0
8590if eq exe 0
8591ret
8592end
8593task = umsg ucl c_task usl m_alloc 0 0 0
8594task = umsg task usl m_init 0 0 0
8595x = umsg task usl m_set_launch exe 0 0
8596arguments = umsg ucl c_mutable_array usl m_array 0 0 0
8597x = umsg arguments usl m_add_object uns x_index_word 0 0
8598x = umsg task usl m_set_arguments arguments 0 0
8599quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
8600x = umsg task usl m_set_output quiet 0 0
8601x = umsg task usl m_launch 0 0 0
8602put g_m 23 umsg task usl m_retain 0 0 0
8603ushowst
8604end
8605
8606note is the file index missing, or older than half an hour (Hop builds it anew that often)
8607fn uindexstale to bool
8608path = uhoppath x_index
8609if eq path 0
8610ret false
8611end
8612manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
8613attributes = umsg manager usl m_attributes_of path 0 0
8614if eq attributes 0
8615ret true
8616end
8617changed = umsg attributes usl m_object_for_key uconst s_modified 0 0
8618if eq changed 0
8619ret true
8620end
8621x = umsg changed usl m_since_now 0 0 0
8622age = sub 0.0f64 bitcast f64 ugr 64
8623ret gt age 1800.0f64
8624end
8625
8626note twice a second: when the program building the index has ended, read the new index and show the list anew;
8627note every half hour, and when the panel starts, build it anew when it is old and Hop is not there to do it
8628fn uindextick to void
8629if ne get g_m 23 0
8630if eq and umsg get g_m 23 usl m_is_running 0 0 0 255 0
8631x = umsg get g_m 23 usl m_release 0 0 0
8632put g_m 23 0
8633uloadindex
8634if ne get g_n 13 0
8635unarrow
8636x = umsg get g_o 1 get g_o 7 0 0 0
8637end
8638ushowst
8639end
8640ret
8641end
8642put g_n 38 add get g_n 38 1
8643if ge get g_n 38 3600
8644put g_n 38 0
8645if and not uhoprunning uindexstale
8646uindexstart
8647end
8648if not uhoprunning
8649uremoterefreshall
8650end
8651end
8652end
8653
8654note ---- the agent: the person's coding agent, run on this Mac for the typed text (Sources/Model.swift, runAgent) ----
8655note Hop's settings name the agents (each a name and a command, "{prompt}" standing for the request) and the one
8656note to use. Only that one is ever run, and only when it is installed: the look goes through the login shell
8657note with the usual tool folders added, as Hop's does. The command runs through the same wrapper as in Hop, in
8658note the folder of the settings; what it prints is shown as it comes (the lines of Claude Code's stream are read
8659note for their text and the tools they name). Hop's standing instructions ride along. Not here yet: what the
8660note knowledge base knows, and the count of tokens.
8661note an NSString of text t with every "~" turned into a double quote
8662fn uquoted t view uchar * to ulong
8663put g_nm 0 34
8664put g_nm 1 0
8665quote_mark = unsb
8666plain = uns t
8667ret umsg plain usl m_replace uns x_tilde quote_mark 0
8668end
8669
8670note the words of text t (separated by "|") as an array
8671fn uwords t view uchar * to ulong
8672whole = uns t
8673ret umsg whole usl m_components uns x_bar 0 0
8674end
8675
8676note an agent: a name and a command
8677fn uengine name ulong command ulong to ulong
8678e = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
8679sset = usl m_set_object
8680x = umsg e sset name uns k_name 0
8681x = umsg e sset command uns k_command 0
8682ret e
8683end
8684
8685note is the JSON value v a yes: JSON's own true and nothing else, as Hop reads its settings (a null, a number,
8686note a text, a list or a group is not)
8687fn uyes v ulong to bool
8688if eq v 0
8689ret false
8690end
8691ret eq v uconst s_cf_true
8692end
8693
8694note the agents Hop has out of the box (none of them switches a tool's own approval prompts or sandbox off)
8695fn uenginedefaults to ulong
8696all_engines = umsg ucl c_mutable_array usl m_array 0 0 0
8697sadd = usl m_add_object
8698x = umsg all_engines sadd uengine uns x_engine0 uwords x_engine0_command 0 0
8699x = umsg all_engines sadd uengine uns x_engine1 uwords x_engine1_command 0 0
8700x = umsg all_engines sadd uengine uns x_engine2 uwords x_engine2_command 0 0
8701x = umsg all_engines sadd uengine uns x_engine3 uwords x_engine3_command 0 0
8702x = umsg all_engines sadd uengine uns x_engine4 uwords x_engine4_command 0 0
8703x = umsg all_engines sadd uengine uns x_engine5 uwords x_engine5_command 0 0
8704x = umsg all_engines sadd uengine uns x_engine6 uwords x_engine6_command 0 0
8705ret all_engines
8706end
8707
8708note the zero-ended bytes at src into g_nm from byte p (900 bytes at most in all); the byte after them
8709fn ufetchat p ulong src ulong to ulong
8710if or eq src 0 ge p 900
8711ret p
8712end
8713upr 0 src
8714n = ucall 7
8715if gt add p n 900
8716n = sub 900 p
8717end
8718if eq n 0
8719ret p
8720end
8721upr 0 ulong libptr g_nm p n
8722upr 8 src
8723upr 16 n
8724x = ucall 8
8725ret add p n
8726end
8727
8728note what Hop's settings say about the agent (config: the settings, or 0 without any). A saved command that is
8729note exactly one of the old built-in ones that switched approval prompts or the sandbox off is brought to
8730note today's built-in one, unless keepAgentFlags says the commands are wanted as written (as Hop does on reading)
8731fn uagentconfig config ulong to void
8732engines = ulong 0
8733chosen = ulong 0
8734legacy = ulong 0
8735folder = ulong 0
8736keep_flags = false
8737put g_n 42 0
8738put g_n 44 0
8739put g_n 45 0
8740if ne config 0
8741engines = ukeyed config k_engines
8742chosen = ukeyed config k_engine
8743legacy = ukeyed config k_agent_command
8744folder = ukeyed config k_agent_folder
8745keep_flags = uyes ukeyed config k_keep_flags
8746if uyes ukeyed config k_enter_agent
8747put g_n 42 1
8748end
8749if uyes ukeyed config k_agent_confirmed
8750put g_n 44 1
8751end
8752end
8753defaults = uenginedefaults
8754sat = usl m_at
8755if not uiskind engines 8
8756engines = defaults
8757else
8758if not keep_flags
8759moved = umsg ucl c_mutable_array usl m_array 0 0 0
8760sadd = usl m_add_object
8761sequal = usl m_equal_string
8762ssame = usl m_is_equal_array
8763cnt = umsg engines usl m_count 0 0 0
8764for i ulong cnt bound 256
8765e = umsg engines sat i 0 0
8766if uiskind e 7
8767name = ukeyed e k_name
8768command = ukeyed e k_command
8769if and uiskind name 9 uiskind command 8
8770if and eq and umsg name sequal uns x_engine1 0 0 255 1 eq and umsg command ssame uwords x_old0_command 0 0 255 1
8771e = umsg defaults sat 1 0 0
8772end
8773if and eq and umsg name sequal uns x_engine2 0 0 255 1 eq and umsg command ssame uwords x_old1_command 0 0 255 1
8774e = umsg defaults sat 2 0 0
8775end
8776if and eq and umsg name sequal uns x_engine3 0 0 255 1 eq and umsg command ssame uwords x_old2_command 0 0 255 1
8777e = umsg defaults sat 3 0 0
8778end
8779if and eq and umsg name sequal uns x_engine5 0 0 255 1 eq and umsg command ssame uwords x_old3_command 0 0 255 1
8780e = umsg defaults sat 5 0 0
8781end
8782if and eq and umsg name sequal uns x_engine6 0 0 255 1 eq and umsg command ssame uwords x_old4_command 0 0 255 1
8783e = umsg defaults sat 6 0 0
8784end
8785end
8786end
8787x = umsg moved sadd e 0 0
8788end
8789engines = moved
8790end
8791end
8792if not uiskind chosen 9
8793chosen = uns x_engine0
8794end
8795if not uiskind legacy 8
8796legacy = uwords x_engine0_command
8797end
8798if not uiskind folder 9
8799x = ucall 30
8800folder = ugr 0
8801end
8802sret = usl m_retain
8803put g_m 28 umsg engines sret 0 0 0
8804put g_m 29 umsg chosen sret 0 0 0
8805put g_m 30 umsg folder sret 0 0 0
8806put g_m 31 umsg legacy sret 0 0 0
8807if ne config 0
8808put g_m 34 umsg config sret 0 0 0
8809end
8810note for a check (HOPAGENTS): say each agent's command as it would be run
8811if eq get g_n 14 0
8812n = ucs x_env_agents
8813upr 0 ulong libptr g_nm 0 1024
8814if ne ucall 9 0
8815cnt = umsg engines usl m_count 0 0 0
8816sjoin = usl m_joined
8817for i ulong cnt bound 256
8818e = umsg engines sat i 0 0
8819if uiskind e 7
8820name = ukeyed e k_name
8821command = ukeyed e k_command
8822if and uiskind name 9 uiskind command 8
8823said_words = umsg command sjoin uns x_space 0 0
8824name_bytes = umsg name get g_o 5 0 0 0
8825word_bytes = umsg said_words get g_o 5 0 0 0
8826p = uptxt 0 x_engine_word
8827p2 = ufetchat p name_bytes
8828p2 = uptxt p2 x_colon
8829p2 = ufetchat p2 word_bytes
8830put g_nm p2 10
8831upr 0 1
8832upr 8 ulong libptr g_nm 0 1024
8833upr 16 add p2 1
8834x = ucall 3
8835end
8836end
8837end
8838end
8839end
8840end
8841
8842note s between single quotes for a shell
8843fn ushellquote s ulong to ulong
8844put g_nm 0 39
8845put g_nm 1 0
8846tick = unsb
8847put g_nm 0 39
8848put g_nm 1 92
8849put g_nm 2 39
8850put g_nm 3 39
8851put g_nm 4 0
8852escaped = unsb
8853inner = umsg s usl m_replace tick escaped 0
8854sappend = usl m_append_string
8855ret umsg umsg tick sappend inner 0 0 sappend tick 0 0
8856end
8857
8858note the folders tools are commonly installed in, joined by ":" (searched after the login shell's own PATH)
8859fn uextrapath to ulong
8860x = ucall 30
8861home_folder = ugr 0
8862if eq home_folder 0
8863ret uns x_colon_only
8864end
8865dirs = umsg ucl c_mutable_array usl m_array 0 0 0
8866sadd = usl m_add_object
8867sappend = usl m_append_string
8868slash = uns x_slash_text
8869x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path0 0 0 0 0
8870x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path1 0 0 0 0
8871x = umsg dirs sadd uns x_path2 0 0
8872x = umsg dirs sadd uns x_path3 0 0
8873x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path4 0 0 0 0
8874x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path5 0 0 0 0
8875x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path6 0 0 0 0
8876x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path7 0 0 0 0
8877x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path8 0 0 0 0
8878x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path9 0 0 0 0
8879x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path10 0 0 0 0
8880x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path11 0 0 0 0
8881manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
8882sat = usl m_at
8883for which ulong 2
8884versions_root = umsg home_folder sappend uns x_nvm 0 0
8885if eq which 1
8886versions_root = umsg home_folder sappend uns x_herd 0 0
8887end
8888found_versions = umsg manager usl m_contents_of_dir versions_root 0 0
8889if ne found_versions 0
8890ordered = umsg found_versions usl m_sorted usl m_standard_compare 0 0
8891cnt = umsg ordered usl m_count 0 0 0
8892for back ulong cnt bound 512
8893v = umsg ordered sat sub sub cnt 1 back 0 0
8894one_dir = umsg umsg umsg versions_root sappend slash 0 0 sappend v 0 0 sappend uns x_slash_bin 0 0
8895if eq and umsg one_dir usl m_contains uns x_colon_only 0 0 255 0
8896x = umsg dirs sadd one_dir 0 0
8897end
8898end
8899end
8900end
8901ret umsg dirs usl m_joined uns x_colon_only 0 0
8902end
8903
8904note a program run through the login shell, as Hop runs every command: zsh -lc with the wrapper that adds the
8905note tool folders, then the words of argv; TERM is dumb and colours are off. Not started yet
8906fn ushellrun argv ulong folder ulong to ulong
8907task = umsg ucl c_task usl m_alloc 0 0 0
8908task = umsg task usl m_init 0 0 0
8909x = umsg task usl m_set_launch uns x_zsh 0 0
8910arguments = umsg ucl c_mutable_array usl m_array 0 0 0
8911sadd = usl m_add_object
8912x = umsg arguments sadd uns x_dash_lc 0 0
8913x = umsg arguments sadd uquoted x_wrapper 0 0
8914x = umsg arguments sadd uns x_hop_word 0 0
8915cnt = umsg argv usl m_count 0 0 0
8916sat = usl m_at
8917for i ulong cnt bound 256
8918x = umsg arguments sadd umsg argv sat i 0 0 0 0
8919end
8920x = umsg task usl m_set_arguments arguments 0 0
8921if ne folder 0
8922x = umsg task usl m_set_cwd folder 0 0
8923end
8924around = umsg umsg umsg ucl c_process_info usl m_process_info 0 0 0 usl m_environment 0 0 0 usl m_mutable_copy 0 0 0
8925sset = usl m_set_object
8926x = umsg around sset uns x_dumb uns x_term 0
8927x = umsg around sset uns x_one uns x_no_color 0
8928x = umsg around sset uextrapath uns x_extra_path 0
8929x = umsg task usl m_set_environment around 0 0
8930ret task
8931end
8932
8933note the agents of the settings that are installed on this Mac, looked for once (the login shell is asked for
8934note each tool); when none of them is and the older single command's tool is, that one, as "Custom command"
8935fn uagentsfound to ulong
8936if eq get g_n 45 1
8937ret get g_m 35
8938end
8939engines = get g_m 28
8940sat = usl m_at
8941sappend = usl m_append_string
8942put g_nm 0 10
8943put g_nm 1 0
8944line_end = unsb
8945script = umsg ucl c_mutable_string usl m_string 0 0 0
8946smore = usl m_append
8947cnt = umsg engines usl m_count 0 0 0
8948for i ulong cnt bound 256
8949e = umsg engines sat i 0 0
8950if uiskind e 7
8951name = ukeyed e k_name
8952command = ukeyed e k_command
8953if and uiskind name 9 uiskind command 8
8954if gt umsg command usl m_count 0 0 0 0
8955tool = umsg command sat 0 0 0
8956if uiskind tool 9
8957x = umsg script smore uns x_probe_a 0 0
8958x = umsg script smore ushellquote tool 0 0
8959x = umsg script smore uns x_probe_b 0 0
8960x = umsg script smore ushellquote name 0 0
8961x = umsg script smore line_end 0 0
8962end
8963end
8964end
8965end
8966end
8967legacy = get g_m 31
8968if gt umsg legacy usl m_count 0 0 0 0
8969tool = umsg legacy sat 0 0 0
8970if uiskind tool 9
8971if gt umsg tool usl m_length 0 0 0 0
8972x = umsg script smore uns x_probe_a 0 0
8973x = umsg script smore ushellquote tool 0 0
8974x = umsg script smore uns x_probe_b 0 0
8975x = umsg script smore uns x_legacy_mark 0 0
8976x = umsg script smore line_end 0 0
8977end
8978end
8979end
8980x = umsg script smore uns x_true_word 0 0
8981argv = umsg ucl c_mutable_array usl m_array 0 0 0
8982sadd = usl m_add_object
8983x = umsg argv sadd uns x_sh 0 0
8984x = umsg argv sadd uns x_dash_c 0 0
8985x = umsg argv sadd script 0 0
8986task = ushellrun argv 0
8987tube = umsg ucl c_pipe usl m_pipe 0 0 0
8988quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
8989x = umsg task usl m_set_output tube 0 0
8990x = umsg task usl m_set_error quiet 0 0
8991x = umsg task usl m_set_input quiet 0 0
8992x = umsg task usl m_launch 0 0 0
8993d = umsg umsg tube usl m_reading 0 0 0 usl m_read_end 0 0 0
8994x = umsg task usl m_wait 0 0 0
8995found = umsg ucl c_mutable_array usl m_array 0 0 0
8996if ne d 0
8997said = umsg ucl c_str usl m_alloc 0 0 0
8998said = umsg said usl m_init_data_encoding d 4 0
8999if ne said 0
9000names_said = umsg said usl m_components line_end 0 0
9001shas = usl m_contains_object
9002for i ulong cnt bound 256
9003e = umsg engines sat i 0 0
9004if uiskind e 7
9005name = ukeyed e k_name
9006if uiskind name 9
9007if eq and umsg names_said shas name 0 0 255 1
9008x = umsg found sadd e 0 0
9009end
9010end
9011end
9012end
9013if and eq umsg found usl m_count 0 0 0 0 eq and umsg names_said shas uns x_legacy_mark 0 0 255 1
9014x = umsg found sadd uengine uns x_custom_command legacy 0 0
9015end
9016end
9017end
9018put g_m 35 umsg found usl m_retain 0 0 0
9019put g_n 45 1
9020ret found
9021end
9022
9023note the agent to run: the one the settings name, when it is installed; never another in its place
9024fn uagentpicked to ulong
9025found = uagentsfound
9026cnt = umsg found usl m_count 0 0 0
9027sat = usl m_at
9028sequal = usl m_equal_string
9029for pass_no ulong 2
9030want = get g_m 29
9031if eq pass_no 1
9032want = uns x_custom_command
9033end
9034for i ulong cnt bound 256
9035e = umsg found sat i 0 0
9036if eq and umsg ukeyed e k_name sequal want 0 0 255 1
9037ret e
9038end
9039end
9040end
9041ret 0
9042end
9043
9044note why nothing was run, in plain words
9045fn uagentwhy to ulong
9046found = uagentsfound
9047sappend = usl m_append_string
9048sat = usl m_at
9049if eq umsg found usl m_count 0 0 0 0
9050engines = get g_m 28
9051cnt = umsg engines usl m_count 0 0 0
9052if eq cnt 0
9053ret uns x_agent_none_b
9054end
9055out_text = uns x_agent_none_a
9056for i ulong cnt bound 256
9057e = umsg engines sat i 0 0
9058if uiskind e 7
9059name = ukeyed e k_name
9060command = ukeyed e k_command
9061if and uiskind name 9 uiskind command 8
9062if gt i 0
9063out_text = umsg out_text sappend uns x_comma_space 0 0
9064end
9065out_text = umsg out_text sappend name 0 0
9066if gt umsg command usl m_count 0 0 0 0
9067out_text = umsg out_text sappend uns x_paren_a 0 0
9068out_text = umsg out_text sappend umsg command sat 0 0 0 0 0
9069out_text = umsg out_text sappend uns x_paren_b 0 0
9070end
9071end
9072end
9073end
9074ret umsg out_text sappend uns x_period 0 0
9075end
9076out_text = umsg get g_m 29 sappend uns x_agent_missing_a 0 0
9077cnt = umsg found usl m_count 0 0 0
9078for i ulong cnt bound 256
9079if gt i 0
9080out_text = umsg out_text sappend uns x_comma_space 0 0
9081end
9082out_text = umsg out_text sappend ukeyed umsg found sat i 0 0 k_name 0 0
9083end
9084ret umsg out_text sappend uns x_agent_missing_b 0 0
9085end
9086
9087note Hop's standing instructions for the agent (Sources/Machines.swift, agentBriefing): kept tiny on purpose
9088fn uagentbrief to ulong
9089sappend = usl m_append_string
9090config = get g_m 34
9091owner = uns x_the_user
9092if ne config 0
9093given = ukeyed config k_owner
9094if uiskind given 9
9095blanks = umsg ucl c_charset usl m_whitespace 0 0 0
9096given = umsg given usl m_trim blanks 0 0
9097if gt umsg given usl m_length 0 0 0 0
9098owner = given
9099end
9100end
9101end
9102head = umsg umsg owner usl m_substring_to 1 0 0 usl m_uppercase 0 0 0
9103brief = umsg umsg head sappend umsg owner usl m_substring_from 1 0 0 0 0 sappend uns x_brief_a 0 0
9104if ne config 0
9105machines = ukeyed config k_machines
9106if uiskind machines 8
9107cnt = umsg machines usl m_count 0 0 0
9108if gt cnt 0
9109sat = usl m_at
9110hosts = umsg ucl c_mutable_array usl m_array 0 0 0
9111for i ulong cnt bound 256
9112m = umsg machines sat i 0 0
9113if uiskind m 7
9114name = ukeyed m k_name
9115via = ukeyed m k_ssh
9116if and uiskind name 9 uiskind via 9
9117one_host = umsg umsg umsg name sappend uns x_ssh_a 0 0 sappend via 0 0 sappend uns x_ssh_b 0 0
9118x = umsg hosts usl m_add_object one_host 0 0
9119end
9120end
9121end
9122brief = umsg brief sappend uns x_brief_b 0 0
9123brief = umsg brief sappend umsg hosts usl m_joined uns x_semi_space 0 0 0 0
9124brief = umsg brief sappend uns x_brief_c 0 0
9125end
9126end
9127factory = ukeyed config k_factory_url
9128if uiskind factory 9
9129blanks = umsg ucl c_charset usl m_whitespace 0 0 0
9130if gt umsg umsg factory usl m_trim blanks 0 0 usl m_length 0 0 0 0
9131brief = umsg brief sappend uns x_brief_d 0 0
9132brief = umsg brief sappend factory 0 0
9133brief = umsg brief sappend uns x_period 0 0
9134end
9135end
9136end
9137ret umsg brief sappend uns x_brief_e 0 0
9138end
9139
9140note add a line to what the agent said, and show it
9141fn uagentsay line ulong to void
9142if eq line 0
9143ret
9144end
9145if eq get g_n 22 0
9146put g_nm 0 0
9147no_text = unsb
9148x = umsg get g_m 4 usl m_set_string no_text 0 0
9149put g_n 22 1
9150end
9151sappend_text = usl m_append
9152x = umsg get g_m 4 sappend_text line 0 0
9153put g_nm 0 10
9154put g_nm 1 0
9155x = umsg get g_m 4 sappend_text unsb 0 0
9156if eq get g_n 20 1
9157uanswershow
9158end
9159end
9160
9161note one line the agent printed, as Hop shows it (Sources/Runners.swift, AgentEvents): a line of Claude Code's
9162note stream gives its text and "> " and the name of each tool it uses, and its last line the id to carry on
9163note from (an error there is said); any other line is shown as it is. 0: nothing to show
9164fn uagentline line ulong to ulong
9165if eq and umsg line usl m_has_prefix uns x_brace 0 0 255 0
9166ret line
9167end
9168d = umsg line usl m_data_using 4 0 0
9169if eq d 0
9170ret line
9171end
9172obj = umsg ucl c_json usl m_json_object d 0 0
9173if not uiskind obj 7
9174ret line
9175end
9176kind = ukeyed obj k_type
9177if not uiskind kind 9
9178ret 0
9179end
9180sequal = usl m_equal_string
9181sappend = usl m_append_string
9182if eq and umsg kind sequal uns x_assistant 0 0 255 1
9183message = ukeyed obj k_message
9184if not uiskind message 7
9185ret 0
9186end
9187parts = ukeyed message k_content
9188if not uiskind parts 8
9189ret 0
9190end
9191put g_nm 0 10
9192put g_nm 1 0
9193line_end = unsb
9194put g_nm 0 0
9195shown_text = unsb
9196cnt = umsg parts usl m_count 0 0 0
9197sat = usl m_at
9198have = ulong 0
9199for i ulong cnt bound 1024
9200part_v = umsg parts sat i 0 0
9201if uiskind part_v 7
9202part_kind = ukeyed part_v k_type
9203piece = ulong 0
9204if uiskind part_kind 9
9205if eq and umsg part_kind sequal uns k_parts_text 0 0 255 1
9206piece = ukeyed part_v k_parts_text
9207if not uiskind piece 9
9208piece = 0
9209end
9210end
9211if eq and umsg part_kind sequal uns k_tool_use 0 0 255 1
9212tool_name = ukeyed part_v k_name
9213if not uiskind tool_name 9
9214tool_name = uns x_tool_word
9215end
9216piece = umsg uns x_tool_mark sappend tool_name 0 0
9217end
9218end
9219if ne piece 0
9220if eq have 1
9221shown_text = umsg shown_text sappend line_end 0 0
9222end
9223shown_text = umsg shown_text sappend piece 0 0
9224have = 1
9225end
9226end
9227end
9228if eq have 0
9229ret 0
9230end
9231ret shown_text
9232end
9233if eq and umsg kind sequal uns k_result 0 0 255 1
9234sid = ukeyed obj k_session_id
9235if uiskind sid 9
9236if ne get g_m 33 0
9237x = umsg get g_m 33 usl m_release 0 0 0
9238end
9239put g_m 33 umsg sid usl m_retain 0 0 0
9240end
9241if uyes ukeyed obj k_is_error
9242problem = ukeyed obj k_result
9243if not uiskind problem 9
9244problem = uns x_agent_error
9245end
9246ret umsg uns x_bang sappend problem 0 0
9247end
9248end
9249ret 0
9250end
9251
9252note output of the agent arrived (d; nothing left when it is empty): every whole line is shown
9253fn uagentout d ulong to void
9254buffer = get g_m 32
9255if eq buffer 0
9256ret
9257end
9258n = umsg d usl m_length 0 0 0
9259if gt n 0
9260x = umsg buffer usl m_append_data d 0 0
9261end
9262put g_nl 0 10
9263newline = umsg ucl c_data usl m_data_bytes ulong libptr g_nl 0 1 1 0
9264srange = usl m_range_of_data
9265ssub = usl m_subdata
9266scut = usl m_replace_bytes
9267slen = usl m_length
9268c_s = ucl c_str
9269salloc = usl m_alloc
9270sinit_data = usl m_init_data_encoding
9271more = true
9272for turn ulong 4096 bound 4096
9273if more
9274total = umsg buffer slen 0 0 0
9275if eq total 0
9276more = false
9277else
9278upr 40 total
9279found_at = umsg buffer srange newline 0 0
9280take = total
9281whole_line = false
9282if lt found_at total
9283take = found_at
9284whole_line = true
9285end
9286if and not whole_line ne n 0
9287more = false
9288else
9289piece = umsg buffer ssub 0 take 0
9290line = umsg c_s salloc 0 0 0
9291line = umsg line sinit_data piece 4 0
9292drop = take
9293if whole_line
9294drop = add take 1
9295end
9296upr 40 0
9297x = umsg buffer scut 0 drop 0
9298if ne line 0
9299uagentsay uagentline line
9300end
9301end
9302end
9303end
9304end
9305end
9306
9307note the agent's run has ended in one more way (1 its output, 2 the program); when both have, the turn is over
9308fn uagentended what ulong to void
9309put g_n 47 or get g_n 47 what
9310if eq get g_n 47 2
9311s_after = usl m_perform_after
9312upr 64 bitcast ulong 2.0f64
9313x = umsg get g_o 27 s_after get g_m 38 0 0
9314end
9315if ne get g_n 47 3
9316ret
9317end
9318task = get g_m 26
9319if eq task 0
9320ret
9321end
9322code = and umsg task usl m_termination 0 0 0 4294967295
9323if ne code 0
9324p = uptxt 0 x_agent_stopped_a
9325p = upnum p code
9326p = uptxt p x_agent_stopped_b
9327put g_nm p 0
9328uagentsay unsb
9329end
9330center = umsg ucl c_center usl m_default_center 0 0 0
9331s_forget = usl m_remove_all_observer
9332x = umsg center s_forget get g_o 27 0 get g_m 27
9333x = umsg center s_forget get g_o 27 0 get g_m 37
9334x = umsg center s_forget get g_o 27 0 task
9335srel = usl m_release
9336x = umsg task srel 0 0 0
9337put g_m 26 0
9338put g_n 43 0
9339put g_n 21 1
9340put g_n 39 1
9341x = umsg ucl c_date usl m_reference_now 0 0 0
9342now_bits = ugr 64
9343if ne get g_m 36 0
9344x = umsg get g_m 36 srel 0 0 0
9345end
9346s_double = usl m_number_double
9347cnum = ucl c_number
9348upr 64 now_bits
9349put g_m 36 umsg umsg cnum s_double 0 0 0 usl m_retain 0 0 0
9350end
9351
9352note what the agent's program tells this one: output (agentOut:), errors (agentErr:), its end (agentEnd:), and the
9353note menu's Stop the Agent (stopAgent:); which is the selector, about is what came with it
9354fn uagentevent which ulong about ulong to void
9355if ustatusevent which
9356ret
9357end
9358if eq which get g_m 64
9359uprobedone about
9360ret
9361end
9362if eq which get g_m 46
9363uremotestart
9364ret
9365end
9366if eq which get g_m 47
9367uremotedone about
9368ret
9369end
9370if eq which get g_m 48
9371ufetchdone about
9372ret
9373end
9374if eq which get g_m 41
9375if ne get g_m 26 0
9376x = umsg get g_m 26 usl m_terminate_task 0 0 0
9377end
9378ret
9379end
9380if eq which get g_m 40
9381uagentended 2
9382ret
9383end
9384if eq get g_m 26 0
9385ret
9386end
9387if eq about 0
9388if and eq which get g_m 38 eq and get g_n 47 1 0
9389uagentout umsg ucl c_data usl m_data 0 0 0
9390uagentended 1
9391end
9392ret
9393end
9394info = umsg about usl m_user_info 0 0 0
9395if eq info 0
9396ret
9397end
9398d = umsg info usl m_object_for_key uconst s_data_item 0 0
9399if eq d 0
9400ret
9401end
9402n = umsg d usl m_length 0 0 0
9403if eq which get g_m 38
9404uagentout d
9405if eq n 0
9406uagentended 1
9407else
9408x = umsg get g_m 27 usl m_read_background 0 0 0
9409end
9410ret
9411end
9412if gt n 0
9413said = umsg ucl c_str usl m_alloc 0 0 0
9414said = umsg said usl m_init_data_encoding d 4 0
9415if ne said 0
9416edge = umsg ucl c_charset usl m_newline_set 0 0 0
9417uagentsay umsg uns x_bang usl m_append_string umsg said usl m_trim edge 0 0 0 0
9418end
9419x = umsg get g_m 37 usl m_read_background 0 0 0
9420end
9421end
9422
9423note send the typed text to the agent
9424fn uagentrun to void
9425a = get g_n 12
9426n = get g_n 13
9427if or eq n 0 gt n 255
9428ret
9429end
9430for i ulong n bound 256
9431put g_nm i get g_q add a i
9432end
9433put g_nm n 0
9434request = unsb
9435if eq request 0
9436ret
9437end
9438note the talk on show: what was there joins what was said before, then the request
9439if eq get g_m 25 0
9440told = umsg ucl c_mutable_string usl m_string 0 0 0
9441put g_m 25 umsg told usl m_retain 0 0 0
9442end
9443if eq get g_m 4 0
9444fresh_text = umsg ucl c_mutable_string usl m_string 0 0 0
9445put g_m 4 umsg fresh_text usl m_retain 0 0 0
9446end
9447if eq get g_n 43 1
9448uanswershow
9449uanswerview 1
9450ret
9451end
9452put g_nm 0 10
9453put g_nm 1 10
9454put g_nm 2 0
9455blank_line = unsb
9456sappend_text = usl m_append
9457if eq get g_n 39 1
9458x = umsg get g_m 25 sappend_text get g_m 4 0 0
9459x = umsg get g_m 25 sappend_text blank_line 0 0
9460end
9461x = umsg get g_m 25 sappend_text uns x_you 0 0
9462x = umsg get g_m 25 sappend_text request 0 0
9463x = umsg get g_m 25 sappend_text blank_line 0 0
9464put g_n 39 0
9465put g_n 21 0
9466put g_n 22 0
9467engine = uagentpicked
9468if eq engine 0
9469uagentsay uagentwhy
9470put g_n 21 1
9471put g_n 39 1
9472uanswershow
9473uanswerview 1
9474ret
9475end
9476if eq get g_n 44 0
9477if eq get g_n 14 0
9478uagentsay uns x_agent_ask
9479put g_n 21 1
9480put g_n 39 1
9481uanswershow
9482uanswerview 1
9483ret
9484end
9485alert = umsg umsg ucl c_alert usl m_alloc 0 0 0 usl m_init 0 0 0
9486x = umsg alert usl m_set_message uns x_agent_ask 0 0
9487x = umsg alert usl m_set_informative uns x_agent_ask_more 0 0
9488x = umsg alert usl m_add_button uns x_agent_yes 0 0
9489x = umsg alert usl m_add_button uns x_agent_no 0 0
9490if ne umsg alert usl m_run_modal 0 0 0 1000
9491ret
9492end
9493put g_n 44 1
9494end
9495x = umsg get g_m 4 usl m_set_string uns x_agent_working 0 0
9496uanswershow
9497uanswerview 1
9498note the words to run: the request in place of "{prompt}", Hop's standing instructions before it, or for
9499note Claude Code as its system prompt; a follow-up within 15 minutes carries on from Claude Code's last run
9500brief = uagentbrief
9501command = ukeyed engine k_command
9502sat = usl m_at
9503sappend = usl m_append_string
9504sequal = usl m_equal_string
9505tool = umsg command sat 0 0 0
9506is_claude = eq and umsg tool sequal uns x_claude 0 0 255 1
9507prompt = request
9508if not is_claude
9509prompt = umsg umsg umsg brief sappend blank_line 0 0 sappend uns x_request 0 0 sappend request 0 0
9510end
9511argv = umsg ucl c_mutable_array usl m_array 0 0 0
9512sadd = usl m_add_object
9513mark = uns x_prompt_mark
9514cnt = umsg command usl m_count 0 0 0
9515for i ulong cnt bound 256
9516word = umsg command sat i 0 0
9517if uiskind word 9
9518x = umsg argv sadd umsg word usl m_replace mark prompt 0 0 0
9519end
9520end
9521if is_claude
9522shas = usl m_contains_object
9523if eq and umsg argv shas uns x_append_system 0 0 255 0
9524x = umsg argv sadd uns x_append_system 0 0
9525x = umsg argv sadd brief 0 0
9526end
9527if and ne get g_m 33 0 ne get g_m 36 0
9528if eq and umsg argv shas uns x_resume 0 0 255 0
9529x = umsg get g_m 36 usl m_double_value 0 0 0
9530last_bits = ugr 64
9531x = umsg ucl c_date usl m_reference_now 0 0 0
9532if lt sub bitcast f64 ugr 64 bitcast f64 last_bits 900.0f64
9533x = umsg argv sadd uns x_resume 0 0
9534x = umsg argv sadd get g_m 33 0 0
9535end
9536end
9537end
9538end
9539task = ushellrun argv get g_m 30
9540tube = umsg ucl c_pipe usl m_pipe 0 0 0
9541error_tube = umsg ucl c_pipe usl m_pipe 0 0 0
9542quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
9543x = umsg task usl m_set_output tube 0 0
9544x = umsg task usl m_set_error error_tube 0 0
9545x = umsg task usl m_set_input quiet 0 0
9546sret = usl m_retain
9547reader = umsg tube usl m_reading 0 0 0
9548error_reader = umsg error_tube usl m_reading 0 0 0
9549if ne get g_m 27 0
9550x = umsg get g_m 27 usl m_release 0 0 0
9551x = umsg get g_m 37 usl m_release 0 0 0
9552x = umsg get g_m 32 usl m_release 0 0 0
9553end
9554put g_m 27 umsg reader sret 0 0 0
9555put g_m 37 umsg error_reader sret 0 0 0
9556put g_m 32 umsg umsg ucl c_mutable_data usl m_data 0 0 0 sret 0 0 0
9557put g_m 26 umsg task sret 0 0 0
9558put g_n 47 0
9559center = umsg ucl c_center usl m_default_center 0 0 0
9560s_observe = usl m_add_observer
9561read_done = uconst s_read_done
9562ended = uconst s_task_ended
9563upr 40 reader
9564x = umsg center s_observe get g_o 27 get g_m 38 read_done
9565upr 40 error_reader
9566x = umsg center s_observe get g_o 27 get g_m 39 read_done
9567upr 40 task
9568x = umsg center s_observe get g_o 27 get g_m 40 ended
9569put g_n 43 1
9570x = umsg task usl m_launch 0 0 0
9571x = umsg reader usl m_read_background 0 0 0
9572x = umsg error_reader usl m_read_background 0 0 0
9573end
9574
9575note ---- files on other machines, as Hop finds them (Sources/Machines.swift, Sources/Model.swift searchFiles) ----
9576note Each machine of Hop's settings keeps its own list of files (20 pieces, built there by a command Hop sends
9577note when the list is missing or old); a search runs on the machine through ssh and the lines that hold every
9578note typed word come back, to be scored here by the rule the local files are scored by. The machines are asked
9579note a moment after typing pauses, all at once, by one program whose answer is read when it has ended. Enter on
9580note such a file brings it over (scp, into the cache folder) and opens it; a folder's path goes to the clipboard.
9581note an NSString of text t with every "%%" turned into a double quote and every "^^" into a backslash
9582fn uquoted2 t view uchar * to ulong
9583put g_nm 0 34
9584put g_nm 1 0
9585quote_mark = unsb
9586put g_nm 0 92
9587put g_nm 1 0
9588back_mark = unsb
9589plain = uns t
9590srep = usl m_replace
9591plain = umsg plain srep uns x_percents quote_mark 0
9592ret umsg plain srep uns x_carets back_mark 0
9593end
9594
9595note the machines of the settings: their names into g_mn (63 bytes each at most), their ssh names kept; 10 at most
9596fn umachines config ulong to void
9597put g_n 54 0
9598put g_n 59 0
9599if eq get g_n 14 1
9600put g_n 59 1
9601else
9602n = ucs x_env_ssh
9603upr 0 ulong libptr g_nm 0 1024
9604if ne ucall 9 0
9605put g_n 59 1
9606end
9607end
9608if eq config 0
9609ret
9610end
9611machines = ukeyed config k_machines
9612if not uiskind machines 8
9613ret
9614end
9615sat = usl m_at
9616aliases = umsg ucl c_mutable_array usl m_array 0 0 0
9617cnt = umsg machines usl m_count 0 0 0
9618have = ulong 0
9619for i ulong cnt bound 64
9620if lt have 10
9621m = umsg machines sat i 0 0
9622if uiskind m 7
9623name = ukeyed m k_name
9624via = ukeyed m k_ssh
9625if and uiskind name 9 uiskind via 9
9626src = umsg name get g_o 5 0 0 0
9627if ne src 0
9628upr 0 src
9629n = ucall 7
9630if gt n 63
9631n = 63
9632end
9633if gt n 0
9634upr 0 ulong libptr g_mn mul have 64 n
9635upr 8 src
9636upr 16 n
9637x = ucall 8
9638end
9639put g_ml have uchar n
9640x = umsg aliases usl m_add_object m 0 0
9641have = add have 1
9642end
9643end
9644end
9645end
9646end
9647if ne get g_m 42 0
9648x = umsg get g_m 42 usl m_release 0 0 0
9649end
9650put g_m 42 umsg aliases usl m_retain 0 0 0
9651put g_n 54 have
9652end
9653
9654note may other machines be reached: always when resident; a check reaches none but through its stand-in (HOPSSH)
9655note (looked up once, when the settings are read: 59 is 1 for yes)
9656fn uremoteok to bool
9657ret eq get g_n 59 1
9658end
9659
9660note the program to reach other machines with: ssh (scp when copy is 1), or for a check its stand-in
9661fn uremotetool copy ulong to ulong
9662if eq get g_n 14 0
9663n = ucs x_env_ssh
9664if eq copy 1
9665n = ucs x_env_scp
9666end
9667upr 0 ulong libptr g_nm 0 1024
9668given = ucall 9
9669if ne given 0
9670n = ufetch given
9671ret ushellquote unsb
9672end
9673end
9674if eq copy 1
9675ret uns x_scp_word
9676end
9677ret uns x_ssh_word
9678end
9679
9680note run a script through the login shell and read all it says when it has ended: done is the selector told then.
9681note The program (kept) and where its answer is read (kept) go to places prog and reader of g_m
9682fn uscriptrun script ulong done ulong prog ulong reader_at ulong to void
9683argv = umsg ucl c_mutable_array usl m_array 0 0 0
9684sadd = usl m_add_object
9685x = umsg argv sadd uns x_sh 0 0
9686x = umsg argv sadd uns x_dash_c 0 0
9687x = umsg argv sadd script 0 0
9688task = ushellrun argv 0
9689tube = umsg ucl c_pipe usl m_pipe 0 0 0
9690quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
9691x = umsg task usl m_set_output tube 0 0
9692x = umsg task usl m_set_error quiet 0 0
9693x = umsg task usl m_set_input quiet 0 0
9694reader = umsg tube usl m_reading 0 0 0
9695sret = usl m_retain
9696center = umsg ucl c_center usl m_default_center 0 0 0
9697whole_read = uconst s_read_to_end_done
9698if ne get g_m prog 0
9699x = umsg get g_m prog usl m_terminate_task 0 0 0
9700x = umsg center usl m_remove_all_observer get g_o 27 whole_read get g_m reader_at
9701x = umsg get g_m prog usl m_release 0 0 0
9702x = umsg get g_m reader_at usl m_release 0 0 0
9703end
9704put g_m prog umsg task sret 0 0 0
9705put g_m reader_at umsg reader sret 0 0 0
9706s_observe = usl m_add_observer
9707upr 40 reader
9708x = umsg center s_observe get g_o 27 done whole_read
9709x = umsg task usl m_launch 0 0 0
9710x = umsg reader usl m_read_to_end 0 0 0
9711end
9712
9713note the command that makes machine m (a settings entry) build its list of files when it has none or an old one
9714fn urefreshscript m ulong to ulong
9715sappend = usl m_append_string
9716sat = usl m_at
9717roots = ukeyed m k_roots_m
9718skips = ukeyed m k_skip_m
9719if not uiskind skips 8
9720skips = umsg ucl c_mutable_array usl m_array 0 0 0
9721sadd = usl m_add_object
9722x = umsg skips sadd uns x_mskip0 0 0
9723x = umsg skips sadd uns x_mskip1 0 0
9724x = umsg skips sadd uns x_mskip2 0 0
9725x = umsg skips sadd uns x_mskip3 0 0
9726x = umsg skips sadd uns x_mskip4 0 0
9727x = umsg skips sadd uns x_mskip5 0 0
9728x = umsg skips sadd uns x_mskip6 0 0
9729x = umsg skips sadd uns x_mskip7 0 0
9730x = umsg skips sadd uns x_mskip8 0 0
9731x = umsg skips sadd uns x_mskip9 0 0
9732end
9733prune = umsg ucl c_mutable_string usl m_string 0 0 0
9734smore = usl m_append
9735cnt = umsg skips usl m_count 0 0 0
9736for i ulong cnt bound 256
9737one_name = umsg skips sat i 0 0
9738if uiskind one_name 9
9739if gt umsg prune usl m_length 0 0 0 0
9740x = umsg prune smore uns x_or_flag 0 0
9741end
9742x = umsg prune smore uns x_name_flag 0 0
9743x = umsg prune smore ushellquote one_name 0 0
9744end
9745end
9746places = umsg ucl c_mutable_string usl m_string 0 0 0
9747if uiskind roots 8
9748cnt = umsg roots usl m_count 0 0 0
9749for i ulong cnt bound 256
9750one_root = umsg roots sat i 0 0
9751if uiskind one_root 9
9752if gt umsg places usl m_length 0 0 0 0
9753x = umsg places smore uns x_space 0 0
9754end
9755x = umsg places smore ushellquote one_root 0 0
9756end
9757end
9758end
9759build = umsg umsg umsg umsg uns x_build_a sappend places 0 0 sappend uquoted2 x_build_b 0 0 sappend prune 0 0 sappend uquoted2 x_build_c 0 0
9760put g_nm 0 10
9761put g_nm 1 0
9762line_end = unsb
9763script = umsg ucl c_mutable_string usl m_string 0 0 0
9764x = umsg script smore uns x_fresh_a 0 0
9765x = umsg script smore line_end 0 0
9766x = umsg script smore uquoted2 x_fresh_b 0 0
9767x = umsg script smore line_end 0 0
9768x = umsg script smore uquoted2 x_fresh_c 0 0
9769x = umsg script smore ushellquote build 0 0
9770x = umsg script smore uns x_fresh_d 0 0
9771x = umsg script smore line_end 0 0
9772x = umsg script smore uns x_fresh_e 0 0
9773ret script
9774end
9775
9776note ask machine k to build its list of files if it has none or an old one; nothing is waited for
9777fn uremoterefresh k ulong to void
9778if or or ge k get g_n 54 eq get g_m 42 0 not uremoteok
9779ret
9780end
9781m = umsg get g_m 42 get g_m 16 k 0 0
9782via = ukeyed m k_ssh
9783sappend = usl m_append_string
9784line = umsg umsg umsg uremotetool 0 sappend uns x_ssh_options 0 0 sappend ushellquote via 0 0 sappend uns x_space 0 0
9785line = umsg line sappend ushellquote urefreshscript m 0 0
9786argv = umsg ucl c_mutable_array usl m_array 0 0 0
9787sadd = usl m_add_object
9788x = umsg argv sadd uns x_sh 0 0
9789x = umsg argv sadd uns x_dash_c 0 0
9790x = umsg argv sadd line 0 0
9791task = ushellrun argv 0
9792quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
9793x = umsg task usl m_set_output quiet 0 0
9794x = umsg task usl m_set_error quiet 0 0
9795x = umsg task usl m_set_input quiet 0 0
9796x = umsg task usl m_launch 0 0 0
9797end
9798
9799note a moment after typing pauses the machines are asked; until then nothing found there is shown
9800fn uremotesoon to void
9801put g_n 49 0
9802put g_n 58 0
9803if le get g_n 51 2
9804put g_n 51 0
9805end
9806if eq get g_n 54 0
9807ret
9808end
9809if not uremoteok
9810ret
9811end
9812s_go = get g_m 46
9813x = umsg ucl c_obj usl m_cancel_previous get g_o 27 s_go 0
9814if or or lt get g_n 13 2 gt get g_n 13 255 ne get g_n 36 0
9815ret
9816end
9817s_after = usl m_perform_after
9818upr 64 bitcast ulong 0.22f64
9819x = umsg get g_o 27 s_after s_go 0 0
9820end
9821
9822note ask every machine for the files that hold every typed word (the longest first, as on the machine's side
9823note each further word narrows what the first found)
9824fn uremotestart to void
9825a = get g_n 12
9826n = get g_n 13
9827if or or lt n 2 gt n 255 eq get g_n 54 0
9828ret
9829end
9830for i ulong n bound 256
9831put g_rq i get g_q add a i
9832put g_nm i get g_q add a i
9833end
9834put g_n 53 n
9835put g_nm n 0
9836typed = unsb
9837if eq typed 0
9838ret
9839end
9840parts = umsg umsg typed usl m_lowercase 0 0 0 usl m_components uns x_space 0 0
9841sat = usl m_at
9842slen = usl m_length
9843cnt = umsg parts usl m_count 0 0 0
9844longest = ulong 0
9845longest_len = ulong 0
9846for i ulong cnt bound 64
9847one_word = umsg parts sat i 0 0
9848wl = umsg one_word slen 0 0 0
9849if ge wl longest_len
9850if gt wl 0
9851longest = one_word
9852longest_len = wl
9853end
9854end
9855end
9856if eq longest 0
9857ret
9858end
9859sappend = usl m_append_string
9860filter = umsg umsg uns x_remote_grep sappend ushellquote longest 0 0 sappend uquoted2 x_remote_shard 0 0
9861for i ulong cnt bound 64
9862one_word = umsg parts sat i 0 0
9863if and gt umsg one_word slen 0 0 0 0 eq and umsg one_word usl m_equal_string longest 0 0 255 0
9864filter = umsg umsg umsg filter sappend uns x_remote_pipe 0 0 sappend uns x_remote_grep 0 0 sappend ushellquote one_word 0 0
9865end
9866end
9867remote = umsg umsg uns x_remote_a sappend filter 0 0 sappend uquoted2 x_remote_b 0 0
9868remote_quoted = ushellquote remote
9869tool = uremotetool 0
9870put g_nm 0 10
9871put g_nm 1 0
9872line_end = unsb
9873script = umsg ucl c_mutable_string usl m_string 0 0 0
9874smore = usl m_append
9875for k ulong get g_n 54 bound 10
9876m = umsg get g_m 42 sat k 0 0
9877via = ukeyed m k_ssh
9878x = umsg script smore uns x_local_a 0 0
9879x = umsg script smore tool 0 0
9880x = umsg script smore uns x_ssh_options 0 0
9881x = umsg script smore ushellquote via 0 0
9882x = umsg script smore uns x_space 0 0
9883x = umsg script smore remote_quoted 0 0
9884x = umsg script smore uns x_local_b 0 0
9885put g_nm 0 uchar add 48 k
9886put g_nm 1 0
9887x = umsg script smore unsb 0 0
9888x = umsg script smore uns x_local_c 0 0
9889x = umsg script smore line_end 0 0
9890end
9891x = umsg script smore uns x_wait_word 0 0
9892uscriptrun script get g_m 47 43 44
9893end
9894
9895note keep a file found on a machine among the best 64, best first
9896fn uremotekeep sc ulong o ulong ln ulong k ulong to void
9897have = get g_n 49
9898if and ge have 64 le sc get g_rs 63
9899ret
9900end
9901pos = have
9902if ge have 64
9903pos = 63
9904else
9905put g_n 49 add have 1
9906end
9907while gt pos 0 bound 80
9908if ge get g_rs sub pos 1 sc
9909break
9910end
9911put g_rs pos get g_rs sub pos 1
9912put g_ro pos get g_ro sub pos 1
9913put g_rl pos get g_rl sub pos 1
9914put g_rw pos get g_rw sub pos 1
9915pos = sub pos 1
9916end
9917put g_rs pos sc
9918put g_ro pos o
9919put g_rl pos ln
9920put g_rw pos uchar k
9921end
9922
9923note does the line at o of g_rb (n bytes) read exactly as text t
9924fn uremoteis o ulong n ulong t view uchar * to bool
9925tl = len t
9926if ne n tl
9927ret false
9928end
9929for i ulong tl bound 64
9930if ne ulong get g_rb add o i ulong get t i
9931ret false
9932end
9933end
9934ret true
9935end
9936
9937note the machines have answered (about: the notice that carries what they said). When the typed text is still
9938note the one they were asked for, every line is scored and the list is made anew
9939fn uremotedone about ulong to void
9940if eq about 0
9941ret
9942end
9943info = umsg about usl m_user_info 0 0 0
9944if eq info 0
9945ret
9946end
9947d = umsg info usl m_object_for_key uconst s_data_item 0 0
9948if eq d 0
9949ret
9950end
9951a = get g_n 12
9952n = get g_n 13
9953if ne n get g_n 53
9954ret
9955end
9956for i ulong n bound 256
9957if ne ulong get g_q add a i ulong get g_rq i
9958ret
9959end
9960end
9961total = umsg d usl m_length 0 0 0
9962if gt total 1048575
9963total = 1048575
9964end
9965put g_n 49 0
9966put g_n 58 0
9967put g_n 50 total
9968if eq total 0
9969ret
9970end
9971src = umsg d usl m_bytes 0 0 0
9972base = ulong libptr g_rb 0 total
9973upr 0 base
9974upr 8 src
9975upr 16 total
9976x = ucall 8
9977pos = ulong 0
9978more = true
9979for turn ulong 20000 bound 20000
9980if more
9981if ge pos total
9982more = false
9983else
9984upr 0 add base pos
9985upr 8 10
9986upr 16 sub total pos
9987x = ucall 12
9988e = total
9989hit_at = ugr 0
9990if ne hit_at 0
9991e = sub hit_at base
9992end
9993ln = sub e pos
9994if and ge ln 3 eq ulong get g_rb add pos 1 58
9995k = sub ulong get g_rb pos 48
9996if lt k get g_n 54
9997o = add pos 2
9998bl = sub ln 2
9999if uremoteis o bl x_no_index
10000put g_n 51 2
10001put g_n 52 k
10002uremoterefresh k
10003else
10004if uremoteis o bl x_unreachable
10005put g_n 51 1
10006put g_n 52 k
10007else
10008pl = bl
10009if eq ulong get g_rb sub add o bl 1 47
10010pl = sub bl 1
10011end
10012if and gt pl 0 le pl 4000
10013for j ulong pl bound 4096
10014put g_line j uchar ulower ulong get g_rb add o j
10015end
10016sc = ufscore pl
10017if ne sc 0
10018uremotekeep sc o bl k
10019name_at = pl
10020while gt name_at 0 bound 4097
10021if eq ulong get g_line sub name_at 1 47
10022break
10023end
10024name_at = sub name_at 1
10025end
10026if eq sub pl name_at n
10027same_name = true
10028for j ulong n bound 256
10029if ne ulong get g_line add name_at j ulower ulong get g_rq j
10030same_name = false
10031end
10032end
10033if same_name
10034put g_n 58 1
10035end
10036end
10037end
10038end
10039end
10040end
10041end
10042end
10043pos = add e 1
10044end
10045end
10046end
10047keep_row = get g_n 6
10048unarrow
10049x = umsg get g_o 1 get g_o 7 0 0 0
10050if lt keep_row get g_n 1
10051uchoose keep_row
10052else
10053if gt get g_n 1 0
10054uchoose 0
10055end
10056end
10057ushowst
10058end
10059
10060note the text of a row for a file on another machine into g_nm from byte p: its name, the folder it is in,
10061note and the machine; the byte after it
10062fn uremoterow p ulong r ulong to ulong
10063if ge r get g_n 49
10064ret p
10065end
10066o = get g_ro r
10067ln = get g_rl r
10068if gt ln 0
10069if eq ulong get g_rb sub add o ln 1 47
10070ln = sub ln 1
10071end
10072end
10073ns0 = ln
10074while gt ns0 0 bound 4097
10075if eq ulong get g_rb sub add o ns0 1 47
10076break
10077end
10078ns0 = sub ns0 1
10079end
10080q = p
10081nl = sub ln ns0
10082if gt nl 300
10083nl = 300
10084end
10085for j ulong nl bound 301
10086put g_nm add q j get g_rb add add o ns0 j
10087end
10088q = add q nl
10089if and gt ns0 1 le ns0 400
10090q = uptxt q x_gap
10091for j ulong sub ns0 1 bound 401
10092put g_nm add q j get g_rb add o j
10093end
10094q = add q sub ns0 1
10095end
10096k = ulong get g_rw r
10097q = uptxt q x_on
10098ml = ulong get g_ml k
10099for j ulong ml bound 64
10100put g_nm add q j get g_mn add mul k 64 j
10101end
10102ret add q ml
10103end
10104
10105note the path of found file r, as it is written on its machine, as an NSString (without a folder's last "/")
10106fn uremotepath r ulong to ulong
10107o = get g_ro r
10108ln = get g_rl r
10109if gt ln 0
10110if eq ulong get g_rb sub add o ln 1 47
10111ln = sub ln 1
10112end
10113end
10114if or eq ln 0 gt ln 1000
10115ret 0
10116end
10117for j ulong ln bound 1001
10118put g_nm j get g_rb add o j
10119end
10120put g_nm ln 0
10121ret unsb
10122end
10123
10124note put text on the clipboard (a check uses a board of its own)
10125fn uclipput words ulong to void
10126pboard = ulong 0
10127if eq get g_n 14 1
10128pboard = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
10129else
10130pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0
10131end
10132x = umsg pboard usl m_clear 0 0 0
10133x = umsg pboard usl m_set_string_type words uns x_type_string 0
10134put g_n 29 1
10135if eq get g_n 14 1
10136uclipmine 0
10137end
10138end
10139
10140note Enter on a file of another machine: a folder's "ssh name:path" goes to the clipboard; a file is brought over
10141note (when it is under 2 GB) into the cache folder and opened when it has arrived
10142fn uremoteopen r ulong to void
10143if or or ge r get g_n 49 eq get g_m 42 0 not uremoteok
10144ret
10145end
10146k = ulong get g_rw r
10147o = get g_ro r
10148ln = get g_rl r
10149is_folder = false
10150if gt ln 0
10151is_folder = eq ulong get g_rb sub add o ln 1 47
10152end
10153path = uremotepath r
10154if eq path 0
10155ret
10156end
10157m = umsg get g_m 42 get g_m 16 k 0 0
10158via = ukeyed m k_ssh
10159name = ukeyed m k_name
10160sappend = usl m_append_string
10161there = umsg umsg via sappend uns x_colon_only 0 0 sappend path 0 0
10162sret = usl m_retain
10163if ne get g_m 51 0
10164x = umsg get g_m 51 usl m_release 0 0 0
10165end
10166put g_m 51 umsg there sret 0 0 0
10167put g_n 52 k
10168if is_folder
10169uclipput there
10170put g_n 51 4
10171ushowst
10172ret
10173end
10174dest = ulong 0
10175if eq get g_n 14 0
10176dest = uhoppath x_check_cache
10177else
10178x = ucall 30
10179dest = umsg ugr 0 sappend uns x_remote_cache 0 0
10180end
10181if eq dest 0
10182ret
10183end
10184dest = umsg umsg dest sappend name 0 0 sappend path 0 0
10185if ne get g_m 50 0
10186x = umsg get g_m 50 usl m_release 0 0 0
10187end
10188put g_m 50 umsg dest sret 0 0 0
10189folder = umsg dest usl m_dir_of 0 0 0
10190tool = uremotetool 0
10191script = umsg uns x_fetch_a sappend tool 0 0
10192script = umsg script sappend uns x_ssh_options 0 0
10193script = umsg script sappend ushellquote via 0 0
10194script = umsg script sappend uns x_space 0 0
10195script = umsg script sappend ushellquote umsg uns x_fetch_stat sappend ushellquote path 0 0 0 0
10196script = umsg script sappend uquoted2 x_fetch_b 0 0
10197script = umsg script sappend ushellquote folder 0 0
10198script = umsg script sappend uns x_fetch_c 0 0
10199script = umsg script sappend uremotetool 1 0 0
10200script = umsg script sappend uns x_scp_options 0 0
10201script = umsg script sappend ushellquote there 0 0
10202script = umsg script sappend uns x_space 0 0
10203script = umsg script sappend ushellquote dest 0 0
10204script = umsg script sappend uns x_fetch_d 0 0
10205put g_n 51 3
10206ushowst
10207uscriptrun script get g_m 48 45 49
10208end
10209
10210note the program bringing a file over has ended: when it says the file arrived it is opened, else the path goes
10211note to the clipboard and that is said
10212fn ufetchdone about ulong to void
10213if eq about 0
10214ret
10215end
10216info = umsg about usl m_user_info 0 0 0
10217if eq info 0
10218ret
10219end
10220d = umsg info usl m_object_for_key uconst s_data_item 0 0
10221arrived = false
10222if ne d 0
10223said = umsg ucl c_str usl m_alloc 0 0 0
10224said = umsg said usl m_init_data_encoding d 4 0
10225if ne said 0
10226arrived = eq and umsg said usl m_contains uns x_fetched 0 0 255 1
10227end
10228end
10229if arrived
10230put g_n 51 0
10231put g_n 55 1
10232if eq get g_n 7 1
10233url = umsg ucl c_url usl m_furl get g_m 50 0 0
10234ws = umsg ucl c_ws usl m_shws 0 0 0
10235put g_n 9 and umsg ws usl m_open url 0 0 255
10236end
10237else
10238if ne get g_m 51 0
10239uclipput get g_m 51
10240end
10241put g_n 51 5
10242end
10243ushowst
10244end
10245
10246note every half hour, and when the panel starts, each machine is asked to build its list if it is old
10247fn uremoterefreshall to void
10248for k ulong get g_n 54 bound 10
10249uremoterefresh k
10250end
10251end
10252
10253note what to say about a machine into g_nm from byte p; the byte after it
10254fn uremotenote p ulong to ulong
10255w = get g_n 51
10256k = get g_n 52
10257if or eq w 0 ge k get g_n 54
10258ret p
10259end
10260q = uptxt p x_gap
10261if eq w 3
10262q = uptxt q x_note_bringing
10263end
10264if eq w 4
10265q = uptxt q x_note_copied
10266end
10267if eq w 5
10268q = uptxt q x_note_failed
10269end
10270ml = ulong get g_ml k
10271for j ulong ml bound 64
10272put g_nm add q j get g_mn add mul k 64 j
10273end
10274q = add q ml
10275if eq w 1
10276q = uptxt q x_note_unreachable
10277end
10278if eq w 2
10279q = uptxt q x_note_building
10280end
10281ret q
10282end
10283
10284note for a check: HOPLATE sends Enter late, when the machines have had time to answer
10285fn uchecklate to void
10286put g_n 48 20
10287n = ucs x_env_late
10288upr 0 ulong libptr g_nm 0 1024
10289if ne ucall 9 0
10290put g_n 48 80
10291end
10292end
10293
10294note the three more things this program is told by selector (entry 13 hears them all)
10295fn umoremethods mine ulong to bool
10296ok = umethod mine m_remote_go 13 t_v
10297ok = and ok umethod mine m_remote_done 13 t_v
10298ok = and ok umethod mine m_fetch_done 13 t_v
10299put g_m 46 usl m_remote_go
10300put g_m 47 usl m_remote_done
10301put g_m 48 usl m_fetch_done
10302ret ok
10303end
10304
10305note ---- the icon in the menu bar and its menu, as Hop has them (Sources/main.swift) ----
10306note Open, Rebuild file index, Allow paste into apps, Open at login, Settings, Clear clipboard history, Quit.
10307note one item of that menu: title, what it tells this program (action_sel), its key (an NSString); the item
10308fn ustatusadd menu ulong title view uchar * action_sel ulong key_string ulong to ulong
10309item = umsg ucl c_menu_item usl m_alloc 0 0 0
10310title_string = uns title
10311item = umsg item usl m_init_item title_string action_sel key_string
10312x = umsg item usl m_set_target get g_o 27 0 0
10313x = umsg menu usl m_add_item item 0 0
10314ret item
10315end
10316
10317note macOS's keeper of what opens at login, for this app (0: there is none)
10318fn uloginservice to ulong
10319n = ucs x_sm_path
10320upr 0 ulong libptr g_nm 0 1024
10321upr 8 1
10322x = ucall 0
10323c = ucl c_sm_service
10324if eq c 0
10325ret 0
10326end
10327ret umsg c usl m_main_app 0 0 0
10328end
10329
10330note Open at login: on becomes off and off on; when macOS refuses, that is said
10331fn ulogintoggle to void
10332service = uloginservice
10333if eq service 0
10334ret
10335end
10336done = ulong 0
10337if eq umsg service usl m_status 0 0 0 1
10338done = and umsg service usl m_unregister 0 0 0 255
10339if eq done 1
10340x = umsg get g_m 53 usl m_set_state 0 0 0
10341end
10342else
10343done = and umsg service usl m_register 0 0 0 255
10344if eq done 1
10345x = umsg get g_m 53 usl m_set_state 1 0 0
10346end
10347end
10348if eq done 0
10349alert = umsg umsg ucl c_alert usl m_alloc 0 0 0 usl m_init 0 0 0
10350x = umsg alert usl m_set_message uns x_login_failed 0 0
10351x = umsg alert usl m_run_modal 0 0 0
10352end
10353end
10354
10355note Allow paste into apps: macOS is asked to show its own question about Accessibility for this app
10356fn upasteask to void
10357prompt_key = uconst s_trusted_prompt
10358if eq prompt_key 0
10359ret
10360end
10361yes_flag = umsg ucl c_number usl m_number_bool 1 0 0
10362options = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
10363x = umsg options usl m_set_object yes_flag prompt_key 0
10364f = usym s_trusted_options
10365if eq f 0
10366ret
10367end
10368upr 0 options
10369x = ucallf f
10370end
10371
10372note Clear clipboard history: every copied thing that is not pinned goes, a picture's sealed file with it. Like
10373note every change to the history it is this program's to do only while Hop is not running
10374fn uclipclear to void
10375if and eq get g_n 14 1 uhoprunning
10376ret
10377end
10378items = uclipsmutable
10379if eq items 0
10380ret
10381end
10382sat = usl m_at
10383sremove = usl m_remove_at
10384cnt = umsg items usl m_count 0 0 0
10385for back ulong cnt bound 100000
10386j = sub sub cnt 1 back
10387e = umsg items sat j 0 0
10388if uiskind e 7
10389if not uclippinned e
10390image_name = ukeyed e k_image
10391if uiskind image_name 9
10392if ne and umsg image_name usl m_contains uns x_slash_text 0 0 255 1
10393folder = uhoppath x_clip_images
10394if ne folder 0
10395gone = umsg folder usl m_append_string image_name 0 0
10396manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
10397x = umsg manager usl m_remove_item gone 0 0
10398end
10399end
10400end
10401x = umsg items sremove j 0 0
10402end
10403end
10404end
10405if eq uclipswrite items 1
10406uloadclips
10407urefresh
10408end
10409end
10410
10411note the menu of the icon in the menu bar
10412fn ustatusmenu to ulong
10413menu = umsg ucl c_menu usl m_alloc 0 0 0
10414menu = umsg menu usl m_init_title uns x_app 0 0
10415put g_nm 0 0
10416no_key = unsb
10417s_add = usl m_add_item
10418c_item = ucl c_menu_item
10419s_line = usl m_separator
10420x = ustatusadd menu x_status_open get g_m 54 no_key
10421x = umsg menu s_add umsg c_item s_line 0 0 0 0 0
10422x = ustatusadd menu x_status_index get g_m 55 no_key
10423x = ustatusadd menu x_status_paste get g_m 56 no_key
10424login_item = ustatusadd menu x_status_login get g_m 57 no_key
10425put g_m 53 login_item
10426if eq get g_n 14 1
10427service = uloginservice
10428if ne service 0
10429if eq umsg service usl m_status 0 0 0 1
10430x = umsg login_item usl m_set_state 1 0 0
10431end
10432end
10433end
10434comma_key = uns x_key_comma
10435x = ustatusadd menu x_status_settings get g_m 58 comma_key
10436x = ustatusadd menu x_status_clear get g_m 59 no_key
10437x = umsg menu s_add umsg c_item s_line 0 0 0 0 0
10438q_key = uns x_key_q
10439s_quit = usl m_terminate
10440quit_item = ustatusadd menu x_quit s_quit q_key
10441x = umsg quit_item usl m_set_target umsg ucl c_app usl m_shared 0 0 0 0 0
10442ret menu
10443end
10444
10445note put the icon in the menu bar (a check has none; with HOPMENU it says the menu's items instead)
10446fn ustatus to void
10447menu = ustatusmenu
10448if eq get g_n 14 0
10449n = ucs x_env_menu
10450upr 0 ulong libptr g_nm 0 1024
10451if eq ucall 9 0
10452ret
10453end
10454entries = umsg menu usl m_item_array 0 0 0
10455sat = usl m_at
10456s_title = usl m_item_title
10457cnt = umsg entries usl m_count 0 0 0
10458p = uptxt 0 x_menu_word
10459for i ulong cnt bound 32
10460title_bytes = umsg umsg umsg entries sat i 0 0 s_title 0 0 0 get g_o 5 0 0 0
10461if gt i 0
10462put g_nm p 124
10463p = add p 1
10464end
10465p = ufetchat p title_bytes
10466end
10467put g_nm p 10
10468upr 0 1
10469upr 8 ulong libptr g_nm 0 1024
10470upr 16 add p 1
10471x = ucall 3
10472ret
10473end
10474bar = umsg ucl c_status_bar usl m_system_status_bar 0 0 0
10475s_length = usl m_status_item_length
10476upr 64 13835058055282163712
10477item = umsg bar s_length 0 0 0
10478if eq item 0
10479ret
10480end
10481item = umsg item usl m_retain 0 0 0
10482put g_m 52 item
10483button = umsg item usl m_button 0 0 0
10484c_i = ucl c_image
10485s_symbol = usl m_symbol_image
10486symbol_name = uns x_status_symbol
10487said_name = uns x_app
10488image = umsg c_i s_symbol symbol_name said_name 0
10489if ne image 0
10490x = umsg button usl m_set_image image 0 0
10491end
10492x = umsg item usl m_set_item_menu menu 0 0
10493center = umsg ucl c_center usl m_default_center 0 0 0
10494s_observe = usl m_add_observer
10495quitting = uconst s_will_terminate
10496upr 40 0
10497x = umsg center s_observe get g_o 27 get g_m 62 quitting
10498end
10499
10500note what the menu of the icon tells this program (which: the selector); true when it was one of its
10501fn ustatusevent which ulong to bool
10502if eq which get g_m 62
10503utunnelstop
10504ret true
10505end
10506if eq which get g_m 54
10507ushow
10508ret true
10509end
10510if eq which get g_m 55
10511uindexstart
10512ret true
10513end
10514if eq which get g_m 56
10515upasteask
10516ret true
10517end
10518if eq which get g_m 57
10519ulogintoggle
10520ret true
10521end
10522if eq which get g_m 58
10523usettings
10524ret true
10525end
10526if eq which get g_m 59
10527uclipclear
10528ret true
10529end
10530ret false
10531end
10532
10533note the six more things this program is told by selector (entry 13 hears them all)
10534fn ustatusmethods mine ulong to bool
10535ok = umethod mine m_menu_open 13 t_v
10536ok = and ok umethod mine m_menu_index 13 t_v
10537ok = and ok umethod mine m_menu_paste 13 t_v
10538ok = and ok umethod mine m_menu_login 13 t_v
10539ok = and ok umethod mine m_menu_settings 13 t_v
10540ok = and ok umethod mine m_menu_clear 13 t_v
10541put g_m 54 usl m_menu_open
10542put g_m 55 usl m_menu_index
10543put g_m 56 usl m_menu_paste
10544put g_m 57 usl m_menu_login
10545put g_m 58 usl m_menu_settings
10546put g_m 59 usl m_menu_clear
10547ret ok
10548end
10549
10550note ---- forwarded ports: the ssh links Hop keeps open (Sources/Factory.swift, TunnelManager) ----
10551note Hop's settings name ports of other computers to have on this Mac (a model's server, the factory, the
10552note knowledge base). At the start and every 20 seconds each one whose link is not running is looked at: when
10553note nothing on this Mac serves its port (nc is asked, as a program of its own), ssh is started for it with Hop's own options (a link of its own, never
10554note the shared connection, so it ends cleanly). A port something else serves is left alone, and so Hop and this
10555note program do not fight over one. When this program quits it ends its links. Not here yet: dropping the links
10556note at once when the network changes (ssh notices by itself within 45 seconds, and the link is made anew).
10557note the whole number an object of the settings holds: 0 when it is not a number, is a yes or a no, or is not
10558note whole (8080.9 is no port, and Hop takes none of these either)
10559fn uwhole obj ulong to ulong
10560if not uisnumber obj
10561ret 0
10562end
10563yes_object = uconst s_cf_true
10564no_object = uconst s_cf_false
10565if or eq obj yes_object eq obj no_object
10566ret 0
10567end
10568v = umsg obj usl m_integer_value 0 0 0
10569same_v = umsg ucl c_number usl m_number_integer v 0 0
10570if eq and umsg obj usl m_is_equal_number same_v 0 0 255 0
10571ret 0
10572end
10573ret v
10574end
10575
10576note one forwarded port to keep: added to list when both ports are ports, the ssh name is there, and this Mac's
10577note port is not in the list already
10578fn utunneladd list ulong local ulong remote ulong host ulong to void
10579if or or eq local 0 gt local 65535 or eq remote 0 gt remote 65535
10580ret
10581end
10582if not uiskind host 9
10583ret
10584end
10585if eq umsg host usl m_length 0 0 0 0
10586ret
10587end
10588sat = usl m_at
10589s_whole = usl m_integer_value
10590cnt = umsg list usl m_count 0 0 0
10591for i ulong cnt bound 256
10592if eq umsg umsg umsg list sat i 0 0 sat 0 0 0 s_whole 0 0 0 local
10593ret
10594end
10595end
10596entry = umsg ucl c_mutable_array usl m_array 0 0 0
10597sadd = usl m_add_object
10598c_n_v = ucl c_number
10599s_number = usl m_number_integer
10600x = umsg entry sadd umsg c_n_v s_number local 0 0 0 0
10601x = umsg entry sadd umsg c_n_v s_number remote 0 0 0 0
10602x = umsg entry sadd host 0 0
10603x = umsg list sadd entry 0 0
10604end
10605
10606note the forwarded ports of the settings: the ones named there, and the one to the knowledge base when it runs
10607note on another computer
10608fn utunnelsload config ulong to void
10609links = umsg ucl c_mutable_array usl m_array 0 0 0
10610if ne config 0
10611named = ukeyed config k_tunnels
10612if uiskind named 8
10613sat = usl m_at
10614cnt = umsg named usl m_count 0 0 0
10615for i ulong cnt bound 256
10616t = umsg named sat i 0 0
10617if uiskind t 7
10618utunneladd links uwhole ukeyed t k_local_port uwhole ukeyed t k_remote_port ukeyed t k_ssh_host
10619end
10620end
10621end
10622cx = ukeyed config k_cortex
10623if uiskind cx 7
10624if uyes ukeyed cx k_enabled
10625address = ukeyed cx k_url
10626if uiskind address 9
10627url = umsg ucl c_url usl m_urlstr address 0 0
10628if ne url 0
10629utunneladd links uwhole umsg url usl m_url_port 0 0 0 uwhole ukeyed cx k_remote_port ukeyed cx k_host
10630end
10631end
10632end
10633end
10634end
10635if ne get g_m 60 0
10636x = umsg get g_m 60 usl m_release 0 0 0
10637end
10638put g_m 60 umsg links usl m_retain 0 0 0
10639put g_n 62 umsg links usl m_count 0 0 0
10640if eq get g_m 61 0
10641running = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
10642put g_m 61 umsg running usl m_retain 0 0 0
10643asking = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
10644put g_m 63 umsg asking usl m_retain 0 0 0
10645end
10646end
10647
10648note start the ssh link for one forwarded port (a check starts its stand-in, never ssh itself)
10649fn utunnelstart local ulong remote ulong host ulong to void
10650tool = uns x_real_ssh
10651if eq get g_n 14 0
10652n = ucs x_env_ssh
10653upr 0 ulong libptr g_nm 0 1024
10654given = ucall 9
10655if eq given 0
10656ret
10657end
10658n = ufetch given
10659tool = unsb
10660end
10661manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
10662if eq and umsg manager usl m_is_executable tool 0 0 255 0
10663ret
10664end
10665arguments = umsg uwords x_tunnel_args usl m_mutable_copy 0 0 0
10666p = uptxt 0 x_loopback
10667p = upnum p local
10668put g_nm p 58
10669p = uptxt add p 1 x_loopback
10670p = upnum p remote
10671put g_nm p 0
10672forward = unsb
10673sadd = usl m_add_object
10674x = umsg arguments sadd forward 0 0
10675x = umsg arguments sadd host 0 0
10676task = umsg umsg ucl c_task usl m_alloc 0 0 0 usl m_init 0 0 0
10677x = umsg task usl m_set_launch tool 0 0
10678x = umsg task usl m_set_arguments arguments 0 0
10679quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
10680x = umsg task usl m_set_output quiet 0 0
10681x = umsg task usl m_set_error quiet 0 0
10682x = umsg task usl m_set_input quiet 0 0
10683x = umsg task usl m_launch 0 0 0
10684put g_n 61 add get g_n 61 1
10685c_n_v = ucl c_number
10686s_number = usl m_number_integer
10687port_key = umsg c_n_v s_number local 0 0
10688x = umsg get g_m 61 usl m_set_object task port_key 0
10689note the list of this Mac's links keeps the program now, and the program its words
10690srel = usl m_release
10691x = umsg task srel 0 0 0
10692x = umsg arguments srel 0 0 0
10693end
10694
10695note is the link of this Mac's port running
10696fn utunnelalive port_key ulong to bool
10697task = umsg get g_m 61 usl m_object_for_key port_key 0 0
10698if eq task 0
10699ret false
10700end
10701ret eq and umsg task usl m_is_running 0 0 0 255 1
10702end
10703
10704note ask whether something on this Mac serves the port: nc tries it for two seconds at most, as a program of its
10705note own, so this program never waits on a port that does not answer (Hop asks with a two second limit too).
10706note probeDone: is told when it has ended
10707fn uprobestart local ulong port_key ulong to void
10708tool = uns x_nc
10709manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
10710if eq and umsg manager usl m_is_executable tool 0 0 255 0
10711ret
10712end
10713arguments = umsg uwords x_nc_args usl m_mutable_copy 0 0 0
10714p = upnum 0 local
10715put g_nm p 0
10716port_text = unsb
10717x = umsg arguments usl m_add_object port_text 0 0
10718task = umsg umsg ucl c_task usl m_alloc 0 0 0 usl m_init 0 0 0
10719x = umsg task usl m_set_launch tool 0 0
10720x = umsg task usl m_set_arguments arguments 0 0
10721quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
10722x = umsg task usl m_set_output quiet 0 0
10723x = umsg task usl m_set_error quiet 0 0
10724x = umsg task usl m_set_input quiet 0 0
10725center = umsg ucl c_center usl m_default_center 0 0 0
10726s_observe = usl m_add_observer
10727ended = uconst s_task_ended
10728upr 40 task
10729x = umsg center s_observe get g_o 27 get g_m 64 ended
10730x = umsg get g_m 63 usl m_set_object task port_key 0
10731x = umsg task usl m_launch 0 0 0
10732note the list of askers keeps the program now, and the program its words
10733srel = usl m_release
10734x = umsg task srel 0 0 0
10735x = umsg arguments srel 0 0 0
10736end
10737
10738note the asking has ended (about: the notice, whose object is the program that asked). A port nothing serves,
10739note whose link is still not running, gets its link
10740fn uprobedone about ulong to void
10741if or eq about 0 eq get g_m 63 0
10742ret
10743end
10744task = umsg about usl m_note_object 0 0 0
10745if eq task 0
10746ret
10747end
10748x = umsg task usl m_retain 0 0 0
10749center = umsg ucl c_center usl m_default_center 0 0 0
10750x = umsg center usl m_remove_all_observer get g_o 27 0 task
10751served = eq and umsg task usl m_termination 0 0 0 4294967295 0
10752port_keys = umsg get g_m 63 usl m_all_keys_for task 0 0
10753sat = usl m_at
10754s_whole = usl m_integer_value
10755s_drop = usl m_remove_for_key
10756links = get g_m 60
10757cnt = umsg port_keys usl m_count 0 0 0
10758for i ulong cnt bound 16
10759port_key = umsg port_keys sat i 0 0
10760local = umsg port_key s_whole 0 0 0
10761x = umsg get g_m 63 s_drop port_key 0 0
10762if and not served ne links 0
10763if not utunnelalive port_key
10764many = umsg links usl m_count 0 0 0
10765for j ulong many bound 256
10766entry = umsg links sat j 0 0
10767if eq umsg umsg entry sat 0 0 0 s_whole 0 0 0 local
10768utunnelstart local umsg umsg entry sat 1 0 0 s_whole 0 0 0 umsg entry sat 2 0 0
10769end
10770end
10771end
10772end
10773end
10774x = umsg task usl m_release 0 0 0
10775end
10776
10777note look at every forwarded port: for one whose link is not running, and that is not being asked about already,
10778note it is asked whether something serves the port
10779fn utunnelcheck to void
10780links = get g_m 60
10781if or or eq links 0 eq get g_m 61 0 eq get g_m 63 0
10782ret
10783end
10784if not uremoteok
10785ret
10786end
10787sat = usl m_at
10788s_whole = usl m_integer_value
10789s_keyed = usl m_object_for_key
10790c_n_v = ucl c_number
10791s_number = usl m_number_integer
10792cnt = umsg links usl m_count 0 0 0
10793for i ulong cnt bound 256
10794entry = umsg links sat i 0 0
10795local = umsg umsg entry sat 0 0 0 s_whole 0 0 0
10796port_key = umsg c_n_v s_number local 0 0
10797if not utunnelalive port_key
10798if eq umsg get g_m 63 s_keyed port_key 0 0 0
10799uprobestart local port_key
10800end
10801end
10802end
10803end
10804
10805note twice a second: every 20 seconds, and half a second after the start, the forwarded ports are looked at
10806fn utunneltick to void
10807ticks = get g_n 60
10808put g_n 60 add ticks 1
10809if eq sub ticks mul div ticks 40 40 0
10810utunnelcheck
10811end
10812end
10813
10814note this program is ending (quitting, or a check at its end): its links and its askers end with it
10815fn utunnelstop to void
10816sat = usl m_at
10817s_running = usl m_is_running
10818s_end = usl m_terminate_task
10819s_values = usl m_all_values
10820for which ulong 2
10821kept = get g_m 61
10822if eq which 1
10823kept = get g_m 63
10824end
10825if ne kept 0
10826tasks = umsg kept s_values 0 0 0
10827cnt = umsg tasks usl m_count 0 0 0
10828for i ulong cnt bound 256
10829task = umsg tasks sat i 0 0
10830if eq and umsg task s_running 0 0 0 255 1
10831x = umsg task s_end 0 0 0
10832end
10833end
10834end
10835end
10836end
10837
10838note hear when this program is about to quit (appQuit:) and when a port has been asked about (probeDone:)
10839fn uquitwatch mine ulong to bool
10840ok = umethod mine m_app_quit 13 t_v
10841ok = and ok umethod mine m_probe_done 13 t_v
10842put g_m 62 usl m_app_quit
10843put g_m 64 usl m_probe_done
10844ret ok
10845end
10846
10847note ---- screens: the list shows one kind of thing, and typing looks in it ----
10848note the copied things: all of them, pinned first, or the ones that have every typed word
10849fn uscreenclips to void
10850uclipmatch 1024
10851h = get g_n 28
10852for i ulong h bound 1024
10853put g_rk i 6
10854put g_hit i get g_cm i
10855put g_why i 0
10856end
10857put g_n 1 h
10858end
10859
10860note the saved accounts: all of them, or the ones whose name has the typed text
10861fn uscreenaccounts to void
10862nacc = get g_n 31
10863a = get g_n 12
10864n = get g_n 13
10865typed_low = ulong 0
10866if and gt n 0 le n 255
10867for i ulong n bound 256
10868put g_nm i get g_q add a i
10869end
10870put g_nm n 0
10871typed = unsb
10872if ne typed 0
10873typed_low = umsg typed usl m_lowercase 0 0 0
10874end
10875end
10876slower = usl m_lowercase
10877scontains = usl m_contains
10878h = ulong 0
10879for i ulong nacc bound 800
10880keep = true
10881if gt n 0
10882keep = false
10883if ne typed_low 0
10884name_low = umsg umsg get g_m 18 get g_m 16 i 0 0 slower 0 0 0
10885keep = eq and umsg name_low scontains typed_low 0 0 255 1
10886end
10887end
10888if keep
10889put g_rk h 5
10890put g_hit h i
10891put g_why h 0
10892h = add h 1
10893end
10894end
10895put g_n 1 h
10896end
10897
10898note show screen number which (0: everything again): the field is emptied and the list made anew
10899fn uscreen which ulong to void
10900put g_n 36 which
10901put g_nm 0 0
10902x = umsg get g_o 0 get g_o 8 unsb 0 0
10903utyped
10904end
10905
10906note make the list anew from what is known now, keeping the first row selected
10907fn urefresh to void
10908unarrow
10909x = umsg get g_o 1 get g_o 7 0 0 0
10910put g_n 6 0
10911if gt get g_n 1 0
10912uchoose 0
10913end
10914ushowst
10915end
10916
10917note pin or unpin (what 1) or delete (what 2) copied thing i in the history, then show the history as it is now.
10918note Like recording it is this program's to do only while Hop is not running
10919fn uclipedit i ulong what ulong to void
10920if ge i get g_n 24
10921ret
10922end
10923if and eq get g_n 14 1 uhoprunning
10924ret
10925end
10926shown_item = umsg get g_m 14 get g_m 16 i 0 0
10927if not uiskind shown_item 7
10928ret
10929end
10930id_text = ukeyed shown_item k_id
10931if not uiskind id_text 9
10932ret
10933end
10934items = uclipsmutable
10935if eq items 0
10936ret
10937end
10938sat = usl m_at
10939sequal = usl m_equal_string
10940cnt = umsg items usl m_count 0 0 0
10941found = cnt
10942for j ulong cnt bound 100000
10943if eq found cnt
10944e = umsg items sat j 0 0
10945if uiskind e 7
10946other_id = ukeyed e k_id
10947if uiskind other_id 9
10948if eq and umsg other_id sequal id_text 0 0 255 1
10949found = j
10950end
10951end
10952end
10953end
10954end
10955if eq found cnt
10956ret
10957end
10958e = umsg items sat found 0 0
10959if eq what 1
10960flip = ulong 1
10961if uclippinned e
10962flip = 0
10963end
10964flag = umsg ucl c_number usl m_number_bool flip 0 0
10965x = umsg e usl m_set_object flag uns k_pinned 0
10966else
10967image_name = ukeyed e k_image
10968if uiskind image_name 9
10969if ne and umsg image_name usl m_contains uns x_slash_text 0 0 255 1
10970folder = uhoppath x_clip_images
10971if ne folder 0
10972gone = umsg folder usl m_append_string image_name 0 0
10973manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
10974x = umsg manager usl m_remove_item gone 0 0
10975end
10976end
10977end
10978x = umsg items usl m_remove_at found 0 0
10979end
10980if eq uclipswrite items 1
10981uloadclips
10982urefresh
10983end
10984end
10985
10986note the menu's Pin or Unpin and Delete from History: on the selected row when it is a copied thing
10987fn uclipmenu what ulong to void
10988r = get g_n 6
10989if or ge r get g_n 1 ne ulong get g_rk r 6
10990ret
10991end
10992uclipedit get g_hit r what
10993end
10994
10995note open Hop's settings file in TextEdit, as Hop does (a check: with the program macOS has for it). When there
10996note is no settings file yet an empty one is made, which Hop reads as all its built-in settings
10997fn usettings to void
10998path = uhoppath x_config
10999if eq path 0
11000ret
11001end
11002url = umsg ucl c_url usl m_furl path 0 0
11003ws = umsg ucl c_ws usl m_shws 0 0 0
11004if eq get g_n 14 0
11005put g_n 9 and umsg ws usl m_open url 0 0 255
11006ret
11007end
11008manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
11009if eq and umsg manager usl m_file_exists path 0 0 255 0
11010d = umsg uns x_empty_settings usl m_data_using 4 0 0
11011x = umsg d usl m_write_file path 1 0
11012upr 0 umsg path get g_o 5 0 0 0
11013upr 8 384
11014x = ucall 16
11015end
11016urls = umsg ucl c_array usl m_array_with url 0 0
11017editor = umsg ucl c_url usl m_furl uns x_textedit 0 0
11018how = umsg ucl c_open_config usl m_configuration 0 0 0
11019s_open = usl m_open_urls_with
11020upr 40 0
11021x = umsg ws s_open urls editor how
11022put g_n 9 1
11023end
11024
11025note the rows to show: a screen's own, else what is offered when nothing is typed, else what the one box's
11026note rules give for the text
11027fn unarrow to void
11028if eq get g_n 36 1
11029uscreenclips
11030ret
11031end
11032if eq get g_n 36 2
11033uscreenaccounts
11034ret
11035end
11036if eq get g_n 13 0
11037usuggest
11038ret
11039end
11040m = ulong 0
11041for k ulong get g_n 0 bound 2048
11042s = uscore k
11043if gt s 0
11044put g_mk m k
11045put g_ms m sub s 1
11046m = add m 1
11047end
11048end
11049usearch
11050urankrows m
11051end
11052
11053note "H of N apps" into the status line
11054fn ushowst to void
11055p = upnum 0 get g_n 1
11056if eq get g_n 36 0
11057p = uptxt p x_of
11058p = upnum p get g_n 0
11059p = uptxt p x_apps
11060end
11061if eq get g_n 36 1
11062p = uptxt p x_copied_things
11063end
11064if eq get g_n 36 2
11065p = uptxt p x_accounts_word
11066end
11067if ne get g_m 23 0
11068p = uptxt p x_indexing
11069end
11070p = uremotenote p
11071put g_nm p 0
11072str = unsb
11073x = umsg get g_o 2 get g_o 8 str 0 0
11074end
11075
11076note select row r of the list and bring it into view
11077fn uchoose r ulong to void
11078put g_n 6 r
11079ix = umsg get g_o 13 get g_o 14 r 0 0
11080x = umsg get g_o 1 get g_o 12 ix 0 0
11081x = umsg get g_o 1 get g_o 15 r 0 0
11082end
11083
11084note what the list shows was typed into the field: read it, narrow, show
11085fn utyped to void
11086uaskstop
11087str = umsg get g_o 0 get g_o 6 0 0 0
11088p = umsg str get g_o 5 0 0 0
11089n = ufetch p
11090if gt n 255
11091n = 255
11092end
11093for i ulong n bound 256
11094put g_q i get g_nm i
11095end
11096put g_n 4 n
11097a = ulong 0
11098while lt a n bound 256
11099c = ulong get g_q a
11100if and ne c 32 ne c 9
11101break
11102end
11103a = add a 1
11104end
11105e = n
11106while gt e a bound 256
11107c = ulong get g_q sub e 1
11108if and ne c 32 ne c 9
11109break
11110end
11111e = sub e 1
11112end
11113put g_n 12 a
11114put g_n 13 sub e a
11115udecide
11116uremotesoon
11117unarrow
11118x = umsg get g_o 1 get g_o 7 0 0 0
11119put g_n 6 0
11120if gt get g_n 1 0
11121uchoose 0
11122end
11123ushowst
11124end
11125
11126note open app k: its folder, "/", its name and ".app" as a file address, handed to the workspace
11127fn ulaunch k ulong to void
11128p = ulong 0
11129if eq ulong get g_dir k 0
11130p = uptxt 0 x_dir1
11131else
11132p = uptxt 0 x_dir2
11133end
11134p = uptxt p x_slash
11135p = upname p k
11136p = uptxt p x_dotapp
11137put g_nm p 0
11138str = unsb
11139c = ucl c_url
11140s = usl m_furl
11141url = umsg c s str 0 0
11142c = ucl c_ws
11143s = usl m_shws
11144ws = umsg c s 0 0 0
11145s = usl m_open
11146put g_n 9 and umsg ws s url 0 0 255
11147end
11148
11149note open the web address the typed text stands for
11150fn uopenaddr to void
11151p = upaddr 0
11152put g_nm p 0
11153str = unsb
11154u = umsg get g_o 16 get g_o 17 str 0 0
11155c = ucl c_ws
11156s = usl m_shws
11157ws = umsg c s 0 0 0
11158s = usl m_open
11159put g_n 9 and umsg ws s u 0 0 255
11160end
11161
11162note ---- copied things: Hop's encrypted clipboard history (Sources/Clipboard.swift), read and never written ----
11163note The history is one file, sealed with AES-256-GCM (the core's fn gcunlock) under a key that Hop keeps in the
11164note login Keychain as an item of Apple's security tool and reads through that tool; the panel reads it the same
11165note way. The key and the unsealed bytes are wiped from the core's buffers as soon as they are used. The panel
11166note only reads the history: Hop, when it runs, is the one that keeps it, and it sees what the panel puts on
11167note the clipboard like anything else that is copied. A check (HOPCHECK) never asks the tool and never touches
11168note the real clipboard: it takes the key from HOPCLIPKEY and pastes into a board of its own.
11169note the clipboard key into the core's c_k; 1 when it is there
11170fn uclipkey to ulong
11171encoded = ulong 0
11172item_name = ulong 0
11173if eq get g_n 14 0
11174n = ucs x_env_clipkey
11175upr 0 ulong libptr g_nm 0 1024
11176key_text = ucall 9
11177if eq key_text 0
11178ret 0
11179end
11180n = ufetch key_text
11181if and and gt n 5 eq get g_nm 0 116 and eq get g_nm 3 108 eq get g_nm 4 58
11182for i ulong sub n 5 bound 1024
11183put g_nm i get g_nm add 5 i
11184end
11185put g_nm sub n 5 0
11186item_name = unsb
11187else
11188encoded = unsb
11189end
11190else
11191item_name = uns x_clip_service
11192end
11193if ne item_name 0
11194task = umsg ucl c_task usl m_alloc 0 0 0
11195task = umsg task usl m_init 0 0 0
11196x = umsg task usl m_set_launch uns x_security 0 0
11197arguments = umsg ucl c_mutable_array usl m_array 0 0 0
11198sadd = usl m_add_object
11199x = umsg arguments sadd uns x_find 0 0
11200x = umsg arguments sadd uns x_dash_s 0 0
11201x = umsg arguments sadd item_name 0 0
11202x = umsg arguments sadd uns x_dash_a 0 0
11203x = umsg arguments sadd uns x_clip_account 0 0
11204x = umsg arguments sadd uns x_dash_w 0 0
11205x = umsg task usl m_set_arguments arguments 0 0
11206tube = umsg ucl c_pipe usl m_pipe 0 0 0
11207x = umsg task usl m_set_output tube 0 0
11208quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
11209x = umsg task usl m_set_error quiet 0 0
11210x = umsg task usl m_launch 0 0 0
11211reader = umsg tube usl m_reading 0 0 0
11212d = umsg reader usl m_read_end 0 0 0
11213x = umsg task usl m_wait 0 0 0
11214if ne and umsg task usl m_termination 0 0 0 4294967295 0
11215ret 0
11216end
11217if eq d 0
11218ret 0
11219end
11220whole = umsg ucl c_str usl m_alloc 0 0 0
11221whole = umsg whole usl m_init_data_encoding d 4 0
11222if eq whole 0
11223ret 0
11224end
11225blanks = umsg ucl c_charset usl m_whitespace 0 0 0
11226encoded = umsg whole usl m_trim blanks 0 0
11227end
11228if eq encoded 0
11229ret 0
11230end
11231kd = umsg ucl c_data usl m_alloc 0 0 0
11232kd = umsg kd usl m_init_base64 encoded 0 0
11233if eq kd 0
11234ret 0
11235end
11236if ne umsg kd usl m_length 0 0 0 32
11237ret 0
11238end
11239src = umsg kd usl m_bytes 0 0 0
11240upr 0 ulong libptr c_k 0 32
11241upr 8 src
11242upr 16 32
11243x = ucall 8
11244ret 1
11245end
11246
11247note wipe the first m unsealed bytes of the core's buffer
11248fn uforget m ulong to void
11249if eq m 0
11250ret
11251end
11252upr 0 ulong libptr c_d 0 m
11253upr 8 0
11254upr 16 m
11255x = ucall 17
11256end
11257
11258note the sealed bytes of d (an NSData: the nonce, the data, the tag) unsealed into the core's c_d with the
11259note clipboard key; the count of data bytes plus 1, or 0 when it cannot be done (no key, or not sealed by it)
11260fn uunseal d ulong to ulong
11261n = umsg d usl m_length 0 0 0
11262if or lt n 28 gt n 16777244
11263ret 0
11264end
11265src = umsg d usl m_bytes 0 0 0
11266if eq uclipkey 0
11267ret 0
11268end
11269m = sub n 28
11270upr 0 ulong libptr c_n 0 12
11271upr 8 src
11272upr 16 12
11273x = ucall 8
11274if gt m 0
11275upr 0 ulong libptr c_d 0 m
11276upr 8 add src 12
11277upr 16 m
11278x = ucall 8
11279end
11280upr 0 ulong libptr c_tg 0 16
11281upr 8 add src sub n 16
11282upr 16 16
11283x = ucall 8
11284good = gcunlock m
11285gcwipe
11286if eq good 0
11287ret 0
11288end
11289ret add m 1
11290end
11291
11292note the text a copied thing is shown by: its text without the blanks around it, a mark where a line ends, the
11293note first 80 characters; "Image" for a picture
11294fn uclippreview item ulong to ulong
11295if not uiskind item 7
11296ret uns x_image
11297end
11298words = ukeyed item k_text
11299if not uiskind words 9
11300ret uns x_image
11301end
11302blanks = umsg ucl c_charset usl m_whitespace 0 0 0
11303t = umsg words usl m_trim blanks 0 0
11304put g_nm 0 10
11305put g_nm 1 0
11306line_end = unsb
11307put g_nm 0 32
11308put g_nm 1 226
11309put g_nm 2 143
11310put g_nm 3 142
11311put g_nm 4 32
11312put g_nm 5 0
11313mark = unsb
11314t = umsg t usl m_replace line_end mark 0
11315if gt umsg t usl m_length 0 0 0 80
11316cut = umsg t usl m_composed_at 80 0 0
11317t = umsg t usl m_substring_to cut 0 0
11318end
11319ret t
11320end
11321
11322note read the history: the copied things, the text each is shown by, which are pinned, and the order they are
11323note searched in. Nothing is kept when the file is not there, the key is not to be had or the file is not Hop's
11324fn uloadclips to void
11325put g_n 24 0
11326d = uhopfile x_clipboard_file
11327if eq d 0
11328ret
11329end
11330r = uunseal d
11331if le r 1
11332ret
11333end
11334m = sub r 1
11335plain = umsg ucl c_data usl m_data_bytes ulong libptr c_d 0 m m 0
11336uforget m
11337items = umsg ucl c_json usl m_json_object plain 0 0
11338if not uiskind items 8
11339ret
11340end
11341cnt = umsg items usl m_count 0 0 0
11342if gt cnt 1024
11343cnt = 1024
11344end
11345sret = usl m_retain
11346srel = usl m_release
11347if ne get g_m 14 0
11348x = umsg get g_m 14 srel 0 0 0
11349x = umsg get g_m 15 srel 0 0 0
11350end
11351put g_m 14 umsg items sret 0 0 0
11352shown_by = umsg ucl c_mutable_array usl m_array 0 0 0
11353put g_m 15 umsg shown_by sret 0 0 0
11354sat = usl m_at
11355put g_m 16 sat
11356sadd = usl m_add_object
11357for i ulong cnt bound 1024
11358item = umsg items sat i 0 0
11359pv = uclippreview item
11360x = umsg shown_by sadd pv 0 0
11361put g_cp i 0
11362if uiskind item 7
11363pin = ukeyed item k_pinned
11364if uisnumber pin
11365if eq and umsg pin usl m_bool_value 0 0 0 255 1
11366put g_cp i 1
11367end
11368end
11369end
11370end
11371pos = ulong 0
11372for i ulong cnt bound 1024
11373if eq ulong get g_cp i 1
11374put g_ci pos i
11375pos = add pos 1
11376end
11377end
11378for i ulong cnt bound 1024
11379if eq ulong get g_cp i 0
11380put g_ci pos i
11381pos = add pos 1
11382end
11383end
11384put g_n 24 cnt
11385end
11386
11387note the text copied thing i is shown by into g_nm from byte p; the byte after it
11388fn uclipname p ulong i ulong to ulong
11389if or ge i get g_n 24 ge p 900
11390ret p
11391end
11392pv = umsg get g_m 15 get g_m 16 i 0 0
11393src = umsg pv get g_o 5 0 0 0
11394if eq src 0
11395ret p
11396end
11397upr 0 src
11398n = ucall 7
11399if gt add p n 900
11400n = sub 900 p
11401end
11402if eq n 0
11403ret p
11404end
11405upr 0 ulong libptr g_nm p n
11406upr 8 src
11407upr 16 n
11408x = ucall 8
11409ret add p n
11410end
11411
11412note the newest copied thing's text takes the place of the typed text (on 1) so that the address helpers work on
11413note it, and gives it back (on 0). Only used while nothing is typed
11414fn uclipaddr on ulong to void
11415if eq on 1
11416n = get g_n 25
11417for i ulong n bound 256
11418put g_q i get g_ca i
11419end
11420put g_n 12 0
11421put g_n 13 n
11422put g_n 10 get g_n 26
11423else
11424put g_n 13 0
11425put g_n 10 0
11426end
11427end
11428
11429note the copied things that match the typed text, as Hop's search does: the pinned ones first, each in lower
11430note case has to contain every typed word (a picture counts as "image"); the first "most" of them into g_cm
11431note (for a whole screen with nothing typed: all of them)
11432fn uclipmatch most ulong to void
11433put g_n 28 0
11434cnt = get g_n 24
11435if eq cnt 0
11436ret
11437end
11438a = get g_n 12
11439n = get g_n 13
11440if and eq n 0 gt most 8
11441every = cnt
11442if gt every most
11443every = most
11444end
11445for pos ulong every bound 1024
11446put g_cm pos get g_ci pos
11447end
11448put g_n 28 every
11449ret
11450end
11451if or eq n 0 gt n 255
11452ret
11453end
11454for i ulong n bound 256
11455put g_nm i get g_q add a i
11456end
11457put g_nm n 0
11458typed = unsb
11459if eq typed 0
11460ret
11461end
11462slower = usl m_lowercase
11463typed_low = umsg typed slower 0 0 0
11464parts = umsg typed_low usl m_components uns x_space 0 0
11465nt = umsg parts usl m_count 0 0 0
11466scontains = usl m_contains
11467slen = usl m_length
11468sat = get g_m 16
11469image_low = uns x_image_low
11470found = ulong 0
11471for pos ulong cnt bound 1024
11472if lt found most
11473i = get g_ci pos
11474item = umsg get g_m 14 sat i 0 0
11475hay = image_low
11476if uiskind item 7
11477words = ukeyed item k_text
11478if uiskind words 9
11479hay = umsg words slower 0 0 0
11480end
11481end
11482okay = true
11483for j ulong nt bound 64
11484term = umsg parts sat j 0 0
11485if gt umsg term slen 0 0 0 0
11486if ne and umsg hay scontains term 0 0 255 1
11487okay = false
11488end
11489end
11490end
11491if okay
11492put g_cm found i
11493found = add found 1
11494end
11495end
11496end
11497put g_n 28 found
11498end
11499
11500note put copied thing i on the clipboard: its text, or its picture unsealed (as PNG data). A check uses a board
11501note of its own
11502fn upasteclip i ulong to void
11503if ge i get g_n 24
11504ret
11505end
11506item = umsg get g_m 14 get g_m 16 i 0 0
11507if not uiskind item 7
11508ret
11509end
11510pboard = ulong 0
11511if eq get g_n 14 1
11512pboard = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
11513else
11514pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0
11515end
11516x = umsg pboard usl m_clear 0 0 0
11517words = ukeyed item k_text
11518if uiskind words 9
11519x = umsg pboard usl m_set_string_type words uns x_type_string 0
11520put g_n 29 1
11521ret
11522end
11523name = ukeyed item k_image
11524if not uiskind name 9
11525ret
11526end
11527if eq and umsg name usl m_contains uns x_slash_text 0 0 255 1
11528ret
11529end
11530folder = uhoppath x_clip_images
11531if eq folder 0
11532ret
11533end
11534path = umsg folder usl m_append_string name 0 0
11535d = umsg ucl c_data usl m_data_file path 0 0
11536if eq d 0
11537ret
11538end
11539r = uunseal d
11540if le r 1
11541ret
11542end
11543m = sub r 1
11544picture = umsg ucl c_data usl m_data_bytes ulong libptr c_d 0 m m 0
11545uforget m
11546x = umsg pboard usl m_set_data_type picture uns x_type_png 0
11547put g_n 29 2
11548end
11549
11550note press Command V for the app that is in front again, as Hop does after it has put something on the clipboard
11551fn usendpaste to void
11552for half ulong 2
11553upr 0 0
11554upr 8 9
11555upr 16 sub 1 half
11556ev = ucall 19
11557if ne ev 0
11558upr 0 ev
11559upr 8 1048576
11560x = ucall 20
11561upr 0 0
11562upr 8 ev
11563x = ucall 21
11564upr 0 ev
11565x = ucall 22
11566end
11567end
11568end
11569
11570note a moment from now, press Command V; only when this program is allowed to control the Mac (Accessibility)
11571fn ulaterpaste to void
11572if eq and ucall 18 255 0
11573ret
11574end
11575s_after = usl m_perform_after
11576s_paste = usl m_paste_now
11577upr 64 bitcast ulong 0.15f64
11578x = umsg get g_o 27 s_after s_paste 0 0
11579end
11580
11581note ---- recording what is copied, as Hop does (Sources/Clipboard.swift, poll) ----
11582note Only while Hop itself is not running: two programs must not write the same history. The history is read
11583note again at that moment, changed and written whole, sealed under the same key with a fresh nonce (the core's fn
11584note gclock), for the owner only. Before this program's first change in a run the history as it was is set
11585note aside next to it (clipboard.before-hop-omega.bin). What is marked concealed or transient is never kept.
11586note seal the first m bytes of the core's c_d under the clipboard key; nonce, data and tag as NSData, or 0
11587fn useal m ulong to ulong
11588if or eq m 0 gt m 16777216
11589ret 0
11590end
11591if eq uclipkey 0
11592ret 0
11593end
11594upr 0 ulong libptr c_n 0 12
11595upr 8 12
11596x = ucall 27
11597gclock m
11598gcwipe
11599sealed = umsg ucl c_mutable_data usl m_data 0 0 0
11600sappend = usl m_append_bytes
11601x = umsg sealed sappend ulong libptr c_n 0 12 12 0
11602x = umsg sealed sappend ulong libptr c_d 0 m m 0
11603x = umsg sealed sappend ulong libptr c_tg 0 16 16 0
11604ret sealed
11605end
11606
11607note the history as it is on disk now, as a list that can be changed: an empty one when there is no file yet,
11608note 0 when there is no key or the file is not Hop's
11609fn uclipsmutable to ulong
11610path = uhoppath x_clipboard_file
11611if eq path 0
11612ret 0
11613end
11614manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
11615if eq and umsg manager usl m_file_exists path 0 0 255 0
11616if eq uclipkey 0
11617ret 0
11618end
11619gcwipe
11620ret umsg ucl c_mutable_array usl m_array 0 0 0
11621end
11622d = umsg ucl c_data usl m_data_file path 0 0
11623if eq d 0
11624ret 0
11625end
11626r = uunseal d
11627if le r 1
11628ret 0
11629end
11630m = sub r 1
11631plain = umsg ucl c_data usl m_data_bytes ulong libptr c_d 0 m m 0
11632uforget m
11633items = umsg ucl c_json usl m_json_object plain 1 0
11634if not uiskind items 8
11635ret 0
11636end
11637ret items
11638end
11639
11640note write the list as the history; 1 when it was written
11641fn uclipswrite items ulong to ulong
11642data = umsg ucl c_json usl m_json_data items 0 0
11643if eq data 0
11644ret 0
11645end
11646n = umsg data usl m_length 0 0 0
11647if or eq n 0 gt n 16777216
11648ret 0
11649end
11650s_write = usl m_write_file
11651if eq get g_n 33 0
11652before = uhopfile x_clipboard_file
11653if ne before 0
11654aside = uhoppath x_clip_backup
11655x = umsg before s_write aside 1 0
11656upr 0 ulong libptr g_nm 0 1024
11657upr 8 384
11658x = ucall 16
11659end
11660put g_n 33 1
11661end
11662src = umsg data usl m_bytes 0 0 0
11663upr 0 ulong libptr c_d 0 n
11664upr 8 src
11665upr 16 n
11666x = ucall 8
11667sealed = useal n
11668uforget n
11669if eq sealed 0
11670ret 0
11671end
11672path = uhoppath x_clipboard_file
11673if eq path 0
11674ret 0
11675end
11676ok = and umsg sealed s_write path 1 0 255
11677path = uhoppath x_clipboard_file
11678upr 0 ulong libptr g_nm 0 1024
11679upr 8 384
11680x = ucall 16
11681ret ok
11682end
11683
11684note is the copied thing e pinned
11685fn uclippinned e ulong to bool
11686if not uiskind e 7
11687ret false
11688end
11689pin = ukeyed e k_pinned
11690if not uisnumber pin
11691ret false
11692end
11693ret eq and umsg pin usl m_bool_value 0 0 0 255 1
11694end
11695
11696note what is on the pasteboard pb goes into the history as Hop puts it there: text that is already there moves
11697note to the front, new text or a picture (as PNG, sealed in a file of its own) is added in front with the app it
11698note came from; then the unpinned ones over the limit go, the oldest first
11699fn ucliprecord pb ulong to void
11700types = umsg pb usl m_types 0 0 0
11701if ne types 0
11702shas = usl m_contains_object
11703if eq and umsg types shas uns x_skip0 0 0 255 1
11704ret
11705end
11706if eq and umsg types shas uns x_skip1 0 0 255 1
11707ret
11708end
11709if eq and umsg types shas uns x_skip2 0 0 255 1
11710ret
11711end
11712if eq and umsg types shas uns x_skip3 0 0 255 1
11713ret
11714end
11715if eq and umsg types shas uns x_skip4 0 0 255 1
11716ret
11717end
11718if eq and umsg types shas uns x_skip5 0 0 255 1
11719ret
11720end
11721end
11722items = uclipsmutable
11723if eq items 0
11724ret
11725end
11726source = ulong 0
11727if eq get g_n 14 1
11728front_app = umsg umsg ucl c_ws usl m_shws 0 0 0 usl m_frontmost 0 0 0
11729if ne front_app 0
11730source = umsg front_app usl m_localized_name 0 0 0
11731end
11732end
11733cnum = ucl c_number
11734x = umsg ucl c_date usl m_reference_now 0 0 0
11735now_bits = ugr 64
11736s_double = usl m_number_double
11737upr 64 now_bits
11738moment = umsg cnum s_double 0 0 0
11739sset = usl m_set_object
11740sat = usl m_at
11741sins = usl m_insert_at
11742copied = umsg pb usl m_string_for_type uns x_type_string 0 0
11743has_text = false
11744if ne copied 0
11745if gt umsg copied usl m_length 0 0 0 0
11746has_text = true
11747end
11748end
11749fresh_item = ulong 0
11750if has_text
11751if gt umsg copied usl m_byte_length 4 0 0 512000
11752ret
11753end
11754cnt = umsg items usl m_count 0 0 0
11755found = cnt
11756sequal = usl m_equal_string
11757for i ulong cnt bound 100000
11758if eq found cnt
11759e = umsg items sat i 0 0
11760if uiskind e 7
11761words = ukeyed e k_text
11762if uiskind words 9
11763if eq and umsg words sequal copied 0 0 255 1
11764found = i
11765end
11766end
11767end
11768end
11769end
11770if lt found cnt
11771e = umsg items sat found 0 0
11772kept = umsg e usl m_retain 0 0 0
11773x = umsg e sset moment uns k_date 0
11774x = umsg items usl m_remove_at found 0 0
11775x = umsg items sins e 0 0
11776x = umsg e usl m_release 0 0 0
11777else
11778fresh_item = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
11779x = umsg fresh_item sset copied uns k_text 0
11780end
11781else
11782picture = umsg ucl c_image usl m_alloc 0 0 0
11783picture = umsg picture usl m_init_pasteboard pb 0 0
11784if eq picture 0
11785ret
11786end
11787tiff = umsg picture usl m_tiff 0 0 0
11788if eq tiff 0
11789ret
11790end
11791bitmap = umsg ucl c_bitmap usl m_rep_with_data tiff 0 0
11792if eq bitmap 0
11793ret
11794end
11795no_properties = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
11796png = umsg bitmap usl m_rep_using 4 no_properties 0
11797if eq png 0
11798ret
11799end
11800pn = umsg png usl m_length 0 0 0
11801if or eq pn 0 gt pn 16777216
11802ret
11803end
11804src = umsg png usl m_bytes 0 0 0
11805upr 0 ulong libptr c_d 0 pn
11806upr 8 src
11807upr 16 pn
11808x = ucall 8
11809sealed = useal pn
11810uforget pn
11811if eq sealed 0
11812ret
11813end
11814folder = uhoppath x_clip_images
11815if eq folder 0
11816ret
11817end
11818manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
11819s_create = usl m_create_dir
11820upr 40 0
11821x = umsg manager s_create folder 1 0
11822file_name = umsg umsg umsg ucl c_uuid usl m_uuid 0 0 0 usl m_uuid_string 0 0 0 usl m_append_string uns x_dot_bin 0 0
11823file_path = umsg folder usl m_append_string file_name 0 0
11824if eq and umsg sealed usl m_write_file file_path 1 0 255 0
11825ret
11826end
11827fresh_item = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
11828x = umsg fresh_item sset file_name uns k_image 0
11829end
11830if ne fresh_item 0
11831id_text = umsg umsg ucl c_uuid usl m_uuid 0 0 0 usl m_uuid_string 0 0 0
11832x = umsg fresh_item sset id_text uns k_id 0
11833x = umsg fresh_item sset moment uns k_date 0
11834if ne source 0
11835x = umsg fresh_item sset source uns k_source 0
11836end
11837no = umsg cnum usl m_number_bool 0 0 0
11838x = umsg fresh_item sset no uns k_pinned 0
11839x = umsg items sins fresh_item 0 0
11840end
11841note the unpinned ones over the limit go, from the end
11842limit = get g_n 34
11843if lt limit 50
11844limit = 50
11845end
11846cnt = umsg items usl m_count 0 0 0
11847loose = ulong 0
11848for i ulong cnt bound 100000
11849if not uclippinned umsg items sat i 0 0
11850loose = add loose 1
11851end
11852end
11853if gt loose limit
11854drop = sub loose limit
11855manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
11856for back ulong cnt bound 100000
11857i = sub sub cnt 1 back
11858if gt drop 0
11859e = umsg items sat i 0 0
11860if not uclippinned e
11861if uiskind e 7
11862image_name = ukeyed e k_image
11863if uiskind image_name 9
11864if ne and umsg image_name usl m_contains uns x_slash_text 0 0 255 1
11865folder = uhoppath x_clip_images
11866if ne folder 0
11867gone = umsg folder usl m_append_string image_name 0 0
11868x = umsg manager usl m_remove_item gone 0 0
11869end
11870end
11871end
11872end
11873x = umsg items usl m_remove_at i 0 0
11874drop = sub drop 1
11875end
11876end
11877end
11878end
11879x = uclipswrite items
11880end
11881
11882note is Hop itself running
11883fn uhoprunning to bool
11884others = umsg ucl c_running_app usl m_running_with uns x_hop_id 0 0
11885if eq others 0
11886ret false
11887end
11888ret gt umsg others usl m_count 0 0 0 0
11889end
11890
11891note twice a second: when the clipboard has changed and Hop is not there to keep the history, this program does
11892fn ucliptick to void
11893uindextick
11894utunneltick
11895pb = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
11896cc = umsg pb usl m_change_count 0 0 0
11897if eq cc get g_n 35
11898ret
11899end
11900put g_n 35 cc
11901if uhoprunning
11902ret
11903end
11904ucliprecord pb
11905end
11906
11907note after this program put something on the clipboard itself: that change is not a new copied thing; a text that
11908note was pasted moves to the front of the history, as in Hop
11909fn uclipmine was_text ulong to void
11910pb = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
11911put g_n 35 umsg pb usl m_change_count 0 0 0
11912if and eq was_text 1 not uhoprunning
11913ucliprecord pb
11914end
11915end
11916
11917note is the app in front a browser, by Hop's list
11918fn ufrontbrowser to ulong
11919id = get g_m 11
11920if eq id 0
11921ret 0
11922end
11923sequal = usl m_equal_string
11924if eq and umsg id sequal uns x_browser0 0 0 255 1
11925ret 1
11926end
11927if eq and umsg id sequal uns x_browser1 0 0 255 1
11928ret 1
11929end
11930if eq and umsg id sequal uns x_browser2 0 0 255 1
11931ret 1
11932end
11933if eq and umsg id sequal uns x_browser3 0 0 255 1
11934ret 1
11935end
11936if eq and umsg id sequal uns x_browser4 0 0 255 1
11937ret 1
11938end
11939if eq and umsg id sequal uns x_browser5 0 0 255 1
11940ret 1
11941end
11942if eq and umsg id sequal uns x_browser6 0 0 255 1
11943ret 1
11944end
11945if eq and umsg id sequal uns x_browser7 0 0 255 1
11946ret 1
11947end
11948if eq and umsg id sequal uns x_browser8 0 0 255 1
11949ret 1
11950end
11951ret 0
11952end
11953
11954note the Ask row's text into g_nm from byte p: "Ask NAME: TEXT", or why it cannot ask; the byte after it
11955fn uaskrow p ulong to ulong
11956if eq get g_m 3 0
11957ret uptxt p x_ask_none
11958end
11959name_bytes = umsg get g_m 2 get g_o 5 0 0 0
11960q = uptxt p x_ask
11961upr 0 name_bytes
11962n = ucall 7
11963if gt n 200
11964n = 200
11965end
11966upr 0 ulong libptr g_nm q n
11967upr 8 name_bytes
11968upr 16 n
11969x = ucall 8
11970q = add q n
11971q = uptxt q x_colon
11972a = get g_n 12
11973n = get g_n 13
11974for i ulong n bound 256
11975put g_nm add q i get g_q add a i
11976end
11977ret add q n
11978end
11979
11980note the text of row r into g_nm from byte p (an app's name, the address, a file's whole path, or the Ask row); the byte after it
11981fn uprow p ulong r ulong to ulong
11982if eq ulong get g_rk r 8
11983ret uaskrow p
11984end
11985if eq ulong get g_rk r 10
11986ret uremoterow p get g_hit r
11987end
11988if eq ulong get g_rk r 9
11989q = uptxt p x_agent_row
11990a = get g_n 12
11991n = get g_n 13
11992for i ulong n bound 256
11993put g_nm add q i get g_q add a i
11994end
11995ret add q n
11996end
11997if eq ulong get g_rk r 6
11998ret uclipname p get g_hit r
11999end
12000if eq ulong get g_rk r 5
12001ret ustrat get g_m 18 p get g_hit r
12002end
12003if eq ulong get g_rk r 3
12004if eq get g_hit r 0
12005ret uptxt p x_screen0
12006end
12007if eq get g_hit r 2
12008ret uptxt p x_screen2
12009end
12010ret uptxt p x_screen1
12011end
12012if eq ulong get g_rk r 4
12013if eq get g_hit r 0
12014ret uptxt p x_command0
12015end
12016if eq get g_hit r 2
12017ret uptxt p x_command2
12018end
12019if eq get g_hit r 3
12020ret uptxt p x_command3
12021end
12022ret uptxt p x_command1
12023end
12024if and eq ulong get g_rk r 2 eq get g_n 13 0
12025uclipaddr 1
12026q = upaddr p
12027uclipaddr 0
12028ret q
12029end
12030if eq ulong get g_rk r 2
12031ret upaddr p
12032end
12033if eq ulong get g_rk r 7
12034ret ufilepath p get g_hit r
12035end
12036ret upname p get g_hit r
12037end
12038
12039note one turn of the event loop: wait for an event until date d and hand it to AppKit
12040fn utick app ulong sn ulong se ulong mode ulong d ulong to void
12041upr 0 app
12042upr 8 sn
12043upr 16 18446744073709551615
12044upr 24 d
12045upr 32 mode
12046upr 40 1
12047ev = ucall 2
12048if ne ev 0
12049x = umsg app se ev 0 0
12050end
12051end
12052
12053note put the panel away. A program that stays also empties the field, shows every app again and hides itself, so
12054note the app that was in front before has the keyboard back
12055fn uhide to void
12056uaskstop
12057put g_n 36 0
12058x = umsg get g_o 19 get g_o 20 0 0 0
12059if eq get g_n 14 1
12060put g_nm 0 0
12061x = umsg get g_o 0 get g_o 8 unsb 0 0
12062utyped
12063x = umsg get g_o 21 get g_o 22 0 0 0
12064end
12065end
12066
12067note bring the panel back: in front with the keyboard in the field for a program that stays, else just visible
12068fn ushow to void
12069if eq get g_n 14 1
12070ufront
12071uloadclips
12072uloadvault
12073if eq get g_m 3 0
12074uloadconfig
12075end
12076if eq get g_n 13 0
12077unarrow
12078x = umsg get g_o 1 get g_o 7 0 0 0
12079put g_n 6 0
12080if gt get g_n 1 0
12081uchoose 0
12082end
12083ushowst
12084end
12085x = umsg get g_o 21 get g_o 23 1 0 0
12086x = umsg get g_o 19 get g_o 24 0 0 0
12087x = umsg get g_o 19 get g_o 25 get g_o 0 0 0
12088else
12089x = umsg get g_o 19 get g_o 26 0 0 0
12090end
12091end
12092
12093note the library function at address f on the register file; x0 as it came back
12094fn ucallf f ulong to ulong
12095lr = libcall f g_rg 0 128
12096ret ugr 0
12097end
12098
12099note a global key: a Carbon hot key (key code, modifiers) whose handler is callback entry 5. 0 when both the
12100note handler and the key were taken; the hot key's id is 'HOPO' 1
12101fn ukey code ulong mods ulong to ulong
12102n = ucs s_carbon
12103upr 0 ulong libptr g_nm 0 1024
12104upr 8 2
12105lr = libcall ulong libfn 0 g_rg 0 128
12106target_fn = usym s_event_target
12107install_fn = usym s_install_handler
12108register_fn = usym s_register_key
12109if or or eq target_fn 0 eq install_fn 0 eq register_fn 0
12110ret 1
12111end
12112target = ucallf target_fn
12113put g_ev 0 98
12114put g_ev 1 121
12115put g_ev 2 101
12116put g_ev 3 107
12117put g_ev 4 5
12118upr 0 target
12119upr 8 ulong libfn 7
12120upr 16 1
12121upr 24 ulong libptr g_ev 0 16
12122upr 32 0
12123upr 40 0
12124installed = and ucallf install_fn 4294967295
12125upr 0 code
12126upr 8 mods
12127upr 16 5507124751
12128upr 24 target
12129upr 32 0
12130upr 40 ulong libptr g_ev 8 8
12131registered = and ucallf register_fn 4294967295
12132ret or installed registered
12133end
12134
12135note one menu item: title, action (a selector) and key. An unsized text takes two of a function's six places
12136fn uitem menu ulong title view uchar * action_sel ulong key view uchar * to void
12137c = ucl c_menu_item
12138s = usl m_alloc
12139item = umsg c s 0 0 0
12140title_string = uns title
12141key_string = uns key
12142s = usl m_init_item
12143item = umsg item s title_string action_sel key_string
12144s = usl m_add_item
12145x = umsg menu s item 0 0
12146end
12147
12148note a menu bar entry with an empty menu under it; the menu
12149fn usubmenu bar ulong title view uchar * to ulong
12150c = ucl c_menu_item
12151s = usl m_alloc
12152sinit = usl m_init
12153entry = umsg c s 0 0 0
12154entry = umsg entry sinit 0 0 0
12155s = usl m_add_item
12156x = umsg bar s entry 0 0
12157c = ucl c_menu
12158s = usl m_alloc
12159menu = umsg c s 0 0 0
12160title_string = uns title
12161s = usl m_init_title
12162menu = umsg menu s title_string 0 0
12163s = usl m_set_submenu
12164x = umsg entry s menu 0 0
12165ret menu
12166end
12167
12168note the menu: Quit, and Edit with the four commands the field's editor answers itself
12169fn umenu app ulong to void
12170c = ucl c_menu
12171s = usl m_alloc
12172sinit = usl m_init
12173bar = umsg c s 0 0 0
12174bar = umsg bar sinit 0 0 0
12175app_menu = usubmenu bar x_app
12176a = usl m_terminate
12177uitem app_menu x_quit a x_key_q
12178edit_menu = usubmenu bar x_edit
12179a = usl m_cut
12180uitem edit_menu x_cut a x_key_x
12181a = usl m_copy
12182uitem edit_menu x_copy a x_key_c
12183a = usl m_paste
12184uitem edit_menu x_paste a x_key_v
12185a = usl m_select_all
12186uitem edit_menu x_select_all a x_key_a
12187clip_menu = usubmenu bar x_clip_menu
12188a = usl m_pin_clip
12189uitem clip_menu x_pin_item a x_key_p
12190a = usl m_delete_clip
12191uitem clip_menu x_delete_item a x_key_d
12192agent_menu = usubmenu bar x_agent_menu
12193a = usl m_agent_stop
12194uitem agent_menu x_stop_item a x_key_period
12195s = usl m_set_menu
12196x = umsg app s bar 0 0
12197ustatus
12198end
12199
12200note the methods of OmegaHopPanel. 0 controlTextDidChange: 1 numberOfRowsInTableView:
12201note 2 tableView:objectValueForTableColumn:row: (e is the row) 3 go: (the field's action, Enter: c is the sender;
12202note it is remembered, and opened when g_n 7 allows) 4 control:textView:doCommandBySelector: (e is
12203note the command: the arrows move the selection, Escape puts the panel away; 1 says the key was handled)
12204note 5 the hot key's handler (a C function for Carbon: 0 says no error) 6 applicationShouldHandleReopen:
12205note hasVisibleWindows: (a click on the Dock icon, or the app opened again) 7 URLSession:dataTask:didReceiveData:
12206note (e is the data) 8 URLSession:task:didCompleteWithError: (d the task, e the problem or nothing)
12207note 9 pasteNow: (a moment after a copied thing was chosen) 10 clipTick: (twice a second, to see what was copied)
12208note 11 pinClip: 12 deleteClip: (the Clipboard menu, on the selected copied thing) 13 agentOut: agentErr:
12209note agentEnd: stopAgent: (what the agent's program tells, and the Agent menu; b is the selector, c what came)
12210fn libback k ulong a ulong b ulong c ulong d ulong e ulong to ulong
12211if eq k 0
12212utyped
12213ret 0
12214end
12215if eq k 1
12216ret get g_n 1
12217end
12218if eq k 2
12219if ge e get g_n 1
12220ret 0
12221end
12222p = ulong 0
12223if eq ulong get g_rk e 7
12224p = ufilerow 0 get g_hit e
12225else
12226if eq ulong get g_rk e 2
12227p = uptxt 0 x_open
12228end
12229if eq ulong get g_rk e 6
12230p = uptxt 0 x_paste_row
12231end
12232p = uprow p e
12233if or or eq ulong get g_rk e 1 eq ulong get g_rk e 6 eq ulong get g_rk e 2
12234p = uwhy p e
12235end
12236if eq ulong get g_rk e 5
12237q = uptxt p x_gap
12238q2 = ustrat get g_m 19 q get g_hit e
12239if gt q2 q
12240p = q2
12241end
12242end
12243if and eq ulong get g_rk e 6 or ne get g_n 13 0 ne get g_n 36 0
12244if eq ulong get g_cp get g_hit e 1
12245p = uptxt p x_gap
12246p = uptxt p x_pinned
12247end
12248end
12249if eq ulong get g_rk e 3
12250p = uptxt p x_gap
12251if eq get g_hit e 0
12252p = uptxt p x_screen0_about
12253end
12254if eq get g_hit e 1
12255p = uptxt p x_screen1_about
12256end
12257if eq get g_hit e 2
12258p = uptxt p x_screen2_about
12259end
12260end
12261if and eq ulong get g_rk e 4 eq get g_hit e 0
12262p = uptxt p x_gap
12263p = uptxt p x_command0_about
12264end
12265end
12266put g_nm p 0
12267ret unsb
12268end
12269if eq k 3
12270put g_n 3 add get g_n 3 1
12271if and ne c 0 lt get g_n 6 get g_n 1
12272put g_n 8 add get g_n 6 1
12273if and eq ulong get g_rk get g_n 6 3 eq get g_hit get g_n 6 2
12274if ne get g_m 4 0
12275uanswershow
12276uanswerview 1
12277end
12278ret 0
12279end
12280if eq ulong get g_rk get g_n 6 3
12281uscreen add get g_hit get g_n 6 1
12282ret 0
12283end
12284if and eq ulong get g_rk get g_n 6 4 eq get g_hit get g_n 6 3
12285uchatnew
12286uscreen get g_n 36
12287ret 0
12288end
12289if eq get g_n 46 1
12290uagentrun
12291ret 0
12292end
12293if eq get g_n 7 1
12294rk = ulong get g_rk get g_n 6
12295if or eq rk 8 eq rk 9
12296if eq rk 8
12297uask
12298else
12299uagentrun
12300end
12301else
12302if eq rk 2
12303if eq get g_n 13 0
12304uclipaddr 1
12305uopenaddr
12306uclipaddr 0
12307else
12308uopenaddr
12309end
12310end
12311if eq rk 4
12312if eq get g_hit get g_n 6 0
12313usettings
12314end
12315if eq get g_hit get g_n 6 2
12316uindexstart
12317end
12318if eq get g_hit get g_n 6 1
12319if eq get g_n 14 1
12320x = umsg umsg ucl c_app usl m_shared 0 0 0 usl m_terminate 0 0 0
12321end
12322end
12323end
12324if eq rk 6
12325put g_n 29 0
12326upasteclip get g_hit get g_n 6
12327if eq get g_n 14 1
12328uclipmine get g_n 29
12329end
12330end
12331if eq rk 5
12332ucopysecret get g_hit get g_n 6
12333if eq get g_n 14 1
12334uclipmine 0
12335end
12336end
12337if eq rk 10
12338uremoteopen get g_hit get g_n 6
12339end
12340if eq rk 7
12341uopenfile get g_hit get g_n 6
12342urecordfile get g_hit get g_n 6
12343end
12344if eq rk 1
12345ulaunch get g_hit get g_n 6
12346urecordapp get g_hit get g_n 6
12347end
12348put g_n 5 1
12349if eq get g_n 14 1
12350uhide
12351if eq rk 6
12352ulaterpaste
12353end
12354end
12355end
12356end
12357if and eq get g_n 7 0 eq get g_n 23 1
12358rk = ulong get g_rk get g_n 6
12359if eq rk 6
12360upasteclip get g_hit get g_n 6
12361end
12362if eq rk 5
12363ucopysecret get g_hit get g_n 6
12364end
12365if eq rk 10
12366uremoteopen get g_hit get g_n 6
12367end
12368if eq rk 7
12369urecordfile get g_hit get g_n 6
12370end
12371if eq rk 1
12372urecordapp get g_hit get g_n 6
12373end
12374end
12375end
12376end
12377if eq k 4
12378if eq e get g_o 9
12379if lt add get g_n 6 1 get g_n 1
12380uchoose add get g_n 6 1
12381end
12382ret 1
12383end
12384if eq e get g_o 10
12385if gt get g_n 6 0
12386uchoose sub get g_n 6 1
12387end
12388ret 1
12389end
12390if eq e get g_o 11
12391if ne get g_n 36 0
12392uscreen 0
12393ret 1
12394end
12395put g_n 5 1
12396uhide
12397ret 1
12398end
12399end
12400if eq k 5
12401ushow
12402ret 0
12403end
12404if eq k 7
12405unetdata e
12406ret 0
12407end
12408if eq k 8
12409unetdone d e
12410ret 0
12411end
12412if eq k 9
12413usendpaste
12414ret 0
12415end
12416if eq k 10
12417ucliptick
12418ret 0
12419end
12420if eq k 11
12421uclipmenu 1
12422ret 0
12423end
12424if eq k 12
12425uclipmenu 2
12426ret 0
12427end
12428if eq k 13
12429uagentevent b c
12430ret 0
12431end
12432if eq k 6
12433ushow
12434ret 1
12435end
12436ret 0
12437end
12438
12439note one method of the class: selector text, callback entry, type text
12440fn umethod c ulong t view uchar * entry ulong ty view uchar * to bool
12441s = usl t
12442n = ucs ty
12443upr 0 c
12444upr 8 s
12445upr 16 ulong libfn int add 2 entry
12446upr 24 ulong libptr g_nm 0 1024
12447ret eq and ucall 5 255 1
12448end
12449
12450fn main to int
12451n = ucs s_appkit
12452upr 0 ulong libptr g_nm 0 1024
12453upr 8 2
12454lr = libcall ulong libfn 0 g_rg 0 128
12455if eq ugr 0 0
12456ret 2
12457end
12458put g_f 0 usym s_gc
12459put g_f 1 usym s_sr
12460put g_f 2 usym s_ms
12461put g_f 3 usym s_wr
12462put g_f 4 usym s_acp
12463put g_f 5 usym s_cam
12464put g_f 6 usym s_rcp
12465put g_f 7 usym s_strlen
12466put g_f 8 usym s_memcpy
12467put g_f 9 usym s_getenv
12468put g_f 10 usym s_malloc
12469put g_f 11 usym s_memmem
12470put g_f 12 usym s_memchr
12471put g_f 13 usym s_memrchr
12472put g_f 14 usym s_pow
12473put g_f 15 usym s_log2
12474put g_f 16 usym s_chmod
12475put g_f 17 usym s_memset
12476put g_f 18 usym s_trusted
12477put g_f 19 usym s_key_event
12478put g_f 20 usym s_event_flags
12479put g_f 21 usym s_event_post
12480put g_f 22 usym s_cf_release
12481put g_f 23 usym s_item_copy
12482put g_f 24 usym s_item_add
12483put g_f 25 usym s_item_delete
12484put g_f 26 usym s_interaction
12485put g_f 27 usym s_random
12486put g_f 28 usym s_free
12487put g_f 29 usym s_iopolicy
12488put g_f 30 usym s_home_directory
12489for i ulong 31
12490if eq get g_f i 0
12491ret 3
12492end
12493end
12494put g_o 3 ucl c_str
12495put g_o 4 usl m_utf
12496put g_o 5 usl m_cstr
12497put g_m 16 usl m_at
12498put g_m 7 ucl c_dict
12499put g_m 8 ucl c_array
12500put g_m 9 ucl c_str
12501x = uindexmode
12502if eq x 0
12503ret 0
12504end
12505if eq x 1
12506ret 1
12507end
12508put g_o 6 usl m_strval
12509put g_o 7 usl m_reload
12510put g_o 8 usl m_setstr
12511put g_o 9 usl m_down
12512put g_o 10 usl m_up
12513put g_o 11 usl m_cancel
12514put g_o 12 usl m_selrow
12515put g_o 13 ucl c_ixset
12516put g_o 14 usl m_ixwith
12517put g_o 15 usl m_scrrow
12518put g_o 16 ucl c_url
12519put g_o 17 usl m_urlstr
12520put g_o 18 usl m_host
12521c = ucl c_pool
12522s = usl m_alloc
12523pool = umsg c s 0 0 0
12524sinit = usl m_init
12525pool = umsg pool sinit 0 0 0
12526ufolder x_dir1 0
12527ufolder x_dir2 1
12528ubuildmap
12529n = ucs x_env_front
12530upr 0 ulong libptr g_nm 0 1024
12531front_text = ucall 9
12532if ne front_text 0
12533n = ufetch front_text
12534put g_m 11 umsg unsb usl m_retain 0 0 0
12535end
12536n = ucs x_env
12537upr 0 ulong libptr g_nm 0 1024
12538if eq ucall 9 0
12539put g_n 14 1
12540else
12541put g_n 14 0
12542upr 0 0
12543x = ucall 26
12544rn = ucs x_env_screen
12545upr 0 ulong libptr g_nm 0 1024
12546screen_text = ucall 9
12547if ne screen_text 0
12548rn = ufetch screen_text
12549if eq get g_nm 0 99
12550put g_n 36 1
12551end
12552if eq get g_nm 0 97
12553put g_n 36 2
12554end
12555end
12556rn = ucs x_env_clipdo
12557upr 0 ulong libptr g_nm 0 1024
12558do_text = ucall 9
12559if ne do_text 0
12560rn = ufetch do_text
12561if eq get g_nm 0 112
12562put g_n 37 1
12563end
12564if eq get g_nm 0 100
12565put g_n 37 2
12566end
12567if eq get g_nm 0 99
12568put g_n 37 3
12569end
12570end
12571end
12572uloadindex
12573uloadvault
12574uloadconfig
12575if eq get g_n 14 0
12576rn = ucs x_env_cliprec
12577upr 0 ulong libptr g_nm 0 1024
12578if ne ucall 9 0
12579ucliprecord umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0
12580end
12581end
12582uloadclips
12583put g_n 4 0
12584put g_n 13 0
12585unarrow
12586if eq get g_n 0 0
12587ret 4
12588end
12589c = ucl c_app
12590s = usl m_shared
12591app = umsg c s 0 0 0
12592n = ucs x_env
12593upr 0 ulong libptr g_nm 0 1024
12594envp = ucall 9
12595chk = ne envp 0
12596opn = false
12597ovr = false
12598asking = false
12599idle = false
12600tl = ulong 0
12601pol = ulong 0
12602put g_n 7 1
12603if chk
12604pol = 1
12605put g_n 7 0
12606n = ufetch envp
12607skip = ulong 0
12608if and ge n 5 and or eq get g_nm 0 111 eq get g_nm 0 116 eq get g_nm 4 58
12609skip = 5
12610end
12611if and ge n 4 and eq get g_nm 0 97 eq get g_nm 3 58
12612skip = 4
12613asking = true
12614put g_n 7 1
12615end
12616if and eq n 4 and eq get g_nm 0 105 eq get g_nm 3 101
12617skip = 4
12618idle = true
12619end
12620if and ge n 6 and eq get g_nm 0 97 eq get g_nm 5 58
12621skip = 6
12622asking = true
12623put g_n 46 1
12624end
12625if gt skip 0
12626ovr = true
12627if eq get g_nm 0 111
12628opn = true
12629put g_n 7 1
12630end
12631tl = sub n skip
12632if gt tl 60
12633tl = 60
12634end
12635for i ulong tl bound 64
12636put g_t i get g_nm add skip i
12637end
12638end
12639rn = ucs x_env_record
12640upr 0 ulong libptr g_nm 0 1024
12641if ne ucall 9 0
12642put g_n 23 1
12643end
12644rn = ucs x_env_row
12645upr 0 ulong libptr g_nm 0 1024
12646row_text = ucall 9
12647if ne row_text 0
12648rn = ufetch row_text
12649row_pick = ulong 0
12650for i ulong rn bound 4
12651row_digit = ulong get g_nm i
12652if and ge row_digit 48 le row_digit 57
12653row_pick = add mul row_pick 10 sub row_digit 48
12654end
12655end
12656put g_n 30 row_pick
12657end
12658end
12659s = usl m_policy
12660x = umsg app s pol 0 0
12661note the class whose methods are the callback entries
12662c = ucl c_obj
12663n = ucs c_mine
12664upr 0 c
12665upr 8 ulong libptr g_nm 0 1024
12666upr 16 0
12667mine = ucall 4
12668if eq mine 0
12669ret 5
12670end
12671ok = umethod mine m_change 0 t_v
12672ok = and ok umethod mine m_rows 1 t_q
12673ok = and ok umethod mine m_value 2 t_o
12674ok = and ok umethod mine m_go 3 t_v
12675ok = and ok umethod mine m_cmd 4 t_b
12676ok = and ok umethod mine m_reopen 6 t_reopen
12677ok = and ok umethod mine m_did_data 7 t_session
12678ok = and ok umethod mine m_did_complete 8 t_session
12679ok = and ok umethod mine m_paste_now 9 t_v
12680ok = and ok umethod mine m_clip_tick 10 t_v
12681ok = and ok umethod mine m_pin_clip 11 t_v
12682ok = and ok umethod mine m_delete_clip 12 t_v
12683ok = and ok umethod mine m_agent_out 13 t_v
12684ok = and ok umethod mine m_agent_err 13 t_v
12685ok = and ok umethod mine m_agent_end 13 t_v
12686ok = and ok umethod mine m_agent_stop 13 t_v
12687put g_m 38 usl m_agent_out
12688put g_m 39 usl m_agent_err
12689put g_m 40 usl m_agent_end
12690put g_m 41 usl m_agent_stop
12691ok = and ok umoremethods mine
12692ok = and ok ustatusmethods mine
12693ok = and ok uquitwatch mine
12694uchecklate
12695if not ok
12696ret 6
12697end
12698upr 0 mine
12699x = ucall 6
12700s = usl m_alloc
12701me = umsg mine s 0 0 0
12702me = umsg me sinit 0 0 0
12703put g_o 27 me
12704note the window
12705c = ucl c_win
12706s = usl m_alloc
12707w = umsg c s 0 0 0
12708s = usl m_initwi
12709urect 240.0f64 260.0f64 520.0f64 360.0f64
12710w = umsg w s 3 2 0
12711if eq w 0
12712ret 7
12713end
12714str = uns x_title
12715s = usl m_title
12716x = umsg w s str 0 0
12717s = usl m_conten
12718cv = umsg w s 0 0 0
12719sadd = usl m_addsub
12720sframe = usl m_initfr
12721note the search field
12722c = ucl c_field
12723s = usl m_alloc
12724fld = umsg c s 0 0 0
12725urect 16.0f64 316.0f64 488.0f64 28.0f64
12726fld = umsg fld sframe 0 0 0
12727str = uns x_hint
12728s = usl m_placeh
12729x = umsg fld s str 0 0
12730s = usl m_setdel
12731x = umsg fld s me 0 0
12732s = usl m_settar
12733x = umsg fld s me 0 0
12734s = usl m_setact
12735sgo = usl m_go
12736x = umsg fld s sgo 0 0
12737x = umsg cv sadd fld 0 0
12738put g_o 0 fld
12739note the status line
12740str = uns x_hint
12741c = ucl c_field
12742s = usl m_label
12743lbl = umsg c s str 0 0
12744s = usl m_setfra
12745urect 16.0f64 8.0f64 488.0f64 20.0f64
12746x = umsg lbl s 0 0 0
12747x = umsg cv sadd lbl 0 0
12748put g_o 2 lbl
12749note the list
12750c = ucl c_scroll
12751s = usl m_alloc
12752sv = umsg c s 0 0 0
12753urect 16.0f64 36.0f64 488.0f64 272.0f64
12754sv = umsg sv sframe 0 0 0
12755c = ucl c_table
12756s = usl m_alloc
12757tv = umsg c s 0 0 0
12758urect 0.0f64 0.0f64 470.0f64 272.0f64
12759tv = umsg tv sframe 0 0 0
12760c = ucl c_col
12761s = usl m_alloc
12762col = umsg c s 0 0 0
12763str = uns x_name
12764s = usl m_initid
12765col = umsg col s str 0 0
12766s = usl m_setwid
12767upr 64 bitcast ulong 460.0f64
12768x = umsg col s 0 0 0
12769s = usl m_addcol
12770x = umsg tv s col 0 0
12771s = usl m_header
12772x = umsg tv s 0 0 0
12773s = usl m_dataso
12774x = umsg tv s me 0 0
12775s = usl m_docvie
12776x = umsg sv s tv 0 0
12777s = usl m_scroll
12778x = umsg sv s 1 0 0
12779x = umsg cv sadd sv 0 0
12780put g_o 1 tv
12781put g_o 28 sv
12782note the answer: a text view in the list's place, hidden until a question is asked
12783c = ucl c_scroll
12784s = usl m_alloc
12785answer_scroll = umsg c s 0 0 0
12786urect 16.0f64 36.0f64 488.0f64 272.0f64
12787answer_scroll = umsg answer_scroll sframe 0 0 0
12788c = ucl c_text_view
12789s = usl m_alloc
12790answer_text = umsg c s 0 0 0
12791urect 0.0f64 0.0f64 470.0f64 272.0f64
12792answer_text = umsg answer_text sframe 0 0 0
12793x = umsg answer_text usl m_set_editable 0 0 0
12794x = umsg answer_scroll usl m_docvie answer_text 0 0
12795x = umsg answer_scroll usl m_scroll 1 0 0
12796x = umsg answer_scroll usl m_set_hidden 1 0 0
12797x = umsg cv sadd answer_scroll 0 0
12798put g_o 29 answer_scroll
12799put g_o 30 answer_text
12800ushowst
12801s = usl m_finish
12802x = umsg app s 0 0 0
12803put g_o 19 w
12804put g_o 20 usl m_order_out
12805put g_o 21 app
12806put g_o 22 usl m_hide_app
12807put g_o 23 usl m_activ
12808put g_o 24 usl m_key
12809put g_o 25 usl m_firstr
12810put g_o 26 usl m_front
12811s = usl m_released
12812x = umsg w s 0 0 0
12813s = usl m_set_app_delegate
12814x = umsg app s me 0 0
12815if chk
12816put g_n 14 0
12817put g_n 15 ukey 80 6912
12818else
12819put g_n 14 1
12820put g_n 15 ukey 49 2048
12821umenu app
12822note keep the history of what is copied while Hop is not running: look twice a second
12823first_board = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
12824put g_n 35 umsg first_board usl m_change_count 0 0 0
12825c_t = ucl c_timer
12826s_timer = usl m_timer
12827s_tick = usl m_clip_tick
12828upr 64 bitcast ulong 0.5f64
12829upr 40 1
12830x = umsg c_t s_timer get g_o 27 s_tick 0
12831if and not uhoprunning uindexstale
12832uindexstart
12833end
12834if not uhoprunning
12835uremoterefreshall
12836end
12837end
12838ushow
12839if gt get g_n 1 0
12840uchoose 0
12841end
12842svis = usl m_visibl
12843vis = and umsg w svis 0 0 0 255
12844mode = uns x_mode
12845cd = ucl c_date
12846sd = usl m_since
12847sn = usl m_next
12848se = usl m_send
12849schanged = usl m_change
12850total = get g_n 0
12851if not chk
12852note a person uses it: AppKit's own event loop, until the app is quit
12853s = usl m_run
12854x = umsg app s 0 0 0
12855ret 0
12856end
12857note the check: about six seconds. The text goes in through the field's editor; arrow down, Enter and Escape are
12858note commands sent to that editor, which asks the field, which asks its delegate and sends its action
12859sfr = usl m_firstr
12860sed = usl m_curred
12861sins = usl m_instxt
12862sdo = usl m_docmd
12863snl = usl m_newln
12864esc = ulong 0
12865hid = ulong 0
12866back = ulong 0
12867for i ulong 120
12868upr 64 bitcast ulong 0.05f64
12869d = umsg cd sd 0 0 0
12870utick app sn se mode d
12871if eq i 10
12872x = umsg w sfr fld 0 0
12873ed = umsg fld sed 0 0 0
12874if ovr
12875for j ulong tl bound 64
12876put g_nm j get g_t j
12877end
12878put g_nm tl 0
12879str = unsb
12880else
12881str = uns x_typed
12882end
12883if not idle
12884x = umsg ed sins str 0 0
12885end
12886end
12887if and eq i 15 not ovr
12888ed = umsg fld sed 0 0 0
12889x = umsg ed sdo get g_o 9 0 0
12890end
12891if and and eq i 15 ovr and gt get g_n 30 0 lt get g_n 30 get g_n 1
12892uchoose get g_n 30
12893end
12894if and and eq i 16 ovr ne get g_n 37 0
12895if eq get g_n 37 3
12896uclipclear
12897else
12898uclipmenu get g_n 37
12899end
12900end
12901if eq i 2
12902ustatus
12903utunnelcheck
12904end
12905if eq i get g_n 48
12906ed = umsg fld sed 0 0 0
12907x = umsg ed sdo snl 0 0
12908end
12909if eq i 60
12910uasksecond
12911end
12912if and and eq i 25 not asking eq get g_n 36 0
12913put g_n 5 0
12914x = umsg w sfr fld 0 0
12915ed = umsg fld sed 0 0 0
12916x = umsg ed sdo get g_o 11 0 0
12917esc = get g_n 5
12918put g_n 5 0
12919if eq and umsg w svis 0 0 0 255 0
12920hid = 1
12921end
12922end
12923if eq i 30
12924upr 0 0
12925upr 8 0
12926upr 16 0
12927x = ucallf ulong libfn 7
12928if eq and umsg w svis 0 0 0 255 1
12929back = 1
12930end
12931end
12932end
12933note the first row, asked of the list's own data source through Objective-C, and the list's own selection
12934shown = get g_n 1
12935row = umsg tv usl m_selrd 0 0 0
12936want = ulong 0
12937if and gt shown 1 not ovr
12938want = 1
12939end
12940first = umsg me usl m_value tv col 0
12941flen = ulong 0
12942if ne first 0
12943p = umsg first get g_o 5 0 0 0
12944flen = ufetch p
12945end
12946if gt flen 255
12947flen = 255
12948end
12949for i ulong flen bound 256
12950put g_x i get g_nm i
12951end
12952uvaultcheckend
12953utunnelstop
12954paste_text = ulong 0
12955paste_size = ulong 0
12956if ne get g_n 29 0
12957pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0
12958if eq get g_n 29 1
12959got = umsg pboard usl m_string_for_type uns x_type_string 0 0
12960if ne got 0
12961paste_text = umsg got get g_o 5 0 0 0
12962end
12963else
12964got = umsg pboard usl m_data_for_type uns x_type_png 0 0
12965if ne got 0
12966paste_size = umsg got usl m_length 0 0 0
12967end
12968end
12969x = umsg pboard usl m_clear 0 0 0
12970end
12971p = uptxt 0 x_out1
12972p = upnum p total
12973p = uptxt p x_out2
12974p = upnum p shown
12975p = uptxt p x_out3
12976for i ulong flen bound 256
12977put g_nm add p i get g_x i
12978end
12979p = add p flen
12980p = uptxt p x_out4
12981p = upnum p and row 255
12982p = uptxt p x_out5
12983if and gt get g_n 8 0 le get g_n 8 shown
12984p = uprow p sub get g_n 8 1
12985end
12986if opn
12987p = uptxt p x_out6
12988p = upnum p get g_n 9
12989end
12990if ne get g_n 29 0
12991p = uptxt p x_out11
12992if ne paste_text 0
12993upr 0 paste_text
12994pn = ucall 7
12995if gt pn 80
12996pn = 80
12997end
12998if gt pn 0
12999upr 0 ulong libptr g_nm p pn
13000upr 8 paste_text
13001upr 16 pn
13002x = ucall 8
13003for j ulong pn bound 81
13004if lt ulong get g_nm add p j 32
13005put g_nm add p j 32
13006end
13007end
13008p = add p pn
13009end
13010end
13011if eq get g_n 29 2
13012p = uptxt p x_png_word
13013p = upnum p paste_size
13014end
13015end
13016if ne get g_n 36 0
13017p = uptxt p x_out12
13018p = upnum p get g_n 36
13019end
13020if eq get g_n 55 1
13021p = uptxt p x_out13
13022p = upnum p 1
13023end
13024if gt get g_n 62 0
13025p = uptxt p x_out16
13026p = upnum p get g_n 61
13027end
13028if ne get g_n 51 0
13029p = uptxt p x_out14
13030p = upnum p get g_n 52
13031p = uptxt p x_out15
13032p = upnum p get g_n 51
13033end
13034answered = false
13035if asking
13036p = uptxt p x_out10
13037if ne get g_m 4 0
13038answer_bytes = umsg get g_m 4 get g_o 5 0 0 0
13039upr 0 answer_bytes
13040an = ucall 7
13041if gt an 120
13042an = 120
13043end
13044upr 0 ulong libptr g_nm p an
13045upr 8 answer_bytes
13046upr 16 an
13047x = ucall 8
13048for j ulong an bound 121
13049if lt ulong get g_nm add p j 32
13050put g_nm add p j 32
13051end
13052end
13053p = add p an
13054answered = and and gt an 0 eq get g_n 21 1 eq get g_n 22 1
13055end
13056end
13057if not ovr
13058p = uptxt p x_out7
13059p = upnum p get g_n 15
13060p = uptxt p x_out8
13061p = upnum p hid
13062p = uptxt p x_out9
13063p = upnum p back
13064end
13065put g_nm p 10
13066upr 0 1
13067upr 8 ulong libptr g_nm 0 1024
13068upr 16 add p 1
13069x = ucall 3
13070s = usl m_close
13071x = umsg w s 0 0 0
13072if ne vis 1
13073ret 8
13074end
13075if ovr
13076took = true
13077if opn
13078took = eq get g_n 9 1
13079end
13080if asking
13081took = answered
13082end
13083if and and gt shown 0 eq get g_n 3 1 and gt get g_n 8 0 took
13084ret 1
13085end
13086ret 9
13087end
13088picked = and eq get g_n 8 add want 1 eq ulong get g_rk 0 1
13089if and and and gt shown 0 lt shown total and gt flen 0 and eq get g_n 3 1 picked and and eq esc 1 eq row want and and eq hid 1 eq back 1 eq get g_n 15 0
13090ret 1
13091end
13092ret 9
13093end