-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwb_tutorial_07_ate
executable file
·66 lines (56 loc) · 1.6 KB
/
pwb_tutorial_07_ate
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
#!/usr/bin/env bash
## BEGIN_DOC
## This tutorial introduces a custom Bash builtin
## to be used for the PWB` datasource: the ATE
## array table extension.
##
## This change will affect all of the steps, but
## particulary steps 2 (implement line-print
## function) and 3 (prepare data source).
## END_DOC
# 1. Enable the builtin(s)
enable pwb
# Diff #1: enable ATE builtin, too.
enable ate
# 2. Create line-printing function
print_line()
{
local -i index="$1"
local data_name="$2"
local -i chars_limit="$3"
# Diff #2: Using ATE methods to retrieve data
ate get_row "$data_name" "$index"
local line="${ATE_ARRAY[0]}"
printf "%-*s" "$chars_limit" "${line:0:$chars_limit}"
}
# 3. Get data
# Diff #3 Using ATE methods
declare ftable
ate declare ftable 1
# Use one of two methods to fill the ATE table:
if : ; then
# using ATE method
ate append_data ftable *
else
# or writing to host array
ate get_array_name ftable
declare -n ftarray="$ATE_VALUE"
ftarray=( * )
# -n unset the nameref, leaving its source untouched:
unset -n ftarray
fi
# You should always 'index_rows' after changing the array
# contents. Neglecting this leaves new records invisible
# when adding records, but can cause a segmentation fault
# if array elements are removed without reindexing the rows.
ate index_rows ftable
# Diff #4: use ATE methods to get table data count
declare -i file_count
ate get_row_count ftable -v file_count
#4 Declare the pwb handle
declare phandle
pwb declare phandle ftable "$file_count" print_line
#5 Start the interaction
pwb init
pwb start phandle
pwb restore