usenet@cps3xx.UUCP (Usenet file owner) (12/18/89)
Nifty editor (and other utility) idea. This is not an original idea but I am willing to implement (part at least) it. Make an editor.library. Then make "editors" which simply make calls to "editor.library". Then all there would be to makeing an editor is creating a user interface. It would also be possible to make a usable line editor (unlike AmigaDos EDIT) using editor.library. BASIC IDEA ABOUT HOW THINGS WOULD FUNCTION: edito.library would run async to your application. Before you could touch the file (look or modify directly) my would need to get the semaphore associated with the file. Then with certain lib calls you could look at parts of the file and make immediate changes. Some things like inserting while somebody types would best be handled by GetSem, ModifyLine, ReleaseSem syncronously. Things like Search and Replace could be handled async. You would send a msg to do some action. It would then do it async, ReplyMsg, and SendMsg appropriate update the display commands back to you. IT would handle optimizing the display by doing all requests in its MsgPort queue, and only send Update msgs when this queue is empty. It would get empty at somepoint, since everything would endup Waiting for the files semaphore while it was modifying the file. This setup would allowyou to edit the same file from 2 editors (that don't know about each other) simultaeneously!!! I have not worked out hardly any of the design but I would like to stimulate the discussion of such on this newsgroup. This idea would work especially for Databases and spreadsheet type things. Discussion about this would also be welcome. Here is a sample (very incomplete) edit application. edit.c: /* User interface code */ /* Usage: edit <filename> */ #include <editor/edit.h> extern long EditorBase; EDITFILE *myfile; struct Window *mywindow; main(x,y) int x; char **y; { if(x<2) edit(-1); openstdlibs(); EditorBase = OpenLibrary("editor.library",1); /* VIRTUAL means the editor should be able to edit BIG files without the OS doing the VIRTUAL stuff INTERACTIVE means that editor should optimize its operation for interactive use. */ myfile=EditOpenFile(y[1],VIRTUAL|INTERACTIVE); if(myfile==0) exit(-1); mywindow=openawindow(); disinfo.height=numlines; /* # of displayed lines in window */ disinfo.width= MAXLINELENGTH; disinfo.curline=0; /* Start at the top */ EditDisInfo(myfile,&disinfo); /* Tell editor about it */ refreshwindow(myfile); do { Wait(-1); /* Wait for any signal */ if(windowsig) { getsemaphore(myfile->semaphore); /* Not a editor.lib call. Editor.lib will run async. */ while( (msg=GetMsg(windowport))!=0) { switch (event) { case ARROWKEY: EditMove(myfile,DIRECTION); break; case TEXTKEY: EditInsertChar(myfile,key); break; case ETC: do more stuff..... break; } ReplayMsg(msg); } } else if(editeventsignal) { while(GetMsg(editorport) { switch (event) { case SCROLLWINDOWX: /* Dunno how to handle refresh in this case */ myscrollwindowhoriz(msg->count); break; case SCROLLWINDOWy: myscrollwindowvert(msg->count); break; case CURSORNEWPOS: /* Cursor pos in characters relative to upperleft. This case would be more complex in the case of Proportional fonts */ mymovecursorto(msg->curx, msg->cury); case DAMAGED: EditGetSemaphore(myfile); for(x=myfile->curline;x<myfile->lastline;x++) { if(EditDamage(myfile,x)) { redraw(myfile,x); } } EditReleaseSemaphore(myfile); break; case ETC: bla bla bla./ } } } else { /* Handle other sigs */ } } while (!done); } Joe Porkka porkka@frith.egr.msu.edu