X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=cde%2Fprograms%2Fdtstyle%2FBackdrop.c;h=2168a13a1d8b5f9df81bf220195035e6d7226a8e;hb=4f5e7fe5e3b8ef48be3b7129d0a4411c2a100170;hp=65a7daa217d9e9961f60d23d91d7d4adcc6bf5d8;hpb=83b6996daa2c5ae22fc2b69093814cb08314954a;p=oweals%2Fcde.git diff --git a/cde/programs/dtstyle/Backdrop.c b/cde/programs/dtstyle/Backdrop.c index 65a7daa2..2168a13a 100644 --- a/cde/programs/dtstyle/Backdrop.c +++ b/cde/programs/dtstyle/Backdrop.c @@ -1,3 +1,25 @@ +/* + * 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 + */ /* $TOG: Backdrop.c /main/7 1998/11/25 14:48:36 samborn $ */ /************************************<+>************************************* **************************************************************************** @@ -20,7 +42,10 @@ /* include files */ /*+++++++++++++++++++++++++++++++++++++++*/ #include +#include +#include #include +#include #if defined(_AIX) || defined(__apollo) #include @@ -401,10 +426,10 @@ CreateBackdropDialog( XtFree(bd_desc); /* Set up DialogBox button labels. */ - strings[0] = XmStringCreateLocalized (_DtOkString); - strings[1] = XmStringCreateLocalized (_DtApplyString); - strings[2] = XmStringCreateLocalized (_DtCloseString); - strings[3] = XmStringCreateLocalized (_DtHelpString); + strings[0] = XmStringCreateLocalized ((String) _DtOkString); + strings[1] = XmStringCreateLocalized ((String) _DtApplyString); + strings[2] = XmStringCreateLocalized ((String) _DtCloseString); + strings[3] = XmStringCreateLocalized ((String) _DtHelpString); /* saveRestore * Note that save.poscnt has been initialized elsewhere. @@ -516,6 +541,17 @@ MoreBitmaps( void ) backdrops.maxNumBitmaps += 100; } +/************************************************************************ + * cmpstringp() + * qsort() sort function, used for sorting bitmap names into alphabetical order + * can't use strcmp() due to char** rather than char* + ************************************************************************/ +static int +cmpstringp(const void *p1, const void *p2) +{ + return strcmp(*(char * const *) p1, *(char * const *) p2); +} + /************************************************************************ * ReadBitmaps() * Create an array of bitmaps by reading backdrop directories in the @@ -530,7 +566,7 @@ static ReadBitmaps( void ) { int status; - Pixmap tmpPix = NULL; + Pixmap tmpPix = 0; int width, height, x, y; Window win; int num; @@ -558,21 +594,26 @@ static /* read the directory $HOME/.dt/backdrops */ string = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops") + 1); - sprintf(string, "%s/.dt/backdrops", style.home); - ReadBitmapDirectory(string); if (string != NULL) + { + sprintf(string, "%s/.dt/backdrops", style.home); + ReadBitmapDirectory(string); XtFree(string); + } if (backdrops.tmpNumBitmaps == 0) { /* give error dialog, free space, and return */ backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1); - sprintf(backdrops.errStr, ERR2); + sprintf(backdrops.errStr, "%s", ERR2); ErrDialog (backdrops.errStr, style.shell); FreeAll(); free_dirList(backdrops.dirList, backdrops.dirCount); return 0; } + + /* Sort the list into alphanetical order */ + qsort(backdrops.tmpBitmapNames, backdrops.tmpNumBitmaps, sizeof(char *), cmpstringp); /* get the fg/bg colors from Dtwm */ if (backdrops.newColors) @@ -586,7 +627,7 @@ static { /* give error dialog, free space, and return */ backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1); - sprintf(backdrops.errStr, ERR2); + sprintf(backdrops.errStr, "%s", ERR2); ErrDialog (backdrops.errStr, style.shell); FreeAll(); free_dirList(backdrops.dirList, backdrops.dirCount); @@ -698,12 +739,20 @@ ReadBitmapDirectory( filep = readdir(dirp); continue; } - - /* strip suffix off filename */ name = (char *) XtMalloc(strlen(filep->d_name) + 1); strcpy (name, filep->d_name); - (void)strtok(name, "."); + + /* strip suffix off filename if it's a .pm or .bm + * motif requires other formats like jpg, png etc to + * have the extension on to work with the XmGetPixmap() calls */ + if(strlen(name) > 3 + && (0 == strcmp(name + strlen(name) - 3, ".pm") + || 0 == strcmp(name + strlen(name) - 3, ".bm"))) + { + (void)strtok(name, "."); + } + /* check for duplicates */ duplicate = 0; @@ -1107,7 +1156,7 @@ restoreBackdrop( XrmValue value; xrm_name [0] = XrmStringToQuark (BACKDROPSDLG); - xrm_name [2] = NULL; + xrm_name [2] = 0; /* get x position */ xrm_name [1] = XrmStringToQuark ("x"); @@ -1197,7 +1246,9 @@ saveBackdrop( backdrops.selected); sprintf(bufr, "%s*backdropsDialog.selectedItem: %s\n", bufr, backdrops.bitmapNames[backdrops.selected]); - write (fd, bufr, strlen(bufr)); + if(-1 == write (fd, bufr, strlen(bufr))) { + perror(strerror(errno)); + } } }