1 /* $XConsortium: Utils.c /main/6 1996/10/09 11:44:33 mustafa $ */
2 /************************************<+>*************************************
3 ****************************************************************************
7 * COMPONENT_NAME: Desktop File Manager (dtfile)
9 * Description: Contains utility routines.
11 * FUNCTIONS: ResolveLocalPathName
12 * ResolveTranslationString
14 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
15 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
16 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
17 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
19 ****************************************************************************
20 ************************************<+>*************************************/
22 #include <Dt/Connect.h>
26 /***********************************************************************
27 * FUNCTION NAME: ResolveLocalPathName
29 * PURPOSE: This function takes the given parameters and returns a path
30 * (owned by the caller) suitable for passing to open(2). It
31 * takes the internal cannonical file name kept by the File
32 * Manager and remaps them into the standard CDE file name
33 * mapping calls (tt_host_file_netfile, tt_netfile_file). The
34 * returned pathname is valid only on the local host. See
35 * ResolveRemotePathName if you need a pathname which is valid
36 * on a different host.
38 * SYNOPSIS: path = ResolveLocalPathName(hostname, directory_name,
39 * file_name,local_hostname,
42 * char *path; The returned pathname. The memory is owned
43 * by the caller. NULL is returned on failure.
45 * char *hostname; The host where the file is located.
47 * char *directory_name; The directory portion of the pathname;
49 * char *file_name; The name of the file.
51 * char *local_hostname; The current host.
53 * Tt_status *tt_status; Upon error, the tool talk error status will
54 * be returned for use by the caller. Use
55 * tt_status_message to get a printable string.
57 ********************************************************************************/
67 char * fully_qualified_name;
71 int len = strlen( directory_name );
75 printf ("Home host name is %s actual hostname is %s\n",
76 local_hostname, hostname);
79 /* construct full qualified filename
83 if( len == 1 && *directory_name == '/' )
85 fully_qualified_name = (char *)XtCalloc ( 1, ( strlen (file_name) + 2 ) );
86 sprintf( fully_qualified_name, "/%s", file_name );
90 fully_qualified_name = (char *)XtCalloc ( 1, ( len + strlen (file_name) + 2 ) );
91 sprintf( fully_qualified_name, "%s/%s", directory_name, file_name );
98 fully_qualified_name = (char *)XtMalloc ( len + 1 );
99 strcpy( fully_qualified_name, directory_name );
102 fully_qualified_name = NULL;
107 #if defined(FILE_MAP_OPTIMIZE)
108 /* check if local host name = hostname */
109 /* Do not do a tooltalk call if that is */
111 if (strcmp(hostname, local_hostname) == 0 )
114 printf ("fully qualified name is %s\n", path);
116 return (fully_qualified_name);
119 /* not on local host, make an rpc trip */
122 /* What about no hostname, then just send the file */
123 if (!hostname || (hostname[0] == '\0'))
124 return fully_qualified_name;
126 /* convert to network canonical name
128 cannon_name = (char *)tt_host_file_netfile (hostname, fully_qualified_name);
129 XtFree (fully_qualified_name);
130 if ( (*tt_status = tt_pointer_error(cannon_name)) != TT_OK)
133 printf( "Tooltalk error message: %s\n", tt_status_message(*tt_status));
139 /* resolve canonical name on local host
141 tmp = (char *) tt_netfile_file(cannon_name);
142 tt_free (cannon_name);
144 if ( (*tt_status = tt_pointer_error (tmp)) != TT_OK)
147 printf( "Tooltalk error message: %s\n", tt_status_message(*tt_status));
152 path = XtNewString( tmp );
161 ResolveTranslationString( char * originalString,
166 char * resolvedString = NULL;
167 int i, j, k, total, length;
170 sprintf( addressStr, "%lx", address );
172 sprintf( addressStr, "%p", address );
175 for( i = 0, total = 0; originalString[i] != '\0'; ++i )
176 if( originalString[i] == '@' )
179 length = strlen( originalString );
183 resolvedString = XtNewString( originalString );
187 resolvedString = (char *)XtCalloc( 1, length + ( ( strlen( addressStr ) )
189 if( resolvedString != NULL )
193 while( originalString[i] != '\0' )
195 if( originalString[i] == '@' )
197 for( k = 0; addressStr[k] != '\0'; ++j, ++k )
198 resolvedString[ j ] = addressStr[k];
202 resolvedString[ j++ ] = originalString[ i++ ];
207 return resolvedString;