Исправление ssh, сделал признаком приглашения @

v++
This commit is contained in:
2024-03-21 02:25:56 +03:00
parent 082753b366
commit dd0570f281
4 changed files with 45 additions and 11 deletions

View File

@@ -13,7 +13,7 @@ public class ShellParser {
public static char c;
public static char[] buffer = new char[1];
public static Vector<String> lines = new Vector<>();
public static boolean bracketOpened = false;
// public static boolean bracketOpened = false;
public static boolean return_active = false;
public static boolean isCommandSymbol() {
int code = c;
@@ -22,7 +22,7 @@ public class ShellParser {
public static void ResetLine() {
invitationBuilder = new StringBuilder();
lineBuilder = new StringBuilder();
bracketOpened = false;
// bracketOpened = false;
state = ShellParserState.NewLine;
return_active = false;
}
@@ -30,6 +30,10 @@ public class ShellParser {
//латиница, цифры,подчеркивания. и -
return String.valueOf(c).matches("[\\w\\-]*") || c == '?';
}
public static boolean isRBracket(){
return c=='('||c==')';
}
//false наоборот означать что конец строки ЕСТЬ.
public static boolean checkEndLine() {
if (return_active) {
@@ -59,9 +63,10 @@ public class ShellParser {
}
return true;
}
/*
public static void NewLine() {
if (c == '[') {//приглашение со скобками.
bracketOpened = true;
// bracketOpened = true;
invitationBuilder.append(c);
state = ShellParserState.UserName;
} else {
@@ -73,10 +78,36 @@ public class ShellParser {
state = ShellParserState.Skip;
}
}
*/
public static void NewLine() {
if (c=='@'){ //собака, признак приглашения.
String test = invitationBuilder.toString();
test = test.toLowerCase();
state = test.endsWith(userName.toLowerCase()) ? ShellParserState.MachineName : ShellParserState.Skip;
invitationBuilder.append(c);
}else {
invitationBuilder.append(c);
}
/*
if (c == '[') {//приглашение со скобками.
// bracketOpened = true;
invitationBuilder.append(c);
state = ShellParserState.UserName;
} else {
if (isNameCharacter()) {
invitationBuilder.append(c);
state = ShellParserState.UserName;
} else
//не буква и не скобка. значит в этой строке приглашения нет.
state = ShellParserState.Skip;
}
*/
}
/*
public static void UserName() {
if (c == '@') { //проверить. а тот ли юзернейм.
String test = invitationBuilder.toString();
if (bracketOpened) test = test.substring(1);
// if (bracketOpened) test = test.substring(1);
test = test.toLowerCase();
state = test.endsWith(userName.toLowerCase()) ? ShellParserState.MachineName : ShellParserState.Skip;
invitationBuilder.append(c);
@@ -85,6 +116,7 @@ public class ShellParser {
else
state = ShellParserState.Skip;
}
*/
public static void MachineName() {
switch (c) {
case ' ':
@@ -107,6 +139,7 @@ public class ShellParser {
invitationBuilder.append(c);
state = ShellParserState.Space; //приглашение завершено. осталось прочитать пробел после него
break;
/*
case ']':
if (bracketOpened) {
invitationBuilder.append(c);
@@ -116,6 +149,7 @@ public class ShellParser {
state = ShellParserState.Skip; //непарная скобка, все, привет
}
break;
*/
default:
invitationBuilder.append(c);
break;
@@ -158,9 +192,9 @@ public class ShellParser {
case NewLine:
NewLine();
break;
case UserName:
UserName();
break;
// case UserName:
// UserName();
// break;
case MachineName:
MachineName();
break;