Changeset a827529
- Timestamp:
- Jan 11, 2008, 2:28:36 PM (17 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- fac5463
- Parents:
- 16c6cca (diff), 9e02bb7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 2 added
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
message.c
r3a7cf49 ra827529 330 330 res=owl_message_get_attribute_value(m, "isprivate"); 331 331 if (!res) return(0); 332 return (1);332 return !strcmp(res, "true"); 333 333 } 334 334 -
perl/lib/BarnOwl/ModuleLoader.pm
rbe98ba5 rb0c8011 9 9 10 10 sub load_all { 11 PAR::reload_libs(); 11 12 my %modules; 12 13 my @modules; … … 36 37 for my $class (keys %modules) { 37 38 if(!defined eval "use BarnOwl::Module::$class") { 38 BarnOwl::error("Unable to load module $class: $!") if $!;39 # BarnOwl::error("Unable to load module $class: $!") if $!; 39 40 BarnOwl::error("Unable to load module $class: $@") if $@; 40 41 } … … 47 48 BarnOwl::new_command('reload-modules', sub {BarnOwl::ModuleLoader->reload}, { 48 49 summary => 'Reload all modules', 49 usage => 'reload ',50 usage => 'reload-modules', 50 51 description => q{Reloads all modules located in ~/.owl/modules and the system modules directory} 51 52 }); -
perl/modules/IRC/lib/BarnOwl/Message/IRC.pm
r0e52069 r2fb58e4 56 56 sub long_sender {shift->{from} || ""}; 57 57 58 sub login_extra { shift->channel; } 59 58 60 59 61 1; -
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
r6286f26 rb0c8011 30 30 31 31 sub startup { 32 BarnOwl::new_variable_string('irc:nick', {default => $ENV{USER}}); 33 BarnOwl::new_variable_string('irc:user', {default => $ENV{USER}}); 34 BarnOwl::new_variable_string('irc:name', {default => ""}); 35 BarnOwl::new_variable_bool('irc:spew', {default => 0}); 32 BarnOwl::new_variable_string('irc:nick', { 33 default => $ENV{USER}, 34 summary => 'The default IRC nickname', 35 description => 'By default, irc-connect will use this nick ' . 36 'when connecting to a new server. See :help irc-connect for ' . 37 'more information.' 38 }); 39 40 BarnOwl::new_variable_string('irc:user', { 41 default => $ENV{USER}, 42 summary => 'The IRC "username" field' 43 }); 44 BarnOwl::new_variable_string('irc:name', { 45 default => "", 46 summary => 'A short name field for IRC', 47 description => 'A short (maybe 60 or so chars) piece of text, ' . 48 'originally intended to display your real name, which people ' . 49 'often use for pithy quotes and URLs.' 50 }); 51 52 BarnOwl::new_variable_bool('irc:spew', { 53 default => 0, 54 summary => 'Show unhandled IRC events', 55 description => 'If set, display all unrecognized IRC events as ' . 56 'admin messages. Intended for debugging and development use only ' 57 }); 58 36 59 register_commands(); 37 60 register_handlers(); … … 61 84 62 85 sub register_commands { 63 BarnOwl::new_command('irc-connect' => \&cmd_connect); 86 BarnOwl::new_command('irc-connect' => \&cmd_connect, 87 { 88 summary => 'Connect to an IRC server', 89 usage => 'irc-connect [-a ALIAS ] [-s] [-p PASSWORD] [-n NICK] SERVER [port]', 90 description => 91 92 "Connect to an IRC server. Supported options are\n\n" . 93 "-a <alias> Define an alias for this server\n" . 94 "-s Use SSL\n" . 95 "-p <password> Specify the password to use\n" . 96 "-n <nick> Use a non-default nick" 97 }); 64 98 BarnOwl::new_command('irc-disconnect' => \&cmd_disconnect); 65 BarnOwl::new_command('irc-msg' => \&cmd_msg); 66 BarnOwl::new_command('irc-join' => \&cmd_join); 67 BarnOwl::new_command('irc-nick' => \&cmd_nick); 99 BarnOwl::new_command('irc-msg' => \&cmd_msg); 100 BarnOwl::new_command('irc-join' => \&cmd_join); 101 BarnOwl::new_command('irc-part' => \&cmd_part); 102 BarnOwl::new_command('irc-nick' => \&cmd_nick); 103 BarnOwl::new_command('irc-names' => \&cmd_names); 104 BarnOwl::new_command('irc-whois' => \&cmd_whois); 68 105 } 69 106 … … 94 131 "ssl" => \$ssl, 95 132 "password=s" => \$password, 96 " port=i" => \$port,133 "nick=s" => \$nick, 97 134 ); 98 135 $host = shift @ARGV or die("Usage: $cmd HOST\n"); 99 136 if(!$alias) { 100 $alias = $1 if $host =~ /^(?:irc[.])?(\w+)[.]\w+$/; 101 $alias ||= $host; 137 if($host =~ /^(?:irc[.])?(\w+)[.]\w+$/) { 138 $alias = $1; 139 } else { 140 $alias = $host; 141 } 102 142 } 103 $port ||=6667;143 $port = shift @ARGV || 6667; 104 144 $ssl ||= 0; 145 } 146 147 if(exists $ircnets{$alias}) { 148 die("Already connected to a server with alias '$alias'. Either disconnect or specify an alias with -a.\n"); 105 149 } 106 150 … … 148 192 my $msg = BarnOwl::Message->new( 149 193 type => 'IRC', 150 direction => 'out',194 direction => is_private($to) ? 'out' : 'in', 151 195 server => $conn->server, 152 196 network => $conn->alias, … … 169 213 } 170 214 215 sub cmd_part { 216 my $cmd = shift; 217 my $conn = get_connection(\@_); 218 my $chan = get_channel(\@_) || die("Usage: $cmd <channel>\n"); 219 $conn->part($chan); 220 } 221 171 222 sub cmd_nick { 172 223 my $cmd = shift; 173 224 my $conn = get_connection(\@_); 174 my $nick = shift or die("Usage: $cmd <new nick> ");225 my $nick = shift or die("Usage: $cmd <new nick>\n"); 175 226 $conn->nick($nick); 227 } 228 229 sub cmd_names { 230 my $cmd = shift; 231 my $conn = get_connection(\@_); 232 my $chan = get_channel(\@_) || die("Usage: $cmd <channel>\n"); 233 $conn->names($chan); 234 } 235 236 sub cmd_whois { 237 my $cmd = shift; 238 my $conn = get_connection(\@_); 239 my $who = shift || die("Usage: $cmd <user>\n"); 240 $conn->whois($who); 176 241 } 177 242 … … 196 261 } 197 262 263 sub get_channel { 264 my $args = shift; 265 if(scalar @$args) { 266 return shift @$args; 267 } 268 my $m = BarnOwl::getcurmsg(); 269 if($m && $m->type eq 'IRC') { 270 return $m->channel if !$m->is_private; 271 } 272 return undef; 273 } 274 198 275 sub get_connection_by_alias { 199 276 my $key = shift; -
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
r0e52069 r9e02bb7 16 16 17 17 use base qw(Net::IRC::Connection Class::Accessor Exporter); 18 __PACKAGE__->mk_accessors(qw(alias channels ));18 __PACKAGE__->mk_accessors(qw(alias channels motd)); 19 19 our @EXPORT_OK = qw(&is_private); 20 20 … … 29 29 $self->alias($alias); 30 30 $self->channels([]); 31 $self->motd(""); 31 32 bless($self, $class); 32 33 33 $self->add_global_handler(376 => sub { goto &on_connect }); 34 $self->add_global_handler(['msg', 'notice', 'public', 'caction'], 34 $self->add_default_handler(sub { goto &on_event; }); 35 $self->add_handler(376 => sub { goto &on_connect }); 36 $self->add_handler(['msg', 'notice', 'public', 'caction'], 35 37 sub { goto &on_msg }); 36 $self->add_global_handler(cping => sub { goto &on_ping }); 37 $self->add_default_handler(sub { goto &on_event; }); 38 $self->add_handler(['welcome', 'yourhost', 'created', 39 'luserclient', 'luserop', 'luserchannels', 'luserme'], 40 sub { goto &on_admin_msg }); 41 $self->add_handler(['myinfo', 'map', 'n_local', 'n_global', 42 'luserconns'], 43 sub { }); 44 $self->add_handler(motdstart => sub { goto &on_motdstart }); 45 $self->add_handler(motd => sub { goto &on_motd }); 46 $self->add_handler(endofmotd => sub { goto &on_endofmotd }); 47 $self->add_handler(join => sub { goto &on_join }); 48 $self->add_handler(part => sub { goto &on_part }); 49 $self->add_handler(disconnect => sub { goto &on_disconnect }); 50 $self->add_handler(nicknameinuse => sub { goto &on_nickinuse }); 51 $self->add_handler(cping => sub { goto &on_ping }); 38 52 39 53 return $self; … … 49 63 } 50 64 51 sub on_msg { 52 my ($self, $evt) = @_; 53 my ($recipient) = $evt->to; 54 my $body = strip_irc_formatting([$evt->args]->[0]); 55 $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction'; 56 my $msg = BarnOwl::Message->new( 65 sub new_message { 66 my $self = shift; 67 my $evt = shift; 68 return BarnOwl::Message->new( 57 69 type => 'IRC', 58 direction => 'in',59 70 server => $self->server, 60 71 network => $self->alias, 61 recipient => $recipient,62 body => $body,63 72 sender => $evt->nick, 64 73 hostname => $evt->host, 65 74 from => $evt->from, 75 @_ 76 ); 77 } 78 79 sub on_msg { 80 my ($self, $evt) = @_; 81 my ($recipient) = $evt->to; 82 my $body = strip_irc_formatting([$evt->args]->[0]); 83 my $nick = $self->nick; 84 BarnOwl::beep() if $body =~ /\b\Q$nick\E\b/; 85 $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction'; 86 my $msg = $self->new_message($evt, 87 direction => 'in', 88 recipient => $recipient, 89 body => $body, 66 90 $evt->type eq 'notice' ? 67 91 (notice => 'true') : (), … … 70 94 replycmd => 'irc-msg ' . 71 95 (is_private($recipient) ? $evt->nick : $recipient), 72 replysendercmd => 'irc-msg ' . $evt->nick ,96 replysendercmd => 'irc-msg ' . $evt->nick 73 97 ); 98 74 99 BarnOwl::queue_message($msg); 75 100 } … … 80 105 } 81 106 107 sub on_admin_msg { 108 my ($self, $evt) = @_; 109 BarnOwl::admin_message("IRC", 110 BarnOwl::Style::boldify('IRC ' . $evt->type . ' message from ' 111 . $evt->alias) . "\n" 112 . strip_irc_formatting(join '\n', cdr $evt->args)); 113 } 114 115 sub on_motdstart { 116 my ($self, $evt) = @_; 117 $self->motd(join "\n", cdr $evt->args); 118 } 119 120 sub on_motd { 121 my ($self, $evt) = @_; 122 $self->motd(join "\n", $self->motd, cdr $evt->args); 123 } 124 125 sub on_endofmotd { 126 my ($self, $evt) = @_; 127 $self->motd(join "\n", $self->motd, cdr $evt->args); 128 BarnOwl::admin_message("IRC", 129 BarnOwl::Style::boldify('MOTD for ' . $evt->alias) . "\n" 130 . strip_irc_formatting($self->motd)); 131 } 132 133 sub on_join { 134 my ($self, $evt) = @_; 135 my $msg = $self->new_message($evt, 136 loginout => 'login', 137 channel => $evt->to, 138 ); 139 BarnOwl::queue_message($msg); 140 } 141 142 sub on_part { 143 my ($self, $evt) = @_; 144 my $msg = $self->new_message($evt, 145 loginout => 'logout', 146 channel => $evt->to, 147 ); 148 BarnOwl::queue_message($msg); 149 } 150 151 sub on_disconnect { 152 my $self = shift; 153 delete $BarnOwl::Module::IRC::ircnets{$self->alias}; 154 155 BarnOwl::admin_message('IRC', 156 "[" . $self->alias . "] Disconnected from server"); 157 } 158 159 sub on_nickinuse { 160 my ($self, $evt) = @_; 161 BarnOwl::admin_message("IRC", 162 "[" . $self->alias . "] " . 163 [$evt->args]->[1] . ": Nick already in use"); 164 } 165 82 166 sub on_event { 83 167 my ($self, $evt) = @_; 84 168 BarnOwl::admin_message("IRC", 85 " Unhandled IRC event of type " . $evt->type . ":\n"169 "[" . $self->alias . "] Unhandled IRC event of type " . $evt->type . ":\n" 86 170 . strip_irc_formatting(join("\n", $evt->args))) 87 171 if BarnOwl::getvar('irc:spew') eq 'on'; 88 172 } 89 173 174 90 175 ################################################################################ 91 176 ########################### Utilities/Helpers ################################## … … 94 179 sub strip_irc_formatting { 95 180 my $body = shift; 96 my @pieces = split /\x02/, $body; 181 # Strip mIRC colors. If someone wants to write code to convert 182 # these to zephyr colors, be my guest. 183 $body =~ s/\cC\d+(?:,\d+)?//g; 184 $body =~ s/\cO//g; 185 186 my @pieces = split /\cB/, $body; 97 187 my $out; 98 188 while(@pieces) { … … 109 199 } 110 200 201 sub cdr { 202 shift; 203 return @_; 204 } 205 111 206 1; -
perlglue.xs
rb363d83 r65fea01 13 13 #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV) 14 14 15 MODULE = BarnOwl PACKAGE = BarnOwl 15 /************************************************************* 16 * NOTE 17 ************************************************************* 18 * These functions, when they are intended to be user-visible, 19 * are document in perlwrap.pm. If you add functions to this 20 * file, add the appropriate documentation there! 21 * 22 * If the function is simple enough, we simply define its 23 * entire functionality here in XS. If, however, it needs 24 * complex argument processing or something, we define a 25 * simple version here that takes arguments in as flat a 26 * manner as possible, to simplify the XS code, with a name 27 * with a trailing `_internal', and write a perl wrapper in 28 * perlwrap.pm that munges the arguments as appropriate and 29 * calls the internal version. 30 */ 31 32 MODULE = BarnOwl PACKAGE = BarnOwl 16 33 17 34 char * -
perlwrap.pm
r18fb3d4f rb0c8011 14 14 15 15 package BarnOwl; 16 17 =head1 NAME 18 19 BarnOwl 20 21 =head1 DESCRIPTION 22 23 The BarnOwl module contains the core of BarnOwl's perl 24 bindings. Source in this module is also run at startup to bootstrap 25 barnowl by defining things like the default style. 26 27 =for NOTE 28 These following functions are defined in perlglue.xs. Keep the 29 documentation here in sync with the user-visible commands defined 30 there! 31 32 =head2 command STRING 33 34 Executes a BarnOwl command in the same manner as if the user had 35 executed it at the BarnOwl command prompt. If the command returns a 36 value, return it as a string, otherwise return undef. 37 38 =head2 getcurmsg 39 40 Returns the current message as a C<BarnOwl::Message> subclass, or 41 undef if there is no message selected 42 43 =head2 getnumcols 44 45 Returns the width of the display window BarnOwl is currently using 46 47 =head2 getidletime 48 49 Returns the length of time since the user has pressed a key, in 50 seconds. 51 52 =head2 zephyr_getrealm 53 54 Returns the zephyr realm barnowl is running in 55 56 =head2 zephyr_getsender 57 58 Returns the fully-qualified name of the zephyr sender barnowl is 59 running as, e.g. C<nelhage@ATHENA.MIT.EDU> 60 61 =head2 zephyr_zwrite COMMAND MESSAGE 62 63 Sends a zephyr programmatically. C<COMMAND> should be a C<zwrite> 64 command line, and C<MESSAGE> is the zephyr body to send. 65 66 =head2 ztext_stylestrip STRING 67 68 Strips zephyr formatting from a string and returns the result 69 70 =head2 queue_message MESSAGE 71 72 Enqueue a message in the BarnOwl message list, logging it and 73 processing it appropriately. C<MESSAGE> should be an instance of 74 BarnOwl::Message or a subclass. 75 76 =head2 admin_message HEADER BODY 77 78 Display a BarnOwl B<Admin> message, with the given header and body. 79 80 =head2 start_question PROMPT CALLBACK 81 82 Displays C<PROMPT> on the screen and lets the user enter a line of 83 text, and calls C<CALLBACK>, which must be a perl subroutine 84 reference, with the text the user entered 85 86 =head2 start_password PROMPT CALLBACK 87 88 Like C<start_question>, but echoes the user's input as C<*>s when they 89 input. 90 91 =head2 start_editwin PROMPT CALLBACK 92 93 Like C<start_question>, but displays C<PROMPT> on a line of its own 94 and opens the editwin. If the user cancels the edit win, C<CALLBACK> 95 is not invoked. 96 97 =head2 get_data_dir 98 99 Returns the BarnOwl system data directory, where system libraries and 100 modules are stored 101 102 =head2 get_config_dir 103 104 Returns the BarnOwl user configuration directory, where user modules 105 and configuration are stored (by default, C<$HOME/.owl>) 106 107 =head2 popless_text TEXT 108 109 Show a popup window containing the given C<TEXT> 110 111 =head2 popless_ztext TEXT 112 113 Show a popup window containing the provided zephyr-formatted C<TEXT> 114 115 =head2 error STRING 116 117 Reports an error and log it in `show errors'. Note that in any 118 callback or hook called in perl code from BarnOwl, a C<die> will be 119 caught and passed to C<error>. 120 121 =head2 getnumcolors 122 123 Returns the number of colors this BarnOwl is capable of displaying 124 125 =cut 126 16 127 17 128 BEGIN { … … 46 157 return &BarnOwl::Hooks::_receive_msg($m); 47 158 } 159 160 =head2 AUTOLOAD 161 162 BarnOwl.pm has a C<AUTOLOAD> method that translates unused names in 163 the BarnOwl:: namespace to a call to BarnOwl::command() with that 164 command. Underscores are also translated to C<->s, so you can do 165 e.g. C<BarnOwl::start_command()> and it will be translated into 166 C<start-command>. 167 168 So, if you're looking for functionality that you can't find in the 169 perl interface, check C<:show commands> or C<commands.c> in the 170 BarnOwl source tree -- there's a good chance it exists as a BarnOwl 171 command. 172 173 =head3 BUGS 174 175 There are horrible quoting issues here. The AUTOLOAD simple joins your 176 commands with spaces and passes them unmodified to C<::command> 177 178 =cut 48 179 49 180 # make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo"); … … 63 194 64 195 ARGS should be a hashref containing any or all of C<summary>, 65 C<usage>, or C<description> keys. 196 C<usage>, or C<description> keys: 197 198 =over 4 199 200 =item summary 201 202 A one-line summary of the purpose of the command 203 204 =item usage 205 206 A one-line usage synopsis, showing available options and syntax 207 208 =item description 209 210 A longer description of the syntax and semantics of the command, 211 explaining usage and options 212 213 =back 66 214 67 215 =cut … … 410 558 package BarnOwl::Hook; 411 559 560 =head1 BarnOwl::Hook 561 562 =head1 DESCRIPTION 563 564 A C<BarnOwl::Hook> represents a list of functions to be triggered on 565 some event. C<BarnOwl> exports a default set of these (see 566 C<BarnOwl::Hooks>), but can also be created and used by module code. 567 568 =head2 new 569 570 Creates a new Hook object 571 572 =cut 573 412 574 sub new { 413 575 my $class = shift; 414 576 return bless [], $class; 415 577 } 578 579 =head2 run [ARGS] 580 581 Calls each of the functions registered with this hook with the given 582 arguments. 583 584 =cut 416 585 417 586 sub run { … … 420 589 return map {$_->(@args)} @$self; 421 590 } 591 592 =head2 add SUBREF 593 594 Registers a given subroutine with this hook 595 596 =cut 422 597 423 598 sub add { … … 428 603 } 429 604 605 =head2 clear 606 607 Remove all functions registered with this hook. 608 609 =cut 610 430 611 sub clear { 431 612 my $self = shift; … … 434 615 435 616 package BarnOwl::Hooks; 617 618 =head1 BarnOwl::Hooks 619 620 =head1 DESCRIPTION 621 622 C<BarnOwl::Hooks> exports a set of C<BarnOwl::Hook> objects made 623 available by BarnOwl internally. 624 625 =head2 USAGE 626 627 Modules wishing to respond to events in BarnOwl should register 628 functions with these hooks. 629 630 =head2 EXPORTS 631 632 None by default. Either import the hooks you need explicitly, or refer 633 to them with fully-qualified names. Available hooks are: 634 635 =over 4 636 637 =item $startup 638 639 Called on BarnOwl startup, and whenever modules are 640 reloaded. Functions registered with the C<$startup> hook get a true 641 argument if this is a reload, and false if this is a true startup 642 643 =item $shutdown 644 645 Called before BarnOwl shutdown 646 647 =item $receiveMessage 648 649 Called with a C<BarnOwl::Message> object every time BarnOwl appends a 650 new message to its message list 651 652 =item $mainLoop 653 654 Called on B<every pass> through the C<BarnOwl> main loop. Any 655 functions with this hook should be very cheap, as they are very 656 frequently by the runtime. 657 658 =item $getBuddyList 659 660 Called to display buddy lists for all protocol handlers. The result 661 from every function registered with this hook will be appended and 662 displayed in a popup window, with zephyr formatting parsed. 663 664 =back 665 666 =cut 436 667 437 668 use Exporter; … … 468 699 } 469 700 } 701 702 # These are the internal hooks called by the barnowl C code, which 703 # take care of dispatching to the appropriate perl hooks, and deal 704 # with compatibility by calling the old, fixed-name hooks. 470 705 471 706 sub _startup { -
variable.c
rad15610 rd536e72 455 455 456 456 int owl_variable_dict_setup(owl_vardict *vd) { 457 owl_variable * cur;457 owl_variable *var, *cur; 458 458 if (owl_dict_create(vd)) return(-1); 459 for (cur = variables_to_init; cur->name != NULL; cur++) { 459 for (var = variables_to_init; var->name != NULL; var++) { 460 cur = owl_malloc(sizeof(owl_variable)); 461 memcpy(cur, var, sizeof(owl_variable)); 460 462 switch (cur->type) { 461 463 case OWL_VARIABLE_OTHER: … … 520 522 void owl_variable_dict_add_variable(owl_vardict * vardict, 521 523 owl_variable * var) { 522 owl_dict_insert_element(vardict, var->name, (void*)var, NULL);524 owl_dict_insert_element(vardict, var->name, (void*)var, (void(*)(void*))owl_variable_free); 523 525 } 524 526 … … 532 534 } 533 535 536 void owl_variable_update(owl_variable *var, char *summary, char *desc) { 537 if(var->summary) owl_free(var->summary); 538 var->summary = owl_strdup(summary); 539 if(var->description) owl_free(var->description); 540 var->description = owl_strdup(desc); 541 } 542 534 543 void owl_variable_dict_newvar_string(owl_vardict * vd, char *name, char *summ, char * desc, char * initval) { 535 owl_variable * var = owl_variable_newvar(name, summ, desc); 536 var->type = OWL_VARIABLE_STRING; 537 var->pval_default = owl_strdup(initval); 538 var->set_fn = owl_variable_string_set_default; 539 var->set_fromstring_fn = owl_variable_string_set_fromstring_default; 540 var->get_fn = owl_variable_get_default; 541 var->get_tostring_fn = owl_variable_string_get_tostring_default; 542 var->free_fn = owl_variable_free_default; 543 var->set_fn(var, initval); 544 owl_variable_dict_add_variable(vd, var); 544 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_STRING); 545 if(old) { 546 owl_variable_update(old, summ, desc); 547 if(old->pval_default) owl_free(old->pval_default); 548 old->pval_default = owl_strdup(initval); 549 } else { 550 owl_variable * var = owl_variable_newvar(name, summ, desc); 551 var->type = OWL_VARIABLE_STRING; 552 var->pval_default = owl_strdup(initval); 553 var->set_fn = owl_variable_string_set_default; 554 var->set_fromstring_fn = owl_variable_string_set_fromstring_default; 555 var->get_fn = owl_variable_get_default; 556 var->get_tostring_fn = owl_variable_string_get_tostring_default; 557 var->free_fn = owl_variable_free_default; 558 var->set_fn(var, initval); 559 owl_variable_dict_add_variable(vd, var); 560 } 545 561 } 546 562 547 563 void owl_variable_dict_newvar_int(owl_vardict * vd, char *name, char *summ, char * desc, int initval) { 548 owl_variable * var = owl_variable_newvar(name, summ, desc); 549 var->type = OWL_VARIABLE_INT; 550 var->ival_default = initval; 551 var->validate_fn = owl_variable_int_validate_default; 552 var->set_fn = owl_variable_int_set_default; 553 var->set_fromstring_fn = owl_variable_int_set_fromstring_default; 554 var->get_fn = owl_variable_get_default; 555 var->get_tostring_fn = owl_variable_int_get_tostring_default; 556 var->free_fn = owl_variable_free_default; 557 var->val = owl_malloc(sizeof(int)); 558 var->set_fn(var, &initval); 559 owl_variable_dict_add_variable(vd, var); 564 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_INT); 565 if(old) { 566 owl_variable_update(old, summ, desc); 567 old->ival_default = initval; 568 } else { 569 owl_variable * var = owl_variable_newvar(name, summ, desc); 570 var->type = OWL_VARIABLE_INT; 571 var->ival_default = initval; 572 var->validate_fn = owl_variable_int_validate_default; 573 var->set_fn = owl_variable_int_set_default; 574 var->set_fromstring_fn = owl_variable_int_set_fromstring_default; 575 var->get_fn = owl_variable_get_default; 576 var->get_tostring_fn = owl_variable_int_get_tostring_default; 577 var->free_fn = owl_variable_free_default; 578 var->val = owl_malloc(sizeof(int)); 579 var->set_fn(var, &initval); 580 owl_variable_dict_add_variable(vd, var); 581 } 560 582 } 561 583 562 584 void owl_variable_dict_newvar_bool(owl_vardict * vd, char *name, char *summ, char * desc, int initval) { 563 owl_variable * var = owl_variable_newvar(name, summ, desc); 564 var->type = OWL_VARIABLE_BOOL; 565 var->ival_default = initval; 566 var->validate_fn = owl_variable_bool_validate_default; 567 var->set_fn = owl_variable_bool_set_default; 568 var->set_fromstring_fn = owl_variable_bool_set_fromstring_default; 569 var->get_fn = owl_variable_get_default; 570 var->get_tostring_fn = owl_variable_bool_get_tostring_default; 571 var->free_fn = owl_variable_free_default; 572 var->val = owl_malloc(sizeof(int)); 573 var->set_fn(var, &initval); 574 owl_variable_dict_add_variable(vd, var); 585 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_BOOL); 586 if(old) { 587 owl_variable_update(old, summ, desc); 588 old->ival_default = initval; 589 } else { 590 owl_variable * var = owl_variable_newvar(name, summ, desc); 591 var->type = OWL_VARIABLE_BOOL; 592 var->ival_default = initval; 593 var->validate_fn = owl_variable_bool_validate_default; 594 var->set_fn = owl_variable_bool_set_default; 595 var->set_fromstring_fn = owl_variable_bool_set_fromstring_default; 596 var->get_fn = owl_variable_get_default; 597 var->get_tostring_fn = owl_variable_bool_get_tostring_default; 598 var->free_fn = owl_variable_free_default; 599 var->val = owl_malloc(sizeof(int)); 600 var->set_fn(var, &initval); 601 owl_variable_dict_add_variable(vd, var); 602 } 575 603 } 576 604 … … 590 618 void owl_variable_free(owl_variable *v) { 591 619 if (v->free_fn) v->free_fn(v); 620 owl_free(v); 592 621 } 593 622 … … 687 716 } 688 717 689 /* returns a reference */ 690 void *owl_variable_get(owl_vardict *d, char *name, int require_type) { 718 owl_variable *owl_variable_get_var(owl_vardict *d, char *name, int require_type) { 691 719 owl_variable *v; 692 720 if (!name) return(NULL); 693 721 v = owl_dict_find_element(d, name); 694 722 if (v == NULL || !v->get_fn || v->type != require_type) return(NULL); 723 return v; 724 } 725 726 /* returns a reference */ 727 void *owl_variable_get(owl_vardict *d, char *name, int require_type) { 728 owl_variable *v = owl_variable_get_var(d, name, require_type); 729 if(v == NULL) return NULL; 695 730 return v->get_fn(v); 696 731 } -
zephyr.c
r6201646 ra827529 601 601 } 602 602 } else if (!strcmp(retnotice->z_message, ZSRVACK_NOTSENT)) { 603 if (strcasecmp(retnotice->z_class, "message")) { 604 char buff[1024]; 605 owl_function_error("No one subscribed to class class %s", retnotice->z_class); 606 sprintf(buff, "Could not send message to class %s: no one subscribed.\n", retnotice->z_class); 603 #define BUFFLEN 1024 604 if (retnotice->z_recipient == NULL 605 || *retnotice->z_recipient == NULL 606 || *retnotice->z_recipient == '@') { 607 char buff[BUFFLEN]; 608 owl_function_error("No one subscribed to class %s", retnotice->z_class); 609 snprintf(buff, BUFFLEN, "Could not send message to class %s: no one subscribed.\n", retnotice->z_class); 607 610 owl_function_adminmsg("", buff); 608 611 } else { 609 char buff[ 1024];612 char buff[BUFFLEN]; 610 613 tmp = short_zuser(retnotice->z_recipient); 611 owl_function_error("%s: Not logged in or subscribing to messages.", tmp); 612 sprintf(buff, "Could not send message to %s: not logged in or subscribing to messages.\n", tmp); 614 owl_function_error("%s: Not logged in or subscribing.", tmp); 615 snprintf(buff, BUFFLEN, "Could not send message to %s: not logged in or subscribing to", tmp); 616 if(strcmp(retnotice->z_class, "message")) { 617 snprintf(buff, BUFFLEN, 618 "%s class %s, instance %s.\n", buff, 619 retnotice->z_class, 620 retnotice->z_class_inst); 621 } else { 622 snprintf(buff, BUFFLEN, 623 "%s messages.\n", buff); 624 } 613 625 owl_function_adminmsg("", buff); 614 626 owl_log_outgoing_zephyr_error(tmp, buff); -
Makefile.in
r2bdfed9 rc60ade2 26 26 keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \ 27 27 aim.c buddy.c buddylist.c timer.c style.c stylefunc.c errqueue.c \ 28 zbuddylist.c muxevents.c popexec.c obarray.c 28 zbuddylist.c muxevents.c popexec.c obarray.c wcwidth.c glib_compat.c 29 29 OWL_SRC = owl.c 30 30 TESTER_SRC = tester.c -
aim.c
r9854278 r34509d5 948 948 949 949 if (modname) { 950 if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) {950 if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) { 951 951 /* perror("memrequest: malloc"); */ 952 952 return -1; … … 954 954 sprintf(filename, "%s/%s.ocm", priv->aimbinarypath, modname); 955 955 } else { 956 if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) {956 if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) { 957 957 /* perror("memrequest: malloc"); */ 958 958 return -1; … … 964 964 if (!modname) { 965 965 /* perror("memrequest: stat"); */ 966 free(filename);966 owl_free(filename); 967 967 return -1; 968 968 } … … 986 986 int i; 987 987 988 free(filename); /* not needed */988 owl_free(filename); /* not needed */ 989 989 owl_function_error("getaimdata memrequest: recieved invalid request for 0x%08lx bytes at 0x%08lx (file %s)\n", len, offset, modname); 990 990 i = 8; … … 993 993 } 994 994 995 if (!(buf = malloc(i))) {995 if (!(buf = owl_malloc(i))) { 996 996 return -1; 997 997 } … … 1017 1017 *buflenret = i; 1018 1018 } else { 1019 if (!(buf = malloc(len))) {1020 free(filename);1019 if (!(buf = owl_malloc(len))) { 1020 owl_free(filename); 1021 1021 return -1; 1022 1022 } … … 1024 1024 if (!(f = fopen(filename, "r"))) { 1025 1025 /* perror("memrequest: fopen"); */ 1026 free(filename);1027 free(buf);1026 owl_free(filename); 1027 owl_free(buf); 1028 1028 return -1; 1029 1029 } 1030 1030 1031 free(filename);1031 owl_free(filename); 1032 1032 1033 1033 if (fseek(f, offset, SEEK_SET) == -1) { 1034 1034 /* perror("memrequest: fseek"); */ 1035 1035 fclose(f); 1036 free(buf);1036 owl_free(buf); 1037 1037 return -1; 1038 1038 } … … 1041 1041 /* perror("memrequest: fread"); */ 1042 1042 fclose(f); 1043 free(buf);1043 owl_free(buf); 1044 1044 return -1; 1045 1045 } … … 1076 1076 if (priv->aimbinarypath && (getaimdata(sess, &buf, &buflen, offset, len, modname) == 0)) { 1077 1077 aim_sendmemblock(sess, fr->conn, offset, buflen, buf, AIM_SENDMEMBLOCK_FLAG_ISREQUEST); 1078 free(buf);1078 owl_free(buf); 1079 1079 } else { 1080 1080 owl_function_debugmsg("faimtest_memrequest: unable to use AIM binary (\"%s/%s\"), sending defaults...\n", priv->aimbinarypath, modname); … … 1342 1342 int z; 1343 1343 1344 newbuf = malloc(i+1);1344 newbuf = owl_malloc(i+1); 1345 1345 for (z = 0; z < i; z++) 1346 1346 newbuf[z] = (z % 10)+0x30; 1347 1347 newbuf[i] = '\0'; 1348 1348 /* aim_send_im(sess, userinfo->sn, AIM_IMFLAGS_ACK | AIM_IMFLAGS_AWAY, newbuf); */ 1349 free(newbuf);1349 owl_free(newbuf); 1350 1350 } 1351 1351 } else if (strstr(tmpstr, "seticqstatus")) { -
cmd.c
r6922edd r34509d5 74 74 owl_cmd *cmd; 75 75 76 tmpbuff= strdup(cmdbuff);76 tmpbuff=owl_strdup(cmdbuff); 77 77 argv=owl_parseline(tmpbuff, &argc); 78 78 if (argc < 0) { -
config.h.in
r03cf6b9 re23eb2b 22 22 #undef HAVE_LIBCOM_ERR 23 23 24 /* Define to 1 if you have the `curses' library (-lcurses). */25 #undef HAVE_LIBCURSES26 27 24 /* Define to 1 if you have the `des425' library (-ldes425). */ 28 25 #undef HAVE_LIBDES425 … … 39 36 /* Define to 1 if you have the `krb5' library (-lkrb5). */ 40 37 #undef HAVE_LIBKRB5 41 42 /* Define to 1 if you have the `ncurses' library (-lncurses). */43 #undef HAVE_LIBNCURSES44 38 45 39 /* Define to 1 if you have the `ncursesw' library (-lncursesw). */ -
configure.in
r18e28a4 re23eb2b 12 12 fi 13 13 14 m4_include(/usr/share/aclocal/pkg.m4) 15 dnl m4_include(pkg.m4) 14 16 15 17 dnl Check for Athena … … 44 46 fi 45 47 46 AC_CHECK_LIB(ncursesw, initscr,, 47 AC_CHECK_LIB(ncurses, initscr,, 48 AC_CHECK_LIB(curses, initscr,, AC_MSG_ERROR(No curses library found.)))) 48 AC_CHECK_LIB(ncursesw, initscr,, AC_MSG_ERROR(No curses library found.)) 49 49 AC_CHECK_LIB(com_err, com_err) 50 50 AC_CHECK_LIB(nsl, gethostbyname) … … 109 109 LDFLAGS=${LDFLAGS}\ ${FOO} 110 110 111 dnl Add CFLAGS and LDFLAGS for glib-2.0 112 PKG_CHECK_MODULES(GLIB,glib-2.0) 113 114 echo Adding glib-2.0 CFLAGS ${GLIB_CFLAGS} 115 CFLAGS=${CFLAGS}\ ${GLIB_CFLAGS} 116 echo Adding glib-2.0 LDFLAGS ${GLIB_LIBS} 117 LDFLAGS=${LDFLAGS}\ ${GLIB_LIBS} 118 119 111 120 dnl Checks for typedefs, structures, and compiler characteristics. 112 121 -
editwin.c
r9a6cc40 r830c36e 143 143 e->buffy=0; 144 144 owl_editwin_overwrite_string(e, text); 145 owl_editwin_overwrite_char(e, '\0'); 145 146 e->lock=strlen(text); 146 147 /* if (text[e->lock-1]=='\n') e->lock--; */ 147 e->buffx=x;148 e->buffy=y;148 /* e->buffx=x; */ 149 /* e->buffy=y; */ 149 150 owl_editwin_adjust_for_locktext(e); 150 151 owl_editwin_redisplay(e, 0); … … 251 252 252 253 /* start at topline */ 253 ptr1 =e->buff;254 for (i =0; i<e->topline; i++) {255 ptr2 =strchr(ptr1, '\n');254 ptr1 = e->buff; 255 for (i = 0; i < e->topline; i++) { 256 ptr2 = strchr(ptr1, '\n'); 256 257 if (!ptr2) { 257 258 /* we're already on the last line */ 258 259 break; 259 260 } 260 ptr1 =ptr2+1;261 ptr1 = ptr2 + 1; 261 262 } 262 263 /* ptr1 now stores the starting point */ 263 264 264 265 /* find the ending point and store it in ptr3 */ 265 ptr2 =ptr1;266 ptr3 =ptr1;267 for (i =0; i<e->winlines; i++) {268 ptr3 =strchr(ptr2, '\n');266 ptr2 = ptr1; 267 ptr3 = ptr1; 268 for (i = 0; i < e->winlines; i++) { 269 ptr3 = strchr(ptr2, '\n'); 269 270 if (!ptr3) { 270 271 /* we've hit the last line */ 271 272 /* print everything to the end */ 272 ptr3 =e->buff+e->bufflen-1;273 ptr3 = e->buff + e->bufflen - 1; 273 274 ptr3--; 274 275 break; 275 276 } 276 ptr2 =ptr3+1;277 } 278 ptr3 +=2;279 280 buff =owl_malloc(ptr3-ptr1+50);281 strncpy(buff, ptr1, ptr3 -ptr1);282 buff[ptr3 -ptr1]='\0';283 if (e->echochar =='\0') {277 ptr2 = ptr3 + 1; 278 } 279 ptr3 += 2; 280 281 buff = owl_malloc(ptr3 - ptr1 + 50); 282 strncpy(buff, ptr1, ptr3 - ptr1); 283 buff[ptr3 - ptr1] = '\0'; 284 if (e->echochar == '\0') { 284 285 waddstr(e->curswin, buff); 285 286 } else { 286 287 /* translate to echochar, *except* for the locktext */ 287 288 int len; 288 int dolocklen =e->lock-(ptr1-e->buff);289 290 for (i =0; i<dolocklen; i++) {289 int dolocklen = e->lock - (ptr1 - e->buff); 290 291 for (i = 0; i < dolocklen; i++) { 291 292 waddch(e->curswin, buff[i]); 292 293 } 293 len =strlen(buff);294 for (i =0; i<len-dolocklen; i++) {294 len = strlen(buff); 295 for (i = 0; i < len-dolocklen; i++) { 295 296 waddch(e->curswin, e->echochar); 296 297 } 297 298 } 298 wmove(e->curswin, e->buffy-e->topline, e->buffx );299 wmove(e->curswin, e->buffy-e->topline, e->buffx + _owl_editwin_cursor_adjustment(e)); 299 300 wnoutrefresh(e->curswin); 300 if (update ==1) {301 if (update == 1) { 301 302 doupdate(); 302 303 } 303 304 owl_free(buff); 305 } 306 307 /* Remove n bytes at cursor. */ 308 void _owl_editwin_remove_bytes(owl_editwin *e, int n) /*noproto*/ 309 { 310 int i = _owl_editwin_get_index_from_xy(e) + n; 311 for (; i < e->bufflen; i++) { 312 e->buff[i-n] = e->buff[i]; 313 } 314 315 e->bufflen -= n; 316 e->buff[e->bufflen] = '\0'; 317 } 318 319 /* Insert n bytes at cursor.*/ 320 void _owl_editwin_insert_bytes(owl_editwin *e, int n) /*noproto*/ 321 { 322 int i, z; 323 324 if ((e->bufflen + n) > (e->allocated - 5)) { 325 _owl_editwin_addspace(e); 326 } 327 328 e->bufflen += n; 329 e->buff[e->bufflen] = '\0'; 330 331 z = _owl_editwin_get_index_from_xy(e); 332 for (i = e->bufflen - 1; i > z; i--) { 333 e->buff[i] = e->buff[i - n]; 334 } 304 335 } 305 336 … … 313 344 int i, z; 314 345 315 z =_owl_editwin_get_index_from_xy(e);346 z = _owl_editwin_get_index_from_xy(e); 316 347 /* move back and line wrap the previous word */ 317 for (i =z-1; ; i--) {348 for (i = z - 1; ; i--) { 318 349 /* move back until you find a space or hit the beginning of the line */ 319 if (e->buff[i] ==' ') {350 if (e->buff[i] == ' ') { 320 351 /* replace the space with a newline */ 321 e->buff[i] ='\n';352 e->buff[i] = '\n'; 322 353 e->buffy++; 323 e->buffx =z-i-1;354 e->buffx = z - i - 1; 324 355 /* were we on the last line */ 325 356 return(0); 326 } else if (e->buff[i] =='\n' || i<=e->lock) {327 /* we hit the beg ginning of the line or the buffer, we cannot357 } else if (e->buff[i] == '\n' || i <= e->lock) { 358 /* we hit the beginning of the line or the buffer, we cannot 328 359 * wrap. 329 360 */ … … 336 367 * characters over) 337 368 */ 338 void owl_editwin_insert_char(owl_editwin *e, char c) 339 { 340 341 int z, i, ret; 369 void owl_editwin_insert_char(owl_editwin *e, gunichar c) 370 { 371 int z, i, ret, len; 372 char tmp[6]; 373 memset(tmp, '\0', 6); 342 374 343 375 /* \r is \n */ 344 if (c =='\r') {345 c ='\n';346 } 347 348 if (c =='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {376 if (c == '\r') { 377 c = '\n'; 378 } 379 380 if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) { 349 381 /* perhaps later this will change some state that allows the string 350 382 to be read */ … … 352 384 } 353 385 386 g_unichar_to_utf8(c, tmp); 387 len = strlen(tmp); 388 354 389 /* make sure there is enough memory for the new text */ 355 if ((e->bufflen +1) > (e->allocated-5)) {390 if ((e->bufflen + len) > (e->allocated - 5)) { 356 391 _owl_editwin_addspace(e); 357 392 } 358 393 359 394 /* get the insertion point */ 360 z =_owl_editwin_get_index_from_xy(e);395 z = _owl_editwin_get_index_from_xy(e); 361 396 362 397 /* If we're going to insert at the last column do word wrapping, unless it's a \n */ 363 if ((e->buffx +1==e->wrapcol) && (c!='\n')) {364 ret =_owl_editwin_linewrap_word(e);365 if (ret ==-1) {398 if ((e->buffx + 1 == e->wrapcol) && (c != '\n')) { 399 ret = _owl_editwin_linewrap_word(e); 400 if (ret == -1) { 366 401 /* we couldn't wrap, insert a hard newline instead */ 367 402 owl_editwin_insert_char(e, '\n'); … … 369 404 } 370 405 371 z=_owl_editwin_get_index_from_xy(e);372 406 /* shift all the other characters right */ 373 for (i=e->bufflen; i>z; i--) { 374 e->buff[i]=e->buff[i-1]; 375 } 376 377 /* insert the new one */ 378 e->buff[z]=c; 407 if (z != e->bufflen) { 408 _owl_editwin_insert_bytes(e, len); 409 } 410 411 /* insert the new character */ 412 for(i = 0; i < len; i++) { 413 e->buff[z + i] = tmp[i]; 414 } 379 415 380 416 /* housekeeping */ 381 e->bufflen ++;382 e->buff[e->bufflen] ='\0';383 417 e->bufflen += len; 418 e->buff[e->bufflen] = '\0'; 419 384 420 /* advance the cursor */ 385 if (c=='\n') { 386 e->buffx=0; 387 e->buffy++; 388 } else { 389 e->buffx++; 390 } 421 z += len; 422 _owl_editwin_set_xy_by_index(e, z); 391 423 } 392 424 393 425 /* overwrite the character at the current point with 'c' */ 394 void owl_editwin_overwrite_char(owl_editwin *e, char c) 395 { 396 int z; 397 426 void owl_editwin_overwrite_char(owl_editwin *e, gunichar c) 427 { 428 int z, oldlen, newlen, i; 429 char tmp[6]; 430 memset(tmp, '\0', 6); 431 398 432 /* \r is \n */ 399 if (c =='\r') {400 c ='\n';401 } 402 403 if (c =='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {433 if (c == '\r') { 434 c = '\n'; 435 } 436 437 if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) { 404 438 /* perhaps later this will change some state that allows the string 405 439 to be read */ … … 407 441 } 408 442 409 z=_owl_editwin_get_index_from_xy(e); 410 411 /* only if we are at the end of the buffer do we create new space */ 412 if (z==e->bufflen) { 413 if ((e->bufflen+1) > (e->allocated-5)) { 443 g_unichar_to_utf8(c, tmp); 444 newlen = strlen(tmp); 445 446 z = _owl_editwin_get_index_from_xy(e); 447 { 448 char *t = g_utf8_find_next_char(e->buff + z, NULL); 449 oldlen = (t ? (t - (e->buff + z)) : 0); 450 } 451 452 /* only if we are at the end of the buffer do we create new space here */ 453 if (z == e->bufflen) { 454 if ((e->bufflen+newlen) > (e->allocated-5)) { 414 455 _owl_editwin_addspace(e); 415 456 } 416 457 } 417 418 e->buff[z]=c; 419 420 /* housekeeping if we are at the end of the buffer */ 421 if (z==e->bufflen) { 422 e->bufflen++; 423 e->buff[e->bufflen]='\0'; 424 } 425 458 /* if not at the end of the buffer, adjust based in char size difference. */ 459 else if (oldlen > newlen) { 460 _owl_editwin_remove_bytes(e, oldlen-newlen); 461 } 462 else /* oldlen < newlen */ { 463 _owl_editwin_insert_bytes(e, newlen-oldlen); 464 } 465 /* Overwrite the old char*/ 466 for (i = 0; i < newlen; i++) { 467 e->buff[z+i] = tmp[i]; 468 } 469 470 /* housekeeping */ 471 if (z == e->bufflen) { 472 e->bufflen += newlen; 473 e->buff[e->bufflen] = '\0'; 474 } 475 426 476 /* advance the cursor */ 427 if (c=='\n') { 428 e->buffx=0; 429 e->buffy++; 430 } else { 431 e->buffx++; 432 } 433 477 z += newlen; 478 _owl_editwin_set_xy_by_index(e, z); 434 479 } 435 480 … … 439 484 void owl_editwin_delete_char(owl_editwin *e) 440 485 { 441 int z, i; 442 443 if (e->bufflen==0) return; 486 int z; 487 char *p1, *p2; 488 gunichar c; 489 490 if (e->bufflen == 0) return; 444 491 445 492 /* get the deletion point */ 446 z=_owl_editwin_get_index_from_xy(e); 447 448 if (z==e->bufflen) return; 449 450 for (i=z; i<e->bufflen; i++) { 451 e->buff[i]=e->buff[i+1]; 452 } 453 e->bufflen--; 454 e->buff[e->bufflen]='\0'; 493 z = _owl_editwin_get_index_from_xy(e); 494 495 if (z == e->bufflen) return; 496 497 p1 = e->buff + z; 498 p2 = g_utf8_next_char(p1); 499 c = g_utf8_get_char(p2); 500 while (g_unichar_ismark(c)) { 501 p2 = g_utf8_next_char(p2); 502 c = g_utf8_get_char(p2); 503 } 504 _owl_editwin_remove_bytes(e, p2-p1); 455 505 } 456 506 … … 463 513 { 464 514 int z; 465 char tmp;466 467 if (e->bufflen ==0) return;515 char *p1, *p2, *p3, *tmp; 516 517 if (e->bufflen == 0) return; 468 518 469 519 /* get the cursor point */ 470 z =_owl_editwin_get_index_from_xy(e);471 472 if (z ==e->bufflen) {520 z = _owl_editwin_get_index_from_xy(e); 521 522 if (z == e->bufflen) { 473 523 /* point is after last character */ 474 524 z--; 475 525 } 476 526 477 if (z -1 < e->lock) {527 if (z - 1 < e->lock) { 478 528 /* point is at beginning of buffer, do nothing */ 479 529 return; 480 530 } 481 531 482 tmp=e->buff[z]; 483 e->buff[z]=e->buff[z-1]; 484 e->buff[z-1]=tmp; 485 owl_editwin_key_right(e); 532 /* Transpose two utf-8 unicode glyphs. */ 533 p1 = e->buff + z; 534 535 p2 = g_utf8_find_next_char(p1, NULL); 536 while (p2 != NULL && g_unichar_ismark(g_utf8_get_char(p2))) { 537 p2 = g_utf8_find_next_char(p2, NULL); 538 } 539 if (p2 == NULL) return; 540 541 p3 = g_utf8_find_prev_char(e->buff, p1); 542 while (p3 != NULL && g_unichar_ismark(g_utf8_get_char(p3))) { 543 p3 = g_utf8_find_prev_char(p3, NULL); 544 } 545 if (p3 == NULL) return; 546 547 tmp = owl_malloc(p2 - p3 + 5); 548 *tmp = '\0'; 549 strncat(tmp, p1, p2 - p1); 550 strncat(tmp, p3, p1 - p3); 551 strncpy(p3, tmp, p2 - p3); 552 owl_free(tmp); 553 _owl_editwin_set_xy_by_index(e, p3 - e->buff); 486 554 } 487 555 … … 491 559 void owl_editwin_insert_string(owl_editwin *e, char *string) 492 560 { 493 int i, j; 494 495 j=strlen(string); 496 for (i=0; i<j; i++) { 497 owl_editwin_insert_char(e, string[i]); 561 char *p; 562 gunichar c; 563 if (!g_utf8_validate(string, -1, NULL)) { 564 owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string."); 565 return; 566 } 567 p = string; 568 c = g_utf8_get_char(p); 569 while (c) { 570 owl_editwin_process_char(e, c); 571 p = g_utf8_next_char(p); 572 c = g_utf8_get_char(p); 498 573 } 499 574 } … … 505 580 void owl_editwin_overwrite_string(owl_editwin *e, char *string) 506 581 { 507 int i, j; 508 509 j=strlen(string); 510 for (i=0; i<j; i++) { 511 owl_editwin_overwrite_char(e, string[i]); 582 char *p; 583 gunichar c; 584 585 if (!g_utf8_validate(string, -1, NULL)) { 586 owl_function_debugmsg("owl_editwin_overwrite_string: received non-utf-8 string."); 587 return; 588 } 589 p = string; 590 c = g_utf8_get_char(p); 591 while (c) { 592 owl_editwin_overwrite_char(e, c); 593 p = g_utf8_next_char(p); 594 c = g_utf8_get_char(p); 512 595 } 513 596 } … … 520 603 int i; 521 604 char *ptr1, *ptr2; 522 523 if (e->bufflen==0) return(0); 605 gunichar c; 606 607 if (e->bufflen == 0) return(0); 524 608 525 609 /* first go to the yth line */ 526 ptr1 =e->buff;527 for (i =0; i<e->buffy; i++) {528 ptr2= strchr(ptr1, '\n');610 ptr1 = e->buff; 611 for (i = 0; i < e->buffy; i++) { 612 ptr2= strchr(ptr1, '\n'); 529 613 if (!ptr2) { 530 614 /* we're already on the last line */ 531 615 break; 532 616 } 533 ptr1=ptr2+1; 534 } 535 536 /* now go to the xth character */ 537 ptr2=strchr(ptr1, '\n'); 538 if (!ptr2) { 539 ptr2=e->buff+e->bufflen; 540 } 541 542 if ((ptr2-ptr1) < e->buffx) { 543 ptr1=ptr2-1; 544 } else { 545 ptr1+=e->buffx; 546 } 547 548 /* printf("DEBUG: index is %i\r\n", ptr1-e->buff); */ 549 return(ptr1-e->buff); 617 ptr1 = ptr2 + 1; 618 } 619 620 /* now go to the xth cell */ 621 ptr2 = ptr1; 622 i = 0; 623 while (ptr2 != NULL && i < e->buffx && (ptr2 - e->buff) < e->bufflen) { 624 c = g_utf8_get_char(ptr2); 625 i += (c == '\n' ? 1 : mk_wcwidth(c)); 626 ptr2 = g_utf8_next_char(ptr2); 627 } 628 while(ptr2 != NULL && g_unichar_ismark(g_utf8_get_char(ptr2))) { 629 ptr2 = g_utf8_next_char(ptr2); 630 } 631 if (ptr2 == NULL) return e->bufflen; 632 return(ptr2 - e->buff); 550 633 } 551 634 552 635 void _owl_editwin_set_xy_by_index(owl_editwin *e, int index) 553 636 { 554 int z, i; 555 556 z=_owl_editwin_get_index_from_xy(e); 557 if (index>z) { 558 for (i=0; i<index-z; i++) { 559 owl_editwin_key_right(e); 560 } 561 } else if (index<z) { 562 for (i=0; i<z-index; i++) { 563 owl_editwin_key_left(e); 564 } 565 } 637 char *ptr1, *ptr2, *target; 638 gunichar c; 639 640 e->buffx = 0; 641 e->buffy = 0; 642 643 ptr1 = e->buff; 644 target = ptr1 + index; 645 /* target sanitizing */ 646 if ((target[0] & 0x80) && (~target[0] & 0x40)) { 647 /* middle of a utf-8 character, back up to previous character. */ 648 target = g_utf8_find_prev_char(e->buff, target); 649 } 650 c = g_utf8_get_char(target); 651 while (g_unichar_ismark(c) && target > e->buff) { 652 /* Adjust the target off of combining characters and the like. */ 653 target = g_utf8_find_prev_char(e->buff, target); 654 c = g_utf8_get_char(target); 655 } 656 /* If we start with a mark, something is wrong.*/ 657 if (g_unichar_ismark(c)) return; 658 659 /* Now our target should be acceptable. */ 660 ptr2 = strchr(ptr1, '\n'); 661 while (ptr2 != NULL && ptr2 < target) { 662 e->buffy++; 663 ptr1 = ptr2 + 1; 664 ptr2 = strchr(ptr1, '\n'); 665 } 666 ptr2 = ptr1; 667 while (ptr2 != NULL && ptr2 < target) { 668 c = g_utf8_get_char(ptr2); 669 e->buffx += mk_wcwidth(c); 670 ptr2 = g_utf8_next_char(ptr2); 671 } 672 } 673 674 int _owl_editwin_cursor_adjustment(owl_editwin *e) 675 { 676 char *ptr1, *ptr2; 677 gunichar c; 678 int x, i; 679 680 ptr1 = e->buff; 681 ptr2 = strchr(ptr1, '\n'); 682 for (i = 0; ptr2 != NULL && i < e->buffy; i++) { 683 ptr1 = ptr2 + 1; 684 ptr2 = strchr(ptr1, '\n'); 685 } 686 ptr2 = ptr1; 687 x = 0; 688 while (ptr2 != NULL && x < e->buffx) { 689 if (*ptr2 == '\n') return 0; 690 c = g_utf8_get_char(ptr2); 691 x += mk_wcwidth(c); 692 ptr2 = g_utf8_next_char(ptr2); 693 } 694 return x - e->buffx; 566 695 } 567 696 … … 570 699 /* if we happen to have the cursor over locked text 571 700 * move it to be out of the locktext region */ 572 if (_owl_editwin_get_index_from_xy(e) <e->lock) {701 if (_owl_editwin_get_index_from_xy(e) < e->lock) { 573 702 _owl_editwin_set_xy_by_index(e, e->lock); 574 703 } … … 590 719 { 591 720 if (e->buffy > 0) e->buffy--; 592 if (e->buffx >= owl_editwin_get_numc hars_on_line(e, e->buffy)) {593 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);721 if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) { 722 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 594 723 } 595 724 … … 608 737 609 738 /* if we're past the last character move back */ 610 if (e->buffx >= owl_editwin_get_numc hars_on_line(e, e->buffy)) {611 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);739 if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) { 740 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 612 741 } 613 742 … … 623 752 void owl_editwin_key_left(owl_editwin *e) 624 753 { 625 /* move left if we can, and maybe up a line */ 626 if (e->buffx>0) { 627 e->buffx--; 628 } else if (e->buffy>0) { 629 e->buffy--; 630 e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy); 631 } 632 633 /* do we need to scroll up? */ 634 if (e->buffy-e->topline < 0) { 635 e->topline-=e->winlines/2; 754 int i; 755 char * p; 756 i = _owl_editwin_get_index_from_xy(e); 757 p = e->buff + i; 758 p = g_utf8_find_prev_char(e->buff, p); 759 while (p && g_unichar_ismark(g_utf8_get_char(p))) { 760 p = g_utf8_find_prev_char(e->buff, p); 761 } 762 if (p == NULL) p = e->buff; 763 _owl_editwin_set_xy_by_index(e, p - e->buff); 764 765 if (e->buffy - e->topline < 0) { 766 e->topline -= e->winlines / 2; 636 767 } 637 768 … … 643 774 { 644 775 int i; 645 646 /* move right if we can, and skip down a line if needed */ 647 i=owl_editwin_get_numchars_on_line(e, e->buffy); 648 if (e->buffx < i) { 649 e->buffx++; 650 /* } else if (e->buffy+1 < owl_editwin_get_numlines(e)) { */ 651 } else if (_owl_editwin_get_index_from_xy(e) < e->bufflen) { 652 if (e->style==OWL_EDITWIN_STYLE_MULTILINE) { 653 e->buffx=0; 654 e->buffy++; 655 } 776 char * p; 777 i = _owl_editwin_get_index_from_xy(e); 778 p = e->buff + i; 779 p = g_utf8_find_next_char(p, NULL); 780 while (p && g_unichar_ismark(g_utf8_get_char(p))) { 781 p = g_utf8_find_next_char(p, NULL); 782 } 783 if (p == NULL) { 784 _owl_editwin_set_xy_by_index(e, e->bufflen); 785 } 786 else { 787 _owl_editwin_set_xy_by_index(e, p - e->buff); 656 788 } 657 789 658 790 /* do we need to scroll down? */ 659 if (e->buffy -e->topline >= e->winlines) {660 e->topline +=e->winlines/2;791 if (e->buffy - e->topline >= e->winlines) { 792 e->topline += e->winlines / 2; 661 793 } 662 794 } … … 664 796 void owl_editwin_move_to_nextword(owl_editwin *e) 665 797 { 798 /* asedeno: needs fixing for utf-8*/ 666 799 int i, x; 667 800 … … 703 836 void owl_editwin_move_to_previousword(owl_editwin *e) 704 837 { 838 /* asedeno: needs fixing for utf-8*/ 705 839 int i, x; 706 840 … … 738 872 void owl_editwin_delete_nextword(owl_editwin *e) 739 873 { 874 /* asedeno: needs fixing for utf-8*/ 740 875 int z; 741 876 … … 768 903 void owl_editwin_delete_previousword(owl_editwin *e) 769 904 { 905 /* asedeno: needs fixing for utf-8*/ 770 906 /* go backwards to the last non-space character, then delete chars */ 771 907 int i, startpos, endpos; … … 781 917 void owl_editwin_delete_to_endofline(owl_editwin *e) 782 918 { 919 /* asedeno: needs fixing for utf-8*/ 783 920 int i; 784 921 785 if (owl_editwin_get_numchars_on_line(e, e->buffy) >e->buffx) {922 if (owl_editwin_get_numchars_on_line(e, e->buffy) > e->buffx) { 786 923 /* normal line */ 787 924 i=_owl_editwin_get_index_from_xy(e); … … 804 941 void owl_editwin_move_to_line_end(owl_editwin *e) 805 942 { 806 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);943 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 807 944 } 808 945 … … 817 954 /* go to last char */ 818 955 e->buffy=owl_editwin_get_numlines(e)-1; 819 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);956 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 820 957 owl_editwin_key_right(e); 821 958 … … 841 978 void owl_editwin_fill_paragraph(owl_editwin *e) 842 979 { 980 /* asedeno: needs fixing for utf-8*/ 843 981 int i, save; 844 982 … … 857 995 /* main loop */ 858 996 while (1) { 859 i =_owl_editwin_get_index_from_xy(e);997 i = _owl_editwin_get_index_from_xy(e); 860 998 861 999 /* bail if we hit the end of the buffer */ 862 if (i >=e->bufflen) break;1000 if (i >= e->bufflen || e->buff[i] == '\0') break; 863 1001 864 1002 /* bail if we hit the end of the paragraph */ 865 if (e->buff[i] =='\n' && e->buff[i+1]=='\n') break;1003 if (e->buff[i] == '\n' && e->buff[i+1] == '\n') break; 866 1004 867 1005 /* if we've travelled too far, linewrap */ … … 871 1009 872 1010 /* did we hit the end of a line too soon? */ 873 i =_owl_editwin_get_index_from_xy(e);874 if (e->buff[i] =='\n' && e->buffx<e->fillcol-1) {1011 i = _owl_editwin_get_index_from_xy(e); 1012 if (e->buff[i] == '\n' && e->buffx < e->fillcol - 1) { 875 1013 /* ********* we need to make sure we don't pull in a word that's too long ***********/ 876 1014 e->buff[i]=' '; … … 878 1016 879 1017 /* fix spacing */ 880 i =_owl_editwin_get_index_from_xy(e);881 if (e->buff[i] ==' ' && e->buff[i+1]==' ') {882 if (e->buff[i-1] =='.' || e->buff[i-1]=='!' || e->buff[i-1]=='?') {1018 i = _owl_editwin_get_index_from_xy(e); 1019 if (e->buff[i] == ' ' && e->buff[i+1] == ' ') { 1020 if (e->buff[i-1] == '.' || e->buff[i-1] == '!' || e->buff[i-1] == '?') { 883 1021 owl_editwin_key_right(e); 884 1022 } else { 885 1023 owl_editwin_delete_char(e); 886 1024 /* if we did this ahead of the save point, adjust it */ 887 if (i <save) save--;1025 if (i < save) save--; 888 1026 } 889 1027 } else { … … 911 1049 int owl_editwin_check_dotsend(owl_editwin *e) 912 1050 { 913 int i; 1051 char *p, *p_n, *p_p; 1052 gunichar c; 914 1053 915 1054 if (!e->dotsend) return(0); 916 for (i=e->bufflen-1; i>0; i--) { 917 if (e->buff[i] == '.' 918 && (e->buff[i-1] == '\n' || e->buff[i-1] == '\r') 919 && (e->buff[i+1] == '\n' || e->buff[i+1] == '\r')) { 920 e->bufflen = i; 921 e->buff[i] = '\0'; 1055 1056 p = g_utf8_find_prev_char(e->buff, e->buff + e->bufflen); 1057 p_n = g_utf8_find_next_char(p, NULL); 1058 p_p = g_utf8_find_prev_char(e->buff, p); 1059 c = g_utf8_get_char(p); 1060 while (p != NULL) { 1061 if (*p == '.' 1062 && p_p != NULL && (*p_p == '\n' || *p_p == '\r') 1063 && p_n != NULL && (*p_n == '\n' || *p_n == '\r')) { 1064 e->bufflen = p - e->buff; 1065 e->buff[e->bufflen] = '\0'; 922 1066 return(1); 923 1067 } 924 if (!isspace((int) e->buff[i])) { 925 return(0); 926 } 1068 if (c != '\0' && !g_unichar_isspace(c)) return(0); 1069 p_n = p; 1070 p = p_p; 1071 c = g_utf8_get_char(p); 1072 p_p = g_utf8_find_prev_char(e->buff, p); 927 1073 } 928 1074 return(0); 929 1075 } 930 1076 931 void owl_editwin_post_process_char(owl_editwin *e, intj)1077 void owl_editwin_post_process_char(owl_editwin *e, gunichar j) 932 1078 { 933 1079 /* check if we need to scroll down */ … … 942 1088 } 943 1089 944 void owl_editwin_process_char(owl_editwin *e, intj)1090 void owl_editwin_process_char(owl_editwin *e, gunichar j) 945 1091 { 946 1092 if (j == ERR) return; 947 if ( j>127 || ((j<32) && (j!=10) && (j!=13))) {1093 if (g_unichar_iscntrl(j) && (j != 10) && (j != 13)) { 948 1094 return; 949 } else { 1095 } 1096 else { 950 1097 owl_editwin_insert_char(e, j); 951 1098 } … … 975 1122 } 976 1123 977 /* now go to the xth character */ 978 ptr2=strchr(ptr1, '\n'); 979 if (!ptr2) { 980 return(e->buff + e->bufflen - ptr1); 981 } 982 return(ptr2-ptr1); /* don't count the newline for now */ 1124 /* now count characters */ 1125 i = 0; 1126 ptr2 = ptr1; 1127 while (ptr2 - e->buff < e->bufflen 1128 && *ptr2 != '\n') { 1129 ++i; 1130 ptr2 = g_utf8_next_char(ptr2); 1131 } 1132 return i; 1133 } 1134 1135 int owl_editwin_get_numcells_on_line(owl_editwin *e, int line) 1136 { 1137 int i; 1138 char *ptr1, *ptr2; 1139 gunichar c; 1140 1141 if (e->bufflen==0) return(0); 1142 1143 /* first go to the yth line */ 1144 ptr1=e->buff; 1145 for (i=0; i<line; i++) { 1146 ptr2=strchr(ptr1, '\n'); 1147 if (!ptr2) { 1148 /* we're already on the last line */ 1149 return(0); 1150 } 1151 ptr1=ptr2+1; 1152 } 1153 1154 /* now count cells */ 1155 i = 0; 1156 ptr2 = ptr1; 1157 while (ptr2 - e->buff < e->bufflen 1158 && *ptr2 != '\n') { 1159 c = g_utf8_get_char(ptr2); 1160 i += mk_wcwidth(c); 1161 ptr2 = g_utf8_next_char(ptr2); 1162 } 1163 return i; 983 1164 } 984 1165 -
fmtext.c
rfa3290d r16c6cca 8 8 void owl_fmtext_init_null(owl_fmtext *f) 9 9 { 10 f->textlen=0; 11 f->bufflen=5; 12 f->textbuff=owl_malloc(5); 13 f->fmbuff=owl_malloc(5); 14 f->fgcolorbuff=owl_malloc(5 * sizeof(short)); 15 f->bgcolorbuff=owl_malloc(5 * sizeof(short)); 16 f->textbuff[0]=0; 17 f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE; 18 f->fgcolorbuff[0]=OWL_COLOR_DEFAULT; 19 f->bgcolorbuff[0]=OWL_COLOR_DEFAULT; 10 f->textlen = 0; 11 f->bufflen = 5; 12 f->textbuff = owl_malloc(5); 13 f->textbuff[0] = 0; 14 f->default_attrs = OWL_FMTEXT_ATTR_NONE; 15 f->default_fgcolor = OWL_COLOR_DEFAULT; 16 f->default_fgcolor = OWL_COLOR_DEFAULT; 20 17 } 21 18 … … 24 21 void owl_fmtext_clear(owl_fmtext *f) 25 22 { 26 f->textlen = 0; 27 f->textbuff[0] = 0; 28 f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE; 29 f->fgcolorbuff[0]=OWL_COLOR_DEFAULT; 30 f->bgcolorbuff[0]=OWL_COLOR_DEFAULT; 31 } 32 33 /* Internal function. Set the attribute 'attr' from index 'first' to 34 * index 'last' 35 */ 36 void _owl_fmtext_set_attr(owl_fmtext *f, int attr, int first, int last) 37 { 38 int i; 39 for (i=first; i<=last; i++) { 40 f->fmbuff[i]=(unsigned char) attr; 41 } 42 } 43 44 /* Internal function. Add the attribute 'attr' to the existing 45 * attributes from index 'first' to index 'last' 46 */ 47 void _owl_fmtext_add_attr(owl_fmtext *f, int attr, int first, int last) 48 { 49 int i; 50 for (i=first; i<=last; i++) { 51 f->fmbuff[i]|=(unsigned char) attr; 52 } 53 } 54 55 /* Internal function. Set the color to be 'color' from index 'first' 56 * to index 'last 57 */ 58 void _owl_fmtext_set_fgcolor(owl_fmtext *f, int color, int first, int last) 59 { 60 int i; 61 for (i=first; i<=last; i++) { 62 f->fgcolorbuff[i]=(short)color; 63 } 64 } 65 66 void _owl_fmtext_set_bgcolor(owl_fmtext *f, int color, int first, int last) 67 { 68 int i; 69 for (i=first; i<=last; i++) { 70 f->bgcolorbuff[i]=(short)color; 71 } 23 f->textlen = 0; 24 f->textbuff[0] = 0; 25 f->default_attrs = OWL_FMTEXT_ATTR_NONE; 26 f->default_fgcolor = OWL_COLOR_DEFAULT; 27 f->default_fgcolor = OWL_COLOR_DEFAULT; 72 28 } 73 29 … … 75 31 { 76 32 if(newlen + 1 > f->bufflen) { 77 f->textbuff=owl_realloc(f->textbuff, newlen+1); 78 f->fmbuff=owl_realloc(f->fmbuff, newlen+1); 79 f->fgcolorbuff=owl_realloc(f->fgcolorbuff, (newlen+1) * sizeof(short)); 80 f->bgcolorbuff=owl_realloc(f->bgcolorbuff, (newlen+1) * sizeof(short)); 33 f->textbuff = owl_realloc(f->textbuff, newlen + 1); 81 34 f->bufflen = newlen+1; 82 35 } 83 36 } 84 37 38 int _owl_fmtext_is_format_char(gunichar c) /*noproto*/ 39 { 40 if ((c & ~OWL_FMTEXT_UC_ATTR_MASK) == OWL_FMTEXT_UC_ATTR) return 1; 41 if ((c & ~(OWL_FMTEXT_UC_ALLCOLOR_MASK)) == OWL_FMTEXT_UC_COLOR_BASE) return 1; 42 return 0; 43 } 85 44 /* append text to the end of 'f' with attribute 'attr' and color 86 45 * 'color' 87 46 */ 88 void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int fgcolor, int bgcolor) 89 { 90 int newlen; 91 newlen=strlen(f->textbuff)+strlen(text); 47 void owl_fmtext_append_attr(owl_fmtext *f, char *text, char attr, short fgcolor, short bgcolor) 48 { 49 char attrbuff[6]; 50 int newlen, a = 0, fg = 0, bg = 0; 51 52 if (attr != OWL_FMTEXT_ATTR_NONE) a=1; 53 if (fgcolor != OWL_COLOR_DEFAULT) fg=1; 54 if (bgcolor != OWL_COLOR_DEFAULT) bg=1; 55 56 /* Plane-16 characters in UTF-8 are 4 bytes long. */ 57 newlen = strlen(f->textbuff) + strlen(text) + (8 * (a + fg + bg)); 92 58 _owl_fmtext_realloc(f, newlen); 59 60 /* Set attributes */ 61 if (a) { 62 memset(attrbuff,0,6); 63 g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff); 64 strcat(f->textbuff, attrbuff); 65 } 66 if (fg) { 67 memset(attrbuff,0,6); 68 g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff); 69 strcat(f->textbuff, attrbuff); 70 } 71 if (bg) { 72 memset(attrbuff,0,6); 73 g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff); 74 strcat(f->textbuff, attrbuff); 75 } 93 76 94 77 strcat(f->textbuff, text); 95 _owl_fmtext_set_attr(f, attr, f->textlen, newlen); 96 _owl_fmtext_set_fgcolor(f, fgcolor, f->textlen, newlen); 97 _owl_fmtext_set_bgcolor(f, bgcolor, f->textlen, newlen); 78 79 /* Reset attributes */ 80 if (bg) strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT); 81 if (fg) strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT); 82 if (a) strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE); 98 83 f->textlen=newlen; 99 84 } … … 129 114 } 130 115 131 /* Add the attribute 'attr' to alltext in 'f' */132 void owl_fmtext_addattr(owl_fmtext *f, intattr)116 /* Add the attribute 'attr' to the default atts for the text in 'f' */ 117 void owl_fmtext_addattr(owl_fmtext *f, char attr) 133 118 { 134 119 /* add the attribute to all text */ 135 int i, j; 136 137 j=f->textlen; 138 for (i=0; i<j; i++) { 139 f->fmbuff[i] |= attr; 140 } 141 } 142 143 /* Anywhere the color is NOT ALREDY SET, set the color to 'color'. 144 * Other colors are left unchanged 120 f->default_attrs |= attr; 121 } 122 123 /* Set the default foreground color for this fmtext to 'color'. 124 * Only affects text that is colored default. 145 125 */ 146 126 void owl_fmtext_colorize(owl_fmtext *f, int color) 147 127 { 148 /* everywhere the fgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */ 149 int i, j; 150 151 j=f->textlen; 152 for(i=0; i<j; i++) { 153 if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = (short)color; 154 } 155 } 156 128 f->default_fgcolor = color; 129 } 130 131 /* Set the default foreground color for this fmtext to 'color'. 132 * Only affects text that is colored default. 133 */ 157 134 void owl_fmtext_colorizebg(owl_fmtext *f, int color) 158 135 { 159 /* everywhere the bgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */ 160 int i, j; 161 162 j=f->textlen; 163 for(i=0; i<j; i++) { 164 if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = (short)color; 165 } 166 } 136 f->default_bgcolor = color; 137 } 138 139 /* Internal function. Parse attrbute character. */ 140 void _owl_fmtext_update_attributes(gunichar c, char *attr, short *fgcolor, short *bgcolor) /*noproto*/ 141 { 142 if ((c & OWL_FMTEXT_UC_ATTR) == OWL_FMTEXT_UC_ATTR) { 143 *attr = c & OWL_FMTEXT_UC_ATTR_MASK; 144 } 145 else if ((c & OWL_FMTEXT_UC_FGCOLOR) == OWL_FMTEXT_UC_FGCOLOR) { 146 *fgcolor = (c == OWL_FMTEXT_UC_FGDEFAULT 147 ? OWL_COLOR_DEFAULT 148 : c & OWL_FMTEXT_UC_COLOR_MASK); 149 } 150 else if ((c & OWL_FMTEXT_UC_BGCOLOR) == OWL_FMTEXT_UC_BGCOLOR) { 151 *bgcolor = (c == OWL_FMTEXT_UC_BGDEFAULT 152 ? OWL_COLOR_DEFAULT 153 : c & OWL_FMTEXT_UC_COLOR_MASK); 154 } 155 } 156 157 /* Internal function. Scan for attribute characters. */ 158 void _owl_fmtext_scan_attributes(owl_fmtext *f, int start, char *attr, short *fgcolor, short *bgcolor) /*noproto*/ 159 { 160 char *p; 161 p = strchr(f->textbuff, OWL_FMTEXT_UC_STARTBYTE_UTF8); 162 while (p && p < f->textbuff + start) { 163 _owl_fmtext_update_attributes(g_utf8_get_char(p), attr, fgcolor, bgcolor); 164 p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8); 165 } 166 } 167 167 168 168 /* Internal function. Append text from 'in' between index 'start' and 169 169 * 'stop' to the end of 'f' 170 170 */ 171 void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) 172 { 173 int newlen, i; 174 175 newlen=strlen(f->textbuff)+(stop-start+1); 171 void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) /*noproto*/ 172 { 173 char attrbuff[6]; 174 int newlen, a = 0, fg = 0, bg = 0; 175 char attr = 0; 176 short fgcolor = OWL_COLOR_DEFAULT; 177 short bgcolor = OWL_COLOR_DEFAULT; 178 179 _owl_fmtext_scan_attributes(in, start, &attr, &fgcolor, &bgcolor); 180 if (attr != OWL_FMTEXT_ATTR_NONE) a=1; 181 if (fgcolor != OWL_COLOR_DEFAULT) fg=1; 182 if (bgcolor != OWL_COLOR_DEFAULT) bg=1; 183 184 /* We will reset to defaults after appending the text. We may need 185 to set initial attributes. */ 186 newlen=strlen(f->textbuff)+(stop-start+1) + (4 * (a + fg + bg)) + 12; 176 187 _owl_fmtext_realloc(f, newlen); 177 188 189 if (a) { 190 memset(attrbuff,0,6); 191 g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff); 192 strcat(f->textbuff, attrbuff); 193 } 194 if (fg) { 195 memset(attrbuff,0,6); 196 g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff); 197 strcat(f->textbuff, attrbuff); 198 } 199 if (bg) { 200 memset(attrbuff,0,6); 201 g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff); 202 strcat(f->textbuff, attrbuff); 203 } 204 178 205 strncat(f->textbuff, in->textbuff+start, stop-start+1); 206 207 /* Reset attributes */ 208 strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT); 209 strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT); 210 strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE); 211 179 212 f->textbuff[newlen]='\0'; 180 for (i=start; i<=stop; i++) {181 f->fmbuff[f->textlen+(i-start)]=in->fmbuff[i];182 f->fgcolorbuff[f->textlen+(i-start)]=in->fgcolorbuff[i];183 f->bgcolorbuff[f->textlen+(i-start)]=in->bgcolorbuff[i];184 }185 213 f->textlen=newlen; 186 214 } … … 207 235 char *owl_fmtext_print_plain(owl_fmtext *f) 208 236 { 209 return(owl_strdup(f->textbuff)); 237 return owl_strip_format_chars(f->textbuff); 238 } 239 240 void _owl_fmtext_wattrset(WINDOW *w, int attrs) /*noproto*/ 241 { 242 wattrset(w, A_NORMAL); 243 if (attrs & OWL_FMTEXT_ATTR_BOLD) wattron(w, A_BOLD); 244 if (attrs & OWL_FMTEXT_ATTR_REVERSE) wattron(w, A_REVERSE); 245 if (attrs & OWL_FMTEXT_ATTR_UNDERLINE) wattron(w, A_UNDERLINE); 246 } 247 248 void _owl_fmtext_update_colorpair(short fg, short bg, short *pair) /*noproto*/ 249 { 250 if (owl_global_get_hascolors(&g)) { 251 *pair = owl_fmtext_get_colorpair(fg, bg); 252 } 253 } 254 255 void _owl_fmtext_wcolor_set(WINDOW *w, short pair) /*noproto*/ 256 { 257 if (owl_global_get_hascolors(&g)) { 258 wcolor_set(w,pair,NULL); 259 } 210 260 } 211 261 … … 213 263 * must already be initiatlized with curses 214 264 */ 215 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w) 216 { 217 char *tmpbuff; 218 int position, trans1, trans2, trans3, len, lastsame; 219 265 void _owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search) /*noproto*/ 266 { 267 /* char *tmpbuff; */ 268 /* int position, trans1, trans2, trans3, len, lastsame; */ 269 char *s, *p; 270 char attr; 271 short fg, bg, pair; 272 int search_results, search_len; 273 220 274 if (w==NULL) { 221 275 owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr."); … … 223 277 } 224 278 225 tmpbuff=owl_malloc(f->textlen+10); 226 227 position=0; 228 len=f->textlen; 229 while (position<=len) { 230 /* find the last char with the current format and color */ 231 trans1=owl_util_find_trans(f->fmbuff+position, len-position); 232 trans2=owl_util_find_trans_short(f->fgcolorbuff+position, len-position); 233 trans3=owl_util_find_trans_short(f->bgcolorbuff+position, len-position); 234 235 lastsame = (trans1 < trans2) ? trans1 : trans2; 236 lastsame = (lastsame < trans3) ? lastsame : trans3; 237 lastsame += position; 238 239 /* set the format */ 240 wattrset(w, A_NORMAL); 241 if (f->fmbuff[position] & OWL_FMTEXT_ATTR_BOLD) { 242 wattron(w, A_BOLD); 243 } 244 if (f->fmbuff[position] & OWL_FMTEXT_ATTR_REVERSE) { 245 wattron(w, A_REVERSE); 246 } 247 if (f->fmbuff[position] & OWL_FMTEXT_ATTR_UNDERLINE) { 248 wattron(w, A_UNDERLINE); 249 } 250 251 /* set the color */ 252 /* warning, this is sort of a hack */ 253 if (owl_global_get_hascolors(&g)) { 254 short fg, bg, pair; 255 fg = f->fgcolorbuff[position]; 256 bg = f->bgcolorbuff[position]; 257 258 pair = owl_fmtext_get_colorpair(fg, bg); 259 if (pair != -1) { 260 wcolor_set(w,pair,NULL); 261 } 262 } 263 264 /* add the text */ 265 strncpy(tmpbuff, f->textbuff + position, lastsame-position+1); 266 tmpbuff[lastsame-position+1]='\0'; 267 waddstr(w, tmpbuff); 268 269 position=lastsame+1; 270 } 271 owl_free(tmpbuff); 272 } 273 279 search_results = (do_search 280 ? owl_fmtext_search(f, owl_global_get_search_string(&g)) 281 : 0); 282 search_len = (search_results 283 ? strlen(owl_global_get_search_string(&g)) 284 : 0); 285 s = f->textbuff; 286 /* Set default attributes. */ 287 attr = f->default_attrs; 288 fg = f->default_fgcolor; 289 bg = f->default_bgcolor; 290 _owl_fmtext_wattrset(w, attr); 291 _owl_fmtext_update_colorpair(fg, bg, &pair); 292 _owl_fmtext_wcolor_set(w, pair); 293 294 /* Find next possible format character. */ 295 p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8); 296 while(p) { 297 if (_owl_fmtext_is_format_char(g_utf8_get_char(p))) { 298 /* Deal with all text from last insert to here. */ 299 char tmp; 300 301 tmp = p[0]; 302 p[0] = '\0'; 303 if (search_results) { 304 /* Search is active, so highlight search results. */ 305 char tmp2, *ss; 306 ss = stristr(s, owl_global_get_search_string(&g)); 307 while (ss) { 308 /* Found search string, highlight it. */ 309 310 tmp2 = ss[0]; 311 ss[0] = '\0'; 312 waddstr(w, s); 313 ss[0] = tmp2; 314 315 _owl_fmtext_wattrset(w, attr ^ OWL_FMTEXT_ATTR_REVERSE); 316 _owl_fmtext_wcolor_set(w, pair); 317 318 tmp2 = ss[search_len]; 319 ss[search_len] = '\0'; 320 waddstr(w, ss); 321 ss[search_len] = tmp2; 322 323 _owl_fmtext_wattrset(w, attr); 324 _owl_fmtext_wcolor_set(w, pair); 325 326 s = ss + search_len; 327 ss = stristr(s, owl_global_get_search_string(&g)); 328 } 329 } 330 /* Deal with remaining part of string. */ 331 waddstr(w, s); 332 p[0] = tmp; 333 334 /* Deal with new attributes. Initialize to defaults, then 335 process all consecutive formatting characters. */ 336 attr = f->default_attrs; 337 fg = f->default_fgcolor; 338 bg = f->default_bgcolor; 339 while (p && _owl_fmtext_is_format_char(g_utf8_get_char(p))) { 340 _owl_fmtext_update_attributes(g_utf8_get_char(p), &attr, &fg, &bg); 341 p = g_utf8_next_char(p); 342 } 343 _owl_fmtext_wattrset(w, attr | f->default_attrs); 344 if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor; 345 if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor; 346 _owl_fmtext_update_colorpair(fg, bg, &pair); 347 _owl_fmtext_wcolor_set(w, pair); 348 349 /* Advance to next non-formatting character. */ 350 s = p; 351 p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8); 352 } 353 else { 354 p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8); 355 } 356 } 357 if (s) { 358 waddstr(w, s); 359 } 360 } 361 362 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w) 363 { 364 _owl_fmtext_curs_waddstr(f, w, owl_global_is_search_active(&g)); 365 } 366 367 void owl_fmtext_curs_waddstr_without_search(owl_fmtext *f, WINDOW *w) 368 { 369 _owl_fmtext_curs_waddstr(f, w, 0); 370 } 274 371 275 372 /* start with line 'aline' (where the first line is 0) and print … … 282 379 283 380 /* find the starting line */ 284 ptr1=in->textbuff; 285 if (aline!=0) { 286 for (i=0; i<aline; i++) { 287 ptr1=strchr(ptr1, '\n'); 288 if (!ptr1) return(-1); 289 ptr1++; 290 } 291 } 381 ptr1 = in->textbuff; 382 for (i = 0; i < aline; i++) { 383 ptr1 = strchr(ptr1, '\n'); 384 if (!ptr1) return(-1); 385 ptr1++; 386 } 387 292 388 /* ptr1 now holds the starting point */ 293 389 294 390 /* copy in the next 'lines' lines */ 295 if (lines <1) return(-1);296 297 for (i =0; i<lines; i++) {298 offset =ptr1-in->textbuff;299 ptr2 =strchr(ptr1, '\n');391 if (lines < 1) return(-1); 392 393 for (i = 0; i < lines; i++) { 394 offset = ptr1 - in->textbuff; 395 ptr2 = strchr(ptr1, '\n'); 300 396 if (!ptr2) { 301 _owl_fmtext_append_fmtext(out, in, offset, (in->textlen) -1);397 _owl_fmtext_append_fmtext(out, in, offset, (in->textlen) - 1); 302 398 return(-1); 303 399 } 304 _owl_fmtext_append_fmtext(out, in, offset, (ptr2 -ptr1)+offset);305 ptr1 =ptr2+1;400 _owl_fmtext_append_fmtext(out, in, offset, (ptr2 - ptr1) + offset); 401 ptr1 = ptr2 + 1; 306 402 } 307 403 return(0); … … 311 407 * ends at 'bcol' or sooner. The first column is number 0. The new 312 408 * message is placed in 'out'. The message is * expected to end in a 313 * new line for now 409 * new line for now. NOTE: This needs to be modified to deal with 410 * backing up if we find a SPACING COMBINING MARK at the end of a 411 * line. If that happens, we should back up to the last non-mark 412 * character and stop there. 314 413 */ 315 414 void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out) 316 415 { 317 char *ptr 1, *ptr2, *last;318 int len, offset;416 char *ptr_s, *ptr_e, *ptr_c, *last; 417 int col, st, padding, chwidth; 319 418 320 419 last=in->textbuff+in->textlen-1; 321 ptr 1=in->textbuff;322 while (ptr 1<=last) {323 ptr 2=strchr(ptr1, '\n');324 if (!ptr 2) {420 ptr_s=in->textbuff; 421 while (ptr_s <= last) { 422 ptr_e=strchr(ptr_s, '\n'); 423 if (!ptr_e) { 325 424 /* but this shouldn't happen if we end in a \n */ 326 425 break; 327 426 } 328 427 329 if (ptr 2==ptr1) {428 if (ptr_e == ptr_s) { 330 429 owl_fmtext_append_normal(out, "\n"); 331 ptr1++;430 ++ptr_s; 332 431 continue; 333 432 } 334 433 335 /* we need to check that we won't run over here */ 336 len=bcol-acol; 337 if (len > (ptr2-(ptr1+acol))) { 338 /* the whole line fits with room to spare, don't take a full 'len' */ 339 len=ptr2-(ptr1+acol); 340 } 341 if (len>last-ptr1) { 342 /* the whole rest of the text fits with room to spare, adjust for it */ 343 len-=(last-ptr1); 344 } 345 if (len<=0) { 346 /* saftey check */ 434 col = 0; 435 st = 0; 436 padding = 0; 437 chwidth = 0; 438 ptr_c = ptr_s; 439 while(ptr_c < ptr_e) { 440 gunichar c = g_utf8_get_char(ptr_c); 441 if (!_owl_fmtext_is_format_char(c)) { 442 chwidth = mk_wcwidth(c); 443 if (col + chwidth > bcol) break; 444 445 if (col >= acol) { 446 if (st == 0) { 447 ptr_s = ptr_c; 448 padding = col - acol; 449 ++st; 450 } 451 } 452 col += chwidth; 453 chwidth = 0; 454 } 455 ptr_c = g_utf8_next_char(ptr_c); 456 } 457 if (st) { 458 /* lead padding */ 459 owl_fmtext_append_spaces(out, padding); 460 if (ptr_c == ptr_e) { 461 /* We made it to the newline. */ 462 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff); 463 } 464 else { 465 if (chwidth > 1) { 466 /* Last char is wide, truncate. */ 467 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1); 468 owl_fmtext_append_normal(out, "\n"); 469 } 470 else { 471 /* Last char fits perfectly, leave alone.*/ 472 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff); 473 } 474 } 475 } 476 else { 347 477 owl_fmtext_append_normal(out, "\n"); 348 ptr1=ptr2+1; 349 continue; 350 } 351 352 offset=ptr1-in->textbuff; 353 _owl_fmtext_append_fmtext(out, in, offset+acol, offset+acol+len); 354 355 ptr1=ptr2+1; 478 } 479 ptr_s = g_utf8_next_char(ptr_e); 356 480 } 357 481 } … … 381 505 382 506 /* set the charater at 'index' to be 'char'. If index is out of 383 * bounds don't do anything */ 384 void owl_fmtext_set_char(owl_fmtext *f, int index, int ch) 507 * bounds don't do anything. If c or char at index is not ASCII, don't 508 * do anything because it's not UTF-8 safe. */ 509 void owl_fmtext_set_char(owl_fmtext *f, int index, char ch) 385 510 { 386 511 if ((index < 0) || (index > f->textlen-1)) return; 512 /* NOT ASCII*/ 513 if (f->textbuff[index] & 0x80 || ch & 0x80) return; 387 514 f->textbuff[index]=ch; 388 515 } … … 400 527 dst->textlen=src->textlen; 401 528 dst->textbuff=owl_malloc(mallocsize); 402 dst->fmbuff=owl_malloc(mallocsize);403 dst->fgcolorbuff=owl_malloc(mallocsize * sizeof(short));404 dst->bgcolorbuff=owl_malloc(mallocsize * sizeof(short));405 529 memcpy(dst->textbuff, src->textbuff, src->textlen+1); 406 memcpy(dst->fmbuff, src->fmbuff, src->textlen); 407 memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen * sizeof(short)); 408 memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen * sizeof(short)); 409 } 410 411 /* highlight all instances of "string". Return the number of 412 * instances found. This is a case insensitive search. 413 */ 414 int owl_fmtext_search_and_highlight(owl_fmtext *f, char *string) 415 { 416 417 int found, len; 418 char *ptr1, *ptr2; 419 420 len=strlen(string); 421 found=0; 422 ptr1=f->textbuff; 423 while (ptr1-f->textbuff <= f->textlen) { 424 ptr2=stristr(ptr1, string); 425 if (!ptr2) return(found); 426 427 found++; 428 _owl_fmtext_add_attr(f, OWL_FMTEXT_ATTR_REVERSE, 429 ptr2 - f->textbuff, 430 ptr2 - f->textbuff + len - 1); 431 432 ptr1=ptr2+len; 433 } 434 return(found); 530 dst->default_attrs = src->default_attrs; 531 dst->default_fgcolor = src->default_fgcolor; 532 dst->default_bgcolor = src->default_bgcolor; 435 533 } 436 534 … … 440 538 int owl_fmtext_search(owl_fmtext *f, char *string) 441 539 { 442 443 540 if (stristr(f->textbuff, string)) return(1); 444 541 return(0); … … 681 778 { 682 779 if (f->textbuff) owl_free(f->textbuff); 683 if (f->fmbuff) owl_free(f->fmbuff);684 if (f->fgcolorbuff) owl_free(f->fgcolorbuff);685 if (f->bgcolorbuff) owl_free(f->bgcolorbuff);686 780 } 687 781 -
functions.c
r3617286 rf9eea4c 1606 1606 sprintf(buff, " Field %i : ", i+1); 1607 1607 1608 ptr=owl_zephyr_get_field (n, i+1);1608 ptr=owl_zephyr_get_field_as_utf8(n, i+1); 1609 1609 len=strlen(ptr); 1610 1610 if (len<30) { … … 2187 2187 void owl_function_start_command(char *line) 2188 2188 { 2189 int i, j;2190 2189 owl_editwin *tw; 2191 2190 … … 2198 2197 owl_global_set_needrefresh(&g); 2199 2198 2200 j=strlen(line); 2201 for (i=0; i<j; i++) { 2202 owl_editwin_process_char(tw, line[i]); 2203 } 2199 owl_editwin_insert_string(tw, line); 2204 2200 owl_editwin_redisplay(tw, 0); 2205 2201 … … 2599 2595 } 2600 2596 /* downcase it */ 2601 downstr(filtname); 2597 { 2598 char *temp = g_utf8_strdown(filtname, -1); 2599 if (temp) { 2600 owl_free(filtname); 2601 filtname = temp; 2602 } 2603 } 2602 2604 /* turn spaces, single quotes, and double quotes into dots */ 2603 2605 owl_text_tr(filtname, ' ', '.'); … … 3024 3026 char *quoted; 3025 3027 3026 buff= malloc(strlen(class)+strlen(inst)+strlen(recip)+100);3028 buff=owl_malloc(strlen(class)+strlen(inst)+strlen(recip)+100); 3027 3029 strcpy(buff, "class"); 3028 3030 if (!strcmp(class, "*")) { … … 3328 3330 if (ret==0) { 3329 3331 for (x=0; x<numlocs; x++) { 3330 line= malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100);3332 line=owl_malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100); 3331 3333 tmp=short_zuser(user); 3332 3334 sprintf(line, " %-10.10s %-24.24s %-12.12s %20.20s\n", … … 3371 3373 owl_view *v; 3372 3374 FILE *file; 3375 char *plaintext; 3373 3376 3374 3377 v=owl_global_get_current_view(&g); … … 3393 3396 for (i=0; i<j; i++) { 3394 3397 m=owl_view_get_element(v, i); 3395 fputs(owl_message_get_text(m), file); 3398 plaintext = owl_strip_format_chars(owl_message_get_text(m)); 3399 if (plaintext) { 3400 fputs(plaintext, file); 3401 owl_free(plaintext); 3402 } 3396 3403 } 3397 3404 fclose(file); … … 3434 3441 _exit(127); 3435 3442 } 3436 parsed= realloc(parsed, sizeof(*parsed) * (myargc+1));3443 parsed=owl_realloc(parsed, sizeof(*parsed) * (myargc+1)); 3437 3444 parsed[myargc] = NULL; 3438 3445 -
global.c
rc0f9e30 rc277d89 549 549 len+=strlen(argv[i])+5; 550 550 } 551 g->startupargs= malloc(len+5);551 g->startupargs=owl_malloc(len+5); 552 552 553 553 strcpy(g->startupargs, ""); -
keymap.c
rcf83b7a r428834d 5 5 6 6 /* returns 0 on success */ 7 int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)( int), void (*prealways_fn)(int), void (*postalways_fn)(int))7 int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input)) 8 8 { 9 9 if (!name || !desc) return(-1); … … 151 151 } 152 152 153 owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)( int), void (*prealways_fn)(int), void (*postalways_fn)(int))153 owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input)) 154 154 { 155 155 owl_keymap *km; … … 202 202 /* processes a keypress. returns 0 if the keypress was handled, 203 203 * 1 if not handled, -1 on error, and -2 if j==ERR. */ 204 int owl_keyhandler_process(owl_keyhandler *kh, int j)204 int owl_keyhandler_process(owl_keyhandler *kh, owl_input j) 205 205 { 206 206 owl_keymap *km; … … 214 214 215 215 /* temporarily disallow C-`/C-SPACE until we fix associated bugs */ 216 if (j ==ERR || j==0) {216 if (j.ch == ERR || j.ch == 0) { 217 217 return(-1); 218 218 } … … 224 224 225 225 /* deal with ESC prefixing */ 226 if (!kh->in_esc && j ==27) {226 if (!kh->in_esc && j.ch == 27) { 227 227 kh->in_esc = 1; 228 228 return(0); 229 229 } 230 230 if (kh->in_esc) { 231 j = OWL_META(j);231 j.ch = OWL_META(j.ch); 232 232 kh->in_esc = 0; 233 233 } 234 234 235 kh->kpstack[++(kh->kpstackpos)] = j ;235 kh->kpstack[++(kh->kpstackpos)] = j.ch; 236 236 if (kh->kpstackpos >= OWL_KEYMAP_MAXSTACK) { 237 237 owl_keyhandler_reset(kh); … … 260 260 } else if (match == 2) { /* exact match */ 261 261 /* owl_function_debugmsg("processkey: found exact match in %s", km->name); */ 262 owl_keybinding_execute(kb, j );262 owl_keybinding_execute(kb, j.ch); 263 263 owl_keyhandler_reset(kh); 264 264 if (km->postalways_fn) { -
keypress.c
r948b942 r428834d 148 148 } 149 149 if (!*kb) { 150 if (j &OWL_META(0)) {150 if (j & OWL_META(0)) { 151 151 strcat(kb, "M-"); 152 152 j &= ~OWL_META(0); … … 163 163 strcat(kb, kb2); 164 164 } 165 165 166 } 166 167 if (!*kb) { -
keys.c
r8938188 r428834d 294 294 /****************************************************************/ 295 295 296 void owl_keys_recwin_prealways( int j) {296 void owl_keys_recwin_prealways(owl_input j) { 297 297 /* Clear the message line on subsequent key presses */ 298 298 owl_function_makemsg(""); 299 299 } 300 300 301 void owl_keys_editwin_default( int j) {301 void owl_keys_editwin_default(owl_input j) { 302 302 owl_editwin *e; 303 if (NULL != (e=owl_global_get_typwin(&g))) { 304 owl_editwin_process_char(e, j); 303 if (NULL != (e=owl_global_get_typwin(&g)) 304 && j.ch < 0x100) { 305 owl_editwin_process_char(e, j.uch); 305 306 } 306 307 } 307 308 308 void owl_keys_editwin_postalways( int j) {309 void owl_keys_editwin_postalways(owl_input j) { 309 310 owl_editwin *e; 310 if (NULL != (e=owl_global_get_typwin(&g))) { 311 owl_editwin_post_process_char(e, j); 311 if (NULL != (e=owl_global_get_typwin(&g)) 312 && j.ch < 0x100) { 313 owl_editwin_post_process_char(e, j.uch); 312 314 } 313 315 owl_global_set_needrefresh(&g); 314 316 } 315 317 316 void owl_keys_popless_postalways( int j) {318 void owl_keys_popless_postalways(owl_input j) { 317 319 owl_viewwin *v = owl_global_get_viewwin(&g); 318 320 owl_popwin *pw = owl_global_get_popwin(&g); … … 323 325 } 324 326 325 void owl_keys_default_invalid( int j) {326 if (j ==ERR) return;327 if (j ==410) return;327 void owl_keys_default_invalid(owl_input j) { 328 if (j.ch==ERR) return; 329 if (j.ch==410) return; 328 330 owl_keyhandler_invalidkey(owl_global_get_keyhandler(&g)); 329 331 } -
logging.c
rd0961fe r28ee32b 155 155 to = owl_sprintf("jabber:%s", owl_message_get_recipient(m)); 156 156 } else if (owl_message_is_type_aim(m)) { 157 char *temp2; 157 158 temp = owl_aim_normalize_screenname(owl_message_get_recipient(m)); 158 downstr(temp); 159 to = owl_sprintf("aim:%s", temp); 159 temp2 = g_utf8_strdown(temp,-1); 160 to = owl_sprintf("aim:%s", temp2); 161 owl_free(temp2); 160 162 owl_free(temp); 161 163 } else { … … 267 269 } else if (owl_message_is_type_aim(m)) { 268 270 /* we do not yet handle chat rooms */ 269 char *normalto ;270 normalto=owl_aim_normalize_screenname(owl_message_get_sender(m));271 downstr(normalto);271 char *normalto, *temp; 272 temp = owl_aim_normalize_screenname(owl_message_get_sender(m)); 273 normalto = g_utf8_strdown(temp, -1); 272 274 from=frombuff=owl_sprintf("aim:%s", normalto); 273 275 owl_free(normalto); 276 owl_free(temp); 274 277 } else if (owl_message_is_type_loopback(m)) { 275 278 from=frombuff=owl_strdup("loopback"); … … 290 293 291 294 ch=frombuff[0]; 292 if (! isalnum(ch)) from="weird";295 if (!g_ascii_isalnum(ch)) from="weird"; 293 296 294 297 for (i=0; i<len; i++) { … … 299 302 300 303 if (!personal) { 301 if (strcmp(from, "weird")) downstr(from); 304 if (strcmp(from, "weird")) { 305 char* temp = g_utf8_strdown(frombuff, -1); 306 if (temp) { 307 owl_free(frombuff); 308 from = frombuff = temp; 309 } 310 } 302 311 } 303 312 -
owl.c
r89f5338 r428834d 48 48 #include <termios.h> 49 49 #include <sys/stat.h> 50 #include <locale.h> 50 51 #include "owl.h" 51 52 … … 69 70 owl_editwin *tw; 70 71 owl_popwin *pw; 71 int j, ret, initialsubs, debug, argcsave, followlast; 72 int ret, initialsubs, debug, argcsave, followlast; 73 owl_input j; 72 74 int newmsgs, nexttimediff; 73 75 struct sigaction sigact; … … 84 86 int newstderr; 85 87 #endif 88 89 if (!GLIB_CHECK_VERSION (2, 12, 0)) 90 g_error ("GLib version 2.12.0 or above is needed."); 86 91 87 92 argcsave=argc; … … 92 97 debug=0; 93 98 initialsubs=1; 99 100 setlocale(LC_ALL, ""); 101 94 102 if (argc>0) { 95 103 argv++; … … 538 546 * little bit, but otherwise do not. This lets input be grabbed 539 547 * as quickly as possbile */ 540 j =wgetch(typwin);541 if (j ==ERR) {548 j.ch = wgetch(typwin); 549 if (j.ch == ERR) { 542 550 usleep(10000); 543 551 } else { 552 j.uch = '\0'; 553 if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) { 554 /* This is a curses control character. */ 555 } 556 else if (j.ch > 0x7f && j.ch < 0xfe) { 557 /* Pull in a full utf-8 character. */ 558 int bytes, i; 559 char *utf8buf[7]; 560 memset(utf8buf, '\0', 7); 561 562 utf8buf[0] = j.ch; 563 564 if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2; 565 else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3; 566 else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4; 567 else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5; 568 else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6; 569 else bytes = 1; 570 571 for (i = 1; i < bytes; i++) { 572 utf8buf[i] = wgetch(typwin); 573 } 574 if (g_utf8_validate(utf8buf, -1, NULL)) { 575 j.uch = g_utf8_get_char(utf8buf); 576 } 577 else { 578 j.ch = ERR; 579 } 580 } 581 else if (j.ch <= 0x7f) { 582 j.uch = j.ch; 583 } 584 544 585 owl_global_update_lastinputtime(&g); 545 586 /* find and activate the current keymap. -
owl.h
r18e28a4 r428834d 52 52 #include <termios.h> 53 53 #include <libfaim/aim.h> 54 #include <wchar.h> 54 55 #include "config.h" 56 #include "glib.h" 55 57 #ifdef HAVE_LIBZEPHYR 56 58 #include <zephyr/zephyr.h> … … 98 100 #define OWL_FMTEXT_ATTR_REVERSE 2 99 101 #define OWL_FMTEXT_ATTR_UNDERLINE 4 102 103 #define OWL_FMTEXT_UC_BASE 0x100000 /* Unicode Plane 16 - Supplementary Private Use Area-B*/ 104 #define OWL_FMTEXT_UC_ATTR ( OWL_FMTEXT_UC_BASE | 0x800 ) 105 #define OWL_FMTEXT_UC_ATTR_MASK 0x7 106 #define OWL_FMTEXT_UC_COLOR_BASE ( OWL_FMTEXT_UC_BASE | 0x400 ) 107 #define OWL_FMTEXT_UC_FGCOLOR OWL_FMTEXT_UC_COLOR_BASE 108 #define OWL_FMTEXT_UC_BGCOLOR ( OWL_FMTEXT_UC_COLOR_BASE | 0x200 ) 109 #define OWL_FMTEXT_UC_DEFAULT_COLOR 0x100 110 #define OWL_FMTEXT_UC_FGDEFAULT ( OWL_FMTEXT_UC_FGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR ) 111 #define OWL_FMTEXT_UC_BGDEFAULT ( OWL_FMTEXT_UC_BGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR ) 112 #define OWL_FMTEXT_UC_COLOR_MASK 0xFF 113 #define OWL_FMTEXT_UC_ALLCOLOR_MASK ( OWL_FMTEXT_UC_COLOR_MASK | OWL_FMTEXT_UC_DEFAULT_COLOR | 0x200) 114 #define OWL_FMTEXT_UC_STARTBYTE_UTF8 '\xf4' 115 116 #define OWL_FMTEXT_UTF8_ATTR_NONE "\xf4\x80\xa0\x80" 117 #define OWL_FMTEXT_UTF8_FGDEFAULT "\xf4\x80\x94\x80" 118 #define OWL_FMTEXT_UTF8_BGDEFAULT "\xf4\x80\x96\x80" 119 120 121 100 122 101 123 #define OWL_COLOR_BLACK 0 … … 250 272 } owl_variable; 251 273 274 typedef struct _owl_input { 275 int ch; 276 char utf8buf[8]; 277 gunichar uch; 278 } owl_input; 279 252 280 typedef struct _owl_fmtext { 253 281 int textlen; 254 282 int bufflen; 255 283 char *textbuff; 256 char *fmbuff;257 short *fgcolorbuff;258 short *bgcolorbuff;284 char default_attrs; 285 short default_fgcolor; 286 short default_bgcolor; 259 287 } owl_fmtext; 260 288 … … 489 517 owl_list bindings; /* key bindings */ 490 518 struct _owl_keymap *submap; /* submap */ 491 void (*default_fn)( int j); /* default action (takes a keypress) */492 void (*prealways_fn)( intj); /* always called before a keypress is received */493 void (*postalways_fn)( intj); /* always called after keypress is processed */519 void (*default_fn)(owl_input j); /* default action (takes a keypress) */ 520 void (*prealways_fn)(owl_input j); /* always called before a keypress is received */ 521 void (*postalways_fn)(owl_input j); /* always called after keypress is processed */ 494 522 } owl_keymap; 495 523 -
perlconfig.c
rad15610 r5376a95 55 55 j=owl_zephyr_get_num_fields(owl_message_get_notice(m)); 56 56 for (i=0; i<j; i++) { 57 ptr=owl_zephyr_get_field (owl_message_get_notice(m), i+1);57 ptr=owl_zephyr_get_field_as_utf8(owl_message_get_notice(m), i+1); 58 58 av_push(av_zfields, newSVpvn(ptr, strlen(ptr))); 59 59 owl_free(ptr); -
text.c
r72db971 r47519e1b 50 50 void owl_text_truncate_cols(char *out, char *in, int acol, int bcol) 51 51 { 52 char *ptr 1, *ptr2, *tmpbuff, *last;53 int len;54 52 char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last; 53 int col, cnt, padding; 54 55 55 tmpbuff=owl_malloc(strlen(in)+20); 56 56 57 57 strcpy(tmpbuff, ""); 58 58 last=in+strlen(in)-1; 59 ptr 1=in;60 while (ptr 1<last) {61 ptr 2=strchr(ptr1, '\n');62 if (!ptr 2) {59 ptr_s=in; 60 while (ptr_s<last) { 61 ptr_e=strchr(ptr_s, '\n'); 62 if (!ptr_e) { 63 63 /* but this shouldn't happen if we end in a \n */ 64 64 break; 65 65 } 66 66 67 if (ptr 2==ptr1) {67 if (ptr_e==ptr_s) { 68 68 strcat(tmpbuff, "\n"); 69 ptr1++; 70 continue; 71 } 72 69 ptr_s++; 70 continue; 71 } 72 73 col = 0; 74 cnt = 0; 75 padding = 0; 76 ptr_c = ptr_s; 77 while(col < bcol && ptr_c < ptr_e) { 78 gunichar c = g_utf8_get_char(ptr_c); 79 if (col + mk_wcwidth(c) > bcol) break; 80 col += mk_wcwidth(c); 81 ptr_c = g_utf8_next_char(ptr_c); 82 if (col >= acol) { 83 if (cnt == 0) { 84 ptr_s = ptr_c; 85 padding = col - acol; 86 } 87 ++cnt; 88 } 89 } 90 if (cnt) { 91 while(padding-- > 0) { 92 strcat(tmpbuff, " "); 93 } 94 strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1); 95 } 96 strcat(tmpbuff, "\n"); 97 ptr_s = ptr_e + 1; 98 #if 0 73 99 /* we need to check that we won't run over here */ 74 if ( (ptr 2-ptr1) < (bcol-acol) ) {75 len=ptr 2-(ptr1+acol);100 if ( (ptr_e-ptr_s) < (bcol-acol) ) { 101 len=ptr_e-(ptr_s+acol); 76 102 } else { 77 103 len=bcol-acol; 78 104 } 79 if ((ptr 1+len)>=last) {80 len-=last-(ptr 1+len);81 } 82 83 strncat(tmpbuff, ptr 1+acol, len);105 if ((ptr_s+len)>=last) { 106 len-=last-(ptr_s+len); 107 } 108 109 strncat(tmpbuff, ptr_s+acol, len); 84 110 strcat(tmpbuff, "\n"); 85 111 86 ptr1=ptr2+1; 112 ptr_s=ptr_e+1; 113 #endif 87 114 } 88 115 strcpy(out, tmpbuff); … … 275 302 char *stristr(char *a, char *b) 276 303 { 277 char *x, *y, *ret; 278 279 if ((x=owl_strdup(a))==NULL) return(NULL); 280 if ((y=owl_strdup(b))==NULL) return(NULL); 281 downstr(x); 282 downstr(y); 283 ret=strstr(x, y); 284 if (ret==NULL) { 285 owl_free(x); 286 owl_free(y); 287 return(NULL); 288 } 289 ret=ret-x+a; 290 owl_free(x); 291 owl_free(y); 304 char *x, *y; 305 char *ret = NULL; 306 if ((x = g_utf8_casefold(a, -1)) != NULL) { 307 if ((y = g_utf8_casefold(b, -1)) != NULL) { 308 ret = strstr(x, y); 309 if (ret != NULL) { 310 ret = ret - x + a; 311 } 312 g_free(y); 313 } 314 g_free(x); 315 } 292 316 return(ret); 293 317 } … … 296 320 int only_whitespace(char *s) 297 321 { 298 int i; 299 for (i=0; s[i]; i++) { 300 if (!isspace((int) s[i])) return(0); 322 if (g_utf8_validate(s,-1,NULL)) { 323 char *p; 324 for(p = s; p[0]; p=g_utf8_next_char(p)) { 325 if (!g_unichar_isspace(g_utf8_get_char(p))) return 0; 326 } 327 } 328 else { 329 int i; 330 for (i=0; s[i]; i++) { 331 if (!isspace((int) s[i])) return(0); 332 } 301 333 } 302 334 return(1); … … 327 359 tolen = strlen(to); 328 360 fromlen = strlen(from); 329 out = malloc(outlen);361 out = owl_malloc(outlen); 330 362 331 363 while (in[inpos]) { -
util.c
r89f5338 r7b1d048 399 399 } 400 400 401 /* downcase the string 'foo' */402 void downstr(char *foo)403 {404 int i;405 for (i=0; foo[i]!='\0'; i++) {406 foo[i]=tolower(foo[i]);407 }408 }409 410 401 /* Caller must free response. 411 402 * Takes in strings which are space-separated lists of tokens … … 446 437 void *owl_malloc(size_t size) 447 438 { 448 return( malloc(size));439 return(g_malloc(size)); 449 440 } 450 441 451 442 void owl_free(void *ptr) 452 443 { 453 free(ptr);444 g_free(ptr); 454 445 } 455 446 456 447 char *owl_strdup(const char *s1) 457 448 { 458 return( strdup(s1));449 return(g_strdup(s1)); 459 450 } 460 451 461 452 void *owl_realloc(void *ptr, size_t size) 462 453 { 463 return( realloc(ptr, size));454 return(g_realloc(ptr, size)); 464 455 } 465 456 466 457 /* allocates memory and returns the string or null. 467 458 * caller must free the string. 468 * from Linux sprintf man page.469 459 */ 470 460 char *owl_sprintf(const char *fmt, ...) 471 461 { 472 int n, size = 100;473 char *p;474 462 va_list ap; 475 if ((p = owl_malloc (size)) == NULL) return (NULL); 476 while (1) { 477 /* Try to print in the allocated space. */ 478 va_start(ap, fmt); 479 n = vsnprintf (p, size, fmt, ap); 480 va_end(ap); 481 /* If that worked, return the string. */ 482 if (n > -1 && n < size) 483 return p; 484 /* Else try again with more space. */ 485 if (n > -1) /* glibc 2.1 */ 486 size = n+1; /* precisely what is needed */ 487 else /* glibc 2.0 */ 488 size *= 2; /* twice the old size */ 489 if ((p = owl_realloc (p, size)) == NULL) 490 return NULL; 491 } 492 } 463 char *ret = NULL; 464 va_start(ap, fmt); 465 ret = g_strdup_vprintf(fmt, ap); 466 va_end(ap); 467 return ret; 468 } 469 493 470 494 471 /* Return the owl color associated with the named color. Return -1 … … 776 753 } 777 754 778 char * owl_get_datadir() { 779 char * datadir = getenv("BARNOWL_DATA_DIR"); 780 if(datadir != NULL) 781 return strchr(datadir, '=') + 1; 782 return DATADIR; 755 char * owl_get_datadir() 756 { 757 char * datadir = getenv("BARNOWL_DATA_DIR"); 758 if(datadir != NULL) 759 return strchr(datadir, '=') + 1; 760 return DATADIR; 761 } 762 763 /* Strips format characters from a valid utf-8 string. Returns the 764 empty string if 'in' does not validate. */ 765 char * owl_strip_format_chars(char *in) 766 { 767 char *r; 768 if (g_utf8_validate(in, -1, NULL)) { 769 char *s, *p; 770 r = owl_malloc(strlen(in)+1); 771 r[0] = '\0'; 772 s = in; 773 p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8); 774 while(p) { 775 /* If it's a format character, copy up to it, and skip all 776 immediately following format characters. */ 777 if (_owl_fmtext_is_format_char(g_utf8_get_char(p))) { 778 strncat(r, s, p-s); 779 p = g_utf8_next_char(p); 780 while (p && _owl_fmtext_is_format_char(g_utf8_get_char(p))) { 781 p = g_utf8_next_char(p); 782 } 783 s = p; 784 p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8); 785 } 786 else { 787 p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8); 788 } 789 } 790 if (s) strcat(r,s); 791 } 792 else { 793 r = owl_strdup(""); 794 } 795 return r; 796 } 797 798 /* If in is not UTF-8, convert from ISO-8859-1. We may want to allow 799 * the caller to specify an alternative in the future. We also strip 800 * out characters in Unicode Plane 16, as we use that plane internally 801 * for formatting. 802 */ 803 char * owl_validate_or_convert(char *in) 804 { 805 if (g_utf8_validate(in, -1, NULL)) { 806 return owl_strip_format_chars(in); 807 } 808 else { 809 return g_convert(in, -1, 810 "UTF-8", "ISO-8859-1", 811 NULL, NULL, NULL); 812 } 813 } 814 /* Attempts to convert 'in' to ISO-8859-1. Returns that if possible, 815 else returns UTF-8. 816 */ 817 char * owl_get_iso_8859_1_if_possible(char *in) 818 { 819 char *out; 820 if (g_utf8_validate(in, -1, NULL)) { 821 out = g_convert(in, -1, 822 "ISO-8859-1", "UTF-8", 823 NULL, NULL, NULL); 824 if (!out) { 825 out = owl_strdup(in); 826 } 827 } 828 else { 829 out = owl_strdup(""); 830 } 831 return out; 783 832 } 784 833 -
viewwin.c
r8721756 r47519e1b 73 73 owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2); 74 74 75 owl_fmtext_curs_waddstr (&fm2, v->curswin);75 owl_fmtext_curs_waddstr_without_search(&fm2, v->curswin); 76 76 77 77 /* print the message at the bottom */ -
zcrypt.c
r9ceee9d r34509d5 385 385 386 386 /* Build a space-separated string from argv from elements between start * 387 * and end - 1. malloc()'s the returned string. */387 * and end - 1. owl_malloc()'s the returned string. */ 388 388 char *BuildArgString(char **argv, int start, int end) { 389 389 int len = 1; … … 397 397 398 398 /* Allocate memory */ 399 result = (char *) malloc(len);399 result = (char *)owl_malloc(len); 400 400 if (result) { 401 401 /* Build the string */ … … 482 482 /* Prepare result to be returned */ 483 483 char *temp = keyfile; 484 keyfile = (char *) malloc(strlen(temp) + 1);484 keyfile = (char *)owl_malloc(strlen(temp) + 1); 485 485 if (keyfile) { 486 486 strcpy(keyfile, temp); … … 611 611 } 612 612 use_buffer = TRUE; 613 if ((inptr = inbuff = (char *) malloc(MAX_RESULT)) == NULL) {613 if ((inptr = inbuff = (char *)owl_malloc(MAX_RESULT)) == NULL) { 614 614 printf("Memory allocation error\n"); 615 615 return FALSE; … … 639 639 printf("Could not run zwrite\n"); 640 640 if (freein && inbuff) { 641 free(inbuff);641 owl_free(inbuff); 642 642 } 643 643 return(FALSE); … … 685 685 686 686 /* Free the input buffer, if necessary */ 687 if (freein && inbuff) free(inbuff);687 if (freein && inbuff) owl_free(inbuff); 688 688 689 689 return(!error); -
zwrite.c
r1fe100c r7b1d048 44 44 break; 45 45 } 46 z->class=owl_ strdup(myargv[1]);46 z->class=owl_get_iso_8859_1_if_possible(myargv[1]); 47 47 myargv+=2; 48 48 myargc-=2; … … 52 52 break; 53 53 } 54 z->inst=owl_ strdup(myargv[1]);54 z->inst=owl_get_iso_8859_1_if_possible(myargv[1]); 55 55 myargv+=2; 56 56 myargc-=2; … … 60 60 break; 61 61 } 62 z->realm=owl_ strdup(myargv[1]);62 z->realm=owl_get_iso_8859_1_if_possible(myargv[1]); 63 63 myargv+=2; 64 64 myargc-=2; … … 68 68 break; 69 69 } 70 z->zsig=owl_ strdup(myargv[1]);70 z->zsig=owl_get_iso_8859_1_if_possible(myargv[1]); 71 71 myargv+=2; 72 72 myargc-=2; … … 76 76 break; 77 77 } 78 z->opcode=owl_ strdup(myargv[1]);78 z->opcode=owl_get_iso_8859_1_if_possible(myargv[1]); 79 79 myargv+=2; 80 80 myargc-=2; … … 93 93 myargv++; 94 94 myargc--; 95 z->message=owl_ strdup("");95 z->message=owl_get_iso_8859_1_if_possible(""); 96 96 while (myargc) { 97 z->message= realloc(z->message, strlen(z->message)+strlen(myargv[0])+5);97 z->message=owl_realloc(z->message, strlen(z->message)+strlen(myargv[0])+5); 98 98 strcat(z->message, myargv[0]); 99 99 strcat(z->message, " "); … … 113 113 } else { 114 114 /* anything unattached is a recipient */ 115 owl_list_append_element(&(z->recips), strdup(myargv[0]));115 owl_list_append_element(&(z->recips), owl_get_iso_8859_1_if_possible(myargv[0])); 116 116 myargv++; 117 117 myargc--; … … 146 146 147 147 if (zsigowlvar && *zsigowlvar) { 148 z->zsig=owl_ strdup(zsigowlvar);148 z->zsig=owl_get_iso_8859_1_if_possible(zsigowlvar); 149 149 } else if (zsigproc && *zsigproc) { 150 150 FILE *file; … … 161 161 if (!file) { 162 162 if (zsigzvar && *zsigzvar) { 163 z->zsig=owl_ strdup(zsigzvar);163 z->zsig=owl_get_iso_8859_1_if_possible(zsigzvar); 164 164 } 165 165 } else { … … 175 175 } 176 176 } else if (zsigzvar) { 177 z->zsig=owl_ strdup(zsigzvar);177 z->zsig=owl_get_iso_8859_1_if_possible(zsigzvar); 178 178 } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) { 179 z->zsig= strdup(pw->pw_gecos);179 z->zsig=owl_get_iso_8859_1_if_possible(pw->pw_gecos); 180 180 ptr=strchr(z->zsig, ','); 181 181 if (ptr) { … … 218 218 int i, j; 219 219 char toline[LINE]; 220 char *tmp = NULL; 220 221 221 222 if (z->message) owl_free(z->message); … … 231 232 } 232 233 } 233 z->message=owl_sprintf("%s\n%s", toline, msg); 234 tmp = owl_get_iso_8859_1_if_possible(msg); 235 z->message=owl_sprintf("%s\n%s", toline, tmp); 234 236 } else { 235 z->message=owl_strdup(msg); 236 } 237 z->message=owl_get_iso_8859_1_if_possible(msg); 238 } 239 if (tmp) owl_free(tmp); 237 240 } 238 241 … … 305 308 { 306 309 if (z->opcode) owl_free(z->opcode); 307 z->opcode=owl_ strdup(opcode);310 z->opcode=owl_get_iso_8859_1_if_possible(opcode); 308 311 } 309 312
Note: See TracChangeset
for help on using the changeset viewer.