From 82683098ae7db79bd441a391dc72a38918c782d0 Mon Sep 17 00:00:00 2001 From: Anubhav Saini Date: Wed, 14 Feb 2024 17:44:34 +0530 Subject: [PATCH] changes: makefile restored, long quotes, :retab, error fix in util.go while reading files --- Makefile | 3 +-- quotes/long | 22 ++++++++++++++++++ src/db.go | 64 ++++++++++++++++++++++++++--------------------------- src/util.go | 2 +- 4 files changed, 56 insertions(+), 35 deletions(-) create mode 100644 quotes/long diff --git a/Makefile b/Makefile index d36b8b2..0696fe1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ DESTDIR := -#PREFIX := /usr/local -PREFIX := . +PREFIX := /usr/local .PHONY: all all: diff --git a/quotes/long b/quotes/long new file mode 100644 index 0000000..693446f --- /dev/null +++ b/quotes/long @@ -0,0 +1,22 @@ +[ + { + "text": "It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming; but who does actually strive to do the deeds; who knows great enthusiasms, the great devotions; who spends himself in a worthy cause; who at the best knows in the end the triumph of high achievement, and who at the worst, if he fails, at least fails while daring greatly, so that his place shall never be with those cold and timid souls who neither know victory nor defeat.", + "attribution": "Theodore Roosevelt" + }, + { + "text": "I must not fear. Fear is the mind killer. Fear is the little-death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past I will turn the inner eye to see its path. Where the fear has gone there will be nothing. Only I will remain.", + "attribution": "Frank Herbert, Dune" + }, + { + "text": "The only thing we have to fear is fear itself nameless, unreasoning, unjustified terror which paralyzes needed efforts to convert retreat into advance. In every dark hour of our national life a leadership of frankness and vigor has met with that understanding and support of the people themselves which is essential to victory.", + "attribution": "Franklin D. Roosevelt" + }, + { + "text": "It is easy in the world to live after the world's opinion; it is easy in solitude to live after our own; but the great man is he who in the midst of the crowd keeps with perfect sweetness the independence of solitude.", + "attribution": "Ralph Waldo Emerson, Self-Reliance" + }, + { + "text": "The mass of men lead lives of quiet desperation. What is called resignation is confirmed desperation. From the desperate city you go into the desperate country, and have to console yourself with the bravery of minks and muskrats. A stereotyped but unconscious despair is concealed even under what are called the games and amusements of mankind.", + "attribution": "Henry David Thoreau, Walden" + } +] diff --git a/src/db.go b/src/db.go index 1584d33..b1fc0fb 100644 --- a/src/db.go +++ b/src/db.go @@ -1,54 +1,54 @@ package main import ( - "encoding/json" - "io/ioutil" - "os" - "path/filepath" + "encoding/json" + "io/ioutil" + "os" + "path/filepath" ) var FILE_STATE_DB string var MISTAKE_DB string func init() { - var ok bool - var data string - var home string + var ok bool + var data string + var home string - if home, ok = os.LookupEnv("HOME"); !ok { - die("Could not resolve home directory.") - } + if home, ok = os.LookupEnv("HOME"); !ok { + die("Could not resolve home directory.") + } - if data, ok = os.LookupEnv("XDG_DATA_HOME"); ok { - data = filepath.Join(data, "/tt") - } else { - data = filepath.Join(home, "/.local/share/tt") - } + if data, ok = os.LookupEnv("XDG_DATA_HOME"); ok { + data = filepath.Join(data, "/tt") + } else { + data = filepath.Join(home, "/.local/share/tt") + } - os.MkdirAll(data, 0700) + os.MkdirAll(data, 0700) - FILE_STATE_DB = filepath.Join(data, ".db") - MISTAKE_DB = filepath.Join(data, ".errors") + FILE_STATE_DB = filepath.Join(data, ".db") + MISTAKE_DB = filepath.Join(data, ".errors") } func readValue(path string, o interface{}) error { - b, err := ioutil.ReadFile(path) + b, err := ioutil.ReadFile(path) - if err != nil { - return err - } + if err != nil { + return err + } - return json.Unmarshal(b, o) + return json.Unmarshal(b, o) } func writeValue(path string, o interface{}) { - b, err := json.Marshal(o) - if err != nil { - panic(err) - } - - err = ioutil.WriteFile(path, b, 0600) - if err != nil { - panic(err) - } + b, err := json.Marshal(o) + if err != nil { + panic(err) + } + + err = ioutil.WriteFile(path, b, 0600) + if err != nil { + panic(err) + } } diff --git a/src/util.go b/src/util.go index c7c9f69..a003439 100644 --- a/src/util.go +++ b/src/util.go @@ -209,7 +209,7 @@ func readResource(typ, name string) []byte { return b } - if b, err := os.ReadFile(name); err != nil { + if b, err := os.ReadFile(filepath.Join(typ, name)); err != nil { fmt.Println(err) } else { return b