Navigation


Changeset 1434:8850d29960aa in freeDiameter


Ignore:
Timestamp:
Feb 19, 2020, 4:05:01 PM (4 years ago)
Author:
Luke Mewburn <luke@mewburn.net>
Branch:
default
Phase:
public
committer:
Luke Mewburn <luke@mewburn.net> 1582097521 -39600
Message:

org_to_fd.pl: improve formatting of generated data

  • Add more explicit comment blocks for "Start of generated data" and "End of generated data", including the invocation of org_to_fd.pl.
  • Change the default vendor to Base: code 0, name "".
  • Add Type, Code, and Section (if present) to the AVP comment.
  • Consistently use \t to ensure tab output.
  • Provide functions to format comment blocks.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • contrib/tools/org_to_fd.pl

    r1433 r1434  
    11#!/usr/bin/env perl
    22use strict;
     3use File::Basename;
    34use Getopt::Std;
     5
     6my ($progname) = basename($0);
    47
    58our ($opt_V, $opt_v);
    69
    7 # default to 3GPP
    8 my ($vendor) = 10415;
    9 my ($vendor_name) = "3GPP";
     10# default to Base
     11my ($vendor) = 0;
     12my ($vendor_name) = "";
    1013
    1114sub convert_must_to_flags($) {
     
    3336}
    3437
     38
     39my ($comment_width) = 64;
     40
     41sub print_header() {
     42    printf "\t/*=%s=*/\n", '=' x $comment_width;
     43}
     44
     45sub print_comment($) {
     46    my ($str) = @_;
     47    printf "\t/* %-*s */\n", $comment_width, $str;
     48}
     49
    3550sub print_insert($$) {
    3651    my ($type, $name) = @_;
     
    4055        $avp_type = "NULL";
    4156    } elsif ($type =~ m/Enumerated/) {
    42         print "\t\tstruct dict_object           *type;\n";
    43         print "\t\tstruct dict_type_data        tdata = { AVP_TYPE_INTEGER32, \"Enumerated(" . ($vendor_name ? "$vendor_name/" : "") ."$name)\", NULL, NULL, NULL };\n";
     57        print "\t\tstruct dict_object\t*type;\n";
     58        print "\t\tstruct dict_type_data\t tdata = { AVP_TYPE_INTEGER32, \"Enumerated(" . ($vendor_name ? "$vendor_name/" : "") ."$name)\", NULL, NULL, NULL };\n";
    4459        # XXX: add enumerated values
    4560        print "\t\tCHECK_dict_new(DICT_TYPE, &tdata, NULL, &type);\n";
     
    5368
    5469sub usage($) {
    55     die("usage: org_to_fd.pl [-V vendor_name -v vendor_code] [file ...]\n");
     70    die(sprintf("usage: %s [-V vendor_name] [-v vendor_code] [file ...]\n", $progname));
    5671    exit(@_);
    5772}
     
    6277    $vendor = $opt_v;
    6378    if (!defined($opt_V)) {
    64         usage(1);
     79        usage(1);
    6580    }
    6681    $vendor_name = $opt_V;
    6782}
    6883
    69 print "\t/* The following is created automatically. Do not modify. */\n";
    70 print "\t/* Changes will be lost during the next update. Modify the source org file instead. */\n\n";
     84print_header();
     85print_comment("Start of generated data.");
     86print_comment("");
     87print_comment("The following is created automatically with:");
     88print_comment(sprintf("    org_to_fd.pl -V '%s' -v %s", $vendor_name, $vendor));
     89print_comment("Changes will be lost during the next update.");
     90print_comment("Do not modify; modify the source .org file instead.");
     91print_header();
     92print "\n";
    7193
    7294while (<>) {
     
    7597    next if ($name =~ m/Attribute Name/);
    7698    if ($name =~ m/# (.*)/) {
    77         printf "\t/* %-60s */\n", $1;
     99        print_comment($1);
    78100        next;
    79101    }
    80102
    81103    if ($name =~ m/\s/) {
    82         die(sprintf("name '%s' contains space", $name));
     104        die(sprintf("name '%s' contains space", $name));
    83105    }
    84106
    85     print "\t/* $name */\n\t{\n\t\tstruct dict_avp_data data = {\n";
     107    my ($desc) = $name;
     108    $desc .= ", " . $type;
     109    $desc .= ", code " . $code;
     110    $desc .= ", section " . $section if $section != "";
     111    print_comment($desc);
     112    print "\t{\n";
     113    print "\t\tstruct dict_avp_data data = {\n";
    86114    print "\t\t\t$code,\t/* Code */\n";
    87115    print "\t\t\t$vendor,\t/* Vendor */\n";
     
    94122    print "\t};\n\n";
    95123}
     124
     125print_header();
     126print_comment("End of generated data.");
     127print_header();
Note: See TracChangeset for help on using the changeset viewer.