Skip to content

Instantly share code, notes, and snippets.

@3F
Created April 19, 2015 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3F/c98f172cf97f647c8470 to your computer and use it in GitHub Desktop.
Save 3F/c98f172cf97f647c8470 to your computer and use it in GitHub Desktop.
Parsing of .html files and generating cshelp.h with C++ macro definitions - /replacement gen_cshelp.py on bash & batch commands - https://bitbucket.org/3F/featuresdc/issue/1/ :: Old sample. Netbeans
#!/bin/sh
# range of 11000 - 11999
# replacement help/gen_cshelp.py
# details on https://bitbucket.org/3F/featuresdc/issue/1/help-cshelph-dcpp-version-revnoinc
##### variables #####
range_begin=11000
workdir=../../../src/help
foutput=cshelp.h
newline="\n"
### processing #
# yep, simply... in compare with cshelp.bat =_=
cd $workdir
# init
output=""
dnum=$range_begin
output+="// generated by cshelp.sh$newline"
output+="#ifndef DCPLUSPLUS_HELP_CSHELP_H$newline"
output+="#define DCPLUSPLUS_HELP_CSHELP_H$newline"
#--only-matching : for const in $( grep -hoisE "cshelp\s*=\s*([^ ]+)" *.html | sed -r "s#cshelp\s*=\s*['\"]([^'\"]+).*#\1#i")
for const in $( grep -hisE "cshelp\s*=\s*([^ ]+)" *.html | sed -r "s#.*cshelp\s*=\s*['\"]([^'\"]+).*#\1#i")
do
output+="\t#define $const $dnum$newline"
((dnum++))
done
output+="#endif"
### finalize #
echo -e $output > $foutput
echo $((dnum-range_begin)) done.
@echo off
REM range of 11000 - 11999
REM replacement help/gen_cshelp.py
REM details on https://bitbucket.org/3F/featuresdc/issue/1/help-cshelph-dcpp-version-revnoinc
REM ##### variables #####
set range_begin=11000
set workdir=../../../src/help
set output=cshelp.h
REM ### processing #
setlocal enableDelayedExpansion
cd %workdir%
echo // generated by cshelp.bat > %output%
echo #ifndef DCPLUSPLUS_HELP_CSHELP_H >> %output%
echo #define DCPLUSPLUS_HELP_CSHELP_H >> %output%
rem init
set search_after=2
set /a dnum=range_begin
set /a pos=%search_after%
set token_pos=!pos!
for /F "tokens=2 delims=<" %%l in ('findstr /r "cshelp.*=.*\"[^\"]*" *.html') do (
set line=%%l
set /a pos=%search_after%
set token_pos=!pos!
rem echo !line!
call :handler
)
echo #endif >> %output%
REM ### finalize #
set /a count=!dnum!-!range_begin!
echo !count! done.
rem exit /b 0
exit 0
REM ### logics #
:handler
for /F delims^=^"^ tokens^=^%token_pos% %%d in ("!line!") do (
set verify=%%d
if NOT "!verify:~0,4!" == "IDH_" (
set /a pos+=1
set token_pos=!pos!
rem echo %token_pos% :: !verify:~0,4! === IDH_
rem with changed offset:
goto handler
) else (
echo #define %%d !dnum! >> %output%
set /a dnum+=1
)
)
# bin
OUTPUT_FILE_NAME=DCPlusPlus
OUTPUT_FILE_NAME_STRIP=DCPlusPlus_stripped
OUTPUT_FILE_EXT_E=.exe
OUTPUT_FILE_EXT_S=.pdb
# dependencies
PATH_DEP_CSHELP=../../../src/help/cshelp.h
# build
build: .build-post
.build-pre: .check-exist .gpch
.check-exist:
@if [ ! -f $(PATH_DEP_CSHELP) ]; then \
echo "generate cshelp.h ..."; \
if [ $(shell echo $(CND_PLATFORM_${CONF}) | sed -r 's/(\S{5}).*/\L\1/') = 'mingw' ] ; then \
sh cshelp.sh; \
else \
cmd //c start "cshelp.bat"; \
fi; \
fi;
.gpch:
@if [ $(shell echo ${CONF} | sed -r 's/(\S{5}).*/\L\1/') = 'pch__' ] ; then \
${MAKE} -f nbproject/Makefile-${CONF}.mk "stdafx.h.gch"; \
fi;
.build-post: .build-impl
strip --only-keep-debug $(PATH_TO_BUILD)/_bin_/${CONF}/$(OUTPUT_FILE_NAME)$(OUTPUT_FILE_EXT_E) -o $(PATH_TO_BUILD)/_bin_/${CONF}/$(OUTPUT_FILE_NAME)$(OUTPUT_FILE_EXT_S)
strip $(PATH_TO_BUILD)/_bin_/${CONF}/$(OUTPUT_FILE_NAME)$(OUTPUT_FILE_EXT_E) -o $(PATH_TO_BUILD)/_bin_/${CONF}/$(OUTPUT_FILE_NAME_STRIP)$(OUTPUT_FILE_EXT_E)
# clean
clean: .clean-post
rm -f $(PATH_TO_BUILD)/_bin_/${CONF}/$(OUTPUT_FILE_NAME)$(OUTPUT_FILE_EXT_S)
rm -f $(PATH_TO_BUILD)/_bin_/${CONF}/$(OUTPUT_FILE_NAME_STRIP)$(OUTPUT_FILE_EXT_E)
.clean-pre:
# Add your pre 'clean' code here...
.clean-post: .clean-impl
rm -f $(PATH_DEP_CSHELP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment