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

« back to all changes in this revision

Viewing changes to cli/cdkmatrix.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
 
/* $Id: cdkmatrix.c,v 1.10 2005/03/08 19:52:01 tom Exp $ */
 
1
/* $Id: cdkmatrix.c,v 1.13 2005/12/27 16:54:49 tom Exp $ */
2
2
 
3
 
#include <cdk.h>
 
3
#include <cdk_test.h>
4
4
 
5
5
#ifdef XCURSES
6
6
char *XCursesProgramName = "cdkmatrix";
43
43
   char **colTitles;
44
44
   char **rowTemp               = 0;
45
45
   char **colTemp               = 0;
 
46
   char **kolTemp               = 0;
46
47
   char **buttonList            = 0;
47
48
   int *colWidths;
48
49
   int *colTypes;
87
88
      if ((fp = fopen (outputFile, "w")) == 0)
88
89
      {
89
90
         fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
90
 
         exit (-1);
 
91
         ExitProgram (CLI_ERROR);
91
92
      }
92
93
   }
93
94
 
98
99
        (vrows == -1))
99
100
   {
100
101
      fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
101
 
      exit (-1);
 
102
      ExitProgram (CLI_ERROR);
102
103
   }
103
104
 
104
 
   /* Convert the char * titles to a char ** */
 
105
   /* Convert the char * titles to a char **, offset by one */
105
106
   rowTemp = CDKsplitString (myRowTitles, '\n');
106
107
   rows = CDKcountStrings (rowTemp);
107
108
   rowTitles = (char **) calloc (rows + 1, sizeof(char *));
109
110
   {
110
111
      rowTitles[x+1] = rowTemp[x];
111
112
   }
 
113
 
112
114
   colTemp = CDKsplitString (myColTitles, '\n');
113
115
   cols = CDKcountStrings (colTemp);
114
116
   colTitles = (char **) calloc (cols + 1, sizeof(char *));
116
118
   {
117
119
      colTitles[x+1] = colTemp[x];
118
120
   }
119
 
   free (colTemp);
120
121
 
121
122
   /* Convert the column widths. */
122
 
   colTemp = CDKsplitString (myColWidths, '\n');
123
 
   count = CDKcountStrings (colTemp);
 
123
   kolTemp = CDKsplitString (myColWidths, '\n');
 
124
   count = CDKcountStrings (kolTemp);
124
125
   colWidths = (int *) calloc (count + 1, sizeof(int));
125
126
   for (x=0; x < count; x++)
126
127
   {
127
 
      colWidths[x+1] = atoi (colTemp[x]);
 
128
      colWidths[x+1] = atoi (kolTemp[x]);
128
129
   }
129
 
   CDKfreeStrings(colTemp);
130
130
 
131
131
   /* If they passed in the column types, convert them. */
132
132
   if (myColTypes != 0)
133
133
   {
134
 
      colTemp = CDKsplitString (myColTypes, '\n');
135
 
      count = CDKcountStrings (colTemp);
 
134
      char **ss = CDKsplitString (myColTypes, '\n');
 
135
      count = CDKcountStrings (ss);
136
136
      colTypes = (int *) calloc (MAXIMUM(cols, count) + 1, sizeof(int));
137
137
      for (x=0; x < count; x++)
138
138
      {
139
 
         colTypes[x+1] = char2DisplayType (colTemp[x]);
 
139
         colTypes[x+1] = char2DisplayType (ss[x]);
140
140
      }
141
 
      CDKfreeStrings(colTemp);
 
141
      CDKfreeStrings(ss);
142
142
   }
143
143
   else
144
144
   {
189
189
                                colWidths, colTypes, 1, 1,
190
190
                                filler, COL,
191
191
                                boxWidget, TRUE, shadowWidget);
 
192
   free (rowTitles);
 
193
   free (colTitles);
192
194
 
193
195
   /* Make sure we could create the widget. */
194
196
   if (widget == 0)
197
199
      destroyCDKScreen (cdkScreen);
198
200
      endCDK();
199
201
 
200
 
      /* Spit out the message. */
201
202
      fprintf (stderr, "Error: Could not create the matrix. Is the window too small?\n");
202
203
 
203
 
      /* Exit with an error. */
204
 
      exit (-1);
 
204
      ExitProgram (CLI_ERROR);
205
205
   }
206
206
 
207
 
  /*
208
 
   * If the user sent in a file of default values, read it and
209
 
   * stick the values read in from the file into the matrix.
210
 
   */
 
207
   /*
 
208
    * If the user sent in a file of default values, read it and
 
209
    * stick the values read in from the file into the matrix.
 
210
    */
211
211
   if (defaultValue != 0)
212
212
   {
213
213
      int limit = (rows + 1) * (cols + 1);
214
214
      char **info = (char **) calloc (limit, sizeof(char *));
 
215
      char **lineTemp = 0;
215
216
 
216
217
      /* Read the file. */
217
 
      infoLines = CDKreadFile (defaultValue, &rowTemp);
 
218
      infoLines = CDKreadFile (defaultValue, &lineTemp);
218
219
      if (infoLines > 0)
219
220
      {
220
221
         int *subSize = (int *) calloc(infoLines + 1, sizeof(int *));
222
223
         /* For each line, split on a CTRL-V. */
223
224
         for (x=0; x < infoLines; x++)
224
225
         {
225
 
            colTemp = CDKsplitString (rowTemp[x], CTRL('V'));
226
 
            subSize[x+1] = CDKcountStrings (colTemp);
 
226
            char **ss = CDKsplitString (lineTemp[x], CTRL('V'));
 
227
            subSize[x+1] = CDKcountStrings (ss);
227
228
            for (y=0; y < subSize[x+1]; y++)
228
229
            {
229
 
               MY_INFO(x, y) = colTemp[y];
 
230
               MY_INFO(x, y) = ss[y];
230
231
            }
231
 
            free (colTemp);
 
232
            free (ss);
232
233
         }
233
 
         CDKfreeStrings (rowTemp);
 
234
         CDKfreeStrings (lineTemp);
234
235
 
235
236
         setCDKMatrixCells (widget, info, rows, cols, subSize);
236
237
 
237
 
         /* Clean up. */
238
238
         for (x=0; x < infoLines; x++)
239
239
         {
240
240
            for (y=0; y < subSize[x+1]; y++)
266
266
      setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
267
267
      setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
268
268
 
269
 
     /*
270
 
      * We need to set the lower left and right
271
 
      * characters of the widget.
272
 
      */
 
269
      /*
 
270
       * We need to set the lower left and right
 
271
       * characters of the widget.
 
272
       */
273
273
      setCDKMatrixLLChar (widget, ACS_LTEE);
274
274
      setCDKMatrixLRChar (widget, ACS_RTEE);
275
275
 
276
 
     /*
277
 
      * Bind the Tab key in the widget to send a
278
 
      * Tab key to the button box widget.
279
 
      */
 
276
      /*
 
277
       * Bind the Tab key in the widget to send a
 
278
       * Tab key to the button box widget.
 
279
       */
280
280
      bindCDKObject (vMATRIX, widget, KEY_TAB, widgetCB, buttonWidget);
281
281
      bindCDKObject (vMATRIX, widget, CDK_NEXT, widgetCB, buttonWidget);
282
282
      bindCDKObject (vMATRIX, widget, CDK_PREV, widgetCB, buttonWidget);
288
288
      drawCDKButtonbox (buttonWidget, boxWidget);
289
289
   }
290
290
 
291
 
  /*
292
 
   * If the user asked for a shadow, we need to create one.
293
 
   * I do this instead of using the shadow parameter because
294
 
   * the button widget isn't part of the main widget and if
295
 
   * the user asks for both buttons and a shadow, we need to
296
 
   * create a shadow big enough for both widgets. We'll create
297
 
   * the shadow window using the widgets shadowWin element, so
298
 
   * screen refreshes will draw them as well.
299
 
   */
 
291
   /*
 
292
    * If the user asked for a shadow, we need to create one.  Do this instead
 
293
    * of using the shadow parameter because the button widget is not part of
 
294
    * the main widget and if the user asks for both buttons and a shadow, we
 
295
    * need to create a shadow big enough for both widgets.  Create the shadow
 
296
    * window using the widgets shadowWin element, so screen refreshes will draw
 
297
    * them as well.
 
298
    */
300
299
   if (shadowWidget == TRUE)
301
300
   {
302
301
      /* Determine the height of the shadow window. */
315
314
      {
316
315
         widget->shadow = TRUE;
317
316
 
318
 
        /*
319
 
         * We force the widget and buttonWidget to be drawn so the
320
 
         * buttonbox widget will be drawn when the widget is activated.
321
 
         * Otherwise the shadow window will draw over the button widget.
322
 
         */
 
317
         /*
 
318
          * We force the widget and buttonWidget to be drawn so the
 
319
          * buttonbox widget will be drawn when the widget is activated.
 
320
          * Otherwise the shadow window will draw over the button widget.
 
321
          */
323
322
         drawCDKMatrix (widget, ObjOf(widget)->box);
324
323
         eraseCDKButtonbox (buttonWidget);
325
324
         drawCDKButtonbox (buttonWidget, ObjOf(buttonWidget)->box);
365
364
   free (colTypes);
366
365
   free (colWidths);
367
366
 
368
 
   for (x=0; x < rows; x++)
369
 
   {
370
 
      free (rowTitles[x+1]);
371
 
   }
372
 
   free (rowTitles);
373
 
 
374
 
   for (x=0; x < cols; x++)
375
 
   {
376
 
      free (colTitles[x+1]);
377
 
   }
378
 
   free (colTitles);
 
367
   CDKfreeStrings (rowTemp);
 
368
   CDKfreeStrings (colTemp);
 
369
   CDKfreeStrings (kolTemp);
379
370
 
380
371
   destroyCDKMatrix (widget);
381
372
   destroyCDKScreen (cdkScreen);
382
 
 
383
 
   /* this is needed */
384
373
   endCDK();
385
 
   exit (selection);
 
374
 
 
375
   /* do this late, in case it was stderr */
 
376
   fclose (fp);
 
377
 
 
378
   ExitProgram (selection);
386
379
}
387
380
 
388
381
static int widgetCB (EObjectType cdktype GCC_UNUSED, void *object GCC_UNUSED, void *clientData, chtype key)