~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to src/cmd/godoc/codewalk.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
        "fmt"
18
18
        "http"
19
19
        "io"
20
 
        "io/ioutil"
21
20
        "log"
22
21
        "os"
23
22
        "regexp"
42
41
        }
43
42
 
44
43
        // If directory exists, serve list of code walks.
45
 
        dir, err := os.Lstat(abspath)
 
44
        dir, err := fs.Lstat(abspath)
46
45
        if err == nil && dir.IsDirectory() {
47
46
                codewalkDir(w, r, relpath, abspath)
48
47
                return
75
74
 
76
75
// A Codewalk represents a single codewalk read from an XML file.
77
76
type Codewalk struct {
78
 
        Title string "attr"
 
77
        Title string `xml:"attr"`
79
78
        File  []string
80
79
        Step  []*Codestep
81
80
}
84
83
// A Codestep is a single step in a codewalk.
85
84
type Codestep struct {
86
85
        // Filled in from XML
87
 
        Src   string "attr"
88
 
        Title string "attr"
89
 
        XML   string "innerxml"
 
86
        Src   string `xml:"attr"`
 
87
        Title string `xml:"attr"`
 
88
        XML   string `xml:"innerxml"`
90
89
 
91
90
        // Derived from Src; not in XML.
92
91
        Err    os.Error
114
113
 
115
114
 
116
115
// loadCodewalk reads a codewalk from the named XML file.
117
 
func loadCodewalk(file string) (*Codewalk, os.Error) {
118
 
        f, err := os.Open(file)
 
116
func loadCodewalk(filename string) (*Codewalk, os.Error) {
 
117
        f, err := fs.Open(filename)
119
118
        if err != nil {
120
119
                return nil, err
121
120
        }
125
124
        p.Entity = xml.HTMLEntity
126
125
        err = p.Unmarshal(cw, nil)
127
126
        if err != nil {
128
 
                return nil, &os.PathError{"parsing", file, err}
 
127
                return nil, &os.PathError{"parsing", filename, err}
129
128
        }
130
129
 
131
130
        // Compute file list, evaluate line numbers for addresses.
135
134
                if i < 0 {
136
135
                        i = len(st.Src)
137
136
                }
138
 
                file := st.Src[0:i]
139
 
                data, err := ioutil.ReadFile(absolutePath(file, *goroot))
 
137
                filename := st.Src[0:i]
 
138
                data, err := fs.ReadFile(absolutePath(filename, *goroot))
140
139
                if err != nil {
141
140
                        st.Err = err
142
141
                        continue
158
157
                        st.Hi = byteToLine(data, hi-1)
159
158
                }
160
159
                st.Data = data
161
 
                st.File = file
162
 
                m[file] = true
 
160
                st.File = filename
 
161
                m[filename] = true
163
162
        }
164
163
 
165
164
        // Make list of files
169
168
                cw.File[i] = f
170
169
                i++
171
170
        }
172
 
        sort.SortStrings(cw.File)
 
171
        sort.Strings(cw.File)
173
172
 
174
173
        return cw, nil
175
174
}
184
183
                Title string
185
184
        }
186
185
 
187
 
        dir, err := ioutil.ReadDir(abspath)
 
186
        dir, err := fs.ReadDir(abspath)
188
187
        if err != nil {
189
188
                log.Print(err)
190
189
                serveError(w, r, relpath, err)
192
191
        }
193
192
        var v vector.Vector
194
193
        for _, fi := range dir {
 
194
                name := fi.Name()
195
195
                if fi.IsDirectory() {
196
 
                        v.Push(&elem{fi.Name + "/", ""})
197
 
                } else if strings.HasSuffix(fi.Name, ".xml") {
198
 
                        cw, err := loadCodewalk(abspath + "/" + fi.Name)
 
196
                        v.Push(&elem{name + "/", ""})
 
197
                } else if strings.HasSuffix(name, ".xml") {
 
198
                        cw, err := loadCodewalk(abspath + "/" + name)
199
199
                        if err != nil {
200
200
                                continue
201
201
                        }
202
 
                        v.Push(&elem{fi.Name[0 : len(fi.Name)-len(".xml")], cw.Title})
 
202
                        v.Push(&elem{name[0 : len(name)-len(".xml")], cw.Title})
203
203
                }
204
204
        }
205
205
 
216
216
// the usual godoc HTML wrapper.
217
217
func codewalkFileprint(w http.ResponseWriter, r *http.Request, f string) {
218
218
        abspath := absolutePath(f, *goroot)
219
 
        data, err := ioutil.ReadFile(abspath)
 
219
        data, err := fs.ReadFile(abspath)
220
220
        if err != nil {
221
221
                log.Print(err)
222
222
                serveError(w, r, f, err)