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
e3211286
Commit
e3211286
authored
5 years ago
by
Eric Vidal
Browse files
Options
Downloads
Patches
Plain Diff
rewrite instance function, mark insta_? as deprecated
parent
e0bd46c4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/include/66/utils.h
+9
-5
9 additions, 5 deletions
src/include/66/utils.h
src/lib66/instance.c
+93
-0
93 additions, 0 deletions
src/lib66/instance.c
with
102 additions
and
5 deletions
src/include/66/utils.h
+
9
−
5
View file @
e3211286
...
...
@@ -20,6 +20,7 @@
#include
<skalibs/stralloc.h>
#include
<skalibs/genalloc.h>
#include
<skalibs/gccattributes.h>
#include
<66/ssexec.h>
#include
<66/resolve.h>
...
...
@@ -47,10 +48,13 @@ extern int set_livedir(stralloc *live) ;
extern
int
set_livescan
(
stralloc
*
live
,
uid_t
owner
)
;
extern
int
set_livetree
(
stralloc
*
live
,
uid_t
owner
)
;
extern
int
set_livestate
(
stralloc
*
live
,
uid_t
owner
)
;
extern
int
insta_check
(
char
const
*
svname
)
;
extern
int
insta_create
(
stralloc
*
sasv
,
stralloc
*
sv
,
char
const
*
src
,
int
len
)
;
extern
int
insta_splitname
(
stralloc
*
sa
,
char
const
*
name
,
int
len
,
int
what
)
;
extern
int
insta_replace
(
stralloc
*
sa
,
char
const
*
src
,
char
const
*
cpy
)
;
extern
int
insta_check
(
char
const
*
svname
)
gccattr_deprecated
;
extern
int
insta_create
(
stralloc
*
sasv
,
stralloc
*
sv
,
char
const
*
src
,
int
len
)
gccattr_deprecated
;
extern
int
insta_splitname
(
stralloc
*
sa
,
char
const
*
name
,
int
len
,
int
what
)
gccattr_deprecated
;
extern
int
insta_replace
(
stralloc
*
sa
,
char
const
*
src
,
char
const
*
cpy
)
gccattr_deprecated
;
extern
int
read_svfile
(
stralloc
*
sasv
,
char
const
*
name
,
char
const
*
src
)
;
extern
int
instance_check
(
char
const
*
svname
)
;
extern
int
instance_splitname
(
stralloc
*
sa
,
char
const
*
name
,
int
len
,
int
what
)
;
//extern int instance_change_name(stralloc *sa,char const *template,char const *copy) ;
extern
int
instance_create
(
stralloc
*
sasv
,
char
const
*
svname
,
char
const
*
regex
,
char
const
*
src
,
int
len
)
;
#endif
This diff is collapsed.
Click to expand it.
src/lib66/instance.c
+
93
−
0
View file @
e3211286
...
...
@@ -21,10 +21,103 @@
#include
<oblibs/string.h>
#include
<oblibs/stralist.h>
#include
<oblibs/directory.h>
#include
<oblibs/environ.h>
#include
<oblibs/sastr.h>
#include
<skalibs/stralloc.h>
#include
<skalibs/djbunix.h>
#include
<66/enum.h>
/** New functions */
int
instance_check
(
char
const
*
svname
)
{
int
r
;
size_t
len
=
strlen
(
svname
)
;
r
=
get_len_until
(
svname
,
'@'
)
;
// len == r avoid empty value after the instance template name
if
(
strlen
(
svname
+
r
)
<=
1
&&
r
>
0
)
return
0
;
return
r
;
}
int
instance_splitname
(
stralloc
*
sa
,
char
const
*
name
,
int
len
,
int
what
)
{
char
const
*
copy
;
size_t
tlen
=
len
+
1
;
char
template
[
tlen
+
1
]
;
memcpy
(
template
,
name
,
tlen
)
;
template
[
tlen
]
=
0
;
copy
=
name
+
tlen
;
if
(
!
what
)
return
stralloc_obreplace
(
sa
,
template
)
;
else
return
stralloc_obreplace
(
sa
,
copy
)
;
}
/*
int instance_change_name(stralloc *sa,char const *template,char const *copy)
{
stralloc tmp = STRALLOC_ZERO ;
stralloc iname = STRALLOC_ZERO ;
if (!stralloc_cats(&iname,template) ||
!stralloc_cats(&iname,copy) ||
!stralloc_0(&iname) ||
!stralloc_copy(&tmp,sa) ||
!environ_get_val_of_key(&tmp,get_keybyid(NAME)) ||
!sastr_replace(sa,tmp.s,iname.s)) goto err ;
stralloc_free(&tmp) ;
stralloc_free(&iname) ;
return 1 ;
err:
stralloc_free(&tmp) ;
stralloc_free(&iname) ;
return 0 ;
}
*/
int
instance_create
(
stralloc
*
sasv
,
char
const
*
svname
,
char
const
*
regex
,
char
const
*
src
,
int
len
)
{
char
const
*
copy
;
size_t
tlen
=
len
+
1
;
stralloc
tmp
=
STRALLOC_ZERO
;
char
template
[
tlen
+
1
]
;
memcpy
(
template
,
svname
,
tlen
)
;
template
[
tlen
]
=
0
;
copy
=
svname
+
tlen
;
if
(
!
file_readputsa
(
&
tmp
,
src
,
template
))
{
VERBO3
strerr_warnwu3sys
(
"open: "
,
src
,
template
)
;
goto
err
;
}
/* if (!instance_change_name(&tmp,template,copy)) {
VERBO3 strerr_warnwu3x("replace instance name at: ",src,template) ;
goto err ;
}*/
if
(
!
sastr_replace_all
(
&
tmp
,
regex
,
copy
)){
VERBO3
strerr_warnwu3x
(
"replace instance character at: "
,
src
,
template
)
;
goto
err
;
}
if
(
!
stralloc_copy
(
sasv
,
&
tmp
))
goto
err
;
stralloc_free
(
&
tmp
)
;
return
1
;
err:
stralloc_free
(
&
tmp
)
;
return
0
;
}
/*********************
* Deprecated function
* *******************/
int
insta_replace
(
stralloc
*
sa
,
char
const
*
src
,
char
const
*
cpy
)
{
...
...
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