mirror of https://github.com/tstack/lnav
[markdown] add support for going to an anchor
parent
fd956c66d3
commit
87791ec94b
@ -0,0 +1,54 @@
|
||||
import datetime
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
MSGS = [
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
|
||||
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
|
||||
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||
]
|
||||
|
||||
GLOG_DATE_FMT = "%Y%m%d %H:%M:%S"
|
||||
|
||||
START_TIME = datetime.datetime.fromtimestamp(1490191111)
|
||||
|
||||
try:
|
||||
shutil.rmtree("/tmp/demo")
|
||||
os.makedirs("/tmp/demo")
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
PIDS = [
|
||||
"123",
|
||||
"123",
|
||||
"123",
|
||||
"121",
|
||||
"124",
|
||||
"123",
|
||||
"61456",
|
||||
"61456",
|
||||
"61457",
|
||||
]
|
||||
|
||||
LOG_LOCS = [
|
||||
"demo.cc:123",
|
||||
"demo.cc:352",
|
||||
"loader.cc:13",
|
||||
"loader.cc:552",
|
||||
"blaster.cc:352",
|
||||
"blaster.cc:112",
|
||||
"blaster.cc:6782",
|
||||
]
|
||||
|
||||
CURR_TIME = START_TIME
|
||||
for _index in range(0, int(sys.argv[1])):
|
||||
CURR_TIME += datetime.timedelta(seconds=random.randrange(1, 22))
|
||||
print("I%s.%06d %s %s] %s" % (
|
||||
CURR_TIME.strftime(GLOG_DATE_FMT),
|
||||
random.randrange(0, 100000),
|
||||
random.choice(PIDS),
|
||||
random.choice(LOG_LOCS),
|
||||
random.choice(MSGS)))
|
@ -0,0 +1,18 @@
|
||||
{
|
||||
"$schema": "https://lnav.org/schemas/config-v1.schema.json",
|
||||
"global": {
|
||||
"lnav_tutorial_name": "tutorial1"
|
||||
},
|
||||
"ui": {
|
||||
"keymap-defs": {
|
||||
"default": {
|
||||
"x79": {
|
||||
"command": "|lnav-tutorial-key-handler next"
|
||||
},
|
||||
"x59": {
|
||||
"command": "|lnav-tutorial-key-handler prev"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
|
||||
;SELECT filepath AS tutorial_path FROM lnav_file
|
||||
WHERE filepath GLOB '*/tutorial1/index.md' LIMIT 1
|
||||
;SELECT CASE
|
||||
WHEN $1 = 'next' AND
|
||||
step < (SELECT max(step) FROM lnav_tutorial_steps WHERE name = $lnav_tutorial_name)
|
||||
THEN step + 1
|
||||
WHEN $1 = 'prev' AND step > 1 THEN step - 1
|
||||
ELSE step
|
||||
END AS new_step
|
||||
FROM lnav_tutorial_step WHERE name = $lnav_tutorial_name
|
||||
;SELECT CASE
|
||||
WHEN $1 = 'next' AND
|
||||
step = (SELECT max(step) FROM lnav_tutorial_steps WHERE name = $lnav_tutorial_name)
|
||||
THEN '#conclusion'
|
||||
ELSE '#step-' || $new_step
|
||||
END AS new_anchor
|
||||
FROM lnav_tutorial_step WHERE name = $lnav_tutorial_name
|
||||
;UPDATE lnav_tutorial_step SET step = $new_step WHERE name = $lnav_tutorial_name
|
||||
;UPDATE lnav_views SET top_meta = json_object(
|
||||
'file', $tutorial_path,
|
||||
'anchor', $new_anchor
|
||||
)
|
||||
WHERE name = 'text'
|
||||
:switch-to-view text
|
||||
;UPDATE lnav_views SET top = 0
|
||||
WHERE name = 'log'
|
||||
;REPLACE INTO lnav_user_notifications (id, views, message)
|
||||
SELECT * FROM lnav_tutorial_log_notification;
|
@ -0,0 +1,141 @@
|
||||
CREATE TABLE lnav_tutorial_step
|
||||
(
|
||||
name TEXT NOT NULL PRIMARY KEY,
|
||||
step INTEGER NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO lnav_tutorial_step
|
||||
VALUES ('tutorial1', 1);
|
||||
|
||||
CREATE TABLE lnav_tutorial_steps
|
||||
(
|
||||
name TEXT NOT NULL,
|
||||
step INTEGER NOT NULL,
|
||||
achievements TEXT NOT NULL,
|
||||
PRIMARY KEY (name, step)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS lnav_tutorial_progress
|
||||
(
|
||||
name TEXT NOT NULL,
|
||||
step INTEGER NOT NULL,
|
||||
achieved TEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY (name, step, achieved)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS lnav_tutorial_lines
|
||||
(
|
||||
name TEXT NOT NULL,
|
||||
step INTEGER NOT NULL,
|
||||
view_ptr TEXT NOT NULL,
|
||||
view_value TEXT NOT NULL,
|
||||
achievement TEXT NOT NULL,
|
||||
log_comment TEXT
|
||||
);
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS add_tutorial_data
|
||||
AFTER INSERT
|
||||
ON lnav_events
|
||||
WHEN jget(new.content, '/$schema') = 'https://lnav.org/event-file-format-detected-v1.schema.json' AND
|
||||
jget(new.content, '/format') = 'text/markdown'
|
||||
BEGIN
|
||||
INSERT INTO lnav_tutorial_steps
|
||||
SELECT jget(tutorial_meta, '/name'),
|
||||
key + 1,
|
||||
value
|
||||
FROM (SELECT yaml_to_json(lnav_file_metadata.content) AS tutorial_meta
|
||||
FROM lnav_file_metadata
|
||||
WHERE filepath = jget(new.content, '/filename')) AS meta_content,
|
||||
json_each(jget(meta_content.tutorial_meta, '/steps'));
|
||||
|
||||
REPLACE INTO lnav_tutorial_lines
|
||||
SELECT name,
|
||||
step,
|
||||
jget(value, '/view_ptr'),
|
||||
jget(value, '/view_value'),
|
||||
key,
|
||||
jget(value, '/comment')
|
||||
FROM lnav_tutorial_steps,
|
||||
json_each(achievements)
|
||||
WHERE jget(value, '/view_ptr') IS NOT NULL;
|
||||
|
||||
REPLACE INTO lnav_user_notifications (id, views, message)
|
||||
SELECT *
|
||||
FROM lnav_tutorial_log_notification;
|
||||
|
||||
END;
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS lnav_tutorial_view_listener UPDATE OF top
|
||||
ON lnav_views_echo
|
||||
WHEN new.name = 'log'
|
||||
BEGIN
|
||||
INSERT OR IGNORE INTO lnav_tutorial_progress
|
||||
SELECT lnav_tutorial_lines.name,
|
||||
lnav_tutorial_lines.step,
|
||||
achievement
|
||||
FROM lnav_tutorial_step,
|
||||
lnav_tutorial_lines
|
||||
WHERE lnav_tutorial_step.step = lnav_tutorial_lines.step
|
||||
AND jget(json_object('top', new.top,
|
||||
'left', new.left,
|
||||
'search', new.search),
|
||||
view_ptr) = view_value;
|
||||
UPDATE all_logs
|
||||
SET log_comment = (SELECT log_comment
|
||||
FROM lnav_tutorial_step,
|
||||
lnav_tutorial_lines
|
||||
WHERE lnav_tutorial_step.step = lnav_tutorial_lines.step
|
||||
AND lnav_tutorial_lines.log_comment IS NOT NULL
|
||||
AND jget(json_object('top', new.top,
|
||||
'left', new.left,
|
||||
'search', new.search), view_ptr) = view_value)
|
||||
WHERE log_line = new.top
|
||||
AND log_comment IS NULL;
|
||||
END;
|
||||
|
||||
CREATE TABLE lnav_tutorial_message
|
||||
(
|
||||
msgid INTEGER PRIMARY KEY,
|
||||
msg TEXT
|
||||
);
|
||||
|
||||
CREATE VIEW lnav_tutorial_current_achievements AS
|
||||
SELECT key AS achievement, value
|
||||
FROM lnav_tutorial_step,
|
||||
lnav_tutorial_steps, json_each(lnav_tutorial_steps.achievements)
|
||||
WHERE lnav_tutorial_step.step = lnav_tutorial_steps.step;
|
||||
|
||||
CREATE VIEW lnav_tutorial_current_progress AS
|
||||
SELECT achieved
|
||||
FROM lnav_tutorial_step,
|
||||
lnav_tutorial_progress
|
||||
WHERE lnav_tutorial_step.step = lnav_tutorial_progress.step;
|
||||
|
||||
CREATE VIEW lnav_tutorial_remaining_achievements AS
|
||||
SELECT *
|
||||
FROM lnav_tutorial_current_achievements
|
||||
WHERE achievement NOT IN (SELECT * FROM lnav_tutorial_current_progress);
|
||||
|
||||
CREATE VIEW lnav_tutorial_log_notification AS
|
||||
SELECT *
|
||||
FROM (SELECT 'org.lnav.tutorial.log' AS id, '["log"]' AS views, jget(value, '/notification') AS message
|
||||
FROM lnav_tutorial_remaining_achievements
|
||||
UNION ALL
|
||||
SELECT 'org.lnav.tutorial.log' AS id,
|
||||
'["log"]' AS views,
|
||||
'Press y to go to the next step in the tutorial' AS message)
|
||||
LIMIT 1;
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS lnav_tutorial_progress_listener
|
||||
AFTER INSERT
|
||||
ON lnav_tutorial_progress
|
||||
BEGIN
|
||||
DELETE FROM lnav_user_notifications WHERE id = 'org.lnav.tutorial.log';
|
||||
REPLACE INTO lnav_user_notifications (id, views, message)
|
||||
SELECT *
|
||||
FROM lnav_tutorial_log_notification;
|
||||
END;
|
||||
|
||||
REPLACE INTO lnav_user_notifications (id, views, message)
|
||||
VALUES ('org.lnav.tutorial.text', '["text"]', 'Press "q" to go to the log view')
|
@ -0,0 +1,96 @@
|
||||
---
|
||||
name: tutorial1
|
||||
steps:
|
||||
- move-to-error:
|
||||
description: "Move to an error"
|
||||
view_ptr: /top
|
||||
view_value: 6
|
||||
notification: "Press e/Shift+E to move through the errors"
|
||||
comment: |
|
||||
You found the error!
|
||||
[Log formats](https://docs.lnav.org/en/latest/formats.html#format-file-reference)
|
||||
can define the log levels for a given message.
|
||||
The [theme](https://docs.lnav.org/en/latest/config.html#theme-definitions) defines
|
||||
how the levels are displayed.
|
||||
move-to-warning:
|
||||
description: "Move to a warning"
|
||||
notification: "Press w/Shift+W to move through the warnings"
|
||||
view_ptr: /top
|
||||
view_value: 3
|
||||
comment: |
|
||||
You found the warning! The scrollbar on the right is highlighted
|
||||
to show the position of
|
||||
<span class="-lnav_log-level-styles_warning">warnings</span> and
|
||||
<span class="-lnav_log-level-styles_error">errors</span> in this
|
||||
view.
|
||||
- search-for-term:
|
||||
description: "Search for something"
|
||||
notification: "Press / to search for '1AF9...'"
|
||||
view_ptr: /search
|
||||
view_value: 1AF9293A-F42D-4318-BCDF-60234B240955
|
||||
move-to-next-hit:
|
||||
description: "Move to the next hit"
|
||||
notification: "Press n/Shift+N to move through the search hits"
|
||||
view_ptr: /top
|
||||
view_value: 53
|
||||
comment: |
|
||||
The matching text in a search is highlighted in
|
||||
<span class="-lnav_styles_search">reverse-video</span>.
|
||||
However, the text is not always on-screen, so the bar on the
|
||||
left will also be highlighted. You can then press `>` to
|
||||
move right to the next (horizontal) search hit. Pressing
|
||||
`<` will move left to the previous (horizontal) hit or all
|
||||
the way back to the start of the line.
|
||||
move-right:
|
||||
description: "Move to the right"
|
||||
notification: "Press > to move horizontally to view the search hit"
|
||||
view_ptr: /left
|
||||
view_value: 150
|
||||
---
|
||||
# Tutorial 1
|
||||
|
||||
Welcome to the first _interactive_ **lnav** tutorial!
|
||||
|
||||
This tutorial will guide you through the basics of navigating log files.
|
||||
|
||||
## Step 1
|
||||
|
||||
Finding errors quickly is one of the main use-cases for **lnav**. To
|
||||
make that quick and easy, **lnav** parses the log messages in log files
|
||||
as they are loaded and builds indexes of the errors and warnings. You
|
||||
can then use the following hotkeys to jump to them in the log view:
|
||||
|
||||
| Key | Action |
|
||||
|-----------|----------------------------------------------------------------------------------|
|
||||
| `e` | Move to the next <span class="-lnav_log-level-styles_error">error</span> |
|
||||
| `Shift+E` | Move to the previous <span class="-lnav_log-level-styles_error">error</span> |
|
||||
| `w` | Move to the next <span class="-lnav_log-level-styles_warning">warning</span> |
|
||||
| `Shift+W` | Move to the previous <span class="-lnav_log-level-styles_warning">warning</span> |
|
||||
|
||||
To complete this step in the tutorial, you'll need to navigate to the
|
||||
errors and warnings in the sample log file. You can check the upper-right
|
||||
status bar for tips on what you need to do next. Now, press `q` to switch
|
||||
to the log view and begin navigating the sample log file.
|
||||
|
||||
## Step 2
|
||||
|
||||
To search for text in files, you can press `/` to enter the search
|
||||
prompt. To make it easier to search for text that is on-screen, you
|
||||
can press `TAB` to complete values that are shown on screen. For
|
||||
example, to search for the UUID "1AF9293A-F42D-4318-BCDF-60234B240955"
|
||||
that is in one of the error messages, you can enter "1AF9" and then
|
||||
press `TAB` to complete the rest of the UUID.
|
||||
|
||||
Press `q` to switch to the log view and try searching for the UUID.
|
||||
|
||||
## Conclusion
|
||||
|
||||
That's all for now, visit https://lnav.org/downloads to find how to
|
||||
download/install a copy of lnav for your system. The full documentation
|
||||
is available at https://docs.lnav.org.
|
||||
|
||||
## Colophon
|
||||
|
||||
The source for this tutorial is available here:
|
||||
|
||||
https://github.com/tstack/lnav/tree/master/docs/tutorial/tutorial1
|
@ -0,0 +1,100 @@
|
||||
I20170322 06:58:47.082758 61456 blaster.cc:112] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 06:58:58.019562 121 demo.cc:123] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 06:58:59.059175 123 blaster.cc:6782] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
W20170322 06:59:16.062826 61456 demo.cc:352] Ut enim ad minim veniam, quis nostrud exercitation 1AF9293A-F42D-4318-BCDF-60234B240955 ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 06:59:28.084062 124 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 06:59:32.053551 123 loader.cc:13] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
E20170322 06:59:53.084969 123 loader.cc:552] Excepteur sint occaecat cupidatat non proident 1AF9293A-F42D-4318-BCDF-60234B240955, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:00:00.096693 123 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:00:03.049849 123 demo.cc:352] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:00:08.070575 123 blaster.cc:6782] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:00:23.019849 123 blaster.cc:352] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:00:28.022692 61457 loader.cc:552] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:00:29.058438 61456 blaster.cc:352] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:00:30.028483 123 loader.cc:13] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:00:49.070676 123 demo.cc:352] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:00:56.095214 123 loader.cc:552] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
W20170322 07:01:14.042785 123 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:01:31.083704 123 blaster.cc:112] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:01:44.013733 121 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:01:55.024085 121 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:02:02.027811 121 blaster.cc:6782] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:02:14.022939 61456 blaster.cc:112] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:02:30.035925 123 loader.cc:13] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:02:49.024985 123 loader.cc:13] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:03:09.056478 121 blaster.cc:6782] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:03:15.023777 123 demo.cc:352] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:03:32.066107 123 blaster.cc:352] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:03:48.028662 124 blaster.cc:6782] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:03:54.027078 123 demo.cc:123] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:04:09.041478 123 demo.cc:123] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:04:14.068162 121 blaster.cc:6782] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:04:28.099513 124 blaster.cc:112] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:04:40.063473 124 loader.cc:552] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:04:50.024030 123 loader.cc:552] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:04:56.081415 121 blaster.cc:352] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:05:14.096304 123 blaster.cc:352] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:05:21.086331 123 demo.cc:352] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:05:33.039503 123 loader.cc:13] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:05:43.092657 124 blaster.cc:6782] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:05:59.002644 123 demo.cc:123] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:06:01.022102 123 demo.cc:352] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:06:22.005675 123 blaster.cc:6782] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:06:37.088974 123 blaster.cc:112] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:06:44.043938 61457 demo.cc:123] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:06:47.060703 123 loader.cc:13] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:06:49.052185 61456 demo.cc:123] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:06:52.074424 61457 demo.cc:352] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:07:02.063191 123 demo.cc:123] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:07:10.030327 61457 blaster.cc:112] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:07:11.011338 123 loader.cc:13] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:07:27.078391 123 blaster.cc:352] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:07:41.061684 123 blaster.cc:112] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:07:53.076558 121 blaster.cc:112] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:08:04.055174 121 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur: 1AF9293A-F42D-4318-BCDF-60234B240955
|
||||
I20170322 07:08:18.046756 123 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:08:28.004198 123 loader.cc:552] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:08:36.032193 61457 blaster.cc:352] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:08:50.028964 61456 loader.cc:13] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:08:56.074576 124 blaster.cc:112] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:08:57.090258 123 loader.cc:13] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:09:00.067690 121 blaster.cc:352] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:09:19.036483 61457 blaster.cc:112] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:09:40.048046 123 blaster.cc:352] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:09:52.051526 123 loader.cc:13] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:10:11.003845 61456 loader.cc:552] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:10:27.094133 123 blaster.cc:6782] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:10:43.027892 121 blaster.cc:352] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:10:57.078489 124 demo.cc:352] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:11:09.014685 123 demo.cc:123] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:11:18.029203 61456 blaster.cc:352] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:11:24.067068 121 demo.cc:123] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:11:38.053891 61456 loader.cc:552] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:11:59.027292 61457 blaster.cc:112] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:12:10.069054 61457 loader.cc:13] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:12:22.018053 123 loader.cc:552] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:12:39.000436 123 demo.cc:352] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:12:53.009916 123 loader.cc:13] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:13:13.051890 121 demo.cc:123] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:13:24.076724 123 demo.cc:123] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:13:34.075980 123 blaster.cc:6782] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:13:35.096130 61456 blaster.cc:6782] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:13:49.087790 121 demo.cc:123] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:14:08.033671 61457 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:14:23.091358 61456 blaster.cc:112] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:14:35.088133 61456 demo.cc:123] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:14:55.005577 123 blaster.cc:352] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:14:58.008392 61457 demo.cc:123] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:15:05.004789 123 loader.cc:552] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:15:07.070013 123 blaster.cc:6782] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:15:08.012805 123 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:15:25.042509 61456 loader.cc:552] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
E20170322 07:15:32.027688 123 blaster.cc:6782] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:15:41.020299 61456 blaster.cc:6782] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:15:42.021039 124 loader.cc:552] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:15:59.063918 123 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
I20170322 07:16:19.082250 123 loader.cc:552] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:16:20.026445 61457 loader.cc:13] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
I20170322 07:16:41.048447 123 blaster.cc:6782] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
I20170322 07:16:52.097215 61456 demo.cc:123] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
I20170322 07:17:01.020663 61456 blaster.cc:112] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
@ -0,0 +1,333 @@
|
||||
/**
|
||||
* Copyright (c) 2022, Timothy Stack
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* * Neither the name of Timothy Stack nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "static_file_vtab.hh"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "base/auto_mem.hh"
|
||||
#include "base/fs_util.hh"
|
||||
#include "base/lnav_log.hh"
|
||||
#include "base/paths.hh"
|
||||
#include "config.h"
|
||||
#include "ghc/filesystem.hpp"
|
||||
#include "lnav.hh"
|
||||
#include "vtab_module.hh"
|
||||
|
||||
const char* const STATIC_FILE_CREATE_STMT = R"(
|
||||
-- Access static files in the lnav configuration directories
|
||||
CREATE TABLE lnav_static_files (
|
||||
name TEXT PRIMARY KEY,
|
||||
filepath TEXT,
|
||||
content BLOB HIDDEN
|
||||
);
|
||||
)";
|
||||
|
||||
struct vtab {
|
||||
sqlite3_vtab base;
|
||||
sqlite3* db;
|
||||
};
|
||||
|
||||
struct static_file_info {
|
||||
ghc::filesystem::path sfi_path;
|
||||
};
|
||||
|
||||
struct vtab_cursor {
|
||||
sqlite3_vtab_cursor base;
|
||||
std::map<std::string, static_file_info>::iterator vc_files_iter;
|
||||
std::map<std::string, static_file_info> vc_files;
|
||||
};
|
||||
|
||||
static int sfvt_destructor(sqlite3_vtab* p_svt);
|
||||
|
||||
static int
|
||||
sfvt_create(sqlite3* db,
|
||||
void* pAux,
|
||||
int argc,
|
||||
const char* const* argv,
|
||||
sqlite3_vtab** pp_vt,
|
||||
char** pzErr)
|
||||
{
|
||||
vtab* p_vt;
|
||||
|
||||
/* Allocate the sqlite3_vtab/vtab structure itself */
|
||||
p_vt = (vtab*) sqlite3_malloc(sizeof(*p_vt));
|
||||
|
||||
if (p_vt == nullptr) {
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
memset(&p_vt->base, 0, sizeof(sqlite3_vtab));
|
||||
p_vt->db = db;
|
||||
|
||||
*pp_vt = &p_vt->base;
|
||||
|
||||
int rc = sqlite3_declare_vtab(db, STATIC_FILE_CREATE_STMT);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_destructor(sqlite3_vtab* p_svt)
|
||||
{
|
||||
vtab* p_vt = (vtab*) p_svt;
|
||||
|
||||
/* Free the SQLite structure */
|
||||
sqlite3_free(p_vt);
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_connect(sqlite3* db,
|
||||
void* p_aux,
|
||||
int argc,
|
||||
const char* const* argv,
|
||||
sqlite3_vtab** pp_vt,
|
||||
char** pzErr)
|
||||
{
|
||||
return sfvt_create(db, p_aux, argc, argv, pp_vt, pzErr);
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_disconnect(sqlite3_vtab* pVtab)
|
||||
{
|
||||
return sfvt_destructor(pVtab);
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_destroy(sqlite3_vtab* p_vt)
|
||||
{
|
||||
return sfvt_destructor(p_vt);
|
||||
}
|
||||
|
||||
static int sfvt_next(sqlite3_vtab_cursor* cur);
|
||||
|
||||
static void
|
||||
find_static_files(vtab_cursor* p_cur, const ghc::filesystem::path& dir)
|
||||
{
|
||||
auto& file_map = p_cur->vc_files;
|
||||
std::error_code ec;
|
||||
|
||||
for (const auto& format_dir_entry :
|
||||
ghc::filesystem::directory_iterator(dir, ec))
|
||||
{
|
||||
if (!format_dir_entry.is_directory()) {
|
||||
continue;
|
||||
}
|
||||
auto format_static_files_dir = format_dir_entry.path() / "static-files";
|
||||
log_debug("format static files: %s", format_static_files_dir.c_str());
|
||||
for (const auto& static_file_entry :
|
||||
ghc::filesystem::recursive_directory_iterator(
|
||||
format_static_files_dir, ec))
|
||||
{
|
||||
auto rel_path = ghc::filesystem::relative(static_file_entry.path(),
|
||||
format_static_files_dir);
|
||||
|
||||
file_map[rel_path.string()] = {static_file_entry.path()};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_open(sqlite3_vtab* p_svt, sqlite3_vtab_cursor** pp_cursor)
|
||||
{
|
||||
vtab* p_vt = (vtab*) p_svt;
|
||||
|
||||
p_vt->base.zErrMsg = NULL;
|
||||
|
||||
vtab_cursor* p_cur = (vtab_cursor*) new vtab_cursor();
|
||||
|
||||
if (p_cur == nullptr) {
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
*pp_cursor = (sqlite3_vtab_cursor*) p_cur;
|
||||
|
||||
p_cur->base.pVtab = p_svt;
|
||||
|
||||
for (const auto& config_path : lnav_data.ld_config_paths) {
|
||||
auto formats_root = config_path / "formats";
|
||||
log_debug("format root: %s", formats_root.c_str());
|
||||
find_static_files(p_cur, formats_root);
|
||||
auto configs_root = config_path / "configs";
|
||||
log_debug("configs root: %s", configs_root.c_str());
|
||||
find_static_files(p_cur, configs_root);
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_close(sqlite3_vtab_cursor* cur)
|
||||
{
|
||||
vtab_cursor* p_cur = (vtab_cursor*) cur;
|
||||
|
||||
p_cur->vc_files_iter = p_cur->vc_files.end();
|
||||
/* Free cursor struct. */
|
||||
delete p_cur;
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_eof(sqlite3_vtab_cursor* cur)
|
||||
{
|
||||
vtab_cursor* vc = (vtab_cursor*) cur;
|
||||
|
||||
return vc->vc_files_iter == vc->vc_files.end();
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_next(sqlite3_vtab_cursor* cur)
|
||||
{
|
||||
vtab_cursor* vc = (vtab_cursor*) cur;
|
||||
|
||||
if (vc->vc_files_iter != vc->vc_files.end()) {
|
||||
++vc->vc_files_iter;
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_column(sqlite3_vtab_cursor* cur, sqlite3_context* ctx, int col)
|
||||
{
|
||||
vtab_cursor* vc = (vtab_cursor*) cur;
|
||||
|
||||
switch (col) {
|
||||
case 0:
|
||||
to_sqlite(ctx, vc->vc_files_iter->first);
|
||||
break;
|
||||
case 1: {
|
||||
sqlite3_result_text(ctx,
|
||||
vc->vc_files_iter->second.sfi_path.c_str(),
|
||||
-1,
|
||||
SQLITE_TRANSIENT);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
auto read_res = lnav::filesystem::read_file(
|
||||
vc->vc_files_iter->second.sfi_path);
|
||||
if (read_res.isErr()) {
|
||||
auto um = lnav::console::user_message::error(
|
||||
"unable to read static file")
|
||||
.with_reason(read_res.unwrapErr());
|
||||
|
||||
to_sqlite(ctx, um);
|
||||
} else {
|
||||
auto str = read_res.unwrap();
|
||||
|
||||
sqlite3_result_blob(
|
||||
ctx, str.c_str(), str.size(), SQLITE_TRANSIENT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_rowid(sqlite3_vtab_cursor* cur, sqlite_int64* p_rowid)
|
||||
{
|
||||
vtab_cursor* p_cur = (vtab_cursor*) cur;
|
||||
|
||||
*p_rowid = std::distance(p_cur->vc_files.begin(), p_cur->vc_files_iter);
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_best_index(sqlite3_vtab* tab, sqlite3_index_info* p_info)
|
||||
{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sfvt_filter(sqlite3_vtab_cursor* cur,
|
||||
int idxNum,
|
||||
const char* idxStr,
|
||||
int argc,
|
||||
sqlite3_value** argv)
|
||||
{
|
||||
vtab_cursor* p_cur = (vtab_cursor*) cur;
|
||||
|
||||
p_cur->vc_files_iter = p_cur->vc_files.begin();
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static sqlite3_module static_file_vtab_module = {
|
||||
0, /* iVersion */
|
||||
sfvt_create, /* xCreate - create a vtable */
|
||||
sfvt_connect, /* xConnect - associate a vtable with a connection */
|
||||
sfvt_best_index, /* xBestIndex - best index */
|
||||
sfvt_disconnect, /* xDisconnect - disassociate a vtable with a connection
|
||||
*/
|
||||
sfvt_destroy, /* xDestroy - destroy a vtable */
|
||||
sfvt_open, /* xOpen - open a cursor */
|
||||
sfvt_close, /* xClose - close a cursor */
|
||||
sfvt_filter, /* xFilter - configure scan constraints */
|
||||
sfvt_next, /* xNext - advance a cursor */
|
||||
sfvt_eof, /* xEof - inidicate end of result set*/
|
||||
sfvt_column, /* xColumn - read data */
|
||||
sfvt_rowid, /* xRowid - read data */
|
||||
nullptr, /* xUpdate - write data */
|
||||
nullptr, /* xBegin - begin transaction */
|
||||
nullptr, /* xSync - sync transaction */
|
||||
nullptr, /* xCommit - commit transaction */
|
||||
nullptr, /* xRollback - rollback transaction */
|
||||
nullptr, /* xFindFunction - function overloading */
|
||||
};
|
||||
|
||||
int
|
||||
register_static_file_vtab(sqlite3* db)
|
||||
{
|
||||
auto_mem<char, sqlite3_free> errmsg;
|
||||
int rc;
|
||||
rc = sqlite3_create_module(
|
||||
db, "lnav_static_file_vtab_impl", &static_file_vtab_module, nullptr);
|
||||
ensure(rc == SQLITE_OK);
|
||||
if ((rc = sqlite3_exec(db,
|
||||
"CREATE VIRTUAL TABLE lnav_static_files USING "
|
||||
"lnav_static_file_vtab_impl()",
|
||||
nullptr,
|
||||
nullptr,
|
||||
errmsg.out()))
|
||||
!= SQLITE_OK)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"unable to create lnav_static_file table %s\n",
|
||||
errmsg.in());
|
||||
}
|
||||
return rc;
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2022, Timothy Stack
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* * Neither the name of Timothy Stack nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef static_file_vtab_hh
|
||||
#define static_file_vtab_hh
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
int register_static_file_vtab(sqlite3* db);
|
||||
|
||||
extern const char* const STATIC_FILE_CREATE_STMT;
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Copyright (c) 2022, Timothy Stack
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* * Neither the name of Timothy Stack nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @file yaml-extension-functions.cc
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#define RYML_SINGLE_HDR_DEFINE_NOW
|
||||
|
||||
#include "ryml_all.hpp"
|
||||
#include "sqlite-extension-func.hh"
|
||||
#include "vtab_module.hh"
|
||||
#include "yajlpp/yajlpp.hh"
|
||||
|
||||
using namespace lnav::roles::literals;
|
||||
|
||||
static void
|
||||
ryml_error_to_um(const char* msg, size_t len, ryml::Location loc, void* ud)
|
||||
{
|
||||
intern_string_t src = intern_string::lookup(
|
||||
string_fragment::from_bytes(loc.name.data(), loc.name.size()));
|
||||
auto& sf = *(static_cast<string_fragment*>(ud));
|
||||
auto msg_str = string_fragment::from_bytes(msg, len).trim().to_string();
|
||||
|
||||
if (loc.offset == sf.length()) {
|
||||
loc.line -= 1;
|
||||
}
|
||||
throw lnav::console::user_message::error("failed to parse YAML content")
|
||||
.with_reason(msg_str)
|
||||
.with_snippet(lnav::console::snippet::from(
|
||||
source_location{src, (int32_t) loc.line}, ""));
|
||||
}
|
||||
|
||||
static text_auto_buffer
|
||||
yaml_to_json(string_fragment in)
|
||||
{
|
||||
ryml::Callbacks callbacks(&in, nullptr, nullptr, ryml_error_to_um);
|
||||
|
||||
ryml::set_callbacks(callbacks);
|
||||
auto tree = ryml::parse_in_arena(
|
||||
"input", ryml::csubstr{in.data(), (size_t) in.length()});
|
||||
|
||||
auto output = ryml::emit_json(
|
||||
tree, tree.root_id(), ryml::substr{}, /*error_on_excess*/ false);
|
||||
auto buf = auto_buffer::alloc(output.len);
|
||||
buf.resize(output.len);
|
||||
output = ryml::emit_json(tree,
|
||||
tree.root_id(),
|
||||
ryml::substr(buf.in(), buf.size()),
|
||||
/*error_on_excess*/ true);
|
||||
|
||||
return {std::move(buf)};
|
||||
}
|
||||
|
||||
int
|
||||
yaml_extension_functions(struct FuncDef** basic_funcs,
|
||||
struct FuncDefAgg** agg_funcs)
|
||||
{
|
||||
static struct FuncDef yaml_funcs[] = {
|
||||
sqlite_func_adapter<decltype(&yaml_to_json), yaml_to_json>::builder(
|
||||
help_text("yaml_to_json",
|
||||
"Convert a YAML document to a JSON-encoded string")
|
||||
.sql_function()
|
||||
.with_parameter({"yaml", "The YAML value to convert to JSON."})
|
||||
.with_tags({"json", "yaml"})
|
||||
.with_example({
|
||||
"To convert the document \"abc: def\"",
|
||||
"SELECT yaml_to_json('abc: def')",
|
||||
})),
|
||||
|
||||
{nullptr},
|
||||
};
|
||||
|
||||
*basic_funcs = yaml_funcs;
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
you might find this tool more comfortable to work with.
|
||||
|
||||
▌[1] - https://github.com/rcoh/angle-grinder
|
||||
|
@ -0,0 +1,5 @@
|
||||
#! /bin/bash
|
||||
|
||||
export YES_COLOR=1
|
||||
|
||||
run_cap_test ${lnav_test} -n -c ";SELECT yaml_to_json('[abc')"
|
Loading…
Reference in New Issue