Commit 99a78145 authored by Claes Sjöfors's avatar Claes Sjöfors

Wb build directories, BuildConvert added

parent 925420fe
!
! 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.
!
! pwrb_c_buildconvert.wb_load -- Defines the class BuildConvert.
!
SObject pwrb:Class
!/**
! @Version 1.0
! @Group ProjectConfiguration
! @Summary Configures copy of files with conversion from source to build tree.
! The BuildCopy object configures copying of files with conversion from
! source to build tree.
!
! One BuildConvert object causes one or several files (with wildcard
! specification) to be copied from a directory in the source tree to the
! build tree.
!
! The object reside in the project volume beneath an BuildDirectory object.
!
! The copy is carried out when Build Directories in the configurator menu
! is activated, or when the node is built.
!
! If the Options attribute in the BuildDirectory object is set to BuildBeforeNode
! the copy is performed automatically before a node is built.
!
! @b See also
! @classlink BuildConfig pwrb_buildconfig.html
! @classlink BuildDirectory pwrb_builddirectory.html
! @classlink BuildMake pwrb_buildmake.html
! @classlink BuildExecute pwrb_buildexecute.html
!*/
Object BuildConvert $ClassDef 719
Body SysBody
Attr Editor = pwr_eEditor_AttrEd
Attr Method = pwr_eMethod_RtAndDevBodies
EndBody
Object DevBody $ObjBodyDef 2
!/**
! Type of conversion.
!*/
Object Conversion $Attribute 1
Body SysBody
Attr TypeRef = "pwrb:Type-FileConvertEnum"
EndBody
EndObject
!/**
! @Summary Source file specification.
! Source file specification.
! The asterisk (*) wild card character can be used in the file
! specification.
!
! Example
! $pwrp_load/*.pwg
!*/
Object Source $Attribute 2
Body SysBody
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
!/**
! Target file specification.
!*/
Object Target $Attribute 3
Body SysBody
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
EndObject
EndObject
EndSObject
!
! 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.
!
! pwrb_fileconvertenum.wb_load -- Defines the enum type FileConvertEnum
!
SObject pwrb:Type
!/**
! @Version 1.0
! @Group Types
! File conversion type.
!
! @b See also
! @classlink BuildConvert pwrb_buildconvert.html
!*/
Object FileConvertEnum $TypeDef 90
Body SysBody
Attr TypeRef = "pwrs:Type-$Enum"
Attr PgmName = "FileConvertEnum"
EndBody
!/**
! No conversion..
!*/
Object No $Value
Body SysBody
Attr PgmName = "No"
Attr Text = "No"
Attr Value = 0
EndBody
EndObject
!/**
! Convert from ISO-8859-1 to UTF-8.
!*/
Object ISO88591_UTF8 $Value
Body SysBody
Attr PgmName = "ISO88591_UTF8"
Attr Text = "ISO-8859-1 to UTF-8"
Attr Value = 1
EndBody
EndObject
EndObject
EndSObject
...@@ -668,6 +668,7 @@ palette ProjectNavigatorPalette ...@@ -668,6 +668,7 @@ palette ProjectNavigatorPalette
{ {
class BuildConfig class BuildConfig
class BuildDirectory class BuildDirectory
class BuildConvert
class BuildCopy class BuildCopy
class BuildMake class BuildMake
class BuildExecute class BuildExecute
......
...@@ -1884,7 +1884,7 @@ void wb_build::directories(char* dir, bld_ePass pass) ...@@ -1884,7 +1884,7 @@ void wb_build::directories(char* dir, bld_ePass pass)
{ {
pwr_tFileName fname; pwr_tFileName fname;
char line[400]; char line[400];
char line_item[4][250]; char line_item[5][250];
pwr_tFileName found_file; pwr_tFileName found_file;
int num; int num;
int sts; int sts;
...@@ -1998,6 +1998,95 @@ void wb_build::directories(char* dir, bld_ePass pass) ...@@ -1998,6 +1998,95 @@ void wb_build::directories(char* dir, bld_ePass pass)
} }
dcli_search_file(line_item[1], found_file, DCLI_DIR_SEARCH_END); dcli_search_file(line_item[1], found_file, DCLI_DIR_SEARCH_END);
} else if (streq(cdh_Low(line_item[0]), "buildconvert")) {
pwr_tFileConvertEnum conversion;
if (num != 5) {
printf("File corrupt " pwr_cNameDistribute);
continue;
}
if (sscanf(line_item[2], "%d", &conversion) != 1) {
printf("File corrupt " pwr_cNameDistribute);
continue;
}
if ((pass == bld_ePass_BeforeNode
&& !(current_options & pwr_mBuildDirectoryMask_BuildBeforeNode))
|| (pass == bld_ePass_AfterNode
&& !(current_options
& pwr_mBuildDirectoryMask_BuildAfterNode)))
continue;
for (sts
= dcli_search_file(line_item[3], found_file, DCLI_DIR_SEARCH_INIT);
ODD(sts); sts
= dcli_search_file(line_item[3], found_file, DCLI_DIR_SEARCH_NEXT)) {
// Check if file should be updated
int update = 0;
pwr_tFileName source, target;
pwr_tFileName target_dir;
pwr_tTime source_time, target_time;
char* s;
strncpy(source, found_file, sizeof(source));
strncpy(target, line_item[4], sizeof(target));
sts = dcli_file_time(source, &source_time);
if (target[strlen(target) - 1] == '/') {
// Target is a directory, add file name
char* s = strrchr(source, '/');
if (!s)
strncat(target, source, sizeof(target) - strlen(target) - 1);
else
strncat(target, s + 1, sizeof(target) - strlen(target) - 1);
}
dcli_translate_filename(target, target);
sts = dcli_file_time(target, &target_time);
if (ODD(sts) && time_Acomp(&source_time, &target_time) != 1)
update = 0;
else
update = 1;
if (!opt.force && !update)
continue;
if (EVEN(sts)) {
// Check that directory exist, create if it doesn't
strcpy(target_dir, target);
if ((s = strrchr(target_dir, '/'))) {
*s = 0;
sts = dcli_file_time(target_dir, &target_time);
if (EVEN(sts)) {
sprintf(cmd, "mkdir -p %s", target_dir);
system(cmd);
}
}
}
switch (conversion) {
case pwr_eFileConvertEnum_No:
sprintf(cmd, "cp %s %s", source, target);
break;
case pwr_eFileConvertEnum_ISO88591_UTF8:
sprintf(cmd, "iconv -f ISO-8859-1 -t UTF-8 < %s > %s", source, target);
break;
}
system(cmd);
sprintf(
cmd, "Build: convert %s %s -> %s", line_item[2], source, target);
MsgWindow::message('I', cmd, msgw_ePop_No);
// wb_log::log( wlog_eCategory_GeBuild, name, 0);
if (m_sts != PWRB__MAKEUPDATED)
m_sts = PWRB__SUCCESS;
}
dcli_search_file(line_item[2], found_file, DCLI_DIR_SEARCH_END);
} else if (streq(cdh_Low(line_item[0]), "buildmake")) { } else if (streq(cdh_Low(line_item[0]), "buildmake")) {
if (num != 4) { if (num != 4) {
printf("File corrupt " pwr_cNameDistribute); printf("File corrupt " pwr_cNameDistribute);
......
...@@ -673,7 +673,7 @@ void WbExpWNav::show_builddir() ...@@ -673,7 +673,7 @@ void WbExpWNav::show_builddir()
{ {
pwr_tFileName fname; pwr_tFileName fname;
char line[400]; char line[400];
char line_item[4][250]; char line_item[5][250];
pwr_tFileName found_file; pwr_tFileName found_file;
int num; int num;
int sts; int sts;
...@@ -748,7 +748,70 @@ void WbExpWNav::show_builddir() ...@@ -748,7 +748,70 @@ void WbExpWNav::show_builddir()
continue; continue;
} }
dir->copy_insert(source, target, update); dir->copy_insert(source, target, pwr_eFileConvertEnum_No, update);
if (update)
dir->update = 1;
}
dcli_search_file(line_item[1], found_file, DCLI_DIR_SEARCH_END);
ItemExp* item = new ItemExp(
this, found_file, line_item[1], 0, 0, flow_eDest_IntoLast);
if (dir_update)
brow_SetRadiobutton(item->node, 0, 1);
}
else if (streq(cdh_Low(line_item[0]), "buildconvert")) {
int dir_update = 0;
pwr_tFileConvertEnum conversion;
if (num != 5) {
printf("File corrupt " pwr_cNameDistribute);
continue;
}
if (sscanf(line_item[2], "%d", &conversion) != 1) {
printf("File corrupt " pwr_cNameDistribute);
continue;
}
for (sts
= dcli_search_file(line_item[3], found_file, DCLI_DIR_SEARCH_INIT);
ODD(sts); sts
= dcli_search_file(line_item[3], found_file, DCLI_DIR_SEARCH_NEXT)) {
// Check if file should be updated
int update = 0;
pwr_tFileName source, target;
pwr_tTime source_time, target_time;
strncpy(source, found_file, sizeof(source));
strncpy(target, line_item[4], sizeof(target));
sts = dcli_file_time(source, &source_time);
if (target[strlen(target) - 1] == '/') {
// Target is a directory, add file name
char* s = strrchr(source, '/');
if (!s)
strncat(target, source, sizeof(target) - strlen(target) - 1);
else
strncat(target, s + 1, sizeof(target) - strlen(target) - 1);
}
dcli_translate_filename(target, target);
sts = dcli_file_time(target, &target_time);
if (ODD(sts) && time_Acomp(&source_time, &target_time) != 1)
update = 0;
else
update = 1;
ExpWDir* dir = dir_find(line_item[1]);
if (!dir) {
printf("File corrupt " pwr_cNameDistribute);
continue;
}
dir->copy_insert(source, target, conversion, update);
if (update) if (update)
dir->update = 1; dir->update = 1;
} }
...@@ -893,11 +956,13 @@ ExpWDir* WbExpWNav::dir_insert(char* name, char* options_str, char* description) ...@@ -893,11 +956,13 @@ ExpWDir* WbExpWNav::dir_insert(char* name, char* options_str, char* description)
return dir; return dir;
} }
ExpWCopy* ExpWDir::copy_insert(char* source, char* target, int update) ExpWCopy* ExpWDir::copy_insert(char* source, char* target, pwr_tFileConvertEnum conversion,
int update)
{ {
ExpWCopy* copy = new ExpWCopy(); ExpWCopy* copy = new ExpWCopy();
strncpy(copy->source, source, sizeof(copy->source)); strncpy(copy->source, source, sizeof(copy->source));
strncpy(copy->target, target, sizeof(copy->target)); strncpy(copy->target, target, sizeof(copy->target));
copy->conversion = conversion;
copy->update = update; copy->update = update;
if (!copylist) if (!copylist)
...@@ -994,8 +1059,16 @@ pwr_tStatus WbExpWNav::exp() ...@@ -994,8 +1059,16 @@ pwr_tStatus WbExpWNav::exp()
if (!cp->update) if (!cp->update)
continue; continue;
sprintf(cmd, "cp %s %s", cp->source, cp->target); switch (cp->conversion) {
printf("%s\n", cmd); case pwr_eFileConvertEnum_No:
sprintf(cmd, "cp %s %s", cp->source, cp->target);
printf("%s\n", cmd);
break;
case pwr_eFileConvertEnum_ISO88591_UTF8:
sprintf(cmd, "iconv -f ISO-8859-1 -t UTF8 < %s > %s", cp->source, cp->target);
printf("%s\n", cmd);
break;
}
sts = system(cmd); sts = system(cmd);
if (sts != 0) { if (sts != 0) {
// Check that directory exist, create if it doesn't // Check that directory exist, create if it doesn't
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
/* wb_expwnav.h -- Backupfile display window */ /* wb_expwnav.h -- Backupfile display window */
#include "flow_browapi.h" #include "flow_browapi.h"
#include "pwr_baseclasses.h"
#include "wb_bck.h" #include "wb_bck.h"
typedef enum { typedef enum {
...@@ -80,6 +80,7 @@ public: ...@@ -80,6 +80,7 @@ public:
ExpWCopy* prev; ExpWCopy* prev;
pwr_tFileName source; pwr_tFileName source;
pwr_tFileName target; pwr_tFileName target;
pwr_tFileConvertEnum conversion;
ExpWCopy() : next(0), prev(0) ExpWCopy() : next(0), prev(0)
{ {
...@@ -127,7 +128,8 @@ public: ...@@ -127,7 +128,8 @@ public:
options(0) options(0)
{ {
} }
ExpWCopy* copy_insert(char* source, char* target, int update); ExpWCopy* copy_insert(char* source, char* target, pwr_tFileConvertEnum conversion,
int update);
ExpWMake* make_insert(char* dir, char* makefile, int update); ExpWMake* make_insert(char* dir, char* makefile, int update);
ExpWExec* exec_insert(char* dir, char* command, int update); ExpWExec* exec_insert(char* dir, char* command, int update);
}; };
......
...@@ -2110,6 +2110,9 @@ pwr_tStatus lfu_SaveDirectoryVolume( ...@@ -2110,6 +2110,9 @@ pwr_tStatus lfu_SaveDirectoryVolume(
nc.isfriend = 1; nc.isfriend = 1;
sts = ldh_ObjidToName(ldhses, fnodeo.oid(), ldh_eName_Object,
nodeconfig_name, sizeof(nodeconfig_name), &size);
// Get attribute NodeName // Get attribute NodeName
a = sp->attribute(fnodeo.oid(), "RtBody", "NodeName"); a = sp->attribute(fnodeo.oid(), "RtBody", "NodeName");
if (!a) { if (!a) {
...@@ -3359,6 +3362,40 @@ pwr_tStatus lfu_SaveDirectoryVolume( ...@@ -3359,6 +3362,40 @@ pwr_tStatus lfu_SaveDirectoryVolume(
free(target_ptr); free(target_ptr);
break; break;
} }
case pwr_cClass_BuildConvert: {
char target_array[10][80];
int target_cnt;
pwr_tEnum *conversion_ptr;
sts = ldh_GetObjectPar(
ldhses, coid, "DevBody", "Conversion", (char**)&conversion_ptr, &size);
if (EVEN(sts))
return sts;
sts = ldh_GetObjectPar(
ldhses, coid, "DevBody", "Source", (char**)&source_ptr, &size);
if (EVEN(sts))
return sts;
sts = ldh_GetObjectPar(
ldhses, coid, "DevBody", "Target", (char**)&target_ptr, &size);
if (EVEN(sts))
return sts;
// Target can be a list
target_cnt = dcli_parse(target_ptr, ",", "", (char*)target_array,
sizeof(target_array) / sizeof(target_array[0]),
sizeof(target_array[0]), 0);
for (int i = 0; i < target_cnt; i++) {
str_trim(target_array[i], target_array[i]);
fprintf(file, "buildconvert %s %d %s%s %s\n", cdh_Low(fullname), *conversion_ptr, dir,
source_ptr, target_array[i]);
}
free(conversion_ptr);
free(source_ptr);
free(target_ptr);
break;
}
case pwr_cClass_BuildExecute: { case pwr_cClass_BuildExecute: {
char* command_ptr; char* command_ptr;
......
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