#! perl # miscellaneous commands sub rename_to($$$) { my ($ob, $from, $to) = @_; warn "<$ob|$from|$to>\n";#d# $to =~ /^[a-zA-Z0-9.,=#\/%$!^]*$/ or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things."); 127 >= length $to or return $ob->message ("rename: new name must be <= 127 characters."); my $item; if (length $from) { $item = $ob->find_best_object_match ($from) or return $ob->message ("rename: could not find a matching item to rename."); } else { $item = $ob->find_marked_object () or return $ob->message ("rename: no from name and no marked item found to rename."); } $item->custom_name (length $to ? $to : undef); if (length $to) { $item->custom_name ($to); $ob->message ("Your " . $item->base_name . " will now be called $to."); } else { $item->custom_name (undef); $ob->message ("You stop calling your " . $item->base_name . " with weird names."); } $ob->esrv_update_item (cf::UPD_NAME, $item); return 1; } cf::register_command rename => 0, sub { my ($ob, $arg) = @_; warn "<<<$arg>>>\n";#d# if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]+)> \s*$/x) { # compatibility syntax rename_to $ob, $1, $2; } elsif ($arg =~ / ^\s* (?: (?: "((?:[^"]+|\\.)*)" | (\S+) ) \s+)? to \s+ (?: "((?:[^"]+|\\.)*)" | (\S+) ) \s*$ /x) { # does not unquote $1 or $3 rename_to $ob, $2||$1, $4||$3; } else { $ob->message ('Syntax error. Rename usage: rename ["oldname"] to "newname"'); } };