Mercurial > vim
comparison src/ex_cmds.c @ 3141:6963603ec6dc v7.3.341
updated for version 7.3.341
Problem: Local help files are only listed in help.txt, not in translated
help files.
Solution: Also find translated help files. (Yasuhiro Matsumoto)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 20 Oct 2011 18:17:42 +0200 |
parents | 9028c70adafd |
children | 074ddc768fea |
comparison
equal
deleted
inserted
replaced
3140:c70481d40802 | 3141:6963603ec6dc |
---|---|
5980 { | 5980 { |
5981 linenr_T lnum; | 5981 linenr_T lnum; |
5982 char_u *line; | 5982 char_u *line; |
5983 int in_example = FALSE; | 5983 int in_example = FALSE; |
5984 int len; | 5984 int len; |
5985 char_u *fname; | |
5985 char_u *p; | 5986 char_u *p; |
5986 char_u *rt; | 5987 char_u *rt; |
5987 int mustfree; | 5988 int mustfree; |
5988 | 5989 |
5989 /* set filetype to "help". */ | 5990 /* set filetype to "help". */ |
6026 } | 6027 } |
6027 } | 6028 } |
6028 } | 6029 } |
6029 | 6030 |
6030 /* | 6031 /* |
6031 * In the "help.txt" file, add the locally added help files. | 6032 * In the "help.txt" and "help.abx" file, add the locally added help |
6032 * This uses the very first line in the help file. | 6033 * files. This uses the very first line in the help file. |
6033 */ | 6034 */ |
6034 if (fnamecmp(gettail(curbuf->b_fname), "help.txt") == 0) | 6035 fname = gettail(curbuf->b_fname); |
6036 if (fnamecmp(fname, "help.txt") == 0 | |
6037 #ifdef FEAT_MULTI_LANG | |
6038 || (fnamencmp(fname, "help.", 5) == 0 | |
6039 && ASCII_ISALPHA(fname[5]) | |
6040 && ASCII_ISALPHA(fname[6]) | |
6041 && TOLOWER_ASC(fname[7]) == 'x' | |
6042 && fname[8] == NUL) | |
6043 #endif | |
6044 ) | |
6035 { | 6045 { |
6036 for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; ++lnum) | 6046 for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; ++lnum) |
6037 { | 6047 { |
6038 line = ml_get_buf(curbuf, lnum, FALSE); | 6048 line = ml_get_buf(curbuf, lnum, FALSE); |
6039 if (strstr((char *)line, "*local-additions*") != NULL) | 6049 if (strstr((char *)line, "*local-additions*") == NULL) |
6040 { | 6050 continue; |
6041 /* Go through all directories in 'runtimepath', skipping | 6051 |
6042 * $VIMRUNTIME. */ | 6052 /* Go through all directories in 'runtimepath', skipping |
6043 p = p_rtp; | 6053 * $VIMRUNTIME. */ |
6044 while (*p != NUL) | 6054 p = p_rtp; |
6055 while (*p != NUL) | |
6056 { | |
6057 copy_option_part(&p, NameBuff, MAXPATHL, ","); | |
6058 mustfree = FALSE; | |
6059 rt = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); | |
6060 if (fullpathcmp(rt, NameBuff, FALSE) != FPC_SAME) | |
6045 { | 6061 { |
6046 copy_option_part(&p, NameBuff, MAXPATHL, ","); | 6062 int fcount; |
6047 mustfree = FALSE; | 6063 char_u **fnames; |
6048 rt = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); | 6064 FILE *fd; |
6049 if (fullpathcmp(rt, NameBuff, FALSE) != FPC_SAME) | 6065 char_u *s; |
6066 int fi; | |
6067 #ifdef FEAT_MBYTE | |
6068 vimconv_T vc; | |
6069 char_u *cp; | |
6070 #endif | |
6071 | |
6072 /* Find all "doc/ *.txt" files in this directory. */ | |
6073 add_pathsep(NameBuff); | |
6074 #ifdef FEAT_MULTI_LANG | |
6075 STRCAT(NameBuff, "doc/*.??[tx]"); | |
6076 #else | |
6077 STRCAT(NameBuff, "doc/*.txt"); | |
6078 #endif | |
6079 if (gen_expand_wildcards(1, &NameBuff, &fcount, | |
6080 &fnames, EW_FILE|EW_SILENT) == OK | |
6081 && fcount > 0) | |
6050 { | 6082 { |
6051 int fcount; | 6083 #ifdef FEAT_MULTI_LANG |
6052 char_u **fnames; | 6084 int i1; |
6053 FILE *fd; | 6085 int i2; |
6054 char_u *s; | 6086 char_u *f1; |
6055 int fi; | 6087 char_u *f2; |
6056 #ifdef FEAT_MBYTE | 6088 char_u *t1; |
6057 vimconv_T vc; | 6089 char_u *e1; |
6058 char_u *cp; | 6090 char_u *e2; |
6059 #endif | 6091 |
6060 | 6092 /* If foo.abx is found use it instead of foo.txt in |
6061 /* Find all "doc/ *.txt" files in this directory. */ | 6093 * the same directory. */ |
6062 add_pathsep(NameBuff); | 6094 for (i1 = 0; i1 < fcount; ++i1) |
6063 STRCAT(NameBuff, "doc/*.txt"); | |
6064 if (gen_expand_wildcards(1, &NameBuff, &fcount, | |
6065 &fnames, EW_FILE|EW_SILENT) == OK | |
6066 && fcount > 0) | |
6067 { | 6095 { |
6068 for (fi = 0; fi < fcount; ++fi) | 6096 for (i2 = 0; i2 < fcount; ++i2) |
6069 { | 6097 { |
6070 fd = mch_fopen((char *)fnames[fi], "r"); | 6098 if (i1 == i2) |
6071 if (fd != NULL) | 6099 continue; |
6100 if (fnames[i1] == NULL || fnames[i2] == NULL) | |
6101 continue; | |
6102 f1 = fnames[i1]; | |
6103 f2 = fnames[i2]; | |
6104 t1 = gettail(f1); | |
6105 if (fnamencmp(f1, f2, t1 - f1) != 0) | |
6106 continue; | |
6107 e1 = vim_strrchr(t1, '.'); | |
6108 e2 = vim_strrchr(gettail(f2), '.'); | |
6109 if (e1 == NUL || e2 == NUL) | |
6110 continue; | |
6111 if (fnamecmp(e1, ".txt") != 0 | |
6112 && fnamecmp(e1, fname + 4) != 0) | |
6072 { | 6113 { |
6073 vim_fgets(IObuff, IOSIZE, fd); | 6114 /* Not .txt and not .abx, remove it. */ |
6074 if (IObuff[0] == '*' | 6115 vim_free(fnames[i1]); |
6075 && (s = vim_strchr(IObuff + 1, '*')) | 6116 fnames[i1] = NULL; |
6076 != NULL) | 6117 continue; |
6077 { | 6118 } |
6078 #ifdef FEAT_MBYTE | 6119 if (fnamencmp(f1, f2, e1 - f1) != 0) |
6079 int this_utf = MAYBE; | 6120 continue; |
6080 #endif | 6121 if (fnamecmp(e1, ".txt") == 0 |
6081 /* Change tag definition to a | 6122 && fnamecmp(e2, fname + 4) == 0) |
6082 * reference and remove <CR>/<NL>. */ | 6123 { |
6083 IObuff[0] = '|'; | 6124 /* use .abx instead of .txt */ |
6084 *s = '|'; | 6125 vim_free(fnames[i1]); |
6085 while (*s != NUL) | 6126 fnames[i1] = NULL; |
6086 { | |
6087 if (*s == '\r' || *s == '\n') | |
6088 *s = NUL; | |
6089 #ifdef FEAT_MBYTE | |
6090 /* The text is utf-8 when a byte | |
6091 * above 127 is found and no | |
6092 * illegal byte sequence is found. | |
6093 */ | |
6094 if (*s >= 0x80 && this_utf != FALSE) | |
6095 { | |
6096 int l; | |
6097 | |
6098 this_utf = TRUE; | |
6099 l = utf_ptr2len(s); | |
6100 if (l == 1) | |
6101 this_utf = FALSE; | |
6102 s += l - 1; | |
6103 } | |
6104 #endif | |
6105 ++s; | |
6106 } | |
6107 #ifdef FEAT_MBYTE | |
6108 /* The help file is latin1 or utf-8; | |
6109 * conversion to the current | |
6110 * 'encoding' may be required. */ | |
6111 vc.vc_type = CONV_NONE; | |
6112 convert_setup(&vc, (char_u *)( | |
6113 this_utf == TRUE ? "utf-8" | |
6114 : "latin1"), p_enc); | |
6115 if (vc.vc_type == CONV_NONE) | |
6116 /* No conversion needed. */ | |
6117 cp = IObuff; | |
6118 else | |
6119 { | |
6120 /* Do the conversion. If it fails | |
6121 * use the unconverted text. */ | |
6122 cp = string_convert(&vc, IObuff, | |
6123 NULL); | |
6124 if (cp == NULL) | |
6125 cp = IObuff; | |
6126 } | |
6127 convert_setup(&vc, NULL, NULL); | |
6128 | |
6129 ml_append(lnum, cp, (colnr_T)0, FALSE); | |
6130 if (cp != IObuff) | |
6131 vim_free(cp); | |
6132 #else | |
6133 ml_append(lnum, IObuff, (colnr_T)0, | |
6134 FALSE); | |
6135 #endif | |
6136 ++lnum; | |
6137 } | |
6138 fclose(fd); | |
6139 } | 6127 } |
6140 } | 6128 } |
6141 FreeWild(fcount, fnames); | |
6142 } | 6129 } |
6130 #endif | |
6131 for (fi = 0; fi < fcount; ++fi) | |
6132 { | |
6133 if (fnames[fi] == NULL) | |
6134 continue; | |
6135 fd = mch_fopen((char *)fnames[fi], "r"); | |
6136 if (fd != NULL) | |
6137 { | |
6138 vim_fgets(IObuff, IOSIZE, fd); | |
6139 if (IObuff[0] == '*' | |
6140 && (s = vim_strchr(IObuff + 1, '*')) | |
6141 != NULL) | |
6142 { | |
6143 #ifdef FEAT_MBYTE | |
6144 int this_utf = MAYBE; | |
6145 #endif | |
6146 /* Change tag definition to a | |
6147 * reference and remove <CR>/<NL>. */ | |
6148 IObuff[0] = '|'; | |
6149 *s = '|'; | |
6150 while (*s != NUL) | |
6151 { | |
6152 if (*s == '\r' || *s == '\n') | |
6153 *s = NUL; | |
6154 #ifdef FEAT_MBYTE | |
6155 /* The text is utf-8 when a byte | |
6156 * above 127 is found and no | |
6157 * illegal byte sequence is found. | |
6158 */ | |
6159 if (*s >= 0x80 && this_utf != FALSE) | |
6160 { | |
6161 int l; | |
6162 | |
6163 this_utf = TRUE; | |
6164 l = utf_ptr2len(s); | |
6165 if (l == 1) | |
6166 this_utf = FALSE; | |
6167 s += l - 1; | |
6168 } | |
6169 #endif | |
6170 ++s; | |
6171 } | |
6172 #ifdef FEAT_MBYTE | |
6173 /* The help file is latin1 or utf-8; | |
6174 * conversion to the current | |
6175 * 'encoding' may be required. */ | |
6176 vc.vc_type = CONV_NONE; | |
6177 convert_setup(&vc, (char_u *)( | |
6178 this_utf == TRUE ? "utf-8" | |
6179 : "latin1"), p_enc); | |
6180 if (vc.vc_type == CONV_NONE) | |
6181 /* No conversion needed. */ | |
6182 cp = IObuff; | |
6183 else | |
6184 { | |
6185 /* Do the conversion. If it fails | |
6186 * use the unconverted text. */ | |
6187 cp = string_convert(&vc, IObuff, | |
6188 NULL); | |
6189 if (cp == NULL) | |
6190 cp = IObuff; | |
6191 } | |
6192 convert_setup(&vc, NULL, NULL); | |
6193 | |
6194 ml_append(lnum, cp, (colnr_T)0, FALSE); | |
6195 if (cp != IObuff) | |
6196 vim_free(cp); | |
6197 #else | |
6198 ml_append(lnum, IObuff, (colnr_T)0, | |
6199 FALSE); | |
6200 #endif | |
6201 ++lnum; | |
6202 } | |
6203 fclose(fd); | |
6204 } | |
6205 } | |
6206 FreeWild(fcount, fnames); | |
6143 } | 6207 } |
6144 if (mustfree) | |
6145 vim_free(rt); | |
6146 } | 6208 } |
6147 break; | 6209 if (mustfree) |
6148 } | 6210 vim_free(rt); |
6211 } | |
6212 break; | |
6149 } | 6213 } |
6150 } | 6214 } |
6151 } | 6215 } |
6152 | 6216 |
6153 /* | 6217 /* |