Mercurial > vim
comparison src/ex_cmds2.c @ 7819:f86adafb28d4 v7.4.1206
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 30 15:52:46 2016 +0100
patch 7.4.1206
Problem: Using old style function declarations.
Solution: Change to new style function declarations. (script by Hirohito
Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 30 Jan 2016 16:00:06 +0100 |
parents | 1a5d34492798 |
children | 10f17a228661 |
comparison
equal
deleted
inserted
replaced
7818:19dfb097d82d | 7819:f86adafb28d4 |
---|---|
76 /* | 76 /* |
77 * do_debug(): Debug mode. | 77 * do_debug(): Debug mode. |
78 * Repeatedly get Ex commands, until told to continue normal execution. | 78 * Repeatedly get Ex commands, until told to continue normal execution. |
79 */ | 79 */ |
80 void | 80 void |
81 do_debug(cmd) | 81 do_debug(char_u *cmd) |
82 char_u *cmd; | |
83 { | 82 { |
84 int save_msg_scroll = msg_scroll; | 83 int save_msg_scroll = msg_scroll; |
85 int save_State = State; | 84 int save_State = State; |
86 int save_did_emsg = did_emsg; | 85 int save_did_emsg = did_emsg; |
87 int save_cmd_silent = cmd_silent; | 86 int save_cmd_silent = cmd_silent; |
431 | 430 |
432 /* | 431 /* |
433 * ":debug". | 432 * ":debug". |
434 */ | 433 */ |
435 void | 434 void |
436 ex_debug(eap) | 435 ex_debug(exarg_T *eap) |
437 exarg_T *eap; | |
438 { | 436 { |
439 int debug_break_level_save = debug_break_level; | 437 int debug_break_level_save = debug_break_level; |
440 | 438 |
441 debug_break_level = 9999; | 439 debug_break_level = 9999; |
442 do_cmdline_cmd(eap->arg); | 440 do_cmdline_cmd(eap->arg); |
462 * executed. Return TRUE and set breakpoint_name for skipped commands that | 460 * executed. Return TRUE and set breakpoint_name for skipped commands that |
463 * decide to execute something themselves. | 461 * decide to execute something themselves. |
464 * Called from do_one_cmd() before executing a command. | 462 * Called from do_one_cmd() before executing a command. |
465 */ | 463 */ |
466 void | 464 void |
467 dbg_check_breakpoint(eap) | 465 dbg_check_breakpoint(exarg_T *eap) |
468 exarg_T *eap; | |
469 { | 466 { |
470 char_u *p; | 467 char_u *p; |
471 | 468 |
472 debug_skipped = FALSE; | 469 debug_skipped = FALSE; |
473 if (debug_breakpoint_name != NULL) | 470 if (debug_breakpoint_name != NULL) |
510 /* | 507 /* |
511 * Go to debug mode if skipped by dbg_check_breakpoint() because eap->skip was | 508 * Go to debug mode if skipped by dbg_check_breakpoint() because eap->skip was |
512 * set. Return TRUE when the debug mode is entered this time. | 509 * set. Return TRUE when the debug mode is entered this time. |
513 */ | 510 */ |
514 int | 511 int |
515 dbg_check_skipped(eap) | 512 dbg_check_skipped(exarg_T *eap) |
516 exarg_T *eap; | |
517 { | 513 { |
518 int prev_got_int; | 514 int prev_got_int; |
519 | 515 |
520 if (debug_skipped) | 516 if (debug_skipped) |
521 { | 517 { |
570 * in the entry just after the last one in dbg_breakp. Note that "dbg_name" | 566 * in the entry just after the last one in dbg_breakp. Note that "dbg_name" |
571 * is allocated. | 567 * is allocated. |
572 * Returns FAIL for failure. | 568 * Returns FAIL for failure. |
573 */ | 569 */ |
574 static int | 570 static int |
575 dbg_parsearg(arg, gap) | 571 dbg_parsearg( |
576 char_u *arg; | 572 char_u *arg, |
577 garray_T *gap; /* either &dbg_breakp or &prof_ga */ | 573 garray_T *gap) /* either &dbg_breakp or &prof_ga */ |
578 { | 574 { |
579 char_u *p = arg; | 575 char_u *p = arg; |
580 char_u *q; | 576 char_u *q; |
581 struct debuggy *bp; | 577 struct debuggy *bp; |
582 int here = FALSE; | 578 int here = FALSE; |
667 | 663 |
668 /* | 664 /* |
669 * ":breakadd". | 665 * ":breakadd". |
670 */ | 666 */ |
671 void | 667 void |
672 ex_breakadd(eap) | 668 ex_breakadd(exarg_T *eap) |
673 exarg_T *eap; | |
674 { | 669 { |
675 struct debuggy *bp; | 670 struct debuggy *bp; |
676 char_u *pat; | 671 char_u *pat; |
677 garray_T *gap; | 672 garray_T *gap; |
678 | 673 |
713 | 708 |
714 /* | 709 /* |
715 * ":debuggreedy". | 710 * ":debuggreedy". |
716 */ | 711 */ |
717 void | 712 void |
718 ex_debuggreedy(eap) | 713 ex_debuggreedy(exarg_T *eap) |
719 exarg_T *eap; | |
720 { | 714 { |
721 if (eap->addr_count == 0 || eap->line2 != 0) | 715 if (eap->addr_count == 0 || eap->line2 != 0) |
722 debug_greedy = TRUE; | 716 debug_greedy = TRUE; |
723 else | 717 else |
724 debug_greedy = FALSE; | 718 debug_greedy = FALSE; |
726 | 720 |
727 /* | 721 /* |
728 * ":breakdel" and ":profdel". | 722 * ":breakdel" and ":profdel". |
729 */ | 723 */ |
730 void | 724 void |
731 ex_breakdel(eap) | 725 ex_breakdel(exarg_T *eap) |
732 exarg_T *eap; | |
733 { | 726 { |
734 struct debuggy *bp, *bpi; | 727 struct debuggy *bp, *bpi; |
735 int nr; | 728 int nr; |
736 int todel = -1; | 729 int todel = -1; |
737 int del_all = FALSE; | 730 int del_all = FALSE; |
817 | 810 |
818 /* | 811 /* |
819 * ":breaklist". | 812 * ":breaklist". |
820 */ | 813 */ |
821 void | 814 void |
822 ex_breaklist(eap) | 815 ex_breaklist(exarg_T *eap UNUSED) |
823 exarg_T *eap UNUSED; | |
824 { | 816 { |
825 struct debuggy *bp; | 817 struct debuggy *bp; |
826 int i; | 818 int i; |
827 | 819 |
828 if (dbg_breakp.ga_len == 0) | 820 if (dbg_breakp.ga_len == 0) |
844 /* | 836 /* |
845 * Find a breakpoint for a function or sourced file. | 837 * Find a breakpoint for a function or sourced file. |
846 * Returns line number at which to break; zero when no matching breakpoint. | 838 * Returns line number at which to break; zero when no matching breakpoint. |
847 */ | 839 */ |
848 linenr_T | 840 linenr_T |
849 dbg_find_breakpoint(file, fname, after) | 841 dbg_find_breakpoint( |
850 int file; /* TRUE for a file, FALSE for a function */ | 842 int file, /* TRUE for a file, FALSE for a function */ |
851 char_u *fname; /* file or function name */ | 843 char_u *fname, /* file or function name */ |
852 linenr_T after; /* after this line number */ | 844 linenr_T after) /* after this line number */ |
853 { | 845 { |
854 return debuggy_find(file, fname, after, &dbg_breakp, NULL); | 846 return debuggy_find(file, fname, after, &dbg_breakp, NULL); |
855 } | 847 } |
856 | 848 |
857 #if defined(FEAT_PROFILE) || defined(PROTO) | 849 #if defined(FEAT_PROFILE) || defined(PROTO) |
858 /* | 850 /* |
859 * Return TRUE if profiling is on for a function or sourced file. | 851 * Return TRUE if profiling is on for a function or sourced file. |
860 */ | 852 */ |
861 int | 853 int |
862 has_profiling(file, fname, fp) | 854 has_profiling( |
863 int file; /* TRUE for a file, FALSE for a function */ | 855 int file, /* TRUE for a file, FALSE for a function */ |
864 char_u *fname; /* file or function name */ | 856 char_u *fname, /* file or function name */ |
865 int *fp; /* return: forceit */ | 857 int *fp) /* return: forceit */ |
866 { | 858 { |
867 return (debuggy_find(file, fname, (linenr_T)0, &prof_ga, fp) | 859 return (debuggy_find(file, fname, (linenr_T)0, &prof_ga, fp) |
868 != (linenr_T)0); | 860 != (linenr_T)0); |
869 } | 861 } |
870 #endif | 862 #endif |
871 | 863 |
872 /* | 864 /* |
873 * Common code for dbg_find_breakpoint() and has_profiling(). | 865 * Common code for dbg_find_breakpoint() and has_profiling(). |
874 */ | 866 */ |
875 static linenr_T | 867 static linenr_T |
876 debuggy_find(file, fname, after, gap, fp) | 868 debuggy_find( |
877 int file; /* TRUE for a file, FALSE for a function */ | 869 int file, /* TRUE for a file, FALSE for a function */ |
878 char_u *fname; /* file or function name */ | 870 char_u *fname, /* file or function name */ |
879 linenr_T after; /* after this line number */ | 871 linenr_T after, /* after this line number */ |
880 garray_T *gap; /* either &dbg_breakp or &prof_ga */ | 872 garray_T *gap, /* either &dbg_breakp or &prof_ga */ |
881 int *fp; /* if not NULL: return forceit */ | 873 int *fp) /* if not NULL: return forceit */ |
882 { | 874 { |
883 struct debuggy *bp; | 875 struct debuggy *bp; |
884 int i; | 876 int i; |
885 linenr_T lnum = 0; | 877 linenr_T lnum = 0; |
886 char_u *name = fname; | 878 char_u *name = fname; |
938 | 930 |
939 /* | 931 /* |
940 * Called when a breakpoint was encountered. | 932 * Called when a breakpoint was encountered. |
941 */ | 933 */ |
942 void | 934 void |
943 dbg_breakpoint(name, lnum) | 935 dbg_breakpoint(char_u *name, linenr_T lnum) |
944 char_u *name; | |
945 linenr_T lnum; | |
946 { | 936 { |
947 /* We need to check if this line is actually executed in do_one_cmd() */ | 937 /* We need to check if this line is actually executed in do_one_cmd() */ |
948 debug_breakpoint_name = name; | 938 debug_breakpoint_name = name; |
949 debug_breakpoint_lnum = lnum; | 939 debug_breakpoint_lnum = lnum; |
950 } | 940 } |
953 # if defined(FEAT_PROFILE) || defined(FEAT_RELTIME) || defined(PROTO) | 943 # if defined(FEAT_PROFILE) || defined(FEAT_RELTIME) || defined(PROTO) |
954 /* | 944 /* |
955 * Store the current time in "tm". | 945 * Store the current time in "tm". |
956 */ | 946 */ |
957 void | 947 void |
958 profile_start(tm) | 948 profile_start(proftime_T *tm) |
959 proftime_T *tm; | |
960 { | 949 { |
961 # ifdef WIN3264 | 950 # ifdef WIN3264 |
962 QueryPerformanceCounter(tm); | 951 QueryPerformanceCounter(tm); |
963 # else | 952 # else |
964 gettimeofday(tm, NULL); | 953 gettimeofday(tm, NULL); |
967 | 956 |
968 /* | 957 /* |
969 * Compute the elapsed time from "tm" till now and store in "tm". | 958 * Compute the elapsed time from "tm" till now and store in "tm". |
970 */ | 959 */ |
971 void | 960 void |
972 profile_end(tm) | 961 profile_end(proftime_T *tm) |
973 proftime_T *tm; | |
974 { | 962 { |
975 proftime_T now; | 963 proftime_T now; |
976 | 964 |
977 # ifdef WIN3264 | 965 # ifdef WIN3264 |
978 QueryPerformanceCounter(&now); | 966 QueryPerformanceCounter(&now); |
991 | 979 |
992 /* | 980 /* |
993 * Subtract the time "tm2" from "tm". | 981 * Subtract the time "tm2" from "tm". |
994 */ | 982 */ |
995 void | 983 void |
996 profile_sub(tm, tm2) | 984 profile_sub(proftime_T *tm, proftime_T *tm2) |
997 proftime_T *tm, *tm2; | |
998 { | 985 { |
999 # ifdef WIN3264 | 986 # ifdef WIN3264 |
1000 tm->QuadPart -= tm2->QuadPart; | 987 tm->QuadPart -= tm2->QuadPart; |
1001 # else | 988 # else |
1002 tm->tv_usec -= tm2->tv_usec; | 989 tm->tv_usec -= tm2->tv_usec; |
1012 /* | 999 /* |
1013 * Return a string that represents the time in "tm". | 1000 * Return a string that represents the time in "tm". |
1014 * Uses a static buffer! | 1001 * Uses a static buffer! |
1015 */ | 1002 */ |
1016 char * | 1003 char * |
1017 profile_msg(tm) | 1004 profile_msg(proftime_T *tm) |
1018 proftime_T *tm; | |
1019 { | 1005 { |
1020 static char buf[50]; | 1006 static char buf[50]; |
1021 | 1007 |
1022 # ifdef WIN3264 | 1008 # ifdef WIN3264 |
1023 LARGE_INTEGER fr; | 1009 LARGE_INTEGER fr; |
1032 | 1018 |
1033 /* | 1019 /* |
1034 * Put the time "msec" past now in "tm". | 1020 * Put the time "msec" past now in "tm". |
1035 */ | 1021 */ |
1036 void | 1022 void |
1037 profile_setlimit(msec, tm) | 1023 profile_setlimit(long msec, proftime_T *tm) |
1038 long msec; | |
1039 proftime_T *tm; | |
1040 { | 1024 { |
1041 if (msec <= 0) /* no limit */ | 1025 if (msec <= 0) /* no limit */ |
1042 profile_zero(tm); | 1026 profile_zero(tm); |
1043 else | 1027 else |
1044 { | 1028 { |
1061 | 1045 |
1062 /* | 1046 /* |
1063 * Return TRUE if the current time is past "tm". | 1047 * Return TRUE if the current time is past "tm". |
1064 */ | 1048 */ |
1065 int | 1049 int |
1066 profile_passed_limit(tm) | 1050 profile_passed_limit(proftime_T *tm) |
1067 proftime_T *tm; | |
1068 { | 1051 { |
1069 proftime_T now; | 1052 proftime_T now; |
1070 | 1053 |
1071 # ifdef WIN3264 | 1054 # ifdef WIN3264 |
1072 if (tm->QuadPart == 0) /* timer was not set */ | 1055 if (tm->QuadPart == 0) /* timer was not set */ |
1084 | 1067 |
1085 /* | 1068 /* |
1086 * Set the time in "tm" to zero. | 1069 * Set the time in "tm" to zero. |
1087 */ | 1070 */ |
1088 void | 1071 void |
1089 profile_zero(tm) | 1072 profile_zero(proftime_T *tm) |
1090 proftime_T *tm; | |
1091 { | 1073 { |
1092 # ifdef WIN3264 | 1074 # ifdef WIN3264 |
1093 tm->QuadPart = 0; | 1075 tm->QuadPart = 0; |
1094 # else | 1076 # else |
1095 tm->tv_usec = 0; | 1077 tm->tv_usec = 0; |
1106 | 1088 |
1107 /* | 1089 /* |
1108 * Divide the time "tm" by "count" and store in "tm2". | 1090 * Divide the time "tm" by "count" and store in "tm2". |
1109 */ | 1091 */ |
1110 void | 1092 void |
1111 profile_divide(tm, count, tm2) | 1093 profile_divide(proftime_T *tm, int count, proftime_T *tm2) |
1112 proftime_T *tm; | |
1113 proftime_T *tm2; | |
1114 int count; | |
1115 { | 1094 { |
1116 if (count == 0) | 1095 if (count == 0) |
1117 profile_zero(tm2); | 1096 profile_zero(tm2); |
1118 else | 1097 else |
1119 { | 1098 { |
1139 | 1118 |
1140 /* | 1119 /* |
1141 * Add the time "tm2" to "tm". | 1120 * Add the time "tm2" to "tm". |
1142 */ | 1121 */ |
1143 void | 1122 void |
1144 profile_add(tm, tm2) | 1123 profile_add(proftime_T *tm, proftime_T *tm2) |
1145 proftime_T *tm, *tm2; | |
1146 { | 1124 { |
1147 # ifdef WIN3264 | 1125 # ifdef WIN3264 |
1148 tm->QuadPart += tm2->QuadPart; | 1126 tm->QuadPart += tm2->QuadPart; |
1149 # else | 1127 # else |
1150 tm->tv_usec += tm2->tv_usec; | 1128 tm->tv_usec += tm2->tv_usec; |
1159 | 1137 |
1160 /* | 1138 /* |
1161 * Add the "self" time from the total time and the children's time. | 1139 * Add the "self" time from the total time and the children's time. |
1162 */ | 1140 */ |
1163 void | 1141 void |
1164 profile_self(self, total, children) | 1142 profile_self(proftime_T *self, proftime_T *total, proftime_T *children) |
1165 proftime_T *self, *total, *children; | |
1166 { | 1143 { |
1167 /* Check that the result won't be negative. Can happen with recursive | 1144 /* Check that the result won't be negative. Can happen with recursive |
1168 * calls. */ | 1145 * calls. */ |
1169 #ifdef WIN3264 | 1146 #ifdef WIN3264 |
1170 if (total->QuadPart <= children->QuadPart) | 1147 if (total->QuadPart <= children->QuadPart) |
1181 | 1158 |
1182 /* | 1159 /* |
1183 * Get the current waittime. | 1160 * Get the current waittime. |
1184 */ | 1161 */ |
1185 void | 1162 void |
1186 profile_get_wait(tm) | 1163 profile_get_wait(proftime_T *tm) |
1187 proftime_T *tm; | |
1188 { | 1164 { |
1189 *tm = prof_wait_time; | 1165 *tm = prof_wait_time; |
1190 } | 1166 } |
1191 | 1167 |
1192 /* | 1168 /* |
1193 * Subtract the passed waittime since "tm" from "tma". | 1169 * Subtract the passed waittime since "tm" from "tma". |
1194 */ | 1170 */ |
1195 void | 1171 void |
1196 profile_sub_wait(tm, tma) | 1172 profile_sub_wait(proftime_T *tm, proftime_T *tma) |
1197 proftime_T *tm, *tma; | |
1198 { | 1173 { |
1199 proftime_T tm3 = prof_wait_time; | 1174 proftime_T tm3 = prof_wait_time; |
1200 | 1175 |
1201 profile_sub(&tm3, tm); | 1176 profile_sub(&tm3, tm); |
1202 profile_sub(tma, &tm3); | 1177 profile_sub(tma, &tm3); |
1204 | 1179 |
1205 /* | 1180 /* |
1206 * Return TRUE if "tm1" and "tm2" are equal. | 1181 * Return TRUE if "tm1" and "tm2" are equal. |
1207 */ | 1182 */ |
1208 int | 1183 int |
1209 profile_equal(tm1, tm2) | 1184 profile_equal(proftime_T *tm1, proftime_T *tm2) |
1210 proftime_T *tm1, *tm2; | |
1211 { | 1185 { |
1212 # ifdef WIN3264 | 1186 # ifdef WIN3264 |
1213 return (tm1->QuadPart == tm2->QuadPart); | 1187 return (tm1->QuadPart == tm2->QuadPart); |
1214 # else | 1188 # else |
1215 return (tm1->tv_usec == tm2->tv_usec && tm1->tv_sec == tm2->tv_sec); | 1189 return (tm1->tv_usec == tm2->tv_usec && tm1->tv_sec == tm2->tv_sec); |
1218 | 1192 |
1219 /* | 1193 /* |
1220 * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2" | 1194 * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2" |
1221 */ | 1195 */ |
1222 int | 1196 int |
1223 profile_cmp(tm1, tm2) | 1197 profile_cmp(const proftime_T *tm1, const proftime_T *tm2) |
1224 const proftime_T *tm1, *tm2; | |
1225 { | 1198 { |
1226 # ifdef WIN3264 | 1199 # ifdef WIN3264 |
1227 return (int)(tm2->QuadPart - tm1->QuadPart); | 1200 return (int)(tm2->QuadPart - tm1->QuadPart); |
1228 # else | 1201 # else |
1229 if (tm1->tv_sec == tm2->tv_sec) | 1202 if (tm1->tv_sec == tm2->tv_sec) |
1237 | 1210 |
1238 /* | 1211 /* |
1239 * ":profile cmd args" | 1212 * ":profile cmd args" |
1240 */ | 1213 */ |
1241 void | 1214 void |
1242 ex_profile(eap) | 1215 ex_profile(exarg_T *eap) |
1243 exarg_T *eap; | |
1244 { | 1216 { |
1245 char_u *e; | 1217 char_u *e; |
1246 int len; | 1218 int len; |
1247 | 1219 |
1248 e = skiptowhite(eap->arg); | 1220 e = skiptowhite(eap->arg); |
1306 /* | 1278 /* |
1307 * Function given to ExpandGeneric() to obtain the profile command | 1279 * Function given to ExpandGeneric() to obtain the profile command |
1308 * specific expansion. | 1280 * specific expansion. |
1309 */ | 1281 */ |
1310 char_u * | 1282 char_u * |
1311 get_profile_name(xp, idx) | 1283 get_profile_name(expand_T *xp UNUSED, int idx) |
1312 expand_T *xp UNUSED; | |
1313 int idx; | |
1314 { | 1284 { |
1315 switch (pexpand_what) | 1285 switch (pexpand_what) |
1316 { | 1286 { |
1317 case PEXP_SUBCMD: | 1287 case PEXP_SUBCMD: |
1318 return (char_u *)pexpand_cmds[idx]; | 1288 return (char_u *)pexpand_cmds[idx]; |
1324 | 1294 |
1325 /* | 1295 /* |
1326 * Handle command line completion for :profile command. | 1296 * Handle command line completion for :profile command. |
1327 */ | 1297 */ |
1328 void | 1298 void |
1329 set_context_in_profile_cmd(xp, arg) | 1299 set_context_in_profile_cmd(expand_T *xp, char_u *arg) |
1330 expand_T *xp; | |
1331 char_u *arg; | |
1332 { | 1300 { |
1333 char_u *end_subcmd; | 1301 char_u *end_subcmd; |
1334 | 1302 |
1335 /* Default: expand subcommands. */ | 1303 /* Default: expand subcommands. */ |
1336 xp->xp_context = EXPAND_PROFILE; | 1304 xp->xp_context = EXPAND_PROFILE; |
1354 | 1322 |
1355 /* | 1323 /* |
1356 * Dump the profiling info. | 1324 * Dump the profiling info. |
1357 */ | 1325 */ |
1358 void | 1326 void |
1359 profile_dump() | 1327 profile_dump(void) |
1360 { | 1328 { |
1361 FILE *fd; | 1329 FILE *fd; |
1362 | 1330 |
1363 if (profile_fname != NULL) | 1331 if (profile_fname != NULL) |
1364 { | 1332 { |
1376 | 1344 |
1377 /* | 1345 /* |
1378 * Start profiling script "fp". | 1346 * Start profiling script "fp". |
1379 */ | 1347 */ |
1380 static void | 1348 static void |
1381 script_do_profile(si) | 1349 script_do_profile(scriptitem_T *si) |
1382 scriptitem_T *si; | |
1383 { | 1350 { |
1384 si->sn_pr_count = 0; | 1351 si->sn_pr_count = 0; |
1385 profile_zero(&si->sn_pr_total); | 1352 profile_zero(&si->sn_pr_total); |
1386 profile_zero(&si->sn_pr_self); | 1353 profile_zero(&si->sn_pr_self); |
1387 | 1354 |
1393 | 1360 |
1394 /* | 1361 /* |
1395 * save time when starting to invoke another script or function. | 1362 * save time when starting to invoke another script or function. |
1396 */ | 1363 */ |
1397 void | 1364 void |
1398 script_prof_save(tm) | 1365 script_prof_save( |
1399 proftime_T *tm; /* place to store wait time */ | 1366 proftime_T *tm) /* place to store wait time */ |
1400 { | 1367 { |
1401 scriptitem_T *si; | 1368 scriptitem_T *si; |
1402 | 1369 |
1403 if (current_SID > 0 && current_SID <= script_items.ga_len) | 1370 if (current_SID > 0 && current_SID <= script_items.ga_len) |
1404 { | 1371 { |
1411 | 1378 |
1412 /* | 1379 /* |
1413 * Count time spent in children after invoking another script or function. | 1380 * Count time spent in children after invoking another script or function. |
1414 */ | 1381 */ |
1415 void | 1382 void |
1416 script_prof_restore(tm) | 1383 script_prof_restore(proftime_T *tm) |
1417 proftime_T *tm; | |
1418 { | 1384 { |
1419 scriptitem_T *si; | 1385 scriptitem_T *si; |
1420 | 1386 |
1421 if (current_SID > 0 && current_SID <= script_items.ga_len) | 1387 if (current_SID > 0 && current_SID <= script_items.ga_len) |
1422 { | 1388 { |
1435 | 1401 |
1436 /* | 1402 /* |
1437 * Called when starting to wait for the user to type a character. | 1403 * Called when starting to wait for the user to type a character. |
1438 */ | 1404 */ |
1439 void | 1405 void |
1440 prof_inchar_enter() | 1406 prof_inchar_enter(void) |
1441 { | 1407 { |
1442 profile_start(&inchar_time); | 1408 profile_start(&inchar_time); |
1443 } | 1409 } |
1444 | 1410 |
1445 /* | 1411 /* |
1446 * Called when finished waiting for the user to type a character. | 1412 * Called when finished waiting for the user to type a character. |
1447 */ | 1413 */ |
1448 void | 1414 void |
1449 prof_inchar_exit() | 1415 prof_inchar_exit(void) |
1450 { | 1416 { |
1451 profile_end(&inchar_time); | 1417 profile_end(&inchar_time); |
1452 profile_add(&prof_wait_time, &inchar_time); | 1418 profile_add(&prof_wait_time, &inchar_time); |
1453 } | 1419 } |
1454 | 1420 |
1455 /* | 1421 /* |
1456 * Dump the profiling results for all scripts in file "fd". | 1422 * Dump the profiling results for all scripts in file "fd". |
1457 */ | 1423 */ |
1458 static void | 1424 static void |
1459 script_dump_profile(fd) | 1425 script_dump_profile(FILE *fd) |
1460 FILE *fd; | |
1461 { | 1426 { |
1462 int id; | 1427 int id; |
1463 scriptitem_T *si; | 1428 scriptitem_T *si; |
1464 int i; | 1429 int i; |
1465 FILE *sfd; | 1430 FILE *sfd; |
1513 /* | 1478 /* |
1514 * Return TRUE when a function defined in the current script should be | 1479 * Return TRUE when a function defined in the current script should be |
1515 * profiled. | 1480 * profiled. |
1516 */ | 1481 */ |
1517 int | 1482 int |
1518 prof_def_func() | 1483 prof_def_func(void) |
1519 { | 1484 { |
1520 if (current_SID > 0) | 1485 if (current_SID > 0) |
1521 return SCRIPT_ITEM(current_SID).sn_pr_force; | 1486 return SCRIPT_ITEM(current_SID).sn_pr_force; |
1522 return FALSE; | 1487 return FALSE; |
1523 } | 1488 } |
1530 * Careful: autocommands may make "buf" invalid! | 1495 * Careful: autocommands may make "buf" invalid! |
1531 * | 1496 * |
1532 * return FAIL for failure, OK otherwise | 1497 * return FAIL for failure, OK otherwise |
1533 */ | 1498 */ |
1534 int | 1499 int |
1535 autowrite(buf, forceit) | 1500 autowrite(buf_T *buf, int forceit) |
1536 buf_T *buf; | |
1537 int forceit; | |
1538 { | 1501 { |
1539 int r; | 1502 int r; |
1540 | 1503 |
1541 if (!(p_aw || p_awa) || !p_write | 1504 if (!(p_aw || p_awa) || !p_write |
1542 #ifdef FEAT_QUICKFIX | 1505 #ifdef FEAT_QUICKFIX |
1556 | 1519 |
1557 /* | 1520 /* |
1558 * flush all buffers, except the ones that are readonly | 1521 * flush all buffers, except the ones that are readonly |
1559 */ | 1522 */ |
1560 void | 1523 void |
1561 autowrite_all() | 1524 autowrite_all(void) |
1562 { | 1525 { |
1563 buf_T *buf; | 1526 buf_T *buf; |
1564 | 1527 |
1565 if (!(p_aw || p_awa) || !p_write) | 1528 if (!(p_aw || p_awa) || !p_write) |
1566 return; | 1529 return; |
1579 /* | 1542 /* |
1580 * Return TRUE if buffer was changed and cannot be abandoned. | 1543 * Return TRUE if buffer was changed and cannot be abandoned. |
1581 * For flags use the CCGD_ values. | 1544 * For flags use the CCGD_ values. |
1582 */ | 1545 */ |
1583 int | 1546 int |
1584 check_changed(buf, flags) | 1547 check_changed(buf_T *buf, int flags) |
1585 buf_T *buf; | |
1586 int flags; | |
1587 { | 1548 { |
1588 int forceit = (flags & CCGD_FORCEIT); | 1549 int forceit = (flags & CCGD_FORCEIT); |
1589 | 1550 |
1590 if ( !forceit | 1551 if ( !forceit |
1591 && bufIsChanged(buf) | 1552 && bufIsChanged(buf) |
1635 #if defined(FEAT_BROWSE) || defined(PROTO) | 1596 #if defined(FEAT_BROWSE) || defined(PROTO) |
1636 /* | 1597 /* |
1637 * When wanting to write a file without a file name, ask the user for a name. | 1598 * When wanting to write a file without a file name, ask the user for a name. |
1638 */ | 1599 */ |
1639 void | 1600 void |
1640 browse_save_fname(buf) | 1601 browse_save_fname(buf_T *buf) |
1641 buf_T *buf; | |
1642 { | 1602 { |
1643 if (buf->b_fname == NULL) | 1603 if (buf->b_fname == NULL) |
1644 { | 1604 { |
1645 char_u *fname; | 1605 char_u *fname; |
1646 | 1606 |
1659 /* | 1619 /* |
1660 * Ask the user what to do when abandoning a changed buffer. | 1620 * Ask the user what to do when abandoning a changed buffer. |
1661 * Must check 'write' option first! | 1621 * Must check 'write' option first! |
1662 */ | 1622 */ |
1663 void | 1623 void |
1664 dialog_changed(buf, checkall) | 1624 dialog_changed( |
1665 buf_T *buf; | 1625 buf_T *buf, |
1666 int checkall; /* may abandon all changed buffers */ | 1626 int checkall) /* may abandon all changed buffers */ |
1667 { | 1627 { |
1668 char_u buff[DIALOG_MSG_SIZE]; | 1628 char_u buff[DIALOG_MSG_SIZE]; |
1669 int ret; | 1629 int ret; |
1670 buf_T *buf2; | 1630 buf_T *buf2; |
1671 exarg_T ea; | 1631 exarg_T ea; |
1744 /* | 1704 /* |
1745 * Return TRUE if the buffer "buf" can be abandoned, either by making it | 1705 * Return TRUE if the buffer "buf" can be abandoned, either by making it |
1746 * hidden, autowriting it or unloading it. | 1706 * hidden, autowriting it or unloading it. |
1747 */ | 1707 */ |
1748 int | 1708 int |
1749 can_abandon(buf, forceit) | 1709 can_abandon(buf_T *buf, int forceit) |
1750 buf_T *buf; | |
1751 int forceit; | |
1752 { | 1710 { |
1753 return ( P_HID(buf) | 1711 return ( P_HID(buf) |
1754 || !bufIsChanged(buf) | 1712 || !bufIsChanged(buf) |
1755 || buf->b_nwindows > 1 | 1713 || buf->b_nwindows > 1 |
1756 || autowrite(buf, forceit) == OK | 1714 || autowrite(buf, forceit) == OK |
1761 | 1719 |
1762 /* | 1720 /* |
1763 * Add a buffer number to "bufnrs", unless it's already there. | 1721 * Add a buffer number to "bufnrs", unless it's already there. |
1764 */ | 1722 */ |
1765 static void | 1723 static void |
1766 add_bufnum(bufnrs, bufnump, nr) | 1724 add_bufnum(int *bufnrs, int *bufnump, int nr) |
1767 int *bufnrs; | |
1768 int *bufnump; | |
1769 int nr; | |
1770 { | 1725 { |
1771 int i; | 1726 int i; |
1772 | 1727 |
1773 for (i = 0; i < *bufnump; ++i) | 1728 for (i = 0; i < *bufnump; ++i) |
1774 if (bufnrs[i] == nr) | 1729 if (bufnrs[i] == nr) |
1782 * That changed buffer becomes the current buffer. | 1737 * That changed buffer becomes the current buffer. |
1783 * When "unload" is true the current buffer is unloaded instead of making it | 1738 * When "unload" is true the current buffer is unloaded instead of making it |
1784 * hidden. This is used for ":q!". | 1739 * hidden. This is used for ":q!". |
1785 */ | 1740 */ |
1786 int | 1741 int |
1787 check_changed_any(hidden, unload) | 1742 check_changed_any( |
1788 int hidden; /* Only check hidden buffers */ | 1743 int hidden, /* Only check hidden buffers */ |
1789 int unload; | 1744 int unload) |
1790 { | 1745 { |
1791 int ret = FALSE; | 1746 int ret = FALSE; |
1792 buf_T *buf; | 1747 buf_T *buf; |
1793 int save; | 1748 int save; |
1794 int i; | 1749 int i; |
1907 /* | 1862 /* |
1908 * return FAIL if there is no file name, OK if there is one | 1863 * return FAIL if there is no file name, OK if there is one |
1909 * give error message for FAIL | 1864 * give error message for FAIL |
1910 */ | 1865 */ |
1911 int | 1866 int |
1912 check_fname() | 1867 check_fname(void) |
1913 { | 1868 { |
1914 if (curbuf->b_ffname == NULL) | 1869 if (curbuf->b_ffname == NULL) |
1915 { | 1870 { |
1916 EMSG(_(e_noname)); | 1871 EMSG(_(e_noname)); |
1917 return FAIL; | 1872 return FAIL; |
1923 * flush the contents of a buffer, unless it has no file name | 1878 * flush the contents of a buffer, unless it has no file name |
1924 * | 1879 * |
1925 * return FAIL for failure, OK otherwise | 1880 * return FAIL for failure, OK otherwise |
1926 */ | 1881 */ |
1927 int | 1882 int |
1928 buf_write_all(buf, forceit) | 1883 buf_write_all(buf_T *buf, int forceit) |
1929 buf_T *buf; | |
1930 int forceit; | |
1931 { | 1884 { |
1932 int retval; | 1885 int retval; |
1933 #ifdef FEAT_AUTOCMD | 1886 #ifdef FEAT_AUTOCMD |
1934 buf_T *old_curbuf = curbuf; | 1887 buf_T *old_curbuf = curbuf; |
1935 #endif | 1888 #endif |
1966 * Isolate one argument, taking backticks. | 1919 * Isolate one argument, taking backticks. |
1967 * Changes the argument in-place, puts a NUL after it. Backticks remain. | 1920 * Changes the argument in-place, puts a NUL after it. Backticks remain. |
1968 * Return a pointer to the start of the next argument. | 1921 * Return a pointer to the start of the next argument. |
1969 */ | 1922 */ |
1970 static char_u * | 1923 static char_u * |
1971 do_one_arg(str) | 1924 do_one_arg(char_u *str) |
1972 char_u *str; | |
1973 { | 1925 { |
1974 char_u *p; | 1926 char_u *p; |
1975 int inbacktick; | 1927 int inbacktick; |
1976 | 1928 |
1977 inbacktick = FALSE; | 1929 inbacktick = FALSE; |
2003 /* | 1955 /* |
2004 * Separate the arguments in "str" and return a list of pointers in the | 1956 * Separate the arguments in "str" and return a list of pointers in the |
2005 * growarray "gap". | 1957 * growarray "gap". |
2006 */ | 1958 */ |
2007 int | 1959 int |
2008 get_arglist(gap, str) | 1960 get_arglist(garray_T *gap, char_u *str) |
2009 garray_T *gap; | |
2010 char_u *str; | |
2011 { | 1961 { |
2012 ga_init2(gap, (int)sizeof(char_u *), 20); | 1962 ga_init2(gap, (int)sizeof(char_u *), 20); |
2013 while (*str != NUL) | 1963 while (*str != NUL) |
2014 { | 1964 { |
2015 if (ga_grow(gap, 1) == FAIL) | 1965 if (ga_grow(gap, 1) == FAIL) |
2030 * Parse a list of arguments (file names), expand them and return in | 1980 * Parse a list of arguments (file names), expand them and return in |
2031 * "fnames[fcountp]". When "wig" is TRUE, removes files matching 'wildignore'. | 1981 * "fnames[fcountp]". When "wig" is TRUE, removes files matching 'wildignore'. |
2032 * Return FAIL or OK. | 1982 * Return FAIL or OK. |
2033 */ | 1983 */ |
2034 int | 1984 int |
2035 get_arglist_exp(str, fcountp, fnamesp, wig) | 1985 get_arglist_exp( |
2036 char_u *str; | 1986 char_u *str, |
2037 int *fcountp; | 1987 int *fcountp, |
2038 char_u ***fnamesp; | 1988 char_u ***fnamesp, |
2039 int wig; | 1989 int wig) |
2040 { | 1990 { |
2041 garray_T ga; | 1991 garray_T ga; |
2042 int i; | 1992 int i; |
2043 | 1993 |
2044 if (get_arglist(&ga, str) == FAIL) | 1994 if (get_arglist(&ga, str) == FAIL) |
2058 #if defined(FEAT_GUI) || defined(FEAT_CLIENTSERVER) || defined(PROTO) | 2008 #if defined(FEAT_GUI) || defined(FEAT_CLIENTSERVER) || defined(PROTO) |
2059 /* | 2009 /* |
2060 * Redefine the argument list. | 2010 * Redefine the argument list. |
2061 */ | 2011 */ |
2062 void | 2012 void |
2063 set_arglist(str) | 2013 set_arglist(char_u *str) |
2064 char_u *str; | |
2065 { | 2014 { |
2066 do_arglist(str, AL_SET, 0); | 2015 do_arglist(str, AL_SET, 0); |
2067 } | 2016 } |
2068 #endif | 2017 #endif |
2069 | 2018 |
2073 * "what" == AL_DEL: remove files in 'str' from the argument list. | 2022 * "what" == AL_DEL: remove files in 'str' from the argument list. |
2074 * | 2023 * |
2075 * Return FAIL for failure, OK otherwise. | 2024 * Return FAIL for failure, OK otherwise. |
2076 */ | 2025 */ |
2077 static int | 2026 static int |
2078 do_arglist(str, what, after) | 2027 do_arglist( |
2079 char_u *str; | 2028 char_u *str, |
2080 int what UNUSED; | 2029 int what UNUSED, |
2081 int after UNUSED; /* 0 means before first one */ | 2030 int after UNUSED) /* 0 means before first one */ |
2082 { | 2031 { |
2083 garray_T new_ga; | 2032 garray_T new_ga; |
2084 int exp_count; | 2033 int exp_count; |
2085 char_u **exp_files; | 2034 char_u **exp_files; |
2086 int i; | 2035 int i; |
2181 | 2130 |
2182 /* | 2131 /* |
2183 * Check the validity of the arg_idx for each other window. | 2132 * Check the validity of the arg_idx for each other window. |
2184 */ | 2133 */ |
2185 static void | 2134 static void |
2186 alist_check_arg_idx() | 2135 alist_check_arg_idx(void) |
2187 { | 2136 { |
2188 #ifdef FEAT_WINDOWS | 2137 #ifdef FEAT_WINDOWS |
2189 win_T *win; | 2138 win_T *win; |
2190 tabpage_T *tp; | 2139 tabpage_T *tp; |
2191 | 2140 |
2200 /* | 2149 /* |
2201 * Return TRUE if window "win" is editing the file at the current argument | 2150 * Return TRUE if window "win" is editing the file at the current argument |
2202 * index. | 2151 * index. |
2203 */ | 2152 */ |
2204 static int | 2153 static int |
2205 editing_arg_idx(win) | 2154 editing_arg_idx(win_T *win) |
2206 win_T *win; | |
2207 { | 2155 { |
2208 return !(win->w_arg_idx >= WARGCOUNT(win) | 2156 return !(win->w_arg_idx >= WARGCOUNT(win) |
2209 || (win->w_buffer->b_fnum | 2157 || (win->w_buffer->b_fnum |
2210 != WARGLIST(win)[win->w_arg_idx].ae_fnum | 2158 != WARGLIST(win)[win->w_arg_idx].ae_fnum |
2211 && (win->w_buffer->b_ffname == NULL | 2159 && (win->w_buffer->b_ffname == NULL |
2216 | 2164 |
2217 /* | 2165 /* |
2218 * Check if window "win" is editing the w_arg_idx file in its argument list. | 2166 * Check if window "win" is editing the w_arg_idx file in its argument list. |
2219 */ | 2167 */ |
2220 void | 2168 void |
2221 check_arg_idx(win) | 2169 check_arg_idx(win_T *win) |
2222 win_T *win; | |
2223 { | 2170 { |
2224 if (WARGCOUNT(win) > 1 && !editing_arg_idx(win)) | 2171 if (WARGCOUNT(win) > 1 && !editing_arg_idx(win)) |
2225 { | 2172 { |
2226 /* We are not editing the current entry in the argument list. | 2173 /* We are not editing the current entry in the argument list. |
2227 * Set "arg_had_last" if we are editing the last one. */ | 2174 * Set "arg_had_last" if we are editing the last one. */ |
2255 | 2202 |
2256 /* | 2203 /* |
2257 * ":args", ":argslocal" and ":argsglobal". | 2204 * ":args", ":argslocal" and ":argsglobal". |
2258 */ | 2205 */ |
2259 void | 2206 void |
2260 ex_args(eap) | 2207 ex_args(exarg_T *eap) |
2261 exarg_T *eap; | |
2262 { | 2208 { |
2263 int i; | 2209 int i; |
2264 | 2210 |
2265 if (eap->cmdidx != CMD_args) | 2211 if (eap->cmdidx != CMD_args) |
2266 { | 2212 { |
2332 | 2278 |
2333 /* | 2279 /* |
2334 * ":previous", ":sprevious", ":Next" and ":sNext". | 2280 * ":previous", ":sprevious", ":Next" and ":sNext". |
2335 */ | 2281 */ |
2336 void | 2282 void |
2337 ex_previous(eap) | 2283 ex_previous(exarg_T *eap) |
2338 exarg_T *eap; | |
2339 { | 2284 { |
2340 /* If past the last one already, go to the last one. */ | 2285 /* If past the last one already, go to the last one. */ |
2341 if (curwin->w_arg_idx - (int)eap->line2 >= ARGCOUNT) | 2286 if (curwin->w_arg_idx - (int)eap->line2 >= ARGCOUNT) |
2342 do_argfile(eap, ARGCOUNT - 1); | 2287 do_argfile(eap, ARGCOUNT - 1); |
2343 else | 2288 else |
2346 | 2291 |
2347 /* | 2292 /* |
2348 * ":rewind", ":first", ":sfirst" and ":srewind". | 2293 * ":rewind", ":first", ":sfirst" and ":srewind". |
2349 */ | 2294 */ |
2350 void | 2295 void |
2351 ex_rewind(eap) | 2296 ex_rewind(exarg_T *eap) |
2352 exarg_T *eap; | |
2353 { | 2297 { |
2354 do_argfile(eap, 0); | 2298 do_argfile(eap, 0); |
2355 } | 2299 } |
2356 | 2300 |
2357 /* | 2301 /* |
2358 * ":last" and ":slast". | 2302 * ":last" and ":slast". |
2359 */ | 2303 */ |
2360 void | 2304 void |
2361 ex_last(eap) | 2305 ex_last(exarg_T *eap) |
2362 exarg_T *eap; | |
2363 { | 2306 { |
2364 do_argfile(eap, ARGCOUNT - 1); | 2307 do_argfile(eap, ARGCOUNT - 1); |
2365 } | 2308 } |
2366 | 2309 |
2367 /* | 2310 /* |
2368 * ":argument" and ":sargument". | 2311 * ":argument" and ":sargument". |
2369 */ | 2312 */ |
2370 void | 2313 void |
2371 ex_argument(eap) | 2314 ex_argument(exarg_T *eap) |
2372 exarg_T *eap; | |
2373 { | 2315 { |
2374 int i; | 2316 int i; |
2375 | 2317 |
2376 if (eap->addr_count > 0) | 2318 if (eap->addr_count > 0) |
2377 i = eap->line2 - 1; | 2319 i = eap->line2 - 1; |
2382 | 2324 |
2383 /* | 2325 /* |
2384 * Edit file "argn" of the argument lists. | 2326 * Edit file "argn" of the argument lists. |
2385 */ | 2327 */ |
2386 void | 2328 void |
2387 do_argfile(eap, argn) | 2329 do_argfile(exarg_T *eap, int argn) |
2388 exarg_T *eap; | |
2389 int argn; | |
2390 { | 2330 { |
2391 int other; | 2331 int other; |
2392 char_u *p; | 2332 char_u *p; |
2393 int old_arg_idx = curwin->w_arg_idx; | 2333 int old_arg_idx = curwin->w_arg_idx; |
2394 | 2334 |
2462 | 2402 |
2463 /* | 2403 /* |
2464 * ":next", and commands that behave like it. | 2404 * ":next", and commands that behave like it. |
2465 */ | 2405 */ |
2466 void | 2406 void |
2467 ex_next(eap) | 2407 ex_next(exarg_T *eap) |
2468 exarg_T *eap; | |
2469 { | 2408 { |
2470 int i; | 2409 int i; |
2471 | 2410 |
2472 /* | 2411 /* |
2473 * check for changed buffer now, if this fails the argument list is not | 2412 * check for changed buffer now, if this fails the argument list is not |
2494 #ifdef FEAT_LISTCMDS | 2433 #ifdef FEAT_LISTCMDS |
2495 /* | 2434 /* |
2496 * ":argedit" | 2435 * ":argedit" |
2497 */ | 2436 */ |
2498 void | 2437 void |
2499 ex_argedit(eap) | 2438 ex_argedit(exarg_T *eap) |
2500 exarg_T *eap; | |
2501 { | 2439 { |
2502 int fnum; | 2440 int fnum; |
2503 int i; | 2441 int i; |
2504 char_u *s; | 2442 char_u *s; |
2505 | 2443 |
2531 | 2469 |
2532 /* | 2470 /* |
2533 * ":argadd" | 2471 * ":argadd" |
2534 */ | 2472 */ |
2535 void | 2473 void |
2536 ex_argadd(eap) | 2474 ex_argadd(exarg_T *eap) |
2537 exarg_T *eap; | |
2538 { | 2475 { |
2539 do_arglist(eap->arg, AL_ADD, | 2476 do_arglist(eap->arg, AL_ADD, |
2540 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); | 2477 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); |
2541 #ifdef FEAT_TITLE | 2478 #ifdef FEAT_TITLE |
2542 maketitle(); | 2479 maketitle(); |
2545 | 2482 |
2546 /* | 2483 /* |
2547 * ":argdelete" | 2484 * ":argdelete" |
2548 */ | 2485 */ |
2549 void | 2486 void |
2550 ex_argdelete(eap) | 2487 ex_argdelete(exarg_T *eap) |
2551 exarg_T *eap; | |
2552 { | 2488 { |
2553 int i; | 2489 int i; |
2554 int n; | 2490 int n; |
2555 | 2491 |
2556 if (eap->addr_count > 0) | 2492 if (eap->addr_count > 0) |
2589 | 2525 |
2590 /* | 2526 /* |
2591 * ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo" | 2527 * ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo" |
2592 */ | 2528 */ |
2593 void | 2529 void |
2594 ex_listdo(eap) | 2530 ex_listdo(exarg_T *eap) |
2595 exarg_T *eap; | |
2596 { | 2531 { |
2597 int i; | 2532 int i; |
2598 #ifdef FEAT_WINDOWS | 2533 #ifdef FEAT_WINDOWS |
2599 win_T *wp; | 2534 win_T *wp; |
2600 tabpage_T *tp; | 2535 tabpage_T *tp; |
2838 * The file names in files[count] must have been allocated and are taken over. | 2773 * The file names in files[count] must have been allocated and are taken over. |
2839 * Files[] itself is not taken over. | 2774 * Files[] itself is not taken over. |
2840 * Returns index of first added argument. Returns -1 when failed (out of mem). | 2775 * Returns index of first added argument. Returns -1 when failed (out of mem). |
2841 */ | 2776 */ |
2842 static int | 2777 static int |
2843 alist_add_list(count, files, after) | 2778 alist_add_list( |
2844 int count; | 2779 int count, |
2845 char_u **files; | 2780 char_u **files, |
2846 int after; /* where to add: 0 = before first one */ | 2781 int after) /* where to add: 0 = before first one */ |
2847 { | 2782 { |
2848 int i; | 2783 int i; |
2849 int old_argcount = ARGCOUNT; | 2784 int old_argcount = ARGCOUNT; |
2850 | 2785 |
2851 if (ga_grow(&ALIST(curwin)->al_ga, count) == OK) | 2786 if (ga_grow(&ALIST(curwin)->al_ga, count) == OK) |
2878 #ifdef FEAT_EVAL | 2813 #ifdef FEAT_EVAL |
2879 /* | 2814 /* |
2880 * ":compiler[!] {name}" | 2815 * ":compiler[!] {name}" |
2881 */ | 2816 */ |
2882 void | 2817 void |
2883 ex_compiler(eap) | 2818 ex_compiler(exarg_T *eap) |
2884 exarg_T *eap; | |
2885 { | 2819 { |
2886 char_u *buf; | 2820 char_u *buf; |
2887 char_u *old_cur_comp = NULL; | 2821 char_u *old_cur_comp = NULL; |
2888 char_u *p; | 2822 char_u *p; |
2889 | 2823 |
2952 | 2886 |
2953 /* | 2887 /* |
2954 * ":runtime {name}" | 2888 * ":runtime {name}" |
2955 */ | 2889 */ |
2956 void | 2890 void |
2957 ex_runtime(eap) | 2891 ex_runtime(exarg_T *eap) |
2958 exarg_T *eap; | |
2959 { | 2892 { |
2960 source_runtime(eap->arg, eap->forceit); | 2893 source_runtime(eap->arg, eap->forceit); |
2961 } | 2894 } |
2962 | 2895 |
2963 static void source_callback(char_u *fname, void *cookie); | 2896 static void source_callback(char_u *fname, void *cookie); |
2964 | 2897 |
2965 static void | 2898 static void |
2966 source_callback(fname, cookie) | 2899 source_callback(char_u *fname, void *cookie UNUSED) |
2967 char_u *fname; | |
2968 void *cookie UNUSED; | |
2969 { | 2900 { |
2970 (void)do_source(fname, FALSE, DOSO_NONE); | 2901 (void)do_source(fname, FALSE, DOSO_NONE); |
2971 } | 2902 } |
2972 | 2903 |
2973 /* | 2904 /* |
2975 * "name" can contain wildcards. | 2906 * "name" can contain wildcards. |
2976 * When "all" is TRUE, source all files, otherwise only the first one. | 2907 * When "all" is TRUE, source all files, otherwise only the first one. |
2977 * return FAIL when no file could be sourced, OK otherwise. | 2908 * return FAIL when no file could be sourced, OK otherwise. |
2978 */ | 2909 */ |
2979 int | 2910 int |
2980 source_runtime(name, all) | 2911 source_runtime(char_u *name, int all) |
2981 char_u *name; | |
2982 int all; | |
2983 { | 2912 { |
2984 return do_in_runtimepath(name, all, source_callback, NULL); | 2913 return do_in_runtimepath(name, all, source_callback, NULL); |
2985 } | 2914 } |
2986 | 2915 |
2987 /* | 2916 /* |
2994 * If "name" is NULL calls callback for each entry in runtimepath. Cookie is | 2923 * If "name" is NULL calls callback for each entry in runtimepath. Cookie is |
2995 * passed by reference in this case, setting it to NULL indicates that callback | 2924 * passed by reference in this case, setting it to NULL indicates that callback |
2996 * has done its job. | 2925 * has done its job. |
2997 */ | 2926 */ |
2998 int | 2927 int |
2999 do_in_runtimepath(name, all, callback, cookie) | 2928 do_in_runtimepath( |
3000 char_u *name; | 2929 char_u *name, |
3001 int all; | 2930 int all, |
3002 void (*callback)(char_u *fname, void *ck); | 2931 void (*callback)(char_u *fname, void *ck), |
3003 void *cookie; | 2932 void *cookie) |
3004 { | 2933 { |
3005 char_u *rtp; | 2934 char_u *rtp; |
3006 char_u *np; | 2935 char_u *np; |
3007 char_u *buf; | 2936 char_u *buf; |
3008 char_u *rtp_copy; | 2937 char_u *rtp_copy; |
3101 #if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD) | 3030 #if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD) |
3102 /* | 3031 /* |
3103 * ":options" | 3032 * ":options" |
3104 */ | 3033 */ |
3105 void | 3034 void |
3106 ex_options(eap) | 3035 ex_options( |
3107 exarg_T *eap UNUSED; | 3036 exarg_T *eap UNUSED) |
3108 { | 3037 { |
3109 cmd_source((char_u *)SYS_OPTWIN_FILE, NULL); | 3038 cmd_source((char_u *)SYS_OPTWIN_FILE, NULL); |
3110 } | 3039 } |
3111 #endif | 3040 #endif |
3112 | 3041 |
3113 /* | 3042 /* |
3114 * ":source {fname}" | 3043 * ":source {fname}" |
3115 */ | 3044 */ |
3116 void | 3045 void |
3117 ex_source(eap) | 3046 ex_source(exarg_T *eap) |
3118 exarg_T *eap; | |
3119 { | 3047 { |
3120 #ifdef FEAT_BROWSE | 3048 #ifdef FEAT_BROWSE |
3121 if (cmdmod.browse) | 3049 if (cmdmod.browse) |
3122 { | 3050 { |
3123 char_u *fname = NULL; | 3051 char_u *fname = NULL; |
3134 #endif | 3062 #endif |
3135 cmd_source(eap->arg, eap); | 3063 cmd_source(eap->arg, eap); |
3136 } | 3064 } |
3137 | 3065 |
3138 static void | 3066 static void |
3139 cmd_source(fname, eap) | 3067 cmd_source(char_u *fname, exarg_T *eap) |
3140 char_u *fname; | |
3141 exarg_T *eap; | |
3142 { | 3068 { |
3143 if (*fname == NUL) | 3069 if (*fname == NUL) |
3144 EMSG(_(e_argreq)); | 3070 EMSG(_(e_argreq)); |
3145 | 3071 |
3146 else if (eap != NULL && eap->forceit) | 3072 else if (eap != NULL && eap->forceit) |
3195 #ifdef FEAT_EVAL | 3121 #ifdef FEAT_EVAL |
3196 /* | 3122 /* |
3197 * Return the address holding the next breakpoint line for a source cookie. | 3123 * Return the address holding the next breakpoint line for a source cookie. |
3198 */ | 3124 */ |
3199 linenr_T * | 3125 linenr_T * |
3200 source_breakpoint(cookie) | 3126 source_breakpoint(void *cookie) |
3201 void *cookie; | |
3202 { | 3127 { |
3203 return &((struct source_cookie *)cookie)->breakpoint; | 3128 return &((struct source_cookie *)cookie)->breakpoint; |
3204 } | 3129 } |
3205 | 3130 |
3206 /* | 3131 /* |
3207 * Return the address holding the debug tick for a source cookie. | 3132 * Return the address holding the debug tick for a source cookie. |
3208 */ | 3133 */ |
3209 int * | 3134 int * |
3210 source_dbg_tick(cookie) | 3135 source_dbg_tick(void *cookie) |
3211 void *cookie; | |
3212 { | 3136 { |
3213 return &((struct source_cookie *)cookie)->dbg_tick; | 3137 return &((struct source_cookie *)cookie)->dbg_tick; |
3214 } | 3138 } |
3215 | 3139 |
3216 /* | 3140 /* |
3217 * Return the nesting level for a source cookie. | 3141 * Return the nesting level for a source cookie. |
3218 */ | 3142 */ |
3219 int | 3143 int |
3220 source_level(cookie) | 3144 source_level(void *cookie) |
3221 void *cookie; | |
3222 { | 3145 { |
3223 return ((struct source_cookie *)cookie)->level; | 3146 return ((struct source_cookie *)cookie)->level; |
3224 } | 3147 } |
3225 #endif | 3148 #endif |
3226 | 3149 |
3233 /* | 3156 /* |
3234 * Special function to open a file without handle inheritance. | 3157 * Special function to open a file without handle inheritance. |
3235 * When possible the handle is closed on exec(). | 3158 * When possible the handle is closed on exec(). |
3236 */ | 3159 */ |
3237 static FILE * | 3160 static FILE * |
3238 fopen_noinh_readbin(filename) | 3161 fopen_noinh_readbin(char *filename) |
3239 char *filename; | |
3240 { | 3162 { |
3241 # ifdef WIN32 | 3163 # ifdef WIN32 |
3242 int fd_tmp = mch_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0); | 3164 int fd_tmp = mch_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0); |
3243 # else | 3165 # else |
3244 int fd_tmp = mch_open(filename, O_RDONLY, 0); | 3166 int fd_tmp = mch_open(filename, O_RDONLY, 0); |
3266 * This function may be called recursively! | 3188 * This function may be called recursively! |
3267 * | 3189 * |
3268 * return FAIL if file could not be opened, OK otherwise | 3190 * return FAIL if file could not be opened, OK otherwise |
3269 */ | 3191 */ |
3270 int | 3192 int |
3271 do_source(fname, check_other, is_vimrc) | 3193 do_source( |
3272 char_u *fname; | 3194 char_u *fname, |
3273 int check_other; /* check for .vimrc and _vimrc */ | 3195 int check_other, /* check for .vimrc and _vimrc */ |
3274 int is_vimrc; /* DOSO_ value */ | 3196 int is_vimrc) /* DOSO_ value */ |
3275 { | 3197 { |
3276 struct source_cookie cookie; | 3198 struct source_cookie cookie; |
3277 char_u *save_sourcing_name; | 3199 char_u *save_sourcing_name; |
3278 linenr_T save_sourcing_lnum; | 3200 linenr_T save_sourcing_lnum; |
3279 char_u *p; | 3201 char_u *p; |
3626 | 3548 |
3627 /* | 3549 /* |
3628 * ":scriptnames" | 3550 * ":scriptnames" |
3629 */ | 3551 */ |
3630 void | 3552 void |
3631 ex_scriptnames(eap) | 3553 ex_scriptnames(exarg_T *eap UNUSED) |
3632 exarg_T *eap UNUSED; | |
3633 { | 3554 { |
3634 int i; | 3555 int i; |
3635 | 3556 |
3636 for (i = 1; i <= script_items.ga_len && !got_int; ++i) | 3557 for (i = 1; i <= script_items.ga_len && !got_int; ++i) |
3637 if (SCRIPT_ITEM(i).sn_name != NULL) | 3558 if (SCRIPT_ITEM(i).sn_name != NULL) |
3645 # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) | 3566 # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) |
3646 /* | 3567 /* |
3647 * Fix slashes in the list of script names for 'shellslash'. | 3568 * Fix slashes in the list of script names for 'shellslash'. |
3648 */ | 3569 */ |
3649 void | 3570 void |
3650 scriptnames_slash_adjust() | 3571 scriptnames_slash_adjust(void) |
3651 { | 3572 { |
3652 int i; | 3573 int i; |
3653 | 3574 |
3654 for (i = 1; i <= script_items.ga_len; ++i) | 3575 for (i = 1; i <= script_items.ga_len; ++i) |
3655 if (SCRIPT_ITEM(i).sn_name != NULL) | 3576 if (SCRIPT_ITEM(i).sn_name != NULL) |
3659 | 3580 |
3660 /* | 3581 /* |
3661 * Get a pointer to a script name. Used for ":verbose set". | 3582 * Get a pointer to a script name. Used for ":verbose set". |
3662 */ | 3583 */ |
3663 char_u * | 3584 char_u * |
3664 get_scriptname(id) | 3585 get_scriptname(scid_T id) |
3665 scid_T id; | |
3666 { | 3586 { |
3667 if (id == SID_MODELINE) | 3587 if (id == SID_MODELINE) |
3668 return (char_u *)_("modeline"); | 3588 return (char_u *)_("modeline"); |
3669 if (id == SID_CMDARG) | 3589 if (id == SID_CMDARG) |
3670 return (char_u *)_("--cmd argument"); | 3590 return (char_u *)_("--cmd argument"); |
3677 return SCRIPT_ITEM(id).sn_name; | 3597 return SCRIPT_ITEM(id).sn_name; |
3678 } | 3598 } |
3679 | 3599 |
3680 # if defined(EXITFREE) || defined(PROTO) | 3600 # if defined(EXITFREE) || defined(PROTO) |
3681 void | 3601 void |
3682 free_scriptnames() | 3602 free_scriptnames(void) |
3683 { | 3603 { |
3684 int i; | 3604 int i; |
3685 | 3605 |
3686 for (i = script_items.ga_len; i > 0; --i) | 3606 for (i = script_items.ga_len; i > 0; --i) |
3687 vim_free(SCRIPT_ITEM(i).sn_name); | 3607 vim_free(SCRIPT_ITEM(i).sn_name); |
3697 /* | 3617 /* |
3698 * Newer version of the Metrowerks library handle DOS and UNIX files | 3618 * Newer version of the Metrowerks library handle DOS and UNIX files |
3699 * without help. | 3619 * without help. |
3700 * Test with earlier versions, MSL 2.2 is the library supplied with | 3620 * Test with earlier versions, MSL 2.2 is the library supplied with |
3701 * Codewarrior Pro 2. | 3621 * Codewarrior Pro 2. |
3622 */ | |
3623 char * | |
3624 fgets_cr(char *s, int n, FILE *stream) | |
3625 { | |
3626 return fgets(s, n, stream); | |
3627 } | |
3628 # else | |
3629 /* | |
3630 * Version of fgets() which also works for lines ending in a <CR> only | |
3631 * (Macintosh format). | |
3632 * For older versions of the Metrowerks library. | |
3633 * At least CodeWarrior 9 needed this code. | |
3702 */ | 3634 */ |
3703 char * | 3635 char * |
3704 fgets_cr(s, n, stream) | 3636 fgets_cr(s, n, stream) |
3705 char *s; | 3637 char *s; |
3706 int n; | 3638 int n; |
3707 FILE *stream; | 3639 FILE *stream; |
3708 { | 3640 { |
3709 return fgets(s, n, stream); | |
3710 } | |
3711 # else | |
3712 /* | |
3713 * Version of fgets() which also works for lines ending in a <CR> only | |
3714 * (Macintosh format). | |
3715 * For older versions of the Metrowerks library. | |
3716 * At least CodeWarrior 9 needed this code. | |
3717 */ | |
3718 char * | |
3719 fgets_cr(s, n, stream) | |
3720 char *s; | |
3721 int n; | |
3722 FILE *stream; | |
3723 { | |
3724 int c = 0; | 3641 int c = 0; |
3725 int char_read = 0; | 3642 int char_read = 0; |
3726 | 3643 |
3727 while (!feof(stream) && c != '\r' && c != '\n' && char_read < n - 1) | 3644 while (!feof(stream) && c != '\r' && c != '\n' && char_read < n - 1) |
3728 { | 3645 { |
3756 * | 3673 * |
3757 * Return a pointer to the line in allocated memory. | 3674 * Return a pointer to the line in allocated memory. |
3758 * Return NULL for end-of-file or some error. | 3675 * Return NULL for end-of-file or some error. |
3759 */ | 3676 */ |
3760 char_u * | 3677 char_u * |
3761 getsourceline(c, cookie, indent) | 3678 getsourceline(int c UNUSED, void *cookie, int indent UNUSED) |
3762 int c UNUSED; | |
3763 void *cookie; | |
3764 int indent UNUSED; | |
3765 { | 3679 { |
3766 struct source_cookie *sp = (struct source_cookie *)cookie; | 3680 struct source_cookie *sp = (struct source_cookie *)cookie; |
3767 char_u *line; | 3681 char_u *line; |
3768 char_u *p; | 3682 char_u *p; |
3769 | 3683 |
3870 | 3784 |
3871 return line; | 3785 return line; |
3872 } | 3786 } |
3873 | 3787 |
3874 static char_u * | 3788 static char_u * |
3875 get_one_sourceline(sp) | 3789 get_one_sourceline(struct source_cookie *sp) |
3876 struct source_cookie *sp; | |
3877 { | 3790 { |
3878 garray_T ga; | 3791 garray_T ga; |
3879 int len; | 3792 int len; |
3880 int c; | 3793 int c; |
3881 char_u *buf; | 3794 char_u *buf; |
4027 * "sourcing_lnum" must be correct! | 3940 * "sourcing_lnum" must be correct! |
4028 * When skipping lines it may not actually be executed, but we won't find out | 3941 * When skipping lines it may not actually be executed, but we won't find out |
4029 * until later and we need to store the time now. | 3942 * until later and we need to store the time now. |
4030 */ | 3943 */ |
4031 void | 3944 void |
4032 script_line_start() | 3945 script_line_start(void) |
4033 { | 3946 { |
4034 scriptitem_T *si; | 3947 scriptitem_T *si; |
4035 sn_prl_T *pp; | 3948 sn_prl_T *pp; |
4036 | 3949 |
4037 if (current_SID <= 0 || current_SID > script_items.ga_len) | 3950 if (current_SID <= 0 || current_SID > script_items.ga_len) |
4062 | 3975 |
4063 /* | 3976 /* |
4064 * Called when actually executing a function line. | 3977 * Called when actually executing a function line. |
4065 */ | 3978 */ |
4066 void | 3979 void |
4067 script_line_exec() | 3980 script_line_exec(void) |
4068 { | 3981 { |
4069 scriptitem_T *si; | 3982 scriptitem_T *si; |
4070 | 3983 |
4071 if (current_SID <= 0 || current_SID > script_items.ga_len) | 3984 if (current_SID <= 0 || current_SID > script_items.ga_len) |
4072 return; | 3985 return; |
4077 | 3990 |
4078 /* | 3991 /* |
4079 * Called when done with a function line. | 3992 * Called when done with a function line. |
4080 */ | 3993 */ |
4081 void | 3994 void |
4082 script_line_end() | 3995 script_line_end(void) |
4083 { | 3996 { |
4084 scriptitem_T *si; | 3997 scriptitem_T *si; |
4085 sn_prl_T *pp; | 3998 sn_prl_T *pp; |
4086 | 3999 |
4087 if (current_SID <= 0 || current_SID > script_items.ga_len) | 4000 if (current_SID <= 0 || current_SID > script_items.ga_len) |
4108 /* | 4021 /* |
4109 * ":scriptencoding": Set encoding conversion for a sourced script. | 4022 * ":scriptencoding": Set encoding conversion for a sourced script. |
4110 * Without the multi-byte feature it's simply ignored. | 4023 * Without the multi-byte feature it's simply ignored. |
4111 */ | 4024 */ |
4112 void | 4025 void |
4113 ex_scriptencoding(eap) | 4026 ex_scriptencoding(exarg_T *eap UNUSED) |
4114 exarg_T *eap UNUSED; | |
4115 { | 4027 { |
4116 #ifdef FEAT_MBYTE | 4028 #ifdef FEAT_MBYTE |
4117 struct source_cookie *sp; | 4029 struct source_cookie *sp; |
4118 char_u *name; | 4030 char_u *name; |
4119 | 4031 |
4144 #if defined(FEAT_EVAL) || defined(PROTO) | 4056 #if defined(FEAT_EVAL) || defined(PROTO) |
4145 /* | 4057 /* |
4146 * ":finish": Mark a sourced file as finished. | 4058 * ":finish": Mark a sourced file as finished. |
4147 */ | 4059 */ |
4148 void | 4060 void |
4149 ex_finish(eap) | 4061 ex_finish(exarg_T *eap) |
4150 exarg_T *eap; | |
4151 { | 4062 { |
4152 if (getline_equal(eap->getline, eap->cookie, getsourceline)) | 4063 if (getline_equal(eap->getline, eap->cookie, getsourceline)) |
4153 do_finish(eap, FALSE); | 4064 do_finish(eap, FALSE); |
4154 else | 4065 else |
4155 EMSG(_("E168: :finish used outside of a sourced file")); | 4066 EMSG(_("E168: :finish used outside of a sourced file")); |
4159 * Mark a sourced file as finished. Possibly makes the ":finish" pending. | 4070 * Mark a sourced file as finished. Possibly makes the ":finish" pending. |
4160 * Also called for a pending finish at the ":endtry" or after returning from | 4071 * Also called for a pending finish at the ":endtry" or after returning from |
4161 * an extra do_cmdline(). "reanimate" is used in the latter case. | 4072 * an extra do_cmdline(). "reanimate" is used in the latter case. |
4162 */ | 4073 */ |
4163 void | 4074 void |
4164 do_finish(eap, reanimate) | 4075 do_finish(exarg_T *eap, int reanimate) |
4165 exarg_T *eap; | |
4166 int reanimate; | |
4167 { | 4076 { |
4168 int idx; | 4077 int idx; |
4169 | 4078 |
4170 if (reanimate) | 4079 if (reanimate) |
4171 ((struct source_cookie *)getline_cookie(eap->getline, | 4080 ((struct source_cookie *)getline_cookie(eap->getline, |
4193 * Return TRUE when a sourced file had the ":finish" command: Don't give error | 4102 * Return TRUE when a sourced file had the ":finish" command: Don't give error |
4194 * message for missing ":endif". | 4103 * message for missing ":endif". |
4195 * Return FALSE when not sourcing a file. | 4104 * Return FALSE when not sourcing a file. |
4196 */ | 4105 */ |
4197 int | 4106 int |
4198 source_finished(fgetline, cookie) | 4107 source_finished( |
4199 char_u *(*fgetline)(int, void *, int); | 4108 char_u *(*fgetline)(int, void *, int), |
4200 void *cookie; | 4109 void *cookie) |
4201 { | 4110 { |
4202 return (getline_equal(fgetline, cookie, getsourceline) | 4111 return (getline_equal(fgetline, cookie, getsourceline) |
4203 && ((struct source_cookie *)getline_cookie( | 4112 && ((struct source_cookie *)getline_cookie( |
4204 fgetline, cookie))->finished); | 4113 fgetline, cookie))->finished); |
4205 } | 4114 } |
4208 #if defined(FEAT_LISTCMDS) || defined(PROTO) | 4117 #if defined(FEAT_LISTCMDS) || defined(PROTO) |
4209 /* | 4118 /* |
4210 * ":checktime [buffer]" | 4119 * ":checktime [buffer]" |
4211 */ | 4120 */ |
4212 void | 4121 void |
4213 ex_checktime(eap) | 4122 ex_checktime(exarg_T *eap) |
4214 exarg_T *eap; | |
4215 { | 4123 { |
4216 buf_T *buf; | 4124 buf_T *buf; |
4217 int save_no_check_timestamps = no_check_timestamps; | 4125 int save_no_check_timestamps = no_check_timestamps; |
4218 | 4126 |
4219 no_check_timestamps = 0; | 4127 no_check_timestamps = 0; |
4233 && (defined(FEAT_EVAL) || defined(FEAT_MULTI_LANG)) | 4141 && (defined(FEAT_EVAL) || defined(FEAT_MULTI_LANG)) |
4234 # define HAVE_GET_LOCALE_VAL | 4142 # define HAVE_GET_LOCALE_VAL |
4235 static char *get_locale_val(int what); | 4143 static char *get_locale_val(int what); |
4236 | 4144 |
4237 static char * | 4145 static char * |
4238 get_locale_val(what) | 4146 get_locale_val(int what) |
4239 int what; | |
4240 { | 4147 { |
4241 char *loc; | 4148 char *loc; |
4242 | 4149 |
4243 /* Obtain the locale value from the libraries. For DJGPP this is | 4150 /* Obtain the locale value from the libraries. For DJGPP this is |
4244 * redefined and it doesn't use the arguments. */ | 4151 * redefined and it doesn't use the arguments. */ |
4315 /* | 4222 /* |
4316 * Obtain the current messages language. Used to set the default for | 4223 * Obtain the current messages language. Used to set the default for |
4317 * 'helplang'. May return NULL or an empty string. | 4224 * 'helplang'. May return NULL or an empty string. |
4318 */ | 4225 */ |
4319 char_u * | 4226 char_u * |
4320 get_mess_lang() | 4227 get_mess_lang(void) |
4321 { | 4228 { |
4322 char_u *p; | 4229 char_u *p; |
4323 | 4230 |
4324 # ifdef HAVE_GET_LOCALE_VAL | 4231 # ifdef HAVE_GET_LOCALE_VAL |
4325 # if defined(LC_MESSAGES) | 4232 # if defined(LC_MESSAGES) |
4357 | 4264 |
4358 /* | 4265 /* |
4359 * Get the language used for messages from the environment. | 4266 * Get the language used for messages from the environment. |
4360 */ | 4267 */ |
4361 static char_u * | 4268 static char_u * |
4362 get_mess_env() | 4269 get_mess_env(void) |
4363 { | 4270 { |
4364 char_u *p; | 4271 char_u *p; |
4365 | 4272 |
4366 p = mch_getenv((char_u *)"LC_ALL"); | 4273 p = mch_getenv((char_u *)"LC_ALL"); |
4367 if (p == NULL || *p == NUL) | 4274 if (p == NULL || *p == NUL) |
4387 /* | 4294 /* |
4388 * Set the "v:lang" variable according to the current locale setting. | 4295 * Set the "v:lang" variable according to the current locale setting. |
4389 * Also do "v:lc_time"and "v:ctype". | 4296 * Also do "v:lc_time"and "v:ctype". |
4390 */ | 4297 */ |
4391 void | 4298 void |
4392 set_lang_var() | 4299 set_lang_var(void) |
4393 { | 4300 { |
4394 char_u *loc; | 4301 char_u *loc; |
4395 | 4302 |
4396 # ifdef HAVE_GET_LOCALE_VAL | 4303 # ifdef HAVE_GET_LOCALE_VAL |
4397 loc = (char_u *)get_locale_val(LC_CTYPE); | 4304 loc = (char_u *)get_locale_val(LC_CTYPE); |
4421 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | 4328 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) |
4422 /* | 4329 /* |
4423 * ":language": Set the language (locale). | 4330 * ":language": Set the language (locale). |
4424 */ | 4331 */ |
4425 void | 4332 void |
4426 ex_language(eap) | 4333 ex_language(exarg_T *eap) |
4427 exarg_T *eap; | |
4428 { | 4334 { |
4429 char *loc; | 4335 char *loc; |
4430 char_u *p; | 4336 char_u *p; |
4431 char_u *name; | 4337 char_u *name; |
4432 int what = LC_ALL; | 4338 int what = LC_ALL; |
4560 | 4466 |
4561 /* | 4467 /* |
4562 * Lazy initialization of all available locales. | 4468 * Lazy initialization of all available locales. |
4563 */ | 4469 */ |
4564 static void | 4470 static void |
4565 init_locales() | 4471 init_locales(void) |
4566 { | 4472 { |
4567 if (!did_init_locales) | 4473 if (!did_init_locales) |
4568 { | 4474 { |
4569 did_init_locales = TRUE; | 4475 did_init_locales = TRUE; |
4570 locales = find_locales(); | 4476 locales = find_locales(); |
4572 } | 4478 } |
4573 | 4479 |
4574 /* Return an array of strings for all available locales + NULL for the | 4480 /* Return an array of strings for all available locales + NULL for the |
4575 * last element. Return NULL in case of error. */ | 4481 * last element. Return NULL in case of error. */ |
4576 static char_u ** | 4482 static char_u ** |
4577 find_locales() | 4483 find_locales(void) |
4578 { | 4484 { |
4579 garray_T locales_ga; | 4485 garray_T locales_ga; |
4580 char_u *loc; | 4486 char_u *loc; |
4581 | 4487 |
4582 /* Find all available locales by running command "locale -a". If this | 4488 /* Find all available locales by running command "locale -a". If this |
4612 return (char_u **)locales_ga.ga_data; | 4518 return (char_u **)locales_ga.ga_data; |
4613 } | 4519 } |
4614 | 4520 |
4615 # if defined(EXITFREE) || defined(PROTO) | 4521 # if defined(EXITFREE) || defined(PROTO) |
4616 void | 4522 void |
4617 free_locales() | 4523 free_locales(void) |
4618 { | 4524 { |
4619 int i; | 4525 int i; |
4620 if (locales != NULL) | 4526 if (locales != NULL) |
4621 { | 4527 { |
4622 for (i = 0; locales[i] != NULL; i++) | 4528 for (i = 0; locales[i] != NULL; i++) |
4630 /* | 4536 /* |
4631 * Function given to ExpandGeneric() to obtain the possible arguments of the | 4537 * Function given to ExpandGeneric() to obtain the possible arguments of the |
4632 * ":language" command. | 4538 * ":language" command. |
4633 */ | 4539 */ |
4634 char_u * | 4540 char_u * |
4635 get_lang_arg(xp, idx) | 4541 get_lang_arg(expand_T *xp UNUSED, int idx) |
4636 expand_T *xp UNUSED; | |
4637 int idx; | |
4638 { | 4542 { |
4639 if (idx == 0) | 4543 if (idx == 0) |
4640 return (char_u *)"messages"; | 4544 return (char_u *)"messages"; |
4641 if (idx == 1) | 4545 if (idx == 1) |
4642 return (char_u *)"ctype"; | 4546 return (char_u *)"ctype"; |
4651 | 4555 |
4652 /* | 4556 /* |
4653 * Function given to ExpandGeneric() to obtain the available locales. | 4557 * Function given to ExpandGeneric() to obtain the available locales. |
4654 */ | 4558 */ |
4655 char_u * | 4559 char_u * |
4656 get_locales(xp, idx) | 4560 get_locales(expand_T *xp UNUSED, int idx) |
4657 expand_T *xp UNUSED; | |
4658 int idx; | |
4659 { | 4561 { |
4660 init_locales(); | 4562 init_locales(); |
4661 if (locales == NULL) | 4563 if (locales == NULL) |
4662 return NULL; | 4564 return NULL; |
4663 return locales[idx]; | 4565 return locales[idx]; |