123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $XConsortium: SharedProcs.c /main/7 1996/10/03 14:01:42 drk $ */
- /************************************<+>*************************************
- ****************************************************************************
- *
- * FILE: SharedProcs.c
- *
- * COMPONENT_NAME: Desktop File Manager (dtfile)
- *
- * Description: Contains the set of functions which are of general
- * use to all DT clients.
- *
- * FUNCTIONS: BuildBufferFileName
- * RenameCollisions
- * RenameEntry
- * RetrieveAndUseNameTemplateInfo
- * SetBufferFileNames
- * _DtAddOneSubdialog
- * _DtBuildActionArgsWithDroppedBuffers
- * _DtBuildActionArgsWithDroppedFiles
- * _DtBuildActionArgsWithSelectedFiles
- * _DtBuildActionArgsWithDTSelectedFiles
- * _DtBuildFMTitle
- * _DtBuildPath
- * _DtChangeTildeToHome
- * _DtCheckAndFreePixmapData
- * _DtCheckForDataTypeProperty
- * _DtCompileActionVector
- * _DtCopyDroppedFileInfo
- * _DtDestroySubdialog
- * _DtDestroySubdialogArray
- * _DtDuplicateDialogNameList
- * _DtFollowLink
- * _DtFreeActionArgs
- * _DtFreeDroppedBufferInfo
- * _DtFreeDroppedFileInfo
- * _DtGenericDestroy
- * _DtGenericMapWindow
- * _DtGenericUpdateWindowPosition
- * _DtGetSelectedFilePath
- * _DtHideOneSubdialog
- * _DtIsBufferExecutable
- * _DtLoadSubdialogArray
- * _DtMappedCB
- * _DtPName
- * _DtPathFromInput
- * _DtResolveAppManPath
- * _DtRetrieveDefaultAction
- * _DtRetrievePixmapData
- * _DtSaveSubdialogArray
- * _DtSetDroppedBufferInfo
- * _DtSetDroppedFileInfo
- * _DtSpacesInFileNames
- * _DtStringsAreEquivalent
- *
- * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
- * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
- * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
- * (c) Copyright 1993, 1994, 1995 Novell, Inc.
- *
- ****************************************************************************
- ************************************<+>*************************************/
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <limits.h>
- #include <stdio.h>
- #include <time.h>
- #include <pwd.h>
- #include <ctype.h>
- #include <Xm/Xm.h>
- #include <Xm/XmP.h>
- #include <Xm/VendorSEP.h>
- #include <Xm/MessageB.h>
- #include <Xm/RowColumn.h>
- #include <Xm/MwmUtil.h>
- #include <Xm/Protocols.h>
- #include <X11/ShellP.h>
- #include <X11/Shell.h>
- #include <X11/Xatom.h>
- /* Copied from Xm/BaseClassI.h */
- extern XmWidgetExtData _XmGetWidgetExtData(
- Widget widget,
- #if NeedWidePrototypes
- unsigned int extType) ;
- #else
- unsigned char extType) ;
- #endif /* NeedWidePrototypes */
- #include <Dt/DtP.h>
- #include <Dt/Connect.h>
- #include <Dt/DtNlUtils.h>
- #include <Dt/Dts.h>
- #include <Dt/Icon.h>
- #include <Dt/IconP.h>
- #include <Dt/IconFile.h>
- #include <Dt/Action.h>
- #include <Dt/Dnd.h>
- #include <Dt/Utility.h>
- #include <Dt/SharedProcs.h>
- #include <Tt/tttk.h>
- #include "Encaps.h"
- #include "FileMgr.h"
- #include "Desktop.h"
- #include "Common.h"
- #include "Main.h"
- #include "SharedProcs.h"
- extern char *pathcollapse();
- /* Defines */
- #define RW_ALL S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
- /* Global controlling whether auto-positioning is enabled */
- Boolean disableDialogAutoPlacement = False;
- /******** Static Function Declarations ********/
- static void SetBufferFileNames (
- char **file_set,
- DtDndBuffer *buffers,
- int num_of_buffers) ;
- static char * BuildBufferFileName (
- char *file_name,
- int postfix_index,
- void *buffer,
- int buffer_size) ;
- static char * RetrieveAndUseNameTemplateInfo(
- void *buffer,
- int buffer_size,
- char *template_input) ;
- static void RenameEntry(
- char **name,
- unsigned int addIndex) ;
- static void RenameCollisions(
- char **list,
- int count) ;
- /******** End Static Function Declarations ********/
- /************************************************************************
- *
- * _DtPName
- * Returns the parent directory of its argument.
- * Does this by looking for the last "/" in the name, and
- * NULL'ing it out.
- *
- ************************************************************************/
- char *
- _DtPName(
- char *name )
- {
- char * q;
- static char pnam[MAXPATHLEN];
- static char dot[] = ".";
- strcpy(pnam, name);
- q = strrchr(pnam, '/');
- if (q == NULL)
- q = pnam;
- else if ((q == pnam) &&
- #ifdef NLS16
- (mblen(q, MB_CUR_MAX) == 1) &&
- #endif
- (*q == '/'))
- {
- q++;
- }
- *q = '\0';
- return(pnam[0] ? pnam : dot);
- }
- /*
- * Given a filename, follow it to the end of its link. Returns NULL if
- * a recursive symbolic link is found.
- *
- * Note, the path returned is a static buffer, and should not be freed by
- * the calling function.
- */
- char *
- _DtFollowLink (
- char * path)
- {
- char link_path[MAXPATHLEN];
- static char file[MAXPATHLEN];
- int link_len;
- char * end;
- int history_count;
- int history_size;
- char ** history;
- int i;
- /* Used to check for symbolic link loops */
- history_count = 0;
- history_size = 100;
- history = (char **)XtMalloc(sizeof(char *) * history_size);
- strcpy(file, path);
- while ((link_len = readlink(file, link_path, MAXPATHLEN - 1)) > 0)
- {
- link_path[link_len] = 0;
- /* Force the link to be an absolute path, if necessary */
- if (link_path[0] != '/')
- {
- /* Relative paths are relative to the current directory */
- end = strrchr(file, '/') + 1;
- *end = '\0';
- strcat(file, link_path);
- }
- else
- strcpy(file, link_path);
- /* Check for a recursive loop; abort if found */
- for (i = 0; i < history_count; i++)
- {
- if (strcmp(file, history[i]) == 0)
- {
- for (i = 0; i < history_count; i++)
- XtFree(history[i]);
- XtFree((char *)history);
- history = NULL;
- return(NULL);
- }
- }
- /* Add to the history list */
- if (history_count >= history_size)
- {
- history_size += 100;
- history = (char **)XtRealloc((char *)history,
- sizeof(char *) * history_size);
- }
- history[history_count++] = XtNewString(file);
- }
- /* Free up the history list */
- for (i = 0; i < history_count; i++)
- XtFree(history[i]);
- XtFree((char *)history);
- history = NULL;
- return(file);
- }
- /************************************************************************
- *
- * _DtStringsAreEquivalent
- * Compare two strings and return true if equal.
- * The comparison is on lower cased strings. It is the callers
- * responsibility to ensure that test_str is already lower cased.
- *
- ************************************************************************/
- Boolean
- _DtStringsAreEquivalent(
- char *in_str,
- char *test_str )
- {
- #ifdef NLS16
- wchar_t c1;
- wchar_t c2;
- int c1size, c2size;
- #endif
- int i;
- int j;
- #ifdef NLS16
- if (is_multibyte)
- {
- for (;;)
- {
- /* Convert each character from multibyte to wide format */
- c1size = mbtowc(&c1, in_str, MB_CUR_MAX);
- c2size = mbtowc(&c2, test_str, MB_CUR_MAX);
- /* No match, if the two characters have different byte counts */
- if (c1size != c2size)
- return(False);
- /* Do case conversion only for single byte characters */
- if (c1size == 1)
- {
- if (isupper((int) c1))
- c1 = tolower((int) c1);
- }
- /* See if the two wide characters match */
- if (c1 != c2)
- return(False);
- /* Are we at the end of the string? */
- if (c1 == '\0')
- return(True);
- /* Keep comparing */
- in_str += c1size;
- test_str += c2size;
- }
- }
- else
- #endif
- {
- for (;;)
- {
- i = *in_str;
- j = *test_str;
- if (isupper (i)) i = tolower (i);
- if (i != j) return (False);
- if (i == 0) return (True);
- in_str++;
- test_str++;
- }
- }
- }
- void
- _DtDuplicateDialogNameList (
- char ** nameList,
- char ** newNameList,
- int newNameListSize,
- int * nameCount )
- {
- int i;
- /* Get a copy of the name list to be used to build new name lists. */
- *nameCount = 0;
- while (nameList[*nameCount] != NULL)
- {
- newNameList[*nameCount] = nameList[*nameCount];
- (*nameCount)++;
- }
- /* NULL out any remaining array entries */
- for (i = (*nameCount); i < newNameListSize; i++)
- newNameList[i] = NULL;
- }
- void
- _DtLoadSubdialogArray (
- char ** nameList,
- int nameCount,
- DialogData *** dialogArray,
- int dialogCount,
- int dialogId,
- XrmDatabase dataBase,
- int firstId )
- {
- int i;
- static char number[10];
- /* Load sub-dialogs */
- nameList[nameCount] = number;
- nameList[nameCount + 1] = NULL;
- /* Get text annotation dialogs */
- *dialogArray = (DialogData **) XtMalloc(sizeof(DialogData *) * dialogCount);
- for (i = 0; i < dialogCount; i++)
- {
- snprintf(number, 10, "%d", firstId);
- (*dialogArray)[i] = _DtGetResourceDialogData(dialogId, dataBase, nameList);
- firstId++;
- }
- }
- void
- _DtSaveSubdialogArray (
- char ** nameList,
- int nameCount,
- DialogData ** dialogArray,
- int dialogCount,
- int fd,
- int firstId )
- {
- int i;
- static char number[10];
- nameList[nameCount] = number;
- nameList[nameCount + 1] = NULL;
- for (i = 0; i < dialogCount; i++)
- {
- snprintf(number, 10, "%d", firstId);
- _DtWriteDialogData(dialogArray[i], fd, nameList);
- firstId++;
- }
- }
- void
- _DtDestroySubdialogArray (
- DialogData ** dialogArray,
- int dialogCount )
- {
- int i;
- for (i = 0; i < dialogCount; i++)
- {
- if (_DtIsDialogShowing(dialogArray[i]))
- _DtHideDialog(dialogArray[i], False);
- _DtFreeDialogData(dialogArray[i]);
- }
- XtFree((char *)dialogArray);
- }
- void
- _DtDestroySubdialog (
- DialogData * dialogData )
- {
- if (dialogData)
- {
- if (_DtIsDialogShowing(dialogData))
- _DtHideDialog(dialogData, False);
- _DtFreeDialogData(dialogData);
- }
- }
- void
- _DtHideOneSubdialog (
- DialogData * dialogData,
- DialogData *** dialogArray,
- int * dialogCountPtr )
- {
- int i, j;
- for (i = 0; i < *dialogCountPtr; i++)
- {
- if (dialogData == (*dialogArray)[i])
- {
- for (j = i; j < (*dialogCountPtr) - 1; j++)
- (*dialogArray)[j] = (*dialogArray)[j + 1];
- break;
- }
- }
- /* Free or decrease the size of the dialog data list */
- (*dialogCountPtr)--;
- if (*dialogCountPtr == 0)
- {
- XtFree((char *)*dialogArray);
- *dialogArray = NULL;
- }
- else
- {
- *dialogArray = (DialogData **)
- XtRealloc((char *)*dialogArray,
- sizeof(DialogData *) * (*dialogCountPtr));
- }
- }
- void
- _DtAddOneSubdialog (
- DialogData * dialogData,
- DialogData *** dialogArray,
- int * dialogCountPtr )
- {
- int count;
- count = *dialogCountPtr;
- (*dialogCountPtr)++;
- (*dialogArray) = (DialogData **) XtRealloc((char *)(*dialogArray),
- sizeof(DialogData *) * (*dialogCountPtr));
- (*dialogArray)[count] = dialogData;
- }
- /*
- * This function acts as a frontend to the encapsulator's map callback
- * function. If we are in the middle of a restore session, then we don't
- * want the map callback to alter the placement of the dialog, so we will
- * not call the encapsulator's function.
- */
- void
- _DtMappedCB(
- Widget w,
- XtPointer client_data,
- XtPointer call_data )
- {
- if (!disableDialogAutoPlacement)
- _DtmapCB(w,client_data,call_data);
- XtRemoveCallback(w, XmNpopupCallback, (XtCallbackProc)_DtMappedCB, client_data);
- }
- /*
- * This is the generic function for registering the map callback.
- */
- void
- _DtGenericMapWindow (
- Widget parent,
- XtPointer recordPtr)
- {
- GenericRecord * genericRecord = (GenericRecord *) recordPtr;
- XtAddCallback (genericRecord->shell, XmNpopupCallback,
- (XtCallbackProc)_DtMappedCB, (XtPointer) parent);
- }
- /*
- * This is the generic function for destroying a dialog widget hierarchy.
- */
- void
- _DtGenericDestroy(
- XtPointer recordPtr )
- {
- GenericRecord * genericRecord = (GenericRecord *) recordPtr;
- XtDestroyWidget(genericRecord->shell);
- XtFree((char *) genericRecord);
- }
- /*
- * This is the generic function for updating the shell's x and y, to
- * take the window manager border into consideration.
- */
- void
- _DtGenericUpdateWindowPosition(
- DialogData * dataPtr )
- {
- DialogInstanceData * genericData = (DialogInstanceData *) dataPtr->data;
- GenericRecord * genericRecord;
- /* Do nothing, if the dialog is not displayed */
- if (genericData->displayed == True)
- {
- XmVendorShellExtObject vendorExt;
- XmWidgetExtData extData;
- Window junkWindow;
- int t_x, t_y;
- Arg args[5];
- genericRecord = (GenericRecord *)_DtGetDialogInstance(dataPtr);
- XtSetArg(args[0], XmNwidth, &genericData->width);
- XtSetArg(args[1], XmNheight, &genericData->height);
- XtGetValues(genericRecord->shell, args, 2);
- XTranslateCoordinates(XtDisplay(genericRecord->shell),
- XtWindow(genericRecord->shell),
- RootWindowOfScreen(XtScreen(genericRecord->shell)),
- 0, 0, &t_x, &t_y,
- &junkWindow);
- genericData->x = (Position) t_x;
- genericData->y = (Position) t_y;
- /* Modify x & y to take into account window mgr frames */
- extData=_XmGetWidgetExtData(genericRecord->shell, XmSHELL_EXTENSION);
- vendorExt = (XmVendorShellExtObject)extData->widget;
- genericData->x -= vendorExt->vendor.xOffset;
- genericData->y -= vendorExt->vendor.yOffset;
- }
- }
- /*
- * This is a function for building a path from directory and filename
- * parameters.
- */
- void
- _DtBuildPath(
- char *path,
- char *directory,
- char *fileName)
- {
- if (directory)
- {
- if (fileName)
- sprintf(path, "%s/%s", directory, fileName);
- else
- sprintf(path, "%s", directory);
- }
- else
- {
- if (fileName)
- sprintf(path, "%s", fileName);
- else
- sprintf(path, "%s", "");
- }
- }
- /*
- * This is a function for retrieving the pixmap data for a data type.
- */
- PixmapData *
- _DtRetrievePixmapData(
- char *dataType,
- char *fileName,
- char *directory,
- Widget shell,
- int size)
- {
- PixmapData *pixmapData;
- char path[MAXPATHLEN];
- char *iconName;
- pixmapData = (PixmapData *) XtMalloc(sizeof(PixmapData));
- if (!pixmapData)
- return NULL;
- path[0] = 0x0;
- _DtBuildPath(path, directory, fileName);
- pixmapData->size = size;
- /* retrieve host name */
- pixmapData->hostPrefix = DtDtsDataTypeToAttributeValue(dataType,
- DtDTS_DA_DATA_HOST,
- NULL);
- /*
- retrieve instance icon name if one exists; otherwise, retrieve class
- icon name
- */
- if (path[0] != 0x0)
- {
- pixmapData->instanceIconName = DtDtsDataTypeToAttributeValue(dataType,
- DtDTS_DA_INSTANCE_ICON,
- path);
- }
- else
- pixmapData->instanceIconName = NULL;
- if (pixmapData->instanceIconName == NULL)
- {
- pixmapData->iconName = DtDtsDataTypeToAttributeValue( dataType,
- DtDTS_DA_ICON, NULL);
- if( pixmapData->iconName == NULL )
- {
- if( strcmp( dataType, LT_DIRECTORY ) == 0 )
- pixmapData->iconName = XtNewString( "DtdirB" );
- else
- pixmapData->iconName = XtNewString( "Dtdeflt" );
- }
- }
- else
- {
- pixmapData->iconName = NULL;
- }
- /* retrieve icon file name */
- if (pixmapData->size == LARGE)
- pixmapData->iconFileName = _DtGetIconFileName(XtScreen(shell),
- pixmapData->instanceIconName,
- pixmapData->iconName,
- pixmapData->hostPrefix,
- DtMEDIUM);
- else
- pixmapData->iconFileName = _DtGetIconFileName(XtScreen(shell),
- pixmapData->instanceIconName,
- pixmapData->iconName,
- pixmapData->hostPrefix,
- DtTINY);
- /* return pixmap data */
- return(pixmapData);
- }
- /*
- * This is a function for checking the size, etc of an icon pixmap and
- * freeing the pixmap data for an icon.
- */
- void
- _DtCheckAndFreePixmapData(
- char *dataType,
- Widget shell,
- DtIconGadget iconGadget,
- PixmapData *pixmapData)
- {
- Arg args[1];
- if (!pixmapData)
- return;
- /*
- if there was an instance icon name; verify that the pixmap parameters
- do not exceed system limits; if system limits are exceeded, retrieve
- class icon name and set icon gadget image resource to this value
- */
- if (pixmapData->instanceIconName)
- {
- if(! pixmapData->iconFileName && iconGadget->icon.pixmap == 0)
- { /* Try to get pixmap name
- */
- char * tmp, * ptr;
- tmp = XtNewString( pixmapData->instanceIconName );
- if( ptr = strrchr( tmp,'/' ) )
- *(ptr) = 0;
- XmeFlushIconFileCache( tmp );
- if (pixmapData->iconFileName != NULL)
- XtFree(pixmapData->iconFileName);
- if (pixmapData->size == LARGE)
- pixmapData->iconFileName = _DtGetIconFileName( XtScreen(shell),
- pixmapData->instanceIconName,
- NULL,
- pixmapData->hostPrefix,
- DtMEDIUM );
- else
- pixmapData->iconFileName = _DtGetIconFileName(XtScreen(shell),
- pixmapData->instanceIconName,
- NULL,
- pixmapData->hostPrefix,
- DtTINY);
- XtSetArg(args[0], XmNimageName, pixmapData->iconFileName);
- XtSetValues((Widget) iconGadget, args, 1);
- XtFree( tmp );
- }
- DtDtsFreeAttributeValue(pixmapData->instanceIconName);
- pixmapData->instanceIconName = NULL;
- if (iconGadget->icon.pixmap == 0 ||
- iconGadget->icon.pixmap_width == 0 ||
- iconGadget->icon.pixmap_height == 0 ||
- (Dimension)iconGadget->icon.pixmap_width > (Dimension)instanceWidth ||
- (Dimension)iconGadget->icon.pixmap_height > (Dimension)instanceHeight)
- {
- pixmapData->iconName = DtDtsDataTypeToAttributeValue(
- dataType,
- DtDTS_DA_ICON, NULL);
- /* retrieve icon file name */
- if (pixmapData->iconFileName != NULL)
- {
- XtFree(pixmapData->iconFileName);
- pixmapData->iconFileName = NULL;
- }
- if (pixmapData->size == LARGE)
- pixmapData->iconFileName = _DtGetIconFileName(XtScreen(shell),
- pixmapData->instanceIconName,
- pixmapData->iconName,
- pixmapData->hostPrefix,
- DtMEDIUM);
- else
- pixmapData->iconFileName = _DtGetIconFileName(XtScreen(shell),
- pixmapData->instanceIconName,
- pixmapData->iconName,
- pixmapData->hostPrefix,
- DtTINY);
- XtSetArg(args[0], XmNimageName, pixmapData->iconFileName);
- XtSetValues((Widget) iconGadget, args, 1);
- DtDtsFreeAttributeValue(pixmapData->iconName);
- pixmapData->iconName = NULL;
- }
- }
- else
- {
- DtDtsFreeAttributeValue(pixmapData->iconName);
- pixmapData->iconName = NULL;
- }
- DtDtsFreeAttributeValue(pixmapData->hostPrefix);
- if (pixmapData->iconFileName)
- XtFree(pixmapData->iconFileName);
- XtFree((char *) pixmapData);
- }
- /*
- * This is a function for checking for a datatype property.
- */
- Boolean
- _DtCheckForDataTypeProperty(
- char *dataType,
- char *property)
- {
- char *properties;
- char *prop;
- char *props;
- Boolean found = False;
- properties = DtDtsDataTypeToAttributeValue(dataType,
- DtDTS_DA_PROPERTIES,
- NULL);
- if (properties)
- {
- props = properties;
- prop = props;
- while (props = DtStrchr(props, ','))
- {
- *props = '\0';
- if (strcmp(prop, property) == 0)
- {
- found = True;
- break;
- }
- *props = ',';
- props++;
- prop = props;
- }
- if (!props)
- {
- if (strcmp(prop, property) == 0)
- found = True;
- }
- DtDtsFreeAttributeValue(properties);
- }
- return found;
- }
- /*
- * This is a function for compiling a vectorized action list for a data type.
- */
- char **
- _DtCompileActionVector(
- char *dataType)
- {
- char *actions;
- char **vector = NULL;
- actions = DtDtsDataTypeToAttributeValue(dataType,
- DtDTS_DA_ACTION_LIST,
- NULL);
- if (actions)
- vector = (char **) _DtVectorizeInPlace(actions, ',');
- return(vector);
- }
- /*
- * This is a generic function for retrieving the default action for a data
- * type.
- */
- char *
- _DtRetrieveDefaultAction(
- char *dataType)
- {
- char *actions;
- char *acts;
- char *default_action = NULL;
- actions = DtDtsDataTypeToAttributeValue(dataType,
- DtDTS_DA_ACTION_LIST,
- NULL);
- if (actions)
- {
- if (acts = DtStrchr(actions, ','))
- *acts = '\0';
- default_action = XtNewString(actions);
- DtDtsFreeAttributeValue(actions);
- }
- return(default_action);
- }
- /*
- * This is a function for building a title for a File Manager view.
- */
- char *
- _DtBuildFMTitle(
- FileMgrData *file_mgr_data )
- {
- char *title, *ptr, *fileLabel, *fileName;
- if (fileLabel = DtDtsFileToAttributeValue(file_mgr_data->current_directory,
- DtDTS_DA_LABEL))
- ptr = fileLabel;
- else if (fileName = strrchr(file_mgr_data->current_directory, '/'))
- ptr = fileName + 1;
- else
- ptr = "";
- if (file_mgr_data->title)
- {
- if (file_mgr_data->toolbox &&
- strcmp(file_mgr_data->current_directory,
- file_mgr_data->restricted_directory) != 0)
- {
- title = (char *)XtMalloc(strlen(file_mgr_data->title) +
- strlen(ptr) +
- 4); /* Need for blank dash blank NULL */
- sprintf(title, "%s - %s", file_mgr_data->title, ptr);
- }
- else
- {
- title = XtNewString(file_mgr_data->title);
- }
- }
- else
- {
- if (strcmp(file_mgr_data->current_directory, "/") == 0 && !fileLabel)
- {
- title = (char *)XtMalloc(strlen((GETMESSAGE(12, 7, "File Manager"))) +
- strlen(file_mgr_data->host) +
- strlen(root_title) +
- 5); /* Need for blank dash blank colon NULL */
- sprintf( title, "%s - %s:%s", (GETMESSAGE(12, 7, "File Manager")),
- file_mgr_data->host,
- root_title );
- }
- else
- {
- title = (char *)XtMalloc(strlen((GETMESSAGE(12, 7, "File Manager"))) +
- strlen(ptr) +
- 4); /* Need for blank dash blank NULL */
- sprintf( title, "%s - %s", (GETMESSAGE(12, 7, "File Manager")), ptr);
- }
- }
- DtDtsFreeAttributeValue(fileLabel);
- return(title);
- }
- /*
- * This is a function for building a path from the directory name
- * and file name pieces of a FileViewData structure.
- */
- char *
- _DtGetSelectedFilePath(
- FileViewData *selected_file )
- {
- char *directory;
- char *file;
- char *path;
- directory = ((DirectorySet *)selected_file->directory_set)->name;
- file = selected_file->file_data->file_name;
- if (strcmp(directory, "/") == 0)
- {
- path = XtMalloc(strlen(directory) + strlen(file) + 1);
- sprintf(path, "%s%s", directory, file);
- }
- else
- {
- path = XtMalloc(strlen(directory) + strlen(file) + 2);
- sprintf(path, "%s/%s", directory, file);
- }
- return(path);
- }
- /*
- * This is a generic function for building action parameters from an array of
- * file view data structures.
- */
- void
- _DtBuildActionArgsWithSelectedFiles(
- FileViewData **selection_list,
- int selected_count,
- DtActionArg **action_args,
- int *arg_count )
- {
- *arg_count = 0;
- *action_args = (DtActionArg *)
- XtCalloc(1, sizeof(DtActionArg) * selected_count);
- if (*action_args)
- {
- int i;
- for(i = 0; i < selected_count; i++)
- {
- ((*action_args)[(*arg_count)]).argClass = DtACTION_FILE;
- ((*action_args)[(*arg_count)++]).u.file.name =
- _DtGetSelectedFilePath(selection_list[i]);
- }
- }
- }
- void
- _DtBuildActionArgsWithDTSelectedFiles(
- DesktopRec **selection_list,
- int selected_count,
- DtActionArg **action_args,
- int *arg_count )
- {
- *arg_count = 0;
- *action_args = (DtActionArg *)
- XtCalloc(1, sizeof(DtActionArg) * selected_count);
- if (*action_args)
- {
- int i;
- for(i = 0; i < selected_count; i++)
- {
- ((*action_args)[(*arg_count)]).argClass = DtACTION_FILE;
- ((*action_args)[(*arg_count)++]).u.file.name =
- _DtGetSelectedFilePath(selection_list[i]->file_view_data);
- }
- }
- }
- /*
- * This is a generic function for building action parameters from drag and drop
- * file information.
- */
- void
- _DtBuildActionArgsWithDroppedFiles(
- FileViewData *dropped_on_obj,
- DtDndDropCallbackStruct *drop_parameters,
- DtActionArg **action_args,
- int *arg_count )
- {
- *arg_count = 0;
- if (dropped_on_obj)
- *action_args = (DtActionArg *) XtCalloc
- (1, sizeof(DtActionArg) * (drop_parameters->dropData->numItems + 1));
- else
- *action_args = (DtActionArg *) XtCalloc
- (1, sizeof(DtActionArg) * drop_parameters->dropData->numItems);
- if (*action_args)
- {
- int i;
- if (dropped_on_obj)
- {
- ((*action_args)[(*arg_count)]).argClass = DtACTION_FILE;
- ((*action_args)[(*arg_count)++]).u.file.name =
- _DtGetSelectedFilePath(dropped_on_obj);
- }
- for(i = 0; i < drop_parameters->dropData->numItems; i++)
- {
- ((*action_args)[(*arg_count)]).argClass = DtACTION_FILE;
- ((*action_args)[(*arg_count)++]).u.file.name =
- XtNewString(drop_parameters->dropData->data.files[i]);
- }
- }
- }
- /*
- * This is a generic function for building action parameters from drag and drop
- * buffer information.
- */
- void
- _DtBuildActionArgsWithDroppedBuffers(
- FileViewData *dropped_on_obj,
- DtDndDropCallbackStruct *drop_parameters,
- DtActionArg **action_args,
- int *arg_count )
- {
- *arg_count = 0;
- if (dropped_on_obj)
- *action_args = (DtActionArg *) XtCalloc
- (1, sizeof(DtActionArg) * (drop_parameters->dropData->numItems + 1));
- else
- *action_args = (DtActionArg *) XtCalloc
- (1, sizeof(DtActionArg) * drop_parameters->dropData->numItems);
- if (*action_args)
- {
- int i;
- DtActionBuffer buffer_arg = {NULL, 0, NULL, NULL, False};
- if (dropped_on_obj)
- {
- ((*action_args)[(*arg_count)]).argClass = DtACTION_FILE;
- ((*action_args)[(*arg_count)++]).u.file.name =
- _DtGetSelectedFilePath(dropped_on_obj);
- }
- for(i = 0; i < drop_parameters->dropData->numItems; i++)
- {
- buffer_arg.bp = drop_parameters->dropData->data.buffers[i].bp;
- buffer_arg.size = drop_parameters->dropData->data.buffers[i].size;
- buffer_arg.name = drop_parameters->dropData->data.buffers[i].name;
- ((*action_args)[(*arg_count)]).argClass = DtACTION_BUFFER;
- ((*action_args)[(*arg_count)++]).u.buffer = buffer_arg;
- }
- }
- }
- /*
- * This is a generic function for freeing action parameters.
- */
- void
- _DtFreeActionArgs(
- DtActionArg *action_args,
- int arg_count )
- {
- int i;
- for (i = 0; i < arg_count; i++)
- {
- if (action_args[i].argClass == DtACTION_FILE)
- {
- XtFree(action_args[i].u.file.name);
- action_args[i].u.file.name = NULL;
- }
- }
-
- XtFree((char *) action_args);
- }
- /************************************************************************
- * The following functions deal with Buffer Manipulation and Naming
- ************************************************************************/
- /*
- * This is a generic function for extracting buffer information from
- * drop input.
- */
- void
- _DtSetDroppedBufferInfo(char **file_set,
- BufferInfo *buffer_set,
- char **host_set,
- DtDndDropCallbackStruct *drop_parameters)
- {
- int num_of_buffers = drop_parameters->dropData->numItems;
- int i;
- DtDndBuffer *buffers = drop_parameters->dropData->data.buffers;
- DPRINTF (("Executing..._DtSetDroppedBufferInfo\n"));
- /* Initialize file_set and ensure of unique file names for unamed buffers*/
- SetBufferFileNames(file_set, buffers, num_of_buffers);
- for (i= 0; i < num_of_buffers; i++)
- {
- (buffer_set[i]).buf_ptr = buffers[i].bp;
- (buffer_set[i]).size = buffers[i].size;
- host_set[i] = XtNewString(home_host_name);
- DPRINTF(("_DtSetDroppedBufferInfo:\n host_set[%d]=%s,\
- buffer_set[%d].buf_ptr=%p, buffer_set[%d].size=%d\n",
- i, host_set[i], i, buffer_set[i].buf_ptr, i, buffer_set[i].size));
- }
- }
- /*
- * This is a function for creating file names for a set of buffers.
- */
- static void
- SetBufferFileNames (char **file_set,
- DtDndBuffer *buffers,
- int num_of_buffers)
- {
- int null_filenames_count = 0;
- int i;
- int first_nullfile_index = 0;
- Boolean NULL_FILENAMES=FALSE;
- DPRINTF (("Executing...SetBufferFileNames\n"));
- for (i = 0; i < num_of_buffers; i++)
- {
- if (buffers[i].name == NULL)
- {
- /* generate buffer name using Untitled as a base name */
- file_set[i]=BuildBufferFileName(DEFAULT_BUFFER_FILENAME,
- -1,
- buffers[i].bp,
- buffers[i].size);
- }
- else
- {
- /* file name is supplied by the drag initiator */
- file_set[i] = XtNewString(buffers[i].name);
- }
- DPRINTF(("file_set[%d]=%s\n", i, file_set[i]));
- } /* end for loop */
- /* Rename any collisions to unique names */
- RenameCollisions(file_set, num_of_buffers);
- return;
- }
- /*
- * This is a generic function for generating a name for an untitled buffer.
- * A default name (Untitled) is used in conjunction with the name template
- * information from the types database.
- */
- static char *
- BuildBufferFileName (char *file_name,
- int postfix_index,
- void *buffer,
- int buffer_size)
- {
- const char delim = '_';
- char *new_file_name;
- DPRINTF (("Executing....BuildBufferFileName\n"));
- /* Malloc memory and contruct the new file name */
- new_file_name = (char *) XtMalloc (strlen(file_name) + 1 +
- MAX_POSTFIX_LENGTH + 1);
- DPRINTF (("BuildBufferFileName: Old file name is %s\n", file_name));
- /* determine whether to append post fix name */
- if (postfix_index == -1)
- strcpy(new_file_name, file_name);
- else
- sprintf(new_file_name,"%s%c%d", file_name, delim, postfix_index);
- /* Retrieve the name template if it exists and use it in the filename */
- new_file_name = RetrieveAndUseNameTemplateInfo(buffer,
- buffer_size,
- new_file_name);
- DPRINTF(("BuildBufferFileName: Returning new_file_name=%s\n", new_file_name));
- /* return new file name */
- return (new_file_name);
- }
- /*
- * This is a function for building a buffer name using predfined input
- * and name template information from the types database.
- * WARNING: template_input MAY be freed. It must point to a char *.
- */
- static char *
- RetrieveAndUseNameTemplateInfo(
- void *buffer,
- int buffer_size,
- char *template_input)
- {
- char *name_template;
- char *buffer_name = NULL;
- name_template = DtDtsBufferToAttributeValue(buffer,
- buffer_size,
- DtDTS_DA_NAME_TEMPLATE,
- NULL);
- if (name_template)
- buffer_name = (char *) XtMalloc(strlen(name_template) +
- strlen(template_input) +
- 1);
- if (buffer_name)
- {
- sprintf(buffer_name, name_template, template_input);
- DtDtsFreeAttributeValue(name_template);
- XtFree(template_input);
- return(buffer_name);
- }
- else
- {
- DtDtsFreeAttributeValue(name_template);
- return(template_input);
- }
- }
- /*
- * This is a function for resolving collisions in a list of buffer names.
- */
- static void
- RenameCollisions( char ** list, int count )
- {
- int i, j, k, l;
- char flg = 0, flg2 = 0;
- for( i = 0; i < count; ++i )
- {
- unsigned int addIndex = 1;
- if( *(list[i]) == 0x0 )
- {
- k = i;
- flg = 1;
- }
- for( j = i+1; j < count; ++j )
- {
- if( strcmp( list[i], list[j] ) == 0 )
- {
- RenameEntry( &(list[j]), ++addIndex );
- l = i;
- flg2 = 1;
- }
- }
- if( flg2 )
- {
- flg2 = 0;
- RenameEntry( &(list[l]), 1 );
- }
- }
- if( flg )
- {
- free( list[k] );
- list[k] = (char *)malloc( strlen( DEFAULT_BUFFER_FILENAME ) + 1 );
- sprintf( list[k], "%s", DEFAULT_BUFFER_FILENAME );
- }
- }
- /*
- * This is a function for adding an index to a buffer name which has
- * collided.
- */
- static void
- RenameEntry( char ** name, unsigned int addIndex )
- {
- #define MAX_INT_SIZE 15
- char * tmpPtr, * newName;
- if( *name == 0x0 )
- return;
- else if( **name == 0x0 )
- {
- newName = (char *)XtCalloc(1,strlen(DEFAULT_BUFFER_FILENAME)+ MAX_INT_SIZE);
- sprintf( newName, "%s_%d", DEFAULT_BUFFER_FILENAME, addIndex );
- }
- else
- {
- tmpPtr = strrchr( *name, '.' );
- newName = (char *)XtCalloc( 1, strlen( *name ) + MAX_INT_SIZE );
- if( tmpPtr == NULL )
- sprintf( newName, "%s_%d", *name, addIndex );
- else if( tmpPtr == *name )
- sprintf( newName, "%d%s", addIndex, *name );
- else
- {
- *tmpPtr = 0x0;
- sprintf( newName, "%s_%d.%s", *name, addIndex, ++tmpPtr);
- }
- }
- free( *name );
- *name = newName;
- }
- /*
- * This is a generic function for freeing buffer information extracted from
- * drop input.
- */
- void
- _DtFreeDroppedBufferInfo(char **file_set,
- BufferInfo *buffer_set,
- char **host_set,
- int num_of_buffers)
- {
- int i;
- DPRINTF (("Executing..._DtFreeDroppedBufferInfo\n"));
- /* Check for Null pointers */
- if (file_set && buffer_set && host_set )
- {
- for (i=0; i< num_of_buffers; i++ )
- {
- XtFree(file_set[i]);
- XtFree(host_set[i]);
- }
- XtFree((char *)file_set);
- XtFree((char *)host_set);
- XtFree((char *)buffer_set);
- }
- }
- /*
- * This is a generic function for determining if a buffer is executable.
- */
- Boolean
- _DtIsBufferExecutable(
- void *buffer,
- int buffer_size)
- {
- char *exe_attribute;
- Boolean is_exe = False;
- exe_attribute = DtDtsBufferToAttributeValue(buffer,
- buffer_size,
- "IS_EXECUTABLE",
- NULL);
- if (exe_attribute)
- {
- if (DtDtsIsTrue(exe_attribute))
- is_exe = True;
- DtDtsFreeAttributeValue(exe_attribute);
- }
- return(is_exe);
- }
- /*
- * This is a generic function for extracting file information from drop input.
- */
- void
- _DtSetDroppedFileInfo(
- DtDndDropCallbackStruct *drop_parameters,
- char ***file_set,
- char ***host_set)
- {
- int numFiles, i;
- numFiles = drop_parameters->dropData->numItems;
- *file_set = (char **)XtMalloc(sizeof(char *) * numFiles);
- *host_set = (char **)XtMalloc(sizeof(char *) * numFiles);
- for(i = 0; i < numFiles; i++)
- {
- (*file_set)[i] = XtNewString(drop_parameters->dropData->data.files[i]);
- (*host_set)[i] = home_host_name;
- DPRINTF(("ProcessMoveCopyLink:\n host_set[%d]=%s, file_set[%d]=%s\n",
- i, (*host_set)[i], i, (*file_set)[i]));
- }
- }
- /*
- * This is a generic function for copying file info extracted from drop input.
- */
- void
- _DtCopyDroppedFileInfo(
- int num_files,
- char **orig_file_set,
- char **orig_host_set,
- char ***new_file_set,
- char ***new_host_set)
- {
- int i;
- *new_file_set = (char **)XtMalloc(sizeof(char *) * num_files);
- *new_host_set = (char **)XtMalloc(sizeof(char *) * num_files);
- for(i = 0; i < num_files; i++)
- {
- (*new_file_set)[i] = XtNewString(orig_file_set[i]);
- (*new_host_set)[i] = XtNewString(orig_host_set[i]);
- }
- }
- /*
- * This is a generic function for freeing file info extracted from drop input.
- */
- void
- _DtFreeDroppedFileInfo(
- int num_files,
- char **file_set,
- char **host_set)
- {
- int i;
- for(i = 0; i < num_files; i++)
- XtFree(file_set[i]);
- XtFree((char *)file_set);
- XtFree((char *)host_set);
- }
- /*
- * This is a generic function for resolving a cannonical path from user input.
- */
- void
- _DtPathFromInput(
- char *input_string,
- char *current_dir,
- char **host,
- char **rel_path)
- {
- char *path;
- char *tmp_path = NULL;
- char *true_path = NULL;
- Tt_status tt_status;
- int dir_len;
- /* find host */
- *host = XtNewString(home_host_name);
- /* find relative path */
- tmp_path = path = XtNewString(input_string);
- /* Strip any spaces from name -- input is overwritten */
- path = (char *) _DtStripSpaces(path);
- /* Resolve, if there're any, environment variables */
- {
- FILE *pfp = NULL;
- char command[MAXPATHLEN];
- memset(command, 0, sizeof(command));
- sprintf(command,"echo %s",path);
- if((pfp=popen(command,"r")) != NULL)
- {
- int read_ok = 1;
- if (NULL == (fgets(command,MAXPATHLEN,pfp)))
- {
- /*
- * Try a few more reads and if the read still fails,
- * just use the path as is.
- */
- int i;
- for (i=0; i < 5; i++)
- {
- sleep (1);
- if (NULL != (fgets(command,MAXPATHLEN,pfp)))
- break;
- }
- if (i >= 5)
- read_ok = 0;
- }
- if (read_ok)
- {
- int slen = strlen(command);
- /* need to remove the trailing newline safely*/
- if (slen >= 1)
- command[slen-1] = '\0';
- XtFree(path);
- path = XtNewString(command);
- pclose(pfp);
- pfp = NULL;
- }
- }
- if (pfp)
- {
- pclose(pfp);
- pfp = NULL;
- }
- }
- /* Resolve '~' -- new memory is allocated, old memory is freed */
- if (*path == '~')
- path = _DtChangeTildeToHome(path);
- /* If current dir provided, check for relative path */
- if (path && current_dir)
- {
- if (*path != '/')
- {
- /* file is relative path i.e. xyz/abc */
- if (strcmp(current_dir, "/") == 0)
- {
- tmp_path = (char *)XtMalloc(strlen(current_dir) + strlen(path) + 1);
- sprintf(tmp_path, "%s%s", current_dir, path);
- }
- else
- {
- tmp_path = (char *)XtMalloc(strlen(current_dir) + strlen(path) + 2);
- sprintf(tmp_path, "%s/%s", current_dir, path);
- }
- XtFree(path);
- path = tmp_path;
- tmp_path = NULL;
- }
- }
- else if (!path)
- {
- *rel_path = NULL;
- XtFree(tmp_path);
- return;
- }
- /* Resolve '.' or '..' -- input is overwritten, output may be NULL! */
- /* Save pointer to path to free if output is NULL. */
- tmp_path = path;
- path = (char *) DtEliminateDots(path);
- if (path)
- {
- /* Resolve to local pathname */
- true_path = ResolveLocalPathName(*host,
- path,
- NULL,
- home_host_name,
- &tt_status);
- XtFree(path);
- /* Strip off trailing '/' */
- dir_len = strlen(true_path);
- if (dir_len > 1 && *(true_path + dir_len - 1) == '/')
- *(true_path + dir_len - 1) = '\0';
- }
- else
- {
- true_path = NULL;
- XtFree(tmp_path);
- }
- *rel_path = true_path;
- }
- /*
- * This function takes a path name, and resolves any leading '~' to refer
- * to one of the following:
- *
- * 1) if ~ or ~/path, then it resolves to the user's home directory on
- * their home host.
- *
- * 2) if ~user or ~user/path, then it resolves to the specified user's
- * home directory on the home host.
- *
- * This function never resolves to any host but the home host, since we
- * have no way of determining a user's home directory on any system other
- * than the home system.
- */
- char *
- _DtChangeTildeToHome (
- char *input_string)
- {
- char *path;
- char *full_path;
- struct passwd * pwInfo;
- if ((input_string[1] != '\0') && (input_string[1] != '/'))
- {
- char *path;
- /* ~user or ~user/path format */
- /* is there a path? */
- path = DtStrchr(input_string, '/');
- /* find user */
- if (path)
- *path = '\0';
- if ((pwInfo = getpwnam(input_string + 1)) == NULL)
- {
- /* user doesn't exist */
- if (path)
- *path = '/';
- return NULL;
- }
- if (path)
- {
- /* ~user/path format */
- *path = '/';
- if (strcmp(pwInfo->pw_dir, "/") == 0)
- {
- /* We don't want to end up with double '/' in the path */
- full_path = (char *) XtMalloc(strlen(path) + 1);
- strcpy(full_path, path);
- }
- else
- {
- full_path = (char *) XtMalloc(strlen(pwInfo->pw_dir) +
- strlen(path) + 1);
- sprintf(full_path, "%s%s", pwInfo->pw_dir, path);
- }
- }
- else
- {
- /* ~user format */
- full_path = XtMalloc(strlen(pwInfo->pw_dir) + 1);
- strcpy(full_path, pwInfo->pw_dir);
- }
- }
- else if (input_string[1])
- {
- /* ~/path format */
- /* NOTE: users_home_dir has trailing '/' */
- full_path = XtMalloc(strlen(users_home_dir) + strlen(input_string+2) + 1);
- sprintf(full_path, "%s%s", users_home_dir, (input_string + 2));
- }
- else
- {
- /* ~ format */
- full_path = XtMalloc(strlen(users_home_dir) + 1);
- strcpy(full_path, users_home_dir);
- }
- XtFree(input_string);
- return(full_path);
- }
- /*
- * This function checks for spaces in filenames.
- */
- #ifdef _CHECK_FOR_SPACES
- Boolean
- _DtSpacesInFileNames(
- char **fileNames,
- int fileCount )
- {
- int i;
- for (i = 0; i < fileCount; i++)
- {
- fileNames[i] = (char *) _DtStripSpaces(fileNames[i]);
- if (DtStrchr (fileNames[i], ' ') != NULL ||
- DtStrchr (fileNames[i], '\t') != NULL)
- return(TRUE);
- }
- return(FALSE);
- }
- #endif
- /*
- * This resolves the path for an appmanager object to its true path.
- */
- char *
- _DtResolveAppManPath(
- char *path,
- char *restricted_dir )
- {
- if (strlen(path) > strlen(restricted_dir))
- {
- char *linkDir, *ptr, *tmpPath;
- linkDir = path + strlen(restricted_dir) + 1;
- ptr = DtStrchr(linkDir, '/');
- if (ptr)
- {
- *ptr = '\0';
- linkDir = _DtFollowLink(path);
- *ptr = '/';
- tmpPath = XtMalloc(strlen(linkDir) + strlen(ptr) + 1);
- sprintf(tmpPath, "%s%s", linkDir, ptr);
- XtFree(path);
- path = tmpPath;
- }
- else
- {
- linkDir = _DtFollowLink(path);
- XtFree(path);
- path = XtNewString(linkDir);
- }
- }
- return(path);
- }
|