Commit 1da30fe2 authored by Claes Sjofors's avatar Claes Sjofors

Merge branch 'master'

parents 1006a60b a911da1b
...@@ -1225,7 +1225,6 @@ static void classList(qcom_sGet* get) ...@@ -1225,7 +1225,6 @@ static void classList(qcom_sGet* get)
int i; int i;
pwr_tOid oid; pwr_tOid oid;
int listcnt; int listcnt;
array_tCtx arr;
pwr_tAttrRef aref; pwr_tAttrRef aref;
gdb_ScopeLock gdb_ScopeLock
...@@ -1239,14 +1238,14 @@ static void classList(qcom_sGet* get) ...@@ -1239,14 +1238,14 @@ static void classList(qcom_sGet* get)
cdh_NodeIdToString(NULL, np->nid, 0, 0)); cdh_NodeIdToString(NULL, np->nid, 0, 0));
} }
array_Init(&arr, sizeof(pwr_tAttrRef), 20); array_tCtx arr = array_New(sizeof(pwr_tAttrRef), 20);
listcnt = 0; listcnt = 0;
if (mp->attrobjects) { if (mp->attrobjects) {
for (i = 0; i < mp->cidcnt; i++) { for (i = 0; i < mp->cidcnt; i++) {
for (sts = gdh_GetClassListAttrRef(mp->cid[i], &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(mp->cid[i], &aref); ODD(sts);
sts = gdh_GetNextAttrRef(mp->cid[i], &aref, &aref)) { sts = gdh_GetNextAttrRef(mp->cid[i], &aref, &aref)) {
array_Add(arr, &aref); array_Push(arr, &aref);
listcnt++; listcnt++;
} }
} }
...@@ -1255,7 +1254,7 @@ static void classList(qcom_sGet* get) ...@@ -1255,7 +1254,7 @@ static void classList(qcom_sGet* get)
for (sts = gdh_GetClassList(mp->cid[i], &oid); ODD(sts); for (sts = gdh_GetClassList(mp->cid[i], &oid); ODD(sts);
sts = gdh_GetNextObject(oid, &oid)) { sts = gdh_GetNextObject(oid, &oid)) {
aref = cdh_ObjidToAref(oid); aref = cdh_ObjidToAref(oid);
array_Add(arr, &aref); array_Push(arr, &aref);
listcnt++; listcnt++;
} }
} }
...@@ -1279,10 +1278,10 @@ static void classList(qcom_sGet* get) ...@@ -1279,10 +1278,10 @@ static void classList(qcom_sGet* get)
rmp->listcnt = 0; rmp->listcnt = 0;
} else { } else {
rmp->listcnt = listcnt; rmp->listcnt = listcnt;
memcpy(rmp->classlist, arr->a, listcnt * sizeof(pwr_tAttrRef)); memcpy(rmp->classlist, arr->data, listcnt * sizeof(pwr_tAttrRef));
} }
array_Close(arr); array_Delete(arr);
net_Reply(&sts, get, &put, 0); net_Reply(&sts, get, &put, 0);
} }
...@@ -38,90 +38,51 @@ ...@@ -38,90 +38,51 @@
#include "pwr.h" #include "pwr.h"
#include "co_array.h" #include "co_array.h"
#include "co_math.h"
int array_Init(array_tCtx* ctx, int elemsize, int alloc_incr) array_tCtx array_New(int elemsize, int alloc_incr)
{ {
*ctx = calloc(1, sizeof(array_sCtx)); array_tCtx arr = calloc(1, sizeof(array_sCtx));
if (!*ctx) if (!arr)
return 0; return NULL;
(*ctx)->elemsize = elemsize; arr->data = calloc(1, elemsize * alloc_incr);
(*ctx)->alloc_incr = alloc_incr; if (!arr->data)
(*ctx)->a = calloc(1, elemsize * alloc_incr); return NULL;
if (!(*ctx)->a) arr->elemsize = elemsize;
return 0; arr->alloc_incr = alloc_incr;
(*ctx)->allocated = alloc_incr; arr->capacity = alloc_incr;
return 1; return arr;
} }
void array_Close(array_tCtx ctx) void array_Delete(array_tCtx arr)
{ {
free((char*)ctx->a); free((char*)arr->data);
free((char*)ctx); free((char*)arr);
} }
int array_Add(array_tCtx ctx, void* elem) int array_Push(array_tCtx arr, void* elem)
{ {
if (ctx->allocated <= ctx->a_size) { return array_Concat(arr, elem, 1);
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) int array_Concat(array_tCtx arr, void* elems, int number)
{ {
if (ctx->allocated <= ctx->a_size + elements - 1) { if (arr->capacity <= arr->size + number - 1) {
void* a_tmp; void* a_tmp = realloc(arr->data, arr->elemsize * MAX(arr->capacity + arr->alloc_incr, arr->size + number));
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) if (!a_tmp)
return 0; return 0;
memcpy(a_tmp, ctx->a, ctx->a_size * ctx->elemsize); arr->data = a_tmp;
free((char*)ctx->a); arr->capacity = number;
ctx->a = a_tmp;
} }
memcpy((char*)ctx->a + ctx->a_size * ctx->elemsize, elem, memcpy((char*)arr->data + arr->size * arr->elemsize, elems,
ctx->elemsize * elements); arr->elemsize * number);
ctx->a_size += elements; arr->size += number;
return 1; return 1;
} }
int array_Get(array_tCtx ctx, int idx, void** elem) void* array_Copy(array_tCtx arr)
{ {
if (idx >= ctx->a_size) void* buf = malloc(arr->elemsize * arr->size);
return 0; memcpy(buf, arr->data, arr->size * arr->elemsize);
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; return buf;
} }
...@@ -45,22 +45,47 @@ extern "C" { ...@@ -45,22 +45,47 @@ extern "C" {
#include <stddef.h> #include <stddef.h>
#endif #endif
/*! \file co_array.h
\brief Dynamic-size array, like std::vector from C++ or ArrayList from Java.
*/
typedef struct { typedef struct {
void* a; void* data;
int elemsize; int elemsize;
int allocated; int capacity;
int alloc_incr; int alloc_incr;
int a_size; int size;
} array_sCtx, *array_tCtx; } array_sCtx, *array_tCtx;
int array_Init(array_tCtx* ctx, int elemsize, int alloc_incr); /*! \fn array_tCtx array_New(int elemsize, int alloc_incr)
void array_Close(array_tCtx ctx); \brief Allocates a new dynamic array containing elements of size \a elemsize
int array_Add(array_tCtx ctx, void* elem);
int array_MAdd(array_tCtx ctx, void* elem, int elements); \param elemsize The sizeof() an element.
int array_Get(array_tCtx ctx, int idx, void** elem); \param alloc_incr How much the dynamic array should grow when it is full.
int array_Size(array_tCtx ctx); \return Returns a new dynamic array.
void* array_Array(array_tCtx ctx); */
void* array_CopyArray(array_tCtx ctx); array_tCtx array_New(int elemsize, int alloc_incr);
/*! \fn void array_Delete(array_tCtx arr)
\brief Frees the memory held by \a arr
*/
void array_Delete(array_tCtx arr);
/*! \fn int array_Push(array_tCtx arr, void* elem)
\brief Appends \a elem to the end of the array.
*/
int array_Push(array_tCtx arr, void* elem);
/*! \fn int array_Push(array_tCtx arr, void* elem)
\brief Concatenates \a number of elements from the fixed-size array
\a elems to the end of the dynamic array \a arr.
*/
int array_Concat(array_tCtx arr, void* elems, int number);
/*! \fn void* array_Copy(array_tCtx arr)
\brief Creates and returns a copy of \a arr.
Warning! The returned array must be free() explicitly.
*/
void* array_Copy(array_tCtx arr);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -192,8 +192,6 @@ static int logging_page = 0; ...@@ -192,8 +192,6 @@ static int logging_page = 0;
* prototypes____________________________________________________*/ * prototypes____________________________________________________*/
static int rttsys_get_nodename(pwr_tNodeId nid, char* nodename); static int rttsys_get_nodename(pwr_tNodeId nid, char* nodename);
static int rttsys_plclist_bubblesort(rttsys_t_plcpgm_list* plclist, int size);
static int rttsys_steplist_bubblesort(rttsys_t_step_list* steplist, int size);
static int rttsys_get_plcpgm(pwr_tObjid initstep_objid, pwr_tObjid* plc_objid); static int rttsys_get_plcpgm(pwr_tObjid initstep_objid, pwr_tObjid* plc_objid);
static int rttsys_plclist_add(pwr_tObjid plc_objid, static int rttsys_plclist_add(pwr_tObjid plc_objid,
rttsys_t_plcpgm_list** plclist, int* plclist_count, int* alloc); rttsys_t_plcpgm_list** plclist, int* plclist_count, int* alloc);
...@@ -2096,71 +2094,22 @@ int RTTSYS_OBJECT_AV(menu_ctx ctx, int event, char* parameter_ptr, ...@@ -2096,71 +2094,22 @@ int RTTSYS_OBJECT_AV(menu_ctx ctx, int event, char* parameter_ptr,
#define GRAFCET_PAGESIZE 20 #define GRAFCET_PAGESIZE 20
/************************************************************************* static int rttsys_plclist_cmp(const void* p1, const void* p2)
*
* Name: rtt_menu_bubblesort()
*
* Type int
*
* Type Parameter IOGF Description
* rtt_t_menu *menulist I menulist.
*
* Description:
* This function sorts the items in a plclist in
* aphabetic order.
*
**************************************************************************/
static int rttsys_plclist_bubblesort(rttsys_t_plcpgm_list* plclist, int size)
{ {
int i, j; char* str1 = ((rttsys_t_plcpgm_list*) p1)->name;
char *str1, *str2; char* str2 = ((rttsys_t_plcpgm_list*) p2)->name;
rttsys_t_plcpgm_list dum; if (*str2 == 0)
rttsys_t_plcpgm_list* plclist_ptr; return 0;
return strcmp(str1, str2);
for (i = size - 1; i > 0; i--) {
plclist_ptr = plclist;
for (j = 0; j < i; j++) {
str1 = plclist_ptr->name;
str2 = (plclist_ptr + 1)->name;
if (*str2 == 0)
break;
if (strcmp(str1, str2) > 0) {
/* Change order */
memcpy(&dum, plclist_ptr + 1, sizeof(rttsys_t_plcpgm_list));
memcpy(plclist_ptr + 1, plclist_ptr, sizeof(rttsys_t_plcpgm_list));
memcpy(plclist_ptr, &dum, sizeof(rttsys_t_plcpgm_list));
}
plclist_ptr++;
}
}
return RTT__SUCCESS;
} }
static int rttsys_steplist_bubblesort(rttsys_t_step_list* steplist, int size) static int rttsys_steplist_cmp(const void* p1, const void* p2)
{ {
int i, j; char* str1 = ((rttsys_t_step_list*) p1)->name;
char *str1, *str2; char* str2 = ((rttsys_t_step_list*) p2)->name;
rttsys_t_step_list dum; if (*str2 == 0)
rttsys_t_step_list* steplist_ptr; return 0;
return strcmp(str1, str2);
for (i = size - 1; i > 0; i--) {
steplist_ptr = steplist;
for (j = 0; j < i; j++) {
str1 = steplist_ptr->name;
str2 = (steplist_ptr + 1)->name;
if (*str2 == 0)
break;
if (strcmp(str1, str2) > 0) {
/* Change order */
memcpy(&dum, steplist_ptr + 1, sizeof(rttsys_t_step_list));
memcpy(steplist_ptr + 1, steplist_ptr, sizeof(rttsys_t_step_list));
memcpy(steplist_ptr, &dum, sizeof(rttsys_t_step_list));
}
steplist_ptr++;
}
}
return RTT__SUCCESS;
} }
static int rttsys_get_plcpgm(pwr_tObjid initstep_objid, pwr_tObjid* plc_objid) static int rttsys_get_plcpgm(pwr_tObjid initstep_objid, pwr_tObjid* plc_objid)
...@@ -2428,7 +2377,7 @@ int RTTSYS_GRAFCET(menu_ctx ctx, int event, char* parameter_ptr, ...@@ -2428,7 +2377,7 @@ int RTTSYS_GRAFCET(menu_ctx ctx, int event, char* parameter_ptr,
sts = gdh_GetNextObject(initstep_objid, &initstep_objid); sts = gdh_GetNextObject(initstep_objid, &initstep_objid);
} }
rttsys_plclist_bubblesort(plclist, plclist_count); qsort(plclist, plclist_count, sizeof(rttsys_t_plcpgm_list), rttsys_plclist_cmp);
menulist = (rtt_t_menu_upd*)ctx->menu; menulist = (rtt_t_menu_upd*)ctx->menu;
menu_ptr = menulist; menu_ptr = menulist;
for (i = grafcet_page * GRAFCET_PAGESIZE; for (i = grafcet_page * GRAFCET_PAGESIZE;
...@@ -2761,8 +2710,8 @@ int RTTSYS_GRAFCET_PLC(menu_ctx ctx, int event, char* parameter_ptr, ...@@ -2761,8 +2710,8 @@ int RTTSYS_GRAFCET_PLC(menu_ctx ctx, int event, char* parameter_ptr,
&plclist_ptr->order_alloc, (void*)pwr_cClass_order, 0); &plclist_ptr->order_alloc, (void*)pwr_cClass_order, 0);
if (EVEN(sts)) if (EVEN(sts))
return sts; return sts;
rttsys_steplist_bubblesort(plclist_ptr->steps, plclist_ptr->step_count); qsort(plclist_ptr->steps, plclist_ptr->step_count, sizeof(rttsys_t_step_list), rttsys_steplist_cmp);
rttsys_steplist_bubblesort(plclist_ptr->orders, plclist_ptr->order_count); qsort(plclist_ptr->orders, plclist_ptr->order_count, sizeof(rttsys_t_step_list), rttsys_steplist_cmp);
i = 0; i = 0;
/* Print the plcname in line 1, just show the segment name */ /* Print the plcname in line 1, just show the segment name */
...@@ -2999,7 +2948,7 @@ int RTTSYS_PLCPGM(menu_ctx ctx, int event, char* parameter_ptr, ...@@ -2999,7 +2948,7 @@ int RTTSYS_PLCPGM(menu_ctx ctx, int event, char* parameter_ptr,
if (EVEN(sts)) if (EVEN(sts))
return sts; return sts;
rttsys_steplist_bubblesort(plclist, plclist_count); qsort(plclist, plclist_count, sizeof(rttsys_t_step_list), rttsys_steplist_cmp);
menulist = (rtt_t_menu_upd*)ctx->menu; menulist = (rtt_t_menu_upd*)ctx->menu;
menu_ptr = menulist; menu_ptr = menulist;
plclist_ptr = plclist; plclist_ptr = plclist;
...@@ -3362,7 +3311,7 @@ int RTTSYS_PLCTHREAD(menu_ctx ctx, int event, char* parameter_ptr, ...@@ -3362,7 +3311,7 @@ int RTTSYS_PLCTHREAD(menu_ctx ctx, int event, char* parameter_ptr,
return sts; return sts;
rttsys_objectlist_modname(objectlist, objectlist_count); rttsys_objectlist_modname(objectlist, objectlist_count);
rttsys_steplist_bubblesort(objectlist, objectlist_count); qsort(objectlist, objectlist_count, sizeof(rttsys_t_step_list), rttsys_steplist_cmp);
rttsys_thread_update(ctx, objectlist, objectlist_count, page); rttsys_thread_update(ctx, objectlist, objectlist_count, page);
THREAD_MAXPAGE = MAX(1, (objectlist_count - 1) / THREAD_PAGESIZE + 1); THREAD_MAXPAGE = MAX(1, (objectlist_count - 1) / THREAD_PAGESIZE + 1);
...@@ -3624,8 +3573,6 @@ int RTTSYS_PID(menu_ctx ctx, int event, char* parameter_ptr, char* objectname, ...@@ -3624,8 +3573,6 @@ int RTTSYS_PID(menu_ctx ctx, int event, char* parameter_ptr, char* objectname,
objectlist_count /= 2; objectlist_count /= 2;
rttsys_objectlist_modname_plc(objectlist, objectlist_count); rttsys_objectlist_modname_plc(objectlist, objectlist_count);
/* rttsys_steplist_bubblesort( objectlist, objectlist_count);
*/
rttsys_pid_update(ctx, objectlist, objectlist_count, page); rttsys_pid_update(ctx, objectlist, objectlist_count, page);
PID_MAXPAGE = MAX(1, (objectlist_count - 1) / PID_PAGESIZE + 1); PID_MAXPAGE = MAX(1, (objectlist_count - 1) / PID_PAGESIZE + 1);
} }
...@@ -4718,30 +4665,13 @@ static int rttsys_cell_dataobject(menu_ctx ctx, pwr_tObjid cell_objid, ...@@ -4718,30 +4665,13 @@ static int rttsys_cell_dataobject(menu_ctx ctx, pwr_tObjid cell_objid,
return RTT__SUCCESS; return RTT__SUCCESS;
} }
static int rttsys_cellist_bubblesort(rttsys_t_cell_list* cellist, int size) static int rttsys_cellist_cmp(const void* p1, const void* p2)
{ {
int i, j; char* str1 = ((rttsys_t_cell_list*) p1)->name;
char *str1, *str2; char* str2 = ((rttsys_t_cell_list*) p2)->name;
rttsys_t_cell_list dum; if (*str2 == 0)
rttsys_t_cell_list* cellist_ptr; return 0;
return strcmp(str1, str2);
for (i = size - 1; i > 0; i--) {
cellist_ptr = cellist;
for (j = 0; j < i; j++) {
str1 = cellist_ptr->name;
str2 = (cellist_ptr + 1)->name;
if (*str2 == 0)
break;
if (strcmp(str1, str2) > 0) {
/* Change order */
memcpy(&dum, cellist_ptr + 1, sizeof(rttsys_t_cell_list));
memcpy(cellist_ptr + 1, cellist_ptr, sizeof(rttsys_t_cell_list));
memcpy(cellist_ptr, &dum, sizeof(rttsys_t_cell_list));
}
cellist_ptr++;
}
}
return RTT__SUCCESS;
} }
#define NMPSCELL_PAGESIZE 19 #define NMPSCELL_PAGESIZE 19
...@@ -4815,8 +4745,7 @@ int RTTSYS_NMPSCELL(menu_ctx ctx, int event, char* parameter_ptr, ...@@ -4815,8 +4745,7 @@ int RTTSYS_NMPSCELL(menu_ctx ctx, int event, char* parameter_ptr,
if (EVEN(sts)) if (EVEN(sts))
return sts; return sts;
rttsys_cellist_bubblesort(cellist, cellist_count); qsort(cellist, cellist_count, sizeof(rttsys_t_cell_list), rttsys_cellist_cmp);
} }
/********************************************************** /**********************************************************
* Exit of the picture * Exit of the picture
......
...@@ -5153,21 +5153,20 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects, ...@@ -5153,21 +5153,20 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
pwr_tStatus sts; pwr_tStatus sts;
qcom_sNode mynode, node; qcom_sNode mynode, node;
pwr_tNid nid; pwr_tNid nid;
array_tCtx arr;
pwr_tAttrRef* clist; pwr_tAttrRef* clist;
int ccnt; int ccnt;
int i; int i;
pwr_tObjid oid; pwr_tObjid oid;
pwr_tAttrRef aref; pwr_tAttrRef aref;
array_Init(&arr, sizeof(pwr_tAttrRef), 20); array_tCtx arr = array_New(sizeof(pwr_tAttrRef), 20);
/* Add local objects */ /* Add local objects */
if (attrobjects) { if (attrobjects) {
for (i = 0; i < cidcnt; i++) { for (i = 0; i < cidcnt; i++) {
for (sts = gdh_GetClassListAttrRef(cid[i], &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(cid[i], &aref); ODD(sts);
sts = gdh_GetNextAttrRef(cid[i], &aref, &aref)) { sts = gdh_GetNextAttrRef(cid[i], &aref, &aref)) {
array_Add(arr, &aref); array_Push(arr, &aref);
} }
} }
} else { } else {
...@@ -5175,7 +5174,7 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects, ...@@ -5175,7 +5174,7 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
for (sts = gdh_GetClassList(cid[i], &oid); ODD(sts); for (sts = gdh_GetClassList(cid[i], &oid); ODD(sts);
sts = gdh_GetNextObject(oid, &oid)) { sts = gdh_GetNextObject(oid, &oid)) {
aref = cdh_ObjidToAref(oid); aref = cdh_ObjidToAref(oid);
array_Add(arr, &aref); array_Push(arr, &aref);
} }
} }
} }
...@@ -5189,18 +5188,18 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects, ...@@ -5189,18 +5188,18 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
if (EVEN(sts)) if (EVEN(sts))
continue; continue;
array_MAdd(arr, clist, ccnt); array_Concat(arr, clist, ccnt);
} }
if (array_Size(arr)) if (arr->size)
*classlist = array_CopyArray(arr); *classlist = array_Copy(arr);
else { else {
*classlist = 0; *classlist = 0;
sts = GDH__NOSUCHOBJ; sts = GDH__NOSUCHOBJ;
} }
*listcnt = array_Size(arr); *listcnt = arr->size;
array_Close(arr); array_Delete(arr);
return GDH__SUCCESS; return GDH__SUCCESS;
} }
...@@ -5208,19 +5207,18 @@ pwr_tStatus gdh_GetLocalClassList(int cidcnt, pwr_tCid* cid, int attrobjects, ...@@ -5208,19 +5207,18 @@ pwr_tStatus gdh_GetLocalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
pwr_tAttrRef* classlist[], int* listcnt) pwr_tAttrRef* classlist[], int* listcnt)
{ {
pwr_tStatus sts; pwr_tStatus sts;
array_tCtx arr;
int i; int i;
pwr_tObjid oid; pwr_tObjid oid;
pwr_tAttrRef aref; pwr_tAttrRef aref;
array_Init(&arr, sizeof(pwr_tAttrRef), 20); array_tCtx arr = array_New(sizeof(pwr_tAttrRef), 20);
/* Add local objects */ /* Add local objects */
if (attrobjects) { if (attrobjects) {
for (i = 0; i < cidcnt; i++) { for (i = 0; i < cidcnt; i++) {
for (sts = gdh_GetClassListAttrRef(cid[i], &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(cid[i], &aref); ODD(sts);
sts = gdh_GetNextAttrRef(cid[i], &aref, &aref)) { sts = gdh_GetNextAttrRef(cid[i], &aref, &aref)) {
array_Add(arr, &aref); array_Push(arr, &aref);
} }
} }
} else { } else {
...@@ -5228,20 +5226,20 @@ pwr_tStatus gdh_GetLocalClassList(int cidcnt, pwr_tCid* cid, int attrobjects, ...@@ -5228,20 +5226,20 @@ pwr_tStatus gdh_GetLocalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
for (sts = gdh_GetClassList(cid[i], &oid); ODD(sts); for (sts = gdh_GetClassList(cid[i], &oid); ODD(sts);
sts = gdh_GetNextObject(oid, &oid)) { sts = gdh_GetNextObject(oid, &oid)) {
aref = cdh_ObjidToAref(oid); aref = cdh_ObjidToAref(oid);
array_Add(arr, &aref); array_Push(arr, &aref);
} }
} }
} }
if (array_Size(arr)) if (arr->size)
*classlist = array_CopyArray(arr); *classlist = array_Copy(arr);
else { else {
*classlist = 0; *classlist = 0;
sts = GDH__NOSUCHOBJ; sts = GDH__NOSUCHOBJ;
} }
*listcnt = array_Size(arr); *listcnt = arr->size;
array_Close(arr); array_Delete(arr);
return GDH__SUCCESS; return GDH__SUCCESS;
} }
......
...@@ -6138,36 +6138,25 @@ int rtt_menu_classort(rtt_t_menu* menulist, int redo) ...@@ -6138,36 +6138,25 @@ int rtt_menu_classort(rtt_t_menu* menulist, int redo)
* *
**************************************************************************/ **************************************************************************/
int rtt_menu_bubblesort(rtt_t_menu* menulist) static int rtt_menu_cmp(const void* p1, const void* p2)
{ {
int i, j, size; char* str1 = ((rtt_t_menu*) p1)->text;
char *str1, *str2; char* str2 = ((rtt_t_menu*) p2)->text;
rtt_t_menu dum; if (*str2 == 0)
rtt_t_menu* menu_ptr; return 0;
return strcmp(str1, str2);
}
int rtt_menu_bubblesort(rtt_t_menu* menulist)
{
/* Get the size of the menu */ /* Get the size of the menu */
menu_ptr = menulist; rtt_t_menu* menu_ptr = menulist;
size = 0; int size = 0;
while (menu_ptr->text[0] != 0) { while (menu_ptr->text[0] != 0) {
menu_ptr++; menu_ptr++;
size++; size++;
} }
for (i = size - 1; i > 0; i--) { qsort(menulist, size, sizeof(rtt_t_menu), rtt_menu_cmp);
menu_ptr = menulist;
for (j = 0; j < i; j++) {
str1 = menu_ptr->text;
str2 = (menu_ptr + 1)->text;
if (*str2 == 0)
break;
if (strcmp(str1, str2) > 0) {
memcpy(&dum, menu_ptr + 1, sizeof(rtt_t_menu));
memcpy(menu_ptr + 1, menu_ptr, sizeof(rtt_t_menu));
memcpy(menu_ptr, &dum, sizeof(rtt_t_menu));
}
menu_ptr++;
}
}
return RTT__SUCCESS; return RTT__SUCCESS;
} }
...@@ -6186,35 +6175,25 @@ int rtt_menu_bubblesort(rtt_t_menu* menulist) ...@@ -6186,35 +6175,25 @@ int rtt_menu_bubblesort(rtt_t_menu* menulist)
* *
**************************************************************************/ **************************************************************************/
int rtt_menu_upd_bubblesort(rtt_t_menu_upd* menulist) static int rtt_menu_upd_cmp(const void* p1, const void* p2)
{ {
int i, j, size; char* str1 = ((rtt_t_menu_upd*) p1)->text;
char *str1, *str2; char* str2 = ((rtt_t_menu_upd*) p2)->text;
rtt_t_menu_upd dum; if (*str2 == 0)
rtt_t_menu_upd* menu_ptr; return 0;
return strcmp(str1, str2);
}
int rtt_menu_upd_bubblesort(rtt_t_menu_upd* menulist)
{
/* Get the size of the menu */ /* Get the size of the menu */
menu_ptr = menulist; rtt_t_menu_upd* menu_ptr = menulist;
size = 0; int size = 0;
while (menu_ptr->text[0] != 0) { while (menu_ptr->text[0] != 0) {
menu_ptr++; menu_ptr++;
size++; size++;
} }
for (i = size - 1; i > 0; i--) { qsort(menulist, size, sizeof(rtt_t_menu_upd), rtt_menu_upd_cmp);
menu_ptr = menulist;
for (j = 0; j < i; j++) {
str1 = menu_ptr->text;
str2 = (menu_ptr + 1)->text;
if (*str2 == 0)
break;
if (strcmp(str1, str2) > 0) {
memcpy(&dum, menu_ptr + 1, sizeof(rtt_t_menu_upd));
memcpy(menu_ptr + 1, menu_ptr, sizeof(rtt_t_menu_upd));
memcpy(menu_ptr, &dum, sizeof(rtt_t_menu_upd));
}
menu_ptr++;
}
}
return RTT__SUCCESS; return RTT__SUCCESS;
} }
......
...@@ -994,7 +994,7 @@ pwr_tStatus WFoeQt::create_window(int x_top, int y_top, int width_adb, ...@@ -994,7 +994,7 @@ pwr_tStatus WFoeQt::create_window(int x_top, int y_top, int width_adb,
"$pwr_exe/foe_redraw.png"); "$pwr_exe/foe_redraw.png");
// Feedback connection checkbutton // Feedback connection checkbutton
tools_confeedback = addCheckableToolItem(toplevel, tools, "Redraw", tools_confeedback = addCheckableToolItem(toplevel, tools, "Feedback connection",
SLOT(activate_confeedback(bool)), "$pwr_exe/foe_confeedback.png"); SLOT(activate_confeedback(bool)), "$pwr_exe/foe_confeedback.png");
// Singlelinetext button // Singlelinetext button
......
...@@ -729,6 +729,8 @@ XttQt::XttQt(int argc, char* argv[], int* return_sts) ...@@ -729,6 +729,8 @@ XttQt::XttQt(int argc, char* argv[], int* return_sts)
statusbar->show(); statusbar->show();
wow = new CoWowQt(toplevel);
xnav = new XNavQt(this, xnav_form, "Plant", &brow_widget, xnav = new XNavQt(this, xnav_form, "Plant", &brow_widget,
(xnav_sStartMenu*)root_menu, opplace_str, op_close_button, &sts); (xnav_sStartMenu*)root_menu, opplace_str, op_close_button, &sts);
xnav->message_cb = &xtt_message_cb; xnav->message_cb = &xtt_message_cb;
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include "cow_xhelpnav_gtk.h" #include "cow_xhelpnav_gtk.h"
#include "flow_browwidget_gtk.h" #include "flow_browwidget_gtk.h"
#include "flow_utils.h"
extern "C" { extern "C" {
#include "co_api.h" #include "co_api.h"
......
...@@ -56,7 +56,6 @@ ...@@ -56,7 +56,6 @@
#include "flow_browctx.h" #include "flow_browctx.h"
#include "flow_browapi.h" #include "flow_browapi.h"
#include "flow_browwidget_motif.h" #include "flow_browwidget_motif.h"
#include "flow_utils.h"
#include "cow_xhelpnav_motif.h" #include "cow_xhelpnav_motif.h"
......
...@@ -44,8 +44,6 @@ ...@@ -44,8 +44,6 @@
#include "cow_xhelpnav.h" #include "cow_xhelpnav.h"
#include "flow_utils.h"
#include "xnav_bitmap_morehelp8.h" #include "xnav_bitmap_morehelp8.h"
#include "xnav_bitmap_morehelp10.h" #include "xnav_bitmap_morehelp10.h"
#include "xnav_bitmap_morehelp12.h" #include "xnav_bitmap_morehelp12.h"
...@@ -1399,8 +1397,7 @@ int CoXHelpNav::help_index( ...@@ -1399,8 +1397,7 @@ int CoXHelpNav::help_index(
brow_GetObjectList(brow->ctx, &object_list, &object_cnt); brow_GetObjectList(brow->ctx, &object_list, &object_cnt);
flow_qsort( qsort(&object_list[2], object_cnt - 2, sizeof(object_list[0]), help_cmp_items);
&object_list[2], object_cnt - 2, sizeof(object_list[0]), help_cmp_items);
brow_ResetNodraw(brow->ctx); brow_ResetNodraw(brow->ctx);
brow_Redraw(brow->ctx, 0); brow_Redraw(brow->ctx, 0);
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
#include "flow_conpoint.h" #include "flow_conpoint.h"
#include "flow_draw.h" #include "flow_draw.h"
#include "flow_text.h" #include "flow_text.h"
#include "flow_utils.h"
#include "flow_msg.h" #include "flow_msg.h"
#define LINE_TABLE_SIZE 500 #define LINE_TABLE_SIZE 500
...@@ -2033,33 +2032,33 @@ int FlowCon::sort_lines(double dest_x, double dest_y, flow_eDirection dest_dir, ...@@ -2033,33 +2032,33 @@ int FlowCon::sort_lines(double dest_x, double dest_y, flow_eDirection dest_dir,
sort_dest = dest_node; sort_dest = dest_node;
if (dest_dir == flow_eDirection_Right && src_dir == flow_eDirection_Left if (dest_dir == flow_eDirection_Right && src_dir == flow_eDirection_Left
&& src_x > dest_x) { && src_x > dest_x) {
flow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
flow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3; ideal_line_cnt = 3;
} else if (dest_dir == flow_eDirection_Right } else if (dest_dir == flow_eDirection_Right
&& src_dir == flow_eDirection_Left && src_x <= dest_x) { && src_dir == flow_eDirection_Left && src_x <= dest_x) {
flow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
flow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h3); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h3);
ideal_line_cnt = 5; ideal_line_cnt = 5;
} else if (dest_dir == flow_eDirection_Left } else if (dest_dir == flow_eDirection_Left
&& src_dir == flow_eDirection_Right && src_x < dest_x) { && src_dir == flow_eDirection_Right && src_x < dest_x) {
flow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
flow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3; ideal_line_cnt = 3;
} else if (dest_dir == flow_eDirection_Left } else if (dest_dir == flow_eDirection_Left
&& src_dir == flow_eDirection_Right && src_x > dest_x) { && src_dir == flow_eDirection_Right && src_x > dest_x) {
flow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
flow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h2); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h2);
ideal_line_cnt = 5; ideal_line_cnt = 5;
} else if (dest_dir == flow_eDirection_Right } else if (dest_dir == flow_eDirection_Right
&& src_dir == flow_eDirection_Right) { && src_dir == flow_eDirection_Right) {
flow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
flow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3; ideal_line_cnt = 3;
} else if (dest_dir == flow_eDirection_Left } else if (dest_dir == flow_eDirection_Left
&& src_dir == flow_eDirection_Left) { && src_dir == flow_eDirection_Left) {
flow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
flow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3; ideal_line_cnt = 3;
} }
......
/**
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* 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 ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. 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
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR 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 ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
#include <stdlib.h>
#include "flow_utils.h"
static void qsort_swp(int, char*, char*);
void flow_qsort(void* basearg, size_t nel, size_t width,
int (*compar)(const void*, const void*))
{
int gap, ngap, i, j;
int t1, t2;
char* jd;
char* base = basearg;
t1 = nel * width;
for (ngap = nel / 2; ngap > 0; ngap = ngap / 2) {
gap = ngap * width;
t2 = gap + width;
jd = base + gap;
for (i = t2; i <= t1; i += width)
for (j = i - t2; j >= 0; j -= gap) {
if ((*compar)(base + j, jd + j) <= 0)
break;
qsort_swp(width, base + j, jd + j);
}
}
}
static void qsort_swp(int w, char* a, char* b)
{
char tmp;
while (w--) {
tmp = *a;
*a++ = *b;
*b++ = tmp;
}
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* 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 ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. 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
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR 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 ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef flow_utils_h
#define flow_utils_h
#if defined __cplusplus
extern "C" {
#endif
void flow_qsort(void* basearg, size_t nel, size_t width,
int (*compar)(const void*, const void*));
#if defined __cplusplus
}
#endif
#endif
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <algorithm>
#include "pwr_baseclasses.h" #include "pwr_baseclasses.h"
#include "co_cdh.h" #include "co_cdh.h"
...@@ -309,17 +311,9 @@ public: ...@@ -309,17 +311,9 @@ public:
pwr_tFileName name; pwr_tFileName name;
}; };
void subpalette_sort(std::vector<LocalFile>& fvect) int subpalette_cmp(LocalFile p1, LocalFile p2)
{ {
for (int i = fvect.size() - 1; i > 0; i--) { return strcmp(p1.name, p2.name);
for (int j = 0; j < i; j++) {
if (strcmp(fvect[i].name, fvect[j].name) < 0) {
LocalFile tmp = fvect[i];
fvect[i] = fvect[j];
fvect[j] = tmp;
}
}
}
} }
// //
...@@ -1386,7 +1380,7 @@ int ItemLocalSubGraphs::open_children( ...@@ -1386,7 +1380,7 @@ int ItemLocalSubGraphs::open_children(
dcli_search_file(fname, found_file, DCLI_DIR_SEARCH_END); dcli_search_file(fname, found_file, DCLI_DIR_SEARCH_END);
} }
subpalette_sort(fvect); std::sort(fvect.begin(), fvect.end(), subpalette_cmp);
for (i = 0; i < (int)fvect.size(); i++) { for (i = 0; i < (int)fvect.size(); i++) {
dcli_parse_filename(fvect[i].name, dev, dir, file, type, &version); dcli_parse_filename(fvect[i].name, dev, dir, file, type, &version);
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include "glow_conpoint.h" #include "glow_conpoint.h"
#include "glow_draw.h" #include "glow_draw.h"
#include "glow_text.h" #include "glow_text.h"
#include "glow_utils.h"
#include "glow_growgroup.h" #include "glow_growgroup.h"
#include "glow_growconglue.h" #include "glow_growconglue.h"
#include "glow_msg.h" #include "glow_msg.h"
...@@ -119,12 +118,12 @@ GlowCon::GlowCon( GrowCtx *glow_ctx, const char *name, GlowConClass *con_class, ...@@ -119,12 +118,12 @@ GlowCon::GlowCon( GrowCtx *glow_ctx, const char *name, GlowConClass *con_class,
GlowNode *source, GlowNode *dest, int source_cp, int dest_cp) : GlowNode *source, GlowNode *dest, int source_cp, int dest_cp) :
ctx(glow_ctx), cc(con_class), ctx(glow_ctx), cc(con_class),
source_node(source), dest_node(dest), source_conpoint(source_cp), source_node(source), dest_node(dest), source_conpoint(source_cp),
dest_conpoint(dest_cp), p_num(0), l_num(0), a_num(0), line_a(10,10), dest_conpoint(dest_cp), p_num(0), l_num(0), a_num(0), line_a(10,10),
arc_a(10,10), hot(0), highlight(0), arrow_num(0), arrow_a(1,1), arc_a(10,10), hot(0), highlight(0), arrow_num(0), arrow_a(1,1),
ref_num(0), ref_a(4,4), temporary_ref(0), trace_p(NULL), border(0), shadow(0) ref_num(0), ref_a(4,4), temporary_ref(0), trace_p(NULL), border(0), shadow(0)
{ {
double x1, y1, x2, y2; double x1, y1, x2, y2;
GlowLine *l1; GlowLine *l1;
if ( !cc) if ( !cc)
return; return;
...@@ -2078,33 +2077,33 @@ int GlowCon::sort_lines(double dest_x, double dest_y, glow_eDirection dest_dir, ...@@ -2078,33 +2077,33 @@ int GlowCon::sort_lines(double dest_x, double dest_y, glow_eDirection dest_dir,
sort_dest = dest_node; sort_dest = dest_node;
if (dest_dir == glow_eDirection_Right && src_dir == glow_eDirection_Left if (dest_dir == glow_eDirection_Right && src_dir == glow_eDirection_Left
&& src_x > dest_x) { && src_x > dest_x) {
glow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
glow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3; ideal_line_cnt = 3;
} else if (dest_dir == glow_eDirection_Right } else if (dest_dir == glow_eDirection_Right
&& src_dir == glow_eDirection_Left && src_x <= dest_x) { && src_dir == glow_eDirection_Left && src_x <= dest_x) {
glow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
glow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h3); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h3);
ideal_line_cnt = 5; ideal_line_cnt = 5;
} else if (dest_dir == glow_eDirection_Left } else if (dest_dir == glow_eDirection_Left
&& src_dir == glow_eDirection_Right && src_x < dest_x) { && src_dir == glow_eDirection_Right && src_x < dest_x) {
glow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
glow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3; ideal_line_cnt = 3;
} else if (dest_dir == glow_eDirection_Left } else if (dest_dir == glow_eDirection_Left
&& src_dir == glow_eDirection_Right && src_x > dest_x) { && src_dir == glow_eDirection_Right && src_x > dest_x) {
glow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
glow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h2); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h2);
ideal_line_cnt = 5; ideal_line_cnt = 5;
} else if (dest_dir == glow_eDirection_Right } else if (dest_dir == glow_eDirection_Right
&& src_dir == glow_eDirection_Right) { && src_dir == glow_eDirection_Right) {
glow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
glow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3; ideal_line_cnt = 3;
} else if (dest_dir == glow_eDirection_Left } else if (dest_dir == glow_eDirection_Left
&& src_dir == glow_eDirection_Left) { && src_dir == glow_eDirection_Left) {
glow_qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2); qsort(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
glow_qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1); qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3; ideal_line_cnt = 3;
} }
......
/**
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* 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 ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. 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
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR 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 ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
#include <stdlib.h>
#include "glow_utils.h"
static void qsort_swp(int, char*, char*);
void glow_qsort(void* basearg, size_t nel, size_t width,
int (*compar)(const void*, const void*))
{
int gap, ngap, i, j;
int t1, t2;
char* jd;
char* base = basearg;
t1 = nel * width;
for (ngap = nel / 2; ngap > 0; ngap = ngap / 2) {
gap = ngap * width;
t2 = gap + width;
jd = base + gap;
for (i = t2; i <= t1; i += width)
for (j = i - t2; j >= 0; j -= gap) {
if ((*compar)(base + j, jd + j) <= 0)
break;
qsort_swp(width, base + j, jd + j);
}
}
}
static void qsort_swp(int w, char* a, char* b)
{
char tmp;
while (w--) {
tmp = *a;
*a++ = *b;
*b++ = tmp;
}
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* 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 ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. 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
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR 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 ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef glow_utils_h
#define glow_utils_h
#if defined __cplusplus
extern "C" {
#endif
void glow_qsort(void* basearg, size_t nel, size_t width,
int (*compar)(const void*, const void*));
#if defined __cplusplus
}
#endif
#endif
...@@ -47,8 +47,6 @@ ...@@ -47,8 +47,6 @@
#include "co_dcli_msg.h" #include "co_dcli_msg.h"
#include "co_string.h" #include "co_string.h"
#include "flow_utils.h"
#include "xtt_item.h" #include "xtt_item.h"
#include "xtt_trace.h" #include "xtt_trace.h"
#include "xtt_xnav_crr.h" #include "xtt_xnav_crr.h"
...@@ -182,7 +180,7 @@ int XNav::help_index(navh_eHelpFile file_type, char* file_name, int pop) ...@@ -182,7 +180,7 @@ int XNav::help_index(navh_eHelpFile file_type, char* file_name, int pop)
sts = navhelp->help_index(file_type, file_name); sts = navhelp->help_index(file_type, file_name);
brow_GetObjectList(brow->ctx, &object_list, &object_cnt); brow_GetObjectList(brow->ctx, &object_list, &object_cnt);
flow_qsort( qsort(
&object_list[2], object_cnt - 2, sizeof(object_list[0]), help_cmp_items); &object_list[2], object_cnt - 2, sizeof(object_list[0]), help_cmp_items);
brow_ResetNodraw(brow->ctx); brow_ResetNodraw(brow->ctx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment