Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
6
66
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eric Vidal
66
Commits
20c30065
Commit
20c30065
authored
5 years ago
by
Eric Vidal
Browse files
Options
Downloads
Patches
Plain Diff
use parser from oblibs
parent
4bb9e0aa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/include/66/parser.h
+20
-67
20 additions, 67 deletions
src/include/66/parser.h
src/lib66/parser.c
+4
-131
4 additions, 131 deletions
src/lib66/parser.c
src/lib66/parser_utils.c
+372
-614
372 additions, 614 deletions
src/lib66/parser_utils.c
with
396 additions
and
812 deletions
src/include/66/parser.h
+
20
−
67
View file @
20c30065
...
...
@@ -12,8 +12,8 @@
* except according to the terms contained in the LICENSE file./
*/
#ifndef PARSER_H
#define PARSER_H
#ifndef
SS_
PARSER_H
#define
SS_
PARSER_H
#include
<66/enum.h>
...
...
@@ -22,6 +22,8 @@
#include
<oblibs/oblist.h>
#include
<oblibs/stralist.h>
#include
<oblibs/mill.h>
#include
<skalibs/stralloc.h>
#include
<skalibs/genalloc.h>
...
...
@@ -244,90 +246,41 @@ struct section_s
.idx = { 0 } , \
.file = 0 }
typedef
struct
parse_mill_inner_s
parse_mill_inner_t
,
*
parse_mill_inner_t_ref
;
struct
parse_mill_inner_s
{
char
curr
;
uint32_t
nline
;
uint8_t
nopen
;
//number of open found
uint8_t
nclose
;
//number of close found
uint8_t
jumped
;
//jump was made or not 1->no,0->yes
uint8_t
flushed
;
//flush was made or not 1->no,0->yes
}
;
#define PARSE_MILL_INNER_ZERO { .curr = 0, \
.nline = 1, \
.nopen = 0, \
.nclose = 0, \
.jumped = 0, \
.flushed = 0 }
typedef
struct
parse_mill_s
parse_mill_t
,
*
parse_mill_t_ref
;
struct
parse_mill_s
{
char
const
open
;
char
const
close
;
uint8_t
force
;
//1 -> only one open and close
char
const
*
skip
;
size_t
skiplen
;
char
const
*
end
;
size_t
endlen
;
char
const
*
jump
;
//skip the complete line
size_t
jumplen
;
uint8_t
check
;
//check if nopen == openclose, 0 -> no,1->yes
uint8_t
flush
;
//set nopen,nclose,sa.len to 0 at every new line
uint8_t
forceskip
;
//force to skip even if nopen is positive
parse_mill_inner_t
inner
;
}
;
typedef
enum
parse_enum_e
parse_enum_t
,
*
parse_enum_t_ref
;
enum
parse_enum_e
{
IGN
=
0
,
KEEP
,
JUMP
,
EXIT
,
END
}
;
/** Main */
extern
int
parser
(
sv_alltype
*
service
,
stralloc
*
src
,
char
const
*
file
)
;
extern
int
parse_config
(
parse_mill_t
*
p
,
char
const
*
file
,
stralloc
*
src
,
stralloc
*
kp
,
size_t
*
pos
)
;
extern
char
next
(
stralloc
*
s
,
size_t
*
pos
)
;
extern
uint8_t
cclass
(
parse_mill_t
*
p
)
;
/** freed */
extern
void
sv_alltype_free
(
sv_alltype
*
sv
)
;
extern
void
keynocheck_free
(
keynocheck
*
nocheck
)
;
extern
void
section_free
(
section_t
*
sec
)
;
extern
void
freed_parser
(
void
)
;
/** enable phase */
extern
int
parser
(
sv_alltype
*
service
,
stralloc
*
src
,
char
const
*
file
)
;
extern
int
parse_service_get_list
(
stralloc
*
result
,
stralloc
*
list
)
;
extern
int
parse_service_before
(
ssexec_t
*
info
,
stralloc
*
parsed_list
,
char
const
*
sv
,
unsigned
int
*
nbsv
,
stralloc
*
sasv
,
unsigned
int
force
,
unsigned
int
exist
)
;
extern
int
parse_service_deps
(
ssexec_t
*
info
,
stralloc
*
parsed_list
,
sv_alltype
*
sv_before
,
char
const
*
sv
,
unsigned
int
*
nbsv
,
stralloc
*
sasv
,
unsigned
int
force
)
;
extern
int
parse_add_service
(
stralloc
*
parsed_list
,
sv_alltype
*
sv_before
,
char
const
*
service
,
unsigned
int
*
nbsv
,
uid_t
owner
)
;
/** utilities */
/** mill utilities
extern parse_mill_t MILL_FIRST_BRACKET ;
extern parse_mill_t MILL_GET_AROBASE_KEY ;
extern parse_mill_t MILL_GET_COMMENTED_KEY ;
extern parse_mill_t MILL_GET_SECTION_NAME ; */
/** utilities
extern int parse_line(stralloc *src,size_t *pos) ;
extern
int
parse_quote
(
stralloc
*
src
,
size_t
*
pos
)
;
extern
int
parse_bracket
(
stralloc
*
src
,
size_t
*
pos
)
;
extern
int
parse_env
(
stralloc
*
src
,
size_t
*
pos
)
;
extern int parse_bracket(stralloc *src,size_t *pos) ; */
/** split */
extern
int
get_
section_range
(
section_t
*
sasection
,
stralloc
*
src
)
;
extern
int
get_key
_range
(
genalloc
*
ga
,
section_t
*
sasection
,
char
const
*
file
,
int
*
svtype
)
;
extern
int
section_
get_
range
(
section_t
*
sasection
,
stralloc
*
src
)
;
extern
int
key_get
_range
(
genalloc
*
ga
,
section_t
*
sasection
,
int
*
svtype
)
;
extern
int
get_mandatory
(
genalloc
*
nocheck
,
int
idsec
,
int
idkey
)
;
extern
int
nocheck_toservice
(
keynocheck
*
nocheck
,
int
svtype
,
sv_alltype
*
service
)
;
/** store */
extern
int
keep_common
(
sv_alltype
*
service
,
keynocheck
*
nocheck
,
int
svtype
)
;
extern
int
keep_runfinish
(
sv_exec
*
exec
,
keynocheck
*
nocheck
)
;
extern
int
keep_logger
(
sv_execlog
*
log
,
keynocheck
*
nocheck
)
;
/** helper */
extern
int
read_svfile
(
stralloc
*
sasv
,
char
const
*
name
,
char
const
*
src
)
;
extern
ssize_t
get_sep_before
(
char
const
*
line
,
char
const
sepstart
,
char
const
sepend
)
;
/** helper
extern void section_setsa(int id, stralloc_ref *p,section_t *sa) ;
extern
int
section_skip
(
char
const
*
s
,
size_t
pos
,
int
nline
)
;
extern
int
section_valid
(
int
id
,
uint32_t
nline
,
size_t
pos
,
stralloc
*
src
,
char
const
*
file
)
;
extern
int
clean_value
(
stralloc
*
sa
)
;
extern
void
parse_err
(
int
ierr
,
int
idsec
,
int
idkey
)
;
extern int section_get_skip(char const *s,size_t pos,int nline) ;
extern int section_get_id(stralloc *secname, char const *string,size_t *pos,int *id) ;
extern int key_get_next_id(stralloc *sa, char const *string,size_t *pos) ;
extern void parse_err(int ierr,int idsec,int idkey) ; */
extern
int
read_svfile
(
stralloc
*
sasv
,
char
const
*
name
,
char
const
*
src
)
;
extern
int
add_pipe
(
sv_alltype
*
sv
,
stralloc
*
sa
)
;
/** write */
extern
int
write_services
(
ssexec_t
*
info
,
sv_alltype
*
sv
,
char
const
*
workdir
,
unsigned
int
force
,
unsigned
int
conf
)
;
...
...
This diff is collapsed.
Click to expand it.
src/lib66/parser.c
+
4
−
131
View file @
20c30065
...
...
@@ -13,6 +13,7 @@
*/
#include
<string.h>
#include
<stdint.h>
//#include <stdio.h>
#include
<oblibs/error2.h>
...
...
@@ -20,6 +21,7 @@
#include
<oblibs/files.h>
#include
<oblibs/stralist.h>
#include
<oblibs/obgetopt.h>
#include
<oblibs/mill.h>
#include
<skalibs/buffer.h>
#include
<skalibs/stralloc.h>
...
...
@@ -31,135 +33,6 @@
#include
<66/utils.h>
#include
<66/parser.h>
inline
uint8_t
cclass
(
parse_mill_t
*
p
)
{
size_t
i
=
0
;
if
(
!
p
->
inner
.
curr
)
return
0
;
else
if
(
p
->
inner
.
curr
==
'\n'
)
{
if
(
p
->
flush
)
p
->
inner
.
flushed
=
1
;
p
->
inner
.
jumped
=
0
;
p
->
inner
.
nline
++
;
}
for
(;
i
<
p
->
jumplen
;
i
++
)
{
if
(
p
->
inner
.
curr
==
p
->
jump
[
i
])
{
p
->
inner
.
jumped
=
1
;
return
2
;
}
}
for
(
i
=
0
;
i
<
p
->
endlen
;
i
++
)
{
if
(
p
->
inner
.
curr
==
p
->
end
[
i
])
{
if
(
p
->
inner
.
curr
==
p
->
close
)
p
->
inner
.
nclose
++
;
return
3
;
}
}
for
(
i
=
0
;
i
<
p
->
skiplen
;
i
++
)
{
if
(
p
->
inner
.
curr
==
p
->
skip
[
i
])
{
if
(
p
->
open
&&
!
p
->
forceskip
)
return
1
;
return
0
;
}
}
/* close and open can be the same, in this case
* we skip open if it already found */
if
(
p
->
inner
.
curr
==
p
->
open
&&
!
p
->
inner
.
nopen
)
{
p
->
inner
.
nopen
++
;
return
0
;
}
if
(
p
->
inner
.
curr
==
p
->
close
)
{
p
->
inner
.
nclose
++
;
if
(
p
->
force
)
return
3
;
return
0
;
}
return
1
;
}
inline
char
next
(
stralloc
*
s
,
size_t
*
pos
)
{
char
c
;
if
(
*
pos
>=
s
->
len
)
return
-
1
;
c
=
s
->
s
[
*
pos
]
;
(
*
pos
)
+=
1
;
return
c
;
}
/** @Return 1 on sucess
* @Return 0 on fail
* @Return 2 for end of file
* @Return -1 if close was not found */
inline
int
parse_config
(
parse_mill_t
*
p
,
char
const
*
file
,
stralloc
*
src
,
stralloc
*
kp
,
size_t
*
pos
)
{
uint8_t
what
=
0
;
static
uint8_t
const
table
[
5
]
=
{
IGN
,
KEEP
,
JUMP
,
EXIT
,
END
}
;
uint8_t
state
=
1
,
end
=
0
;
char
j
=
0
;
while
(
state
)
{
p
->
inner
.
curr
=
next
(
src
,
pos
)
;
what
=
table
[
cclass
(
p
)]
;
// end of file
if
(
p
->
inner
.
curr
==
-
1
)
what
=
END
;
if
(
p
->
inner
.
flushed
)
{
kp
->
len
=
0
;
p
->
inner
.
nopen
=
0
;
p
->
inner
.
nclose
=
0
;
p
->
inner
.
flushed
=
0
;
what
=
SKIP
;
}
switch
(
what
)
{
case
KEEP
:
if
(
p
->
inner
.
nopen
&&
!
p
->
inner
.
jumped
)
if
(
!
stralloc_catb
(
kp
,
&
p
->
inner
.
curr
,
1
))
return
0
;
break
;
case
JUMP
:
if
(
!
p
->
inner
.
nopen
)
{
while
(
j
!=
'\n'
)
{
j
=
next
(
src
,
pos
)
;
if
(
j
<
0
)
break
;
//end of string
}
p
->
inner
.
jumped
=
0
;
p
->
inner
.
nline
++
;
}
break
;
case
IGN
:
break
;
case
EXIT
:
state
=
0
;
break
;
case
END
:
state
=
0
;
end
=
1
;
break
;
default:
break
;
}
}
if
(
p
->
check
&&
p
->
inner
.
nopen
!=
p
->
inner
.
nclose
)
{
char
fmt
[
UINT_FMT
]
;
fmt
[
uint_fmt
(
fmt
,
p
->
inner
.
nline
-
1
)]
=
0
;
char
sepopen
[
2
]
=
{
p
->
open
,
0
}
;
char
sepclose
[
2
]
=
{
p
->
close
,
0
}
;
strerr_warnw6x
(
"umatched "
,(
p
->
inner
.
nopen
>
p
->
inner
.
nclose
)
?
sepopen
:
sepclose
,
" in: "
,
file
,
" at line: "
,
fmt
)
;
return
0
;
}
if
(
!
p
->
inner
.
nclose
)
return
-
1
;
if
(
end
)
return
2
;
return
1
;
}
int
parser
(
sv_alltype
*
service
,
stralloc
*
src
,
char
const
*
file
)
{
...
...
@@ -169,7 +42,7 @@ int parser(sv_alltype *service,stralloc *src,char const *file)
genalloc
ganocheck
=
GENALLOC_ZERO
;
sasection
.
file
=
file
;
r
=
get_
section_range
(
&
sasection
,
src
)
;
r
=
section_
get_
range
(
&
sasection
,
src
)
;
if
(
r
<=
0
){
strerr_warnwu2x
(
"parse section of service file: "
,
file
)
;
goto
err
;
...
...
@@ -179,7 +52,7 @@ int parser(sv_alltype *service,stralloc *src,char const *file)
VERBO1
strerr_warnw2x
(
"missing section [main] in service file: "
,
file
)
;
goto
err
;
}
if
(
!
get_key
_range
(
&
ganocheck
,
&
sasection
,
file
,
&
svtype
))
goto
err
;
if
(
!
key_get
_range
(
&
ganocheck
,
&
sasection
,
&
svtype
))
goto
err
;
if
(
svtype
<
0
)
{
VERBO1
strerr_warnw2x
(
"invalid value for key: @type in service file: "
,
file
)
;
...
...
This diff is collapsed.
Click to expand it.
src/lib66/parser_utils.c
+
372
−
614
View file @
20c30065
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment