tcledit: Fix some logic errors.

This commit is contained in:
Gregory Nutt 2016-11-12 07:56:59 -06:00
parent 307bb794a8
commit 104d743c2a
7 changed files with 329 additions and 286 deletions

View File

@ -397,7 +397,7 @@ static uint8_t wld_read_filename(INIHANDLE handle,
* Description:
************************************************************************/
uint8_t wld_create_world(char *wldfile)
uint8_t wld_create_world(const char *wldfile)
{
INIHANDLE handle;
uint8_t result;

View File

@ -101,7 +101,8 @@ extern "C"
/* World file return codes */
enum {
enum
{
WORLD_SUCCESS = 0,
WORLD_FILE_OPEN_ERROR = 100,
WORLD_INTEGER_OUT_OF_RANGE,
@ -112,20 +113,23 @@ enum {
WORLD_BITMAP_FILE_NAME_ERROR
};
/* The following structure contains all information necessary to define
* a point-of-view
*/
typedef struct {
struct wld_camer_s
{
wld_coord_t x; /* Camera position */
wld_coord_t y;
wld_coord_t z;
int16_t yaw; /* Camera orientation */
int16_t pitch;
};
wld_coord_t x, y, z; /* Camera position */
int16_t yaw, pitch; /* Camera orientation */
} wld_camera_t;
typedef struct wld_camer_s wld_camera_t;
/*************************************************************************
* Global Data
* Public Data
*************************************************************************/
/* This is the starting position and orientation of the camera in the world */
@ -150,7 +154,7 @@ extern wld_coord_t g_run_stepheight;
* Global Function Prototypes
*************************************************************************/
uint8_t wld_create_world(char *mapfile);
uint8_t wld_create_world(const char *mapfile);
void wld_deallocate_world(void);
#ifdef __cplusplus

View File

@ -1,6 +1,9 @@
Build instuctions
=================
tcledit is a world editor for the traveler. You should be able to build it
under Linux or Cygwin. It needs X11 and Tcl/Tk.
At the time of 'make', you must have a valid Traveler configuration instantiated
in the NuttX directory. This is because the build will depend on certain
configurations (such as color format).
@ -40,6 +43,8 @@ Build instuctions
10b. make tcledit DEBUG_LEVEL=1
On Cygwin, the make target will be tcledit.exe, not tcledit.
Usage
=====
@ -54,3 +59,6 @@ Usage
like:
./tcledit -D ../../world transfrm.wld
On Cywgin, the correct name of the program will be tcledit.exe and must also
remember to start the X11 server before trying run the applications.

View File

@ -40,6 +40,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
@ -58,8 +59,9 @@
static Tcl_Interp *g_tcledit_interp;
static const char *g_in_filename;
static const char *g_out_filename;
static const char g_default_filename[] = "planes.pll";
static char *g_out_filename;
static char g_tcledit_filename[] = "tcl_edit.tk";
static char *g_tcledit_path = g_tcledit_filename;
/****************************************************************************
* Public Variables
@ -166,7 +168,7 @@ static void tcledit_update_newmode_display(void)
}
}
/* Called in response to the "seteditmode" Tcl command to set the
/* Called in response to the "tcl_seteditmode" Tcl command to set the
* current edit mode
*/
@ -237,7 +239,7 @@ static int tcledit_setmode(ClientData clientData,
return TCL_OK;
}
/* Called in response to the "position" Tcl command */
/* Called in response to the "tcl_position" Tcl command */
static int tcledit_new_position(ClientData clientData,
Tcl_Interp *interp, int argc, const char *argv[])
@ -261,7 +263,7 @@ static int tcledit_new_position(ClientData clientData,
return TCL_OK;
}
/* Called in response to the "zoom" Tcl command */
/* Called in response to the "tcl_zoom" Tcl command */
static int tcledit_new_zoom(ClientData clientData,
Tcl_Interp *interp, int argc, const char *argv[])
@ -331,7 +333,7 @@ static int tcledit_new_zoom(ClientData clientData,
return TCL_OK;
}
/* Called in response to the "edit" Tcl command */
/* Called in response to the "tcl_edit" Tcl command */
static int tcledit_new_edit(ClientData clientData,
Tcl_Interp *interp, int argc, const char *argv[])
@ -446,7 +448,7 @@ static int tcledit_new_edit(ClientData clientData,
return TCL_OK;
}
/* Called in response to the "attributes" Tcl command */
/* Called in response to the "tcl_attributes" Tcl command */
static int tcledit_new_attributes(ClientData clientData,
Tcl_Interp *interp, int argc, const char *argv[])
@ -527,7 +529,7 @@ static int tcledit_new_attributes(ClientData clientData,
return TCL_OK;
}
/* Called in response to the "addrectangle" Tcl command */
/* Called in response to the "tcl_addrectangle" Tcl command */
static int tcledit_add_rectangle(ClientData clientData,
Tcl_Interp *interp, int argc, const char *argv[])
@ -574,7 +576,7 @@ static int tcledit_add_rectangle(ClientData clientData,
return TCL_OK;
}
/* Called in response to the "save" Tcl command */
/* Called in response to the "tcl_save" Tcl command */
static int tcledit_save_rectangles(ClientData clientData,
Tcl_Interp *interp, int argc, const char *argv[])
@ -607,17 +609,33 @@ int main(int argc, char **argv, char **envp)
{
char *directory;
int option;
int len;
int ret;
/* Parse command line options */
g_out_filename = g_default_filename;
g_out_filename = NULL;
while ((option = getopt(argc, argv, "D:o:")) != EOF)
{
switch (option)
{
case 'D':
/* 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 */
directory = optarg;
ret = chdir(directory);
if (ret < 0)
@ -650,6 +668,19 @@ int main(int argc, char **argv, char **envp)
g_in_filename = argv[optind];
/* 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");
}
/* Read the world files now so that we can be certain that it is a valid
* world file.
*/
@ -682,6 +713,7 @@ int do_tcl_action(const char *script)
int Tcl_AppInit(Tcl_Interp *interp)
{
int ret;
int i;
/* Save the interpreter for later */
@ -692,48 +724,46 @@ int Tcl_AppInit(Tcl_Interp * interp)
for (i = 0; i < NUM_PLANES; i++)
{
x11_initilaize_graphics(&g_windows[i]);
x11_initialize_graphics(&g_windows[i]);
}
/* Tcl_Init() sets up the Tcl library factility */
if (Tcl_Init(interp) == TCL_ERROR)
{
return TCL_ERROR;
}
if (Tk_Init(interp) == TCL_ERROR)
ret = Tcl_Init(interp);
if (ret == TCL_ERROR)
{
return TCL_ERROR;
}
/* Define application-specific commands */
Tcl_CreateCommand(g_tcledit_interp, "seteditmode", tcledit_setmode,
Tcl_CreateCommand(g_tcledit_interp, "tcl_seteditmode", tcledit_setmode,
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(g_tcledit_interp, "position", tcledit_new_position,
Tcl_CreateCommand(g_tcledit_interp, "tcl_position", tcledit_new_position,
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(g_tcledit_interp, "zoom", tcledit_new_zoom,
Tcl_CreateCommand(g_tcledit_interp, "tcl_zoom", tcledit_new_zoom,
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(g_tcledit_interp, "edit", tcledit_new_edit,
Tcl_CreateCommand(g_tcledit_interp, "tcl_edit", tcledit_new_edit,
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(g_tcledit_interp, "attributes", tcledit_new_attributes,
Tcl_CreateCommand(g_tcledit_interp, "tcl_attributes", tcledit_new_attributes,
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(g_tcledit_interp, "addrectangle", tcledit_add_rectangle,
Tcl_CreateCommand(g_tcledit_interp, "tcl_addrectangle", tcledit_add_rectangle,
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(g_tcledit_interp, "save", tcledit_save_rectangles,
Tcl_CreateCommand(g_tcledit_interp, "tcl_save", tcledit_save_rectangles,
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
/* Initialize the Tcl parser */
if (Tcl_EvalFile(g_tcledit_interp, "tcledit.tk") != TCL_OK)
ret = Tcl_EvalFile(g_tcledit_interp, g_tcledit_path);
if (ret != TCL_OK)
{
fprintf(stderr, "Tcl_EvalFile failed: %d\n", ret);
fprintf(stderr, " %s\n", Tcl_GetVar(g_tcledit_interp, "errorCode", 0));
fprintf(stderr, " %s\n", Tcl_GetVar(g_tcledit_interp, "errorInfo", 0));
exit(1);
}
return TCL_OK;
return ret;
}
void wld_fatal_error(char *message, ...)

View File

@ -35,6 +35,7 @@
#############################################################################
# Control features for each element
proc configentry {w option items} {
foreach i $items {
$w.$i configure -state $option

View File

@ -436,11 +436,11 @@ void x11_UpdateScreen(tcl_window_t * w)
****************************************************************************/
/****************************************************************************
* Name: x11_initilaize_graphics
* Name: x11_initialize_graphics
* Description:
***************************************************************************/
void x11_initilaize_graphics(tcl_window_t * w)
void x11_initialize_graphics(tcl_window_t * w)
{
XWindowAttributes windowAttributes;

View File

@ -166,7 +166,7 @@ extern rect_data_t g_edit_rect;
* Public Function Prototypes
****************************************************************************/
void x11_initilaize_graphics(tcl_window_t *w);
void x11_initialize_graphics(tcl_window_t *w);
void x11_end_graphics(tcl_window_t *w);
void x11_update_screen(tcl_window_t *w);