File: auxiliary.lua

package info (click to toggle)
imapfilter 1%3A1.2.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 300 kB
  • ctags: 315
  • sloc: ansic: 3,392; sh: 182; makefile: 103
file content (69 lines) | stat: -rw-r--r-- 1,109 bytes parent folder | download
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
61
62
63
64
65
66
67
68
69
-- date_before()
function date_before(days)
    check_type(days, 'number')

    return os.date("%d-%b-%Y", os.time() - days * 60 * 60 * 24)
end


-- get_pass()
function get_pass(prompt)
    if (prompt ~= nil) then
	check_type(prompt, 'string')
	io.write(prompt)
    else
	io.write('Password: ')
    end

    ifsys.noecho()
    local pass = io.read()
    ifsys.echo()

    return pass
end


-- pipe_to()
function pipe_to(command, data)
    check_type(command, 'string')
    check_type(data, 'string')

    f = ifsys.popen(command, "w")

    ifsys.write(f, data)

    return ifsys.pclose(f)
end


-- pipe_from()
function pipe_from(command)
    check_type(command, 'string')

    f = ifsys.popen(command, "r")

    local string = ''
    while (true) do
	s = ifsys.read(f)
	if (s ~= nil) then
	    string = string .. s
	else
	    break
	end
    end

    return ifsys.pclose(f), string
end


-- daemon_mode()
function daemon_mode(interval, commands)
    check_type(interval, 'number')
    check_type(commands, 'function')

    ifsys.daemon()

    repeat
	pcall(commands)
    until (ifsys.sleep(interval) ~= 0)
end