]> git.proxmox.com Git - mirror_frr.git/blame - tools/fixup-deprecated.py
lib, zebra: Ensure that the ifp->node exists
[mirror_frr.git] / tools / fixup-deprecated.py
CommitLineData
04746079
LB
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
47a3a827 3# SPDX-License-Identifier: NONE
04746079
LB
4#
5# Script used to replace deprecated quagga/frr mactors/types/etc.
6#
7# loosly based on indent.py, 2017 by David Lamparter
8# 2018 by Lou Berger, placed in public domain
9
10import sys, re, subprocess, os
11
701a0192 12
04746079 13class replaceEntry:
701a0192 14 compiled = None # compiled regex
15 repl = None # regex
16
04746079
LB
17 def __init__(self, c, r):
18 self.compiled = c
19 self.repl = r
20
701a0192 21
04746079
LB
22rList = [
23 # old #define VNL, VTYNL, VTY_NEWLINE
701a0192 24 replaceEntry(re.compile(r"(VNL|VTYNL|VTY_NEWLINE)"), r'"\\n"'),
04746079
LB
25 # old #define VTY_GET_INTEGER(desc, v, str)
26 # old #define VTY_GET_INTEGER_RANGE(desc, v, str, min, max)
27 # old #define VTY_GET_ULONG(desc, v, str)
701a0192 28 replaceEntry(
29 re.compile(
30 r"(VTY_GET_INTEGER(_RANGE|)|VTY_GET_ULONG)[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;",
31 re.M | re.S,
32 ),
33 r"(\4) = strtoul((\5), NULL, 10);\t/* \3 */",
34 ),
04746079 35 # old #define VTY_GET_ULL(desc, v, str)
701a0192 36 replaceEntry(
37 re.compile(
38 r"VTY_GET_ULL[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;",
39 re.M | re.S,
40 ),
41 r"(\2) = strtoull((\3), NULL, 10);\t/* \1 */",
42 ),
04746079 43 # old #define VTY_GET_IPV4_ADDRESS(desc, v, str)
701a0192 44 replaceEntry(
45 re.compile(
46 r"VTY_GET_IPV4_ADDRESS[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;",
47 re.M | re.S,
48 ),
49 r"inet_aton((\3), &(\2));\t/* \1 */",
50 ),
04746079 51 # old #define VTY_GET_IPV4_PREFIX(desc, v, str)
701a0192 52 replaceEntry(
53 re.compile(
54 r"VTY_GET_IPV4_PREFIX[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;",
55 re.M | re.S,
56 ),
57 r"str2prefix_ipv4((\3), &(\2));\t/* \1 */",
58 ),
04746079 59 # old #define vty_outln(vty, str, ...)
701a0192 60 replaceEntry(
61 re.compile(r'vty_outln[\s\(]*(.*?)\s*,\s*(".*?"|.*?)\s*(\)|,)', re.M | re.S),
62 r'vty_out(\1, \2 "\\n"\3',
63 ),
64]
65
04746079
LB
66
67def fixup_file(fn):
701a0192 68 with open(fn, "r") as fd:
04746079
LB
69 text = fd.read()
70
71 for re in rList:
701a0192 72 text = re.compiled.sub(re.repl, text)
04746079 73
701a0192 74 tmpname = fn + ".fixup"
75 with open(tmpname, "w") as ofd:
04746079
LB
76 ofd.write(text)
77 os.rename(tmpname, fn)
78
701a0192 79
80if __name__ == "__main__":
04746079
LB
81 for fn in sys.argv[1:]:
82 fixup_file(fn)