Sponsored Content
Top Forums Shell Programming and Scripting Perl:: mass replacement of converting C code formats to tgmath.h Post 302967610 by f77hack on Thursday 25th of February 2016 04:36:07 PM
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String Replacement with Perl

I want to replace a string within a file using perl. We have a line that gets commented out, and I want to replace that line now matter how it was commented out. for example, I'd want to replace ###ES=PR1A with ES=PR1A or ##LJW(9/16/26)ES=PR1A with ES=PR1A I tried: perl... (4 Replies)
Discussion started by: Lindarella
4 Replies

2. AIX

VI questions : mass changes, mass delete and external insert

Is it possible in VI to do a global change but take the search patterns and the replacement patterns from an external file ? I have cases where I can have 100,200 or 300+ global changes to do. All the new records are inside a file and I must VI a work file to change all of them. Also, can... (1 Reply)
Discussion started by: Browser_ice
1 Replies

3. Shell Programming and Scripting

Replacement of sed with perl

Hi using the below cmd i am identifying wheether last character in each line in thousands of files as semicolon or not.If last character is semicolon i am removing semicolon .If last character is not semicolon then i am appending next line to present line . For example my input file consists of... (4 Replies)
Discussion started by: dbsurf
4 Replies

4. Shell Programming and Scripting

Replacement for eval in Perl??????

I used the eval command in shell programming for assigning a value to a stored value of a variable. Example: VAR="Unix_Id" eval $VAR="101" eval echo $"$VAR" How can i assign a value to a stored value of a variable in perl OR how i can write above code in Perl? I need your help... (4 Replies)
Discussion started by: kunal_dixit
4 Replies

5. Shell Programming and Scripting

Converting Perl code to shell

I have a perl code that runs like Code I sub p { if ($d >= $D) {return} printf "%3s"x$d++," "; printf "%s%s\n",$_,$h{$_}?" ** ":""; if (!$h{$_}) { $h{$_}=1; map {p($_)} @{$s{$_}} } $d-- } ($Set,$Job,$Num,$D) = (@ARGV); map {shift} 0..3; (8 Replies)
Discussion started by: zainravi
8 Replies

6. Shell Programming and Scripting

Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl

Hi , This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated. use Time::Local; my $d = $ARGV; my $t = $ARGV; my $m = ""; @d = split /\//, $d; @t = split /:/, $t; if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies

7. Shell Programming and Scripting

Converting date string to different formats

Sucks to be a noob :o See my last post for solution I have 3 different log formats and the filenames contain a date. I am trying to write a script to grep these files between two date ranges. I am now stuck at the date conversion bit. I let the user entered a date string in the format... (6 Replies)
Discussion started by: GermanJulian
6 Replies

8. Shell Programming and Scripting

Block of code replacement in Java source code through Unix script

Hi, I want to remove the following code from Source files (or replace the code with empty.) from all the source files in given directory. finally { if (null != hibernateSession && hibernateSession.isOpen()) { //hibernateSession.close(); } } It would be great if the script has... (2 Replies)
Discussion started by: hareeshram
2 Replies

9. Shell Programming and Scripting

Word replacement in Perl

I have the following string : Cat dog fox catepillar bear foxy I need to replace "cat" and "fox" words from this sentence to word "animal" I do the following: $Str1="cat"; $Str2="fox"; $NewStr="animal"; open(F1, "<$inputFile") or die "Error: $!"; open(F2, ">$outputFile") or... (1 Reply)
Discussion started by: AIX_30
1 Replies

10. Shell Programming and Scripting

Perl to parse a variety of formats

The below perl script parses a variety of formats. If I use the numeric text file as input the script works correctly. However using the alpha text file as input there is a black output file. The portion in bold splits the field to parse f or NC_000023.10:g.153297761C>A into a variable $common but... (3 Replies)
Discussion started by: cmccabe
3 Replies
tgmath.h(3HEAD) 						      Headers							   tgmath.h(3HEAD)

NAME
tgmath.h, tgmath - type-generic macros SYNOPSIS
#include <tgmath.h> DESCRIPTION
The <tgmath.h> header includes the headers <math.h> and <complex.h> and defines several type-generic macros. Of the functions contained within the <math.h> and <complex.h> headers without an f (float) or l (long double) suffix, several have one or more parameters whose corresponding real type is double. For each such function except modf(3M), there is a corresponding type-generic macro. The parameters whose corresponding real type is double in the function synopsis are generic parameters. Use of the macro invokes a function whose corresponding real type and type domain are determined by the arguments for the generic parameters. Use of the macro invokes a function whose generic parameters have the corresponding real type determined as follows: o First, if any argument for generic parameters has type long double, the type determined is long double. o Otherwise, if any argument for generic parameters has type double or is of integer type, the type determined is double. o Otherwise, the type determined is float. For each unsuffixed function in the <math.h> header for which there is a function in the <complex.h> header with the same name except for a c prefix, the corresponding type-generic macro (for both functions) has the same name as the function in the <math.h> header. The corre- sponding type-generic macro for fabs() and cabs() is fabs(). <math.h> Function <complex.h> Function Type-Generic Macro ---------------------------------------------------------------- acos() cacos() acos() asin() casin() asin() atan() catan() atan() acosh() cacosh() acosh() asinh() casinh() asinh() atanh() catanh() atanh() cos() ccos() cos() sin() csin() sin() tan() ctan() tan() cosh() ccosh() cosh() sinh() csinh() sinh() tanh() ctanh() tanh() exp() cexp() exp() log() clog() log() pow() cpow() pow() sqrt() csqrt() sqrt() fabs() cfabs() fabs() If at least one argument for a generic parameter is complex, then use of the macro invokes a complex function; otherwise, use of the macro invokes a real function. For each unsuffixed function in the <math.h> header without a c-prefixed counterpart in the <complex.h> header, the corresponding type- generic macro has the same name as the function. These type-generic macros are: atan2() fma() llround() remainder() cbrt() fmax() log10() remquo() ceil() fmin() log1p() rint() copysign() fmod() log2() round() erf() frexp() logb() scalbn() erfc() hypot() lrint() scalbln() exp2() ilogb() lround() tgamma() expm1() ldexp() nearbyint() trunc() fdim() lgamma() nextafter() floor() llrint() nexttoward() If all arguments for generic parameters are real, then use of the macro invokes a real function; otherwise, use of the macro results in undefined behavior. For each unsuffixed function in the <complex.h> header that is not a c-prefixed counterpart to a function in the <math.h> header, the cor- responding type-generic macro has the same name as the function. These type-generic macros are: carg() cimag() conj() cproj() creal() Use of the macro with any real or complex argument invokes a complex function. USAGE
Functions invoked by use of type-generic macros are invoked with the declarations listed below. #include <tgmath.h> int n; float f; double d; long double ld; float complex fc; double complex dc; long double complex ldc; The following are the type-generic macros that invoke the functions that are invoked with the preceding declarations. Macro Use Invokes ------------------------------------------------------------ exp(n) exp(n), the function acosh(f) acoshf(f) sin(d) sin(d), the function atan(ld) atanl(ld) log(fc) clogf(fc) sqrt(dc) csqrt(dc) pow(ldc,f) cpowl(ldc, f) remainder(n,n) remainder(n, n), the function nextafter(d,f) nextafter(d, f), the function nexttoward(f,ld) nexttowardf(f, ld) copysign(n,ld) copysignl(n, ld) ceil(fc) undefined behavior rint(dc) undefined behavior fmax(ldc,ld) undefined behavior carg(n) carg(n), the function cproj(f) cprojf(f) creal(d) creal(d), the function cimag(ld) cimagl(ld) cabs(fc) cabsf(fc) carg(dc) carg(dc), the function cproj(ldc) cprojl(ldc) ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
modf(3M), complex.h(3HEAD), math.h(3HEAD), cabs(3M), fabs(3M), attributes(5), standards(5) SunOS 5.11 17 Dec 2003 tgmath.h(3HEAD)
All times are GMT -4. The time now is 08:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy