== code # instruction effective address register displacement immediate # . op subop mod rm32 base index scale r32 # . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes # If datum of 'word' is not a valid name, it must be a hex int. Parse and print # it in 'width' bytes of hex, least significant first. # Otherwise just print the entire word including metadata. # Always print a trailing space. emit: # out: (addr buffered-file), word: (addr slice), width: int # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 50/push-eax 56/push-esi 57/push-edi # esi = word 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0xc/disp8 . # copy *(ebp+12) to esi # var datum/edi: slice 68/push 0/imm32/end 68/push 0/imm32/start 89/copy 3/mod/direct 7/rm32/edi . . . 4/r32/esp . . # copy esp to edi # datum = next-token-from-slice(word->start, word->end, '/') # . . push args 57/push-edi 68/push 0x2f/imm32/slash ff 6/subop/push 1/mod/*+disp8 6/rm32/esi . . . . 4/disp8 . # push *(esi+4) ff 6/subop/push 0/mod/indirect 6/rm32/esi . . . . . . # push *esi # . . call e8/call next-token-from-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp # if (is-valid-name?(datum)) write-slice-buffered(out, word) and return # . eax = is-valid-name?(name) # . . push args 57/push-edi # . . call e8/call is-valid-name?/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . if (eax != false) 3d/compare-eax-and 0/imm32/false 74/jump-if-= $emit:hex-int/disp8 $emit:name: # . write-slice-buffered(out, word) # . . push args 56/push-esi ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write-buffered(out, " ") # . . push args 68/push Space/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call write-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . return eb/jump $emit:end/disp8 # otherwise emit-hex(out, parse-hex-int-from-slice(datum), width) # (Weird shit can happen here if the datum of 'word' isn't either a valid # name or a hex number. `emit` is mostly used by translate_subx, which # is currently designed to only receive legal SubX programs. We just # want to make sure that valid names aren't treated as (valid) hex # numbers.) $emit:hex-int: # . var value/eax: int = parse-hex-int-from-slice(datum) # . . push args 57/push-edi # . . call e8/call parse-hex-int-from-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . emit-hex(out, value, width) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 . # push *(ebp+16) 50/push-eax ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call emit-hex/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp $emit:end: # . reclaim locals 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . restore registers 5f/pop-to-edi 5e/pop-to-esi 58/pop-to-eax # . epi
/*
* profanity.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include <string.h>
#include <stdlib.h>
#include <ncurses.h>
#include "profanity.h"
#include "log.h"
#include "windows.h"
#include "jabber.h"
#include "command.h"
#include "history.h"
static void _profanity_shutdown(void);
void profanity_run(void)
{
int cmd_result = TRUE;
inp_non_block();
while(cmd_result == TRUE) {
int ch = ERR;
char inp[100];
int size = 0;
while(ch != '\n') {
win_handle_special_keys(&ch);
if (ch == KEY_RESIZE) {
gui_resize(ch, inp, size);
}
gui_refresh();
jabber_process_events();
inp_get_char(&ch, inp, &size);
}
inp[size++] = '\0';
cmd_result = process_input(inp);
}
}
void profanity_init(const int disable_tls)
{
log_init();
gui_init();
jabber_init(disable_tls);
history_init();
atexit(_profanity_shutdown);
}
void _profanity_shutdown(void)
{
jabber_disconnect();
gui_close();
log_close();
}