about summary refs log tree commit diff stats
path: root/015immediate_addressing.cc
diff options
context:
space:
mode:
Diffstat (limited to '015immediate_addressing.cc')
0 files changed, 0 insertions, 0 deletions
23-09-19 21:55:42 +0200 ftp, file: better dirlist, fix FTP path issue' href='/ahoang/chawan/commit/src/loader/dirlist.nim?id=2277b19905ae3fb736166eb8f0d2d5c02f29bef9'>2277b199 ^
17969768 ^
2277b199 ^

17969768 ^

2277b199 ^






46837a6b ^
2277b199 ^









7badcc1f ^
2277b199 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

                
                     















                                
                                                                            











                                                    
                                         

                                                                   

                                           






                                                                           
                                                                      









                                     
                                           



                                              
import algorithm

import utils/strwidth
import utils/twtstr

type DirlistItemType = enum
  ITEM_FILE, ITEM_LINK, ITEM_DIR

type DirlistItem* = object
  name*: string
  modified*: string
  case t*: DirlistItemType
  of ITEM_LINK:
    linkto*: string
  of ITEM_FILE:
    nsize*: int
  of ITEM_DIR:
    discard

type NameWidthTuple = tuple[name: string, width: int, item: ptr DirlistItem]

func makeDirlist*(items: seq[DirlistItem]): string =
  var names: seq[NameWidthTuple]
  var maxw = 20
  for item in items:
    var name = item.name
    if item.t == ITEM_LINK:
      name &= '@'
    elif item.t == ITEM_DIR:
      name &= '/'
    let w = name.width()
    maxw = max(w, maxw)
    names.add((name, w, unsafeAddr item))
  names.sort(proc(a, b: NameWidthTuple): int = cmp(a.name, b.name))
  var outs = "<A HREF=\"../\">[Upper Directory]</A>\n"
  for (name, width, itemp) in names.mitems:
    let item = itemp[]
    var path = percentEncode(item.name, PathPercentEncodeSet)
    if item.t == ITEM_LINK:
      if item.linkto.len > 0 and item.linkto[^1] == '/':
        # If the target is a directory, treat it as a directory. (For FTP.)
        path &= '/'
    elif item.t == ITEM_DIR:
      path &= '/'
    var line = "<A HREF=\"" & path & "\">" & htmlEscape(name) & "</A>"
    while width <= maxw:
      if width mod 2 == 0:
        line &= ' '
      else:
        line &= '.'
      inc width
    if line[^1] != ' ':
      line &= ' '
    line &= htmlEscape(item.modified)
    if item.t == ITEM_FILE:
      line &= ' ' & convertSize(item.nsize)
    elif item.t == ITEM_LINK:
      line &= " -> " & htmlEscape(item.linkto)
    outs &= line & '\n'
  return outs