Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
Esteban Blanc
proview
Commits
d863a8e8
Commit
d863a8e8
authored
Dec 22, 2016
by
Claes Sjofors
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Co, array added
parent
511210c9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
198 additions
and
0 deletions
+198
-0
src/lib/co/src/co_array.c
src/lib/co/src/co_array.c
+128
-0
src/lib/co/src/co_array.h
src/lib/co/src/co_array.h
+70
-0
No files found.
src/lib/co/src/co_array.c
0 → 100644
View file @
d863a8e8
/**
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pwr.h"
#include "co_array.h"
int
array_Init
(
array_tCtx
*
ctx
,
int
elemsize
,
int
alloc_incr
)
{
*
ctx
=
calloc
(
1
,
sizeof
(
array_sCtx
));
if
(
!*
ctx
)
return
0
;
(
*
ctx
)
->
elemsize
=
elemsize
;
(
*
ctx
)
->
alloc_incr
=
alloc_incr
;
(
*
ctx
)
->
a
=
calloc
(
1
,
elemsize
*
alloc_incr
);
if
(
!
(
*
ctx
)
->
a
)
return
0
;
(
*
ctx
)
->
allocated
=
alloc_incr
;
return
1
;
}
void
array_Close
(
array_tCtx
ctx
)
{
free
(
(
char
*
)
ctx
->
a
);
free
(
(
char
*
)
ctx
);
}
int
array_Add
(
array_tCtx
ctx
,
void
*
elem
)
{
if
(
ctx
->
allocated
<=
ctx
->
a_size
)
{
void
*
a_tmp
;
ctx
->
allocated
+=
ctx
->
alloc_incr
;
a_tmp
=
calloc
(
ctx
->
allocated
,
ctx
->
elemsize
);
if
(
!
a_tmp
)
return
0
;
memcpy
(
a_tmp
,
ctx
->
a
,
ctx
->
a_size
*
ctx
->
elemsize
);
free
(
(
char
*
)
ctx
->
a
);
ctx
->
a
=
a_tmp
;
}
memcpy
(
(
char
*
)
ctx
->
a
+
ctx
->
a_size
*
ctx
->
elemsize
,
elem
,
ctx
->
elemsize
);
ctx
->
a_size
++
;
return
1
;
}
int
array_MAdd
(
array_tCtx
ctx
,
void
*
elem
,
int
elements
)
{
if
(
ctx
->
allocated
<=
ctx
->
a_size
+
elements
-
1
)
{
void
*
a_tmp
;
ctx
->
allocated
+=
ctx
->
alloc_incr
;
if
(
ctx
->
allocated
<
ctx
->
a_size
+
elements
)
ctx
->
allocated
=
ctx
->
a_size
+
elements
;
a_tmp
=
calloc
(
ctx
->
allocated
,
ctx
->
elemsize
);
if
(
!
a_tmp
)
return
0
;
memcpy
(
a_tmp
,
ctx
->
a
,
ctx
->
a_size
*
ctx
->
elemsize
);
free
(
(
char
*
)
ctx
->
a
);
ctx
->
a
=
a_tmp
;
}
memcpy
(
(
char
*
)
ctx
->
a
+
ctx
->
a_size
*
ctx
->
elemsize
,
elem
,
ctx
->
elemsize
*
elements
);
ctx
->
a_size
+=
elements
;
return
1
;
}
int
array_Get
(
array_tCtx
ctx
,
int
idx
,
void
**
elem
)
{
if
(
idx
>=
ctx
->
a_size
)
return
0
;
memcpy
(
elem
,
(
char
*
)
ctx
->
a
+
idx
*
ctx
->
elemsize
,
ctx
->
elemsize
);
return
1
;
}
int
array_Size
(
array_tCtx
ctx
)
{
return
ctx
->
a_size
;
}
void
*
array_Array
(
array_tCtx
ctx
)
{
return
ctx
->
a
;
}
void
*
array_CopyArray
(
array_tCtx
ctx
)
{
void
*
buf
;
buf
=
malloc
(
ctx
->
elemsize
*
ctx
->
a_size
);
memcpy
(
buf
,
ctx
->
a
,
ctx
->
a_size
*
ctx
->
elemsize
);
return
buf
;
}
src/lib/co/src/co_array.h
0 → 100644
View file @
d863a8e8
/**
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
#ifndef co_array_h
#define co_array_h
#ifdef __cplusplus
extern
"C"
{
#endif
#ifndef __STDDEF_LOADED
#include <stddef.h>
#endif
typedef
struct
{
void
*
a
;
int
elemsize
;
int
allocated
;
int
alloc_incr
;
int
a_size
;
}
array_sCtx
,
*
array_tCtx
;
int
array_Init
(
array_tCtx
*
ctx
,
int
elemsize
,
int
alloc_incr
);
void
array_Close
(
array_tCtx
ctx
);
int
array_Add
(
array_tCtx
ctx
,
void
*
elem
);
int
array_MAdd
(
array_tCtx
ctx
,
void
*
elem
,
int
elements
);
int
array_Get
(
array_tCtx
ctx
,
int
idx
,
void
**
elem
);
int
array_Size
(
array_tCtx
ctx
);
void
*
array_Array
(
array_tCtx
ctx
);
void
*
array_CopyArray
(
array_tCtx
ctx
);
#ifdef __cplusplus
}
#endif
#endif
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