Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Perl:: mass replacement of converting C code formats to tgmath.h

Shell Programming and Scripting


Tags
perl, prefix, replace a string, solved, suffix

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-25-2016
f77hack f77hack is offline
Registered User
 
Join Date: Jan 2016
Last Activity: 25 March 2017, 2:45 AM EDT
Location: 3rd planet
Posts: 19
Thanks: 11
Thanked 1 Time in 1 Post
Perl:: mass replacement of converting C code formats to tgmath.h

hello,

i have a lot of C old code I'm updating to C11 with tgmath.h for generic math. the old code has very specific types, real and complex, like cabsl, csinhl, etc

usually for simple bulk replacements i would do something simple like this

perl -pi -e 's/cosl/cos/g' *.c

the reference is here
HTML Code:
http://en.cppreference.com/w/c/numeric/tgmath
snippet

real complex
generic float long dble dble dble float long dble dble dble
fabs fabsf fabs fabsl cabsf cabs cabsl
exp expf exp expl cexpf cexp cexpl
log logf log logl clogf clog clogl


there are basically two classes of operations


Code:
array=(fabs exp log pow sqrt sin cos tan acos atan sinh cosh tanh asinh acosh atanh)
for tgt in array
{
perl -pi -e 's/${tgt}f/${tgt}/g' *.*
perl -pi -e 's/${tgt}l/${tgt}/g' *.*
perl -pi -e 's/c${tgt}/${tgt}/g' *.*
perl -pi -e 's/c${tgt}f/${tgt}/g' *.*
perl -pi -e 's/c${tgt}l/${tgt}/g' *.*
}
#special case of fabs
perl -pi -e 's/cabs/${tgt}/g' *.*

and


Code:
array=(atan2 cbrt ceil copysign erf erfc exp2 expm1 fdim floor fma fmax fmin fmod)
array+=(frexp hypot ilogb ldexp lgamma llrint llround log10 log1p log2 logb lrint)
array+=(lround nearbyint nextafter nexttoward remainder remquo rint roiund scalbin)
array+=(scalbn tgamma trunc carg conj creal cimag cproj)
for tgt in array
{
perl -pi -e 's/${tgt}f/${tgt}/g' *.*
perl -pi -e 's/${tgt}l/${tgt}/g' *.
}

perl is not mandatory, but a sweet one or two liner would be excellent.


thanks.

---------- Post updated at 04:36 PM ---------- Previous update was at 02:55 PM ----------

oh well, i went ahead my own my loops and forked.

Last edited by f77hack; 02-25-2016 at 03:30 PM.. Reason: typo
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Block of code replacement in Java source code through Unix script hareeshram Shell Programming and Scripting 2 01-30-2012 10:54 AM
Converting date string to different formats GermanJulian Shell Programming and Scripting 6 05-13-2010 10:05 AM
Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl akil Shell Programming and Scripting 7 07-17-2009 09:09 AM
Converting Perl code to shell zainravi Shell Programming and Scripting 8 03-12-2009 12:54 PM
VI questions : mass changes, mass delete and external insert Browser_ice AIX 1 12-13-2006 03:20 AM



All times are GMT -4. The time now is 01:15 AM.