Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
apk-tools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
60
Issues
60
List
Boards
Labels
Service Desk
Milestones
Merge Requests
15
Merge Requests
15
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpine
apk-tools
Commits
d7374642
Commit
d7374642
authored
Sep 14, 2011
by
Natanael Copa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lua: initial db_open
so far we just parse the db options
parent
cca6a7e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
1 deletion
+75
-1
src/lua-apk.c
src/lua-apk.c
+75
-1
No files found.
src/lua-apk.c
View file @
d7374642
...
...
@@ -2,12 +2,34 @@
#include <lualib.h>
#include <lauxlib.h>
#include "apk_blob.h"
#include "apk_database.h"
#include "apk_defines.h"
#include "apk_version.h"
#include "apk_blob.h"
#define LIBNAME "apk"
struct
flagmap
{
const
char
*
name
;
int
flag
;
};
struct
flagmap
opendb_flagmap
[]
=
{
{
"read"
,
APK_OPENF_READ
},
{
"write"
,
APK_OPENF_WRITE
},
{
"create"
,
APK_OPENF_CREATE
},
{
"no_installed"
,
APK_OPENF_NO_INSTALLED
},
{
"no_scripts"
,
APK_OPENF_NO_SCRIPTS
},
{
"no_world"
,
APK_OPENF_NO_WORLD
},
{
"no_sys_repos"
,
APK_OPENF_NO_SYS_REPOS
},
{
"no_installed_repo"
,
APK_OPENF_NO_INSTALLED_REPO
},
{
"no_repos"
,
APK_OPENF_NO_REPOS
},
{
"no_state"
,
APK_OPENF_NO_STATE
},
{
"no_scripts"
,
APK_OPENF_NO_SCRIPTS
},
{
"no_world"
,
APK_OPENF_NO_WORLD
},
{
NULL
,
0
}
};
static
apk_blob_t
check_blob
(
lua_State
*
L
,
int
index
)
{
apk_blob_t
blob
;
...
...
@@ -48,11 +70,63 @@ static int Pversion_is_less(lua_State *L)
return
1
;
}
//static getfield(lua_State *L, const char *key)
//{
static
const
char
*
get_opt_string_field
(
lua_State
*
L
,
int
index
,
const
char
*
key
,
const
char
*
def
)
{
const
char
*
value
;
lua_getfield
(
L
,
index
,
key
);
value
=
luaL_optstring
(
L
,
-
1
,
def
);
lua_pop
(
L
,
1
);
return
value
;
}
static
int
get_opt_int_field
(
lua_State
*
L
,
int
index
,
const
char
*
key
,
int
def
)
{
int
value
;
lua_getfield
(
L
,
index
,
key
);
value
=
luaL_optinteger
(
L
,
-
1
,
def
);
lua_pop
(
L
,
1
);
return
value
;
}
static
int
get_boolean_field
(
lua_State
*
L
,
int
index
,
const
char
*
key
)
{
int
value
;
lua_getfield
(
L
,
index
,
key
);
value
=
lua_toboolean
(
L
,
-
1
);
lua_pop
(
L
,
1
);
return
value
;
}
static
int
get_dbopts
(
lua_State
*
L
,
int
i
,
struct
apk_db_options
*
o
)
{
struct
flagmap
*
f
;
o
->
root
=
(
char
*
)
get_opt_string_field
(
L
,
i
,
"root"
,
NULL
);
o
->
repositories_file
=
(
char
*
)
get_opt_string_field
(
L
,
i
,
"repositories_file"
,
NULL
);
o
->
keys_dir
=
(
char
*
)
get_opt_string_field
(
L
,
i
,
"keys_dir"
,
NULL
);
o
->
lock_wait
=
get_opt_int_field
(
L
,
i
,
"lock_wait"
,
0
);
for
(
f
=
opendb_flagmap
;
f
->
name
!=
NULL
;
f
++
)
if
(
get_boolean_field
(
L
,
i
,
f
->
name
))
o
->
open_flags
|=
f
->
flag
;
return
0
;
}
static
int
Papk_db_open
(
lua_State
*
L
)
{
struct
apk_db_options
opts
;
memset
(
&
opts
,
0
,
sizeof
(
opts
));
if
(
lua_istable
(
L
,
1
))
get_dbopts
(
L
,
1
,
&
opts
);
return
0
;
}
static
const
luaL_reg
R
[]
=
{
{
"version_validate"
,
Pversion_validate
},
{
"version_compare"
,
Pversion_compare
},
{
"version_is_less"
,
Pversion_is_less
},
{
"db_open"
,
Papk_db_open
},
{
NULL
,
NULL
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment