Inform - Support - Source

Back to List

Inventory
Complete

Backward
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing parserm.h

Keyboard (lines 1031-1221)

1031  #Endif; ! TARGET_
1032   
1033  [ Keyboard  a_buffer a_table  nw i w w2 x1 x2;
1034      DisplayStatus();
1035   
1036    .FreshInput;
1037   
1038      ! Save the start of the buffer, in case "oops" needs to restore it
1039      ! to the previous time's buffer
1040   
1041      for (i=0 : i<64 : i++) oops_workspace->i = a_buffer->i;
1042   
1043      ! In case of an array entry corruption that shouldn't happen, but would be
1044      ! disastrous if it did:
1045   
1046      #Ifdef TARGET_ZCODE;
1047      a_buffer->0 = INPUT_BUFFER_LEN;
1048      a_table->0 = 15;  ! Allow to split input into this many words
1049      #Endif; ! TARGET_
1050   
1051      ! Print the prompt, and read in the words and dictionary addresses
1052   
1053      L__M(##Prompt);
1054      AfterPrompt();
1055      #IfV5;
1056      DrawStatusLine();
1057      #Endif; ! V5
1058      KeyboardPrimitive(a_buffer, a_table);
1059      #Ifdef TARGET_ZCODE;
1060      nw = a_table->1;
1061      #Ifnot; ! TARGET_GLULX
1062      nw = a_table-->0;
1063      #Endif; ! TARGET_
1064   
1065      ! If the line was blank, get a fresh line
1066      if (nw == 0) {
1067          L__M(##Miscellany, 10);
1068          jump FreshInput;
1069      }
1070   
1071      ! Unless the opening word was "oops", return
1072      ! Conveniently, a_table-->1 is the first word in both ZCODE and GLULX.
1073   
1074      w = a_table-->1;
1075      if (w == OOPS1__WD or OOPS2__WD or OOPS3__WD) jump DoOops;
1076   
1077      if (a_buffer->WORDSIZE == COMMENT_CHARACTER) {
1078          #Ifdef TARGET_ZCODE;
1079          if ((HDR_GAMEFLAGS-->0) & 1 || xcommsdir)
1080                                             L__M(##Miscellany, 54);
1081          else                               L__M(##Miscellany, 55);
1082          #Ifnot; ! TARGET_GLULX
1083          if (gg_scriptstr || gg_commandstr) L__M(##Miscellany, 54);
1084          else                               L__M(##Miscellany, 55);
1085          #Endif; ! TARGET_
1086   
1087          jump FreshInput;
1088      }
1089   
1090      #IfV5;
1091      ! Undo handling
1092   
1093      if ((w == UNDO1__WD or UNDO2__WD or UNDO3__WD) && (nw==1)) {
1094          if (turns == START_MOVE) {
1095              L__M(##Miscellany, 11);
1096              jump FreshInput;
1097          }
1098          if (undo_flag == 0) {
1099              L__M(##Miscellany, 6);
1100              jump FreshInput;
1101          }
1102          if (undo_flag == 1) jump UndoFailed;
1103          #Ifdef TARGET_ZCODE;
1104          @restore_undo i;
1105          #Ifnot; ! TARGET_GLULX
1106          @restoreundo i;
1107          i = (~~i);
1108          #Endif; ! TARGET_
1109          if (i == 0) {
1110            .UndoFailed;
1111              L__M(##Miscellany, 7);
1112          }
1113          jump FreshInput;
1114      }
1115      #Ifdef TARGET_ZCODE;
1116      @save_undo i;
1117      #Ifnot; ! TARGET_GLULX
1118      @saveundo i;
1119      if (i == -1) {
1120          GGRecoverObjects();
1121          i = 2;
1122      }
1123      else  i = (~~i);
1124      #Endif; ! TARGET_
1125      just_undone = 0;
1126      undo_flag = 2;
1127      if (i == -1) undo_flag = 0;
1128      if (i == 0) undo_flag = 1;
1129      if (i == 2) {
1130          RestoreColours();
1131          #Ifdef TARGET_ZCODE;
1132          style bold;
1133          #Ifnot; ! TARGET_GLULX
1134          glk($0086, 4); ! set subheader style
1135          #Endif; ! TARGET_
1136          print (name) location, "^";
1137          #Ifdef TARGET_ZCODE;
1138          style roman;
1139          #Ifnot; ! TARGET_GLULX
1140          glk($0086, 0); ! set normal style
1141          #Endif; ! TARGET_
1142          L__M(##Miscellany, 13);
1143          just_undone = 1;
1144          jump FreshInput;
1145      }
1146      #Endif; ! V5
1147   
1148      return nw;
1149   
1150    .DoOops;
1151      if (oops_from == 0) {
1152          L__M(##Miscellany, 14);
1153          jump FreshInput;
1154      }
1155      if (nw == 1) {
1156          L__M(##Miscellany, 15);
1157          jump FreshInput;
1158      }
1159      if (nw > 2) {
1160          L__M(##Miscellany, 16);
1161          jump FreshInput;
1162      }
1163   
1164      ! So now we know: there was a previous mistake, and the player has
1165      ! attempted to correct a single word of it.
1166   
1167      for (i=0 : i<INPUT_BUFFER_LEN : i++) buffer2->i = a_buffer->i;
1168      #Ifdef TARGET_ZCODE;
1169      x1 = a_table->9;  ! Start of word following "oops"
1170      x2 = a_table->8;  ! Length of word following "oops"
1171      #Ifnot; ! TARGET_GLULX
1172      x1 = a_table-->6; ! Start of word following "oops"
1173      x2 = a_table-->5; ! Length of word following "oops"
1174      #Endif; ! TARGET_
1175   
1176      ! Repair the buffer to the text that was in it before the "oops"
1177      ! was typed:
1178   
1179      for (i=0 : i<64 : i++) a_buffer->i = oops_workspace->i;
1180      Tokenise__(a_buffer,a_table);
1181   
1182      ! Work out the position in the buffer of the word to be corrected:
1183   
1184      #Ifdef TARGET_ZCODE;
1185      w = a_table->(4*oops_from + 1); ! Start of word to go
1186      w2 = a_table->(4*oops_from);    ! Length of word to go
1187      #Ifnot; ! TARGET_GLULX
1188      w = a_table-->(3*oops_from);      ! Start of word to go
1189      w2 = a_table-->(3*oops_from - 1); ! Length of word to go
1190      #Endif; ! TARGET_
1191   
1192      ! Write spaces over the word to be corrected:
1193   
1194      for (i=0 : i<w2 : i++) a_buffer->(i+w) = ' ';
1195   
1196      if (w2 < x2) {
1197          ! If the replacement is longer than the original, move up...
1198          for (i=INPUT_BUFFER_LEN-1 : i>=w+x2 : i--)
1199              a_buffer->i = a_buffer->(i-x2+w2);
1200   
1201          ! ...increasing buffer size accordingly.
1202          #Ifdef TARGET_ZCODE;
1203          a_buffer->1 = (a_buffer->1) + (x2-w2);
1204          #Ifnot; ! TARGET_GLULX
1205          a_buffer-->0 = (a_buffer-->0) + (x2-w2);
1206          #Endif; ! TARGET_
1207      }
1208   
1209      ! Write the correction in:
1210   
1211      for (i=0 : i<x2 : i++) a_buffer->(i+w) = buffer2->(i+x1);
1212   
1213      Tokenise__(a_buffer, a_table);
1214      #Ifdef TARGET_ZCODE;
1215      nw = a_table->1;
1216      #Ifnot; ! TARGET_GLULX
1217      nw = a_table-->0;
1218      #Endif; ! TARGET_
1219   
1220      return nw;
1221  ]; ! end of Keyboard


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.