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