Commit a911da1b authored by Christoffer Ackelman's avatar Christoffer Ackelman

Use qsort from stdlib instead of custom implementation.

parent 63c120eb
......@@ -192,8 +192,6 @@ static int logging_page = 0;
* prototypes____________________________________________________*/
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_plclist_add(pwr_tObjid plc_objid,
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,
#define GRAFCET_PAGESIZE 20
/*************************************************************************
*
* 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)
static int rttsys_plclist_cmp(const void* p1, const void* p2)
{
int i, j;
char *str1, *str2;
rttsys_t_plcpgm_list dum;
rttsys_t_plcpgm_list* plclist_ptr;
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;
char* str1 = ((rttsys_t_plcpgm_list*) p1)->name;
char* str2 = ((rttsys_t_plcpgm_list*) p2)->name;
if (*str2 == 0)
return 0;
return strcmp(str1, str2);
}
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, *str2;
rttsys_t_step_list dum;
rttsys_t_step_list* steplist_ptr;
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;
char* str1 = ((rttsys_t_step_list*) p1)->name;
char* str2 = ((rttsys_t_step_list*) p2)->name;
if (*str2 == 0)
return 0;
return strcmp(str1, str2);
}
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,
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;
menu_ptr = menulist;
for (i = grafcet_page * GRAFCET_PAGESIZE;
......@@ -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);
if (EVEN(sts))
return sts;
rttsys_steplist_bubblesort(plclist_ptr->steps, plclist_ptr->step_count);
rttsys_steplist_bubblesort(plclist_ptr->orders, plclist_ptr->order_count);
qsort(plclist_ptr->steps, plclist_ptr->step_count, sizeof(rttsys_t_step_list), rttsys_steplist_cmp);
qsort(plclist_ptr->orders, plclist_ptr->order_count, sizeof(rttsys_t_step_list), rttsys_steplist_cmp);
i = 0;
/* 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,
if (EVEN(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;
menu_ptr = menulist;
plclist_ptr = plclist;
......@@ -3362,7 +3311,7 @@ int RTTSYS_PLCTHREAD(menu_ctx ctx, int event, char* parameter_ptr,
return sts;
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);
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,
objectlist_count /= 2;
rttsys_objectlist_modname_plc(objectlist, objectlist_count);
/* rttsys_steplist_bubblesort( objectlist, objectlist_count);
*/
rttsys_pid_update(ctx, objectlist, objectlist_count, page);
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,
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, *str2;
rttsys_t_cell_list dum;
rttsys_t_cell_list* cellist_ptr;
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;
char* str1 = ((rttsys_t_cell_list*) p1)->name;
char* str2 = ((rttsys_t_cell_list*) p2)->name;
if (*str2 == 0)
return 0;
return strcmp(str1, str2);
}
#define NMPSCELL_PAGESIZE 19
......@@ -4815,8 +4745,7 @@ int RTTSYS_NMPSCELL(menu_ctx ctx, int event, char* parameter_ptr,
if (EVEN(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
......
......@@ -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, *str2;
rtt_t_menu dum;
rtt_t_menu* menu_ptr;
char* str1 = ((rtt_t_menu*) p1)->text;
char* str2 = ((rtt_t_menu*) p2)->text;
if (*str2 == 0)
return 0;
return strcmp(str1, str2);
}
int rtt_menu_bubblesort(rtt_t_menu* menulist)
{
/* Get the size of the menu */
menu_ptr = menulist;
size = 0;
rtt_t_menu* menu_ptr = menulist;
int size = 0;
while (menu_ptr->text[0] != 0) {
menu_ptr++;
size++;
}
for (i = size - 1; i > 0; i--) {
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++;
}
}
qsort(menulist, size, sizeof(rtt_t_menu), rtt_menu_cmp);
return RTT__SUCCESS;
}
......@@ -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, *str2;
rtt_t_menu_upd dum;
rtt_t_menu_upd* menu_ptr;
char* str1 = ((rtt_t_menu_upd*) p1)->text;
char* str2 = ((rtt_t_menu_upd*) p2)->text;
if (*str2 == 0)
return 0;
return strcmp(str1, str2);
}
int rtt_menu_upd_bubblesort(rtt_t_menu_upd* menulist)
{
/* Get the size of the menu */
menu_ptr = menulist;
size = 0;
rtt_t_menu_upd* menu_ptr = menulist;
int size = 0;
while (menu_ptr->text[0] != 0) {
menu_ptr++;
size++;
}
for (i = size - 1; i > 0; i--) {
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++;
}
}
qsort(menulist, size, sizeof(rtt_t_menu_upd), rtt_menu_upd_cmp);
return RTT__SUCCESS;
}
......
......@@ -994,7 +994,7 @@ pwr_tStatus WFoeQt::create_window(int x_top, int y_top, int width_adb,
"$pwr_exe/foe_redraw.png");
// 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");
// Singlelinetext button
......
......@@ -729,6 +729,8 @@ XttQt::XttQt(int argc, char* argv[], int* return_sts)
statusbar->show();
wow = new CoWowQt(toplevel);
xnav = new XNavQt(this, xnav_form, "Plant", &brow_widget,
(xnav_sStartMenu*)root_menu, opplace_str, op_close_button, &sts);
xnav->message_cb = &xtt_message_cb;
......
......@@ -44,7 +44,6 @@
#include "cow_xhelpnav_gtk.h"
#include "flow_browwidget_gtk.h"
#include "flow_utils.h"
extern "C" {
#include "co_api.h"
......
......@@ -56,7 +56,6 @@
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "flow_browwidget_motif.h"
#include "flow_utils.h"
#include "cow_xhelpnav_motif.h"
......
......@@ -44,8 +44,6 @@
#include "cow_xhelpnav.h"
#include "flow_utils.h"
#include "xnav_bitmap_morehelp8.h"
#include "xnav_bitmap_morehelp10.h"
#include "xnav_bitmap_morehelp12.h"
......@@ -1399,8 +1397,7 @@ int CoXHelpNav::help_index(
brow_GetObjectList(brow->ctx, &object_list, &object_cnt);
flow_qsort(
&object_list[2], object_cnt - 2, sizeof(object_list[0]), help_cmp_items);
qsort(&object_list[2], object_cnt - 2, sizeof(object_list[0]), help_cmp_items);
brow_ResetNodraw(brow->ctx);
brow_Redraw(brow->ctx, 0);
......
......@@ -45,7 +45,6 @@
#include "flow_conpoint.h"
#include "flow_draw.h"
#include "flow_text.h"
#include "flow_utils.h"
#include "flow_msg.h"
#define LINE_TABLE_SIZE 500
......@@ -2033,33 +2032,33 @@ int FlowCon::sort_lines(double dest_x, double dest_y, flow_eDirection dest_dir,
sort_dest = dest_node;
if (dest_dir == flow_eDirection_Right && src_dir == flow_eDirection_Left
&& src_x > dest_x) {
flow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3;
} else if (dest_dir == flow_eDirection_Right
&& src_dir == flow_eDirection_Left && src_x <= dest_x) {
flow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h3);
ideal_line_cnt = 5;
} else if (dest_dir == flow_eDirection_Left
&& src_dir == flow_eDirection_Right && src_x < dest_x) {
flow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3;
} else if (dest_dir == flow_eDirection_Left
&& src_dir == flow_eDirection_Right && src_x > dest_x) {
flow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h2);
ideal_line_cnt = 5;
} else if (dest_dir == flow_eDirection_Right
&& src_dir == flow_eDirection_Right) {
flow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3;
} else if (dest_dir == flow_eDirection_Left
&& src_dir == flow_eDirection_Left) {
flow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
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 @@
#include <stdlib.h>
#include <algorithm>
#include "pwr_baseclasses.h"
#include "co_cdh.h"
......@@ -309,17 +311,9 @@ public:
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--) {
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;
}
}
}
return strcmp(p1.name, p2.name);
}
//
......@@ -1386,7 +1380,7 @@ int ItemLocalSubGraphs::open_children(
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++) {
dcli_parse_filename(fvect[i].name, dev, dir, file, type, &version);
......
......@@ -44,7 +44,6 @@
#include "glow_conpoint.h"
#include "glow_draw.h"
#include "glow_text.h"
#include "glow_utils.h"
#include "glow_growgroup.h"
#include "glow_growconglue.h"
#include "glow_msg.h"
......@@ -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) :
ctx(glow_ctx), cc(con_class),
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),
ref_num(0), ref_a(4,4), temporary_ref(0), trace_p(NULL), border(0), shadow(0)
{
double x1, y1, x2, y2;
GlowLine *l1;
GlowLine *l1;
if ( !cc)
return;
......@@ -2078,33 +2077,33 @@ int GlowCon::sort_lines(double dest_x, double dest_y, glow_eDirection dest_dir,
sort_dest = dest_node;
if (dest_dir == glow_eDirection_Right && src_dir == glow_eDirection_Left
&& src_x > dest_x) {
glow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3;
} else if (dest_dir == glow_eDirection_Right
&& src_dir == glow_eDirection_Left && src_x <= dest_x) {
glow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h3);
ideal_line_cnt = 5;
} else if (dest_dir == glow_eDirection_Left
&& src_dir == glow_eDirection_Right && src_x < dest_x) {
glow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3;
} else if (dest_dir == glow_eDirection_Left
&& src_dir == glow_eDirection_Right && src_x > dest_x) {
glow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h2);
ideal_line_cnt = 5;
} else if (dest_dir == glow_eDirection_Right
&& src_dir == glow_eDirection_Right) {
glow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v1);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
ideal_line_cnt = 3;
} else if (dest_dir == glow_eDirection_Left
&& src_dir == glow_eDirection_Left) {
glow_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(vert_line, vert_line_cnt, sizeof(vert_line[0]), con_cmp_v2);
qsort(horiz_line, horiz_line_cnt, sizeof(horiz_line[0]), con_cmp_h1);
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 @@
#include "co_dcli_msg.h"
#include "co_string.h"
#include "flow_utils.h"
#include "xtt_item.h"
#include "xtt_trace.h"
#include "xtt_xnav_crr.h"
......@@ -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);
brow_GetObjectList(brow->ctx, &object_list, &object_cnt);
flow_qsort(
qsort(
&object_list[2], object_cnt - 2, sizeof(object_list[0]), help_cmp_items);
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