The Lightsabre Project ====================== Part 004 - Parsing Server Responses New that I'm receiving data from the server, I need to make sense of the stuff that's arriving. The gopher data is landing in a single large buffer, and in order to display it properly I need to split it by line, and parse each of those lines to extract types, selectors etc. As mentioned in the previous update, UNSTRING will parse the data for me. It works like this: unstring read-buffer (1:recv-bytes-read) delimited by X"0D25" into current-line with pointer line-pointer. 'read-buffer' contains the data read from the server (post ASCII-EBCDIC conversion), and 'recv-bytes-read' hold a count of bytes received from the server. The (1:...) bit is like an array slice of the read buffer. Unstring works its way through read-buffer until it reaches data that matches the 'delimited by' clause - in this case EBCDIC CRLF. Once it reaches a delimiter, it puts the data read so far in to 'current-line', and sets 'line-pointer' to the current index of the delimiter in the read-buffer. At this point, we have a line ('current-line') ready for parsing. The line parsing is also an UNSTRING, this time looking for TABs. Wrap all this in a loop, and you're pretty much set. There's a little bit more to it than that (tracking UNSTRING pointers, getting field lengths etc.) but not much. Once we've got the server response parsed, display is just a matter of looping over the parsed data. I'm now creating permanent executables with my compiles, not the temporary ones used previously. This is mainly because I'm now at the stage where I need to start introducing some interactivity, so running the thing in batch isn't an option any more. Creating executables that remain on disk requires creating a dataset to accept them (I use 'LEE.GOPHER.LOAD') and modifying the compile JCL to use IBM procedure IGYWCL (CL is 'compile and link'), and instructing the linker to put it's output in my dataset. The resulting executable can then be run in TSO. First however, I need to tell MVS to allocate SYSOUT and SYSIN to my terminal using 'allocate'. That stuff all happens automatically in a Unix shell of course (STDOUT, STDIN, STDERR and all that). The executable is run by issuing the CALL command, followed by the name of the executable. When the thing's ready for release, I'll need to do some work around getting rid of the allocation step and making it so you can just enter the command as eg. 'gopher', but for the time being, this is fine. So, a copy and paste of the output as it stands is shown below: ('READY' is the TSO prompt) ------- READY allocate ddname(sysout) dsname(*) READY allocate ddname(sysin) dsname(*) READY call gopher.load(gopher) gopher for mvs hostname-value republic.circumlunar.space hostname-length 0026 read: retcode = 0, done. counting lines in 00002870 bytes line count 0059 splitting data into 0059 lines Welcome to the Mare Serenitatis Circumlunar Corporate Republic . : / 0 . . . / : * /-----------------: ==================-+-+-+-+-+-+-+-+-+-+================== ++++++: /:/:/:/:/:/:/:/:/:/:/:/:/:/:/:/:/://++++++ :_______ .oo. . . . .oo._______/ :_______ oooo _______/ . | :||||/ | . | :++++: | * ::: |><| ::: . (((II))) * . /::: . . :::/ || . (((((oo))))) * : / !! . . . YY / : /: /><: !----------|UU|----------! |__________: /__________| . ++ . . . . 001 DIR About this Server 002 DIR Our Sister Colony Zaibatsu 003 FILE Signup for a Republic user account 004 DIR Recent Phlog Updates Sundogs granted asylum here: 005 DIR aidanh010 006 DIR bacterio 007 DIR ben 008 DIR cleber 009 DIR emar 010 DIR katolaz 011 DIR kevin 012 DIR kst 013 DIR leeb 014 DIR lntl 015 DIR mijk 016 DIR mrguilt 017 DIR np89 018 DIR papa 019 DIR rond 020 DIR spring 021 DIR uwu Please enter command (h for help) q done! READY ------- Starting to look more like a proper client now :-) As the fancy screen handling etc. is still some way off, for the time being I'm temporarily putting in a prompt for the user to issue commands to the client. Not put too much thought into this yet, but you can see above that the 'q' command seems to work pretty well. There are numbers next to the selectors, which I've added in anticipation of implementing, say, a 'g' command (goto), which will accept a number parameter to follow a particular selector. So eg. 'g 017' (or something similar) would follow the link to np89's gopherhole. You get the idea. That's the plan, at least. Let's see how it goes.