👤
Home Man
Search
Today's Posts
Register

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

Tags
perl, prefix, replace a string, 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 03:30 PM.. Reason: typo
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:37 AM
Word replacement in Perl AIX_30 Shell Programming and Scripting 1 05-22-2013 01:30 PM
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
Replacement of sentence in perl vanitham Shell Programming and Scripting 1 12-05-2008 04:17 AM
Replacement of sed with perl dbsurf Shell Programming and Scripting 4 01-25-2008 05:21 PM
VI questions : mass changes, mass delete and external insert Browser_ice AIX 1 12-13-2006 03:20 AM
String Replacement with Perl Lindarella Shell Programming and Scripting 4 09-29-2006 02:05 PM


All times are GMT -4. The time now is 02:20 AM.



All times are GMT -4. The time now is 02:20 AM.

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