Re: OT: konverzia typu komentárov v zdrojovom kóde
Peter Berec
p.berec na bonum.sk
Neděle Prosinec 19 11:39:15 CET 2021
Ďakujem, toto funguje super !
Peter
Dňa 17. 12. 2021 o 15:30 T. Meinlschmidt napísal(a):
> staci jen sed :)
>
> $ cat a.txt
> 1
> 2
> /**
> * Copyright (c) 2014
> * All rights reserved.
> * bla bla many lines like this
> * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
> OF THE
> * POSSIBILITY OF SUCH DAMAGE.
> */
> 3
> 4
> /* and here is another comment
> * you presumably want to keep
> */
> 5
> 6
>
> $ cat a.txt | sed '/\/\*/,/\*\//s/^\(.\)/\/\/ \1/'
> 1
> 2
> // /**
> // * Copyright (c) 2014
> // * All rights reserved.
> // * bla bla many lines like this
> // * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
> ADVISED OF THE
> // * POSSIBILITY OF SUCH DAMAGE.
> // */
> 3
> 4
> // /* and here is another comment
> // * you presumably want to keep
> // */
> 5
> 6
>
> tm
>
>
> Dne 2021-12-17 14:30, Petr Simek napsal:
>> Zdravim
>>
>> zkusil jsem si vytvorit soubor x.sht s radky :
>>
>> normalni radek 1
>> /* comment line 1
>> comment line 2
>> comment line
>> */
>> normalni radek 2
>>
>> a bash skript x.sh obsahujici povely :
>>
>> #!/bin/sh
>>
>> KOM=""
>>
>> while read LINE ; do
>> if echo "$LINE" | grep '\/\*' > /dev/null ; then
>> KOM="\\\\"
>> #echo "KOM set"
>> fi
>> if echo "$LINE" | grep '\*\/' > /dev/null ; then
>> KOM=""
>> #echo "KOM del"
>> fi
>> #echo -n $KOM ; echo "$LINE" | sed 's/\*\///g'
>> echo -n $KOM ; echo "$LINE" | sed 's/\*\//\\\\\*\//g'
>>
>> done
>>
>> Kdyz pak prozenu x.sht skrz x.sh (more x.sht | ./x.sh) mam vysledek:
>>
>> normalni radek 1
>> \\/* comment line 1
>> \\comment line 2
>> \\comment line
>> \\*/
>> normalni radek 2
>>
>>
>>
>> *------------------------------------------------------------------------*
>>
>> | Petr Simek APS
>> JU |
>> | psimek na jcu.cz |
>> *------------------------------------------------------------------------*
>>
>>
>>> Zdravím,
>>>
>>> vie prosím niekto poradiť nejaký skript / spôsob (ideálne Linux) na
>>> konverziu komentárov ?
>>> Potrebujem konvertovať komentáre:
>>>
>>> /* comment line 1
>>> comment line 2
>>> comment line
>>> */
>>>
>>> na:
>>>
>>> // comment line 1
>>> // comment line 2
>>> // comment line
>>>
>>> Dôvod:
>>> Na porovnanie rozdielov v hlavičkových súboroch používam program
>>> Meld, ale ten nevie ignorovať viacriadkové komentáre medzi /* a */.
>>>
>>> Ďakujem
>>>
>>> Peter
>>
>> _______________________________________________
>> HW-list mailing list - sponsored by www.HW.cz
>> Hw-list na list.hw.cz
>> http://list.hw.cz/mailman/listinfo/hw-list
> _______________________________________________
> HW-list mailing list - sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list
Další informace o konferenci Hw-list