2021年3月27日 星期六

在vs code裡加入clang-format(google sytle)的功能

目的:

         在vs code的ide底下設定google coding sytle的clang-format功能。

步驟:

         1. 安裝clang-format
                若是windows則安裝llvm;若是linux系統(ubuntu)則用apt-get install clang-format

         2.. 安裝vs code的clang-format套件
         3. 到檔案->偏好設定->設定
         4.  在search settings鍵入clang-format
         5. 將Clang-format: Fallback Style以及Clang-format:Style設定為Google

         6. 最後在編輯的c程式裡面可以就由滑鼠右鍵選擇Format Document,這樣就會編排成Google的coding sytle。


   

參考資料:


2021年3月20日 星期六

在vim加入clang-format的功能

 目的:

使用clang-format官網提供的方法加入排版功能

平台:

ubuntu 18.04

作法:

1. 在clang-format的官網裡面的Vim Integration有提到需要有clang-format.py這個檔案並可從這裡獲得。並且需要特過指令:

        sudo apt-get install clang-format

下載clang-format這個工具。

2. 從.vimrc加入以下內容

        imap <c-f> <c-o>:py3file ~/clang-format.py<cr>

3. 之後便可在vim的insert mode透過ctrl-f使目前的程式編排成google的coding style。


參考資料:

1. Clang 12 documentation CLANGFORMAT

make bootable usb

 在ubuntu環境下製作linux的開機usb


 1.用fdisk -l 確認要用的usb是否被掛載,如果有請用umount指令卸下
 2. 啟動  Startup Disk Creator ,指定你系統的iso檔以及要製作的usb
 3. 按下Make Startup Disk啟動製作程序
 4.最後成功後會有視窗跳出提醒

 在ubuntu環境下製作windows的開機usb


1.用fdisk -l 確認要用的usb是否被掛載,如果有請用umount指令卸下
2.下載woeusb->apt-get install woeusb
3. 開啟woeusbgui
4. 選定iso檔和要燒錄的隨身碟
5. 成功後即可使用

參考資料: 

在vim中建立clang-format功能

 目的: 

在vim中加入clang-format的附件功能,並以google當作coding sytle。

步驟:

1. 在vim加入套件管理程式Vundle

    1-1. 下載vundle模組

        git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/Vundle.vim

    1-2. 下載clang-format程式和vundle的模組

        sudo apt-get install clang-format
        git clone https://github.com/rhysd/vim-clang-format.git  ~/.vim/Vundle.vim/vim-clang-format

    1-3. 加入vimrc並改為特定的內容

        vim ~/.vimrc

       內容如下:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/Vundle.vim/
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
call vundle#end()            " required
filetype plugin indent on    " required


    1-4. 一般模式下輸入:PlugInstall安裝Vundle模組的部份,若是成功會在右下角暗道Done!的字樣。

2. 增加clang-format的功能和vim相關的外掛模組

    2-1. 安裝clang-format

        sudo apt-get install clang-format

    2-2.在vimrc加入clang-format模組部份:

        Plugin 'rhysd/vim-clang-format'

    2-3.一般模式下輸入:PlugInstall安裝Vundle模組的部份,若是成功會在右下角暗道Done!的字樣。


    2-4.在.vim同的同層的資料夾下使用指令

        clang-format -style=google -dump-config > ./.clang-format 

        建立google的coding style規則。

3. 為了更方便使用,將vim的clang-format加入快捷鍵(ctrl+f)的功能。為此要在vimrc裡面加入以下內容:

        let g:clang_format#command = 'clang-format'
        nmap <c-f> :ClangFormat<cr>
        autocmd FileType c ClangFormatAutoEnable
        let g:clang_format#detect_style_file = 1

4. 最終的vimrc如下:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/Vundle.vim/
call vundle#begin()

Plugin 'gmarik/Vundle.vim'
Plugin 'rhysd/vim-clang-format'
call vundle#end()            " required
filetype plugin indent on    " required

let g:clang_format#command = 'clang-format'
nmap <c-f> :ClangFormat<cr>
autocmd FileType c ClangFormatAutoEnable
let g:clang_format#detect_style_file = 1

5. 最後即可在自己的c語言裡面藉由ctrl+f將程式排版成符合google的coding style。


參考資料:

1. Linux下vim配置clang-format的方法

2. Vim 套件管理程式 Vundle

3. [Vim] Vim 的插件管理工具 Vundle

2020年12月19日 星期六

使用ibus使用新酷音輸入法(ubuntu)

目的: 在ubuntu18.04的系統使用ibus調整出可以使用新酷音輸入法

注意:需在一般使用者的命令視窗:

1. 用指令下載ibus-chewing
"sudo apt install ibus-chewing"
  之後重新啟動ibus
 "ibus restart"
2 到設定裡的language support安裝chinese(traditional)的語法。


3. 到text entry裡面安裝chinese這個選項。


4. 用指令"ibus-setup"input method將新酷音輸入法加入。


5. 確認用指令"ibus list-engine"輸出的輸入法裡面有沒有chewing這個選項。


6.使用"ibus engine"確認目前的輸入法,若不是chewing,使用指令"ibus engine chewing"設定。
7.之後用指令"ibus engine"確認是否改成chewing,若成功便可使用注音輸入法了。


將上述的指令加入初始話腳本:

1. 在/etc/init.d/底下加入ibus-chewing這個腳本
內容為
------
#! /bin/sh

ibus engine chewing

exit 0
------
2. 改變權限
  sudo chmod 755 /etc/init.d/ibus-chewing

3.透過指令update-rc.d加入初始話腳本
   sudo update-rc.d /etc/init.d/ibus_chewing default


參考資料:
1. 如何透過指令「ibus」來切換輸入法
2. Debian/Ubuntu 新增開機自動執行程式

2020年6月28日 星期日

常用指令整理

du: 顯示檔案的空間使用狀況

           du -h -BK [檔案或是資料夾]
               以Kbyte為單位顯示檔案或資料夾\
---------------------------------------------------------
apt-file: 可以用來尋找需要的檔案是存在哪一個套件中
             apt-file update 更新資料
             apt-file [檔案 ex .gtkwidget.h]
             Debian 尋找某檔案在哪個 Package 的工具: apt-file
---------------------------------------------------------
grep -iRl "your-text-to-find" /尋找的路徑/
i:忽略大小寫
R:遞迴的方式去搜尋路徑下的所有子目錄下的檔案
l:列出包含欲搜尋文字的檔案
n:印出在檔案中的行數
---------------------------------------------------------
namp -sn ip/24:查詢相關區域網路的ip
---------------------------------------------------------
ls -t

t:依照最新修改時間排序

2020年5月25日 星期一

從源碼產生arm,riscv,x86的qemu

作業系統︰Ubuntu 18.04

GIT的ssh設定
    為了在git使用ssh將專案拉下來需使用指令"ssh-keygen"產生金鑰,之後在github settings的"SSH and GPG keys"指令產生的金鑰複製到這裡。
    資料可參考這裡

建制arm的qemu︰
1. git clone git@github.com:qemu/qemu.git

2.
 ./configure --target-list=i386-softmmu,x86_64-softmmu,aarch64-softmmu,arm-softmmu,riscv32-softmmu,riscv64-softmmu --disable-libssh  --enable-debug --enable-kvm
3.
  make
4.
  ln -s  到arm-system-aarch64的路徑/arm-system-aarch64 /usr/bin/arm-system-aarch64
5. 完成

錯誤排除︰
發生錯誤-> make: aarch64-linux-gnu-gcc: Command not found
可能原因為32和64位元相容問題
解法:sudo apt-get install binutils-multiarch-dev  binutils-multiarch lib32ncurses5-dev lib32z1