hop
Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.
Brought by drakestapleton
hop / Omega / tests / mutant / hoppanel-deaf.om
| 1 | target macos |
| 2 | om2 |
| 3 | note hoppanel: the first cut of Hop's launcher panel as one Omega program, with no Swift. A window with a search |
| 4 | note field and a list. Before anything is typed the list offers up to six apps by Hop's own rule (fn swsuggest): the |
| 5 | note ones you usually open from the app in front or around this hour (habits.json, through fn swlifts), the ones |
| 6 | note 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). |
| 7 | note The apps are the names in /Applications and /System/Applications. Typing narrows the |
| 8 | note list by Hop's own rules: the matcher (hopfuzz), the test for a web address (weba) and the order of the rows |
| 9 | note (swrank) are the functions of Omega/hopcore.om, which Omega/gen-ui.sh puts between the two marker notes, so |
| 10 | note the panel and the one box cannot drift apart. Typed text shows the eight best apps, a row that opens the text when |
| 11 | note it is a web address, and up to twelve files and folders from Hop's file index (file-index.bin in Hop's folder, |
| 12 | note which Hop builds: the panel reads it, lower-cases a copy and searches it by the rule of Hop's file search). |
| 13 | note The Ask row sends the typed text to a model and shows the answer as it arrives, in place of the list: the |
| 14 | note model is the default one of Hop's settings (config.json) when it is an HTTP one, else the |
| 15 | note first such; the request is Hop's (POST base/chat/completions, the model, one user message, stream true) and |
| 16 | note the answer's pieces are read from the server's "data:" lines. The session's delegate methods are Omega code |
| 17 | note (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 |
| 18 | note opens the selected row. Like Hop it then stays: Enter and Escape hide the panel and give the app before it the |
| 19 | note 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 |
| 20 | note back. It has a small menu (Quit, and Edit with cut, copy, paste, select all) and runs in AppKit's own event |
| 21 | note loop. The global key is a Carbon hot key whose handler is callback entry 5. |
| 22 | note The field's two delegate methods, the list's two data-source methods and the field's action are Omega code, reached |
| 23 | note through the callback entries (libback; omega-mv seed/ng/a64/DESIGN.md s14). |
| 24 | note With HOPCHECK set in the environment it checks itself instead: it stays in the background and, after half a |
| 25 | note second, puts "sa" into its field through the field's own editor (so AppKit, not the program, tells the |
| 26 | note delegate that the text changed), sends that editor arrow down, Enter and Escape as commands, prints |
| 27 | note "hoppanel apps N shown H first NAME selected R enter APP" and ends after six seconds. Enter reaches the field's |
| 28 | note action with the field as sender, as a real Enter does, but opens nothing. Status then: 1 when apps were found, |
| 29 | note the typed text narrowed them, the first one was read back from the list's own data source, the arrow moved the |
| 30 | note list's selection, Enter chose the selected app, Escape hid the panel, a hot key could be registered (a spare |
| 31 | note one: Control Option Shift Command F19) and its handler showed the panel again; 2 to 9 name a failed step. |
| 32 | note The line then ends " key K hid H back B" (K 0 when the key was registered). |
| 33 | note With HOPCHECK=type:TEXT it types TEXT instead and sends Enter (no arrow), still opening nothing: status 1 when |
| 34 | note Enter chose a row. With HOPCHECK=open:TEXT it does the same and does open the row: the line ends " opened 1" |
| 35 | note when the workspace took it, and the status is 1 then. With HOPCHECK=ask:TEXT it types TEXT, sends Enter on the |
| 36 | note Ask row (first for a question) and does ask the model: the line ends " answer TEXT" and the status is 1 when an |
| 37 | note answer came. With HOPCHECK=idle it types nothing and sends Enter on the first offer; HOPFRONT=ID then stands for |
| 38 | note the app in front. With HOPRECORD set as well, a check that opens nothing still remembers what Enter chose, |
| 39 | note and puts a chosen copied thing on a board of its own (the line then ends " pasted " and what is on it). |
| 40 | note A check reaches no other machine but through HOPSSH and HOPSCP, its stand-ins for ssh and scp (HOPSSH is |
| 41 | note also what a check starts in place of ssh for a forwarded port), and HOPLATE sends Enter late, when |
| 42 | note they have answered. With HOPCHECK=agent:TEXT a check sends TEXT to the agent of the settings and waits for it to end; with |
| 43 | note HOPAGENTS it first says each agent's command as it would be run. |
| 44 | note HOPASK2 is a second question a check asks in the same conversation once the first is answered; with |
| 45 | note HOPASKNEW it starts a new chat first. |
| 46 | note HOPSCREEN (clipboard or accounts) starts a check in that screen, and HOPCLIPDO (pin or delete) does that to |
| 47 | note 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 |
| 48 | note 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 |
| 49 | note 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. |
| 50 | note Without HOPCHECK it runs until it is quit. |
| 51 | text s_appkit "/System/Library/Frameworks/AppKit.framework/AppKit" |
| 52 | text s_gc "objc_getClass" |
| 53 | text s_sr "sel_registerName" |
| 54 | text s_ms "objc_msgSend" |
| 55 | text s_wr "write" |
| 56 | text s_acp "objc_allocateClassPair" |
| 57 | text s_cam "class_addMethod" |
| 58 | text s_rcp "objc_registerClassPair" |
| 59 | text s_strlen "strlen" |
| 60 | text s_memcpy "memcpy" |
| 61 | text s_getenv "getenv" |
| 62 | text c_pool "NSAutoreleasePool" |
| 63 | text c_app "NSApplication" |
| 64 | text c_win "NSWindow" |
| 65 | text c_str "NSString" |
| 66 | text c_field "NSTextField" |
| 67 | text c_scroll "NSScrollView" |
| 68 | text c_table "NSTableView" |
| 69 | text c_col "NSTableColumn" |
| 70 | text c_fm "NSFileManager" |
| 71 | text c_obj "NSObject" |
| 72 | text c_date "NSDate" |
| 73 | text c_mine "OmegaHopPanel" |
| 74 | text c_url "NSURL" |
| 75 | text c_ws "NSWorkspace" |
| 76 | text m_alloc "alloc" |
| 77 | text m_init "init" |
| 78 | text m_shared "sharedApplication" |
| 79 | text m_policy "setActivationPolicy:" |
| 80 | text m_initwi "initWithContentRect:styleMask:backing:defer:" |
| 81 | text m_utf "stringWithUTF8String:" |
| 82 | text m_cstr "UTF8String" |
| 83 | text m_title "setTitle:" |
| 84 | text m_conten "contentView" |
| 85 | text m_addsub "addSubview:" |
| 86 | text m_initfr "initWithFrame:" |
| 87 | text m_label "labelWithString:" |
| 88 | text m_setfra "setFrame:" |
| 89 | text m_placeh "setPlaceholderString:" |
| 90 | text m_setdel "setDelegate:" |
| 91 | text m_settar "setTarget:" |
| 92 | text m_setact "setAction:" |
| 93 | text m_initid "initWithIdentifier:" |
| 94 | text m_setwid "setWidth:" |
| 95 | text m_addcol "addTableColumn:" |
| 96 | text m_header "setHeaderView:" |
| 97 | text m_dataso "setDataSource:" |
| 98 | text m_docvie "setDocumentView:" |
| 99 | text m_scroll "setHasVerticalScroller:" |
| 100 | text m_reload "reloadData" |
| 101 | text m_strval "stringValue" |
| 102 | text m_setstr "setStringValue:" |
| 103 | text m_defaul "defaultManager" |
| 104 | text m_conte1 "contentsOfDirectoryAtPath:error:" |
| 105 | text m_count "count" |
| 106 | text m_at "objectAtIndex:" |
| 107 | text m_finish "finishLaunching" |
| 108 | text m_front "orderFrontRegardless" |
| 109 | text m_visibl "isVisible" |
| 110 | text m_close "close" |
| 111 | text m_since "dateWithTimeIntervalSinceNow:" |
| 112 | text m_next "nextEventMatchingMask:untilDate:inMode:dequeue:" |
| 113 | text m_send "sendEvent:" |
| 114 | text m_change "controlTextDidChange:" |
| 115 | text m_rows "numberOfRowsInTableView:" |
| 116 | text m_value "tableView:objectValueForTableColumn:row:" |
| 117 | text m_go "go:" |
| 118 | text m_furl "fileURLWithPath:" |
| 119 | text m_shws "sharedWorkspace" |
| 120 | text m_open "openURL:" |
| 121 | text m_activ "activateIgnoringOtherApps:" |
| 122 | text m_key "makeKeyAndOrderFront:" |
| 123 | text m_firstr "makeFirstResponder:" |
| 124 | text m_down "moveDown:" |
| 125 | text m_up "moveUp:" |
| 126 | text m_cancel "cancelOperation:" |
| 127 | text m_selrow "selectRowIndexes:byExtendingSelection:" |
| 128 | text m_ixwith "indexSetWithIndex:" |
| 129 | text m_scrrow "scrollRowToVisible:" |
| 130 | text m_cmd "control:textView:doCommandBySelector:" |
| 131 | text m_selrd "selectedRow" |
| 132 | text c_ixset "NSIndexSet" |
| 133 | text t_b "B@:@@:" |
| 134 | text m_curred "currentEditor" |
| 135 | text m_instxt "insertText:" |
| 136 | text m_docmd "doCommandBySelector:" |
| 137 | text m_newln "insertNewline:" |
| 138 | text t_v "v@:@" |
| 139 | text t_q "q@:@" |
| 140 | text t_o "@@:@@q" |
| 141 | text x_title "Hop (Omega)" |
| 142 | text x_hint "Type to find an app" |
| 143 | text x_dir1 "/Applications" |
| 144 | text x_dir2 "/System/Applications" |
| 145 | text x_mode "kCFRunLoopDefaultMode" |
| 146 | text x_name "name" |
| 147 | text x_typed "sa" |
| 148 | text x_out1 "hoppanel apps " |
| 149 | text x_out2 " shown " |
| 150 | text x_out3 " first " |
| 151 | text x_out4 " selected " |
| 152 | text x_out5 " enter " |
| 153 | text x_out6 " opened " |
| 154 | text x_https "https://" |
| 155 | text x_open "Open " |
| 156 | text m_urlstr "URLWithString:" |
| 157 | text m_host "host" |
| 158 | text s_carbon "/System/Library/Frameworks/Carbon.framework/Carbon" |
| 159 | text s_event_target "GetApplicationEventTarget" |
| 160 | text s_install_handler "InstallEventHandler" |
| 161 | text s_register_key "RegisterEventHotKey" |
| 162 | text m_order_out "orderOut:" |
| 163 | text m_hide_app "hide:" |
| 164 | text m_released "setReleasedWhenClosed:" |
| 165 | text m_set_app_delegate "setDelegate:" |
| 166 | text m_reopen "applicationShouldHandleReopen:hasVisibleWindows:" |
| 167 | text m_run "run" |
| 168 | text m_terminate "terminate:" |
| 169 | text m_set_menu "setMainMenu:" |
| 170 | text m_add_item "addItem:" |
| 171 | text m_set_submenu "setSubmenu:" |
| 172 | text m_init_title "initWithTitle:" |
| 173 | text m_init_item "initWithTitle:action:keyEquivalent:" |
| 174 | text m_cut "cut:" |
| 175 | text m_copy "copy:" |
| 176 | text m_paste "paste:" |
| 177 | text m_select_all "selectAll:" |
| 178 | text c_menu "NSMenu" |
| 179 | text c_menu_item "NSMenuItem" |
| 180 | text t_reopen "B@:@B" |
| 181 | text t_handler "i^v^v^v" |
| 182 | text x_quit "Quit Hop Omega" |
| 183 | text x_edit "Edit" |
| 184 | text x_cut "Cut" |
| 185 | text x_copy "Copy" |
| 186 | text x_paste "Paste" |
| 187 | text x_select_all "Select All" |
| 188 | text x_key_q "q" |
| 189 | text x_key_x "x" |
| 190 | text x_key_c "c" |
| 191 | text x_key_v "v" |
| 192 | text x_key_a "a" |
| 193 | text x_app "Hop Omega" |
| 194 | text x_out7 " key " |
| 195 | text x_out8 " hid " |
| 196 | text x_out9 " back " |
| 197 | text s_malloc "malloc" |
| 198 | text s_memmem "memmem" |
| 199 | text s_memchr "memchr" |
| 200 | text s_memrchr "memrchr" |
| 201 | text c_data "NSData" |
| 202 | text m_data_file "dataWithContentsOfFile:" |
| 203 | text m_retain "retain" |
| 204 | text m_bytes "bytes" |
| 205 | text m_length "length" |
| 206 | text x_env_dir "HOP_CONFIG_DIR" |
| 207 | text x_env_home "HOME" |
| 208 | text x_support "/Library/Application Support/Hop" |
| 209 | text x_index "/file-index.bin" |
| 210 | text x_gap " - " |
| 211 | text x_dotapp_low ".app" |
| 212 | text x_dir1_low "/applications/" |
| 213 | text x_dir2_low "/system/applications/" |
| 214 | text x_config "/config.json" |
| 215 | text c_json "NSJSONSerialization" |
| 216 | text c_dict "NSDictionary" |
| 217 | text c_array "NSArray" |
| 218 | text c_number "NSNumber" |
| 219 | text c_mutable_dict "NSMutableDictionary" |
| 220 | text c_mutable_string "NSMutableString" |
| 221 | text c_request "NSMutableURLRequest" |
| 222 | text c_session "NSURLSession" |
| 223 | text c_session_config "NSURLSessionConfiguration" |
| 224 | text c_queue "NSOperationQueue" |
| 225 | text c_text_view "NSTextView" |
| 226 | text m_json_object "JSONObjectWithData:options:error:" |
| 227 | text m_json_data "dataWithJSONObject:options:error:" |
| 228 | text m_object_for_key "objectForKey:" |
| 229 | text m_is_kind "isKindOfClass:" |
| 230 | text m_equal_string "isEqualToString:" |
| 231 | text m_has_suffix "hasSuffix:" |
| 232 | text m_substring_to "substringToIndex:" |
| 233 | text m_append_string "stringByAppendingString:" |
| 234 | text m_append "appendString:" |
| 235 | text m_set_string "setString:" |
| 236 | text m_string "string" |
| 237 | text m_dictionary "dictionary" |
| 238 | text m_set_object "setObject:forKey:" |
| 239 | text m_array_with "arrayWithObject:" |
| 240 | text m_number_bool "numberWithBool:" |
| 241 | text m_request_url "requestWithURL:" |
| 242 | text m_set_method "setHTTPMethod:" |
| 243 | text m_set_header "setValue:forHTTPHeaderField:" |
| 244 | text m_set_body "setHTTPBody:" |
| 245 | text m_set_timeout "setTimeoutInterval:" |
| 246 | text m_ephemeral "ephemeralSessionConfiguration" |
| 247 | text m_main_queue "mainQueue" |
| 248 | text m_session_with "sessionWithConfiguration:delegate:delegateQueue:" |
| 249 | text m_data_task "dataTaskWithRequest:" |
| 250 | text m_resume "resume" |
| 251 | text m_cancel_task "cancel" |
| 252 | text m_data_bytes "dataWithBytes:length:" |
| 253 | text m_set_editable "setEditable:" |
| 254 | text m_set_hidden "setHidden:" |
| 255 | text m_description "localizedDescription" |
| 256 | text m_response "response" |
| 257 | text m_status_code "statusCode" |
| 258 | text m_did_data "URLSession:dataTask:didReceiveData:" |
| 259 | text m_did_complete "URLSession:task:didCompleteWithError:" |
| 260 | text t_session "v@:@@@" |
| 261 | text k_models "models" |
| 262 | text k_default "defaultModel" |
| 263 | text k_name "name" |
| 264 | text k_base "baseURL" |
| 265 | text k_model "model" |
| 266 | text k_kind "kind" |
| 267 | text k_key "keychainKey" |
| 268 | text k_messages "messages" |
| 269 | text k_stream "stream" |
| 270 | text k_role "role" |
| 271 | text k_content "content" |
| 272 | text k_choices "choices" |
| 273 | text k_delta "delta" |
| 274 | text k_message "message" |
| 275 | text x_openai "openai" |
| 276 | text x_user "user" |
| 277 | text x_post "POST" |
| 278 | text x_json_type "application/json" |
| 279 | text x_content_type "Content-Type" |
| 280 | text x_slash_text "/" |
| 281 | text x_completions "/chat/completions" |
| 282 | text x_ask "Ask " |
| 283 | text x_colon ": " |
| 284 | text x_ask_none "Ask: no model in Hop's settings that can be asked from here" |
| 285 | text x_asking "Asking ..." |
| 286 | text x_no_answer "[no answer]" |
| 287 | text x_http "[HTTP " |
| 288 | text x_busy "The model is busy right now. Try again in a moment. " |
| 289 | text x_bracket "]" |
| 290 | text x_out10 " answer " |
| 291 | text s_pow "pow" |
| 292 | text s_log2 "log2" |
| 293 | text c_calendar "NSCalendar" |
| 294 | text c_running_app "NSRunningApplication" |
| 295 | text m_current_calendar "currentCalendar" |
| 296 | text m_component "component:fromDate:" |
| 297 | text m_date_now "date" |
| 298 | text m_current_app "currentApplication" |
| 299 | text m_frontmost "frontmostApplication" |
| 300 | text m_running_apps "runningApplications" |
| 301 | text m_policy_of "activationPolicy" |
| 302 | text m_bundle_id "bundleIdentifier" |
| 303 | text m_bundle_url "bundleURL" |
| 304 | text m_path "path" |
| 305 | text m_localized_name "localizedName" |
| 306 | text m_integer_value "integerValue" |
| 307 | text m_double_value "doubleValue" |
| 308 | text m_number_integer "numberWithInteger:" |
| 309 | text m_reference_now "timeIntervalSinceReferenceDate" |
| 310 | text x_habits "/habits.json" |
| 311 | text x_recents "/recents.json" |
| 312 | text x_mac_key "Mac:" |
| 313 | text x_env_front "HOPFRONT" |
| 314 | text k_app "app" |
| 315 | text k_from "from" |
| 316 | text k_hour "hour" |
| 317 | text k_count "count" |
| 318 | text k_last "last" |
| 319 | text x_why4 "You often open this from " |
| 320 | text x_here "here" |
| 321 | text x_why5 "You were just here" |
| 322 | text x_why6 "You often open this around now" |
| 323 | text x_why7 "One of your most used" |
| 324 | text x_why8 "Running now" |
| 325 | text s_chmod "chmod" |
| 326 | text c_mutable_array "NSMutableArray" |
| 327 | text m_array "array" |
| 328 | text m_add_object "addObject:" |
| 329 | text m_remove_range "removeObjectsInRange:" |
| 330 | text m_remove_key "removeObjectForKey:" |
| 331 | text m_all_keys "allKeys" |
| 332 | text m_number_double "numberWithDouble:" |
| 333 | text m_write_file "writeToFile:atomically:" |
| 334 | text k_at_key "at" |
| 335 | text k_path "path" |
| 336 | text x_env_record "HOPRECORD" |
| 337 | text s_memset "memset" |
| 338 | text s_trusted "AXIsProcessTrusted" |
| 339 | text s_key_event "CGEventCreateKeyboardEvent" |
| 340 | text s_event_flags "CGEventSetFlags" |
| 341 | text s_event_post "CGEventPost" |
| 342 | text s_cf_release "CFRelease" |
| 343 | text x_security "/usr/bin/security" |
| 344 | text x_find "find-generic-password" |
| 345 | text x_dash_s "-s" |
| 346 | text x_clip_service "com.aienos.hop.clipboard" |
| 347 | text x_dash_a "-a" |
| 348 | text x_clip_account "storage-key-v2" |
| 349 | text x_dash_w "-w" |
| 350 | text x_clipboard_file "/clipboard.bin" |
| 351 | text x_clip_images "/clip-images/" |
| 352 | text x_env_clipkey "HOPCLIPKEY" |
| 353 | text x_env_row "HOPROW" |
| 354 | text x_env_vault "HOPVAULT" |
| 355 | text x_env_cliprec "HOPCLIPREC" |
| 356 | text x_real_ssh "/usr/bin/ssh" |
| 357 | text x_nc "/usr/bin/nc" |
| 358 | text x_nc_args "-z|-G|2|127.0.0.1" |
| 359 | text m_probe_done "probeDone:" |
| 360 | text m_all_keys_for "allKeysForObject:" |
| 361 | text m_remove_for_key "removeObjectForKey:" |
| 362 | text m_note_object "object" |
| 363 | text m_is_equal_number "isEqualToNumber:" |
| 364 | text s_cf_true "kCFBooleanTrue" |
| 365 | text s_cf_false "kCFBooleanFalse" |
| 366 | text x_out16 " links " |
| 367 | text 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" |
| 368 | text x_loopback "127.0.0.1:" |
| 369 | text k_tunnels "tunnels" |
| 370 | text k_local_port "localPort" |
| 371 | text k_remote_port "remotePort" |
| 372 | text k_ssh_host "sshHost" |
| 373 | text k_cortex "cortex" |
| 374 | text k_enabled "enabled" |
| 375 | text k_url "url" |
| 376 | text k_host "host" |
| 377 | text m_url_port "port" |
| 378 | text m_is_executable "isExecutableFileAtPath:" |
| 379 | text m_all_values "allValues" |
| 380 | text s_will_terminate "NSApplicationWillTerminateNotification" |
| 381 | text m_app_quit "appQuit:" |
| 382 | text x_env_menu "HOPMENU" |
| 383 | text x_status_symbol "bolt.horizontal.circle" |
| 384 | text x_status_open "Open Hop Omega (Option Space)" |
| 385 | text x_status_index "Rebuild file index" |
| 386 | text x_status_paste "Allow paste into apps ..." |
| 387 | text x_status_login "Open at login" |
| 388 | text x_status_settings "Settings (edit config file) ..." |
| 389 | text x_status_clear "Clear clipboard history" |
| 390 | text x_key_comma "," |
| 391 | text x_menu_word "menu " |
| 392 | text c_status_bar "NSStatusBar" |
| 393 | text m_system_status_bar "systemStatusBar" |
| 394 | text m_status_item_length "statusItemWithLength:" |
| 395 | text m_button "button" |
| 396 | text m_set_image "setImage:" |
| 397 | text m_symbol_image "imageWithSystemSymbolName:accessibilityDescription:" |
| 398 | text m_set_target "setTarget:" |
| 399 | text m_set_state "setState:" |
| 400 | text m_separator "separatorItem" |
| 401 | text m_set_item_menu "setMenu:" |
| 402 | text m_item_array "itemArray" |
| 403 | text m_item_title "title" |
| 404 | text m_menu_open "menuOpen:" |
| 405 | text m_menu_index "menuIndex:" |
| 406 | text m_menu_paste "menuPaste:" |
| 407 | text m_menu_login "menuLogin:" |
| 408 | text m_menu_settings "menuSettings:" |
| 409 | text m_menu_clear "menuClear:" |
| 410 | text s_trusted_options "AXIsProcessTrustedWithOptions" |
| 411 | text s_trusted_prompt "kAXTrustedCheckOptionPrompt" |
| 412 | text x_sm_path "/System/Library/Frameworks/ServiceManagement.framework/ServiceManagement" |
| 413 | text c_sm_service "SMAppService" |
| 414 | text m_main_app "mainAppService" |
| 415 | text m_status "status" |
| 416 | text m_register "registerAndReturnError:" |
| 417 | text m_unregister "unregisterAndReturnError:" |
| 418 | text x_login_failed "Couldn't change Open at login" |
| 419 | text x_textedit "/System/Applications/TextEdit.app" |
| 420 | text c_open_config "NSWorkspaceOpenConfiguration" |
| 421 | text m_configuration "configuration" |
| 422 | text m_open_urls_with "openURLs:withApplicationAtURL:configuration:completionHandler:" |
| 423 | text x_empty_settings "{}" |
| 424 | text x_env_ssh "HOPSSH" |
| 425 | text x_env_scp "HOPSCP" |
| 426 | text x_env_late "HOPLATE" |
| 427 | text x_ssh_word "ssh" |
| 428 | text x_scp_word "scp" |
| 429 | text x_ssh_options " -o BatchMode=yes -o ConnectTimeout=8 " |
| 430 | text x_scp_options " -q -o BatchMode=yes " |
| 431 | text 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 ( " |
| 432 | text x_remote_grep "LC_ALL=C grep -F -i -- " |
| 433 | text x_remote_shard " %%$s%%" |
| 434 | text x_remote_pipe " | " |
| 435 | text x_remote_b " | head -300 > %%$t/${s##*/}%% ) & done; wait; cat %%$t%%/*; rm -rf %%$t%%" |
| 436 | text x_local_a "( " |
| 437 | text x_local_b "; [ $? = 255 ] && echo HOP-UNREACHABLE ) 2>/dev/null | sed 's/^/" |
| 438 | text x_local_c ":/' &" |
| 439 | text x_wait_word "wait" |
| 440 | text x_build_a "cd ~/.cache/hop && find " |
| 441 | text x_build_b " -xdev ^^( -path '*/.*' -o " |
| 442 | text 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" |
| 443 | text x_name_flag "-name " |
| 444 | text x_or_flag " -o " |
| 445 | text x_fresh_a "mkdir -p ~/.cache/hop; f=~/.cache/hop/shards/s00" |
| 446 | text 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" |
| 447 | text 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 " |
| 448 | text x_fresh_d " >/dev/null 2>&1 & fi; fi" |
| 449 | text x_fresh_e "echo ok" |
| 450 | text x_percents "%%" |
| 451 | text x_carets "^^" |
| 452 | text x_fetch_a "sz=$(" |
| 453 | text x_fetch_stat "stat -c %s -- " |
| 454 | text x_fetch_b ") && [ %%$sz%% -le 2000000000 ] && mkdir -p " |
| 455 | text x_fetch_c " && " |
| 456 | text x_fetch_d " && echo HOP-FETCHED" |
| 457 | text x_fetched "HOP-FETCHED" |
| 458 | text x_no_index "HOP-NO-INDEX" |
| 459 | text x_unreachable "HOP-UNREACHABLE" |
| 460 | text x_remote_cache "/Library/Caches/Hop/remote/" |
| 461 | text x_check_cache "/remote/" |
| 462 | text x_on " on " |
| 463 | text x_note_unreachable " is unreachable right now" |
| 464 | text x_note_building " is building its file list ..." |
| 465 | text x_note_bringing "Bringing it over from " |
| 466 | text x_note_copied "Copied the path on the clipboard: " |
| 467 | text x_note_failed "Could not bring it over; its path is on the clipboard: " |
| 468 | text x_out13 " fetched " |
| 469 | text x_out14 " machine " |
| 470 | text x_out15 " says " |
| 471 | text k_roots_m "roots" |
| 472 | text k_skip_m "skip" |
| 473 | text m_remote_go "remoteGo:" |
| 474 | text m_remote_done "remoteDone:" |
| 475 | text m_fetch_done "fetchDone:" |
| 476 | text m_read_to_end "readToEndOfFileInBackgroundAndNotify" |
| 477 | text s_read_to_end_done "NSFileHandleReadToEndOfFileCompletionNotification" |
| 478 | text m_cancel_previous "cancelPreviousPerformRequestsWithTarget:selector:object:" |
| 479 | text m_dir_of "stringByDeletingLastPathComponent" |
| 480 | text x_mskip0 ".git" |
| 481 | text x_mskip1 "node_modules" |
| 482 | text x_mskip2 "target" |
| 483 | text x_mskip3 "__pycache__" |
| 484 | text x_mskip4 "venv" |
| 485 | text x_mskip5 ".venv" |
| 486 | text x_mskip6 "site-packages" |
| 487 | text x_mskip7 "build" |
| 488 | text x_mskip8 "dist" |
| 489 | text x_mskip9 "proc" |
| 490 | text x_engine0 "Claude Code" |
| 491 | text x_engine0_command "claude|-p|{prompt}|--output-format|stream-json|--verbose" |
| 492 | text x_engine1 "Codex" |
| 493 | text x_engine1_command "codex|exec|--skip-git-repo-check|{prompt}" |
| 494 | text x_engine2 "Grok" |
| 495 | text x_engine2_command "grok|-p|{prompt}" |
| 496 | text x_engine3 "Gemini" |
| 497 | text x_engine3_command "gemini|-p|{prompt}" |
| 498 | text x_engine4 "OpenCode" |
| 499 | text x_engine4_command "opencode|run|{prompt}" |
| 500 | text x_engine5 "Cursor" |
| 501 | text x_engine5_command "cursor-agent|-p|--output-format|text|{prompt}" |
| 502 | text x_engine6 "Hermes" |
| 503 | text x_engine6_command "hermes|-z|{prompt}" |
| 504 | text x_old0_command "codex|exec|--skip-git-repo-check|--dangerously-bypass-approvals-and-sandbox|{prompt}" |
| 505 | text x_old1_command "grok|--always-approve|-p|{prompt}" |
| 506 | text x_old2_command "gemini|-y|-p|{prompt}" |
| 507 | text x_old3_command "cursor-agent|-p|-f|--output-format|text|{prompt}" |
| 508 | text x_old4_command "hermes|--yolo|-z|{prompt}" |
| 509 | text x_path0 ".local/bin" |
| 510 | text x_path1 ".claude/local" |
| 511 | text x_path2 "/opt/homebrew/bin" |
| 512 | text x_path3 "/usr/local/bin" |
| 513 | text x_path4 ".bun/bin" |
| 514 | text x_path5 ".npm-global/bin" |
| 515 | text x_path6 ".cargo/bin" |
| 516 | text x_path7 ".opencode/bin" |
| 517 | text x_path8 ".volta/bin" |
| 518 | text x_path9 ".asdf/shims" |
| 519 | text x_path10 ".local/share/mise/shims" |
| 520 | text x_path11 "bin" |
| 521 | text x_custom_command "Custom command" |
| 522 | text x_legacy_mark "HOP-LEGACY-COMMAND" |
| 523 | text x_zsh "/bin/zsh" |
| 524 | text x_dash_lc "-lc" |
| 525 | text x_wrapper "[ -n ~$HOP_EXTRA_PATH~ ] && PATH=~$PATH:$HOP_EXTRA_PATH~; unset HOP_EXTRA_PATH; exec ~$@~" |
| 526 | text x_tilde "~" |
| 527 | text x_hop_word "hop" |
| 528 | text x_sh "sh" |
| 529 | text x_dash_c "-c" |
| 530 | text x_probe_a "command -v " |
| 531 | text x_probe_b " >/dev/null 2>&1 && echo " |
| 532 | text x_true_word "true" |
| 533 | text x_term "TERM" |
| 534 | text x_dumb "dumb" |
| 535 | text x_no_color "NO_COLOR" |
| 536 | text x_one "1" |
| 537 | text x_extra_path "HOP_EXTRA_PATH" |
| 538 | text x_colon_only ":" |
| 539 | text x_nvm "/.nvm/versions/node" |
| 540 | text x_herd "/Library/Application Support/Herd/config/nvm/versions/node" |
| 541 | text x_slash_bin "/bin" |
| 542 | text x_prompt_mark "{prompt}" |
| 543 | text x_claude "claude" |
| 544 | text x_append_system "--append-system-prompt" |
| 545 | text x_resume "--resume" |
| 546 | text x_request "Request: " |
| 547 | text x_the_user "the user" |
| 548 | text x_brief_a "'s agent." |
| 549 | text x_brief_b " All machines = one box; never ask which. Mac = here. " |
| 550 | text x_brief_c " (auto-routed). Find files anywhere: hop find <words>." |
| 551 | text x_brief_d " Factory: " |
| 552 | text x_brief_e " Never delete agent files. Back up before destructive changes. Reply short, plain words." |
| 553 | text x_ssh_a ": ssh " |
| 554 | text x_ssh_b " '<cmd>'" |
| 555 | text x_semi_space "; " |
| 556 | text x_period "." |
| 557 | text x_agent_row "Agent fixes it: " |
| 558 | text x_brace "{" |
| 559 | text x_bang "! " |
| 560 | text x_tool_word "tool" |
| 561 | text x_tool_mark "> " |
| 562 | text x_agent_error "agent error" |
| 563 | text 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: " |
| 564 | text x_agent_none_b "No coding agent was found on this Mac. Add an agent command to Hop's settings." |
| 565 | text x_agent_missing_a " is set as your agent but is not installed on this Mac. Installed here: " |
| 566 | text x_agent_missing_b ". Name one of them as agentEngine in Hop's settings. Nothing was run." |
| 567 | text x_agent_stopped_a "Agent stopped (exit " |
| 568 | text x_agent_stopped_b ")." |
| 569 | text x_agent_working "The agent is working ..." |
| 570 | text x_agent_busy "The agent is still working on the last request. Nothing new was run." |
| 571 | text x_agent_ask "Let the agent work on this Mac?" |
| 572 | text 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." |
| 573 | text x_agent_yes "Run the agent" |
| 574 | text x_agent_no "Cancel" |
| 575 | text x_comma_space ", " |
| 576 | text x_paren_a " (" |
| 577 | text x_paren_b ")" |
| 578 | text x_screen2 "Agent" |
| 579 | text x_screen2_about "what the agent said" |
| 580 | text x_word_agent "agent" |
| 581 | text x_stop_item "Stop the Agent" |
| 582 | text x_key_period "." |
| 583 | text x_agent_menu "Agent" |
| 584 | text c_alert "NSAlert" |
| 585 | text m_set_message "setMessageText:" |
| 586 | text m_set_informative "setInformativeText:" |
| 587 | text m_add_button "addButtonWithTitle:" |
| 588 | text m_run_modal "runModal" |
| 589 | text c_center "NSNotificationCenter" |
| 590 | text m_default_center "defaultCenter" |
| 591 | text m_add_observer "addObserver:selector:name:object:" |
| 592 | text m_remove_all_observer "removeObserver:name:object:" |
| 593 | text s_read_done "NSFileHandleReadCompletionNotification" |
| 594 | text s_data_item "NSFileHandleNotificationDataItem" |
| 595 | text s_task_ended "NSTaskDidTerminateNotification" |
| 596 | text m_read_background "readInBackgroundAndNotify" |
| 597 | text m_user_info "userInfo" |
| 598 | text m_set_cwd "setCurrentDirectoryPath:" |
| 599 | text m_set_environment "setEnvironment:" |
| 600 | text m_set_input "setStandardInput:" |
| 601 | text m_environment "environment" |
| 602 | text m_mutable_copy "mutableCopy" |
| 603 | text m_terminate_task "terminate" |
| 604 | text m_is_equal_array "isEqualToArray:" |
| 605 | text m_range_of_data "rangeOfData:options:range:" |
| 606 | text m_subdata "subdataWithRange:" |
| 607 | text m_replace_bytes "replaceBytesInRange:withBytes:length:" |
| 608 | text m_append_data "appendData:" |
| 609 | text m_joined "componentsJoinedByString:" |
| 610 | text m_uppercase "uppercaseString" |
| 611 | text m_substring_from "substringFromIndex:" |
| 612 | text m_contents_of_dir "contentsOfDirectoryAtPath:error:" |
| 613 | text m_standard_compare "localizedStandardCompare:" |
| 614 | text m_newline_set "newlineCharacterSet" |
| 615 | text m_agent_out "agentOut:" |
| 616 | text m_agent_err "agentErr:" |
| 617 | text m_agent_end "agentEnd:" |
| 618 | text m_agent_stop "stopAgent:" |
| 619 | text k_engines "agentEngines" |
| 620 | text k_engine "agentEngine" |
| 621 | text k_agent_command "agentCommand" |
| 622 | text k_agent_folder "agentWorkingDirectory" |
| 623 | text k_enter_agent "enterSendsToAgent" |
| 624 | text k_agent_confirmed "agentConfirmed" |
| 625 | text k_keep_flags "keepAgentFlags" |
| 626 | text k_command "command" |
| 627 | text k_owner "ownerName" |
| 628 | text k_machines "machines" |
| 629 | text k_ssh "ssh" |
| 630 | text k_factory_url "factoryURL" |
| 631 | text k_type "type" |
| 632 | text k_parts_text "text" |
| 633 | text k_tool_use "tool_use" |
| 634 | text k_result "result" |
| 635 | text k_is_error "is_error" |
| 636 | text k_session_id "session_id" |
| 637 | text x_env_ask2 "HOPASK2" |
| 638 | text x_env_agents "HOPAGENTS" |
| 639 | text x_engine_word "engine " |
| 640 | text x_env_asknew "HOPASKNEW" |
| 641 | text m_array_adding "arrayByAddingObject:" |
| 642 | text m_remove_last "removeLastObject" |
| 643 | text x_assistant "assistant" |
| 644 | text x_you "You: " |
| 645 | text x_command3 "New chat" |
| 646 | text x_word_new_chat "new chat" |
| 647 | text x_word_clear_chat "clear chat" |
| 648 | text s_free "free" |
| 649 | text s_iopolicy "setiopolicy_np" |
| 650 | text s_home_directory "NSHomeDirectory" |
| 651 | text s_key_directory "NSURLIsDirectoryKey" |
| 652 | text s_key_package "NSURLIsPackageKey" |
| 653 | text s_key_link "NSURLIsSymbolicLinkKey" |
| 654 | text s_modified "NSFileModificationDate" |
| 655 | text c_process_info "NSProcessInfo" |
| 656 | text m_process_info "processInfo" |
| 657 | text m_arguments "arguments" |
| 658 | text c_bundle "NSBundle" |
| 659 | text m_main_bundle "mainBundle" |
| 660 | text m_executable_path "executablePath" |
| 661 | text m_drain "drain" |
| 662 | text c_set "NSSet" |
| 663 | text m_set_with_array "setWithArray:" |
| 664 | text m_enumerator "enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:" |
| 665 | text m_next_object "nextObject" |
| 666 | text m_get_resource "getResourceValue:forKey:error:" |
| 667 | text m_last_component "lastPathComponent" |
| 668 | text m_skip_descendants "skipDescendants" |
| 669 | text m_is_running "isRunning" |
| 670 | text m_attributes_of "attributesOfItemAtPath:error:" |
| 671 | text m_since_now "timeIntervalSinceNow" |
| 672 | text k_roots "indexRoots" |
| 673 | text k_skip_names "indexSkipNames" |
| 674 | text x_index_word "index" |
| 675 | text x_applications "/Applications" |
| 676 | text x_system_applications "/System/Applications" |
| 677 | text x_indexed "indexed " |
| 678 | text x_items " items" |
| 679 | text x_indexing " (indexing files ...)" |
| 680 | text x_command2 "Rebuild file index" |
| 681 | text x_word_rebuild "rebuild file index" |
| 682 | text x_word_reindex "reindex" |
| 683 | text x_word_index_files "index files" |
| 684 | text x_skipname0 "Library" |
| 685 | text x_skipname1 "node_modules" |
| 686 | text x_skipname2 ".git" |
| 687 | text x_skipname3 "target" |
| 688 | text x_skipname4 "build" |
| 689 | text x_skipname5 "dist" |
| 690 | text x_skipname6 "DerivedData" |
| 691 | text x_skipname7 "__pycache__" |
| 692 | text x_skipname8 "venv" |
| 693 | text x_skipname9 ".venv" |
| 694 | text x_skipname10 ".cache" |
| 695 | text x_skipname11 "Caches" |
| 696 | text x_skipname12 ".Trash" |
| 697 | text x_skipname13 "site-packages" |
| 698 | text x_skipname14 ".build" |
| 699 | text x_skipname15 "Pods" |
| 700 | text x_word0 "clipboard" |
| 701 | text x_word1 "copied" |
| 702 | text x_word2 "clipboard history" |
| 703 | text x_word3 "accounts" |
| 704 | text x_word4 "keys" |
| 705 | text x_word5 "api keys" |
| 706 | text x_word6 "passwords" |
| 707 | text x_word7 "logins" |
| 708 | text x_word8 "settings" |
| 709 | text x_word9 "preferences" |
| 710 | text x_word10 "config" |
| 711 | text x_word11 "hop settings" |
| 712 | text x_word12 "quit hop" |
| 713 | text x_screen0 "Clipboard" |
| 714 | text x_screen0_about "your copied things" |
| 715 | text x_screen1 "Accounts" |
| 716 | text x_screen1_about "your saved keys and logins" |
| 717 | text x_command0 "Settings" |
| 718 | text x_command0_about "opens Hop's settings file" |
| 719 | text x_command1 "Quit Hop Omega" |
| 720 | text x_copied_things " copied things" |
| 721 | text x_accounts_word " accounts" |
| 722 | text x_pinned "pinned" |
| 723 | text x_env_screen "HOPSCREEN" |
| 724 | text x_env_clipdo "HOPCLIPDO" |
| 725 | text x_clip_menu "Clipboard" |
| 726 | text x_pin_item "Pin or Unpin" |
| 727 | text x_delete_item "Delete from History" |
| 728 | text x_key_p "p" |
| 729 | text x_key_d "d" |
| 730 | text m_pin_clip "pinClip:" |
| 731 | text m_delete_clip "deleteClip:" |
| 732 | text x_out12 " screen " |
| 733 | text s_random "arc4random_buf" |
| 734 | text c_uuid "NSUUID" |
| 735 | text m_uuid "UUID" |
| 736 | text m_uuid_string "UUIDString" |
| 737 | text c_timer "NSTimer" |
| 738 | text m_timer "scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:" |
| 739 | text m_clip_tick "clipTick:" |
| 740 | text m_change_count "changeCount" |
| 741 | text m_types "types" |
| 742 | text m_contains_object "containsObject:" |
| 743 | text c_image "NSImage" |
| 744 | text m_init_pasteboard "initWithPasteboard:" |
| 745 | text m_tiff "TIFFRepresentation" |
| 746 | text c_bitmap "NSBitmapImageRep" |
| 747 | text m_rep_with_data "imageRepWithData:" |
| 748 | text m_rep_using "representationUsingType:properties:" |
| 749 | text m_running_with "runningApplicationsWithBundleIdentifier:" |
| 750 | text x_hop_id "com.aienos.hop" |
| 751 | text k_id "id" |
| 752 | text k_source "sourceApp" |
| 753 | text k_limit "clipboardLimit" |
| 754 | text m_insert_at "insertObject:atIndex:" |
| 755 | text m_remove_at "removeObjectAtIndex:" |
| 756 | text m_byte_length "lengthOfBytesUsingEncoding:" |
| 757 | text c_mutable_data "NSMutableData" |
| 758 | text m_data "data" |
| 759 | text m_append_bytes "appendBytes:length:" |
| 760 | text c_file_manager "NSFileManager" |
| 761 | text m_default_manager "defaultManager" |
| 762 | text m_file_exists "fileExistsAtPath:" |
| 763 | text m_remove_item "removeItemAtPath:error:" |
| 764 | text m_create_dir "createDirectoryAtPath:withIntermediateDirectories:attributes:error:" |
| 765 | text x_clip_backup "/clipboard.before-hop-omega.bin" |
| 766 | text x_dot_bin ".bin" |
| 767 | text x_skip0 "org.nspasteboard.ConcealedType" |
| 768 | text x_skip1 "org.nspasteboard.TransientType" |
| 769 | text x_skip2 "org.nspasteboard.AutoGeneratedType" |
| 770 | text x_skip3 "com.agilebits.onepassword" |
| 771 | text x_skip4 "com.typeit4me.clipping" |
| 772 | text x_skip5 "de.petermaurer.TransientPasteboardType" |
| 773 | text x_env_vault_add "HOPVAULTADD" |
| 774 | text s_item_add "SecItemAdd" |
| 775 | text s_item_delete "SecItemDelete" |
| 776 | text s_interaction "SecKeychainSetUserInteractionAllowed" |
| 777 | text s_value_data "kSecValueData" |
| 778 | text s_accessible "kSecAttrAccessible" |
| 779 | text s_accessible_unlocked "kSecAttrAccessibleWhenUnlockedThisDeviceOnly" |
| 780 | text m_data_using "dataUsingEncoding:" |
| 781 | text x_semicolon ";" |
| 782 | text x_bar "|" |
| 783 | text x_vault_service "com.aienos.hop.vault" |
| 784 | text s_item_copy "SecItemCopyMatching" |
| 785 | text s_class "kSecClass" |
| 786 | text s_class_generic "kSecClassGenericPassword" |
| 787 | text s_attr_service "kSecAttrService" |
| 788 | text s_attr_account "kSecAttrAccount" |
| 789 | text s_attr_description "kSecAttrDescription" |
| 790 | text s_attr_comment "kSecAttrComment" |
| 791 | text s_match_limit "kSecMatchLimit" |
| 792 | text s_limit_all "kSecMatchLimitAll" |
| 793 | text s_limit_one "kSecMatchLimitOne" |
| 794 | text s_return_attributes "kSecReturnAttributes" |
| 795 | text s_return_data "kSecReturnData" |
| 796 | text s_true "kCFBooleanTrue" |
| 797 | text m_sorted "sortedArrayUsingSelector:" |
| 798 | text m_compare "compare:" |
| 799 | text m_has_prefix "hasPrefix:" |
| 800 | text m_declare_types "declareTypes:owner:" |
| 801 | text x_type_concealed "org.nspasteboard.ConcealedType" |
| 802 | text x_bearer "Bearer " |
| 803 | text x_authorization "Authorization" |
| 804 | text x_no_key "[The key of this model could not be read from the Keychain]" |
| 805 | text x_check_board "com.aienos.hop.omega.check" |
| 806 | text c_task "NSTask" |
| 807 | text c_pipe "NSPipe" |
| 808 | text c_file_handle "NSFileHandle" |
| 809 | text c_pasteboard "NSPasteboard" |
| 810 | text c_charset "NSCharacterSet" |
| 811 | text m_set_launch "setLaunchPath:" |
| 812 | text m_set_arguments "setArguments:" |
| 813 | text m_pipe "pipe" |
| 814 | text m_set_output "setStandardOutput:" |
| 815 | text m_set_error "setStandardError:" |
| 816 | text m_null_device "fileHandleWithNullDevice" |
| 817 | text m_launch "launch" |
| 818 | text m_reading "fileHandleForReading" |
| 819 | text m_read_end "readDataToEndOfFile" |
| 820 | text m_wait "waitUntilExit" |
| 821 | text m_termination "terminationStatus" |
| 822 | text m_init_data_encoding "initWithData:encoding:" |
| 823 | text m_trim "stringByTrimmingCharactersInSet:" |
| 824 | text m_whitespace "whitespaceAndNewlineCharacterSet" |
| 825 | text m_init_base64 "initWithBase64EncodedString:options:" |
| 826 | text m_general_pasteboard "generalPasteboard" |
| 827 | text m_board_named "pasteboardWithName:" |
| 828 | text m_clear "clearContents" |
| 829 | text m_set_string_type "setString:forType:" |
| 830 | text m_set_data_type "setData:forType:" |
| 831 | text m_string_for_type "stringForType:" |
| 832 | text m_data_for_type "dataForType:" |
| 833 | text m_lowercase "lowercaseString" |
| 834 | text m_contains "containsString:" |
| 835 | text m_components "componentsSeparatedByString:" |
| 836 | text m_replace "stringByReplacingOccurrencesOfString:withString:" |
| 837 | text m_composed_at "rangeOfComposedCharacterSequenceAtIndex:" |
| 838 | text m_bool_value "boolValue" |
| 839 | text m_release "release" |
| 840 | text m_perform_after "performSelector:withObject:afterDelay:" |
| 841 | text m_paste_now "pasteNow:" |
| 842 | text x_type_string "public.utf8-plain-text" |
| 843 | text x_type_png "public.png" |
| 844 | text k_text "text" |
| 845 | text k_image "imageFile" |
| 846 | text k_pinned "pinned" |
| 847 | text k_date "date" |
| 848 | text x_image "Image" |
| 849 | text x_image_low "image" |
| 850 | text x_space " " |
| 851 | text x_paste_row "Paste: " |
| 852 | text x_why1 "You just copied this" |
| 853 | text x_why2 "The last thing you copied" |
| 854 | text x_why3 "You copied a web address" |
| 855 | text x_out11 " pasted " |
| 856 | text x_png_word "png " |
| 857 | text x_browser0 "com.apple.Safari" |
| 858 | text x_browser1 "com.google.Chrome" |
| 859 | text x_browser2 "com.brave.Browser" |
| 860 | text x_browser3 "org.mozilla.firefox" |
| 861 | text x_browser4 "company.thebrowser.Browser" |
| 862 | text x_browser5 "com.microsoft.edgemac" |
| 863 | text x_browser6 "com.operasoftware.Opera" |
| 864 | text x_browser7 "com.vivaldi.Vivaldi" |
| 865 | text x_browser8 "app.zen-browser.zen" |
| 866 | text x_of " of " |
| 867 | text x_apps " apps" |
| 868 | text x_slash "/" |
| 869 | text x_dotapp ".app" |
| 870 | text x_env "HOPCHECK" |
| 871 | |
| 872 | note g_f: library functions. 0 objc_getClass 1 sel_registerName 2 objc_msgSend 3 write 4 objc_allocateClassPair |
| 873 | note 5 class_addMethod 6 objc_registerClassPair 7 strlen 8 memcpy 9 getenv 10 malloc 11 memmem 12 memchr 13 memrchr |
| 874 | note 14 pow 15 log2 16 chmod 17 memset 18 AXIsProcessTrusted 19 CGEventCreateKeyboardEvent 20 CGEventSetFlags |
| 875 | note 21 CGEventPost 22 CFRelease 23 SecItemCopyMatching 24 SecItemAdd 25 SecItemDelete |
| 876 | note 26 SecKeychainSetUserInteractionAllowed 27 arc4random_buf 28 free 29 setiopolicy_np 30 NSHomeDirectory |
| 877 | global g_f ulong 32 |
| 878 | note g_o: objects and selectors the callbacks need. 0 field 1 table 2 status line 3 NSString 4 stringWithUTF8String: |
| 879 | note 5 UTF8String 6 stringValue 7 reloadData 8 setStringValue: 9 moveDown: 10 moveUp: 11 cancelOperation: |
| 880 | note 12 selectRowIndexes:byExtendingSelection: 13 NSIndexSet 14 indexSetWithIndex: 15 scrollRowToVisible: |
| 881 | note 16 NSURL 17 URLWithString: 18 host 19 the window 20 orderOut: 21 the application 22 hide: |
| 882 | note 23 activateIgnoringOtherApps: 24 makeKeyAndOrderFront: 25 makeFirstResponder: 26 orderFrontRegardless |
| 883 | note 27 the object whose methods are the callbacks 28 the list's scroll view 29 the answer's scroll view |
| 884 | note 30 the answer's text view |
| 885 | global g_o ulong 32 |
| 886 | note 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 |
| 887 | note 6 the selected row 7 1 when Enter may open the row 8 the row Enter chose, plus 1 9 what the workspace answered |
| 888 | note 10 the typed text as a web address (0 it is none, 1 written with its scheme, 2 a bare address) 12 where the |
| 889 | note typed text starts once blanks are trimmed 13 its length then 14 1 when the program stays (no HOPCHECK) |
| 890 | note 15 what registering the hot key gave (0 it is registered) 16 the words of the typed text 17 the files found |
| 891 | note 18 1 when a file has exactly the typed text as its name 19 bytes of the answer waiting in g_net |
| 892 | note 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 |
| 893 | note 23 1 when the check asks for what is chosen to be remembered without being opened 24 the count of copied |
| 894 | note things 25 the bytes of the newest one's text when it may be a web address 26 its address kind 27 the count |
| 895 | note of other copied things offered 28 the count of copied things that match the typed text 29 what the check |
| 896 | note pasted (1 text, 2 a picture) 30 the row the check chooses before Enter (0: the first) 31 the count of |
| 897 | note saved accounts 32 the place plus 1 of the app that was in front before the one in front now |
| 898 | note 33 1 once the history was set aside before this run's first change to it 34 how many unpinned copied |
| 899 | note things are kept 35 the clipboard's change count last seen 36 the screen the list shows (0 everything, |
| 900 | note 1 the copied things, 2 the saved accounts) 37 what a check does to the selected copied thing (1 pin or |
| 901 | note unpin, 2 delete) 38 half seconds since the file index was last looked at |
| 902 | note 39 1 when the answer on show belongs to a turn that has ended 40 1 when that turn failed 41 1 when the |
| 903 | note typed text reads as a question 42 1 when Hop's settings send a sentence to the agent on Enter 43 1 while |
| 904 | note the agent runs 44 1 once the person said yes to the agent 45 1 once the agents on this Mac were looked |
| 905 | note for 46 1 when a check sends what it types to the agent 47 what of the agent's run has ended (1 its |
| 906 | note output, 2 the program) 48 the turn at which a check sends Enter 49 the count of files found on other |
| 907 | note machines 50 the bytes of what the machines answered 51 what to say about a machine (1 unreachable, 2 building |
| 908 | note its list, 3 a file is on its way, 4 a path was copied, 5 a file could not be brought) 52 which machine |
| 909 | note 53 the bytes of the text the machines were asked for 54 the count of machines 55 1 when a check's file |
| 910 | note 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 |
| 911 | note 59 1 when other machines may be reached 60 half seconds since the forwarded ports were last looked at |
| 912 | note 61 how many links this program has started 62 how many forwarded ports the settings name |
| 913 | global g_n ulong 64 |
| 914 | note g_t: the text HOPCHECK=open:TEXT asks to type |
| 915 | global g_t uchar 64 |
| 916 | global g_rg uchar 128 |
| 917 | global g_nm uchar 1024 |
| 918 | global g_pool uchar 65536 |
| 919 | global g_off ulong 2048 |
| 920 | global g_ln ulong 2048 |
| 921 | global g_hit ulong 2048 |
| 922 | note 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 |
| 923 | note app is in (0 /Applications, 1 /System/Applications); g_mk and g_ms: the apps hopfuzz matched and their scores |
| 924 | global g_rk uchar 2048 |
| 925 | global g_dir uchar 2048 |
| 926 | global g_mk ulong 2048 |
| 927 | global g_ms ulong 2048 |
| 928 | global g_q uchar 256 |
| 929 | note g_x: the first row's text, kept for the check's line |
| 930 | global g_x uchar 256 |
| 931 | note g_ev: the hot key's event type (class 'keyb', kind 5 pressed) and, from byte 8, the reference Carbon gives back |
| 932 | global g_ev uchar 16 |
| 933 | note The file index. g_fb: 0 where its bytes are (paths, a line each), 1 where the lower-case copy is, 2 how many |
| 934 | note 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. |
| 935 | note g_lq: the typed text, lower case; g_to and g_tl: where each of its words starts and how long it is. |
| 936 | note g_fs, g_fo, g_fl: the best 40 files, best first: score plus 100000, where the path starts, how long it is |
| 937 | global g_fb ulong 8 |
| 938 | note The model. g_m: 0 its id, 1 the address to post to, 2 its name (three NSStrings), 3 1 when there is one, |
| 939 | note 4 the answer so far (an NSMutableString), 5 the session, 6 the running task, 7 NSDictionary, 8 NSArray, |
| 940 | note 9 NSString (the classes, to tell what a JSON value is), 10 each app's path and its place (a dictionary), |
| 941 | note 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, |
| 942 | note 14 the copied things (an array, newest first), 15 the text each one is shown by, 16 objectAtIndex:, |
| 943 | note 18 the names of the saved accounts in order, 19 what each is (its kind and note), 20 the Keychain service |
| 944 | note they are under, 21 the name of the account that holds the model's key (nothing: it needs none), 22 the |
| 945 | note accounts a check made for itself (an array of their names), to be deleted when it ends, 23 the program |
| 946 | note that is building the file index now (nothing: none), 24 the conversation with the model (an array of |
| 947 | note messages, each a role and a content), 25 what was said before the answer on show (a text), 26 the agent's |
| 948 | note program while it runs, 27 where its output is read, 28 the agents of Hop's settings (each a name and a |
| 949 | note command), 29 the name of the one to use, 30 the folder it works in, 31 the older single command, 32 its |
| 950 | note output not yet a whole line, 33 the id of its last run (to carry on from), 34 the settings (for the |
| 951 | note agent's standing instructions), 35 the agents found on this Mac, 36 when the agent last worked (a number |
| 952 | note object), 37 where its errors are read, 38 to 41 the selectors agentOut: agentErr: agentEnd: stopAgent:, |
| 953 | note 42 the ssh names of the machines (an array), 43 the program asking the machines, 44 where its answer is |
| 954 | note read, 45 the program bringing a file over, 46 to 48 the selectors remoteGo: remoteDone: fetchDone:, |
| 955 | note 49 where the fetch's answer is read, 50 where the file that is on its way lands (a path), 51 its |
| 956 | note machine's ssh name and path, for the clipboard, 52 the icon in the menu bar, 53 its Open at login item, |
| 957 | note 54 to 59 the selectors menuOpen: menuIndex: menuPaste: menuLogin: menuSettings: menuClear:, |
| 958 | note 60 the forwarded ports to keep open (each: this Mac's port, the far port, the ssh name), 61 the programs |
| 959 | note that hold them open (by this Mac's port), 62 the selector appQuit:, 63 the programs asking whether a port |
| 960 | note is served (by the port), 64 the selector probeDone:. |
| 961 | note g_net: bytes from the server not yet read as lines |
| 962 | global g_m ulong 80 |
| 963 | global g_net uchar 262144 |
| 964 | note What is offered before anything is typed. g_so: the apps in the order of their paths; g_lf, g_lh: each app's |
| 965 | note lift from the app in front and from the hour; g_us: how much it is used; g_rn: 1 when it is running; |
| 966 | note g_fr: the apps that were in front when the panel was shown, newest first (place plus 1); g_why: why each |
| 967 | note row is offered |
| 968 | global g_so ulong 2048 |
| 969 | global g_lf ulong 2048 |
| 970 | global g_lh ulong 2048 |
| 971 | global g_us ulong 2048 |
| 972 | global g_rn uchar 2048 |
| 973 | global g_fr ulong 12 |
| 974 | global g_why uchar 2048 |
| 975 | note Copied things. g_ci: all of them in the order they are searched (the pinned ones first); g_cp: 1 for a |
| 976 | note pinned one; g_cr: the others offered before anything is typed; g_cm: the ones that match the typed text; |
| 977 | note g_ca: the newest one's text, kept while it may be a web address |
| 978 | global g_ci ulong 1024 |
| 979 | global g_cp uchar 1024 |
| 980 | global g_cr ulong 20 |
| 981 | global g_cm ulong 1024 |
| 982 | global g_ca uchar 256 |
| 983 | note eight bytes a library function writes a pointer into |
| 984 | global g_t8 uchar 8 |
| 985 | note Files on other machines. g_rb: what the machines answered (lines "K:path", K the machine's number); g_rq: |
| 986 | note 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 |
| 987 | note g_rb, its length, its score plus 100000, its machine); g_mn and g_ml: the machines' names |
| 988 | global g_rb uchar 1048576 |
| 989 | global g_rq uchar 256 |
| 990 | global g_ro ulong 64 |
| 991 | global g_rl ulong 64 |
| 992 | global g_rs ulong 64 |
| 993 | global g_rw uchar 64 |
| 994 | global g_mn uchar 640 |
| 995 | global g_ml uchar 10 |
| 996 | note the byte that ends a line of the file index |
| 997 | global g_nl uchar 1 |
| 998 | global g_chunk uchar 524288 |
| 999 | global g_line uchar 4096 |
| 1000 | global g_lq uchar 256 |
| 1001 | global g_to ulong 16 |
| 1002 | global g_tl ulong 16 |
| 1003 | global g_fs ulong 64 |
| 1004 | global g_fo ulong 64 |
| 1005 | global g_fl ulong 64 |
| 1006 | |
| 1007 | note ---- the core of Hop, from Omega/hopcore.om ---- |
| 1008 | fn isword w ulong to bool |
| 1009 | ret ne and w 4294967296 0 |
| 1010 | end |
| 1011 | |
| 1012 | fn istrim w ulong to bool |
| 1013 | ret ne and w 8589934592 0 |
| 1014 | end |
| 1015 | |
| 1016 | fn minu a ulong b ulong to ulong |
| 1017 | if lt a b |
| 1018 | ret a |
| 1019 | end |
| 1020 | ret b |
| 1021 | end |
| 1022 | |
| 1023 | note true when inp[a .. a+n) equals inp[b .. b+n); both runs must lie inside the buffer |
| 1024 | fn same inp view ulong 256 a ulong b ulong n ulong to bool |
| 1025 | for k ulong n |
| 1026 | if ne get inp add a k get inp add b k |
| 1027 | ret false |
| 1028 | end |
| 1029 | end |
| 1030 | ret true |
| 1031 | end |
| 1032 | |
| 1033 | note x is one longer than y (ls characters): true when dropping one character of x gives y |
| 1034 | fn skip1 inp view ulong 256 x ulong y ulong ls ulong to bool |
| 1035 | k = ulong 0 |
| 1036 | while lt k ls bound 256 |
| 1037 | if ne get inp add x k get inp add y k |
| 1038 | break |
| 1039 | end |
| 1040 | k = add k 1 |
| 1041 | end |
| 1042 | ret same inp add x add k 1 add y k sub ls k |
| 1043 | end |
| 1044 | |
| 1045 | note edit distance at most 1, where swapping two neighbours counts as one |
| 1046 | fn near inp view ulong 256 a ulong la ulong b ulong lb ulong to bool |
| 1047 | if eq la lb |
| 1048 | d = ulong 0 |
| 1049 | p = ulong 0 |
| 1050 | for k ulong la |
| 1051 | if ne get inp add a k get inp add b k |
| 1052 | if eq d 0 |
| 1053 | p = k |
| 1054 | end |
| 1055 | d = add d 1 |
| 1056 | end |
| 1057 | end |
| 1058 | if le d 1 |
| 1059 | ret true |
| 1060 | end |
| 1061 | if eq d 2 |
| 1062 | if lt add p 1 la |
| 1063 | if eq get inp add a p get inp add b add p 1 |
| 1064 | if eq get inp add a add p 1 get inp add b p |
| 1065 | ret true |
| 1066 | end |
| 1067 | end |
| 1068 | end |
| 1069 | end |
| 1070 | ret false |
| 1071 | end |
| 1072 | if eq la add lb 1 |
| 1073 | ret skip1 inp a b lb |
| 1074 | end |
| 1075 | if eq lb add la 1 |
| 1076 | ret skip1 inp b a la |
| 1077 | end |
| 1078 | ret false |
| 1079 | end |
| 1080 | |
| 1081 | note score of q = inp[qa .. qa+ql) in the name inp[72 .. 72+nl); 0 means no match. ql and nl >= 1 |
| 1082 | fn one inp view ulong 256 qa ulong ql ulong nl ulong to ulong |
| 1083 | if le ql nl |
| 1084 | if same inp qa 72 ql |
| 1085 | if eq ql nl |
| 1086 | ret 200 |
| 1087 | end |
| 1088 | ret sub 160 minu 30 sub nl ql |
| 1089 | end |
| 1090 | end |
| 1091 | qw = true |
| 1092 | for k ulong ql |
| 1093 | if not isword get inp add qa k |
| 1094 | qw = false |
| 1095 | end |
| 1096 | end |
| 1097 | wc = ulong 0 |
| 1098 | later = false |
| 1099 | inits = true |
| 1100 | inw = false |
| 1101 | for i ulong nl |
| 1102 | c = get inp add 72 i |
| 1103 | if isword c |
| 1104 | if not inw |
| 1105 | if lt wc ql |
| 1106 | if ne c get inp add qa wc |
| 1107 | inits = false |
| 1108 | end |
| 1109 | end |
| 1110 | if gt wc 0 |
| 1111 | if qw |
| 1112 | if le add i ql nl |
| 1113 | if same inp qa add 72 i ql |
| 1114 | later = true |
| 1115 | end |
| 1116 | end |
| 1117 | end |
| 1118 | end |
| 1119 | wc = add wc 1 |
| 1120 | end |
| 1121 | inw = true |
| 1122 | else |
| 1123 | inw = false |
| 1124 | end |
| 1125 | end |
| 1126 | if later |
| 1127 | ret sub 120 minu 20 div nl 3 |
| 1128 | end |
| 1129 | if ge ql 2 |
| 1130 | if gt wc 1 |
| 1131 | if ge wc ql |
| 1132 | if inits |
| 1133 | ret 110 |
| 1134 | end |
| 1135 | end |
| 1136 | end |
| 1137 | end |
| 1138 | if le ql nl |
| 1139 | for i ulong add sub nl ql 1 |
| 1140 | if same inp qa add 72 i ql |
| 1141 | ret sub 80 minu 20 div nl 3 |
| 1142 | end |
| 1143 | end |
| 1144 | end |
| 1145 | if ge ql 4 |
| 1146 | if le ql nl |
| 1147 | if near inp qa ql 72 ql |
| 1148 | ret 70 |
| 1149 | end |
| 1150 | end |
| 1151 | if le sub ql 1 nl |
| 1152 | if near inp qa ql 72 sub ql 1 |
| 1153 | ret 70 |
| 1154 | end |
| 1155 | end |
| 1156 | if le add ql 1 nl |
| 1157 | if near inp qa ql 72 add ql 1 |
| 1158 | ret 70 |
| 1159 | end |
| 1160 | end |
| 1161 | end |
| 1162 | if lt ql 3 |
| 1163 | ret 0 |
| 1164 | end |
| 1165 | qi = ulong 0 |
| 1166 | gaps = ulong 0 |
| 1167 | last = ulong 0 |
| 1168 | first = ulong 0 |
| 1169 | for i ulong nl |
| 1170 | if lt qi ql |
| 1171 | if eq get inp add 72 i get inp add qa qi |
| 1172 | if gt qi 0 |
| 1173 | gaps = add gaps sub sub i last 1 |
| 1174 | else |
| 1175 | first = i |
| 1176 | end |
| 1177 | last = i |
| 1178 | qi = add qi 1 |
| 1179 | end |
| 1180 | end |
| 1181 | end |
| 1182 | if ne qi ql |
| 1183 | ret 0 |
| 1184 | end |
| 1185 | if gt gaps ql |
| 1186 | ret 0 |
| 1187 | end |
| 1188 | t = add mul gaps 6 mul first 3 |
| 1189 | if ge t 45 |
| 1190 | ret 15 |
| 1191 | end |
| 1192 | ret sub 60 t |
| 1193 | end |
| 1194 | |
| 1195 | note first faulting word plus 1, or 0 when the input is well formed |
| 1196 | fn check inp view ulong 256 to ulong |
| 1197 | if ne get inp 0 1212568922 |
| 1198 | ret 1 |
| 1199 | end |
| 1200 | if ne get inp 1 1 |
| 1201 | ret 2 |
| 1202 | end |
| 1203 | ql = get inp 2 |
| 1204 | nl = get inp 3 |
| 1205 | if gt ql 64 |
| 1206 | ret 3 |
| 1207 | end |
| 1208 | if gt nl 184 |
| 1209 | ret 4 |
| 1210 | end |
| 1211 | for i ulong 4 |
| 1212 | if ne get inp add 4 i 0 |
| 1213 | ret add 5 i |
| 1214 | end |
| 1215 | end |
| 1216 | for i ulong 64 |
| 1217 | w = get inp add 8 i |
| 1218 | if lt i ql |
| 1219 | if ge w 17179869184 |
| 1220 | ret add 9 i |
| 1221 | end |
| 1222 | if eq and w 4294967295 0 |
| 1223 | ret add 9 i |
| 1224 | end |
| 1225 | else |
| 1226 | if ne w 0 |
| 1227 | ret add 9 i |
| 1228 | end |
| 1229 | end |
| 1230 | end |
| 1231 | for i ulong 184 |
| 1232 | w = get inp add 72 i |
| 1233 | if lt i nl |
| 1234 | if ge w 17179869184 |
| 1235 | ret add 73 i |
| 1236 | end |
| 1237 | if eq and w 4294967295 0 |
| 1238 | ret add 73 i |
| 1239 | end |
| 1240 | else |
| 1241 | if ne w 0 |
| 1242 | ret add 73 i |
| 1243 | end |
| 1244 | end |
| 1245 | end |
| 1246 | ret 0 |
| 1247 | end |
| 1248 | |
| 1249 | fn hopfuzz inp view ulong 256 res edit ulong 256 to ulong |
| 1250 | for i ulong 256 |
| 1251 | put res i 0 |
| 1252 | end |
| 1253 | put res 0 1212568922 |
| 1254 | put res 1 1 |
| 1255 | e = check inp |
| 1256 | if ne e 0 |
| 1257 | put res 2 2 |
| 1258 | put res 4 sub e 1 |
| 1259 | ret 2 |
| 1260 | end |
| 1261 | nl = get inp 3 |
| 1262 | qa = ulong 8 |
| 1263 | qe = add 8 get inp 2 |
| 1264 | while lt qa qe bound 256 |
| 1265 | if not istrim get inp qa |
| 1266 | break |
| 1267 | end |
| 1268 | qa = add qa 1 |
| 1269 | end |
| 1270 | while gt qe qa bound 256 |
| 1271 | if not istrim get inp sub qe 1 |
| 1272 | break |
| 1273 | end |
| 1274 | qe = sub qe 1 |
| 1275 | end |
| 1276 | ql = sub qe qa |
| 1277 | if eq ql 0 |
| 1278 | ret 0 |
| 1279 | end |
| 1280 | if eq nl 0 |
| 1281 | ret 0 |
| 1282 | end |
| 1283 | s = one inp qa ql nl |
| 1284 | if eq s 0 |
| 1285 | terms = ulong 0 |
| 1286 | sum = ulong 0 |
| 1287 | p = qa |
| 1288 | while lt p qe bound 256 |
| 1289 | if eq and get inp p 4294967295 32 |
| 1290 | p = add p 1 |
| 1291 | continue |
| 1292 | end |
| 1293 | b = p |
| 1294 | while lt p qe bound 256 |
| 1295 | if eq and get inp p 4294967295 32 |
| 1296 | break |
| 1297 | end |
| 1298 | p = add p 1 |
| 1299 | end |
| 1300 | ts = one inp b sub p b nl |
| 1301 | if eq ts 0 |
| 1302 | ret 0 |
| 1303 | end |
| 1304 | terms = add terms 1 |
| 1305 | sum = add sum ts |
| 1306 | end |
| 1307 | if le terms 1 |
| 1308 | ret 0 |
| 1309 | end |
| 1310 | s = sub div sum terms 10 |
| 1311 | end |
| 1312 | put res 2 1 |
| 1313 | put res 3 s |
| 1314 | ret 1 |
| 1315 | end |
| 1316 | |
| 1317 | note ---- file-name scoring (kind 2): how well a path found on another machine matches the typed terms ---- |
| 1318 | note The host sends bytes: the terms, and for each path its lowercased bytes, the lowercased bytes of its last |
| 1319 | note component (its name), and the byte length of the path as written. A term found in the name scores 60 when the name |
| 1320 | note starts with it and 30 otherwise; found only elsewhere in the path it scores 5; a term found nowhere, or an |
| 1321 | note 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 | |
| 1323 | fn rd16 b view uchar 1048576 o ulong to ulong |
| 1324 | ret or ulong get b o shl ulong get b add o 1 8 |
| 1325 | end |
| 1326 | |
| 1327 | fn rd32 b view uchar 1048576 o ulong to ulong |
| 1328 | ret or rd16 b o shl rd16 b add o 2 16 |
| 1329 | end |
| 1330 | |
| 1331 | note true when b[x .. x+n) equals b[y .. y+n) |
| 1332 | fn beq b view uchar 1048576 x ulong y ulong n ulong to bool |
| 1333 | for k ulong n |
| 1334 | if ne get b add x k get b add y k |
| 1335 | ret false |
| 1336 | end |
| 1337 | end |
| 1338 | ret true |
| 1339 | end |
| 1340 | |
| 1341 | note true when the run b[t .. t+tl) occurs in b[h .. h+hl) |
| 1342 | fn bhas b view uchar 1048576 h ulong hl ulong t ulong tl ulong to bool |
| 1343 | if gt tl hl |
| 1344 | ret false |
| 1345 | end |
| 1346 | for i ulong add sub hl tl 1 |
| 1347 | if beq b add h i t tl |
| 1348 | ret true |
| 1349 | end |
| 1350 | end |
| 1351 | ret false |
| 1352 | end |
| 1353 | |
| 1354 | note score of one path plus 1000000, or 0 for no match. pm: 0 the number of terms, 1 where the path's bytes |
| 1355 | note start, 2 how many, 3 where its name's bytes start, 4 how many, 5 the path's length as written |
| 1356 | fn fscore b view uchar 1048576 toff view ulong 64 tlen view ulong 64 pm view ulong 8 to ulong |
| 1357 | nt = get pm 0 |
| 1358 | p = get pm 1 |
| 1359 | pl = get pm 2 |
| 1360 | ns = get pm 3 |
| 1361 | nl = get pm 4 |
| 1362 | ol = get pm 5 |
| 1363 | s = ulong 1000000 |
| 1364 | sum = ulong 0 |
| 1365 | for k ulong nt |
| 1366 | t = get toff k |
| 1367 | tl = get tlen k |
| 1368 | sum = add sum tl |
| 1369 | if eq tl 0 |
| 1370 | ret 0 |
| 1371 | end |
| 1372 | if bhas b ns nl t tl |
| 1373 | if beq b ns t tl |
| 1374 | s = add s 60 |
| 1375 | else |
| 1376 | s = add s 30 |
| 1377 | end |
| 1378 | else |
| 1379 | if bhas b p pl t tl |
| 1380 | s = add s 5 |
| 1381 | else |
| 1382 | ret 0 |
| 1383 | end |
| 1384 | end |
| 1385 | end |
| 1386 | s = sub s div ol 20 |
| 1387 | if eq nl sum |
| 1388 | s = add s 40 |
| 1389 | end |
| 1390 | ret s |
| 1391 | end |
| 1392 | |
| 1393 | note ---- text decisions (kind 3): is it a question, which words to search for, is it a web address ---- |
| 1394 | note The host lowercases the text and sends one 8-byte word per character: bits 0..31 an id (equal characters get |
| 1395 | note equal ids; a character of one Unicode scalar has that scalar's number), then a flag byte: 1 letter or number, |
| 1396 | note 2 trimmable white space, 4 white space, 8 white space or line end. |
| 1397 | note lists: three lists of plain words, separated by "|": 0 the words a question starts with, 1 the words a search |
| 1398 | note leaves out, 2 the endings of a bare web address. |
| 1399 | text 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 | |
| 1401 | fn cid b view uchar 1048576 i ulong to ulong |
| 1402 | ret rd32 b add 16 mul i 8 |
| 1403 | end |
| 1404 | |
| 1405 | fn cfl b view uchar 1048576 i ulong to ulong |
| 1406 | ret ulong get b add 20 mul i 8 |
| 1407 | end |
| 1408 | |
| 1409 | note true when the n characters from s are exactly one word of list sec |
| 1410 | fn inlist b view uchar 1048576 s ulong n ulong sec ulong to bool |
| 1411 | cur = ulong 0 |
| 1412 | p = ulong 0 |
| 1413 | ln = len lists |
| 1414 | while lt p ln bound 999999 |
| 1415 | e = p |
| 1416 | while lt e ln bound 999999 |
| 1417 | c = ulong get lists e |
| 1418 | if or eq c 32 eq c 124 |
| 1419 | break |
| 1420 | end |
| 1421 | e = add e 1 |
| 1422 | end |
| 1423 | if eq cur sec |
| 1424 | if eq sub e p n |
| 1425 | ok = true |
| 1426 | for k ulong n |
| 1427 | if ne cid b add s k ulong get lists add p k |
| 1428 | ok = false |
| 1429 | end |
| 1430 | end |
| 1431 | if ok |
| 1432 | ret true |
| 1433 | end |
| 1434 | end |
| 1435 | end |
| 1436 | if lt e ln |
| 1437 | if eq ulong get lists e 124 |
| 1438 | cur = add cur 1 |
| 1439 | end |
| 1440 | end |
| 1441 | p = add e 1 |
| 1442 | end |
| 1443 | ret false |
| 1444 | end |
| 1445 | |
| 1446 | note op 1: 1 when the text reads as a question: it ends with "?" and is longer than that, or it has three words |
| 1447 | note or more and starts with a question word |
| 1448 | fn qlike b view uchar 1048576 n ulong to ulong |
| 1449 | a = ulong 0 |
| 1450 | e = n |
| 1451 | while lt a e bound 999999 |
| 1452 | if eq and cfl b a 8 0 |
| 1453 | break |
| 1454 | end |
| 1455 | a = add a 1 |
| 1456 | end |
| 1457 | while gt e a bound 999999 |
| 1458 | if eq and cfl b sub e 1 8 0 |
| 1459 | break |
| 1460 | end |
| 1461 | e = sub e 1 |
| 1462 | end |
| 1463 | if gt sub e a 1 |
| 1464 | if eq cid b sub e 1 63 |
| 1465 | ret 1 |
| 1466 | end |
| 1467 | end |
| 1468 | w = ulong 0 |
| 1469 | fs = ulong 0 |
| 1470 | fl = ulong 0 |
| 1471 | i = a |
| 1472 | while lt i e bound 999999 |
| 1473 | if ne and cfl b i 4 0 |
| 1474 | i = add i 1 |
| 1475 | continue |
| 1476 | end |
| 1477 | st = i |
| 1478 | while lt i e bound 999999 |
| 1479 | if ne and cfl b i 4 0 |
| 1480 | break |
| 1481 | end |
| 1482 | i = add i 1 |
| 1483 | end |
| 1484 | if eq w 0 |
| 1485 | fs = st |
| 1486 | fl = sub i st |
| 1487 | end |
| 1488 | w = add w 1 |
| 1489 | end |
| 1490 | if lt w 3 |
| 1491 | ret 0 |
| 1492 | end |
| 1493 | if inlist b fs fl 0 |
| 1494 | ret 1 |
| 1495 | end |
| 1496 | ret 0 |
| 1497 | end |
| 1498 | |
| 1499 | note a character of a search word: a letter, a number, "-", "_" or "." |
| 1500 | fn iswc b view uchar 1048576 i ulong to bool |
| 1501 | if ne and cfl b i 1 0 |
| 1502 | ret true |
| 1503 | end |
| 1504 | c = cid b i |
| 1505 | if eq c 45 |
| 1506 | ret true |
| 1507 | end |
| 1508 | if eq c 95 |
| 1509 | ret true |
| 1510 | end |
| 1511 | ret eq c 46 |
| 1512 | end |
| 1513 | |
| 1514 | fn samec b view uchar 1048576 x ulong y ulong n ulong to bool |
| 1515 | for k ulong n |
| 1516 | if ne cid b add x k cid b add y k |
| 1517 | ret false |
| 1518 | end |
| 1519 | end |
| 1520 | ret true |
| 1521 | end |
| 1522 | |
| 1523 | note true when the word of wl characters at st also stands earlier in the text |
| 1524 | fn seen b view uchar 1048576 st ulong wl ulong to bool |
| 1525 | i = ulong 0 |
| 1526 | while lt i st bound 999999 |
| 1527 | if not iswc b i |
| 1528 | i = add i 1 |
| 1529 | continue |
| 1530 | end |
| 1531 | s0 = i |
| 1532 | while lt i st bound 999999 |
| 1533 | if not iswc b i |
| 1534 | break |
| 1535 | end |
| 1536 | i = add i 1 |
| 1537 | end |
| 1538 | if eq sub i s0 wl |
| 1539 | if samec b s0 st wl |
| 1540 | ret true |
| 1541 | end |
| 1542 | end |
| 1543 | end |
| 1544 | ret false |
| 1545 | end |
| 1546 | |
| 1547 | note op 2: the words to search for: three characters or more, not a left-out word, each once, the longest four, |
| 1548 | note longest first and in the order typed among equals. Writes the count, then where each starts and its length |
| 1549 | fn keyw b view uchar 1048576 n ulong ob edit uchar 65544 to ulong |
| 1550 | ts = new ulong 4 0 |
| 1551 | tl = new ulong 4 0 |
| 1552 | k = ulong 0 |
| 1553 | i = ulong 0 |
| 1554 | while lt i n bound 999999 |
| 1555 | if not iswc b i |
| 1556 | i = add i 1 |
| 1557 | continue |
| 1558 | end |
| 1559 | st = i |
| 1560 | while lt i n bound 999999 |
| 1561 | if not iswc b i |
| 1562 | break |
| 1563 | end |
| 1564 | i = add i 1 |
| 1565 | end |
| 1566 | wl = sub i st |
| 1567 | if lt wl 3 |
| 1568 | continue |
| 1569 | end |
| 1570 | if inlist b st wl 1 |
| 1571 | continue |
| 1572 | end |
| 1573 | if seen b st wl |
| 1574 | continue |
| 1575 | end |
| 1576 | pos = k |
| 1577 | for j ulong k |
| 1578 | if lt get tl j wl |
| 1579 | if eq pos k |
| 1580 | pos = j |
| 1581 | end |
| 1582 | end |
| 1583 | end |
| 1584 | if lt pos 4 |
| 1585 | for d ulong sub 3 pos |
| 1586 | u = sub 3 d |
| 1587 | put tl u get tl sub u 1 |
| 1588 | put ts u get ts sub u 1 |
| 1589 | end |
| 1590 | put tl pos wl |
| 1591 | put ts pos st |
| 1592 | if lt k 4 |
| 1593 | k = add k 1 |
| 1594 | end |
| 1595 | end |
| 1596 | end |
| 1597 | put ob 8 uchar k |
| 1598 | for j ulong k |
| 1599 | s = get ts j |
| 1600 | l = get tl j |
| 1601 | put ob add 9 mul j 4 uchar and s 255 |
| 1602 | put ob add 10 mul j 4 uchar shr s 8 |
| 1603 | put ob add 11 mul j 4 uchar and l 255 |
| 1604 | put ob add 12 mul j 4 uchar shr l 8 |
| 1605 | end |
| 1606 | ret add 1 mul k 4 |
| 1607 | end |
| 1608 | |
| 1609 | fn hasscheme b view uchar 1048576 n ulong to bool |
| 1610 | if lt n 7 |
| 1611 | ret false |
| 1612 | end |
| 1613 | if ne cid b 0 104 |
| 1614 | ret false |
| 1615 | end |
| 1616 | if ne cid b 1 116 |
| 1617 | ret false |
| 1618 | end |
| 1619 | if ne cid b 2 116 |
| 1620 | ret false |
| 1621 | end |
| 1622 | if ne cid b 3 112 |
| 1623 | ret false |
| 1624 | end |
| 1625 | o = ulong 4 |
| 1626 | if eq cid b 4 115 |
| 1627 | o = ulong 5 |
| 1628 | end |
| 1629 | if lt n add o 3 |
| 1630 | ret false |
| 1631 | end |
| 1632 | if ne cid b o 58 |
| 1633 | ret false |
| 1634 | end |
| 1635 | if ne cid b add o 1 47 |
| 1636 | ret false |
| 1637 | end |
| 1638 | ret eq cid b add o 2 47 |
| 1639 | end |
| 1640 | |
| 1641 | note op 3: 0 not a web address; 1 it starts with http:// or https:// (the host then checks that it names a |
| 1642 | note machine); 2 a bare address such as example.com/page (the host then checks that it parses). aux: the text's |
| 1643 | note length in bytes as written |
| 1644 | fn weba b view uchar 1048576 n ulong aux ulong to ulong |
| 1645 | if eq n 0 |
| 1646 | ret 0 |
| 1647 | end |
| 1648 | if ge aux 2000 |
| 1649 | ret 0 |
| 1650 | end |
| 1651 | for i ulong n |
| 1652 | if ne and cfl b i 4 0 |
| 1653 | ret 0 |
| 1654 | end |
| 1655 | end |
| 1656 | if hasscheme b n |
| 1657 | ret 1 |
| 1658 | end |
| 1659 | h0 = ulong 0 |
| 1660 | while lt h0 n bound 999999 |
| 1661 | if ne cid b h0 47 |
| 1662 | break |
| 1663 | end |
| 1664 | h0 = add h0 1 |
| 1665 | end |
| 1666 | h1 = h0 |
| 1667 | while lt h1 n bound 999999 |
| 1668 | if eq cid b h1 47 |
| 1669 | break |
| 1670 | end |
| 1671 | h1 = add h1 1 |
| 1672 | end |
| 1673 | parts = ulong 0 |
| 1674 | ps = h0 |
| 1675 | i = h0 |
| 1676 | while le i h1 bound 999999 |
| 1677 | atend = eq i h1 |
| 1678 | dot = false |
| 1679 | if not atend |
| 1680 | dot = eq cid b i 46 |
| 1681 | end |
| 1682 | if or atend dot |
| 1683 | if eq i ps |
| 1684 | ret 0 |
| 1685 | end |
| 1686 | parts = add parts 1 |
| 1687 | if atend |
| 1688 | if lt parts 2 |
| 1689 | ret 0 |
| 1690 | end |
| 1691 | if inlist b ps sub i ps 2 |
| 1692 | ret 2 |
| 1693 | end |
| 1694 | ret 0 |
| 1695 | end |
| 1696 | ps = add i 1 |
| 1697 | else |
| 1698 | if eq and cfl b i 1 0 |
| 1699 | if ne cid b i 45 |
| 1700 | ret 0 |
| 1701 | end |
| 1702 | end |
| 1703 | end |
| 1704 | i = add i 1 |
| 1705 | end |
| 1706 | ret 0 |
| 1707 | end |
| 1708 | |
| 1709 | note the single-character edits that turn one spelling into another, on letters and numbers only. r: 0 and 1 the |
| 1710 | note first spelling's characters [from, to), 2 and 3 the second's. Writes 4 the edits and 5 the longer length. |
| 1711 | note Returns 1, and writes nothing, when a spelling has more than 4096 letters and numbers |
| 1712 | fn edist b view uchar 1048576 r edit ulong 8 to ulong |
| 1713 | xa = new ulong 4096 0 |
| 1714 | ya = new ulong 4096 0 |
| 1715 | row = new ulong 4097 0 |
| 1716 | xc = ulong 0 |
| 1717 | yc = ulong 0 |
| 1718 | i = get r 0 |
| 1719 | x1 = get r 1 |
| 1720 | while lt i x1 bound 999999 |
| 1721 | if ne and cfl b i 1 0 |
| 1722 | if ge xc 4096 |
| 1723 | ret 1 |
| 1724 | end |
| 1725 | put xa xc cid b i |
| 1726 | xc = add xc 1 |
| 1727 | end |
| 1728 | i = add i 1 |
| 1729 | end |
| 1730 | i = get r 2 |
| 1731 | y1 = get r 3 |
| 1732 | while lt i y1 bound 999999 |
| 1733 | if ne and cfl b i 1 0 |
| 1734 | if ge yc 4096 |
| 1735 | ret 1 |
| 1736 | end |
| 1737 | put ya yc cid b i |
| 1738 | yc = add yc 1 |
| 1739 | end |
| 1740 | i = add i 1 |
| 1741 | end |
| 1742 | for j ulong add yc 1 |
| 1743 | put row j j |
| 1744 | end |
| 1745 | for k ulong xc |
| 1746 | prev = get row 0 |
| 1747 | put row 0 add k 1 |
| 1748 | xi = get xa k |
| 1749 | for j ulong yc |
| 1750 | cur = get row add j 1 |
| 1751 | v = add cur 1 |
| 1752 | w = add get row j 1 |
| 1753 | if lt w v |
| 1754 | v = w |
| 1755 | end |
| 1756 | w = prev |
| 1757 | if ne xi get ya j |
| 1758 | w = add prev 1 |
| 1759 | end |
| 1760 | if lt w v |
| 1761 | v = w |
| 1762 | end |
| 1763 | put row add j 1 v |
| 1764 | prev = cur |
| 1765 | end |
| 1766 | end |
| 1767 | m = xc |
| 1768 | if gt yc m |
| 1769 | m = yc |
| 1770 | end |
| 1771 | put r 4 get row yc |
| 1772 | put r 5 m |
| 1773 | ret 0 |
| 1774 | end |
| 1775 | |
| 1776 | note op 4: how alike two spellings are. The text is the first spelling (aux characters), then the second. Writes |
| 1777 | note the edits and the longer length, each as a 16-bit number; the host divides |
| 1778 | fn alike b view uchar 1048576 n ulong aux ulong ob edit uchar 65544 to ulong |
| 1779 | r = new ulong 8 0 |
| 1780 | bad = ulong 18446744073709551615 |
| 1781 | if gt aux n |
| 1782 | ret bad |
| 1783 | end |
| 1784 | put r 0 0 |
| 1785 | put r 1 aux |
| 1786 | put r 2 aux |
| 1787 | put r 3 n |
| 1788 | if ne edist b r 0 |
| 1789 | ret bad |
| 1790 | end |
| 1791 | d = get r 4 |
| 1792 | m = get r 5 |
| 1793 | put ob 8 uchar and d 255 |
| 1794 | put ob 9 uchar shr d 8 |
| 1795 | put ob 10 uchar and m 255 |
| 1796 | put ob 11 uchar shr m 8 |
| 1797 | ret 4 |
| 1798 | end |
| 1799 | |
| 1800 | note op 5: which run of typed words is the fix for what was heard. The text is what was heard (aux characters), |
| 1801 | note then up to four runs: the first typed word, the first two, the first three, the first four; flag 16 marks the |
| 1802 | note last character of each run. Each run is compared with what was heard (fn edist); the most alike wins, the |
| 1803 | note shorter run among equals. Returns which run (1 to 4), or 0 for no fix: the winner is less than half alike, or |
| 1804 | note is the very text that was heard (the host says which runs are: bit k-1 of sm). 255: a spelling is too long |
| 1805 | fn pick b view uchar 1048576 n ulong aux ulong sm ulong to ulong |
| 1806 | r = new ulong 8 0 |
| 1807 | if gt aux n |
| 1808 | ret 255 |
| 1809 | end |
| 1810 | bk = ulong 0 |
| 1811 | bn = ulong 0 |
| 1812 | bd = ulong 1 |
| 1813 | k = ulong 0 |
| 1814 | i = aux |
| 1815 | while lt i n bound 999999 |
| 1816 | e = i |
| 1817 | while lt e n bound 999999 |
| 1818 | f = cfl b e |
| 1819 | e = add e 1 |
| 1820 | if ne and f 16 0 |
| 1821 | break |
| 1822 | end |
| 1823 | end |
| 1824 | k = add k 1 |
| 1825 | if gt k 4 |
| 1826 | break |
| 1827 | end |
| 1828 | put r 0 0 |
| 1829 | put r 1 aux |
| 1830 | put r 2 i |
| 1831 | put r 3 e |
| 1832 | if ne edist b r 0 |
| 1833 | ret 255 |
| 1834 | end |
| 1835 | m = get r 5 |
| 1836 | nu = ulong 1 |
| 1837 | de = ulong 1 |
| 1838 | if gt m 0 |
| 1839 | nu = sub m get r 4 |
| 1840 | de = m |
| 1841 | end |
| 1842 | if eq bk 0 |
| 1843 | bk = k |
| 1844 | bn = nu |
| 1845 | bd = de |
| 1846 | else |
| 1847 | if gt mul nu bd mul bn de |
| 1848 | bk = k |
| 1849 | bn = nu |
| 1850 | bd = de |
| 1851 | end |
| 1852 | end |
| 1853 | i = e |
| 1854 | end |
| 1855 | if eq bk 0 |
| 1856 | ret 0 |
| 1857 | end |
| 1858 | if lt mul bn 2 bd |
| 1859 | ret 0 |
| 1860 | end |
| 1861 | if ne and shr sm sub bk 1 1 0 |
| 1862 | ret 0 |
| 1863 | end |
| 1864 | ret bk |
| 1865 | end |
| 1866 | |
| 1867 | note kind 3: op, the number of characters n (at most 16384), aux and 0 as four 32-bit numbers, then n character |
| 1868 | note words. Returns the reply length, or 18446744073709551615 for a malformed body or an unknown op |
| 1869 | fn texts ib view uchar 1048576 nb ulong ob edit uchar 65544 to ulong |
| 1870 | bad = ulong 18446744073709551615 |
| 1871 | if lt nb 16 |
| 1872 | ret bad |
| 1873 | end |
| 1874 | op = rd32 ib 0 |
| 1875 | n = rd32 ib 4 |
| 1876 | aux = rd32 ib 8 |
| 1877 | if gt n 16384 |
| 1878 | ret bad |
| 1879 | end |
| 1880 | if ne nb add 16 mul n 8 |
| 1881 | ret bad |
| 1882 | end |
| 1883 | if eq op 1 |
| 1884 | put ob 8 uchar qlike ib n |
| 1885 | ret 1 |
| 1886 | end |
| 1887 | if eq op 2 |
| 1888 | ret keyw ib n ob |
| 1889 | end |
| 1890 | if eq op 3 |
| 1891 | put ob 8 uchar weba ib n aux |
| 1892 | ret 1 |
| 1893 | end |
| 1894 | if eq op 4 |
| 1895 | ret alike ib n aux ob |
| 1896 | end |
| 1897 | if eq op 5 |
| 1898 | put ob 8 uchar pick ib n aux rd32 ib 12 |
| 1899 | ret 1 |
| 1900 | end |
| 1901 | ret bad |
| 1902 | end |
| 1903 | |
| 1904 | note ---- the helper process ---- |
| 1905 | note hopcore main: Hop's core as a helper process. A request is 8 bytes (kind, then body length n, both 32-bit |
| 1906 | note little-endian) and n body bytes, n at most 1048576. The reply is 8 bytes (status, then length m) and m bytes. |
| 1907 | note Status 0 is an answer; 1 an unknown kind; 2 a malformed body. End of input ends it with status 0; a body |
| 1908 | note over the limit or a short read ends it with status 3 (the host starts a fresh one). |
| 1909 | note Kind 1, names: the body is k cases of 2048 bytes (256 words, the hopfuzz input); 3 bytes back per case: |
| 1910 | note verdict, score low byte, score high byte. At most 512 cases. |
| 1911 | note Kind 2, paths: 16-bit little-endian fields: number of terms (at most 64), number of paths (at most 16000); |
| 1912 | note each term as length then bytes; each path as three lengths (its lowercased bytes, its name's lowercased |
| 1913 | note bytes, the path as written), then the path bytes, then the name bytes. 4 bytes back per path: 0 for no |
| 1914 | note match, else the score plus 1000000. |
| 1915 | note 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; |
| 1916 | note op 4 two 16-bit numbers; op 5 one byte. |
| 1917 | note 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 | |
| 1919 | note fill b[0 .. n) from stdin; false at end of input or on a short read |
| 1920 | fn rdn b edit uchar 1048576 n ulong to bool |
| 1921 | got = ulong 0 |
| 1922 | while lt got n bound 999999 |
| 1923 | k = read 0 b got sub n got |
| 1924 | if le k 0 |
| 1925 | ret false |
| 1926 | end |
| 1927 | got = add got ulong k |
| 1928 | end |
| 1929 | ret true |
| 1930 | end |
| 1931 | |
| 1932 | fn wrn b view uchar 65544 n ulong to bool |
| 1933 | p = ulong 0 |
| 1934 | while lt p n bound 999999 |
| 1935 | k = write 1 b p sub n p |
| 1936 | if le k 0 |
| 1937 | ret false |
| 1938 | end |
| 1939 | p = add p ulong k |
| 1940 | end |
| 1941 | ret true |
| 1942 | end |
| 1943 | |
| 1944 | fn put32 b edit uchar 65544 o ulong v ulong to void |
| 1945 | put b o uchar and v 255 |
| 1946 | put b add o 1 uchar and shr v 8 255 |
| 1947 | put b add o 2 uchar and shr v 16 255 |
| 1948 | put b add o 3 uchar and shr v 24 255 |
| 1949 | end |
| 1950 | |
| 1951 | note kind 1: returns the reply length, or 18446744073709551615 for a malformed body |
| 1952 | note ---- one line of a plain-text board (kind 5) ---- |
| 1953 | note A swarm's board is a text file, one post a line: |
| 1954 | note <time> <sender> (<detail>) to <recipient> + <recipient> (<detail>): <text> |
| 1955 | note Also read: several senders joined by " + ", no "to" part, recipients written "@name", a leading "- ", and |
| 1956 | note words between the sender's bracket and the colon (they stay in the text). A line that does not start with a |
| 1957 | note time is not a post. A header that does not fit the form is read plainly: the first word is the sender, the |
| 1958 | note rest is the text. The answer names every part by where it starts in the line and how long it is. |
| 1959 | note Limits: 65536 bytes of line, 600 of header, 4 senders, 16 recipients, 64 bytes and 3 words a name, 32768 bytes |
| 1960 | note of text; over a limit the part is cut at a whole character and the answer says so. |
| 1961 | |
| 1962 | note byte i of the line (the line follows the 8-byte op header of the request) |
| 1963 | fn lc b view uchar 1048576 i ulong to ulong |
| 1964 | ret ulong get b add 8 i |
| 1965 | end |
| 1966 | |
| 1967 | fn lsp c ulong to bool |
| 1968 | ret or eq c 32 eq c 9 |
| 1969 | end |
| 1970 | |
| 1971 | note the two digits at byte i of the n-byte line as a number, or 100 |
| 1972 | fn l2d b view uchar 1048576 i ulong n ulong to ulong |
| 1973 | if ge add i 1 n |
| 1974 | ret 100 |
| 1975 | end |
| 1976 | x = lc b i |
| 1977 | y = lc b add i 1 |
| 1978 | if or lt x 48 gt x 57 |
| 1979 | ret 100 |
| 1980 | end |
| 1981 | if or lt y 48 gt y 57 |
| 1982 | ret 100 |
| 1983 | end |
| 1984 | ret add mul sub x 48 10 sub y 48 |
| 1985 | end |
| 1986 | |
| 1987 | note out[k], out[k+1]: the bytes lo..hi without spaces at either end (equal when nothing is left) |
| 1988 | fn ltrim b view uchar 1048576 lo ulong hi ulong outv edit ulong 8 k ulong to void |
| 1989 | a = lo |
| 1990 | e = hi |
| 1991 | while lt a e bound 999999 |
| 1992 | if not lsp lc b a |
| 1993 | break |
| 1994 | end |
| 1995 | a = add a 1 |
| 1996 | end |
| 1997 | while gt e a bound 999999 |
| 1998 | if not lsp lc b sub e 1 |
| 1999 | break |
| 2000 | end |
| 2001 | e = sub e 1 |
| 2002 | end |
| 2003 | put outv k a |
| 2004 | put outv add k 1 e |
| 2005 | end |
| 2006 | |
| 2007 | note where a text of bytes a..e is cut to lim bytes without splitting a character (e when it is short enough) |
| 2008 | fn lclip b view uchar 1048576 a ulong e ulong lim ulong to ulong |
| 2009 | if le sub e a lim |
| 2010 | ret e |
| 2011 | end |
| 2012 | ce = add a lim |
| 2013 | back = ulong 0 |
| 2014 | while gt ce a bound 8 |
| 2015 | if ge back 3 |
| 2016 | break |
| 2017 | end |
| 2018 | if ne and lc b ce 192 128 |
| 2019 | break |
| 2020 | end |
| 2021 | ce = sub ce 1 |
| 2022 | back = add back 1 |
| 2023 | end |
| 2024 | ret ce |
| 2025 | end |
| 2026 | |
| 2027 | note "YYYY-MM-DD", then optionally "T" or one space and "HH:MM" or "HH:MM:SS", a fraction, and "Z" or an offset |
| 2028 | note 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 |
| 2029 | note seconds since 1970 as written (less the offset when one is named) plus 100000, 2 the first byte after the |
| 2030 | note time, 3 1 when the text names its zone |
| 2031 | fn ltime b view uchar 1048576 s ulong n ulong tm edit ulong 16 to ulong |
| 2032 | if gt add s 10 n |
| 2033 | ret 0 |
| 2034 | end |
| 2035 | ce = l2d b s n |
| 2036 | yy = l2d b add s 2 n |
| 2037 | mo = l2d b add s 5 n |
| 2038 | dy = l2d b add s 8 n |
| 2039 | if or eq ce 100 eq yy 100 |
| 2040 | ret 0 |
| 2041 | end |
| 2042 | if or or lt mo 1 gt mo 12 or lt dy 1 gt dy 31 |
| 2043 | ret 0 |
| 2044 | end |
| 2045 | if or ne lc b add s 4 45 ne lc b add s 7 45 |
| 2046 | ret 0 |
| 2047 | end |
| 2048 | yr = add mul ce 100 yy |
| 2049 | if lt yr 1970 |
| 2050 | ret 0 |
| 2051 | end |
| 2052 | p = add s 10 |
| 2053 | sec = ulong 0 |
| 2054 | off = ulong 0 |
| 2055 | pls = ulong 0 |
| 2056 | zoned = ulong 0 |
| 2057 | tp = ulong 0 |
| 2058 | if lt add p 5 n |
| 2059 | tp = lc b p |
| 2060 | end |
| 2061 | if or eq tp 84 eq tp 32 |
| 2062 | hr = l2d b add p 1 n |
| 2063 | mi = l2d b add p 4 n |
| 2064 | okhm = false |
| 2065 | if and lt hr 24 lt mi 60 |
| 2066 | if eq lc b add p 3 58 |
| 2067 | okhm = true |
| 2068 | end |
| 2069 | end |
| 2070 | if okhm |
| 2071 | sec = add mul hr 3600 mul mi 60 |
| 2072 | p = add p 6 |
| 2073 | if lt p n |
| 2074 | if eq lc b p 58 |
| 2075 | sx = l2d b add p 1 n |
| 2076 | if lt sx 61 |
| 2077 | sec = add sec sx |
| 2078 | p = add p 3 |
| 2079 | end |
| 2080 | end |
| 2081 | end |
| 2082 | if lt p n |
| 2083 | if eq lc b p 46 |
| 2084 | q = add p 1 |
| 2085 | while lt q n bound 32 |
| 2086 | if gt sub q p 9 |
| 2087 | break |
| 2088 | end |
| 2089 | c = lc b q |
| 2090 | if or lt c 48 gt c 57 |
| 2091 | break |
| 2092 | end |
| 2093 | q = add q 1 |
| 2094 | end |
| 2095 | if gt q add p 1 |
| 2096 | p = q |
| 2097 | end |
| 2098 | end |
| 2099 | end |
| 2100 | if lt p n |
| 2101 | zc = lc b p |
| 2102 | if or eq zc 90 eq zc 122 |
| 2103 | zoned = 1 |
| 2104 | p = add p 1 |
| 2105 | else |
| 2106 | if or eq zc 43 eq zc 45 |
| 2107 | oh = l2d b add p 1 n |
| 2108 | om = ulong 100 |
| 2109 | used = ulong 5 |
| 2110 | c3 = false |
| 2111 | if lt add p 3 n |
| 2112 | if eq lc b add p 3 58 |
| 2113 | c3 = true |
| 2114 | end |
| 2115 | end |
| 2116 | if c3 |
| 2117 | om = l2d b add p 4 n |
| 2118 | used = 6 |
| 2119 | else |
| 2120 | om = l2d b add p 3 n |
| 2121 | end |
| 2122 | if and lt oh 24 lt om 60 |
| 2123 | o = add mul oh 3600 mul om 60 |
| 2124 | if eq zc 43 |
| 2125 | off = o |
| 2126 | else |
| 2127 | pls = o |
| 2128 | end |
| 2129 | zoned = 1 |
| 2130 | p = add p used |
| 2131 | end |
| 2132 | end |
| 2133 | end |
| 2134 | end |
| 2135 | else |
| 2136 | if eq tp 84 |
| 2137 | ret 0 |
| 2138 | end |
| 2139 | end |
| 2140 | else |
| 2141 | if lt p n |
| 2142 | if eq lc b p 84 |
| 2143 | ret 0 |
| 2144 | end |
| 2145 | end |
| 2146 | end |
| 2147 | y = yr |
| 2148 | if le mo 2 |
| 2149 | y = sub yr 1 |
| 2150 | end |
| 2151 | era = div y 400 |
| 2152 | yoe = sub y mul era 400 |
| 2153 | mm = add mo 9 |
| 2154 | if gt mo 2 |
| 2155 | mm = sub mo 3 |
| 2156 | end |
| 2157 | doy = sub add div add mul 153 mm 2 5 dy 1 |
| 2158 | doe = add sub add mul yoe 365 div yoe 4 div yoe 100 doy |
| 2159 | days = sub add mul era 146097 doe 719468 |
| 2160 | put tm 1 sub add add add mul days 86400 sec 100000 pls off |
| 2161 | put tm 2 p |
| 2162 | put tm 3 zoned |
| 2163 | ret 1 |
| 2164 | end |
| 2165 | |
| 2166 | note one name from byte lo, stopping before " + ", before "(" and, on the sender side (side 1), before " to " |
| 2167 | note and " @". A bracket right after the name is its detail. nr: 0 and 1 the name, 2 and 3 the detail, 4 the first |
| 2168 | note byte after the name, its bracket and the spaces that follow, 5 1 when there was a bracket |
| 2169 | fn lname b view uchar 1048576 lo ulong limit ulong side ulong nr edit ulong 8 to void |
| 2170 | i = lo |
| 2171 | while lt i limit bound 999999 |
| 2172 | if not lsp lc b i |
| 2173 | break |
| 2174 | end |
| 2175 | i = add i 1 |
| 2176 | end |
| 2177 | start = i |
| 2178 | while lt i limit bound 999999 |
| 2179 | c = lc b i |
| 2180 | if eq c 40 |
| 2181 | break |
| 2182 | end |
| 2183 | stop = false |
| 2184 | if eq c 32 |
| 2185 | if lt add i 1 limit |
| 2186 | d = lc b add i 1 |
| 2187 | if eq d 43 |
| 2188 | if ge add i 2 limit |
| 2189 | stop = true |
| 2190 | else |
| 2191 | if eq lc b add i 2 32 |
| 2192 | stop = true |
| 2193 | end |
| 2194 | end |
| 2195 | end |
| 2196 | if eq side 1 |
| 2197 | if eq d 64 |
| 2198 | stop = true |
| 2199 | end |
| 2200 | if eq d 116 |
| 2201 | if lt add i 2 limit |
| 2202 | if eq lc b add i 2 111 |
| 2203 | if ge add i 3 limit |
| 2204 | stop = true |
| 2205 | else |
| 2206 | if eq lc b add i 3 32 |
| 2207 | stop = true |
| 2208 | end |
| 2209 | end |
| 2210 | end |
| 2211 | end |
| 2212 | end |
| 2213 | end |
| 2214 | end |
| 2215 | end |
| 2216 | if stop |
| 2217 | break |
| 2218 | end |
| 2219 | i = add i 1 |
| 2220 | end |
| 2221 | ltrim b start i nr 0 |
| 2222 | while lt i limit bound 999999 |
| 2223 | if not lsp lc b i |
| 2224 | break |
| 2225 | end |
| 2226 | i = add i 1 |
| 2227 | end |
| 2228 | put nr 2 0 |
| 2229 | put nr 3 0 |
| 2230 | put nr 5 0 |
| 2231 | if lt i limit |
| 2232 | if eq lc b i 40 |
| 2233 | depth = ulong 0 |
| 2234 | j = i |
| 2235 | while lt j limit bound 999999 |
| 2236 | cj = lc b j |
| 2237 | if eq cj 40 |
| 2238 | depth = add depth 1 |
| 2239 | else |
| 2240 | if eq cj 41 |
| 2241 | depth = sub depth 1 |
| 2242 | if eq depth 0 |
| 2243 | break |
| 2244 | end |
| 2245 | end |
| 2246 | end |
| 2247 | j = add j 1 |
| 2248 | end |
| 2249 | ltrim b add i 1 j nr 2 |
| 2250 | put nr 5 1 |
| 2251 | i = limit |
| 2252 | if lt j limit |
| 2253 | i = add j 1 |
| 2254 | end |
| 2255 | while lt i limit bound 999999 |
| 2256 | if not lsp lc b i |
| 2257 | break |
| 2258 | end |
| 2259 | i = add i 1 |
| 2260 | end |
| 2261 | end |
| 2262 | end |
| 2263 | put nr 4 i |
| 2264 | end |
| 2265 | |
| 2266 | note a name fits when it has 1 to 64 bytes and at most 3 words |
| 2267 | fn lfits b view uchar 1048576 a ulong e ulong to bool |
| 2268 | if le e a |
| 2269 | ret false |
| 2270 | end |
| 2271 | if gt sub e a 64 |
| 2272 | ret false |
| 2273 | end |
| 2274 | n = ulong 0 |
| 2275 | inw = false |
| 2276 | i = a |
| 2277 | while lt i e bound 999999 |
| 2278 | if lsp lc b i |
| 2279 | inw = false |
| 2280 | else |
| 2281 | if not inw |
| 2282 | inw = true |
| 2283 | n = add n 1 |
| 2284 | end |
| 2285 | end |
| 2286 | i = add i 1 |
| 2287 | end |
| 2288 | ret le n 3 |
| 2289 | end |
| 2290 | |
| 2291 | note "all", "all lanes", "everyone" (any case, a leading "@" dropped): the whole board, not one member. |
| 2292 | note The name fits (lfits), so its key has at most 64 bytes |
| 2293 | fn levery b view uchar 1048576 a ulong e ulong to bool |
| 2294 | k = new uchar 80 0 |
| 2295 | n = ulong 0 |
| 2296 | i = a |
| 2297 | if lt i e |
| 2298 | if eq lc b i 64 |
| 2299 | i = add i 1 |
| 2300 | end |
| 2301 | end |
| 2302 | gap = false |
| 2303 | while lt i e bound 999999 |
| 2304 | c = lc b i |
| 2305 | if lsp c |
| 2306 | gap = true |
| 2307 | else |
| 2308 | if and gap gt n 0 |
| 2309 | put k n uchar 45 |
| 2310 | n = add n 1 |
| 2311 | end |
| 2312 | gap = false |
| 2313 | if and ge c 65 le c 90 |
| 2314 | c = add c 32 |
| 2315 | end |
| 2316 | put k n uchar c |
| 2317 | n = add n 1 |
| 2318 | end |
| 2319 | i = add i 1 |
| 2320 | end |
| 2321 | if lt n 3 |
| 2322 | ret false |
| 2323 | end |
| 2324 | al = and and eq ulong get k 0 97 eq ulong get k 1 108 eq ulong get k 2 108 |
| 2325 | if eq n 3 |
| 2326 | ret al |
| 2327 | end |
| 2328 | if gt n 4 |
| 2329 | if and al eq ulong get k 3 45 |
| 2330 | ret true |
| 2331 | end |
| 2332 | end |
| 2333 | if ne n 8 |
| 2334 | ret false |
| 2335 | end |
| 2336 | ev = 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 |
| 2337 | ev = 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 |
| 2338 | ret ev |
| 2339 | end |
| 2340 | |
| 2341 | note where a part starts and how long it is, at byte o of the answer |
| 2342 | fn lput ob edit uchar 65544 o ulong s ulong e ulong to void |
| 2343 | l = ulong 0 |
| 2344 | if gt e s |
| 2345 | l = sub e s |
| 2346 | end |
| 2347 | put32 ob add 8 o s |
| 2348 | put32 ob add 12 o l |
| 2349 | end |
| 2350 | |
| 2351 | note 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, |
| 2352 | note 2 1 when something went over a limit, 3 the senders, 4 the recipients; 8 the time (64-bit, seconds since 1970 |
| 2353 | note plus 100000); 16 the text; from 24 sixteen bytes a sender (name, detail), from 88 sixteen a recipient. Each |
| 2354 | note part is two 32-bit numbers: where it starts in the line and its length |
| 2355 | fn lline b view uchar 1048576 n0 ulong ob edit uchar 65544 to ulong |
| 2356 | tm = new ulong 16 0 |
| 2357 | nr = new ulong 8 0 |
| 2358 | for z ulong 344 |
| 2359 | put ob add 8 z uchar 0 |
| 2360 | end |
| 2361 | n = n0 |
| 2362 | clipped = ulong 0 |
| 2363 | if gt n 65536 |
| 2364 | n = lclip b 0 n 65536 |
| 2365 | clipped = 1 |
| 2366 | end |
| 2367 | put ob 10 uchar clipped |
| 2368 | en = n |
| 2369 | while gt en 0 bound 999999 |
| 2370 | c = lc b sub en 1 |
| 2371 | blank = lsp c |
| 2372 | if or eq c 13 eq c 10 |
| 2373 | blank = true |
| 2374 | end |
| 2375 | if not blank |
| 2376 | break |
| 2377 | end |
| 2378 | en = sub en 1 |
| 2379 | end |
| 2380 | p = ulong 0 |
| 2381 | while lt p en bound 999999 |
| 2382 | if not lsp lc b p |
| 2383 | break |
| 2384 | end |
| 2385 | p = add p 1 |
| 2386 | end |
| 2387 | if lt add p 1 en |
| 2388 | if and eq lc b p 45 eq lc b add p 1 32 |
| 2389 | p = add p 2 |
| 2390 | end |
| 2391 | end |
| 2392 | if eq ltime b p n tm 0 |
| 2393 | ret 344 |
| 2394 | end |
| 2395 | te = get tm 2 |
| 2396 | if ge te en |
| 2397 | ret 344 |
| 2398 | end |
| 2399 | if not lsp lc b te |
| 2400 | ret 344 |
| 2401 | end |
| 2402 | p = te |
| 2403 | while lt p en bound 999999 |
| 2404 | if not lsp lc b p |
| 2405 | break |
| 2406 | end |
| 2407 | p = add p 1 |
| 2408 | end |
| 2409 | if ge p en |
| 2410 | ret 344 |
| 2411 | end |
| 2412 | put ob 8 uchar 1 |
| 2413 | tv = get tm 1 |
| 2414 | put32 ob 16 tv |
| 2415 | put32 ob 20 shr tv 32 |
| 2416 | bst = p |
| 2417 | colon = ulong 0 |
| 2418 | hasc = false |
| 2419 | depth = ulong 0 |
| 2420 | i = p |
| 2421 | while lt i en bound 999999 |
| 2422 | if ge sub i p 600 |
| 2423 | break |
| 2424 | end |
| 2425 | c = lc b i |
| 2426 | if eq c 40 |
| 2427 | depth = add depth 1 |
| 2428 | else |
| 2429 | if eq c 41 |
| 2430 | if gt depth 0 |
| 2431 | depth = sub depth 1 |
| 2432 | end |
| 2433 | else |
| 2434 | if and eq c 58 eq depth 0 |
| 2435 | nx = true |
| 2436 | if lt add i 1 en |
| 2437 | if ne lc b add i 1 32 |
| 2438 | nx = false |
| 2439 | end |
| 2440 | end |
| 2441 | if nx |
| 2442 | colon = i |
| 2443 | hasc = true |
| 2444 | break |
| 2445 | end |
| 2446 | end |
| 2447 | end |
| 2448 | end |
| 2449 | i = add i 1 |
| 2450 | end |
| 2451 | fits = hasc |
| 2452 | ts = add colon 1 |
| 2453 | q = p |
| 2454 | md = ulong 0 |
| 2455 | ns = ulong 0 |
| 2456 | nrc = ulong 0 |
| 2457 | tall = ulong 0 |
| 2458 | rnd = ulong 0 |
| 2459 | while and and fits eq md 0 lt rnd 64 bound 100 |
| 2460 | rnd = add rnd 1 |
| 2461 | lname b q colon 1 nr |
| 2462 | if not lfits b get nr 0 get nr 1 |
| 2463 | fits = false |
| 2464 | break |
| 2465 | end |
| 2466 | if lt ns 4 |
| 2467 | lput ob add 24 mul ns 16 get nr 0 get nr 1 |
| 2468 | lput ob add 32 mul ns 16 get nr 2 get nr 3 |
| 2469 | ns = add ns 1 |
| 2470 | else |
| 2471 | clipped = 1 |
| 2472 | end |
| 2473 | x = get nr 4 |
| 2474 | if ge x colon |
| 2475 | md = 3 |
| 2476 | else |
| 2477 | cx = lc b x |
| 2478 | did = false |
| 2479 | if eq cx 43 |
| 2480 | sp = true |
| 2481 | if lt add x 1 colon |
| 2482 | if ne lc b add x 1 32 |
| 2483 | sp = false |
| 2484 | end |
| 2485 | end |
| 2486 | if sp |
| 2487 | q = add x 1 |
| 2488 | did = true |
| 2489 | end |
| 2490 | end |
| 2491 | if not did |
| 2492 | if eq cx 116 |
| 2493 | if lt add x 2 colon |
| 2494 | if and eq lc b add x 1 111 eq lc b add x 2 32 |
| 2495 | md = 1 |
| 2496 | q = add x 3 |
| 2497 | did = true |
| 2498 | end |
| 2499 | end |
| 2500 | end |
| 2501 | end |
| 2502 | if not did |
| 2503 | if eq cx 64 |
| 2504 | md = 2 |
| 2505 | q = x |
| 2506 | did = true |
| 2507 | end |
| 2508 | end |
| 2509 | if not did |
| 2510 | if eq get nr 5 1 |
| 2511 | md = 3 |
| 2512 | ts = x |
| 2513 | else |
| 2514 | fits = false |
| 2515 | end |
| 2516 | end |
| 2517 | end |
| 2518 | end |
| 2519 | if and fits eq md 0 |
| 2520 | fits = false |
| 2521 | end |
| 2522 | rnd = 0 |
| 2523 | while and and fits eq md 1 lt rnd 64 bound 100 |
| 2524 | rnd = add rnd 1 |
| 2525 | lname b q colon 0 nr |
| 2526 | a = get nr 0 |
| 2527 | e = get nr 1 |
| 2528 | if gt e a |
| 2529 | if eq lc b a 64 |
| 2530 | a = add a 1 |
| 2531 | end |
| 2532 | end |
| 2533 | if not lfits b a e |
| 2534 | fits = false |
| 2535 | break |
| 2536 | end |
| 2537 | if levery b a e |
| 2538 | tall = 1 |
| 2539 | else |
| 2540 | if lt nrc 16 |
| 2541 | lput ob add 88 mul nrc 16 a e |
| 2542 | lput ob add 96 mul nrc 16 get nr 2 get nr 3 |
| 2543 | nrc = add nrc 1 |
| 2544 | else |
| 2545 | clipped = 1 |
| 2546 | end |
| 2547 | end |
| 2548 | x = get nr 4 |
| 2549 | if ge x colon |
| 2550 | md = 3 |
| 2551 | else |
| 2552 | plus = false |
| 2553 | if eq lc b x 43 |
| 2554 | plus = true |
| 2555 | if lt add x 1 colon |
| 2556 | if ne lc b add x 1 32 |
| 2557 | plus = false |
| 2558 | end |
| 2559 | end |
| 2560 | end |
| 2561 | if plus |
| 2562 | q = add x 1 |
| 2563 | else |
| 2564 | fits = false |
| 2565 | end |
| 2566 | end |
| 2567 | end |
| 2568 | if and fits eq md 1 |
| 2569 | fits = false |
| 2570 | end |
| 2571 | rnd = 0 |
| 2572 | while and and fits eq md 2 lt rnd 64 bound 100 |
| 2573 | rnd = add rnd 1 |
| 2574 | while lt q colon bound 999999 |
| 2575 | c = lc b q |
| 2576 | if not or lsp c eq c 43 |
| 2577 | break |
| 2578 | end |
| 2579 | q = add q 1 |
| 2580 | end |
| 2581 | if ge q colon |
| 2582 | md = 3 |
| 2583 | break |
| 2584 | end |
| 2585 | if ne lc b q 64 |
| 2586 | fits = false |
| 2587 | break |
| 2588 | end |
| 2589 | j = add q 1 |
| 2590 | while lt j colon bound 999999 |
| 2591 | if lsp lc b j |
| 2592 | break |
| 2593 | end |
| 2594 | j = add j 1 |
| 2595 | end |
| 2596 | ltrim b add q 1 j nr 0 |
| 2597 | a = get nr 0 |
| 2598 | e = get nr 1 |
| 2599 | if not lfits b a e |
| 2600 | fits = false |
| 2601 | break |
| 2602 | end |
| 2603 | if levery b a e |
| 2604 | tall = 1 |
| 2605 | else |
| 2606 | if lt nrc 16 |
| 2607 | lput ob add 88 mul nrc 16 a e |
| 2608 | nrc = add nrc 1 |
| 2609 | else |
| 2610 | clipped = 1 |
| 2611 | end |
| 2612 | end |
| 2613 | q = j |
| 2614 | end |
| 2615 | if and fits eq md 2 |
| 2616 | fits = false |
| 2617 | end |
| 2618 | if not fits |
| 2619 | for z ulong 320 |
| 2620 | put ob add 32 z uchar 0 |
| 2621 | end |
| 2622 | ns = 1 |
| 2623 | nrc = 0 |
| 2624 | tall = 0 |
| 2625 | j = bst |
| 2626 | while lt j en bound 999999 |
| 2627 | if lsp lc b j |
| 2628 | break |
| 2629 | end |
| 2630 | j = add j 1 |
| 2631 | end |
| 2632 | ltrim b bst j nr 0 |
| 2633 | a = get nr 0 |
| 2634 | e = get nr 1 |
| 2635 | if gt sub e a 1 |
| 2636 | if eq lc b sub e 1 58 |
| 2637 | e = sub e 1 |
| 2638 | end |
| 2639 | end |
| 2640 | if gt sub e a 64 |
| 2641 | e = lclip b a e 64 |
| 2642 | clipped = 1 |
| 2643 | end |
| 2644 | lput ob 24 a e |
| 2645 | ts = j |
| 2646 | end |
| 2647 | ltrim b ts en nr 0 |
| 2648 | a = get nr 0 |
| 2649 | e = get nr 1 |
| 2650 | if gt e a |
| 2651 | if gt sub e a 32768 |
| 2652 | e = lclip b a e 32768 |
| 2653 | clipped = 1 |
| 2654 | end |
| 2655 | end |
| 2656 | lput ob 16 a e |
| 2657 | put ob 9 uchar tall |
| 2658 | put ob 10 uchar clipped |
| 2659 | put ob 11 uchar ns |
| 2660 | put ob 12 uchar nrc |
| 2661 | ret 344 |
| 2662 | end |
| 2663 | |
| 2664 | note ---- who a post calls and which posts it cites (kind 5 op 3) ---- |
| 2665 | note "@name", "@all", "@#channel" and "#seq" in the text of a post. A mention counts only at a word start: the |
| 2666 | note character before "@" or "#" must not be a name character, and the name must not run on into more name |
| 2667 | note characters. Positions in these functions are places in the request: the text is the bytes t0..t1. |
| 2668 | |
| 2669 | note the character that starts at byte i, as a code point; 4294967295 at or after t1. A broken sequence gives its |
| 2670 | note first byte |
| 2671 | fn rune b view uchar 1048576 i ulong t1 ulong to ulong |
| 2672 | if ge i t1 |
| 2673 | ret 4294967295 |
| 2674 | end |
| 2675 | b0 = ulong get b i |
| 2676 | if or lt b0 128 ge b0 248 |
| 2677 | ret b0 |
| 2678 | end |
| 2679 | if lt b0 192 |
| 2680 | ret b0 |
| 2681 | end |
| 2682 | need = ulong 1 |
| 2683 | cp = and b0 31 |
| 2684 | if ge b0 224 |
| 2685 | need = 2 |
| 2686 | cp = and b0 15 |
| 2687 | end |
| 2688 | if ge b0 240 |
| 2689 | need = 3 |
| 2690 | cp = and b0 7 |
| 2691 | end |
| 2692 | k = ulong 1 |
| 2693 | while le k need bound 8 |
| 2694 | if ge add i k t1 |
| 2695 | ret b0 |
| 2696 | end |
| 2697 | c = ulong get b add i k |
| 2698 | if ne and c 192 128 |
| 2699 | ret b0 |
| 2700 | end |
| 2701 | cp = or shl cp 6 and c 63 |
| 2702 | k = add k 1 |
| 2703 | end |
| 2704 | ret cp |
| 2705 | end |
| 2706 | |
| 2707 | note the character that ends just before byte e; 4294967295 at the start of the text |
| 2708 | fn runeb b view uchar 1048576 e ulong t0 ulong t1 ulong to ulong |
| 2709 | if or le e t0 gt e t1 |
| 2710 | ret 4294967295 |
| 2711 | end |
| 2712 | i = sub e 1 |
| 2713 | back = ulong 0 |
| 2714 | while gt i t0 bound 8 |
| 2715 | if ge back 3 |
| 2716 | break |
| 2717 | end |
| 2718 | if ne and ulong get b i 192 128 |
| 2719 | break |
| 2720 | end |
| 2721 | i = sub i 1 |
| 2722 | back = add back 1 |
| 2723 | end |
| 2724 | ret rune b i t1 |
| 2725 | end |
| 2726 | |
| 2727 | note can this character be part of a name? Letters, digits, "_" and "-"; outside ASCII everything except the |
| 2728 | note blocks that hold punctuation, symbols and emoji |
| 2729 | fn namer cp ulong to bool |
| 2730 | if eq cp 4294967295 |
| 2731 | ret false |
| 2732 | end |
| 2733 | if lt cp 128 |
| 2734 | if and ge cp 48 le cp 57 |
| 2735 | ret true |
| 2736 | end |
| 2737 | if and ge cp 65 le cp 90 |
| 2738 | ret true |
| 2739 | end |
| 2740 | if and ge cp 97 le cp 122 |
| 2741 | ret true |
| 2742 | end |
| 2743 | ret or eq cp 95 eq cp 45 |
| 2744 | end |
| 2745 | if or or lt cp 192 eq cp 215 eq cp 247 |
| 2746 | ret false |
| 2747 | end |
| 2748 | if and ge cp 8192 le cp 11263 |
| 2749 | ret false |
| 2750 | end |
| 2751 | if and ge cp 12288 le cp 12351 |
| 2752 | ret false |
| 2753 | end |
| 2754 | if and ge cp 65072 le cp 65135 |
| 2755 | ret false |
| 2756 | end |
| 2757 | if or and ge cp 65280 le cp 65295 and ge cp 65306 le cp 65312 |
| 2758 | ret false |
| 2759 | end |
| 2760 | if or and ge cp 65339 le cp 65344 and ge cp 65371 le cp 65381 |
| 2761 | ret false |
| 2762 | end |
| 2763 | if and ge cp 126976 le cp 129791 |
| 2764 | ret false |
| 2765 | end |
| 2766 | ret true |
| 2767 | end |
| 2768 | |
| 2769 | fn lowc c ulong to ulong |
| 2770 | if and ge c 65 le c 90 |
| 2771 | ret add c 32 |
| 2772 | end |
| 2773 | ret c |
| 2774 | end |
| 2775 | |
| 2776 | note true when the ln bytes at na stand at byte pos of the text (ASCII letters without case) and no name |
| 2777 | note character follows them |
| 2778 | fn nameat b view uchar 1048576 pos ulong na ulong ln ulong t1 ulong to bool |
| 2779 | if eq ln 0 |
| 2780 | ret false |
| 2781 | end |
| 2782 | if gt add pos ln t1 |
| 2783 | ret false |
| 2784 | end |
| 2785 | for k ulong ln |
| 2786 | if ne lowc ulong get b add pos k lowc ulong get b add na k |
| 2787 | ret false |
| 2788 | end |
| 2789 | end |
| 2790 | ret not namer rune b add pos ln t1 |
| 2791 | end |
| 2792 | |
| 2793 | note "all" at byte pos, and no name character after it |
| 2794 | fn allat b view uchar 1048576 pos ulong t1 ulong to bool |
| 2795 | if gt add pos 3 t1 |
| 2796 | ret false |
| 2797 | end |
| 2798 | if ne lowc ulong get b pos 97 |
| 2799 | ret false |
| 2800 | end |
| 2801 | if ne lowc ulong get b add pos 1 108 |
| 2802 | ret false |
| 2803 | end |
| 2804 | if ne lowc ulong get b add pos 2 108 |
| 2805 | ret false |
| 2806 | end |
| 2807 | ret not namer rune b add pos 3 t1 |
| 2808 | end |
| 2809 | |
| 2810 | note a member called "<prefix>-<digits>" also answers to "@<prefix>": the length of that prefix, or 0 |
| 2811 | fn cprefix b view uchar 1048576 na ulong nl ulong to ulong |
| 2812 | i = nl |
| 2813 | while gt i 0 bound 999999 |
| 2814 | c = ulong get b add na sub i 1 |
| 2815 | if or lt c 48 gt c 57 |
| 2816 | break |
| 2817 | end |
| 2818 | i = sub i 1 |
| 2819 | end |
| 2820 | if eq i nl |
| 2821 | ret 0 |
| 2822 | end |
| 2823 | if lt i 2 |
| 2824 | ret 0 |
| 2825 | end |
| 2826 | if ne ulong get b add na sub i 1 45 |
| 2827 | ret 0 |
| 2828 | end |
| 2829 | ret sub i 1 |
| 2830 | end |
| 2831 | |
| 2832 | note the length of a channel name at byte pos (after "@#"): a letter, then letters, digits and "-", 24 at most |
| 2833 | fn chlen b view uchar 1048576 pos ulong t1 ulong to ulong |
| 2834 | if ge pos t1 |
| 2835 | ret 0 |
| 2836 | end |
| 2837 | f = lowc ulong get b pos |
| 2838 | if or lt f 97 gt f 122 |
| 2839 | ret 0 |
| 2840 | end |
| 2841 | j = pos |
| 2842 | while lt j t1 bound 64 |
| 2843 | if ge sub j pos 25 |
| 2844 | break |
| 2845 | end |
| 2846 | c = lowc ulong get b j |
| 2847 | okc = and ge c 97 le c 122 |
| 2848 | if and ge c 48 le c 57 |
| 2849 | okc = true |
| 2850 | end |
| 2851 | if eq c 45 |
| 2852 | okc = true |
| 2853 | end |
| 2854 | if not okc |
| 2855 | break |
| 2856 | end |
| 2857 | j = add j 1 |
| 2858 | end |
| 2859 | n = sub j pos |
| 2860 | if gt n 24 |
| 2861 | ret 0 |
| 2862 | end |
| 2863 | if namer rune b j t1 |
| 2864 | ret 0 |
| 2865 | end |
| 2866 | ret n |
| 2867 | end |
| 2868 | |
| 2869 | note part idx of the answer: where it starts in the text, its length, its kind (1 a member, 2 all, 3 a channel, |
| 2870 | note 4 a cited post) and its value (the member's number, or the post's) |
| 2871 | fn semit ob edit uchar 65544 idx ulong s ulong l ulong kind ulong v ulong to void |
| 2872 | o = add 16 mul idx 16 |
| 2873 | put32 ob o s |
| 2874 | put32 ob add o 4 l |
| 2875 | put32 ob add o 8 kind |
| 2876 | put32 ob add o 12 v |
| 2877 | end |
| 2878 | |
| 2879 | note 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 |
| 2880 | note and its bytes, then the text (900000 bytes at most). head is the highest post number that may be cited; 0 |
| 2881 | note turns citations off. The answer: a 16-bit count of parts, a byte that is 1 when the post has more than 128 |
| 2882 | note parts (the rest is not marked), then from byte 8 sixteen bytes a part (semit), in text order. Parts that |
| 2883 | note start at one byte are kept or dropped together |
| 2884 | fn spans b view uchar 1048576 n ulong head ulong ob edit uchar 65544 to ulong |
| 2885 | noff = new ulong 96 0 |
| 2886 | nlen = new ulong 96 0 |
| 2887 | npre = new ulong 96 0 |
| 2888 | bad = ulong 18446744073709551615 |
| 2889 | if lt n 2 |
| 2890 | ret bad |
| 2891 | end |
| 2892 | nn = rd16 b 8 |
| 2893 | if gt nn 96 |
| 2894 | ret bad |
| 2895 | end |
| 2896 | lim = add 8 n |
| 2897 | p = ulong 10 |
| 2898 | for k ulong nn |
| 2899 | if gt add p 2 lim |
| 2900 | ret bad |
| 2901 | end |
| 2902 | l = rd16 b p |
| 2903 | p = add p 2 |
| 2904 | if gt add p l lim |
| 2905 | ret bad |
| 2906 | end |
| 2907 | put noff k p |
| 2908 | put nlen k l |
| 2909 | put npre k cprefix b p l |
| 2910 | p = add p l |
| 2911 | end |
| 2912 | t0 = p |
| 2913 | t1 = lim |
| 2914 | if gt sub t1 t0 900000 |
| 2915 | ret bad |
| 2916 | end |
| 2917 | cnt = ulong 0 |
| 2918 | clipped = ulong 0 |
| 2919 | i = t0 |
| 2920 | while lt i t1 bound 999999 |
| 2921 | c = ulong get b i |
| 2922 | st = ulong 1 |
| 2923 | g = ulong 0 |
| 2924 | mark = or eq c 64 eq c 35 |
| 2925 | if mark |
| 2926 | if namer runeb b i t0 t1 |
| 2927 | mark = false |
| 2928 | end |
| 2929 | end |
| 2930 | if mark |
| 2931 | if eq c 64 |
| 2932 | nxt = ulong 0 |
| 2933 | if lt add i 1 t1 |
| 2934 | nxt = ulong get b add i 1 |
| 2935 | end |
| 2936 | if eq nxt 35 |
| 2937 | cl = chlen b add i 2 t1 |
| 2938 | if gt cl 0 |
| 2939 | semit ob cnt sub i t0 add cl 2 3 0 |
| 2940 | g = 1 |
| 2941 | st = add cl 2 |
| 2942 | end |
| 2943 | else |
| 2944 | for k ulong nn |
| 2945 | if nameat b add i 1 get noff k get nlen k t1 |
| 2946 | semit ob add cnt g sub i t0 add get nlen k 1 1 k |
| 2947 | g = add g 1 |
| 2948 | end |
| 2949 | end |
| 2950 | if eq g 0 |
| 2951 | if allat b add i 1 t1 |
| 2952 | semit ob add cnt g sub i t0 4 2 0 |
| 2953 | g = 1 |
| 2954 | end |
| 2955 | end |
| 2956 | k2 = ulong 0 |
| 2957 | while lt k2 nn bound 128 |
| 2958 | if gt g 0 |
| 2959 | break |
| 2960 | end |
| 2961 | pk = get npre k2 |
| 2962 | if gt pk 0 |
| 2963 | if nameat b add i 1 get noff k2 pk t1 |
| 2964 | j = k2 |
| 2965 | while lt j nn bound 128 |
| 2966 | if eq get npre j pk |
| 2967 | if nameat b add i 1 get noff j pk t1 |
| 2968 | semit ob add cnt g sub i t0 add pk 1 1 j |
| 2969 | g = add g 1 |
| 2970 | end |
| 2971 | end |
| 2972 | j = add j 1 |
| 2973 | end |
| 2974 | end |
| 2975 | end |
| 2976 | k2 = add k2 1 |
| 2977 | end |
| 2978 | end |
| 2979 | else |
| 2980 | if gt head 0 |
| 2981 | if ne runeb b i t0 t1 38 |
| 2982 | j = add i 1 |
| 2983 | v = ulong 0 |
| 2984 | while lt j t1 bound 16 |
| 2985 | if gt sub j i 9 |
| 2986 | break |
| 2987 | end |
| 2988 | d = ulong get b j |
| 2989 | if or lt d 48 gt d 57 |
| 2990 | break |
| 2991 | end |
| 2992 | v = add mul v 10 sub d 48 |
| 2993 | j = add j 1 |
| 2994 | end |
| 2995 | if gt j add i 1 |
| 2996 | if and ge v 1 le v head |
| 2997 | if not namer rune b j t1 |
| 2998 | semit ob cnt sub i t0 sub j i 4 v |
| 2999 | g = 1 |
| 3000 | st = sub j i |
| 3001 | end |
| 3002 | end |
| 3003 | end |
| 3004 | end |
| 3005 | end |
| 3006 | end |
| 3007 | end |
| 3008 | if gt g 0 |
| 3009 | if gt add cnt g 128 |
| 3010 | clipped = 1 |
| 3011 | break |
| 3012 | end |
| 3013 | cnt = add cnt g |
| 3014 | end |
| 3015 | i = add i st |
| 3016 | end |
| 3017 | put ob 8 uchar and cnt 255 |
| 3018 | put ob 9 uchar shr cnt 8 |
| 3019 | put ob 10 uchar clipped |
| 3020 | for z ulong 5 |
| 3021 | put ob add 11 z uchar 0 |
| 3022 | end |
| 3023 | ret add 8 mul cnt 16 |
| 3024 | end |
| 3025 | |
| 3026 | note ---- who a post addresses (kind 5 op 4) ---- |
| 3027 | note the members its header names, the members its text calls with "@name" or reaches through "@#channel", and |
| 3028 | note whether it is to everyone. The sender is left out. |
| 3029 | |
| 3030 | note two runs of bytes of the request, equal when ASCII letters are compared without case |
| 3031 | fn eqf b view uchar 1048576 x ulong xl ulong y ulong yl ulong to bool |
| 3032 | if ne xl yl |
| 3033 | ret false |
| 3034 | end |
| 3035 | for k ulong xl |
| 3036 | if ne lowc ulong get b add x k lowc ulong get b add y k |
| 3037 | ret false |
| 3038 | end |
| 3039 | end |
| 3040 | ret true |
| 3041 | end |
| 3042 | |
| 3043 | note "main", "all" and "here" are not channels anyone follows |
| 3044 | fn chplain b view uchar 1048576 x ulong n ulong to bool |
| 3045 | if eq n 3 |
| 3046 | ret 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 |
| 3047 | end |
| 3048 | if ne n 4 |
| 3049 | ret false |
| 3050 | end |
| 3051 | c0 = lowc ulong get b x |
| 3052 | c1 = lowc ulong get b add x 1 |
| 3053 | c2 = lowc ulong get b add x 2 |
| 3054 | c3 = lowc ulong get b add x 3 |
| 3055 | if and and eq c0 109 eq c1 97 and eq c2 105 eq c3 110 |
| 3056 | ret true |
| 3057 | end |
| 3058 | ret and and eq c0 104 eq c1 101 and eq c2 114 eq c3 101 |
| 3059 | end |
| 3060 | |
| 3061 | note does a member follow the channel named by the xl bytes at x? cp is where the member's channel list starts: a |
| 3062 | note count, then each channel as a 16-bit length and its bytes. An empty list is the role's default: everyone but a |
| 3063 | note worker (role 0) follows every channel. "*" follows every channel |
| 3064 | fn follows b view uchar 1048576 role ulong cp ulong x ulong xl ulong to bool |
| 3065 | cc = ulong get b cp |
| 3066 | if eq cc 0 |
| 3067 | ret ne role 0 |
| 3068 | end |
| 3069 | p = add cp 1 |
| 3070 | for i ulong cc |
| 3071 | l = rd16 b p |
| 3072 | if eq l 1 |
| 3073 | if eq ulong get b add p 2 42 |
| 3074 | ret true |
| 3075 | end |
| 3076 | end |
| 3077 | if eqf b add p 2 l x xl |
| 3078 | ret true |
| 3079 | end |
| 3080 | p = add add p 2 l |
| 3081 | end |
| 3082 | ret false |
| 3083 | end |
| 3084 | |
| 3085 | note op 4: n bytes after the op header: 16-bit counts of members (96 at most), parts (128) and header recipients |
| 3086 | note (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 |
| 3087 | note member (0 for a worker); the header's recipients, 32 bits each; the parts as fn spans gives them; for each |
| 3088 | note member its channel list (follows); then the text of the post. A number that is not a member is 4294967295. |
| 3089 | note The answer: a byte that is 1 when the post is to everyone, a count, then that many member numbers |
| 3090 | fn addr b view uchar 1048576 n ulong ob edit uchar 65544 to ulong |
| 3091 | flag = new ulong 96 0 |
| 3092 | coff = new ulong 96 0 |
| 3093 | bad = ulong 18446744073709551615 |
| 3094 | if lt n 12 |
| 3095 | ret bad |
| 3096 | end |
| 3097 | lim = add 8 n |
| 3098 | mem = rd16 b 8 |
| 3099 | nsp = rd16 b 10 |
| 3100 | nh = rd16 b 12 |
| 3101 | tall = ulong get b 14 |
| 3102 | sender = rd32 b 16 |
| 3103 | if or gt mem 96 or gt nsp 128 gt nh 16 |
| 3104 | ret bad |
| 3105 | end |
| 3106 | roles = ulong 20 |
| 3107 | hto = add roles mem |
| 3108 | sp = add hto mul nh 4 |
| 3109 | p = add sp mul nsp 16 |
| 3110 | if gt p lim |
| 3111 | ret bad |
| 3112 | end |
| 3113 | for m ulong mem |
| 3114 | if ge p lim |
| 3115 | ret bad |
| 3116 | end |
| 3117 | put coff m p |
| 3118 | cc = ulong get b p |
| 3119 | if gt cc 16 |
| 3120 | ret bad |
| 3121 | end |
| 3122 | p = add p 1 |
| 3123 | for c ulong cc |
| 3124 | if gt add p 2 lim |
| 3125 | ret bad |
| 3126 | end |
| 3127 | p = add add p 2 rd16 b p |
| 3128 | if gt p lim |
| 3129 | ret bad |
| 3130 | end |
| 3131 | end |
| 3132 | end |
| 3133 | t0 = p |
| 3134 | tn = sub lim t0 |
| 3135 | for i ulong nh |
| 3136 | v = rd32 b add hto mul i 4 |
| 3137 | if lt v mem |
| 3138 | put flag v 1 |
| 3139 | end |
| 3140 | end |
| 3141 | for s ulong nsp |
| 3142 | o = add sp mul s 16 |
| 3143 | start = rd32 b o |
| 3144 | ln = rd32 b add o 4 |
| 3145 | kind = rd32 b add o 8 |
| 3146 | v = rd32 b add o 12 |
| 3147 | if eq kind 1 |
| 3148 | if lt v mem |
| 3149 | put flag v 1 |
| 3150 | end |
| 3151 | end |
| 3152 | if eq kind 2 |
| 3153 | tall = 1 |
| 3154 | end |
| 3155 | if eq kind 3 |
| 3156 | if and gt ln 2 le add start ln tn |
| 3157 | cx = add add t0 start 2 |
| 3158 | cl = sub ln 2 |
| 3159 | if not chplain b cx cl |
| 3160 | for m ulong mem |
| 3161 | if follows b ulong get b add roles m get coff m cx cl |
| 3162 | put flag m 1 |
| 3163 | end |
| 3164 | end |
| 3165 | end |
| 3166 | end |
| 3167 | end |
| 3168 | end |
| 3169 | if lt sender mem |
| 3170 | put flag sender 0 |
| 3171 | end |
| 3172 | cnt = ulong 0 |
| 3173 | for m ulong mem |
| 3174 | if eq get flag m 1 |
| 3175 | put ob add 10 cnt uchar m |
| 3176 | cnt = add cnt 1 |
| 3177 | end |
| 3178 | end |
| 3179 | if ne tall 0 |
| 3180 | tall = 1 |
| 3181 | end |
| 3182 | put ob 8 uchar tall |
| 3183 | put ob 9 uchar cnt |
| 3184 | ret add 2 cnt |
| 3185 | end |
| 3186 | |
| 3187 | note 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). |
| 3188 | note 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 |
| 3189 | note 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 |
| 3190 | note (64-bit). op 3: who a post calls and what it cites (fn spans; the number is the highest post that may be |
| 3191 | note cited). op 4: who a post addresses (fn addr). Returns the reply length, or 18446744073709551615 for a malformed body or an unknown op |
| 3192 | fn board ib view uchar 1048576 nb ulong ob edit uchar 65544 to ulong |
| 3193 | tm = new ulong 16 0 |
| 3194 | bad = ulong 18446744073709551615 |
| 3195 | if lt nb 8 |
| 3196 | ret bad |
| 3197 | end |
| 3198 | op = rd32 ib 0 |
| 3199 | arg = rd32 ib 4 |
| 3200 | n = sub nb 8 |
| 3201 | if eq op 3 |
| 3202 | ret spans ib n arg ob |
| 3203 | end |
| 3204 | if eq op 4 |
| 3205 | ret addr ib n ob |
| 3206 | end |
| 3207 | if gt n 70000 |
| 3208 | ret bad |
| 3209 | end |
| 3210 | if eq op 1 |
| 3211 | ret lline ib n ob |
| 3212 | end |
| 3213 | if eq op 2 |
| 3214 | for z ulong 16 |
| 3215 | put ob add 8 z uchar 0 |
| 3216 | end |
| 3217 | if eq ltime ib arg n tm 1 |
| 3218 | put ob 8 uchar 1 |
| 3219 | put ob 9 uchar get tm 3 |
| 3220 | put32 ob 12 get tm 2 |
| 3221 | put32 ob 16 get tm 1 |
| 3222 | put32 ob 20 shr get tm 1 32 |
| 3223 | end |
| 3224 | ret 16 |
| 3225 | end |
| 3226 | ret bad |
| 3227 | end |
| 3228 | |
| 3229 | note ---- a whole plain-text board: its members and who each post is from and to (kind 6) ---- |
| 3230 | note 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 |
| 3231 | note post, a byte that is 1 when it was cut, the number of senders (4 at most) and of recipients (16 at most), then |
| 3232 | note each sender and each recipient as a 16-bit length and the name, a 16-bit length and the bracket after it. |
| 3233 | note Senders and recipients become members. Two spellings are one member when they share a key (no leading "@", |
| 3234 | note ASCII lower case, each run of spaces one "-"); when one stands in the brackets of one agent only and is used |
| 3235 | note as a sender or recipient elsewhere ("merge-desk (omp-queen-spark)"); or when it is that agent's name without |
| 3236 | note its lane ("Worker" for "lane/Worker") and exactly one sender posts under a name that ends that way. |
| 3237 | note Limits: 400 lines, 192 spellings, 96 members, 8 comma-separated items in a bracket. |
| 3238 | global a_keys uchar 12288 |
| 3239 | global a_kl ulong 192 |
| 3240 | global a_sref ulong 192 |
| 3241 | global a_own ulong 192 |
| 3242 | global a_can ulong 192 |
| 3243 | global a_mem ulong 192 |
| 3244 | global a_lo ulong 400 |
| 3245 | global a_kb uchar 72 |
| 3246 | global a_e ulong 8 |
| 3247 | global a_ds ulong 96 |
| 3248 | |
| 3249 | note 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 |
| 3250 | fn aent b view uchar 1048576 p ulong side ulong k ulong to void |
| 3251 | skip = k |
| 3252 | if eq side 1 |
| 3253 | skip = add k ulong get b add p 2 |
| 3254 | end |
| 3255 | q = add p 4 |
| 3256 | for i ulong skip |
| 3257 | q = add add q 2 rd16 b q |
| 3258 | q = add add q 2 rd16 b q |
| 3259 | end |
| 3260 | nl = rd16 b q |
| 3261 | put a_e 0 add q 2 |
| 3262 | put a_e 1 nl |
| 3263 | q = add add q 2 nl |
| 3264 | put a_e 2 add q 2 |
| 3265 | put a_e 3 rd16 b q |
| 3266 | end |
| 3267 | |
| 3268 | note 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) |
| 3269 | fn akey b view uchar 1048576 off ulong n ulong to ulong |
| 3270 | a = off |
| 3271 | e = add off n |
| 3272 | while lt a e bound 999999 |
| 3273 | if not lsp ulong get b a |
| 3274 | break |
| 3275 | end |
| 3276 | a = add a 1 |
| 3277 | end |
| 3278 | while gt e a bound 999999 |
| 3279 | if not lsp ulong get b sub e 1 |
| 3280 | break |
| 3281 | end |
| 3282 | e = sub e 1 |
| 3283 | end |
| 3284 | if lt a e |
| 3285 | if eq ulong get b a 64 |
| 3286 | a = add a 1 |
| 3287 | end |
| 3288 | end |
| 3289 | kn = ulong 0 |
| 3290 | gap = false |
| 3291 | while lt a e bound 999999 |
| 3292 | c = ulong get b a |
| 3293 | if lsp c |
| 3294 | gap = true |
| 3295 | else |
| 3296 | if and gap gt kn 0 |
| 3297 | if ge kn 64 |
| 3298 | ret 65 |
| 3299 | end |
| 3300 | put a_kb kn uchar 45 |
| 3301 | kn = add kn 1 |
| 3302 | end |
| 3303 | gap = false |
| 3304 | if ge kn 64 |
| 3305 | ret 65 |
| 3306 | end |
| 3307 | put a_kb kn uchar lowc c |
| 3308 | kn = add kn 1 |
| 3309 | end |
| 3310 | a = add a 1 |
| 3311 | end |
| 3312 | ret kn |
| 3313 | end |
| 3314 | |
| 3315 | note where the key in a_kb (kn bytes) stands among the first nk keys, or 1000 |
| 3316 | fn afind kn ulong nk ulong to ulong |
| 3317 | if gt kn 64 |
| 3318 | ret 1000 |
| 3319 | end |
| 3320 | i = ulong 0 |
| 3321 | while lt i nk bound 256 |
| 3322 | if eq get a_kl i kn |
| 3323 | j = ulong 0 |
| 3324 | while lt j kn bound 128 |
| 3325 | if ne ulong get a_keys add mul i 64 j ulong get a_kb j |
| 3326 | break |
| 3327 | end |
| 3328 | j = add j 1 |
| 3329 | end |
| 3330 | if eq j kn |
| 3331 | ret i |
| 3332 | end |
| 3333 | end |
| 3334 | i = add i 1 |
| 3335 | end |
| 3336 | ret 1000 |
| 3337 | end |
| 3338 | |
| 3339 | note "L1122" or "L1124/L1125": a ledger number, never another name of the agent |
| 3340 | fn aledger b view uchar 1048576 off ulong n ulong to bool |
| 3341 | i = ulong 0 |
| 3342 | parts = ulong 0 |
| 3343 | while lt i n bound 16 |
| 3344 | if ge parts 8 |
| 3345 | break |
| 3346 | end |
| 3347 | c = ulong get b add off i |
| 3348 | if and ne c 76 ne c 108 |
| 3349 | ret false |
| 3350 | end |
| 3351 | j = add i 1 |
| 3352 | while lt j n bound 16 |
| 3353 | if gt sub j i 9 |
| 3354 | break |
| 3355 | end |
| 3356 | d = ulong get b add off j |
| 3357 | if or lt d 48 gt d 57 |
| 3358 | break |
| 3359 | end |
| 3360 | j = add j 1 |
| 3361 | end |
| 3362 | if eq j add i 1 |
| 3363 | ret false |
| 3364 | end |
| 3365 | parts = add parts 1 |
| 3366 | if eq j n |
| 3367 | ret true |
| 3368 | end |
| 3369 | if ne ulong get b add off j 47 |
| 3370 | ret false |
| 3371 | end |
| 3372 | i = add j 1 |
| 3373 | end |
| 3374 | ret false |
| 3375 | end |
| 3376 | |
| 3377 | note the main spelling of the set that holds spelling s |
| 3378 | fn aroot s ulong nk ulong to ulong |
| 3379 | i = s |
| 3380 | hops = ulong 0 |
| 3381 | while lt i nk bound 256 |
| 3382 | if eq get a_can i i |
| 3383 | break |
| 3384 | end |
| 3385 | if ge hops 192 |
| 3386 | break |
| 3387 | end |
| 3388 | i = get a_can i |
| 3389 | hops = add hops 1 |
| 3390 | end |
| 3391 | ret i |
| 3392 | end |
| 3393 | |
| 3394 | note joins the sets that hold x0 and y0; the earlier spelling stays the main one |
| 3395 | fn ajoin x0 ulong y0 ulong nk ulong to void |
| 3396 | x = aroot x0 nk |
| 3397 | y = aroot y0 nk |
| 3398 | if or ge x nk ge y nk |
| 3399 | ret |
| 3400 | end |
| 3401 | if eq x y |
| 3402 | ret |
| 3403 | end |
| 3404 | if lt x y |
| 3405 | put a_can y x |
| 3406 | else |
| 3407 | put a_can x y |
| 3408 | end |
| 3409 | end |
| 3410 | |
| 3411 | note is key f the key s with a lane in front: "lane/s"? |
| 3412 | fn alane f ulong s ulong to bool |
| 3413 | fl = get a_kl f |
| 3414 | sl = get a_kl s |
| 3415 | if eq sl 0 |
| 3416 | ret false |
| 3417 | end |
| 3418 | if lt fl add sl 2 |
| 3419 | ret false |
| 3420 | end |
| 3421 | p = sub fl sl |
| 3422 | if ne ulong get a_keys add mul f 64 sub p 1 47 |
| 3423 | ret false |
| 3424 | end |
| 3425 | i = ulong 0 |
| 3426 | while lt i sl bound 128 |
| 3427 | if ne ulong get a_keys add add mul f 64 p i ulong get a_keys add mul s 64 i |
| 3428 | ret false |
| 3429 | end |
| 3430 | i = add i 1 |
| 3431 | end |
| 3432 | ret true |
| 3433 | end |
| 3434 | |
| 3435 | note the member that the name of the current entry (a_e) belongs to, or 1000 |
| 3436 | fn amember b view uchar 1048576 nk ulong to ulong |
| 3437 | f = afind akey b get a_e 0 get a_e 1 nk |
| 3438 | if ge f 1000 |
| 3439 | ret 1000 |
| 3440 | end |
| 3441 | ret get a_mem f |
| 3442 | end |
| 3443 | |
| 3444 | note kind 6: a 32-bit count of lines, then the line records. The answer: 16-bit counts of members, of joined |
| 3445 | note spellings and of posts; from byte 8 four 32-bit counts: lines that are not posts, posts that were cut, |
| 3446 | note agents beyond 96 members, names met after the 192 spellings were full; from byte 24 eight bytes a member: |
| 3447 | note the line (16-bit), side and entry of its newest spelling, then the line (65535: none) and entry of the newest |
| 3448 | note bracket after it as a sender; six bytes a joined spelling: its member, 0, then line, side and entry; then a |
| 3449 | note post each: its sender (255: none), how many others signed and how many members its header names, then |
| 3450 | note those members. Returns the reply length, or 18446744073709551615 for a malformed body |
| 3451 | fn asm b view uchar 1048576 n ulong ob edit uchar 65544 to ulong |
| 3452 | wl = new ulong 8 0 |
| 3453 | to2 = new ulong 24 0 |
| 3454 | bad = ulong 18446744073709551615 |
| 3455 | if lt n 4 |
| 3456 | ret bad |
| 3457 | end |
| 3458 | nl = rd32 b 0 |
| 3459 | if gt nl 400 |
| 3460 | ret bad |
| 3461 | end |
| 3462 | p = ulong 4 |
| 3463 | for li ulong nl |
| 3464 | if gt add p 4 n |
| 3465 | ret bad |
| 3466 | end |
| 3467 | put a_lo li p |
| 3468 | ns = ulong get b add p 2 |
| 3469 | nr = ulong get b add p 3 |
| 3470 | if or gt ns 4 gt nr 16 |
| 3471 | ret bad |
| 3472 | end |
| 3473 | p = add p 4 |
| 3474 | for k ulong mul 2 add ns nr |
| 3475 | if gt add p 2 n |
| 3476 | ret bad |
| 3477 | end |
| 3478 | p = add add p 2 rd16 b p |
| 3479 | if gt p n |
| 3480 | ret bad |
| 3481 | end |
| 3482 | end |
| 3483 | end |
| 3484 | nk = ulong 0 |
| 3485 | sdrop = ulong 0 |
| 3486 | skeys = ulong 0 |
| 3487 | for pz ulong 2 |
| 3488 | for lr ulong nl |
| 3489 | lq = sub sub nl 1 lr |
| 3490 | p = get a_lo lq |
| 3491 | if eq ulong get b p 1 |
| 3492 | cnt = ulong get b add p 2 |
| 3493 | if eq pz 1 |
| 3494 | cnt = ulong get b add p 3 |
| 3495 | end |
| 3496 | for k ulong cnt |
| 3497 | aent b p pz k |
| 3498 | kn = akey b get a_e 0 get a_e 1 |
| 3499 | if and gt kn 0 le kn 64 |
| 3500 | if ge afind kn nk 1000 |
| 3501 | if lt nk 192 |
| 3502 | for j ulong kn |
| 3503 | put a_keys add mul nk 64 j get a_kb j |
| 3504 | end |
| 3505 | put a_kl nk kn |
| 3506 | put a_sref nk or or shl lq 16 shl pz 8 k |
| 3507 | nk = add nk 1 |
| 3508 | else |
| 3509 | sdrop = add sdrop 1 |
| 3510 | end |
| 3511 | end |
| 3512 | end |
| 3513 | end |
| 3514 | end |
| 3515 | end |
| 3516 | if eq pz 0 |
| 3517 | skeys = nk |
| 3518 | end |
| 3519 | end |
| 3520 | for c ulong nk |
| 3521 | put a_own c 1000 |
| 3522 | put a_can c c |
| 3523 | put a_mem c 1000 |
| 3524 | end |
| 3525 | for li ulong nl |
| 3526 | p = get a_lo li |
| 3527 | if eq ulong get b p 1 |
| 3528 | for side ulong 2 |
| 3529 | cnt = ulong get b add p 2 |
| 3530 | if eq side 1 |
| 3531 | cnt = ulong get b add p 3 |
| 3532 | end |
| 3533 | for k ulong cnt |
| 3534 | aent b p side k |
| 3535 | d0 = get a_e 2 |
| 3536 | dn = get a_e 3 |
| 3537 | outer = afind akey b get a_e 0 get a_e 1 nk |
| 3538 | a = ulong 0 |
| 3539 | items = ulong 0 |
| 3540 | while le a dn bound 1024 |
| 3541 | if ge outer 1000 |
| 3542 | break |
| 3543 | end |
| 3544 | if ge items 8 |
| 3545 | break |
| 3546 | end |
| 3547 | e = a |
| 3548 | while lt e dn bound 999999 |
| 3549 | if eq ulong get b add d0 e 44 |
| 3550 | break |
| 3551 | end |
| 3552 | e = add e 1 |
| 3553 | end |
| 3554 | x = a |
| 3555 | y = e |
| 3556 | while lt x y bound 999999 |
| 3557 | if not lsp ulong get b add d0 x |
| 3558 | break |
| 3559 | end |
| 3560 | x = add x 1 |
| 3561 | end |
| 3562 | while gt y x bound 999999 |
| 3563 | if not lsp ulong get b add d0 sub y 1 |
| 3564 | break |
| 3565 | end |
| 3566 | y = sub y 1 |
| 3567 | end |
| 3568 | if lt x y |
| 3569 | if not aledger b add d0 x sub y x |
| 3570 | inner = afind akey b add d0 x sub y x nk |
| 3571 | if lt inner 1000 |
| 3572 | if ne inner outer |
| 3573 | if eq get a_own inner 1000 |
| 3574 | put a_own inner outer |
| 3575 | else |
| 3576 | if ne get a_own inner outer |
| 3577 | put a_own inner 2000 |
| 3578 | end |
| 3579 | end |
| 3580 | end |
| 3581 | end |
| 3582 | end |
| 3583 | end |
| 3584 | items = add items 1 |
| 3585 | a = add e 1 |
| 3586 | end |
| 3587 | end |
| 3588 | end |
| 3589 | end |
| 3590 | end |
| 3591 | for c ulong nk |
| 3592 | if lt get a_own c 1000 |
| 3593 | ajoin get a_own c c nk |
| 3594 | end |
| 3595 | end |
| 3596 | for c ulong nk |
| 3597 | slash = false |
| 3598 | for j ulong get a_kl c |
| 3599 | if eq ulong get a_keys add mul c 64 j 47 |
| 3600 | slash = true |
| 3601 | end |
| 3602 | end |
| 3603 | if not slash |
| 3604 | mt1 = ulong 0 |
| 3605 | matches = ulong 0 |
| 3606 | for k ulong skeys |
| 3607 | if ne k c |
| 3608 | if alane k c |
| 3609 | mt1 = k |
| 3610 | matches = add matches 1 |
| 3611 | end |
| 3612 | end |
| 3613 | end |
| 3614 | if eq matches 1 |
| 3615 | ajoin mt1 c nk |
| 3616 | end |
| 3617 | end |
| 3618 | end |
| 3619 | nm = ulong 0 |
| 3620 | mdrop = ulong 0 |
| 3621 | for c ulong nk |
| 3622 | if eq aroot c nk c |
| 3623 | if lt nm 96 |
| 3624 | put a_mem c nm |
| 3625 | r = get a_sref c |
| 3626 | o = add 32 mul nm 8 |
| 3627 | put ob o uchar and shr r 16 255 |
| 3628 | put ob add o 1 uchar shr r 24 |
| 3629 | put ob add o 2 uchar and shr r 8 255 |
| 3630 | put ob add o 3 uchar and r 255 |
| 3631 | put ob add o 4 uchar 255 |
| 3632 | put ob add o 5 uchar 255 |
| 3633 | put ob add o 6 uchar 0 |
| 3634 | put ob add o 7 uchar 0 |
| 3635 | put a_ds nm 0 |
| 3636 | nm = add nm 1 |
| 3637 | else |
| 3638 | mdrop = add mdrop 1 |
| 3639 | end |
| 3640 | end |
| 3641 | end |
| 3642 | o = add 32 mul nm 8 |
| 3643 | nalso = ulong 0 |
| 3644 | for c ulong nk |
| 3645 | rt = aroot c nk |
| 3646 | if ne rt c |
| 3647 | if lt rt nk |
| 3648 | if lt get a_mem rt 1000 |
| 3649 | put a_mem c get a_mem rt |
| 3650 | r = get a_sref c |
| 3651 | put ob o uchar get a_mem rt |
| 3652 | put ob add o 1 uchar 0 |
| 3653 | put ob add o 2 uchar and shr r 16 255 |
| 3654 | put ob add o 3 uchar shr r 24 |
| 3655 | put ob add o 4 uchar and shr r 8 255 |
| 3656 | put ob add o 5 uchar and r 255 |
| 3657 | o = add o 6 |
| 3658 | nalso = add nalso 1 |
| 3659 | end |
| 3660 | end |
| 3661 | end |
| 3662 | end |
| 3663 | skipped = ulong 0 |
| 3664 | clipped = ulong 0 |
| 3665 | nposts = ulong 0 |
| 3666 | for li ulong nl |
| 3667 | p = get a_lo li |
| 3668 | if ne ulong get b p 1 |
| 3669 | skipped = add skipped 1 |
| 3670 | else |
| 3671 | if eq ulong get b add p 1 1 |
| 3672 | clipped = add clipped 1 |
| 3673 | end |
| 3674 | sender = ulong 1000 |
| 3675 | nw = ulong 0 |
| 3676 | ns = ulong get b add p 2 |
| 3677 | for k ulong ns |
| 3678 | aent b p 0 k |
| 3679 | m = amember b nk |
| 3680 | if eq k 0 |
| 3681 | sender = m |
| 3682 | else |
| 3683 | if and lt m 1000 ne m sender |
| 3684 | dup = false |
| 3685 | for j ulong nw |
| 3686 | if eq get wl j m |
| 3687 | dup = true |
| 3688 | end |
| 3689 | end |
| 3690 | if not dup |
| 3691 | put wl nw m |
| 3692 | nw = add nw 1 |
| 3693 | end |
| 3694 | end |
| 3695 | end |
| 3696 | end |
| 3697 | nt = ulong 0 |
| 3698 | nr = ulong get b add p 3 |
| 3699 | for k ulong nr |
| 3700 | aent b p 1 k |
| 3701 | m = amember b nk |
| 3702 | if and lt m 1000 ne m sender |
| 3703 | dup = false |
| 3704 | for j ulong nt |
| 3705 | if eq get to2 j m |
| 3706 | dup = true |
| 3707 | end |
| 3708 | end |
| 3709 | if not dup |
| 3710 | put to2 nt m |
| 3711 | nt = add nt 1 |
| 3712 | end |
| 3713 | end |
| 3714 | end |
| 3715 | sb = ulong 255 |
| 3716 | if lt sender 1000 |
| 3717 | sb = sender |
| 3718 | end |
| 3719 | put ob o uchar sb |
| 3720 | put ob add o 1 uchar nw |
| 3721 | put ob add o 2 uchar nt |
| 3722 | o = add o 3 |
| 3723 | for j ulong nw |
| 3724 | put ob o uchar get wl j |
| 3725 | o = add o 1 |
| 3726 | end |
| 3727 | for j ulong nt |
| 3728 | put ob o uchar get to2 j |
| 3729 | o = add o 1 |
| 3730 | end |
| 3731 | nposts = add nposts 1 |
| 3732 | end |
| 3733 | end |
| 3734 | for lr ulong nl |
| 3735 | lq = sub sub nl 1 lr |
| 3736 | p = get a_lo lq |
| 3737 | if eq ulong get b p 1 |
| 3738 | ns = ulong get b add p 2 |
| 3739 | for k ulong ns |
| 3740 | aent b p 0 k |
| 3741 | dn = get a_e 3 |
| 3742 | m = amember b nk |
| 3743 | if and lt m 1000 gt dn 0 |
| 3744 | if eq get a_ds m 0 |
| 3745 | put a_ds m 1 |
| 3746 | mo = add 36 mul m 8 |
| 3747 | put ob mo uchar and lq 255 |
| 3748 | put ob add mo 1 uchar shr lq 8 |
| 3749 | put ob add mo 2 uchar k |
| 3750 | end |
| 3751 | end |
| 3752 | end |
| 3753 | end |
| 3754 | end |
| 3755 | put ob 8 uchar and nm 255 |
| 3756 | put ob 9 uchar shr nm 8 |
| 3757 | put ob 10 uchar and nalso 255 |
| 3758 | put ob 11 uchar shr nalso 8 |
| 3759 | put ob 12 uchar and nposts 255 |
| 3760 | put ob 13 uchar shr nposts 8 |
| 3761 | put ob 14 uchar 0 |
| 3762 | put ob 15 uchar 0 |
| 3763 | put32 ob 16 skipped |
| 3764 | put32 ob 20 clipped |
| 3765 | put32 ob 24 mdrop |
| 3766 | put32 ob 28 sdrop |
| 3767 | ret sub o 8 |
| 3768 | end |
| 3769 | |
| 3770 | note ---- the state of a swarm's members, and the graph (kind 7) ---- |
| 3771 | note 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 |
| 3772 | note text. Every number, in and out, is the value plus 1099511627776, so that -1 ("not known", "none") travels as |
| 3773 | note an unsigned number. Codes: role 0 worker, 1 coordinator, 2 helper; turn 0 not known, 1 running, 2 ended; wake |
| 3774 | note 2 parked for mentions, 3 for any post; state 1 working, 2 waiting, 3 stopped; attention 0 none, 1 stuck, |
| 3775 | note 2 error, 3 quota; group 1 needs you, 2 working, 3 waiting on someone, 4 parked; step 1 planner, 2 result, |
| 3776 | note 3 user, 4 error; status 1 done, 2 error. |
| 3777 | const k_b ulong 1099511627776 |
| 3778 | text q_words "resource_exhausted|quota|rate limit|rate-limit|ratelimit|exhausted your capacity|" |
| 3779 | text q_roles "coordinatorworkernarratormonitor" |
| 3780 | global d_role ulong 96 |
| 3781 | global d_kill ulong 96 |
| 3782 | global d_wake ulong 96 |
| 3783 | global d_turn ulong 96 |
| 3784 | global d_lr ulong 96 |
| 3785 | global d_lm ulong 96 |
| 3786 | global d_fail ulong 96 |
| 3787 | global d_own ulong 96 |
| 3788 | global d_no ulong 96 |
| 3789 | global d_nl ulong 96 |
| 3790 | global d_cnt ulong 96 |
| 3791 | global d_last ulong 96 |
| 3792 | global d_state ulong 96 |
| 3793 | global d_att ulong 96 |
| 3794 | global d_won ulong 96 |
| 3795 | global d_grp ulong 96 |
| 3796 | global d_key ulong 96 |
| 3797 | global d_ord ulong 96 |
| 3798 | global d_po ulong 400 |
| 3799 | global d_cell ulong 18432 |
| 3800 | global d_nm ulong 96 |
| 3801 | |
| 3802 | note number k of the request |
| 3803 | fn gi b view uchar 1048576 k ulong to ulong |
| 3804 | o = add 8 mul k 8 |
| 3805 | ret or rd32 b o shl rd32 b add o 4 32 |
| 3806 | end |
| 3807 | |
| 3808 | note number k of the request as a count; a negative number gives a value over every limit |
| 3809 | fn gu b view uchar 1048576 k ulong to ulong |
| 3810 | v = gi b k |
| 3811 | if lt v k_b |
| 3812 | ret 4294967295 |
| 3813 | end |
| 3814 | ret sub v k_b |
| 3815 | end |
| 3816 | |
| 3817 | note number k of the answer |
| 3818 | fn po ob edit uchar 65544 k ulong v ulong to void |
| 3819 | o = add 8 mul k 8 |
| 3820 | put32 ob o v |
| 3821 | put32 ob add o 4 shr v 32 |
| 3822 | end |
| 3823 | |
| 3824 | note a member's state is worked out, never taken from what it says about itself. With a roster: stopped when it |
| 3825 | note was killed; else waiting when its own run has ended and working when it is mid-turn; with no transcript to |
| 3826 | note go on, waiting when it is parked. With no roster: working when it posted within 900 seconds (age, -1 never) |
| 3827 | fn swstate killed ulong turn ulong wake ulong roster ulong age ulong to ulong |
| 3828 | if eq killed add k_b 1 |
| 3829 | ret 3 |
| 3830 | end |
| 3831 | if ne roster add k_b 1 |
| 3832 | if and ge age k_b le age add k_b 900 |
| 3833 | ret 1 |
| 3834 | end |
| 3835 | ret 2 |
| 3836 | end |
| 3837 | if eq turn add k_b 2 |
| 3838 | ret 2 |
| 3839 | end |
| 3840 | if eq turn add k_b 1 |
| 3841 | ret 1 |
| 3842 | end |
| 3843 | if or eq wake add k_b 2 eq wake add k_b 3 |
| 3844 | ret 2 |
| 3845 | end |
| 3846 | ret 1 |
| 3847 | end |
| 3848 | |
| 3849 | note what needs a look: a failed newest step, or a member that should be working and has not moved for more |
| 3850 | note than 600 seconds (idle -1: not known) |
| 3851 | fn swatt state ulong failure ulong idle ulong to ulong |
| 3852 | if eq state add k_b 3 |
| 3853 | ret 0 |
| 3854 | end |
| 3855 | if eq failure add k_b 2 |
| 3856 | ret 2 |
| 3857 | end |
| 3858 | if eq failure add k_b 3 |
| 3859 | ret 3 |
| 3860 | end |
| 3861 | if and eq state add k_b 1 gt idle add k_b 600 |
| 3862 | ret 1 |
| 3863 | end |
| 3864 | ret 0 |
| 3865 | end |
| 3866 | |
| 3867 | note the Overview group of one member (asks and won: 1 when it asks the owner, when it waits on someone) |
| 3868 | fn swgroup state ulong att ulong asks ulong won ulong to ulong |
| 3869 | if eq state add k_b 3 |
| 3870 | ret 4 |
| 3871 | end |
| 3872 | if or ne att k_b ne asks k_b |
| 3873 | ret 1 |
| 3874 | end |
| 3875 | if eq state add k_b 1 |
| 3876 | ret 2 |
| 3877 | end |
| 3878 | if ne won k_b |
| 3879 | ret 3 |
| 3880 | end |
| 3881 | ret 4 |
| 3882 | end |
| 3883 | |
| 3884 | note is this post the first row of a visual group? Posts by one sender, next to each other and at most 600 |
| 3885 | note seconds apart, are one group |
| 3886 | fn swstarts ps ulong pt ulong s ulong t ulong to ulong |
| 3887 | if or lt s k_b ne s ps |
| 3888 | ret 1 |
| 3889 | end |
| 3890 | if or le t k_b le pt k_b |
| 3891 | ret 0 |
| 3892 | end |
| 3893 | if or gt t add pt 600 lt t pt |
| 3894 | ret 1 |
| 3895 | end |
| 3896 | ret 0 |
| 3897 | end |
| 3898 | |
| 3899 | note the n bytes at off, ASCII letters without case, against the wn bytes at w0 of q_roles |
| 3900 | fn eqrole b view uchar 1048576 off ulong n ulong w0 ulong wn ulong to bool |
| 3901 | if ne n wn |
| 3902 | ret false |
| 3903 | end |
| 3904 | i = ulong 0 |
| 3905 | while lt i n bound 64 |
| 3906 | if ne lowc ulong get b add off i ulong get q_roles add w0 i |
| 3907 | ret false |
| 3908 | end |
| 3909 | i = add i 1 |
| 3910 | end |
| 3911 | ret true |
| 3912 | end |
| 3913 | |
| 3914 | note the order of members: by key (small first), the coordinator before the others, then by name (ASCII letters |
| 3915 | note 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 |
| 3916 | fn sworder b view uchar 1048576 n ulong to void |
| 3917 | cntd = ulong 0 |
| 3918 | for i ulong n |
| 3919 | pos = cntd |
| 3920 | while gt pos 0 bound 128 |
| 3921 | o = get d_ord sub pos 1 |
| 3922 | after = false |
| 3923 | if ne get d_key o get d_key i |
| 3924 | after = gt get d_key o get d_key i |
| 3925 | else |
| 3926 | co = eq get d_role o 1 |
| 3927 | ci = eq get d_role i 1 |
| 3928 | dif = false |
| 3929 | if co |
| 3930 | if not ci |
| 3931 | dif = true |
| 3932 | end |
| 3933 | else |
| 3934 | if ci |
| 3935 | dif = true |
| 3936 | end |
| 3937 | end |
| 3938 | if dif |
| 3939 | after = ci |
| 3940 | else |
| 3941 | x = get d_no o |
| 3942 | xl = get d_nl o |
| 3943 | y = get d_no i |
| 3944 | yl = get d_nl i |
| 3945 | k = ulong 0 |
| 3946 | cmp = ulong 1 |
| 3947 | while lt k xl bound 999999 |
| 3948 | if ge k yl |
| 3949 | break |
| 3950 | end |
| 3951 | cx = lowc ulong get b add x k |
| 3952 | cy = lowc ulong get b add y k |
| 3953 | if ne cx cy |
| 3954 | cmp = 0 |
| 3955 | if gt cx cy |
| 3956 | cmp = 2 |
| 3957 | end |
| 3958 | break |
| 3959 | end |
| 3960 | k = add k 1 |
| 3961 | end |
| 3962 | if eq cmp 1 |
| 3963 | if gt xl yl |
| 3964 | cmp = 2 |
| 3965 | end |
| 3966 | end |
| 3967 | after = eq cmp 2 |
| 3968 | end |
| 3969 | end |
| 3970 | if not after |
| 3971 | break |
| 3972 | end |
| 3973 | put d_ord pos o |
| 3974 | pos = sub pos 1 |
| 3975 | end |
| 3976 | put d_ord pos i |
| 3977 | cntd = add cntd 1 |
| 3978 | end |
| 3979 | end |
| 3980 | |
| 3981 | note op 8: has the member's run stopped? Its newest steps, oldest first: four counts (they must be equal), then |
| 3982 | note the kinds, the statuses, for a planner step how many tools it called, and which of them was the wait for |
| 3983 | note posts (-1 none). Ended (2) when the newest planner step called no tool and nothing came after it, or when it |
| 3984 | note called the wait and that call's result is done; anything newer means mid-turn (1). 0: not known |
| 3985 | fn swturn b view uchar 1048576 c ulong to ulong |
| 3986 | if lt c 4 |
| 3987 | ret 0 |
| 3988 | end |
| 3989 | n = gu b 0 |
| 3990 | if gt n 100000 |
| 3991 | ret 0 |
| 3992 | end |
| 3993 | if 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 |
| 3994 | ret 0 |
| 3995 | end |
| 3996 | if ne c add 4 mul n 4 |
| 3997 | ret 0 |
| 3998 | end |
| 3999 | kd = ulong 4 |
| 4000 | sx = add 4 n |
| 4001 | tl = add 4 mul n 2 |
| 4002 | wt2 = add 4 mul n 3 |
| 4003 | i = n |
| 4004 | results = ulong 0 |
| 4005 | looked = ulong 0 |
| 4006 | while gt i 0 bound 512 |
| 4007 | if ge looked 256 |
| 4008 | break |
| 4009 | end |
| 4010 | if ne gi b add kd sub i 1 add k_b 2 |
| 4011 | break |
| 4012 | end |
| 4013 | results = add results 1 |
| 4014 | i = sub i 1 |
| 4015 | looked = add looked 1 |
| 4016 | end |
| 4017 | if or eq i 0 ge looked 256 |
| 4018 | ret 1 |
| 4019 | end |
| 4020 | i = sub i 1 |
| 4021 | if ne gi b add kd i add k_b 1 |
| 4022 | ret 1 |
| 4023 | end |
| 4024 | tools = gi b add tl i |
| 4025 | if le tools k_b |
| 4026 | if eq results 0 |
| 4027 | ret 2 |
| 4028 | end |
| 4029 | ret 1 |
| 4030 | end |
| 4031 | wait = gi b add wt2 i |
| 4032 | if or lt wait k_b ge wait tools |
| 4033 | ret 1 |
| 4034 | end |
| 4035 | if lt results sub tools k_b |
| 4036 | ret 1 |
| 4037 | end |
| 4038 | if eq gi b add sx add add i 1 sub wait k_b add k_b 1 |
| 4039 | ret 2 |
| 4040 | end |
| 4041 | ret 1 |
| 4042 | end |
| 4043 | |
| 4044 | note op 9: the step that says what the member is doing now: the newest planner step of the current turn that has |
| 4045 | note a label. Three counts (equal), then kinds, waits and labels. A turn starts after user input or after a wait |
| 4046 | note for posts. The answer is the step's place, or -1 |
| 4047 | fn swact b view uchar 1048576 c ulong to ulong |
| 4048 | none = sub k_b 1 |
| 4049 | if lt c 3 |
| 4050 | ret none |
| 4051 | end |
| 4052 | n = gu b 0 |
| 4053 | if gt n 100000 |
| 4054 | ret none |
| 4055 | end |
| 4056 | if or ne gi b 1 gi b 0 ne gi b 2 gi b 0 |
| 4057 | ret none |
| 4058 | end |
| 4059 | if ne c add 3 mul n 3 |
| 4060 | ret none |
| 4061 | end |
| 4062 | i = n |
| 4063 | looked = ulong 0 |
| 4064 | while gt i 0 bound 512 |
| 4065 | if ge looked 256 |
| 4066 | break |
| 4067 | end |
| 4068 | kk = gi b add 3 sub i 1 |
| 4069 | if eq kk add k_b 3 |
| 4070 | ret none |
| 4071 | end |
| 4072 | if eq kk add k_b 1 |
| 4073 | if ge gi b add add 3 n sub i 1 k_b |
| 4074 | ret none |
| 4075 | end |
| 4076 | if eq gi b add add 3 mul n 2 sub i 1 add k_b 1 |
| 4077 | ret add k_b sub i 1 |
| 4078 | end |
| 4079 | end |
| 4080 | i = sub i 1 |
| 4081 | looked = add looked 1 |
| 4082 | end |
| 4083 | ret none |
| 4084 | end |
| 4085 | |
| 4086 | note op 10: does an error text (t0..t1) say the member ran out of quota or was rate limited? One of the words of |
| 4087 | note q_words in its first 32768 places, or "429" standing alone |
| 4088 | fn swquota b view uchar 1048576 t0 ulong t1 ulong to ulong |
| 4089 | tn = sub t1 t0 |
| 4090 | w0 = ulong 0 |
| 4091 | wi = ulong 0 |
| 4092 | while lt wi len q_words bound 256 |
| 4093 | if eq ulong get q_words wi 124 |
| 4094 | wn = sub wi w0 |
| 4095 | if and gt wn 0 ge tn wn |
| 4096 | i = ulong 0 |
| 4097 | while le add i wn tn bound 40000 |
| 4098 | if ge i 32768 |
| 4099 | break |
| 4100 | end |
| 4101 | k = ulong 0 |
| 4102 | while lt k wn bound 64 |
| 4103 | if ne lowc ulong get b add add t0 i k ulong get q_words add w0 k |
| 4104 | break |
| 4105 | end |
| 4106 | k = add k 1 |
| 4107 | end |
| 4108 | if eq k wn |
| 4109 | ret 1 |
| 4110 | end |
| 4111 | i = add i 1 |
| 4112 | end |
| 4113 | end |
| 4114 | w0 = add wi 1 |
| 4115 | end |
| 4116 | wi = add wi 1 |
| 4117 | end |
| 4118 | i = ulong 0 |
| 4119 | while le add i 3 tn bound 40000 |
| 4120 | if ge i 32768 |
| 4121 | break |
| 4122 | end |
| 4123 | p = add t0 i |
| 4124 | if and and eq ulong get b p 52 eq ulong get b add p 1 50 eq ulong get b add p 2 57 |
| 4125 | if not namer runeb b p t0 t1 |
| 4126 | if not namer rune b add p 3 t1 |
| 4127 | ret 1 |
| 4128 | end |
| 4129 | end |
| 4130 | end |
| 4131 | i = add i 1 |
| 4132 | end |
| 4133 | ret 0 |
| 4134 | end |
| 4135 | |
| 4136 | note op 11: the role code of a roster member from its role (rl bytes at ro) and its name (nl bytes at no). The |
| 4137 | note coordinator leads; "narrator" and "monitor", also with "-<digits>" after, are helpers by name; so is any role |
| 4138 | note other than "worker" |
| 4139 | fn swrole b view uchar 1048576 ro ulong rl ulong no ulong nl ulong to ulong |
| 4140 | if eqrole b ro rl 0 11 |
| 4141 | ret 1 |
| 4142 | end |
| 4143 | plain = eq rl 0 |
| 4144 | if eqrole b ro rl 11 6 |
| 4145 | plain = true |
| 4146 | end |
| 4147 | if not plain |
| 4148 | ret 2 |
| 4149 | end |
| 4150 | bl = nl |
| 4151 | pf = cprefix b no nl |
| 4152 | if gt pf 0 |
| 4153 | bl = pf |
| 4154 | end |
| 4155 | if eqrole b no bl 17 8 |
| 4156 | ret 2 |
| 4157 | end |
| 4158 | if eqrole b no bl 25 7 |
| 4159 | ret 2 |
| 4160 | end |
| 4161 | ret 0 |
| 4162 | end |
| 4163 | |
| 4164 | note op 16: everything the views show about the members. Numbers: 0 1 when there is a roster, 1 now (seconds |
| 4165 | note since 1970), 2 the members n (96 at most), 3 the posts p (400 at most); nine a member: role, killed, wake, |
| 4166 | note turn, the last post it read (-1 not known), its last own movement (0 not known), failure, 1 when it is the |
| 4167 | note person using Hop, the length of its name; then a post each: its number, its time (0 not known), its sender |
| 4168 | note (-1: not a member), how many others signed and who, how many members it addresses by name and who. The |
| 4169 | note names follow as bytes. The answer: 0 the newest post number, 1 to 3 the members working, waiting and stopped |
| 4170 | note (helpers are not counted); a number a post: 1 when it starts a visual group; then eleven lists of n: posts |
| 4171 | note by each member, its newest post (-1 none), state, attention, idle seconds (-1), unread posts (-1), 1 for a |
| 4172 | note helper, who it waits on (-1), the post that says so, the post that asks the owner (0 none), its group; then |
| 4173 | note the Overview order and the Members order. Returns the count of numbers, or 0 for a malformed request |
| 4174 | fn swderive b view uchar 1048576 c ulong nbytes ulong ob edit uchar 65544 to ulong |
| 4175 | if lt c 4 |
| 4176 | ret 0 |
| 4177 | end |
| 4178 | roster = gi b 0 |
| 4179 | now = gi b 1 |
| 4180 | n = gu b 2 |
| 4181 | p = gu b 3 |
| 4182 | if or gt n 96 gt p 400 |
| 4183 | ret 0 |
| 4184 | end |
| 4185 | q = add 4 mul n 9 |
| 4186 | if gt q c |
| 4187 | ret 0 |
| 4188 | end |
| 4189 | no = add 8 mul c 8 |
| 4190 | for m ulong n |
| 4191 | o = add 4 mul m 9 |
| 4192 | put d_role m gu b o |
| 4193 | put d_kill m gi b add o 1 |
| 4194 | put d_wake m gi b add o 2 |
| 4195 | put d_turn m gi b add o 3 |
| 4196 | put d_lr m gi b add o 4 |
| 4197 | put d_lm m gi b add o 5 |
| 4198 | put d_fail m gi b add o 6 |
| 4199 | put d_own m gi b add o 7 |
| 4200 | l = gu b add o 8 |
| 4201 | if gt l 1048576 |
| 4202 | ret 0 |
| 4203 | end |
| 4204 | put d_no m no |
| 4205 | put d_nl m l |
| 4206 | no = add no l |
| 4207 | put d_cnt m 0 |
| 4208 | put d_last m 1000 |
| 4209 | end |
| 4210 | if gt no add add 8 mul c 8 nbytes |
| 4211 | ret 0 |
| 4212 | end |
| 4213 | for i ulong p |
| 4214 | if gt add q 4 c |
| 4215 | ret 0 |
| 4216 | end |
| 4217 | put d_po i q |
| 4218 | nw = gu b add q 3 |
| 4219 | if gt nw 4 |
| 4220 | ret 0 |
| 4221 | end |
| 4222 | if gt add add q 5 nw c |
| 4223 | ret 0 |
| 4224 | end |
| 4225 | nd = gu b add add q 4 nw |
| 4226 | if gt nd 96 |
| 4227 | ret 0 |
| 4228 | end |
| 4229 | q = add add add q 5 nw nd |
| 4230 | if gt q c |
| 4231 | ret 0 |
| 4232 | end |
| 4233 | end |
| 4234 | head = k_b |
| 4235 | if gt p 0 |
| 4236 | head = gi b get d_po sub p 1 |
| 4237 | end |
| 4238 | po ob 0 head |
| 4239 | for i ulong p |
| 4240 | q = get d_po i |
| 4241 | s = gi b add q 2 |
| 4242 | sg = ulong 1 |
| 4243 | if gt i 0 |
| 4244 | pq = get d_po sub i 1 |
| 4245 | sg = swstarts gi b add pq 2 gi b add pq 1 s gi b add q 1 |
| 4246 | end |
| 4247 | po ob add 4 i add k_b sg |
| 4248 | if and ge s k_b lt s add k_b n |
| 4249 | sm = sub s k_b |
| 4250 | put d_cnt sm add get d_cnt sm 1 |
| 4251 | put d_last sm i |
| 4252 | end |
| 4253 | nw = gu b add q 3 |
| 4254 | for k ulong nw |
| 4255 | w = gi b add add q 4 k |
| 4256 | if ne w s |
| 4257 | if and ge w k_b lt w add k_b n |
| 4258 | wm = sub w k_b |
| 4259 | put d_cnt wm add get d_cnt wm 1 |
| 4260 | put d_last wm i |
| 4261 | end |
| 4262 | end |
| 4263 | end |
| 4264 | end |
| 4265 | base = add 4 p |
| 4266 | for m ulong n |
| 4267 | last = get d_last m |
| 4268 | age = sub k_b 1 |
| 4269 | if lt last 1000 |
| 4270 | pt = gi b add get d_po last 1 |
| 4271 | if gt pt k_b |
| 4272 | age = k_b |
| 4273 | if gt now pt |
| 4274 | age = add k_b sub now pt |
| 4275 | end |
| 4276 | end |
| 4277 | end |
| 4278 | st = swstate get d_kill m get d_turn m get d_wake m roster age |
| 4279 | idle = sub k_b 1 |
| 4280 | if eq roster add k_b 1 |
| 4281 | lm = get d_lm m |
| 4282 | if gt lm k_b |
| 4283 | idle = k_b |
| 4284 | if gt now lm |
| 4285 | idle = add k_b sub now lm |
| 4286 | end |
| 4287 | end |
| 4288 | end |
| 4289 | put d_state m st |
| 4290 | put d_att m swatt add k_b st get d_fail m idle |
| 4291 | unr = sub k_b 1 |
| 4292 | if eq roster add k_b 1 |
| 4293 | lr = get d_lr m |
| 4294 | if ge lr k_b |
| 4295 | unr = k_b |
| 4296 | if gt head lr |
| 4297 | unr = add k_b sub head lr |
| 4298 | end |
| 4299 | end |
| 4300 | end |
| 4301 | po ob add base m add k_b get d_cnt m |
| 4302 | lp = sub k_b 1 |
| 4303 | if lt last 1000 |
| 4304 | lp = add k_b last |
| 4305 | end |
| 4306 | po ob add add base n m lp |
| 4307 | po ob add add base mul n 2 m add k_b st |
| 4308 | po ob add add base mul n 3 m add k_b get d_att m |
| 4309 | po ob add add base mul n 4 m idle |
| 4310 | po ob add add base mul n 5 m unr |
| 4311 | hp = ulong 0 |
| 4312 | if eq get d_role m 2 |
| 4313 | hp = 1 |
| 4314 | end |
| 4315 | po ob add add base mul n 6 m add k_b hp |
| 4316 | end |
| 4317 | working = ulong 0 |
| 4318 | waiting = ulong 0 |
| 4319 | stopped = ulong 0 |
| 4320 | for m ulong n |
| 4321 | on = ulong 1000 |
| 4322 | seq = k_b |
| 4323 | you = k_b |
| 4324 | last = get d_last m |
| 4325 | if and lt last 1000 ne get d_state m 3 |
| 4326 | q = get d_po last |
| 4327 | nw = gu b add q 3 |
| 4328 | nd = gu b add add q 4 nw |
| 4329 | t0 = add add q 5 nw |
| 4330 | if gt nd 0 |
| 4331 | answered = false |
| 4332 | j = add last 1 |
| 4333 | while lt j p bound 512 |
| 4334 | if answered |
| 4335 | break |
| 4336 | end |
| 4337 | qj = get d_po j |
| 4338 | sj = gi b add qj 2 |
| 4339 | nwj = gu b add qj 3 |
| 4340 | for k ulong nd |
| 4341 | tk = gi b add t0 k |
| 4342 | if eq tk sj |
| 4343 | answered = true |
| 4344 | end |
| 4345 | for k2 ulong nwj |
| 4346 | if eq tk gi b add add qj 4 k2 |
| 4347 | answered = true |
| 4348 | end |
| 4349 | end |
| 4350 | end |
| 4351 | j = add j 1 |
| 4352 | end |
| 4353 | if not answered |
| 4354 | for k ulong nd |
| 4355 | tk = gi b add t0 k |
| 4356 | if and ge tk k_b lt tk add k_b n |
| 4357 | tm2 = sub tk k_b |
| 4358 | if eq get d_own tm2 add k_b 1 |
| 4359 | you = gi b q |
| 4360 | else |
| 4361 | if and eq on 1000 ne get d_state tm2 3 |
| 4362 | on = tm2 |
| 4363 | end |
| 4364 | end |
| 4365 | end |
| 4366 | end |
| 4367 | if lt on 1000 |
| 4368 | seq = gi b q |
| 4369 | end |
| 4370 | end |
| 4371 | end |
| 4372 | end |
| 4373 | wo = sub k_b 1 |
| 4374 | won = ulong 0 |
| 4375 | if lt on 1000 |
| 4376 | wo = add k_b on |
| 4377 | won = 1 |
| 4378 | end |
| 4379 | asks = ulong 0 |
| 4380 | if gt you k_b |
| 4381 | asks = 1 |
| 4382 | end |
| 4383 | g = swgroup add k_b get d_state m add k_b get d_att m add k_b asks add k_b won |
| 4384 | put d_grp m g |
| 4385 | po ob add add base mul n 7 m wo |
| 4386 | po ob add add base mul n 8 m seq |
| 4387 | po ob add add base mul n 9 m you |
| 4388 | po ob add add base mul n 10 m add k_b g |
| 4389 | if ne get d_role m 2 |
| 4390 | if eq get d_state m 1 |
| 4391 | working = add working 1 |
| 4392 | else |
| 4393 | if eq get d_state m 2 |
| 4394 | waiting = add waiting 1 |
| 4395 | else |
| 4396 | stopped = add stopped 1 |
| 4397 | end |
| 4398 | end |
| 4399 | end |
| 4400 | end |
| 4401 | po ob 1 add k_b working |
| 4402 | po ob 2 add k_b waiting |
| 4403 | po ob 3 add k_b stopped |
| 4404 | for pass2 ulong 2 |
| 4405 | for m ulong n |
| 4406 | v = get d_grp m |
| 4407 | if eq pass2 1 |
| 4408 | v = get d_state m |
| 4409 | end |
| 4410 | if ne roster add k_b 1 |
| 4411 | v = mul v 2 |
| 4412 | if eq get d_cnt m 0 |
| 4413 | v = add v 1 |
| 4414 | end |
| 4415 | end |
| 4416 | put d_key m v |
| 4417 | end |
| 4418 | sworder b n |
| 4419 | for m ulong n |
| 4420 | po ob add add base mul n add 11 pass2 m add k_b get d_ord m |
| 4421 | end |
| 4422 | end |
| 4423 | ret add base mul n 13 |
| 4424 | end |
| 4425 | |
| 4426 | note op 12: who addressed whom in the first posts, for the graph. Numbers: the members n, upTo, how many posts |
| 4427 | note have a sender, how many helper flags, how many posts have their co-signers, their addressed members and |
| 4428 | note their to-all flag; then the helper flags (n); then a post each: sender, how many co-signers (4 at most) and |
| 4429 | note who, how many addressed members and who, 1 when it is to all. Helpers are left out. The answer is bytes, |
| 4430 | note six a pair in order of sender then receiver: from, to, how many posts named the receiver (16-bit), how many |
| 4431 | note reached it only because the post was for everyone (16-bit). Returns the reply length |
| 4432 | fn swedges b view uchar 1048576 c ulong ob edit uchar 65544 to ulong |
| 4433 | named = new ulong 96 0 |
| 4434 | if lt c 7 |
| 4435 | ret 0 |
| 4436 | end |
| 4437 | nn = gi b 0 |
| 4438 | if or le nn k_b gt nn add k_b 96 |
| 4439 | ret 0 |
| 4440 | end |
| 4441 | n = sub nn k_b |
| 4442 | upto = gi b 1 |
| 4443 | posts = gu b 2 |
| 4444 | if gt posts 100000 |
| 4445 | ret 0 |
| 4446 | end |
| 4447 | if lt upto add k_b posts |
| 4448 | posts = ulong 0 |
| 4449 | if gt upto k_b |
| 4450 | posts = sub upto k_b |
| 4451 | end |
| 4452 | end |
| 4453 | if or gt posts 400 ne gi b 3 nn |
| 4454 | ret 0 |
| 4455 | end |
| 4456 | if 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 |
| 4457 | ret 0 |
| 4458 | end |
| 4459 | for z ulong mul n n |
| 4460 | put d_cell z 0 |
| 4461 | put d_cell add 9216 z 0 |
| 4462 | end |
| 4463 | hb = ulong 7 |
| 4464 | q = add 7 n |
| 4465 | if gt q c |
| 4466 | ret 0 |
| 4467 | end |
| 4468 | for i ulong posts |
| 4469 | if gt add q 2 c |
| 4470 | ret 0 |
| 4471 | end |
| 4472 | s0 = gi b q |
| 4473 | nw = gu b add q 1 |
| 4474 | if gt nw 4 |
| 4475 | ret 0 |
| 4476 | end |
| 4477 | if gt add add q 3 nw c |
| 4478 | ret 0 |
| 4479 | end |
| 4480 | nd = gu b add add q 2 nw |
| 4481 | if gt nd 96 |
| 4482 | ret 0 |
| 4483 | end |
| 4484 | dq = add add q 3 nw |
| 4485 | if gt add add dq nd 1 c |
| 4486 | ret 0 |
| 4487 | end |
| 4488 | tall = gi b add dq nd |
| 4489 | for s ulong add nw 1 |
| 4490 | from = s0 |
| 4491 | if gt s 0 |
| 4492 | from = gi b add add q 2 sub s 1 |
| 4493 | end |
| 4494 | okf = and ge from k_b lt from add k_b n |
| 4495 | if okf |
| 4496 | if ne gi b add hb sub from k_b k_b |
| 4497 | okf = false |
| 4498 | end |
| 4499 | end |
| 4500 | if okf |
| 4501 | if gt s 0 |
| 4502 | if eq from s0 |
| 4503 | okf = false |
| 4504 | end |
| 4505 | end |
| 4506 | end |
| 4507 | if okf |
| 4508 | f = sub from k_b |
| 4509 | for z ulong n |
| 4510 | put named z 0 |
| 4511 | end |
| 4512 | for k ulong nd |
| 4513 | if lt k n |
| 4514 | tv = gi b add dq k |
| 4515 | if and ge tv k_b lt tv add k_b n |
| 4516 | tt = sub tv k_b |
| 4517 | if and ne tt f eq gi b add hb tt k_b |
| 4518 | if eq get named tt 0 |
| 4519 | put named tt 1 |
| 4520 | put d_cell add mul f n tt add get d_cell add mul f n tt 1 |
| 4521 | end |
| 4522 | end |
| 4523 | end |
| 4524 | end |
| 4525 | end |
| 4526 | if eq tall add k_b 1 |
| 4527 | for tt ulong n |
| 4528 | if and ne tt f eq gi b add hb tt k_b |
| 4529 | if eq get named tt 0 |
| 4530 | put d_cell add 9216 add mul f n tt add get d_cell add 9216 add mul f n tt 1 |
| 4531 | end |
| 4532 | end |
| 4533 | end |
| 4534 | end |
| 4535 | end |
| 4536 | end |
| 4537 | q = add add dq nd 1 |
| 4538 | end |
| 4539 | o = ulong 8 |
| 4540 | for cell ulong mul n n |
| 4541 | dv = get d_cell cell |
| 4542 | av = get d_cell add 9216 cell |
| 4543 | if gt add dv av 0 |
| 4544 | put ob o uchar div cell n |
| 4545 | put ob add o 1 uchar rem cell n |
| 4546 | put ob add o 2 uchar and dv 255 |
| 4547 | put ob add o 3 uchar and shr dv 8 255 |
| 4548 | put ob add o 4 uchar and av 255 |
| 4549 | put ob add o 5 uchar and shr av 8 255 |
| 4550 | o = add o 6 |
| 4551 | end |
| 4552 | end |
| 4553 | ret sub o 8 |
| 4554 | end |
| 4555 | |
| 4556 | note op 14: which members to draw when there are too many for one picture: the keep members with the most posts |
| 4557 | note to or from others (the earlier member wins a tie). Numbers: the members n, 1 to count posts for everyone |
| 4558 | note too, keep, how many edge numbers follow, then the edges, five numbers a row: from, to, count, direct, to all. |
| 4559 | note The answer is a byte a member, 1 when it is picked; a member with no line is never picked |
| 4560 | fn swbusy b view uchar 1048576 c ulong ob edit uchar 65544 to ulong |
| 4561 | weight = new ulong 96 0 |
| 4562 | flag = new ulong 96 0 |
| 4563 | if lt c 4 |
| 4564 | ret 0 |
| 4565 | end |
| 4566 | nn = gi b 0 |
| 4567 | if or le nn k_b gt nn add k_b 96 |
| 4568 | ret 0 |
| 4569 | end |
| 4570 | n = sub nn k_b |
| 4571 | ne2 = gu b 3 |
| 4572 | if ne c add 4 ne2 |
| 4573 | ret 0 |
| 4574 | end |
| 4575 | e = ulong 0 |
| 4576 | while lt add e 4 ne2 bound 16384 |
| 4577 | if ge e 46080 |
| 4578 | break |
| 4579 | end |
| 4580 | from = gi b add 4 e |
| 4581 | tv = gi b add 5 e |
| 4582 | cv = gi b add 7 e |
| 4583 | if eq gi b 1 add k_b 1 |
| 4584 | cv = gi b add 6 e |
| 4585 | end |
| 4586 | if and and ge from k_b lt from add k_b n and ge tv k_b lt tv add k_b n |
| 4587 | if ge cv k_b |
| 4588 | put weight sub from k_b add get weight sub from k_b sub cv k_b |
| 4589 | put weight sub tv k_b add get weight sub tv k_b sub cv k_b |
| 4590 | end |
| 4591 | end |
| 4592 | e = add e 5 |
| 4593 | end |
| 4594 | keep = gi b 2 |
| 4595 | picked = ulong 0 |
| 4596 | while lt picked n bound 128 |
| 4597 | if ge add k_b picked keep |
| 4598 | break |
| 4599 | end |
| 4600 | best = ulong 1000 |
| 4601 | for m ulong n |
| 4602 | if and eq get flag m 0 gt get weight m 0 |
| 4603 | if eq best 1000 |
| 4604 | best = m |
| 4605 | else |
| 4606 | if gt get weight m get weight best |
| 4607 | best = m |
| 4608 | end |
| 4609 | end |
| 4610 | end |
| 4611 | end |
| 4612 | if eq best 1000 |
| 4613 | break |
| 4614 | end |
| 4615 | put flag best 1 |
| 4616 | picked = add picked 1 |
| 4617 | end |
| 4618 | for m ulong n |
| 4619 | put ob add 8 m uchar get flag m |
| 4620 | end |
| 4621 | ret n |
| 4622 | end |
| 4623 | |
| 4624 | note op 13: how many of the first posts each member sent to everyone. Numbers: the members n, upTo, how many posts |
| 4625 | note 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 |
| 4626 | note numbers (none when n is not 1 to 96). Returns the count of numbers |
| 4627 | fn swbroad b view uchar 1048576 c ulong ob edit uchar 65544 to ulong |
| 4628 | outv = new ulong 96 0 |
| 4629 | if lt c 4 |
| 4630 | ret 0 |
| 4631 | end |
| 4632 | nn = gi b 0 |
| 4633 | if or le nn k_b gt nn add k_b 96 |
| 4634 | ret 0 |
| 4635 | end |
| 4636 | n = sub nn k_b |
| 4637 | posts = gu b 2 |
| 4638 | if gt posts 100000 |
| 4639 | posts = ulong 100000 |
| 4640 | end |
| 4641 | upto = gi b 1 |
| 4642 | if lt upto add k_b posts |
| 4643 | posts = ulong 0 |
| 4644 | if gt upto k_b |
| 4645 | posts = sub upto k_b |
| 4646 | end |
| 4647 | end |
| 4648 | na = gu b 3 |
| 4649 | i = ulong 0 |
| 4650 | while lt i posts bound 512 |
| 4651 | if or ge i 400 ge i na |
| 4652 | break |
| 4653 | end |
| 4654 | if gt add 6 mul i 2 c |
| 4655 | break |
| 4656 | end |
| 4657 | s = gi b add 4 mul i 2 |
| 4658 | if eq gi b add 5 mul i 2 add k_b 1 |
| 4659 | if and ge s k_b lt s add k_b n |
| 4660 | put outv sub s k_b add get outv sub s k_b 1 |
| 4661 | end |
| 4662 | end |
| 4663 | i = add i 1 |
| 4664 | end |
| 4665 | for m ulong n |
| 4666 | po ob m add k_b get outv m |
| 4667 | end |
| 4668 | ret n |
| 4669 | end |
| 4670 | |
| 4671 | note ---- the one box: which rows it shows for a typed text, and in which order (kind 7 op 17) ---- |
| 4672 | note Numbers: 0 the characters of the typed text (trimmed, lower case), 1 its bytes, 2 a web address (0 no, 1 typed |
| 4673 | note with its scheme, 2 bare), 3 1 when this Mac has finished searching its files, 4 1 when a file has exactly that |
| 4674 | note name, 5 1 for a question, 6 1 when a sentence may go to the agent; 7 to 12 the counts of apps, files, |
| 4675 | note screens, commands, accounts and copied things; then four an app (how well it matched, how much it is used, |
| 4676 | note its lift from habit, 1 when it was in front before), three a file (its match, its use, 1 when it is an app |
| 4677 | note already listed), two an account (1 when its name holds the text, 1 when it starts with it), one a copied |
| 4678 | note thing (1 when pinned); then for each screen and each command a count of words and their lengths. Bytes: the |
| 4679 | note text, then those words. The rows: the 8 best apps (match + 40 + use + half the lift + 10 for the one in |
| 4680 | note front before); the address (150 with a scheme; bare, only after the file search: 95, or 3 when a file has |
| 4681 | note that name); from 2 characters a screen (230 named, 125 a word starts so), a command (220; 110 from 3 |
| 4682 | note characters when a word starts so) and each matching account (95 when it starts so, else 70); the first 8 |
| 4683 | note copied things (85 less the place, 10 more when pinned); the first 12 files that are not apps (match + use); |
| 4684 | note Ask (1000 for a question, else 2); the agent (999 when nothing else matched, it is not a question and a |
| 4685 | note sentence may go to it, else 1). Highest first; equal rows stay in this order. |
| 4686 | note The answer: the count of rows, then four numbers a row: its kind (1 app, 2 address, 3 screen, 4 command, |
| 4687 | note 5 account, 6 copied, 7 file, 8 ask, 9 agent), its place in its list, its score, 1 for the promoted agent |
| 4688 | global r_kind ulong 1024 |
| 4689 | global r_idx ulong 1024 |
| 4690 | global r_score ulong 1024 |
| 4691 | global r_flag ulong 1024 |
| 4692 | global r_as ulong 2048 |
| 4693 | global r_ao ulong 2048 |
| 4694 | |
| 4695 | fn rkadd n ulong kind ulong idx ulong score ulong flag ulong to ulong |
| 4696 | if ge n 1024 |
| 4697 | ret n |
| 4698 | end |
| 4699 | put r_kind n kind |
| 4700 | put r_idx n idx |
| 4701 | put r_score n score |
| 4702 | put r_flag n flag |
| 4703 | ret add n 1 |
| 4704 | end |
| 4705 | |
| 4706 | note half of a number as it travels, toward zero |
| 4707 | fn rkhalf v ulong to ulong |
| 4708 | if ge v k_b |
| 4709 | ret add k_b div sub v k_b 2 |
| 4710 | end |
| 4711 | ret sub k_b div sub k_b v 2 |
| 4712 | end |
| 4713 | |
| 4714 | note the wl bytes at w against the ll bytes of the typed text at lo: equal (md 0), or starting with it (md 1) |
| 4715 | fn rkword b view uchar 1048576 w ulong wl ulong lo ulong ll ulong md ulong to bool |
| 4716 | if eq md 0 |
| 4717 | if ne wl ll |
| 4718 | ret false |
| 4719 | end |
| 4720 | else |
| 4721 | if lt wl ll |
| 4722 | ret false |
| 4723 | end |
| 4724 | end |
| 4725 | i = ulong 0 |
| 4726 | while lt i ll bound 999999 |
| 4727 | if ne ulong get b add w i ulong get b add lo i |
| 4728 | ret false |
| 4729 | end |
| 4730 | i = add i 1 |
| 4731 | end |
| 4732 | ret true |
| 4733 | end |
| 4734 | |
| 4735 | note the n rows, highest score first (equal rows stay in their order), as the answer: the count, then four numbers |
| 4736 | note a row (kind, place, score, flag); how many numbers that is |
| 4737 | fn rkout n ulong ob edit uchar 65544 to ulong |
| 4738 | for i ulong n |
| 4739 | s = get r_score i |
| 4740 | pos = i |
| 4741 | while gt pos 0 bound 2048 |
| 4742 | p = get r_ao sub pos 1 |
| 4743 | if ge get r_score p s |
| 4744 | break |
| 4745 | end |
| 4746 | put r_ao pos p |
| 4747 | pos = sub pos 1 |
| 4748 | end |
| 4749 | put r_ao pos i |
| 4750 | end |
| 4751 | po ob 0 add k_b n |
| 4752 | for i ulong n |
| 4753 | x = get r_ao i |
| 4754 | o = add 1 mul i 4 |
| 4755 | po ob o add k_b get r_kind x |
| 4756 | po ob add o 1 add k_b get r_idx x |
| 4757 | po ob add o 2 get r_score x |
| 4758 | po ob add o 3 add k_b get r_flag x |
| 4759 | end |
| 4760 | ret add 1 mul n 4 |
| 4761 | end |
| 4762 | |
| 4763 | fn swrank b view uchar 1048576 c ulong nbytes ulong ob edit uchar 65544 to ulong |
| 4764 | if lt c 13 |
| 4765 | ret 0 |
| 4766 | end |
| 4767 | lcn = gu b 0 |
| 4768 | ll = gu b 1 |
| 4769 | na = gu b 7 |
| 4770 | nf = gu b 8 |
| 4771 | ns = gu b 9 |
| 4772 | nc = gu b 10 |
| 4773 | nacc = gu b 11 |
| 4774 | ncl = gu b 12 |
| 4775 | if or or gt na 2048 gt nf 4000 or gt ns 32 gt nc 32 |
| 4776 | ret 0 |
| 4777 | end |
| 4778 | if or gt nacc 800 or gt ncl 64 gt ll 100000 |
| 4779 | ret 0 |
| 4780 | end |
| 4781 | pa = ulong 13 |
| 4782 | pf = add pa mul na 4 |
| 4783 | pacc = add pf mul nf 3 |
| 4784 | pcl = add pacc mul nacc 2 |
| 4785 | q = add pcl ncl |
| 4786 | if gt q c |
| 4787 | ret 0 |
| 4788 | end |
| 4789 | lo = add 8 mul c 8 |
| 4790 | tend = add lo nbytes |
| 4791 | wp = add lo ll |
| 4792 | if gt wp tend |
| 4793 | ret 0 |
| 4794 | end |
| 4795 | n = ulong 0 |
| 4796 | for i ulong na |
| 4797 | o = add pa mul i 4 |
| 4798 | s = sub add add add gi b o gi b add o 1 rkhalf gi b add o 2 40 mul 2 k_b |
| 4799 | if eq gi b add o 3 add k_b 1 |
| 4800 | s = add s 10 |
| 4801 | end |
| 4802 | put r_as i s |
| 4803 | pos = i |
| 4804 | while gt pos 0 bound 4096 |
| 4805 | p = get r_ao sub pos 1 |
| 4806 | if ge get r_as p s |
| 4807 | break |
| 4808 | end |
| 4809 | put r_ao pos p |
| 4810 | pos = sub pos 1 |
| 4811 | end |
| 4812 | put r_ao pos i |
| 4813 | end |
| 4814 | for i ulong na |
| 4815 | if lt i 8 |
| 4816 | n = rkadd n 1 get r_ao i get r_as get r_ao i 0 |
| 4817 | end |
| 4818 | end |
| 4819 | adr = gi b 2 |
| 4820 | if eq adr add k_b 1 |
| 4821 | n = rkadd n 2 0 add k_b 150 0 |
| 4822 | end |
| 4823 | if and eq adr add k_b 2 eq gi b 3 add k_b 1 |
| 4824 | sc = add k_b 95 |
| 4825 | if eq gi b 4 add k_b 1 |
| 4826 | sc = add k_b 3 |
| 4827 | end |
| 4828 | n = rkadd n 2 0 sc 0 |
| 4829 | end |
| 4830 | for pass3 ulong 2 |
| 4831 | cntw = ns |
| 4832 | if eq pass3 1 |
| 4833 | cntw = nc |
| 4834 | end |
| 4835 | for k ulong cntw |
| 4836 | if ge q c |
| 4837 | ret 0 |
| 4838 | end |
| 4839 | nw = gu b q |
| 4840 | q = add q 1 |
| 4841 | if gt nw 64 |
| 4842 | ret 0 |
| 4843 | end |
| 4844 | exact = false |
| 4845 | pre = false |
| 4846 | for w ulong nw |
| 4847 | if ge q c |
| 4848 | ret 0 |
| 4849 | end |
| 4850 | wl = gu b q |
| 4851 | q = add q 1 |
| 4852 | if gt add wp wl tend |
| 4853 | ret 0 |
| 4854 | end |
| 4855 | if rkword b wp wl lo ll 0 |
| 4856 | exact = true |
| 4857 | end |
| 4858 | if rkword b wp wl lo ll 1 |
| 4859 | pre = true |
| 4860 | end |
| 4861 | wp = add wp wl |
| 4862 | end |
| 4863 | if ge lcn 2 |
| 4864 | if eq pass3 0 |
| 4865 | if exact |
| 4866 | n = rkadd n 3 k add k_b 230 0 |
| 4867 | else |
| 4868 | if pre |
| 4869 | n = rkadd n 3 k add k_b 125 0 |
| 4870 | end |
| 4871 | end |
| 4872 | else |
| 4873 | if exact |
| 4874 | n = rkadd n 4 k add k_b 220 0 |
| 4875 | else |
| 4876 | if and pre ge lcn 3 |
| 4877 | n = rkadd n 4 k add k_b 110 0 |
| 4878 | end |
| 4879 | end |
| 4880 | end |
| 4881 | end |
| 4882 | end |
| 4883 | end |
| 4884 | if ge lcn 2 |
| 4885 | for i ulong nacc |
| 4886 | if eq gi b add pacc mul i 2 add k_b 1 |
| 4887 | sc = add k_b 70 |
| 4888 | if eq gi b add add pacc mul i 2 1 add k_b 1 |
| 4889 | sc = add k_b 95 |
| 4890 | end |
| 4891 | n = rkadd n 5 i sc 0 |
| 4892 | end |
| 4893 | end |
| 4894 | end |
| 4895 | for i ulong ncl |
| 4896 | if lt i 8 |
| 4897 | sc = sub add k_b 85 i |
| 4898 | if eq gi b add pcl i add k_b 1 |
| 4899 | sc = add sc 10 |
| 4900 | end |
| 4901 | n = rkadd n 6 i sc 0 |
| 4902 | end |
| 4903 | end |
| 4904 | shown = ulong 0 |
| 4905 | for i ulong nf |
| 4906 | o = add pf mul i 3 |
| 4907 | if and ne gi b add o 2 add k_b 1 lt shown 12 |
| 4908 | n = rkadd n 7 i sub add gi b o gi b add o 1 k_b 0 |
| 4909 | shown = add shown 1 |
| 4910 | end |
| 4911 | end |
| 4912 | nothing = eq n 0 |
| 4913 | quest = eq gi b 5 add k_b 1 |
| 4914 | sc = add k_b 2 |
| 4915 | if quest |
| 4916 | sc = add k_b 1000 |
| 4917 | end |
| 4918 | n = rkadd n 8 0 sc 0 |
| 4919 | prom = ulong 0 |
| 4920 | sc = add k_b 1 |
| 4921 | if and and not quest nothing eq gi b 6 add k_b 1 |
| 4922 | prom = 1 |
| 4923 | sc = add k_b 999 |
| 4924 | end |
| 4925 | n = rkadd n 9 0 sc prom |
| 4926 | ret rkout n ob |
| 4927 | end |
| 4928 | |
| 4929 | note ---- the one box before anything is typed: what to offer (kind 7 op 18) ---- |
| 4930 | note Numbers: 0 1 when something was copied, 1 how many seconds ago, 2 1 when it is a web address written with |
| 4931 | note http, 3 1 when the app in front is a browser, 4 how many other copied things follow (at most 20), 5 1 when |
| 4932 | note the clipboard history is paused, 6 the count of apps; then six an app: its lift from the app in front, its |
| 4933 | note lift from the hour, how much it is used, 1 when it is running, 1 when it was in front before, and its |
| 4934 | note points for being in front lately. The apps come in the order of their ids, which settles equal scores. |
| 4935 | note The rows: the copied thing (130 under a minute old, 95 under ten, else 70) and, for an address, a row to |
| 4936 | note open it (5 more, or 5 less when a browser is in front); the six best apps among those with a lift, some |
| 4937 | note use, running or in front before (40 + both lifts + a quarter of the use + 45 in front before + 8 running + |
| 4938 | note the points for lately); the other copied things (38 less the place); the clipboard screen at 39 when the |
| 4939 | note history is paused. Highest first; equal rows stay in this order. |
| 4940 | note The answer: the count of rows, then four numbers a row: its kind (1 app, 2 address, 3 the clipboard |
| 4941 | note screen, 6 copied), its place (an app's place in the list; 0 the newest copied thing, then 1 and up), its |
| 4942 | note score, and why it is offered (0 nothing said, 1 just copied, 2 the last thing copied, 3 a copied address, |
| 4943 | note 4 often opened from here, 5 just here, 6 often opened around now, 7 among the most used, 8 running now, |
| 4944 | note 9 the history is paused) |
| 4945 | global s_ps ulong 8 |
| 4946 | global s_pi ulong 8 |
| 4947 | global s_pw ulong 8 |
| 4948 | |
| 4949 | fn swsuggest b view uchar 1048576 c ulong ob edit uchar 65544 to ulong |
| 4950 | if lt c 7 |
| 4951 | ret 0 |
| 4952 | end |
| 4953 | rest = gu b 4 |
| 4954 | na = gu b 6 |
| 4955 | if or gt na 2048 gt rest 20 |
| 4956 | ret 0 |
| 4957 | end |
| 4958 | if ne c add 7 mul na 6 |
| 4959 | ret 0 |
| 4960 | end |
| 4961 | n = ulong 0 |
| 4962 | if eq gi b 0 add k_b 1 |
| 4963 | age = gi b 1 |
| 4964 | s = ulong 70 |
| 4965 | why = ulong 2 |
| 4966 | if lt age add k_b 600 |
| 4967 | s = 95 |
| 4968 | why = 1 |
| 4969 | end |
| 4970 | if lt age add k_b 60 |
| 4971 | s = 130 |
| 4972 | end |
| 4973 | n = rkadd n 6 0 add k_b s why |
| 4974 | if eq gi b 2 add k_b 1 |
| 4975 | if eq gi b 3 add k_b 1 |
| 4976 | n = rkadd n 2 0 add k_b sub s 5 3 |
| 4977 | else |
| 4978 | n = rkadd n 2 0 add k_b add s 5 3 |
| 4979 | end |
| 4980 | end |
| 4981 | end |
| 4982 | cnt = ulong 0 |
| 4983 | for i ulong na |
| 4984 | o = add 7 mul i 6 |
| 4985 | lf = gu b o |
| 4986 | lh = gu b add o 1 |
| 4987 | used = gu b add o 2 |
| 4988 | run = eq gi b add o 3 add k_b 1 |
| 4989 | prev = eq gi b add o 4 add k_b 1 |
| 4990 | lately = gu b add o 5 |
| 4991 | if or or gt add lf lh 0 gt used 0 or run prev |
| 4992 | sc = add add add 40 lf lh div used 4 |
| 4993 | if prev |
| 4994 | sc = add sc 45 |
| 4995 | end |
| 4996 | if run |
| 4997 | sc = add sc 8 |
| 4998 | end |
| 4999 | sc = add sc lately |
| 5000 | why = ulong 8 |
| 5001 | if gt used 0 |
| 5002 | why = 7 |
| 5003 | end |
| 5004 | if gt lh 0 |
| 5005 | why = 6 |
| 5006 | end |
| 5007 | if prev |
| 5008 | why = 5 |
| 5009 | end |
| 5010 | if gt lf 0 |
| 5011 | why = 4 |
| 5012 | end |
| 5013 | keep = true |
| 5014 | pos = cnt |
| 5015 | if eq cnt 6 |
| 5016 | if le sc get s_ps 5 |
| 5017 | keep = false |
| 5018 | end |
| 5019 | pos = 5 |
| 5020 | else |
| 5021 | cnt = add cnt 1 |
| 5022 | end |
| 5023 | if keep |
| 5024 | while gt pos 0 bound 8 |
| 5025 | if ge get s_ps sub pos 1 sc |
| 5026 | break |
| 5027 | end |
| 5028 | put s_ps pos get s_ps sub pos 1 |
| 5029 | put s_pi pos get s_pi sub pos 1 |
| 5030 | put s_pw pos get s_pw sub pos 1 |
| 5031 | pos = sub pos 1 |
| 5032 | end |
| 5033 | put s_ps pos sc |
| 5034 | put s_pi pos i |
| 5035 | put s_pw pos why |
| 5036 | end |
| 5037 | end |
| 5038 | end |
| 5039 | for j ulong cnt |
| 5040 | n = rkadd n 1 get s_pi j add k_b get s_ps j get s_pw j |
| 5041 | end |
| 5042 | for i ulong rest |
| 5043 | n = rkadd n 6 add 1 i add k_b sub 38 i 0 |
| 5044 | end |
| 5045 | if eq gi b 5 add k_b 1 |
| 5046 | n = rkadd n 3 0 add k_b 39 9 |
| 5047 | end |
| 5048 | ret rkout n ob |
| 5049 | end |
| 5050 | |
| 5051 | note ---- habits: how much an app is lifted by where and when it is usually opened (kind 7 op 19) ---- |
| 5052 | note Numbers: 0 the hour now, 1 1 when an app is in front, 2 the count of apps, 3 the count of remembered |
| 5053 | note launches; then three a launch: 1 when it was made from the app now in front, its hour, and which app it |
| 5054 | note opened (its place in the list, or -1 for an app not in it). A habit counts from the second time. An app's |
| 5055 | note lift from the app in front is 60 times its share of the launches made from there; its lift from the hour |
| 5056 | note is 25 times its share of the launches within an hour of now (23 and 0 are an hour apart). |
| 5057 | note The answer: the count of apps, then two numbers an app: the lift from the app in front, the lift from the hour |
| 5058 | fn swlifts b view uchar 1048576 c ulong ob edit uchar 65544 to ulong |
| 5059 | if lt c 4 |
| 5060 | ret 0 |
| 5061 | end |
| 5062 | hour = gi b 0 |
| 5063 | front = eq gi b 1 add k_b 1 |
| 5064 | na = gu b 2 |
| 5065 | nl = gu b 3 |
| 5066 | if or gt na 2048 gt nl 4096 |
| 5067 | ret 0 |
| 5068 | end |
| 5069 | if ne c add 4 mul nl 3 |
| 5070 | ret 0 |
| 5071 | end |
| 5072 | for i ulong na |
| 5073 | put r_as i 0 |
| 5074 | put r_ao i 0 |
| 5075 | end |
| 5076 | ft = ulong 0 |
| 5077 | nt = ulong 0 |
| 5078 | for j ulong nl |
| 5079 | o = add 4 mul j 3 |
| 5080 | here = and front eq gi b o add k_b 1 |
| 5081 | h = gi b add o 1 |
| 5082 | d = ulong 0 |
| 5083 | if ge h hour |
| 5084 | d = sub h hour |
| 5085 | else |
| 5086 | d = sub hour h |
| 5087 | end |
| 5088 | nearh = or le d 1 ge d 23 |
| 5089 | a = gi b add o 2 |
| 5090 | ix = na |
| 5091 | if ge a k_b |
| 5092 | if lt sub a k_b na |
| 5093 | ix = sub a k_b |
| 5094 | end |
| 5095 | end |
| 5096 | if here |
| 5097 | ft = add ft 1 |
| 5098 | if lt ix na |
| 5099 | put r_as ix add get r_as ix 1 |
| 5100 | end |
| 5101 | end |
| 5102 | if nearh |
| 5103 | nt = add nt 1 |
| 5104 | if lt ix na |
| 5105 | put r_ao ix add get r_ao ix 1 |
| 5106 | end |
| 5107 | end |
| 5108 | end |
| 5109 | po ob 0 add k_b na |
| 5110 | for i ulong na |
| 5111 | f = ulong 0 |
| 5112 | if ge get r_as i 2 |
| 5113 | f = div mul 60 get r_as i ft |
| 5114 | end |
| 5115 | g = ulong 0 |
| 5116 | if ge get r_ao i 2 |
| 5117 | g = div mul 25 get r_ao i nt |
| 5118 | end |
| 5119 | po ob add 1 mul i 2 add k_b f |
| 5120 | po ob add 2 mul i 2 add k_b g |
| 5121 | end |
| 5122 | ret add 1 mul na 2 |
| 5123 | end |
| 5124 | |
| 5125 | note ---- AES-256-GCM, for Hop's encrypted clipboard history (kind 7 op 20) ---- |
| 5126 | note The history is sealed as CryptoKit's AES.GCM seals it: a 256-bit key, a 12-byte nonce, no added data, a |
| 5127 | note 16-byte tag. This is that cipher in Omega: AES by its definition (the S-box is worked out, not listed), the |
| 5128 | note counter mode, and the tag by GHASH with a table of 16 multiples of the hash key. The work is done on |
| 5129 | note 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 |
| 5130 | note the tag over the whole data before any of it is unsealed, and compares all 16 bytes whatever they are. It is |
| 5131 | note not written to run in the same time for every key (the tables are indexed by secret bytes): it is for |
| 5132 | note files on the person's own Mac, not for a service others can time. |
| 5133 | note Request: two numbers (1 to seal, 0 to unseal; the count of data bytes, 4096 at most), then the bytes: the |
| 5134 | note key, the nonce, the data, and to unseal the tag. Answer to unseal: 1 and the data's bytes, or 0 alone when |
| 5135 | note the tag is not the data's. Answer to seal: 1, the sealed bytes, the 16 bytes of the tag. |
| 5136 | global c_sb uchar 256 |
| 5137 | global c_m2 uchar 256 |
| 5138 | global c_l4 ulong 16 |
| 5139 | global c_rd ulong 1 |
| 5140 | global c_k uchar 32 |
| 5141 | global c_n uchar 12 |
| 5142 | global c_tg uchar 16 |
| 5143 | global c_rk uchar 240 |
| 5144 | global c_st uchar 16 |
| 5145 | global c_tm uchar 16 |
| 5146 | global c_y uchar 16 |
| 5147 | global c_x uchar 16 |
| 5148 | global c_hh ulong 16 |
| 5149 | global c_hl ulong 16 |
| 5150 | global c_d uchar 16777216 |
| 5151 | |
| 5152 | note the tables that do not depend on the key: the S-box (the inverse in the field, then the affine step), the |
| 5153 | note doubling in the field, and the 16 reductions of GHASH |
| 5154 | fn gcinit to void |
| 5155 | if eq get c_rd 0 1 |
| 5156 | ret |
| 5157 | end |
| 5158 | p = ulong 1 |
| 5159 | q = ulong 1 |
| 5160 | for i ulong 255 |
| 5161 | t = xor p shl p 1 |
| 5162 | if ne and p 128 0 |
| 5163 | t = xor t 27 |
| 5164 | end |
| 5165 | p = and t 255 |
| 5166 | q = and xor q shl q 1 255 |
| 5167 | q = and xor q shl q 2 255 |
| 5168 | q = and xor q shl q 4 255 |
| 5169 | if ne and q 128 0 |
| 5170 | q = xor q 9 |
| 5171 | end |
| 5172 | r1 = and or shl q 1 shr q 7 255 |
| 5173 | r2 = and or shl q 2 shr q 6 255 |
| 5174 | r3 = and or shl q 3 shr q 5 255 |
| 5175 | r4 = and or shl q 4 shr q 4 255 |
| 5176 | x = xor xor xor xor q r1 r2 r3 r4 |
| 5177 | put c_sb p uchar xor x 99 |
| 5178 | end |
| 5179 | put c_sb 0 99 |
| 5180 | for i ulong 256 |
| 5181 | d = shl i 1 |
| 5182 | if ne and i 128 0 |
| 5183 | d = xor d 27 |
| 5184 | end |
| 5185 | put c_m2 i uchar and d 255 |
| 5186 | end |
| 5187 | put c_l4 0 0 |
| 5188 | put c_l4 1 7200 |
| 5189 | put c_l4 2 14400 |
| 5190 | put c_l4 3 9312 |
| 5191 | put c_l4 4 28800 |
| 5192 | put c_l4 5 27808 |
| 5193 | put c_l4 6 18624 |
| 5194 | put c_l4 7 21728 |
| 5195 | put c_l4 8 57600 |
| 5196 | put c_l4 9 64800 |
| 5197 | put c_l4 10 55616 |
| 5198 | put c_l4 11 50528 |
| 5199 | put c_l4 12 37248 |
| 5200 | put c_l4 13 36256 |
| 5201 | put c_l4 14 43456 |
| 5202 | put c_l4 15 46560 |
| 5203 | put c_rd 0 1 |
| 5204 | end |
| 5205 | |
| 5206 | note the cipher on the 16 bytes of c_st, with the round keys of c_rk |
| 5207 | fn gcblk to void |
| 5208 | for i ulong 16 |
| 5209 | put c_st i uchar xor ulong get c_st i ulong get c_rk i |
| 5210 | end |
| 5211 | for r ulong 14 |
| 5212 | rk = mul add r 1 16 |
| 5213 | for cc ulong 4 |
| 5214 | for w ulong 4 |
| 5215 | put c_tm add mul cc 4 w get c_sb ulong get c_st add mul and add cc w 3 4 w |
| 5216 | end |
| 5217 | end |
| 5218 | if lt r 13 |
| 5219 | for cc ulong 4 |
| 5220 | o = mul cc 4 |
| 5221 | a0 = ulong get c_tm o |
| 5222 | a1 = ulong get c_tm add o 1 |
| 5223 | a2 = ulong get c_tm add o 2 |
| 5224 | a3 = ulong get c_tm add o 3 |
| 5225 | d0 = ulong get c_m2 a0 |
| 5226 | d1 = ulong get c_m2 a1 |
| 5227 | d2 = ulong get c_m2 a2 |
| 5228 | d3 = ulong get c_m2 a3 |
| 5229 | put c_st o uchar xor xor xor xor xor d0 d1 a1 a2 a3 ulong get c_rk add rk o |
| 5230 | put 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 |
| 5231 | put 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 |
| 5232 | put 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 |
| 5233 | end |
| 5234 | else |
| 5235 | for i ulong 16 |
| 5236 | put c_st i uchar xor ulong get c_tm i ulong get c_rk add rk i |
| 5237 | end |
| 5238 | end |
| 5239 | end |
| 5240 | end |
| 5241 | |
| 5242 | note 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 |
| 5243 | note bytes) into c_hh and c_hl |
| 5244 | fn gckey to void |
| 5245 | gcinit |
| 5246 | for i ulong 32 |
| 5247 | put c_rk i get c_k i |
| 5248 | end |
| 5249 | rc = ulong 1 |
| 5250 | for w ulong 52 |
| 5251 | i = add w 8 |
| 5252 | o = mul i 4 |
| 5253 | t0 = ulong get c_rk sub o 4 |
| 5254 | t1 = ulong get c_rk sub o 3 |
| 5255 | t2 = ulong get c_rk sub o 2 |
| 5256 | t3 = ulong get c_rk sub o 1 |
| 5257 | if eq and i 7 0 |
| 5258 | u0 = xor ulong get c_sb t1 rc |
| 5259 | u1 = ulong get c_sb t2 |
| 5260 | u2 = ulong get c_sb t3 |
| 5261 | u3 = ulong get c_sb t0 |
| 5262 | rc = ulong get c_m2 rc |
| 5263 | t0 = u0 |
| 5264 | t1 = u1 |
| 5265 | t2 = u2 |
| 5266 | t3 = u3 |
| 5267 | end |
| 5268 | if eq and i 7 4 |
| 5269 | t0 = ulong get c_sb t0 |
| 5270 | t1 = ulong get c_sb t1 |
| 5271 | t2 = ulong get c_sb t2 |
| 5272 | t3 = ulong get c_sb t3 |
| 5273 | end |
| 5274 | put c_rk o uchar xor ulong get c_rk sub o 32 t0 |
| 5275 | put c_rk add o 1 uchar xor ulong get c_rk sub o 31 t1 |
| 5276 | put c_rk add o 2 uchar xor ulong get c_rk sub o 30 t2 |
| 5277 | put c_rk add o 3 uchar xor ulong get c_rk sub o 29 t3 |
| 5278 | end |
| 5279 | for i ulong 16 |
| 5280 | put c_st i 0 |
| 5281 | end |
| 5282 | gcblk |
| 5283 | vh = ulong 0 |
| 5284 | vl = ulong 0 |
| 5285 | for i ulong 8 |
| 5286 | vh = or shl vh 8 ulong get c_st i |
| 5287 | vl = or shl vl 8 ulong get c_st add 8 i |
| 5288 | end |
| 5289 | put c_hh 0 0 |
| 5290 | put c_hl 0 0 |
| 5291 | put c_hh 8 vh |
| 5292 | put c_hl 8 vl |
| 5293 | ix = ulong 4 |
| 5294 | for s ulong 3 |
| 5295 | tt = ulong 0 |
| 5296 | if ne and vl 1 0 |
| 5297 | tt = 16212958658533785600 |
| 5298 | end |
| 5299 | vl = or shl vh 63 shr vl 1 |
| 5300 | vh = xor shr vh 1 tt |
| 5301 | put c_hl ix vl |
| 5302 | put c_hh ix vh |
| 5303 | ix = shr ix 1 |
| 5304 | end |
| 5305 | ix = 2 |
| 5306 | for s ulong 3 |
| 5307 | for j ulong sub ix 1 |
| 5308 | jj = add j 1 |
| 5309 | put c_hh add ix jj xor get c_hh ix get c_hh jj |
| 5310 | put c_hl add ix jj xor get c_hl ix get c_hl jj |
| 5311 | end |
| 5312 | ix = shl ix 1 |
| 5313 | end |
| 5314 | end |
| 5315 | |
| 5316 | note c_y times the hash key, in the field of GHASH |
| 5317 | fn gcmul to void |
| 5318 | nlo = and ulong get c_y 15 15 |
| 5319 | zh = get c_hh nlo |
| 5320 | zl = get c_hl nlo |
| 5321 | for s ulong 16 |
| 5322 | bv = ulong get c_y sub 15 s |
| 5323 | nlo = and bv 15 |
| 5324 | nhi = shr bv 4 |
| 5325 | if ne s 0 |
| 5326 | r4 = and zl 15 |
| 5327 | zl = or shl zh 60 shr zl 4 |
| 5328 | zh = xor shr zh 4 shl get c_l4 r4 48 |
| 5329 | zh = xor zh get c_hh nlo |
| 5330 | zl = xor zl get c_hl nlo |
| 5331 | end |
| 5332 | r4 = and zl 15 |
| 5333 | zl = or shl zh 60 shr zl 4 |
| 5334 | zh = xor shr zh 4 shl get c_l4 r4 48 |
| 5335 | zh = xor zh get c_hh nhi |
| 5336 | zl = xor zl get c_hl nhi |
| 5337 | end |
| 5338 | for i ulong 8 |
| 5339 | sh = mul sub 7 i 8 |
| 5340 | put c_y i uchar and shr zh sh 255 |
| 5341 | put c_y add 8 i uchar and shr zl sh 255 |
| 5342 | end |
| 5343 | end |
| 5344 | |
| 5345 | note the tag of the n sealed bytes of c_d under the key and the nonce, into c_x |
| 5346 | fn gctag n ulong to void |
| 5347 | for i ulong 16 |
| 5348 | put c_y i 0 |
| 5349 | end |
| 5350 | nb = div add n 15 16 |
| 5351 | bk = ulong 0 |
| 5352 | for seg ulong 17 |
| 5353 | while and lt bk nb lt bk mul add seg 1 65536 bound 70000 |
| 5354 | o = mul bk 16 |
| 5355 | m = sub n o |
| 5356 | if gt m 16 |
| 5357 | m = 16 |
| 5358 | end |
| 5359 | for j ulong m bound 16 |
| 5360 | put c_y j uchar xor ulong get c_y j ulong get c_d add o j |
| 5361 | end |
| 5362 | gcmul |
| 5363 | bk = add bk 1 |
| 5364 | end |
| 5365 | end |
| 5366 | bits = mul n 8 |
| 5367 | for j ulong 8 |
| 5368 | put c_y add 8 j uchar xor ulong get c_y add 8 j and shr bits mul sub 7 j 8 255 |
| 5369 | end |
| 5370 | gcmul |
| 5371 | for i ulong 12 |
| 5372 | put c_st i get c_n i |
| 5373 | end |
| 5374 | put c_st 12 0 |
| 5375 | put c_st 13 0 |
| 5376 | put c_st 14 0 |
| 5377 | put c_st 15 1 |
| 5378 | gcblk |
| 5379 | for i ulong 16 |
| 5380 | put c_x i uchar xor ulong get c_st i ulong get c_y i |
| 5381 | end |
| 5382 | end |
| 5383 | |
| 5384 | note the n bytes of c_d through the counter mode (sealing and unsealing are the same) |
| 5385 | fn gcctr n ulong to void |
| 5386 | ctr = ulong 2 |
| 5387 | nb = div add n 15 16 |
| 5388 | bk = ulong 0 |
| 5389 | for seg ulong 17 |
| 5390 | while and lt bk nb lt bk mul add seg 1 65536 bound 70000 |
| 5391 | for i ulong 12 |
| 5392 | put c_st i get c_n i |
| 5393 | end |
| 5394 | put c_st 12 uchar and shr ctr 24 255 |
| 5395 | put c_st 13 uchar and shr ctr 16 255 |
| 5396 | put c_st 14 uchar and shr ctr 8 255 |
| 5397 | put c_st 15 uchar and ctr 255 |
| 5398 | gcblk |
| 5399 | o = mul bk 16 |
| 5400 | m = sub n o |
| 5401 | if gt m 16 |
| 5402 | m = 16 |
| 5403 | end |
| 5404 | for j ulong m bound 16 |
| 5405 | put c_d add o j uchar xor ulong get c_d add o j ulong get c_st j |
| 5406 | end |
| 5407 | ctr = add ctr 1 |
| 5408 | bk = add bk 1 |
| 5409 | end |
| 5410 | end |
| 5411 | end |
| 5412 | |
| 5413 | note 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 |
| 5414 | fn gcunlock n ulong to ulong |
| 5415 | if gt n 16777216 |
| 5416 | ret 0 |
| 5417 | end |
| 5418 | gckey |
| 5419 | gctag n |
| 5420 | df = ulong 0 |
| 5421 | for i ulong 16 |
| 5422 | df = or df xor ulong get c_x i ulong get c_tg i |
| 5423 | end |
| 5424 | if ne df 0 |
| 5425 | ret 0 |
| 5426 | end |
| 5427 | gcctr n |
| 5428 | ret 1 |
| 5429 | end |
| 5430 | |
| 5431 | note 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 |
| 5432 | fn gclock n ulong to void |
| 5433 | if gt n 16777216 |
| 5434 | for i ulong 16 |
| 5435 | put c_tg i 0 |
| 5436 | end |
| 5437 | ret |
| 5438 | end |
| 5439 | gckey |
| 5440 | gcctr n |
| 5441 | gctag n |
| 5442 | for i ulong 16 |
| 5443 | put c_tg i get c_x i |
| 5444 | end |
| 5445 | end |
| 5446 | |
| 5447 | note forget the key and everything worked out from it |
| 5448 | fn gcwipe to void |
| 5449 | for i ulong 32 |
| 5450 | put c_k i 0 |
| 5451 | end |
| 5452 | for i ulong 240 |
| 5453 | put c_rk i 0 |
| 5454 | end |
| 5455 | for i ulong 16 |
| 5456 | put c_hh i 0 |
| 5457 | put c_hl i 0 |
| 5458 | put c_st i 0 |
| 5459 | put c_tm i 0 |
| 5460 | put c_y i 0 |
| 5461 | put c_x i 0 |
| 5462 | end |
| 5463 | end |
| 5464 | |
| 5465 | fn swgcm b view uchar 1048576 c ulong nbytes ulong ob edit uchar 65544 to ulong |
| 5466 | if ne c 2 |
| 5467 | ret 0 |
| 5468 | end |
| 5469 | dir = gu b 0 |
| 5470 | n = gu b 1 |
| 5471 | if or gt dir 1 gt n 4096 |
| 5472 | ret 0 |
| 5473 | end |
| 5474 | want = add 44 n |
| 5475 | if eq dir 0 |
| 5476 | want = add want 16 |
| 5477 | end |
| 5478 | if ne nbytes want |
| 5479 | ret 0 |
| 5480 | end |
| 5481 | t0 = add 8 mul c 8 |
| 5482 | for i ulong 32 |
| 5483 | put c_k i get b add t0 i |
| 5484 | end |
| 5485 | for i ulong 12 |
| 5486 | put c_n i get b add add t0 32 i |
| 5487 | end |
| 5488 | for i ulong n bound 4096 |
| 5489 | put c_d i get b add add t0 44 i |
| 5490 | end |
| 5491 | if eq dir 0 |
| 5492 | for i ulong 16 |
| 5493 | put c_tg i get b add add add t0 44 n i |
| 5494 | end |
| 5495 | good = gcunlock n |
| 5496 | gcwipe |
| 5497 | po ob 0 add k_b good |
| 5498 | if eq good 0 |
| 5499 | ret 1 |
| 5500 | end |
| 5501 | for i ulong n bound 4096 |
| 5502 | po ob add 1 i add k_b ulong get c_d i |
| 5503 | end |
| 5504 | ret add 1 n |
| 5505 | end |
| 5506 | gclock n |
| 5507 | gcwipe |
| 5508 | po ob 0 add k_b 1 |
| 5509 | for i ulong n bound 4096 |
| 5510 | po ob add 1 i add k_b ulong get c_d i |
| 5511 | end |
| 5512 | for i ulong 16 |
| 5513 | po ob add add 1 n i add k_b ulong get c_tg i |
| 5514 | end |
| 5515 | ret add 17 n |
| 5516 | end |
| 5517 | |
| 5518 | note kind 7: see the note above. Scalar ops answer one number: 1 state, 2 attention, 3 unread (the newest post |
| 5519 | note less the last one read; -1 not known), 4 group, 5 starts a group, 6 failure (how a member's newest step |
| 5520 | note failed: a model error at once, a failed tool step once it stayed newest for 60 seconds; 3 when the text |
| 5521 | note spoke of quota), 7 the line weight of an edge, 1 to 5, by its count against the heaviest, 8 to 11 as noted. |
| 5522 | note 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). |
| 5523 | note 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 |
| 5524 | note 18446744073709551615 for a malformed request |
| 5525 | fn status ib view uchar 1048576 nb ulong ob edit uchar 65544 to ulong |
| 5526 | bad = ulong 18446744073709551615 |
| 5527 | if lt nb 8 |
| 5528 | ret bad |
| 5529 | end |
| 5530 | op = rd32 ib 0 |
| 5531 | c = rd32 ib 4 |
| 5532 | if gt add 8 mul c 8 nb |
| 5533 | ret bad |
| 5534 | end |
| 5535 | nbytes = sub nb add 8 mul c 8 |
| 5536 | t0 = add 8 mul c 8 |
| 5537 | r = k_b |
| 5538 | if eq op 1 |
| 5539 | if ne c 5 |
| 5540 | ret bad |
| 5541 | end |
| 5542 | r = add k_b swstate gi ib 0 gi ib 1 gi ib 2 gi ib 3 gi ib 4 |
| 5543 | end |
| 5544 | if eq op 2 |
| 5545 | if ne c 3 |
| 5546 | ret bad |
| 5547 | end |
| 5548 | r = add k_b swatt gi ib 0 gi ib 1 gi ib 2 |
| 5549 | end |
| 5550 | if eq op 3 |
| 5551 | if ne c 2 |
| 5552 | ret bad |
| 5553 | end |
| 5554 | r = sub k_b 1 |
| 5555 | if ge gi ib 1 k_b |
| 5556 | r = k_b |
| 5557 | if gt gi ib 0 gi ib 1 |
| 5558 | r = add k_b sub gi ib 0 gi ib 1 |
| 5559 | end |
| 5560 | end |
| 5561 | end |
| 5562 | if eq op 4 |
| 5563 | if ne c 4 |
| 5564 | ret bad |
| 5565 | end |
| 5566 | r = add k_b swgroup gi ib 0 gi ib 1 gi ib 2 gi ib 3 |
| 5567 | end |
| 5568 | if eq op 5 |
| 5569 | if ne c 4 |
| 5570 | ret bad |
| 5571 | end |
| 5572 | r = add k_b swstarts gi ib 0 gi ib 1 gi ib 2 gi ib 3 |
| 5573 | end |
| 5574 | if eq op 6 |
| 5575 | if ne c 4 |
| 5576 | ret bad |
| 5577 | end |
| 5578 | failed = eq gi ib 0 add k_b 4 |
| 5579 | if and eq gi ib 1 add k_b 2 ge gi ib 2 add k_b 60 |
| 5580 | failed = true |
| 5581 | end |
| 5582 | r = k_b |
| 5583 | if failed |
| 5584 | r = add k_b 2 |
| 5585 | if eq gi ib 3 add k_b 1 |
| 5586 | r = add k_b 3 |
| 5587 | end |
| 5588 | end |
| 5589 | end |
| 5590 | if eq op 7 |
| 5591 | if ne c 2 |
| 5592 | ret bad |
| 5593 | end |
| 5594 | cn = gi ib 0 |
| 5595 | hv = gi ib 1 |
| 5596 | r = add k_b 1 |
| 5597 | if and gt cn add k_b 1 gt hv add k_b 1 |
| 5598 | if ge cn hv |
| 5599 | r = add k_b 5 |
| 5600 | else |
| 5601 | r = add add k_b 1 div mul sub sub cn k_b 1 4 sub sub hv k_b 1 |
| 5602 | end |
| 5603 | end |
| 5604 | end |
| 5605 | if eq op 8 |
| 5606 | r = add k_b swturn ib c |
| 5607 | end |
| 5608 | if eq op 9 |
| 5609 | r = swact ib c |
| 5610 | end |
| 5611 | if eq op 10 |
| 5612 | r = add k_b swquota ib t0 add t0 nbytes |
| 5613 | end |
| 5614 | if eq op 11 |
| 5615 | if ne c 2 |
| 5616 | ret bad |
| 5617 | end |
| 5618 | rl = gu ib 0 |
| 5619 | nl = gu ib 1 |
| 5620 | if or gt rl 1048576 gt nl 1048576 |
| 5621 | ret bad |
| 5622 | end |
| 5623 | if ne add rl nl nbytes |
| 5624 | ret bad |
| 5625 | end |
| 5626 | r = add k_b swrole ib t0 rl add t0 rl nl |
| 5627 | end |
| 5628 | if eq op 12 |
| 5629 | ret swedges ib c ob |
| 5630 | end |
| 5631 | if eq op 13 |
| 5632 | ret mul 8 swbroad ib c ob |
| 5633 | end |
| 5634 | if eq op 14 |
| 5635 | ret swbusy ib c ob |
| 5636 | end |
| 5637 | if eq op 16 |
| 5638 | k = swderive ib c nbytes ob |
| 5639 | if eq k 0 |
| 5640 | ret bad |
| 5641 | end |
| 5642 | ret mul k 8 |
| 5643 | end |
| 5644 | if eq op 17 |
| 5645 | k = swrank ib c nbytes ob |
| 5646 | if eq k 0 |
| 5647 | ret bad |
| 5648 | end |
| 5649 | ret mul k 8 |
| 5650 | end |
| 5651 | if eq op 18 |
| 5652 | k = swsuggest ib c ob |
| 5653 | if eq k 0 |
| 5654 | ret bad |
| 5655 | end |
| 5656 | ret mul k 8 |
| 5657 | end |
| 5658 | if eq op 19 |
| 5659 | k = swlifts ib c ob |
| 5660 | if eq k 0 |
| 5661 | ret bad |
| 5662 | end |
| 5663 | ret mul k 8 |
| 5664 | end |
| 5665 | if eq op 20 |
| 5666 | k = swgcm ib c nbytes ob |
| 5667 | if eq k 0 |
| 5668 | ret bad |
| 5669 | end |
| 5670 | ret mul k 8 |
| 5671 | end |
| 5672 | if or gt op 11 eq op 0 |
| 5673 | ret bad |
| 5674 | end |
| 5675 | po ob 0 r |
| 5676 | ret 8 |
| 5677 | end |
| 5678 | |
| 5679 | note ---- which words were corrected (kind 4) ---- |
| 5680 | note After Hop types a dictation, the field is read again later. The host splits three texts into words (what was |
| 5681 | note dictated, the field before, the field after) and gives each distinct word a number. This finds the dictation |
| 5682 | note in the field (its last whole occurrence), sets aside the words that are the same at both ends, lines up the |
| 5683 | note rest word by word (longest common subsequence) and reports each run where words of the dictation were |
| 5684 | note replaced: at most 3 words, wholly inside the dictation. Nothing is reported when the dictation is not in the |
| 5685 | note field, when the part that changed is too large (words before times words after over 250000), or when more |
| 5686 | note than half of the dictation changed (a rewrite, not a fix). |
| 5687 | note wt: the table of the line-up, (words before + 1) rows of (words after + 1) |
| 5688 | global wt ulong 500008 |
| 5689 | |
| 5690 | note st: 0 where the removed run starts in the field, 1 its length, 2 where the typed run starts in the later |
| 5691 | note field, 3 its length, 4 runs written, 5 where the dictation starts, 6 its length, 7 removed words that lie |
| 5692 | note inside the dictation, 8 1 when there were more runs than the answer holds (4096) |
| 5693 | fn hclose st edit ulong 16 ob edit uchar 65544 to void |
| 5694 | rc = get st 1 |
| 5695 | ic = get st 3 |
| 5696 | if and gt rc 0 gt ic 0 |
| 5697 | rs = get st 0 |
| 5698 | s0 = get st 5 |
| 5699 | if ge rs s0 |
| 5700 | if le add rs rc add s0 get st 6 |
| 5701 | if le rc 3 |
| 5702 | h = get st 4 |
| 5703 | if ge h 4096 |
| 5704 | put st 8 1 |
| 5705 | else |
| 5706 | o = add 10 mul h 14 |
| 5707 | put32 ob o rs |
| 5708 | put ob add o 4 uchar and rc 255 |
| 5709 | put ob add o 5 uchar shr rc 8 |
| 5710 | put32 ob add o 6 get st 2 |
| 5711 | put32 ob add o 10 ic |
| 5712 | put st 4 add h 1 |
| 5713 | end |
| 5714 | end |
| 5715 | end |
| 5716 | end |
| 5717 | end |
| 5718 | put st 1 0 |
| 5719 | put st 3 0 |
| 5720 | end |
| 5721 | |
| 5722 | note kind 4: three 32-bit counts (dictated, before, after), then that many 32-bit word numbers for each. The |
| 5723 | note answer is a 16-bit count, then for each run: where the removed words start in the field before (32-bit), how |
| 5724 | note many (16-bit), where the typed words start in the field after (32-bit) and how many (32-bit). |
| 5725 | note Returns the reply length, or 18446744073709551615 for a malformed body or too many runs |
| 5726 | fn wdiff ib view uchar 1048576 n ulong ob edit uchar 65544 to ulong |
| 5727 | st = new ulong 16 0 |
| 5728 | bad = ulong 18446744073709551615 |
| 5729 | if lt n 12 |
| 5730 | ret bad |
| 5731 | end |
| 5732 | nd = rd32 ib 0 |
| 5733 | nb = rd32 ib 4 |
| 5734 | na = rd32 ib 8 |
| 5735 | if ne n add 12 mul 4 add add nd nb na |
| 5736 | ret bad |
| 5737 | end |
| 5738 | d0 = ulong 12 |
| 5739 | b0 = add 12 mul 4 nd |
| 5740 | a0 = add b0 mul 4 nb |
| 5741 | put ob 8 uchar 0 |
| 5742 | put ob 9 uchar 0 |
| 5743 | if eq nd 0 |
| 5744 | ret 2 |
| 5745 | end |
| 5746 | if lt nb nd |
| 5747 | ret 2 |
| 5748 | end |
| 5749 | found = false |
| 5750 | start = ulong 0 |
| 5751 | q = sub nb nd |
| 5752 | while true bound 999999 |
| 5753 | k = ulong 0 |
| 5754 | while lt k nd bound 999999 |
| 5755 | if ne rd32 ib add b0 mul 4 add q k rd32 ib add d0 mul 4 k |
| 5756 | break |
| 5757 | end |
| 5758 | k = add k 1 |
| 5759 | end |
| 5760 | if eq k nd |
| 5761 | found = true |
| 5762 | start = q |
| 5763 | break |
| 5764 | end |
| 5765 | if eq q 0 |
| 5766 | break |
| 5767 | end |
| 5768 | q = sub q 1 |
| 5769 | end |
| 5770 | if not found |
| 5771 | ret 2 |
| 5772 | end |
| 5773 | p = ulong 0 |
| 5774 | while lt p nb bound 999999 |
| 5775 | if ge p na |
| 5776 | break |
| 5777 | end |
| 5778 | if ne rd32 ib add b0 mul 4 p rd32 ib add a0 mul 4 p |
| 5779 | break |
| 5780 | end |
| 5781 | p = add p 1 |
| 5782 | end |
| 5783 | s = ulong 0 |
| 5784 | while lt s sub nb p bound 999999 |
| 5785 | if ge s sub na p |
| 5786 | break |
| 5787 | end |
| 5788 | if ne rd32 ib add b0 mul 4 sub sub nb 1 s rd32 ib add a0 mul 4 sub sub na 1 s |
| 5789 | break |
| 5790 | end |
| 5791 | s = add s 1 |
| 5792 | end |
| 5793 | bc = sub sub nb p s |
| 5794 | ac = sub sub na p s |
| 5795 | if eq bc 0 |
| 5796 | ret 2 |
| 5797 | end |
| 5798 | am = ac |
| 5799 | if eq am 0 |
| 5800 | am = ulong 1 |
| 5801 | end |
| 5802 | if gt mul bc am 250000 |
| 5803 | ret 2 |
| 5804 | end |
| 5805 | w1 = add ac 1 |
| 5806 | for z ulong add bc 1 |
| 5807 | put wt add mul z w1 ac 0 |
| 5808 | end |
| 5809 | for z ulong w1 |
| 5810 | put wt add mul bc w1 z 0 |
| 5811 | end |
| 5812 | for ii ulong bc |
| 5813 | i = sub sub bc 1 ii |
| 5814 | bi = rd32 ib add b0 mul 4 add p i |
| 5815 | for jj ulong ac |
| 5816 | j = sub sub ac 1 jj |
| 5817 | if eq bi rd32 ib add a0 mul 4 add p j |
| 5818 | put wt add mul i w1 j add get wt add mul add i 1 w1 add j 1 1 |
| 5819 | else |
| 5820 | x = get wt add mul add i 1 w1 j |
| 5821 | y = get wt add mul i w1 add j 1 |
| 5822 | if lt x y |
| 5823 | x = y |
| 5824 | end |
| 5825 | put wt add mul i w1 j x |
| 5826 | end |
| 5827 | end |
| 5828 | end |
| 5829 | put st 5 start |
| 5830 | put st 6 nd |
| 5831 | ci = ulong 0 |
| 5832 | cj = ulong 0 |
| 5833 | while or lt ci bc lt cj ac bound 999999 |
| 5834 | mt = false |
| 5835 | if lt ci bc |
| 5836 | if lt cj ac |
| 5837 | if eq rd32 ib add b0 mul 4 add p ci rd32 ib add a0 mul 4 add p cj |
| 5838 | mt = true |
| 5839 | end |
| 5840 | end |
| 5841 | end |
| 5842 | if mt |
| 5843 | hclose st ob |
| 5844 | ci = add ci 1 |
| 5845 | cj = add cj 1 |
| 5846 | continue |
| 5847 | end |
| 5848 | rm = false |
| 5849 | if lt ci bc |
| 5850 | if eq cj ac |
| 5851 | rm = true |
| 5852 | else |
| 5853 | if ge get wt add mul add ci 1 w1 cj get wt add mul ci w1 add cj 1 |
| 5854 | rm = true |
| 5855 | end |
| 5856 | end |
| 5857 | end |
| 5858 | if rm |
| 5859 | if eq get st 1 0 |
| 5860 | put st 0 add p ci |
| 5861 | end |
| 5862 | put st 1 add get st 1 1 |
| 5863 | ai = add p ci |
| 5864 | if ge ai start |
| 5865 | if lt ai add start nd |
| 5866 | put st 7 add get st 7 1 |
| 5867 | end |
| 5868 | end |
| 5869 | ci = add ci 1 |
| 5870 | else |
| 5871 | if eq get st 3 0 |
| 5872 | put st 2 add p cj |
| 5873 | end |
| 5874 | put st 3 add get st 3 1 |
| 5875 | cj = add cj 1 |
| 5876 | end |
| 5877 | end |
| 5878 | hclose st ob |
| 5879 | if ne get st 8 0 |
| 5880 | ret bad |
| 5881 | end |
| 5882 | h = get st 4 |
| 5883 | lim = nd |
| 5884 | if lt lim 2 |
| 5885 | lim = ulong 2 |
| 5886 | end |
| 5887 | if gt mul get st 7 2 lim |
| 5888 | h = ulong 0 |
| 5889 | end |
| 5890 | put ob 8 uchar and h 255 |
| 5891 | put ob 9 uchar shr h 8 |
| 5892 | ret add 2 mul h 14 |
| 5893 | end |
| 5894 | |
| 5895 | fn names ib view uchar 1048576 n ulong ob edit uchar 65544 a edit ulong 256 r edit ulong 256 to ulong |
| 5896 | if ne rem n 2048 0 |
| 5897 | ret 18446744073709551615 |
| 5898 | end |
| 5899 | c = div n 2048 |
| 5900 | if gt c 512 |
| 5901 | ret 18446744073709551615 |
| 5902 | end |
| 5903 | for q ulong c |
| 5904 | for i ulong 256 |
| 5905 | w = ulong 0 |
| 5906 | for j ulong 8 |
| 5907 | w = or w shl ulong get ib add add mul q 2048 mul i 8 j mul j 8 |
| 5908 | end |
| 5909 | put a i w |
| 5910 | end |
| 5911 | v = hopfuzz a r |
| 5912 | s = get r 3 |
| 5913 | put ob add 8 mul q 3 uchar v |
| 5914 | put ob add 9 mul q 3 uchar and s 255 |
| 5915 | put ob add 10 mul q 3 uchar shr s 8 |
| 5916 | end |
| 5917 | ret mul c 3 |
| 5918 | end |
| 5919 | |
| 5920 | note kind 2: returns the reply length, or 18446744073709551615 for a malformed body |
| 5921 | fn 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 |
| 5922 | bad = ulong 18446744073709551615 |
| 5923 | if lt n 4 |
| 5924 | ret bad |
| 5925 | end |
| 5926 | nt = rd16 ib 0 |
| 5927 | np = rd16 ib 2 |
| 5928 | if gt nt 64 |
| 5929 | ret bad |
| 5930 | end |
| 5931 | if gt np 16000 |
| 5932 | ret bad |
| 5933 | end |
| 5934 | o = ulong 4 |
| 5935 | for k ulong nt |
| 5936 | if gt add o 2 n |
| 5937 | ret bad |
| 5938 | end |
| 5939 | tl = rd16 ib o |
| 5940 | o = add o 2 |
| 5941 | if gt add o tl n |
| 5942 | ret bad |
| 5943 | end |
| 5944 | put toff k o |
| 5945 | put tlen k tl |
| 5946 | o = add o tl |
| 5947 | end |
| 5948 | for q ulong np |
| 5949 | if gt add o 6 n |
| 5950 | ret bad |
| 5951 | end |
| 5952 | pl = rd16 ib o |
| 5953 | nl = rd16 ib add o 2 |
| 5954 | ol = rd16 ib add o 4 |
| 5955 | o = add o 6 |
| 5956 | if gt add o add pl nl n |
| 5957 | ret bad |
| 5958 | end |
| 5959 | put pm 0 nt |
| 5960 | put pm 1 o |
| 5961 | put pm 2 pl |
| 5962 | put pm 3 add o pl |
| 5963 | put pm 4 nl |
| 5964 | put pm 5 ol |
| 5965 | put32 ob add 8 mul q 4 fscore ib toff tlen pm |
| 5966 | o = add o add pl nl |
| 5967 | end |
| 5968 | if ne o n |
| 5969 | ret bad |
| 5970 | end |
| 5971 | ret mul np 4 |
| 5972 | end |
| 5973 | |
| 5974 | note ---- end of the core of Hop ---- |
| 5975 | |
| 5976 | fn upr o ulong v ulong to void |
| 5977 | for i ulong 8 |
| 5978 | put g_rg add o i uchar and shr v mul i 8 255 |
| 5979 | end |
| 5980 | end |
| 5981 | |
| 5982 | fn ugr o ulong to ulong |
| 5983 | v = ulong 0 |
| 5984 | for i ulong 8 |
| 5985 | v = or v shl ulong get g_rg add o i mul i 8 |
| 5986 | end |
| 5987 | ret v |
| 5988 | end |
| 5989 | |
| 5990 | note the text into g_nm with a zero byte after it; its length |
| 5991 | fn ucs t view uchar * to ulong |
| 5992 | n = len t |
| 5993 | for i ulong n |
| 5994 | put g_nm i get t i |
| 5995 | end |
| 5996 | put g_nm n 0 |
| 5997 | ret n |
| 5998 | end |
| 5999 | |
| 6000 | note library function k of g_f on the register file; x0 as it came back (an object may have its top bit set) |
| 6001 | fn ucall k ulong to ulong |
| 6002 | lr = libcall get g_f k g_rg 0 128 |
| 6003 | ret ugr 0 |
| 6004 | end |
| 6005 | |
| 6006 | fn usym t view uchar * to ulong |
| 6007 | n = ucs t |
| 6008 | upr 0 18446744073709551614 |
| 6009 | upr 8 ulong libptr g_nm 0 1024 |
| 6010 | lr = libcall ulong libfn 1 g_rg 0 128 |
| 6011 | ret ugr 0 |
| 6012 | end |
| 6013 | |
| 6014 | fn ucl t view uchar * to ulong |
| 6015 | n = ucs t |
| 6016 | upr 0 ulong libptr g_nm 0 1024 |
| 6017 | ret ucall 0 |
| 6018 | end |
| 6019 | |
| 6020 | fn usl t view uchar * to ulong |
| 6021 | n = ucs t |
| 6022 | upr 0 ulong libptr g_nm 0 1024 |
| 6023 | ret ucall 1 |
| 6024 | end |
| 6025 | |
| 6026 | note [obj s a b c] |
| 6027 | fn umsg obj ulong s ulong a ulong b ulong c ulong to ulong |
| 6028 | upr 0 obj |
| 6029 | upr 8 s |
| 6030 | upr 16 a |
| 6031 | upr 24 b |
| 6032 | upr 32 c |
| 6033 | ret ucall 2 |
| 6034 | end |
| 6035 | |
| 6036 | note an NSString of the zero-ended bytes in g_nm |
| 6037 | fn unsb to ulong |
| 6038 | ret umsg get g_o 3 get g_o 4 ulong libptr g_nm 0 1024 0 0 |
| 6039 | end |
| 6040 | |
| 6041 | fn uns t view uchar * to ulong |
| 6042 | n = ucs t |
| 6043 | ret unsb |
| 6044 | end |
| 6045 | |
| 6046 | note a rectangle for the next message, in d0..d3 |
| 6047 | fn urect x f64 y f64 w f64 h f64 to void |
| 6048 | upr 64 bitcast ulong x |
| 6049 | upr 72 bitcast ulong y |
| 6050 | upr 80 bitcast ulong w |
| 6051 | upr 88 bitcast ulong h |
| 6052 | end |
| 6053 | |
| 6054 | fn ulower c ulong to ulong |
| 6055 | if and ge c 65 le c 90 |
| 6056 | ret add c 32 |
| 6057 | end |
| 6058 | ret c |
| 6059 | end |
| 6060 | |
| 6061 | note the zero-ended bytes at address p into g_nm (at most 1000); their count |
| 6062 | fn ufetch p ulong to ulong |
| 6063 | upr 0 p |
| 6064 | n = ucall 7 |
| 6065 | if gt n 1000 |
| 6066 | n = 1000 |
| 6067 | end |
| 6068 | upr 0 ulong libptr g_nm 0 1024 |
| 6069 | upr 8 p |
| 6070 | upr 16 n |
| 6071 | x = ucall 8 |
| 6072 | put g_nm n 0 |
| 6073 | ret n |
| 6074 | end |
| 6075 | |
| 6076 | note the names in one folder that end in ".app", without that ending, into the pool |
| 6077 | fn ufolder t view uchar * dn ulong to void |
| 6078 | c = ucl c_fm |
| 6079 | s = usl m_defaul |
| 6080 | mgr = umsg c s 0 0 0 |
| 6081 | s = usl m_conte1 |
| 6082 | path = uns t |
| 6083 | arr = umsg mgr s path 0 0 |
| 6084 | if eq arr 0 |
| 6085 | ret |
| 6086 | end |
| 6087 | s = usl m_count |
| 6088 | cnt = umsg arr s 0 0 0 |
| 6089 | sat = usl m_at |
| 6090 | for i ulong cnt bound 4096 |
| 6091 | item = umsg arr sat i 0 0 |
| 6092 | p = umsg item get g_o 5 0 0 0 |
| 6093 | n = ufetch p |
| 6094 | k = get g_n 0 |
| 6095 | used = get g_n 2 |
| 6096 | if and and gt n 4 lt k 2048 lt add used n 65536 |
| 6097 | if 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 |
| 6098 | m = sub n 4 |
| 6099 | for j ulong m bound 1000 |
| 6100 | put g_pool add used j get g_nm j |
| 6101 | end |
| 6102 | put g_off k used |
| 6103 | put g_ln k m |
| 6104 | put g_dir k uchar dn |
| 6105 | put g_n 0 add k 1 |
| 6106 | put g_n 2 add used m |
| 6107 | end |
| 6108 | end |
| 6109 | end |
| 6110 | end |
| 6111 | |
| 6112 | note the word hopfuzz reads for one byte: its lower-case value, bit 32 for a letter or digit (and for every byte of |
| 6113 | note a longer character), bit 33 for a space or tab |
| 6114 | fn ufword c ulong to ulong |
| 6115 | l = ulower c |
| 6116 | w = l |
| 6117 | if or or and ge l 97 le l 122 and ge l 48 le l 57 ge l 128 |
| 6118 | w = or w 4294967296 |
| 6119 | end |
| 6120 | if or eq l 32 eq l 9 |
| 6121 | w = or w 8589934592 |
| 6122 | end |
| 6123 | ret w |
| 6124 | end |
| 6125 | |
| 6126 | note 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 |
| 6127 | note or a name over 184, which hopfuzz refuses) |
| 6128 | fn uscore k ulong to ulong |
| 6129 | inp = new ulong 256 0 |
| 6130 | res = new ulong 256 0 |
| 6131 | ql = get g_n 4 |
| 6132 | nl = get g_ln k |
| 6133 | o = get g_off k |
| 6134 | if or gt ql 64 or gt nl 184 eq nl 0 |
| 6135 | ret 0 |
| 6136 | end |
| 6137 | put inp 0 1212568922 |
| 6138 | put inp 1 1 |
| 6139 | put inp 2 ql |
| 6140 | put inp 3 nl |
| 6141 | for i ulong ql bound 64 |
| 6142 | put inp add 8 i ufword ulong get g_q i |
| 6143 | end |
| 6144 | for i ulong nl bound 184 |
| 6145 | put inp add 72 i ufword ulong get g_pool add o i |
| 6146 | end |
| 6147 | v = hopfuzz inp res |
| 6148 | if ne v 1 |
| 6149 | ret 0 |
| 6150 | end |
| 6151 | ret 0 |
| 6152 | end |
| 6153 | |
| 6154 | note a number in decimal into g_nm from byte p; the byte after it |
| 6155 | fn upnum p ulong v ulong to ulong |
| 6156 | d = ulong 1 |
| 6157 | while ge div v d 10 bound 24 |
| 6158 | d = mul d 10 |
| 6159 | end |
| 6160 | q = p |
| 6161 | while gt d 0 bound 24 |
| 6162 | put g_nm q uchar add 48 rem div v d 10 |
| 6163 | q = add q 1 |
| 6164 | d = div d 10 |
| 6165 | end |
| 6166 | ret q |
| 6167 | end |
| 6168 | |
| 6169 | note the text into g_nm from byte p; the byte after it |
| 6170 | fn uptxt p ulong t view uchar * to ulong |
| 6171 | for i ulong len t |
| 6172 | put g_nm add p i get t i |
| 6173 | end |
| 6174 | ret add p len t |
| 6175 | end |
| 6176 | |
| 6177 | note name k into g_nm from byte p; the byte after it |
| 6178 | fn upname p ulong k ulong to ulong |
| 6179 | o = get g_off k |
| 6180 | n = get g_ln k |
| 6181 | for i ulong n bound 1000 |
| 6182 | put g_nm add p i get g_pool add o i |
| 6183 | end |
| 6184 | ret add p n |
| 6185 | end |
| 6186 | |
| 6187 | note four bytes and eight bytes into a request for the core, and eight bytes out of its answer; numbers travel with |
| 6188 | note 2^40 added (k_b), as in Omega/README.md kind 7 |
| 6189 | fn uw32 b edit uchar 1048576 o ulong v ulong to void |
| 6190 | for i ulong 4 |
| 6191 | put b add o i uchar and shr v mul i 8 255 |
| 6192 | end |
| 6193 | end |
| 6194 | |
| 6195 | fn upb b edit uchar 1048576 k ulong x ulong to void |
| 6196 | o = add 8 mul k 8 |
| 6197 | for i ulong 8 |
| 6198 | put b add o i uchar and shr x mul i 8 255 |
| 6199 | end |
| 6200 | end |
| 6201 | |
| 6202 | fn upn b edit uchar 1048576 k ulong v ulong to void |
| 6203 | upb b k add v k_b |
| 6204 | end |
| 6205 | |
| 6206 | fn uog ob view uchar 65544 k ulong to ulong |
| 6207 | v = ulong 0 |
| 6208 | o = add 8 mul k 8 |
| 6209 | for i ulong 8 |
| 6210 | v = or v shl ulong get ob add o i mul i 8 |
| 6211 | end |
| 6212 | ret v |
| 6213 | end |
| 6214 | |
| 6215 | note the address the typed text stands for into g_nm from byte p (with "https://" before a bare one); the byte after |
| 6216 | fn upaddr p ulong to ulong |
| 6217 | q = p |
| 6218 | if eq get g_n 10 2 |
| 6219 | q = uptxt p x_https |
| 6220 | end |
| 6221 | a = get g_n 12 |
| 6222 | n = get g_n 13 |
| 6223 | for i ulong n bound 256 |
| 6224 | put g_nm add q i get g_q add a i |
| 6225 | end |
| 6226 | ret add q n |
| 6227 | end |
| 6228 | |
| 6229 | note is the typed text a web address? The shape is the core's decision (fn weba, text decisions op 3); that macOS |
| 6230 | note can read it is asked of NSURL, as Hop does. The answer goes to g_n 10 |
| 6231 | fn udecide to void |
| 6232 | tb = new uchar 1048576 0 |
| 6233 | a = get g_n 12 |
| 6234 | n = get g_n 13 |
| 6235 | put g_n 10 0 |
| 6236 | put g_n 41 0 |
| 6237 | if or eq n 0 gt n 255 |
| 6238 | ret |
| 6239 | end |
| 6240 | uw32 tb 0 3 |
| 6241 | uw32 tb 4 n |
| 6242 | uw32 tb 8 n |
| 6243 | for i ulong n bound 256 |
| 6244 | l = ulower ulong get g_q add a i |
| 6245 | o = add 16 mul i 8 |
| 6246 | put tb o uchar l |
| 6247 | f = ulong 0 |
| 6248 | if or or and ge l 97 le l 122 and ge l 48 le l 57 ge l 128 |
| 6249 | f = 1 |
| 6250 | end |
| 6251 | if or eq l 32 eq l 9 |
| 6252 | f = 14 |
| 6253 | end |
| 6254 | put tb add o 4 uchar f |
| 6255 | end |
| 6256 | put g_n 41 qlike tb n |
| 6257 | k = weba tb n n |
| 6258 | if eq k 0 |
| 6259 | ret |
| 6260 | end |
| 6261 | put g_n 10 k |
| 6262 | p = upaddr 0 |
| 6263 | put g_nm p 0 |
| 6264 | str = unsb |
| 6265 | u = umsg get g_o 16 get g_o 17 str 0 0 |
| 6266 | if eq u 0 |
| 6267 | put g_n 10 0 |
| 6268 | ret |
| 6269 | end |
| 6270 | if eq k 1 |
| 6271 | if eq umsg u get g_o 18 0 0 0 0 |
| 6272 | put g_n 10 0 |
| 6273 | end |
| 6274 | end |
| 6275 | end |
| 6276 | |
| 6277 | note ---- files: Hop's file index, searched by the rule of Hop's own file search (Sources/FileIndex.swift) ---- |
| 6278 | note read file-index.bin from Hop's folder (HOP_CONFIG_DIR, else the user's Application Support/Hop) and make the |
| 6279 | note lower-case copy the search runs on. Without the file there are no file rows |
| 6280 | fn uloadindex to void |
| 6281 | if eq get g_fb 3 1 |
| 6282 | upr 0 get g_fb 1 |
| 6283 | x = ucall 28 |
| 6284 | x = umsg get g_fb 4 usl m_release 0 0 0 |
| 6285 | end |
| 6286 | put g_fb 3 0 |
| 6287 | n = ucs x_env_dir |
| 6288 | upr 0 ulong libptr g_nm 0 1024 |
| 6289 | dir_text = ucall 9 |
| 6290 | p = ulong 0 |
| 6291 | if ne dir_text 0 |
| 6292 | p = ufetch dir_text |
| 6293 | end |
| 6294 | if eq p 0 |
| 6295 | n = ucs x_env_home |
| 6296 | upr 0 ulong libptr g_nm 0 1024 |
| 6297 | home_text = ucall 9 |
| 6298 | if eq home_text 0 |
| 6299 | ret |
| 6300 | end |
| 6301 | p = ufetch home_text |
| 6302 | p = uptxt p x_support |
| 6303 | end |
| 6304 | p = uptxt p x_index |
| 6305 | put g_nm p 0 |
| 6306 | path = unsb |
| 6307 | c = ucl c_data |
| 6308 | s = usl m_data_file |
| 6309 | d = umsg c s path 0 0 |
| 6310 | if eq d 0 |
| 6311 | ret |
| 6312 | end |
| 6313 | s = usl m_retain |
| 6314 | x = umsg d s 0 0 0 |
| 6315 | s = usl m_bytes |
| 6316 | src = umsg d s 0 0 0 |
| 6317 | s = usl m_length |
| 6318 | total = umsg d s 0 0 0 |
| 6319 | if or or eq src 0 eq total 0 gt total 536870912 |
| 6320 | ret |
| 6321 | end |
| 6322 | upr 0 total |
| 6323 | dst = ucall 10 |
| 6324 | if eq dst 0 |
| 6325 | x = umsg d usl m_release 0 0 0 |
| 6326 | ret |
| 6327 | end |
| 6328 | done = ulong 0 |
| 6329 | while lt done total bound 2048 |
| 6330 | m = sub total done |
| 6331 | if gt m 524288 |
| 6332 | m = 524288 |
| 6333 | end |
| 6334 | upr 0 ulong libptr g_chunk 0 524288 |
| 6335 | upr 8 add src done |
| 6336 | upr 16 m |
| 6337 | x = ucall 8 |
| 6338 | for i ulong m bound 524288 |
| 6339 | cc = ulong get g_chunk i |
| 6340 | if and ge cc 65 le cc 90 |
| 6341 | put g_chunk i uchar add cc 32 |
| 6342 | end |
| 6343 | end |
| 6344 | upr 0 add dst done |
| 6345 | upr 8 ulong libptr g_chunk 0 524288 |
| 6346 | upr 16 m |
| 6347 | x = ucall 8 |
| 6348 | done = add done m |
| 6349 | end |
| 6350 | put g_fb 0 src |
| 6351 | put g_fb 1 dst |
| 6352 | put g_fb 2 total |
| 6353 | put g_fb 4 d |
| 6354 | put g_fb 3 1 |
| 6355 | end |
| 6356 | |
| 6357 | note does g_line[ho .. ho+hl) hold word t of the typed text; md 1: does it start with it |
| 6358 | fn uhas ho ulong hl ulong t ulong md ulong to bool |
| 6359 | wo = get g_to t |
| 6360 | wl = get g_tl t |
| 6361 | if gt wl hl |
| 6362 | ret false |
| 6363 | end |
| 6364 | last = sub hl wl |
| 6365 | if eq md 1 |
| 6366 | last = 0 |
| 6367 | end |
| 6368 | st = ulong 0 |
| 6369 | while le st last bound 4097 |
| 6370 | same_bytes = true |
| 6371 | j = ulong 0 |
| 6372 | while and same_bytes lt j wl bound 257 |
| 6373 | if ne get g_line add add ho st j get g_lq add wo j |
| 6374 | same_bytes = false |
| 6375 | end |
| 6376 | j = add j 1 |
| 6377 | end |
| 6378 | if same_bytes |
| 6379 | ret true |
| 6380 | end |
| 6381 | st = add st 1 |
| 6382 | end |
| 6383 | ret false |
| 6384 | end |
| 6385 | |
| 6386 | note the score of the path in g_line (ln bytes, lower case) plus 100000, or 0 when a word is in it nowhere: a |
| 6387 | note word in the name counts 60 at its start and 30 elsewhere, a word only in the folders 5; a point less for |
| 6388 | note every 20 bytes of path; 40 more when the name is exactly as long as the words; 25 more for an app |
| 6389 | fn ufscore ln ulong to ulong |
| 6390 | nt = get g_n 16 |
| 6391 | ns0 = ln |
| 6392 | while gt ns0 0 bound 4097 |
| 6393 | if eq ulong get g_line sub ns0 1 47 |
| 6394 | break |
| 6395 | end |
| 6396 | ns0 = sub ns0 1 |
| 6397 | end |
| 6398 | nl = sub ln ns0 |
| 6399 | sc = ulong 100000 |
| 6400 | words_len = ulong 0 |
| 6401 | for t ulong nt bound 16 |
| 6402 | words_len = add words_len get g_tl t |
| 6403 | if uhas ns0 nl t 0 |
| 6404 | if uhas ns0 nl t 1 |
| 6405 | sc = add sc 60 |
| 6406 | else |
| 6407 | sc = add sc 30 |
| 6408 | end |
| 6409 | else |
| 6410 | if uhas 0 ln t 0 |
| 6411 | sc = add sc 5 |
| 6412 | else |
| 6413 | ret 0 |
| 6414 | end |
| 6415 | end |
| 6416 | end |
| 6417 | sc = sub sc div ln 20 |
| 6418 | if eq nl words_len |
| 6419 | sc = add sc 40 |
| 6420 | end |
| 6421 | if ge ln 4 |
| 6422 | if 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 |
| 6423 | sc = add sc 25 |
| 6424 | end |
| 6425 | end |
| 6426 | ret sc |
| 6427 | end |
| 6428 | |
| 6429 | note keep a found path among the best 40, best first; equal scores stay in the order they were found |
| 6430 | fn ufkeep sc ulong o ulong ln ulong to void |
| 6431 | k = get g_n 17 |
| 6432 | if and ge k 40 le sc get g_fs 39 |
| 6433 | ret |
| 6434 | end |
| 6435 | pos = k |
| 6436 | if ge k 40 |
| 6437 | pos = 39 |
| 6438 | else |
| 6439 | put g_n 17 add k 1 |
| 6440 | end |
| 6441 | while gt pos 0 bound 64 |
| 6442 | if ge get g_fs sub pos 1 sc |
| 6443 | break |
| 6444 | end |
| 6445 | put g_fs pos get g_fs sub pos 1 |
| 6446 | put g_fo pos get g_fo sub pos 1 |
| 6447 | put g_fl pos get g_fl sub pos 1 |
| 6448 | pos = sub pos 1 |
| 6449 | end |
| 6450 | put g_fs pos sc |
| 6451 | put g_fo pos o |
| 6452 | put g_fl pos ln |
| 6453 | end |
| 6454 | |
| 6455 | note 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 |
| 6456 | fn ufpath i ulong lo ulong to ulong |
| 6457 | ln = get g_fl i |
| 6458 | upr 0 ulong libptr g_line 0 4096 |
| 6459 | upr 8 add get g_fb lo get g_fo i |
| 6460 | upr 16 ln |
| 6461 | x = ucall 8 |
| 6462 | ret ln |
| 6463 | end |
| 6464 | |
| 6465 | note the files for the typed text: every line of the index that holds the longest word is scored (at most |
| 6466 | note 20000 lines, as Hop does), the best 40 are kept. Nothing under two characters |
| 6467 | fn usearch to void |
| 6468 | put g_n 17 0 |
| 6469 | put g_n 18 0 |
| 6470 | a = get g_n 12 |
| 6471 | n = get g_n 13 |
| 6472 | nt = ulong 0 |
| 6473 | i = ulong 0 |
| 6474 | while lt i n bound 257 |
| 6475 | c = ulower ulong get g_q add a i |
| 6476 | put g_lq i uchar c |
| 6477 | if or eq c 32 eq c 9 |
| 6478 | i = add i 1 |
| 6479 | continue |
| 6480 | end |
| 6481 | st = i |
| 6482 | while lt i n bound 257 |
| 6483 | c = ulower ulong get g_q add a i |
| 6484 | if or eq c 32 eq c 9 |
| 6485 | break |
| 6486 | end |
| 6487 | put g_lq i uchar c |
| 6488 | i = add i 1 |
| 6489 | end |
| 6490 | if lt nt 16 |
| 6491 | put g_to nt st |
| 6492 | put g_tl nt sub i st |
| 6493 | nt = add nt 1 |
| 6494 | end |
| 6495 | end |
| 6496 | put g_n 16 nt |
| 6497 | if or or eq get g_fb 3 0 lt n 2 eq nt 0 |
| 6498 | ret |
| 6499 | end |
| 6500 | lead = ulong 0 |
| 6501 | for t ulong nt bound 16 |
| 6502 | if gt get g_tl t get g_tl lead |
| 6503 | lead = t |
| 6504 | end |
| 6505 | end |
| 6506 | low = get g_fb 1 |
| 6507 | total = get g_fb 2 |
| 6508 | pos = ulong 0 |
| 6509 | scanned = ulong 0 |
| 6510 | while and lt pos total lt scanned 20000 bound 20001 |
| 6511 | upr 0 add low pos |
| 6512 | upr 8 sub total pos |
| 6513 | upr 16 ulong libptr g_lq get g_to lead get g_tl lead |
| 6514 | upr 24 get g_tl lead |
| 6515 | m = ucall 11 |
| 6516 | if eq m 0 |
| 6517 | break |
| 6518 | end |
| 6519 | hit_at = sub m low |
| 6520 | upr 0 low |
| 6521 | upr 8 10 |
| 6522 | upr 16 hit_at |
| 6523 | r = ucall 13 |
| 6524 | s = ulong 0 |
| 6525 | if ne r 0 |
| 6526 | s = add sub r low 1 |
| 6527 | end |
| 6528 | upr 0 m |
| 6529 | upr 8 10 |
| 6530 | upr 16 sub total hit_at |
| 6531 | r = ucall 12 |
| 6532 | e = total |
| 6533 | if ne r 0 |
| 6534 | e = sub r low |
| 6535 | end |
| 6536 | pos = add e 1 |
| 6537 | scanned = add scanned 1 |
| 6538 | ln = sub e s |
| 6539 | if and gt ln 0 le ln 4000 |
| 6540 | upr 0 ulong libptr g_line 0 4096 |
| 6541 | upr 8 add low s |
| 6542 | upr 16 ln |
| 6543 | x = ucall 8 |
| 6544 | sc = ufscore ln |
| 6545 | if ne sc 0 |
| 6546 | ufkeep sc s ln |
| 6547 | end |
| 6548 | end |
| 6549 | end |
| 6550 | note does one of them have exactly the typed text as its name (a folder's last "/" aside) |
| 6551 | for f ulong get g_n 17 bound 64 |
| 6552 | ln = ufpath f 1 |
| 6553 | if gt ln 0 |
| 6554 | if eq ulong get g_line sub ln 1 47 |
| 6555 | ln = sub ln 1 |
| 6556 | end |
| 6557 | end |
| 6558 | ns0 = ln |
| 6559 | while gt ns0 0 bound 4097 |
| 6560 | if eq ulong get g_line sub ns0 1 47 |
| 6561 | break |
| 6562 | end |
| 6563 | ns0 = sub ns0 1 |
| 6564 | end |
| 6565 | if eq sub ln ns0 n |
| 6566 | same_bytes = true |
| 6567 | for j ulong n bound 256 |
| 6568 | if ne get g_line add ns0 j get g_lq j |
| 6569 | same_bytes = false |
| 6570 | end |
| 6571 | end |
| 6572 | if same_bytes |
| 6573 | put g_n 18 1 |
| 6574 | end |
| 6575 | end |
| 6576 | end |
| 6577 | end |
| 6578 | |
| 6579 | note is g_line[o .. o+n) the text t |
| 6580 | fn ulineis o ulong n ulong t view uchar * to bool |
| 6581 | if ne n len t |
| 6582 | ret false |
| 6583 | end |
| 6584 | for i ulong n bound 64 |
| 6585 | if ne get g_line add o i get t i |
| 6586 | ret false |
| 6587 | end |
| 6588 | end |
| 6589 | ret true |
| 6590 | end |
| 6591 | |
| 6592 | note is best file i one of the m matched apps (an app already listed is not shown again as a file) |
| 6593 | fn uisapp i ulong m ulong to ulong |
| 6594 | ln = ufpath i 1 |
| 6595 | if lt ln 6 |
| 6596 | ret 0 |
| 6597 | end |
| 6598 | if not ulineis sub ln 4 4 x_dotapp_low |
| 6599 | ret 0 |
| 6600 | end |
| 6601 | o = ulong 0 |
| 6602 | if and ge ln 14 ulineis 0 14 x_dir1_low |
| 6603 | o = 14 |
| 6604 | end |
| 6605 | if and ge ln 21 ulineis 0 21 x_dir2_low |
| 6606 | o = 21 |
| 6607 | end |
| 6608 | if eq o 0 |
| 6609 | ret 0 |
| 6610 | end |
| 6611 | nl = sub sub ln o 4 |
| 6612 | for j ulong m bound 2048 |
| 6613 | k = get g_mk j |
| 6614 | if eq get g_ln k nl |
| 6615 | same_bytes = true |
| 6616 | for b ulong nl bound 1000 |
| 6617 | if ne ulower ulong get g_pool add get g_off k b ulong get g_line add o b |
| 6618 | same_bytes = false |
| 6619 | end |
| 6620 | end |
| 6621 | if same_bytes |
| 6622 | ret 1 |
| 6623 | end |
| 6624 | end |
| 6625 | end |
| 6626 | ret 0 |
| 6627 | end |
| 6628 | |
| 6629 | note 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 |
| 6630 | fn ufilerow p ulong i ulong to ulong |
| 6631 | ln = ufpath i 0 |
| 6632 | if gt ln 0 |
| 6633 | if eq ulong get g_line sub ln 1 47 |
| 6634 | ln = sub ln 1 |
| 6635 | end |
| 6636 | end |
| 6637 | ns0 = ln |
| 6638 | while gt ns0 0 bound 4097 |
| 6639 | if eq ulong get g_line sub ns0 1 47 |
| 6640 | break |
| 6641 | end |
| 6642 | ns0 = sub ns0 1 |
| 6643 | end |
| 6644 | q = p |
| 6645 | nl = sub ln ns0 |
| 6646 | if gt nl 300 |
| 6647 | nl = 300 |
| 6648 | end |
| 6649 | for j ulong nl bound 301 |
| 6650 | put g_nm add q j get g_line add ns0 j |
| 6651 | end |
| 6652 | q = add q nl |
| 6653 | if and gt ns0 1 le ns0 600 |
| 6654 | q = uptxt q x_gap |
| 6655 | for j ulong sub ns0 1 bound 601 |
| 6656 | put g_nm add q j get g_line j |
| 6657 | end |
| 6658 | q = add q sub ns0 1 |
| 6659 | end |
| 6660 | ret q |
| 6661 | end |
| 6662 | |
| 6663 | note the whole path of best file i into g_nm from byte p (nothing when it is over 900 bytes); the byte after it |
| 6664 | fn ufilepath p ulong i ulong to ulong |
| 6665 | ln = ufpath i 0 |
| 6666 | if gt ln 900 |
| 6667 | ret p |
| 6668 | end |
| 6669 | for j ulong ln bound 901 |
| 6670 | put g_nm add p j get g_line j |
| 6671 | end |
| 6672 | ret add p ln |
| 6673 | end |
| 6674 | |
| 6675 | note open best file i with the app macOS has for it |
| 6676 | fn uopenfile i ulong to void |
| 6677 | p = ufilepath 0 i |
| 6678 | if eq p 0 |
| 6679 | ret |
| 6680 | end |
| 6681 | put g_nm p 0 |
| 6682 | str = unsb |
| 6683 | c = ucl c_url |
| 6684 | s = usl m_furl |
| 6685 | url = umsg c s str 0 0 |
| 6686 | c = ucl c_ws |
| 6687 | s = usl m_shws |
| 6688 | ws = umsg c s 0 0 0 |
| 6689 | s = usl m_open |
| 6690 | put g_n 9 and umsg ws s url 0 0 255 |
| 6691 | end |
| 6692 | |
| 6693 | note ---- Ask: the model of Hop's settings, asked over HTTP as Hop asks it (Sources/Runners.swift) ---- |
| 6694 | note [obj objectForKey: the key named by t] |
| 6695 | fn ukeyed obj ulong t view uchar * to ulong |
| 6696 | key = uns t |
| 6697 | ret umsg obj usl m_object_for_key key 0 0 |
| 6698 | end |
| 6699 | |
| 6700 | note is obj an object of class number w of g_m (7 a dictionary, 8 an array, 9 a string); nothing is not |
| 6701 | fn uiskind obj ulong w ulong to bool |
| 6702 | if eq obj 0 |
| 6703 | ret false |
| 6704 | end |
| 6705 | ret eq and umsg obj usl m_is_kind get g_m w 0 0 255 1 |
| 6706 | end |
| 6707 | |
| 6708 | note the path of the file at Hop's folder plus the text t (an NSString, its bytes left in g_nm; 0 when the |
| 6709 | note folder is not known) |
| 6710 | fn uhoppath t view uchar * to ulong |
| 6711 | n = ucs x_env_dir |
| 6712 | upr 0 ulong libptr g_nm 0 1024 |
| 6713 | dir_text = ucall 9 |
| 6714 | p = ulong 0 |
| 6715 | if ne dir_text 0 |
| 6716 | p = ufetch dir_text |
| 6717 | end |
| 6718 | if eq p 0 |
| 6719 | n = ucs x_env_home |
| 6720 | upr 0 ulong libptr g_nm 0 1024 |
| 6721 | home_text = ucall 9 |
| 6722 | if eq home_text 0 |
| 6723 | ret 0 |
| 6724 | end |
| 6725 | p = ufetch home_text |
| 6726 | p = uptxt p x_support |
| 6727 | end |
| 6728 | p = uptxt p t |
| 6729 | put g_nm p 0 |
| 6730 | ret unsb |
| 6731 | end |
| 6732 | |
| 6733 | note the file at Hop's folder plus the text t, as NSData (0 when it is not there) |
| 6734 | fn uhopfile t view uchar * to ulong |
| 6735 | path = uhoppath t |
| 6736 | if eq path 0 |
| 6737 | ret 0 |
| 6738 | end |
| 6739 | ret umsg ucl c_data usl m_data_file path 0 0 |
| 6740 | end |
| 6741 | |
| 6742 | note ---- saved accounts: Hop's keys and logins in the login Keychain (Sources/Vault.swift) ---- |
| 6743 | note Each is a generic password under Hop's service: the account is its name, the description its kind, the comment |
| 6744 | note its note. Listing them reads no secret. Enter on one reads its secret and puts it on the clipboard, marked |
| 6745 | note concealed so that clipboard histories pass it over, as Hop does; macOS asks the person the first time this |
| 6746 | note program reads an item Hop made. A check (HOPCHECK) reads only the service named by HOPVAULT, never Hop's, |
| 6747 | note and tells the Keychain to put no dialog up for it: what it may not read without one, it does not read. |
| 6748 | note It makes its accounts itself (HOPVAULTADD), since macOS lets a program read back what it saved, and |
| 6749 | note deletes them when it ends. |
| 6750 | note the eight bytes of g_t8 as a number |
| 6751 | fn uread8 to ulong |
| 6752 | v = ulong 0 |
| 6753 | for i ulong 8 |
| 6754 | v = or v shl ulong get g_t8 i mul i 8 |
| 6755 | end |
| 6756 | ret v |
| 6757 | end |
| 6758 | |
| 6759 | note the value of the library's constant named t (a pointer kept in a variable of that name); 0 when there is none |
| 6760 | fn uconst t view uchar * to ulong |
| 6761 | sym_at = usym t |
| 6762 | if eq sym_at 0 |
| 6763 | ret 0 |
| 6764 | end |
| 6765 | upr 0 ulong libptr g_t8 0 8 |
| 6766 | upr 8 sym_at |
| 6767 | upr 16 8 |
| 6768 | x = ucall 8 |
| 6769 | ret uread8 |
| 6770 | end |
| 6771 | |
| 6772 | note ask the Keychain for what q describes; the answer (an object), or 0 |
| 6773 | fn ukeychain q ulong to ulong |
| 6774 | for i ulong 8 |
| 6775 | put g_t8 i 0 |
| 6776 | end |
| 6777 | upr 0 q |
| 6778 | upr 8 ulong libptr g_t8 0 8 |
| 6779 | if ne and ucall 23 4294967295 0 |
| 6780 | ret 0 |
| 6781 | end |
| 6782 | ret uread8 |
| 6783 | end |
| 6784 | |
| 6785 | note a question to the Keychain about Hop's items: the generic passwords under the service |
| 6786 | fn uvaultquery to ulong |
| 6787 | q = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 6788 | sset = usl m_set_object |
| 6789 | x = umsg q sset uconst s_class_generic uconst s_class 0 |
| 6790 | x = umsg q sset get g_m 20 uconst s_attr_service 0 |
| 6791 | ret q |
| 6792 | end |
| 6793 | |
| 6794 | note the saved accounts: their names in order (lower case decides), and what each is |
| 6795 | fn uloadvault to void |
| 6796 | put g_n 31 0 |
| 6797 | service = ulong 0 |
| 6798 | if eq get g_n 14 0 |
| 6799 | n = ucs x_env_vault |
| 6800 | upr 0 ulong libptr g_nm 0 1024 |
| 6801 | vault_text = ucall 9 |
| 6802 | if eq vault_text 0 |
| 6803 | ret |
| 6804 | end |
| 6805 | n = ufetch vault_text |
| 6806 | service = unsb |
| 6807 | else |
| 6808 | service = uns x_vault_service |
| 6809 | end |
| 6810 | if eq service 0 |
| 6811 | ret |
| 6812 | end |
| 6813 | sret = usl m_retain |
| 6814 | if eq get g_m 20 0 |
| 6815 | put g_m 20 umsg service sret 0 0 0 |
| 6816 | if eq get g_n 14 0 |
| 6817 | uvaultcheckadd |
| 6818 | end |
| 6819 | end |
| 6820 | q = uvaultquery |
| 6821 | sset = usl m_set_object |
| 6822 | x = umsg q sset uconst s_limit_all uconst s_match_limit 0 |
| 6823 | x = umsg q sset uconst s_true uconst s_return_attributes 0 |
| 6824 | items = ukeychain q |
| 6825 | if not uiskind items 8 |
| 6826 | ret |
| 6827 | end |
| 6828 | key_account = uconst s_attr_account |
| 6829 | key_kind = uconst s_attr_description |
| 6830 | key_note = uconst s_attr_comment |
| 6831 | sget = usl m_object_for_key |
| 6832 | sat = usl m_at |
| 6833 | slower = usl m_lowercase |
| 6834 | sappend = usl m_append_string |
| 6835 | slen = usl m_length |
| 6836 | by_low = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 6837 | cnt = umsg items usl m_count 0 0 0 |
| 6838 | for i ulong cnt bound 4096 |
| 6839 | item = umsg items sat i 0 0 |
| 6840 | if uiskind item 7 |
| 6841 | name = umsg item sget key_account 0 0 |
| 6842 | if uiskind name 9 |
| 6843 | x = umsg by_low sset item umsg name slower 0 0 0 0 |
| 6844 | end |
| 6845 | end |
| 6846 | end |
| 6847 | lows = umsg umsg by_low usl m_all_keys 0 0 0 usl m_sorted usl m_compare 0 0 |
| 6848 | acct_names = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 6849 | acct_details = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 6850 | sadd = usl m_add_object |
| 6851 | put g_nm 0 32 |
| 6852 | put g_nm 1 194 |
| 6853 | put g_nm 2 183 |
| 6854 | put g_nm 3 32 |
| 6855 | put g_nm 4 0 |
| 6856 | dot = unsb |
| 6857 | put g_nm 0 0 |
| 6858 | nothing = unsb |
| 6859 | total = umsg lows usl m_count 0 0 0 |
| 6860 | if gt total 800 |
| 6861 | total = 800 |
| 6862 | end |
| 6863 | for i ulong total bound 800 |
| 6864 | item = umsg by_low sget umsg lows sat i 0 0 0 0 |
| 6865 | x = umsg acct_names sadd umsg item sget key_account 0 0 0 0 |
| 6866 | detail = nothing |
| 6867 | kind = umsg item sget key_kind 0 0 |
| 6868 | if uiskind kind 9 |
| 6869 | detail = kind |
| 6870 | end |
| 6871 | remark = umsg item sget key_note 0 0 |
| 6872 | if uiskind remark 9 |
| 6873 | if gt umsg remark slen 0 0 0 0 |
| 6874 | if gt umsg detail slen 0 0 0 0 |
| 6875 | detail = umsg detail sappend dot 0 0 |
| 6876 | end |
| 6877 | detail = umsg detail sappend remark 0 0 |
| 6878 | end |
| 6879 | end |
| 6880 | x = umsg acct_details sadd detail 0 0 |
| 6881 | end |
| 6882 | srel = usl m_release |
| 6883 | if ne get g_m 18 0 |
| 6884 | x = umsg get g_m 18 srel 0 0 0 |
| 6885 | x = umsg get g_m 19 srel 0 0 0 |
| 6886 | end |
| 6887 | put g_m 18 umsg acct_names sret 0 0 0 |
| 6888 | put g_m 19 umsg acct_details sret 0 0 0 |
| 6889 | put g_n 31 total |
| 6890 | end |
| 6891 | |
| 6892 | note the secret of the account named name (an NSString), as text; 0 when it cannot be read |
| 6893 | fn usecret name ulong to ulong |
| 6894 | if or eq get g_m 20 0 eq name 0 |
| 6895 | ret 0 |
| 6896 | end |
| 6897 | q = uvaultquery |
| 6898 | sset = usl m_set_object |
| 6899 | x = umsg q sset name uconst s_attr_account 0 |
| 6900 | x = umsg q sset uconst s_true uconst s_return_data 0 |
| 6901 | x = umsg q sset uconst s_limit_one uconst s_match_limit 0 |
| 6902 | d = ukeychain q |
| 6903 | if eq d 0 |
| 6904 | ret 0 |
| 6905 | end |
| 6906 | whole = umsg ucl c_str usl m_alloc 0 0 0 |
| 6907 | ret umsg whole usl m_init_data_encoding d 4 0 |
| 6908 | end |
| 6909 | |
| 6910 | note save an account as Hop does (Vault.save): any item of that name goes, then one is added with the secret as |
| 6911 | note its data, the kind as its description and the note as its comment; 1 when it was added |
| 6912 | fn uvaultsave name ulong secret_text ulong kind ulong remark ulong to ulong |
| 6913 | if or eq get g_m 20 0 or eq name 0 eq secret_text 0 |
| 6914 | ret 0 |
| 6915 | end |
| 6916 | q = uvaultquery |
| 6917 | sset = usl m_set_object |
| 6918 | x = umsg q sset name uconst s_attr_account 0 |
| 6919 | upr 0 q |
| 6920 | x = ucall 25 |
| 6921 | data = umsg secret_text usl m_data_using 4 0 0 |
| 6922 | if eq data 0 |
| 6923 | ret 0 |
| 6924 | end |
| 6925 | x = umsg q sset data uconst s_value_data 0 |
| 6926 | if ne kind 0 |
| 6927 | x = umsg q sset kind uconst s_attr_description 0 |
| 6928 | end |
| 6929 | if ne remark 0 |
| 6930 | x = umsg q sset remark uconst s_attr_comment 0 |
| 6931 | end |
| 6932 | x = umsg q sset uconst s_accessible_unlocked uconst s_accessible 0 |
| 6933 | upr 0 q |
| 6934 | upr 8 0 |
| 6935 | if ne and ucall 24 4294967295 0 |
| 6936 | ret 0 |
| 6937 | end |
| 6938 | ret 1 |
| 6939 | end |
| 6940 | |
| 6941 | note delete the account of that name (Vault.delete) |
| 6942 | fn uvaultdelete name ulong to void |
| 6943 | if or eq get g_m 20 0 eq name 0 |
| 6944 | ret |
| 6945 | end |
| 6946 | q = uvaultquery |
| 6947 | x = umsg q usl m_set_object name uconst s_attr_account 0 |
| 6948 | upr 0 q |
| 6949 | x = ucall 25 |
| 6950 | end |
| 6951 | |
| 6952 | note for a check: the accounts HOPVAULTADD describes ("name|kind|note|value", more after ";") are saved under the |
| 6953 | note check's service by this very program, so that it may read them back without the person being asked |
| 6954 | fn uvaultcheckadd to void |
| 6955 | if eq get g_m 20 0 |
| 6956 | ret |
| 6957 | end |
| 6958 | n = ucs x_env_vault_add |
| 6959 | upr 0 ulong libptr g_nm 0 1024 |
| 6960 | add_text = ucall 9 |
| 6961 | if eq add_text 0 |
| 6962 | ret |
| 6963 | end |
| 6964 | n = ufetch add_text |
| 6965 | whole = unsb |
| 6966 | if eq whole 0 |
| 6967 | ret |
| 6968 | end |
| 6969 | ssplit = usl m_components |
| 6970 | sat = usl m_at |
| 6971 | slen = usl m_length |
| 6972 | made = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 6973 | put g_m 22 umsg made usl m_retain 0 0 0 |
| 6974 | entries = umsg whole ssplit uns x_semicolon 0 0 |
| 6975 | entry_count = umsg entries usl m_count 0 0 0 |
| 6976 | for i ulong entry_count bound 16 |
| 6977 | fields = umsg umsg entries sat i 0 0 ssplit uns x_bar 0 0 |
| 6978 | if eq umsg fields usl m_count 0 0 0 4 |
| 6979 | name = umsg fields sat 0 0 0 |
| 6980 | kind = umsg fields sat 1 0 0 |
| 6981 | remark = umsg fields sat 2 0 0 |
| 6982 | value = umsg fields sat 3 0 0 |
| 6983 | if eq umsg kind slen 0 0 0 0 |
| 6984 | kind = 0 |
| 6985 | end |
| 6986 | if eq umsg remark slen 0 0 0 0 |
| 6987 | remark = 0 |
| 6988 | end |
| 6989 | if eq uvaultsave name value kind remark 1 |
| 6990 | x = umsg made usl m_add_object name 0 0 |
| 6991 | end |
| 6992 | end |
| 6993 | end |
| 6994 | end |
| 6995 | |
| 6996 | note for a check: delete the accounts it made |
| 6997 | fn uvaultcheckend to void |
| 6998 | made = get g_m 22 |
| 6999 | if eq made 0 |
| 7000 | ret |
| 7001 | end |
| 7002 | cnt = umsg made usl m_count 0 0 0 |
| 7003 | for i ulong cnt bound 16 |
| 7004 | uvaultdelete umsg made get g_m 16 i 0 0 |
| 7005 | end |
| 7006 | put g_m 22 0 |
| 7007 | end |
| 7008 | |
| 7009 | note string i of the array into g_nm from byte p; the byte after it |
| 7010 | fn ustrat list_of ulong p ulong i ulong to ulong |
| 7011 | if or eq list_of 0 ge p 900 |
| 7012 | ret p |
| 7013 | end |
| 7014 | entry_text = umsg list_of get g_m 16 i 0 0 |
| 7015 | src = umsg entry_text get g_o 5 0 0 0 |
| 7016 | if eq src 0 |
| 7017 | ret p |
| 7018 | end |
| 7019 | upr 0 src |
| 7020 | n = ucall 7 |
| 7021 | if gt add p n 900 |
| 7022 | n = sub 900 p |
| 7023 | end |
| 7024 | if eq n 0 |
| 7025 | ret p |
| 7026 | end |
| 7027 | upr 0 ulong libptr g_nm p n |
| 7028 | upr 8 src |
| 7029 | upr 16 n |
| 7030 | x = ucall 8 |
| 7031 | ret add p n |
| 7032 | end |
| 7033 | |
| 7034 | note put the secret of saved account i on the clipboard, marked concealed. A check uses a board of its own |
| 7035 | fn ucopysecret i ulong to void |
| 7036 | if ge i get g_n 31 |
| 7037 | ret |
| 7038 | end |
| 7039 | name = umsg get g_m 18 get g_m 16 i 0 0 |
| 7040 | secret_text = usecret name |
| 7041 | if eq secret_text 0 |
| 7042 | ret |
| 7043 | end |
| 7044 | pboard = ulong 0 |
| 7045 | if eq get g_n 14 1 |
| 7046 | pboard = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0 |
| 7047 | else |
| 7048 | pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0 |
| 7049 | end |
| 7050 | x = umsg pboard usl m_clear 0 0 0 |
| 7051 | plain_type = uns x_type_string |
| 7052 | concealed = uns x_type_concealed |
| 7053 | types = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 7054 | sadd = usl m_add_object |
| 7055 | x = umsg types sadd plain_type 0 0 |
| 7056 | x = umsg types sadd concealed 0 0 |
| 7057 | x = umsg pboard usl m_declare_types types 0 0 |
| 7058 | sput = usl m_set_string_type |
| 7059 | x = umsg pboard sput secret_text plain_type 0 |
| 7060 | put g_nm 0 0 |
| 7061 | nothing = unsb |
| 7062 | x = umsg pboard sput nothing concealed 0 |
| 7063 | put g_n 29 1 |
| 7064 | end |
| 7065 | |
| 7066 | note is entry e of the models an HTTP model the panel can ask (one whose key is a saved account needs the |
| 7067 | note accounts to be readable); when it is, keep it as the model to ask |
| 7068 | fn utakemodel e ulong to bool |
| 7069 | if not uiskind e 7 |
| 7070 | ret false |
| 7071 | end |
| 7072 | kind = ukeyed e k_kind |
| 7073 | if uiskind kind 9 |
| 7074 | want = uns x_openai |
| 7075 | if ne and umsg kind usl m_equal_string want 0 0 255 1 |
| 7076 | ret false |
| 7077 | end |
| 7078 | end |
| 7079 | key_name = ukeyed e k_key |
| 7080 | if uiskind key_name 9 |
| 7081 | if eq get g_m 20 0 |
| 7082 | ret false |
| 7083 | end |
| 7084 | else |
| 7085 | key_name = 0 |
| 7086 | end |
| 7087 | base = ukeyed e k_base |
| 7088 | model = ukeyed e k_model |
| 7089 | name = ukeyed e k_name |
| 7090 | if or or not uiskind base 9 not uiskind model 9 not uiskind name 9 |
| 7091 | ret false |
| 7092 | end |
| 7093 | slash = uns x_slash_text |
| 7094 | for i ulong 8 |
| 7095 | if eq and umsg base usl m_has_suffix slash 0 0 255 1 |
| 7096 | base = umsg base usl m_substring_to sub umsg base usl m_length 0 0 0 1 0 0 |
| 7097 | end |
| 7098 | end |
| 7099 | if eq umsg base usl m_length 0 0 0 0 |
| 7100 | ret false |
| 7101 | end |
| 7102 | tail = uns x_completions |
| 7103 | address = umsg base usl m_append_string tail 0 0 |
| 7104 | sret = usl m_retain |
| 7105 | put g_m 0 umsg model sret 0 0 0 |
| 7106 | put g_m 1 umsg address sret 0 0 0 |
| 7107 | put g_m 2 umsg name sret 0 0 0 |
| 7108 | put g_m 21 0 |
| 7109 | if ne key_name 0 |
| 7110 | put g_m 21 umsg key_name sret 0 0 0 |
| 7111 | end |
| 7112 | put g_m 3 1 |
| 7113 | ret true |
| 7114 | end |
| 7115 | |
| 7116 | note read Hop's settings and choose the model: the default one when it will do, else the first that will |
| 7117 | fn uloadconfig to void |
| 7118 | put g_m 3 0 |
| 7119 | put g_m 7 ucl c_dict |
| 7120 | put g_m 8 ucl c_array |
| 7121 | put g_m 9 ucl c_str |
| 7122 | d = uhopfile x_config |
| 7123 | if eq d 0 |
| 7124 | uagentconfig 0 |
| 7125 | ret |
| 7126 | end |
| 7127 | config = umsg ucl c_json usl m_json_object d 0 0 |
| 7128 | if not uiskind config 7 |
| 7129 | uagentconfig 0 |
| 7130 | ret |
| 7131 | end |
| 7132 | uagentconfig config |
| 7133 | umachines config |
| 7134 | utunnelsload config |
| 7135 | put g_n 34 500 |
| 7136 | limit_number = ukeyed config k_limit |
| 7137 | if ne limit_number 0 |
| 7138 | limit_value = ujsonint limit_number |
| 7139 | if and gt limit_value 0 lt limit_value 1000000 |
| 7140 | put g_n 34 limit_value |
| 7141 | end |
| 7142 | end |
| 7143 | models = ukeyed config k_models |
| 7144 | if not uiskind models 8 |
| 7145 | ret |
| 7146 | end |
| 7147 | default_name = ukeyed config k_default |
| 7148 | count = umsg models usl m_count 0 0 0 |
| 7149 | sat = usl m_at |
| 7150 | if uiskind default_name 9 |
| 7151 | for i ulong count bound 256 |
| 7152 | e = umsg models sat i 0 0 |
| 7153 | if uiskind e 7 |
| 7154 | name = ukeyed e k_name |
| 7155 | if uiskind name 9 |
| 7156 | if eq and umsg name usl m_equal_string default_name 0 0 255 1 |
| 7157 | if utakemodel e |
| 7158 | ret |
| 7159 | end |
| 7160 | end |
| 7161 | end |
| 7162 | end |
| 7163 | end |
| 7164 | end |
| 7165 | for i ulong count bound 256 |
| 7166 | e = umsg models sat i 0 0 |
| 7167 | if utakemodel e |
| 7168 | ret |
| 7169 | end |
| 7170 | end |
| 7171 | end |
| 7172 | |
| 7173 | note show the answer in place of the list (on 1), or the list again (on 0) |
| 7174 | fn uanswerview on ulong to void |
| 7175 | s = usl m_set_hidden |
| 7176 | x = umsg get g_o 28 s on 0 0 |
| 7177 | x = umsg get g_o 29 s sub 1 on 0 0 |
| 7178 | put g_n 20 on |
| 7179 | end |
| 7180 | |
| 7181 | note put the answer so far on show |
| 7182 | fn uanswershow to void |
| 7183 | whole_talk = get g_m 4 |
| 7184 | if ne get g_m 25 0 |
| 7185 | whole_talk = umsg get g_m 25 usl m_append_string get g_m 4 0 0 |
| 7186 | end |
| 7187 | x = umsg get g_o 30 usl m_set_string whole_talk 0 0 |
| 7188 | end |
| 7189 | |
| 7190 | note stop asking: the running task is cancelled and the list is back |
| 7191 | fn uaskstop to void |
| 7192 | if ne get g_m 6 0 |
| 7193 | x = umsg get g_m 6 usl m_cancel_task 0 0 0 |
| 7194 | put g_m 6 0 |
| 7195 | if ne get g_m 24 0 |
| 7196 | x = umsg get g_m 24 usl m_remove_last 0 0 0 |
| 7197 | end |
| 7198 | put g_n 39 1 |
| 7199 | end |
| 7200 | if eq get g_n 20 1 |
| 7201 | uanswerview 0 |
| 7202 | end |
| 7203 | end |
| 7204 | |
| 7205 | note ask the model the typed text. The body is made by Foundation, so the text is quoted as JSON wants it |
| 7206 | fn uask to void |
| 7207 | if eq get g_m 3 0 |
| 7208 | ret |
| 7209 | end |
| 7210 | a = get g_n 12 |
| 7211 | n = get g_n 13 |
| 7212 | for i ulong n bound 256 |
| 7213 | put g_nm i get g_q add a i |
| 7214 | end |
| 7215 | put g_nm n 0 |
| 7216 | question = unsb |
| 7217 | sset = usl m_set_object |
| 7218 | message = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 7219 | x = umsg message sset uns x_user uns k_role 0 |
| 7220 | x = umsg message sset question uns k_content 0 |
| 7221 | if eq get g_m 24 0 |
| 7222 | talk = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 7223 | put g_m 24 umsg talk usl m_retain 0 0 0 |
| 7224 | told = umsg ucl c_mutable_string usl m_string 0 0 0 |
| 7225 | put g_m 25 umsg told usl m_retain 0 0 0 |
| 7226 | end |
| 7227 | note a question asked while another is on its way takes its place |
| 7228 | if ne get g_m 6 0 |
| 7229 | x = umsg get g_m 6 usl m_cancel_task 0 0 0 |
| 7230 | put g_m 6 0 |
| 7231 | x = umsg get g_m 24 usl m_remove_last 0 0 0 |
| 7232 | put g_n 39 1 |
| 7233 | end |
| 7234 | messages = umsg get g_m 24 usl m_array_adding message 0 0 |
| 7235 | body = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 7236 | x = umsg body sset get g_m 0 uns k_model 0 |
| 7237 | x = umsg body sset messages uns k_messages 0 |
| 7238 | yes = umsg ucl c_number usl m_number_bool 1 0 0 |
| 7239 | x = umsg body sset yes uns k_stream 0 |
| 7240 | data = umsg ucl c_json usl m_json_data body 0 0 |
| 7241 | url = umsg get g_o 16 get g_o 17 get g_m 1 0 0 |
| 7242 | if or eq data 0 eq url 0 |
| 7243 | ret |
| 7244 | end |
| 7245 | req = umsg ucl c_request usl m_request_url url 0 0 |
| 7246 | x = umsg req usl m_set_method uns x_post 0 0 |
| 7247 | x = umsg req usl m_set_header uns x_json_type uns x_content_type 0 |
| 7248 | if ne get g_m 21 0 |
| 7249 | secret_text = usecret get g_m 21 |
| 7250 | if eq secret_text 0 |
| 7251 | if eq get g_m 4 0 |
| 7252 | fresh_text = umsg ucl c_mutable_string usl m_string 0 0 0 |
| 7253 | put g_m 4 umsg fresh_text usl m_retain 0 0 0 |
| 7254 | end |
| 7255 | x = umsg get g_m 4 usl m_set_string uns x_no_key 0 0 |
| 7256 | put g_n 21 1 |
| 7257 | put g_n 22 1 |
| 7258 | uanswershow |
| 7259 | uanswerview 1 |
| 7260 | ret |
| 7261 | end |
| 7262 | bearer = umsg uns x_bearer usl m_append_string secret_text 0 0 |
| 7263 | x = umsg req usl m_set_header bearer uns x_authorization 0 |
| 7264 | end |
| 7265 | x = umsg req usl m_set_body data 0 0 |
| 7266 | s_timeout = usl m_set_timeout |
| 7267 | upr 64 bitcast ulong 120.0f64 |
| 7268 | x = umsg req s_timeout 0 0 0 |
| 7269 | if eq get g_m 5 0 |
| 7270 | cfg = umsg ucl c_session_config usl m_ephemeral 0 0 0 |
| 7271 | queue = umsg ucl c_queue usl m_main_queue 0 0 0 |
| 7272 | session = umsg ucl c_session usl m_session_with cfg get g_o 27 queue |
| 7273 | put g_m 5 umsg session usl m_retain 0 0 0 |
| 7274 | end |
| 7275 | if eq get g_m 4 0 |
| 7276 | fresh_text = umsg ucl c_mutable_string usl m_string 0 0 0 |
| 7277 | put g_m 4 umsg fresh_text usl m_retain 0 0 0 |
| 7278 | end |
| 7279 | note what was on show joins what was said before; then the question |
| 7280 | put g_nm 0 10 |
| 7281 | put g_nm 1 10 |
| 7282 | put g_nm 2 0 |
| 7283 | blank_line = unsb |
| 7284 | sappend_text = usl m_append |
| 7285 | if eq get g_n 39 1 |
| 7286 | x = umsg get g_m 25 sappend_text get g_m 4 0 0 |
| 7287 | x = umsg get g_m 25 sappend_text blank_line 0 0 |
| 7288 | end |
| 7289 | x = umsg get g_m 25 sappend_text uns x_you 0 0 |
| 7290 | x = umsg get g_m 25 sappend_text question 0 0 |
| 7291 | x = umsg get g_m 25 sappend_text blank_line 0 0 |
| 7292 | x = umsg get g_m 24 usl m_add_object message 0 0 |
| 7293 | x = umsg get g_m 4 usl m_set_string uns x_asking 0 0 |
| 7294 | put g_n 19 0 |
| 7295 | put g_n 21 0 |
| 7296 | put g_n 22 0 |
| 7297 | put g_n 39 0 |
| 7298 | put g_n 40 0 |
| 7299 | uanswershow |
| 7300 | uanswerview 1 |
| 7301 | task = umsg get g_m 5 usl m_data_task req 0 0 |
| 7302 | put g_m 6 umsg task usl m_retain 0 0 0 |
| 7303 | x = umsg task usl m_resume 0 0 0 |
| 7304 | end |
| 7305 | |
| 7306 | note a turn has ended: an answer joins the conversation; without one the question leaves it again, so that the |
| 7307 | note model is not sent a question it never answered |
| 7308 | fn uturnend to void |
| 7309 | put g_n 39 1 |
| 7310 | if eq get g_m 24 0 |
| 7311 | ret |
| 7312 | end |
| 7313 | if or eq get g_n 40 1 eq get g_n 22 0 |
| 7314 | x = umsg get g_m 24 usl m_remove_last 0 0 0 |
| 7315 | ret |
| 7316 | end |
| 7317 | sset = usl m_set_object |
| 7318 | reply = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 7319 | x = umsg reply sset uns x_assistant uns k_role 0 |
| 7320 | said = umsg ucl c_str usl m_utf umsg get g_m 4 get g_o 5 0 0 0 0 0 |
| 7321 | if eq said 0 |
| 7322 | x = umsg get g_m 24 usl m_remove_last 0 0 0 |
| 7323 | ret |
| 7324 | end |
| 7325 | x = umsg reply sset said uns k_content 0 |
| 7326 | x = umsg get g_m 24 usl m_add_object reply 0 0 |
| 7327 | end |
| 7328 | |
| 7329 | note New chat: the conversation is forgotten |
| 7330 | fn uchatnew to void |
| 7331 | if ne get g_m 33 0 |
| 7332 | x = umsg get g_m 33 usl m_release 0 0 0 |
| 7333 | put g_m 33 0 |
| 7334 | end |
| 7335 | if ne get g_m 6 0 |
| 7336 | x = umsg get g_m 6 usl m_cancel_task 0 0 0 |
| 7337 | put g_m 6 0 |
| 7338 | end |
| 7339 | srel = usl m_release |
| 7340 | if ne get g_m 24 0 |
| 7341 | x = umsg get g_m 24 srel 0 0 0 |
| 7342 | x = umsg get g_m 25 srel 0 0 0 |
| 7343 | put g_m 24 0 |
| 7344 | put g_m 25 0 |
| 7345 | end |
| 7346 | put g_n 39 0 |
| 7347 | if ne get g_m 4 0 |
| 7348 | put g_nm 0 0 |
| 7349 | no_text = unsb |
| 7350 | x = umsg get g_m 4 usl m_set_string no_text 0 0 |
| 7351 | end |
| 7352 | if eq get g_n 20 1 |
| 7353 | uanswerview 0 |
| 7354 | end |
| 7355 | end |
| 7356 | |
| 7357 | note for a check: when the first answer has come, ask the second question (HOPASK2) in the same conversation |
| 7358 | fn uasksecond to void |
| 7359 | n = ucs x_env_ask2 |
| 7360 | upr 0 ulong libptr g_nm 0 1024 |
| 7361 | second_text = ucall 9 |
| 7362 | if or eq second_text 0 eq get g_n 21 0 |
| 7363 | ret |
| 7364 | end |
| 7365 | n = ucs x_env_asknew |
| 7366 | upr 0 ulong libptr g_nm 0 1024 |
| 7367 | if ne ucall 9 0 |
| 7368 | uchatnew |
| 7369 | end |
| 7370 | n = ufetch second_text |
| 7371 | second = unsb |
| 7372 | x = umsg get g_o 0 get g_o 8 second 0 0 |
| 7373 | utyped |
| 7374 | if and gt get g_n 1 0 eq ulong get g_rk 0 8 |
| 7375 | uask |
| 7376 | end |
| 7377 | end |
| 7378 | |
| 7379 | note a piece of the answer: the first one takes the place of "Asking ..." |
| 7380 | fn uanswerpiece piece ulong to void |
| 7381 | if eq get g_n 22 0 |
| 7382 | put g_nm 0 0 |
| 7383 | empty_text = unsb |
| 7384 | x = umsg get g_m 4 usl m_set_string empty_text 0 0 |
| 7385 | put g_n 22 1 |
| 7386 | end |
| 7387 | x = umsg get g_m 4 usl m_append piece 0 0 |
| 7388 | uanswershow |
| 7389 | end |
| 7390 | |
| 7391 | note the JSON in g_net[o .. o+n) as an object (0 when it is not JSON) |
| 7392 | fn unetjson o ulong n ulong to ulong |
| 7393 | if or eq n 0 gt add o n 262144 |
| 7394 | ret 0 |
| 7395 | end |
| 7396 | d = umsg ucl c_data usl m_data_bytes ulong libptr g_net o n n 0 |
| 7397 | ret umsg ucl c_json usl m_json_object d 0 0 |
| 7398 | end |
| 7399 | |
| 7400 | note one line from the server: "data: {...}" carries a piece of the answer at choices[0].delta.content |
| 7401 | note (an empty line may stand first in what came: a server's packet may begin with the line break that ends an |
| 7402 | note event, so nothing before the line is looked at when it is empty; "and" looks at both its sides) |
| 7403 | fn unetline o ulong n ulong to void |
| 7404 | ln = n |
| 7405 | if gt ln 0 |
| 7406 | if eq ulong get g_net sub add o ln 1 13 |
| 7407 | ln = sub ln 1 |
| 7408 | end |
| 7409 | end |
| 7410 | if lt ln 6 |
| 7411 | ret |
| 7412 | end |
| 7413 | if 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 |
| 7414 | ret |
| 7415 | end |
| 7416 | pay_o = add o 5 |
| 7417 | pay_l = sub ln 5 |
| 7418 | while and gt pay_l 0 eq ulong get g_net pay_o 32 bound 300000 |
| 7419 | pay_o = add pay_o 1 |
| 7420 | pay_l = sub pay_l 1 |
| 7421 | end |
| 7422 | obj = unetjson pay_o pay_l |
| 7423 | if not uiskind obj 7 |
| 7424 | ret |
| 7425 | end |
| 7426 | choices = ukeyed obj k_choices |
| 7427 | if not uiskind choices 8 |
| 7428 | ret |
| 7429 | end |
| 7430 | if eq umsg choices usl m_count 0 0 0 0 |
| 7431 | ret |
| 7432 | end |
| 7433 | choice = umsg choices usl m_at 0 0 0 |
| 7434 | if not uiskind choice 7 |
| 7435 | ret |
| 7436 | end |
| 7437 | delta = ukeyed choice k_delta |
| 7438 | if not uiskind delta 7 |
| 7439 | ret |
| 7440 | end |
| 7441 | content = ukeyed delta k_content |
| 7442 | if uiskind content 9 |
| 7443 | if gt umsg content usl m_length 0 0 0 0 |
| 7444 | uanswerpiece content |
| 7445 | end |
| 7446 | end |
| 7447 | end |
| 7448 | |
| 7449 | note bytes from the server: add them to g_net, read every whole line, keep the rest |
| 7450 | fn unetdata data ulong to void |
| 7451 | p = umsg data usl m_bytes 0 0 0 |
| 7452 | n = umsg data usl m_length 0 0 0 |
| 7453 | fill = get g_n 19 |
| 7454 | if or eq p 0 gt add fill n 262144 |
| 7455 | put g_n 19 0 |
| 7456 | ret |
| 7457 | end |
| 7458 | if eq n 0 |
| 7459 | ret |
| 7460 | end |
| 7461 | upr 0 ulong libptr g_net fill n |
| 7462 | upr 8 p |
| 7463 | upr 16 n |
| 7464 | x = ucall 8 |
| 7465 | fill = add fill n |
| 7466 | line_start = ulong 0 |
| 7467 | i = ulong 0 |
| 7468 | while lt i fill bound 300000 |
| 7469 | if eq ulong get g_net i 10 |
| 7470 | unetline line_start sub i line_start |
| 7471 | line_start = add i 1 |
| 7472 | end |
| 7473 | i = add i 1 |
| 7474 | end |
| 7475 | rest = sub fill line_start |
| 7476 | for j ulong rest bound 300000 |
| 7477 | put g_net j get g_net add line_start j |
| 7478 | end |
| 7479 | put g_n 19 rest |
| 7480 | end |
| 7481 | |
| 7482 | note the answer has ended (problem: what went wrong, or nothing). A server that did not stream gave one JSON |
| 7483 | note object: its text is at choices[0].message.content |
| 7484 | fn unetdone task ulong problem ulong to void |
| 7485 | put g_n 21 1 |
| 7486 | if ne task get g_m 6 |
| 7487 | ret |
| 7488 | end |
| 7489 | put g_m 6 0 |
| 7490 | if ne problem 0 |
| 7491 | uanswerpiece umsg problem usl m_description 0 0 0 |
| 7492 | put g_n 40 1 |
| 7493 | uturnend |
| 7494 | ret |
| 7495 | end |
| 7496 | if eq get g_n 22 0 |
| 7497 | obj = unetjson 0 get g_n 19 |
| 7498 | if uiskind obj 7 |
| 7499 | choices = ukeyed obj k_choices |
| 7500 | if uiskind choices 8 |
| 7501 | if gt umsg choices usl m_count 0 0 0 0 |
| 7502 | choice = umsg choices usl m_at 0 0 0 |
| 7503 | if uiskind choice 7 |
| 7504 | message = ukeyed choice k_message |
| 7505 | if uiskind message 7 |
| 7506 | content = ukeyed message k_content |
| 7507 | if uiskind content 9 |
| 7508 | uanswerpiece content |
| 7509 | end |
| 7510 | end |
| 7511 | end |
| 7512 | end |
| 7513 | end |
| 7514 | end |
| 7515 | end |
| 7516 | if eq get g_n 22 0 |
| 7517 | code = umsg umsg task usl m_response 0 0 0 usl m_status_code 0 0 0 |
| 7518 | if ge code 300 |
| 7519 | p = ulong 0 |
| 7520 | if or eq code 429 eq code 503 |
| 7521 | p = uptxt 0 x_busy |
| 7522 | end |
| 7523 | p = uptxt p x_http |
| 7524 | p = upnum p code |
| 7525 | p = uptxt p x_bracket |
| 7526 | put g_nm p 0 |
| 7527 | uanswerpiece unsb |
| 7528 | else |
| 7529 | uanswerpiece uns x_no_answer |
| 7530 | end |
| 7531 | put g_n 40 1 |
| 7532 | end |
| 7533 | uturnend |
| 7534 | end |
| 7535 | |
| 7536 | note the rows for typed text, by the one box's rules (fn swrank): the request is what Sources/SmartRank.swift |
| 7537 | note sends, with the m matched apps of g_mk, their hopfuzz scores, use and habits, the web address and the files found, and |
| 7538 | note 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. |
| 7539 | note one word of a screen or a command into the request: its length as number k, its bytes at bp; the byte after |
| 7540 | fn uwordput tb edit uchar 1048576 k ulong bp ulong t view uchar * to ulong |
| 7541 | n = ucs t |
| 7542 | upn tb k n |
| 7543 | for i ulong n bound 64 |
| 7544 | put tb add bp i get g_nm i |
| 7545 | end |
| 7546 | ret add bp n |
| 7547 | end |
| 7548 | |
| 7549 | fn urankrows m ulong to void |
| 7550 | tb = new uchar 1048576 0 |
| 7551 | ob = new uchar 65544 0 |
| 7552 | a = get g_n 12 |
| 7553 | n = get g_n 13 |
| 7554 | nf = get g_n 17 |
| 7555 | uclipmatch 8 |
| 7556 | ncl = get g_n 28 |
| 7557 | nacc = get g_n 31 |
| 7558 | nr = get g_n 49 |
| 7559 | nfa = add nf nr |
| 7560 | c = add add add add add 13 mul m 4 mul nfa 3 mul nacc 2 ncl 26 |
| 7561 | upn tb 0 n |
| 7562 | upn tb 1 n |
| 7563 | upn tb 2 get g_n 10 |
| 7564 | upn tb 3 1 |
| 7565 | exact_name = get g_n 18 |
| 7566 | if eq get g_n 58 1 |
| 7567 | exact_name = 1 |
| 7568 | end |
| 7569 | upn tb 4 exact_name |
| 7570 | upn tb 5 get g_n 41 |
| 7571 | words_typed = ulong 0 |
| 7572 | in_word = false |
| 7573 | for i ulong n bound 256 |
| 7574 | cw = ulong get g_q add a i |
| 7575 | if or eq cw 32 eq cw 9 |
| 7576 | in_word = false |
| 7577 | else |
| 7578 | if not in_word |
| 7579 | words_typed = add words_typed 1 |
| 7580 | end |
| 7581 | in_word = true |
| 7582 | end |
| 7583 | end |
| 7584 | send_agent = ulong 0 |
| 7585 | if and eq get g_n 42 1 ge words_typed 3 |
| 7586 | send_agent = 1 |
| 7587 | end |
| 7588 | upn tb 6 send_agent |
| 7589 | upn tb 7 m |
| 7590 | upn tb 8 nfa |
| 7591 | for i ulong nr bound 64 |
| 7592 | o = add add 13 mul m 4 mul add nf i 3 |
| 7593 | upb tb o sub add k_b get g_rs i 100000 |
| 7594 | upn tb add o 1 0 |
| 7595 | upn tb add o 2 0 |
| 7596 | end |
| 7597 | for i ulong 4 |
| 7598 | upn tb add 9 i 0 |
| 7599 | end |
| 7600 | upn tb 12 ncl |
| 7601 | upn tb 11 nacc |
| 7602 | pacc = add add 13 mul m 4 mul nfa 3 |
| 7603 | note the screens the panel has (the copied things, the accounts) and what it can do (settings, quit), each with |
| 7604 | note the words that name it (and Rebuild file index): a count, then the length of each word; the words themselves follow the typed text |
| 7605 | q = add add pacc mul nacc 2 ncl |
| 7606 | word_start = add add 8 mul c 8 n |
| 7607 | bp = word_start |
| 7608 | upn tb add q 0 3 |
| 7609 | bp = uwordput tb add q 1 bp x_word0 |
| 7610 | bp = uwordput tb add q 2 bp x_word1 |
| 7611 | bp = uwordput tb add q 3 bp x_word2 |
| 7612 | upn tb add q 4 5 |
| 7613 | bp = uwordput tb add q 5 bp x_word3 |
| 7614 | bp = uwordput tb add q 6 bp x_word4 |
| 7615 | bp = uwordput tb add q 7 bp x_word5 |
| 7616 | bp = uwordput tb add q 8 bp x_word6 |
| 7617 | bp = uwordput tb add q 9 bp x_word7 |
| 7618 | upn tb add q 10 1 |
| 7619 | bp = uwordput tb add q 11 bp x_word_agent |
| 7620 | upn tb add q 12 4 |
| 7621 | bp = uwordput tb add q 13 bp x_word8 |
| 7622 | bp = uwordput tb add q 14 bp x_word9 |
| 7623 | bp = uwordput tb add q 15 bp x_word10 |
| 7624 | bp = uwordput tb add q 16 bp x_word11 |
| 7625 | upn tb add q 17 1 |
| 7626 | bp = uwordput tb add q 18 bp x_word12 |
| 7627 | upn tb add q 19 3 |
| 7628 | bp = uwordput tb add q 20 bp x_word_rebuild |
| 7629 | bp = uwordput tb add q 21 bp x_word_reindex |
| 7630 | bp = uwordput tb add q 22 bp x_word_index_files |
| 7631 | upn tb add q 23 2 |
| 7632 | bp = uwordput tb add q 24 bp x_word_new_chat |
| 7633 | bp = uwordput tb add q 25 bp x_word_clear_chat |
| 7634 | word_bytes = sub bp word_start |
| 7635 | upn tb 9 3 |
| 7636 | upn tb 10 4 |
| 7637 | for i ulong ncl bound 8 |
| 7638 | upn tb add add pacc mul nacc 2 i ulong get g_cp get g_cm i |
| 7639 | end |
| 7640 | if gt nacc 0 |
| 7641 | for i ulong n bound 256 |
| 7642 | put g_nm i get g_q add a i |
| 7643 | end |
| 7644 | put g_nm n 0 |
| 7645 | typed = unsb |
| 7646 | typed_low = ulong 0 |
| 7647 | if ne typed 0 |
| 7648 | typed_low = umsg typed usl m_lowercase 0 0 0 |
| 7649 | end |
| 7650 | slower = usl m_lowercase |
| 7651 | scontains = usl m_contains |
| 7652 | sprefix = usl m_has_prefix |
| 7653 | for i ulong nacc bound 800 |
| 7654 | has = ulong 0 |
| 7655 | starts = ulong 0 |
| 7656 | if ne typed_low 0 |
| 7657 | name_low = umsg umsg get g_m 18 get g_m 16 i 0 0 slower 0 0 0 |
| 7658 | has = and umsg name_low scontains typed_low 0 0 255 |
| 7659 | starts = and umsg name_low sprefix typed_low 0 0 255 |
| 7660 | end |
| 7661 | upn tb add pacc mul i 2 has |
| 7662 | upn tb add add pacc mul i 2 1 starts |
| 7663 | end |
| 7664 | end |
| 7665 | note 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 |
| 7666 | note hour, and whether it is the app that was in front before (all as they were when the panel was last shown) |
| 7667 | for i ulong m bound 2048 |
| 7668 | o = add 13 mul i 4 |
| 7669 | k = get g_mk i |
| 7670 | upn tb o get g_ms i |
| 7671 | upn tb add o 1 get g_us k |
| 7672 | upn tb add o 2 add get g_lf k get g_lh k |
| 7673 | was_before = ulong 0 |
| 7674 | if eq add k 1 get g_n 32 |
| 7675 | was_before = 1 |
| 7676 | end |
| 7677 | upn tb add o 3 was_before |
| 7678 | end |
| 7679 | note a file's score may be below zero: it goes in as 2^40 plus the score, written as it is |
| 7680 | for i ulong nf bound 64 |
| 7681 | o = add add 13 mul m 4 mul i 3 |
| 7682 | upb tb o sub add k_b get g_fs i 100000 |
| 7683 | upn tb add o 1 0 |
| 7684 | upn tb add o 2 uisapp i m |
| 7685 | end |
| 7686 | lo = add 8 mul c 8 |
| 7687 | for i ulong n bound 256 |
| 7688 | put tb add lo i uchar ulower ulong get g_q add a i |
| 7689 | end |
| 7690 | k = swrank tb c add n word_bytes ob |
| 7691 | h = ulong 0 |
| 7692 | if ne k 0 |
| 7693 | rws = sub uog ob 0 k_b |
| 7694 | for i ulong rws bound 1024 |
| 7695 | knd = sub uog ob add 1 mul i 4 k_b |
| 7696 | ix = sub uog ob add 2 mul i 4 k_b |
| 7697 | if and eq knd 1 lt ix m |
| 7698 | put g_rk h 1 |
| 7699 | put g_hit h get g_mk ix |
| 7700 | h = add h 1 |
| 7701 | end |
| 7702 | if eq knd 2 |
| 7703 | put g_rk h 2 |
| 7704 | put g_hit h 0 |
| 7705 | h = add h 1 |
| 7706 | end |
| 7707 | if and eq knd 7 lt ix nf |
| 7708 | put g_rk h 7 |
| 7709 | put g_hit h ix |
| 7710 | h = add h 1 |
| 7711 | end |
| 7712 | if and and eq knd 7 ge ix nf lt ix nfa |
| 7713 | put g_rk h 10 |
| 7714 | put g_hit h sub ix nf |
| 7715 | h = add h 1 |
| 7716 | end |
| 7717 | if eq knd 8 |
| 7718 | put g_rk h 8 |
| 7719 | put g_hit h 0 |
| 7720 | h = add h 1 |
| 7721 | end |
| 7722 | if eq knd 9 |
| 7723 | put g_rk h 9 |
| 7724 | put g_hit h 0 |
| 7725 | h = add h 1 |
| 7726 | end |
| 7727 | if and eq knd 6 lt ix ncl |
| 7728 | put g_rk h 6 |
| 7729 | put g_hit h get g_cm ix |
| 7730 | h = add h 1 |
| 7731 | end |
| 7732 | if and eq knd 5 lt ix nacc |
| 7733 | put g_rk h 5 |
| 7734 | put g_hit h ix |
| 7735 | h = add h 1 |
| 7736 | end |
| 7737 | if and eq knd 3 lt ix 3 |
| 7738 | put g_rk h 3 |
| 7739 | put g_hit h ix |
| 7740 | h = add h 1 |
| 7741 | end |
| 7742 | if and eq knd 4 lt ix 4 |
| 7743 | put g_rk h 4 |
| 7744 | put g_hit h ix |
| 7745 | h = add h 1 |
| 7746 | end |
| 7747 | end |
| 7748 | end |
| 7749 | put g_n 1 h |
| 7750 | end |
| 7751 | |
| 7752 | note ---- before anything is typed: what to offer, by Hop's rule (fn swsuggest, fn swlifts) ---- |
| 7753 | note the path of app k into g_nm from byte p (its folder, "/", its name, ".app"); the byte after it |
| 7754 | fn uapppath p ulong k ulong to ulong |
| 7755 | q = p |
| 7756 | if eq ulong get g_dir k 0 |
| 7757 | q = uptxt p x_dir1 |
| 7758 | else |
| 7759 | q = uptxt p x_dir2 |
| 7760 | end |
| 7761 | q = uptxt q x_slash |
| 7762 | q = upname q k |
| 7763 | ret uptxt q x_dotapp |
| 7764 | end |
| 7765 | |
| 7766 | note byte j of app k's name with ".app" after it (0 past the end): what its path is ordered by within a folder |
| 7767 | fn ukeybyte k ulong j ulong to ulong |
| 7768 | n = get g_ln k |
| 7769 | if lt j n |
| 7770 | ret ulong get g_pool add get g_off k j |
| 7771 | end |
| 7772 | if lt j add n 4 |
| 7773 | ret ulong get x_dotapp sub j n |
| 7774 | end |
| 7775 | ret 0 |
| 7776 | end |
| 7777 | |
| 7778 | note does app a come before app b in the order of their paths |
| 7779 | fn uappless a ulong b ulong to bool |
| 7780 | da = ulong get g_dir a |
| 7781 | db = ulong get g_dir b |
| 7782 | if ne da db |
| 7783 | ret lt da db |
| 7784 | end |
| 7785 | for j ulong 1100 |
| 7786 | ca = ukeybyte a j |
| 7787 | cb = ukeybyte b j |
| 7788 | if ne ca cb |
| 7789 | ret lt ca cb |
| 7790 | end |
| 7791 | if eq ca 0 |
| 7792 | ret false |
| 7793 | end |
| 7794 | end |
| 7795 | ret false |
| 7796 | end |
| 7797 | |
| 7798 | note each app's path and place into a dictionary, and the apps into the order of their paths |
| 7799 | fn ubuildmap to void |
| 7800 | map = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 7801 | put g_m 10 umsg map usl m_retain 0 0 0 |
| 7802 | sset = usl m_set_object |
| 7803 | snum = usl m_number_integer |
| 7804 | cnum = ucl c_number |
| 7805 | for k ulong get g_n 0 bound 2048 |
| 7806 | p = uapppath 0 k |
| 7807 | put g_nm p 0 |
| 7808 | path = unsb |
| 7809 | num = umsg cnum snum k 0 0 |
| 7810 | x = umsg map sset num path 0 |
| 7811 | pos = k |
| 7812 | while gt pos 0 bound 4096 |
| 7813 | if not uappless k get g_so sub pos 1 |
| 7814 | break |
| 7815 | end |
| 7816 | put g_so pos get g_so sub pos 1 |
| 7817 | pos = sub pos 1 |
| 7818 | end |
| 7819 | put g_so pos k |
| 7820 | end |
| 7821 | end |
| 7822 | |
| 7823 | note the place of the app at this path (an NSString), or the count of apps when it is not one of them |
| 7824 | fn uplaceof path ulong to ulong |
| 7825 | if or eq path 0 eq get g_m 10 0 |
| 7826 | ret get g_n 0 |
| 7827 | end |
| 7828 | num = umsg get g_m 10 usl m_object_for_key path 0 0 |
| 7829 | if eq num 0 |
| 7830 | ret get g_n 0 |
| 7831 | end |
| 7832 | ret umsg num usl m_integer_value 0 0 0 |
| 7833 | end |
| 7834 | |
| 7835 | note how much the user's own use lifts a path: 25 times the base-2 logarithm of 1 plus the count of openings, the |
| 7836 | note count halved for every three days since the last, plus 10; 80 at most (Sources/Recents.swift) |
| 7837 | fn uboost cnt ulong last_bits ulong now_bits ulong to ulong |
| 7838 | age = sub bitcast f64 now_bits bitcast f64 last_bits |
| 7839 | upr 64 bitcast ulong 0.5f64 |
| 7840 | upr 72 bitcast ulong div age 259200.0f64 |
| 7841 | x = ucall 14 |
| 7842 | weighed = mul f64 cnt bitcast f64 ugr 64 |
| 7843 | upr 64 bitcast ulong add 1.0f64 weighed |
| 7844 | x = ucall 15 |
| 7845 | v = add mul 25.0f64 bitcast f64 ugr 64 10.0f64 |
| 7846 | if gt v 80.0f64 |
| 7847 | ret 80 |
| 7848 | end |
| 7849 | if lt v 0.0f64 |
| 7850 | ret 0 |
| 7851 | end |
| 7852 | ret ulong v |
| 7853 | end |
| 7854 | |
| 7855 | note remember the app in front (not this program) before the panel takes its place |
| 7856 | fn ufront to void |
| 7857 | ws = umsg ucl c_ws usl m_shws 0 0 0 |
| 7858 | app_front = umsg ws usl m_frontmost 0 0 0 |
| 7859 | this_app = umsg ucl c_running_app usl m_current_app 0 0 0 |
| 7860 | if or eq app_front 0 eq app_front this_app |
| 7861 | ret |
| 7862 | end |
| 7863 | sret = usl m_retain |
| 7864 | id = umsg app_front usl m_bundle_id 0 0 0 |
| 7865 | put g_m 11 0 |
| 7866 | if ne id 0 |
| 7867 | put g_m 11 umsg id sret 0 0 0 |
| 7868 | end |
| 7869 | name = umsg app_front usl m_localized_name 0 0 0 |
| 7870 | put g_m 12 0 |
| 7871 | if ne name 0 |
| 7872 | put g_m 12 umsg name sret 0 0 0 |
| 7873 | end |
| 7874 | put g_m 13 0 |
| 7875 | url = umsg app_front usl m_bundle_url 0 0 0 |
| 7876 | if eq url 0 |
| 7877 | ret |
| 7878 | end |
| 7879 | k = uplaceof umsg url usl m_path 0 0 0 |
| 7880 | if ge k get g_n 0 |
| 7881 | ret |
| 7882 | end |
| 7883 | put g_m 13 add k 1 |
| 7884 | note newest first, each app once |
| 7885 | found = ulong 11 |
| 7886 | for i ulong 12 |
| 7887 | if and eq get g_fr i add k 1 eq found 11 |
| 7888 | found = i |
| 7889 | end |
| 7890 | end |
| 7891 | pos = found |
| 7892 | while gt pos 0 bound 16 |
| 7893 | put g_fr pos get g_fr sub pos 1 |
| 7894 | pos = sub pos 1 |
| 7895 | end |
| 7896 | put g_fr 0 add k 1 |
| 7897 | end |
| 7898 | |
| 7899 | note is the JSON value a number (a file a person may have edited can hold anything where a number belongs, and |
| 7900 | note only a number can be asked for its value: a null, a list or a group asked so would stop the program) |
| 7901 | fn uisnumber obj ulong to bool |
| 7902 | if eq obj 0 |
| 7903 | ret false |
| 7904 | end |
| 7905 | ret eq and umsg obj usl m_is_kind ucl c_number 0 0 255 1 |
| 7906 | end |
| 7907 | |
| 7908 | note a whole number from a JSON value (0 when it is none); below zero comes back as a number of 2^63 and up |
| 7909 | fn ujsonint obj ulong to ulong |
| 7910 | if not uisnumber obj |
| 7911 | ret 0 |
| 7912 | end |
| 7913 | ret umsg obj usl m_integer_value 0 0 0 |
| 7914 | end |
| 7915 | |
| 7916 | note the rows before anything is typed: the lifts from habit, the use, what is running and what was in front go |
| 7917 | note to the rule as numbers, in the order of the apps' paths; the app in front is never offered |
| 7918 | fn usuggest to void |
| 7919 | tb = new uchar 1048576 0 |
| 7920 | ob = new uchar 65544 0 |
| 7921 | na = get g_n 0 |
| 7922 | put g_n 1 0 |
| 7923 | if eq get g_m 10 0 |
| 7924 | ret |
| 7925 | end |
| 7926 | note the lifts from habit |
| 7927 | for k ulong na bound 2048 |
| 7928 | put g_lf k 0 |
| 7929 | put g_lh k 0 |
| 7930 | put g_us k 0 |
| 7931 | put g_rn k 0 |
| 7932 | end |
| 7933 | cal = umsg ucl c_calendar usl m_current_calendar 0 0 0 |
| 7934 | now_date = umsg ucl c_date usl m_date_now 0 0 0 |
| 7935 | hour = umsg cal usl m_component 32 now_date 0 |
| 7936 | front_id = get g_m 11 |
| 7937 | nl = ulong 0 |
| 7938 | habits = ulong 0 |
| 7939 | d = uhopfile x_habits |
| 7940 | if ne d 0 |
| 7941 | habits = umsg ucl c_json usl m_json_object d 0 0 |
| 7942 | end |
| 7943 | if uiskind habits 8 |
| 7944 | nl = umsg habits usl m_count 0 0 0 |
| 7945 | if gt nl 4096 |
| 7946 | nl = 4096 |
| 7947 | end |
| 7948 | end |
| 7949 | upn tb 0 hour |
| 7950 | front_number = ulong 0 |
| 7951 | if ne front_id 0 |
| 7952 | front_number = 1 |
| 7953 | end |
| 7954 | upn tb 1 front_number |
| 7955 | upn tb 2 na |
| 7956 | upn tb 3 nl |
| 7957 | sat = usl m_at |
| 7958 | for j ulong nl bound 4096 |
| 7959 | o = add 4 mul j 3 |
| 7960 | launch = umsg habits sat j 0 0 |
| 7961 | here = ulong 0 |
| 7962 | hr = ulong 0 |
| 7963 | place = na |
| 7964 | if uiskind launch 7 |
| 7965 | from = ukeyed launch k_from |
| 7966 | if and ne front_id 0 uiskind from 9 |
| 7967 | if eq and umsg from usl m_equal_string front_id 0 0 255 1 |
| 7968 | here = 1 |
| 7969 | end |
| 7970 | end |
| 7971 | hr = ujsonint ukeyed launch k_hour |
| 7972 | opened = ukeyed launch k_app |
| 7973 | if uiskind opened 9 |
| 7974 | place = uplaceof opened |
| 7975 | end |
| 7976 | end |
| 7977 | upn tb o here |
| 7978 | if ge hr 9223372036854775808 |
| 7979 | upb tb add o 1 sub k_b add xor hr 18446744073709551615 1 |
| 7980 | else |
| 7981 | if gt hr 1000000 |
| 7982 | hr = 1000000 |
| 7983 | end |
| 7984 | upn tb add o 1 hr |
| 7985 | end |
| 7986 | if lt place na |
| 7987 | upn tb add o 2 place |
| 7988 | else |
| 7989 | upb tb add o 2 sub k_b 1 |
| 7990 | end |
| 7991 | end |
| 7992 | k1 = swlifts tb add 4 mul nl 3 ob |
| 7993 | if ne k1 0 |
| 7994 | for k ulong na bound 2048 |
| 7995 | put g_lf k sub uog ob add 1 mul k 2 k_b |
| 7996 | put g_lh k sub uog ob add 2 mul k 2 k_b |
| 7997 | end |
| 7998 | end |
| 7999 | note how much each app is used |
| 8000 | recents = ulong 0 |
| 8001 | d = uhopfile x_recents |
| 8002 | if ne d 0 |
| 8003 | recents = umsg ucl c_json usl m_json_object d 0 0 |
| 8004 | end |
| 8005 | if uiskind recents 7 |
| 8006 | x = umsg ucl c_date usl m_reference_now 0 0 0 |
| 8007 | now_bits = ugr 64 |
| 8008 | for k ulong na bound 2048 |
| 8009 | p = uptxt 0 x_mac_key |
| 8010 | p = uapppath p k |
| 8011 | put g_nm p 0 |
| 8012 | key = unsb |
| 8013 | e = umsg recents usl m_object_for_key key 0 0 |
| 8014 | if uiskind e 7 |
| 8015 | cnt = ujsonint ukeyed e k_count |
| 8016 | last = ukeyed e k_last |
| 8017 | if and uisnumber last lt cnt 1000000000 |
| 8018 | x = umsg last usl m_double_value 0 0 0 |
| 8019 | put g_us k uboost cnt ugr 64 now_bits |
| 8020 | end |
| 8021 | end |
| 8022 | end |
| 8023 | end |
| 8024 | note what is running (apps a person sees: the regular ones) |
| 8025 | ws = umsg ucl c_ws usl m_shws 0 0 0 |
| 8026 | running = umsg ws usl m_running_apps 0 0 0 |
| 8027 | if ne running 0 |
| 8028 | nr = umsg running usl m_count 0 0 0 |
| 8029 | for j ulong nr bound 4096 |
| 8030 | r = umsg running sat j 0 0 |
| 8031 | if eq umsg r usl m_policy_of 0 0 0 0 |
| 8032 | url = umsg r usl m_bundle_url 0 0 0 |
| 8033 | if ne url 0 |
| 8034 | k = uplaceof umsg url usl m_path 0 0 0 |
| 8035 | if lt k na |
| 8036 | put g_rn k 1 |
| 8037 | end |
| 8038 | end |
| 8039 | end |
| 8040 | end |
| 8041 | end |
| 8042 | note the app in front before: the newest remembered one that is not in front now |
| 8043 | front_place = get g_m 13 |
| 8044 | previous = ulong 0 |
| 8045 | for i ulong 12 |
| 8046 | if and and eq previous 0 ne get g_fr i 0 ne get g_fr i front_place |
| 8047 | previous = get g_fr i |
| 8048 | end |
| 8049 | end |
| 8050 | put g_n 32 previous |
| 8051 | note the request of fn swsuggest: what was copied, then six numbers an app |
| 8052 | for i ulong 6 |
| 8053 | upn tb i 0 |
| 8054 | end |
| 8055 | ncl = get g_n 24 |
| 8056 | nrest = ulong 0 |
| 8057 | put g_n 25 0 |
| 8058 | put g_n 26 0 |
| 8059 | if gt ncl 0 |
| 8060 | upn tb 0 1 |
| 8061 | newest = umsg get g_m 14 get g_m 16 0 0 0 |
| 8062 | age = ulong 0 |
| 8063 | if uiskind newest 7 |
| 8064 | moment = ukeyed newest k_date |
| 8065 | if uisnumber moment |
| 8066 | x = umsg moment usl m_double_value 0 0 0 |
| 8067 | then_bits = ugr 64 |
| 8068 | x = umsg ucl c_date usl m_reference_now 0 0 0 |
| 8069 | gap = sub bitcast f64 ugr 64 bitcast f64 then_bits |
| 8070 | if gt gap 0.0f64 |
| 8071 | age = 1000000000 |
| 8072 | if lt gap 1000000000.0f64 |
| 8073 | age = ulong gap |
| 8074 | end |
| 8075 | end |
| 8076 | end |
| 8077 | words = ukeyed newest k_text |
| 8078 | if uiskind words 9 |
| 8079 | wb = umsg words get g_o 5 0 0 0 |
| 8080 | if ne wb 0 |
| 8081 | upr 0 wb |
| 8082 | wn = ucall 7 |
| 8083 | if and ge wn 4 le wn 255 |
| 8084 | upr 0 ulong libptr g_ca 0 wn |
| 8085 | upr 8 wb |
| 8086 | upr 16 wn |
| 8087 | x = ucall 8 |
| 8088 | if 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 |
| 8089 | put g_n 25 wn |
| 8090 | uclipaddr 1 |
| 8091 | udecide |
| 8092 | put g_n 26 get g_n 10 |
| 8093 | uclipaddr 0 |
| 8094 | end |
| 8095 | end |
| 8096 | end |
| 8097 | end |
| 8098 | end |
| 8099 | upn tb 1 age |
| 8100 | if ne get g_n 26 0 |
| 8101 | upn tb 2 1 |
| 8102 | end |
| 8103 | upn tb 3 ufrontbrowser |
| 8104 | for pos ulong ncl bound 1024 |
| 8105 | i = get g_ci pos |
| 8106 | if and ne i 0 lt nrest 20 |
| 8107 | put g_cr nrest i |
| 8108 | nrest = add nrest 1 |
| 8109 | end |
| 8110 | end |
| 8111 | upn tb 4 nrest |
| 8112 | end |
| 8113 | put g_n 27 nrest |
| 8114 | upn tb 6 na |
| 8115 | for pos ulong na bound 2048 |
| 8116 | k = get g_so pos |
| 8117 | o = add 7 mul pos 6 |
| 8118 | if eq add k 1 front_place |
| 8119 | for i ulong 6 |
| 8120 | upn tb add o i 0 |
| 8121 | end |
| 8122 | else |
| 8123 | upn tb o get g_lf k |
| 8124 | upn tb add o 1 get g_lh k |
| 8125 | upn tb add o 2 get g_us k |
| 8126 | upn tb add o 3 ulong get g_rn k |
| 8127 | was_before = ulong 0 |
| 8128 | if eq add k 1 previous |
| 8129 | was_before = 1 |
| 8130 | end |
| 8131 | upn tb add o 4 was_before |
| 8132 | lately = ulong 0 |
| 8133 | for i ulong 5 |
| 8134 | if eq get g_fr i add k 1 |
| 8135 | lately = sub 10 mul 2 i |
| 8136 | end |
| 8137 | end |
| 8138 | upn tb add o 5 lately |
| 8139 | end |
| 8140 | end |
| 8141 | k2 = swsuggest tb add 7 mul na 6 ob |
| 8142 | h = ulong 0 |
| 8143 | if ne k2 0 |
| 8144 | rws = sub uog ob 0 k_b |
| 8145 | for i ulong rws bound 64 |
| 8146 | knd = sub uog ob add 1 mul i 4 k_b |
| 8147 | ix = sub uog ob add 2 mul i 4 k_b |
| 8148 | if and eq knd 1 lt ix na |
| 8149 | put g_rk h 1 |
| 8150 | put g_hit h get g_so ix |
| 8151 | put g_why h uchar sub uog ob add 4 mul i 4 k_b |
| 8152 | h = add h 1 |
| 8153 | end |
| 8154 | if and eq knd 6 le ix nrest |
| 8155 | put g_rk h 6 |
| 8156 | if eq ix 0 |
| 8157 | put g_hit h 0 |
| 8158 | else |
| 8159 | put g_hit h get g_cr sub ix 1 |
| 8160 | end |
| 8161 | put g_why h uchar sub uog ob add 4 mul i 4 k_b |
| 8162 | h = add h 1 |
| 8163 | end |
| 8164 | if and eq knd 2 ne get g_n 26 0 |
| 8165 | put g_rk h 2 |
| 8166 | put g_hit h 0 |
| 8167 | put g_why h 3 |
| 8168 | h = add h 1 |
| 8169 | end |
| 8170 | end |
| 8171 | end |
| 8172 | put g_n 1 h |
| 8173 | end |
| 8174 | |
| 8175 | note ---- remembering what was opened, as Hop does (Habits.record in Sources/Smart.swift, Sources/Recents.swift) ---- |
| 8176 | note Both files are read again at that moment and written whole, all at once. A file that is there but is not |
| 8177 | note what Hop writes is left alone. While Hop itself runs it keeps its own copy and writes that over the file the |
| 8178 | note next time it remembers something, so what the panel added then is lost. |
| 8179 | note write the JSON object obj as Hop's file named t; private: only the owner may read it; 1 when it was written |
| 8180 | fn uhopwrite obj ulong t view uchar * private ulong to ulong |
| 8181 | data = umsg ucl c_json usl m_json_data obj 0 0 |
| 8182 | if eq data 0 |
| 8183 | ret 0 |
| 8184 | end |
| 8185 | s_write = usl m_write_file |
| 8186 | path = uhoppath t |
| 8187 | if eq path 0 |
| 8188 | ret 0 |
| 8189 | end |
| 8190 | ok = and umsg data s_write path 1 0 255 |
| 8191 | if and eq ok 1 eq private 1 |
| 8192 | path = uhoppath t |
| 8193 | upr 0 ulong libptr g_nm 0 1024 |
| 8194 | upr 8 384 |
| 8195 | x = ucall 16 |
| 8196 | end |
| 8197 | ret ok |
| 8198 | end |
| 8199 | |
| 8200 | note the weight of an entry of recents.json: its count of openings, halved for every three days since the last |
| 8201 | fn urecentweight e ulong now_bits ulong to ulong |
| 8202 | if not uiskind e 7 |
| 8203 | ret bitcast ulong 0.0f64 |
| 8204 | end |
| 8205 | cnt = ujsonint ukeyed e k_count |
| 8206 | if ge cnt 1000000000 |
| 8207 | cnt = 0 |
| 8208 | end |
| 8209 | last = ukeyed e k_last |
| 8210 | if not uisnumber last |
| 8211 | ret bitcast ulong 0.0f64 |
| 8212 | end |
| 8213 | x = umsg last usl m_double_value 0 0 0 |
| 8214 | last_bits = ugr 64 |
| 8215 | age = sub bitcast f64 now_bits bitcast f64 last_bits |
| 8216 | upr 64 bitcast ulong 0.5f64 |
| 8217 | upr 72 bitcast ulong div age 259200.0f64 |
| 8218 | x = ucall 14 |
| 8219 | ret bitcast ulong mul f64 cnt bitcast f64 ugr 64 |
| 8220 | end |
| 8221 | |
| 8222 | note one more opening of path (an NSString) into recents.json: its count up by one, now as the last time; over 500 |
| 8223 | note entries the one that weighs least goes |
| 8224 | fn urecent path ulong to void |
| 8225 | recents = ulong 0 |
| 8226 | d = uhopfile x_recents |
| 8227 | if ne d 0 |
| 8228 | recents = umsg ucl c_json usl m_json_object d 1 0 |
| 8229 | if not uiskind recents 7 |
| 8230 | ret |
| 8231 | end |
| 8232 | else |
| 8233 | recents = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 8234 | end |
| 8235 | prefix = uns x_mac_key |
| 8236 | key = umsg prefix usl m_append_string path 0 0 |
| 8237 | sset = usl m_set_object |
| 8238 | cnum = ucl c_number |
| 8239 | e = umsg recents usl m_object_for_key key 0 0 |
| 8240 | cnt = ulong 0 |
| 8241 | if uiskind e 7 |
| 8242 | cnt = ujsonint ukeyed e k_count |
| 8243 | if ge cnt 1000000000 |
| 8244 | cnt = 0 |
| 8245 | end |
| 8246 | else |
| 8247 | e = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 8248 | key_path = uns k_path |
| 8249 | x = umsg e sset path key_path 0 |
| 8250 | x = umsg recents sset e key 0 |
| 8251 | end |
| 8252 | num = umsg cnum usl m_number_integer add cnt 1 0 0 |
| 8253 | key_count = uns k_count |
| 8254 | x = umsg e sset num key_count 0 |
| 8255 | x = umsg ucl c_date usl m_reference_now 0 0 0 |
| 8256 | now_bits = ugr 64 |
| 8257 | s_double = usl m_number_double |
| 8258 | upr 64 now_bits |
| 8259 | last = umsg cnum s_double 0 0 0 |
| 8260 | key_last = uns k_last |
| 8261 | x = umsg e sset last key_last 0 |
| 8262 | n = umsg recents usl m_count 0 0 0 |
| 8263 | if gt n 500 |
| 8264 | keys = umsg recents usl m_all_keys 0 0 0 |
| 8265 | sat = usl m_at |
| 8266 | least = ulong 0 |
| 8267 | least_bits = ulong 0 |
| 8268 | for i ulong n bound 4096 |
| 8269 | k = umsg keys sat i 0 0 |
| 8270 | w = urecentweight umsg recents usl m_object_for_key k 0 0 now_bits |
| 8271 | if or eq least 0 lt bitcast f64 w bitcast f64 least_bits |
| 8272 | least = k |
| 8273 | least_bits = w |
| 8274 | end |
| 8275 | end |
| 8276 | if ne least 0 |
| 8277 | x = umsg recents usl m_remove_key least 0 0 |
| 8278 | end |
| 8279 | end |
| 8280 | x = uhopwrite recents x_recents 0 |
| 8281 | end |
| 8282 | |
| 8283 | note app k was opened: into recents.json, and into habits.json with the app that was in front and the hour (the |
| 8284 | note newest 400 are kept) |
| 8285 | fn urecordapp k ulong to void |
| 8286 | p = uapppath 0 k |
| 8287 | put g_nm p 0 |
| 8288 | path = unsb |
| 8289 | urecent path |
| 8290 | habits = ulong 0 |
| 8291 | d = uhopfile x_habits |
| 8292 | if ne d 0 |
| 8293 | habits = umsg ucl c_json usl m_json_object d 1 0 |
| 8294 | if not uiskind habits 8 |
| 8295 | ret |
| 8296 | end |
| 8297 | else |
| 8298 | habits = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8299 | end |
| 8300 | cal = umsg ucl c_calendar usl m_current_calendar 0 0 0 |
| 8301 | now_date = umsg ucl c_date usl m_date_now 0 0 0 |
| 8302 | hour = umsg cal usl m_component 32 now_date 0 |
| 8303 | x = umsg ucl c_date usl m_reference_now 0 0 0 |
| 8304 | now_bits = ugr 64 |
| 8305 | cnum = ucl c_number |
| 8306 | sset = usl m_set_object |
| 8307 | launch = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 8308 | key_app = uns k_app |
| 8309 | x = umsg launch sset path key_app 0 |
| 8310 | from_id = get g_m 11 |
| 8311 | if eq from_id 0 |
| 8312 | put g_nm 0 0 |
| 8313 | from_id = unsb |
| 8314 | end |
| 8315 | key_from = uns k_from |
| 8316 | x = umsg launch sset from_id key_from 0 |
| 8317 | num = umsg cnum usl m_number_integer hour 0 0 |
| 8318 | key_hour = uns k_hour |
| 8319 | x = umsg launch sset num key_hour 0 |
| 8320 | s_double = usl m_number_double |
| 8321 | upr 64 now_bits |
| 8322 | moment = umsg cnum s_double 0 0 0 |
| 8323 | key_moment = uns k_at_key |
| 8324 | x = umsg launch sset moment key_moment 0 |
| 8325 | x = umsg habits usl m_add_object launch 0 0 |
| 8326 | n = umsg habits usl m_count 0 0 0 |
| 8327 | if gt n 400 |
| 8328 | x = umsg habits usl m_remove_range 0 sub n 400 0 |
| 8329 | end |
| 8330 | x = uhopwrite habits x_habits 1 |
| 8331 | end |
| 8332 | |
| 8333 | note best file i was opened: into recents.json under its whole path |
| 8334 | fn urecordfile i ulong to void |
| 8335 | p = ufilepath 0 i |
| 8336 | if eq p 0 |
| 8337 | ret |
| 8338 | end |
| 8339 | put g_nm p 0 |
| 8340 | path = unsb |
| 8341 | urecent path |
| 8342 | end |
| 8343 | |
| 8344 | note why an offered app is offered into g_nm from byte p (nothing for a typed row); the byte after it |
| 8345 | fn uwhy p ulong r ulong to ulong |
| 8346 | w = ulong get g_why r |
| 8347 | if or ne get g_n 13 0 eq w 0 |
| 8348 | ret p |
| 8349 | end |
| 8350 | q = uptxt p x_gap |
| 8351 | if eq w 1 |
| 8352 | ret uptxt q x_why1 |
| 8353 | end |
| 8354 | if eq w 2 |
| 8355 | ret uptxt q x_why2 |
| 8356 | end |
| 8357 | if eq w 3 |
| 8358 | ret uptxt q x_why3 |
| 8359 | end |
| 8360 | if eq w 4 |
| 8361 | q = uptxt q x_why4 |
| 8362 | name = get g_m 12 |
| 8363 | if eq name 0 |
| 8364 | ret uptxt q x_here |
| 8365 | end |
| 8366 | name_bytes = umsg name get g_o 5 0 0 0 |
| 8367 | upr 0 name_bytes |
| 8368 | n = ucall 7 |
| 8369 | if gt n 200 |
| 8370 | n = 200 |
| 8371 | end |
| 8372 | upr 0 ulong libptr g_nm q n |
| 8373 | upr 8 name_bytes |
| 8374 | upr 16 n |
| 8375 | x = ucall 8 |
| 8376 | ret add q n |
| 8377 | end |
| 8378 | if eq w 5 |
| 8379 | ret uptxt q x_why5 |
| 8380 | end |
| 8381 | if eq w 6 |
| 8382 | ret uptxt q x_why6 |
| 8383 | end |
| 8384 | if eq w 7 |
| 8385 | ret uptxt q x_why7 |
| 8386 | end |
| 8387 | ret uptxt q x_why8 |
| 8388 | end |
| 8389 | |
| 8390 | note ---- building the file index, as Hop builds it (Sources/FileIndex.swift, rebuild) ---- |
| 8391 | note The program run with the one argument "index" walks the folders of Hop's settings (indexRoots; without |
| 8392 | note settings the home folder, /Applications and /System/Applications) at throttled disk priority with the walker |
| 8393 | note Hop uses (NSFileManager's, hidden things left out), and writes every path, a line each, as Hop's |
| 8394 | note file-index.bin, all at once, for the owner only. A folder with one of the names to skip, or one that is a |
| 8395 | note link, is left out with all in it; a package (an app, a document that is a folder) is one line. Three million |
| 8396 | note lines at most. It is a program of its own run beside the panel, because the panel does one thing at a time. |
| 8397 | note is the resource named key of the URL u set (a yes among its values) |
| 8398 | fn uresource u ulong sget ulong key ulong to bool |
| 8399 | for i ulong 8 |
| 8400 | put g_t8 i 0 |
| 8401 | end |
| 8402 | x = umsg u sget ulong libptr g_t8 0 8 key 0 |
| 8403 | v = uread8 |
| 8404 | if eq v 0 |
| 8405 | ret false |
| 8406 | end |
| 8407 | ret eq and umsg v usl m_bool_value 0 0 0 255 1 |
| 8408 | end |
| 8409 | |
| 8410 | fn uindexbuild to ulong |
| 8411 | upr 0 0 |
| 8412 | upr 8 0 |
| 8413 | upr 16 3 |
| 8414 | x = ucall 29 |
| 8415 | folder_roots = ulong 0 |
| 8416 | skip_names = ulong 0 |
| 8417 | d = uhopfile x_config |
| 8418 | if ne d 0 |
| 8419 | config = umsg ucl c_json usl m_json_object d 0 0 |
| 8420 | if uiskind config 7 |
| 8421 | folder_roots = ukeyed config k_roots |
| 8422 | if not uiskind folder_roots 8 |
| 8423 | folder_roots = 0 |
| 8424 | end |
| 8425 | skip_names = ukeyed config k_skip_names |
| 8426 | if not uiskind skip_names 8 |
| 8427 | skip_names = 0 |
| 8428 | end |
| 8429 | end |
| 8430 | end |
| 8431 | sadd = usl m_add_object |
| 8432 | if eq folder_roots 0 |
| 8433 | folder_roots = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8434 | x = ucall 30 |
| 8435 | home_folder = ugr 0 |
| 8436 | if ne home_folder 0 |
| 8437 | x = umsg folder_roots sadd home_folder 0 0 |
| 8438 | end |
| 8439 | x = umsg folder_roots sadd uns x_applications 0 0 |
| 8440 | x = umsg folder_roots sadd uns x_system_applications 0 0 |
| 8441 | end |
| 8442 | if eq skip_names 0 |
| 8443 | skip_names = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8444 | x = umsg skip_names sadd uns x_skipname0 0 0 |
| 8445 | x = umsg skip_names sadd uns x_skipname1 0 0 |
| 8446 | x = umsg skip_names sadd uns x_skipname2 0 0 |
| 8447 | x = umsg skip_names sadd uns x_skipname3 0 0 |
| 8448 | x = umsg skip_names sadd uns x_skipname4 0 0 |
| 8449 | x = umsg skip_names sadd uns x_skipname5 0 0 |
| 8450 | x = umsg skip_names sadd uns x_skipname6 0 0 |
| 8451 | x = umsg skip_names sadd uns x_skipname7 0 0 |
| 8452 | x = umsg skip_names sadd uns x_skipname8 0 0 |
| 8453 | x = umsg skip_names sadd uns x_skipname9 0 0 |
| 8454 | x = umsg skip_names sadd uns x_skipname10 0 0 |
| 8455 | x = umsg skip_names sadd uns x_skipname11 0 0 |
| 8456 | x = umsg skip_names sadd uns x_skipname12 0 0 |
| 8457 | x = umsg skip_names sadd uns x_skipname13 0 0 |
| 8458 | x = umsg skip_names sadd uns x_skipname14 0 0 |
| 8459 | x = umsg skip_names sadd uns x_skipname15 0 0 |
| 8460 | end |
| 8461 | skip_set = umsg ucl c_set usl m_set_with_array skip_names 0 0 |
| 8462 | key_dir = uconst s_key_directory |
| 8463 | key_pkg = uconst s_key_package |
| 8464 | key_link = uconst s_key_link |
| 8465 | wanted_keys = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8466 | x = umsg wanted_keys sadd key_dir 0 0 |
| 8467 | x = umsg wanted_keys sadd key_pkg 0 0 |
| 8468 | x = umsg wanted_keys sadd key_link 0 0 |
| 8469 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 8470 | index_lines = umsg ucl c_mutable_data usl m_data 0 0 0 |
| 8471 | sappend = usl m_append_bytes |
| 8472 | snext = usl m_next_object |
| 8473 | sget = usl m_get_resource |
| 8474 | spath = usl m_path |
| 8475 | slast = usl m_last_component |
| 8476 | sskip = usl m_skip_descendants |
| 8477 | shas = usl m_contains_object |
| 8478 | s_enum = usl m_enumerator |
| 8479 | sat = usl m_at |
| 8480 | c_p = ucl c_pool |
| 8481 | salloc = usl m_alloc |
| 8482 | sinit = usl m_init |
| 8483 | sdrain = usl m_drain |
| 8484 | sfurl = usl m_furl |
| 8485 | c_u = ucl c_url |
| 8486 | put g_nl 0 10 |
| 8487 | listed = ulong 0 |
| 8488 | nroots = umsg folder_roots usl m_count 0 0 0 |
| 8489 | for ri ulong nroots bound 64 |
| 8490 | folder_root = umsg folder_roots sat ri 0 0 |
| 8491 | if uiskind folder_root 9 |
| 8492 | folder_url = umsg c_u sfurl folder_root 0 0 |
| 8493 | upr 40 0 |
| 8494 | en = umsg manager s_enum folder_url wanted_keys 4 |
| 8495 | if ne en 0 |
| 8496 | walking = true |
| 8497 | for portion ulong 3001 bound 3001 |
| 8498 | if walking |
| 8499 | walk_pool = umsg umsg c_p salloc 0 0 0 sinit 0 0 0 |
| 8500 | for turn ulong 1000 bound 1000 |
| 8501 | if and walking lt listed 3000000 |
| 8502 | u = umsg en snext 0 0 0 |
| 8503 | if eq u 0 |
| 8504 | walking = false |
| 8505 | else |
| 8506 | list_it = true |
| 8507 | if uresource u sget key_dir |
| 8508 | item_name = umsg u slast 0 0 0 |
| 8509 | skip_it = eq and umsg skip_set shas item_name 0 0 255 1 |
| 8510 | if not skip_it |
| 8511 | skip_it = uresource u sget key_link |
| 8512 | end |
| 8513 | if skip_it |
| 8514 | x = umsg en sskip 0 0 0 |
| 8515 | list_it = false |
| 8516 | else |
| 8517 | if uresource u sget key_pkg |
| 8518 | x = umsg en sskip 0 0 0 |
| 8519 | end |
| 8520 | end |
| 8521 | end |
| 8522 | if list_it |
| 8523 | path_bytes = umsg umsg u spath 0 0 0 get g_o 5 0 0 0 |
| 8524 | if ne path_bytes 0 |
| 8525 | upr 0 path_bytes |
| 8526 | pn = ucall 7 |
| 8527 | x = umsg index_lines sappend path_bytes pn 0 |
| 8528 | x = umsg index_lines sappend ulong libptr g_nl 0 1 1 0 |
| 8529 | listed = add listed 1 |
| 8530 | end |
| 8531 | end |
| 8532 | end |
| 8533 | end |
| 8534 | end |
| 8535 | x = umsg walk_pool sdrain 0 0 0 |
| 8536 | if ge listed 3000000 |
| 8537 | walking = false |
| 8538 | end |
| 8539 | end |
| 8540 | end |
| 8541 | end |
| 8542 | end |
| 8543 | end |
| 8544 | s_write = usl m_write_file |
| 8545 | path = uhoppath x_index |
| 8546 | if eq path 0 |
| 8547 | ret 1 |
| 8548 | end |
| 8549 | ok = and umsg index_lines s_write path 1 0 255 |
| 8550 | path = uhoppath x_index |
| 8551 | upr 0 ulong libptr g_nm 0 1024 |
| 8552 | upr 8 384 |
| 8553 | x = ucall 16 |
| 8554 | p = uptxt 0 x_indexed |
| 8555 | p = upnum p listed |
| 8556 | p = uptxt p x_items |
| 8557 | put g_nm p 10 |
| 8558 | upr 0 1 |
| 8559 | upr 8 ulong libptr g_nm 0 1024 |
| 8560 | upr 16 add p 1 |
| 8561 | x = ucall 3 |
| 8562 | if eq ok 1 |
| 8563 | ret 0 |
| 8564 | end |
| 8565 | ret 1 |
| 8566 | end |
| 8567 | |
| 8568 | note when the program was run with the one argument "index": build the index (0 done, 1 not written); else 2 |
| 8569 | fn uindexmode to ulong |
| 8570 | run_arguments = umsg umsg ucl c_process_info usl m_process_info 0 0 0 usl m_arguments 0 0 0 |
| 8571 | if eq run_arguments 0 |
| 8572 | ret 2 |
| 8573 | end |
| 8574 | if le umsg run_arguments usl m_count 0 0 0 1 |
| 8575 | ret 2 |
| 8576 | end |
| 8577 | first_argument = umsg run_arguments get g_m 16 1 0 0 |
| 8578 | if ne and umsg first_argument usl m_equal_string uns x_index_word 0 0 255 1 |
| 8579 | ret 2 |
| 8580 | end |
| 8581 | ret uindexbuild |
| 8582 | end |
| 8583 | |
| 8584 | note start building the file index in a program of its own (this one, run with "index"); one at a time |
| 8585 | fn uindexstart to void |
| 8586 | if ne get g_m 23 0 |
| 8587 | ret |
| 8588 | end |
| 8589 | exe = umsg umsg ucl c_bundle usl m_main_bundle 0 0 0 usl m_executable_path 0 0 0 |
| 8590 | if eq exe 0 |
| 8591 | ret |
| 8592 | end |
| 8593 | task = umsg ucl c_task usl m_alloc 0 0 0 |
| 8594 | task = umsg task usl m_init 0 0 0 |
| 8595 | x = umsg task usl m_set_launch exe 0 0 |
| 8596 | arguments = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8597 | x = umsg arguments usl m_add_object uns x_index_word 0 0 |
| 8598 | x = umsg task usl m_set_arguments arguments 0 0 |
| 8599 | quiet = umsg ucl c_file_handle usl m_null_device 0 0 0 |
| 8600 | x = umsg task usl m_set_output quiet 0 0 |
| 8601 | x = umsg task usl m_launch 0 0 0 |
| 8602 | put g_m 23 umsg task usl m_retain 0 0 0 |
| 8603 | ushowst |
| 8604 | end |
| 8605 | |
| 8606 | note is the file index missing, or older than half an hour (Hop builds it anew that often) |
| 8607 | fn uindexstale to bool |
| 8608 | path = uhoppath x_index |
| 8609 | if eq path 0 |
| 8610 | ret false |
| 8611 | end |
| 8612 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 8613 | attributes = umsg manager usl m_attributes_of path 0 0 |
| 8614 | if eq attributes 0 |
| 8615 | ret true |
| 8616 | end |
| 8617 | changed = umsg attributes usl m_object_for_key uconst s_modified 0 0 |
| 8618 | if eq changed 0 |
| 8619 | ret true |
| 8620 | end |
| 8621 | x = umsg changed usl m_since_now 0 0 0 |
| 8622 | age = sub 0.0f64 bitcast f64 ugr 64 |
| 8623 | ret gt age 1800.0f64 |
| 8624 | end |
| 8625 | |
| 8626 | note twice a second: when the program building the index has ended, read the new index and show the list anew; |
| 8627 | note every half hour, and when the panel starts, build it anew when it is old and Hop is not there to do it |
| 8628 | fn uindextick to void |
| 8629 | if ne get g_m 23 0 |
| 8630 | if eq and umsg get g_m 23 usl m_is_running 0 0 0 255 0 |
| 8631 | x = umsg get g_m 23 usl m_release 0 0 0 |
| 8632 | put g_m 23 0 |
| 8633 | uloadindex |
| 8634 | if ne get g_n 13 0 |
| 8635 | unarrow |
| 8636 | x = umsg get g_o 1 get g_o 7 0 0 0 |
| 8637 | end |
| 8638 | ushowst |
| 8639 | end |
| 8640 | ret |
| 8641 | end |
| 8642 | put g_n 38 add get g_n 38 1 |
| 8643 | if ge get g_n 38 3600 |
| 8644 | put g_n 38 0 |
| 8645 | if and not uhoprunning uindexstale |
| 8646 | uindexstart |
| 8647 | end |
| 8648 | if not uhoprunning |
| 8649 | uremoterefreshall |
| 8650 | end |
| 8651 | end |
| 8652 | end |
| 8653 | |
| 8654 | note ---- the agent: the person's coding agent, run on this Mac for the typed text (Sources/Model.swift, runAgent) ---- |
| 8655 | note Hop's settings name the agents (each a name and a command, "{prompt}" standing for the request) and the one |
| 8656 | note to use. Only that one is ever run, and only when it is installed: the look goes through the login shell |
| 8657 | note with the usual tool folders added, as Hop's does. The command runs through the same wrapper as in Hop, in |
| 8658 | note the folder of the settings; what it prints is shown as it comes (the lines of Claude Code's stream are read |
| 8659 | note for their text and the tools they name). Hop's standing instructions ride along. Not here yet: what the |
| 8660 | note knowledge base knows, and the count of tokens. |
| 8661 | note an NSString of text t with every "~" turned into a double quote |
| 8662 | fn uquoted t view uchar * to ulong |
| 8663 | put g_nm 0 34 |
| 8664 | put g_nm 1 0 |
| 8665 | quote_mark = unsb |
| 8666 | plain = uns t |
| 8667 | ret umsg plain usl m_replace uns x_tilde quote_mark 0 |
| 8668 | end |
| 8669 | |
| 8670 | note the words of text t (separated by "|") as an array |
| 8671 | fn uwords t view uchar * to ulong |
| 8672 | whole = uns t |
| 8673 | ret umsg whole usl m_components uns x_bar 0 0 |
| 8674 | end |
| 8675 | |
| 8676 | note an agent: a name and a command |
| 8677 | fn uengine name ulong command ulong to ulong |
| 8678 | e = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 8679 | sset = usl m_set_object |
| 8680 | x = umsg e sset name uns k_name 0 |
| 8681 | x = umsg e sset command uns k_command 0 |
| 8682 | ret e |
| 8683 | end |
| 8684 | |
| 8685 | note is the JSON value v a yes: JSON's own true and nothing else, as Hop reads its settings (a null, a number, |
| 8686 | note a text, a list or a group is not) |
| 8687 | fn uyes v ulong to bool |
| 8688 | if eq v 0 |
| 8689 | ret false |
| 8690 | end |
| 8691 | ret eq v uconst s_cf_true |
| 8692 | end |
| 8693 | |
| 8694 | note the agents Hop has out of the box (none of them switches a tool's own approval prompts or sandbox off) |
| 8695 | fn uenginedefaults to ulong |
| 8696 | all_engines = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8697 | sadd = usl m_add_object |
| 8698 | x = umsg all_engines sadd uengine uns x_engine0 uwords x_engine0_command 0 0 |
| 8699 | x = umsg all_engines sadd uengine uns x_engine1 uwords x_engine1_command 0 0 |
| 8700 | x = umsg all_engines sadd uengine uns x_engine2 uwords x_engine2_command 0 0 |
| 8701 | x = umsg all_engines sadd uengine uns x_engine3 uwords x_engine3_command 0 0 |
| 8702 | x = umsg all_engines sadd uengine uns x_engine4 uwords x_engine4_command 0 0 |
| 8703 | x = umsg all_engines sadd uengine uns x_engine5 uwords x_engine5_command 0 0 |
| 8704 | x = umsg all_engines sadd uengine uns x_engine6 uwords x_engine6_command 0 0 |
| 8705 | ret all_engines |
| 8706 | end |
| 8707 | |
| 8708 | note the zero-ended bytes at src into g_nm from byte p (900 bytes at most in all); the byte after them |
| 8709 | fn ufetchat p ulong src ulong to ulong |
| 8710 | if or eq src 0 ge p 900 |
| 8711 | ret p |
| 8712 | end |
| 8713 | upr 0 src |
| 8714 | n = ucall 7 |
| 8715 | if gt add p n 900 |
| 8716 | n = sub 900 p |
| 8717 | end |
| 8718 | if eq n 0 |
| 8719 | ret p |
| 8720 | end |
| 8721 | upr 0 ulong libptr g_nm p n |
| 8722 | upr 8 src |
| 8723 | upr 16 n |
| 8724 | x = ucall 8 |
| 8725 | ret add p n |
| 8726 | end |
| 8727 | |
| 8728 | note what Hop's settings say about the agent (config: the settings, or 0 without any). A saved command that is |
| 8729 | note exactly one of the old built-in ones that switched approval prompts or the sandbox off is brought to |
| 8730 | note today's built-in one, unless keepAgentFlags says the commands are wanted as written (as Hop does on reading) |
| 8731 | fn uagentconfig config ulong to void |
| 8732 | engines = ulong 0 |
| 8733 | chosen = ulong 0 |
| 8734 | legacy = ulong 0 |
| 8735 | folder = ulong 0 |
| 8736 | keep_flags = false |
| 8737 | put g_n 42 0 |
| 8738 | put g_n 44 0 |
| 8739 | put g_n 45 0 |
| 8740 | if ne config 0 |
| 8741 | engines = ukeyed config k_engines |
| 8742 | chosen = ukeyed config k_engine |
| 8743 | legacy = ukeyed config k_agent_command |
| 8744 | folder = ukeyed config k_agent_folder |
| 8745 | keep_flags = uyes ukeyed config k_keep_flags |
| 8746 | if uyes ukeyed config k_enter_agent |
| 8747 | put g_n 42 1 |
| 8748 | end |
| 8749 | if uyes ukeyed config k_agent_confirmed |
| 8750 | put g_n 44 1 |
| 8751 | end |
| 8752 | end |
| 8753 | defaults = uenginedefaults |
| 8754 | sat = usl m_at |
| 8755 | if not uiskind engines 8 |
| 8756 | engines = defaults |
| 8757 | else |
| 8758 | if not keep_flags |
| 8759 | moved = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8760 | sadd = usl m_add_object |
| 8761 | sequal = usl m_equal_string |
| 8762 | ssame = usl m_is_equal_array |
| 8763 | cnt = umsg engines usl m_count 0 0 0 |
| 8764 | for i ulong cnt bound 256 |
| 8765 | e = umsg engines sat i 0 0 |
| 8766 | if uiskind e 7 |
| 8767 | name = ukeyed e k_name |
| 8768 | command = ukeyed e k_command |
| 8769 | if and uiskind name 9 uiskind command 8 |
| 8770 | if 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 |
| 8771 | e = umsg defaults sat 1 0 0 |
| 8772 | end |
| 8773 | if 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 |
| 8774 | e = umsg defaults sat 2 0 0 |
| 8775 | end |
| 8776 | if 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 |
| 8777 | e = umsg defaults sat 3 0 0 |
| 8778 | end |
| 8779 | if 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 |
| 8780 | e = umsg defaults sat 5 0 0 |
| 8781 | end |
| 8782 | if 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 |
| 8783 | e = umsg defaults sat 6 0 0 |
| 8784 | end |
| 8785 | end |
| 8786 | end |
| 8787 | x = umsg moved sadd e 0 0 |
| 8788 | end |
| 8789 | engines = moved |
| 8790 | end |
| 8791 | end |
| 8792 | if not uiskind chosen 9 |
| 8793 | chosen = uns x_engine0 |
| 8794 | end |
| 8795 | if not uiskind legacy 8 |
| 8796 | legacy = uwords x_engine0_command |
| 8797 | end |
| 8798 | if not uiskind folder 9 |
| 8799 | x = ucall 30 |
| 8800 | folder = ugr 0 |
| 8801 | end |
| 8802 | sret = usl m_retain |
| 8803 | put g_m 28 umsg engines sret 0 0 0 |
| 8804 | put g_m 29 umsg chosen sret 0 0 0 |
| 8805 | put g_m 30 umsg folder sret 0 0 0 |
| 8806 | put g_m 31 umsg legacy sret 0 0 0 |
| 8807 | if ne config 0 |
| 8808 | put g_m 34 umsg config sret 0 0 0 |
| 8809 | end |
| 8810 | note for a check (HOPAGENTS): say each agent's command as it would be run |
| 8811 | if eq get g_n 14 0 |
| 8812 | n = ucs x_env_agents |
| 8813 | upr 0 ulong libptr g_nm 0 1024 |
| 8814 | if ne ucall 9 0 |
| 8815 | cnt = umsg engines usl m_count 0 0 0 |
| 8816 | sjoin = usl m_joined |
| 8817 | for i ulong cnt bound 256 |
| 8818 | e = umsg engines sat i 0 0 |
| 8819 | if uiskind e 7 |
| 8820 | name = ukeyed e k_name |
| 8821 | command = ukeyed e k_command |
| 8822 | if and uiskind name 9 uiskind command 8 |
| 8823 | said_words = umsg command sjoin uns x_space 0 0 |
| 8824 | name_bytes = umsg name get g_o 5 0 0 0 |
| 8825 | word_bytes = umsg said_words get g_o 5 0 0 0 |
| 8826 | p = uptxt 0 x_engine_word |
| 8827 | p2 = ufetchat p name_bytes |
| 8828 | p2 = uptxt p2 x_colon |
| 8829 | p2 = ufetchat p2 word_bytes |
| 8830 | put g_nm p2 10 |
| 8831 | upr 0 1 |
| 8832 | upr 8 ulong libptr g_nm 0 1024 |
| 8833 | upr 16 add p2 1 |
| 8834 | x = ucall 3 |
| 8835 | end |
| 8836 | end |
| 8837 | end |
| 8838 | end |
| 8839 | end |
| 8840 | end |
| 8841 | |
| 8842 | note s between single quotes for a shell |
| 8843 | fn ushellquote s ulong to ulong |
| 8844 | put g_nm 0 39 |
| 8845 | put g_nm 1 0 |
| 8846 | tick = unsb |
| 8847 | put g_nm 0 39 |
| 8848 | put g_nm 1 92 |
| 8849 | put g_nm 2 39 |
| 8850 | put g_nm 3 39 |
| 8851 | put g_nm 4 0 |
| 8852 | escaped = unsb |
| 8853 | inner = umsg s usl m_replace tick escaped 0 |
| 8854 | sappend = usl m_append_string |
| 8855 | ret umsg umsg tick sappend inner 0 0 sappend tick 0 0 |
| 8856 | end |
| 8857 | |
| 8858 | note the folders tools are commonly installed in, joined by ":" (searched after the login shell's own PATH) |
| 8859 | fn uextrapath to ulong |
| 8860 | x = ucall 30 |
| 8861 | home_folder = ugr 0 |
| 8862 | if eq home_folder 0 |
| 8863 | ret uns x_colon_only |
| 8864 | end |
| 8865 | dirs = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8866 | sadd = usl m_add_object |
| 8867 | sappend = usl m_append_string |
| 8868 | slash = uns x_slash_text |
| 8869 | x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path0 0 0 0 0 |
| 8870 | x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path1 0 0 0 0 |
| 8871 | x = umsg dirs sadd uns x_path2 0 0 |
| 8872 | x = umsg dirs sadd uns x_path3 0 0 |
| 8873 | x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path4 0 0 0 0 |
| 8874 | x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path5 0 0 0 0 |
| 8875 | x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path6 0 0 0 0 |
| 8876 | x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path7 0 0 0 0 |
| 8877 | x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path8 0 0 0 0 |
| 8878 | x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path9 0 0 0 0 |
| 8879 | x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path10 0 0 0 0 |
| 8880 | x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path11 0 0 0 0 |
| 8881 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 8882 | sat = usl m_at |
| 8883 | for which ulong 2 |
| 8884 | versions_root = umsg home_folder sappend uns x_nvm 0 0 |
| 8885 | if eq which 1 |
| 8886 | versions_root = umsg home_folder sappend uns x_herd 0 0 |
| 8887 | end |
| 8888 | found_versions = umsg manager usl m_contents_of_dir versions_root 0 0 |
| 8889 | if ne found_versions 0 |
| 8890 | ordered = umsg found_versions usl m_sorted usl m_standard_compare 0 0 |
| 8891 | cnt = umsg ordered usl m_count 0 0 0 |
| 8892 | for back ulong cnt bound 512 |
| 8893 | v = umsg ordered sat sub sub cnt 1 back 0 0 |
| 8894 | one_dir = umsg umsg umsg versions_root sappend slash 0 0 sappend v 0 0 sappend uns x_slash_bin 0 0 |
| 8895 | if eq and umsg one_dir usl m_contains uns x_colon_only 0 0 255 0 |
| 8896 | x = umsg dirs sadd one_dir 0 0 |
| 8897 | end |
| 8898 | end |
| 8899 | end |
| 8900 | end |
| 8901 | ret umsg dirs usl m_joined uns x_colon_only 0 0 |
| 8902 | end |
| 8903 | |
| 8904 | note a program run through the login shell, as Hop runs every command: zsh -lc with the wrapper that adds the |
| 8905 | note tool folders, then the words of argv; TERM is dumb and colours are off. Not started yet |
| 8906 | fn ushellrun argv ulong folder ulong to ulong |
| 8907 | task = umsg ucl c_task usl m_alloc 0 0 0 |
| 8908 | task = umsg task usl m_init 0 0 0 |
| 8909 | x = umsg task usl m_set_launch uns x_zsh 0 0 |
| 8910 | arguments = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8911 | sadd = usl m_add_object |
| 8912 | x = umsg arguments sadd uns x_dash_lc 0 0 |
| 8913 | x = umsg arguments sadd uquoted x_wrapper 0 0 |
| 8914 | x = umsg arguments sadd uns x_hop_word 0 0 |
| 8915 | cnt = umsg argv usl m_count 0 0 0 |
| 8916 | sat = usl m_at |
| 8917 | for i ulong cnt bound 256 |
| 8918 | x = umsg arguments sadd umsg argv sat i 0 0 0 0 |
| 8919 | end |
| 8920 | x = umsg task usl m_set_arguments arguments 0 0 |
| 8921 | if ne folder 0 |
| 8922 | x = umsg task usl m_set_cwd folder 0 0 |
| 8923 | end |
| 8924 | around = 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 |
| 8925 | sset = usl m_set_object |
| 8926 | x = umsg around sset uns x_dumb uns x_term 0 |
| 8927 | x = umsg around sset uns x_one uns x_no_color 0 |
| 8928 | x = umsg around sset uextrapath uns x_extra_path 0 |
| 8929 | x = umsg task usl m_set_environment around 0 0 |
| 8930 | ret task |
| 8931 | end |
| 8932 | |
| 8933 | note the agents of the settings that are installed on this Mac, looked for once (the login shell is asked for |
| 8934 | note each tool); when none of them is and the older single command's tool is, that one, as "Custom command" |
| 8935 | fn uagentsfound to ulong |
| 8936 | if eq get g_n 45 1 |
| 8937 | ret get g_m 35 |
| 8938 | end |
| 8939 | engines = get g_m 28 |
| 8940 | sat = usl m_at |
| 8941 | sappend = usl m_append_string |
| 8942 | put g_nm 0 10 |
| 8943 | put g_nm 1 0 |
| 8944 | line_end = unsb |
| 8945 | script = umsg ucl c_mutable_string usl m_string 0 0 0 |
| 8946 | smore = usl m_append |
| 8947 | cnt = umsg engines usl m_count 0 0 0 |
| 8948 | for i ulong cnt bound 256 |
| 8949 | e = umsg engines sat i 0 0 |
| 8950 | if uiskind e 7 |
| 8951 | name = ukeyed e k_name |
| 8952 | command = ukeyed e k_command |
| 8953 | if and uiskind name 9 uiskind command 8 |
| 8954 | if gt umsg command usl m_count 0 0 0 0 |
| 8955 | tool = umsg command sat 0 0 0 |
| 8956 | if uiskind tool 9 |
| 8957 | x = umsg script smore uns x_probe_a 0 0 |
| 8958 | x = umsg script smore ushellquote tool 0 0 |
| 8959 | x = umsg script smore uns x_probe_b 0 0 |
| 8960 | x = umsg script smore ushellquote name 0 0 |
| 8961 | x = umsg script smore line_end 0 0 |
| 8962 | end |
| 8963 | end |
| 8964 | end |
| 8965 | end |
| 8966 | end |
| 8967 | legacy = get g_m 31 |
| 8968 | if gt umsg legacy usl m_count 0 0 0 0 |
| 8969 | tool = umsg legacy sat 0 0 0 |
| 8970 | if uiskind tool 9 |
| 8971 | if gt umsg tool usl m_length 0 0 0 0 |
| 8972 | x = umsg script smore uns x_probe_a 0 0 |
| 8973 | x = umsg script smore ushellquote tool 0 0 |
| 8974 | x = umsg script smore uns x_probe_b 0 0 |
| 8975 | x = umsg script smore uns x_legacy_mark 0 0 |
| 8976 | x = umsg script smore line_end 0 0 |
| 8977 | end |
| 8978 | end |
| 8979 | end |
| 8980 | x = umsg script smore uns x_true_word 0 0 |
| 8981 | argv = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8982 | sadd = usl m_add_object |
| 8983 | x = umsg argv sadd uns x_sh 0 0 |
| 8984 | x = umsg argv sadd uns x_dash_c 0 0 |
| 8985 | x = umsg argv sadd script 0 0 |
| 8986 | task = ushellrun argv 0 |
| 8987 | tube = umsg ucl c_pipe usl m_pipe 0 0 0 |
| 8988 | quiet = umsg ucl c_file_handle usl m_null_device 0 0 0 |
| 8989 | x = umsg task usl m_set_output tube 0 0 |
| 8990 | x = umsg task usl m_set_error quiet 0 0 |
| 8991 | x = umsg task usl m_set_input quiet 0 0 |
| 8992 | x = umsg task usl m_launch 0 0 0 |
| 8993 | d = umsg umsg tube usl m_reading 0 0 0 usl m_read_end 0 0 0 |
| 8994 | x = umsg task usl m_wait 0 0 0 |
| 8995 | found = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 8996 | if ne d 0 |
| 8997 | said = umsg ucl c_str usl m_alloc 0 0 0 |
| 8998 | said = umsg said usl m_init_data_encoding d 4 0 |
| 8999 | if ne said 0 |
| 9000 | names_said = umsg said usl m_components line_end 0 0 |
| 9001 | shas = usl m_contains_object |
| 9002 | for i ulong cnt bound 256 |
| 9003 | e = umsg engines sat i 0 0 |
| 9004 | if uiskind e 7 |
| 9005 | name = ukeyed e k_name |
| 9006 | if uiskind name 9 |
| 9007 | if eq and umsg names_said shas name 0 0 255 1 |
| 9008 | x = umsg found sadd e 0 0 |
| 9009 | end |
| 9010 | end |
| 9011 | end |
| 9012 | end |
| 9013 | if 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 |
| 9014 | x = umsg found sadd uengine uns x_custom_command legacy 0 0 |
| 9015 | end |
| 9016 | end |
| 9017 | end |
| 9018 | put g_m 35 umsg found usl m_retain 0 0 0 |
| 9019 | put g_n 45 1 |
| 9020 | ret found |
| 9021 | end |
| 9022 | |
| 9023 | note the agent to run: the one the settings name, when it is installed; never another in its place |
| 9024 | fn uagentpicked to ulong |
| 9025 | found = uagentsfound |
| 9026 | cnt = umsg found usl m_count 0 0 0 |
| 9027 | sat = usl m_at |
| 9028 | sequal = usl m_equal_string |
| 9029 | for pass_no ulong 2 |
| 9030 | want = get g_m 29 |
| 9031 | if eq pass_no 1 |
| 9032 | want = uns x_custom_command |
| 9033 | end |
| 9034 | for i ulong cnt bound 256 |
| 9035 | e = umsg found sat i 0 0 |
| 9036 | if eq and umsg ukeyed e k_name sequal want 0 0 255 1 |
| 9037 | ret e |
| 9038 | end |
| 9039 | end |
| 9040 | end |
| 9041 | ret 0 |
| 9042 | end |
| 9043 | |
| 9044 | note why nothing was run, in plain words |
| 9045 | fn uagentwhy to ulong |
| 9046 | found = uagentsfound |
| 9047 | sappend = usl m_append_string |
| 9048 | sat = usl m_at |
| 9049 | if eq umsg found usl m_count 0 0 0 0 |
| 9050 | engines = get g_m 28 |
| 9051 | cnt = umsg engines usl m_count 0 0 0 |
| 9052 | if eq cnt 0 |
| 9053 | ret uns x_agent_none_b |
| 9054 | end |
| 9055 | out_text = uns x_agent_none_a |
| 9056 | for i ulong cnt bound 256 |
| 9057 | e = umsg engines sat i 0 0 |
| 9058 | if uiskind e 7 |
| 9059 | name = ukeyed e k_name |
| 9060 | command = ukeyed e k_command |
| 9061 | if and uiskind name 9 uiskind command 8 |
| 9062 | if gt i 0 |
| 9063 | out_text = umsg out_text sappend uns x_comma_space 0 0 |
| 9064 | end |
| 9065 | out_text = umsg out_text sappend name 0 0 |
| 9066 | if gt umsg command usl m_count 0 0 0 0 |
| 9067 | out_text = umsg out_text sappend uns x_paren_a 0 0 |
| 9068 | out_text = umsg out_text sappend umsg command sat 0 0 0 0 0 |
| 9069 | out_text = umsg out_text sappend uns x_paren_b 0 0 |
| 9070 | end |
| 9071 | end |
| 9072 | end |
| 9073 | end |
| 9074 | ret umsg out_text sappend uns x_period 0 0 |
| 9075 | end |
| 9076 | out_text = umsg get g_m 29 sappend uns x_agent_missing_a 0 0 |
| 9077 | cnt = umsg found usl m_count 0 0 0 |
| 9078 | for i ulong cnt bound 256 |
| 9079 | if gt i 0 |
| 9080 | out_text = umsg out_text sappend uns x_comma_space 0 0 |
| 9081 | end |
| 9082 | out_text = umsg out_text sappend ukeyed umsg found sat i 0 0 k_name 0 0 |
| 9083 | end |
| 9084 | ret umsg out_text sappend uns x_agent_missing_b 0 0 |
| 9085 | end |
| 9086 | |
| 9087 | note Hop's standing instructions for the agent (Sources/Machines.swift, agentBriefing): kept tiny on purpose |
| 9088 | fn uagentbrief to ulong |
| 9089 | sappend = usl m_append_string |
| 9090 | config = get g_m 34 |
| 9091 | owner = uns x_the_user |
| 9092 | if ne config 0 |
| 9093 | given = ukeyed config k_owner |
| 9094 | if uiskind given 9 |
| 9095 | blanks = umsg ucl c_charset usl m_whitespace 0 0 0 |
| 9096 | given = umsg given usl m_trim blanks 0 0 |
| 9097 | if gt umsg given usl m_length 0 0 0 0 |
| 9098 | owner = given |
| 9099 | end |
| 9100 | end |
| 9101 | end |
| 9102 | head = umsg umsg owner usl m_substring_to 1 0 0 usl m_uppercase 0 0 0 |
| 9103 | brief = umsg umsg head sappend umsg owner usl m_substring_from 1 0 0 0 0 sappend uns x_brief_a 0 0 |
| 9104 | if ne config 0 |
| 9105 | machines = ukeyed config k_machines |
| 9106 | if uiskind machines 8 |
| 9107 | cnt = umsg machines usl m_count 0 0 0 |
| 9108 | if gt cnt 0 |
| 9109 | sat = usl m_at |
| 9110 | hosts = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 9111 | for i ulong cnt bound 256 |
| 9112 | m = umsg machines sat i 0 0 |
| 9113 | if uiskind m 7 |
| 9114 | name = ukeyed m k_name |
| 9115 | via = ukeyed m k_ssh |
| 9116 | if and uiskind name 9 uiskind via 9 |
| 9117 | one_host = umsg umsg umsg name sappend uns x_ssh_a 0 0 sappend via 0 0 sappend uns x_ssh_b 0 0 |
| 9118 | x = umsg hosts usl m_add_object one_host 0 0 |
| 9119 | end |
| 9120 | end |
| 9121 | end |
| 9122 | brief = umsg brief sappend uns x_brief_b 0 0 |
| 9123 | brief = umsg brief sappend umsg hosts usl m_joined uns x_semi_space 0 0 0 0 |
| 9124 | brief = umsg brief sappend uns x_brief_c 0 0 |
| 9125 | end |
| 9126 | end |
| 9127 | factory = ukeyed config k_factory_url |
| 9128 | if uiskind factory 9 |
| 9129 | blanks = umsg ucl c_charset usl m_whitespace 0 0 0 |
| 9130 | if gt umsg umsg factory usl m_trim blanks 0 0 usl m_length 0 0 0 0 |
| 9131 | brief = umsg brief sappend uns x_brief_d 0 0 |
| 9132 | brief = umsg brief sappend factory 0 0 |
| 9133 | brief = umsg brief sappend uns x_period 0 0 |
| 9134 | end |
| 9135 | end |
| 9136 | end |
| 9137 | ret umsg brief sappend uns x_brief_e 0 0 |
| 9138 | end |
| 9139 | |
| 9140 | note add a line to what the agent said, and show it |
| 9141 | fn uagentsay line ulong to void |
| 9142 | if eq line 0 |
| 9143 | ret |
| 9144 | end |
| 9145 | if eq get g_n 22 0 |
| 9146 | put g_nm 0 0 |
| 9147 | no_text = unsb |
| 9148 | x = umsg get g_m 4 usl m_set_string no_text 0 0 |
| 9149 | put g_n 22 1 |
| 9150 | end |
| 9151 | sappend_text = usl m_append |
| 9152 | x = umsg get g_m 4 sappend_text line 0 0 |
| 9153 | put g_nm 0 10 |
| 9154 | put g_nm 1 0 |
| 9155 | x = umsg get g_m 4 sappend_text unsb 0 0 |
| 9156 | if eq get g_n 20 1 |
| 9157 | uanswershow |
| 9158 | end |
| 9159 | end |
| 9160 | |
| 9161 | note one line the agent printed, as Hop shows it (Sources/Runners.swift, AgentEvents): a line of Claude Code's |
| 9162 | note stream gives its text and "> " and the name of each tool it uses, and its last line the id to carry on |
| 9163 | note from (an error there is said); any other line is shown as it is. 0: nothing to show |
| 9164 | fn uagentline line ulong to ulong |
| 9165 | if eq and umsg line usl m_has_prefix uns x_brace 0 0 255 0 |
| 9166 | ret line |
| 9167 | end |
| 9168 | d = umsg line usl m_data_using 4 0 0 |
| 9169 | if eq d 0 |
| 9170 | ret line |
| 9171 | end |
| 9172 | obj = umsg ucl c_json usl m_json_object d 0 0 |
| 9173 | if not uiskind obj 7 |
| 9174 | ret line |
| 9175 | end |
| 9176 | kind = ukeyed obj k_type |
| 9177 | if not uiskind kind 9 |
| 9178 | ret 0 |
| 9179 | end |
| 9180 | sequal = usl m_equal_string |
| 9181 | sappend = usl m_append_string |
| 9182 | if eq and umsg kind sequal uns x_assistant 0 0 255 1 |
| 9183 | message = ukeyed obj k_message |
| 9184 | if not uiskind message 7 |
| 9185 | ret 0 |
| 9186 | end |
| 9187 | parts = ukeyed message k_content |
| 9188 | if not uiskind parts 8 |
| 9189 | ret 0 |
| 9190 | end |
| 9191 | put g_nm 0 10 |
| 9192 | put g_nm 1 0 |
| 9193 | line_end = unsb |
| 9194 | put g_nm 0 0 |
| 9195 | shown_text = unsb |
| 9196 | cnt = umsg parts usl m_count 0 0 0 |
| 9197 | sat = usl m_at |
| 9198 | have = ulong 0 |
| 9199 | for i ulong cnt bound 1024 |
| 9200 | part_v = umsg parts sat i 0 0 |
| 9201 | if uiskind part_v 7 |
| 9202 | part_kind = ukeyed part_v k_type |
| 9203 | piece = ulong 0 |
| 9204 | if uiskind part_kind 9 |
| 9205 | if eq and umsg part_kind sequal uns k_parts_text 0 0 255 1 |
| 9206 | piece = ukeyed part_v k_parts_text |
| 9207 | if not uiskind piece 9 |
| 9208 | piece = 0 |
| 9209 | end |
| 9210 | end |
| 9211 | if eq and umsg part_kind sequal uns k_tool_use 0 0 255 1 |
| 9212 | tool_name = ukeyed part_v k_name |
| 9213 | if not uiskind tool_name 9 |
| 9214 | tool_name = uns x_tool_word |
| 9215 | end |
| 9216 | piece = umsg uns x_tool_mark sappend tool_name 0 0 |
| 9217 | end |
| 9218 | end |
| 9219 | if ne piece 0 |
| 9220 | if eq have 1 |
| 9221 | shown_text = umsg shown_text sappend line_end 0 0 |
| 9222 | end |
| 9223 | shown_text = umsg shown_text sappend piece 0 0 |
| 9224 | have = 1 |
| 9225 | end |
| 9226 | end |
| 9227 | end |
| 9228 | if eq have 0 |
| 9229 | ret 0 |
| 9230 | end |
| 9231 | ret shown_text |
| 9232 | end |
| 9233 | if eq and umsg kind sequal uns k_result 0 0 255 1 |
| 9234 | sid = ukeyed obj k_session_id |
| 9235 | if uiskind sid 9 |
| 9236 | if ne get g_m 33 0 |
| 9237 | x = umsg get g_m 33 usl m_release 0 0 0 |
| 9238 | end |
| 9239 | put g_m 33 umsg sid usl m_retain 0 0 0 |
| 9240 | end |
| 9241 | if uyes ukeyed obj k_is_error |
| 9242 | problem = ukeyed obj k_result |
| 9243 | if not uiskind problem 9 |
| 9244 | problem = uns x_agent_error |
| 9245 | end |
| 9246 | ret umsg uns x_bang sappend problem 0 0 |
| 9247 | end |
| 9248 | end |
| 9249 | ret 0 |
| 9250 | end |
| 9251 | |
| 9252 | note output of the agent arrived (d; nothing left when it is empty): every whole line is shown |
| 9253 | fn uagentout d ulong to void |
| 9254 | buffer = get g_m 32 |
| 9255 | if eq buffer 0 |
| 9256 | ret |
| 9257 | end |
| 9258 | n = umsg d usl m_length 0 0 0 |
| 9259 | if gt n 0 |
| 9260 | x = umsg buffer usl m_append_data d 0 0 |
| 9261 | end |
| 9262 | put g_nl 0 10 |
| 9263 | newline = umsg ucl c_data usl m_data_bytes ulong libptr g_nl 0 1 1 0 |
| 9264 | srange = usl m_range_of_data |
| 9265 | ssub = usl m_subdata |
| 9266 | scut = usl m_replace_bytes |
| 9267 | slen = usl m_length |
| 9268 | c_s = ucl c_str |
| 9269 | salloc = usl m_alloc |
| 9270 | sinit_data = usl m_init_data_encoding |
| 9271 | more = true |
| 9272 | for turn ulong 4096 bound 4096 |
| 9273 | if more |
| 9274 | total = umsg buffer slen 0 0 0 |
| 9275 | if eq total 0 |
| 9276 | more = false |
| 9277 | else |
| 9278 | upr 40 total |
| 9279 | found_at = umsg buffer srange newline 0 0 |
| 9280 | take = total |
| 9281 | whole_line = false |
| 9282 | if lt found_at total |
| 9283 | take = found_at |
| 9284 | whole_line = true |
| 9285 | end |
| 9286 | if and not whole_line ne n 0 |
| 9287 | more = false |
| 9288 | else |
| 9289 | piece = umsg buffer ssub 0 take 0 |
| 9290 | line = umsg c_s salloc 0 0 0 |
| 9291 | line = umsg line sinit_data piece 4 0 |
| 9292 | drop = take |
| 9293 | if whole_line |
| 9294 | drop = add take 1 |
| 9295 | end |
| 9296 | upr 40 0 |
| 9297 | x = umsg buffer scut 0 drop 0 |
| 9298 | if ne line 0 |
| 9299 | uagentsay uagentline line |
| 9300 | end |
| 9301 | end |
| 9302 | end |
| 9303 | end |
| 9304 | end |
| 9305 | end |
| 9306 | |
| 9307 | note the agent's run has ended in one more way (1 its output, 2 the program); when both have, the turn is over |
| 9308 | fn uagentended what ulong to void |
| 9309 | put g_n 47 or get g_n 47 what |
| 9310 | if eq get g_n 47 2 |
| 9311 | s_after = usl m_perform_after |
| 9312 | upr 64 bitcast ulong 2.0f64 |
| 9313 | x = umsg get g_o 27 s_after get g_m 38 0 0 |
| 9314 | end |
| 9315 | if ne get g_n 47 3 |
| 9316 | ret |
| 9317 | end |
| 9318 | task = get g_m 26 |
| 9319 | if eq task 0 |
| 9320 | ret |
| 9321 | end |
| 9322 | code = and umsg task usl m_termination 0 0 0 4294967295 |
| 9323 | if ne code 0 |
| 9324 | p = uptxt 0 x_agent_stopped_a |
| 9325 | p = upnum p code |
| 9326 | p = uptxt p x_agent_stopped_b |
| 9327 | put g_nm p 0 |
| 9328 | uagentsay unsb |
| 9329 | end |
| 9330 | center = umsg ucl c_center usl m_default_center 0 0 0 |
| 9331 | s_forget = usl m_remove_all_observer |
| 9332 | x = umsg center s_forget get g_o 27 0 get g_m 27 |
| 9333 | x = umsg center s_forget get g_o 27 0 get g_m 37 |
| 9334 | x = umsg center s_forget get g_o 27 0 task |
| 9335 | srel = usl m_release |
| 9336 | x = umsg task srel 0 0 0 |
| 9337 | put g_m 26 0 |
| 9338 | put g_n 43 0 |
| 9339 | put g_n 21 1 |
| 9340 | put g_n 39 1 |
| 9341 | x = umsg ucl c_date usl m_reference_now 0 0 0 |
| 9342 | now_bits = ugr 64 |
| 9343 | if ne get g_m 36 0 |
| 9344 | x = umsg get g_m 36 srel 0 0 0 |
| 9345 | end |
| 9346 | s_double = usl m_number_double |
| 9347 | cnum = ucl c_number |
| 9348 | upr 64 now_bits |
| 9349 | put g_m 36 umsg umsg cnum s_double 0 0 0 usl m_retain 0 0 0 |
| 9350 | end |
| 9351 | |
| 9352 | note what the agent's program tells this one: output (agentOut:), errors (agentErr:), its end (agentEnd:), and the |
| 9353 | note menu's Stop the Agent (stopAgent:); which is the selector, about is what came with it |
| 9354 | fn uagentevent which ulong about ulong to void |
| 9355 | if ustatusevent which |
| 9356 | ret |
| 9357 | end |
| 9358 | if eq which get g_m 64 |
| 9359 | uprobedone about |
| 9360 | ret |
| 9361 | end |
| 9362 | if eq which get g_m 46 |
| 9363 | uremotestart |
| 9364 | ret |
| 9365 | end |
| 9366 | if eq which get g_m 47 |
| 9367 | uremotedone about |
| 9368 | ret |
| 9369 | end |
| 9370 | if eq which get g_m 48 |
| 9371 | ufetchdone about |
| 9372 | ret |
| 9373 | end |
| 9374 | if eq which get g_m 41 |
| 9375 | if ne get g_m 26 0 |
| 9376 | x = umsg get g_m 26 usl m_terminate_task 0 0 0 |
| 9377 | end |
| 9378 | ret |
| 9379 | end |
| 9380 | if eq which get g_m 40 |
| 9381 | uagentended 2 |
| 9382 | ret |
| 9383 | end |
| 9384 | if eq get g_m 26 0 |
| 9385 | ret |
| 9386 | end |
| 9387 | if eq about 0 |
| 9388 | if and eq which get g_m 38 eq and get g_n 47 1 0 |
| 9389 | uagentout umsg ucl c_data usl m_data 0 0 0 |
| 9390 | uagentended 1 |
| 9391 | end |
| 9392 | ret |
| 9393 | end |
| 9394 | info = umsg about usl m_user_info 0 0 0 |
| 9395 | if eq info 0 |
| 9396 | ret |
| 9397 | end |
| 9398 | d = umsg info usl m_object_for_key uconst s_data_item 0 0 |
| 9399 | if eq d 0 |
| 9400 | ret |
| 9401 | end |
| 9402 | n = umsg d usl m_length 0 0 0 |
| 9403 | if eq which get g_m 38 |
| 9404 | uagentout d |
| 9405 | if eq n 0 |
| 9406 | uagentended 1 |
| 9407 | else |
| 9408 | x = umsg get g_m 27 usl m_read_background 0 0 0 |
| 9409 | end |
| 9410 | ret |
| 9411 | end |
| 9412 | if gt n 0 |
| 9413 | said = umsg ucl c_str usl m_alloc 0 0 0 |
| 9414 | said = umsg said usl m_init_data_encoding d 4 0 |
| 9415 | if ne said 0 |
| 9416 | edge = umsg ucl c_charset usl m_newline_set 0 0 0 |
| 9417 | uagentsay umsg uns x_bang usl m_append_string umsg said usl m_trim edge 0 0 0 0 |
| 9418 | end |
| 9419 | x = umsg get g_m 37 usl m_read_background 0 0 0 |
| 9420 | end |
| 9421 | end |
| 9422 | |
| 9423 | note send the typed text to the agent |
| 9424 | fn uagentrun to void |
| 9425 | a = get g_n 12 |
| 9426 | n = get g_n 13 |
| 9427 | if or eq n 0 gt n 255 |
| 9428 | ret |
| 9429 | end |
| 9430 | for i ulong n bound 256 |
| 9431 | put g_nm i get g_q add a i |
| 9432 | end |
| 9433 | put g_nm n 0 |
| 9434 | request = unsb |
| 9435 | if eq request 0 |
| 9436 | ret |
| 9437 | end |
| 9438 | note the talk on show: what was there joins what was said before, then the request |
| 9439 | if eq get g_m 25 0 |
| 9440 | told = umsg ucl c_mutable_string usl m_string 0 0 0 |
| 9441 | put g_m 25 umsg told usl m_retain 0 0 0 |
| 9442 | end |
| 9443 | if eq get g_m 4 0 |
| 9444 | fresh_text = umsg ucl c_mutable_string usl m_string 0 0 0 |
| 9445 | put g_m 4 umsg fresh_text usl m_retain 0 0 0 |
| 9446 | end |
| 9447 | if eq get g_n 43 1 |
| 9448 | uanswershow |
| 9449 | uanswerview 1 |
| 9450 | ret |
| 9451 | end |
| 9452 | put g_nm 0 10 |
| 9453 | put g_nm 1 10 |
| 9454 | put g_nm 2 0 |
| 9455 | blank_line = unsb |
| 9456 | sappend_text = usl m_append |
| 9457 | if eq get g_n 39 1 |
| 9458 | x = umsg get g_m 25 sappend_text get g_m 4 0 0 |
| 9459 | x = umsg get g_m 25 sappend_text blank_line 0 0 |
| 9460 | end |
| 9461 | x = umsg get g_m 25 sappend_text uns x_you 0 0 |
| 9462 | x = umsg get g_m 25 sappend_text request 0 0 |
| 9463 | x = umsg get g_m 25 sappend_text blank_line 0 0 |
| 9464 | put g_n 39 0 |
| 9465 | put g_n 21 0 |
| 9466 | put g_n 22 0 |
| 9467 | engine = uagentpicked |
| 9468 | if eq engine 0 |
| 9469 | uagentsay uagentwhy |
| 9470 | put g_n 21 1 |
| 9471 | put g_n 39 1 |
| 9472 | uanswershow |
| 9473 | uanswerview 1 |
| 9474 | ret |
| 9475 | end |
| 9476 | if eq get g_n 44 0 |
| 9477 | if eq get g_n 14 0 |
| 9478 | uagentsay uns x_agent_ask |
| 9479 | put g_n 21 1 |
| 9480 | put g_n 39 1 |
| 9481 | uanswershow |
| 9482 | uanswerview 1 |
| 9483 | ret |
| 9484 | end |
| 9485 | alert = umsg umsg ucl c_alert usl m_alloc 0 0 0 usl m_init 0 0 0 |
| 9486 | x = umsg alert usl m_set_message uns x_agent_ask 0 0 |
| 9487 | x = umsg alert usl m_set_informative uns x_agent_ask_more 0 0 |
| 9488 | x = umsg alert usl m_add_button uns x_agent_yes 0 0 |
| 9489 | x = umsg alert usl m_add_button uns x_agent_no 0 0 |
| 9490 | if ne umsg alert usl m_run_modal 0 0 0 1000 |
| 9491 | ret |
| 9492 | end |
| 9493 | put g_n 44 1 |
| 9494 | end |
| 9495 | x = umsg get g_m 4 usl m_set_string uns x_agent_working 0 0 |
| 9496 | uanswershow |
| 9497 | uanswerview 1 |
| 9498 | note the words to run: the request in place of "{prompt}", Hop's standing instructions before it, or for |
| 9499 | note Claude Code as its system prompt; a follow-up within 15 minutes carries on from Claude Code's last run |
| 9500 | brief = uagentbrief |
| 9501 | command = ukeyed engine k_command |
| 9502 | sat = usl m_at |
| 9503 | sappend = usl m_append_string |
| 9504 | sequal = usl m_equal_string |
| 9505 | tool = umsg command sat 0 0 0 |
| 9506 | is_claude = eq and umsg tool sequal uns x_claude 0 0 255 1 |
| 9507 | prompt = request |
| 9508 | if not is_claude |
| 9509 | prompt = umsg umsg umsg brief sappend blank_line 0 0 sappend uns x_request 0 0 sappend request 0 0 |
| 9510 | end |
| 9511 | argv = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 9512 | sadd = usl m_add_object |
| 9513 | mark = uns x_prompt_mark |
| 9514 | cnt = umsg command usl m_count 0 0 0 |
| 9515 | for i ulong cnt bound 256 |
| 9516 | word = umsg command sat i 0 0 |
| 9517 | if uiskind word 9 |
| 9518 | x = umsg argv sadd umsg word usl m_replace mark prompt 0 0 0 |
| 9519 | end |
| 9520 | end |
| 9521 | if is_claude |
| 9522 | shas = usl m_contains_object |
| 9523 | if eq and umsg argv shas uns x_append_system 0 0 255 0 |
| 9524 | x = umsg argv sadd uns x_append_system 0 0 |
| 9525 | x = umsg argv sadd brief 0 0 |
| 9526 | end |
| 9527 | if and ne get g_m 33 0 ne get g_m 36 0 |
| 9528 | if eq and umsg argv shas uns x_resume 0 0 255 0 |
| 9529 | x = umsg get g_m 36 usl m_double_value 0 0 0 |
| 9530 | last_bits = ugr 64 |
| 9531 | x = umsg ucl c_date usl m_reference_now 0 0 0 |
| 9532 | if lt sub bitcast f64 ugr 64 bitcast f64 last_bits 900.0f64 |
| 9533 | x = umsg argv sadd uns x_resume 0 0 |
| 9534 | x = umsg argv sadd get g_m 33 0 0 |
| 9535 | end |
| 9536 | end |
| 9537 | end |
| 9538 | end |
| 9539 | task = ushellrun argv get g_m 30 |
| 9540 | tube = umsg ucl c_pipe usl m_pipe 0 0 0 |
| 9541 | error_tube = umsg ucl c_pipe usl m_pipe 0 0 0 |
| 9542 | quiet = umsg ucl c_file_handle usl m_null_device 0 0 0 |
| 9543 | x = umsg task usl m_set_output tube 0 0 |
| 9544 | x = umsg task usl m_set_error error_tube 0 0 |
| 9545 | x = umsg task usl m_set_input quiet 0 0 |
| 9546 | sret = usl m_retain |
| 9547 | reader = umsg tube usl m_reading 0 0 0 |
| 9548 | error_reader = umsg error_tube usl m_reading 0 0 0 |
| 9549 | if ne get g_m 27 0 |
| 9550 | x = umsg get g_m 27 usl m_release 0 0 0 |
| 9551 | x = umsg get g_m 37 usl m_release 0 0 0 |
| 9552 | x = umsg get g_m 32 usl m_release 0 0 0 |
| 9553 | end |
| 9554 | put g_m 27 umsg reader sret 0 0 0 |
| 9555 | put g_m 37 umsg error_reader sret 0 0 0 |
| 9556 | put g_m 32 umsg umsg ucl c_mutable_data usl m_data 0 0 0 sret 0 0 0 |
| 9557 | put g_m 26 umsg task sret 0 0 0 |
| 9558 | put g_n 47 0 |
| 9559 | center = umsg ucl c_center usl m_default_center 0 0 0 |
| 9560 | s_observe = usl m_add_observer |
| 9561 | read_done = uconst s_read_done |
| 9562 | ended = uconst s_task_ended |
| 9563 | upr 40 reader |
| 9564 | x = umsg center s_observe get g_o 27 get g_m 38 read_done |
| 9565 | upr 40 error_reader |
| 9566 | x = umsg center s_observe get g_o 27 get g_m 39 read_done |
| 9567 | upr 40 task |
| 9568 | x = umsg center s_observe get g_o 27 get g_m 40 ended |
| 9569 | put g_n 43 1 |
| 9570 | x = umsg task usl m_launch 0 0 0 |
| 9571 | x = umsg reader usl m_read_background 0 0 0 |
| 9572 | x = umsg error_reader usl m_read_background 0 0 0 |
| 9573 | end |
| 9574 | |
| 9575 | note ---- files on other machines, as Hop finds them (Sources/Machines.swift, Sources/Model.swift searchFiles) ---- |
| 9576 | note Each machine of Hop's settings keeps its own list of files (20 pieces, built there by a command Hop sends |
| 9577 | note when the list is missing or old); a search runs on the machine through ssh and the lines that hold every |
| 9578 | note typed word come back, to be scored here by the rule the local files are scored by. The machines are asked |
| 9579 | note a moment after typing pauses, all at once, by one program whose answer is read when it has ended. Enter on |
| 9580 | note such a file brings it over (scp, into the cache folder) and opens it; a folder's path goes to the clipboard. |
| 9581 | note an NSString of text t with every "%%" turned into a double quote and every "^^" into a backslash |
| 9582 | fn uquoted2 t view uchar * to ulong |
| 9583 | put g_nm 0 34 |
| 9584 | put g_nm 1 0 |
| 9585 | quote_mark = unsb |
| 9586 | put g_nm 0 92 |
| 9587 | put g_nm 1 0 |
| 9588 | back_mark = unsb |
| 9589 | plain = uns t |
| 9590 | srep = usl m_replace |
| 9591 | plain = umsg plain srep uns x_percents quote_mark 0 |
| 9592 | ret umsg plain srep uns x_carets back_mark 0 |
| 9593 | end |
| 9594 | |
| 9595 | note the machines of the settings: their names into g_mn (63 bytes each at most), their ssh names kept; 10 at most |
| 9596 | fn umachines config ulong to void |
| 9597 | put g_n 54 0 |
| 9598 | put g_n 59 0 |
| 9599 | if eq get g_n 14 1 |
| 9600 | put g_n 59 1 |
| 9601 | else |
| 9602 | n = ucs x_env_ssh |
| 9603 | upr 0 ulong libptr g_nm 0 1024 |
| 9604 | if ne ucall 9 0 |
| 9605 | put g_n 59 1 |
| 9606 | end |
| 9607 | end |
| 9608 | if eq config 0 |
| 9609 | ret |
| 9610 | end |
| 9611 | machines = ukeyed config k_machines |
| 9612 | if not uiskind machines 8 |
| 9613 | ret |
| 9614 | end |
| 9615 | sat = usl m_at |
| 9616 | aliases = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 9617 | cnt = umsg machines usl m_count 0 0 0 |
| 9618 | have = ulong 0 |
| 9619 | for i ulong cnt bound 64 |
| 9620 | if lt have 10 |
| 9621 | m = umsg machines sat i 0 0 |
| 9622 | if uiskind m 7 |
| 9623 | name = ukeyed m k_name |
| 9624 | via = ukeyed m k_ssh |
| 9625 | if and uiskind name 9 uiskind via 9 |
| 9626 | src = umsg name get g_o 5 0 0 0 |
| 9627 | if ne src 0 |
| 9628 | upr 0 src |
| 9629 | n = ucall 7 |
| 9630 | if gt n 63 |
| 9631 | n = 63 |
| 9632 | end |
| 9633 | if gt n 0 |
| 9634 | upr 0 ulong libptr g_mn mul have 64 n |
| 9635 | upr 8 src |
| 9636 | upr 16 n |
| 9637 | x = ucall 8 |
| 9638 | end |
| 9639 | put g_ml have uchar n |
| 9640 | x = umsg aliases usl m_add_object m 0 0 |
| 9641 | have = add have 1 |
| 9642 | end |
| 9643 | end |
| 9644 | end |
| 9645 | end |
| 9646 | end |
| 9647 | if ne get g_m 42 0 |
| 9648 | x = umsg get g_m 42 usl m_release 0 0 0 |
| 9649 | end |
| 9650 | put g_m 42 umsg aliases usl m_retain 0 0 0 |
| 9651 | put g_n 54 have |
| 9652 | end |
| 9653 | |
| 9654 | note may other machines be reached: always when resident; a check reaches none but through its stand-in (HOPSSH) |
| 9655 | note (looked up once, when the settings are read: 59 is 1 for yes) |
| 9656 | fn uremoteok to bool |
| 9657 | ret eq get g_n 59 1 |
| 9658 | end |
| 9659 | |
| 9660 | note the program to reach other machines with: ssh (scp when copy is 1), or for a check its stand-in |
| 9661 | fn uremotetool copy ulong to ulong |
| 9662 | if eq get g_n 14 0 |
| 9663 | n = ucs x_env_ssh |
| 9664 | if eq copy 1 |
| 9665 | n = ucs x_env_scp |
| 9666 | end |
| 9667 | upr 0 ulong libptr g_nm 0 1024 |
| 9668 | given = ucall 9 |
| 9669 | if ne given 0 |
| 9670 | n = ufetch given |
| 9671 | ret ushellquote unsb |
| 9672 | end |
| 9673 | end |
| 9674 | if eq copy 1 |
| 9675 | ret uns x_scp_word |
| 9676 | end |
| 9677 | ret uns x_ssh_word |
| 9678 | end |
| 9679 | |
| 9680 | note run a script through the login shell and read all it says when it has ended: done is the selector told then. |
| 9681 | note The program (kept) and where its answer is read (kept) go to places prog and reader of g_m |
| 9682 | fn uscriptrun script ulong done ulong prog ulong reader_at ulong to void |
| 9683 | argv = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 9684 | sadd = usl m_add_object |
| 9685 | x = umsg argv sadd uns x_sh 0 0 |
| 9686 | x = umsg argv sadd uns x_dash_c 0 0 |
| 9687 | x = umsg argv sadd script 0 0 |
| 9688 | task = ushellrun argv 0 |
| 9689 | tube = umsg ucl c_pipe usl m_pipe 0 0 0 |
| 9690 | quiet = umsg ucl c_file_handle usl m_null_device 0 0 0 |
| 9691 | x = umsg task usl m_set_output tube 0 0 |
| 9692 | x = umsg task usl m_set_error quiet 0 0 |
| 9693 | x = umsg task usl m_set_input quiet 0 0 |
| 9694 | reader = umsg tube usl m_reading 0 0 0 |
| 9695 | sret = usl m_retain |
| 9696 | center = umsg ucl c_center usl m_default_center 0 0 0 |
| 9697 | whole_read = uconst s_read_to_end_done |
| 9698 | if ne get g_m prog 0 |
| 9699 | x = umsg get g_m prog usl m_terminate_task 0 0 0 |
| 9700 | x = umsg center usl m_remove_all_observer get g_o 27 whole_read get g_m reader_at |
| 9701 | x = umsg get g_m prog usl m_release 0 0 0 |
| 9702 | x = umsg get g_m reader_at usl m_release 0 0 0 |
| 9703 | end |
| 9704 | put g_m prog umsg task sret 0 0 0 |
| 9705 | put g_m reader_at umsg reader sret 0 0 0 |
| 9706 | s_observe = usl m_add_observer |
| 9707 | upr 40 reader |
| 9708 | x = umsg center s_observe get g_o 27 done whole_read |
| 9709 | x = umsg task usl m_launch 0 0 0 |
| 9710 | x = umsg reader usl m_read_to_end 0 0 0 |
| 9711 | end |
| 9712 | |
| 9713 | note the command that makes machine m (a settings entry) build its list of files when it has none or an old one |
| 9714 | fn urefreshscript m ulong to ulong |
| 9715 | sappend = usl m_append_string |
| 9716 | sat = usl m_at |
| 9717 | roots = ukeyed m k_roots_m |
| 9718 | skips = ukeyed m k_skip_m |
| 9719 | if not uiskind skips 8 |
| 9720 | skips = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 9721 | sadd = usl m_add_object |
| 9722 | x = umsg skips sadd uns x_mskip0 0 0 |
| 9723 | x = umsg skips sadd uns x_mskip1 0 0 |
| 9724 | x = umsg skips sadd uns x_mskip2 0 0 |
| 9725 | x = umsg skips sadd uns x_mskip3 0 0 |
| 9726 | x = umsg skips sadd uns x_mskip4 0 0 |
| 9727 | x = umsg skips sadd uns x_mskip5 0 0 |
| 9728 | x = umsg skips sadd uns x_mskip6 0 0 |
| 9729 | x = umsg skips sadd uns x_mskip7 0 0 |
| 9730 | x = umsg skips sadd uns x_mskip8 0 0 |
| 9731 | x = umsg skips sadd uns x_mskip9 0 0 |
| 9732 | end |
| 9733 | prune = umsg ucl c_mutable_string usl m_string 0 0 0 |
| 9734 | smore = usl m_append |
| 9735 | cnt = umsg skips usl m_count 0 0 0 |
| 9736 | for i ulong cnt bound 256 |
| 9737 | one_name = umsg skips sat i 0 0 |
| 9738 | if uiskind one_name 9 |
| 9739 | if gt umsg prune usl m_length 0 0 0 0 |
| 9740 | x = umsg prune smore uns x_or_flag 0 0 |
| 9741 | end |
| 9742 | x = umsg prune smore uns x_name_flag 0 0 |
| 9743 | x = umsg prune smore ushellquote one_name 0 0 |
| 9744 | end |
| 9745 | end |
| 9746 | places = umsg ucl c_mutable_string usl m_string 0 0 0 |
| 9747 | if uiskind roots 8 |
| 9748 | cnt = umsg roots usl m_count 0 0 0 |
| 9749 | for i ulong cnt bound 256 |
| 9750 | one_root = umsg roots sat i 0 0 |
| 9751 | if uiskind one_root 9 |
| 9752 | if gt umsg places usl m_length 0 0 0 0 |
| 9753 | x = umsg places smore uns x_space 0 0 |
| 9754 | end |
| 9755 | x = umsg places smore ushellquote one_root 0 0 |
| 9756 | end |
| 9757 | end |
| 9758 | end |
| 9759 | build = 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 |
| 9760 | put g_nm 0 10 |
| 9761 | put g_nm 1 0 |
| 9762 | line_end = unsb |
| 9763 | script = umsg ucl c_mutable_string usl m_string 0 0 0 |
| 9764 | x = umsg script smore uns x_fresh_a 0 0 |
| 9765 | x = umsg script smore line_end 0 0 |
| 9766 | x = umsg script smore uquoted2 x_fresh_b 0 0 |
| 9767 | x = umsg script smore line_end 0 0 |
| 9768 | x = umsg script smore uquoted2 x_fresh_c 0 0 |
| 9769 | x = umsg script smore ushellquote build 0 0 |
| 9770 | x = umsg script smore uns x_fresh_d 0 0 |
| 9771 | x = umsg script smore line_end 0 0 |
| 9772 | x = umsg script smore uns x_fresh_e 0 0 |
| 9773 | ret script |
| 9774 | end |
| 9775 | |
| 9776 | note ask machine k to build its list of files if it has none or an old one; nothing is waited for |
| 9777 | fn uremoterefresh k ulong to void |
| 9778 | if or or ge k get g_n 54 eq get g_m 42 0 not uremoteok |
| 9779 | ret |
| 9780 | end |
| 9781 | m = umsg get g_m 42 get g_m 16 k 0 0 |
| 9782 | via = ukeyed m k_ssh |
| 9783 | sappend = usl m_append_string |
| 9784 | line = umsg umsg umsg uremotetool 0 sappend uns x_ssh_options 0 0 sappend ushellquote via 0 0 sappend uns x_space 0 0 |
| 9785 | line = umsg line sappend ushellquote urefreshscript m 0 0 |
| 9786 | argv = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 9787 | sadd = usl m_add_object |
| 9788 | x = umsg argv sadd uns x_sh 0 0 |
| 9789 | x = umsg argv sadd uns x_dash_c 0 0 |
| 9790 | x = umsg argv sadd line 0 0 |
| 9791 | task = ushellrun argv 0 |
| 9792 | quiet = umsg ucl c_file_handle usl m_null_device 0 0 0 |
| 9793 | x = umsg task usl m_set_output quiet 0 0 |
| 9794 | x = umsg task usl m_set_error quiet 0 0 |
| 9795 | x = umsg task usl m_set_input quiet 0 0 |
| 9796 | x = umsg task usl m_launch 0 0 0 |
| 9797 | end |
| 9798 | |
| 9799 | note a moment after typing pauses the machines are asked; until then nothing found there is shown |
| 9800 | fn uremotesoon to void |
| 9801 | put g_n 49 0 |
| 9802 | put g_n 58 0 |
| 9803 | if le get g_n 51 2 |
| 9804 | put g_n 51 0 |
| 9805 | end |
| 9806 | if eq get g_n 54 0 |
| 9807 | ret |
| 9808 | end |
| 9809 | if not uremoteok |
| 9810 | ret |
| 9811 | end |
| 9812 | s_go = get g_m 46 |
| 9813 | x = umsg ucl c_obj usl m_cancel_previous get g_o 27 s_go 0 |
| 9814 | if or or lt get g_n 13 2 gt get g_n 13 255 ne get g_n 36 0 |
| 9815 | ret |
| 9816 | end |
| 9817 | s_after = usl m_perform_after |
| 9818 | upr 64 bitcast ulong 0.22f64 |
| 9819 | x = umsg get g_o 27 s_after s_go 0 0 |
| 9820 | end |
| 9821 | |
| 9822 | note ask every machine for the files that hold every typed word (the longest first, as on the machine's side |
| 9823 | note each further word narrows what the first found) |
| 9824 | fn uremotestart to void |
| 9825 | a = get g_n 12 |
| 9826 | n = get g_n 13 |
| 9827 | if or or lt n 2 gt n 255 eq get g_n 54 0 |
| 9828 | ret |
| 9829 | end |
| 9830 | for i ulong n bound 256 |
| 9831 | put g_rq i get g_q add a i |
| 9832 | put g_nm i get g_q add a i |
| 9833 | end |
| 9834 | put g_n 53 n |
| 9835 | put g_nm n 0 |
| 9836 | typed = unsb |
| 9837 | if eq typed 0 |
| 9838 | ret |
| 9839 | end |
| 9840 | parts = umsg umsg typed usl m_lowercase 0 0 0 usl m_components uns x_space 0 0 |
| 9841 | sat = usl m_at |
| 9842 | slen = usl m_length |
| 9843 | cnt = umsg parts usl m_count 0 0 0 |
| 9844 | longest = ulong 0 |
| 9845 | longest_len = ulong 0 |
| 9846 | for i ulong cnt bound 64 |
| 9847 | one_word = umsg parts sat i 0 0 |
| 9848 | wl = umsg one_word slen 0 0 0 |
| 9849 | if ge wl longest_len |
| 9850 | if gt wl 0 |
| 9851 | longest = one_word |
| 9852 | longest_len = wl |
| 9853 | end |
| 9854 | end |
| 9855 | end |
| 9856 | if eq longest 0 |
| 9857 | ret |
| 9858 | end |
| 9859 | sappend = usl m_append_string |
| 9860 | filter = umsg umsg uns x_remote_grep sappend ushellquote longest 0 0 sappend uquoted2 x_remote_shard 0 0 |
| 9861 | for i ulong cnt bound 64 |
| 9862 | one_word = umsg parts sat i 0 0 |
| 9863 | if and gt umsg one_word slen 0 0 0 0 eq and umsg one_word usl m_equal_string longest 0 0 255 0 |
| 9864 | filter = umsg umsg umsg filter sappend uns x_remote_pipe 0 0 sappend uns x_remote_grep 0 0 sappend ushellquote one_word 0 0 |
| 9865 | end |
| 9866 | end |
| 9867 | remote = umsg umsg uns x_remote_a sappend filter 0 0 sappend uquoted2 x_remote_b 0 0 |
| 9868 | remote_quoted = ushellquote remote |
| 9869 | tool = uremotetool 0 |
| 9870 | put g_nm 0 10 |
| 9871 | put g_nm 1 0 |
| 9872 | line_end = unsb |
| 9873 | script = umsg ucl c_mutable_string usl m_string 0 0 0 |
| 9874 | smore = usl m_append |
| 9875 | for k ulong get g_n 54 bound 10 |
| 9876 | m = umsg get g_m 42 sat k 0 0 |
| 9877 | via = ukeyed m k_ssh |
| 9878 | x = umsg script smore uns x_local_a 0 0 |
| 9879 | x = umsg script smore tool 0 0 |
| 9880 | x = umsg script smore uns x_ssh_options 0 0 |
| 9881 | x = umsg script smore ushellquote via 0 0 |
| 9882 | x = umsg script smore uns x_space 0 0 |
| 9883 | x = umsg script smore remote_quoted 0 0 |
| 9884 | x = umsg script smore uns x_local_b 0 0 |
| 9885 | put g_nm 0 uchar add 48 k |
| 9886 | put g_nm 1 0 |
| 9887 | x = umsg script smore unsb 0 0 |
| 9888 | x = umsg script smore uns x_local_c 0 0 |
| 9889 | x = umsg script smore line_end 0 0 |
| 9890 | end |
| 9891 | x = umsg script smore uns x_wait_word 0 0 |
| 9892 | uscriptrun script get g_m 47 43 44 |
| 9893 | end |
| 9894 | |
| 9895 | note keep a file found on a machine among the best 64, best first |
| 9896 | fn uremotekeep sc ulong o ulong ln ulong k ulong to void |
| 9897 | have = get g_n 49 |
| 9898 | if and ge have 64 le sc get g_rs 63 |
| 9899 | ret |
| 9900 | end |
| 9901 | pos = have |
| 9902 | if ge have 64 |
| 9903 | pos = 63 |
| 9904 | else |
| 9905 | put g_n 49 add have 1 |
| 9906 | end |
| 9907 | while gt pos 0 bound 80 |
| 9908 | if ge get g_rs sub pos 1 sc |
| 9909 | break |
| 9910 | end |
| 9911 | put g_rs pos get g_rs sub pos 1 |
| 9912 | put g_ro pos get g_ro sub pos 1 |
| 9913 | put g_rl pos get g_rl sub pos 1 |
| 9914 | put g_rw pos get g_rw sub pos 1 |
| 9915 | pos = sub pos 1 |
| 9916 | end |
| 9917 | put g_rs pos sc |
| 9918 | put g_ro pos o |
| 9919 | put g_rl pos ln |
| 9920 | put g_rw pos uchar k |
| 9921 | end |
| 9922 | |
| 9923 | note does the line at o of g_rb (n bytes) read exactly as text t |
| 9924 | fn uremoteis o ulong n ulong t view uchar * to bool |
| 9925 | tl = len t |
| 9926 | if ne n tl |
| 9927 | ret false |
| 9928 | end |
| 9929 | for i ulong tl bound 64 |
| 9930 | if ne ulong get g_rb add o i ulong get t i |
| 9931 | ret false |
| 9932 | end |
| 9933 | end |
| 9934 | ret true |
| 9935 | end |
| 9936 | |
| 9937 | note the machines have answered (about: the notice that carries what they said). When the typed text is still |
| 9938 | note the one they were asked for, every line is scored and the list is made anew |
| 9939 | fn uremotedone about ulong to void |
| 9940 | if eq about 0 |
| 9941 | ret |
| 9942 | end |
| 9943 | info = umsg about usl m_user_info 0 0 0 |
| 9944 | if eq info 0 |
| 9945 | ret |
| 9946 | end |
| 9947 | d = umsg info usl m_object_for_key uconst s_data_item 0 0 |
| 9948 | if eq d 0 |
| 9949 | ret |
| 9950 | end |
| 9951 | a = get g_n 12 |
| 9952 | n = get g_n 13 |
| 9953 | if ne n get g_n 53 |
| 9954 | ret |
| 9955 | end |
| 9956 | for i ulong n bound 256 |
| 9957 | if ne ulong get g_q add a i ulong get g_rq i |
| 9958 | ret |
| 9959 | end |
| 9960 | end |
| 9961 | total = umsg d usl m_length 0 0 0 |
| 9962 | if gt total 1048575 |
| 9963 | total = 1048575 |
| 9964 | end |
| 9965 | put g_n 49 0 |
| 9966 | put g_n 58 0 |
| 9967 | put g_n 50 total |
| 9968 | if eq total 0 |
| 9969 | ret |
| 9970 | end |
| 9971 | src = umsg d usl m_bytes 0 0 0 |
| 9972 | base = ulong libptr g_rb 0 total |
| 9973 | upr 0 base |
| 9974 | upr 8 src |
| 9975 | upr 16 total |
| 9976 | x = ucall 8 |
| 9977 | pos = ulong 0 |
| 9978 | more = true |
| 9979 | for turn ulong 20000 bound 20000 |
| 9980 | if more |
| 9981 | if ge pos total |
| 9982 | more = false |
| 9983 | else |
| 9984 | upr 0 add base pos |
| 9985 | upr 8 10 |
| 9986 | upr 16 sub total pos |
| 9987 | x = ucall 12 |
| 9988 | e = total |
| 9989 | hit_at = ugr 0 |
| 9990 | if ne hit_at 0 |
| 9991 | e = sub hit_at base |
| 9992 | end |
| 9993 | ln = sub e pos |
| 9994 | if and ge ln 3 eq ulong get g_rb add pos 1 58 |
| 9995 | k = sub ulong get g_rb pos 48 |
| 9996 | if lt k get g_n 54 |
| 9997 | o = add pos 2 |
| 9998 | bl = sub ln 2 |
| 9999 | if uremoteis o bl x_no_index |
| 10000 | put g_n 51 2 |
| 10001 | put g_n 52 k |
| 10002 | uremoterefresh k |
| 10003 | else |
| 10004 | if uremoteis o bl x_unreachable |
| 10005 | put g_n 51 1 |
| 10006 | put g_n 52 k |
| 10007 | else |
| 10008 | pl = bl |
| 10009 | if eq ulong get g_rb sub add o bl 1 47 |
| 10010 | pl = sub bl 1 |
| 10011 | end |
| 10012 | if and gt pl 0 le pl 4000 |
| 10013 | for j ulong pl bound 4096 |
| 10014 | put g_line j uchar ulower ulong get g_rb add o j |
| 10015 | end |
| 10016 | sc = ufscore pl |
| 10017 | if ne sc 0 |
| 10018 | uremotekeep sc o bl k |
| 10019 | name_at = pl |
| 10020 | while gt name_at 0 bound 4097 |
| 10021 | if eq ulong get g_line sub name_at 1 47 |
| 10022 | break |
| 10023 | end |
| 10024 | name_at = sub name_at 1 |
| 10025 | end |
| 10026 | if eq sub pl name_at n |
| 10027 | same_name = true |
| 10028 | for j ulong n bound 256 |
| 10029 | if ne ulong get g_line add name_at j ulower ulong get g_rq j |
| 10030 | same_name = false |
| 10031 | end |
| 10032 | end |
| 10033 | if same_name |
| 10034 | put g_n 58 1 |
| 10035 | end |
| 10036 | end |
| 10037 | end |
| 10038 | end |
| 10039 | end |
| 10040 | end |
| 10041 | end |
| 10042 | end |
| 10043 | pos = add e 1 |
| 10044 | end |
| 10045 | end |
| 10046 | end |
| 10047 | keep_row = get g_n 6 |
| 10048 | unarrow |
| 10049 | x = umsg get g_o 1 get g_o 7 0 0 0 |
| 10050 | if lt keep_row get g_n 1 |
| 10051 | uchoose keep_row |
| 10052 | else |
| 10053 | if gt get g_n 1 0 |
| 10054 | uchoose 0 |
| 10055 | end |
| 10056 | end |
| 10057 | ushowst |
| 10058 | end |
| 10059 | |
| 10060 | note the text of a row for a file on another machine into g_nm from byte p: its name, the folder it is in, |
| 10061 | note and the machine; the byte after it |
| 10062 | fn uremoterow p ulong r ulong to ulong |
| 10063 | if ge r get g_n 49 |
| 10064 | ret p |
| 10065 | end |
| 10066 | o = get g_ro r |
| 10067 | ln = get g_rl r |
| 10068 | if gt ln 0 |
| 10069 | if eq ulong get g_rb sub add o ln 1 47 |
| 10070 | ln = sub ln 1 |
| 10071 | end |
| 10072 | end |
| 10073 | ns0 = ln |
| 10074 | while gt ns0 0 bound 4097 |
| 10075 | if eq ulong get g_rb sub add o ns0 1 47 |
| 10076 | break |
| 10077 | end |
| 10078 | ns0 = sub ns0 1 |
| 10079 | end |
| 10080 | q = p |
| 10081 | nl = sub ln ns0 |
| 10082 | if gt nl 300 |
| 10083 | nl = 300 |
| 10084 | end |
| 10085 | for j ulong nl bound 301 |
| 10086 | put g_nm add q j get g_rb add add o ns0 j |
| 10087 | end |
| 10088 | q = add q nl |
| 10089 | if and gt ns0 1 le ns0 400 |
| 10090 | q = uptxt q x_gap |
| 10091 | for j ulong sub ns0 1 bound 401 |
| 10092 | put g_nm add q j get g_rb add o j |
| 10093 | end |
| 10094 | q = add q sub ns0 1 |
| 10095 | end |
| 10096 | k = ulong get g_rw r |
| 10097 | q = uptxt q x_on |
| 10098 | ml = ulong get g_ml k |
| 10099 | for j ulong ml bound 64 |
| 10100 | put g_nm add q j get g_mn add mul k 64 j |
| 10101 | end |
| 10102 | ret add q ml |
| 10103 | end |
| 10104 | |
| 10105 | note the path of found file r, as it is written on its machine, as an NSString (without a folder's last "/") |
| 10106 | fn uremotepath r ulong to ulong |
| 10107 | o = get g_ro r |
| 10108 | ln = get g_rl r |
| 10109 | if gt ln 0 |
| 10110 | if eq ulong get g_rb sub add o ln 1 47 |
| 10111 | ln = sub ln 1 |
| 10112 | end |
| 10113 | end |
| 10114 | if or eq ln 0 gt ln 1000 |
| 10115 | ret 0 |
| 10116 | end |
| 10117 | for j ulong ln bound 1001 |
| 10118 | put g_nm j get g_rb add o j |
| 10119 | end |
| 10120 | put g_nm ln 0 |
| 10121 | ret unsb |
| 10122 | end |
| 10123 | |
| 10124 | note put text on the clipboard (a check uses a board of its own) |
| 10125 | fn uclipput words ulong to void |
| 10126 | pboard = ulong 0 |
| 10127 | if eq get g_n 14 1 |
| 10128 | pboard = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0 |
| 10129 | else |
| 10130 | pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0 |
| 10131 | end |
| 10132 | x = umsg pboard usl m_clear 0 0 0 |
| 10133 | x = umsg pboard usl m_set_string_type words uns x_type_string 0 |
| 10134 | put g_n 29 1 |
| 10135 | if eq get g_n 14 1 |
| 10136 | uclipmine 0 |
| 10137 | end |
| 10138 | end |
| 10139 | |
| 10140 | note Enter on a file of another machine: a folder's "ssh name:path" goes to the clipboard; a file is brought over |
| 10141 | note (when it is under 2 GB) into the cache folder and opened when it has arrived |
| 10142 | fn uremoteopen r ulong to void |
| 10143 | if or or ge r get g_n 49 eq get g_m 42 0 not uremoteok |
| 10144 | ret |
| 10145 | end |
| 10146 | k = ulong get g_rw r |
| 10147 | o = get g_ro r |
| 10148 | ln = get g_rl r |
| 10149 | is_folder = false |
| 10150 | if gt ln 0 |
| 10151 | is_folder = eq ulong get g_rb sub add o ln 1 47 |
| 10152 | end |
| 10153 | path = uremotepath r |
| 10154 | if eq path 0 |
| 10155 | ret |
| 10156 | end |
| 10157 | m = umsg get g_m 42 get g_m 16 k 0 0 |
| 10158 | via = ukeyed m k_ssh |
| 10159 | name = ukeyed m k_name |
| 10160 | sappend = usl m_append_string |
| 10161 | there = umsg umsg via sappend uns x_colon_only 0 0 sappend path 0 0 |
| 10162 | sret = usl m_retain |
| 10163 | if ne get g_m 51 0 |
| 10164 | x = umsg get g_m 51 usl m_release 0 0 0 |
| 10165 | end |
| 10166 | put g_m 51 umsg there sret 0 0 0 |
| 10167 | put g_n 52 k |
| 10168 | if is_folder |
| 10169 | uclipput there |
| 10170 | put g_n 51 4 |
| 10171 | ushowst |
| 10172 | ret |
| 10173 | end |
| 10174 | dest = ulong 0 |
| 10175 | if eq get g_n 14 0 |
| 10176 | dest = uhoppath x_check_cache |
| 10177 | else |
| 10178 | x = ucall 30 |
| 10179 | dest = umsg ugr 0 sappend uns x_remote_cache 0 0 |
| 10180 | end |
| 10181 | if eq dest 0 |
| 10182 | ret |
| 10183 | end |
| 10184 | dest = umsg umsg dest sappend name 0 0 sappend path 0 0 |
| 10185 | if ne get g_m 50 0 |
| 10186 | x = umsg get g_m 50 usl m_release 0 0 0 |
| 10187 | end |
| 10188 | put g_m 50 umsg dest sret 0 0 0 |
| 10189 | folder = umsg dest usl m_dir_of 0 0 0 |
| 10190 | tool = uremotetool 0 |
| 10191 | script = umsg uns x_fetch_a sappend tool 0 0 |
| 10192 | script = umsg script sappend uns x_ssh_options 0 0 |
| 10193 | script = umsg script sappend ushellquote via 0 0 |
| 10194 | script = umsg script sappend uns x_space 0 0 |
| 10195 | script = umsg script sappend ushellquote umsg uns x_fetch_stat sappend ushellquote path 0 0 0 0 |
| 10196 | script = umsg script sappend uquoted2 x_fetch_b 0 0 |
| 10197 | script = umsg script sappend ushellquote folder 0 0 |
| 10198 | script = umsg script sappend uns x_fetch_c 0 0 |
| 10199 | script = umsg script sappend uremotetool 1 0 0 |
| 10200 | script = umsg script sappend uns x_scp_options 0 0 |
| 10201 | script = umsg script sappend ushellquote there 0 0 |
| 10202 | script = umsg script sappend uns x_space 0 0 |
| 10203 | script = umsg script sappend ushellquote dest 0 0 |
| 10204 | script = umsg script sappend uns x_fetch_d 0 0 |
| 10205 | put g_n 51 3 |
| 10206 | ushowst |
| 10207 | uscriptrun script get g_m 48 45 49 |
| 10208 | end |
| 10209 | |
| 10210 | note the program bringing a file over has ended: when it says the file arrived it is opened, else the path goes |
| 10211 | note to the clipboard and that is said |
| 10212 | fn ufetchdone about ulong to void |
| 10213 | if eq about 0 |
| 10214 | ret |
| 10215 | end |
| 10216 | info = umsg about usl m_user_info 0 0 0 |
| 10217 | if eq info 0 |
| 10218 | ret |
| 10219 | end |
| 10220 | d = umsg info usl m_object_for_key uconst s_data_item 0 0 |
| 10221 | arrived = false |
| 10222 | if ne d 0 |
| 10223 | said = umsg ucl c_str usl m_alloc 0 0 0 |
| 10224 | said = umsg said usl m_init_data_encoding d 4 0 |
| 10225 | if ne said 0 |
| 10226 | arrived = eq and umsg said usl m_contains uns x_fetched 0 0 255 1 |
| 10227 | end |
| 10228 | end |
| 10229 | if arrived |
| 10230 | put g_n 51 0 |
| 10231 | put g_n 55 1 |
| 10232 | if eq get g_n 7 1 |
| 10233 | url = umsg ucl c_url usl m_furl get g_m 50 0 0 |
| 10234 | ws = umsg ucl c_ws usl m_shws 0 0 0 |
| 10235 | put g_n 9 and umsg ws usl m_open url 0 0 255 |
| 10236 | end |
| 10237 | else |
| 10238 | if ne get g_m 51 0 |
| 10239 | uclipput get g_m 51 |
| 10240 | end |
| 10241 | put g_n 51 5 |
| 10242 | end |
| 10243 | ushowst |
| 10244 | end |
| 10245 | |
| 10246 | note every half hour, and when the panel starts, each machine is asked to build its list if it is old |
| 10247 | fn uremoterefreshall to void |
| 10248 | for k ulong get g_n 54 bound 10 |
| 10249 | uremoterefresh k |
| 10250 | end |
| 10251 | end |
| 10252 | |
| 10253 | note what to say about a machine into g_nm from byte p; the byte after it |
| 10254 | fn uremotenote p ulong to ulong |
| 10255 | w = get g_n 51 |
| 10256 | k = get g_n 52 |
| 10257 | if or eq w 0 ge k get g_n 54 |
| 10258 | ret p |
| 10259 | end |
| 10260 | q = uptxt p x_gap |
| 10261 | if eq w 3 |
| 10262 | q = uptxt q x_note_bringing |
| 10263 | end |
| 10264 | if eq w 4 |
| 10265 | q = uptxt q x_note_copied |
| 10266 | end |
| 10267 | if eq w 5 |
| 10268 | q = uptxt q x_note_failed |
| 10269 | end |
| 10270 | ml = ulong get g_ml k |
| 10271 | for j ulong ml bound 64 |
| 10272 | put g_nm add q j get g_mn add mul k 64 j |
| 10273 | end |
| 10274 | q = add q ml |
| 10275 | if eq w 1 |
| 10276 | q = uptxt q x_note_unreachable |
| 10277 | end |
| 10278 | if eq w 2 |
| 10279 | q = uptxt q x_note_building |
| 10280 | end |
| 10281 | ret q |
| 10282 | end |
| 10283 | |
| 10284 | note for a check: HOPLATE sends Enter late, when the machines have had time to answer |
| 10285 | fn uchecklate to void |
| 10286 | put g_n 48 20 |
| 10287 | n = ucs x_env_late |
| 10288 | upr 0 ulong libptr g_nm 0 1024 |
| 10289 | if ne ucall 9 0 |
| 10290 | put g_n 48 80 |
| 10291 | end |
| 10292 | end |
| 10293 | |
| 10294 | note the three more things this program is told by selector (entry 13 hears them all) |
| 10295 | fn umoremethods mine ulong to bool |
| 10296 | ok = umethod mine m_remote_go 13 t_v |
| 10297 | ok = and ok umethod mine m_remote_done 13 t_v |
| 10298 | ok = and ok umethod mine m_fetch_done 13 t_v |
| 10299 | put g_m 46 usl m_remote_go |
| 10300 | put g_m 47 usl m_remote_done |
| 10301 | put g_m 48 usl m_fetch_done |
| 10302 | ret ok |
| 10303 | end |
| 10304 | |
| 10305 | note ---- the icon in the menu bar and its menu, as Hop has them (Sources/main.swift) ---- |
| 10306 | note Open, Rebuild file index, Allow paste into apps, Open at login, Settings, Clear clipboard history, Quit. |
| 10307 | note one item of that menu: title, what it tells this program (action_sel), its key (an NSString); the item |
| 10308 | fn ustatusadd menu ulong title view uchar * action_sel ulong key_string ulong to ulong |
| 10309 | item = umsg ucl c_menu_item usl m_alloc 0 0 0 |
| 10310 | title_string = uns title |
| 10311 | item = umsg item usl m_init_item title_string action_sel key_string |
| 10312 | x = umsg item usl m_set_target get g_o 27 0 0 |
| 10313 | x = umsg menu usl m_add_item item 0 0 |
| 10314 | ret item |
| 10315 | end |
| 10316 | |
| 10317 | note macOS's keeper of what opens at login, for this app (0: there is none) |
| 10318 | fn uloginservice to ulong |
| 10319 | n = ucs x_sm_path |
| 10320 | upr 0 ulong libptr g_nm 0 1024 |
| 10321 | upr 8 1 |
| 10322 | x = ucall 0 |
| 10323 | c = ucl c_sm_service |
| 10324 | if eq c 0 |
| 10325 | ret 0 |
| 10326 | end |
| 10327 | ret umsg c usl m_main_app 0 0 0 |
| 10328 | end |
| 10329 | |
| 10330 | note Open at login: on becomes off and off on; when macOS refuses, that is said |
| 10331 | fn ulogintoggle to void |
| 10332 | service = uloginservice |
| 10333 | if eq service 0 |
| 10334 | ret |
| 10335 | end |
| 10336 | done = ulong 0 |
| 10337 | if eq umsg service usl m_status 0 0 0 1 |
| 10338 | done = and umsg service usl m_unregister 0 0 0 255 |
| 10339 | if eq done 1 |
| 10340 | x = umsg get g_m 53 usl m_set_state 0 0 0 |
| 10341 | end |
| 10342 | else |
| 10343 | done = and umsg service usl m_register 0 0 0 255 |
| 10344 | if eq done 1 |
| 10345 | x = umsg get g_m 53 usl m_set_state 1 0 0 |
| 10346 | end |
| 10347 | end |
| 10348 | if eq done 0 |
| 10349 | alert = umsg umsg ucl c_alert usl m_alloc 0 0 0 usl m_init 0 0 0 |
| 10350 | x = umsg alert usl m_set_message uns x_login_failed 0 0 |
| 10351 | x = umsg alert usl m_run_modal 0 0 0 |
| 10352 | end |
| 10353 | end |
| 10354 | |
| 10355 | note Allow paste into apps: macOS is asked to show its own question about Accessibility for this app |
| 10356 | fn upasteask to void |
| 10357 | prompt_key = uconst s_trusted_prompt |
| 10358 | if eq prompt_key 0 |
| 10359 | ret |
| 10360 | end |
| 10361 | yes_flag = umsg ucl c_number usl m_number_bool 1 0 0 |
| 10362 | options = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 10363 | x = umsg options usl m_set_object yes_flag prompt_key 0 |
| 10364 | f = usym s_trusted_options |
| 10365 | if eq f 0 |
| 10366 | ret |
| 10367 | end |
| 10368 | upr 0 options |
| 10369 | x = ucallf f |
| 10370 | end |
| 10371 | |
| 10372 | note Clear clipboard history: every copied thing that is not pinned goes, a picture's sealed file with it. Like |
| 10373 | note every change to the history it is this program's to do only while Hop is not running |
| 10374 | fn uclipclear to void |
| 10375 | if and eq get g_n 14 1 uhoprunning |
| 10376 | ret |
| 10377 | end |
| 10378 | items = uclipsmutable |
| 10379 | if eq items 0 |
| 10380 | ret |
| 10381 | end |
| 10382 | sat = usl m_at |
| 10383 | sremove = usl m_remove_at |
| 10384 | cnt = umsg items usl m_count 0 0 0 |
| 10385 | for back ulong cnt bound 100000 |
| 10386 | j = sub sub cnt 1 back |
| 10387 | e = umsg items sat j 0 0 |
| 10388 | if uiskind e 7 |
| 10389 | if not uclippinned e |
| 10390 | image_name = ukeyed e k_image |
| 10391 | if uiskind image_name 9 |
| 10392 | if ne and umsg image_name usl m_contains uns x_slash_text 0 0 255 1 |
| 10393 | folder = uhoppath x_clip_images |
| 10394 | if ne folder 0 |
| 10395 | gone = umsg folder usl m_append_string image_name 0 0 |
| 10396 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 10397 | x = umsg manager usl m_remove_item gone 0 0 |
| 10398 | end |
| 10399 | end |
| 10400 | end |
| 10401 | x = umsg items sremove j 0 0 |
| 10402 | end |
| 10403 | end |
| 10404 | end |
| 10405 | if eq uclipswrite items 1 |
| 10406 | uloadclips |
| 10407 | urefresh |
| 10408 | end |
| 10409 | end |
| 10410 | |
| 10411 | note the menu of the icon in the menu bar |
| 10412 | fn ustatusmenu to ulong |
| 10413 | menu = umsg ucl c_menu usl m_alloc 0 0 0 |
| 10414 | menu = umsg menu usl m_init_title uns x_app 0 0 |
| 10415 | put g_nm 0 0 |
| 10416 | no_key = unsb |
| 10417 | s_add = usl m_add_item |
| 10418 | c_item = ucl c_menu_item |
| 10419 | s_line = usl m_separator |
| 10420 | x = ustatusadd menu x_status_open get g_m 54 no_key |
| 10421 | x = umsg menu s_add umsg c_item s_line 0 0 0 0 0 |
| 10422 | x = ustatusadd menu x_status_index get g_m 55 no_key |
| 10423 | x = ustatusadd menu x_status_paste get g_m 56 no_key |
| 10424 | login_item = ustatusadd menu x_status_login get g_m 57 no_key |
| 10425 | put g_m 53 login_item |
| 10426 | if eq get g_n 14 1 |
| 10427 | service = uloginservice |
| 10428 | if ne service 0 |
| 10429 | if eq umsg service usl m_status 0 0 0 1 |
| 10430 | x = umsg login_item usl m_set_state 1 0 0 |
| 10431 | end |
| 10432 | end |
| 10433 | end |
| 10434 | comma_key = uns x_key_comma |
| 10435 | x = ustatusadd menu x_status_settings get g_m 58 comma_key |
| 10436 | x = ustatusadd menu x_status_clear get g_m 59 no_key |
| 10437 | x = umsg menu s_add umsg c_item s_line 0 0 0 0 0 |
| 10438 | q_key = uns x_key_q |
| 10439 | s_quit = usl m_terminate |
| 10440 | quit_item = ustatusadd menu x_quit s_quit q_key |
| 10441 | x = umsg quit_item usl m_set_target umsg ucl c_app usl m_shared 0 0 0 0 0 |
| 10442 | ret menu |
| 10443 | end |
| 10444 | |
| 10445 | note put the icon in the menu bar (a check has none; with HOPMENU it says the menu's items instead) |
| 10446 | fn ustatus to void |
| 10447 | menu = ustatusmenu |
| 10448 | if eq get g_n 14 0 |
| 10449 | n = ucs x_env_menu |
| 10450 | upr 0 ulong libptr g_nm 0 1024 |
| 10451 | if eq ucall 9 0 |
| 10452 | ret |
| 10453 | end |
| 10454 | entries = umsg menu usl m_item_array 0 0 0 |
| 10455 | sat = usl m_at |
| 10456 | s_title = usl m_item_title |
| 10457 | cnt = umsg entries usl m_count 0 0 0 |
| 10458 | p = uptxt 0 x_menu_word |
| 10459 | for i ulong cnt bound 32 |
| 10460 | title_bytes = umsg umsg umsg entries sat i 0 0 s_title 0 0 0 get g_o 5 0 0 0 |
| 10461 | if gt i 0 |
| 10462 | put g_nm p 124 |
| 10463 | p = add p 1 |
| 10464 | end |
| 10465 | p = ufetchat p title_bytes |
| 10466 | end |
| 10467 | put g_nm p 10 |
| 10468 | upr 0 1 |
| 10469 | upr 8 ulong libptr g_nm 0 1024 |
| 10470 | upr 16 add p 1 |
| 10471 | x = ucall 3 |
| 10472 | ret |
| 10473 | end |
| 10474 | bar = umsg ucl c_status_bar usl m_system_status_bar 0 0 0 |
| 10475 | s_length = usl m_status_item_length |
| 10476 | upr 64 13835058055282163712 |
| 10477 | item = umsg bar s_length 0 0 0 |
| 10478 | if eq item 0 |
| 10479 | ret |
| 10480 | end |
| 10481 | item = umsg item usl m_retain 0 0 0 |
| 10482 | put g_m 52 item |
| 10483 | button = umsg item usl m_button 0 0 0 |
| 10484 | c_i = ucl c_image |
| 10485 | s_symbol = usl m_symbol_image |
| 10486 | symbol_name = uns x_status_symbol |
| 10487 | said_name = uns x_app |
| 10488 | image = umsg c_i s_symbol symbol_name said_name 0 |
| 10489 | if ne image 0 |
| 10490 | x = umsg button usl m_set_image image 0 0 |
| 10491 | end |
| 10492 | x = umsg item usl m_set_item_menu menu 0 0 |
| 10493 | center = umsg ucl c_center usl m_default_center 0 0 0 |
| 10494 | s_observe = usl m_add_observer |
| 10495 | quitting = uconst s_will_terminate |
| 10496 | upr 40 0 |
| 10497 | x = umsg center s_observe get g_o 27 get g_m 62 quitting |
| 10498 | end |
| 10499 | |
| 10500 | note what the menu of the icon tells this program (which: the selector); true when it was one of its |
| 10501 | fn ustatusevent which ulong to bool |
| 10502 | if eq which get g_m 62 |
| 10503 | utunnelstop |
| 10504 | ret true |
| 10505 | end |
| 10506 | if eq which get g_m 54 |
| 10507 | ushow |
| 10508 | ret true |
| 10509 | end |
| 10510 | if eq which get g_m 55 |
| 10511 | uindexstart |
| 10512 | ret true |
| 10513 | end |
| 10514 | if eq which get g_m 56 |
| 10515 | upasteask |
| 10516 | ret true |
| 10517 | end |
| 10518 | if eq which get g_m 57 |
| 10519 | ulogintoggle |
| 10520 | ret true |
| 10521 | end |
| 10522 | if eq which get g_m 58 |
| 10523 | usettings |
| 10524 | ret true |
| 10525 | end |
| 10526 | if eq which get g_m 59 |
| 10527 | uclipclear |
| 10528 | ret true |
| 10529 | end |
| 10530 | ret false |
| 10531 | end |
| 10532 | |
| 10533 | note the six more things this program is told by selector (entry 13 hears them all) |
| 10534 | fn ustatusmethods mine ulong to bool |
| 10535 | ok = umethod mine m_menu_open 13 t_v |
| 10536 | ok = and ok umethod mine m_menu_index 13 t_v |
| 10537 | ok = and ok umethod mine m_menu_paste 13 t_v |
| 10538 | ok = and ok umethod mine m_menu_login 13 t_v |
| 10539 | ok = and ok umethod mine m_menu_settings 13 t_v |
| 10540 | ok = and ok umethod mine m_menu_clear 13 t_v |
| 10541 | put g_m 54 usl m_menu_open |
| 10542 | put g_m 55 usl m_menu_index |
| 10543 | put g_m 56 usl m_menu_paste |
| 10544 | put g_m 57 usl m_menu_login |
| 10545 | put g_m 58 usl m_menu_settings |
| 10546 | put g_m 59 usl m_menu_clear |
| 10547 | ret ok |
| 10548 | end |
| 10549 | |
| 10550 | note ---- forwarded ports: the ssh links Hop keeps open (Sources/Factory.swift, TunnelManager) ---- |
| 10551 | note Hop's settings name ports of other computers to have on this Mac (a model's server, the factory, the |
| 10552 | note knowledge base). At the start and every 20 seconds each one whose link is not running is looked at: when |
| 10553 | note 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 |
| 10554 | note the shared connection, so it ends cleanly). A port something else serves is left alone, and so Hop and this |
| 10555 | note program do not fight over one. When this program quits it ends its links. Not here yet: dropping the links |
| 10556 | note at once when the network changes (ssh notices by itself within 45 seconds, and the link is made anew). |
| 10557 | note 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 |
| 10558 | note whole (8080.9 is no port, and Hop takes none of these either) |
| 10559 | fn uwhole obj ulong to ulong |
| 10560 | if not uisnumber obj |
| 10561 | ret 0 |
| 10562 | end |
| 10563 | yes_object = uconst s_cf_true |
| 10564 | no_object = uconst s_cf_false |
| 10565 | if or eq obj yes_object eq obj no_object |
| 10566 | ret 0 |
| 10567 | end |
| 10568 | v = umsg obj usl m_integer_value 0 0 0 |
| 10569 | same_v = umsg ucl c_number usl m_number_integer v 0 0 |
| 10570 | if eq and umsg obj usl m_is_equal_number same_v 0 0 255 0 |
| 10571 | ret 0 |
| 10572 | end |
| 10573 | ret v |
| 10574 | end |
| 10575 | |
| 10576 | note one forwarded port to keep: added to list when both ports are ports, the ssh name is there, and this Mac's |
| 10577 | note port is not in the list already |
| 10578 | fn utunneladd list ulong local ulong remote ulong host ulong to void |
| 10579 | if or or eq local 0 gt local 65535 or eq remote 0 gt remote 65535 |
| 10580 | ret |
| 10581 | end |
| 10582 | if not uiskind host 9 |
| 10583 | ret |
| 10584 | end |
| 10585 | if eq umsg host usl m_length 0 0 0 0 |
| 10586 | ret |
| 10587 | end |
| 10588 | sat = usl m_at |
| 10589 | s_whole = usl m_integer_value |
| 10590 | cnt = umsg list usl m_count 0 0 0 |
| 10591 | for i ulong cnt bound 256 |
| 10592 | if eq umsg umsg umsg list sat i 0 0 sat 0 0 0 s_whole 0 0 0 local |
| 10593 | ret |
| 10594 | end |
| 10595 | end |
| 10596 | entry = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 10597 | sadd = usl m_add_object |
| 10598 | c_n_v = ucl c_number |
| 10599 | s_number = usl m_number_integer |
| 10600 | x = umsg entry sadd umsg c_n_v s_number local 0 0 0 0 |
| 10601 | x = umsg entry sadd umsg c_n_v s_number remote 0 0 0 0 |
| 10602 | x = umsg entry sadd host 0 0 |
| 10603 | x = umsg list sadd entry 0 0 |
| 10604 | end |
| 10605 | |
| 10606 | note the forwarded ports of the settings: the ones named there, and the one to the knowledge base when it runs |
| 10607 | note on another computer |
| 10608 | fn utunnelsload config ulong to void |
| 10609 | links = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 10610 | if ne config 0 |
| 10611 | named = ukeyed config k_tunnels |
| 10612 | if uiskind named 8 |
| 10613 | sat = usl m_at |
| 10614 | cnt = umsg named usl m_count 0 0 0 |
| 10615 | for i ulong cnt bound 256 |
| 10616 | t = umsg named sat i 0 0 |
| 10617 | if uiskind t 7 |
| 10618 | utunneladd links uwhole ukeyed t k_local_port uwhole ukeyed t k_remote_port ukeyed t k_ssh_host |
| 10619 | end |
| 10620 | end |
| 10621 | end |
| 10622 | cx = ukeyed config k_cortex |
| 10623 | if uiskind cx 7 |
| 10624 | if uyes ukeyed cx k_enabled |
| 10625 | address = ukeyed cx k_url |
| 10626 | if uiskind address 9 |
| 10627 | url = umsg ucl c_url usl m_urlstr address 0 0 |
| 10628 | if ne url 0 |
| 10629 | utunneladd links uwhole umsg url usl m_url_port 0 0 0 uwhole ukeyed cx k_remote_port ukeyed cx k_host |
| 10630 | end |
| 10631 | end |
| 10632 | end |
| 10633 | end |
| 10634 | end |
| 10635 | if ne get g_m 60 0 |
| 10636 | x = umsg get g_m 60 usl m_release 0 0 0 |
| 10637 | end |
| 10638 | put g_m 60 umsg links usl m_retain 0 0 0 |
| 10639 | put g_n 62 umsg links usl m_count 0 0 0 |
| 10640 | if eq get g_m 61 0 |
| 10641 | running = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 10642 | put g_m 61 umsg running usl m_retain 0 0 0 |
| 10643 | asking = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 10644 | put g_m 63 umsg asking usl m_retain 0 0 0 |
| 10645 | end |
| 10646 | end |
| 10647 | |
| 10648 | note start the ssh link for one forwarded port (a check starts its stand-in, never ssh itself) |
| 10649 | fn utunnelstart local ulong remote ulong host ulong to void |
| 10650 | tool = uns x_real_ssh |
| 10651 | if eq get g_n 14 0 |
| 10652 | n = ucs x_env_ssh |
| 10653 | upr 0 ulong libptr g_nm 0 1024 |
| 10654 | given = ucall 9 |
| 10655 | if eq given 0 |
| 10656 | ret |
| 10657 | end |
| 10658 | n = ufetch given |
| 10659 | tool = unsb |
| 10660 | end |
| 10661 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 10662 | if eq and umsg manager usl m_is_executable tool 0 0 255 0 |
| 10663 | ret |
| 10664 | end |
| 10665 | arguments = umsg uwords x_tunnel_args usl m_mutable_copy 0 0 0 |
| 10666 | p = uptxt 0 x_loopback |
| 10667 | p = upnum p local |
| 10668 | put g_nm p 58 |
| 10669 | p = uptxt add p 1 x_loopback |
| 10670 | p = upnum p remote |
| 10671 | put g_nm p 0 |
| 10672 | forward = unsb |
| 10673 | sadd = usl m_add_object |
| 10674 | x = umsg arguments sadd forward 0 0 |
| 10675 | x = umsg arguments sadd host 0 0 |
| 10676 | task = umsg umsg ucl c_task usl m_alloc 0 0 0 usl m_init 0 0 0 |
| 10677 | x = umsg task usl m_set_launch tool 0 0 |
| 10678 | x = umsg task usl m_set_arguments arguments 0 0 |
| 10679 | quiet = umsg ucl c_file_handle usl m_null_device 0 0 0 |
| 10680 | x = umsg task usl m_set_output quiet 0 0 |
| 10681 | x = umsg task usl m_set_error quiet 0 0 |
| 10682 | x = umsg task usl m_set_input quiet 0 0 |
| 10683 | x = umsg task usl m_launch 0 0 0 |
| 10684 | put g_n 61 add get g_n 61 1 |
| 10685 | c_n_v = ucl c_number |
| 10686 | s_number = usl m_number_integer |
| 10687 | port_key = umsg c_n_v s_number local 0 0 |
| 10688 | x = umsg get g_m 61 usl m_set_object task port_key 0 |
| 10689 | note the list of this Mac's links keeps the program now, and the program its words |
| 10690 | srel = usl m_release |
| 10691 | x = umsg task srel 0 0 0 |
| 10692 | x = umsg arguments srel 0 0 0 |
| 10693 | end |
| 10694 | |
| 10695 | note is the link of this Mac's port running |
| 10696 | fn utunnelalive port_key ulong to bool |
| 10697 | task = umsg get g_m 61 usl m_object_for_key port_key 0 0 |
| 10698 | if eq task 0 |
| 10699 | ret false |
| 10700 | end |
| 10701 | ret eq and umsg task usl m_is_running 0 0 0 255 1 |
| 10702 | end |
| 10703 | |
| 10704 | note ask whether something on this Mac serves the port: nc tries it for two seconds at most, as a program of its |
| 10705 | note own, so this program never waits on a port that does not answer (Hop asks with a two second limit too). |
| 10706 | note probeDone: is told when it has ended |
| 10707 | fn uprobestart local ulong port_key ulong to void |
| 10708 | tool = uns x_nc |
| 10709 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 10710 | if eq and umsg manager usl m_is_executable tool 0 0 255 0 |
| 10711 | ret |
| 10712 | end |
| 10713 | arguments = umsg uwords x_nc_args usl m_mutable_copy 0 0 0 |
| 10714 | p = upnum 0 local |
| 10715 | put g_nm p 0 |
| 10716 | port_text = unsb |
| 10717 | x = umsg arguments usl m_add_object port_text 0 0 |
| 10718 | task = umsg umsg ucl c_task usl m_alloc 0 0 0 usl m_init 0 0 0 |
| 10719 | x = umsg task usl m_set_launch tool 0 0 |
| 10720 | x = umsg task usl m_set_arguments arguments 0 0 |
| 10721 | quiet = umsg ucl c_file_handle usl m_null_device 0 0 0 |
| 10722 | x = umsg task usl m_set_output quiet 0 0 |
| 10723 | x = umsg task usl m_set_error quiet 0 0 |
| 10724 | x = umsg task usl m_set_input quiet 0 0 |
| 10725 | center = umsg ucl c_center usl m_default_center 0 0 0 |
| 10726 | s_observe = usl m_add_observer |
| 10727 | ended = uconst s_task_ended |
| 10728 | upr 40 task |
| 10729 | x = umsg center s_observe get g_o 27 get g_m 64 ended |
| 10730 | x = umsg get g_m 63 usl m_set_object task port_key 0 |
| 10731 | x = umsg task usl m_launch 0 0 0 |
| 10732 | note the list of askers keeps the program now, and the program its words |
| 10733 | srel = usl m_release |
| 10734 | x = umsg task srel 0 0 0 |
| 10735 | x = umsg arguments srel 0 0 0 |
| 10736 | end |
| 10737 | |
| 10738 | note the asking has ended (about: the notice, whose object is the program that asked). A port nothing serves, |
| 10739 | note whose link is still not running, gets its link |
| 10740 | fn uprobedone about ulong to void |
| 10741 | if or eq about 0 eq get g_m 63 0 |
| 10742 | ret |
| 10743 | end |
| 10744 | task = umsg about usl m_note_object 0 0 0 |
| 10745 | if eq task 0 |
| 10746 | ret |
| 10747 | end |
| 10748 | x = umsg task usl m_retain 0 0 0 |
| 10749 | center = umsg ucl c_center usl m_default_center 0 0 0 |
| 10750 | x = umsg center usl m_remove_all_observer get g_o 27 0 task |
| 10751 | served = eq and umsg task usl m_termination 0 0 0 4294967295 0 |
| 10752 | port_keys = umsg get g_m 63 usl m_all_keys_for task 0 0 |
| 10753 | sat = usl m_at |
| 10754 | s_whole = usl m_integer_value |
| 10755 | s_drop = usl m_remove_for_key |
| 10756 | links = get g_m 60 |
| 10757 | cnt = umsg port_keys usl m_count 0 0 0 |
| 10758 | for i ulong cnt bound 16 |
| 10759 | port_key = umsg port_keys sat i 0 0 |
| 10760 | local = umsg port_key s_whole 0 0 0 |
| 10761 | x = umsg get g_m 63 s_drop port_key 0 0 |
| 10762 | if and not served ne links 0 |
| 10763 | if not utunnelalive port_key |
| 10764 | many = umsg links usl m_count 0 0 0 |
| 10765 | for j ulong many bound 256 |
| 10766 | entry = umsg links sat j 0 0 |
| 10767 | if eq umsg umsg entry sat 0 0 0 s_whole 0 0 0 local |
| 10768 | utunnelstart local umsg umsg entry sat 1 0 0 s_whole 0 0 0 umsg entry sat 2 0 0 |
| 10769 | end |
| 10770 | end |
| 10771 | end |
| 10772 | end |
| 10773 | end |
| 10774 | x = umsg task usl m_release 0 0 0 |
| 10775 | end |
| 10776 | |
| 10777 | note look at every forwarded port: for one whose link is not running, and that is not being asked about already, |
| 10778 | note it is asked whether something serves the port |
| 10779 | fn utunnelcheck to void |
| 10780 | links = get g_m 60 |
| 10781 | if or or eq links 0 eq get g_m 61 0 eq get g_m 63 0 |
| 10782 | ret |
| 10783 | end |
| 10784 | if not uremoteok |
| 10785 | ret |
| 10786 | end |
| 10787 | sat = usl m_at |
| 10788 | s_whole = usl m_integer_value |
| 10789 | s_keyed = usl m_object_for_key |
| 10790 | c_n_v = ucl c_number |
| 10791 | s_number = usl m_number_integer |
| 10792 | cnt = umsg links usl m_count 0 0 0 |
| 10793 | for i ulong cnt bound 256 |
| 10794 | entry = umsg links sat i 0 0 |
| 10795 | local = umsg umsg entry sat 0 0 0 s_whole 0 0 0 |
| 10796 | port_key = umsg c_n_v s_number local 0 0 |
| 10797 | if not utunnelalive port_key |
| 10798 | if eq umsg get g_m 63 s_keyed port_key 0 0 0 |
| 10799 | uprobestart local port_key |
| 10800 | end |
| 10801 | end |
| 10802 | end |
| 10803 | end |
| 10804 | |
| 10805 | note twice a second: every 20 seconds, and half a second after the start, the forwarded ports are looked at |
| 10806 | fn utunneltick to void |
| 10807 | ticks = get g_n 60 |
| 10808 | put g_n 60 add ticks 1 |
| 10809 | if eq sub ticks mul div ticks 40 40 0 |
| 10810 | utunnelcheck |
| 10811 | end |
| 10812 | end |
| 10813 | |
| 10814 | note this program is ending (quitting, or a check at its end): its links and its askers end with it |
| 10815 | fn utunnelstop to void |
| 10816 | sat = usl m_at |
| 10817 | s_running = usl m_is_running |
| 10818 | s_end = usl m_terminate_task |
| 10819 | s_values = usl m_all_values |
| 10820 | for which ulong 2 |
| 10821 | kept = get g_m 61 |
| 10822 | if eq which 1 |
| 10823 | kept = get g_m 63 |
| 10824 | end |
| 10825 | if ne kept 0 |
| 10826 | tasks = umsg kept s_values 0 0 0 |
| 10827 | cnt = umsg tasks usl m_count 0 0 0 |
| 10828 | for i ulong cnt bound 256 |
| 10829 | task = umsg tasks sat i 0 0 |
| 10830 | if eq and umsg task s_running 0 0 0 255 1 |
| 10831 | x = umsg task s_end 0 0 0 |
| 10832 | end |
| 10833 | end |
| 10834 | end |
| 10835 | end |
| 10836 | end |
| 10837 | |
| 10838 | note hear when this program is about to quit (appQuit:) and when a port has been asked about (probeDone:) |
| 10839 | fn uquitwatch mine ulong to bool |
| 10840 | ok = umethod mine m_app_quit 13 t_v |
| 10841 | ok = and ok umethod mine m_probe_done 13 t_v |
| 10842 | put g_m 62 usl m_app_quit |
| 10843 | put g_m 64 usl m_probe_done |
| 10844 | ret ok |
| 10845 | end |
| 10846 | |
| 10847 | note ---- screens: the list shows one kind of thing, and typing looks in it ---- |
| 10848 | note the copied things: all of them, pinned first, or the ones that have every typed word |
| 10849 | fn uscreenclips to void |
| 10850 | uclipmatch 1024 |
| 10851 | h = get g_n 28 |
| 10852 | for i ulong h bound 1024 |
| 10853 | put g_rk i 6 |
| 10854 | put g_hit i get g_cm i |
| 10855 | put g_why i 0 |
| 10856 | end |
| 10857 | put g_n 1 h |
| 10858 | end |
| 10859 | |
| 10860 | note the saved accounts: all of them, or the ones whose name has the typed text |
| 10861 | fn uscreenaccounts to void |
| 10862 | nacc = get g_n 31 |
| 10863 | a = get g_n 12 |
| 10864 | n = get g_n 13 |
| 10865 | typed_low = ulong 0 |
| 10866 | if and gt n 0 le n 255 |
| 10867 | for i ulong n bound 256 |
| 10868 | put g_nm i get g_q add a i |
| 10869 | end |
| 10870 | put g_nm n 0 |
| 10871 | typed = unsb |
| 10872 | if ne typed 0 |
| 10873 | typed_low = umsg typed usl m_lowercase 0 0 0 |
| 10874 | end |
| 10875 | end |
| 10876 | slower = usl m_lowercase |
| 10877 | scontains = usl m_contains |
| 10878 | h = ulong 0 |
| 10879 | for i ulong nacc bound 800 |
| 10880 | keep = true |
| 10881 | if gt n 0 |
| 10882 | keep = false |
| 10883 | if ne typed_low 0 |
| 10884 | name_low = umsg umsg get g_m 18 get g_m 16 i 0 0 slower 0 0 0 |
| 10885 | keep = eq and umsg name_low scontains typed_low 0 0 255 1 |
| 10886 | end |
| 10887 | end |
| 10888 | if keep |
| 10889 | put g_rk h 5 |
| 10890 | put g_hit h i |
| 10891 | put g_why h 0 |
| 10892 | h = add h 1 |
| 10893 | end |
| 10894 | end |
| 10895 | put g_n 1 h |
| 10896 | end |
| 10897 | |
| 10898 | note show screen number which (0: everything again): the field is emptied and the list made anew |
| 10899 | fn uscreen which ulong to void |
| 10900 | put g_n 36 which |
| 10901 | put g_nm 0 0 |
| 10902 | x = umsg get g_o 0 get g_o 8 unsb 0 0 |
| 10903 | utyped |
| 10904 | end |
| 10905 | |
| 10906 | note make the list anew from what is known now, keeping the first row selected |
| 10907 | fn urefresh to void |
| 10908 | unarrow |
| 10909 | x = umsg get g_o 1 get g_o 7 0 0 0 |
| 10910 | put g_n 6 0 |
| 10911 | if gt get g_n 1 0 |
| 10912 | uchoose 0 |
| 10913 | end |
| 10914 | ushowst |
| 10915 | end |
| 10916 | |
| 10917 | note pin or unpin (what 1) or delete (what 2) copied thing i in the history, then show the history as it is now. |
| 10918 | note Like recording it is this program's to do only while Hop is not running |
| 10919 | fn uclipedit i ulong what ulong to void |
| 10920 | if ge i get g_n 24 |
| 10921 | ret |
| 10922 | end |
| 10923 | if and eq get g_n 14 1 uhoprunning |
| 10924 | ret |
| 10925 | end |
| 10926 | shown_item = umsg get g_m 14 get g_m 16 i 0 0 |
| 10927 | if not uiskind shown_item 7 |
| 10928 | ret |
| 10929 | end |
| 10930 | id_text = ukeyed shown_item k_id |
| 10931 | if not uiskind id_text 9 |
| 10932 | ret |
| 10933 | end |
| 10934 | items = uclipsmutable |
| 10935 | if eq items 0 |
| 10936 | ret |
| 10937 | end |
| 10938 | sat = usl m_at |
| 10939 | sequal = usl m_equal_string |
| 10940 | cnt = umsg items usl m_count 0 0 0 |
| 10941 | found = cnt |
| 10942 | for j ulong cnt bound 100000 |
| 10943 | if eq found cnt |
| 10944 | e = umsg items sat j 0 0 |
| 10945 | if uiskind e 7 |
| 10946 | other_id = ukeyed e k_id |
| 10947 | if uiskind other_id 9 |
| 10948 | if eq and umsg other_id sequal id_text 0 0 255 1 |
| 10949 | found = j |
| 10950 | end |
| 10951 | end |
| 10952 | end |
| 10953 | end |
| 10954 | end |
| 10955 | if eq found cnt |
| 10956 | ret |
| 10957 | end |
| 10958 | e = umsg items sat found 0 0 |
| 10959 | if eq what 1 |
| 10960 | flip = ulong 1 |
| 10961 | if uclippinned e |
| 10962 | flip = 0 |
| 10963 | end |
| 10964 | flag = umsg ucl c_number usl m_number_bool flip 0 0 |
| 10965 | x = umsg e usl m_set_object flag uns k_pinned 0 |
| 10966 | else |
| 10967 | image_name = ukeyed e k_image |
| 10968 | if uiskind image_name 9 |
| 10969 | if ne and umsg image_name usl m_contains uns x_slash_text 0 0 255 1 |
| 10970 | folder = uhoppath x_clip_images |
| 10971 | if ne folder 0 |
| 10972 | gone = umsg folder usl m_append_string image_name 0 0 |
| 10973 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 10974 | x = umsg manager usl m_remove_item gone 0 0 |
| 10975 | end |
| 10976 | end |
| 10977 | end |
| 10978 | x = umsg items usl m_remove_at found 0 0 |
| 10979 | end |
| 10980 | if eq uclipswrite items 1 |
| 10981 | uloadclips |
| 10982 | urefresh |
| 10983 | end |
| 10984 | end |
| 10985 | |
| 10986 | note the menu's Pin or Unpin and Delete from History: on the selected row when it is a copied thing |
| 10987 | fn uclipmenu what ulong to void |
| 10988 | r = get g_n 6 |
| 10989 | if or ge r get g_n 1 ne ulong get g_rk r 6 |
| 10990 | ret |
| 10991 | end |
| 10992 | uclipedit get g_hit r what |
| 10993 | end |
| 10994 | |
| 10995 | note open Hop's settings file in TextEdit, as Hop does (a check: with the program macOS has for it). When there |
| 10996 | note is no settings file yet an empty one is made, which Hop reads as all its built-in settings |
| 10997 | fn usettings to void |
| 10998 | path = uhoppath x_config |
| 10999 | if eq path 0 |
| 11000 | ret |
| 11001 | end |
| 11002 | url = umsg ucl c_url usl m_furl path 0 0 |
| 11003 | ws = umsg ucl c_ws usl m_shws 0 0 0 |
| 11004 | if eq get g_n 14 0 |
| 11005 | put g_n 9 and umsg ws usl m_open url 0 0 255 |
| 11006 | ret |
| 11007 | end |
| 11008 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 11009 | if eq and umsg manager usl m_file_exists path 0 0 255 0 |
| 11010 | d = umsg uns x_empty_settings usl m_data_using 4 0 0 |
| 11011 | x = umsg d usl m_write_file path 1 0 |
| 11012 | upr 0 umsg path get g_o 5 0 0 0 |
| 11013 | upr 8 384 |
| 11014 | x = ucall 16 |
| 11015 | end |
| 11016 | urls = umsg ucl c_array usl m_array_with url 0 0 |
| 11017 | editor = umsg ucl c_url usl m_furl uns x_textedit 0 0 |
| 11018 | how = umsg ucl c_open_config usl m_configuration 0 0 0 |
| 11019 | s_open = usl m_open_urls_with |
| 11020 | upr 40 0 |
| 11021 | x = umsg ws s_open urls editor how |
| 11022 | put g_n 9 1 |
| 11023 | end |
| 11024 | |
| 11025 | note the rows to show: a screen's own, else what is offered when nothing is typed, else what the one box's |
| 11026 | note rules give for the text |
| 11027 | fn unarrow to void |
| 11028 | if eq get g_n 36 1 |
| 11029 | uscreenclips |
| 11030 | ret |
| 11031 | end |
| 11032 | if eq get g_n 36 2 |
| 11033 | uscreenaccounts |
| 11034 | ret |
| 11035 | end |
| 11036 | if eq get g_n 13 0 |
| 11037 | usuggest |
| 11038 | ret |
| 11039 | end |
| 11040 | m = ulong 0 |
| 11041 | for k ulong get g_n 0 bound 2048 |
| 11042 | s = uscore k |
| 11043 | if gt s 0 |
| 11044 | put g_mk m k |
| 11045 | put g_ms m sub s 1 |
| 11046 | m = add m 1 |
| 11047 | end |
| 11048 | end |
| 11049 | usearch |
| 11050 | urankrows m |
| 11051 | end |
| 11052 | |
| 11053 | note "H of N apps" into the status line |
| 11054 | fn ushowst to void |
| 11055 | p = upnum 0 get g_n 1 |
| 11056 | if eq get g_n 36 0 |
| 11057 | p = uptxt p x_of |
| 11058 | p = upnum p get g_n 0 |
| 11059 | p = uptxt p x_apps |
| 11060 | end |
| 11061 | if eq get g_n 36 1 |
| 11062 | p = uptxt p x_copied_things |
| 11063 | end |
| 11064 | if eq get g_n 36 2 |
| 11065 | p = uptxt p x_accounts_word |
| 11066 | end |
| 11067 | if ne get g_m 23 0 |
| 11068 | p = uptxt p x_indexing |
| 11069 | end |
| 11070 | p = uremotenote p |
| 11071 | put g_nm p 0 |
| 11072 | str = unsb |
| 11073 | x = umsg get g_o 2 get g_o 8 str 0 0 |
| 11074 | end |
| 11075 | |
| 11076 | note select row r of the list and bring it into view |
| 11077 | fn uchoose r ulong to void |
| 11078 | put g_n 6 r |
| 11079 | ix = umsg get g_o 13 get g_o 14 r 0 0 |
| 11080 | x = umsg get g_o 1 get g_o 12 ix 0 0 |
| 11081 | x = umsg get g_o 1 get g_o 15 r 0 0 |
| 11082 | end |
| 11083 | |
| 11084 | note what the list shows was typed into the field: read it, narrow, show |
| 11085 | fn utyped to void |
| 11086 | uaskstop |
| 11087 | str = umsg get g_o 0 get g_o 6 0 0 0 |
| 11088 | p = umsg str get g_o 5 0 0 0 |
| 11089 | n = ufetch p |
| 11090 | if gt n 255 |
| 11091 | n = 255 |
| 11092 | end |
| 11093 | for i ulong n bound 256 |
| 11094 | put g_q i get g_nm i |
| 11095 | end |
| 11096 | put g_n 4 n |
| 11097 | a = ulong 0 |
| 11098 | while lt a n bound 256 |
| 11099 | c = ulong get g_q a |
| 11100 | if and ne c 32 ne c 9 |
| 11101 | break |
| 11102 | end |
| 11103 | a = add a 1 |
| 11104 | end |
| 11105 | e = n |
| 11106 | while gt e a bound 256 |
| 11107 | c = ulong get g_q sub e 1 |
| 11108 | if and ne c 32 ne c 9 |
| 11109 | break |
| 11110 | end |
| 11111 | e = sub e 1 |
| 11112 | end |
| 11113 | put g_n 12 a |
| 11114 | put g_n 13 sub e a |
| 11115 | udecide |
| 11116 | uremotesoon |
| 11117 | unarrow |
| 11118 | x = umsg get g_o 1 get g_o 7 0 0 0 |
| 11119 | put g_n 6 0 |
| 11120 | if gt get g_n 1 0 |
| 11121 | uchoose 0 |
| 11122 | end |
| 11123 | ushowst |
| 11124 | end |
| 11125 | |
| 11126 | note open app k: its folder, "/", its name and ".app" as a file address, handed to the workspace |
| 11127 | fn ulaunch k ulong to void |
| 11128 | p = ulong 0 |
| 11129 | if eq ulong get g_dir k 0 |
| 11130 | p = uptxt 0 x_dir1 |
| 11131 | else |
| 11132 | p = uptxt 0 x_dir2 |
| 11133 | end |
| 11134 | p = uptxt p x_slash |
| 11135 | p = upname p k |
| 11136 | p = uptxt p x_dotapp |
| 11137 | put g_nm p 0 |
| 11138 | str = unsb |
| 11139 | c = ucl c_url |
| 11140 | s = usl m_furl |
| 11141 | url = umsg c s str 0 0 |
| 11142 | c = ucl c_ws |
| 11143 | s = usl m_shws |
| 11144 | ws = umsg c s 0 0 0 |
| 11145 | s = usl m_open |
| 11146 | put g_n 9 and umsg ws s url 0 0 255 |
| 11147 | end |
| 11148 | |
| 11149 | note open the web address the typed text stands for |
| 11150 | fn uopenaddr to void |
| 11151 | p = upaddr 0 |
| 11152 | put g_nm p 0 |
| 11153 | str = unsb |
| 11154 | u = umsg get g_o 16 get g_o 17 str 0 0 |
| 11155 | c = ucl c_ws |
| 11156 | s = usl m_shws |
| 11157 | ws = umsg c s 0 0 0 |
| 11158 | s = usl m_open |
| 11159 | put g_n 9 and umsg ws s u 0 0 255 |
| 11160 | end |
| 11161 | |
| 11162 | note ---- copied things: Hop's encrypted clipboard history (Sources/Clipboard.swift), read and never written ---- |
| 11163 | note The history is one file, sealed with AES-256-GCM (the core's fn gcunlock) under a key that Hop keeps in the |
| 11164 | note login Keychain as an item of Apple's security tool and reads through that tool; the panel reads it the same |
| 11165 | note way. The key and the unsealed bytes are wiped from the core's buffers as soon as they are used. The panel |
| 11166 | note only reads the history: Hop, when it runs, is the one that keeps it, and it sees what the panel puts on |
| 11167 | note the clipboard like anything else that is copied. A check (HOPCHECK) never asks the tool and never touches |
| 11168 | note the real clipboard: it takes the key from HOPCLIPKEY and pastes into a board of its own. |
| 11169 | note the clipboard key into the core's c_k; 1 when it is there |
| 11170 | fn uclipkey to ulong |
| 11171 | encoded = ulong 0 |
| 11172 | item_name = ulong 0 |
| 11173 | if eq get g_n 14 0 |
| 11174 | n = ucs x_env_clipkey |
| 11175 | upr 0 ulong libptr g_nm 0 1024 |
| 11176 | key_text = ucall 9 |
| 11177 | if eq key_text 0 |
| 11178 | ret 0 |
| 11179 | end |
| 11180 | n = ufetch key_text |
| 11181 | if and and gt n 5 eq get g_nm 0 116 and eq get g_nm 3 108 eq get g_nm 4 58 |
| 11182 | for i ulong sub n 5 bound 1024 |
| 11183 | put g_nm i get g_nm add 5 i |
| 11184 | end |
| 11185 | put g_nm sub n 5 0 |
| 11186 | item_name = unsb |
| 11187 | else |
| 11188 | encoded = unsb |
| 11189 | end |
| 11190 | else |
| 11191 | item_name = uns x_clip_service |
| 11192 | end |
| 11193 | if ne item_name 0 |
| 11194 | task = umsg ucl c_task usl m_alloc 0 0 0 |
| 11195 | task = umsg task usl m_init 0 0 0 |
| 11196 | x = umsg task usl m_set_launch uns x_security 0 0 |
| 11197 | arguments = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 11198 | sadd = usl m_add_object |
| 11199 | x = umsg arguments sadd uns x_find 0 0 |
| 11200 | x = umsg arguments sadd uns x_dash_s 0 0 |
| 11201 | x = umsg arguments sadd item_name 0 0 |
| 11202 | x = umsg arguments sadd uns x_dash_a 0 0 |
| 11203 | x = umsg arguments sadd uns x_clip_account 0 0 |
| 11204 | x = umsg arguments sadd uns x_dash_w 0 0 |
| 11205 | x = umsg task usl m_set_arguments arguments 0 0 |
| 11206 | tube = umsg ucl c_pipe usl m_pipe 0 0 0 |
| 11207 | x = umsg task usl m_set_output tube 0 0 |
| 11208 | quiet = umsg ucl c_file_handle usl m_null_device 0 0 0 |
| 11209 | x = umsg task usl m_set_error quiet 0 0 |
| 11210 | x = umsg task usl m_launch 0 0 0 |
| 11211 | reader = umsg tube usl m_reading 0 0 0 |
| 11212 | d = umsg reader usl m_read_end 0 0 0 |
| 11213 | x = umsg task usl m_wait 0 0 0 |
| 11214 | if ne and umsg task usl m_termination 0 0 0 4294967295 0 |
| 11215 | ret 0 |
| 11216 | end |
| 11217 | if eq d 0 |
| 11218 | ret 0 |
| 11219 | end |
| 11220 | whole = umsg ucl c_str usl m_alloc 0 0 0 |
| 11221 | whole = umsg whole usl m_init_data_encoding d 4 0 |
| 11222 | if eq whole 0 |
| 11223 | ret 0 |
| 11224 | end |
| 11225 | blanks = umsg ucl c_charset usl m_whitespace 0 0 0 |
| 11226 | encoded = umsg whole usl m_trim blanks 0 0 |
| 11227 | end |
| 11228 | if eq encoded 0 |
| 11229 | ret 0 |
| 11230 | end |
| 11231 | kd = umsg ucl c_data usl m_alloc 0 0 0 |
| 11232 | kd = umsg kd usl m_init_base64 encoded 0 0 |
| 11233 | if eq kd 0 |
| 11234 | ret 0 |
| 11235 | end |
| 11236 | if ne umsg kd usl m_length 0 0 0 32 |
| 11237 | ret 0 |
| 11238 | end |
| 11239 | src = umsg kd usl m_bytes 0 0 0 |
| 11240 | upr 0 ulong libptr c_k 0 32 |
| 11241 | upr 8 src |
| 11242 | upr 16 32 |
| 11243 | x = ucall 8 |
| 11244 | ret 1 |
| 11245 | end |
| 11246 | |
| 11247 | note wipe the first m unsealed bytes of the core's buffer |
| 11248 | fn uforget m ulong to void |
| 11249 | if eq m 0 |
| 11250 | ret |
| 11251 | end |
| 11252 | upr 0 ulong libptr c_d 0 m |
| 11253 | upr 8 0 |
| 11254 | upr 16 m |
| 11255 | x = ucall 17 |
| 11256 | end |
| 11257 | |
| 11258 | note the sealed bytes of d (an NSData: the nonce, the data, the tag) unsealed into the core's c_d with the |
| 11259 | note clipboard key; the count of data bytes plus 1, or 0 when it cannot be done (no key, or not sealed by it) |
| 11260 | fn uunseal d ulong to ulong |
| 11261 | n = umsg d usl m_length 0 0 0 |
| 11262 | if or lt n 28 gt n 16777244 |
| 11263 | ret 0 |
| 11264 | end |
| 11265 | src = umsg d usl m_bytes 0 0 0 |
| 11266 | if eq uclipkey 0 |
| 11267 | ret 0 |
| 11268 | end |
| 11269 | m = sub n 28 |
| 11270 | upr 0 ulong libptr c_n 0 12 |
| 11271 | upr 8 src |
| 11272 | upr 16 12 |
| 11273 | x = ucall 8 |
| 11274 | if gt m 0 |
| 11275 | upr 0 ulong libptr c_d 0 m |
| 11276 | upr 8 add src 12 |
| 11277 | upr 16 m |
| 11278 | x = ucall 8 |
| 11279 | end |
| 11280 | upr 0 ulong libptr c_tg 0 16 |
| 11281 | upr 8 add src sub n 16 |
| 11282 | upr 16 16 |
| 11283 | x = ucall 8 |
| 11284 | good = gcunlock m |
| 11285 | gcwipe |
| 11286 | if eq good 0 |
| 11287 | ret 0 |
| 11288 | end |
| 11289 | ret add m 1 |
| 11290 | end |
| 11291 | |
| 11292 | note the text a copied thing is shown by: its text without the blanks around it, a mark where a line ends, the |
| 11293 | note first 80 characters; "Image" for a picture |
| 11294 | fn uclippreview item ulong to ulong |
| 11295 | if not uiskind item 7 |
| 11296 | ret uns x_image |
| 11297 | end |
| 11298 | words = ukeyed item k_text |
| 11299 | if not uiskind words 9 |
| 11300 | ret uns x_image |
| 11301 | end |
| 11302 | blanks = umsg ucl c_charset usl m_whitespace 0 0 0 |
| 11303 | t = umsg words usl m_trim blanks 0 0 |
| 11304 | put g_nm 0 10 |
| 11305 | put g_nm 1 0 |
| 11306 | line_end = unsb |
| 11307 | put g_nm 0 32 |
| 11308 | put g_nm 1 226 |
| 11309 | put g_nm 2 143 |
| 11310 | put g_nm 3 142 |
| 11311 | put g_nm 4 32 |
| 11312 | put g_nm 5 0 |
| 11313 | mark = unsb |
| 11314 | t = umsg t usl m_replace line_end mark 0 |
| 11315 | if gt umsg t usl m_length 0 0 0 80 |
| 11316 | cut = umsg t usl m_composed_at 80 0 0 |
| 11317 | t = umsg t usl m_substring_to cut 0 0 |
| 11318 | end |
| 11319 | ret t |
| 11320 | end |
| 11321 | |
| 11322 | note read the history: the copied things, the text each is shown by, which are pinned, and the order they are |
| 11323 | note 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 |
| 11324 | fn uloadclips to void |
| 11325 | put g_n 24 0 |
| 11326 | d = uhopfile x_clipboard_file |
| 11327 | if eq d 0 |
| 11328 | ret |
| 11329 | end |
| 11330 | r = uunseal d |
| 11331 | if le r 1 |
| 11332 | ret |
| 11333 | end |
| 11334 | m = sub r 1 |
| 11335 | plain = umsg ucl c_data usl m_data_bytes ulong libptr c_d 0 m m 0 |
| 11336 | uforget m |
| 11337 | items = umsg ucl c_json usl m_json_object plain 0 0 |
| 11338 | if not uiskind items 8 |
| 11339 | ret |
| 11340 | end |
| 11341 | cnt = umsg items usl m_count 0 0 0 |
| 11342 | if gt cnt 1024 |
| 11343 | cnt = 1024 |
| 11344 | end |
| 11345 | sret = usl m_retain |
| 11346 | srel = usl m_release |
| 11347 | if ne get g_m 14 0 |
| 11348 | x = umsg get g_m 14 srel 0 0 0 |
| 11349 | x = umsg get g_m 15 srel 0 0 0 |
| 11350 | end |
| 11351 | put g_m 14 umsg items sret 0 0 0 |
| 11352 | shown_by = umsg ucl c_mutable_array usl m_array 0 0 0 |
| 11353 | put g_m 15 umsg shown_by sret 0 0 0 |
| 11354 | sat = usl m_at |
| 11355 | put g_m 16 sat |
| 11356 | sadd = usl m_add_object |
| 11357 | for i ulong cnt bound 1024 |
| 11358 | item = umsg items sat i 0 0 |
| 11359 | pv = uclippreview item |
| 11360 | x = umsg shown_by sadd pv 0 0 |
| 11361 | put g_cp i 0 |
| 11362 | if uiskind item 7 |
| 11363 | pin = ukeyed item k_pinned |
| 11364 | if uisnumber pin |
| 11365 | if eq and umsg pin usl m_bool_value 0 0 0 255 1 |
| 11366 | put g_cp i 1 |
| 11367 | end |
| 11368 | end |
| 11369 | end |
| 11370 | end |
| 11371 | pos = ulong 0 |
| 11372 | for i ulong cnt bound 1024 |
| 11373 | if eq ulong get g_cp i 1 |
| 11374 | put g_ci pos i |
| 11375 | pos = add pos 1 |
| 11376 | end |
| 11377 | end |
| 11378 | for i ulong cnt bound 1024 |
| 11379 | if eq ulong get g_cp i 0 |
| 11380 | put g_ci pos i |
| 11381 | pos = add pos 1 |
| 11382 | end |
| 11383 | end |
| 11384 | put g_n 24 cnt |
| 11385 | end |
| 11386 | |
| 11387 | note the text copied thing i is shown by into g_nm from byte p; the byte after it |
| 11388 | fn uclipname p ulong i ulong to ulong |
| 11389 | if or ge i get g_n 24 ge p 900 |
| 11390 | ret p |
| 11391 | end |
| 11392 | pv = umsg get g_m 15 get g_m 16 i 0 0 |
| 11393 | src = umsg pv get g_o 5 0 0 0 |
| 11394 | if eq src 0 |
| 11395 | ret p |
| 11396 | end |
| 11397 | upr 0 src |
| 11398 | n = ucall 7 |
| 11399 | if gt add p n 900 |
| 11400 | n = sub 900 p |
| 11401 | end |
| 11402 | if eq n 0 |
| 11403 | ret p |
| 11404 | end |
| 11405 | upr 0 ulong libptr g_nm p n |
| 11406 | upr 8 src |
| 11407 | upr 16 n |
| 11408 | x = ucall 8 |
| 11409 | ret add p n |
| 11410 | end |
| 11411 | |
| 11412 | note the newest copied thing's text takes the place of the typed text (on 1) so that the address helpers work on |
| 11413 | note it, and gives it back (on 0). Only used while nothing is typed |
| 11414 | fn uclipaddr on ulong to void |
| 11415 | if eq on 1 |
| 11416 | n = get g_n 25 |
| 11417 | for i ulong n bound 256 |
| 11418 | put g_q i get g_ca i |
| 11419 | end |
| 11420 | put g_n 12 0 |
| 11421 | put g_n 13 n |
| 11422 | put g_n 10 get g_n 26 |
| 11423 | else |
| 11424 | put g_n 13 0 |
| 11425 | put g_n 10 0 |
| 11426 | end |
| 11427 | end |
| 11428 | |
| 11429 | note the copied things that match the typed text, as Hop's search does: the pinned ones first, each in lower |
| 11430 | note case has to contain every typed word (a picture counts as "image"); the first "most" of them into g_cm |
| 11431 | note (for a whole screen with nothing typed: all of them) |
| 11432 | fn uclipmatch most ulong to void |
| 11433 | put g_n 28 0 |
| 11434 | cnt = get g_n 24 |
| 11435 | if eq cnt 0 |
| 11436 | ret |
| 11437 | end |
| 11438 | a = get g_n 12 |
| 11439 | n = get g_n 13 |
| 11440 | if and eq n 0 gt most 8 |
| 11441 | every = cnt |
| 11442 | if gt every most |
| 11443 | every = most |
| 11444 | end |
| 11445 | for pos ulong every bound 1024 |
| 11446 | put g_cm pos get g_ci pos |
| 11447 | end |
| 11448 | put g_n 28 every |
| 11449 | ret |
| 11450 | end |
| 11451 | if or eq n 0 gt n 255 |
| 11452 | ret |
| 11453 | end |
| 11454 | for i ulong n bound 256 |
| 11455 | put g_nm i get g_q add a i |
| 11456 | end |
| 11457 | put g_nm n 0 |
| 11458 | typed = unsb |
| 11459 | if eq typed 0 |
| 11460 | ret |
| 11461 | end |
| 11462 | slower = usl m_lowercase |
| 11463 | typed_low = umsg typed slower 0 0 0 |
| 11464 | parts = umsg typed_low usl m_components uns x_space 0 0 |
| 11465 | nt = umsg parts usl m_count 0 0 0 |
| 11466 | scontains = usl m_contains |
| 11467 | slen = usl m_length |
| 11468 | sat = get g_m 16 |
| 11469 | image_low = uns x_image_low |
| 11470 | found = ulong 0 |
| 11471 | for pos ulong cnt bound 1024 |
| 11472 | if lt found most |
| 11473 | i = get g_ci pos |
| 11474 | item = umsg get g_m 14 sat i 0 0 |
| 11475 | hay = image_low |
| 11476 | if uiskind item 7 |
| 11477 | words = ukeyed item k_text |
| 11478 | if uiskind words 9 |
| 11479 | hay = umsg words slower 0 0 0 |
| 11480 | end |
| 11481 | end |
| 11482 | okay = true |
| 11483 | for j ulong nt bound 64 |
| 11484 | term = umsg parts sat j 0 0 |
| 11485 | if gt umsg term slen 0 0 0 0 |
| 11486 | if ne and umsg hay scontains term 0 0 255 1 |
| 11487 | okay = false |
| 11488 | end |
| 11489 | end |
| 11490 | end |
| 11491 | if okay |
| 11492 | put g_cm found i |
| 11493 | found = add found 1 |
| 11494 | end |
| 11495 | end |
| 11496 | end |
| 11497 | put g_n 28 found |
| 11498 | end |
| 11499 | |
| 11500 | note put copied thing i on the clipboard: its text, or its picture unsealed (as PNG data). A check uses a board |
| 11501 | note of its own |
| 11502 | fn upasteclip i ulong to void |
| 11503 | if ge i get g_n 24 |
| 11504 | ret |
| 11505 | end |
| 11506 | item = umsg get g_m 14 get g_m 16 i 0 0 |
| 11507 | if not uiskind item 7 |
| 11508 | ret |
| 11509 | end |
| 11510 | pboard = ulong 0 |
| 11511 | if eq get g_n 14 1 |
| 11512 | pboard = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0 |
| 11513 | else |
| 11514 | pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0 |
| 11515 | end |
| 11516 | x = umsg pboard usl m_clear 0 0 0 |
| 11517 | words = ukeyed item k_text |
| 11518 | if uiskind words 9 |
| 11519 | x = umsg pboard usl m_set_string_type words uns x_type_string 0 |
| 11520 | put g_n 29 1 |
| 11521 | ret |
| 11522 | end |
| 11523 | name = ukeyed item k_image |
| 11524 | if not uiskind name 9 |
| 11525 | ret |
| 11526 | end |
| 11527 | if eq and umsg name usl m_contains uns x_slash_text 0 0 255 1 |
| 11528 | ret |
| 11529 | end |
| 11530 | folder = uhoppath x_clip_images |
| 11531 | if eq folder 0 |
| 11532 | ret |
| 11533 | end |
| 11534 | path = umsg folder usl m_append_string name 0 0 |
| 11535 | d = umsg ucl c_data usl m_data_file path 0 0 |
| 11536 | if eq d 0 |
| 11537 | ret |
| 11538 | end |
| 11539 | r = uunseal d |
| 11540 | if le r 1 |
| 11541 | ret |
| 11542 | end |
| 11543 | m = sub r 1 |
| 11544 | picture = umsg ucl c_data usl m_data_bytes ulong libptr c_d 0 m m 0 |
| 11545 | uforget m |
| 11546 | x = umsg pboard usl m_set_data_type picture uns x_type_png 0 |
| 11547 | put g_n 29 2 |
| 11548 | end |
| 11549 | |
| 11550 | note press Command V for the app that is in front again, as Hop does after it has put something on the clipboard |
| 11551 | fn usendpaste to void |
| 11552 | for half ulong 2 |
| 11553 | upr 0 0 |
| 11554 | upr 8 9 |
| 11555 | upr 16 sub 1 half |
| 11556 | ev = ucall 19 |
| 11557 | if ne ev 0 |
| 11558 | upr 0 ev |
| 11559 | upr 8 1048576 |
| 11560 | x = ucall 20 |
| 11561 | upr 0 0 |
| 11562 | upr 8 ev |
| 11563 | x = ucall 21 |
| 11564 | upr 0 ev |
| 11565 | x = ucall 22 |
| 11566 | end |
| 11567 | end |
| 11568 | end |
| 11569 | |
| 11570 | note a moment from now, press Command V; only when this program is allowed to control the Mac (Accessibility) |
| 11571 | fn ulaterpaste to void |
| 11572 | if eq and ucall 18 255 0 |
| 11573 | ret |
| 11574 | end |
| 11575 | s_after = usl m_perform_after |
| 11576 | s_paste = usl m_paste_now |
| 11577 | upr 64 bitcast ulong 0.15f64 |
| 11578 | x = umsg get g_o 27 s_after s_paste 0 0 |
| 11579 | end |
| 11580 | |
| 11581 | note ---- recording what is copied, as Hop does (Sources/Clipboard.swift, poll) ---- |
| 11582 | note Only while Hop itself is not running: two programs must not write the same history. The history is read |
| 11583 | note again at that moment, changed and written whole, sealed under the same key with a fresh nonce (the core's fn |
| 11584 | note gclock), for the owner only. Before this program's first change in a run the history as it was is set |
| 11585 | note aside next to it (clipboard.before-hop-omega.bin). What is marked concealed or transient is never kept. |
| 11586 | note seal the first m bytes of the core's c_d under the clipboard key; nonce, data and tag as NSData, or 0 |
| 11587 | fn useal m ulong to ulong |
| 11588 | if or eq m 0 gt m 16777216 |
| 11589 | ret 0 |
| 11590 | end |
| 11591 | if eq uclipkey 0 |
| 11592 | ret 0 |
| 11593 | end |
| 11594 | upr 0 ulong libptr c_n 0 12 |
| 11595 | upr 8 12 |
| 11596 | x = ucall 27 |
| 11597 | gclock m |
| 11598 | gcwipe |
| 11599 | sealed = umsg ucl c_mutable_data usl m_data 0 0 0 |
| 11600 | sappend = usl m_append_bytes |
| 11601 | x = umsg sealed sappend ulong libptr c_n 0 12 12 0 |
| 11602 | x = umsg sealed sappend ulong libptr c_d 0 m m 0 |
| 11603 | x = umsg sealed sappend ulong libptr c_tg 0 16 16 0 |
| 11604 | ret sealed |
| 11605 | end |
| 11606 | |
| 11607 | note the history as it is on disk now, as a list that can be changed: an empty one when there is no file yet, |
| 11608 | note 0 when there is no key or the file is not Hop's |
| 11609 | fn uclipsmutable to ulong |
| 11610 | path = uhoppath x_clipboard_file |
| 11611 | if eq path 0 |
| 11612 | ret 0 |
| 11613 | end |
| 11614 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 11615 | if eq and umsg manager usl m_file_exists path 0 0 255 0 |
| 11616 | if eq uclipkey 0 |
| 11617 | ret 0 |
| 11618 | end |
| 11619 | gcwipe |
| 11620 | ret umsg ucl c_mutable_array usl m_array 0 0 0 |
| 11621 | end |
| 11622 | d = umsg ucl c_data usl m_data_file path 0 0 |
| 11623 | if eq d 0 |
| 11624 | ret 0 |
| 11625 | end |
| 11626 | r = uunseal d |
| 11627 | if le r 1 |
| 11628 | ret 0 |
| 11629 | end |
| 11630 | m = sub r 1 |
| 11631 | plain = umsg ucl c_data usl m_data_bytes ulong libptr c_d 0 m m 0 |
| 11632 | uforget m |
| 11633 | items = umsg ucl c_json usl m_json_object plain 1 0 |
| 11634 | if not uiskind items 8 |
| 11635 | ret 0 |
| 11636 | end |
| 11637 | ret items |
| 11638 | end |
| 11639 | |
| 11640 | note write the list as the history; 1 when it was written |
| 11641 | fn uclipswrite items ulong to ulong |
| 11642 | data = umsg ucl c_json usl m_json_data items 0 0 |
| 11643 | if eq data 0 |
| 11644 | ret 0 |
| 11645 | end |
| 11646 | n = umsg data usl m_length 0 0 0 |
| 11647 | if or eq n 0 gt n 16777216 |
| 11648 | ret 0 |
| 11649 | end |
| 11650 | s_write = usl m_write_file |
| 11651 | if eq get g_n 33 0 |
| 11652 | before = uhopfile x_clipboard_file |
| 11653 | if ne before 0 |
| 11654 | aside = uhoppath x_clip_backup |
| 11655 | x = umsg before s_write aside 1 0 |
| 11656 | upr 0 ulong libptr g_nm 0 1024 |
| 11657 | upr 8 384 |
| 11658 | x = ucall 16 |
| 11659 | end |
| 11660 | put g_n 33 1 |
| 11661 | end |
| 11662 | src = umsg data usl m_bytes 0 0 0 |
| 11663 | upr 0 ulong libptr c_d 0 n |
| 11664 | upr 8 src |
| 11665 | upr 16 n |
| 11666 | x = ucall 8 |
| 11667 | sealed = useal n |
| 11668 | uforget n |
| 11669 | if eq sealed 0 |
| 11670 | ret 0 |
| 11671 | end |
| 11672 | path = uhoppath x_clipboard_file |
| 11673 | if eq path 0 |
| 11674 | ret 0 |
| 11675 | end |
| 11676 | ok = and umsg sealed s_write path 1 0 255 |
| 11677 | path = uhoppath x_clipboard_file |
| 11678 | upr 0 ulong libptr g_nm 0 1024 |
| 11679 | upr 8 384 |
| 11680 | x = ucall 16 |
| 11681 | ret ok |
| 11682 | end |
| 11683 | |
| 11684 | note is the copied thing e pinned |
| 11685 | fn uclippinned e ulong to bool |
| 11686 | if not uiskind e 7 |
| 11687 | ret false |
| 11688 | end |
| 11689 | pin = ukeyed e k_pinned |
| 11690 | if not uisnumber pin |
| 11691 | ret false |
| 11692 | end |
| 11693 | ret eq and umsg pin usl m_bool_value 0 0 0 255 1 |
| 11694 | end |
| 11695 | |
| 11696 | note what is on the pasteboard pb goes into the history as Hop puts it there: text that is already there moves |
| 11697 | note 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 |
| 11698 | note came from; then the unpinned ones over the limit go, the oldest first |
| 11699 | fn ucliprecord pb ulong to void |
| 11700 | types = umsg pb usl m_types 0 0 0 |
| 11701 | if ne types 0 |
| 11702 | shas = usl m_contains_object |
| 11703 | if eq and umsg types shas uns x_skip0 0 0 255 1 |
| 11704 | ret |
| 11705 | end |
| 11706 | if eq and umsg types shas uns x_skip1 0 0 255 1 |
| 11707 | ret |
| 11708 | end |
| 11709 | if eq and umsg types shas uns x_skip2 0 0 255 1 |
| 11710 | ret |
| 11711 | end |
| 11712 | if eq and umsg types shas uns x_skip3 0 0 255 1 |
| 11713 | ret |
| 11714 | end |
| 11715 | if eq and umsg types shas uns x_skip4 0 0 255 1 |
| 11716 | ret |
| 11717 | end |
| 11718 | if eq and umsg types shas uns x_skip5 0 0 255 1 |
| 11719 | ret |
| 11720 | end |
| 11721 | end |
| 11722 | items = uclipsmutable |
| 11723 | if eq items 0 |
| 11724 | ret |
| 11725 | end |
| 11726 | source = ulong 0 |
| 11727 | if eq get g_n 14 1 |
| 11728 | front_app = umsg umsg ucl c_ws usl m_shws 0 0 0 usl m_frontmost 0 0 0 |
| 11729 | if ne front_app 0 |
| 11730 | source = umsg front_app usl m_localized_name 0 0 0 |
| 11731 | end |
| 11732 | end |
| 11733 | cnum = ucl c_number |
| 11734 | x = umsg ucl c_date usl m_reference_now 0 0 0 |
| 11735 | now_bits = ugr 64 |
| 11736 | s_double = usl m_number_double |
| 11737 | upr 64 now_bits |
| 11738 | moment = umsg cnum s_double 0 0 0 |
| 11739 | sset = usl m_set_object |
| 11740 | sat = usl m_at |
| 11741 | sins = usl m_insert_at |
| 11742 | copied = umsg pb usl m_string_for_type uns x_type_string 0 0 |
| 11743 | has_text = false |
| 11744 | if ne copied 0 |
| 11745 | if gt umsg copied usl m_length 0 0 0 0 |
| 11746 | has_text = true |
| 11747 | end |
| 11748 | end |
| 11749 | fresh_item = ulong 0 |
| 11750 | if has_text |
| 11751 | if gt umsg copied usl m_byte_length 4 0 0 512000 |
| 11752 | ret |
| 11753 | end |
| 11754 | cnt = umsg items usl m_count 0 0 0 |
| 11755 | found = cnt |
| 11756 | sequal = usl m_equal_string |
| 11757 | for i ulong cnt bound 100000 |
| 11758 | if eq found cnt |
| 11759 | e = umsg items sat i 0 0 |
| 11760 | if uiskind e 7 |
| 11761 | words = ukeyed e k_text |
| 11762 | if uiskind words 9 |
| 11763 | if eq and umsg words sequal copied 0 0 255 1 |
| 11764 | found = i |
| 11765 | end |
| 11766 | end |
| 11767 | end |
| 11768 | end |
| 11769 | end |
| 11770 | if lt found cnt |
| 11771 | e = umsg items sat found 0 0 |
| 11772 | kept = umsg e usl m_retain 0 0 0 |
| 11773 | x = umsg e sset moment uns k_date 0 |
| 11774 | x = umsg items usl m_remove_at found 0 0 |
| 11775 | x = umsg items sins e 0 0 |
| 11776 | x = umsg e usl m_release 0 0 0 |
| 11777 | else |
| 11778 | fresh_item = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 11779 | x = umsg fresh_item sset copied uns k_text 0 |
| 11780 | end |
| 11781 | else |
| 11782 | picture = umsg ucl c_image usl m_alloc 0 0 0 |
| 11783 | picture = umsg picture usl m_init_pasteboard pb 0 0 |
| 11784 | if eq picture 0 |
| 11785 | ret |
| 11786 | end |
| 11787 | tiff = umsg picture usl m_tiff 0 0 0 |
| 11788 | if eq tiff 0 |
| 11789 | ret |
| 11790 | end |
| 11791 | bitmap = umsg ucl c_bitmap usl m_rep_with_data tiff 0 0 |
| 11792 | if eq bitmap 0 |
| 11793 | ret |
| 11794 | end |
| 11795 | no_properties = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 11796 | png = umsg bitmap usl m_rep_using 4 no_properties 0 |
| 11797 | if eq png 0 |
| 11798 | ret |
| 11799 | end |
| 11800 | pn = umsg png usl m_length 0 0 0 |
| 11801 | if or eq pn 0 gt pn 16777216 |
| 11802 | ret |
| 11803 | end |
| 11804 | src = umsg png usl m_bytes 0 0 0 |
| 11805 | upr 0 ulong libptr c_d 0 pn |
| 11806 | upr 8 src |
| 11807 | upr 16 pn |
| 11808 | x = ucall 8 |
| 11809 | sealed = useal pn |
| 11810 | uforget pn |
| 11811 | if eq sealed 0 |
| 11812 | ret |
| 11813 | end |
| 11814 | folder = uhoppath x_clip_images |
| 11815 | if eq folder 0 |
| 11816 | ret |
| 11817 | end |
| 11818 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 11819 | s_create = usl m_create_dir |
| 11820 | upr 40 0 |
| 11821 | x = umsg manager s_create folder 1 0 |
| 11822 | file_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 |
| 11823 | file_path = umsg folder usl m_append_string file_name 0 0 |
| 11824 | if eq and umsg sealed usl m_write_file file_path 1 0 255 0 |
| 11825 | ret |
| 11826 | end |
| 11827 | fresh_item = umsg ucl c_mutable_dict usl m_dictionary 0 0 0 |
| 11828 | x = umsg fresh_item sset file_name uns k_image 0 |
| 11829 | end |
| 11830 | if ne fresh_item 0 |
| 11831 | id_text = umsg umsg ucl c_uuid usl m_uuid 0 0 0 usl m_uuid_string 0 0 0 |
| 11832 | x = umsg fresh_item sset id_text uns k_id 0 |
| 11833 | x = umsg fresh_item sset moment uns k_date 0 |
| 11834 | if ne source 0 |
| 11835 | x = umsg fresh_item sset source uns k_source 0 |
| 11836 | end |
| 11837 | no = umsg cnum usl m_number_bool 0 0 0 |
| 11838 | x = umsg fresh_item sset no uns k_pinned 0 |
| 11839 | x = umsg items sins fresh_item 0 0 |
| 11840 | end |
| 11841 | note the unpinned ones over the limit go, from the end |
| 11842 | limit = get g_n 34 |
| 11843 | if lt limit 50 |
| 11844 | limit = 50 |
| 11845 | end |
| 11846 | cnt = umsg items usl m_count 0 0 0 |
| 11847 | loose = ulong 0 |
| 11848 | for i ulong cnt bound 100000 |
| 11849 | if not uclippinned umsg items sat i 0 0 |
| 11850 | loose = add loose 1 |
| 11851 | end |
| 11852 | end |
| 11853 | if gt loose limit |
| 11854 | drop = sub loose limit |
| 11855 | manager = umsg ucl c_file_manager usl m_default_manager 0 0 0 |
| 11856 | for back ulong cnt bound 100000 |
| 11857 | i = sub sub cnt 1 back |
| 11858 | if gt drop 0 |
| 11859 | e = umsg items sat i 0 0 |
| 11860 | if not uclippinned e |
| 11861 | if uiskind e 7 |
| 11862 | image_name = ukeyed e k_image |
| 11863 | if uiskind image_name 9 |
| 11864 | if ne and umsg image_name usl m_contains uns x_slash_text 0 0 255 1 |
| 11865 | folder = uhoppath x_clip_images |
| 11866 | if ne folder 0 |
| 11867 | gone = umsg folder usl m_append_string image_name 0 0 |
| 11868 | x = umsg manager usl m_remove_item gone 0 0 |
| 11869 | end |
| 11870 | end |
| 11871 | end |
| 11872 | end |
| 11873 | x = umsg items usl m_remove_at i 0 0 |
| 11874 | drop = sub drop 1 |
| 11875 | end |
| 11876 | end |
| 11877 | end |
| 11878 | end |
| 11879 | x = uclipswrite items |
| 11880 | end |
| 11881 | |
| 11882 | note is Hop itself running |
| 11883 | fn uhoprunning to bool |
| 11884 | others = umsg ucl c_running_app usl m_running_with uns x_hop_id 0 0 |
| 11885 | if eq others 0 |
| 11886 | ret false |
| 11887 | end |
| 11888 | ret gt umsg others usl m_count 0 0 0 0 |
| 11889 | end |
| 11890 | |
| 11891 | note twice a second: when the clipboard has changed and Hop is not there to keep the history, this program does |
| 11892 | fn ucliptick to void |
| 11893 | uindextick |
| 11894 | utunneltick |
| 11895 | pb = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0 |
| 11896 | cc = umsg pb usl m_change_count 0 0 0 |
| 11897 | if eq cc get g_n 35 |
| 11898 | ret |
| 11899 | end |
| 11900 | put g_n 35 cc |
| 11901 | if uhoprunning |
| 11902 | ret |
| 11903 | end |
| 11904 | ucliprecord pb |
| 11905 | end |
| 11906 | |
| 11907 | note after this program put something on the clipboard itself: that change is not a new copied thing; a text that |
| 11908 | note was pasted moves to the front of the history, as in Hop |
| 11909 | fn uclipmine was_text ulong to void |
| 11910 | pb = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0 |
| 11911 | put g_n 35 umsg pb usl m_change_count 0 0 0 |
| 11912 | if and eq was_text 1 not uhoprunning |
| 11913 | ucliprecord pb |
| 11914 | end |
| 11915 | end |
| 11916 | |
| 11917 | note is the app in front a browser, by Hop's list |
| 11918 | fn ufrontbrowser to ulong |
| 11919 | id = get g_m 11 |
| 11920 | if eq id 0 |
| 11921 | ret 0 |
| 11922 | end |
| 11923 | sequal = usl m_equal_string |
| 11924 | if eq and umsg id sequal uns x_browser0 0 0 255 1 |
| 11925 | ret 1 |
| 11926 | end |
| 11927 | if eq and umsg id sequal uns x_browser1 0 0 255 1 |
| 11928 | ret 1 |
| 11929 | end |
| 11930 | if eq and umsg id sequal uns x_browser2 0 0 255 1 |
| 11931 | ret 1 |
| 11932 | end |
| 11933 | if eq and umsg id sequal uns x_browser3 0 0 255 1 |
| 11934 | ret 1 |
| 11935 | end |
| 11936 | if eq and umsg id sequal uns x_browser4 0 0 255 1 |
| 11937 | ret 1 |
| 11938 | end |
| 11939 | if eq and umsg id sequal uns x_browser5 0 0 255 1 |
| 11940 | ret 1 |
| 11941 | end |
| 11942 | if eq and umsg id sequal uns x_browser6 0 0 255 1 |
| 11943 | ret 1 |
| 11944 | end |
| 11945 | if eq and umsg id sequal uns x_browser7 0 0 255 1 |
| 11946 | ret 1 |
| 11947 | end |
| 11948 | if eq and umsg id sequal uns x_browser8 0 0 255 1 |
| 11949 | ret 1 |
| 11950 | end |
| 11951 | ret 0 |
| 11952 | end |
| 11953 | |
| 11954 | note the Ask row's text into g_nm from byte p: "Ask NAME: TEXT", or why it cannot ask; the byte after it |
| 11955 | fn uaskrow p ulong to ulong |
| 11956 | if eq get g_m 3 0 |
| 11957 | ret uptxt p x_ask_none |
| 11958 | end |
| 11959 | name_bytes = umsg get g_m 2 get g_o 5 0 0 0 |
| 11960 | q = uptxt p x_ask |
| 11961 | upr 0 name_bytes |
| 11962 | n = ucall 7 |
| 11963 | if gt n 200 |
| 11964 | n = 200 |
| 11965 | end |
| 11966 | upr 0 ulong libptr g_nm q n |
| 11967 | upr 8 name_bytes |
| 11968 | upr 16 n |
| 11969 | x = ucall 8 |
| 11970 | q = add q n |
| 11971 | q = uptxt q x_colon |
| 11972 | a = get g_n 12 |
| 11973 | n = get g_n 13 |
| 11974 | for i ulong n bound 256 |
| 11975 | put g_nm add q i get g_q add a i |
| 11976 | end |
| 11977 | ret add q n |
| 11978 | end |
| 11979 | |
| 11980 | note 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 |
| 11981 | fn uprow p ulong r ulong to ulong |
| 11982 | if eq ulong get g_rk r 8 |
| 11983 | ret uaskrow p |
| 11984 | end |
| 11985 | if eq ulong get g_rk r 10 |
| 11986 | ret uremoterow p get g_hit r |
| 11987 | end |
| 11988 | if eq ulong get g_rk r 9 |
| 11989 | q = uptxt p x_agent_row |
| 11990 | a = get g_n 12 |
| 11991 | n = get g_n 13 |
| 11992 | for i ulong n bound 256 |
| 11993 | put g_nm add q i get g_q add a i |
| 11994 | end |
| 11995 | ret add q n |
| 11996 | end |
| 11997 | if eq ulong get g_rk r 6 |
| 11998 | ret uclipname p get g_hit r |
| 11999 | end |
| 12000 | if eq ulong get g_rk r 5 |
| 12001 | ret ustrat get g_m 18 p get g_hit r |
| 12002 | end |
| 12003 | if eq ulong get g_rk r 3 |
| 12004 | if eq get g_hit r 0 |
| 12005 | ret uptxt p x_screen0 |
| 12006 | end |
| 12007 | if eq get g_hit r 2 |
| 12008 | ret uptxt p x_screen2 |
| 12009 | end |
| 12010 | ret uptxt p x_screen1 |
| 12011 | end |
| 12012 | if eq ulong get g_rk r 4 |
| 12013 | if eq get g_hit r 0 |
| 12014 | ret uptxt p x_command0 |
| 12015 | end |
| 12016 | if eq get g_hit r 2 |
| 12017 | ret uptxt p x_command2 |
| 12018 | end |
| 12019 | if eq get g_hit r 3 |
| 12020 | ret uptxt p x_command3 |
| 12021 | end |
| 12022 | ret uptxt p x_command1 |
| 12023 | end |
| 12024 | if and eq ulong get g_rk r 2 eq get g_n 13 0 |
| 12025 | uclipaddr 1 |
| 12026 | q = upaddr p |
| 12027 | uclipaddr 0 |
| 12028 | ret q |
| 12029 | end |
| 12030 | if eq ulong get g_rk r 2 |
| 12031 | ret upaddr p |
| 12032 | end |
| 12033 | if eq ulong get g_rk r 7 |
| 12034 | ret ufilepath p get g_hit r |
| 12035 | end |
| 12036 | ret upname p get g_hit r |
| 12037 | end |
| 12038 | |
| 12039 | note one turn of the event loop: wait for an event until date d and hand it to AppKit |
| 12040 | fn utick app ulong sn ulong se ulong mode ulong d ulong to void |
| 12041 | upr 0 app |
| 12042 | upr 8 sn |
| 12043 | upr 16 18446744073709551615 |
| 12044 | upr 24 d |
| 12045 | upr 32 mode |
| 12046 | upr 40 1 |
| 12047 | ev = ucall 2 |
| 12048 | if ne ev 0 |
| 12049 | x = umsg app se ev 0 0 |
| 12050 | end |
| 12051 | end |
| 12052 | |
| 12053 | note put the panel away. A program that stays also empties the field, shows every app again and hides itself, so |
| 12054 | note the app that was in front before has the keyboard back |
| 12055 | fn uhide to void |
| 12056 | uaskstop |
| 12057 | put g_n 36 0 |
| 12058 | x = umsg get g_o 19 get g_o 20 0 0 0 |
| 12059 | if eq get g_n 14 1 |
| 12060 | put g_nm 0 0 |
| 12061 | x = umsg get g_o 0 get g_o 8 unsb 0 0 |
| 12062 | utyped |
| 12063 | x = umsg get g_o 21 get g_o 22 0 0 0 |
| 12064 | end |
| 12065 | end |
| 12066 | |
| 12067 | note bring the panel back: in front with the keyboard in the field for a program that stays, else just visible |
| 12068 | fn ushow to void |
| 12069 | if eq get g_n 14 1 |
| 12070 | ufront |
| 12071 | uloadclips |
| 12072 | uloadvault |
| 12073 | if eq get g_m 3 0 |
| 12074 | uloadconfig |
| 12075 | end |
| 12076 | if eq get g_n 13 0 |
| 12077 | unarrow |
| 12078 | x = umsg get g_o 1 get g_o 7 0 0 0 |
| 12079 | put g_n 6 0 |
| 12080 | if gt get g_n 1 0 |
| 12081 | uchoose 0 |
| 12082 | end |
| 12083 | ushowst |
| 12084 | end |
| 12085 | x = umsg get g_o 21 get g_o 23 1 0 0 |
| 12086 | x = umsg get g_o 19 get g_o 24 0 0 0 |
| 12087 | x = umsg get g_o 19 get g_o 25 get g_o 0 0 0 |
| 12088 | else |
| 12089 | x = umsg get g_o 19 get g_o 26 0 0 0 |
| 12090 | end |
| 12091 | end |
| 12092 | |
| 12093 | note the library function at address f on the register file; x0 as it came back |
| 12094 | fn ucallf f ulong to ulong |
| 12095 | lr = libcall f g_rg 0 128 |
| 12096 | ret ugr 0 |
| 12097 | end |
| 12098 | |
| 12099 | note a global key: a Carbon hot key (key code, modifiers) whose handler is callback entry 5. 0 when both the |
| 12100 | note handler and the key were taken; the hot key's id is 'HOPO' 1 |
| 12101 | fn ukey code ulong mods ulong to ulong |
| 12102 | n = ucs s_carbon |
| 12103 | upr 0 ulong libptr g_nm 0 1024 |
| 12104 | upr 8 2 |
| 12105 | lr = libcall ulong libfn 0 g_rg 0 128 |
| 12106 | target_fn = usym s_event_target |
| 12107 | install_fn = usym s_install_handler |
| 12108 | register_fn = usym s_register_key |
| 12109 | if or or eq target_fn 0 eq install_fn 0 eq register_fn 0 |
| 12110 | ret 1 |
| 12111 | end |
| 12112 | target = ucallf target_fn |
| 12113 | put g_ev 0 98 |
| 12114 | put g_ev 1 121 |
| 12115 | put g_ev 2 101 |
| 12116 | put g_ev 3 107 |
| 12117 | put g_ev 4 5 |
| 12118 | upr 0 target |
| 12119 | upr 8 ulong libfn 7 |
| 12120 | upr 16 1 |
| 12121 | upr 24 ulong libptr g_ev 0 16 |
| 12122 | upr 32 0 |
| 12123 | upr 40 0 |
| 12124 | installed = and ucallf install_fn 4294967295 |
| 12125 | upr 0 code |
| 12126 | upr 8 mods |
| 12127 | upr 16 5507124751 |
| 12128 | upr 24 target |
| 12129 | upr 32 0 |
| 12130 | upr 40 ulong libptr g_ev 8 8 |
| 12131 | registered = and ucallf register_fn 4294967295 |
| 12132 | ret or installed registered |
| 12133 | end |
| 12134 | |
| 12135 | note one menu item: title, action (a selector) and key. An unsized text takes two of a function's six places |
| 12136 | fn uitem menu ulong title view uchar * action_sel ulong key view uchar * to void |
| 12137 | c = ucl c_menu_item |
| 12138 | s = usl m_alloc |
| 12139 | item = umsg c s 0 0 0 |
| 12140 | title_string = uns title |
| 12141 | key_string = uns key |
| 12142 | s = usl m_init_item |
| 12143 | item = umsg item s title_string action_sel key_string |
| 12144 | s = usl m_add_item |
| 12145 | x = umsg menu s item 0 0 |
| 12146 | end |
| 12147 | |
| 12148 | note a menu bar entry with an empty menu under it; the menu |
| 12149 | fn usubmenu bar ulong title view uchar * to ulong |
| 12150 | c = ucl c_menu_item |
| 12151 | s = usl m_alloc |
| 12152 | sinit = usl m_init |
| 12153 | entry = umsg c s 0 0 0 |
| 12154 | entry = umsg entry sinit 0 0 0 |
| 12155 | s = usl m_add_item |
| 12156 | x = umsg bar s entry 0 0 |
| 12157 | c = ucl c_menu |
| 12158 | s = usl m_alloc |
| 12159 | menu = umsg c s 0 0 0 |
| 12160 | title_string = uns title |
| 12161 | s = usl m_init_title |
| 12162 | menu = umsg menu s title_string 0 0 |
| 12163 | s = usl m_set_submenu |
| 12164 | x = umsg entry s menu 0 0 |
| 12165 | ret menu |
| 12166 | end |
| 12167 | |
| 12168 | note the menu: Quit, and Edit with the four commands the field's editor answers itself |
| 12169 | fn umenu app ulong to void |
| 12170 | c = ucl c_menu |
| 12171 | s = usl m_alloc |
| 12172 | sinit = usl m_init |
| 12173 | bar = umsg c s 0 0 0 |
| 12174 | bar = umsg bar sinit 0 0 0 |
| 12175 | app_menu = usubmenu bar x_app |
| 12176 | a = usl m_terminate |
| 12177 | uitem app_menu x_quit a x_key_q |
| 12178 | edit_menu = usubmenu bar x_edit |
| 12179 | a = usl m_cut |
| 12180 | uitem edit_menu x_cut a x_key_x |
| 12181 | a = usl m_copy |
| 12182 | uitem edit_menu x_copy a x_key_c |
| 12183 | a = usl m_paste |
| 12184 | uitem edit_menu x_paste a x_key_v |
| 12185 | a = usl m_select_all |
| 12186 | uitem edit_menu x_select_all a x_key_a |
| 12187 | clip_menu = usubmenu bar x_clip_menu |
| 12188 | a = usl m_pin_clip |
| 12189 | uitem clip_menu x_pin_item a x_key_p |
| 12190 | a = usl m_delete_clip |
| 12191 | uitem clip_menu x_delete_item a x_key_d |
| 12192 | agent_menu = usubmenu bar x_agent_menu |
| 12193 | a = usl m_agent_stop |
| 12194 | uitem agent_menu x_stop_item a x_key_period |
| 12195 | s = usl m_set_menu |
| 12196 | x = umsg app s bar 0 0 |
| 12197 | ustatus |
| 12198 | end |
| 12199 | |
| 12200 | note the methods of OmegaHopPanel. 0 controlTextDidChange: 1 numberOfRowsInTableView: |
| 12201 | note 2 tableView:objectValueForTableColumn:row: (e is the row) 3 go: (the field's action, Enter: c is the sender; |
| 12202 | note it is remembered, and opened when g_n 7 allows) 4 control:textView:doCommandBySelector: (e is |
| 12203 | note the command: the arrows move the selection, Escape puts the panel away; 1 says the key was handled) |
| 12204 | note 5 the hot key's handler (a C function for Carbon: 0 says no error) 6 applicationShouldHandleReopen: |
| 12205 | note hasVisibleWindows: (a click on the Dock icon, or the app opened again) 7 URLSession:dataTask:didReceiveData: |
| 12206 | note (e is the data) 8 URLSession:task:didCompleteWithError: (d the task, e the problem or nothing) |
| 12207 | note 9 pasteNow: (a moment after a copied thing was chosen) 10 clipTick: (twice a second, to see what was copied) |
| 12208 | note 11 pinClip: 12 deleteClip: (the Clipboard menu, on the selected copied thing) 13 agentOut: agentErr: |
| 12209 | note agentEnd: stopAgent: (what the agent's program tells, and the Agent menu; b is the selector, c what came) |
| 12210 | fn libback k ulong a ulong b ulong c ulong d ulong e ulong to ulong |
| 12211 | if eq k 0 |
| 12212 | utyped |
| 12213 | ret 0 |
| 12214 | end |
| 12215 | if eq k 1 |
| 12216 | ret get g_n 1 |
| 12217 | end |
| 12218 | if eq k 2 |
| 12219 | if ge e get g_n 1 |
| 12220 | ret 0 |
| 12221 | end |
| 12222 | p = ulong 0 |
| 12223 | if eq ulong get g_rk e 7 |
| 12224 | p = ufilerow 0 get g_hit e |
| 12225 | else |
| 12226 | if eq ulong get g_rk e 2 |
| 12227 | p = uptxt 0 x_open |
| 12228 | end |
| 12229 | if eq ulong get g_rk e 6 |
| 12230 | p = uptxt 0 x_paste_row |
| 12231 | end |
| 12232 | p = uprow p e |
| 12233 | if or or eq ulong get g_rk e 1 eq ulong get g_rk e 6 eq ulong get g_rk e 2 |
| 12234 | p = uwhy p e |
| 12235 | end |
| 12236 | if eq ulong get g_rk e 5 |
| 12237 | q = uptxt p x_gap |
| 12238 | q2 = ustrat get g_m 19 q get g_hit e |
| 12239 | if gt q2 q |
| 12240 | p = q2 |
| 12241 | end |
| 12242 | end |
| 12243 | if and eq ulong get g_rk e 6 or ne get g_n 13 0 ne get g_n 36 0 |
| 12244 | if eq ulong get g_cp get g_hit e 1 |
| 12245 | p = uptxt p x_gap |
| 12246 | p = uptxt p x_pinned |
| 12247 | end |
| 12248 | end |
| 12249 | if eq ulong get g_rk e 3 |
| 12250 | p = uptxt p x_gap |
| 12251 | if eq get g_hit e 0 |
| 12252 | p = uptxt p x_screen0_about |
| 12253 | end |
| 12254 | if eq get g_hit e 1 |
| 12255 | p = uptxt p x_screen1_about |
| 12256 | end |
| 12257 | if eq get g_hit e 2 |
| 12258 | p = uptxt p x_screen2_about |
| 12259 | end |
| 12260 | end |
| 12261 | if and eq ulong get g_rk e 4 eq get g_hit e 0 |
| 12262 | p = uptxt p x_gap |
| 12263 | p = uptxt p x_command0_about |
| 12264 | end |
| 12265 | end |
| 12266 | put g_nm p 0 |
| 12267 | ret unsb |
| 12268 | end |
| 12269 | if eq k 3 |
| 12270 | put g_n 3 add get g_n 3 1 |
| 12271 | if and ne c 0 lt get g_n 6 get g_n 1 |
| 12272 | put g_n 8 add get g_n 6 1 |
| 12273 | if and eq ulong get g_rk get g_n 6 3 eq get g_hit get g_n 6 2 |
| 12274 | if ne get g_m 4 0 |
| 12275 | uanswershow |
| 12276 | uanswerview 1 |
| 12277 | end |
| 12278 | ret 0 |
| 12279 | end |
| 12280 | if eq ulong get g_rk get g_n 6 3 |
| 12281 | uscreen add get g_hit get g_n 6 1 |
| 12282 | ret 0 |
| 12283 | end |
| 12284 | if and eq ulong get g_rk get g_n 6 4 eq get g_hit get g_n 6 3 |
| 12285 | uchatnew |
| 12286 | uscreen get g_n 36 |
| 12287 | ret 0 |
| 12288 | end |
| 12289 | if eq get g_n 46 1 |
| 12290 | uagentrun |
| 12291 | ret 0 |
| 12292 | end |
| 12293 | if eq get g_n 7 1 |
| 12294 | rk = ulong get g_rk get g_n 6 |
| 12295 | if or eq rk 8 eq rk 9 |
| 12296 | if eq rk 8 |
| 12297 | uask |
| 12298 | else |
| 12299 | uagentrun |
| 12300 | end |
| 12301 | else |
| 12302 | if eq rk 2 |
| 12303 | if eq get g_n 13 0 |
| 12304 | uclipaddr 1 |
| 12305 | uopenaddr |
| 12306 | uclipaddr 0 |
| 12307 | else |
| 12308 | uopenaddr |
| 12309 | end |
| 12310 | end |
| 12311 | if eq rk 4 |
| 12312 | if eq get g_hit get g_n 6 0 |
| 12313 | usettings |
| 12314 | end |
| 12315 | if eq get g_hit get g_n 6 2 |
| 12316 | uindexstart |
| 12317 | end |
| 12318 | if eq get g_hit get g_n 6 1 |
| 12319 | if eq get g_n 14 1 |
| 12320 | x = umsg umsg ucl c_app usl m_shared 0 0 0 usl m_terminate 0 0 0 |
| 12321 | end |
| 12322 | end |
| 12323 | end |
| 12324 | if eq rk 6 |
| 12325 | put g_n 29 0 |
| 12326 | upasteclip get g_hit get g_n 6 |
| 12327 | if eq get g_n 14 1 |
| 12328 | uclipmine get g_n 29 |
| 12329 | end |
| 12330 | end |
| 12331 | if eq rk 5 |
| 12332 | ucopysecret get g_hit get g_n 6 |
| 12333 | if eq get g_n 14 1 |
| 12334 | uclipmine 0 |
| 12335 | end |
| 12336 | end |
| 12337 | if eq rk 10 |
| 12338 | uremoteopen get g_hit get g_n 6 |
| 12339 | end |
| 12340 | if eq rk 7 |
| 12341 | uopenfile get g_hit get g_n 6 |
| 12342 | urecordfile get g_hit get g_n 6 |
| 12343 | end |
| 12344 | if eq rk 1 |
| 12345 | ulaunch get g_hit get g_n 6 |
| 12346 | urecordapp get g_hit get g_n 6 |
| 12347 | end |
| 12348 | put g_n 5 1 |
| 12349 | if eq get g_n 14 1 |
| 12350 | uhide |
| 12351 | if eq rk 6 |
| 12352 | ulaterpaste |
| 12353 | end |
| 12354 | end |
| 12355 | end |
| 12356 | end |
| 12357 | if and eq get g_n 7 0 eq get g_n 23 1 |
| 12358 | rk = ulong get g_rk get g_n 6 |
| 12359 | if eq rk 6 |
| 12360 | upasteclip get g_hit get g_n 6 |
| 12361 | end |
| 12362 | if eq rk 5 |
| 12363 | ucopysecret get g_hit get g_n 6 |
| 12364 | end |
| 12365 | if eq rk 10 |
| 12366 | uremoteopen get g_hit get g_n 6 |
| 12367 | end |
| 12368 | if eq rk 7 |
| 12369 | urecordfile get g_hit get g_n 6 |
| 12370 | end |
| 12371 | if eq rk 1 |
| 12372 | urecordapp get g_hit get g_n 6 |
| 12373 | end |
| 12374 | end |
| 12375 | end |
| 12376 | end |
| 12377 | if eq k 4 |
| 12378 | if eq e get g_o 9 |
| 12379 | if lt add get g_n 6 1 get g_n 1 |
| 12380 | uchoose add get g_n 6 1 |
| 12381 | end |
| 12382 | ret 1 |
| 12383 | end |
| 12384 | if eq e get g_o 10 |
| 12385 | if gt get g_n 6 0 |
| 12386 | uchoose sub get g_n 6 1 |
| 12387 | end |
| 12388 | ret 1 |
| 12389 | end |
| 12390 | if eq e get g_o 11 |
| 12391 | if ne get g_n 36 0 |
| 12392 | uscreen 0 |
| 12393 | ret 1 |
| 12394 | end |
| 12395 | put g_n 5 1 |
| 12396 | uhide |
| 12397 | ret 1 |
| 12398 | end |
| 12399 | end |
| 12400 | if eq k 5 |
| 12401 | ushow |
| 12402 | ret 0 |
| 12403 | end |
| 12404 | if eq k 7 |
| 12405 | unetdata e |
| 12406 | ret 0 |
| 12407 | end |
| 12408 | if eq k 8 |
| 12409 | unetdone d e |
| 12410 | ret 0 |
| 12411 | end |
| 12412 | if eq k 9 |
| 12413 | usendpaste |
| 12414 | ret 0 |
| 12415 | end |
| 12416 | if eq k 10 |
| 12417 | ucliptick |
| 12418 | ret 0 |
| 12419 | end |
| 12420 | if eq k 11 |
| 12421 | uclipmenu 1 |
| 12422 | ret 0 |
| 12423 | end |
| 12424 | if eq k 12 |
| 12425 | uclipmenu 2 |
| 12426 | ret 0 |
| 12427 | end |
| 12428 | if eq k 13 |
| 12429 | uagentevent b c |
| 12430 | ret 0 |
| 12431 | end |
| 12432 | if eq k 6 |
| 12433 | ushow |
| 12434 | ret 1 |
| 12435 | end |
| 12436 | ret 0 |
| 12437 | end |
| 12438 | |
| 12439 | note one method of the class: selector text, callback entry, type text |
| 12440 | fn umethod c ulong t view uchar * entry ulong ty view uchar * to bool |
| 12441 | s = usl t |
| 12442 | n = ucs ty |
| 12443 | upr 0 c |
| 12444 | upr 8 s |
| 12445 | upr 16 ulong libfn int add 2 entry |
| 12446 | upr 24 ulong libptr g_nm 0 1024 |
| 12447 | ret eq and ucall 5 255 1 |
| 12448 | end |
| 12449 | |
| 12450 | fn main to int |
| 12451 | n = ucs s_appkit |
| 12452 | upr 0 ulong libptr g_nm 0 1024 |
| 12453 | upr 8 2 |
| 12454 | lr = libcall ulong libfn 0 g_rg 0 128 |
| 12455 | if eq ugr 0 0 |
| 12456 | ret 2 |
| 12457 | end |
| 12458 | put g_f 0 usym s_gc |
| 12459 | put g_f 1 usym s_sr |
| 12460 | put g_f 2 usym s_ms |
| 12461 | put g_f 3 usym s_wr |
| 12462 | put g_f 4 usym s_acp |
| 12463 | put g_f 5 usym s_cam |
| 12464 | put g_f 6 usym s_rcp |
| 12465 | put g_f 7 usym s_strlen |
| 12466 | put g_f 8 usym s_memcpy |
| 12467 | put g_f 9 usym s_getenv |
| 12468 | put g_f 10 usym s_malloc |
| 12469 | put g_f 11 usym s_memmem |
| 12470 | put g_f 12 usym s_memchr |
| 12471 | put g_f 13 usym s_memrchr |
| 12472 | put g_f 14 usym s_pow |
| 12473 | put g_f 15 usym s_log2 |
| 12474 | put g_f 16 usym s_chmod |
| 12475 | put g_f 17 usym s_memset |
| 12476 | put g_f 18 usym s_trusted |
| 12477 | put g_f 19 usym s_key_event |
| 12478 | put g_f 20 usym s_event_flags |
| 12479 | put g_f 21 usym s_event_post |
| 12480 | put g_f 22 usym s_cf_release |
| 12481 | put g_f 23 usym s_item_copy |
| 12482 | put g_f 24 usym s_item_add |
| 12483 | put g_f 25 usym s_item_delete |
| 12484 | put g_f 26 usym s_interaction |
| 12485 | put g_f 27 usym s_random |
| 12486 | put g_f 28 usym s_free |
| 12487 | put g_f 29 usym s_iopolicy |
| 12488 | put g_f 30 usym s_home_directory |
| 12489 | for i ulong 31 |
| 12490 | if eq get g_f i 0 |
| 12491 | ret 3 |
| 12492 | end |
| 12493 | end |
| 12494 | put g_o 3 ucl c_str |
| 12495 | put g_o 4 usl m_utf |
| 12496 | put g_o 5 usl m_cstr |
| 12497 | put g_m 16 usl m_at |
| 12498 | put g_m 7 ucl c_dict |
| 12499 | put g_m 8 ucl c_array |
| 12500 | put g_m 9 ucl c_str |
| 12501 | x = uindexmode |
| 12502 | if eq x 0 |
| 12503 | ret 0 |
| 12504 | end |
| 12505 | if eq x 1 |
| 12506 | ret 1 |
| 12507 | end |
| 12508 | put g_o 6 usl m_strval |
| 12509 | put g_o 7 usl m_reload |
| 12510 | put g_o 8 usl m_setstr |
| 12511 | put g_o 9 usl m_down |
| 12512 | put g_o 10 usl m_up |
| 12513 | put g_o 11 usl m_cancel |
| 12514 | put g_o 12 usl m_selrow |
| 12515 | put g_o 13 ucl c_ixset |
| 12516 | put g_o 14 usl m_ixwith |
| 12517 | put g_o 15 usl m_scrrow |
| 12518 | put g_o 16 ucl c_url |
| 12519 | put g_o 17 usl m_urlstr |
| 12520 | put g_o 18 usl m_host |
| 12521 | c = ucl c_pool |
| 12522 | s = usl m_alloc |
| 12523 | pool = umsg c s 0 0 0 |
| 12524 | sinit = usl m_init |
| 12525 | pool = umsg pool sinit 0 0 0 |
| 12526 | ufolder x_dir1 0 |
| 12527 | ufolder x_dir2 1 |
| 12528 | ubuildmap |
| 12529 | n = ucs x_env_front |
| 12530 | upr 0 ulong libptr g_nm 0 1024 |
| 12531 | front_text = ucall 9 |
| 12532 | if ne front_text 0 |
| 12533 | n = ufetch front_text |
| 12534 | put g_m 11 umsg unsb usl m_retain 0 0 0 |
| 12535 | end |
| 12536 | n = ucs x_env |
| 12537 | upr 0 ulong libptr g_nm 0 1024 |
| 12538 | if eq ucall 9 0 |
| 12539 | put g_n 14 1 |
| 12540 | else |
| 12541 | put g_n 14 0 |
| 12542 | upr 0 0 |
| 12543 | x = ucall 26 |
| 12544 | rn = ucs x_env_screen |
| 12545 | upr 0 ulong libptr g_nm 0 1024 |
| 12546 | screen_text = ucall 9 |
| 12547 | if ne screen_text 0 |
| 12548 | rn = ufetch screen_text |
| 12549 | if eq get g_nm 0 99 |
| 12550 | put g_n 36 1 |
| 12551 | end |
| 12552 | if eq get g_nm 0 97 |
| 12553 | put g_n 36 2 |
| 12554 | end |
| 12555 | end |
| 12556 | rn = ucs x_env_clipdo |
| 12557 | upr 0 ulong libptr g_nm 0 1024 |
| 12558 | do_text = ucall 9 |
| 12559 | if ne do_text 0 |
| 12560 | rn = ufetch do_text |
| 12561 | if eq get g_nm 0 112 |
| 12562 | put g_n 37 1 |
| 12563 | end |
| 12564 | if eq get g_nm 0 100 |
| 12565 | put g_n 37 2 |
| 12566 | end |
| 12567 | if eq get g_nm 0 99 |
| 12568 | put g_n 37 3 |
| 12569 | end |
| 12570 | end |
| 12571 | end |
| 12572 | uloadindex |
| 12573 | uloadvault |
| 12574 | uloadconfig |
| 12575 | if eq get g_n 14 0 |
| 12576 | rn = ucs x_env_cliprec |
| 12577 | upr 0 ulong libptr g_nm 0 1024 |
| 12578 | if ne ucall 9 0 |
| 12579 | ucliprecord umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0 |
| 12580 | end |
| 12581 | end |
| 12582 | uloadclips |
| 12583 | put g_n 4 0 |
| 12584 | put g_n 13 0 |
| 12585 | unarrow |
| 12586 | if eq get g_n 0 0 |
| 12587 | ret 4 |
| 12588 | end |
| 12589 | c = ucl c_app |
| 12590 | s = usl m_shared |
| 12591 | app = umsg c s 0 0 0 |
| 12592 | n = ucs x_env |
| 12593 | upr 0 ulong libptr g_nm 0 1024 |
| 12594 | envp = ucall 9 |
| 12595 | chk = ne envp 0 |
| 12596 | opn = false |
| 12597 | ovr = false |
| 12598 | asking = false |
| 12599 | idle = false |
| 12600 | tl = ulong 0 |
| 12601 | pol = ulong 0 |
| 12602 | put g_n 7 1 |
| 12603 | if chk |
| 12604 | pol = 1 |
| 12605 | put g_n 7 0 |
| 12606 | n = ufetch envp |
| 12607 | skip = ulong 0 |
| 12608 | if and ge n 5 and or eq get g_nm 0 111 eq get g_nm 0 116 eq get g_nm 4 58 |
| 12609 | skip = 5 |
| 12610 | end |
| 12611 | if and ge n 4 and eq get g_nm 0 97 eq get g_nm 3 58 |
| 12612 | skip = 4 |
| 12613 | asking = true |
| 12614 | put g_n 7 1 |
| 12615 | end |
| 12616 | if and eq n 4 and eq get g_nm 0 105 eq get g_nm 3 101 |
| 12617 | skip = 4 |
| 12618 | idle = true |
| 12619 | end |
| 12620 | if and ge n 6 and eq get g_nm 0 97 eq get g_nm 5 58 |
| 12621 | skip = 6 |
| 12622 | asking = true |
| 12623 | put g_n 46 1 |
| 12624 | end |
| 12625 | if gt skip 0 |
| 12626 | ovr = true |
| 12627 | if eq get g_nm 0 111 |
| 12628 | opn = true |
| 12629 | put g_n 7 1 |
| 12630 | end |
| 12631 | tl = sub n skip |
| 12632 | if gt tl 60 |
| 12633 | tl = 60 |
| 12634 | end |
| 12635 | for i ulong tl bound 64 |
| 12636 | put g_t i get g_nm add skip i |
| 12637 | end |
| 12638 | end |
| 12639 | rn = ucs x_env_record |
| 12640 | upr 0 ulong libptr g_nm 0 1024 |
| 12641 | if ne ucall 9 0 |
| 12642 | put g_n 23 1 |
| 12643 | end |
| 12644 | rn = ucs x_env_row |
| 12645 | upr 0 ulong libptr g_nm 0 1024 |
| 12646 | row_text = ucall 9 |
| 12647 | if ne row_text 0 |
| 12648 | rn = ufetch row_text |
| 12649 | row_pick = ulong 0 |
| 12650 | for i ulong rn bound 4 |
| 12651 | row_digit = ulong get g_nm i |
| 12652 | if and ge row_digit 48 le row_digit 57 |
| 12653 | row_pick = add mul row_pick 10 sub row_digit 48 |
| 12654 | end |
| 12655 | end |
| 12656 | put g_n 30 row_pick |
| 12657 | end |
| 12658 | end |
| 12659 | s = usl m_policy |
| 12660 | x = umsg app s pol 0 0 |
| 12661 | note the class whose methods are the callback entries |
| 12662 | c = ucl c_obj |
| 12663 | n = ucs c_mine |
| 12664 | upr 0 c |
| 12665 | upr 8 ulong libptr g_nm 0 1024 |
| 12666 | upr 16 0 |
| 12667 | mine = ucall 4 |
| 12668 | if eq mine 0 |
| 12669 | ret 5 |
| 12670 | end |
| 12671 | ok = umethod mine m_change 0 t_v |
| 12672 | ok = and ok umethod mine m_rows 1 t_q |
| 12673 | ok = and ok umethod mine m_value 2 t_o |
| 12674 | ok = and ok umethod mine m_go 3 t_v |
| 12675 | ok = and ok umethod mine m_cmd 4 t_b |
| 12676 | ok = and ok umethod mine m_reopen 6 t_reopen |
| 12677 | ok = and ok umethod mine m_did_data 7 t_session |
| 12678 | ok = and ok umethod mine m_did_complete 8 t_session |
| 12679 | ok = and ok umethod mine m_paste_now 9 t_v |
| 12680 | ok = and ok umethod mine m_clip_tick 10 t_v |
| 12681 | ok = and ok umethod mine m_pin_clip 11 t_v |
| 12682 | ok = and ok umethod mine m_delete_clip 12 t_v |
| 12683 | ok = and ok umethod mine m_agent_out 13 t_v |
| 12684 | ok = and ok umethod mine m_agent_err 13 t_v |
| 12685 | ok = and ok umethod mine m_agent_end 13 t_v |
| 12686 | ok = and ok umethod mine m_agent_stop 13 t_v |
| 12687 | put g_m 38 usl m_agent_out |
| 12688 | put g_m 39 usl m_agent_err |
| 12689 | put g_m 40 usl m_agent_end |
| 12690 | put g_m 41 usl m_agent_stop |
| 12691 | ok = and ok umoremethods mine |
| 12692 | ok = and ok ustatusmethods mine |
| 12693 | ok = and ok uquitwatch mine |
| 12694 | uchecklate |
| 12695 | if not ok |
| 12696 | ret 6 |
| 12697 | end |
| 12698 | upr 0 mine |
| 12699 | x = ucall 6 |
| 12700 | s = usl m_alloc |
| 12701 | me = umsg mine s 0 0 0 |
| 12702 | me = umsg me sinit 0 0 0 |
| 12703 | put g_o 27 me |
| 12704 | note the window |
| 12705 | c = ucl c_win |
| 12706 | s = usl m_alloc |
| 12707 | w = umsg c s 0 0 0 |
| 12708 | s = usl m_initwi |
| 12709 | urect 240.0f64 260.0f64 520.0f64 360.0f64 |
| 12710 | w = umsg w s 3 2 0 |
| 12711 | if eq w 0 |
| 12712 | ret 7 |
| 12713 | end |
| 12714 | str = uns x_title |
| 12715 | s = usl m_title |
| 12716 | x = umsg w s str 0 0 |
| 12717 | s = usl m_conten |
| 12718 | cv = umsg w s 0 0 0 |
| 12719 | sadd = usl m_addsub |
| 12720 | sframe = usl m_initfr |
| 12721 | note the search field |
| 12722 | c = ucl c_field |
| 12723 | s = usl m_alloc |
| 12724 | fld = umsg c s 0 0 0 |
| 12725 | urect 16.0f64 316.0f64 488.0f64 28.0f64 |
| 12726 | fld = umsg fld sframe 0 0 0 |
| 12727 | str = uns x_hint |
| 12728 | s = usl m_placeh |
| 12729 | x = umsg fld s str 0 0 |
| 12730 | s = usl m_setdel |
| 12731 | x = umsg fld s me 0 0 |
| 12732 | s = usl m_settar |
| 12733 | x = umsg fld s me 0 0 |
| 12734 | s = usl m_setact |
| 12735 | sgo = usl m_go |
| 12736 | x = umsg fld s sgo 0 0 |
| 12737 | x = umsg cv sadd fld 0 0 |
| 12738 | put g_o 0 fld |
| 12739 | note the status line |
| 12740 | str = uns x_hint |
| 12741 | c = ucl c_field |
| 12742 | s = usl m_label |
| 12743 | lbl = umsg c s str 0 0 |
| 12744 | s = usl m_setfra |
| 12745 | urect 16.0f64 8.0f64 488.0f64 20.0f64 |
| 12746 | x = umsg lbl s 0 0 0 |
| 12747 | x = umsg cv sadd lbl 0 0 |
| 12748 | put g_o 2 lbl |
| 12749 | note the list |
| 12750 | c = ucl c_scroll |
| 12751 | s = usl m_alloc |
| 12752 | sv = umsg c s 0 0 0 |
| 12753 | urect 16.0f64 36.0f64 488.0f64 272.0f64 |
| 12754 | sv = umsg sv sframe 0 0 0 |
| 12755 | c = ucl c_table |
| 12756 | s = usl m_alloc |
| 12757 | tv = umsg c s 0 0 0 |
| 12758 | urect 0.0f64 0.0f64 470.0f64 272.0f64 |
| 12759 | tv = umsg tv sframe 0 0 0 |
| 12760 | c = ucl c_col |
| 12761 | s = usl m_alloc |
| 12762 | col = umsg c s 0 0 0 |
| 12763 | str = uns x_name |
| 12764 | s = usl m_initid |
| 12765 | col = umsg col s str 0 0 |
| 12766 | s = usl m_setwid |
| 12767 | upr 64 bitcast ulong 460.0f64 |
| 12768 | x = umsg col s 0 0 0 |
| 12769 | s = usl m_addcol |
| 12770 | x = umsg tv s col 0 0 |
| 12771 | s = usl m_header |
| 12772 | x = umsg tv s 0 0 0 |
| 12773 | s = usl m_dataso |
| 12774 | x = umsg tv s me 0 0 |
| 12775 | s = usl m_docvie |
| 12776 | x = umsg sv s tv 0 0 |
| 12777 | s = usl m_scroll |
| 12778 | x = umsg sv s 1 0 0 |
| 12779 | x = umsg cv sadd sv 0 0 |
| 12780 | put g_o 1 tv |
| 12781 | put g_o 28 sv |
| 12782 | note the answer: a text view in the list's place, hidden until a question is asked |
| 12783 | c = ucl c_scroll |
| 12784 | s = usl m_alloc |
| 12785 | answer_scroll = umsg c s 0 0 0 |
| 12786 | urect 16.0f64 36.0f64 488.0f64 272.0f64 |
| 12787 | answer_scroll = umsg answer_scroll sframe 0 0 0 |
| 12788 | c = ucl c_text_view |
| 12789 | s = usl m_alloc |
| 12790 | answer_text = umsg c s 0 0 0 |
| 12791 | urect 0.0f64 0.0f64 470.0f64 272.0f64 |
| 12792 | answer_text = umsg answer_text sframe 0 0 0 |
| 12793 | x = umsg answer_text usl m_set_editable 0 0 0 |
| 12794 | x = umsg answer_scroll usl m_docvie answer_text 0 0 |
| 12795 | x = umsg answer_scroll usl m_scroll 1 0 0 |
| 12796 | x = umsg answer_scroll usl m_set_hidden 1 0 0 |
| 12797 | x = umsg cv sadd answer_scroll 0 0 |
| 12798 | put g_o 29 answer_scroll |
| 12799 | put g_o 30 answer_text |
| 12800 | ushowst |
| 12801 | s = usl m_finish |
| 12802 | x = umsg app s 0 0 0 |
| 12803 | put g_o 19 w |
| 12804 | put g_o 20 usl m_order_out |
| 12805 | put g_o 21 app |
| 12806 | put g_o 22 usl m_hide_app |
| 12807 | put g_o 23 usl m_activ |
| 12808 | put g_o 24 usl m_key |
| 12809 | put g_o 25 usl m_firstr |
| 12810 | put g_o 26 usl m_front |
| 12811 | s = usl m_released |
| 12812 | x = umsg w s 0 0 0 |
| 12813 | s = usl m_set_app_delegate |
| 12814 | x = umsg app s me 0 0 |
| 12815 | if chk |
| 12816 | put g_n 14 0 |
| 12817 | put g_n 15 ukey 80 6912 |
| 12818 | else |
| 12819 | put g_n 14 1 |
| 12820 | put g_n 15 ukey 49 2048 |
| 12821 | umenu app |
| 12822 | note keep the history of what is copied while Hop is not running: look twice a second |
| 12823 | first_board = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0 |
| 12824 | put g_n 35 umsg first_board usl m_change_count 0 0 0 |
| 12825 | c_t = ucl c_timer |
| 12826 | s_timer = usl m_timer |
| 12827 | s_tick = usl m_clip_tick |
| 12828 | upr 64 bitcast ulong 0.5f64 |
| 12829 | upr 40 1 |
| 12830 | x = umsg c_t s_timer get g_o 27 s_tick 0 |
| 12831 | if and not uhoprunning uindexstale |
| 12832 | uindexstart |
| 12833 | end |
| 12834 | if not uhoprunning |
| 12835 | uremoterefreshall |
| 12836 | end |
| 12837 | end |
| 12838 | ushow |
| 12839 | if gt get g_n 1 0 |
| 12840 | uchoose 0 |
| 12841 | end |
| 12842 | svis = usl m_visibl |
| 12843 | vis = and umsg w svis 0 0 0 255 |
| 12844 | mode = uns x_mode |
| 12845 | cd = ucl c_date |
| 12846 | sd = usl m_since |
| 12847 | sn = usl m_next |
| 12848 | se = usl m_send |
| 12849 | schanged = usl m_change |
| 12850 | total = get g_n 0 |
| 12851 | if not chk |
| 12852 | note a person uses it: AppKit's own event loop, until the app is quit |
| 12853 | s = usl m_run |
| 12854 | x = umsg app s 0 0 0 |
| 12855 | ret 0 |
| 12856 | end |
| 12857 | note the check: about six seconds. The text goes in through the field's editor; arrow down, Enter and Escape are |
| 12858 | note commands sent to that editor, which asks the field, which asks its delegate and sends its action |
| 12859 | sfr = usl m_firstr |
| 12860 | sed = usl m_curred |
| 12861 | sins = usl m_instxt |
| 12862 | sdo = usl m_docmd |
| 12863 | snl = usl m_newln |
| 12864 | esc = ulong 0 |
| 12865 | hid = ulong 0 |
| 12866 | back = ulong 0 |
| 12867 | for i ulong 120 |
| 12868 | upr 64 bitcast ulong 0.05f64 |
| 12869 | d = umsg cd sd 0 0 0 |
| 12870 | utick app sn se mode d |
| 12871 | if eq i 10 |
| 12872 | x = umsg w sfr fld 0 0 |
| 12873 | ed = umsg fld sed 0 0 0 |
| 12874 | if ovr |
| 12875 | for j ulong tl bound 64 |
| 12876 | put g_nm j get g_t j |
| 12877 | end |
| 12878 | put g_nm tl 0 |
| 12879 | str = unsb |
| 12880 | else |
| 12881 | str = uns x_typed |
| 12882 | end |
| 12883 | if not idle |
| 12884 | x = umsg ed sins str 0 0 |
| 12885 | end |
| 12886 | end |
| 12887 | if and eq i 15 not ovr |
| 12888 | ed = umsg fld sed 0 0 0 |
| 12889 | x = umsg ed sdo get g_o 9 0 0 |
| 12890 | end |
| 12891 | if and and eq i 15 ovr and gt get g_n 30 0 lt get g_n 30 get g_n 1 |
| 12892 | uchoose get g_n 30 |
| 12893 | end |
| 12894 | if and and eq i 16 ovr ne get g_n 37 0 |
| 12895 | if eq get g_n 37 3 |
| 12896 | uclipclear |
| 12897 | else |
| 12898 | uclipmenu get g_n 37 |
| 12899 | end |
| 12900 | end |
| 12901 | if eq i 2 |
| 12902 | ustatus |
| 12903 | utunnelcheck |
| 12904 | end |
| 12905 | if eq i get g_n 48 |
| 12906 | ed = umsg fld sed 0 0 0 |
| 12907 | x = umsg ed sdo snl 0 0 |
| 12908 | end |
| 12909 | if eq i 60 |
| 12910 | uasksecond |
| 12911 | end |
| 12912 | if and and eq i 25 not asking eq get g_n 36 0 |
| 12913 | put g_n 5 0 |
| 12914 | x = umsg w sfr fld 0 0 |
| 12915 | ed = umsg fld sed 0 0 0 |
| 12916 | x = umsg ed sdo get g_o 11 0 0 |
| 12917 | esc = get g_n 5 |
| 12918 | put g_n 5 0 |
| 12919 | if eq and umsg w svis 0 0 0 255 0 |
| 12920 | hid = 1 |
| 12921 | end |
| 12922 | end |
| 12923 | if eq i 30 |
| 12924 | upr 0 0 |
| 12925 | upr 8 0 |
| 12926 | upr 16 0 |
| 12927 | x = ucallf ulong libfn 7 |
| 12928 | if eq and umsg w svis 0 0 0 255 1 |
| 12929 | back = 1 |
| 12930 | end |
| 12931 | end |
| 12932 | end |
| 12933 | note the first row, asked of the list's own data source through Objective-C, and the list's own selection |
| 12934 | shown = get g_n 1 |
| 12935 | row = umsg tv usl m_selrd 0 0 0 |
| 12936 | want = ulong 0 |
| 12937 | if and gt shown 1 not ovr |
| 12938 | want = 1 |
| 12939 | end |
| 12940 | first = umsg me usl m_value tv col 0 |
| 12941 | flen = ulong 0 |
| 12942 | if ne first 0 |
| 12943 | p = umsg first get g_o 5 0 0 0 |
| 12944 | flen = ufetch p |
| 12945 | end |
| 12946 | if gt flen 255 |
| 12947 | flen = 255 |
| 12948 | end |
| 12949 | for i ulong flen bound 256 |
| 12950 | put g_x i get g_nm i |
| 12951 | end |
| 12952 | uvaultcheckend |
| 12953 | utunnelstop |
| 12954 | paste_text = ulong 0 |
| 12955 | paste_size = ulong 0 |
| 12956 | if ne get g_n 29 0 |
| 12957 | pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0 |
| 12958 | if eq get g_n 29 1 |
| 12959 | got = umsg pboard usl m_string_for_type uns x_type_string 0 0 |
| 12960 | if ne got 0 |
| 12961 | paste_text = umsg got get g_o 5 0 0 0 |
| 12962 | end |
| 12963 | else |
| 12964 | got = umsg pboard usl m_data_for_type uns x_type_png 0 0 |
| 12965 | if ne got 0 |
| 12966 | paste_size = umsg got usl m_length 0 0 0 |
| 12967 | end |
| 12968 | end |
| 12969 | x = umsg pboard usl m_clear 0 0 0 |
| 12970 | end |
| 12971 | p = uptxt 0 x_out1 |
| 12972 | p = upnum p total |
| 12973 | p = uptxt p x_out2 |
| 12974 | p = upnum p shown |
| 12975 | p = uptxt p x_out3 |
| 12976 | for i ulong flen bound 256 |
| 12977 | put g_nm add p i get g_x i |
| 12978 | end |
| 12979 | p = add p flen |
| 12980 | p = uptxt p x_out4 |
| 12981 | p = upnum p and row 255 |
| 12982 | p = uptxt p x_out5 |
| 12983 | if and gt get g_n 8 0 le get g_n 8 shown |
| 12984 | p = uprow p sub get g_n 8 1 |
| 12985 | end |
| 12986 | if opn |
| 12987 | p = uptxt p x_out6 |
| 12988 | p = upnum p get g_n 9 |
| 12989 | end |
| 12990 | if ne get g_n 29 0 |
| 12991 | p = uptxt p x_out11 |
| 12992 | if ne paste_text 0 |
| 12993 | upr 0 paste_text |
| 12994 | pn = ucall 7 |
| 12995 | if gt pn 80 |
| 12996 | pn = 80 |
| 12997 | end |
| 12998 | if gt pn 0 |
| 12999 | upr 0 ulong libptr g_nm p pn |
| 13000 | upr 8 paste_text |
| 13001 | upr 16 pn |
| 13002 | x = ucall 8 |
| 13003 | for j ulong pn bound 81 |
| 13004 | if lt ulong get g_nm add p j 32 |
| 13005 | put g_nm add p j 32 |
| 13006 | end |
| 13007 | end |
| 13008 | p = add p pn |
| 13009 | end |
| 13010 | end |
| 13011 | if eq get g_n 29 2 |
| 13012 | p = uptxt p x_png_word |
| 13013 | p = upnum p paste_size |
| 13014 | end |
| 13015 | end |
| 13016 | if ne get g_n 36 0 |
| 13017 | p = uptxt p x_out12 |
| 13018 | p = upnum p get g_n 36 |
| 13019 | end |
| 13020 | if eq get g_n 55 1 |
| 13021 | p = uptxt p x_out13 |
| 13022 | p = upnum p 1 |
| 13023 | end |
| 13024 | if gt get g_n 62 0 |
| 13025 | p = uptxt p x_out16 |
| 13026 | p = upnum p get g_n 61 |
| 13027 | end |
| 13028 | if ne get g_n 51 0 |
| 13029 | p = uptxt p x_out14 |
| 13030 | p = upnum p get g_n 52 |
| 13031 | p = uptxt p x_out15 |
| 13032 | p = upnum p get g_n 51 |
| 13033 | end |
| 13034 | answered = false |
| 13035 | if asking |
| 13036 | p = uptxt p x_out10 |
| 13037 | if ne get g_m 4 0 |
| 13038 | answer_bytes = umsg get g_m 4 get g_o 5 0 0 0 |
| 13039 | upr 0 answer_bytes |
| 13040 | an = ucall 7 |
| 13041 | if gt an 120 |
| 13042 | an = 120 |
| 13043 | end |
| 13044 | upr 0 ulong libptr g_nm p an |
| 13045 | upr 8 answer_bytes |
| 13046 | upr 16 an |
| 13047 | x = ucall 8 |
| 13048 | for j ulong an bound 121 |
| 13049 | if lt ulong get g_nm add p j 32 |
| 13050 | put g_nm add p j 32 |
| 13051 | end |
| 13052 | end |
| 13053 | p = add p an |
| 13054 | answered = and and gt an 0 eq get g_n 21 1 eq get g_n 22 1 |
| 13055 | end |
| 13056 | end |
| 13057 | if not ovr |
| 13058 | p = uptxt p x_out7 |
| 13059 | p = upnum p get g_n 15 |
| 13060 | p = uptxt p x_out8 |
| 13061 | p = upnum p hid |
| 13062 | p = uptxt p x_out9 |
| 13063 | p = upnum p back |
| 13064 | end |
| 13065 | put g_nm p 10 |
| 13066 | upr 0 1 |
| 13067 | upr 8 ulong libptr g_nm 0 1024 |
| 13068 | upr 16 add p 1 |
| 13069 | x = ucall 3 |
| 13070 | s = usl m_close |
| 13071 | x = umsg w s 0 0 0 |
| 13072 | if ne vis 1 |
| 13073 | ret 8 |
| 13074 | end |
| 13075 | if ovr |
| 13076 | took = true |
| 13077 | if opn |
| 13078 | took = eq get g_n 9 1 |
| 13079 | end |
| 13080 | if asking |
| 13081 | took = answered |
| 13082 | end |
| 13083 | if and and gt shown 0 eq get g_n 3 1 and gt get g_n 8 0 took |
| 13084 | ret 1 |
| 13085 | end |
| 13086 | ret 9 |
| 13087 | end |
| 13088 | picked = and eq get g_n 8 add want 1 eq ulong get g_rk 0 1 |
| 13089 | if 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 |
| 13090 | ret 1 |
| 13091 | end |
| 13092 | ret 9 |
| 13093 | end |