|
|
1.1 root 1: /*
2: * uaeexe.c - UAE remote cli
3: *
4: * (c) 1997 by Samuel Devulder
5: */
6:
7: #include "sysconfig.h"
8: #include "sysdeps.h"
9:
10: #include "options.h"
11: #include "uae.h"
12: #include "memory.h"
13: #include "custom.h"
14: #include "newcpu.h"
1.1.1.5 ! root 15: #include "traps.h"
1.1 root 16: #include "autoconf.h"
17: #include "uaeexe.h"
18:
19: static struct uae_xcmd *first = NULL;
20: static struct uae_xcmd *last = NULL;
21: static char running = 0;
22:
23: /*
24: * Send command to the remote cli.
25: *
1.1.1.5 ! root 26: * To use this, just call uaeexe ("command") and the command will be
1.1 root 27: * executed by the remote cli (provided you've started it in the
28: * s:user-startup for example). Be sure to add "run" if you want
29: * to launch the command asynchronously. Please note also that the
30: * remote cli works better if you've got the fifo-handler installed.
31: */
1.1.1.5 ! root 32: int uaeexe (const char *cmd)
1.1 root 33: {
34: struct uae_xcmd *nw;
35:
36: if (!running)
37: goto NORUN;
38:
1.1.1.5 ! root 39: nw = malloc (sizeof *nw);
1.1 root 40: if (!nw)
41: goto NOMEM;
1.1.1.5 ! root 42: nw->cmd = malloc (strlen (cmd) + 1);
1.1 root 43: if (!nw->cmd) {
44: free (nw);
45: goto NOMEM;
46: }
47:
48: strcpy (nw->cmd, cmd);
49: nw->prev = last;
50: nw->next = NULL;
51:
1.1.1.4 root 52: if (!first)
53: first = nw;
54: if (last) {
55: last->next = nw;
56: last = nw;
57: } else
58: last = nw;
1.1 root 59:
60: return UAEEXE_OK;
61: NOMEM:
62: return UAEEXE_NOMEM;
63: NORUN:
1.1.1.4 root 64: write_log ("Remote cli is not running.\n");
1.1 root 65: return UAEEXE_NOTRUNNING;
66: }
67:
68: /*
69: * returns next command to be executed
70: */
1.1.1.4 root 71: static char *get_cmd (void)
1.1 root 72: {
73: struct uae_xcmd *cmd;
74: char *s;
75:
1.1.1.4 root 76: if (!first)
77: return NULL;
1.1.1.3 root 78: s = first->cmd;
1.1.1.4 root 79: cmd = first;
80: first = first->next;
81: if (!first)
82: last = NULL;
83: free (cmd);
1.1 root 84: return s;
85: }
86:
87: /*
88: * helper function
89: */
1.1.1.5 ! root 90: #define ARG(x) (get_long (m68k_areg (regs, 7) + 4 * (x + 1)))
! 91: static uae_u32 uaeexe_server (TrapContext *dummy)
1.1 root 92: {
93: int len;
94: char *cmd;
95: char *dst;
96:
1.1.1.5 ! root 97: if (ARG (0) && !running) {
1.1.1.3 root 98: running = 1;
1.1.1.4 root 99: write_log ("Remote CLI started.\n");
1.1 root 100: }
101:
1.1.1.5 ! root 102: cmd = get_cmd ();
1.1.1.4 root 103: if (!cmd)
104: return 0;
1.1.1.5 ! root 105: if (!ARG (0)) {
1.1.1.4 root 106: running = 0;
107: return 0;
108: }
1.1 root 109:
1.1.1.5 ! root 110: dst = (char *) get_real_address (ARG (0));
1.1.1.4 root 111: len = ARG (1);
1.1.1.5 ! root 112: strncpy (dst, cmd, len);
! 113: printf ("Sending '%s' to remote cli\n", cmd); /**/
1.1.1.4 root 114: free (cmd);
115: return ARG (0);
1.1 root 116: }
1.1.1.5 ! root 117:
! 118: /*
! 119: * Install the server
! 120: */
! 121: void uaeexe_install (void)
! 122: {
! 123: uaecptr loop;
! 124:
! 125: loop = here ();
! 126: org (UAEEXE_ORG);
! 127: calltrap (deftrap (uaeexe_server));
! 128: dw (RTS);
! 129: org (loop);
! 130: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.