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

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

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 02-25-2016
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 04:30 PM.. Reason: typo
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl to parse a variety of formats cmccabe Shell Programming and Scripting 3 05-02-2017 03:37 AM
Word replacement in Perl AIX_30 Shell Programming and Scripting 1 05-22-2013 02:30 PM
Block of code replacement in Java source code through Unix script hareeshram Shell Programming and Scripting 2 01-30-2012 11:54 AM
Perl Array Elements Replacement ahmed_zaher Shell Programming and Scripting 4 01-02-2011 03:16 PM
Converting date string to different formats GermanJulian Shell Programming and Scripting 6 05-13-2010 11:05 AM
need a perl replacement for this double for loop pseudocoder Shell Programming and Scripting 6 04-01-2010 10:15 PM
HELP Need in SED/PERL conditional line replacement robin.r888 Shell Programming and Scripting 3 02-01-2010 10:46 AM
Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl akil Shell Programming and Scripting 7 07-17-2009 10:09 AM
Converting Perl code to shell zainravi Shell Programming and Scripting 8 03-12-2009 01:54 PM
Replacement of sentence in perl vanitham Shell Programming and Scripting 1 12-05-2008 05:17 AM
perl as awk replacement in a script. trey85stang Shell Programming and Scripting 4 09-02-2008 02:34 AM
Replacement for eval in Perl?????? kunal_dixit Shell Programming and Scripting 4 07-03-2008 04:47 AM
Replacement of sed with perl dbsurf Shell Programming and Scripting 4 01-25-2008 06:21 PM
VI questions : mass changes, mass delete and external insert Browser_ice AIX 1 12-13-2006 04:20 AM
String Replacement with Perl Lindarella Shell Programming and Scripting 4 09-29-2006 03:05 PM
All times are GMT -4. The time now is 02:07 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?