Friday, December 7, 2018

Working on Xchars

As it is, I have the NewWindow command, and it  gets a wid for subsequent NewStr and DelStr.
NewWindow returns wid in arg[0], I use that for return stack in linux command format.

NewStr wid 4 5 "Hello World"  // and so on
DelStr wid  x y
and
DelWindow wid

Everything dangerous, no separation of subsystems.

Each wid keeps its list of strings for redraw in a list  [y,x,char *], so DelStr and NewStr sort on the Y then X for strings.  Strings in the window identified by their Y,X and are null terminated, unique. The expansion of strings ill cut the left string if it overlaps a right.

The event poll is a separate thread.  Xchars starts, then spawns a thread to wait on event. On EXPOSE, the thread grabs a mutex then draws the particular strings onto the particular x,y, then releases the mutex.  The mutex prevents collisions on the string list. So, thread create is now accessible, by default, on the linux command bus:
NewThread arg1 arg2 ...

and handled in the console loop along with module load. I see not reason any subsystem cannot start threads as necessary, just issue the linux command onto the bus. On start up, all loaded modules get a copy of Entry in the console loop which has the list of all module entries.

Xhars is coming in at 200 lines, good enough. I got stuck with multiple windows because, like threads, there is no reason a subsystem cannot throw up its own window.

Could do this in Forth, if I knew the lingo better.  Managing stacks of string points work well, it needs a few string heap built ins.  Forth could easily manage a bunch of Xchar windows. In my case, they are not linked at all, just a flat list off the screen.

Xchars Entry:

int Entry(int *argc, void * args[] {
if(!strcmp(args[0],"Init")) Init(argc,args);
else if(!strcmp(args[0],"NewWin")) NewWin(argc,args);
else if(!strcmp(args[0],"NewWin")) DelWin(argc,args);
else if(!strcmp(args[0],"PollSWin")) PollScr(argc,args);
else if(!strcmp(args[0],"NewStr")) NewStr(argc,args);
else if(!strcmp(args[0],"DelStr")) DelStr(argc,args);
}

The entries all look the same.  All modules get a call to Init on start up. All modules are given an Entry pointer back to the console which leads to all other Entries on the bus.

Does console loop have a parser? No, really, except what it loads. That leaves the question, it needs a simple parser on start up. On start up, no macros, no special flags on args, just the 20 lines of code to find plain args. Then it can load the script module first. A quick parse cost 20 lines of code.

No comments: