https://github.com/akkartik/mu/blob/main/linux/braces.subx
  1 # Structured control flow using break/loop rather than jump.
  2 #
  3 # To run (on Linux):
  4 #   $ ./translate_subx init.linux [012]*.subx subx-params.subx braces.subx
  5 #   $ mv a.elf braces
  6 #
  7 # Example 1:
  8 #   $ cat x.subx
  9 #   {
 10 #     7c/jump-if-< break/disp8
 11 #     74/jump-if-= loop/disp8
 12 #   }
 13 #   $ cat x.subx |braces
 14 #   @loop1:
 15 #     7c/jump-if-< @break1/disp8
 16 #     74/jump-if-= @loop1/disp8
 17 #   @break1:
 18 #
 19 # Example 2:
 20 #   $ cat x.subx
 21 #   {
 22 #     7c/jump-if-< break/disp8
 23 #   }
 24 #   {
 25 #     74/jump-if-= loop/disp8
 26 #   }
 27 #   $ cat x.subx |braces
 28 #   @loop1:
 29 #     7c/jump-if-< @break1/disp8
 30 #   @break1:
 31 #   @loop2:
 32 #     74/jump-if-= @loop2/disp8
 33 #   @break2:
 34 #
 35 # Example 3:
 36 pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * http_download.h
 * vim: expandtab:ts=4:sts=4:sw=4
 *
 * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
 * Copyright (C) 2020 William Wennerström <william@wstrm.dev>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#ifndef TOOLS_HTTP_DOWNLOAD_H
#define TOOLS_HTTP_DOWNLOAD_H

#ifdef PLATFORM_CYGWIN
#define SOCKET int
#endif

#include <sys/select.h>
#include <curl/curl.h>

#include "ui/win_types.h"
#include "tools/http_common.h"

typedef struct http_download_t
{
    char* id;
    char* url;
    char* filename;
    char* cmd_template;
    curl_off_t bytes_received;
    ProfWin* window;
    pthread_t worker;
    int cancel;
} HTTPDownload;

void* http_file_get(void* userdata);

void http_download_cancel_processes(ProfWin* window);
void http_download_add_download(HTTPDownload* download);

#endif
span id="L146" class="LineNr">146 # if (line->write == 0) break 147 81 7/subop/compare *ecx 0/imm32 148 0f 84/jump-if-= $subx-braces:break/disp32 149 (skip-chars-matching-whitespace %ecx) 150 $subx-braces:check-for-curly-open: 151 # if (line->data[line->read] != '{') goto next check 152 # . eax = line->data[line->read] 153 8b/-> *(ecx+4) 0/r32/eax 154 8a/copy-byte *(ecx+eax+0xc) 0/r32/AL 155 25/and-eax-with 0xff/imm32 156 # . if (eax != '{') continue 157 3d/compare-eax-and 0x7b/imm32/open-curly 158 0f 85/jump-if-!= $subx-braces:check-for-curly-closed/disp32 159 $subx-braces:emit-curly-open: 160 # print(out, "@loop" next-label-id ":") 161 (write-buffered *(ebp+0xc) "@loop") 162 (write-int32-hex-buffered *(ebp+0xc) %ebx) 163 (write-buffered *(ebp+0xc) ":") 164 # push(label-stack, next-label-id) 165 (push %edx %ebx) 166 # ++next-label-id 167 ff 0/subop/increment %ebx 168 # continue 169 e9/jump $subx-braces:next-line/disp32 170 $subx-braces:check-for-curly-closed: 171 # if (line->data[line->read] != '}') goto next check 172 3d/compare-eax-and 0x7d/imm32/close-curly 173 0f 85/jump-if-= $subx-braces:word-loop/disp32 174 $subx-braces:emit-curly-closed: 175 # eax = pop(label-stack) 176 (pop %edx) 177 # print(out, "@break" eax ":") 178 (write-buffered *(ebp+0xc) "@break") 179 (write-int32-hex-buffered *(ebp+0xc) %eax) 180 (write-buffered *(ebp+0xc) ":") 181 # continue 182 e9/jump $subx-braces:next-line/disp32 183 $subx-braces:word-loop: 184 (next-word-or-string %ecx %edi) 185 $subx-braces:check1: 186 # if (slice-empty?(word-slice)) break 187 (slice-empty? %edi) 188 3d/compare-eax-and 0/imm32/false 189 0f 85/jump-if-!= $subx-braces:next-line/disp32 190 $subx-braces:check-for-comment: 191 # if (slice-starts-with?(word-slice, "#")) continue 192 # . eax = *word-slice->start 193 8b/-> *edi 0/r32/eax 194 8a/copy-byte *eax 0/r32/AL 195 25/and-eax-with 0xff/imm32 196 # . if (eax == '#') continue 197 3d/compare-eax-and 0x23/imm32/hash 198 74/jump-if-= $subx-braces:word-loop/disp8 199 $subx-braces:check-for-break: 200 # if (!slice-starts-with?(word-slice, "break/")) goto next check 201 # . eax = slice-starts-with?(word-slice, "break/") 202 (slice-starts-with? %edi "break/") 203 # . if (eax == false) goto next check 204 3d/compare-eax-and 0/imm32/false 205 74/jump-if-= $subx-braces:check-for-loop/disp8 206 $subx-braces:emit-break: 207 (top %edx) 208 # print(out, "@break" eax) 209 (write-buffered *(ebp+0xc) "@break") 210 (write-int32-hex-buffered *(ebp+0xc) %eax) 211 # word-slice->start += len("break") 212 81 0/subop/add *edi 5/imm32/strlen 213 # emit rest of word as usual 214 eb/jump $subx-braces:emit-word-slice/disp8 215 $subx-braces:check-for-loop: 216 # if (!slice-starts-with?(word-slice, "loop/")) emit word 217 # . eax = slice-starts-with?(word-slice, "loop/") 218 (slice-starts-with? %edi "loop/") 219 # . if (eax == false) goto next check 220 3d/compare-eax-and 0/imm32/false 221 74/jump-if-= $subx-braces:emit-word-slice/disp8 222 $subx-braces:emit-loop: 223 (top %edx) 224 # print(out, "@loop" eax) 225 (write-buffered *(ebp+0xc) "@loop") 226 (write-int32-hex-buffered *(ebp+0xc) %eax) 227 # word-slice->start += len("loop") 228 81 0/subop/add *edi 4/imm32/strlen 229 # fall through 230 $subx-braces:emit-word-slice: 231 # print(out, word-slice " ") 232 (write-slice-buffered *(ebp+0xc) %edi) 233 (write-buffered *(ebp+0xc) Space) 234 # loop to next word 235 e9/jump $subx-braces:word-loop/disp32 236 $subx-braces:next-line: 237 # print(out, "\n") 238 (write-buffered *(ebp+0xc) Newline) 239 # loop to next line 240 e9/jump $subx-braces:line-loop/disp32 241 $subx-braces:break: 242 (flush *(ebp+0xc)) 243 $subx-braces:end: 244 # . reclaim locals 245 81 0/subop/add %esp 0x29c/imm32 246 # . restore registers 247 5f/pop-to-edi 248 5e/pop-to-esi 249 5b/pop-to-ebx 250 5a/pop-to-edx 251 59/pop-to-ecx 252 58/pop-to-eax 253 # . epilogue 254 89/<- %esp 5/r32/ebp 255 5d/pop-to-ebp 256 c3/return 257 258 test-subx-braces-passes-most-words-through: 259 # . prologue 260 55/push-ebp 261 89/<- %ebp 4/r32/esp 262 # setup 263 (clear-stream _test-input-stream) 264 (clear-stream _test-output-stream) 265 (clear-stream $_test-input-buffered-file->buffer) 266 (clear-stream $_test-output-buffered-file->buffer) 267 # test 268 (write _test-input-stream "== abcd 0x1") 269 (subx-braces _test-input-buffered-file _test-output-buffered-file) 270 # check that the line just passed through 271 (flush _test-output-buffered-file) 272 +-- 5 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------- 277 (check-stream-equal _test-output-stream "== abcd 0x1 \n" "F - test-subx-braces-passes-most-words-through") 278 # . epilogue 279 89/<- %esp 5/r32/ebp 280 5d/pop-to-ebp 281 c3/return 282 283 test-subx-braces-1: 284 # input: 285 # { 286 # ab break/imm32 287 # cd loop/imm32 288 # } 289 # 290 # output: 291 # @loop1: 292 # ab @break1/imm32 293 # cd @loop1/imm32 294 # @break1: 295 # 296 # . prologue 297 55/push-ebp 298 89/<- %ebp 4/r32/esp 299 # setup 300 (clear-stream _test-input-stream) 301 (clear-stream _test-output-stream) 302 (clear-stream $_test-input-buffered-file->buffer) 303 (clear-stream $_test-output-buffered-file->buffer) 304 # test 305 (write _test-input-stream "{\nab break/imm32\ncd loop/imm32\n}") 306 (subx-braces _test-input-buffered-file _test-output-buffered-file) 307 # check that the line just passed through 308 (flush _test-output-buffered-file) 309 +-- 5 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------- 314 (check-stream-equal _test-output-stream "@loop0x00000001:\nab @break0x00000001/imm32 \ncd @loop0x00000001/imm32 \n@break0x00000001:\n" "F - test-subx-braces-1") 315 # . epilogue 316 89/<- %esp 5/r32/ebp 317 5d/pop-to-ebp 318 c3/return 319 320 test-subx-braces-2: 321 # input: 322 # { 323 # { 324 # ab break/imm32 325 # } 326 # cd loop/imm32 327 # } 328 # 329 # output: 330 # @loop1: 331 # @loop2: 332 # ab @break2/imm32 333 # @break2: 334 # cd @loop1/imm32 335 # @break1: 336 # 337 # . prologue 338 55/push-ebp 339 89/<- %ebp 4/r32/esp 340 # setup 341 (clear-stream _test-input-stream) 342 (clear-stream _test-output-stream) 343 (clear-stream $_test-input-buffered-file->buffer) 344 (clear-stream $_test-output-buffered-file->buffer) 345 # test 346 (write _test-input-stream "{\n{\nab break/imm32\n}\ncd loop/imm32\n}") 347 (subx-braces _test-input-buffered-file _test-output-buffered-file) 348 # check that the line just passed through 349 (flush _test-output-buffered-file) 350 +-- 5 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------- 355 (check-stream-equal _test-output-stream "@loop0x00000001:\n@loop0x00000002:\nab @break0x00000002/imm32 \n@break0x00000002:\ncd @loop0x00000001/imm32 \n@break0x00000001:\n" "F - test-subx-braces-2") 356 # . epilogue 357 89/<- %esp 5/r32/ebp 358 5d/pop-to-ebp 359 c3/return