summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2024-12-15 04:06:31 +0100
committerSlávek Banko <slavek.banko@axis.cz>2024-12-15 10:18:46 +0100
commitb471506dcb4441a96185c38f2c23b36369cde61c (patch)
treeadee5c5506e41865c3e87a47c8992db43eb4b6b0
parentd32e6ec571bceb8a041a5d9e3833cd25405a1b40 (diff)
downloadtdebase-b471506dcb4441a96185c38f2c23b36369cde61c.tar.gz
tdebase-b471506dcb4441a96185c38f2c23b36369cde61c.zip
tdeioslave/fish: Use CMake code to generate fishcode.h.
Executable bit on these scripts in the source code is no longer needed. Signed-off-by: Slávek Banko <slavek.banko@axis.cz> (cherry picked from commit 83e4d7076e1e5dfac804c0f89a1fcdf31795671a)
-rw-r--r--tdeioslave/fish/CMakeLists.txt10
-rw-r--r--[-rwxr-xr-x]tdeioslave/fish/fish.pl0
-rw-r--r--tdeioslave/fish/genfishcode.cmake68
-rwxr-xr-xtdeioslave/fish/genfishcode.pl43
4 files changed, 70 insertions, 51 deletions
diff --git a/tdeioslave/fish/CMakeLists.txt b/tdeioslave/fish/CMakeLists.txt
index d7a30416b..c228c27ca 100644
--- a/tdeioslave/fish/CMakeLists.txt
+++ b/tdeioslave/fish/CMakeLists.txt
@@ -35,8 +35,14 @@ tde_create_translated_desktop(
##### tdeio_fish (module) #########################
add_custom_command( OUTPUT fishcode.h
- COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/genfishcode.pl ${CMAKE_CURRENT_SOURCE_DIR}/fish.pl > fishcode.h
- DEPENDS fish.pl )
+ COMMAND ${CMAKE_COMMAND}
+ -DMASTER_CURRENT_SOURCE_DIR:FILEPATH="${CMAKE_CURRENT_SOURCE_DIR}"
+ -DFISH_CODE_SOURCE:FILEPATH="fish.pl"
+ -DFISH_CODE_OUTPUT:FILEPATH="fishcode.h"
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/genfishcode.cmake"
+ COMMENT "Generate fishcode.h"
+ DEPENDS fish.pl
+)
set_property( SOURCE fish.cpp APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/fishcode.h )
diff --git a/tdeioslave/fish/fish.pl b/tdeioslave/fish/fish.pl
index ace813bb9..ace813bb9 100755..100644
--- a/tdeioslave/fish/fish.pl
+++ b/tdeioslave/fish/fish.pl
diff --git a/tdeioslave/fish/genfishcode.cmake b/tdeioslave/fish/genfishcode.cmake
index 9b35a51ec..e66df099b 100644
--- a/tdeioslave/fish/genfishcode.cmake
+++ b/tdeioslave/fish/genfishcode.cmake
@@ -1,8 +1,64 @@
-#!/bin/sh
+#################################################
+#
+# (C) 2024 Slávek Banko
+# slavek (DOT) banko (AT) axis.cz
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
-SUM=$( @MD5SUM@ @CMAKE_CURRENT_SOURCE_DIR@/fish.pl | cut -d ' ' @MD5SUM_CUT@ )
+# check and set variables
+if( NOT "${MASTER_CURRENT_SOURCE_DIR}" STREQUAL "" )
+ set( CMAKE_CURRENT_SOURCE_DIR "${MASTER_CURRENT_SOURCE_DIR}" )
+endif()
+if( "${FISH_CODE_SOURCE}" STREQUAL "" )
+ set( FISH_CODE_SOURCE "fish.pl" )
+endif()
+if( "${FISH_CODE_OUTPUT}" STREQUAL "" )
+ set( FISH_CODE_OUTPUT "fishcode.h" )
+endif()
+if( NOT IS_ABSOLUTE ${FISH_CODE_SOURCE} )
+ set( FISH_CODE_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/${FISH_CODE_SOURCE}" )
+endif()
+if( NOT IS_ABSOLUTE ${FISH_CODE_OUTPUT} )
+ set( FISH_CODE_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FISH_CODE_OUTPUT}" )
+endif()
+if( NOT EXISTS ${FISH_CODE_SOURCE} )
+ message( FATAL_ERROR "Source file ${FISH_CODE_SOURCE} not exists!" )
+endif()
-#echo "#define CHECKSUM "\"$SUM\"" > fishcode.h
-#echo 'static const char *fishCode(' >> fishcode.h
-#sed -e 's/\\/\\\\/g;s/"/\\"/g;s/^[ ]*/"/;/^"# /d;s/[ ]*$$/\\n"/;/^"\\n"$$/d;s/{CHECKSUM}/'$$SUM'/;' @CMAKE_CURRENT_SOURCE_DIR@/fish.pl >> fishcode.h
-#echo ');' >> fishcode.h
+# load fish code source
+file( READ ${FISH_CODE_SOURCE} _fish_code )
+string( REGEX REPLACE "[^\n]" "" _fish_len ${_fish_code} )
+string( LENGTH "+${_fish_len}" _fish_len )
+string( MD5 _fish_md5 "${_fish_code}" )
+
+# prepare for C code
+set( _fish_pos 0 )
+set( _fish_output "\
+#define CHECKSUM \"${_fish_md5}\"
+static const char *fishCode(
+")
+string( REGEX REPLACE "\\\\" "\\\\\\\\" _fish_code "${_fish_code}" )
+string( REGEX REPLACE "\"" "\\\\\"" _fish_code "${_fish_code}" )
+while( _fish_pos LESS ${_fish_len} )
+ # pick line
+ string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\1" _fish_line "${_fish_code}" )
+ string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\2" _fish_code "${_fish_code}" )
+ math( EXPR _fish_pos "${_fish_pos}+1" )
+
+ # skip comments and empty lines
+ string( REGEX REPLACE "^[ \t]+" "" _fish_line "${_fish_line}" )
+ if( "${_fish_line}" STREQUAL "" OR "${_fish_line}" MATCHES "^# " )
+ continue()
+ endif()
+
+ # add line to output
+ set( _fish_output "${_fish_output}\"${_fish_line}\\n\"\n" )
+endwhile()
+set( _fish_output "${_fish_output});\n" )
+
+# write code to output file
+file( WRITE ${FISH_CODE_OUTPUT} "${_fish_output}" )
diff --git a/tdeioslave/fish/genfishcode.pl b/tdeioslave/fish/genfishcode.pl
deleted file mode 100755
index 60dfff8de..000000000
--- a/tdeioslave/fish/genfishcode.pl
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-
-use Digest::MD5;
-
-sub md5sum {
- my $filename = shift;
- my $digest;
- eval {
- open( my $FILE, '<', $filename )
- or die "Can't find file $filename\n";
- my $ctx = Digest::MD5->new;
- $ctx->addfile($FILE);
- $digest = $ctx->hexdigest;
- close($FILE);
- };
- if ($@) {
- warn $@;
- }
- return $digest;
-}
-
-my $file = $ARGV[0] or die "Missing filename argument";
-
-my $fish_md5 = md5sum($file)
- or die "Couldn't compute MD5 for some reason\n";
-print qq{#define CHECKSUM "$fish_md5"\n};
-print qq{static const char *fishCode(\n};
-
-open( my $FISH, "<", "$file" ) or die "Can't open $file\n";
-while (<$FISH>) {
- chomp;
- s|\\|\\\\|g;
- s|"|\\"|g;
- s/^\s*/"/;
- next if /^"# /;
- s/\s*$/\\n"/;
- next if /^"\\n"$/;
- print "$_\n";
-}
-close($FISH);
-print qq{);\n};