@echo off :: filename: unwrap.btm :: author: Eric Pement :: date: 2012-04-27 19:17 CDT :: requires: getopts, sed setlocal unalias * if "%1" == "/?" .or. "%1" == "-?" .or. "%1" == "--help" goto help :: Check for required programs :: Cannot use %@search[..] because it is not supported in TCC_LE (which sed | ffind /E"external|alias|batch" /B >NUL ) || ( echo ERROR! 'sed' is NOT on the PATH! Exiting... %+ quit) :: Parse switch options using "getopts" (free 4DOS option parser at www.pement.org) set F0=%@truename[%0] set num_opts=Y set str_opts=s call getopts.btm %[%@option[ParameterChar]] if %? == 1 goto help for %a in (%rev_args) do shift /%a :: End the "getopts" block. :: Note: Any and all switches have been removed from the command tail. if "%1" eq "" .and. %_pipe == 0 goto noargs iff defined N .and. %N LT 1 then :: A numeric option cannot be zero (-0) or negative (--32) beep echo Error! Numeric option -n (%n) must be 1 or greater! echo Quitting ... goto end endiff : set %N to 4, set %STR to one space if not defined N set N=4 iff defined LC_s then set STR=%LC_s`` else set STR= `` endiff sed -r ":a; $!N; s/\n%STR{%N}//; ta; P;D" %$ goto end :noargs call error_beep.btm echo `-----[ ERROR! No file to look for, nor any values piped from STDIN! ]-----` echo. :help TEXT UNWRAP.btm - TakeCommand script to "unwrap" lines from stdin or a file Given 2 consecutive lines, if line #2 begins with N spaces (default 4), append line #2 to the end of line #1 and remove the spaces. Usage: unwrap [-switches] [file1 file2 ...] Switches: -N must be a positive integer (default = 4) -s string of 1 or more chars at beginning of line (default = space) Note that 's' will be multiplied by 'N', so to wrap 9 tildes at BOL, enter `-9 -s~`, or `-3 -s "~~~"`, or `-1 -s "~~~~~~~~~" `. ENDTEXT :end unset /q N STR LC_s endlocal