diff options
| author | horus_arch | 2015-06-15 13:38:47 +0200 |
|---|---|---|
| committer | horus_arch | 2015-06-15 13:38:47 +0200 |
| commit | c79e605b60040c4c0e5c792fa447487c2b8ae246 (patch) | |
| tree | d20c97b59c6252e555618a128ea63f6fa9d016d9 /scanner.go | |
| parent | 3a09b2509102d58fe4e52a9a8fa699f6b42dc327 (diff) | |
| download | uhttpd-c79e605b60040c4c0e5c792fa447487c2b8ae246.tar.gz | |
Use flex to extract html. Icono-font used for icons.
Diffstat (limited to 'scanner.go')
| -rw-r--r-- | scanner.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/scanner.go b/scanner.go new file mode 100644 index 0000000..10be11b --- /dev/null +++ b/scanner.go @@ -0,0 +1,56 @@ +package main + +/* +#include <stdio.h> +#include <stdlib.h> +#include "urlscanner.h" +*/ +import "C" +import ( + "log" + "strings" +) + +type Link struct { + Url string + Text string + IsDir bool +} + +func getToken(input string) []Link { + var token C.int + var ls []Link + var l Link + + C.scan_string(C.CString(input)) + + for token = C.yylex(); token != C.MYEOF; token = C.yylex() { + + if token == C.TOKEN_URL { + // flex reads the href attr + + l.Url = C.GoString(C.yylval) + + if strings.HasSuffix(l.Url, "/") { + l.IsDir = true + } + + } else if token == C.TOKEN_TEXT { + // flex reads the link description + + l.Text = C.GoString(C.yylval) + ls = append(ls, l) + l = Link{} + } else { + // lexical error + + l = Link{} + log.Printf("Lexical Error on line %d \n", C.yylineno) + continue + } + } + + return ls +} + +// sort |
