~ubuntu-branches/ubuntu/trusty/libcdk5/trusty

« back to all changes in this revision

Viewing changes to fselect.c

  • Committer: Bazaar Package Importer
  • Author(s): John Goerzen
  • Date: 2007-06-06 03:54:31 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070606035431-ba4gdvw0h6ybffsu
Tags: 5.0.20060507-1
* New upstream release.
* Fixed header patching.  Patch from Robert Schiele.
  Closes: #402978, #416336.
* Update widget count in description.  Closes: #294709.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define TRACE
1
2
#include <cdk_int.h>
2
3
 
3
4
/*
4
5
 * $Author: tom $
5
 
 * $Date: 2004/08/31 01:41:29 $
6
 
 * $Revision: 1.56 $
 
6
 * $Date: 2006/05/07 00:22:25 $
 
7
 * $Revision: 1.68 $
7
8
 */
8
9
 
9
10
/*
10
11
 * Declare file local prototypes.
11
12
 */
12
 
static BINDFN_PROTO(completeFilenameCB);
13
 
static BINDFN_PROTO(displayFileInfoCB);
14
 
static BINDFN_PROTO(fselectAdjustScrollCB);
15
 
static char *errorMessage(char *format);
 
13
static BINDFN_PROTO (completeFilenameCB);
 
14
static BINDFN_PROTO (displayFileInfoCB);
 
15
static BINDFN_PROTO (fselectAdjustScrollCB);
 
16
static char *contentToPath (CDKFSELECT *fselect, char *content);
 
17
static char *errorMessage (char *format);
16
18
static char *expandTilde (char *filename);
17
19
static char *format1Date (char *format, time_t value);
18
 
static char *format1Number(char *format, long value);
19
 
static char *format1String(char *format, char *string);
20
 
static char *format3String(char *format, char *s1, char *s2, char *s3);
21
 
static char *format1StrVal(char *format, char *string, int value);
 
20
static char *format1Number (char *format, long value);
 
21
static char *format1String (char *format, char *string);
 
22
static char *format3String (char *format, char *s1, char *s2, char *s3);
 
23
static char *format1StrVal (char *format, char *string, int value);
22
24
static char *trim1Char (char *source);
 
25
static int createList (CDKFSELECT *widget, char **list, int listSize);
23
26
static void setPWD (CDKFSELECT *fselect);
24
27
 
25
 
DeclareSetXXchar(static, _setMy);
26
 
DeclareCDKObjects(FSELECT, Fselect, _setMy, String);
 
28
DeclareSetXXchar (static, _setMy);
 
29
DeclareCDKObjects (FSELECT, Fselect, _setMy, String);
27
30
 
28
31
/*
29
32
 * This creates a file selection widget.
30
33
 */
31
 
CDKFSELECT *newCDKFselect (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, char *title, char *label, chtype fieldAttribute, chtype fillerChar, chtype highlight, char *dAttribute, char *fAttribute, char *lAttribute, char *sAttribute, boolean Box, boolean shadow)
 
34
CDKFSELECT *newCDKFselect (CDKSCREEN *cdkscreen,
 
35
                           int xplace,
 
36
                           int yplace,
 
37
                           int height,
 
38
                           int width,
 
39
                           char *title,
 
40
                           char *label,
 
41
                           chtype fieldAttribute,
 
42
                           chtype fillerChar,
 
43
                           chtype highlight,
 
44
                           char *dAttribute,
 
45
                           char *fAttribute,
 
46
                           char *lAttribute,
 
47
                           char *sAttribute,
 
48
                           boolean Box,
 
49
                           boolean shadow)
32
50
{
33
51
   CDKFSELECT *fselect  = 0;
34
 
   int parentWidth      = getmaxx(cdkscreen->window);
35
 
   int parentHeight     = getmaxy(cdkscreen->window);
 
52
   int parentWidth      = getmaxx (cdkscreen->window);
 
53
   int parentHeight     = getmaxy (cdkscreen->window);
36
54
   int boxWidth         = width;
37
55
   int boxHeight        = height;
38
56
   int xpos             = xplace;
43
61
   chtype *chtypeString;
44
62
   int x;
45
63
 
46
 
   static const struct { int from; int to; } bindings[] = {
47
 
                { CDK_BACKCHAR, KEY_PPAGE },
48
 
                { CDK_FORCHAR,  KEY_NPAGE },
 
64
   static const struct
 
65
   {
 
66
      int from;
 
67
      int to;
 
68
   } bindings[] =
 
69
   {
 
70
      { CDK_BACKCHAR,   KEY_PPAGE },
 
71
      { CDK_FORCHAR,    KEY_NPAGE },
49
72
   };
50
73
 
51
 
   if ((fselect = newCDKObject(CDKFSELECT, &my_funcs)) == 0)
52
 
      return (0);
 
74
   if ((fselect = newCDKObject (CDKFSELECT, &my_funcs)) == 0)
 
75
        return (0);
53
76
 
54
77
   setCDKFselectBox (fselect, Box);
55
78
 
56
 
  /*
57
 
   * If the height is a negative value, the height will
58
 
   * be ROWS-height, otherwise, the height will be the
59
 
   * given height.
60
 
   */
 
79
   /*
 
80
    * If the height is a negative value, the height will
 
81
    * be ROWS-height, otherwise, the height will be the
 
82
    * given height.
 
83
    */
61
84
   boxHeight = setWidgetDimension (parentHeight, height, 0);
62
85
 
63
 
  /*
64
 
   * If the width is a negative value, the width will
65
 
   * be COLS-width, otherwise, the width will be the
66
 
   * given width.
67
 
   */
 
86
   /*
 
87
    * If the width is a negative value, the width will
 
88
    * be COLS-width, otherwise, the width will be the
 
89
    * given width.
 
90
    */
68
91
   boxWidth = setWidgetDimension (parentWidth, width, 0);
69
92
 
70
93
   /* Rejustify the x and y positions if we need to. */
80
103
   /* Is the window null? */
81
104
   if (fselect->win == 0)
82
105
   {
83
 
      destroyCDKObject(fselect);
 
106
      destroyCDKObject (fselect);
84
107
      return (0);
85
108
   }
86
109
   keypad (fselect->win, TRUE);
87
110
 
88
111
   /* Set some variables. */
89
 
   ScreenOf(fselect)            = cdkscreen;
 
112
   ScreenOf (fselect)           = cdkscreen;
90
113
   fselect->parent              = cdkscreen->window;
91
114
   fselect->dirAttribute        = copyChar (dAttribute);
92
115
   fselect->fileAttribute       = copyChar (fAttribute);
99
122
   fselect->boxWidth            = boxWidth;
100
123
   fselect->fileCounter         = 0;
101
124
   fselect->pwd                 = 0;
102
 
   initExitType(fselect);
103
 
   ObjOf(fselect)->inputWindow  = fselect->win;
 
125
   initExitType (fselect);
 
126
   ObjOf (fselect)->inputWindow  = fselect->win;
104
127
   fselect->shadow              = shadow;
105
128
   fselect->shadowWin           = 0;
106
129
 
107
130
   /* Get the present working directory. */
108
 
   setPWD(fselect);
 
131
   setPWD (fselect);
109
132
 
110
133
   /* Get the contents of the current directory. */
111
134
   setCDKFselectDirContents (fselect);
113
136
   /* Create the entry field in the selector. */
114
137
   chtypeString = char2Chtype (label, &labelLen, &junk);
115
138
   freeChtype (chtypeString);
116
 
   tempWidth = (isFullWidth(width)
117
 
                 ? FULL
118
 
                 : boxWidth - 2 - labelLen);
 
139
   tempWidth = (isFullWidth (width)
 
140
                ? FULL
 
141
                : boxWidth - 2 - labelLen);
119
142
   fselect->entryField = newCDKEntry (cdkscreen,
120
 
                                        getbegx(fselect->win),
121
 
                                        getbegy(fselect->win),
122
 
                                        title, label,
123
 
                                        fieldAttribute, fillerChar,
124
 
                                        vMIXED, tempWidth, 0, 512,
125
 
                                        Box, FALSE);
 
143
                                      getbegx (fselect->win),
 
144
                                      getbegy (fselect->win),
 
145
                                      title, label,
 
146
                                      fieldAttribute, fillerChar,
 
147
                                      vMIXED, tempWidth, 0, 512,
 
148
                                      Box, FALSE);
126
149
 
127
150
   /* Make sure the widget was created. */
128
151
   if (fselect->entryField == 0)
129
152
   {
130
 
      destroyCDKObject(fselect);
 
153
      destroyCDKObject (fselect);
131
154
      return (0);
132
155
   }
133
156
 
141
164
   bindCDKObject (vENTRY, fselect->entryField, KEY_DOWN, fselectAdjustScrollCB, fselect);
142
165
   bindCDKObject (vENTRY, fselect->entryField, KEY_NPAGE, fselectAdjustScrollCB, fselect);
143
166
   bindCDKObject (vENTRY, fselect->entryField, KEY_TAB, completeFilenameCB, fselect);
144
 
   bindCDKObject (vENTRY, fselect->entryField, CTRL('^'), displayFileInfoCB, fselect);
 
167
   bindCDKObject (vENTRY, fselect->entryField, CTRL ('^'), displayFileInfoCB, fselect);
145
168
 
146
169
   /* Put the current working directory in the entry field. */
147
170
   setCDKEntryValue (fselect->entryField, fselect->pwd);
148
171
 
149
172
   /* Create the scrolling list in the selector. */
150
 
   tempHeight = getmaxy(fselect->entryField->win) - BorderOf(fselect);
151
 
   tempWidth = (isFullWidth(width)
152
 
                ? FULL
 
173
   tempHeight = getmaxy (fselect->entryField->win) - BorderOf (fselect);
 
174
   tempWidth = (isFullWidth (width)
 
175
                ? FULL
153
176
                : boxWidth - 1);
154
177
   fselect->scrollField = newCDKScroll (cdkscreen,
155
 
                                        getbegx(fselect->win),
156
 
                                        getbegy(fselect->win) + tempHeight,
 
178
                                        getbegx (fselect->win),
 
179
                                        getbegy (fselect->win) + tempHeight,
157
180
                                        RIGHT,
158
 
                                        boxHeight - tempHeight,
 
181
                                        boxHeight - tempHeight,
159
182
                                        tempWidth,
160
183
                                        0,
161
184
                                        fselect->dirContents,
174
197
   }
175
198
 
176
199
   /* Setup the key bindings. */
177
 
   for (x = 0; x < (int) SIZEOF(bindings); ++x)
 
200
   for (x = 0; x < (int) SIZEOF (bindings); ++x)
178
201
      bindCDKObject (vFSELECT, fselect, bindings[x].from, getcCDKBind, (void *)(long)bindings[x].to);
179
202
 
180
 
   /* Register this baby. */
181
203
   registerCDKObject (cdkscreen, vFSELECT, fselect);
182
204
 
183
 
   /* Return the file selector pointer. */
184
205
   return (fselect);
185
206
}
186
207
 
191
212
{
192
213
   if (validCDKObject (object))
193
214
   {
194
 
      CDKFSELECT * fselect = (CDKFSELECT *)object;
 
215
      CDKFSELECT *fselect = (CDKFSELECT *)object;
195
216
 
196
217
      eraseCDKScroll (fselect->scrollField);
197
218
      eraseCDKEntry (fselect->entryField);
202
223
/*
203
224
 * This moves the fselect field to the given location.
204
225
 */
205
 
static void _moveCDKFselect (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag)
 
226
static void _moveCDKFselect (CDKOBJS *object,
 
227
                             int xplace,
 
228
                             int yplace,
 
229
                             boolean relative,
 
230
                             boolean refresh_flag)
206
231
{
207
232
   CDKFSELECT *fselect = (CDKFSELECT *)object;
208
 
   int currentX = getbegx(fselect->win);
209
 
   int currentY = getbegy(fselect->win);
 
233
   int currentX = getbegx (fselect->win);
 
234
   int currentY = getbegy (fselect->win);
210
235
   int xpos     = xplace;
211
236
   int ypos     = yplace;
212
237
   int xdiff    = 0;
218
243
    */
219
244
   if (relative)
220
245
   {
221
 
      xpos = getbegx(fselect->win) + xplace;
222
 
      ypos = getbegy(fselect->win) + yplace;
 
246
      xpos = getbegx (fselect->win) + xplace;
 
247
      ypos = getbegy (fselect->win) + yplace;
223
248
   }
224
249
 
225
250
   /* Adjust the window if we need to. */
226
 
   alignxy (WindowOf(fselect), &xpos, &ypos, fselect->boxWidth, fselect->boxHeight);
 
251
   alignxy (WindowOf (fselect), &xpos, &ypos, fselect->boxWidth, fselect->boxHeight);
227
252
 
228
253
   /* Get the difference. */
229
254
   xdiff = currentX - xpos;
230
255
   ydiff = currentY - ypos;
231
256
 
232
257
   /* Move the window to the new location. */
233
 
   moveCursesWindow(fselect->win, -xdiff, -ydiff);
234
 
   moveCursesWindow(fselect->shadowWin, -xdiff, -ydiff);
 
258
   moveCursesWindow (fselect->win, -xdiff, -ydiff);
 
259
   moveCursesWindow (fselect->shadowWin, -xdiff, -ydiff);
235
260
 
236
261
   /* Move the sub-widgets. */
237
262
   moveCDKEntry (fselect->entryField, xplace, yplace, relative, FALSE);
238
263
   moveCDKScroll (fselect->scrollField, xplace, yplace, relative, FALSE);
239
 
   touchwin (fselect->entryField->win);
240
 
   touchwin (fselect->scrollField->win);
241
264
 
242
265
   /* Redraw the window, if they asked for it. */
243
266
   if (refresh_flag)
244
267
   {
245
 
      drawCDKFselect (fselect, ObjOf(fselect)->box);
 
268
      drawCDKFselect (fselect, ObjOf (fselect)->box);
246
269
   }
247
270
}
248
271
 
249
272
/*
 
273
 * The fselect's focus resides in the entry widget.  But the scroll widget
 
274
 * will not draw items highlighted unless it has focus.  Temporarily adjust the
 
275
 * focus of the scroll widget when drawing on it to get the right highlighting.
 
276
 */
 
277
#define SaveFocus(widget) \
 
278
   boolean save = HasFocusObj (ObjOf (widget->scrollField)); \
 
279
   HasFocusObj (ObjOf (widget->scrollField)) = \
 
280
   HasFocusObj (ObjOf (widget->entryField))
 
281
 
 
282
#define RestoreFocus(widget) \
 
283
   HasFocusObj (ObjOf (widget->scrollField)) = save
 
284
 
 
285
static void drawMyScroller (CDKFSELECT *widget)
 
286
{
 
287
   SaveFocus (widget);
 
288
   drawCDKScroll (widget->scrollField, ObjOf (widget->scrollField)->box);
 
289
   RestoreFocus (widget);
 
290
}
 
291
 
 
292
static void injectMyScroller (CDKFSELECT *widget, chtype key)
 
293
{
 
294
   SaveFocus (widget);
 
295
   injectCDKScroll (widget->scrollField, key);
 
296
   RestoreFocus (widget);
 
297
}
 
298
 
 
299
/*
250
300
 * This draws the file selector widget.
251
301
 */
252
302
static void _drawCDKFselect (CDKOBJS *object, boolean Box GCC_UNUSED)
260
310
   }
261
311
 
262
312
   /* Draw in the entry field. */
263
 
   drawCDKEntry (fselect->entryField, ObjOf(fselect->entryField)->box);
 
313
   drawCDKEntry (fselect->entryField, ObjOf (fselect->entryField)->box);
264
314
 
265
315
   /* Draw in the scroll field. */
266
 
   drawCDKScroll (fselect->scrollField, ObjOf(fselect->scrollField)->box);
 
316
   drawMyScroller (fselect);
267
317
}
268
318
 
269
319
/*
274
324
char *activateCDKFselect (CDKFSELECT *fselect, chtype *actions)
275
325
{
276
326
   chtype input = 0;
277
 
   char *ret    = 0;
 
327
   boolean functionKey;
 
328
   char *ret = 0;
278
329
 
279
330
   /* Draw the widget. */
280
 
   drawCDKFselect (fselect, ObjOf(fselect)->box);
 
331
   drawCDKFselect (fselect, ObjOf (fselect)->box);
281
332
 
282
 
   /* Check if 'actions' is null. */
283
333
   if (actions == 0)
284
334
   {
285
335
      for (;;)
286
336
      {
287
 
         /* Get the input. */
288
 
         input = getcCDKObject (ObjOf(fselect->entryField));
 
337
         input = getchCDKObject (ObjOf (fselect->entryField), &functionKey);
289
338
 
290
339
         /* Inject the character into the widget. */
291
340
         ret = injectCDKFselect (fselect, input);
298
347
   else
299
348
   {
300
349
      int length = chlen (actions);
301
 
      int x =0;
 
350
      int x = 0;
302
351
 
303
352
      /* Inject each character one at a time. */
304
 
      for (x=0; x < length; x++)
 
353
      for (x = 0; x < length; x++)
305
354
      {
306
355
         ret = injectCDKFselect (fselect, actions[x]);
307
356
         if (fselect->exitType != vEARLY_EXIT)
312
361
   }
313
362
 
314
363
   /* Set the exit type and exit. */
315
 
   setExitType(fselect, 0);
 
364
   setExitType (fselect, 0);
316
365
   return 0;
317
366
}
318
367
 
331
380
   filename = injectCDKEntry (fselect->entryField, input);
332
381
 
333
382
   /* Copy the entry field exitType to the fileselector. */
334
 
   copyExitType(fselect, fselect->entryField);
 
383
   copyExitType (fselect, fselect->entryField);
335
384
 
336
385
   /* If we exited early, make sure we don't interpret it as a file. */
337
386
   if (fselect->exitType == vEARLY_EXIT)
357
406
   {
358
407
      /* Set the file selector information. */
359
408
      setCDKFselect (fselect, filename,
360
 
                        fselect->fieldAttribute, fselect->fillerCharacter,
361
 
                        fselect->highlight,
362
 
                        fselect->dirAttribute, fselect->fileAttribute,
363
 
                        fselect->linkAttribute, fselect->sockAttribute,
364
 
                        ObjOf(fselect)->box);
 
409
                     fselect->fieldAttribute, fselect->fillerCharacter,
 
410
                     fselect->highlight,
 
411
                     fselect->dirAttribute, fselect->fileAttribute,
 
412
                     fselect->linkAttribute, fselect->sockAttribute,
 
413
                     ObjOf (fselect)->box);
365
414
 
366
415
      /* Redraw the scrolling list. */
367
 
      drawCDKScroll (fselect->scrollField, ObjOf(fselect->scrollField)->box);
368
 
   }
369
 
 
370
 
   if (!complete) {
371
 
      setExitType(fselect, 0);
372
 
   }
373
 
 
374
 
   ResultOf(fselect).valueString = ret;
 
416
      drawMyScroller (fselect);
 
417
   }
 
418
 
 
419
   if (!complete)
 
420
      setExitType (fselect, 0);
 
421
 
 
422
   ResultOf (fselect).valueString = ret;
375
423
   return (ret != unknownString);
376
424
}
377
425
 
378
426
/*
379
427
 * This function sets the information inside the file selector.
380
428
 */
381
 
void setCDKFselect (CDKFSELECT *fselect, char *directory, chtype fieldAttrib, chtype filler, chtype highlight, char *dirAttribute, char *fileAttribute, char *linkAttribute, char *sockAttribute, boolean Box GCC_UNUSED)
 
429
void setCDKFselect (CDKFSELECT *fselect,
 
430
                    char *directory,
 
431
                    chtype fieldAttrib,
 
432
                    chtype filler,
 
433
                    chtype highlight,
 
434
                    char *dirAttribute,
 
435
                    char *fileAttribute,
 
436
                    char *linkAttribute,
 
437
                    char *sockAttribute,
 
438
                    boolean Box GCC_UNUSED)
382
439
{
383
440
   CDKSCROLL *fscroll   = fselect->scrollField;
384
441
   CDKENTRY *fentry     = fselect->entryField;
405
462
      }
406
463
      else
407
464
      {
408
 
         newDirectory = copyChar(directory);
 
465
         newDirectory = copyChar (directory);
409
466
      }
410
467
 
411
468
      /* Change directories. */
412
469
      if (chdir (newDirectory) != 0)
413
470
      {
414
 
         Beep();
 
471
         Beep ();
415
472
 
416
473
         /* Could not get into the directory, pop up a little message. */
417
 
         mesg[0] = format1String("<C>Could not change into %s", newDirectory);
418
 
         mesg[1] = errorMessage("<C></U>%s");
419
 
         mesg[2] = copyChar(" ");
420
 
         mesg[3] = copyChar("<C>Press Any Key To Continue.");
 
474
         mesg[0] = format1String ("<C>Could not change into %s", newDirectory);
 
475
         mesg[1] = errorMessage ("<C></U>%s");
 
476
         mesg[2] = copyChar (" ");
 
477
         mesg[3] = copyChar ("<C>Press Any Key To Continue.");
421
478
 
422
479
         /* Pop Up a message. */
423
 
         popupLabel (ScreenOf(fselect), mesg, 4);
 
480
         popupLabel (ScreenOf (fselect), mesg, 4);
424
481
 
425
482
         /* Clean up some memory. */
426
483
         freeCharList (mesg, 4);
427
484
 
428
485
         /* Get out of here. */
429
486
         eraseCDKFselect (fselect);
430
 
         drawCDKFselect (fselect, ObjOf(fselect)->box);
 
487
         drawCDKFselect (fselect, ObjOf (fselect)->box);
431
488
         freeChar (newDirectory);
432
489
         return;
433
490
      }
440
497
    */
441
498
   if (fselect->pwd != directory)
442
499
   {
443
 
      setPWD(fselect);
 
500
      setPWD (fselect);
444
501
   }
445
502
   if (fselect->fileAttribute != fileAttribute)
446
503
   {
469
526
 
470
527
   /* Set the contents of the entry field. */
471
528
   setCDKEntryValue (fentry, fselect->pwd);
472
 
   drawCDKEntry (fentry, ObjOf(fentry)->box);
 
529
   drawCDKEntry (fentry, ObjOf (fentry)->box);
473
530
 
474
531
   /* Get the directory contents. */
475
532
   if (setCDKFselectDirContents (fselect) == 0)
476
533
   {
477
 
      Beep();
 
534
      Beep ();
478
535
      return;
479
536
   }
480
537
 
481
538
   /* Set the values in the scrolling list. */
482
539
   setCDKScrollItems (fscroll,
483
 
                        fselect->dirContents,
484
 
                        fselect->fileCounter,
485
 
                        FALSE);
 
540
                      fselect->dirContents,
 
541
                      fselect->fileCounter,
 
542
                      FALSE);
486
543
}
487
544
 
488
545
/*
492
549
{
493
550
   struct stat fileStat;
494
551
   char **dirList = 0;
 
552
   char *oldItem;
495
553
   int fileCount;
496
554
   int x = 0;
497
555
 
500
558
   if (fileCount <= 0)
501
559
   {
502
560
      /* We couldn't read the directory. Return. */
 
561
      CDKfreeStrings (dirList);
503
562
      return 0;
504
563
   }
505
564
 
509
568
   fselect->fileCounter = fileCount;
510
569
 
511
570
   /* Set the properties of the files. */
512
 
   for (x=0; x < fselect->fileCounter; x++)
 
571
   for (x = 0; x < fselect->fileCounter; x++)
513
572
   {
514
573
      char *attr = "";
515
574
      char *mode = "?";
519
578
      {
520
579
         mode = " ";
521
580
         if (((fileStat.st_mode & S_IXUSR) != 0) ||
522
 
                   ((fileStat.st_mode & S_IXGRP) != 0) ||
523
 
                   ((fileStat.st_mode & S_IXOTH) != 0))
 
581
             ((fileStat.st_mode & S_IXGRP) != 0) ||
 
582
             ((fileStat.st_mode & S_IXOTH) != 0))
524
583
         {
525
584
            mode = "*";
526
585
         }
527
586
      }
528
587
 
529
 
      switch (mode2Filetype(fileStat.st_mode)) {
 
588
      switch (mode2Filetype (fileStat.st_mode))
 
589
      {
530
590
      case 'l':
531
591
         attr = fselect->linkAttribute;
532
592
         mode = "@";
545
605
      default:
546
606
         break;
547
607
      }
548
 
      fselect->dirContents[x] = format3String("%s%s%s", attr, dirList[x], mode);
 
608
      oldItem = dirList[x];
 
609
      fselect->dirContents[x] = format3String ("%s%s%s", attr, dirList[x], mode);
 
610
      free (oldItem);
549
611
   }
550
612
   return 1;
551
613
}
578
640
      }
579
641
      else
580
642
      {
581
 
         setPWD(fselect);
 
643
         setPWD (fselect);
582
644
 
583
645
         /* Set the contents of the entry field. */
584
646
         setCDKEntryValue (fentry, fselect->pwd);
585
 
         drawCDKEntry (fentry, ObjOf(fentry)->box);
 
647
         drawCDKEntry (fentry, ObjOf (fentry)->box);
586
648
 
587
649
         /* Get the directory contents. */
588
650
         if (setCDKFselectDirContents (fselect) == 0)
644
706
   /* Make sure they are not the same. */
645
707
   if (fselect->dirAttribute != attribute)
646
708
   {
647
 
      /* Clean out the old attribute, and set the new. */
648
709
      freeChar (fselect->dirAttribute);
649
710
      fselect->dirAttribute = copyChar (attribute);
650
711
 
651
 
     /*
652
 
      * We need to reset the contents of the scrolling
653
 
      * list using the new attribute.
654
 
      */
655
712
      setCDKFselectDirContents (fselect);
656
713
   }
657
714
}
669
726
   /* Make sure they are not the same. */
670
727
   if (fselect->linkAttribute != attribute)
671
728
   {
672
 
      /* Clean out the old attribute, and set the new. */
673
729
      freeChar (fselect->linkAttribute);
674
730
      fselect->linkAttribute = copyChar (attribute);
675
731
 
676
 
     /*
677
 
      * We need to reset the contents of the scrolling
678
 
      * list using the new attribute.
679
 
      */
680
732
      setCDKFselectDirContents (fselect);
681
733
   }
682
734
}
694
746
   /* Make sure they are not the same. */
695
747
   if (fselect->sockAttribute != attribute)
696
748
   {
697
 
      /* Clean out the old attribute, and set the new. */
698
749
      freeChar (fselect->sockAttribute);
699
750
      fselect->sockAttribute = copyChar (attribute);
700
751
 
701
 
     /*
702
 
      * We need to reset the contents of the scrolling
703
 
      * list using the new attribute.
704
 
      */
705
752
      setCDKFselectDirContents (fselect);
706
753
   }
707
754
}
719
766
   /* Make sure they are not the same. */
720
767
   if (fselect->fileAttribute != attribute)
721
768
   {
722
 
      /* Clean out the old attribute, and set the new. */
723
769
      freeChar (fselect->fileAttribute);
724
770
      fselect->fileAttribute = copyChar (attribute);
725
771
 
726
 
     /*
727
 
      * We need to reset the contents of the scrolling
728
 
      * list using the new attribute.
729
 
      */
730
772
      setCDKFselectDirContents (fselect);
731
773
   }
732
774
}
740
782
 */
741
783
void setCDKFselectBox (CDKFSELECT *fselect, boolean Box)
742
784
{
743
 
   ObjOf(fselect)->box = Box;
744
 
   ObjOf(fselect)->borderSize = Box ? 1 : 0;
 
785
   ObjOf (fselect)->box = Box;
 
786
   ObjOf (fselect)->borderSize = Box ? 1 : 0;
745
787
}
746
788
boolean getCDKFselectBox (CDKFSELECT *fselect)
747
789
{
748
 
   return ObjOf(fselect)->box;
 
790
   return ObjOf (fselect)->box;
 
791
}
 
792
 
 
793
/*
 
794
 * This sets the contents of the widget
 
795
 */
 
796
void setCDKFselectContents (CDKFSELECT *widget,
 
797
                            char **list,
 
798
                            int listSize)
 
799
{
 
800
   CDKSCROLL *scrollp   = widget->scrollField;
 
801
   CDKENTRY *entry      = widget->entryField;
 
802
 
 
803
   if (!createList (widget, list, listSize))
 
804
      return;
 
805
 
 
806
   /* Set the information in the scrolling list. */
 
807
   setCDKScroll (scrollp,
 
808
                 widget->dirContents,
 
809
                 widget->fileCounter,
 
810
                 NONUMBERS,
 
811
                 scrollp->highlight,
 
812
                 ObjOf (scrollp)->box);
 
813
 
 
814
   /* Clean out the entry field. */
 
815
   setCDKFselectCurrentItem (widget, 0);
 
816
   cleanCDKEntry (entry);
 
817
 
 
818
   /* Redraw the widget. */
 
819
   eraseCDKFselect (widget);
 
820
   drawCDKFselect (widget, ObjOf (widget)->box);
 
821
}
 
822
 
 
823
char **getCDKFselectContents (CDKFSELECT *widget,
 
824
                              int *size)
 
825
{
 
826
   (*size) = widget->fileCounter;
 
827
   return widget->dirContents;
 
828
}
 
829
 
 
830
/*
 
831
 * Get/set the current position in the scroll-widget.
 
832
 */
 
833
int getCDKFselectCurrentItem (CDKFSELECT *widget)
 
834
{
 
835
   return getCDKScrollCurrent (widget->scrollField);
 
836
}
 
837
 
 
838
void setCDKFselectCurrentItem (CDKFSELECT *widget,
 
839
                               int item)
 
840
{
 
841
   if (widget->fileCounter != 0)
 
842
   {
 
843
      char *data;
 
844
 
 
845
      setCDKScrollCurrent (widget->scrollField, item);
 
846
 
 
847
      data = contentToPath (widget,
 
848
                            widget->dirContents[getCDKScrollCurrentItem (widget->scrollField)]);
 
849
      setCDKEntryValue (widget->entryField, data);
 
850
 
 
851
      free (data);
 
852
   }
749
853
}
750
854
 
751
855
/*
753
857
 */
754
858
static void _setMyULchar (CDKOBJS *object, chtype character)
755
859
{
756
 
   CDKALPHALIST *fselect = (CDKALPHALIST *)object;
 
860
   CDKFSELECT *fselect = (CDKFSELECT *)object;
757
861
 
758
862
   setCDKEntryULChar (fselect->entryField, character);
759
863
}
760
864
static void _setMyURchar (CDKOBJS *object, chtype character)
761
865
{
762
 
   CDKALPHALIST *fselect = (CDKALPHALIST *)object;
 
866
   CDKFSELECT *fselect = (CDKFSELECT *)object;
763
867
 
764
868
   setCDKEntryURChar (fselect->entryField, character);
765
869
}
766
870
static void _setMyLLchar (CDKOBJS *object, chtype character)
767
871
{
768
 
   CDKALPHALIST *fselect = (CDKALPHALIST *)object;
 
872
   CDKFSELECT *fselect = (CDKFSELECT *)object;
769
873
 
770
874
   setCDKScrollLLChar (fselect->scrollField, character);
771
875
}
772
876
static void _setMyLRchar (CDKOBJS *object, chtype character)
773
877
{
774
 
   CDKALPHALIST *fselect = (CDKALPHALIST *)object;
 
878
   CDKFSELECT *fselect = (CDKFSELECT *)object;
775
879
 
776
880
   setCDKScrollLRChar (fselect->scrollField, character);
777
881
}
778
882
static void _setMyVTchar (CDKOBJS *object, chtype character)
779
883
{
780
 
   CDKALPHALIST *fselect = (CDKALPHALIST *)object;
 
884
   CDKFSELECT *fselect = (CDKFSELECT *)object;
781
885
 
782
886
   setCDKEntryVerticalChar (fselect->entryField, character);
783
887
   setCDKScrollVerticalChar (fselect->scrollField, character);
784
888
}
785
889
static void _setMyHZchar (CDKOBJS *object, chtype character)
786
890
{
787
 
   CDKALPHALIST *fselect = (CDKALPHALIST *)object;
 
891
   CDKFSELECT *fselect = (CDKFSELECT *)object;
788
892
 
789
893
   setCDKEntryHorizontalChar (fselect->entryField, character);
790
894
   setCDKScrollHorizontalChar (fselect->scrollField, character);
791
895
}
792
896
static void _setMyBXattr (CDKOBJS *object, chtype character)
793
897
{
794
 
   CDKALPHALIST *fselect = (CDKALPHALIST *)object;
 
898
   CDKFSELECT *fselect = (CDKFSELECT *)object;
795
899
 
796
900
   setCDKEntryBoxAttribute (fselect->entryField, character);
797
901
   setCDKScrollBoxAttribute (fselect->scrollField, character);
804
908
{
805
909
   if (object != 0)
806
910
   {
807
 
      CDKFSELECT *widget = (CDKFSELECT *) object;
 
911
      CDKFSELECT *widget = (CDKFSELECT *)object;
808
912
 
809
913
      setCDKEntryBackgroundAttrib (widget->entryField, attrib);
810
914
      setCDKScrollBackgroundAttrib (widget->scrollField, attrib);
820
924
   {
821
925
      CDKFSELECT *fselect = (CDKFSELECT *)object;
822
926
 
 
927
      cleanCDKObjectBindings (vFSELECT, fselect);
 
928
 
823
929
      /* Free up the character pointers. */
824
930
      freeChar (fselect->pwd);
825
931
      freeChar (fselect->pathname);
837
943
      deleteCursesWindow (fselect->shadowWin);
838
944
      deleteCursesWindow (fselect->win);
839
945
 
 
946
      /* Clean the key bindings. */
840
947
      /* Unregister the object. */
841
948
      unregisterCDKObject (vFSELECT, fselect);
842
949
   }
852
959
 * This is a callback to the scrolling list which displays information
853
960
 * about the current file. (and the whole directory as well)
854
961
 */
855
 
static int displayFileInfoCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED)
 
962
static int displayFileInfoCB (EObjectType objectType GCC_UNUSED,
 
963
                              void *object,
 
964
                              void *clientData,
 
965
                              chtype key GCC_UNUSED)
856
966
{
857
967
   CDKENTRY             *entry          = (CDKENTRY *)object;
858
968
   CDKFSELECT           *fselect        = (CDKFSELECT *)clientData;
865
975
   char                 *mesg[10];
866
976
   char                 stringMode[15];
867
977
   int                  intMode;
 
978
   boolean              functionKey;
868
979
 
869
980
   /* Get the file name. */
870
 
   filename     = fselect->entryField->info;
 
981
   filename = fselect->entryField->info;
871
982
 
872
983
   /* Get specific information about the files. */
873
984
   lstat (filename, &fileStat);
874
985
 
875
986
   /* Determine the file type. */
876
 
   switch (mode2Filetype(fileStat.st_mode)) {
 
987
   switch (mode2Filetype (fileStat.st_mode))
 
988
   {
877
989
   case 'l':
878
990
      filetype = "Symbolic Link";
879
991
      break;
924
1036
                            mesg, 9,
925
1037
                            TRUE, FALSE);
926
1038
   drawCDKLabel (infoLabel, TRUE);
927
 
   getcCDKObject (ObjOf(infoLabel));
 
1039
   getchCDKObject (ObjOf (infoLabel), &functionKey);
928
1040
 
929
1041
   /* Clean up some memory. */
930
1042
   destroyCDKLabel (infoLabel);
931
1043
   freeCharList (mesg, 9);
932
1044
 
933
1045
   /* Redraw the file selector. */
934
 
   drawCDKFselect (fselect, ObjOf(fselect)->box);
 
1046
   drawCDKFselect (fselect, ObjOf (fselect)->box);
935
1047
   return (TRUE);
936
1048
}
937
1049
 
938
 
static char *make_pathname(char *directory, char *filename)
 
1050
static char *make_pathname (char *directory, char *filename)
939
1051
{
940
 
   unsigned need = strlen(filename) + 2;
 
1052
   unsigned need = strlen (filename) + 2;
941
1053
   bool root = (strcmp (directory, "/") == 0);
942
1054
   char *result;
943
1055
 
944
1056
   if (!root)
945
 
      need += strlen(directory);
946
 
   if ((result = (char *)malloc(need)) != 0)
 
1057
      need += strlen (directory);
 
1058
   if ((result = (char *)malloc (need)) != 0)
947
1059
   {
948
1060
      if (root)
949
1061
         sprintf (result, "/%s", filename);
954
1066
}
955
1067
 
956
1068
/*
 
1069
 * Return the plain string that corresponds to an item in dirContents[].
 
1070
 */
 
1071
static char *contentToPath (CDKFSELECT *fselect, char *content)
 
1072
{
 
1073
   chtype *tempChtype;
 
1074
   char *tempChar;
 
1075
   char *result;
 
1076
   int j, j2;
 
1077
 
 
1078
   tempChtype = char2Chtype (content, &j, &j2);
 
1079
   tempChar = chtype2Char (tempChtype);
 
1080
   trim1Char (tempChar);        /* trim the 'mode' stored on the end */
 
1081
 
 
1082
   /* Create the pathname. */
 
1083
   result = make_pathname (fselect->pwd, tempChar);
 
1084
 
 
1085
   /* Clean up. */
 
1086
   freeChtype (tempChtype);
 
1087
   freeChar (tempChar);
 
1088
   return result;
 
1089
}
 
1090
 
 
1091
/*
957
1092
 * This tries to complete the filename.
958
1093
 */
959
 
static int completeFilenameCB (EObjectType objectType GCC_UNUSED, void *object GCC_UNUSED, void *clientData, chtype key GCC_UNUSED)
 
1094
static int completeFilenameCB (EObjectType objectType GCC_UNUSED,
 
1095
                               void *object GCC_UNUSED,
 
1096
                               void *clientData,
 
1097
                               chtype key GCC_UNUSED)
960
1098
{
961
1099
   CDKFSELECT *fselect  = (CDKFSELECT *)clientData;
962
 
   CDKSCROLL *scrollp   = (CDKSCROLL *)fselect->scrollField;
963
 
   CDKENTRY *entry      = (CDKENTRY *)fselect->entryField;
 
1100
   CDKSCROLL *scrollp   = fselect->scrollField;
 
1101
   CDKENTRY *entry      = fselect->entryField;
964
1102
   char *filename       = copyChar (entry->info);
965
1103
   char *mydirname      = dirName (filename);
966
1104
   char *newFilename    = 0;
967
 
   chtype *tempChtype   = 0;
968
 
   char *tempChar       = 0;
969
1105
   unsigned filenameLen = 0;
970
1106
   int currentIndex     = 0;
971
1107
   int matches          = 0;
973
1109
   int secondaryMatches = 0;
974
1110
   int isDirectory;
975
1111
   char **list;
976
 
   char *temp;
977
 
   int Index, pos, j, j2, x;
 
1112
   int Index, pos, x;
978
1113
   int difference, absoluteDifference;
979
1114
 
980
1115
   /* Make sure the filename is not null/empty. */
981
 
   if (filename == 0
982
 
    || (filenameLen = strlen(filename)) == 0)
 
1116
   if (filename == 0 ||
 
1117
       (filenameLen = strlen (filename)) == 0)
983
1118
   {
984
 
      Beep();
985
 
      freeChar(filename);
 
1119
      Beep ();
 
1120
      freeChar (filename);
986
1121
      return (TRUE);
987
1122
   }
988
1123
 
992
1127
      freeChar (filename);
993
1128
      filename = newFilename;
994
1129
      setCDKEntryValue (entry, filename);
995
 
      drawCDKEntry (entry, ObjOf(entry)->box);
 
1130
      drawCDKEntry (entry, ObjOf (entry)->box);
996
1131
   }
997
1132
 
998
1133
   /* Make sure we can change into the directory. */
1008
1143
                  fselect->fileAttribute,
1009
1144
                  fselect->linkAttribute,
1010
1145
                  fselect->sockAttribute,
1011
 
                  ObjOf(fselect)->box);
 
1146
                  ObjOf (fselect)->box);
1012
1147
   freeChar (mydirname);
1013
1148
 
1014
1149
   /* If we can, change into the directory. */
1015
1150
   if (isDirectory)
1016
1151
   {
1017
 
     /*
1018
 
      * Set the entry field with the filename so the current
1019
 
      * filename selection shows up.
1020
 
      */
 
1152
      /*
 
1153
       * Set the entry field with the filename so the current
 
1154
       * filename selection shows up.
 
1155
       */
1021
1156
      setCDKEntryValue (entry, filename);
1022
 
      drawCDKEntry (entry, ObjOf(entry)->box);
 
1157
      drawCDKEntry (entry, ObjOf (entry)->box);
1023
1158
   }
1024
1159
 
1025
1160
   /* Create the file list. */
1026
 
   if ((list = typeMallocN(char *, fselect->fileCounter)) != 0)
 
1161
   if ((list = typeMallocN (char *, fselect->fileCounter)) != 0)
1027
1162
   {
1028
 
      for (x=0; x < fselect->fileCounter; x++)
 
1163
      for (x = 0; x < fselect->fileCounter; x++)
1029
1164
      {
1030
 
         /* We need to remove the special characters from the filenames. */
1031
 
         tempChtype = char2Chtype (fselect->dirContents[x], &j, &j2);
1032
 
         tempChar = chtype2Char (tempChtype);
1033
 
 
1034
 
         /* Create the pathname. */
1035
 
         list[x] = make_pathname(fselect->pwd, tempChar);
1036
 
 
1037
 
         /* Clean up. */
1038
 
         freeChtype (tempChtype);
1039
 
         freeChar (tempChar);
 
1165
         list[x] = contentToPath (fselect, fselect->dirContents[x]);
1040
1166
      }
1041
1167
 
1042
1168
      /* Look for a unique filename match. */
1045
1171
      /* If the index is less than zero, return we didn't find a match. */
1046
1172
      if (Index < 0)
1047
1173
      {
1048
 
         Beep();
 
1174
         Beep ();
1049
1175
      }
1050
1176
      else
1051
1177
      {
1052
 
         /* Create the filename of the found file. */
1053
 
         temp = copyChar(list[Index]);
1054
 
         temp[strlen(temp)-1] = '\0';   /* setCDKFselectDirContents 'mode' */
1055
 
 
1056
1178
         /* Move to the current item in the scrolling list. */
1057
1179
         difference             = Index - scrollp->currentItem;
1058
1180
         absoluteDifference     = abs (difference);
1059
1181
         if (difference < 0)
1060
1182
         {
1061
 
            for (x=0; x < absoluteDifference; x++)
 
1183
            for (x = 0; x < absoluteDifference; x++)
1062
1184
            {
1063
 
               injectCDKScroll (scrollp, KEY_UP);
 
1185
               injectMyScroller (fselect, KEY_UP);
1064
1186
            }
1065
1187
         }
1066
1188
         else if (difference > 0)
1067
1189
         {
1068
 
            for (x=0; x < absoluteDifference; x++)
 
1190
            for (x = 0; x < absoluteDifference; x++)
1069
1191
            {
1070
 
               injectCDKScroll (scrollp, KEY_DOWN);
 
1192
               injectMyScroller (fselect, KEY_DOWN);
1071
1193
            }
1072
1194
         }
1073
 
         drawCDKScroll (scrollp, ObjOf(scrollp)->box);
 
1195
         drawMyScroller (fselect);
1074
1196
 
1075
1197
         /* Ok, we found a match, is the next item similar? */
1076
1198
         if (Index+1 < fselect->fileCounter &&
1099
1221
            for (;;)
1100
1222
            {
1101
1223
               secondaryMatches = 0;
1102
 
               for (x=Index; x < Index + matches; x++)
 
1224
               for (x = Index; x < Index + matches; x++)
1103
1225
               {
1104
1226
                  if (list[Index][baseChars] == list[x][baseChars])
1105
1227
                  {
1109
1231
 
1110
1232
               if (secondaryMatches != matches)
1111
1233
               {
1112
 
                  Beep();
 
1234
                  Beep ();
1113
1235
                  break;
1114
1236
               }
1115
1237
 
1121
1243
         else
1122
1244
         {
1123
1245
            /* Set the entry field with the found item. */
1124
 
            setCDKEntryValue (entry, temp);
1125
 
            drawCDKEntry (entry, ObjOf(entry)->box);
 
1246
            setCDKEntryValue (entry, list[Index]);
 
1247
            drawCDKEntry (entry, ObjOf (entry)->box);
1126
1248
         }
1127
 
         freeChar (temp);
1128
1249
      }
1129
1250
      freeCharList (list, fselect->fileCounter);
1130
1251
      free (list);
1146
1267
 
1147
1268
   /* Get the filename which is to be deleted. */
1148
1269
   filename = chtype2Char (fscroll->item[fscroll->currentItem]);
1149
 
   trim1Char(filename);
 
1270
   trim1Char (filename);
1150
1271
 
1151
1272
   /* Create the dialog message. */
1152
 
   mesg[0] = copyChar("<C>Are you sure you want to delete the file:");
1153
 
   mesg[1] = format1String("<C></U>%s?", filename);
 
1273
   mesg[0] = copyChar ("<C>Are you sure you want to delete the file:");
 
1274
   mesg[1] = format1String ("<C></U>\"%s\"?", filename);
1154
1275
 
1155
1276
   /* Create the dialog box. */
1156
 
   question = newCDKDialog (ScreenOf(fselect), CENTER, CENTER,
1157
 
                        mesg, 2, buttons, 2, A_REVERSE,
1158
 
                        TRUE, TRUE, FALSE);
 
1277
   question = newCDKDialog (ScreenOf (fselect), CENTER, CENTER,
 
1278
                            mesg, 2, buttons, 2, A_REVERSE,
 
1279
                            TRUE, TRUE, FALSE);
1159
1280
   freeCharList (mesg, 2);
1160
1281
 
1161
1282
   /* If the said yes then try to nuke it. */
1166
1287
      {
1167
1288
         /* Set the file selector information. */
1168
1289
         setCDKFselect (fselect, fselect->pwd,
1169
 
                fselect->fieldAttribute, fselect->fillerCharacter, fselect->highlight,
1170
 
                fselect->dirAttribute, fselect->fileAttribute,
1171
 
                fselect->linkAttribute, fselect->sockAttribute,
1172
 
                ObjOf(fselect)->box);
 
1290
                        fselect->fieldAttribute,
 
1291
                        fselect->fillerCharacter,
 
1292
                        fselect->highlight,
 
1293
                        fselect->dirAttribute,
 
1294
                        fselect->fileAttribute,
 
1295
                        fselect->linkAttribute,
 
1296
                        fselect->sockAttribute,
 
1297
                        ObjOf (fselect)->box);
1173
1298
      }
1174
1299
      else
1175
1300
      {
1176
1301
         /* Pop up a message. */
1177
 
         mesg[0] = copyChar(errorMessage ("<C>Cannot delete file: %s"));
1178
 
         mesg[1] = copyChar(" ");
1179
 
         mesg[2] = copyChar("<C>Press any key to continue.");
1180
 
         popupLabel (ScreenOf(fselect), mesg, 3);
 
1302
         mesg[0] = copyChar (errorMessage ("<C>Cannot delete file: %s"));
 
1303
         mesg[1] = copyChar (" ");
 
1304
         mesg[2] = copyChar ("<C>Press any key to continue.");
 
1305
         popupLabel (ScreenOf (fselect), mesg, 3);
1181
1306
         freeCharList (mesg, 3);
1182
1307
      }
1183
1308
   }
1186
1311
   destroyCDKDialog (question);
1187
1312
 
1188
1313
   /* Redraw the file selector. */
1189
 
   drawCDKFselect (fselect, ObjOf(fselect)->box);
 
1314
   drawCDKFselect (fselect, ObjOf (fselect)->box);
1190
1315
}
1191
1316
 
1192
1317
/*
1210
1335
/*
1211
1336
 * Start of callback functions.
1212
1337
 */
1213
 
static int fselectAdjustScrollCB (EObjectType objectType GCC_UNUSED, void *object GCC_UNUSED, void *clientData, chtype key)
 
1338
static int fselectAdjustScrollCB (EObjectType objectType GCC_UNUSED,
 
1339
                                  void *object GCC_UNUSED,
 
1340
                                  void *clientData,
 
1341
                                  chtype key)
1214
1342
{
1215
1343
   CDKFSELECT *fselect  = (CDKFSELECT *)clientData;
1216
1344
   CDKSCROLL *scrollp   = (CDKSCROLL *)fselect->scrollField;
1218
1346
   char *current;
1219
1347
   char *temp;
1220
1348
 
1221
 
   /* Move the scrolling list. */
1222
 
   injectCDKScroll (fselect->scrollField, key);
1223
 
 
1224
 
   /* Get the currently highlighted filename. */
1225
 
   current = chtype2Char (scrollp->item[scrollp->currentItem]);
1226
 
   trim1Char(current);
1227
 
 
1228
 
   temp = make_pathname(fselect->pwd, current);
1229
 
 
1230
 
   /* Set the value in the entry field. */
1231
 
   setCDKEntryValue (entry, temp);
1232
 
   drawCDKEntry (entry, ObjOf(entry)->box);
1233
 
 
1234
 
   freeChar (current);
1235
 
   freeChar (temp);
1236
 
   return (TRUE);
 
1349
   if (scrollp->listSize > 0)
 
1350
   {
 
1351
      /* Move the scrolling list. */
 
1352
      injectMyScroller (fselect, key);
 
1353
 
 
1354
      /* Get the currently highlighted filename. */
 
1355
      current = chtype2Char (scrollp->item[scrollp->currentItem]);
 
1356
      trim1Char (current);
 
1357
 
 
1358
      temp = make_pathname (fselect->pwd, current);
 
1359
 
 
1360
      /* Set the value in the entry field. */
 
1361
      setCDKEntryValue (entry, temp);
 
1362
      drawCDKEntry (entry, ObjOf (entry)->box);
 
1363
 
 
1364
      freeChar (current);
 
1365
      freeChar (temp);
 
1366
      return (TRUE);
 
1367
   }
 
1368
   Beep ();
 
1369
   return (FALSE);
1237
1370
}
1238
1371
 
 
1372
/*
 
1373
 * trim the 'mode' from a copy of a dirContents[] entry.
 
1374
 */
1239
1375
static char *trim1Char (char *source)
1240
1376
{
1241
1377
   unsigned len;
1242
1378
 
1243
 
   if ((len = strlen(source)) != 0)
 
1379
   if ((len = strlen (source)) != 0)
1244
1380
      source[--len] = '\0';
1245
1381
   return source;
1246
1382
}
1250
1386
   char *result;
1251
1387
   char *temp = ctime (&value);
1252
1388
 
1253
 
   if ((result = (char *)malloc(strlen(format) + strlen(temp))) != 0)
 
1389
   if ((result = (char *)malloc (strlen (format) + strlen (temp))) != 0)
1254
1390
   {
1255
 
      sprintf (result, format, trim1Char(temp));
 
1391
      sprintf (result, format, trim1Char (temp));
1256
1392
   }
1257
1393
   return result;
1258
1394
}
1259
1395
 
1260
 
static char *format1Number(char *format, long value)
1261
 
{
1262
 
   char *result;
1263
 
 
1264
 
   if ((result = (char *)malloc(strlen(format) + 20)) != 0)
1265
 
      sprintf(result, format, value);
1266
 
   return result;
1267
 
}
1268
 
 
1269
 
static char *format3String(char *format, char *s1, char *s2, char *s3)
1270
 
{
1271
 
   char *result;
1272
 
 
1273
 
   if ((result = (char *)malloc(strlen(format) + strlen(s1) + strlen(s2) + strlen(s3))) != 0)
1274
 
      sprintf(result, format, s1, s2, s3);
1275
 
   return result;
1276
 
}
1277
 
 
1278
 
static char *format1String(char *format, char *string)
1279
 
{
1280
 
   char *result;
1281
 
 
1282
 
   if ((result = (char *)malloc(strlen(format) + strlen(string))) != 0)
1283
 
      sprintf(result, format, string);
1284
 
   return result;
1285
 
}
1286
 
 
1287
 
static char *format1StrVal(char *format, char *string, int value)
1288
 
{
1289
 
   char *result;
1290
 
 
1291
 
   if ((result = (char *)malloc(strlen(format) + strlen(string) + 20)) != 0)
1292
 
      sprintf(result, format, string, value);
1293
 
   return result;
1294
 
}
1295
 
 
1296
 
static char *errorMessage(char *format)
 
1396
static char *format1Number (char *format, long value)
 
1397
{
 
1398
   char *result;
 
1399
 
 
1400
   if ((result = (char *)malloc (strlen (format) + 20)) != 0)
 
1401
      sprintf (result, format, value);
 
1402
   return result;
 
1403
}
 
1404
 
 
1405
static char *format3String (char *format, char *s1, char *s2, char *s3)
 
1406
{
 
1407
   char *result;
 
1408
 
 
1409
   if ((result = (char *)malloc (strlen (format) +
 
1410
                                 strlen (s1) +
 
1411
                                 strlen (s2) +
 
1412
                                 strlen (s3))) != 0)
 
1413
      sprintf (result, format, s1, s2, s3);
 
1414
   return result;
 
1415
}
 
1416
 
 
1417
static char *format1String (char *format, char *string)
 
1418
{
 
1419
   char *result;
 
1420
 
 
1421
   if ((result = (char *)malloc (strlen (format) + strlen (string))) != 0)
 
1422
      sprintf (result, format, string);
 
1423
   return result;
 
1424
}
 
1425
 
 
1426
static char *format1StrVal (char *format, char *string, int value)
 
1427
{
 
1428
   char *result;
 
1429
 
 
1430
   if ((result = (char *)malloc (strlen (format) + strlen (string) + 20)) != 0)
 
1431
      sprintf (result, format, string, value);
 
1432
   return result;
 
1433
}
 
1434
 
 
1435
static char *errorMessage (char *format)
1297
1436
{
1298
1437
   char *message;
1299
1438
#ifdef HAVE_STRERROR
1301
1440
#else
1302
1441
   message = "Unknown reason.";
1303
1442
#endif
1304
 
   return format1String(format, message);
 
1443
   return format1String (format, message);
1305
1444
}
1306
1445
 
1307
1446
/*
1315
1454
   int len;
1316
1455
 
1317
1456
   /* Make sure the filename is not null/empty, and begins with a tilde */
1318
 
   if ((filename != 0)
1319
 
    && (len = strlen (filename)) != 0
1320
 
    && filename[0] == '~'
1321
 
    && (account = copyChar(filename)) != 0
1322
 
    && (pathname = copyChar(filename)) != 0)
 
1457
   if ((filename != 0) &&
 
1458
       (len = strlen (filename)) != 0 &&
 
1459
       filename[0] == '~' &&
 
1460
       (account = copyChar (filename)) != 0 &&
 
1461
       (pathname = copyChar (filename)) != 0)
1323
1462
   {
1324
1463
      bool slash = FALSE;
1325
1464
      char *home;
1348
1487
      pathname[len_p] = '\0';
1349
1488
 
1350
1489
      home = 0;
1351
 
      if (strlen(account) != 0
1352
 
       && (accountInfo = getpwnam (account)) != 0)
 
1490
      if (strlen (account) != 0 &&
 
1491
          (accountInfo = getpwnam (account)) != 0)
1353
1492
      {
1354
1493
         home = accountInfo->pw_dir;
1355
1494
      }
1356
1495
      if (home == 0 || *home == '\0')
1357
 
         home = getenv("HOME");
 
1496
         home = getenv ("HOME");
1358
1497
      if (home == 0 || *home == '\0')
1359
1498
         home = "/";
1360
1499
 
1363
1502
       * may have a pathname at the end of the account name
1364
1503
       * and we want to keep it.
1365
1504
       */
1366
 
      result = make_pathname(home, pathname);
 
1505
      result = make_pathname (home, pathname);
1367
1506
 
1368
 
      freeChar(account);
1369
 
      freeChar(pathname);
 
1507
      freeChar (account);
 
1508
      freeChar (pathname);
1370
1509
   }
1371
1510
   return result;
1372
1511
}
1378
1517
{
1379
1518
   char buffer[512];
1380
1519
   freeChar (fselect->pwd);
1381
 
   if (getcwd(buffer, sizeof(buffer)) == 0)
1382
 
      strcpy(buffer, ".");
1383
 
   fselect->pwd = copyChar(buffer);
1384
 
}
1385
 
 
1386
 
dummyFocus(Fselect)
1387
 
 
1388
 
dummyUnfocus(Fselect)
1389
 
 
1390
 
dummyRefreshData(Fselect)
1391
 
 
1392
 
dummySaveData(Fselect)
 
1520
   if (getcwd (buffer, sizeof (buffer)) == 0)
 
1521
      strcpy (buffer, ".");
 
1522
   fselect->pwd = copyChar (buffer);
 
1523
}
 
1524
 
 
1525
static void destroyInfo (CDKFSELECT *widget)
 
1526
{
 
1527
   CDKfreeStrings (widget->dirContents);
 
1528
   widget->dirContents = 0;
 
1529
 
 
1530
   widget->fileCounter = 0;
 
1531
}
 
1532
 
 
1533
static int createList (CDKFSELECT *widget, char **list, int listSize)
 
1534
{
 
1535
   int status = 0;
 
1536
 
 
1537
   if (listSize > 0)
 
1538
   {
 
1539
      char **newlist = typeCallocN (char *, listSize + 1);
 
1540
 
 
1541
      if (newlist != 0)
 
1542
      {
 
1543
         int x;
 
1544
 
 
1545
         /* Copy in the new information. */
 
1546
         status = 1;
 
1547
         for (x = 0; x < listSize; x++)
 
1548
         {
 
1549
            if ((newlist[x] = copyChar (list[x])) == 0)
 
1550
            {
 
1551
               status = 0;
 
1552
               break;
 
1553
            }
 
1554
         }
 
1555
         if (status)
 
1556
         {
 
1557
            destroyInfo (widget);
 
1558
            widget->fileCounter = listSize;
 
1559
            widget->dirContents = newlist;
 
1560
         }
 
1561
         else
 
1562
         {
 
1563
            CDKfreeStrings (newlist);
 
1564
         }
 
1565
      }
 
1566
   }
 
1567
   else
 
1568
   {
 
1569
      destroyInfo (widget);
 
1570
      status = TRUE;
 
1571
   }
 
1572
   return status;
 
1573
}
 
1574
 
 
1575
static void _focusCDKFselect (CDKOBJS *object)
 
1576
{
 
1577
   CDKFSELECT *widget = (CDKFSELECT *)object;
 
1578
 
 
1579
   FocusObj (ObjOf (widget->entryField));
 
1580
}
 
1581
 
 
1582
static void _unfocusCDKFselect (CDKOBJS *object)
 
1583
{
 
1584
   CDKFSELECT *widget = (CDKFSELECT *)object;
 
1585
 
 
1586
   UnfocusObj (ObjOf (widget->entryField));
 
1587
}
 
1588
 
 
1589
dummyRefreshData (Fselect)
 
1590
 
 
1591
dummySaveData (Fselect)