Skip to content

Commit 1d9463c

Browse files
committed
fix ps show bug
1 parent e47e3ee commit 1d9463c

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ api.sh
33
notes.txt
44
template.*
55

6-
project/*.task.*
6+
project/1*
77
project/template.*
88
project/cses-cli
99
project/pkg

project/helper.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ func cacheGet(filename string, ret interface{}, root string) bool {
7474
return true
7575
}
7676

77+
func writeTask(filename string, text string, root string){
78+
f, err := os.Create(filepath.Join(root, filename))
79+
defer f.Close()
80+
check(err)
81+
_, err = f.WriteString(text)
82+
check(err)
83+
}
84+
7785
func updateListByTask(task string, status string, root string) {
7886
var problems = []*Problem{}
7987
cacheGet("problemList.json", &problems, root)
@@ -95,18 +103,19 @@ func getTemplate(ext string) string {
95103
return string(content)
96104
}
97105

98-
func getTaskFromCache(task string, root string) string {
106+
func getTaskFromCache(task string, root string) (string, string) {
99107
path := filepath.Join(root, task+".task.html")
100108

101109
output, err := exec.Command("bash", "-c", "lynx -dump "+path).Output()
102110
check(err)
103111
data := string(output)
104-
112+
105113
for k, v := range unicodeMap {
106114
data = strings.Replace(data, k, v, -1)
107115
}
108116

109-
return data
117+
x := strings.Fields(strings.Split(strings.Split(data, "\n")[0], "-")[1])
118+
return strings.Join(x, "-"), data
110119
}
111120

112121
func writeCodeFile(filename string, text string, template string) bool {

project/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func submit(sourceFile string, sess *Session) {
170170
}
171171
}
172172

173-
func getTask(task string, sess *Session) (string, bool) {
173+
func getTask(task string, sess *Session) (string, string, bool) {
174174
filename := task + ".task.html"
175175
path := filepath.Join(sess.Root, filename)
176176

@@ -185,15 +185,16 @@ func getTask(task string, sess *Session) (string, bool) {
185185
s.Stop()
186186

187187
if text == "" {
188-
return "", false
188+
return "", "", false
189189
}
190-
cacheSet(filename, text, sess.Root)
190+
writeTask(filename, text, sess.Root)
191191
}
192-
return getTaskFromCache(task, sess.Root), true
192+
title, text := getTaskFromCache(task, sess.Root)
193+
return title, text, true
193194
}
194195

195196
func show(task string, sess *Session) {
196-
text, exist := getTask(task, sess)
197+
_, text, exist := getTask(task, sess)
197198
if exist {
198199
fmt.Println(text)
199200
} else {
@@ -203,12 +204,12 @@ func show(task string, sess *Session) {
203204

204205
func solve(task string, sess *Session) {
205206

206-
text, exist := getTask(task, sess)
207+
title, text, exist := getTask(task, sess)
207208
if !exist {
208209
fmt.Println("Task Doesn't Exist")
209210
}
210211

211-
filename := task + ".task" + langExtMap[sess.Lang]
212+
filename := task + "."+title+ langExtMap[sess.Lang]
212213
template := getTemplate(langExtMap[sess.Lang])
213214

214215
writeCodeFile(filename, text, template)

0 commit comments

Comments
 (0)