2016-11-09 18:14:35 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/graphics/traveler/tools/tcledit/tcl_edit.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2016-11-12 14:56:59 +01:00
|
|
|
#include <limits.h>
|
2016-11-09 18:14:35 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2016-11-11 17:05:12 +01:00
|
|
|
#include <errno.h>
|
2016-11-09 18:14:35 +01:00
|
|
|
#include <tk.h>
|
|
|
|
|
|
|
|
#include "trv_types.h"
|
2016-11-11 21:17:05 +01:00
|
|
|
#include "wld_world.h"
|
2016-11-12 19:08:44 +01:00
|
|
|
#include "wld_debug.h"
|
2016-11-09 18:37:17 +01:00
|
|
|
#include "wld_utils.h"
|
2016-11-09 18:14:35 +01:00
|
|
|
#include "tcl_x11graphics.h"
|
|
|
|
#include "tcl_colors.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Variables
|
|
|
|
***************************************************************************/
|
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
static Tcl_Interp *g_tcledit_interp;
|
|
|
|
static const char *g_in_filename;
|
2016-11-12 14:56:59 +01:00
|
|
|
static char *g_out_filename;
|
|
|
|
static char g_tcledit_filename[] = "tcl_edit.tk";
|
|
|
|
static char *g_tcledit_path = g_tcledit_filename;
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Variables
|
|
|
|
***************************************************************************/
|
|
|
|
|
2016-11-11 14:52:32 +01:00
|
|
|
enum edit_mode_e g_edit_mode = EDITMODE_NONE;
|
|
|
|
enum edit_plane_e g_edit_plane = EDITPLANE_X;
|
2016-11-10 23:34:25 +01:00
|
|
|
int g_view_size = WORLD_INFINITY;
|
|
|
|
int g_grid_step = WORLD_SIZE / 16;
|
|
|
|
|
|
|
|
int g_coord_offset[NUM_PLANES];
|
|
|
|
int g_plane_position[NUM_PLANES];
|
|
|
|
tcl_window_t g_windows[NUM_PLANES] =
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
{
|
2016-11-10 19:21:47 +01:00
|
|
|
.title = "X-Plane",
|
|
|
|
.plane = EDITPLANE_X,
|
|
|
|
.width = WINDOW_SIZE,
|
2016-11-09 18:14:35 +01:00
|
|
|
.height = WINDOW_SIZE,
|
2016-11-10 19:21:47 +01:00
|
|
|
.palette =
|
|
|
|
{
|
|
|
|
Lavender, Red, Red, LemonChiffon,
|
|
|
|
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
Lavender, Red, Red, LemonChiffon,
|
|
|
|
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
LightGray, DarkGray, DarkGray, DarkGray,
|
|
|
|
LightSteelBlue, SlateGray, SlateGray, SteelBlue,
|
2016-11-09 18:14:35 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-10 19:21:47 +01:00
|
|
|
.title = "Y-Plane",
|
|
|
|
.plane = EDITPLANE_Y,
|
|
|
|
.width = WINDOW_SIZE,
|
|
|
|
.height = WINDOW_SIZE,
|
|
|
|
.palette =
|
|
|
|
{
|
|
|
|
Lavender, Red, Red, LemonChiffon,
|
|
|
|
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
Lavender, Red, Red, LemonChiffon,
|
|
|
|
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
LightGray, DarkGray, DarkGray, DarkGray,
|
|
|
|
LightSteelBlue, SlateGray, SlateGray, SteelBlue,
|
2016-11-09 18:14:35 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-10 19:21:47 +01:00
|
|
|
.title = "Z-Plane",
|
|
|
|
.plane = EDITPLANE_Z,
|
|
|
|
.width = WINDOW_SIZE,
|
|
|
|
.height = WINDOW_SIZE,
|
|
|
|
.palette =
|
|
|
|
{
|
|
|
|
Lavender, Red, Red, LemonChiffon,
|
|
|
|
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
Lavender, Red, Red, LemonChiffon,
|
|
|
|
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
LightGray, DarkGray, DarkGray, DarkGray,
|
|
|
|
LightSteelBlue, SlateGray, SlateGray, SteelBlue,
|
2016-11-09 18:14:35 +01:00
|
|
|
},
|
2016-11-10 19:21:47 +01:00
|
|
|
}
|
2016-11-09 18:14:35 +01:00
|
|
|
};
|
2016-11-10 19:21:47 +01:00
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
rect_data_t g_edit_rect;
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/* Called when any change is made to the display while in POS mode */
|
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
static void tcledit_update_posmode_display(void)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_PLANES; i++)
|
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
tcl_window_t *w = &g_windows[i];
|
2016-11-09 18:37:17 +01:00
|
|
|
tcl_paint_background(w);
|
|
|
|
tcl_paint_grid(w);
|
|
|
|
tcl_paint_rectangles(w);
|
|
|
|
tcl_paint_position(w);
|
2016-11-11 14:52:32 +01:00
|
|
|
x11_update_screen(w);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when any change is made to the display while in NEW mode */
|
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
static void tcledit_update_newmode_display(void)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_PLANES; i++)
|
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
tcl_window_t *w = &g_windows[i];
|
2016-11-09 18:37:17 +01:00
|
|
|
tcl_paint_background(w);
|
|
|
|
tcl_paint_grid(w);
|
|
|
|
tcl_paint_rectangles(w);
|
2016-11-11 14:52:32 +01:00
|
|
|
x11_update_screen(w);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
/* Called in response to the "tcl_seteditmode" Tcl command to set the
|
2016-11-09 18:14:35 +01:00
|
|
|
* current edit mode
|
|
|
|
*/
|
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
static int tcledit_setmode(ClientData clientData,
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_Interp *interp, int argc, const char *argv[])
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Processing command: %s\n", argv[0]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argc);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "POS") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Entering POS mode\n");
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_mode = EDITMODE_POS;
|
2016-11-10 21:04:05 +01:00
|
|
|
tcledit_update_posmode_display();
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (strcmp(argv[1], "NEW") == 0)
|
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_mode = EDITMODE_NEW;
|
|
|
|
memset(&g_edit_rect, 0, sizeof(rect_data_t));
|
2016-11-09 18:14:35 +01:00
|
|
|
if (strcmp(argv[2], "x") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Entering NEWX mode\n");
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_plane = EDITPLANE_X;
|
|
|
|
g_edit_rect.plane = g_plane_position[EDITPLANE_X];
|
2016-11-11 13:57:01 +01:00
|
|
|
g_edit_rect.hstart = g_plane_position[EDITPLANE_Y];
|
|
|
|
g_edit_rect.hend = g_edit_rect.hstart;
|
|
|
|
g_edit_rect.vstart = g_plane_position[EDITPLANE_Z];
|
|
|
|
g_edit_rect.vend = g_edit_rect.vstart;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[2], "y") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Entering NEWY mode\n");
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_plane = EDITPLANE_Y;
|
|
|
|
g_edit_rect.plane = g_plane_position[EDITPLANE_Y];
|
2016-11-11 13:57:01 +01:00
|
|
|
g_edit_rect.hstart = g_plane_position[EDITPLANE_X];
|
|
|
|
g_edit_rect.hend = g_edit_rect.hstart;
|
|
|
|
g_edit_rect.vstart = g_plane_position[EDITPLANE_Z];
|
|
|
|
g_edit_rect.vend = g_edit_rect.vstart;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[2], "z") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Entering NEWZ mode\n");
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_plane = EDITPLANE_Z;
|
|
|
|
g_edit_rect.plane = g_plane_position[EDITPLANE_Z];
|
2016-11-11 13:57:01 +01:00
|
|
|
g_edit_rect.hstart = g_plane_position[EDITPLANE_X];
|
|
|
|
g_edit_rect.hend = g_edit_rect.hstart;
|
|
|
|
g_edit_rect.vstart = g_plane_position[EDITPLANE_Y];
|
|
|
|
g_edit_rect.vend = g_edit_rect.vstart;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unrecognized NEW plane: %s\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argv[2]);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 21:04:05 +01:00
|
|
|
|
|
|
|
tcledit_update_newmode_display();
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-10 19:21:47 +01:00
|
|
|
wld_fatal_error("%s: Unrecognized mode: %s\n", __FUNCTION__, argv[1]);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 19:21:47 +01:00
|
|
|
|
2016-11-09 18:14:35 +01:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
/* Called in response to the "tcl_position" Tcl command */
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
static int tcledit_new_position(ClientData clientData,
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_Interp *interp, int argc, const char *argv[])
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Processing command: %s\n", argv[0]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
if (argc != 4)
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argc);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
g_plane_position[0] = atoi(argv[1]);
|
|
|
|
g_plane_position[1] = atoi(argv[2]);
|
|
|
|
g_plane_position[2] = atoi(argv[3]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New plane positions: {%d,%d,%d}\n",
|
2016-11-10 23:34:25 +01:00
|
|
|
g_plane_position[0], g_plane_position[1], g_plane_position[2]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
tcledit_update_posmode_display();
|
2016-11-09 18:14:35 +01:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
/* Called in response to the "tcl_zoom" Tcl command */
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
static int tcledit_new_zoom(ClientData clientData,
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_Interp *interp, int argc, const char *argv[])
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Processing command: %s\n", argv[0]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
if (argc != 5)
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argc);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the zoom settings */
|
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
g_view_size = atoi(argv[1]);
|
|
|
|
g_coord_offset[0] = atoi(argv[2]);
|
|
|
|
g_coord_offset[1] = atoi(argv[3]);
|
|
|
|
g_coord_offset[2] = atoi(argv[4]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
/* The grid size will be determined by the scaling */
|
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
if (g_view_size <= 256)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_grid_step = 16; /* 16 lines at 256 */
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 23:34:25 +01:00
|
|
|
else if (g_view_size <= 512)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_grid_step = 32; /* 16 lines at 512 */
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 23:34:25 +01:00
|
|
|
else if (g_view_size <= 1024)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_grid_step = 64; /* 16 lines at 1024 */
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 23:34:25 +01:00
|
|
|
else if (g_view_size <= 2048)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_grid_step = 128; /* 16 lines at 2048 */
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 23:34:25 +01:00
|
|
|
else if (g_view_size <= 4096)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_grid_step = 256; /* 16 lines at 4096 */
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 23:34:25 +01:00
|
|
|
else if (g_view_size <= 8192)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_grid_step = 512; /* 16 lines at 8196 */
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 23:34:25 +01:00
|
|
|
else if (g_view_size <= 16384)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_grid_step = 1024; /* 16 lines at 16384 */
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 23:34:25 +01:00
|
|
|
else /* if (g_view_size <= 32768) */
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_grid_step = 2048; /* 16 lines at 32768 */
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New g_view_size, g_grid_step: %d, %d\n", g_view_size, g_grid_step);
|
|
|
|
info("New coordinate offsets: {%d,%d,%d}\n",
|
2016-11-10 23:34:25 +01:00
|
|
|
g_coord_offset[0], g_coord_offset[1], g_coord_offset[2]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
if (g_edit_mode == EDITMODE_POS)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 21:04:05 +01:00
|
|
|
tcledit_update_posmode_display();
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-10 21:04:05 +01:00
|
|
|
tcledit_update_newmode_display();
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
/* Called in response to the "tcl_edit" Tcl command */
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
static int tcledit_new_edit(ClientData clientData,
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_Interp *interp, int argc, const char *argv[])
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
int start;
|
|
|
|
int end;
|
|
|
|
int extent;
|
|
|
|
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Processing command: %s\n", argv[0]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
if (argc != 4)
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argc);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore the command if we are not in NEW mode */
|
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
if (g_edit_mode == EDITMODE_NEW)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
/* Get the new position information */
|
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
start = atoi(argv[2]);
|
2016-11-09 18:14:35 +01:00
|
|
|
extent = atoi(argv[3]);
|
2016-11-10 19:21:47 +01:00
|
|
|
end = start + extent - 1;
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
/* Which plane are we editting? */
|
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
switch (g_edit_plane)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
case EDITPLANE_X:
|
|
|
|
if (strcmp(argv[1], "x") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New X plane position: %d\n", start);
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.plane = start;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "y") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New horizontal Y coordinates: {%d,%d}\n", start, end);
|
2016-11-11 13:57:01 +01:00
|
|
|
g_edit_rect.hstart = start;
|
|
|
|
g_edit_rect.hend = end;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "z") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New vertical Z coordinates: {%d,%d}\n", start, end);
|
2016-11-11 13:57:01 +01:00
|
|
|
g_edit_rect.vstart = start;
|
|
|
|
g_edit_rect.vend = end;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unrecognized EDITX plane: %s\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argv[1]);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EDITPLANE_Y:
|
|
|
|
if (strcmp(argv[1], "x") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New horizontal X coordinates: {%d,%d}\n", start, end);
|
2016-11-11 13:57:01 +01:00
|
|
|
g_edit_rect.hstart = start;
|
|
|
|
g_edit_rect.hend = end;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "y") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New Y plane position: %d\n", start);
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.plane = start;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "z") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New vertical Z coordinates: {%d,%d}\n", start, end);
|
2016-11-11 13:57:01 +01:00
|
|
|
g_edit_rect.vstart = start;
|
|
|
|
g_edit_rect.vend = end;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unrecognized EDITY plane: %s\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argv[1]);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EDITPLANE_Z:
|
|
|
|
if (strcmp(argv[1], "x") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New horizontal X coordinates: {%d,%d}\n", start, end);
|
2016-11-11 13:57:01 +01:00
|
|
|
g_edit_rect.hstart = start;
|
|
|
|
g_edit_rect.hend = end;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "y") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New vertical Y coordinates: {%d,%d}\n", start, end);
|
2016-11-11 13:57:01 +01:00
|
|
|
g_edit_rect.vstart = start;
|
|
|
|
g_edit_rect.vend = end;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "z") == 0)
|
|
|
|
{
|
2016-11-12 19:08:44 +01:00
|
|
|
info("New Z plane position: %d\n", start);
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.plane = start;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unrecognized EDITZ plane: %s\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argv[1]);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-11-10 21:04:05 +01:00
|
|
|
tcledit_update_newmode_display();
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 21:04:05 +01:00
|
|
|
|
2016-11-09 18:14:35 +01:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
/* Called in response to the "tcl_attributes" Tcl command */
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
static int tcledit_new_attributes(ClientData clientData,
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_Interp *interp, int argc, const char *argv[])
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
const char *attributes;
|
|
|
|
int tmp;
|
|
|
|
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Processing command: %s\n", argv[0]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
if (argc != 4)
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argc);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
attributes = argv[1];
|
|
|
|
if (strlen(attributes) != 3)
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unexpected attribute string length: %s\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argv[1]);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore the command if we are not in NEW mode */
|
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
if (g_edit_mode == EDITMODE_NEW)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
if (attributes[0] == '1')
|
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.attribute |= SHADED_PLANE;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.attribute &= ~SHADED_PLANE;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attributes[1] == '1')
|
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.attribute |= TRANSPARENT_PLANE;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.attribute &= ~TRANSPARENT_PLANE;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attributes[2] == '1')
|
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.attribute |= DOOR_PLANE;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.attribute &= ~DOOR_PLANE;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-12 19:08:44 +01:00
|
|
|
info("attributes: %s->%02x\n", attributes, g_edit_rect.attribute);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
tmp = atoi(argv[2]);
|
2016-11-10 19:21:47 +01:00
|
|
|
if ((tmp >= 0) && (tmp < 256))
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.texture = tmp;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Texture index out of range: %d\n", tmp);
|
|
|
|
}
|
2016-11-12 19:08:44 +01:00
|
|
|
info("texture: %s->%d\n", argv[2], g_edit_rect.texture);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
tmp = atoi(argv[3]);
|
2016-11-10 19:21:47 +01:00
|
|
|
if ((tmp >= 0) && (tmp <= MAXX_SCALING))
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 23:34:25 +01:00
|
|
|
g_edit_rect.scale = tmp;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Scaling not supported: %d\n", tmp);
|
|
|
|
}
|
2016-11-12 19:08:44 +01:00
|
|
|
info("scale: %s->%d\n", argv[3], g_edit_rect.scale);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
2016-11-10 19:21:47 +01:00
|
|
|
|
2016-11-09 18:14:35 +01:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
/* Called in response to the "tcl_addrectangle" Tcl command */
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
static int tcledit_add_rectangle(ClientData clientData,
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_Interp *interp, int argc, const char *argv[])
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 19:21:47 +01:00
|
|
|
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Processing command: %s\n", argv[0]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
if (argc != 1)
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argc);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore the command if we are not in NEW mode */
|
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
if (g_edit_mode == EDITMODE_NEW)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
/* Get a new container for the rectangle information */
|
|
|
|
|
2016-11-10 18:42:37 +01:00
|
|
|
rect_list_t *rect = wld_new_plane();
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
/* Copy the rectangle data into the container */
|
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
rect->d = g_edit_rect;
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
/* Save the rectangle in the correct list */
|
|
|
|
|
2016-11-10 23:34:25 +01:00
|
|
|
switch (g_edit_plane)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
case EDITPLANE_X:
|
2016-11-10 19:21:47 +01:00
|
|
|
wld_add_plane(rect, &g_xplane_list);
|
2016-11-09 18:14:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDITPLANE_Y:
|
2016-11-10 19:21:47 +01:00
|
|
|
wld_add_plane(rect, &g_yplane_list);
|
2016-11-09 18:14:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDITPLANE_Z:
|
2016-11-10 19:21:47 +01:00
|
|
|
wld_add_plane(rect, &g_zplane_list);
|
2016-11-09 18:14:35 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 21:04:05 +01:00
|
|
|
|
2016-11-09 18:14:35 +01:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
/* Called in response to the "tcl_save" Tcl command */
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
static int tcledit_save_rectangles(ClientData clientData,
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_Interp *interp, int argc, const char *argv[])
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 19:21:47 +01:00
|
|
|
|
2016-11-12 19:08:44 +01:00
|
|
|
info("Processing command: %s\n", argv[0]);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
if (argc != 1)
|
|
|
|
{
|
2016-11-09 18:54:33 +01:00
|
|
|
wld_fatal_error("%s: Unexpected number of arguments: %d\n",
|
2016-11-10 19:21:47 +01:00
|
|
|
__FUNCTION__, argc);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
wld_save_planes(g_out_filename);
|
2016-11-09 18:14:35 +01:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_usage(const char *progname)
|
|
|
|
{
|
2016-11-11 17:05:12 +01:00
|
|
|
fprintf(stderr, "USAGE:\n\t%s [-D <directory>] [-o <outfilename>] <infilename>\n",
|
|
|
|
progname);
|
2016-11-09 18:14:35 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, char **argv, char **envp)
|
|
|
|
{
|
2016-11-11 17:05:12 +01:00
|
|
|
char *directory;
|
2016-11-09 18:14:35 +01:00
|
|
|
int option;
|
2016-11-12 14:56:59 +01:00
|
|
|
int len;
|
2016-11-11 17:05:12 +01:00
|
|
|
int ret;
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
/* Parse command line options */
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
g_out_filename = NULL;
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-11 17:05:12 +01:00
|
|
|
while ((option = getopt(argc, argv, "D:o:")) != EOF)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
2016-11-11 17:05:12 +01:00
|
|
|
case 'D':
|
2016-11-12 14:56:59 +01:00
|
|
|
/* Save the current working directory */
|
|
|
|
|
|
|
|
g_tcledit_path = (char *)malloc(PATH_MAX);
|
|
|
|
getcwd(g_tcledit_path, PATH_MAX);
|
|
|
|
|
|
|
|
len = strlen(g_tcledit_path);
|
|
|
|
g_tcledit_path[len] = '/';
|
|
|
|
g_tcledit_path[len+1] = '\0';
|
|
|
|
len++;
|
|
|
|
|
|
|
|
strcat(&g_tcledit_path[len], g_tcledit_filename);
|
|
|
|
g_tcledit_path = (char *)realloc(g_tcledit_path, strlen(g_tcledit_path) + 1);
|
|
|
|
|
|
|
|
/* Change to the new directory */
|
|
|
|
|
2016-11-11 17:05:12 +01:00
|
|
|
directory = optarg;
|
|
|
|
ret = chdir(directory);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
fprintf(stderr, "ERROR: Failed to CD to %s: %s\n",
|
|
|
|
directory, strerror(errcode));
|
|
|
|
show_usage(argv[0]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
case 'o':
|
2016-11-10 21:04:05 +01:00
|
|
|
g_out_filename = optarg;
|
2016-11-09 18:14:35 +01:00
|
|
|
break;
|
2016-11-11 17:05:12 +01:00
|
|
|
|
2016-11-09 18:14:35 +01:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unrecognized option: %c\n", option);
|
|
|
|
show_usage(argv[0]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
/* We expect at least one argument after the options: The input file name. */
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
if (optind > argc - 1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Expected input file name\n");
|
|
|
|
show_usage(argv[0]);
|
|
|
|
}
|
2016-11-10 19:21:47 +01:00
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
g_in_filename = argv[optind];
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
/* The output file name defaults to the same as the input file name but
|
|
|
|
* with the extension .pll.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (g_out_filename == NULL)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
g_out_filename = strdup(g_in_filename + 5);
|
|
|
|
for (ptr = g_out_filename; *ptr != '.' && *ptr != '\0'; ptr++);
|
|
|
|
sprintf(ptr, ".pll");
|
|
|
|
}
|
|
|
|
|
2016-11-11 21:17:05 +01:00
|
|
|
/* Read the world files now so that we can be certain that it is a valid
|
|
|
|
* world file.
|
|
|
|
*/
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-11 21:17:05 +01:00
|
|
|
if (wld_create_world(g_in_filename) != PLANE_SUCCESS)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
/* Tk_Main creates a Tcl interpreter and calls Tcl_AppInit() then begins
|
2016-11-12 16:00:05 +01:00
|
|
|
* processing window events and interactive commands.
|
|
|
|
*/
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
Tk_Main(1, argv, Tcl_AppInit);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function can be called at any time after initialization to
|
|
|
|
* execute a user specified script.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int do_tcl_action(const char *script)
|
|
|
|
{
|
2016-11-10 21:04:05 +01:00
|
|
|
return Tcl_Eval(g_tcledit_interp, script);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Tcl_AppInit is called from Tcl_Main() after the Tcl interpreter has
|
|
|
|
* been created and before the script file or interactive command loop
|
|
|
|
* is entered.
|
|
|
|
*/
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
int Tcl_AppInit(Tcl_Interp *interp)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-12 14:56:59 +01:00
|
|
|
int ret;
|
2016-11-09 18:14:35 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Save the interpreter for later */
|
|
|
|
|
2016-11-10 21:04:05 +01:00
|
|
|
g_tcledit_interp = interp;
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
/* Initialize the edit windows before starting the Tcl parser */
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_PLANES; i++)
|
|
|
|
{
|
2016-11-12 14:56:59 +01:00
|
|
|
x11_initialize_graphics(&g_windows[i]);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Tcl_Init() sets up the Tcl library factility */
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
ret = Tcl_Init(interp);
|
|
|
|
if (ret == TCL_ERROR)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Define application-specific commands */
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_CreateCommand(g_tcledit_interp, "tcl_seteditmode", tcledit_setmode,
|
2016-11-10 19:21:47 +01:00
|
|
|
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_CreateCommand(g_tcledit_interp, "tcl_position", tcledit_new_position,
|
2016-11-10 19:21:47 +01:00
|
|
|
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_CreateCommand(g_tcledit_interp, "tcl_zoom", tcledit_new_zoom,
|
2016-11-10 19:21:47 +01:00
|
|
|
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_CreateCommand(g_tcledit_interp, "tcl_edit", tcledit_new_edit,
|
2016-11-10 19:21:47 +01:00
|
|
|
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_CreateCommand(g_tcledit_interp, "tcl_attributes", tcledit_new_attributes,
|
2016-11-10 19:21:47 +01:00
|
|
|
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_CreateCommand(g_tcledit_interp, "tcl_addrectangle", tcledit_add_rectangle,
|
2016-11-10 19:21:47 +01:00
|
|
|
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
2016-11-12 14:56:59 +01:00
|
|
|
Tcl_CreateCommand(g_tcledit_interp, "tcl_save", tcledit_save_rectangles,
|
2016-11-10 19:21:47 +01:00
|
|
|
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
|
|
|
/* Initialize the Tcl parser */
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
ret = Tcl_EvalFile(g_tcledit_interp, g_tcledit_path);
|
|
|
|
if (ret != TCL_OK)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-12 15:19:39 +01:00
|
|
|
Tcl_Obj *result;
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
fprintf(stderr, "Tcl_EvalFile failed (%d): ", ret);
|
|
|
|
|
|
|
|
result = Tcl_GetObjResult(g_tcledit_interp);
|
|
|
|
for (i = 0, ptr = result->bytes; i < result->length; i++, ptr++)
|
|
|
|
{
|
|
|
|
fputc(*ptr, stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputc('\n', stderr);
|
2016-11-09 18:14:35 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2016-11-12 14:56:59 +01:00
|
|
|
return ret;
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-09 18:54:33 +01:00
|
|
|
void wld_fatal_error(char *message, ...)
|
2016-11-09 18:14:35 +01:00
|
|
|
{
|
2016-11-10 19:21:47 +01:00
|
|
|
va_list args;
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
va_start(args, message);
|
|
|
|
vfprintf(stderr, message, args);
|
|
|
|
putc('\n', stderr);
|
|
|
|
va_end(args);
|
2016-11-09 18:14:35 +01:00
|
|
|
|
2016-11-10 19:21:47 +01:00
|
|
|
exit(1);
|
2016-11-09 18:14:35 +01:00
|
|
|
}
|