替换功能或由文本本身定义

时间:2017-07-02 09:37:58

标签: c vim refactoring automated-refactoring

如何替换所有出现的

check_free_set_to_null(&pointer)

通过

if (pointer)
{
    free(pointer)
    printf(pointer have been freed)
}
else
{
    printf(pointer couldnt had been freed)
    return (1)
}

可能使用某种

{1} = check_free_set_to_null(CONTENT)

  if ({1})
    {
        free({1})
        printf({1} have been freed)
    }
    else
    {
        printf({1} couldnt had been freed)
        return (1)
    }

我怎么能这样做? (请注意,它不完全是必须替换的,它只是一个例子) 我不是在寻找编译器将其解释为多行,我正在寻找修改文件。

1 个答案:

答案 0 :(得分:1)

您可以将宏用于此作业。

#define check_free_set_to_null(pointer) if (pointer) { \
    free(pointer)\
    printf(pointer have been freed)\
} else {\
    printf(pointer couldnt had been freed)\
    return (1)\
}