Annotation of uae/src/uaeexe.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.