- if (p >= 'A' && p <= 'Z')
- return TRUE;
- if (p >= 'a' && p <= 'z')
- return TRUE;
- if (p >= '0' && p <= '9')
- return TRUE;
- if (p == '.' || p == ':' || p == '_' || p == '-' || p == '`')
- return TRUE;
- return FALSE;
-}
-
-static char *input;
-static char *value;
-
-static void get_string (void)
-{
- char *start = input;
- while (is_filenamechar (*input)){
- input++;
- }
- if (value != NULL)
- g_free (value);
- value = (char *)g_malloc (input - start + 1);
- strncpy (value, start, input-start);
- value [input-start] = 0;
-}
-
-enum Token {
- TOKEN_METHOD,
- TOKEN_CLASS,
- TOKEN_ALL,
- TOKEN_PROGRAM,
- TOKEN_EXCEPTION,
- TOKEN_NAMESPACE,
- TOKEN_WRAPPER,
- TOKEN_STRING,
- TOKEN_EXCLUDE,
- TOKEN_DISABLED,
- TOKEN_SEPARATOR,
- TOKEN_END,
- TOKEN_ERROR
-};
-
-static int
-get_token (void)
-{
- while (input [0] == '+')
- input++;
-
- if (input [0] == '\0') {
- return TOKEN_END;
- }
- if (input [0] == 'M' && input [1] == ':'){
- input += 2;
- get_string ();
- return TOKEN_METHOD;
- }
- if (input [0] == 'N' && input [1] == ':'){
- input += 2;
- get_string ();
- return TOKEN_NAMESPACE;
- }
- if (input [0] == 'T' && input [1] == ':'){
- input += 2;
- get_string ();
- return TOKEN_CLASS;
- }
- if (input [0] == 'E' && input [1] == ':'){
- input += 2;
- get_string ();
- return TOKEN_EXCEPTION;
- }
- if (*input == '-'){
- input++;
- return TOKEN_EXCLUDE;
- }
- if (is_filenamechar (*input)){
- get_string ();
- if (strcmp (value, "all") == 0)
- return TOKEN_ALL;
- if (strcmp (value, "program") == 0)
- return TOKEN_PROGRAM;
- if (strcmp (value, "wrapper") == 0)
- return TOKEN_WRAPPER;
- if (strcmp (value, "disabled") == 0)
- return TOKEN_DISABLED;
- return TOKEN_STRING;
- }
- if (*input == ','){
- input++;
- return TOKEN_SEPARATOR;
- }
-
- fprintf (stderr, "Syntax error at or around '%s'\n", input);
- return TOKEN_ERROR;
-}
-
-static void
-cleanup (void)
-{
- if (value != NULL)
- g_free (value);
-}
-
-static int
-get_spec (int *last)
-{
- int token = get_token ();
- if (token == TOKEN_EXCLUDE){
- token = get_spec (last);
- if (token == TOKEN_EXCLUDE){
- fprintf (stderr, "Expecting an expression");
- return TOKEN_ERROR;
- }
- if (token == TOKEN_ERROR)
- return token;
- trace_spec.ops [(*last)-1].exclude = 1;
- return TOKEN_SEPARATOR;
- }
- if (token == TOKEN_END || token == TOKEN_SEPARATOR || token == TOKEN_ERROR)
- return token;
-
- if (token == TOKEN_METHOD){
- MonoMethodDesc *desc = mono_method_desc_new (value, TRUE);
- if (desc == NULL){
- fprintf (stderr, "Invalid method name: %s\n", value);
- return TOKEN_ERROR;
- }
- trace_spec.ops [*last].op = MONO_TRACEOP_METHOD;
- trace_spec.ops [*last].data = desc;
- } else if (token == TOKEN_ALL)
- trace_spec.ops [*last].op = MONO_TRACEOP_ALL;
- else if (token == TOKEN_PROGRAM)
- trace_spec.ops [*last].op = MONO_TRACEOP_PROGRAM;
- else if (token == TOKEN_WRAPPER)
- trace_spec.ops [*last].op = MONO_TRACEOP_WRAPPER;
- else if (token == TOKEN_NAMESPACE){
- trace_spec.ops [*last].op = MONO_TRACEOP_NAMESPACE;
- trace_spec.ops [*last].data = g_strdup (value);
- } else if (token == TOKEN_CLASS || token == TOKEN_EXCEPTION){
- char *p = strrchr (value, '.');
- if (p) {
- *p++ = 0;
- trace_spec.ops [*last].data = g_strdup (value);
- trace_spec.ops [*last].data2 = g_strdup (p);
- }
- else {
- trace_spec.ops [*last].data = g_strdup ("");
- trace_spec.ops [*last].data2 = g_strdup (value);
- }
- trace_spec.ops [*last].op = token == TOKEN_CLASS ? MONO_TRACEOP_CLASS : MONO_TRACEOP_EXCEPTION;
- } else if (token == TOKEN_STRING){
- trace_spec.ops [*last].op = MONO_TRACEOP_ASSEMBLY;
- trace_spec.ops [*last].data = g_strdup (value);
- } else if (token == TOKEN_DISABLED) {
- trace_spec.enabled = FALSE;
- } else {
- fprintf (stderr, "Syntax error in trace option specification\n");
- return TOKEN_ERROR;