Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!apple!oliveb!amdahl!rtech!gonzo!daveb From: daveb@gonzo.UUCP (Dave Brower) Newsgroups: comp.emacs Subject: Re: Wanted: minimal EMACS in C Message-ID: <618@gonzo.UUCP> Date: 23 Mar 89 17:01:28 GMT References: <2200001@uxg.cso.uiuc.edu> <1307@dukeac.UUCP> Reply-To: daveb@gonzo.UUCP (Dave Brower) Organization: Gonzo Media Group Lines: 78 In article <1307@dukeac.UUCP> bet@orion.mc.duke.edu (Bennett Todd) writes: >Here's what I'd really love to see in an emacs(3): > > char *emacs(buff, fp, rows, cols, gotoxy) > char *buff; /* buffer to be edited, lines separated w/ \n, may be > realloc()-ed */ > FILE *fp; /* file pointer for terminal I/O */ > int rows; /* height of terminal or window */ > int cols; /* width of terminal or window */ > void (*gotoxy)(int x, int y); /* scoot to x, y */ Since you aren't providing a TERM, and it's already going to have to do fileno(fp) games to set the tty modes, then you don't need to provide rows and cols. What is the gotoxy function supposed to do? My god, are you saying that the screen output primitives are 'position cursor' and 'write chars?' Eek! how about: int editbuf( buf, len ) char **buf; int *len; Buf and len are input/output parameters. The function can move the buffer and change the length of what is there. (Real EMACS can edit binaries with embedded '\0' characters, ya know.) The controlling terminal is presumed to be on fd's 0 and 1, which is presumed to be in the "normal" state. The function evaulates TERM as appropriate. This is trivially implemented: /* I didn't compile this, I just typed it in. ** Beware the nearly total lack of error checking! */ int editbuf( buf, len ) char **buf; int *len; { char fn[] = "/tmp/EbXXXXXX"; char cmd[ 80 ]; FILE *fp; struct stat sb; mktemp( fn ); fp = fopen( fn, "w" ); fwrite( *buf, len, 1, fp ); fclose( fp ); sprintf( cmd, "emacs %s\n", fn ); if( system( cmd ) ) /* token error check */ return 1; stat( fn, &sb ); if( sb.st_size > len ) { free( *buf ); *buf = malloc( sb.st_size ); } fp = fopen( fn, "r" ); fread( buf, sb.st_size, 1, fp ); fclose( fp ); *len = sb.st_size; return 0; } Is the :-) really necessary? -dB PS, don't completely laugh it off. On many systems, substituting "mg" or "jove" for "emacs" would be fast enough, preventing you from having to maintain your own editor. -- "I came here for an argument." "Oh. This is getting hit on the head" {sun,mtxinu,amdahl,hoptoad}!rtech!gonzo!daveb daveb@gonzo.uucp