Search code examples
visual-studio-codecoding-style

change style code function VScode time optimisation while coding


my goal is change a function to a format where the return value of the function is treated : For example ; treating a the function scanf()

Return value of scanf : The value EOF is returned if the end of input is reached before
       either the first successful conversion or a matching failure occurs.
       EOF is also returned if a read error occurs, in which case the error
       indicator for the stream (see ferror(3)) is set, and errno is set to
       indicate the error.

Thus

scanf("%d\n",&i);

will be change to

#define RVAL(exp) do {if ((exp) == -1) { perror (#exp); exit(1); }} while (0)
...
RVAL(scanf("%d\n",&i));

Thus I want this to be done quickly means : so what i do is look for occurences of "scanf" and replace it with "RVAL(scanf" but the problem is i have to add another right parentheses

Can this be done fast ? using a techniques ? or a style ? where each whenever I enter scanf(); its replaced witch rval(scanf());


Solution

  • If you don't have many ) in your format string you can use a regex with (scanf([^)]*)); and replace with rval(\1);

    *see comment