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

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

unix.superglobalmegacorp.com

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