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
4f30353b
Commit
4f30353b
authored
5 years ago
by
Eric Vidal
Browse files
Options
Downloads
Patches
Plain Diff
fix instance name behavior, implement module, add -z for color
parent
32f57b0c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/66/66-parser.c
+44
-45
44 additions, 45 deletions
src/66/66-parser.c
with
44 additions
and
45 deletions
src/66/66-parser.c
+
44
−
45
View file @
4f30353b
...
...
@@ -34,7 +34,7 @@
#include
<66/parser.h>
#include
<66/constants.h>
#define USAGE "66-parser [ -h ] [ -v verbosity ] [ -f ] [ -c|C ] service destination"
#define USAGE "66-parser [ -h ] [
-z ] [
-v verbosity ] [ -f ] [ -c|C ] service destination"
static
inline
void
info_help
(
void
)
{
...
...
@@ -42,7 +42,8 @@ static inline void info_help (void)
"66-parser <options> service destination
\n
"
"
\n
"
"options :
\n
"
" -h: print this help
\n
"
" -h: print this help
\n
"
" -z: use color
\n
"
" -v: increase/decrease verbosity
\n
"
" -f: force to overwrite existing destination
\n
"
" -c: merge it environment configuration file from frontend file
\n
"
...
...
@@ -82,15 +83,18 @@ int main(int argc, char const *const *argv,char const *const *envp)
char
const
*
sv
;
char
name
[
4095
+
1
]
;
char
srcdir
[
4095
+
1
]
;
int
type
;
unsigned
int
type
;
uint8_t
force
=
0
,
conf
=
0
;
log_color
=
&
log_color_disable
;
PROG
=
"66-parser"
;
{
subgetopt_t
l
=
SUBGETOPT_ZERO
;
for
(;;)
{
int
opt
=
getopt_args
(
argc
,
argv
,
">hv:fcC"
,
&
l
)
;
int
opt
=
getopt_args
(
argc
,
argv
,
">hv:fcC
z
"
,
&
l
)
;
if
(
opt
==
-
1
)
break
;
if
(
opt
==
-
2
)
log_die
(
LOG_EXIT_USER
,
"options must be set first"
)
;
switch
(
opt
)
...
...
@@ -100,6 +104,7 @@ int main(int argc, char const *const *argv,char const *const *envp)
case
'f'
:
force
=
1
;
break
;
case
'c'
:
if
(
conf
)
log_usage
(
USAGE
)
;
conf
=
1
;
break
;
case
'C'
:
if
(
conf
)
log_usage
(
USAGE
)
;
conf
=
2
;
break
;
case
'z'
:
log_color
=
!
isatty
(
1
)
?
&
log_color_disable
:
&
log_color_enable
;
break
;
default
:
log_usage
(
USAGE
)
;
}
}
...
...
@@ -110,11 +115,15 @@ int main(int argc, char const *const *argv,char const *const *envp)
sv
=
argv
[
0
]
;
dir
=
argv
[
1
]
;
if
(
dir
[
0
]
!=
'/'
)
log_die
(
LOG_EXIT_USER
,
"directory: "
,
dir
,
" must be an absolute path"
)
;
if
(
sv
[
0
]
!=
'/'
)
log_die
(
LOG_EXIT_USER
,
"service: "
,
sv
,
" must be an absolute path"
)
;
if
(
!
basename
(
name
,
sv
))
log_dieu
(
LOG_EXIT_SYS
,
"set name"
);
if
(
!
ob_basename
(
name
,
sv
))
log_dieu
(
LOG_EXIT_SYS
,
"set name"
);
size_t
svlen
=
strlen
(
sv
)
;
size_t
namelen
=
strlen
(
name
)
;
char
tmp
[
svlen
+
1
+
namelen
+
1
]
;
r
=
scan_mode
(
sv
,
S_IFDIR
)
;
if
(
r
>
0
)
...
...
@@ -125,33 +134,43 @@ int main(int argc, char const *const *argv,char const *const *envp)
tmp
[
svlen
+
1
+
namelen
]
=
0
;
sv
=
tmp
;
}
if
(
!
dirname
(
srcdir
,
sv
))
log_dieu
(
LOG_EXIT_SYS
,
"set directory name"
)
;
if
(
!
ob_dirname
(
srcdir
,
sv
))
log_dieu
(
LOG_EXIT_SYS
,
"set directory name"
)
;
check_dir
(
dir
,
force
,
0
)
;
if
(
!
read_svfile
(
&
src
,
name
,
srcdir
))
log_dieusys
(
LOG_EXIT_SYS
,
"open: "
,
sv
)
;
if
(
!
get_svtype
(
&
service
,
src
.
s
))
log_dieu
(
LOG_EXIT_SYS
,
"enable to get the type of: "
,
sv
)
;
if
(
!
stralloc_cats
(
&
insta
,
name
)
||
!
stralloc_0
(
&
insta
))
log_die_nomem
(
"stralloc"
)
;
if
(
!
auto_stra
(
&
insta
,
name
))
log_die_nomem
(
"stralloc"
)
;
ista
=
instance_check
(
insta
.
s
)
;
if
(
!
ista
)
log_die
(
LOG_EXIT_SYS
,
"invalid instance name: "
,
insta
.
s
)
;
if
(
ista
>
0
)
{
if
(
!
instance_create
(
&
src
,
insta
.
s
,
SS_INSTANCE
,
ista
))
if
(
!
instance_splitname
(
&
insta
,
name
,
ista
,
SS_INSTANCE_TEMPLATE
))
log_dieu
(
LOG_EXIT_SYS
,
"split instance name of: "
,
name
)
;
}
if
(
!
read_svfile
(
&
src
,
insta
.
s
,
srcdir
))
log_dieusys
(
LOG_EXIT_SYS
,
"open: "
,
sv
)
;
if
(
!
get_svtype
(
&
service
,
src
.
s
))
log_dieu
(
LOG_EXIT_SYS
,
"get service type of: "
,
sv
)
;
if
(
ista
>
0
)
{
if
(
!
instance_create
(
&
src
,
name
,
SS_INSTANCE
,
ista
))
log_dieu
(
LOG_EXIT_SYS
,
"create instance service: "
,
name
)
;
memcpy
(
name
,
insta
.
s
,
insta
.
len
)
;
name
[
insta
.
len
]
=
0
;
}
if
(
!
parser
(
&
service
,
&
src
,
sv
,
service
.
cname
.
itype
))
log_dieu
(
LOG_EXIT_SYS
,
"parse service file: "
,
sv
)
;
if
(
!
stralloc_cats
(
&
dst
,
dir
)
||
!
stralloc_cats
(
&
dst
,
"/"
)
||
!
stralloc_cats
(
&
dst
,
name
)
||
!
stralloc_0
(
&
dst
))
log_die_nomem
(
"stralloc"
)
;
if
(
!
auto_stra
(
&
dst
,
dir
,
"/"
,
name
))
log_die_nomem
(
"stralloc"
)
;
check_dir
(
dst
.
s
,
force
,
1
)
;
type
=
service
.
cname
.
itype
;
srcdirlen
=
strlen
(
srcdir
)
;
service
.
src
=
keep
.
len
;
if
(
!
stralloc_catb
(
&
keep
,
srcdir
,
srcdirlen
+
1
))
log_die_nomem
(
"stralloc"
)
;
/**quick fix
* WIP on parser this will change soon*/
...
...
@@ -161,7 +180,7 @@ int main(int argc, char const *const *argv,char const *const *envp)
stralloc
saname
=
STRALLOC_ZERO
;
if
(
!
stralloc_cats
(
&
saname
,
keep
.
s
+
service
.
cname
.
name
))
log_die_nomem
(
"stralloc"
)
;
if
(
!
instance_splitname
(
&
sainsta
,
name
,
ista
,
0
))
log_dieu
(
LOG_EXIT_SYS
,
"split instance name: "
,
name
)
;
if
(
!
instance_splitname
(
&
sainsta
,
name
,
ista
,
SS_INSTANCE_TEMPLATE
))
log_dieu
(
LOG_EXIT_SYS
,
"split instance name: "
,
name
)
;
if
(
sastr_find
(
&
saname
,
sainsta
.
s
)
==
-
1
)
log_die
(
LOG_EXIT_USER
,
"invalid instantiated service name: "
,
keep
.
s
+
service
.
cname
.
name
)
;
...
...
@@ -173,6 +192,7 @@ int main(int argc, char const *const *argv,char const *const *envp)
service
.
cname
.
name
=
keep
.
len
;
if
(
!
stralloc_catb
(
&
keep
,
name
,
namelen
+
1
))
log_die_nomem
(
"stralloc"
)
;
}
/* save and prepare environment file */
if
(
service
.
opts
[
2
])
{
...
...
@@ -189,33 +209,7 @@ int main(int argc, char const *const *argv,char const *const *envp)
if
(
!
stralloc_catb
(
&
keep
,
conf
.
s
,
conf
.
len
+
1
))
log_die_nomem
(
"stralloc"
)
;
stralloc_free
(
&
conf
)
;
}
if
(
ista
>
0
&&
service
.
cname
.
name
>=
0
)
{
stralloc
sainsta
=
STRALLOC_ZERO
;
stralloc
saname
=
STRALLOC_ZERO
;
if
(
!
stralloc_cats
(
&
saname
,
keep
.
s
+
service
.
cname
.
name
))
goto
err
;
if
(
!
instance_splitname
(
&
sainsta
,
name
,
ista
,
0
))
goto
err
;
if
(
sastr_find
(
&
saname
,
sainsta
.
s
)
==
-
1
)
{
log_warn
(
"invalid instantiated service name: "
,
keep
.
s
+
service
.
cname
.
name
)
;
goto
err
;
}
stralloc_free
(
&
sainsta
)
;
stralloc_free
(
&
saname
)
;
goto
swtch
;
err:
stralloc_free
(
&
sainsta
)
;
stralloc_free
(
&
saname
)
;
return
0
;
}
else
{
service
.
cname
.
name
=
keep
.
len
;
if
(
!
stralloc_catb
(
&
keep
,
name
,
namelen
+
1
))
return
0
;
}
swtch:
switch
(
type
)
{
case
TYPE_CLASSIC
:
...
...
@@ -230,17 +224,22 @@ int main(int argc, char const *const *argv,char const *const *envp)
if
(
!
write_oneshot
(
&
service
,
dst
.
s
,
conf
))
log_dieu
(
LOG_EXIT_SYS
,
"write: "
,
name
)
;
break
;
case
TYPE_MODULE
:
case
TYPE_BUNDLE
:
if
(
!
write_bundle
(
&
service
,
dst
.
s
))
log_dieu
(
LOG_EXIT_SYS
,
"write: "
,
name
)
;
break
;
default:
break
;
}
}
log_info
(
"Written successfully: "
,
name
,
" at: "
,
dir
)
;
sv_alltype_free
(
&
service
)
;
stralloc_free
(
&
keep
)
;
stralloc_free
(
&
deps
)
;
stralloc_free
(
&
src
)
;
stralloc_free
(
&
dst
)
;
return
0
;
}
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