1*ef5ccd6cSJohn Marino /* Parse a printf-style format string. 2*ef5ccd6cSJohn Marino 3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc. 4*ef5ccd6cSJohn Marino 5*ef5ccd6cSJohn Marino This file is part of GDB. 6*ef5ccd6cSJohn Marino 7*ef5ccd6cSJohn Marino This program is free software; you can redistribute it and/or modify 8*ef5ccd6cSJohn Marino it under the terms of the GNU General Public License as published by 9*ef5ccd6cSJohn Marino the Free Software Foundation; either version 3 of the License, or 10*ef5ccd6cSJohn Marino (at your option) any later version. 11*ef5ccd6cSJohn Marino 12*ef5ccd6cSJohn Marino This program is distributed in the hope that it will be useful, 13*ef5ccd6cSJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 14*ef5ccd6cSJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*ef5ccd6cSJohn Marino GNU General Public License for more details. 16*ef5ccd6cSJohn Marino 17*ef5ccd6cSJohn Marino You should have received a copy of the GNU General Public License 18*ef5ccd6cSJohn Marino along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19*ef5ccd6cSJohn Marino 20*ef5ccd6cSJohn Marino #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG) 21*ef5ccd6cSJohn Marino # define USE_PRINTF_I64 1 22*ef5ccd6cSJohn Marino # define PRINTF_HAS_LONG_LONG 23*ef5ccd6cSJohn Marino #else 24*ef5ccd6cSJohn Marino # define USE_PRINTF_I64 0 25*ef5ccd6cSJohn Marino #endif 26*ef5ccd6cSJohn Marino 27*ef5ccd6cSJohn Marino /* The argclass represents the general type of data that goes with a 28*ef5ccd6cSJohn Marino format directive; int_arg for %d, long_arg for %l, and so forth. 29*ef5ccd6cSJohn Marino Note that these primarily distinguish types by size and need for 30*ef5ccd6cSJohn Marino special handling, so for instance %u and %x are (at present) also 31*ef5ccd6cSJohn Marino classed as int_arg. */ 32*ef5ccd6cSJohn Marino 33*ef5ccd6cSJohn Marino enum argclass 34*ef5ccd6cSJohn Marino { 35*ef5ccd6cSJohn Marino literal_piece, 36*ef5ccd6cSJohn Marino int_arg, long_arg, long_long_arg, ptr_arg, 37*ef5ccd6cSJohn Marino string_arg, wide_string_arg, wide_char_arg, 38*ef5ccd6cSJohn Marino double_arg, long_double_arg, decfloat_arg 39*ef5ccd6cSJohn Marino }; 40*ef5ccd6cSJohn Marino 41*ef5ccd6cSJohn Marino /* A format piece is a section of the format string that may include a 42*ef5ccd6cSJohn Marino single print directive somewhere in it, and the associated class 43*ef5ccd6cSJohn Marino for the argument. */ 44*ef5ccd6cSJohn Marino 45*ef5ccd6cSJohn Marino struct format_piece 46*ef5ccd6cSJohn Marino { 47*ef5ccd6cSJohn Marino char *string; 48*ef5ccd6cSJohn Marino enum argclass argclass; 49*ef5ccd6cSJohn Marino }; 50*ef5ccd6cSJohn Marino 51*ef5ccd6cSJohn Marino /* Return an array of printf fragments found at the given string, and 52*ef5ccd6cSJohn Marino rewrite ARG with a pointer to the end of the format string. */ 53*ef5ccd6cSJohn Marino 54*ef5ccd6cSJohn Marino extern struct format_piece *parse_format_string (const char **arg); 55*ef5ccd6cSJohn Marino 56*ef5ccd6cSJohn Marino /* Given a pointer to an array of format pieces, free any memory that 57*ef5ccd6cSJohn Marino would have been allocated by parse_format_string. */ 58*ef5ccd6cSJohn Marino 59*ef5ccd6cSJohn Marino extern void free_format_pieces (struct format_piece *frags); 60*ef5ccd6cSJohn Marino 61*ef5ccd6cSJohn Marino /* Freeing, cast as a cleanup. */ 62*ef5ccd6cSJohn Marino 63*ef5ccd6cSJohn Marino extern void free_format_pieces_cleanup (void *); 64