├── .gitignore ├── README.md ├── autoconf ├── .ycm_extra_conf.py ├── _vimrc ├── cpp.sh ├── git_cmd │ ├── git_add_modify │ ├── git_push │ └── git_rebase_upstream ├── go.sh ├── install ├── lib │ ├── lib.sh │ ├── msg.sh │ └── pt.sh ├── patchelf.sh ├── shell_cmd │ ├── del.sh │ └── swap.sh ├── simple │ ├── _vimrc │ └── install ├── sources │ ├── CentOS7-Base-163.repo │ ├── Ubuntu14.04 │ └── Ubuntu15.04 ├── tools │ ├── bear.sh │ ├── cmake.sh │ ├── ctags.sh │ ├── dos2unix.sh │ ├── gcc.sh │ ├── gdbm.sh │ ├── git.sh │ ├── golang.sh │ ├── libncurses.sh │ ├── patchelf.sh │ ├── python.sh │ ├── ruby.sh │ └── vim.sh ├── vim.sh └── win │ └── .ycm_extra_conf.py ├── autoload ├── cppenv.vim └── switch_dd.py ├── pyclang ├── gen_methods.py ├── project │ ├── __init__.py │ ├── cmake.py │ └── find.py ├── test.cpp └── test.h └── snippets └── all.snippets /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cppenv: complete vim environment for coding C++/Golang 2 | *** 3 | 4 | ## Overview ## 5 | 6 | I'm aim at making coding in C++ fast, fluent, and correct, so I choose vim as my editor because its shortcut keys often only require single press. However, I want more... 7 | 8 | This project has two parts: 9 | 10 | - **Complete vim environment installer.** 11 | - **Vim plugin for coding C++** 12 | 13 | Vim environment includes some tools below: 14 | 15 | - g++ 16 | - git 17 | - cmake 18 | - python2 19 | 20 | and some plugins below: 21 | 22 | - Vundle 23 | - YouCompleteMe 24 | - NerdTree 25 | - Airline 26 | - taglist 27 | - vim-snippet 28 | 29 | You can run the script `autoconf/install` to install all of the vim environment I provide. It will automatically install all of the tools and plugins above. If you are in China, it takes only 4 minutes. 30 | 31 | ## Install ## 32 | 33 | If you want use the complete `cppenv`, please follow the instruction below: 34 | 35 | 1. clone this git repository 36 | 2. change work directory to `autoconf` and run script `./install` with the user that you coding with 37 | 3. wait about 4 minutes 38 | 4. if you want coding golang, run script `./go.sh` 39 | 5. if you want coding c++, run script `./install_cpp.sh` 40 | 41 | The script will install `_vimrc`, `.ycm_extra_conf.py` and other plugins in `~/.vim`. 42 | 43 | But, if you want use the plugin `cppenv` only, you can install `cppenv` to you vim runtime path. 44 | And add code `execute cppenv#infect()` into your `.vimrc` when open c++ code files. 45 | Look likes: 46 | 47 | - `au BufNewFile,BufRead *.h,*.hpp,*.inl,*.ipp,*.cpp,*.c,*.cc,*.go execute cppenv#infect()` 48 | 49 | ## AutoComplete ## 50 | 51 | `cppenv` provides some simple auto complete. And others, supported by `YouCompleteMe`. 52 | 53 | **Auto complete brackets:** 54 | This feature supports `class`, `struct`, `union`, `function`, `lambda` and `C++ coroutine lambda`. 55 | The `C++ coroutine lambda` refers to [https://github.com/yyzybb537/cpp_features](https://github.com/yyzybb537/cpp_features) 56 | *** 57 | 58 | ![brackets](http://i.imgur.com/RVNcD8o.gif) 59 | 60 | **Auto complete class-methods definitions:** 61 | This feature supports all of combination `class` and `method` types below: 62 | 63 | - `normal class` 64 | - `template class` 65 | 66 | **and** 67 | 68 | - `normal method` 69 | - `template method` 70 | - `static method` 71 | - `static template method` 72 | 73 | ![defclass](http://imgur.com/npFkaoj.gif) 74 | 75 | ## Jump File ## 76 | 77 | `cppenv` provides some shortcut keys for jump between c/c++ `header file` and c/c++ `source file`. 78 | 79 | - `gs` 80 | - `gns` 81 | - `gS` 82 | - `gvs` 83 | - `gvns` 84 | 85 | Use `gs` can jump between `header` and `source` if there were in a same folder. If the two files have the same parent folder, you can use `gns` to jump between there. If the two files were not in a same folder and have not the same parent folder, the `gs` cannot work, here, you can use `gS`. `gS` will use `locate` command to find the files in all of your file-system, and show the results in `quickfix` window when the results more than one. 86 | 87 | `gvs`, `gvns` are as same as `gs`, `gns` nearly. Difference was the shortcut key including `v` will split the window vertical, and show the other file buffer on right. 88 | 89 | ## Vim environment ## 90 | 91 | If you install the complete vim environment, the `_vimrc` taken effect. It will give you a lot of shortcut key to boost your coding efficiency. 92 | 93 | #### Plugins 94 | 95 | `YouCompleteMe` provides syntax complete and check. 96 | 97 | ![YouCompleteMe GIF demo](http://i.imgur.com/0OP4ood.gif) 98 | 99 | `NerdTree` provides show the files tree. 100 | 101 | ![NerdTree](http://img.hoop8.com/attachments/1511/4341900695509.gif) 102 | 103 | `TagList` provides show the functions in current file. 104 | 105 | ![taglist](http://img.hoop8.com/attachments/1511/6051900695509.gif) 106 | 107 | #### ShortcutKey 108 | 109 | I used `;` as the vim leader charactor, so seted below: 110 | 111 | - **`;b`** jump to begin of line. as `^` 112 | - **`;e`** jump to end of line. as `$` 113 | - **`;w`** save to file. as `:w` 114 | - **`;q`** quit the buffer. as `:quit` 115 | - **`;Q`** quit the vim. as `:quitall` 116 | - **`;hw`** jump to left window. as `h` 117 | - **`;jw`** jump to under window. as `j` 118 | - **`;kw`** jump to over window. as `k` 119 | - **`;lw`** jump to right window. as `l` 120 | - **`;/`** cancel highlight. as `:nohls` 121 | - **`;`** as `"`, e.g. you can use `;ay` to copy selection into `a` register, and use `;ap` to paste `a` register words into cursor position. 122 | 123 | - **`F3`** toggle the `NerdTree` window, show the files tree. 124 | - **`F4`** static syntax check current source file. 125 | 126 | #### Jump 127 | 128 | - **`gy`** jump to the word on the cursor definition or declaration. as call the YCM method `GoToDefinitionElseDeclaration`. 129 | - **`gY`** show the word on the cursor definition or declaration on right window. 130 | - **`gl`** jump to last buffer. as `:b#` 131 | - **`gL`** jump to last buffer and show current buffer on right window 132 | 133 | 134 | #### TabPage 135 | 136 | - **``** jump to previous tabpage. as `:tabprevious` 137 | - **``** jump to next tabpage. as `:tabnext` 138 | 139 | #### Build and Run 140 | 141 | - **`F7`** build current file, output `out.exe` 142 | - **`F5`** build and run. output `out.exe` 143 | - **`F8`** build and run with libboost. output `out.exe` 144 | 145 | #### Complete By Snippet 146 | 147 | - **``** trigge the snippet. 148 | 149 | Support snippet trigger list below: 150 | 151 | - **`time`** the output for e.g: `2015-11-20 23:56:18` 152 | - **`date`** output for e.g: `2015-11-20` 153 | - **`namespace `** 154 | 155 | e.g. 156 | 157 | input: 158 | 159 | namespace ucorf 160 | 161 | output: 162 | 163 | namespace ucorf 164 | { 165 | 166 | } //namespace ucorf 167 | 168 | - **`GNU License `** Make gnu license copyright header in source file. 169 | 170 | 171 | ![license](http://i.imgur.com/C2cN20p.gif) 172 | 173 | - **`def `** First, you must save your class definition. Then, input `def `, will output all method definitions of the class. 174 | -------------------------------------------------------------------------------- /autoconf/.ycm_extra_conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding:utf8 -*- 3 | # This file is NOT licensed under the GPLv3, which is the license for the rest 4 | # of YouCompleteMe. 5 | # 6 | # Here's the license text for this file: 7 | # 8 | # This is free and unencumbered software released into the public domain. 9 | # 10 | # Anyone is free to copy, modify, publish, use, compile, sell, or 11 | # distribute this software, either in source code form or as a compiled 12 | # binary, for any purpose, commercial or non-commercial, and by any 13 | # means. 14 | # 15 | # In jurisdictions that recognize copyright laws, the author or authors 16 | # of this software dedicate any and all copyright interest in the 17 | # software to the public domain. We make this dedication for the benefit 18 | # of the public at large and to the detriment of our heirs and 19 | # successors. We intend this dedication to be an overt act of 20 | # relinquishment in perpetuity of all present and future rights to this 21 | # software under copyright law. 22 | # 23 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 26 | # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 27 | # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 28 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 29 | # OTHER DEALINGS IN THE SOFTWARE. 30 | # 31 | # For more information, please refer to 32 | 33 | import os 34 | import sys 35 | import re 36 | import traceback 37 | import json 38 | import time 39 | 40 | # 打印日志 41 | g_debug = 1 42 | 43 | # 处理Makefile时是否执行(rm .*.d -f) 44 | g_rm_dot_d_files = 1 45 | 46 | # 缓存有效期 47 | g_cmake_cache_valid_seconds = 10 48 | g_makefile_cache_valid_seconds = 10 49 | 50 | def Log(msg): 51 | if not g_debug: 52 | return 53 | 54 | f = open("/tmp/ycm_conf.log", 'a+') 55 | f.write(msg + '\n') 56 | f.close() 57 | 58 | g_home = os.environ.get("HOME") 59 | g_tmp_dir = os.path.join(g_home, '.vim.git/ycm_tmp') 60 | g_time_format = '%Y-%m-%dT%H:%M:%S' 61 | 62 | if __name__ == '__main__': 63 | # clear all cache 64 | os.system('rm %s -rf' % g_tmp_dir) 65 | os.makedirs(g_tmp_dir) 66 | sys.exit(0) 67 | 68 | import ycm_core 69 | 70 | # These are the compilation flags that will be used in case there's no 71 | # compilation database set (by default, one is not set). 72 | # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. 73 | flags = [ 74 | #'-Wall', 75 | #'-Wextra', 76 | #'-Werror', 77 | #'-Wc++98-compat', 78 | #'-Wno-long-long', 79 | #'-Wno-variadic-macros', 80 | '-fexceptions', 81 | '-DNDEBUG', 82 | # You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM 83 | # source code needs it. 84 | '-DUSE_CLANG_COMPLETER', 85 | # THIS IS IMPORTANT! Without a "-std=" flag, clang won't know which 86 | # language to use when compiling headers. So it will guess. Badly. So C++ 87 | # headers will be compiled as C headers. You don't want that so ALWAYS specify 88 | # a "-std=". 89 | # For a C project, you would set this to something like 'c99' instead of 90 | # 'c++11'. 91 | '-std=c++11', 92 | # ...and the same thing goes for the magic -x option which specifies the 93 | # language that the files to be compiled are written in. This is mostly 94 | # relevant for c++ headers. 95 | # For a C project, you would set this to 'c' instead of 'c++'. 96 | '-x', 97 | 'c++', 98 | '-isystem', 99 | '../BoostParts', 100 | '-isystem', 101 | # This path will only work on OS X, but extra paths that don't exist are not 102 | # harmful 103 | '/System/Library/Frameworks/Python.framework/Headers', 104 | '-isystem', 105 | '../llvm/include', 106 | '-isystem', 107 | '../llvm/tools/clang/include', 108 | '-I', 109 | '.', 110 | '-I', 111 | './ClangCompleter', 112 | '-isystem', 113 | './tests/gmock/gtest', 114 | '-isystem', 115 | './tests/gmock/gtest/include', 116 | '-isystem', 117 | './tests/gmock', 118 | '-isystem', 119 | './tests/gmock/include', 120 | ] 121 | 122 | sysflags = [] 123 | 124 | def readFile(filename): 125 | if not os.path.isfile(filename): 126 | return "" 127 | 128 | f = open(filename, 'r') 129 | s = f.read() 130 | f.close() 131 | return s 132 | 133 | def readFileLines(filename): 134 | if not os.path.isfile(filename): 135 | return [] 136 | 137 | f = open(filename, 'r') 138 | lines = f.readlines() 139 | for i in range(len(lines)): 140 | lines[i] = lines[i].strip() 141 | f.close() 142 | return lines 143 | 144 | def writeFile(filename, s): 145 | if not os.path.exists(os.path.dirname(filename)): 146 | os.makedirs(os.path.dirname(filename)) 147 | f = open(filename, 'w') 148 | f.write(s) 149 | f.close() 150 | 151 | def writeFileLines(filename, lines): 152 | if not os.path.exists(os.path.dirname(filename)): 153 | os.makedirs(os.path.dirname(filename)) 154 | f = open(filename, 'w') 155 | for line in lines: 156 | f.write(line + '\n') 157 | f.close() 158 | 159 | # 计算最后修改时间 160 | def isFileTimeout(temp_file, seconds): 161 | if not os.path.isfile(temp_file): 162 | return True 163 | 164 | mt = os.path.getmtime(temp_file) 165 | now = time.mktime(time.localtime()) 166 | return abs(now - mt) > 5; 167 | 168 | # 初始化system flags 169 | def initSysFlags(): 170 | global sysflags 171 | 172 | gcc_search_dirs = '' 173 | 174 | gcc_search = os.path.join(g_tmp_dir, 'gcc_search') 175 | if os.path.isfile(gcc_search): 176 | gcc_search_dirs = readFile(gcc_search) 177 | 178 | if not gcc_search_dirs: 179 | f = open('/tmp/ycm_tmp.cpp', 'w') 180 | f.write('#include \n') 181 | f.write('main() {}') 182 | f.close() 183 | r, w, e = os.popen3('g++ -std=c++11 -v -H /tmp/ycm_tmp.cpp -o /dev/null') 184 | gcc_search_dirs = e.read() 185 | start = '#include <...> search starts here:' 186 | end = 'End of search list.' 187 | gcc_search_dirs = gcc_search_dirs[gcc_search_dirs.index(start) + len(start):gcc_search_dirs.index(end)] 188 | gcc_search_dirs = gcc_search_dirs.strip() 189 | writeFile(gcc_search, gcc_search_dirs) 190 | 191 | Log('gcc_search_dirs:' + gcc_search_dirs) 192 | dirs = gcc_search_dirs.split('\n') 193 | for d in dirs: 194 | d = d.strip() 195 | if d == '': 196 | continue 197 | sysflags.append('-isystem') 198 | sysflags.append(d) 199 | 200 | gcc_version = os.popen('gcc --version | head -1 | cut -d\) -f2 | awk \'{print $1}\'').read().strip() 201 | Log('gcc_version:' + gcc_version) 202 | 203 | # use CPATH 204 | env_cpath = os.environ.get("CPATH") 205 | if env_cpath: 206 | cpaths = env_cpath.split(':') 207 | for cpath in cpaths: 208 | if cpath == '': 209 | continue 210 | 211 | sysflags.append("-I") 212 | sysflags.append(cpath) 213 | 214 | # in Mac and Linux 215 | sysflags.extend([ 216 | '-isystem', 217 | '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1', 218 | '-isystem', 219 | '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include', 220 | '-isystem', 221 | '/usr/include/linux', 222 | '-isystem', 223 | '/usr/include/x86_64-linux-gnu', 224 | '-isystem', 225 | '/usr/include/i386-linux-gnu', 226 | ]) 227 | 228 | initSysFlags() 229 | 230 | SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] 231 | 232 | ## Add includes flags from the Makefile. 233 | # 234 | def ExtractIncludesFromMakefile(mk, filename): 235 | Log('ExtractIncludesFromMakefile(mk="%s")' % mk) 236 | 237 | file_dir = os.path.dirname(filename) 238 | mk_dir = os.path.dirname(mk) 239 | tmp_dir = g_tmp_dir + mk_dir 240 | Log("make_dir:%s, tmp_dir:%s, filename:%s" % (mk_dir, tmp_dir, filename)) 241 | temp_file = os.path.join(tmp_dir, 'makefile.commands') 242 | 243 | include_flags = [] 244 | if not isFileTimeout(temp_file, g_makefile_cache_valid_seconds): 245 | Log("===> match cache file: %s" % temp_file) 246 | include_flags = readFileLines(temp_file) 247 | 248 | if not include_flags: 249 | if g_rm_dot_d_files: 250 | os.system("rm %s/.*.d -f" % file_dir) 251 | make_commands = os.popen('cd %s && make -Bn 2>/dev/null' % mk_dir, 'r').read() 252 | 253 | #Log('Make commands:\n%s' % make_commands); 254 | matchs = re.findall(r'-I\s*[^\s$]+', make_commands) 255 | include_flags = set() 256 | for m in matchs: 257 | include_path = m[2:].strip() 258 | if not os.path.isabs(include_path): 259 | include_path = os.path.join(mk_dir, include_path) 260 | include_flags.add(include_path) 261 | 262 | writeFileLines(temp_file, include_flags) 263 | 264 | return include_flags 265 | 266 | def MakefileIncludesFlags(filename): 267 | Log('MakefileIncludesFlags(filename="%s")' % filename) 268 | 269 | makefile_list = ['Makefile', 'makefile', 'build/Makefile', 'build/makefile'] 270 | mk = findProjectFile(filename, makefile_list) 271 | if not mk: 272 | return [] 273 | 274 | include_flags = ExtractIncludesFromMakefile(mk, filename) 275 | return include_flags 276 | 277 | def ExtractIncludesFromCMake(cmk, filename): 278 | Log('ExtractIncludesFromCMake') 279 | cmk_dir = os.path.dirname(cmk) 280 | tmp_dir = g_tmp_dir + cmk_dir 281 | Log("cmake_dir:%s, tmp_dir:%s, filename:%s" % (cmk_dir, tmp_dir, filename)) 282 | json_file = os.path.join(tmp_dir, "compile_commands.json") 283 | if isFileTimeout(json_file, g_cmake_cache_valid_seconds): 284 | if not os.path.exists(tmp_dir): 285 | os.makedirs(tmp_dir) 286 | os.system("cd %s && cmake . %s -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" % (tmp_dir, cmk_dir)) 287 | else: 288 | Log("===> match cache file: %s" % json_file) 289 | return ExtractIncludesFromJson(json_file, filename) 290 | 291 | def ExtractIncludesFromJson(json_file, filename): 292 | if not os.path.isfile(json_file): 293 | Log("Create compile_commands.json failed.") 294 | return [] 295 | 296 | strjs = readFile(json_file) 297 | 298 | #Log("strjs:" + strjs) 299 | js = json.loads(strjs) 300 | #Log("object json:" + str(js)) 301 | 302 | # 完全匹配 303 | includes = CMakeJsonMatch(js, lambda unit: unit.get("file") == filename) 304 | Log("Best Match returns:%s" % len(includes)) 305 | 306 | # 尝试匹配对应的.cpp 307 | cppfile = os.path.splitext(filename)[0] + ".cpp" 308 | if len(includes) == 0: 309 | includes = CMakeJsonMatch(js, lambda unit: unit.get("file") == cppfile) 310 | Log("Match .cpp returns:%s" % len(includes)) 311 | 312 | # 匹配同目录下的所有cpp 313 | d = os.path.dirname(filename) 314 | if len(includes) == 0: 315 | includes = CMakeJsonMatch(js, lambda unit: os.path.dirname(unit.get("file")) == d) 316 | Log("Match directory returns:%s" % len(includes)) 317 | 318 | # 整合所有cpp 319 | if len(includes) == 0: 320 | includes = CMakeJsonMatch(js, lambda unit: True) 321 | Log("Match All returns:%s" % len(includes)) 322 | 323 | return includes 324 | 325 | def CMakeJsonMatch(js, matcher): 326 | includes = [] 327 | h = {} 328 | for unit in js: 329 | if not matcher(unit): 330 | continue 331 | 332 | command = unit.get("command") 333 | cmd_elems = command.split(" ") 334 | for elem in cmd_elems: 335 | if len(elem) > 2 and elem[:2] == '-I': 336 | #Log("Add elem:{%s}" % elem) 337 | d = elem[2:] 338 | if h.get(d) != None: 339 | continue 340 | h[d] = 1 341 | includes.append(elem[2:]) 342 | 343 | return includes 344 | 345 | def CMakeIncludesFlags(filename): 346 | Log('CMakeIncludesFlags') 347 | try: 348 | cmk = findProjectFile(filename, ['CMakeLists.txt']) 349 | if not cmk: 350 | Log("Not find CMakeLists.txt") 351 | return [] 352 | 353 | includes = ExtractIncludesFromCMake(cmk, filename) 354 | return includes 355 | except: 356 | Log(traceback.format_exc()) 357 | 358 | return [] 359 | 360 | def findProjectFile(cppfile, pfnames): 361 | Log('findProjectFile cppfile=%s, project_file_names=%s' % (cppfile, pfnames)) 362 | try: 363 | d = cppfile 364 | while True: 365 | di = os.path.dirname(d) 366 | if di == d: 367 | return 368 | 369 | d = di 370 | for projectfile in pfnames: 371 | pf = os.path.join(d, projectfile) 372 | #Log("check:" + pf) 373 | if os.path.isfile(pf): 374 | return pf 375 | except: 376 | Log(traceback.format_exc()) 377 | return 378 | 379 | def GetFileMTime(f): 380 | if os.path.exists(f): 381 | stat = os.stat(f) 382 | if stat: 383 | v = time.localtime(stat.st_mtime) 384 | time_str = time.strftime(g_time_format, v) 385 | return time_str 386 | return '' 387 | 388 | def CheckDependFileMTime(f, mtime): 389 | time_str = GetFileMTime(f) 390 | return time_str == mtime 391 | 392 | def GetIncludesDirectories(filename, func, cache_name_leader): 393 | dirs, mk = func(filename) 394 | if len(dirs) == 0: 395 | return dirs 396 | 397 | return dirs 398 | 399 | def FlagsForFile( filename, **kwargs ): 400 | Log("-------------- %s --------------" % filename) 401 | Log("WorkDirectory is: %s" % os.getcwd()) 402 | final_flags = flags 403 | final_flags.extend(['-I', os.path.dirname(filename)]) 404 | 405 | # parse cmake 406 | try: 407 | cmake_include_dirs = CMakeIncludesFlags(filename) 408 | Log("CMake include direcotires: %s" % str(cmake_include_dirs)) 409 | for d in cmake_include_dirs: 410 | final_flags.append('-I') 411 | final_flags.append(d) 412 | except: 413 | Log("parse cmake failed:%s" % traceback.format_exc()) 414 | 415 | # parse makefile 416 | try: 417 | makefile_include_dirs = MakefileIncludesFlags(filename) 418 | Log("Makfile include direcotires: %s" % str(makefile_include_dirs)) 419 | for d in makefile_include_dirs: 420 | final_flags.append('-I') 421 | final_flags.append(d) 422 | except: 423 | Log("parse makefile failed:%s" % traceback.format_exc()) 424 | 425 | final_flags.extend(sysflags) 426 | 427 | Log("file:") 428 | Log(" %s" % filename) 429 | Log("final_flags:") 430 | for i in range(len(final_flags)/2): 431 | Log(" %s %s" % (final_flags[i*2], final_flags[i*2 + 1])) 432 | #Log("build command:") 433 | #cmd = 'g++ -std=c++0x -c %s ' % filename 434 | #cmd += ' '.join(final_flags) 435 | #Log(cmd) 436 | Log("-------------- Done [%s] --------------" % filename) 437 | 438 | return { 439 | 'flags': final_flags, 440 | 'do_cache': True 441 | } 442 | -------------------------------------------------------------------------------- /autoconf/_vimrc: -------------------------------------------------------------------------------- 1 | """"""""""""""""""""""""""快捷键设置""""""""""""""""""""""" 2 | if has("unix") 3 | map ;c :e ~/_vimrc 4 | elseif has("windows") 5 | map ;c :e $VIM/_vimrc 6 | endif 7 | 8 | map :source %:p 9 | map ;b ^ 10 | map ;e $ 11 | 12 | map ;q :q 13 | map ;Q :quitall 14 | map ;w :w 15 | map ;lw l 16 | map ;hw h 17 | map ;kw k 18 | map ;jw j 19 | map gl :b# 20 | map gL vgl 21 | map gY gygL 22 | 23 | map gr viw;ny:grep n *:cw 24 | vmap gr ;ny:grep n *:cw 25 | map gnr viw;ny:grep n ../* -r:cw 26 | vmap gnr ;ny:grep n ../* -r:cw 27 | 28 | map ;/ :nohls 29 | map ; " 30 | noremap ' ; 31 | 32 | map :tabnext 33 | map :tabprevious 34 | 35 | func! Toggle_relative_nu() 36 | if getbufvar('', "&rnu") == 0 37 | set relativenumber 38 | else 39 | set norelativenumber 40 | endif 41 | endfunc 42 | map :call Toggle_relative_nu() 43 | 44 | """"""""""""""""""""""""""MyPlugin""""""""""""""""""""""" 45 | map :e $HOME/.vim/vimfiles/bundle/cppenv/autoload/cppenv.vim 46 | map :call ag#toggleDebug() 47 | 48 | 49 | """"""""""""""""""""""""""Make""""""""""""""""""""""" 50 | 51 | " python 52 | autocmd BufNewFile,BufRead *.py map :! python %:p 53 | 54 | " C 55 | autocmd BufNewFile,BufRead *.c map :! gcc %:p -o out.exe -g -pthread 56 | autocmd BufNewFile,BufRead *.c map :! %:p:h/out.exe 57 | 58 | " C++ 59 | autocmd BufNewFile,BufRead *.cpp,*.cc map :! g++ -std=c++0x %:p -o out.exe -g -pthread 60 | autocmd BufNewFile,BufRead *.cpp,*.cc map :! %:p:h/out.exe 61 | autocmd BufNewFile,BufRead *.cpp,*.cc map :! g++ -std=c++0x %:p -o out.exe -g -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -static:! %:p:h/out.exe 62 | autocmd BufNewFile,BufRead *.cpp,*.cc map :! g++ -std=c++0x %:p -o out.exe -g -lboost_system -lboost_thread -pthread -static-libstdc++:! %:p:h/out.exe 63 | autocmd BufNewFile,BufRead *.cpp,*.cc map mkco :! g++ -std=c++0x %:p -o out.exe -g -llibgo -lboost_thread -lboost_system -ldl -pthread -static-libstdc++:! %:p:h/out.exe 64 | autocmd BufNewFile,BufRead *.cpp,*.cc map mkcob :! g++ -std=c++0x %:p -o out.exe -g -llibgo -lboost_coroutine -lboost_context -lboost_thread -lboost_system -ldl -pthread -static-libstdc++:! %:p:h/out.exe 65 | 66 | " go 67 | autocmd BufNewFile,BufRead *.go map :! go build % 68 | autocmd BufNewFile,BufRead *.go map :! go run % 69 | 70 | " java 71 | autocmd BufNewFile,BufRead *.java map :! javac % 72 | autocmd BufNewFile,BufRead *.java map :! java %:r 73 | 74 | "set makeef=compile_error.log 75 | "set makeprg=make.exe 76 | "set shellpipe= 77 | 78 | """"""""""""""""""""""""""VimEnv""""""""""""""""""""""" 79 | set path+=/usr/include,/usr/include/linux,/usr/include/c++/4.8,/usr/include/x86_64-linux-gnu,/usr/include/x86_64-linux-gnu/c++/4.8,/usr/include/i386-linux-gnu,/usr/include/i386-linux-gnu/c++/4.8,/usr/local/include 80 | 81 | """"""""""""""""""""""""""Style""""""""""""""""""""""" 82 | color evening 83 | "color torte 84 | filetype on 85 | filetype indent on 86 | filetype plugin on 87 | syntax on 88 | syntax enable 89 | set incsearch 90 | "set ignorecase 91 | set smartcase 92 | set nocompatible 93 | set wildmenu 94 | set number 95 | set hlsearch 96 | set nowrap 97 | set autochdir 98 | set fo-=ro 99 | 100 | "折叠 101 | set nofoldenable 102 | "set foldmethod=syntax 103 | set foldlevel=1 104 | 105 | "tab 106 | set expandtab "Tab转换成空格 107 | set tabstop=4 108 | set shiftwidth=4 109 | set softtabstop=4 110 | 111 | set gcr=a:block-blinkon0 "禁止光标闪烁 112 | set guioptions-=m 113 | set guioptions-=T 114 | set laststatus=2 115 | set guifont=Courier\ New:h12 116 | set encoding=utf-8 117 | set fileencoding=utf-8 118 | set fileencodings=utf-8,gbk ",utf-16,gb2312 "可识别文件编码 119 | 120 | set cc=80 121 | hi colorcolumn ctermbg=9 guibg=blue 122 | set backspace=indent,eol,start 123 | 124 | """"""""""""""""""""""""""Plugin Config""""""""""""""""""""""" 125 | 126 | " Vundle 127 | set nocompatible 128 | filetype off 129 | set rtp+=$VIM/vimfiles/bundle/Vundle.vim,$VIM/vimfiles/bundle 130 | set rtp+=$HOME/.vim/vimfiles/bundle/Vundle.vim,$HOME/.vim/vimfiles/bundle 131 | call vundle#begin("$HOME/.vim/vimfiles/bundle") 132 | Plugin 'https://gitee.com/yyzybb537/Vundle.vim.git', {'name': 'Vundle.vim'} 133 | Plugin 'yyzybb/cppenv' 134 | Plugin 'yyzybb/quickfixer' 135 | Plugin 'yyzybb/auto_govender' 136 | Plugin 'https://gitee.com/yyzybb537/vim-airline.git' 137 | Plugin 'https://gitee.com/yyzybb537/nerdtree.git' 138 | Plugin 'https://gitee.com/yyzybb537/taglist.vim.git', {'name': 'taglist.vim'} 139 | Plugin 'https://gitee.com/yyzybb537/ultisnips.git' 140 | Plugin 'https://gitee.com/yyzybb537/vim-snippets.git' 141 | Plugin 'https://gitee.com/yyzybb537/vim-go.git' 142 | Plugin 'https://gitee.com/yyzybb537/vim-toml.git' 143 | Plugin 'https://gitee.com/yyzybb537/tabular.git' 144 | Plugin 'https://gitee.com/yyzybb537/vim-markdown.git' 145 | Plugin 'https://gitee.com/yyzybb537/YouCompleteMe.git' 146 | Plugin 'https://gitee.com/yyzybb537/tagbar.git' 147 | 148 | "Plugin 'godlygeek/tabular' 149 | "Plugin 'plasticboy/vim-markdown' 150 | "Plugin 'suan/vim-instant-markdown' 151 | 152 | "Plugin 'gmarik/Vundle.vim' 153 | "Plugin 'bling/vim-airline' 154 | "Plugin 'scrooloose/nerdtree' 155 | "Plugin 'vim-scripts/taglist.vim' 156 | "Plugin 'yyzybb/cppenv' 157 | "Plugin 'yyzybb/quickfixer' 158 | "Plugin 'Valloric/YouCompleteMe' 159 | "Plugin 'SirVer/ultisnips' 160 | "Plugin 'honza/vim-snippets' 161 | "Plugin 'fatih/vim-go' 162 | "Plugin 'cespare/vim-toml' 163 | call vundle#end() 164 | filetype plugin indent on 165 | 166 | " YouCompleteMe 167 | "let g:ycm_log_level = 'info' 168 | "注释和字符串中的文字也会被收入补全 169 | let g:ycm_collect_identifiers_from_comments_and_strings = 0 170 | " 禁止缓存匹配项,每次都重新生成匹配项 171 | let g:ycm_cache_omnifunc=1 172 | " 开启语义补全 173 | let g:ycm_seed_identifiers_with_syntax=1 174 | "在注释输入中也能补全 175 | let g:ycm_complete_in_comments = 1 176 | "在字符串输入中也能补全 177 | let g:ycm_complete_in_strings = 1 178 | 179 | let g:ycm_error_symbol = '>>' 180 | let g:ycm_warning_symbol = '>*' 181 | let g:ycm_show_diagnostics_ui = 0 182 | let g:ycm_confirm_extra_conf = 0 183 | let g:ycm_global_ycm_extra_conf = "$HOME/.ycm_extra_conf.py" 184 | nnoremap gy :YcmCompleter GoToDefinitionElseDeclaration 185 | nnoremap gu :YcmCompleter GoToImprecise 186 | nmap :YcmDiags 187 | set completeopt=menuone 188 | 189 | " UltiSnips 190 | let g:UltiSnipsUsePythonVersion = 2 191 | let g:UltiSnipsExpandTrigger="" 192 | let g:UltiSnipsJumpForwardTrigger="" 193 | let g:UltiSnipsJumpBackwardTrigger="" 194 | let g:UltiSnipsEditSplit="vertical" 195 | let g:UltiSnipsSnippetDirectories=["UltiSnips","cppenv/snippets"] 196 | 197 | " airline 198 | let g:airline#extensions#tabline#enabled = 1 199 | let g:airline#extensions#tabline#left_sep = ' ' 200 | let g:airline#extensions#tabline#left_alt_sep = '|' 201 | 202 | " nerdtree 203 | map :NERDTreeToggle 204 | 205 | " tagbar 206 | let g:tagbar_left = 1 207 | map TL :TagbarToggle 208 | 209 | " taglist 210 | "let Tlist_Show_One_File=1 211 | "let Tlist_Exit_OnlyWindow=1 212 | "map TL :Tlist 213 | "map TU :TlistUpdate 214 | 215 | " cppenv 216 | au BufNewFile,BufRead * execute cppenv#dummy() 217 | au BufNewFile,BufRead *.h,*.hpp,*.inl,*.ipp,*.cpp,*.c,*.cc,*.go,*.proto,*.jce execute cppenv#infect() 218 | au BufNewFile,BufRead *.h,*.hpp,*.inl,*.ipp,*.cpp,*.c,*.cc,*.go,*.proto,*.jce set fo-=ro 219 | 220 | " auto_govender 221 | au BufNewFile,BufRead *.go execute ag#dummy() 222 | au BufWritePost *.go call ag#onSave() 223 | 224 | " vim-go 225 | let g:go_fmt_autosave = 0 226 | let g:go_def_mapping_enabled = 0 227 | let g:go_bin_path = '/tmp/bin' 228 | "let g:go_highlight_space_tab_error = 0 229 | let g:go_highlight_trailing_whitespace_error = 0 230 | au BufNewFile,BufRead *.go nnoremap gy :GoDef 231 | au BufNewFile,BufRead *.go nnoremap :GoErrCheck 232 | 233 | " tags 234 | set tags=tags,./tags,/usr/include/tags 235 | "set tags+=/home/yyz/C/Bex/Bex/tags,/home/yyz/C/Bex/boost/include/tags 236 | 237 | " vim-markdown 238 | let g:vim_markdown_folding_disabled = 1 239 | let g:vim_markdown_folding_style_pythonic = 1 240 | let g:vim_markdown_override_foldtext = 0 241 | let g:vim_markdown_folding_level = 6 242 | let g:vim_markdown_no_default_key_mappings = 1 243 | let g:vim_markdown_toc_autofit = 1 244 | let g:vim_markdown_emphasis_multiline = 0 245 | set conceallevel=2 246 | let g:vim_markdown_conceal = 0 247 | let g:tex_conceal = "" 248 | let g:vim_markdown_math = 1 249 | let g:vim_markdown_fenced_languages = ['csharp=cs', 'go=golang', 'c++=cpp', 'viml=vim', 'bash=sh', 'ini=dosini'] 250 | let g:vim_markdown_math = 1 251 | let g:vim_markdown_frontmatter = 1 252 | let g:vim_markdown_toml_frontmatter = 1 253 | let g:vim_markdown_json_frontmatter = 1 254 | let g:vim_markdown_new_list_item_indent = 2 255 | let g:vim_markdown_no_extensions_in_markdown = 1 256 | let g:vim_markdown_autowrite = 1 257 | 258 | "" vim-instant-markdown 259 | "let g:instant_markdown_slow = 1 260 | "let g:instant_markdown_autostart = 0 261 | "let g:instant_markdown_open_to_the_world = 1 262 | "let g:instant_markdown_allow_unsafe_content = 1 263 | "let g:instant_markdown_allow_external_content = 0 264 | 265 | " gvim on windows 266 | if !has("unix") 267 | source $VIMRUNTIME/vimrc_example.vim 268 | source $VIMRUNTIME/mswin.vim 269 | behave mswin 270 | endif 271 | 272 | set nobackup 273 | set noswapfile 274 | set undofile 275 | set undodir=$VIM/vimfiles/undodir 276 | set undolevels=100 277 | set sel=inclusive 278 | -------------------------------------------------------------------------------- /autoconf/cpp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Install: 4 | # cmake 3.11 5 | # llvm 6.0.0 6 | # clang 6.0.0 7 | # rebuild YCM 8 | set -e 9 | 10 | . ./lib/lib.sh $@ 11 | . ./lib/msg.sh 12 | 13 | cd tools 14 | ./cmake.sh 15 | #./bear.sh 16 | cd - 17 | 18 | install_clang() 19 | { 20 | clang_ver='' 21 | clang --version && clang_ver=`clang --version | grep version -i | awk '{print $4}' | cut -d\- -f1 | sed 's/[^0-9.]//g'` || echo -n 22 | test ! -z $clang_ver && version_ge $clang_ver "6.0.0" && return 0 || echo -n 23 | 24 | echo 'Not found clang in system, will install there from llvm-clang source code.' 25 | llvm_clang_dir=$TMP/llvm-clang_cppenv 26 | 27 | built_from_source=0 28 | 29 | isMac=`uname -a | grep Darwin -c || echo -n` 30 | echo "isMac:" $isMac 31 | if [ "$isMac" == "0" ]; then 32 | os_ver=`cat /etc/os-release | grep VERSION_ID | cut -d\" -f2` 33 | os_name=`cat /etc/os-release | grep NAME | head -n1 | cut -d\" -f2` 34 | echo "Current OS: " $os_name 35 | echo "Version: " $os_ver 36 | 37 | if [ "$os_name" == "Ubuntu" ] 38 | then 39 | if [ "$os_ver" == "16.04" ] 40 | then 41 | cd $TMP 42 | download http://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz 43 | xz -dk clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz 44 | tar xf clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04.tar 45 | cd clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04 46 | else 47 | if [ "$os_ver" == "14.04" ] 48 | then 49 | cd $TMP 50 | download http://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz 51 | xz -dk clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz 52 | tar xf clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-14.04.tar 53 | cd clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-14.04 54 | else 55 | built_from_source=1 56 | fi 57 | fi 58 | fi 59 | else 60 | echo "download clang6.0-Darwin" 61 | cd $TMP 62 | download http://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-apple-darwin.tar.xz clang+llvm-6.0.0-x86_64-apple-darwin.tar.xz 63 | xz -dk clang+llvm-6.0.0-x86_64-apple-darwin.tar.xz 64 | tar xf clang+llvm-6.0.0-x86_64-apple-darwin.tar 65 | cd clang+llvm-6.0.0-x86_64-apple-darwin 66 | exit 0 67 | fi 68 | 69 | if [ "$built_from_source" == "0" ] 70 | then 71 | cp include/* $HOME/include -r 72 | cp lib/* $HOME/lib -r 73 | cp libexec/* $HOME/bin 74 | cp bin/* $HOME/bin 75 | return 76 | fi 77 | 78 | LLVM_CLANG_GIT=https://gitee.com/yyzybb537/llvm-clang.git 79 | git_clone $LLVM_CLANG_GIT $llvm_clang_dir 80 | cd $llvm_clang_dir 81 | 82 | xz -dk llvm.tar.xz || echo -n 83 | xz -dk clang.tar.xz || echo -n 84 | tar xf clang.tar 85 | tar xf llvm.tar 86 | 87 | printMsg "build llvm" 88 | cd llvm-6.0.0.src 89 | mkdir -p build 90 | cd build 91 | cmake .. -DCMAKE_INSTALL_PREFIX=$HOME 92 | make $MAKEFLAGS 93 | make install 94 | cd ../.. 95 | 96 | printMsg "build clang" 97 | cd cfe-6.0.0.src 98 | mkdir -p build 99 | cd build 100 | cmake .. -DCMAKE_INSTALL_PREFIX=$HOME 101 | make $MAKEFLAGS 102 | make install 103 | cd .. 104 | 105 | pyclang_dst=$HOME/lib/python2.7/dist-packages 106 | test -d $pyclang_dst || pyclang_dst=$HOME/lib/python2.7/site-packages 107 | test -d $pyclang_dst && cp bindings/python/clang $pyclang_dst -r 108 | } 109 | #install_clang 110 | 111 | ycm_flags="--clang-completer" # --system-libclang" 112 | if [ "$isMac" == '1' ] 113 | then 114 | ycm_flags="$ycm_flags --system-libclang" 115 | fi 116 | which gocode && ycm_flags="$ycm_flags --go-completer" 117 | printMsg "build YouCompleteMe flags=$ycm_flags" 118 | ycm_path=${TMP}/YouCompleteMe 119 | cd $ycm_path 120 | cat ./third_party/ycmd/clang_archives/x* > ./third_party/ycmd/clang_archives/clang+llvm-5.0.0-linux-x86_64-ubuntu14.04.tar.xz 121 | ./install.py $ycm_flags 122 | 123 | echo 'vim-cpp-env is ok, good luck!' 124 | 125 | -------------------------------------------------------------------------------- /autoconf/git_cmd/git_add_modify: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | add_files=`git status -s $@ | egrep "^.(A|M)" | awk '{print $2}'` 4 | for f in $add_files 5 | do 6 | git add $f; 7 | echo add $f; 8 | done 9 | 10 | deleted_files=`git status -s $@ | egrep "^[^\s]*D[^\s]*\s" | awk '{print $2}'` 11 | for f in $deleted_files 12 | do 13 | git rm $f; 14 | echo rm $f; 15 | done 16 | -------------------------------------------------------------------------------- /autoconf/git_cmd/git_push: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | br=`git branch | grep \* | cut -d\ -f2` 4 | git push origin HEAD:refs/for/$br 5 | -------------------------------------------------------------------------------- /autoconf/git_cmd/git_rebase_upstream: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | git fetch upstream 4 | git rebase upstream/master 5 | git push origin master 6 | -------------------------------------------------------------------------------- /autoconf/go.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ./lib/lib.sh $@ 4 | 5 | cd tools 6 | ./golang.sh 7 | source $PROFILE 8 | 9 | set +e 10 | go get -v github.com/yyzybb537/goinstall 11 | go get -v github.com/kardianos/govendor 12 | go get -v github.com/rogpeppe/godef 13 | go get -v github.com/bradfitz/goimports 14 | go get -v github.com/bytbox/golint 15 | go get -v github.com/jstemmer/gotags 16 | go get -v github.com/kisielk/errcheck 17 | go get -v github.com/golang/tools 18 | 19 | set -e 20 | go get -v github.com/nsf/gocode 21 | 22 | #cd ${VIMPATH}/vimfiles/bundle/YouCompleteMe 23 | #./install.py --go-completer 24 | -------------------------------------------------------------------------------- /autoconf/install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ./lib/lib.sh $@ 4 | 5 | ./vim.sh $@ 6 | source $PROFILE 7 | 8 | if [ "$withGo" == '1' ] 9 | then 10 | ./go.sh $@ 11 | source $PROFILE 12 | fi 13 | 14 | ./cpp.sh $@ 15 | source $PROFILE 16 | 17 | if [ "$isMac" == '0' ] 18 | then 19 | test -f $PREFIX/bin/g++ && ./patchelf.sh $@ 20 | fi 21 | -------------------------------------------------------------------------------- /autoconf/lib/lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | export PREFIX=$HOME 6 | export VIMPATH=$HOME/.vim 7 | export TMP=$HOME/.vim.git 8 | export PROFILE=$HOME/.profile 9 | export BIN=$HOME/bin 10 | export isMac=`uname -a | grep Darwin -c || echo -n` 11 | export forceInstall= 12 | export withGo=0 13 | 14 | mkdir -p $TMP 15 | mkdir -p $VIMPATH 16 | mkdir -p $BIN 17 | test ! -f $PROFILE && touch $PROFILE || echo -n 18 | 19 | message() { 20 | echo -e "\033[32m$@\033[0m" 21 | } 22 | 23 | error() { 24 | echo -e "\033[31m$@\033[0m" 25 | } 26 | 27 | download() { 28 | url=$1 29 | filename=$2 30 | has=`md5sum -c ${filename}.md5 2>/dev/null >/dev/null && echo 1 || echo 0` 31 | if [ "$has" == "0" ] 32 | then 33 | message "----> Download $filename" 34 | wget $url -O $filename && md5sum $filename > ${filename}.md5 35 | message "====> Download $filename Success" 36 | else 37 | message "====> Exists $filename" 38 | fi 39 | } 40 | 41 | downloadByGit() { 42 | url=$1 43 | dir=$2 44 | if test -d $dir 45 | then 46 | message "----> git pull $url" 47 | cd $dir && git pull 48 | cd .. 49 | else 50 | message "----> git clone $url" 51 | git clone $url $dir 52 | fi 53 | } 54 | 55 | git_clone() 56 | { 57 | remote=$1 58 | dir=$2 59 | mkdir -p $dir 60 | 61 | cd $dir 62 | git status && git pull || git clone $remote . 63 | cd - 64 | } 65 | 66 | usage() 67 | { 68 | message "Flags: (-j4|-j8|...)" 69 | } 70 | 71 | while getopts "j:h:f:g" optvar 72 | do 73 | case $optvar in 74 | j): 75 | __makeflags="-j$OPTARG" 76 | ;; 77 | f): 78 | export forceInstall=1 79 | ;; 80 | g): 81 | export withGo=1 82 | ;; 83 | h): 84 | usage 85 | exit 1 86 | ;; 87 | esac 88 | done 89 | 90 | if [ "$CPPENV_LIB_SHELL_INITED" == "" -o "$__makeflags" != "" ] 91 | then 92 | export CPPENV_LIB_SHELL_INITED=1 93 | export MAKEFLAGS=$__makeflags 94 | message "set MAKEFLAGS=$MAKEFLAGS" 95 | fi 96 | 97 | version_ge() 98 | { 99 | lhs=$1 100 | rhs=$2 101 | lhs_major=`echo $lhs | cut -d. -f1` 102 | lhs_minor=`echo $lhs | cut -d. -f2` 103 | lhs_num=`echo $lhs | cut -d. -f3` 104 | test -z $lhs_major && lhs_major=0 || echo -n 105 | test -z $lhs_minor && lhs_minor=0 || echo -n 106 | test -z $lhs_num && lhs_num=0 || echo -n 107 | 108 | rhs_major=`echo $rhs | cut -d. -f1` 109 | rhs_minor=`echo $rhs | cut -d. -f2` 110 | rhs_num=`echo $rhs | cut -d. -f3` 111 | test -z $rhs_major && rhs_major=0 || echo -n 112 | test -z $rhs_minor && rhs_minor=0 || echo -n 113 | test -z $rhs_num && rhs_num=0 || echo -n 114 | 115 | lhs_cmp=`expr $lhs_major \* 10000 + $lhs_minor \* 100 + $lhs_num` 116 | rhs_cmp=`expr $rhs_major \* 10000 + $rhs_minor \* 100 + $rhs_num` 117 | test $lhs_cmp -ge $rhs_cmp 118 | } 119 | 120 | -------------------------------------------------------------------------------- /autoconf/lib/msg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | printMsg() 4 | { 5 | message "------- $1 -------" 6 | message "MAKEFLAGS: $MAKEFLAGS" 7 | message "CC: $CC" 8 | message "CXX: $CXX" 9 | message "LIBRARY_PATH: $LIBRARY_PATH" 10 | message "LD_LIBRARY_PATH: $LD_LIBRARY_PATH" 11 | } 12 | 13 | if [ $# -ge 1 ] 14 | then 15 | printMsg $1 16 | fi 17 | -------------------------------------------------------------------------------- /autoconf/lib/pt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "------- $1 -------" 4 | echo "MAKEFLAGS: $MAKEFLAGS" 5 | echo "CC: $CC" 6 | echo "CXX: $CXX" 7 | echo "LIBRARY_PATH: $LIBRARY_PATH" 8 | echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH" 9 | -------------------------------------------------------------------------------- /autoconf/patchelf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ./lib/lib.sh $@ 4 | 5 | # patchelf 6 | patch_rpath() 7 | { 8 | patchelf --set-rpath $HOME/lib:$HOME/lib64:$HOME/gcc/x86_64-pc-linux-gnu $1 9 | } 10 | for elf in `ls $HOME/bin` 11 | do 12 | patch_rpath $HOME/bin/$elf || echo "patchelf $HOME/bin/$elf error." 13 | done 14 | 15 | patchelf --set-rpath \ 16 | $VIMPATH/vimfiles/bundle/YouCompleteMe/third_party/ycmd:$HOME/lib:$HOME/lib64:$HOME/gcc/x86_64-pc-linux-gnu \ 17 | $VIMPATH/vimfiles/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so 18 | -------------------------------------------------------------------------------- /autoconf/shell_cmd/del.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | grep "$1" * -rn | cut -d: -f1 | xargs sed -i "/${1}/d" 4 | -------------------------------------------------------------------------------- /autoconf/shell_cmd/swap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | grep "$1" * -rn | cut -d: -f1 | xargs sed -i "s/${1}/${2}/g" 4 | -------------------------------------------------------------------------------- /autoconf/simple/_vimrc: -------------------------------------------------------------------------------- 1 | """"""""""""""""""""""""""快捷键设置""""""""""""""""""""""" 2 | if has("unix") 3 | map ;c :e ~/_vimrc 4 | elseif has("windows") 5 | map ;c :e $VIM/_vimrc 6 | endif 7 | 8 | map :source %:p 9 | map ;b ^ 10 | map ;e $ 11 | 12 | map ;q :q 13 | map ;Q :quitall 14 | map ;w :w 15 | map ;lw l 16 | map ;hw h 17 | map ;kw k 18 | map ;jw j 19 | map gl :b# 20 | map gL vgl 21 | map gY gygL 22 | 23 | map gr viw;ny:grep n *:cw 24 | vmap gr ;ny:grep n *:cw 25 | map gnr viw;ny:grep n ../* -r:cw 26 | vmap gnr ;ny:grep n ../* -r:cw 27 | 28 | map ;/ :nohls 29 | map ; " 30 | noremap ' ; 31 | 32 | map :tabnext 33 | map :tabprevious 34 | 35 | func! Toggle_relative_nu() 36 | if getbufvar('', "&rnu") == 0 37 | set relativenumber 38 | else 39 | set norelativenumber 40 | endif 41 | endfunc 42 | map :call Toggle_relative_nu() 43 | 44 | """"""""""""""""""""""""""MyPlugin""""""""""""""""""""""" 45 | "map :e $HOME/.vim/vimfiles/bundle/cppenv/autoload/cppenv.vim 46 | "map :call ag#toggleDebug() 47 | 48 | 49 | """"""""""""""""""""""""""Make""""""""""""""""""""""" 50 | 51 | " python 52 | autocmd BufNewFile,BufRead *.py map :! python %:p 53 | 54 | " C 55 | autocmd BufNewFile,BufRead *.c map :! gcc %:p -o out.exe -g -pthread 56 | autocmd BufNewFile,BufRead *.c map :! %:p:h/out.exe 57 | 58 | " C++ 59 | autocmd BufNewFile,BufRead *.cpp map :! g++ -std=c++11 %:p -o out.exe -g -pthread 60 | autocmd BufNewFile,BufRead *.cpp map :! %:p:h/out.exe 61 | autocmd BufNewFile,BufRead *.cpp map :! g++ -std=c++11 %:p -o out.exe -g -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -static:! %:p:h/out.exe 62 | autocmd BufNewFile,BufRead *.cpp map :! g++ -std=c++11 %:p -o out.exe -g -lboost_system -lboost_thread -pthread -static-libstdc++:! %:p:h/out.exe 63 | autocmd BufNewFile,BufRead *.cpp map mkco :! g++ -std=c++11 %:p -o out.exe -g -llibgo -lboost_thread -lboost_system -ldl -pthread -static-libstdc++:! %:p:h/out.exe 64 | autocmd BufNewFile,BufRead *.cpp map mkcob :! g++ -std=c++11 %:p -o out.exe -g -llibgo -lboost_coroutine -lboost_context -lboost_thread -lboost_system -ldl -pthread -static-libstdc++:! %:p:h/out.exe 65 | 66 | " go 67 | autocmd BufNewFile,BufRead *.go map :! go build % 68 | autocmd BufNewFile,BufRead *.go map :! go run % 69 | 70 | " java 71 | autocmd BufNewFile,BufRead *.java map :! javac % 72 | autocmd BufNewFile,BufRead *.java map :! java %:r 73 | 74 | "set makeef=compile_error.log 75 | "set makeprg=make.exe 76 | "set shellpipe= 77 | 78 | """"""""""""""""""""""""""VimEnv""""""""""""""""""""""" 79 | set path+=/usr/include,/usr/include/linux,/usr/include/c++/4.8,/usr/include/x86_64-linux-gnu,/usr/include/x86_64-linux-gnu/c++/4.8,/usr/include/i386-linux-gnu,/usr/include/i386-linux-gnu/c++/4.8,/usr/local/include 80 | 81 | """"""""""""""""""""""""""Style""""""""""""""""""""""" 82 | color evening 83 | "color torte 84 | filetype on 85 | filetype indent on 86 | filetype plugin on 87 | syntax on 88 | syntax enable 89 | set incsearch 90 | "set ignorecase 91 | set smartcase 92 | set nocompatible 93 | set wildmenu 94 | set number 95 | set hlsearch 96 | set nowrap 97 | set autochdir 98 | set fo-=ro 99 | 100 | "折叠 101 | set nofoldenable 102 | set foldmethod=syntax 103 | set foldlevel=1 104 | 105 | "tab 106 | set expandtab "Tab转换成空格 107 | set tabstop=4 108 | set shiftwidth=4 109 | set softtabstop=4 110 | 111 | set gcr=a:block-blinkon0 "禁止光标闪烁 112 | set guioptions-=m 113 | set guioptions-=T 114 | set laststatus=2 115 | set guifont=Courier\ New:h12 116 | set encoding=utf-8 117 | set fileencoding=utf-8 118 | set fileencodings=utf-8,gbk ",utf-16,gb2312 "可识别文件编码 119 | 120 | set cc=80 121 | hi colorcolumn ctermbg=9 guibg=blue 122 | set backspace=indent,eol,start 123 | 124 | """"""""""""""""""""""""""Plugin Config""""""""""""""""""""""" 125 | 126 | " Vundle 127 | set nocompatible 128 | filetype off 129 | "set rtp+=$VIM/vimfiles/bundle/Vundle.vim,$VIM/vimfiles/bundle 130 | "set rtp+=$HOME/.vim/vimfiles/bundle/Vundle.vim,$HOME/.vim/vimfiles/bundle 131 | "call vundle#begin("$HOME/.vim/vimfiles/bundle") 132 | "Plugin 'https://gitee.com/yyzybb537/Vundle.vim.git', {'name': 'Vundle.vim'} 133 | "Plugin 'yyzybb/cppenv' 134 | "Plugin 'yyzybb/quickfixer' 135 | "Plugin 'yyzybb/auto_govender' 136 | "Plugin 'https://gitee.com/yyzybb537/vim-airline.git' 137 | "Plugin 'https://gitee.com/yyzybb537/nerdtree.git' 138 | "Plugin 'https://gitee.com/yyzybb537/taglist.vim.git', {'name': 'taglist.vim'} 139 | "Plugin 'https://gitee.com/yyzybb537/ultisnips.git' 140 | "Plugin 'https://gitee.com/yyzybb537/vim-snippets.git' 141 | "Plugin 'https://gitee.com/yyzybb537/vim-go.git' 142 | "Plugin 'https://gitee.com/yyzybb537/vim-toml.git' 143 | "Plugin 'https://gitee.com/yyzybb537/tabular.git' 144 | "Plugin 'https://gitee.com/yyzybb537/vim-markdown.git' 145 | "Plugin 'https://gitee.com/yyzybb537/YouCompleteMe.git' 146 | "call vundle#end() 147 | filetype plugin indent on 148 | 149 | "" YouCompleteMe 150 | "let g:ycm_error_symbol = '>>' 151 | "let g:ycm_warning_symbol = '>*' 152 | "let g:ycm_show_diagnostics_ui = 0 153 | "let g:ycm_global_ycm_extra_conf = '/data1/home/yuyangzi/.ycm_extra_conf.py' 154 | "nnoremap gy :YcmCompleter GoToDefinitionElseDeclaration 155 | "nnoremap gu :YcmCompleter GoToImprecise 156 | "nmap :YcmDiags 157 | "set completeopt=menuone 158 | " 159 | "" UltiSnips 160 | "let g:UltiSnipsUsePythonVersion = 2 161 | "let g:UltiSnipsExpandTrigger="" 162 | "let g:UltiSnipsJumpForwardTrigger="" 163 | "let g:UltiSnipsJumpBackwardTrigger="" 164 | "let g:UltiSnipsEditSplit="vertical" 165 | "let g:UltiSnipsSnippetDirectories=["UltiSnips","cppenv/snippets"] 166 | 167 | "" airline 168 | "let g:airline#extensions#tabline#enabled = 1 169 | "let g:airline#extensions#tabline#left_sep = ' ' 170 | "let g:airline#extensions#tabline#left_alt_sep = '|' 171 | " 172 | "" nerdtree 173 | "map :NERDTreeToggle 174 | " 175 | "" taglist 176 | "let Tlist_Show_One_File=1 177 | "let Tlist_Exit_OnlyWindow=1 178 | "map TL :Tlist 179 | "map TU :TlistUpdate 180 | " 181 | "" cppenv 182 | "au BufNewFile,BufRead * execute cppenv#dummy() 183 | "au BufNewFile,BufRead *.h,*.hpp,*.inl,*.ipp,*.cpp,*.c,*.cc,*.go,*.proto execute cppenv#infect() 184 | "au BufNewFile,BufRead *.h,*.hpp,*.inl,*.ipp,*.cpp,*.c,*.cc,*.go,*.proto set fo-=ro 185 | " 186 | "" auto_govender 187 | "au BufNewFile,BufRead *.go execute ag#dummy() 188 | "au BufWritePost *.go call ag#onSave() 189 | " 190 | "" vim-go 191 | "let g:go_fmt_autosave = 0 192 | "let g:go_def_mapping_enabled = 0 193 | "let g:go_bin_path = '/tmp/bin' 194 | ""let g:go_highlight_space_tab_error = 0 195 | "let g:go_highlight_trailing_whitespace_error = 0 196 | "au BufNewFile,BufRead *.go nnoremap gy :GoDef 197 | "au BufNewFile,BufRead *.go nnoremap :GoErrCheck 198 | " 199 | "" tags 200 | "set tags=tags,./tags,/usr/include/tags 201 | ""set tags+=/home/yyz/C/Bex/Bex/tags,/home/yyz/C/Bex/boost/include/tags 202 | " 203 | "" vim-markdown 204 | "let g:vim_markdown_folding_disabled = 1 205 | "let g:vim_markdown_folding_style_pythonic = 1 206 | "let g:vim_markdown_override_foldtext = 0 207 | "let g:vim_markdown_folding_level = 6 208 | "let g:vim_markdown_no_default_key_mappings = 1 209 | "let g:vim_markdown_toc_autofit = 1 210 | "let g:vim_markdown_emphasis_multiline = 0 211 | "set conceallevel=2 212 | "let g:vim_markdown_conceal = 0 213 | "let g:tex_conceal = "" 214 | "let g:vim_markdown_math = 1 215 | "let g:vim_markdown_fenced_languages = ['csharp=cs', 'go=golang', 'c++=cpp', 'viml=vim', 'bash=sh', 'ini=dosini'] 216 | "let g:vim_markdown_math = 1 217 | "let g:vim_markdown_frontmatter = 1 218 | "let g:vim_markdown_toml_frontmatter = 1 219 | "let g:vim_markdown_json_frontmatter = 1 220 | "let g:vim_markdown_new_list_item_indent = 2 221 | "let g:vim_markdown_no_extensions_in_markdown = 1 222 | "let g:vim_markdown_autowrite = 1 223 | " 224 | """ vim-instant-markdown 225 | ""let g:instant_markdown_slow = 1 226 | ""let g:instant_markdown_autostart = 0 227 | ""let g:instant_markdown_open_to_the_world = 1 228 | ""let g:instant_markdown_allow_unsafe_content = 1 229 | ""let g:instant_markdown_allow_external_content = 0 230 | 231 | " gvim on windows 232 | if !has("unix") 233 | source $VIMRUNTIME/vimrc_example.vim 234 | source $VIMRUNTIME/mswin.vim 235 | behave mswin 236 | endif 237 | 238 | set nobackup 239 | set noswapfile 240 | set undofile 241 | set undodir=$VIM/vimfiles/undodir 242 | set undolevels=100 243 | set sel=inclusive 244 | -------------------------------------------------------------------------------- /autoconf/simple/install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Install the vim and cppenviron. 4 | # 5 | # * And contains config files: 6 | # _vimrc 7 | # 8 | 9 | . ../lib/lib.sh $@ 10 | 11 | set -e 12 | 13 | # copy _vimrc to $HOME 14 | which dos2unix && dos2unix _vimrc 15 | rm $HOME/_vimrc -f 16 | cp _vimrc $HOME/_vimrc 17 | chmod 0666 $HOME/_vimrc 18 | 19 | # clean and backup .vimrc 20 | test -f $HOME/.vimrc && mv $HOME/.vimrc $HOME/.vimrc.`date "+%Y-%m-%dT%H:%M:%S"` 21 | 22 | # alias v to vim 23 | mkdir -p $HOME/bin 24 | rm $HOME/bin/v -f 25 | ln -s `which vim` $HOME/bin/v || echo -n 26 | message 'vim-simple-env is ok, good luck!' 27 | 28 | -------------------------------------------------------------------------------- /autoconf/sources/CentOS7-Base-163.repo: -------------------------------------------------------------------------------- 1 | # CentOS-Base.repo 2 | # 3 | # The mirror system uses the connecting IP address of the client and the 4 | # update status of each mirror to pick mirrors that are updated to and 5 | # geographically close to the client. You should use this for CentOS updates 6 | # unless you are manually picking other mirrors. 7 | # 8 | # If the mirrorlist= does not work for you, as a fall back you can try the 9 | # remarked out baseurl= line instead. 10 | # 11 | # 12 | [base] 13 | name=CentOS-$releasever - Base - 163.com 14 | #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os 15 | baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/ 16 | gpgcheck=1 17 | gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 18 | 19 | #released updates 20 | [updates] 21 | name=CentOS-$releasever - Updates - 163.com 22 | #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates 23 | baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/ 24 | gpgcheck=1 25 | gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 26 | 27 | #additional packages that may be useful 28 | [extras] 29 | name=CentOS-$releasever - Extras - 163.com 30 | #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras 31 | baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/ 32 | gpgcheck=1 33 | gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 34 | 35 | #additional packages that extend functionality of existing packages 36 | [centosplus] 37 | name=CentOS-$releasever - Plus - 163.com 38 | baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/ 39 | gpgcheck=1 40 | enabled=0 41 | gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 42 | -------------------------------------------------------------------------------- /autoconf/sources/Ubuntu14.04: -------------------------------------------------------------------------------- 1 | deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse 2 | deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse 3 | deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse 4 | deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse 5 | deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse 6 | deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse 7 | deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse 8 | deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse 9 | deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse 10 | deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse 11 | -------------------------------------------------------------------------------- /autoconf/sources/Ubuntu15.04: -------------------------------------------------------------------------------- 1 | deb http://mirrors.163.com/ubuntu/ vivid main restricted universe multiverse 2 | deb http://mirrors.163.com/ubuntu/ vivid-security main restricted universe multiverse 3 | deb http://mirrors.163.com/ubuntu/ vivid-updates main restricted universe multiverse 4 | deb http://mirrors.163.com/ubuntu/ vivid-proposed main restricted universe multiverse 5 | deb http://mirrors.163.com/ubuntu/ vivid-backports main restricted universe multiverse 6 | deb-src http://mirrors.163.com/ubuntu/ vivid main restricted universe multiverse 7 | deb-src http://mirrors.163.com/ubuntu/ vivid-security main restricted universe multiverse 8 | deb-src http://mirrors.163.com/ubuntu/ vivid-updates main restricted universe multiverse 9 | deb-src http://mirrors.163.com/ubuntu/ vivid-proposed main restricted universe multiverse 10 | deb-src http://mirrors.163.com/ubuntu/ vivid-backports main restricted universe multiverse 11 | -------------------------------------------------------------------------------- /autoconf/tools/bear.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/bear 9 | 10 | if test -z $forceInstall 11 | then 12 | test -f $target && $target --version && exit 0 13 | fi 14 | 15 | cd $TMP 16 | downloadByGit "https://github.com/rizsotto/Bear.git" Bear 17 | cd Bear 18 | mkdir build -p 19 | cd build/ 20 | cmake .. -DCMAKE_INSTALL_PREFIX=$PREFIX 21 | make $MAKEFLAGS 22 | make install 23 | -------------------------------------------------------------------------------- /autoconf/tools/cmake.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/cmake 9 | pkg=cmake.tar.gz 10 | 11 | if test -z $forceInstall 12 | then 13 | test -f $target && $target --version && exit 0 14 | fi 15 | 16 | # version >= 3.11 17 | if [ "`which cmake | wc -l`" == "1" ] 18 | then 19 | ver=`cmake --version | head -1 | awk '{print $3}' | cut -d\. -f1-2` 20 | version_ge ${ver} "3.0" && exit 0 21 | fi 22 | 23 | cd $TMP 24 | #download "https://github.com/Kitware/CMake/archive/v3.11.3.tar.gz" $pkg 25 | downloadByGit "https://gitee.com/yyzybb537/vim-tgz.git" vimgit 26 | cd vimgit 27 | tar zxf $pkg 28 | dir=`tar tf $pkg | head -1` 29 | cd $dir 30 | ./bootstrap --prefix=$PREFIX 31 | #./configure --prefix=$PREFIX 32 | make $MAKEFLAGS 33 | make install 34 | -------------------------------------------------------------------------------- /autoconf/tools/ctags.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/ctags 9 | pkg=ctags.tar.gz 10 | 11 | if test -z $forceInstall 12 | then 13 | test -f $target && $target --version && exit 0 14 | fi 15 | 16 | cd $TMP 17 | download "http://prdownloads.sourceforge.net/ctags/ctags-5.8.tar.gz" $pkg 18 | tar zxf $pkg 19 | dir=`tar tf $pkg | head -1` 20 | cd $dir 21 | ./configure --prefix=$PREFIX 22 | make $MAKEFLAGS 23 | make install 24 | -------------------------------------------------------------------------------- /autoconf/tools/dos2unix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/dos2unix 9 | pkg=dos2unix.tar.gz 10 | 11 | if test -z $forceInstall 12 | then 13 | dos2unix --version && exit 0 14 | test -f $target && $target --version && exit 0 15 | fi 16 | 17 | cd $TMP 18 | downloadByGit "https://gitee.com/yyzybb537/vim-tgz.git" vimgit 19 | cd vimgit 20 | tar zxf $pkg 21 | dir=dos2unix 22 | cd $dir 23 | make || true 24 | make || true 25 | cp dos2unix $target 26 | test -f $target && $target --version 27 | -------------------------------------------------------------------------------- /autoconf/tools/gcc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/g++ 9 | pkg=gcc.tar.gz 10 | 11 | if test -z $forceInstall 12 | then 13 | echo "int main() { return 0; }" > $TMP/main.cpp 14 | g++ -std=c++11 -E $TMP/main.cpp && exit 0 || 15 | test -f $target && $target --version && exit 0 16 | fi 17 | 18 | cd $TMP 19 | download "https://github.com/gcc-mirror/gcc/archive/gcc-7_1_0-release.tar.gz" $pkg 20 | tar zxf $pkg 21 | dir=`tar tf $pkg | head -1` 22 | cd $dir 23 | ./contrib/download_prerequisites 24 | mkdir gcc-build 25 | cd gcc-build 26 | ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --prefix=$PREFIX/gcc7 27 | make $MAKEFLAGS 28 | make install 29 | 30 | #set default compiler 31 | #has=`grep "export CXX=\\\$HOME/bin/g++" -c $PROFILE || echo -n` 32 | #if [ "$has" == "0" ] 33 | #then 34 | # echo "export CC=\$HOME/bin/gcc" >> $PROFILE 35 | # echo "export CXX=\$HOME/bin/g++" >> $PROFILE 36 | # echo "export LIBRARY_PATH=\$HOME/lib:\$HOME/lib64:\$HOME/lib/gcc/x86_64-pc-linux-gnu/:\$LIBRARY_PATH" >> $PROFILE 37 | # echo "export LD_LIBRARY_PATH=\$HOME/lib:\$HOME/lib64:\$HOME/lib/gcc/x86_64-pc-linux-gnu/:\$LD_LIBRARY_PATH" >> $PROFILE 38 | #fi 39 | -------------------------------------------------------------------------------- /autoconf/tools/gdbm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/gdbmtool 9 | pkg=gdbm-1.18.1.tar.gz 10 | 11 | if test -z $forceInstall 12 | then 13 | test -f $target && $target --version && exit 0 14 | fi 15 | 16 | cd $TMP 17 | download "ftp://ftp.gnu.org/gnu/gdbm/gdbm-1.18.1.tar.gz" $pkg 18 | tar zxf $pkg 19 | dir=gdbm-1.18.1 20 | cd $dir 21 | ./configure --prefix=$PREFIX 22 | make $MAKEFLAGS 23 | make install 24 | -------------------------------------------------------------------------------- /autoconf/tools/git.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/git 9 | pkg=git.tar.gz 10 | 11 | if test -z $forceInstall 12 | then 13 | test -f $target && $target --version && exit 0 || echo -n 14 | git --version && exit 0 || echo -n 15 | fi 16 | 17 | cd $TMP 18 | download "https://www.kernel.org/pub/software/scm/git/git-2.12.2.tar.gz" $pkg 19 | tar zxf $pkg 20 | dir=`tar tf $pkg | head -1` 21 | cd $dir 22 | ./configure --prefix=$PREFIX 23 | make $MAKEFLAGS 24 | make install 25 | -------------------------------------------------------------------------------- /autoconf/tools/golang.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | # check 9 | go_ver='' 10 | 11 | if test -z $forceInstall 12 | then 13 | which go && go_ver=`go version | awk '{print $3}' | sed 's/[^0-9.]//g'` || echo -n 14 | test ! -z $go_ver && version_ge $go_ver "1.10.1" && exit 0 || echo -n 15 | fi 16 | 17 | message "---------- Download golang 1.10.1 -----------" 18 | cd $TMP 19 | isMac=`uname -a | grep Darwin -c || echo -n` 20 | if [ "$isMac" == "0" ]; then 21 | url=https://studygolang.com/dl/golang/go1.10.1.linux-amd64.tar.gz 22 | pkg=go1.10.1.linux-amd64.tar.gz 23 | else 24 | url=https://studygolang.com/dl/golang/go1.10.1.darwin-amd64.tar.gz 25 | pkg=go1.10.1.darwin-amd64.tar.gz 26 | fi 27 | download $url $pkg 28 | message "---------- Uncompress package ----------" 29 | test -d go || tar zxf $pkg 30 | message "---------- Copy it ----------" 31 | cp go $HOME -r || echo -n 32 | cd - 33 | 34 | has=`grep -c "export GOROOT=\\\$HOME/go" $PROFILE || echo -n` 35 | if [ "$has" == "0" ] 36 | then 37 | message "---------- Insert env to ~/.profile ----------" 38 | echo "export GOROOT=\$HOME/go" >> $PROFILE 39 | echo "export GOPATH=\$HOME/gopath" >> $PROFILE 40 | echo "export GOBIN=\$GOROOT/bin" >> $PROFILE 41 | echo "export PATH=\$PATH:\$GOBIN" >> $PROFILE 42 | fi 43 | -------------------------------------------------------------------------------- /autoconf/tools/libncurses.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | pkg=ncurses.tar.gz 9 | test -d $PREFIX/include/ncurses && exit 0 10 | 11 | cd $TMP 12 | download "http://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.1.tar.gz" $pkg 13 | tar zxf $pkg 14 | dir=`tar tf $pkg | head -1` 15 | cd $dir 16 | ./configure --prefix=$PREFIX --with-shared 17 | make $MAKEFLAGS 18 | make install 19 | -------------------------------------------------------------------------------- /autoconf/tools/patchelf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/patchelf 9 | pkg=patchelf.tar.gz 10 | 11 | if test -z $forceInstall 12 | then 13 | test -f $target && $target --version && exit 0 14 | fi 15 | 16 | cd $TMP 17 | download "https://nixos.org/releases/patchelf/patchelf-0.9/patchelf-0.9.tar.gz" $pkg 18 | tar zxf $pkg 19 | dir=`tar tf $pkg | head -1` 20 | cd $dir 21 | ./configure --prefix=$PREFIX 22 | make $MAKEFLAGS 23 | make install 24 | -------------------------------------------------------------------------------- /autoconf/tools/python.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/python 9 | pkg=python.tar.xz 10 | 11 | if test -z $forceInstall 12 | then 13 | test -f $target && $target --version && exit 0 14 | fi 15 | 16 | #./gdbm.sh 17 | 18 | cd $TMP 19 | download "https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz" $pkg 20 | xz -dkf $pkg 21 | tar xf python.tar 22 | dir=`tar tf python.tar | head -1` 23 | cd $dir 24 | ./configure --prefix=$PREFIX 25 | ./configure --prefix=$PREFIX --enable-shared LDFLAGS="-Wl,-rpath $PREFIX/lib" --enable-unicode=ucs4 26 | make $MAKEFLAGS 27 | make install 28 | make commoninstall 29 | -------------------------------------------------------------------------------- /autoconf/tools/ruby.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/ruby 9 | pkg=ruby.tar.gz 10 | 11 | if test -z $forceInstall 12 | then 13 | test -f $target && $target --version && exit 0 14 | fi 15 | 16 | cd $TMP 17 | download "https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz" $pkg 18 | tar zxf $pkg 19 | dir=`tar tf $pkg | head -1` 20 | cd $dir 21 | ./configure --prefix=$PREFIX 22 | make $MAKEFLAGS 23 | make install 24 | -------------------------------------------------------------------------------- /autoconf/tools/vim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | . ../lib/lib.sh $@ 6 | . ../lib/msg.sh $0 7 | 8 | target=$PREFIX/bin/vim 9 | pkg=vim.tar.gz 10 | 11 | if test -z $forceInstall 12 | then 13 | test -f $target && $target --version && exit 0 14 | fi 15 | 16 | cd $TMP 17 | #download "https://github.com/vim/vim/archive/v7.4.2367.tar.gz" $pkg 18 | downloadByGit "https://gitee.com/yyzybb537/vim-tgz.git" vimgit 19 | cd vimgit 20 | tar zxf $pkg 21 | dir=`tar tf $pkg | head -1` 22 | cd $dir 23 | ./configure --with-features=huge --enable-multibyte \ 24 | --enable-pythoninterp=yes --enable-rubyinterp=yes \ 25 | --enable-luainterp=yes --enable-perlinterp=yes \ 26 | --enable-gui=gtk2 \ 27 | --with-tlib=ncurses \ 28 | --enable-cscope \ 29 | --with-python-config-dir=$PREFIX/lib/python2.7/config \ 30 | --prefix=$PREFIX 31 | make $MAKEFLAGS 32 | make install 33 | -------------------------------------------------------------------------------- /autoconf/vim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Install the vim and cppenviron. 4 | # 5 | # * Need tools: 6 | # wget 7 | # dos2unix 8 | # 9 | # * It's contains software: 10 | # git 11 | # g++ supports -std=c++11 12 | # vim 7.4.2367 13 | # ctags 14 | # python 15 | # python-dev 16 | # ruby 17 | # ruby-dev 18 | # 19 | # * Vim plugins: 20 | # vim-YouCompleteMe 21 | # vim-vundle 22 | # vim-airline 23 | # vim-nerdtree 24 | # vim-taglist 25 | # vim-cppenv. 26 | # 27 | # * And contains config files: 28 | # _vimrc 29 | # .ycm_extra_conf.py 30 | # 31 | 32 | # install dos2unix, git, vim, g++, ctags, cmake, python-dev 33 | 34 | . ./lib/lib.sh $@ 35 | . ./lib/msg.sh 36 | 37 | set -e 38 | 39 | workdir=`pwd` 40 | if [ "$isMac" == '1' ] 41 | then 42 | brew --version || /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 43 | brew update 44 | wget --version || brew install wget 45 | dos2unix --version || brew install dos2unix 46 | echo 'MacOS brew installed OK' 47 | fi 48 | 49 | # config git address 50 | VUNDLE_GIT=https://gitee.com/yyzybb537/Vundle.vim.git 51 | YCM_GIT=https://gitee.com/yyzybb537/YouCompleteMe.git 52 | 53 | # update profile 54 | has=`grep "export PATH=\\\$HOME/bin:\\\$PATH" -c $PROFILE || true` 55 | if [ "$has" == "0" ] 56 | then 57 | echo "export PATH=\$HOME/bin:\$PATH" >> $PROFILE 58 | echo "export LD_LIBRARY_PATH=\$HOME/lib:\$LD_LIBRARY_PATH" >> $PROFILE 59 | echo "export LIBRARY_PATH=\$LIBRARY_PATH:\$HOME/lib" >> $PROFILE 60 | fi 61 | source $PROFILE 62 | 63 | # install tools 64 | cd tools 65 | ./dos2unix.sh 66 | ./gcc.sh 67 | source $PROFILE 68 | ./git.sh 69 | ./ctags.sh 70 | test -f $PREFIX/bin/g++ && ./patchelf.sh 71 | #./mlocate.sh 72 | 73 | if [ "$isMac" == "0" ]; then 74 | ./libncurses.sh 75 | ./python.sh 76 | ./ruby.sh 77 | ./vim.sh 78 | fi 79 | cd - 80 | 81 | # init git config, copy git_cmd and shell_cmd to BIN 82 | cp git_cmd/* $BIN 83 | cp shell_cmd/* $BIN 84 | user_name=`whoami` 85 | if [ `git config --global --list | grep user | wc -l` -eq 0 ] 86 | then 87 | git config --global user.email $user_name@gmail.com 88 | git config --global user.name $user_name 89 | fi 90 | git config --global diff.tool vimdiff 91 | git config --global diff.prompt false 92 | git config --global merge.tool vimdiff 93 | git config --global merge.prompt false 94 | git config --global alias.br "branch -av" 95 | git config --global alias.ss status 96 | git config --global alias.co checkout 97 | git config --global alias.cmt commit 98 | git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" 99 | git config --global alias.lgf "log --name-status" 100 | git config --global receive.denyCurrentBranch true 101 | git config --global core.editor vim 102 | 103 | # copy _vimrc and .ycm_extra_conf to $HOME 104 | dos2unix _vimrc 105 | rm $HOME/_vimrc -f 106 | cp _vimrc $HOME/_vimrc 107 | chmod 0666 $HOME/_vimrc 108 | sed -i "s|.*g:ycm_global_ycm_extra_conf.*|let g:ycm_global_ycm_extra_conf = \"$HOME/.ycm_extra_conf.py\"|g" $HOME/_vimrc 109 | dos2unix .ycm_extra_conf.py 110 | rm $HOME/.ycm_extra_conf.py -f 111 | cp .ycm_extra_conf.py $HOME/ 112 | chmod 0666 $HOME/.ycm_extra_conf.py 113 | vim_exe=`which vim` 114 | vim_exe_dir=`dirname $vim_exe` 115 | mkdir -p $HOME/bin 116 | rm $HOME/bin/v -f 117 | ln -s ${vim_exe_dir}/vim $HOME/bin/v || true 118 | 119 | # git clone vim-vundle.git 120 | vundle_path=${VIMPATH}/vimfiles/bundle/Vundle.vim 121 | git_clone ${VUNDLE_GIT} ${vundle_path} 122 | 123 | # compile YouCompleteMe 124 | printMsg "build YouCompleteMe --go-completer" 125 | ycm_path=${VIMPATH}/vimfiles/bundle 126 | ycm_path_ori=${TMP}/YouCompleteMe 127 | git_clone ${YCM_GIT} ${ycm_path_ori} 128 | ln -s ${ycm_path_ori} ${ycm_path} || true 129 | #cd ${ycm_path} 130 | #./install.py 131 | 132 | # install other's vim-plugins 133 | vim +BundleInstall -c quitall 134 | 135 | echo 'vim-base-env is ok, good luck!' 136 | 137 | -------------------------------------------------------------------------------- /autoconf/win/.ycm_extra_conf.py: -------------------------------------------------------------------------------- 1 | # This file is NOT licensed under the GPLv3, which is the license for the rest 2 | # of YouCompleteMe. 3 | # 4 | # Here's the license text for this file: 5 | # 6 | # This is free and unencumbered software released into the public domain. 7 | # 8 | # Anyone is free to copy, modify, publish, use, compile, sell, or 9 | # distribute this software, either in source code form or as a compiled 10 | # binary, for any purpose, commercial or non-commercial, and by any 11 | # means. 12 | # 13 | # In jurisdictions that recognize copyright laws, the author or authors 14 | # of this software dedicate any and all copyright interest in the 15 | # software to the public domain. We make this dedication for the benefit 16 | # of the public at large and to the detriment of our heirs and 17 | # successors. We intend this dedication to be an overt act of 18 | # relinquishment in perpetuity of all present and future rights to this 19 | # software under copyright law. 20 | # 21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24 | # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | # OTHER DEALINGS IN THE SOFTWARE. 28 | # 29 | # For more information, please refer to 30 | 31 | import os 32 | import ycm_core 33 | import re 34 | 35 | _debug = 1 36 | msys2='E:/usr/msys2' 37 | llvm='E:/usr/LLVM' 38 | 39 | # These are the compilation flags that will be used in case there's no 40 | # compilation database set (by default, one is not set). 41 | # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. 42 | flags = [ 43 | '-Wall', 44 | '-Wextra', 45 | '-Werror', 46 | #'-Wc++98-compat', 47 | '-Wno-long-long', 48 | '-Wno-variadic-macros', 49 | '-fexceptions', 50 | '-DNDEBUG', 51 | # You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM 52 | # source code needs it. 53 | '-DUSE_CLANG_COMPLETER', 54 | # THIS IS IMPORTANT! Without a "-std=" flag, clang won't know which 55 | # language to use when compiling headers. So it will guess. Badly. So C++ 56 | # headers will be compiled as C headers. You don't want that so ALWAYS specify 57 | # a "-std=". 58 | # For a C project, you would set this to something like 'c99' instead of 59 | # 'c++11'. 60 | '-fno-ms-compatibility', 61 | '-std=c++14', 62 | # ...and the same thing goes for the magic -x option which specifies the 63 | # language that the files to be compiled are written in. This is mostly 64 | # relevant for c++ headers. 65 | # For a C project, you would set this to 'c' instead of 'c++'. 66 | '-x', 67 | 'c++', 68 | '-isystem', 69 | llvm + '/include', 70 | '-isystem', 71 | llvm + '/tools/clang/include', 72 | '-isystem', 73 | msys2 + '/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/include', 74 | '-isystem', 75 | msys2 + '/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../include', 76 | '-isystem', 77 | msys2 + '/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/include-fixed', 78 | '-isystem', 79 | msys2 + '/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/include', 80 | '-isystem', 81 | msys2 + '/mingw64/lib/gcc/../../include/c++/5.2.0', 82 | '-isystem', 83 | msys2 + '/mingw64/lib/gcc/../../include/c++/5.2.0/x86_64-w64-mingw32', 84 | '-isystem', 85 | msys2 + '/mingw64/lib/gcc/../../include/c++/5.2.0/backward', 86 | 87 | '-include', 88 | msys2 + '/mingw64/lib/gcc/../../include/c++/5.2.0/cstddef', 89 | ] 90 | 91 | def Log(msg): 92 | if not _debug: 93 | return 94 | 95 | f = open("c:/ycm.log", 'a+') 96 | f.write(msg + '\n') 97 | f.close() 98 | 99 | # Set this to the absolute path to the folder (NOT the file!) containing the 100 | # compile_commands.json file to use that instead of 'flags'. See here for 101 | # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html 102 | # 103 | # You can get CMake to generate this file for you by adding: 104 | # set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) 105 | # to your CMakeLists.txt file. 106 | # 107 | # Most projects will NOT need to set this to anything; you can just change the 108 | # 'flags' list of compilation flags. Notice that YCM itself uses that approach. 109 | compilation_database_folder = '' 110 | 111 | if os.path.exists( compilation_database_folder ): 112 | database = ycm_core.CompilationDatabase( compilation_database_folder ) 113 | else: 114 | database = None 115 | 116 | SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] 117 | 118 | def DirectoryOfThisScript(): 119 | Log("__file__ is %s" % __file__) 120 | Log("__file__ abspath is %s" % os.path.abspath( __file__ )) 121 | return os.path.dirname( os.path.abspath( __file__ ) ) 122 | 123 | 124 | def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): 125 | Log(working_directory) 126 | if not working_directory: 127 | return list( flags ) 128 | new_flags = [] 129 | make_next_absolute = False 130 | path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] 131 | for flag in flags: 132 | if make_next_absolute: 133 | make_next_absolute = False 134 | if len(flag) > 1 and flag[1] != ':': 135 | new_flags.append(working_directory + '/' + flag) 136 | continue 137 | 138 | if flag in path_flags: 139 | make_next_absolute = True 140 | 141 | new_flags.append(flag) 142 | 143 | return new_flags 144 | 145 | 146 | def IsHeaderFile( filename ): 147 | extension = os.path.splitext( filename )[ 1 ] 148 | return extension in [ '.h', '.hxx', '.hpp', '.hh' ] 149 | 150 | 151 | def GetCompilationInfoForFile( filename ): 152 | # The compilation_commands.json file generated by CMake does not have entries 153 | # for header files. So we do our best by asking the db for flags for a 154 | # corresponding source file, if any. If one exists, the flags for that file 155 | # should be good enough. 156 | if IsHeaderFile( filename ): 157 | basename = os.path.splitext( filename )[ 0 ] 158 | for extension in SOURCE_EXTENSIONS: 159 | replacement_file = basename + extension 160 | if os.path.exists( replacement_file ): 161 | compilation_info = database.GetCompilationInfoForFile( 162 | replacement_file ) 163 | if compilation_info.compiler_flags_: 164 | return compilation_info 165 | return None 166 | return database.GetCompilationInfoForFile( filename ) 167 | 168 | 169 | ## Add includes flags from the Makefile. 170 | # 171 | makefile_list = ['Makefile', 'makefile', '../Makefile', '../makefile'] 172 | 173 | def ExtractIncludesFromMakefile(path): 174 | Log('ExtractIncludesFromMakefile') 175 | include_flags = set() 176 | cmd = 'cd %s && make -Bn' % path 177 | Log('Make command:\n%s' % cmd); 178 | make_result = os.popen(cmd, 'r').read() 179 | Log('Make result:\n%s' % make_result); 180 | matchs = re.findall(r'-I\s*[^\s$]+', make_result) 181 | for m in matchs: 182 | include_path = m[2:].strip() 183 | if not os.path.isabs(include_path): 184 | include_path = os.path.join(path, include_path) 185 | include_flags.add(include_path) 186 | 187 | return include_flags 188 | 189 | def MakefileIncludesFlags(filename): 190 | Log('MakefileIncludesFlags') 191 | mk_flags = [] 192 | path = os.path.split(filename)[0] 193 | for mk in makefile_list: 194 | abs_mk = os.path.join(path, mk) 195 | if not os.path.isfile(abs_mk): 196 | continue 197 | 198 | include_flags = ExtractIncludesFromMakefile(os.path.split(abs_mk)[0]) 199 | for flag in include_flags: 200 | mk_flags.append('-I') 201 | mk_flags.append(flag) 202 | 203 | break 204 | 205 | Log(str(mk_flags)) 206 | return mk_flags 207 | 208 | 209 | def FlagsForFile( filename, **kwargs ): 210 | Log('-' * 30) 211 | Log("Process file: %s" % filename) 212 | Log("WorkDirectory is: %s" % os.getcwd()) 213 | if database: 214 | Log('database case:') 215 | # Bear in mind that compilation_info.compiler_flags_ does NOT return a 216 | # python list, but a "list-like" StringVec object 217 | compilation_info = GetCompilationInfoForFile( filename ) 218 | if not compilation_info: 219 | return None 220 | 221 | final_flags = MakeRelativePathsInFlagsAbsolute( 222 | compilation_info.compiler_flags_, 223 | compilation_info.compiler_working_dir_ ) 224 | 225 | # NOTE: This is just for YouCompleteMe; it's highly likely that your project 226 | # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR 227 | # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT. 228 | try: 229 | final_flags.remove( '-stdlib=libc++' ) 230 | except ValueError: 231 | pass 232 | else: 233 | Log('no database case:') 234 | relative_to = os.path.dirname(filename) 235 | final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) 236 | 237 | final_flags.extend(MakefileIncludesFlags(filename)) 238 | final_flags.extend(['-I', os.path.dirname(filename)]) 239 | 240 | Log(str(final_flags)) 241 | 242 | return { 243 | 'flags': final_flags, 244 | 'do_cache': True 245 | } 246 | 247 | -------------------------------------------------------------------------------- /autoload/cppenv.vim: -------------------------------------------------------------------------------- 1 | "if exists("g:loaded_cppenv") 2 | " finish 3 | "endif 4 | "let g:loaded_cppenv = 1 5 | 6 | let s:indent_space = repeat(' ', 4) 7 | 8 | func! cppenv#dummy() 9 | endfunc 10 | 11 | func! cppenv#warn(msg) 12 | echohl WarningMsg 13 | echomsg a:msg 14 | echohl NONE 15 | endfunc 16 | 17 | " comment one line code 18 | func! cppenv#comment() 19 | let line_info = getline('.') 20 | "if line_info =~ '^\s*$' 21 | " let indent_n = cindent(line('.') - 1) 22 | " let line_info = repeat(' ', indent_n) 23 | "endif 24 | 25 | "let new_info = substitute(line_info, '\s*', '\0//', "") 26 | let new_info = '//' . line_info 27 | call setline('.', new_info) 28 | endfunc 29 | 30 | " uncomment one line code 31 | func! cppenv#uncomment() 32 | let line_info = getline('.') 33 | "echo line_info 34 | if line_info =~ '^\s*//' 35 | let result = substitute(line_info, "///*", "", "") 36 | call setline('.', result) 37 | endif 38 | endfunc 39 | 40 | " auto complete () [] {} 41 | func! cppenv#auto_brackets(bracket) 42 | let line_info = getline('.') 43 | let pos = getpos('.') 44 | if empty(line_info) 45 | let line_info = line_info . a:bracket 46 | " indent 47 | noremap auto ==a 48 | elseif len(line_info) <= pos[2] 49 | let line_info = line_info . a:bracket 50 | noremap auto a 51 | elseif line_info[pos[2]] == a:bracket[1] 52 | let n1 = cppenv#strcount(line_info, a:bracket[0]) 53 | let n2 = cppenv#strcount(line_info, a:bracket[1]) 54 | if n1 < n2 55 | let line_info = strpart(line_info, 0, pos[2]) . a:bracket[0] . strpart(line_info, pos[2]) 56 | else 57 | let line_info = strpart(line_info, 0, pos[2]) . a:bracket . strpart(line_info, pos[2]) 58 | endif 59 | noremap auto a 60 | else 61 | let line_info = strpart(line_info, 0, pos[2]) . a:bracket[0] . strpart(line_info, pos[2]) 62 | noremap auto a 63 | endif 64 | 65 | call setline('.', line_info) 66 | let pos[2] = pos[2] + 1 67 | call setpos('.', pos) 68 | endfunc 69 | 70 | func! cppenv#strcount(str, c) 71 | let n = 0 72 | let iter = 0 73 | while iter < strlen(a:str) 74 | let s:char = a:str[iter] 75 | if s:char == a:c 76 | let n += 1 77 | endif 78 | let iter += 1 79 | endwhile 80 | return n 81 | endfunc 82 | 83 | " end () [] {} 84 | func! cppenv#end_brackets(bracket) 85 | let line_info = getline('.') 86 | let pos = getpos('.') 87 | let active = 1 88 | "if empty(line_info) 89 | " let active = 0 90 | "elseif line_info[pos[2]] == a:bracket[1] 91 | " let active = 1 92 | "endif 93 | 94 | let n1 = cppenv#strcount(line_info, a:bracket[0]) 95 | let n2 = cppenv#strcount(line_info, a:bracket[1]) 96 | if line_info[pos[2]] == a:bracket[1] && n1 <= n2 97 | let active = 0 98 | endif 99 | 100 | let bracket = active == 1 ? a:bracket[1] : '' 101 | let result = strpart(line_info, 0, pos[2]) . bracket . strpart(line_info, pos[2]) 102 | call setline('.', result) 103 | let pos[2] = pos[2] + 1 104 | call setpos('.', pos) 105 | endfunc 106 | 107 | let s:pos_back=[0,0,0,0] 108 | let s:mapping = 0 109 | 110 | func! cppenv#back_imode_cursor() 111 | let s:pos_back=getpos('.') 112 | let s:mapping = 0 113 | return '' 114 | endfunc 115 | 116 | func! cppenv#restore_imode_cursor() 117 | call setpos('.', s:pos_back) 118 | let pos = getpos('.') 119 | if s:mapping == 1 120 | return 121 | endif 122 | 123 | "if pos[2] < s:pos_back[2] 124 | " noremap i a 125 | "else 126 | noremap i i 127 | "endif 128 | endfunc 129 | 130 | func! cppenv#onEnter() 131 | let pos = getpos('.') 132 | let line1 = getline(pos[1] - 1) 133 | let line2 = getline('.') 134 | 135 | " trimspace 136 | let idx = 0 137 | let start = 0 138 | while idx < strlen(line2) 139 | if line2[idx] =~ '\s' 140 | let start += 1 141 | else 142 | break 143 | endif 144 | let idx += 1 145 | endw 146 | let line2 = strpart(line2, start) 147 | let line_info = line1 . line2 148 | "echo line_info 149 | "redir "" 150 | 151 | let s:bracket = "" 152 | if line2 =~ '}' && line_info =~ '{}\s*$' 153 | let s:bracket = "{}" 154 | elseif line2 =~ ')' && line_info =~ '^import\s*()\s*$' 155 | let s:bracket = "()" 156 | echo "match" 157 | endif 158 | 159 | " 分行 160 | if s:bracket != "" 161 | " for cpp 162 | if line_info =~ '^\s*{}\s*$' && pos[1] > 1 163 | let prev_line_info = getline(pos[1] - 1) 164 | if prev_line_info =~ '^\s*\(class\|struct\|union\)\s\+[^{}]*$' || prev_line_info =~ '^.*=\s*$' || prev_line_info =~ '^\s*go\s\+\[.*\][^{}]*$' 165 | call setline('.', line2 . ";") 166 | endif 167 | elseif line_info =~ '^\(\s*\|.*\s\+\)\(class\|struct\|union\)\s\+\(\w\|\d\|_\)\+\s*{}\s*$' || line_info =~ '^.*=\s*{}\s*$' || line_info =~ '^\s*go\s\+\[.*\][^{}]*{}$' 168 | call setline('.', line2 . ";") 169 | endif 170 | 171 | " for go.import 172 | " nothing need to do 173 | 174 | call append(pos[1] - 1, "") 175 | let s:mapping = 1 176 | noremap i S 177 | else 178 | echo "normal enter" 179 | let s:mapping = 1 180 | if line2 =~ "^\s*$" 181 | noremap i S 182 | else 183 | noremap i i 184 | endif 185 | endif 186 | "redir "" 187 | endfunc 188 | 189 | let g:py_dir = fnamemodify(expand(''), ':p:h:gs?\\?/?') 190 | let g:pyclang_dir = fnamemodify(expand(''), ':p:h:h:gs?\\?/?') . '/pyclang' 191 | 192 | " switch in .h/.hpp/.inl/.cpp/.c/.cc files 193 | " @up_deep: 向上搜索的深度(等于-1时, 用locate命令全局搜索) 194 | " @down_deep:向下搜索的深度 195 | " @vsplit: 是否拆分出新的窗口 196 | func! cppenv#switch_dd(up_deep, down_deep, vsplit) 197 | let s:abs_filename = expand('%:p') 198 | let s:directory = expand('%:p:h') 199 | let s:extension = expand('%:e') 200 | let s:filename = expand('%:r') 201 | let s:extension_list = ['h', 'hpp', 'ipp', 'inl', 'c', 'cc', 'cpp'] 202 | 203 | let s:extension_expr = '^\(' 204 | for ext in s:extension_list 205 | let s:extension_expr = s:extension_expr . ext . '\|' 206 | endfor 207 | let s:extension_expr = s:extension_expr[:-3] . '\)$' 208 | "echo(s:extension_expr) 209 | 210 | if a:up_deep >= 0 && s:extension =~ s:extension_expr 211 | exec(':pyf ' . g:py_dir . '/switch_dd.py') 212 | return 213 | elseif a:up_deep == -1 214 | let s:grep_pattern = '' 215 | for ext in s:extension_list 216 | let s:grep_pattern = s:grep_pattern . '\(\/' . s:filename . '\\.' . ext . '\)' . '\|' 217 | endfor 218 | let s:grep_pattern = s:grep_pattern[:-3] 219 | 220 | let s:command = 'locate ' . s:filename . ' | grep -E ' . s:grep_pattern 221 | let s:locate_result = system(s:command) 222 | let s:abs_path_list = split(s:locate_result) 223 | 224 | if len(s:abs_path_list) > 1 225 | exec(':cexpr ""') 226 | for abs_path in s:abs_path_list 227 | let s:ccmd = ':caddexpr "' . abs_path . ':1:-"' 228 | if s:abs_filename == abs_path 229 | let s:ccmd = s:ccmd[:-2] . ' <<<<"' 230 | endif 231 | exec(s:ccmd) 232 | endfor 233 | exec(':cw') 234 | endif 235 | endif 236 | 237 | echo('Not find switch files.') 238 | endfunc 239 | 240 | " switch to .proto files 241 | func! cppenv#switch_proto() 242 | let s:filename = expand('%:r:r') 243 | let s:protofile = s:filename . '.proto' 244 | exec(':e ' . s:protofile) 245 | endfunc 246 | 247 | """"""""""""""""""""maps""""""""""""""""""""" 248 | let s:is_infect = 0 249 | 250 | func! cppenv#test_expr() 251 | return '### ' 252 | endfunc 253 | 254 | func! cppenv#infect() 255 | let s:is_infect = 1 256 | 257 | map :call cppenv#comment() 258 | imap :call cppenv#comment() 259 | 260 | map :call cppenv#uncomment() 261 | imap :call cppenv#uncomment() 262 | 263 | imap b cppenv#back_imode_cursor() 264 | map r :call cppenv#restore_imode_cursor()i 265 | "imap i "was setting in func! restore_imode_cursor()" 266 | 267 | cnoremap cr 268 | inoremap cr 269 | " use =j to indent below line '}' 270 | "imap = b==r 271 | "imap b:call cppenv#enter()crr=cr 272 | "imap crbko 273 | imap crb:call cppenv#onEnter()crr 274 | 275 | "imap ( :call cppenv#auto_brackets('()')a 276 | "imap [ :call cppenv#auto_brackets('[]')a 277 | "imap { :call cppenv#auto_brackets('{}')a 278 | 279 | imap ( :call cppenv#auto_brackets('()')auto 280 | imap [ :call cppenv#auto_brackets('[]')auto 281 | imap { :call cppenv#auto_brackets('{}')auto 282 | 283 | imap ) :call cppenv#end_brackets('()')a 284 | imap ] :call cppenv#end_brackets('[]')a 285 | imap } :call cppenv#end_brackets('{}')a 286 | 287 | 288 | if has("unix") 289 | "imap < :call cppenv#auto_brackets('<>')auto 290 | "imap > :call cppenv#end_brackets('<>')auto 291 | 292 | imap 293 | 294 | "inoremap G cppenv#test_expr() 295 | "imap F G 296 | endif 297 | 298 | map gp :call cppenv#switch_proto() 299 | map gs :call cppenv#switch_dd(0, 0, 0) 300 | map gns :call cppenv#switch_dd(2, 2, 0) 301 | map gvs :call cppenv#switch_dd(0, 0, 1)Lh 302 | map gvns :call cppenv#switch_dd(2, 2, 1)Lh 303 | map gnvs gvns 304 | map gS :call cppenv#switch_dd(-1, 0, 0) 305 | endfunc 306 | 307 | func! cppenv#uninfect() 308 | let s:is_infect = 0 309 | 310 | unmap 311 | iunmap 312 | 313 | unmap 314 | iunmap 315 | 316 | iunmap ( 317 | iunmap [ 318 | iunmap { 319 | 320 | iunmap ) 321 | iunmap ] 322 | iunmap } 323 | 324 | iunmap 325 | 326 | if has("unix") 327 | "iunmap < 328 | "iunmap > 329 | 330 | iunmap 331 | endif 332 | 333 | call cppenv#warn("Close cppenv.") 334 | unmap gp 335 | unmap gs 336 | unmap gns 337 | unmap gvs 338 | unmap gvns 339 | unmap gS 340 | endfunc 341 | 342 | func! cppenv#toggle() 343 | if s:is_infect == 0 344 | call cppenv#infect() 345 | else 346 | call cppenv#uninfect() 347 | endif 348 | endfunc 349 | 350 | map :call cppenv#toggle() 351 | -------------------------------------------------------------------------------- /autoload/switch_dd.py: -------------------------------------------------------------------------------- 1 | import vim, os 2 | 3 | current_file = vim.eval("s:abs_filename") 4 | path = vim.eval("s:directory") 5 | is_vsplit = int(vim.eval("a:vsplit")) 6 | up_deep = int(vim.eval("a:up_deep")) 7 | down_deep = int(vim.eval("a:down_deep")) 8 | down_deep += up_deep 9 | for i in range(up_deep): 10 | path = os.path.dirname(path) 11 | 12 | extension_list = vim.eval("s:extension_list") 13 | 14 | #print "extension_list:%s" % extension_list 15 | #print "current_file:%s" % current_file 16 | #print "path:%s" % path 17 | #print 'is_vsplit:%s' % is_vsplit 18 | #print 'up_deep:%s' % up_deep 19 | #print 'down_deep:%s' % down_deep 20 | 21 | # show 22 | def show(filelist): 23 | if len(filelist) == 1: 24 | dst_file = filelist[0] 25 | bufindex = int(vim.eval('bufnr("%s")' % dst_file)) 26 | #print "bufindex ", bufindex 27 | if bufindex == -1: 28 | if is_vsplit: 29 | cmd = 'vnew' 30 | else: 31 | cmd = 'e' 32 | else: 33 | if is_vsplit: 34 | cmd = 'sbuf' 35 | else: 36 | cmd = 'buf' 37 | cmd = ":" + cmd + " " + dst_file 38 | #print 'cmd ', cmd 39 | vim.command(cmd) 40 | return 41 | 42 | vim.command(':cexpr ""') 43 | for f in filelist: 44 | cmd = ':caddexpr "%s:1:-"' % f 45 | if f == current_file: 46 | cmd = cmd[:-2] + ' <<<<"' 47 | vim.command(cmd) 48 | vim.command(':cw') 49 | 50 | # Search in directory recursive. 51 | result = [] 52 | def search_r(path, recursive_deep): 53 | if recursive_deep > down_deep: 54 | return 55 | 56 | for p in os.listdir(path): 57 | f = os.path.join(path, p) 58 | #print f 59 | if os.path.isdir(f): 60 | search_r(f, recursive_deep + 1) 61 | 62 | if os.path.isfile(f): 63 | pure_name, ext = os.path.splitext(f) 64 | if ext[1:] in extension_list and \ 65 | os.path.basename(pure_name) == os.path.basename(os.path.splitext(current_file)[0]): 66 | result.append(f) 67 | 68 | search_r(path, 0) 69 | #print 'result:', result 70 | 71 | if len(result) <= 1: 72 | print 'Not find switch files.' 73 | elif len(result) == 2: 74 | result.remove(current_file) 75 | show(result) 76 | else: 77 | show(result) 78 | 79 | -------------------------------------------------------------------------------- /pyclang/gen_methods.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | #-*- coding: utf-8 -*- 3 | 4 | import sys, traceback, re 5 | from clang.cindex import * 6 | 7 | class_kinds = [ 8 | 'CLASS_DECL', 9 | 'STRUCT_DECL', 10 | 'UNION_DECL', 11 | 'CLASS_TEMPLATE', 12 | 'CLASS_TEMPLATE_PARTIAL_SPECIALIZATION', 13 | ] 14 | 15 | template_class_kinds = [ 16 | 'CLASS_TEMPLATE', 17 | 'CLASS_TEMPLATE_PARTIAL_SPECIALIZATION', 18 | ] 19 | 20 | method_kinds = [ 21 | 'CXX_METHOD', 22 | 'FUNCTION_TEMPLATE', 23 | ] 24 | 25 | template_arg_kinds = [ 26 | 'TEMPLATE_TYPE_PARAMETER', 27 | 'TEMPLATE_NON_TYPE_PARAMETER', 28 | ] 29 | 30 | 31 | ## 广度优先遍历AST语法树 32 | # @root 根节点 33 | # @pred 条件谓词(返回false时不再继续遍历当前节点的子节点) 34 | def bft_ast_iter(root, pred = None): 35 | stack = [root] 36 | while len(stack): 37 | c = stack[0] 38 | stack.pop(0) 39 | yield c 40 | if pred and not pred(c): 41 | continue 42 | 43 | for child in c.get_children(): 44 | stack.append(child) 45 | 46 | ## 找到class定义的节点 47 | def find_class_definition_in_file(root, class_name): 48 | for cursor in bft_ast_iter(root): 49 | #print cursor.spelling 50 | if cursor.is_definition() and cursor.spelling == class_name: 51 | kind_name = cursor.kind.name 52 | if kind_name in class_kinds: 53 | return cursor 54 | return 55 | 56 | ## 生成模板参数 57 | [ 58 | template_enum_decl, 59 | template_enum_args, 60 | template_enum_types, 61 | ] = range(3) 62 | 63 | def gen_template_decl_or_args(template_enum, iterator): 64 | elems = [] 65 | for elem in iterator: 66 | value = '' 67 | tokens = ''.join([ch.spelling for ch in elem.get_tokens()]) 68 | variadic = '...' in tokens and '...' or '' 69 | if elem.kind.name == 'TEMPLATE_TYPE_PARAMETER': 70 | if template_enum == template_enum_decl: 71 | value = 'typename %s %s' % (variadic, elem.spelling) 72 | elif template_enum == template_enum_args: 73 | value = '%s%s' % (elem.spelling, variadic) 74 | else: 75 | value = 'typename%s' % variadic 76 | 77 | elif elem.kind.name == 'TEMPLATE_NON_TYPE_PARAMETER': 78 | if template_enum == template_enum_decl: 79 | value = '%s %s %s' % (elem.type.spelling, variadic, elem.spelling) 80 | elif template_enum == template_enum_args: 81 | value = '%s%s' % (elem.spelling, variadic) 82 | else: 83 | value = '%s%s' % (elem.type.spelling, variadic) 84 | 85 | if value: 86 | elems.append(value) 87 | 88 | if not elems: 89 | return '' 90 | 91 | if template_enum == template_enum_decl: 92 | return 'template <' + ', '.join(elems) + '>\n' 93 | else: 94 | return '<' + ', '.join(elems) + '>' 95 | 96 | ## 生成一个member function的定义代码 97 | def gen_one_method_definition(f): 98 | # 类模板参数定义 template 99 | class_template_declarations = '' 100 | 101 | # 类模板参数 102 | class_template_args = '' 103 | 104 | # 类定义节点 105 | class_cursor = f.semantic_parent 106 | 107 | # 类名 108 | class_name = class_cursor.spelling 109 | if class_cursor.kind.name in template_class_kinds: 110 | class_template_declarations = gen_template_decl_or_args(template_enum_decl, class_cursor.get_children()) 111 | class_template_args = gen_template_decl_or_args(template_enum_args, class_cursor.get_children()) 112 | 113 | # 函数模板参数定义 114 | function_template_declarations = gen_template_decl_or_args(template_enum_decl, f.get_children()) 115 | #print 'In gen method:', function_template_declarations 116 | 117 | # 函数参数列表 118 | args = ', '.join([ \ 119 | elem.type.spelling + ' ' + elem.spelling \ 120 | for elem in f.get_children() \ 121 | if elem.kind.name == 'PARM_DECL' \ 122 | ]) 123 | 124 | # 函数修饰符(& && const volatile) 125 | qualified_str = '' 126 | qualifieds = re.findall(r'(?<=\))[^\)]*$', f.type.spelling) 127 | if qualifieds: 128 | # 修饰符无序 (&& & 要在最后) 129 | q_list = qualifieds[0].split(' ') 130 | q_list.sort() 131 | q_list.reverse() 132 | qualified_str = ' '.join(q_list) 133 | 134 | # 返回类型 135 | ori_result_type = f.result_type.spelling 136 | result_type = ori_result_type.replace('%s::' % class_name, '%s%s::' % (class_name, class_template_args)) 137 | if result_type != ori_result_type: 138 | # 受限类型前面要加typename 139 | result_type = 'typename ' + result_type 140 | 141 | return class_template_declarations + function_template_declarations + \ 142 | result_type + ' ' + class_name + class_template_args + "::" + f.spelling + \ 143 | '(' + args + ')' + qualified_str + '\n{\n\n}\n' 144 | 145 | ## 全名 146 | def complete_spelling(c): 147 | if not c.semantic_parent or c.semantic_parent.kind.name == 'TRANSLATION_UNIT': 148 | return c.spelling 149 | 150 | return complete_spelling(c.semantic_parent) + '::' + c.spelling 151 | 152 | ## 生成function的特征码 153 | # @c function cursor 154 | def create_function_traits(c): 155 | if c.kind.name not in method_kinds: 156 | raise '' 157 | 158 | class_name = '' 159 | complete_class_name = '' 160 | if c.semantic_parent.kind.name in class_kinds: 161 | class_name = c.semantic_parent.spelling 162 | complete_class_name = class_name + gen_template_decl_or_args(template_enum_args, c.semantic_parent.get_children()) 163 | 164 | s = complete_spelling(c)# + template_args 165 | s += '(' + ', '.join([arg.type.spelling.replace(complete_class_name, class_name) for arg in c.get_children() if arg.kind.name == 'PARM_DECL']) + ')' 166 | 167 | # 函数修饰符(& && const volatile) 168 | qualifieds = re.findall(r'(?<=\))[^\)]*$', c.type.spelling)[0] 169 | 170 | # 修饰符无序 (&& & 要在最后) 171 | q_list = qualifieds.split(' ') 172 | q_list.sort() 173 | q_list.reverse() 174 | s += ' '.join(q_list) 175 | return s 176 | 177 | ## 获取class定义节点中所有member function的子节点, 并排除已定义的 178 | def get_functions_by_class(class_node, root): 179 | # 收集已定义的function 180 | defineds = {} 181 | for c in bft_ast_iter(root, lambda c: c.kind.name == "NAMESPACE" or c.kind.name == 'TRANSLATION_UNIT'): 182 | if c.kind.name not in method_kinds: 183 | continue 184 | 185 | if c.is_definition() and c.semantic_parent and c.semantic_parent.spelling == class_node.spelling: 186 | defineds[create_function_traits(c)] = c.spelling 187 | 188 | print 'defineds: ', defineds 189 | 190 | out_list = [] 191 | for c in class_node.get_children(): 192 | if c.kind.name not in method_kinds: 193 | continue 194 | 195 | ## 排除定义体直接写在类中的 196 | if c.is_definition(): 197 | continue 198 | 199 | ## 排除在外部定义的 200 | print 'function:', create_function_traits(c) 201 | if defineds.has_key(create_function_traits(c)): 202 | continue 203 | 204 | out_list.append(c) 205 | return out_list 206 | 207 | ## 调试打印出AST语法树结构 208 | def show_ast(cursor, point_c = None): 209 | stack = [(cursor, 0)] 210 | while len(stack): 211 | c, d = stack[0] 212 | stack.pop(0) 213 | if point_c and point_c == c: 214 | space = '*' 215 | else: 216 | space = ' ' 217 | 218 | print '%s%s %s %s' % (space * 2 * d, c.spelling, c.kind.name, complete_spelling(c)) 219 | children = [] 220 | for child in c.get_children(): 221 | children.append((child, d + 1)) 222 | children.extend(stack) 223 | stack = children 224 | 225 | ## returns a tuple as (methods code, error info) 226 | def gen_methods_definition(filename, class_name): 227 | index = Index.create() 228 | tu = index.parse(filename) 229 | root = tu.cursor 230 | #print dir(root); return '', '' 231 | #show_ast(root); return '', '' 232 | class_def_cursor = find_class_definition_in_file(root, class_name) 233 | if not class_def_cursor: 234 | return ('', 'not found class definitions in file: %s' % filename) 235 | 236 | #print 'found class_def_cursor' 237 | code = '' 238 | funcs = get_functions_by_class(class_def_cursor, root) 239 | for f in funcs: 240 | code += gen_one_method_definition(f) 241 | return (code, '') 242 | 243 | if __name__ == '__main__': 244 | code, err = gen_methods_definition("./test.cpp", 'A') 245 | print 'code:' 246 | print code 247 | print 'err:', err 248 | 249 | -------------------------------------------------------------------------------- /pyclang/project/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from find import project_finder 3 | -------------------------------------------------------------------------------- /pyclang/project/cmake.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os 4 | import sys 5 | import re 6 | 7 | class cmake: 8 | def __init__(self): 9 | pass 10 | 11 | def recursive_replace(self, s, args_dct): 12 | arg_list = re.findall(r'\$\{(.+?)\}', s, re.IGNORECASE) 13 | if not arg_list: 14 | return s 15 | 16 | is_replaced = False 17 | for arg in arg_list: 18 | if args_dct.has_key(arg): 19 | is_replaced = True 20 | s = s.replace('${%s}' % arg, args_dct.get(arg)) 21 | 22 | if not is_replaced: 23 | return s 24 | 25 | return self.recursive_replace(s, args_dct) 26 | 27 | def get_includes(self, cmakefile): 28 | ret = [] 29 | with open(cmakefile, 'r') as f: 30 | info_list = f.readlines() 31 | arguments = { 32 | 'PROJECT_SOURCE_DIR' : os.path.split(cmakefile)[0] 33 | } 34 | 35 | for s in info_list: 36 | if s.strip().upper().startswith('SET'): 37 | r = re.match(r'\s*set\(([^"]+)\s+(.*)\)\s*', s, re.IGNORECASE) 38 | if not r or r.group(0) != s: 39 | continue 40 | 41 | arguments[r.group(1)] = r.group(2).strip().strip('"') 42 | 43 | for s in info_list: 44 | if s.strip().upper().startswith('INCLUDE_DIRECTORIES'): 45 | r = re.match(r'\s*include_directories\("([^"]+)"\)\s*', s, re.IGNORECASE) 46 | if not r or r.group(0) != s: 47 | continue 48 | 49 | ret.append(self.recursive_replace(r.group(1), arguments)) 50 | 51 | for i in range(len(ret)): 52 | if not ret[i].startswith('/'): 53 | ret[i] = os.path.join(os.path.dirname(cmakefile), ret[i]) 54 | 55 | return ret 56 | 57 | g_cmake_parser = cmake() 58 | 59 | if __name__ == '__main__': 60 | print g_cmake_parser.get_includes('/home/yyz/cloud/sip/kiev/src/CMakeLists.txt') 61 | -------------------------------------------------------------------------------- /pyclang/project/find.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os 4 | import re 5 | 6 | class finder: 7 | def __init__(self): 8 | self.cache = {} 9 | 10 | def find_cmake(self, start_path): 11 | return self.find(start_path, r'CMakeLists\.txt') 12 | 13 | def find_makefile(self, start_path): 14 | return self.find(start_path, r'[mM]akefile') 15 | 16 | def find(self, start_path, project_file_pattern): 17 | if self.cache.has_key(start_path): 18 | c2 = self.cache[start_path] 19 | if c2.has_key(project_file_pattern): 20 | return c2[project_file_pattern] 21 | 22 | path = start_path 23 | while True: 24 | for p in os.listdir(path): 25 | abs_p = os.path.join(path, p) 26 | if not os.path.isfile(abs_p): 27 | continue 28 | 29 | r = re.match(project_file_pattern, p, 0) 30 | if r.group(0) == p: 31 | self.cache[start_path][project_file_pattern] = abs_p 32 | return abs_p 33 | 34 | parent = os.path.dirname(path) 35 | if path == parent: 36 | break 37 | 38 | path = parent 39 | 40 | return '' 41 | 42 | def findall(self, start_path): 43 | cmake_f = self.find_cmake(start_path) 44 | if cmake_f: 45 | return cmake_f 46 | 47 | return self.find_makefile(start_path) 48 | 49 | project_finder = finder() 50 | 51 | -------------------------------------------------------------------------------- /pyclang/test.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | struct xy; 4 | 5 | template 6 | struct A { 7 | 8 | template 9 | float* foo(T arg, double & db); 10 | 11 | struct In; 12 | In* bar(In& a); 13 | 14 | In* fb(In& a, double b, void(*)(int)) const volatile &&; 15 | 16 | static void fb_defined() {} 17 | 18 | template 19 | int vars(Args && ... args); 20 | 21 | template 22 | int bs(); 23 | 24 | // void invalid_type(xy &); 25 | }; 26 | 27 | class X; 28 | void foo(X* a); 29 | 30 | /* 31 | template 32 | typename A::In * A::bar(A::In & a) 33 | { 34 | 35 | } 36 | template 37 | typename A::In * A::fb(A::In & a, double b, void (*)(int) )volatile const && 38 | { 39 | 40 | } 41 | template 42 | template 43 | int A::vars(Args &&... args) 44 | { 45 | 46 | } 47 | template 48 | template 49 | int A::bs() 50 | { 51 | 52 | } 53 | 54 | template 55 | template 56 | float * A::foo(T arg, double & db) 57 | { 58 | 59 | } 60 | */ 61 | -------------------------------------------------------------------------------- /pyclang/test.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace sb 4 | { 5 | int f; 6 | } 7 | 8 | class B 9 | { 10 | 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /snippets/all.snippets: -------------------------------------------------------------------------------- 1 | ######################################################## 2 | snippet time 3 | `!p import time; snip.rv = time.strftime("%Y-%m-%d %H:%M:%S")` 4 | endsnippet 5 | 6 | ######################################################## 7 | snippet date 8 | `!p import time; snip.rv = time.strftime("%Y-%m-%d")` 9 | endsnippet 10 | 11 | ######################################################## 12 | snippet "namespace (\w+)" "namespace-snippet" r 13 | namespace ${1:`!p snip.rv = match.group(1)`} 14 | { 15 | 16 | } //namespace $1 17 | endsnippet 18 | 19 | ######################################################## 20 | snippet "GNU License ([\d\w]+)" "Make GNU License" r 21 | // Copyright (C) 2011, 2012 Google Inc. 22 | // 23 | // This file is part of ${1:`!p snip.rv = match.group(1)`} 24 | // 25 | // $1 is free software: you can redistribute it and/or modify 26 | // it under the terms of the GNU General Public License as published by 27 | // the Free Software Foundation, either version 3 of the License, or 28 | // (at your option) any later version. 29 | // 30 | // $1 is distributed in the hope that it will be useful, 31 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | // GNU General Public License for more details. 34 | // 35 | // You should have received a copy of the GNU General Public License 36 | // along with $1. If not, see . 37 | 38 | endsnippet 39 | 40 | ######################################################## 41 | snippet "def ([\d\w]+)" "Make Cxx Class Method Definitions" r 42 | `!p 43 | import vim, sys 44 | sys.path.append(vim.eval('g:pyclang_dir')) 45 | import gen_methods 46 | class_name = match.group(1) 47 | code, err = gen_methods.gen_methods_definition(vim.current.buffer.name, class_name) 48 | snip.rv = code + err` 49 | endsnippet 50 | 51 | # class a {}; 52 | # GNU License a 53 | 54 | # Golang imports 55 | ######################################################## 56 | snippet ketty 57 | "github.com/yyzybb537/ketty" 58 | endsnippet 59 | 60 | ######################################################## 61 | snippet gls 62 | "github.com/yyzybb537/gls" 63 | endsnippet 64 | 65 | ######################################################## 66 | snippet option 67 | "github.com/yyzybb537/ketty/option" 68 | endsnippet 69 | 70 | ######################################################## 71 | snippet context 72 | "golang.org/x/net/context" 73 | endsnippet 74 | 75 | ######################################################## 76 | snippet error 77 | "github.com/pkg/errors" 78 | endsnippet 79 | 80 | # Golang coding 81 | ######################################################## 82 | snippet log 83 | ketty.GetLog() 84 | endsnippet 85 | 86 | # C plus plus - CMakeLists.txt 87 | ######################################################## 88 | snippet cmake 89 | cmake_minimum_required(VERSION 2.8) 90 | 91 | # Usage by vcpkg (CMAKE_TOOLCHAIN_FILE): 92 | # mkdir build && cd build && cmake .. -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE 93 | # mkdir build && cd build && cmake .. -DCMAKE_TOOLCHAIN_FILE="/home/ubuntu/git-third/vcpkg/scripts/buildsystems/vcpkg.cmake" 94 | # cmake .. -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE 95 | # cmake .. -DCMAKE_TOOLCHAIN_FILE="/home/ubuntu/git-third/vcpkg/scripts/buildsystems/vcpkg.cmake" 96 | 97 | project($1) 98 | set(TARGET ${CMAKE_PROJECT_NAME}) 99 | 100 | # flags 101 | if (CMAKE_BUILD_TYPE) 102 | else() 103 | set(CMAKE_BUILD_TYPE RELEASE) 104 | endif() 105 | 106 | message("------------ Options -------------") 107 | message(" CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") 108 | message(" CMAKE_COMMAND: ${CMAKE_COMMAND}") 109 | 110 | set(CMAKE_CXX_FLAGS -std=c++11) 111 | set(CMAKE_CXX_FLAGS_DEBUG "-g -pg ${CMAKE_CXX_FLAGS}") 112 | set(CMAKE_CXX_FLAGS_RELEASE "-g -O3 ${CMAKE_CXX_FLAGS}") 113 | 114 | message("------------ Cxx flags -------------") 115 | message(" CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}: ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}") 116 | message("------------------------------------") 117 | 118 | # source 119 | aux_source_directory(${PROJECT_SOURCE_DIR} LIST_SRC) 120 | add_executable(${TARGET} ${LIST_SRC}) 121 | 122 | # include 123 | include_directories(${PROJECT_SOURCE_DIR}) 124 | 125 | # link 126 | target_link_libraries(${TARGET} "") 127 | 128 | # libgo 129 | #find_package(libgo REQUIRED) 130 | find_package(libgo) 131 | if (LIBGO_FOUND) 132 | include_directories(${LIBGO_INCLUDE_DIRS}) 133 | target_link_libraries(${TARGET} ${LIBGO_LIBRARIES}) 134 | endif() 135 | 136 | # boost 137 | #find_package(Boost REQUIRED context thread system date_time chrono regex) 138 | find_package(Boost REQUIRED context thread system) 139 | if (Boost_FOUND) 140 | include_directories(${Boost_INCLUDE_DIRS}) 141 | link_directories(${Boost_LIBRARY_DIRS}) 142 | target_link_libraries(${TARGET} ${Boost_LIBRARIES}) 143 | endif() 144 | 145 | # target 146 | target_link_libraries(${TARGET} -pthread -ldl -static) 147 | endsnippet 148 | 149 | # C plus plus - test code 150 | ######################################################## 151 | snippet cpptest 152 | #include 153 | #include 154 | #include 155 | using namespace std; 156 | using namespace std::chrono; 157 | 158 | #define OUT(x) cout << #x << " = " << x << endl 159 | #define O(x) cout << x << endl 160 | 161 | struct Timer { Timer() : tp(system_clock::now()) {} virtual ~Timer() { auto dur = system_clock::now() - tp; O("Cost " << duration_cast(dur).count() << " ms"); } system_clock::time_point tp; }; 162 | struct Bench : public Timer { Bench() : val(0) {} virtual ~Bench() { stop(); } void stop() { auto dur = system_clock::now() - tp; O("Per op: " << duration_cast(dur).count() / std::max(val, 1L) << " ns"); auto perf = (double)val / duration_cast(dur).count() / 10; if (perf < 1) O("Performance: " << std::setprecision(3) << perf << " w/s"); else O("Performance: " << perf << " w/s"); } Bench& operator++() { ++val; return *this; } Bench& operator++(int) { ++val; return *this; } Bench& add(long v) { val += v; return *this; } long val; }; 163 | 164 | int main() { 165 | 166 | } 167 | 168 | endsnippet 169 | 170 | # C plus plus - lock 171 | ######################################################## 172 | snippet lock 173 | std::unique_lock lock(); 174 | endsnippet 175 | 176 | # if-else 177 | ######################################################## 178 | snippet ifelse 179 | if ($1) { 180 | 181 | } else { 182 | 183 | } 184 | endsnippet 185 | --------------------------------------------------------------------------------