~alivema4ever/ubuntu/trusty/weechat/lp-1299347-fix

« back to all changes in this revision

Viewing changes to src/plugins/perl/weechat-perl.c

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bouthenot
  • Date: 2013-01-23 18:44:36 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20130123184436-pillcj7jmtyyj00j
Tags: 0.4.0-1
* New upstream release.
* Bump Standards-Version to 3.9.4
* Remove UPGRADE_0.3 from doc (no more included in upstream sources).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org>
 
2
 * weechat-perl.c - perl plugin for WeeChat
 
3
 *
 
4
 * Copyright (C) 2003-2013 Sebastien Helleu <flashcode@flashtux.org>
3
5
 * Copyright (C) 2005-2008 Emmanuel Bouthenot <kolter@openics.org>
4
6
 *
5
7
 * This file is part of WeeChat, the extensible chat client.
18
20
 * along with WeeChat.  If not, see <http://www.gnu.org/licenses/>.
19
21
 */
20
22
 
21
 
/*
22
 
 * weechat-perl.c: perl plugin for WeeChat
23
 
 */
24
 
 
25
23
#undef _
26
24
 
27
25
#include <EXTERN.h>
92
90
    "    open FILE, $filename or return \"__WEECHAT_PERL_ERROR__\";"
93
91
    "    $_ = <FILE>;"
94
92
    "    close FILE;"
95
 
    "    return $_;"
 
93
    "    return qq{\n#line 1 \"$filename\"\n$_};"
96
94
    "}"
97
95
    "sub weechat_perl_load_eval_file"
98
96
    "{"
127
125
 
128
126
 
129
127
/*
130
 
 * weechat_perl_hashtable_map_cb: callback called for each key/value in a
131
 
 *                                hashtable
 
128
 * Callback called for each key/value in a hashtable.
132
129
 */
133
130
 
134
131
void
148
145
}
149
146
 
150
147
/*
151
 
 * weechat_perl_hashtable_to_hash: get perl hash with a WeeChat hashtable
 
148
 * Gets perl hash with a WeeChat hashtable.
152
149
 */
153
150
 
154
151
HV *
168
165
}
169
166
 
170
167
/*
171
 
 * weechat_perl_hash_to_hashtable: get WeeChat hashtable with perl hash
172
 
 *                                 Hashtable returned has type string for
173
 
 *                                 both keys and values
174
 
 *                                 Note: hashtable has to be released after use
175
 
 *                                 with call to weechat_hashtable_free()
 
168
 * Gets WeeChat hashtable with perl hash.
 
169
 *
 
170
 * Note: hashtable must be freed after use.
176
171
 */
177
172
 
178
173
struct t_hashtable *
179
 
weechat_perl_hash_to_hashtable (SV *hash, int hashtable_size)
 
174
weechat_perl_hash_to_hashtable (SV *hash, int size, const char *type_keys,
 
175
                                const char *type_values)
180
176
{
181
177
    struct t_hashtable *hashtable;
182
178
    HV *hash2;
184
180
    char *str_key;
185
181
    I32 retlen;
186
182
 
187
 
    hashtable = weechat_hashtable_new (hashtable_size,
188
 
                                       WEECHAT_HASHTABLE_STRING,
189
 
                                       WEECHAT_HASHTABLE_STRING,
 
183
    hashtable = weechat_hashtable_new (size,
 
184
                                       type_keys,
 
185
                                       type_values,
190
186
                                       NULL,
191
187
                                       NULL);
192
188
    if (!hashtable)
198
194
        hv_iterinit (hash2);
199
195
        while ((value = hv_iternextsv (hash2, &str_key, &retlen)))
200
196
        {
201
 
            weechat_hashtable_set (hashtable, str_key, SvPV (value, PL_na));
 
197
            if (strcmp (type_values, WEECHAT_HASHTABLE_STRING) == 0)
 
198
                weechat_hashtable_set (hashtable, str_key, SvPV (value, PL_na));
 
199
            else if (strcmp (type_values, WEECHAT_HASHTABLE_POINTER) == 0)
 
200
            {
 
201
                weechat_hashtable_set (hashtable, str_key,
 
202
                                       plugin_script_str2ptr (weechat_perl_plugin,
 
203
                                                              NULL, NULL,
 
204
                                                              SvPV (value, PL_na)));
 
205
            }
202
206
        }
203
207
    }
204
208
 
206
210
}
207
211
 
208
212
/*
209
 
 * weechat_perl_exec: execute a perl function
 
213
 * Executes a perl function.
210
214
 */
211
215
 
212
216
void *
316
320
            else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE)
317
321
            {
318
322
                ret_value = weechat_perl_hash_to_hashtable (POPs,
319
 
                                                            WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
 
323
                                                            WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
 
324
                                                            WEECHAT_HASHTABLE_STRING,
 
325
                                                            WEECHAT_HASHTABLE_STRING);
320
326
            }
321
327
            else
322
328
            {
354
360
}
355
361
 
356
362
/*
357
 
 * weechat_perl_load: load a Perl script
 
363
 * Loads a perl script.
 
364
 *
 
365
 * Returns:
 
366
 *   1: OK
 
367
 *   0: error
358
368
 */
359
369
 
360
370
int
538
548
}
539
549
 
540
550
/*
541
 
 * weechat_perl_load_cb: callback for weechat_script_auto_load() function
 
551
 * Callback for weechat_script_auto_load() function.
542
552
 */
543
553
 
544
554
void
551
561
}
552
562
 
553
563
/*
554
 
 * weechat_perl_unload: unload a Perl script
 
564
 * Unloads a perl script.
555
565
 */
556
566
 
557
567
void
614
624
}
615
625
 
616
626
/*
617
 
 * weechat_perl_unload_name: unload a Perl script by name
 
627
 * Unloads a perl script by name.
618
628
 */
619
629
 
620
630
void
642
652
}
643
653
 
644
654
/*
645
 
 * weechat_perl_unload_all: unload all Perl scripts
 
655
 * Unloads all perl scripts.
646
656
 */
647
657
 
648
658
void
655
665
}
656
666
 
657
667
/*
658
 
 * weechat_perl_reload_name: reload a Perl script by name
 
668
 * Reloads a perl script by name.
659
669
 */
660
670
 
661
671
void
690
700
}
691
701
 
692
702
/*
693
 
 * weechat_perl_command_cb: callback for "/perl" command
 
703
 * Callback for command "/perl".
694
704
 */
695
705
 
696
706
int
762
772
            }
763
773
            if (weechat_strcasecmp (argv[1], "load") == 0)
764
774
            {
765
 
                /* load Perl script */
 
775
                /* load perl script */
766
776
                path_script = plugin_script_search_path (weechat_perl_plugin,
767
777
                                                         ptr_name);
768
778
                weechat_perl_load ((path_script) ? path_script : ptr_name);
771
781
            }
772
782
            else if (weechat_strcasecmp (argv[1], "reload") == 0)
773
783
            {
774
 
                /* reload one Perl script */
 
784
                /* reload one perl script */
775
785
                weechat_perl_reload_name (ptr_name);
776
786
            }
777
787
            else if (weechat_strcasecmp (argv[1], "unload") == 0)
778
788
            {
779
 
                /* unload Perl script */
 
789
                /* unload perl script */
780
790
                weechat_perl_unload_name (ptr_name);
781
791
            }
782
792
            perl_quiet = 0;
794
804
}
795
805
 
796
806
/*
797
 
 * weechat_perl_completion_cb: callback for script completion
 
807
 * Adds perl scripts to completion list.
798
808
 */
799
809
 
800
810
int
813
823
}
814
824
 
815
825
/*
816
 
 * weechat_perl_hdata_cb: callback for hdata
 
826
 * Returns hdata for perl scripts.
817
827
 */
818
828
 
819
829
struct t_hdata *
828
838
}
829
839
 
830
840
/*
831
 
 * weechat_perl_infolist_cb: callback for infolist
 
841
 * Returns infolist with perl scripts.
832
842
 */
833
843
 
834
844
struct t_infolist *
852
862
}
853
863
 
854
864
/*
855
 
 * weechat_perl_signal_debug_dump_cb: dump Perl plugin data in WeeChat log file
 
865
 * Dumps perl plugin data in WeeChat log file.
856
866
 */
857
867
 
858
868
int
874
884
}
875
885
 
876
886
/*
877
 
 * weechat_perl_signal_buffer_closed_cb: callback called when a buffer is closed
 
887
 * Callback called when a buffer is closed.
878
888
 */
879
889
 
880
890
int
893
903
}
894
904
 
895
905
/*
896
 
 * weechat_perl_timer_action_cb: timer for executing actions
 
906
 * Timer for executing actions.
897
907
 */
898
908
 
899
909
int
927
937
}
928
938
 
929
939
/*
930
 
 * weechat_perl_signal_script_action_cb: callback called when a script action
931
 
 *                                       is asked (install/remove a script)
 
940
 * Callback called when a script action is asked (install/remove a script).
932
941
 */
933
942
 
934
943
int
963
972
}
964
973
 
965
974
/*
966
 
 * weechat_perl_signal_quit_upgrade_cb: callback called when exiting or
967
 
 *                                      upgrading WeeChat
 
975
 * Callback called when exiting or upgrading WeeChat.
968
976
 */
969
977
 
970
978
int
984
992
}
985
993
 
986
994
/*
987
 
 * weechat_plugin_init: initialize Perl plugin
 
995
 * Initializes perl plugin.
988
996
 */
989
997
 
990
998
int
1047
1055
}
1048
1056
 
1049
1057
/*
1050
 
 * weechat_plugin_end: end Perl plugin
 
1058
 * Ends perl plugin.
1051
1059
 */
1052
1060
 
1053
1061
int