完成基本功能.

Signed-off-by: rick.chan <chenyang@autoai.com>
This commit is contained in:
rick.chan 2021-01-22 18:00:26 +08:00
parent 56f95e6a4f
commit ddef866276
4 changed files with 129 additions and 1 deletions

16
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}",
"args":["-i", "Test.md", "-o", "Tmp.md"]
}
]
}

View File

@ -1,3 +1,3 @@
# SpaceMarkdown
在 Markdown 文件的中英文之间插入空格。
在 Markdown 文件的中英文之间插入空格。

107
SpaceMarkdown.go Normal file
View File

@ -0,0 +1,107 @@
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"regexp"
)
func fileExists(file string) bool {
_, err := os.Stat(file)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
return false
}
func fileOpen(file string, canCreate bool) (*os.File, bool) {
if fileExists(file) {
f, e := os.OpenFile(file, os.O_RDWR, 0666)
if nil != e {
return nil, false
}
return f, true
} else if canCreate {
f, e := os.OpenFile(file, os.O_RDWR|os.O_CREATE, 0666)
if nil != e {
return nil, false
}
return f, true
} else {
return nil, false
}
}
func fileWrite(file *os.File, txt []string) {
for i := 0; i < len(txt); i++ {
file.WriteString(txt[i])
}
file.Sync()
}
func fileClose(file *os.File) {
file.Close()
}
func insertSpace2Line(line string) string {
reg1 := regexp.MustCompile("([A-Za-z0-9?/,*])([\u4e00-\u9fa5])")
reg2 := regexp.MustCompile("([\u4e00-\u9fa5])([A-Za-z0-9?/,*])")
line = reg2.ReplaceAllString(reg1.ReplaceAllString(line, "$1 $2"), "$1 $2")
return line
}
func SpacePipeline(file *os.File) []string {
var txt []string
file.Seek(0, os.SEEK_SET)
reader := bufio.NewReader(file)
for {
line, e := reader.ReadString('\n')
if nil != e {
break
}
line = insertSpace2Line(line)
txt = append(txt, line)
}
return txt
}
func usage() {
fmt.Println("SpaceMarkdown")
fmt.Println("version 0.1.0")
flag.PrintDefaults()
}
func main() {
var ifile, ofile string
var ifd, ofd *os.File
var ret bool
flag.StringVar(&ifile, "i", "", "Input markdown file")
flag.StringVar(&ofile, "o", "", "Output markdown file")
flag.Usage = usage
flag.Parse()
if "" == ifile || "" == ofile {
usage()
return
}
ifd, ret = fileOpen(ifile, false)
if !ret {
log.Println("Can not open " + ifile)
}
ofd, ret = fileOpen(ofile, true)
if !ret {
log.Println("Can not open " + ofile)
}
fileWrite(ofd, SpacePipeline(ifd))
fileClose(ifd)
fileClose(ofd)
}

5
Test.md Normal file
View File

@ -0,0 +1,5 @@
# Ldconfig 命令
ldconfig命令的用途主要是在默认搜寻目录/lib和/usr/lib以及动态库配置文件/etc/ld.so.conf内所列的目录下搜索出可共享的动态链接库格式如lib*.so*,进而创建出动态装入程序(ld.so)所需的连接和缓存文件。缓存文件默认为/etc/ld.so.cache此文件保存已排好序的动态链接库名字列表为了让动态链接库为系统所共享需运行动态链接库的管理命令ldconfig此执行程序存放在/sbin目录下。
ldconfig通常在系统启动时运行而当用户安装了一个新的动态链接库时就需要手工运行这个命令。