# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Canonicalize a name into a C identifier.  White space and a few other  junk #
# characters  are stripped out, then strings of various non-alfanum chars are #
# replaced with a single underscore.   We  also  do  assorted  shortening  to #
# regularize  some names.  This routine is called by the "icd-c", "msg-h" and #
# "mib-t" programs, to canonicalize the  various  names  that  they  generate #
# from their input files.                                                     #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
sub cname {
	local($x) = @_;

#	$x =~ s/[\s^"]+//g;		# Doesn't work; don't know why.
	$x =~ s/[\s"']+//g;		# Works just fine.
	$x =~ s'[-+/,.]+'_'g;	# Junk chars to underscore.
	$x =~ s'%'Pct'g; 		# Kludge to handle "percent" field names.
	$x =~ s/\s*\(.*\)\s*//g;	# Discard parenthesised stuff.

	$x =~ s'Administrative'Ad'ig;
	$x =~ s'Operational'Op'ig;
	$x =~ s'Status'Stat'ig;
	$x =~ s'Performance'Perf'ig;
	$x =~ s'Perf_Stat'Perf'ig;

#	$x =~ s'ADMINISTRATIVE'AD'g;
#	$x =~ s'OPERATIONAL'OP'g;
#	$x =~ s'PERFORMANCE'PERF'g;
#	$x =~ s'PERF_STAT'PERF'g;
#	$x =~ s'STATUS'STAT'g;

	$x =~ s'Access_'Acs_'ig;
	$x =~ s'Activation_'Activation_'ig;
	$x =~ s'Add_'Add_'ig;
	$x =~ s'Call_'Call_'ig;
	$x =~ s'Clock_'Clock_'ig;
	$x =~ s'Close_'Close_'ig;
	$x =~ s'Conn_'Conn_'ig;
	$x =~ s'Connection_'Conn_'ig;
	$x =~ s'Core_'Core_'ig;
	$x =~ s'Define_'Define_'ig;
	$x =~ s'Delete_'Delete_'ig;
	$x =~ s'Disconnect_'Disc_'ig;
	$x =~ s'Display_'Disp_'ig;
	$x =~ s'Fault_'Fault_'ig;
	$x =~ s'Get_'Get_'ig;
	$x =~ s'Info_'Info_'ig;
	$x =~ s'Interface_'IF_'ig;
	$x =~ s'Log_'Log_'ig;
	$x =~ s'Logging_'Log_'ig;
	$x =~ s'Mask_'Mask_'ig;
	$x =~ s'Node_'ND_'ig;
	$x =~ s'Open_'Open_'ig;
	$x =~ s'PVC_'Call_'ig;
	$x =~ s'Perf_'Perf_'ig;
	$x =~ s'Points*_'Point_'ig;
	$x =~ s'Port_'Port_'ig;
	$x =~ s'Profile_'Prof_'ig;
	$x =~ s'Release_'Release_'ig;
	$x =~ s'Settings_'Settings_'ig;
	$x =~ s'Setup_'Setup_'ig;
	$x =~ s'Start_'Start_'ig;
	$x =~ s'Stat_'Stat_'ig;
	$x =~ s'Stop_'Stop_'ig;
	$x =~ s'Stop_'Stop_'ig;
	$x =~ s'Thresholds*_'Thresh_'ig;
	$x =~ s'Trip_'Trip_'ig;
	$x =~ s'UnDefine_'UnDefine_'ig;
	$x =~ s'Update_'Update_'ig;
	$x =~ s'_notify'_notify'ig;
	$x =~ s'_progress'_progress'ig;
	$x =~ s'_reply'_reply'ig;
	$x =~ s'_request'_request'ig;

	if ($x =~ m'^unused$'i) {
		++ $unused;
		$x = "UNUSED$unused";
	}
	$x = 'CMAlarm' if ($x eq 'Alarm');	# Conflict with Unix routine (via V macro).
	$x; 
}
1;	# Gotta return a value to satisfy the require command.
