⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swfedit_token.c

📁 Swfdec still is development software, but has also followed a rigid no-crashes-allowed policy. I b
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Swfedit * Copyright (C) 2007 Benjamin Otte <otte@gnome.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, to_string to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor,  * Boston, MA  02110-1301  USA */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <stdlib.h>#include <string.h>#include <gtk/gtk.h>#include <libswfdec/swfdec_buffer.h>#include <libswfdec/swfdec_color.h>#include <libswfdec/swfdec_script.h>#include "swfedit_token.h"/*** CONVERTERS ***/static gbooleanswfedit_parse_hex (const char *s, guint *result){  guint byte;  if (s[0] >= '0' && s[0] <= '9')    byte = s[0] - '0';  else if (s[0] >= 'a' && s[0] <= 'f')    byte = s[0] + 10 - 'a';  else if (s[0] >= 'A' && s[0] <= 'F')    byte = s[0] + 10 - 'A';  else    return FALSE;  s++;  byte *= 16;  if (s[0] >= '0' && s[0] <= '9')    byte += s[0] - '0';  else if (s[0] >= 'a' && s[0] <= 'f')    byte += s[0] + 10 - 'a';  else if (s[0] >= 'A' && s[0] <= 'F')    byte += s[0] + 10 - 'A';  else    return FALSE;  *result = byte;  return TRUE;}static gpointerswfedit_binary_new (void){  return swfdec_buffer_new ();}static gbooleanswfedit_binary_from_string (const char *s, gpointer* result){  GByteArray *array = g_byte_array_new ();  guint byte;  guint8 add;  while (g_ascii_isspace (*s)) s++;  do {    if (!swfedit_parse_hex (s, &byte))      break;    s += 2;    add = byte;    g_byte_array_append (array, &add, 1);    while (g_ascii_isspace (*s)) s++;  } while (*s != '\0');  if (*s == '\0') {    SwfdecBuffer *buffer = swfdec_buffer_new ();    buffer->length = array->len;    buffer->data = array->data;    g_byte_array_free (array, FALSE);    *result = buffer;    return TRUE;  }  g_byte_array_free (array, TRUE);  return FALSE;}static char *swfedit_binary_to_string (gconstpointer value){  guint i;  const SwfdecBuffer *buffer = value;  GString *string = g_string_new ("");  for (i = 0; i < buffer->length; i++) {    if (i && i % 4 == 0)      g_string_append_c (string, ' ');    g_string_append_printf (string, "%02X", buffer->data[i]);  }  return g_string_free (string, FALSE);}static gbooleanswfedit_bit_from_string (const char *s, gpointer* result){  if (s[0] == '1' && s[1] == '\0')    *result = GUINT_TO_POINTER (1);  else if (s[0] == '0' && s[1] == '\0')    *result = GUINT_TO_POINTER (0);  else    return FALSE;  return TRUE;}static char *swfedit_bit_to_string (gconstpointer value){  return g_strdup (value ? "1" : "0");}static gbooleanswfedit_from_string_unsigned (const char *s, gulong max, gpointer* result){  char *end;  gulong u;  g_assert (max <= G_MAXUINT);  u = strtoul (s, &end, 10);  if (*end != '\0')    return FALSE;  if (u > max)    return FALSE;  *result = GUINT_TO_POINTER (u);  return TRUE;}static gbooleanswfedit_uint8_from_string (const char *s, gpointer* result){  return swfedit_from_string_unsigned (s, G_MAXUINT8, result);}static gbooleanswfedit_uint16_from_string (const char *s, gpointer* result){  return swfedit_from_string_unsigned (s, G_MAXUINT16, result);}static gbooleanswfedit_uint32_from_string (const char *s, gpointer* result){  return swfedit_from_string_unsigned (s, G_MAXUINT32, result);}static char *swfedit_to_string_unsigned (gconstpointer value){  return g_strdup_printf ("%u", GPOINTER_TO_UINT (value));}static char *swfedit_string_to_string (gconstpointer value){  return g_strdup (value);}static gbooleanswfedit_string_from_string (const char *s, gpointer* result){  *result = g_strdup (s);  return TRUE;}static gpointerswfedit_rect_new (void){  return g_new0 (SwfdecRect, 1);}static gbooleanswfedit_rect_from_string (const char *s, gpointer* result){  return FALSE;}static char *swfedit_rect_to_string (gconstpointer value){  const SwfdecRect *rect = value;  return g_strdup_printf ("%d, %d, %d, %d", (int) rect->x0, (int) rect->y0,      (int) rect->x1, (int) rect->y1);}static gbooleanswfedit_rgb_from_string (const char *s, gpointer* result){  guint r, g, b;  if (strlen (s) != 6)    return FALSE;  if (!swfedit_parse_hex (s, &r))    return FALSE;  s += 2;  if (!swfedit_parse_hex (s, &g))    return FALSE;  s += 2;  if (!swfedit_parse_hex (s, &b))    return FALSE;  *result = GUINT_TO_POINTER (SWFDEC_COLOR_COMBINE (r, g, b, 0xFF));  return TRUE;}static char *swfedit_rgb_to_string (gconstpointer value){  guint c = GPOINTER_TO_UINT (value);  return g_strdup_printf ("%02X%02X%02X", SWFDEC_COLOR_R (c),      SWFDEC_COLOR_G (c), SWFDEC_COLOR_B (c));}static gbooleanswfedit_rgba_from_string (const char *s, gpointer* result){  guint r, g, b, a;  if (strlen (s) != 8)    return FALSE;  if (!swfedit_parse_hex (s, &a))    return FALSE;  s += 2;  if (!swfedit_parse_hex (s, &r))    return FALSE;  s += 2;  if (!swfedit_parse_hex (s, &g))    return FALSE;  s += 2;  if (!swfedit_parse_hex (s, &b))    return FALSE;  *result = GUINT_TO_POINTER (SWFDEC_COLOR_COMBINE (r, g, b, a));  return TRUE;}static char *swfedit_rgba_to_string (gconstpointer value){  guint c = GPOINTER_TO_UINT (value);  return g_strdup_printf ("%02X%02X%02X%02X", SWFDEC_COLOR_R (c),      SWFDEC_COLOR_G (c), SWFDEC_COLOR_B (c), SWFDEC_COLOR_A (c));}static gpointerswfedit_matrix_new (void){  cairo_matrix_t *matrix = g_new (cairo_matrix_t, 1);  cairo_matrix_init_identity (matrix);  return matrix;}static gbooleanswfedit_matrix_from_string (const char *s, gpointer* result){  return FALSE;}static char *swfedit_matrix_to_string (gconstpointer value){  const cairo_matrix_t *mat = value;  return g_strdup_printf ("{%g %g,  %g %g} + {%g, %g}",       mat->xx, mat->xy, mat->yx, mat->yy, mat->x0, mat->y0);}static gpointerswfedit_ctrans_new (void){  SwfdecColorTransform *trans = g_new (SwfdecColorTransform, 1);  swfdec_color_transform_init_identity (trans);  return trans;}static gbooleanswfedit_ctrans_from_string (const char *s, gpointer* result){  return FALSE;}static char *swfedit_ctrans_to_string (gconstpointer value){  const SwfdecColorTransform *trans = value;  return g_strdup_printf ("{%d %d} {%d %d} {%d %d} {%d %d}",       trans->ra, trans->rb, trans->ga, trans->gb,       trans->ba, trans->bb, trans->aa, trans->ab);}static gpointerswfedit_script_new (void){  return NULL;}static gbooleanswfedit_script_from_string (const char *s, gpointer* result){  gpointer buffer;  SwfdecBits bits;  SwfdecScript *script;    if (!swfedit_binary_from_string (s, &buffer)) {    return FALSE;  }  swfdec_bits_init (&bits, buffer);  script = swfdec_script_new (&bits, "unknown", 6 /* FIXME */);  swfdec_buffer_unref (buffer);  if (script != NULL) {    *result = script;    return TRUE;  } else {    return FALSE;  }}static char *swfedit_script_to_string (gconstpointer value){  if (value == NULL)    return g_strdup ("");  else    return swfedit_binary_to_string (((SwfdecScript *) value)->buffer);}static voidswfedit_script_free (gpointer script){  if (script)    swfdec_script_unref (script);}struct {  gpointer	(* new)		(void);  gboolean	(* from_string)	(const char *s, gpointer *);  char *	(* to_string)	(gconstpointer value);  void	  	(* free)	(gpointer value);} converters[SWFEDIT_N_TOKENS] = {  { NULL, NULL, NULL, g_object_unref },  { swfedit_binary_new, swfedit_binary_from_string, swfedit_binary_to_string, (GDestroyNotify) swfdec_buffer_unref },  { NULL, swfedit_bit_from_string, swfedit_bit_to_string, NULL },  { NULL, swfedit_uint8_from_string, swfedit_to_string_unsigned, NULL },  { NULL, swfedit_uint16_from_string, swfedit_to_string_unsigned, NULL },  { NULL, swfedit_uint32_from_string, swfedit_to_string_unsigned, NULL },  { NULL, swfedit_string_from_string, swfedit_string_to_string, g_free },  { swfedit_rect_new, swfedit_rect_from_string, swfedit_rect_to_string, g_free },  { NULL, swfedit_rgb_from_string, swfedit_rgb_to_string, NULL },  { NULL, swfedit_rgba_from_string, swfedit_rgba_to_string, NULL },  { swfedit_matrix_new, swfedit_matrix_from_string, swfedit_matrix_to_string, g_free },  { swfedit_ctrans_new, swfedit_ctrans_from_string, swfedit_ctrans_to_string, g_free },  { swfedit_script_new, swfedit_script_from_string, swfedit_script_to_string, swfedit_script_free },  { NULL, swfedit_uint32_from_string, swfedit_to_string_unsigned, NULL },};gpointerswfedit_token_new_token (SwfeditTokenType type){  gpointer ret;  g_assert (type < G_N_ELEMENTS (converters));  if (!converters[type].new)    return NULL;  ret = converters[type].new ();  return ret;}/*** GTK_TREE_MODEL ***/#if 0#  define REPORT g_print ("%s\n", G_STRFUNC)#else#  define REPORT #endifstatic GtkTreeModelFlags swfedit_token_get_flags (GtkTreeModel *tree_model){  REPORT;  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -