Inform - Support - Source

Back to List

Inventory
Complete

Backward
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing parserm.h

KeyCharPrimitive (lines 865-956)

0865  #Ifnot; ! TARGET_GLULX
0866   
0867  [ KeyCharPrimitive win nostat done res ix jx ch;
0868      jx = ch; ! squash compiler warnings
0869      if (win == 0) win = gg_mainwin;
0870      if (gg_commandstr ~= 0 && gg_command_reading ~= false) {
0871          ! get_line_stream
0872          done = glk($0091, gg_commandstr, gg_arguments, 31);
0873          if (done == 0) {
0874              glk($0044, gg_commandstr, 0); ! stream_close
0875              gg_commandstr = 0;
0876              gg_command_reading = false;
0877              ! fall through to normal user input.
0878          }
0879          else {
0880              ! Trim the trailing newline
0881              if (gg_arguments->(done-1) == 10) done = done-1;
0882              res = gg_arguments->0;
0883              if (res == '\') {
0884                  res = 0;
0885                  for (ix=1 : ix<done : ix++) {
0886                      ch = gg_arguments->ix;
0887                      if (ch >= '0' && ch <= '9') {
0888                          @shiftl res 4 res;
0889                          res = res + (ch-'0');
0890                      }
0891                      else if (ch >= 'a' && ch <= 'f') {
0892                          @shiftl res 4 res;
0893                          res = res + (ch+10-'a');
0894                      }
0895                      else if (ch >= 'A' && ch <= 'F') {
0896                          @shiftl res 4 res;
0897                          res = res + (ch+10-'A');
0898                      }
0899                  }
0900              }
0901          jump KCPContinue;
0902          }
0903      }
0904      done = false;
0905      glk($00D2, win); ! request_char_event
0906      while (~~done) {
0907          glk($00C0, gg_event); ! select
0908          switch (gg_event-->0) {
0909            5: ! evtype_Arrange
0910              if (nostat) {
0911                  glk($00D3, win); ! cancel_char_event
0912                  res = $80000000;
0913                  done = true;
0914                  break;
0915              }
0916              DrawStatusLine();
0917            2: ! evtype_CharInput
0918              if (gg_event-->1 == win) {
0919                  res = gg_event-->2;
0920                  done = true;
0921                  }
0922          }
0923          ix = HandleGlkEvent(gg_event, 1, gg_arguments);
0924          if (ix == 2) {
0925              res = gg_arguments-->0;
0926              done = true;
0927          }
0928          else if (ix == -1) {
0929              done = false;
0930          }
0931      }
0932      if (gg_commandstr ~= 0 && gg_command_reading == false) {
0933          if (res < 32 || res >= 256 || (res == '\' or ' ')) {
0934              glk($0081, gg_commandstr, '\'); ! put_buffer_char
0935              done = 0;
0936              jx = res;
0937              for (ix=0 : ix<8 : ix++) {
0938                  @ushiftr jx 28 ch;
0939                  @shiftl jx 4 jx;
0940                  ch = ch & $0F;
0941                  if (ch ~= 0 || ix == 7) done = 1;
0942                  if (done) {
0943                      if (ch >= 0 && ch <= 9) ch = ch + '0';
0944                      else                    ch = (ch - 10) + 'A';
0945                      glk($0081, gg_commandstr, ch); ! put_buffer_char
0946                  }
0947              }
0948          }
0949          else {
0950              glk($0081, gg_commandstr, res); ! put_buffer_char
0951          }
0952          glk($0081, gg_commandstr, 10); ! put_char_stream (newline)
0953      }
0954    .KCPContinue;
0955      return res;
0956  ];


Last updated 27 February 2004. The librarian in charge of this page is Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight. Please email any comments, suggestions or corrections to cedenqs@inform-fiction.org.