2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: Utils.c /main/6 1996/10/09 11:44:33 mustafa $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 * COMPONENT_NAME: Desktop File Manager (dtfile)
31 * Description: Contains utility routines.
33 * FUNCTIONS: ResolveLocalPathName
34 * ResolveTranslationString
36 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
37 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
38 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
39 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
41 ****************************************************************************
42 ************************************<+>*************************************/
44 #include <Dt/Connect.h>
48 /***********************************************************************
49 * FUNCTION NAME: ResolveLocalPathName
51 * PURPOSE: This function takes the given parameters and returns a path
52 * (owned by the caller) suitable for passing to open(2). It
53 * takes the internal cannonical file name kept by the File
54 * Manager and remaps them into the standard CDE file name
55 * mapping calls (tt_host_file_netfile, tt_netfile_file). The
56 * returned pathname is valid only on the local host. See
57 * ResolveRemotePathName if you need a pathname which is valid
58 * on a different host.
60 * SYNOPSIS: path = ResolveLocalPathName(hostname, directory_name,
61 * file_name,local_hostname,
64 * char *path; The returned pathname. The memory is owned
65 * by the caller. NULL is returned on failure.
67 * char *hostname; The host where the file is located.
69 * char *directory_name; The directory portion of the pathname;
71 * char *file_name; The name of the file.
73 * char *local_hostname; The current host.
75 * Tt_status *tt_status; Upon error, the tool talk error status will
76 * be returned for use by the caller. Use
77 * tt_status_message to get a printable string.
79 ********************************************************************************/
89 char * fully_qualified_name;
93 int len = strlen( directory_name );
97 printf ("Home host name is %s actual hostname is %s\n",
98 local_hostname, hostname);
101 /* construct full qualified filename
105 if( len == 1 && *directory_name == '/' )
107 fully_qualified_name = (char *)XtCalloc ( 1, ( strlen (file_name) + 2 ) );
108 sprintf( fully_qualified_name, "/%s", file_name );
112 fully_qualified_name = (char *)XtCalloc ( 1, ( len + strlen (file_name) + 2 ) );
113 sprintf( fully_qualified_name, "%s/%s", directory_name, file_name );
120 fully_qualified_name = (char *)XtMalloc ( len + 1 );
121 strcpy( fully_qualified_name, directory_name );
124 fully_qualified_name = NULL;
129 #if defined(FILE_MAP_OPTIMIZE)
130 /* check if local host name = hostname */
131 /* Do not do a tooltalk call if that is */
133 if (strcmp(hostname, local_hostname) == 0 )
136 printf ("fully qualified name is %s\n", path);
138 return (fully_qualified_name);
141 /* not on local host, make an rpc trip */
144 /* What about no hostname, then just send the file */
145 if (!hostname || (hostname[0] == '\0'))
146 return fully_qualified_name;
148 /* convert to network canonical name
150 cannon_name = (char *)tt_host_file_netfile (hostname, fully_qualified_name);
151 XtFree (fully_qualified_name);
152 if ( (*tt_status = tt_pointer_error(cannon_name)) != TT_OK)
155 printf( "Tooltalk error message: %s\n", tt_status_message(*tt_status));
161 /* resolve canonical name on local host
163 tmp = (char *) tt_netfile_file(cannon_name);
164 tt_free (cannon_name);
166 if ( (*tt_status = tt_pointer_error (tmp)) != TT_OK)
169 printf( "Tooltalk error message: %s\n", tt_status_message(*tt_status));
174 path = XtNewString( tmp );
183 ResolveTranslationString( char * originalString,
188 char * resolvedString = NULL;
189 int i, j, k, total, length;
191 sprintf( addressStr, "%p", address );
193 for( i = 0, total = 0; originalString[i] != '\0'; ++i )
194 if( originalString[i] == '@' )
197 length = strlen( originalString );
201 resolvedString = XtNewString( originalString );
205 resolvedString = (char *)XtCalloc( 1, length + ( ( strlen( addressStr ) )
207 if( resolvedString != NULL )
211 while( originalString[i] != '\0' )
213 if( originalString[i] == '@' )
215 for( k = 0; addressStr[k] != '\0'; ++j, ++k )
216 resolvedString[ j ] = addressStr[k];
220 resolvedString[ j++ ] = originalString[ i++ ];
225 return resolvedString;