2022-05-31 05:38:51 +00:00
|
|
|
package archetype
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2023-01-31 04:23:56 +00:00
|
|
|
"fmt"
|
2022-05-31 05:38:51 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2022-06-07 06:59:41 +00:00
|
|
|
"os/exec"
|
2022-05-31 05:38:51 +00:00
|
|
|
"path/filepath"
|
2022-06-08 05:44:54 +00:00
|
|
|
"strconv"
|
2022-05-31 05:38:51 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type EurekaAdapter struct {
|
2022-06-05 18:09:00 +00:00
|
|
|
Root string
|
2022-06-08 05:44:54 +00:00
|
|
|
Config map[ConfigOption]string
|
2022-05-31 05:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *EurekaAdapter) Init(cfg *Config) {
|
|
|
|
fileInfo, err := os.Stat(cfg.Root)
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
panic("SSG content root does not exist! Ensure your configs are correct or create it!")
|
|
|
|
} else if !fileInfo.IsDir() {
|
|
|
|
panic("SSG content root is not a directory!")
|
|
|
|
}
|
|
|
|
|
|
|
|
self.Root = cfg.Root
|
2022-06-08 05:44:54 +00:00
|
|
|
self.Config = make(map[ConfigOption]string)
|
2022-06-10 06:38:29 +00:00
|
|
|
|
2022-06-08 05:44:54 +00:00
|
|
|
err = self.readCfg()
|
|
|
|
if err != nil {
|
2023-10-21 04:46:37 +00:00
|
|
|
fmt.Printf(err.Error())
|
2022-06-08 05:44:54 +00:00
|
|
|
panic("config.h is malformed!")
|
|
|
|
}
|
2022-05-31 05:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *EurekaAdapter) Name() string {
|
|
|
|
return "eureka"
|
|
|
|
}
|
|
|
|
|
2022-06-05 04:34:20 +00:00
|
|
|
func (self *EurekaAdapter) EditableSlugs() bool {
|
2022-06-05 18:09:00 +00:00
|
|
|
return false
|
2022-06-03 04:05:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 06:17:08 +00:00
|
|
|
func (self *EurekaAdapter) BuildOptions() []BuildOption {
|
|
|
|
return []BuildOption{
|
|
|
|
BuildOption{
|
|
|
|
Name: "twtxt",
|
|
|
|
Type: "string",
|
|
|
|
},
|
|
|
|
BuildOption{
|
|
|
|
Name: "remove newest twtxt",
|
|
|
|
Type: "bool",
|
|
|
|
},
|
|
|
|
BuildOption{
|
|
|
|
Name: "clear thumbnail cache",
|
|
|
|
Type: "bool",
|
|
|
|
},
|
|
|
|
}
|
2022-06-05 15:56:52 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 05:44:54 +00:00
|
|
|
func (self *EurekaAdapter) GetConfig() map[ConfigOption]string {
|
|
|
|
return self.Config
|
2022-05-31 05:38:51 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 05:44:54 +00:00
|
|
|
func (self *EurekaAdapter) SetConfig(cfg map[ConfigOption]string) error {
|
|
|
|
self.Config = cfg
|
|
|
|
return self.writeCfg()
|
2022-05-31 05:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *EurekaAdapter) ListPages() map[string]string {
|
|
|
|
files, err := ioutil.ReadDir(
|
|
|
|
filepath.Join(self.Root, "inc"))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
pages := map[string]string{}
|
2024-03-17 05:42:53 +00:00
|
|
|
pages["meta.nav.htm"] = "NAVIGATION"
|
2022-05-31 05:38:51 +00:00
|
|
|
for _, file := range files {
|
|
|
|
filename := file.Name()
|
2024-03-17 05:42:53 +00:00
|
|
|
if strings.HasSuffix(filename, ".htm") && filename != "meta.nav.htm" {
|
2022-05-31 05:38:51 +00:00
|
|
|
pages[filename] = strings.Replace(
|
|
|
|
strings.TrimSuffix(filename, ".htm"), "_", " ", -1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pages
|
|
|
|
}
|
|
|
|
|
2022-06-09 05:13:09 +00:00
|
|
|
func (self *EurekaAdapter) GetPage(filename string) Page {
|
2024-05-03 02:46:59 +00:00
|
|
|
fullPath := filepath.Join(self.Root, "inc", filename)
|
|
|
|
if !strings.HasPrefix(filepath.Clean(fullPath), self.Root) {
|
2022-06-09 05:13:09 +00:00
|
|
|
return Page{
|
|
|
|
Error: "You cannot escape!",
|
|
|
|
}
|
|
|
|
}
|
2022-05-31 05:38:51 +00:00
|
|
|
f, err := os.ReadFile(fullPath)
|
|
|
|
|
|
|
|
if err != nil {
|
2022-06-09 05:13:09 +00:00
|
|
|
return Page{
|
|
|
|
Error: err.Error(),
|
|
|
|
}
|
2022-05-31 05:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasSuffix(filename, ".htm") {
|
2022-06-09 05:13:09 +00:00
|
|
|
return Page{
|
|
|
|
Error: "Page file extension is not '.htm'",
|
|
|
|
}
|
2022-05-31 05:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
title := strings.Replace(
|
|
|
|
strings.TrimSuffix(filename, ".htm"), "_", " ", -1)
|
|
|
|
fileInfo, _ := os.Stat(fullPath)
|
|
|
|
content := string(f[:])
|
|
|
|
|
|
|
|
return Page{
|
|
|
|
Title: title,
|
2022-06-17 04:56:59 +00:00
|
|
|
Content: strings.ReplaceAll(content, "\r", ""),
|
2022-05-31 05:38:51 +00:00
|
|
|
Edited: fileInfo.ModTime(),
|
2022-06-09 05:13:09 +00:00
|
|
|
}
|
2022-05-31 05:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *EurekaAdapter) FormatPage(raw string) string {
|
2022-06-05 18:09:00 +00:00
|
|
|
// TODO: implement Eureka formatter to show preview
|
2022-05-31 05:38:51 +00:00
|
|
|
return raw
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *EurekaAdapter) FormattingHelp() string {
|
2022-06-05 18:09:00 +00:00
|
|
|
// TODO: show Eureka formatting guide
|
2022-06-15 07:33:56 +00:00
|
|
|
return `// shorthand for linking other pages
|
|
|
|
{page name}
|
|
|
|
|
|
|
|
// shorthand for page transclusion
|
|
|
|
{/page name}
|
|
|
|
|
|
|
|
// shorthand for arbitary link
|
|
|
|
{*destination url|text}
|
|
|
|
|
|
|
|
// shorthand for an image you can click to see the full sized version
|
|
|
|
{:anchor-id|image url|alt text}
|
|
|
|
|
|
|
|
// shorthand for an image with arbitrary link destination
|
|
|
|
{?anchor-id|destination url|image url|alt text}
|
|
|
|
|
|
|
|
// shorthand for an audio player
|
|
|
|
{_/path/to/media}
|
|
|
|
|
|
|
|
// shorthand for paragraphs, can embed other markup inside it
|
|
|
|
{¶graph text {with a link} {@and some bold text}}
|
|
|
|
|
|
|
|
// shorthand for ordered lists, can embed other markup inside it
|
|
|
|
{#
|
|
|
|
{-item one}
|
|
|
|
{-item two}
|
|
|
|
{-item three}
|
|
|
|
}
|
|
|
|
|
|
|
|
// shorthand for unordered lists, can embed other markup inside it
|
|
|
|
{,
|
|
|
|
{-item one}
|
|
|
|
{-item two}
|
|
|
|
{-item three}
|
|
|
|
}
|
|
|
|
|
|
|
|
// shorthand for bold
|
|
|
|
{@bold text}
|
|
|
|
|
|
|
|
// shorthand for italic
|
|
|
|
{~italic text}
|
|
|
|
|
|
|
|
// shorthand for code
|
|
|
|
{` + "`" + `short code}
|
|
|
|
|
|
|
|
// shorthand for pre
|
|
|
|
{$longer code}
|
|
|
|
|
|
|
|
// shorthand for quote
|
|
|
|
{'short quote}
|
|
|
|
|
|
|
|
// shorthand for blockquote
|
|
|
|
{>longer quote}
|
|
|
|
|
|
|
|
// shorthand for strikethrough
|
|
|
|
{\crossed-out text}
|
|
|
|
|
|
|
|
// shorthand for level 3 heading
|
|
|
|
{!heading text}
|
|
|
|
|
|
|
|
// shorthand for level 4 heading
|
|
|
|
{.heading text}
|
|
|
|
|
|
|
|
// shorthand for publish date (renders as <time class='publish-date'>)
|
2024-11-10 17:50:56 +00:00
|
|
|
{+2022-02-22}
|
|
|
|
|
|
|
|
// shorthand for tables
|
|
|
|
{[column 1 header|column 2 header|column 3 header}
|
|
|
|
{|simple data|{@bold data}|{*https://nilfm.cc|link data}}
|
|
|
|
{|more|and more|and more data!}
|
|
|
|
{;}
|
|
|
|
|
|
|
|
// shorthand for publish date (renders as <time class='publish-date'>)
|
|
|
|
{+2022-02-22}
|
|
|
|
|
|
|
|
// shorthand for explicit monospace, sans, and serif font respecively:
|
|
|
|
{=some mono text}
|
|
|
|
{(some sans serif text}
|
|
|
|
{)some serif text}
|
|
|
|
|
|
|
|
// shorthand for a pictured directory/list item
|
|
|
|
{%page name|picture}
|
|
|
|
|
|
|
|
// shorthand for a shop listing
|
|
|
|
{^payment-link|description|img1|alttext1|...|imgn|alttextn}`
|
2022-05-31 05:38:51 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 04:34:20 +00:00
|
|
|
func (self *EurekaAdapter) CreatePage(slug, title, content string) error {
|
2022-06-06 05:29:39 +00:00
|
|
|
// eureka creates titles from slugs, so we transform the title into the slug
|
2024-03-17 05:42:53 +00:00
|
|
|
slug = strings.ToLower(strings.ReplaceAll(title, " ", "_")) + ".htm"
|
2022-06-06 05:29:39 +00:00
|
|
|
path := filepath.Join(self.Root, "inc", slug)
|
|
|
|
|
2024-05-03 02:46:59 +00:00
|
|
|
if !strings.HasPrefix(filepath.Clean(path), self.Root) {
|
|
|
|
errors.New("You cannot escape!")
|
2022-06-09 05:13:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 05:29:39 +00:00
|
|
|
_, err := os.Stat(path)
|
|
|
|
if err == nil || !os.IsNotExist(err) {
|
|
|
|
return errors.New("File already exists")
|
|
|
|
}
|
|
|
|
f, err := os.Create(path)
|
2022-06-05 18:09:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
2022-06-17 04:56:59 +00:00
|
|
|
f.WriteString(strings.ReplaceAll(content, "\r", ""))
|
2022-05-31 05:38:51 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-05 04:34:20 +00:00
|
|
|
func (self *EurekaAdapter) SavePage(oldSlug, newSlug, title, content string) error {
|
2022-06-06 05:29:39 +00:00
|
|
|
// eureka creates titles from slugs, so we transform the title into the slug
|
2024-03-17 05:42:53 +00:00
|
|
|
newSlug = strings.ToLower(strings.ReplaceAll(title, " ", "_")) + ".htm"
|
2022-06-09 05:13:09 +00:00
|
|
|
|
2024-05-03 02:46:59 +00:00
|
|
|
oldPath := filepath.Join(self.Root, "inc", oldSlug)
|
|
|
|
newPath := filepath.Join(self.Root, "inc", newSlug)
|
|
|
|
|
|
|
|
if !strings.HasPrefix(filepath.Clean(oldPath), filepath.Join(self.Root, "inc")) ||
|
|
|
|
!strings.HasPrefix(filepath.Clean(newPath), filepath.Join(self.Root, "inc")) {
|
2022-06-09 05:13:09 +00:00
|
|
|
return errors.New("You cannot escape!")
|
|
|
|
}
|
|
|
|
|
2022-06-05 18:09:00 +00:00
|
|
|
f, err := os.Create(filepath.Join(self.Root, "inc", newSlug))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
if oldSlug != newSlug {
|
2022-06-08 05:44:54 +00:00
|
|
|
siteRoot := self.Config[ConfigOption{
|
|
|
|
Name: "SITEROOT",
|
|
|
|
Type: "string",
|
|
|
|
}]
|
|
|
|
htmlFile := filepath.Join(self.Root, siteRoot, oldSlug+"l")
|
|
|
|
_, err := os.Stat(htmlFile)
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
os.Remove(htmlFile)
|
|
|
|
}
|
2022-06-05 18:09:00 +00:00
|
|
|
os.Remove(filepath.Join(self.Root, "inc", oldSlug))
|
|
|
|
}
|
|
|
|
|
2022-11-01 04:39:53 +00:00
|
|
|
f.WriteString(strings.ReplaceAll(content, "\r", ""))
|
2022-05-31 05:38:51 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-05 04:34:20 +00:00
|
|
|
func (self *EurekaAdapter) DeletePage(slug string) error {
|
2022-06-08 05:44:54 +00:00
|
|
|
siteRoot := self.Config[ConfigOption{
|
|
|
|
Name: "SITEROOT",
|
|
|
|
Type: "string",
|
|
|
|
}]
|
|
|
|
htmlFile := filepath.Join(self.Root, siteRoot, slug+"l")
|
2024-05-03 02:46:59 +00:00
|
|
|
|
|
|
|
if !strings.HasPrefix(filepath.Clean(htmlFile), filepath.Join(self.Root, siteRoot)) {
|
|
|
|
return errors.New("You cannot escape!")
|
|
|
|
}
|
|
|
|
|
2022-06-08 05:44:54 +00:00
|
|
|
_, err := os.Stat(htmlFile)
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
os.Remove(htmlFile)
|
|
|
|
}
|
2022-06-05 18:09:00 +00:00
|
|
|
return os.Remove(filepath.Join(self.Root, "inc", slug))
|
2022-05-31 05:38:51 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 06:17:08 +00:00
|
|
|
func (self *EurekaAdapter) Build(buildOptions map[BuildOption]string) BuildStatus {
|
|
|
|
twtxt := buildOptions[BuildOption{
|
|
|
|
Name: "twtxt",
|
|
|
|
Type: "string",
|
|
|
|
}]
|
2022-06-19 05:48:39 +00:00
|
|
|
|
|
|
|
rmNewestTwtxt := buildOptions[BuildOption{
|
|
|
|
Name: "remove newest twtxt",
|
|
|
|
Type: "bool",
|
|
|
|
}]
|
|
|
|
|
|
|
|
clearThumbs := buildOptions[BuildOption{
|
|
|
|
Name: "clear thumbnail cache",
|
|
|
|
Type: "bool",
|
|
|
|
}]
|
|
|
|
|
2022-06-09 05:13:09 +00:00
|
|
|
cmdArgs := []string{}
|
2022-06-19 05:48:39 +00:00
|
|
|
if clearThumbs != "" {
|
|
|
|
cmdArgs = append(cmdArgs, "-r")
|
|
|
|
}
|
|
|
|
if rmNewestTwtxt != "" {
|
|
|
|
cmdArgs = append(cmdArgs, "-d")
|
|
|
|
}
|
2022-06-07 06:59:41 +00:00
|
|
|
if twtxt != "" {
|
2022-06-09 05:13:09 +00:00
|
|
|
cmdArgs = append(cmdArgs, "-t")
|
|
|
|
cmdArgs = append(cmdArgs, twtxt)
|
2022-06-07 06:59:41 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 05:13:09 +00:00
|
|
|
cmd := exec.Command("./build.sh", cmdArgs...)
|
2022-06-07 06:59:41 +00:00
|
|
|
cmd.Dir = self.Root
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
|
|
|
return BuildStatus{
|
|
|
|
Success: err == nil,
|
|
|
|
Message: string(out),
|
|
|
|
}
|
2022-05-31 05:38:51 +00:00
|
|
|
}
|
2022-06-08 05:44:54 +00:00
|
|
|
|
2023-10-21 04:46:37 +00:00
|
|
|
func (self *EurekaAdapter) Deploy() DeployStatus {
|
|
|
|
cmd := exec.Command("./deploy.sh")
|
|
|
|
cmd.Dir = self.Root
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
|
|
|
return DeployStatus{
|
|
|
|
Success: err == nil,
|
|
|
|
Message: string(out),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *EurekaAdapter) Revert() RevertStatus {
|
|
|
|
cmd := exec.Command("./deploy.sh", "--resync")
|
|
|
|
cmd.Dir = self.Root
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
|
|
|
return RevertStatus{
|
|
|
|
Success: err == nil,
|
|
|
|
Message: string(out),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 05:44:54 +00:00
|
|
|
func (self *EurekaAdapter) readCfg() error {
|
|
|
|
configPath := filepath.Join(self.Root, "config.h")
|
|
|
|
_, err := os.Stat(filepath.Join(self.Root, "config.h"))
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
configPath = filepath.Join(self.Root, "config.def.h")
|
|
|
|
}
|
|
|
|
f, err := os.ReadFile(configPath)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-01-31 04:23:56 +00:00
|
|
|
fileData := strings.Replace(
|
2023-10-21 04:46:37 +00:00
|
|
|
strings.Replace(
|
|
|
|
string(f[:]), "/* clang-format on */", "", -1),
|
|
|
|
"/* clang-format off */", "", -1)
|
2022-06-08 05:44:54 +00:00
|
|
|
|
|
|
|
macros := strings.Split(fileData, "#define ")[1:]
|
|
|
|
for _, macro := range macros {
|
|
|
|
tokens := strings.Split(strings.TrimSpace(macro), " ")
|
|
|
|
k := tokens[0]
|
|
|
|
v := strings.TrimSpace(strings.Join(tokens[1:], " "))
|
|
|
|
|
|
|
|
if strings.Contains(v, "\"") {
|
2023-01-13 05:43:44 +00:00
|
|
|
if strings.HasSuffix(k, "_HTML") {
|
2022-06-08 05:44:54 +00:00
|
|
|
// process multiline string
|
|
|
|
lines := strings.Split(v, "\n")
|
|
|
|
cleanedString := ""
|
|
|
|
for _, l := range lines {
|
|
|
|
l = strings.TrimSuffix(l, "\r")
|
|
|
|
l = strings.TrimSuffix(l, "\\")
|
|
|
|
l = strings.TrimSpace(l)
|
|
|
|
l = strings.TrimPrefix(l, "\"")
|
|
|
|
l = strings.TrimSuffix(l, "\"")
|
|
|
|
l = strings.ReplaceAll(l, "\\\"", "\"")
|
|
|
|
l = strings.ReplaceAll(l, "\\n", "\n")
|
|
|
|
cleanedString += l
|
|
|
|
}
|
|
|
|
self.Config[ConfigOption{
|
|
|
|
Name: k,
|
|
|
|
Type: "multilinestring",
|
|
|
|
}] = cleanedString
|
|
|
|
} else {
|
|
|
|
cleanedString := strings.TrimSuffix(strings.TrimPrefix(v, "\""), "\"")
|
|
|
|
cleanedString = strings.ReplaceAll(cleanedString, "\\n", "\n")
|
|
|
|
cleanedString = strings.ReplaceAll(cleanedString, "\r", "")
|
|
|
|
cleanedString = strings.ReplaceAll(cleanedString, "\\\"", "\"")
|
|
|
|
self.Config[ConfigOption{
|
2024-10-27 19:43:17 +00:00
|
|
|
Name: k,
|
|
|
|
Type: "string",
|
|
|
|
Hidden: strings.HasPrefix(k, "DEPLOY") || k == "SITEROOT",
|
2022-06-08 05:44:54 +00:00
|
|
|
}] = cleanedString
|
|
|
|
}
|
|
|
|
} else if strings.Contains(v, ".") {
|
|
|
|
_, err := strconv.ParseFloat(v, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
self.Config[ConfigOption{
|
|
|
|
Name: k,
|
|
|
|
Type: "float",
|
|
|
|
}] = v
|
|
|
|
} else {
|
|
|
|
_, err := strconv.ParseInt(v, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-01-13 05:43:44 +00:00
|
|
|
cfgType := "int"
|
|
|
|
if strings.HasPrefix(k, "IS_") {
|
2023-10-21 04:46:37 +00:00
|
|
|
cfgType = "bool"
|
|
|
|
}
|
2022-06-08 05:44:54 +00:00
|
|
|
self.Config[ConfigOption{
|
|
|
|
Name: k,
|
2023-01-13 05:43:44 +00:00
|
|
|
Type: cfgType,
|
2022-06-08 05:44:54 +00:00
|
|
|
}] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *EurekaAdapter) writeCfg() error {
|
|
|
|
f, err := os.Create(filepath.Join(self.Root, "config.h"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
|
2023-10-21 04:46:37 +00:00
|
|
|
f.WriteString("/* clang-format off */\n")
|
2022-06-08 05:44:54 +00:00
|
|
|
for k, v := range self.Config {
|
|
|
|
switch k.Type {
|
|
|
|
case "int":
|
2023-10-21 04:46:37 +00:00
|
|
|
fallthrough
|
2023-01-13 05:43:44 +00:00
|
|
|
case "bool":
|
2022-06-08 05:44:54 +00:00
|
|
|
_, err := strconv.ParseInt(v, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
f.WriteString("#define " + k.Name + " " + v + "\n")
|
|
|
|
case "float":
|
|
|
|
_, err := strconv.ParseFloat(v, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
f.WriteString("#define " + k.Name + " " + v + "\n")
|
|
|
|
case "string":
|
|
|
|
fallthrough
|
|
|
|
case "multilinestring":
|
|
|
|
v = strings.ReplaceAll(v, "\"", "\\\"")
|
|
|
|
v = strings.ReplaceAll(v, "\n", "\\n\" \\\n\"")
|
|
|
|
v = strings.ReplaceAll(v, "\r", "")
|
|
|
|
f.WriteString("#define " + k.Name + " \"" + v + "\"\n")
|
|
|
|
default:
|
2023-01-31 04:23:56 +00:00
|
|
|
fmt.Println("Unsupported config value type: " + k.Type)
|
2022-06-08 05:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-21 04:46:37 +00:00
|
|
|
|
|
|
|
f.WriteString("/* clang-format on */\n")
|
2022-06-08 05:44:54 +00:00
|
|
|
return nil
|
|
|
|
}
|