migrate-config: use \s, be a bit more whitespace tolerant (+test) (Thanks sbedivere)

Fixes: #457
This commit is contained in:
Michael Stapelberg 2011-08-28 17:01:37 +02:00
parent b76b9be75a
commit 96b219f27b
2 changed files with 18 additions and 11 deletions

View File

@ -67,7 +67,7 @@ sub need_to_convert {
# have a look at bindings # have a look at bindings
next unless $line =~ /^bind/; next unless $line =~ /^bind/;
my ($statement, $key, $command) = ($line =~ /([a-zA-Z_-]+)[ \t]+([^ \t]+)[ \t]+(.*)/); my ($statement, $key, $command) = ($line =~ /([a-zA-Z_-]+)\s+([^\s]+)\s+(.*)/);
return 0 if $command =~ /^layout/ || return 0 if $command =~ /^layout/ ||
$command =~ /^floating/ || $command =~ /^floating/ ||
$command =~ /^workspace/ || $command =~ /^workspace/ ||
@ -94,7 +94,7 @@ for my $line (@lines) {
# skip everything but workspace lines # skip everything but workspace lines
next unless defined($statement) and $statement eq 'workspace'; next unless defined($statement) and $statement eq 'workspace';
my ($number, $params) = ($parameters =~ /[ \t]+([0-9]+) (.+)/); my ($number, $params) = ($parameters =~ /\s+([0-9]+)\s+(.+)/);
# save workspace name (unless the line is actually a workspace assignment) # save workspace name (unless the line is actually a workspace assignment)
$workspace_names{$number} = $params unless $params =~ /^output/; $workspace_names{$number} = $params unless $params =~ /^output/;
@ -124,7 +124,7 @@ for my $line (@lines) {
# workspace_bar is gone, you should use i3bar now # workspace_bar is gone, you should use i3bar now
if ($statement eq 'workspace_bar') { if ($statement eq 'workspace_bar') {
$workspace_bar = ($parameters =~ /[ \t+](yes|true|on|enable|active)/); $workspace_bar = ($parameters =~ /\s+(yes|true|on|enable|active)/);
print "# XXX: REMOVED workspace_bar line. There is no internal workspace bar in v4.\n"; print "# XXX: REMOVED workspace_bar line. There is no internal workspace bar in v4.\n";
next; next;
} }
@ -153,7 +153,7 @@ for my $line (@lines) {
# one form of this is still ok (workspace assignments), the other (named workspaces) isnt # one form of this is still ok (workspace assignments), the other (named workspaces) isnt
if ($statement eq 'workspace') { if ($statement eq 'workspace') {
my ($number, $params) = ($parameters =~ /[ \t]+([0-9]+) (.+)/); my ($number, $params) = ($parameters =~ /\s+([0-9]+)\s+(.+)/);
if ($params =~ /^output/) { if ($params =~ /^output/) {
print "$line\n"; print "$line\n";
next; next;
@ -187,7 +187,7 @@ sub convert_command {
stack-limit stack-limit
); );
my ($statement, $key, $command) = ($line =~ /([a-zA-Z_-]+)[ \t]+([^ \t]+)[ \t]+(.*)/); my ($statement, $key, $command) = ($line =~ /([a-zA-Z_-]+)\s+([^\s]+)\s+(.*)/);
# turn 'bind' to 'bindcode' # turn 'bind' to 'bindcode'
$statement = 'bindcode' if $statement eq 'bind'; $statement = 'bindcode' if $statement eq 'bind';
@ -234,14 +234,14 @@ sub convert_command {
# goto command is now obsolete due to criteria + focus command # goto command is now obsolete due to criteria + focus command
if ($command =~ /^goto/) { if ($command =~ /^goto/) {
my ($mark) = ($command =~ /^goto (.*)/); my ($mark) = ($command =~ /^goto\s+(.*)/);
print qq|$statement $key [con_mark="$mark"] focus\n|; print qq|$statement $key [con_mark="$mark"] focus\n|;
return; return;
} }
# the jump command is also obsolete due to criteria + focus # the jump command is also obsolete due to criteria + focus
if ($command =~ /^jump/) { if ($command =~ /^jump/) {
my ($params) = ($command =~ /^jump (.*)/); my ($params) = ($command =~ /^jump\s+(.*)/);
if ($params =~ /^"/) { if ($params =~ /^"/) {
# jump ["]window class[/window title]["] # jump ["]window class[/window title]["]
($params) = ($params =~ /^"([^"]+)"/); ($params) = ($params =~ /^"([^"]+)"/);
@ -262,8 +262,8 @@ sub convert_command {
} }
if (!$replaced && $command =~ /^focus/) { if (!$replaced && $command =~ /^focus/) {
my ($what) = ($command =~ /^focus (.*)/); my ($what) = ($command =~ /^focus\s+(.*)/);
$what =~ s/[ \t]//g; $what =~ s/\s//g;
if ($what eq 'ft') { if ($what eq 'ft') {
$what = 'mode_toggle'; $what = 'mode_toggle';
} elsif ($what eq 'floating' || $what eq 'tiling') { } elsif ($what eq 'floating' || $what eq 'tiling') {
@ -277,7 +277,7 @@ sub convert_command {
} }
if ($command =~ /^mode/) { if ($command =~ /^mode/) {
my ($parameters) = ($command =~ /^mode (.*)/); my ($parameters) = ($command =~ /^mode\s+(.*)/);
print qq|$statement $key mode "$parameters"\n|; print qq|$statement $key mode "$parameters"\n|;
return; return;
} }
@ -286,7 +286,7 @@ sub convert_command {
if ($command =~ /^resize/) { if ($command =~ /^resize/) {
# OLD: resize <left|right|top|bottom> [+|-]<pixels>\n") # OLD: resize <left|right|top|bottom> [+|-]<pixels>\n")
# NEW: resize <grow|shrink> <direction> [<px> px] [or <ppt> ppt] # NEW: resize <grow|shrink> <direction> [<px> px] [or <ppt> ppt]
my ($direction, $sign, $px) = ($command =~ /^resize (left|right|top|bottom) ([+-])([0-9]+)/); my ($direction, $sign, $px) = ($command =~ /^resize\s+(left|right|top|bottom)\s+([+-])([0-9]+)/);
my $cmd = 'resize '; my $cmd = 'resize ';
$cmd .= ($sign eq '+' ? 'grow' : 'shrink') . ' '; $cmd .= ($sign eq '+' ? 'grow' : 'shrink') . ' ';
if ($direction eq 'top') { if ($direction eq 'top') {

View File

@ -264,6 +264,13 @@ ok(line_exists($output, qr|^bindsym Mod1\+f resize shrink right 20 px$|), 'resiz
$output = migrate_config('bindsym Mod1+f resize bottom +23'); $output = migrate_config('bindsym Mod1+f resize bottom +23');
ok(line_exists($output, qr|^bindsym Mod1\+f resize grow down 23 px$|), 'resize bottom changed'); ok(line_exists($output, qr|^bindsym Mod1\+f resize grow down 23 px$|), 'resize bottom changed');
#####################################################################
# also resizing, but with indention this time
#####################################################################
$output = migrate_config("bindsym Mod1+f resize left \t +10");
ok(line_exists($output, qr|^bindsym Mod1\+f resize grow left 10 px$|), 'resize left changed');
##################################################################### #####################################################################
# check whether jump's parameters get changed correctly # check whether jump's parameters get changed correctly
##################################################################### #####################################################################