home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************
- * *
- * Minimal Term for DNET (uc) Stone, SST *
- * Further modifications by Unknown, SST *
- * Based on FTerm by Matt Dillon *
- * *
- * MTerm portname [port] [networknumber] *
- * *
- * Set ya TABS to 4! *
- * Email me!! c9107253@mystra.newcastle.edu.au *
- * For any reason!! (eg DNet, AmiNet, Demos, amigas...) *
- * Please send any changes U make! *
- * *
- * Mega-thanx to Azza of the SST for hours of DNET source *
- * modification.... yes it compiles under SAS 6! *
- **********************************************************/
- /* DNET TEXT SERVER */
-
- #include "defs.h"
- #include <exec/ports.h>
- #include <dos/dos.h>
- #include <st/textmessage.h>
- #include <st/st_proto.h>
-
- /* Commands this DnetClient->TextServer knows */
- /* Note format: "CMD","CMD2","Help message" where CMD2 is a shortcut */
-
- char *cmds[] = {
- "FLUSH","F","Flush input buffers",
- "LOG","L","Log to file (eg LOG ram:capture1)",
- "LISTLOG","LL","List log files open",
- "MULTILOG","ML","Log to multiple files (eg MULTILOG 1 ram:capture1)",
- "CLOSELOG","CL","Close log file",
- "CLOSEMULTILOG","CML","Close log file 'n'"
- };
-
- /* Strings per command */
- #define CMDN 3
- /* Commands a client may send to us at anytime */
- #define SCMDS_FLUSH 0
- #define SCMDS_LOG 1
- #define SCMDS_MULTILOG 2
- #define SCMDS_CLOSELOG 3
- #define SCMDS_CLOSEMULTILOG 4
- #define SCMDS_LISTLOG 5
- #define CMDCOUNT 6
-
-
- /* Some default things */
- char *WHITE = " \t\n\r",
- *eolntok = "\n\r";
-
-
- long out, err, in;
-
- /* FOLLOWING GLOBALS COPIED FROM FTERM.C */
- char Buf[512],
- Cooked, /* bit 0 = cooked, bit 1 = local echo */
- *progname;
-
- /* File things for capture */
- #define MAXNOOFFILES 20
- BPTR mainlogfile = NULL,
- auxlogfiles[MAXNOOFFILES];
-
- void *chan;
-
- extern struct IntuitionBase *IntuitionBase;
- extern struct GfxBase *GfxBase;
-
- #define SIGNALS (SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_E | SIGBREAKF_CTRL_F)
-
-
- /*********************************************************/
- char *sPrintCommands(char *str)
- /*********************************************************
- Print out the commands we understand into a string
- **********************************************************/
- {
- short i;
- char linebuf[400];
- linebuf[399] = '\0';
- if(!str) return(NULL);
- strcpy(str, "Known commands :-\n");
- for(i = 0; i < CMDCOUNT*CMDN; i += CMDN) {
- spf(linebuf,399,"%s\tor\t%s\t:%s\n",cmds[i],cmds[i+1],cmds[i+2]);
- strcat(str,linebuf);
- }
- return(str);
- }
-
- /*********************************************************/
- short DoCommands(char *string, struct TextMessage *reply)
- /*********************************************************
- Decode a command passed to us and do
- stuff from there (eg open log files etc)
- **********************************************************/
- {
- char *argument, *command, *rest, linebuf[400];
- short i;
- linebuf[399] = '\0';
- command = strtok(string,WHITE);
- rest = strtok(NULL,NULL);
- strupper(command);
-
- for(i = 0; i < CMDCOUNT*CMDN; i += CMDN) {
- if( (strncmp(command,cmds[i],strlen(cmds[i])) == 0) ||
- (strncmp(command,cmds[i+1],strlen(cmds[i])) == 0) )
-
- switch((i+CMDN-1)/CMDN) {
- case SCMDS_FLUSH:
- DIoctl(chan, CIO_FLUSH, 0, 0);
- if(TMREPLYPORT(reply))
- strcpy(AllocString0(&(reply->RepString),30),"Input Flushed\n");
- return(1);
-
- case SCMDS_LOG:
- argument = strtok(rest,WHITE);
- SafeClose(&mainlogfile);
- if(mainlogfile = Open(argument,MODE_NEWFILE))
- spf(linebuf,399,"Writing all output to '%s'\n",argument);
- else
- spf(linebuf,399,"Couldn't write to '%s'\n",argument);
-
- if(TMREPLYPORT(reply))
- strcpy(AllocString0(&(reply->RepString),1000),linebuf);
- return(1);
-
- case SCMDS_CLOSELOG:
- SafeClose(&mainlogfile);
- return(1);
-
- default:
- if(TMREPLYPORT(reply)) {
- spf(linebuf,399,"Sorry... '%s' unimplemented\n",cmds[i]);
- strcpy(AllocString0(&(reply->RepString),1000),linebuf);
- }
- return(0);
- }
- }
- if(TMREPLYPORT(reply)) {
- spf(linebuf,399,"Unknown command: '%s'\n",command);
- strcpy(AllocString0(&(reply->RepString),1000),linebuf);
- }
- return(0);
- }
-
-
- /**********************************************************/
- int main(int argc, char **argv)
- /**********************************************************
- Do the minimal term stuff!
- Wait on our message ports for incoming
- **********************************************************/
- {
- long pmask, dmask, mask, i, j;
-
- char notdone = 1,
- *host = NULL,
- *portname = argv[1];
-
- UWORD port = PORT_IALPHATERM;
- struct MsgPort *ourport = NULL;
- struct TextMessage *currtxtmsg;
-
- out = Output(); in = Input(); err = Open("*", MODE_OLDFILE);
-
- IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
- GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
-
- for(i = 0; i < MAXNOOFFILES; i++ ) auxlogfiles[i] = NULL;
- progname = argv[0];
-
- fpf(out,"MTERM for DNET [port->Dnet->Screen] (uc) Stone, SST\n");
- fpf(out,"email: c9107253@cs.newcastle.edu.au (1993)\n");
- if( argc<2 ) {
- fpf(out,"Use: %s [>file] portname [dnet_portnumber] [network]\n",argv[0]);
- fpf(out,"(The portname and port number are different concepts!)\n");
- return(5);
- }
-
- /* onbreak(brk); */
-
- if(argc > 2)
- port = (UWORD) atoi(argv[2]);
- if(argc > 3)
- host = argv[3];
-
- fpf(out,"Opening port %ld on network %s\n",port,host?host:"0");
-
- /* DO THAT FUNKY DNET STUFF STUFF */
- if( ! (chan = DOpen(host, port, 20, 15)) ) {
- fpf(out,"Unable to connect\n");
- goto e3; }
-
- DQueue(chan, 32);
- dmask = 1 << ((PORT *)chan)->mp_SigBit;
-
- /* GIVE THE OTHER SIDE A TERMINAL SIZE */
- DIoctl(chan, CIO_SETROWS, 25, 0); DIoctl(chan, CIO_SETCOLS, 80, 0);
-
- if( !(ourport = CreatePort(portname,0)) ) {
- fpf(out,"Can't create a port...\n");
- goto e3; }
-
- fpf(out,"Reading from port '%s'\n",portname);
-
- pmask = 1 << ourport->mp_SigBit;
-
- /* HIT ME, U CAN'T HURT ME! */
- while (notdone) {
- mask = Wait(dmask | pmask | SIGNALS);
-
- if(mask & pmask)
- while (currtxtmsg = (struct TextMessage *)GetMsg(ourport))
- {
- TextMessageInitReply(currtxtmsg);
-
- switch(currtxtmsg->Command) {
- case TM_TEXT:
- i = 0;
- for(j = STRLEN(&(currtxtmsg->String))
- ; j >= 256 ; j -= 256) {
- DWrite(chan,&(currtxtmsg->String.String[i]), 256);
- i += 256;
- }
- if(j > 0)
- DWrite(chan,&(currtxtmsg->String.String[i]), j);
-
- break;
-
- case TM_SETWIDTH:
- DIoctl(chan, CIO_SETCOLS, currtxtmsg->Args[0], 0);
- break;
-
- case TM_SETHEIGHT:
- DIoctl(chan, CIO_SETROWS, currtxtmsg->Args[0], 0);
- break;
-
- case TM_EXIT:
- fpf(out,"\nRemote quit command sent\n");
- notdone = 0;
- break;
-
- case TM_COMMAND:
- DoCommands(currtxtmsg->String.String, currtxtmsg);
- break;
-
- case TM_HELP:
- if(TMREPLYPORT(currtxtmsg))
- sPrintCommands(AllocString0(&(currtxtmsg->RepString), 2000));
- break;
- }
- TextMessageReply(&currtxtmsg);
- }
-
- if (mask & dmask) {
- int n;
- if ((n = DNRead(chan, Buf, sizeof(Buf))) > 0) {
- /* WE GOT SOME TEXT! PRINT TO STD OUTPUT! */
- Write(out, Buf, n);
- if(mainlogfile) Write(mainlogfile, Buf, n);
-
- } else if (n == -2) {
- short val, cmd;
- char aux;
- cmd = DGetIoctl(chan, &val, &aux);
- switch(cmd) {
- case CIO_MODE:
- if(Cooked = val)
- fpf(out,"Mode change Cooked unimplemented...\n");
- else
- fpf(out,"Mode change Raw unimplemented...\n");
- break;
- case CIO_SETROWS:
- break;
- case CIO_SETCOLS:
- break;
- }
-
- } else if (n < 0) {
- /* FINE, WE SHOULD QUIT THEN... */
- fpf(out,"Ok ");
- notdone = 0;
- }
- if(mask & SIGBREAKF_CTRL_C) notdone = 0;
- if(mask & SIGBREAKF_CTRL_D) notdone = 0;
- if(mask & SIGBREAKF_CTRL_E) notdone = 0;
- if(mask & SIGBREAKF_CTRL_F) notdone = 0;
-
- }
-
- }
- e3:
- fpf(out,"Closing...");
- if(chan) DClose(chan);
-
- for(i = 0; i < MAXNOOFFILES; i++ ) SafeClose(&auxlogfiles[i]);
- SafeClose(&mainlogfile);
-
- /* remove any pending messages */
- TextMessageSafeCleanup(ourport);
-
- CloseLibrary((LIB *)IntuitionBase);
- CloseLibrary((LIB *)GfxBase);
- SafeClose(&err);
- fpf(out," done!\n");
- return(0);
- }
-