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
983ce834
Commit
983ce834
authored
5 years ago
by
Eric Vidal
Browse files
Options
Downloads
Patches
Plain Diff
add environ file and function
parent
f655692c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/include/66/66.h
+2
-1
2 additions, 1 deletion
src/include/66/66.h
src/include/66/environ.h
+26
-0
26 additions, 0 deletions
src/include/66/environ.h
src/lib66/deps-lib/66
+1
-0
1 addition, 0 deletions
src/lib66/deps-lib/66
src/lib66/environ.c
+158
-0
158 additions, 0 deletions
src/lib66/environ.c
with
187 additions
and
1 deletion
src/include/66/66.h
+
2
−
1
View file @
983ce834
...
...
@@ -20,12 +20,13 @@
#include
<66/constants.h>
#include
<66/db.h>
#include
<66/enum.h>
#include
<66/environ.h>
#include
<66/parser.h>
#include
<66/rc.h>
#include
<66/resolve.h>
#include
<66/ssexec.h>
#include
<66/state.h>
#include
<66/svc.h>
#include
<66/rc.h>
#include
<66/tree.h>
#include
<66/utils.h>
...
...
This diff is collapsed.
Click to expand it.
src/include/66/environ.h
0 → 100644
+
26
−
0
View file @
983ce834
/*
* environ.h
*
* Copyright (c) 2018-2019 Eric Vidal <eric@obarun.org>
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
*/
#ifndef ENVIRON_H
#define ENVIRON_H
#include
<skalibs/stralloc.h>
#include
<skalibs/genalloc.h>
extern
int
env_clean
(
stralloc
*
src
)
;
extern
int
env_split_one
(
char
*
line
,
genalloc
*
ga
,
stralloc
*
sa
)
;
extern
int
env_split
(
genalloc
*
gaenv
,
stralloc
*
saenv
,
stralloc
*
src
)
;
extern
int
env_parsenclean
(
stralloc
*
modifs
,
stralloc
*
src
)
;
#endif
This diff is collapsed.
Click to expand it.
src/lib66/deps-lib/66
+
1
−
0
View file @
983ce834
...
...
@@ -8,6 +8,7 @@ db_get_permissions.o
db_ok.o
db_switch_to.o
db_update.o
environ.o
get_enum.o
get_uidgid.o
get_userhome.o
...
...
This diff is collapsed.
Click to expand it.
src/lib66/environ.c
0 → 100644
+
158
−
0
View file @
983ce834
/*
* environ.c
*
* Copyright (c) 2018-2019 Eric Vidal <eric@obarun.org>
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
*/
#include
<stddef.h>
#include
<stdio.h>
#include
<oblibs/string.h>
#include
<oblibs/stralist.h>
#include
<skalibs/stralloc.h>
#include
<skalibs/genalloc.h>
#include
<skalibs/diuint32.h>
#include
<66/parser.h>
/* @Return 1 on success
* @Return 0 on fail
* @Return -1 for empty line */
int
env_clean
(
stralloc
*
src
)
{
int
r
,
e
=
1
;
unsigned
int
i
;
genalloc
gatmp
=
GENALLOC_ZERO
;
//stralist
stralloc
kp
=
STRALLOC_ZERO
;
stralloc
tmp
=
STRALLOC_ZERO
;
size_t
pos
=
0
;
char
const
*
file
=
"env_clean"
;
parse_mill_t
line
=
{
.
open
=
'@'
,
.
close
=
'='
,
\
.
skip
=
"
\t\r
"
,
.
skiplen
=
3
,
\
.
end
=
"
\n
"
,
.
endlen
=
1
,
\
.
jump
=
"#"
,
.
jumplen
=
1
,
\
.
check
=
0
,
.
flush
=
0
,
\
.
forceskip
=
0
,
.
force
=
1
,
\
.
inner
=
PARSE_MILL_INNER_ZERO
}
;
size_t
blen
=
src
->
len
,
n
=
0
;
if
(
!
stralloc_inserts
(
src
,
0
,
"@"
))
goto
err
;
while
(
pos
<
(
blen
+
n
)
&&
n
<
2
)
{
kp
.
len
=
0
;
genalloc_deepfree
(
stralist
,
&
gatmp
,
stra_free
)
;
line
.
inner
.
nopen
=
line
.
inner
.
nclose
=
0
;
r
=
parse_config
(
&
line
,
file
,
src
,
&
kp
,
&
pos
)
;
if
(
!
r
)
goto
err
;
if
(
r
<
0
&&
!
n
){
e
=
-
1
;
goto
freed
;
}
if
(
!
stralloc_0
(
&
kp
))
goto
err
;
if
(
!
clean_val
(
&
gatmp
,
kp
.
s
))
goto
err
;
for
(
i
=
0
;
i
<
genalloc_len
(
stralist
,
&
gatmp
)
;
i
++
)
{
if
((
i
+
1
)
<
genalloc_len
(
stralist
,
&
gatmp
))
{
if
(
!
stralloc_cats
(
&
tmp
,
gaistr
(
&
gatmp
,
i
)))
goto
err
;
if
(
!
stralloc_cats
(
&
tmp
,
" "
))
goto
err
;
}
else
if
(
!
stralloc_cats
(
&
tmp
,
gaistr
(
&
gatmp
,
i
)))
goto
err
;
}
if
(
!
n
)
if
(
!
stralloc_cats
(
&
tmp
,
"="
))
goto
err
;
if
(
!
stralloc_inserts
(
src
,
pos
,
"@"
))
goto
err
;
n
++
;
}
if
(
!
stralloc_0
(
&
tmp
))
goto
err
;
if
(
!
stralloc_copy
(
src
,
&
tmp
))
goto
err
;
freed:
stralloc_free
(
&
kp
)
;
stralloc_free
(
&
tmp
)
;
genalloc_deepfree
(
stralist
,
&
gatmp
,
stra_free
)
;
return
e
;
err:
stralloc_free
(
&
kp
)
;
stralloc_free
(
&
tmp
)
;
genalloc_deepfree
(
stralist
,
&
gatmp
,
stra_free
)
;
return
0
;
}
int
env_split_one
(
char
*
line
,
genalloc
*
ga
,
stralloc
*
sa
)
{
char
*
k
=
0
;
char
*
v
=
0
;
diuint32
tmp
=
DIUINT32_ZERO
;
k
=
line
;
v
=
line
;
obstr_sep
(
&
v
,
"="
)
;
if
(
v
==
NULL
)
return
0
;
tmp
.
left
=
sa
->
len
;
if
(
!
stralloc_catb
(
sa
,
k
,
strlen
(
k
)
+
1
))
return
0
;
if
(
!
obstr_trim
(
v
,
'\n'
))
return
0
;
tmp
.
right
=
sa
->
len
;
if
(
!
stralloc_catb
(
sa
,
v
,
strlen
(
v
)
+
1
))
return
0
;
if
(
!
genalloc_append
(
diuint32
,
ga
,
&
tmp
))
return
0
;
return
1
;
}
int
env_split
(
genalloc
*
gaenv
,
stralloc
*
saenv
,
stralloc
*
src
)
{
int
nbline
=
0
,
i
=
0
;
printf
(
"src::%s
\n
"
,
src
->
s
)
;
genalloc
gatmp
=
GENALLOC_ZERO
;
//stralist
nbline
=
get_nbline_ga
(
src
->
s
,
src
->
len
,
&
gatmp
)
;
printf
(
"nbline::%i
\n
"
,
nbline
)
;
for
(;
i
<
nbline
;
i
++
)
{
char
*
line
=
gaistr
(
&
gatmp
,
i
)
;
printf
(
"line::%s
\n
"
,
line
)
;
if
(
!
env_split_one
(
line
,
gaenv
,
saenv
))
goto
err
;
}
genalloc_deepfree
(
stralist
,
&
gatmp
,
stra_free
)
;
return
1
;
err:
genalloc_deepfree
(
stralist
,
&
gatmp
,
stra_free
)
;
return
0
;
}
int
env_parsenclean
(
stralloc
*
modifs
,
stralloc
*
src
)
{
int
nbline
=
0
,
i
=
0
;
genalloc
gatmp
=
GENALLOC_ZERO
;
//stralist
if
(
!
parse_env
(
src
))
goto
err
;
if
(
!
env_clean
(
src
))
goto
err
;
nbline
=
get_nbline_ga
(
src
->
s
,
src
->
len
,
&
gatmp
)
;
printf
(
"src + u::%s
\n
"
,
src
->
s
)
;
for
(;
i
<
nbline
;
i
++
)
{
char
*
line
=
gaistr
(
&
gatmp
,
i
)
;
int
u
=
0
;
if
(
line
[
0
]
==
'!'
)
u
++
;
printf
(
"line + u::%s
\n
"
,
gaistr
(
&
gatmp
,
i
)
)
;
if
(
!
stralloc_catb
(
modifs
,
line
+
u
,
strlen
(
line
)
-
u
)
||
!
stralloc_0
(
modifs
))
goto
err
;
}
genalloc_deepfree
(
stralist
,
&
gatmp
,
stra_free
)
;
return
1
;
err:
genalloc_deepfree
(
stralist
,
&
gatmp
,
stra_free
)
;
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