--- uae/src/od-amiga/ami-rexx.c 2018/04/24 16:42:49 1.1.1.2 +++ uae/src/od-amiga/ami-rexx.c 2018/04/24 17:15:16 1.1.1.4 @@ -1,8 +1,8 @@ /* * UAE - The Un*x Amiga Emulator - * + * * ami-rexx.c - * + * * Copyright 1996 Samuel Devulder. * * History: @@ -36,7 +36,7 @@ #include /* this prevent a conflict between and */ -#undef DT_DIR +#undef DT_DIR /****************************************************************************/ @@ -59,7 +59,7 @@ #include "sound.h" #include "gensound.h" #include "uaeexe.h" -#include "threaddep/penguin.h" +#include "threaddep/thread.h" #include "xwin.h" #include @@ -99,7 +99,7 @@ struct RxsLib #else struct Library #endif - *RexxSysBase; + *RexxSysBase; static struct MsgPort *ARexxPort; static gui_rexx_s gui_rexx[GUI_REXX_MAX]; static char RESULT[RESULT_LEN]; @@ -125,17 +125,17 @@ int rexx_init(void) quit_program = 0; RexxSysBase = (void*)OpenLibrary("rexxsyslib.library",0L); if(!RexxSysBase) { - fprintf(stderr, "Can't find rexxsyslib.library!\n"); - return 1; + fprintf(stderr, "Can't find rexxsyslib.library!\n"); + return 1; } if(FindPort(UAE_PORTNAME)) { - fprintf(stderr, "Port \"%s\" already exists!\n",UAE_PORTNAME); - return 1; + fprintf(stderr, "Port \"%s\" already exists!\n",UAE_PORTNAME); + return 1; } ARexxPort = CreatePort(UAE_PORTNAME,0); if(!ARexxPort) { - fprintf(stderr, "Failed to open AREXX port \"%s\"!\n",UAE_PORTNAME); - return 1; + fprintf(stderr, "Failed to open AREXX port \"%s\"!\n",UAE_PORTNAME); + return 1; } fprintf(stderr,"Rexx port \"%s\" installed.\n", UAE_PORTNAME); rexx_handle_events(); @@ -147,30 +147,30 @@ int rexx_init(void) void rexx_exit(void) { if(ARexxPort) { - struct RexxMsg *msg; - gui_rexx_s *gui = &gui_rexx[ON_EXIT]; + struct RexxMsg *msg; + gui_rexx_s *gui = &gui_rexx[ON_EXIT]; - if(gui->port[0] && gui->cmd_on[0]) { - if(ADDRESS(gui->port, gui->cmd_on) != RC_OK) { - fprintf(stderr,"%s:%s:%s\n", gui->port, - gui->cmd_on, - RESULT); - } - gui->port[0] = '\0'; - } - Forbid(); - while((msg = (struct RexxMsg*)GetMsg(ARexxPort))) { - msg->rm_Result1 = RC_ERROR; - msg->rm_Result2 = NULL; - ReplyMsg((void*)msg); - } - DeletePort(ARexxPort); - Permit(); - ARexxPort = NULL; + if(gui->port[0] && gui->cmd_on[0]) { + if(ADDRESS(gui->port, gui->cmd_on) != RC_OK) { + fprintf(stderr,"%s:%s:%s\n", gui->port, + gui->cmd_on, + RESULT); + } + gui->port[0] = '\0'; + } + Forbid(); + while((msg = (struct RexxMsg*)GetMsg(ARexxPort))) { + msg->rm_Result1 = RC_ERROR; + msg->rm_Result2 = NULL; + ReplyMsg((void*)msg); + } + DeletePort(ARexxPort); + Permit(); + ARexxPort = NULL; } if(RexxSysBase) { - CloseLibrary((void*)RexxSysBase); - RexxSysBase = NULL; + CloseLibrary((void*)RexxSysBase); + RexxSysBase = NULL; } } @@ -192,15 +192,15 @@ static int INSERT(char *line) int drive = matchnum(&line); if(drive<0 || drive>3) return RC_WARN; if(disk_empty(drive)) { - char buff[256]; - char *name; - extractstr(&line, buff, 256); - name = to_unix_path(buff); - disk_insert(drive, name); - free(name); + char buff[256]; + char *name; + extractstr(&line, buff, 256); + name = to_unix_path(buff); + disk_insert(drive, name); + free(name); } else { - sprintf(RESULT,"Drive %d not empty!",drive); - return RC_WARN; + sprintf(RESULT,"Drive %d not empty!",drive); + return RC_WARN; } return RC_OK; } @@ -233,20 +233,20 @@ static int QUERY(char *line) else if(matchstr(&line, "FAKEJOYSTICK")) res = currprefs.fake_joystick?"1":"0"; else if(matchstr(&line, "DISPLAY")) res = inhibit_frame?"0":"1"; else if(matchstr(&line, "FRAMERATE")) { - sprintf(RESULT,"%d",currprefs.framerate); - return RC_OK; + sprintf(RESULT,"%d",currprefs.framerate); + return RC_OK; } else if(matchstr(&line, "FRAMENUM")) { - sprintf(RESULT,"%u",frame_num); - return RC_OK; + sprintf(RESULT,"%u",frame_num); + return RC_OK; } else if(matchstr(&line, "SOUND")) { - sprintf(RESULT,"%d",sound_available?currprefs.produce_sound:-1); - return RC_OK; - } + sprintf(RESULT,"%d",sound_available?currprefs.produce_sound:-1); + return RC_OK; + } else return RC_ERROR; if(res) { - strncpy(RESULT, res, RESULT_LEN); - if(alc) free(res); + strncpy(RESULT, res, RESULT_LEN); + if(alc) free(res); } return RC_OK; } @@ -270,16 +270,16 @@ static int FEEDBACK(char *line) else return RC_ERROR; while(1) { - if(matchstr(&line, "ADDRESS") || - matchstr(&line, "PORT")) { - extractstr(&line, gui->port, PORT_LEN); - } else if(matchstr(&line,"COMMAND") || - matchstr(&line,"CMD") || - matchstr(&line,"CMD_ON")) { - extractstr(&line, gui->cmd_on, CMD_LEN); - } else if(matchstr(&line,"CMD_OFF")) { - extractstr(&line, gui->cmd_off, CMD_LEN); - } else break; + if(matchstr(&line, "ADDRESS") || + matchstr(&line, "PORT")) { + extractstr(&line, gui->port, PORT_LEN); + } else if(matchstr(&line,"COMMAND") || + matchstr(&line,"CMD") || + matchstr(&line,"CMD_ON")) { + extractstr(&line, gui->cmd_on, CMD_LEN); + } else if(matchstr(&line,"CMD_OFF")) { + extractstr(&line, gui->cmd_off, CMD_LEN); + } else break; } return RC_OK; } @@ -289,12 +289,12 @@ static int FEEDBACK(char *line) static int VERSION(char *line) { if(matchstr(&line,"STRING")) { - sprintf(RESULT, - "UAE-%d.%d.%d (%s%s%s) © by Bernd Schmidt & contributors, " + sprintf(RESULT, + "UAE-%d.%d.%d (%s%s%s) © by Bernd Schmidt & contributors, " #ifdef POWERUP - "Amiga Port by Samuel Devulder & Holger Jakob (PPC extensions).", + "Amiga Port by Samuel Devulder & Holger Jakob (PPC extensions).", #else - "Amiga Port by Samuel Devulder.", + "Amiga Port by Samuel Devulder.", #endif UAEMAJOR, UAEMINOR, UAESUBREV, currprefs.cpu_level==0?"68000": @@ -303,14 +303,14 @@ static int VERSION(char *line) currprefs.address_space_24?" 24bits":"", currprefs.cpu_compatible?" compat":""); } else if(matchstr(&line,"NUM")) { - sprintf(RESULT,"%d",UAEMAJOR*10000+UAEMINOR*100+UAESUBREV); + sprintf(RESULT,"%d",UAEMAJOR*10000+UAEMINOR*100+UAESUBREV); } else if(matchstr(&line,"AUTHOR")) { - sprintf(RESULT,"© by Bernd Schmidt & contributors"); + sprintf(RESULT,"© by Bernd Schmidt & contributors"); } else if(matchstr(&line,"PORT")) { #ifdef POWERUP sprintf(RESULT,"Amiga Port by Samuel Devulder & Holger Jakob (PPC extensions)"); #else - sprintf(RESULT,"Amiga Port by Samuel Devulder"); + sprintf(RESULT,"Amiga Port by Samuel Devulder"); #endif } else return RC_ERROR; return RC_OK; @@ -323,10 +323,10 @@ static int FRAMERATE(char *line) int num; num = matchnum(&line); if(num>=1 && num<=20) { - changed_prefs.framerate = num; + changed_prefs.framerate = num; } else { - sprintf(RESULT,"Invalid frame rate: %d\n", num); - return RC_WARN; + sprintf(RESULT,"Invalid frame rate: %d\n", num); + return RC_WARN; } return RC_OK; } @@ -338,7 +338,7 @@ static int FAKEJOYSTICK(char *line) if (matchstr(&line,"ON")) changed_prefs.fake_joystick = 2; else if(matchstr(&line,"OFF")) changed_prefs.fake_joystick = 0; else if(matchstr(&line,"TOGGLE")) changed_prefs.fake_joystick = - currprefs.fake_joystick?0:2; + currprefs.fake_joystick?0:2; else return RC_ERROR; return RC_OK; } @@ -359,19 +359,19 @@ static int DISPLAY(char *line) static int SOUND(char *line) { if(!sound_available) { - sprintf(RESULT,"Sound not available!"); - return RC_WARN; + sprintf(RESULT,"Sound not available!"); + return RC_WARN; } if (matchstr(&line,"ON")) currprefs.produce_sound = 2; else if(matchstr(&line,"OFF")) currprefs.produce_sound = 1; else if(matchstr(&line,"BEST")) currprefs.produce_sound = 3; else if(matchstr(&line,"TOGGLE")) currprefs.produce_sound = - currprefs.produce_sound<=1?2:1; + currprefs.produce_sound<=1?2:1; else return RC_ERROR; /* sam: the next 2 lines is a hack and I don't like it */ -/* eventtab[ev_sample].active = (changed_prefs.produce_sound>=2)?1:0; +/* eventtab[ev_sample].active = (changed_prefs.produce_sound>=2)?1:0; events_schedule (); */ return RC_OK; @@ -382,8 +382,8 @@ static int SOUND(char *line) static int UAEEXE(char *line) { if(uaeexe(line)) { - sprintf(RESULT,"Remote CLI failed!"); - return RC_WARN; + sprintf(RESULT,"Remote CLI failed!"); + return RC_WARN; } return RC_OK; } @@ -417,18 +417,18 @@ void rexx_handle_events(void) { struct RexxMsg *msg; while((msg = (struct RexxMsg*)GetMsg(ARexxPort))) { - if(!(msg->rm_Action & RXCOMM)) { - fprintf(stderr,"Unknown action '%08X' recieved!\n", - msg->rm_Action); - continue; - } - msg->rm_Result1 = process_cmd(msg->rm_Args[0]); - msg->rm_Result2 = NULL; - if(msg->rm_Action & RXFF_RESULT) { - int len=strlen(RESULT); /* holger: trick for powerup */ - msg->rm_Result2 = (LONG)CreateArgstring(RESULT,len); - } - ReplyMsg((void*)msg); + if(!(msg->rm_Action & RXCOMM)) { + fprintf(stderr,"Unknown action '%08X' recieved!\n", + msg->rm_Action); + continue; + } + msg->rm_Result1 = process_cmd(msg->rm_Args[0]); + msg->rm_Result2 = NULL; + if(msg->rm_Action & RXFF_RESULT) { + int len=strlen(RESULT); /* holger: trick for powerup */ + msg->rm_Result2 = (LONG)CreateArgstring(RESULT,len); + } + ReplyMsg((void*)msg); } } @@ -448,11 +448,11 @@ void rexx_led(int led, int on) if(led == 4) gui = &gui_rexx[LED_DF3]; if(gui->port[0] && gui->cmd_on[0] && gui->cmd_off[0]) { - if(ADDRESS(gui->port, on ? gui->cmd_on : gui->cmd_off) != RC_OK) { - fprintf(stderr,"%s:%s:%s\n", gui->port, - on ? gui->cmd_on : gui->cmd_off, - RESULT); - } + if(ADDRESS(gui->port, on ? gui->cmd_on : gui->cmd_off) != RC_OK) { + fprintf(stderr,"%s:%s:%s\n", gui->port, + on ? gui->cmd_on : gui->cmd_off, + RESULT); + } } } @@ -464,13 +464,13 @@ void rexx_filename(int num, char *filena if(num < 0 || num > 3) return; gui = &gui_rexx[NAME_DF0 + num]; if(gui->port[0] && gui->cmd_on[0]) { - char buf[CMD_LEN]; - if(!(filename = from_unix_path(filename))) return; - sprintf(buf, gui->cmd_on, filename); - free(filename); - if(ADDRESS(gui->port, buf) != RC_OK) { - fprintf(stderr,"%s:%s:%s\n", gui->port, buf, RESULT); - } + char buf[CMD_LEN]; + if(!(filename = from_unix_path(filename))) return; + sprintf(buf, gui->cmd_on, filename); + free(filename); + if(ADDRESS(gui->port, buf) != RC_OK) { + fprintf(stderr,"%s:%s:%s\n", gui->port, buf, RESULT); + } } } @@ -480,37 +480,37 @@ void rexx_filename(int num, char *filena static int ADDRESS(char *hostname, char *cmd) { struct MsgPort *RexxPort, - *ReplyPort; + *ReplyPort; struct RexxMsg *HostMsg, - *answer; + *answer; int result = RC_WARN; if(!stricmp(hostname, "COMMAND")) { - return SystemTagList(cmd,NULL); + return SystemTagList(cmd,NULL); } if((RexxPort = (void *)FindPort(hostname))) { - if((ReplyPort = (void *)CreateMsgPort())) { - if((HostMsg = CreateRexxMsg(ReplyPort, NULL, hostname))) { - int len=strlen(cmd); /* holger: trick for powerup */ - if((HostMsg->rm_Args[0] = CreateArgstring(cmd,len))) { - HostMsg->rm_Action = RXCOMM | RXFF_RESULT; - PutMsg(RexxPort, (void*)HostMsg); - WaitPort(ReplyPort); - while(!(answer = (void *)GetMsg(ReplyPort))); - result = answer->rm_Result1; - if(result == RC_OK) { - if(answer->rm_Result2) { - strncpy(RESULT,(char *)answer->rm_Result2,RESULT_LEN); - DeleteArgstring((char *)answer->rm_Result2); - } else RESULT[0] = '\0'; - } - DeleteArgstring(HostMsg->rm_Args[0]); - } else strcpy(RESULT, "Can't create argstring!"); - DeleteRexxMsg(HostMsg); - } else strcpy(RESULT, "Can't create rexx message!"); - DeleteMsgPort(ReplyPort); - } else strcpy(RESULT, "Can't alloc reply port!"); + if((ReplyPort = (void *)CreateMsgPort())) { + if((HostMsg = CreateRexxMsg(ReplyPort, NULL, hostname))) { + int len=strlen(cmd); /* holger: trick for powerup */ + if((HostMsg->rm_Args[0] = CreateArgstring(cmd,len))) { + HostMsg->rm_Action = RXCOMM | RXFF_RESULT; + PutMsg(RexxPort, (void*)HostMsg); + WaitPort(ReplyPort); + while(!(answer = (void *)GetMsg(ReplyPort))); + result = answer->rm_Result1; + if(result == RC_OK) { + if(answer->rm_Result2) { + strncpy(RESULT,(char *)answer->rm_Result2,RESULT_LEN); + DeleteArgstring((char *)answer->rm_Result2); + } else RESULT[0] = '\0'; + } + DeleteArgstring(HostMsg->rm_Args[0]); + } else strcpy(RESULT, "Can't create argstring!"); + DeleteRexxMsg(HostMsg); + } else strcpy(RESULT, "Can't create rexx message!"); + DeleteMsgPort(ReplyPort); + } else strcpy(RESULT, "Can't alloc reply port!"); } else sprintf(RESULT, "Port \"%s\" not found!",hostname); return result; } @@ -527,9 +527,9 @@ static int matchstr(char **line,char *pa while(*s && (tolower(*s)==tolower(*pat)) && (!match || *s!=match)) {++s;++pat;} if(match && *s==match && s[1]) ++s; if(!*pat && (!*s || isspace(*s))) { - while(isspace(*s)) ++s; - *line = s; - return 1; + while(isspace(*s)) ++s; + *line = s; + return 1; } return 0; } @@ -545,10 +545,10 @@ static void extractstr(char **line, char if(*s=='\"' || *s=='\'') match = *s++; while(*s && *s != match) { - if(*s == '\\' && (s[1] == '\'' || s[1] == '\"')) ++s; - if(len > 1) {*result++ = *s;--len;} - ++s; - if(!match && isspace(*s)) break; + if(*s == '\\' && (s[1] == '\'' || s[1] == '\"')) ++s; + if(len > 1) {*result++ = *s;--len;} + ++s; + if(!match && isspace(*s)) break; } if(match && *s == match) ++s; while(isspace(*s)) ++s; @@ -579,11 +579,11 @@ static int matchnum(char **line) /****************************************************************************/ #ifdef POWERUP -/* sam: those function should be in the ppc version of the unexisting - libamiga.a */ +/* sam: those function should be in the ppc version of the unexisting + libamiga.a */ #define NEWLIST(l) ((l)->lh_Head = (struct Node *)&(l)->lh_Tail, \ - /*(l)->lh_Tail = NULL,*/ \ - (l)->lh_TailPred = (struct Node *)&(l)->lh_Head) + /*(l)->lh_Tail = NULL,*/ \ + (l)->lh_TailPred = (struct Node *)&(l)->lh_Head) struct MsgPort *CreatePort(STRPTR name,LONG pri) { struct MsgPort *port = NULL; UBYTE portsig; @@ -603,7 +603,7 @@ struct MsgPort *CreatePort(STRPTR name,L port->mp_SigTask=FindTask(NULL); NEWLIST(&port->mp_MsgList); if (port->mp_Node.ln_Name) - AddPort(port); + AddPort(port); } } return port;