summaryrefslogtreecommitdiff
path: root/libgui/src/tclwinmode.c
blob: 958d5c9c6071387c0585c04b276ab98001d64374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* tclwinmode.c - Tcl access to SetErrorMode function.
   Copyright (C) 1998 Cygnus Solutions.
   Written by Tom Tromey <tromey@cygnus.com>.  */

#include <tcl.h>
#include "guitcl.h"

#ifdef __CYGWIN32__

#include <windows.h>

struct pair
{
  const char *name;
  UINT value;
};

static struct pair values[] =
{
  { "failcriticalerrors", SEM_FAILCRITICALERRORS },
  { "noalignmentfaultexcept", SEM_NOALIGNMENTFAULTEXCEPT },
  { "nogpfaulterrorbox", SEM_NOGPFAULTERRORBOX },
  { "noopenfileerrorbox", SEM_NOOPENFILEERRORBOX },
  { NULL, 0 }
};

#endif

static int
seterrormode_command (ClientData cd, Tcl_Interp *interp,
		      int argc, char *argv[])
{
#ifdef __CYGWIN32__
  int len, i;
  char **list;
  UINT val = 0;

  if (argc != 2)
    {
      Tcl_AppendResult (interp, "wrong # args: should be \"",
			argv[0], " modelist\"", (char *) NULL);
      return TCL_ERROR;
    }

  if (Tcl_SplitList (interp, argv[1], &len, &list) != TCL_OK)
    return TCL_ERROR;

  for (i = 0; i < len; ++i)
    {
      int j, found = 0;
      for (j = 0; values[j].name; ++j)
	{
	  if (! strcmp (values[j].name, list[i]))
	    {
	      found = 1;
	      val |= values[j].value;
	      break;
	    }
	}
      if (! found)
	{
	  Tcl_AppendResult (interp, "unrecognized key \"", list[i],
			    "\"", (char *) NULL);
	  Tcl_Free ((char *) list);
	  return TCL_ERROR;
	}
    }
  Tcl_Free ((char *) list);

  val = SetErrorMode (val);

  for (i = 0; values[i].name; ++i)
    {
      if (val & values[i].value)
	Tcl_AppendElement (interp, values[i].name);
    }
#endif /* __CYGWIN32__ */

  return TCL_OK;
}

int
ide_create_set_error_mode_command (Tcl_Interp *interp)
{
  if (Tcl_CreateCommand (interp, "ide_set_error_mode",
			 seterrormode_command, NULL, NULL) == NULL)
    return TCL_ERROR;
  return TCL_OK;
}