/src/wireshark/epan/unit_strings.c
Line | Count | Source |
1 | | /* unit_strings.c |
2 | | * Units to append to field values |
3 | | * |
4 | | * Wireshark - Network traffic analyzer |
5 | | * By Gerald Combs <gerald@wireshark.org> |
6 | | * Copyright 1998 Gerald Combs |
7 | | * |
8 | | * SPDX-License-Identifier: GPL-2.0-or-later |
9 | | */ |
10 | | |
11 | | #include "config.h" |
12 | | |
13 | | #include <wsutil/utf8_entities.h> |
14 | | #include <wsutil/str_util.h> |
15 | | #include "unit_strings.h" |
16 | | |
17 | | /** Returns the unit string appropriate for the 32 bit value. */ |
18 | | const char* unit_name_string_get_value(uint32_t value, const unit_name_string* units) |
19 | 2.60k | { |
20 | 2.60k | if (units->plural == NULL) |
21 | 721 | return units->singular; |
22 | | |
23 | 1.87k | return plurality(value, units->singular, units->plural); |
24 | 2.60k | } |
25 | | |
26 | | /** Returns the unit string appropriate for the 64 bit value. */ |
27 | | const char* unit_name_string_get_value64(uint64_t value, const unit_name_string* units) |
28 | 0 | { |
29 | 0 | if (units->plural == NULL) |
30 | 0 | return units->singular; |
31 | | |
32 | 0 | return plurality(value, units->singular, units->plural); |
33 | 0 | } |
34 | | |
35 | | /** Returns the unit string appropriate for the double value. */ |
36 | | const char* unit_name_string_get_double(double value, const unit_name_string* units) |
37 | 0 | { |
38 | 0 | if (units->plural == NULL) |
39 | 0 | return units->singular; |
40 | | |
41 | 0 | return plurality(value, units->singular, units->plural); |
42 | 0 | } |
43 | | |
44 | | /* |
45 | | * A default set of unit strings that dissectors can use for |
46 | | * header fields. Some units intentionally have a space |
47 | | * character in them for spacing between unit and value |
48 | | */ |
49 | | const unit_name_string units_foot_feet = { " foot", " feet" }; |
50 | | const unit_name_string units_bit_bits = { " bit", " bits" }; |
51 | | const unit_name_string units_byte_bytes = { " byte", " bytes" }; |
52 | | const unit_name_string units_byte_bytespsecond = { " byte/s", " bytes/s" }; |
53 | | const unit_name_string units_octet_octets = { " octet", " octets" }; |
54 | | const unit_name_string units_word_words = { " word", " words" }; |
55 | | const unit_name_string units_tick_ticks = { " tick", " ticks" }; |
56 | | const unit_name_string units_meters = { "m", NULL }; |
57 | | const unit_name_string units_meter_meters = { " meter", " meters" }; |
58 | | const unit_name_string units_centimeters = { "cm", NULL }; |
59 | | const unit_name_string units_centimeter_centimeters = { " centimeter", " centimeters" }; |
60 | | const unit_name_string units_millimeters = { "mm", NULL }; |
61 | | const unit_name_string units_millimeter_millimeters = { " millimeter", " millimeters" }; |
62 | | const unit_name_string units_week_weeks = { " week", " weeks" }; |
63 | | const unit_name_string units_day_days = { " day", " days" }; |
64 | | const unit_name_string units_hour_hours = { " hour", " hours" }; |
65 | | const unit_name_string units_hours = { "h", NULL }; |
66 | | const unit_name_string units_minute_minutes = { " minute", " minutes" }; |
67 | | const unit_name_string units_minutes = { "min", NULL }; |
68 | | const unit_name_string units_second_seconds = { " second", " seconds" }; |
69 | | const unit_name_string units_seconds = { "s", NULL }; |
70 | | const unit_name_string units_millisecond_milliseconds = { " millisecond", " milliseconds" }; |
71 | | const unit_name_string units_milliseconds = { "ms", NULL }; |
72 | | const unit_name_string units_microsecond_microseconds = { " microsecond", " microseconds" }; |
73 | | const unit_name_string units_microseconds = { UTF8_MICRO_SIGN "s", NULL }; |
74 | | const unit_name_string units_nanosecond_nanoseconds = { " nanosecond", " nanoseconds" }; |
75 | | const unit_name_string units_nanoseconds = { "ns", NULL }; |
76 | | const unit_name_string units_nanometers = { "nm", NULL }; |
77 | | const unit_name_string units_picoseconds = { "ps", NULL }; |
78 | | const unit_name_string units_femtoseconds = { "fs", NULL }; |
79 | | const unit_name_string units_attoseconds = { "as", NULL }; |
80 | | const unit_name_string units_degree_degrees = { " degree", " degrees" }; |
81 | | const unit_name_string units_degree_celsius = { UTF8_DEGREE_SIGN "C", NULL }; |
82 | | const unit_name_string units_degree_bearing = { UTF8_DEGREE_SIGN, NULL }; |
83 | | const unit_name_string units_centibels = { " cB", NULL }; |
84 | | const unit_name_string units_decibels = { " dB", NULL }; |
85 | | const unit_name_string units_dbm = { " dBm", NULL }; |
86 | | const unit_name_string units_dbi = { " dBi", NULL }; |
87 | | const unit_name_string units_dbhz = { " dB-Hz", NULL }; |
88 | | const unit_name_string units_mbm = { " mBm", NULL }; |
89 | | const unit_name_string units_percent = { "%", NULL }; |
90 | | const unit_name_string units_khz = { "kHz", NULL }; |
91 | | const unit_name_string units_mhz = { "MHz", NULL }; |
92 | | const unit_name_string units_ghz = { "GHz", NULL }; |
93 | | const unit_name_string units_hz = { "Hz", NULL }; |
94 | | const unit_name_string units_hz_s = { "Hz/s", NULL }; |
95 | | const unit_name_string units_kbit = { "kbit", NULL }; |
96 | | const unit_name_string units_kbps = { "Kbps", NULL }; |
97 | | const unit_name_string units_kibps = { "KiB/s", NULL }; |
98 | | const unit_name_string units_pkts = { " pkts", NULL }; |
99 | | const unit_name_string units_pkts_per_sec = { " pkts/s", NULL }; |
100 | | const unit_name_string units_km = { "km", NULL }; |
101 | | const unit_name_string units_kmh = { "km/h", NULL }; |
102 | | const unit_name_string units_m_s = { "m/s", NULL }; |
103 | | const unit_name_string units_cm_s = { "cm/s", NULL }; |
104 | | const unit_name_string units_mm_s = { "mm/s", NULL }; |
105 | | const unit_name_string units_bit_sec = { "bits/s", NULL }; |
106 | | const unit_name_string units_milliamps = { "mA", NULL }; |
107 | | const unit_name_string units_watt = { "W", NULL }; |
108 | | const unit_name_string units_milliwatt = { "mW", NULL }; |
109 | | const unit_name_string units_microwatt = { UTF8_MICRO_SIGN "W", NULL }; |
110 | | const unit_name_string units_volt = { "V", NULL }; |
111 | | const unit_name_string units_grams_per_second = { "g/s", NULL }; |
112 | | const unit_name_string units_meter_sec = { "m/s", NULL }; |
113 | | const unit_name_string units_meter_sec_squared = { "m/s" UTF8_SUPERSCRIPT_TWO , NULL }; |
114 | | const unit_name_string units_segment_remaining = { " segment remaining", " segments remaining" }; |
115 | | const unit_name_string units_frame_frames = { " frame", " frames" }; |
116 | | const unit_name_string units_revolutions_per_minute = { "rpm", NULL }; |
117 | | const unit_name_string units_pascal = { "Pa", NULL }; |
118 | | const unit_name_string units_kilopascal = { "kPa", NULL }; |
119 | | const unit_name_string units_newton_metre = { "Nm", NULL }; |
120 | | const unit_name_string units_liter_per_hour = { "L/h", NULL }; |
121 | | const unit_name_string units_amp = { "A", NULL }; |
122 | | const unit_name_string units_watthour = { "Wh", NULL }; |
123 | | const unit_name_string units_bpm = { " BPM", NULL }; |
124 | | const unit_name_string units_calorie = { " cal", NULL }; |
125 | | const unit_name_string units_cycle_cycles = { " cycle", " cycles" }; |
126 | | const unit_name_string units_ppm = { " ppm", NULL }; |
127 | | |
128 | | |
129 | | /* |
130 | | * Editor modelines |
131 | | * |
132 | | * Local Variables: |
133 | | * c-basic-offset: 4 |
134 | | * tab-width: 8 |
135 | | * indent-tabs-mode: nil |
136 | | * End: |
137 | | * |
138 | | * ex: set shiftwidth=4 tabstop=8 expandtab: |
139 | | * :indentSize=4:tabSize=8:noTabs=true: |
140 | | */ |