Annotation of uae/src/od-amiga/ami-rexx.c, revision 1.1.1.5

1.1       root        1:  /*
                      2:   * UAE - The Un*x Amiga Emulator
1.1.1.4   root        3:   *
1.1       root        4:   * ami-rexx.c
1.1.1.4   root        5:   *
1.1       root        6:   * Copyright 1996 Samuel Devulder.
                      7:   *
                      8:   * History:
                      9:   *     05/09/97: Added UAEEXE support.
1.1.1.2   root       10:   *    04/03/98: Added event-hack for SOUND(). Added do_inhibit_frame().
                     11:   *    03/05/98: Modified currprefs to changed_prefs where necessary.
1.1       root       12:   */
                     13: 
1.1.1.2   root       14: /****************************************************************************/
                     15: 
                     16: #if defined(POWERUP)
                     17: #include <exec/exec.h> /* sam: I've added this or else I have warnings about missing struct def. */
                     18: #ifndef USE_CLIB
                     19: #include <powerup/ppcproto/exec.h>
                     20: #include <powerup/ppcproto/rexxsyslib.h>
                     21: #include <powerup/ppcproto/dos.h>
                     22: #else
                     23: #include <clib/exec_protos.h>
                     24: #include <clib/alib_protos.h>
                     25: #endif
                     26: #else
1.1       root       27: #include <proto/exec.h>
                     28: #include <proto/rexxsyslib.h>
                     29: #include <proto/dos.h>
                     30: #ifndef __SASC
                     31: #include <proto/alib.h>
                     32: #endif
1.1.1.2   root       33: #endif
1.1       root       34: 
                     35: #include <rexx/storage.h>
                     36: #include <rexx/errors.h>
                     37: 
                     38: /* this prevent a conflict between <rexx/rexxio.h> and <sys/dirent.h> */
1.1.1.4   root       39: #undef DT_DIR
1.1       root       40: 
                     41: /****************************************************************************/
                     42: 
                     43: #include "sysconfig.h"
                     44: #include "sysdeps.h"
                     45: #include "uae.h"
                     46: #include "options.h"
                     47: #ifdef __GNUC__
                     48: #include "../include/memory.h" /* or else gcc includes machdep/memory.h */
1.1.1.2   root       49: #else
                     50: #include "/include/memory.h"
1.1       root       51: #endif
1.1.1.2   root       52: #include "events.h"
1.1       root       53: #include "custom.h"
                     54: #include "readcpu.h"
                     55: #include "newcpu.h"
                     56: #include "disk.h"
                     57: #include "gui.h"
                     58: #include "sound.h"
                     59: #include "gensound.h"
                     60: #include "uaeexe.h"
1.1.1.3   root       61: #include "threaddep/thread.h"
1.1       root       62: #include "xwin.h"
                     63: 
                     64: #include <ctype.h>
                     65: 
                     66: /****************************************************************************/
                     67: 
                     68: #define UAE_PORTNAME    "UAE"
                     69: #define RESULT_LEN      1024
                     70: #define PORT_LEN        80
                     71: #define CMD_LEN         1024
                     72: 
                     73: typedef struct
                     74: {
                     75:     char port[PORT_LEN];
                     76:     char cmd_on[CMD_LEN];
                     77:     char cmd_off[CMD_LEN];
                     78: } gui_rexx_s;
                     79: 
                     80: enum {LED_POW, LED_DF0, LED_DF1, LED_DF2, LED_DF3,
                     81:       NAME_DF0, NAME_DF1, NAME_DF2, NAME_DF3,
                     82:       ON_EXIT,
                     83:       GUI_REXX_MAX};
                     84: 
                     85: /****************************************************************************/
                     86: 
                     87: int  rexx_init(void);
                     88: void rexx_exit(void);
                     89: void rexx_led(int led, int on);
                     90: void rexx_filename(int num, char *name);
                     91: void rexx_handle_events(void);
1.1.1.2   root       92: int do_inhibit_frame(int); /* from ami-win.c */
1.1       root       93: 
                     94: /****************************************************************************/
                     95: 
                     96: #ifdef __GNUC__
                     97: struct RxsLib
                     98: #else
                     99: struct Library
                    100: #endif
1.1.1.4   root      101:                        *RexxSysBase;
1.1       root      102: static struct MsgPort   *ARexxPort;
                    103: static gui_rexx_s        gui_rexx[GUI_REXX_MAX];
                    104: static char              RESULT[RESULT_LEN];
                    105: static int               led_state[5];
                    106: 
                    107: static int   ADDRESS(char *hostname, char *cmd);
                    108: static int   matchstr(char **line,char *pat);
                    109: static void  extractstr(char **line, char *result, int len);
                    110: static int   matchnum(char **line);
                    111: 
                    112: /****************************************************************************/
                    113: 
                    114: extern int quit_program;                                 /* ami-gui.c */
1.1.1.2   root      115: extern ULONG frame_num;                                  /* ami-win.c */
1.1       root      116: extern void activate_debugger(void);                     /* debug.c */
                    117: extern char *to_unix_path(char *s);                      /* ami-disk.c */
                    118: extern char *from_unix_path(char *s);                    /* ami-disk.c */
                    119: 
                    120: /****************************************************************************/
                    121: 
                    122: int rexx_init(void)
                    123: {
                    124:     quit_program = 0;
                    125:     RexxSysBase = (void*)OpenLibrary("rexxsyslib.library",0L);
                    126:     if(!RexxSysBase) {
1.1.1.4   root      127:        fprintf(stderr, "Can't find rexxsyslib.library!\n");
                    128:        return 1;
1.1       root      129:     }
                    130:     if(FindPort(UAE_PORTNAME)) {
1.1.1.4   root      131:        fprintf(stderr, "Port \"%s\" already exists!\n",UAE_PORTNAME);
                    132:        return 1;
1.1       root      133:     }
                    134:     ARexxPort = CreatePort(UAE_PORTNAME,0);
                    135:     if(!ARexxPort) {
1.1.1.4   root      136:        fprintf(stderr, "Failed to open AREXX port \"%s\"!\n",UAE_PORTNAME);
                    137:        return 1;
1.1       root      138:     }
                    139:     fprintf(stderr,"Rexx port \"%s\" installed.\n", UAE_PORTNAME);
                    140:     rexx_handle_events();
                    141:     return 0;
                    142: }
                    143: 
                    144: /****************************************************************************/
                    145: 
                    146: void rexx_exit(void)
                    147: {
                    148:     if(ARexxPort) {
1.1.1.4   root      149:        struct RexxMsg *msg;
                    150:        gui_rexx_s *gui = &gui_rexx[ON_EXIT];
1.1       root      151: 
1.1.1.4   root      152:        if(gui->port[0] && gui->cmd_on[0]) {
                    153:            if(ADDRESS(gui->port, gui->cmd_on) != RC_OK) {
                    154:                fprintf(stderr,"%s:%s:%s\n", gui->port,
                    155:                                             gui->cmd_on,
                    156:                                             RESULT);
                    157:            }
                    158:            gui->port[0] = '\0';
                    159:         }
                    160:        Forbid();
                    161:        while((msg = (struct RexxMsg*)GetMsg(ARexxPort))) {
                    162:           msg->rm_Result1 = RC_ERROR;
                    163:           msg->rm_Result2 = NULL;
                    164:           ReplyMsg((void*)msg);
                    165:        }
                    166:        DeletePort(ARexxPort);
                    167:        Permit();
                    168:        ARexxPort = NULL;
1.1       root      169:     }
                    170:     if(RexxSysBase) {
1.1.1.4   root      171:        CloseLibrary((void*)RexxSysBase);
                    172:        RexxSysBase = NULL;
1.1       root      173:     }
                    174: }
                    175: 
                    176: /****************************************************************************/
                    177: 
                    178: static int EJECT(char *line)
                    179: {
                    180:     int drive = matchnum(&line);
                    181:     if(drive<0 || drive>3) return RC_WARN;
                    182:     disk_eject(drive);
                    183:     sprintf(RESULT,"Drive %d ejected",drive);
                    184:     return RC_OK;
                    185: }
                    186: 
                    187: /****************************************************************************/
                    188: 
                    189: static int INSERT(char *line)
                    190: {
                    191:     int drive = matchnum(&line);
                    192:     if(drive<0 || drive>3) return RC_WARN;
                    193:     if(disk_empty(drive)) {
1.1.1.4   root      194:        char buff[256];
                    195:        char *name;
                    196:        extractstr(&line, buff, 256);
                    197:        name = to_unix_path(buff);
                    198:        disk_insert(drive, name);
                    199:        free(name);
1.1       root      200:     } else {
1.1.1.4   root      201:        sprintf(RESULT,"Drive %d not empty!",drive);
                    202:        return RC_WARN;
1.1       root      203:     }
                    204:     return RC_OK;
                    205: }
                    206: 
                    207: /****************************************************************************/
                    208: 
                    209: static void QUIT(void)
                    210: {
                    211:     broken_in = 1;
                    212:     regs.spcflags |= SPCFLAG_BRK;
                    213:     quit_program = 1;
                    214: }
                    215: 
                    216: /****************************************************************************/
                    217: 
                    218: static int QUERY(char *line)
                    219: {
                    220:     char *res = NULL;
                    221:     int   alc = 0;
                    222: 
                    223:     if     (matchstr(&line, "LED_POW"))  res = led_state[0]?"1":"0";
                    224:     else if(matchstr(&line, "LED_DF0"))  res = led_state[1]?"1":"0";
                    225:     else if(matchstr(&line, "LED_DF1"))  res = led_state[2]?"1":"0";
                    226:     else if(matchstr(&line, "LED_DF2"))  res = led_state[3]?"1":"0";
                    227:     else if(matchstr(&line, "LED_DF3"))  res = led_state[4]?"1":"0";
                    228:     else if(matchstr(&line, "NAME_DF0")) res = from_unix_path(currprefs.df[0]), alc = 1;
                    229:     else if(matchstr(&line, "NAME_DF1")) res = from_unix_path(currprefs.df[1]), alc = 1;
                    230:     else if(matchstr(&line, "NAME_DF2")) res = from_unix_path(currprefs.df[2]), alc = 1;
                    231:     else if(matchstr(&line, "NAME_DF3")) res = from_unix_path(currprefs.df[3]), alc = 1;
                    232:     else if(matchstr(&line, "FAKEJOYSTICK")) res = currprefs.fake_joystick?"1":"0";
                    233:     else if(matchstr(&line, "DISPLAY"))  res = inhibit_frame?"0":"1";
                    234:     else if(matchstr(&line, "FRAMERATE")) {
1.1.1.4   root      235:        sprintf(RESULT,"%d",currprefs.framerate);
                    236:        return RC_OK;
1.1.1.2   root      237:     } else if(matchstr(&line, "FRAMENUM")) {
1.1.1.4   root      238:        sprintf(RESULT,"%u",frame_num);
                    239:        return RC_OK;
1.1       root      240:     } else if(matchstr(&line, "SOUND")) {
1.1.1.4   root      241:        sprintf(RESULT,"%d",sound_available?currprefs.produce_sound:-1);
                    242:        return RC_OK;
                    243:     }
1.1       root      244:     else return RC_ERROR;
                    245: 
                    246:     if(res) {
1.1.1.4   root      247:        strncpy(RESULT, res, RESULT_LEN);
                    248:        if(alc) free(res);
1.1       root      249:     }
                    250:     return RC_OK;
                    251: }
                    252: 
                    253: /****************************************************************************/
                    254: 
                    255: static int FEEDBACK(char *line)
                    256: {
                    257:     gui_rexx_s *gui = NULL;
                    258: 
                    259:     if     (matchstr(&line,"LED_POW"))  gui = &gui_rexx[LED_POW];
                    260:     else if(matchstr(&line,"LED_DF0"))  gui = &gui_rexx[LED_DF0];
                    261:     else if(matchstr(&line,"LED_DF1"))  gui = &gui_rexx[LED_DF1];
                    262:     else if(matchstr(&line,"LED_DF2"))  gui = &gui_rexx[LED_DF2];
                    263:     else if(matchstr(&line,"LED_DF3"))  gui = &gui_rexx[LED_DF3];
                    264:     else if(matchstr(&line,"NAME_DF0")) gui = &gui_rexx[NAME_DF0];
                    265:     else if(matchstr(&line,"NAME_DF1")) gui = &gui_rexx[NAME_DF1];
                    266:     else if(matchstr(&line,"NAME_DF2")) gui = &gui_rexx[NAME_DF2];
                    267:     else if(matchstr(&line,"NAME_DF3")) gui = &gui_rexx[NAME_DF3];
                    268:     else if(matchstr(&line,"ON_EXIT"))  gui = &gui_rexx[ON_EXIT];
                    269:     else return RC_ERROR;
                    270: 
                    271:     while(1) {
1.1.1.4   root      272:        if(matchstr(&line, "ADDRESS") ||
                    273:           matchstr(&line, "PORT")) {
                    274:            extractstr(&line, gui->port, PORT_LEN);
                    275:        } else if(matchstr(&line,"COMMAND") ||
                    276:                  matchstr(&line,"CMD") ||
                    277:                  matchstr(&line,"CMD_ON")) {
                    278:            extractstr(&line, gui->cmd_on,  CMD_LEN);
                    279:        } else if(matchstr(&line,"CMD_OFF")) {
                    280:            extractstr(&line, gui->cmd_off, CMD_LEN);
                    281:        } else break;
1.1       root      282:     }
                    283:     return RC_OK;
                    284: }
                    285: 
                    286: /****************************************************************************/
                    287: 
                    288: static int VERSION(char *line)
                    289: {
                    290:     if(matchstr(&line,"STRING")) {
1.1.1.4   root      291:         sprintf(RESULT,
                    292:                 "UAE-%d.%d.%d (%s%s%s) � by Bernd Schmidt & contributors, "
1.1.1.2   root      293: #ifdef POWERUP
1.1.1.4   root      294:                 "Amiga Port by Samuel Devulder & Holger Jakob (PPC extensions).",
1.1.1.2   root      295: #else
1.1.1.4   root      296:                 "Amiga Port by Samuel Devulder.",
1.1.1.2   root      297: #endif
                    298:                  UAEMAJOR, UAEMINOR, UAESUBREV,
                    299:                  currprefs.cpu_level==0?"68000":
                    300:                  currprefs.cpu_level==1?"68010":
                    301:                  currprefs.cpu_level==2?"68020":"68020/68881",
                    302:                  currprefs.address_space_24?" 24bits":"",
                    303:                  currprefs.cpu_compatible?" compat":"");
1.1       root      304:     } else if(matchstr(&line,"NUM")) {
1.1.1.4   root      305:        sprintf(RESULT,"%d",UAEMAJOR*10000+UAEMINOR*100+UAESUBREV);
1.1       root      306:     } else if(matchstr(&line,"AUTHOR")) {
1.1.1.4   root      307:        sprintf(RESULT,"� by Bernd Schmidt & contributors");
1.1       root      308:     } else if(matchstr(&line,"PORT")) {
1.1.1.2   root      309: #ifdef POWERUP
                    310:        sprintf(RESULT,"Amiga Port by Samuel Devulder & Holger Jakob (PPC extensions)");
                    311: #else
1.1.1.4   root      312:        sprintf(RESULT,"Amiga Port by Samuel Devulder");
1.1.1.2   root      313: #endif
1.1       root      314:     } else return RC_ERROR;
                    315:     return RC_OK;
                    316: }
                    317: 
                    318: /****************************************************************************/
                    319: 
                    320: static int FRAMERATE(char *line)
                    321: {
                    322:     int num;
                    323:     num = matchnum(&line);
                    324:     if(num>=1 && num<=20) {
1.1.1.4   root      325:        changed_prefs.framerate = num;
1.1       root      326:     } else {
1.1.1.4   root      327:        sprintf(RESULT,"Invalid frame rate: %d\n", num);
                    328:        return RC_WARN;
1.1       root      329:     }
                    330:     return RC_OK;
                    331: }
                    332: 
                    333: /****************************************************************************/
                    334: 
                    335: static int FAKEJOYSTICK(char *line)
                    336: {
1.1.1.2   root      337:     if     (matchstr(&line,"ON"))     changed_prefs.fake_joystick = 2;
                    338:     else if(matchstr(&line,"OFF"))    changed_prefs.fake_joystick = 0;
                    339:     else if(matchstr(&line,"TOGGLE")) changed_prefs.fake_joystick =
1.1.1.4   root      340:                                      currprefs.fake_joystick?0:2;
1.1       root      341:     else return RC_ERROR;
                    342:     return RC_OK;
                    343: }
                    344: 
                    345: /****************************************************************************/
                    346: 
                    347: static int DISPLAY(char *line)
                    348: {
1.1.1.2   root      349:     if     (matchstr(&line,"ON"))     do_inhibit_frame(0);
                    350:     else if(matchstr(&line,"OFF"))    do_inhibit_frame(1);
                    351:     else if(matchstr(&line,"TOGGLE")) do_inhibit_frame(inhibit_frame?0:1);
1.1       root      352:     else return RC_ERROR;
                    353:     return RC_OK;
                    354: }
                    355: 
                    356: /****************************************************************************/
                    357: 
                    358: static int SOUND(char *line)
                    359: {
                    360:     if(!sound_available) {
1.1.1.4   root      361:        sprintf(RESULT,"Sound not available!");
                    362:        return RC_WARN;
1.1       root      363:     }
                    364: 
                    365:     if     (matchstr(&line,"ON"))     currprefs.produce_sound = 2;
                    366:     else if(matchstr(&line,"OFF"))    currprefs.produce_sound = 1;
                    367:     else if(matchstr(&line,"BEST"))   currprefs.produce_sound = 3;
                    368:     else if(matchstr(&line,"TOGGLE")) currprefs.produce_sound =
1.1.1.4   root      369:                                      currprefs.produce_sound<=1?2:1;
1.1       root      370:     else return RC_ERROR;
1.1.1.2   root      371: 
                    372:     /* sam: the next 2 lines is a hack and I don't like it */
1.1.1.4   root      373: /*    eventtab[ev_sample].active = (changed_prefs.produce_sound>=2)?1:0;
1.1.1.2   root      374:     events_schedule ();
                    375: */
1.1       root      376:     return RC_OK;
                    377: }
                    378: 
                    379: /****************************************************************************/
                    380: 
                    381: static int UAEEXE(char *line)
                    382: {
                    383:     if(uaeexe(line)) {
1.1.1.4   root      384:        sprintf(RESULT,"Remote CLI failed!");
                    385:        return RC_WARN;
1.1       root      386:     }
                    387:     return RC_OK;
                    388: }
                    389: 
                    390: /****************************************************************************/
                    391: 
                    392: static int process_cmd(char *line)
                    393: {
                    394:     RESULT[0] = '\0';
                    395:     if     (matchstr(&line, "EJECT"))        return EJECT(line);
                    396:     else if(matchstr(&line, "INSERT"))       return INSERT(line);
                    397:     else if(matchstr(&line, "QUERY"))        return QUERY(line);
                    398:     else if(matchstr(&line, "FEEDBACK"))     return FEEDBACK(line);
                    399:     else if(matchstr(&line, "VERSION"))      return VERSION(line);
                    400:     else if(matchstr(&line, "BYE"))          QUIT();
                    401:     else if(matchstr(&line, "QUIT"))         QUIT();
                    402:     else if(matchstr(&line, "DEBUG"))        activate_debugger();
                    403:     else if(matchstr(&line, "RESET"))        m68k_reset();
                    404:     else if(matchstr(&line, "DISPLAY"))      return DISPLAY(line);
                    405:     else if(matchstr(&line, "FRAMERATE"))    return FRAMERATE(line);
                    406:     else if(matchstr(&line, "FAKEJOYSTICK")) return FAKEJOYSTICK(line);
                    407:     else if(matchstr(&line, "SOUND"))        return SOUND(line);
                    408:     else if(matchstr(&line, "UAEEXE"))       return UAEEXE(line);
                    409:     else return RC_ERROR;
                    410:     return RC_OK;
                    411: }
                    412: 
                    413: /****************************************************************************/
                    414: 
                    415: void rexx_handle_events(void)
                    416: {
                    417:     struct RexxMsg *msg;
                    418:     while((msg = (struct RexxMsg*)GetMsg(ARexxPort))) {
1.1.1.4   root      419:        if(!(msg->rm_Action & RXCOMM)) {
                    420:            fprintf(stderr,"Unknown action '%08X' recieved!\n",
                    421:                    msg->rm_Action);
                    422:            continue;
                    423:        }
                    424:        msg->rm_Result1 = process_cmd(msg->rm_Args[0]);
                    425:        msg->rm_Result2 = NULL;
                    426:        if(msg->rm_Action & RXFF_RESULT) {
                    427:            int len=strlen(RESULT); /* holger: trick for powerup */
                    428:            msg->rm_Result2 = (LONG)CreateArgstring(RESULT,len);
                    429:        }
                    430:        ReplyMsg((void*)msg);
1.1       root      431:     }
                    432: }
                    433: 
                    434: /****************************************************************************/
                    435: 
                    436: void rexx_led(int led, int on)
                    437: {
                    438:     gui_rexx_s *gui = NULL;
                    439: 
                    440:     if(led < 0 || led > 4) return;
                    441:     led_state[led] = on;
                    442: 
                    443:     if(led == 0) gui = &gui_rexx[LED_POW];
                    444:     if(led == 1) gui = &gui_rexx[LED_DF0];
                    445:     if(led == 2) gui = &gui_rexx[LED_DF1];
                    446:     if(led == 3) gui = &gui_rexx[LED_DF2];
                    447:     if(led == 4) gui = &gui_rexx[LED_DF3];
                    448: 
                    449:     if(gui->port[0] && gui->cmd_on[0] && gui->cmd_off[0]) {
1.1.1.4   root      450:        if(ADDRESS(gui->port, on ? gui->cmd_on : gui->cmd_off) != RC_OK) {
                    451:            fprintf(stderr,"%s:%s:%s\n", gui->port,
                    452:                                         on ? gui->cmd_on : gui->cmd_off,
                    453:                                         RESULT);
                    454:        }
1.1       root      455:     }
                    456: }
                    457: 
                    458: /****************************************************************************/
                    459: 
                    460: void rexx_filename(int num, char *filename)
                    461: {
                    462:     gui_rexx_s *gui = NULL;
                    463:     if(num < 0 || num > 3) return;
                    464:     gui = &gui_rexx[NAME_DF0 + num];
                    465:     if(gui->port[0] && gui->cmd_on[0]) {
1.1.1.4   root      466:        char buf[CMD_LEN];
                    467:        if(!(filename = from_unix_path(filename))) return;
                    468:        sprintf(buf, gui->cmd_on, filename);
                    469:        free(filename);
                    470:        if(ADDRESS(gui->port, buf) != RC_OK) {
                    471:            fprintf(stderr,"%s:%s:%s\n", gui->port, buf, RESULT);
                    472:        }
1.1       root      473:     }
                    474: }
                    475: 
                    476: /****************************************************************************/
                    477: /* send a message to an AREXX port.
                    478:  */
                    479: static int ADDRESS(char *hostname, char *cmd)
                    480: {
                    481:     struct MsgPort *RexxPort,
1.1.1.4   root      482:                   *ReplyPort;
1.1       root      483:     struct RexxMsg *HostMsg,
1.1.1.4   root      484:                   *answer;
1.1       root      485:     int result = RC_WARN;
                    486: 
                    487:     if(!stricmp(hostname, "COMMAND")) {
1.1.1.4   root      488:        return SystemTagList(cmd,NULL);
1.1       root      489:     }
                    490: 
                    491:     if((RexxPort = (void *)FindPort(hostname))) {
1.1.1.4   root      492:        if((ReplyPort = (void *)CreateMsgPort())) {
                    493:            if((HostMsg = CreateRexxMsg(ReplyPort, NULL, hostname))) {
                    494:                int len=strlen(cmd); /* holger: trick for powerup */
                    495:                if((HostMsg->rm_Args[0] = CreateArgstring(cmd,len))) {
                    496:                    HostMsg->rm_Action  = RXCOMM | RXFF_RESULT;
                    497:                    PutMsg(RexxPort, (void*)HostMsg);
                    498:                    WaitPort(ReplyPort);
                    499:                    while(!(answer = (void *)GetMsg(ReplyPort)));
                    500:                    result = answer->rm_Result1;
                    501:                    if(result == RC_OK) {
                    502:                        if(answer->rm_Result2) {
                    503:                        strncpy(RESULT,(char *)answer->rm_Result2,RESULT_LEN);
                    504:                        DeleteArgstring((char *)answer->rm_Result2);
                    505:                        } else RESULT[0] = '\0';
                    506:                    }
                    507:                    DeleteArgstring(HostMsg->rm_Args[0]);
                    508:                } else strcpy(RESULT, "Can't create argstring!");
                    509:                DeleteRexxMsg(HostMsg);
                    510:            } else strcpy(RESULT, "Can't create rexx message!");
                    511:            DeleteMsgPort(ReplyPort);
                    512:        } else strcpy(RESULT, "Can't alloc reply port!");
1.1       root      513:     } else sprintf(RESULT, "Port \"%s\" not found!",hostname);
                    514:     return result;
                    515: }
                    516: 
                    517: /****************************************************************************/
                    518: /* argument parsing routines
                    519:  */
                    520: static int matchstr(char **line,char *pat)
                    521: {
                    522:     char *s = *line;
                    523:     char match = 0;
                    524:     while(isspace(*s)) ++s;
                    525:     if(*s=='\"' || *s== '\'') match = *s++;
                    526:     while(*s && (tolower(*s)==tolower(*pat)) && (!match || *s!=match)) {++s;++pat;}
                    527:     if(match && *s==match && s[1]) ++s;
                    528:     if(!*pat && (!*s || isspace(*s))) {
1.1.1.4   root      529:        while(isspace(*s)) ++s;
                    530:        *line = s;
                    531:        return 1;
1.1       root      532:     }
                    533:     return 0;
                    534: }
                    535: 
                    536: /****************************************************************************/
                    537: 
                    538: static void extractstr(char **line, char *result, int len)
                    539: {
                    540:     char *s    = *line;
                    541:     char match = 0;
                    542: 
                    543:     while(isspace(*s)) ++s;
                    544: 
                    545:     if(*s=='\"' || *s=='\'') match = *s++;
                    546:     while(*s && *s != match) {
1.1.1.4   root      547:        if(*s == '\\' && (s[1] == '\'' || s[1] == '\"')) ++s;
                    548:        if(len > 1) {*result++ = *s;--len;}
                    549:        ++s;
                    550:        if(!match && isspace(*s)) break;
1.1       root      551:     }
                    552:     if(match && *s == match) ++s;
                    553:     while(isspace(*s)) ++s;
                    554: 
                    555:     *result  = '\0';
                    556:     *line    = s;
                    557: }
                    558: 
                    559: /****************************************************************************/
                    560: 
                    561: static int matchnum(char **line)
                    562: {
                    563:     char *s = *line, match = 0;
                    564:     int sign = 1, num = 0;
                    565: 
                    566:     while(isspace(*s)) ++s;
                    567:     if(*s=='\"' || *s=='\'') match = *s++;
                    568:     if(*s=='-') {sign = -1;++s;}
                    569:     if(*s=='+') ++s;
                    570:     while(isspace(*s)) ++s;
                    571:     while(*s>='0' && *s<='9') num = num*10 + (*s++ - '0');
                    572:     if(match && *s==match && s[1]) ++s;
                    573:     while(isspace(*s)) ++s;
                    574:     *line = s;
                    575:     return sign>0?num:-num;
                    576: }
1.1.1.2   root      577: 
                    578: /****************************************************************************/
                    579: 
                    580: #ifdef POWERUP
1.1.1.4   root      581: /* sam: those function should be in the ppc version of the unexisting
                    582:        libamiga.a */
1.1.1.2   root      583: #define NEWLIST(l) ((l)->lh_Head = (struct Node *)&(l)->lh_Tail, \
1.1.1.4   root      584:                    /*(l)->lh_Tail = NULL,*/ \
                    585:                    (l)->lh_TailPred = (struct Node *)&(l)->lh_Head)
1.1.1.2   root      586: struct MsgPort *CreatePort(STRPTR name,LONG pri)
                    587: { struct MsgPort *port = NULL;
                    588:   UBYTE portsig;
                    589: 
                    590:   if ((BYTE)(portsig=AllocSignal(-1)) >= 0)
                    591:   { if (!(port=PPCAllocMem(sizeof(struct MsgPort),MEMF_CLEAR|MEMF_PUBLIC)))
                    592:       FreeSignal(portsig);
                    593:     else
                    594:     {
                    595:       port->mp_Node.ln_Type=NT_MSGPORT;
                    596:       port->mp_Node.ln_Pri=pri;
                    597:       port->mp_Node.ln_Name=name;
                    598:       /* done via AllocMem
                    599:       port->mp_Flags=PA_SIGNAL;
                    600:       */
                    601:       port->mp_SigBit=portsig;
                    602:       port->mp_SigTask=FindTask(NULL);
                    603:       NEWLIST(&port->mp_MsgList);
                    604:       if (port->mp_Node.ln_Name)
1.1.1.4   root      605:        AddPort(port);
1.1.1.2   root      606:     }
                    607:   }
                    608:   return port;
                    609: }
                    610: 
                    611: void DeletePort(struct MsgPort *port)
                    612: { int i;
                    613: 
                    614:   if (port->mp_Node.ln_Name != NULL)
                    615:     RemPort(port);
                    616:   i=-1;
                    617:   port->mp_Node.ln_Type=i;
                    618:   port->mp_MsgList.lh_Head=(struct Node *)i;
                    619:   FreeSignal(port->mp_SigBit);
                    620:   PPCFreeMem(port,sizeof(struct MsgPort));
                    621: }
                    622: 
                    623: struct IORequest *CreateExtIO(struct MsgPort *port,long iosize)
                    624: {
                    625:   struct IORequest *ioreq=NULL;
                    626: 
                    627:   if (port && (ioreq=PPCAllocMem(iosize,MEMF_CLEAR|MEMF_PUBLIC)))
                    628:   {
                    629:     ioreq->io_Message.mn_Node.ln_Type=NT_REPLYMSG;
                    630:     ioreq->io_Message.mn_ReplyPort=port;
                    631:     ioreq->io_Message.mn_Length=iosize;
                    632:   }
                    633:   return ioreq;
                    634: }
                    635: 
                    636: struct IOStdReq *CreateStdIO(struct MsgPort *port)
                    637: {
                    638:   return (struct IOStdReq *)CreateExtIO(port,sizeof(struct IOStdReq));
                    639: }
                    640: 
                    641: void DeleteExtIO(struct IORequest *ioreq)
                    642: {
                    643:   int i;
                    644: 
                    645:   i=-1;
                    646:   ioreq->io_Message.mn_Node.ln_Type=i;
                    647:   ioreq->io_Device=(struct Device *)i;
                    648:   ioreq->io_Unit=(struct Unit *)i;
                    649:   PPCFreeMem(ioreq,ioreq->io_Message.mn_Length);
                    650: }
                    651: 
                    652: void DeleteStdIO(struct IORequest *ioreq) {DeleteExtIO(ioreq);}
                    653: #endif

unix.superglobalmegacorp.com

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