gimp-gap r818 - trunk/libgapbase
- From: wolfgangh svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp-gap r818 - trunk/libgapbase
- Date: Sun, 8 Mar 2009 13:53:32 +0000 (UTC)
Author: wolfgangh
Date: Sun Mar 8 13:53:32 2009
New Revision: 818
URL: http://svn.gnome.org/viewvc/gimp-gap?rev=818&view=rev
Log:
fixes for ffmpeg based videoapi and video indexes, limit for open videofiles and refactoring
Added:
trunk/libgapbase/gap_base.c
trunk/libgapbase/gap_base.h
trunk/libgapbase/gap_file_util.c (contents, props changed)
trunk/libgapbase/gap_file_util.h
trunk/libgapbase/gap_libgapbase.h
Modified:
trunk/libgapbase/Makefile.am
Modified: trunk/libgapbase/Makefile.am
==============================================================================
--- trunk/libgapbase/Makefile.am (original)
+++ trunk/libgapbase/Makefile.am Sun Mar 8 13:53:32 2009
@@ -15,6 +15,11 @@
libgapbase_a_SOURCES = \
- gap_val_file.c \
+ gap_libgapbase.h \
+ gap_base.c \
+ gap_base.h \
+ gap_file_util.c \
+ gap_file_util.h \
+ gap_val_file.c \
gap_val_file.h
Added: trunk/libgapbase/gap_base.c
==============================================================================
--- (empty file)
+++ trunk/libgapbase/gap_base.c Sun Mar 8 13:53:32 2009
@@ -0,0 +1,520 @@
+/* gap_base.c
+ * 1997.11.01 hof (Wolfgang Hofer)
+ *
+ * GAP ... Gimp Animation Plugins
+ *
+ * basic GAP types and utility procedures
+ *
+ */
+/* The GIMP -- an image manipulation program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* revision history:
+ * 2.5.0 2009.03.07 hof: created
+ */
+
+#include "config.h"
+
+/* SYSTEM (UNIX) includes */
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <signal.h> /* for kill */
+#ifdef HAVE_SYS_TIMES_H
+#include <sys/times.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <glib/gstdio.h>
+
+/* GIMP includes */
+#include "gtk/gtk.h"
+#include "libgimp/gimp.h"
+
+#ifdef G_OS_WIN32
+#include <io.h>
+# ifndef S_ISDIR
+# define S_ISDIR(m) ((m) & _S_IFDIR)
+# endif
+# ifndef S_ISREG
+# define S_ISREG(m) ((m) & _S_IFREG)
+# endif
+#endif
+
+
+#ifdef G_OS_WIN32
+#include <process.h> /* For _getpid() */
+#endif
+
+/* GAP includes */
+#include "gap_base.h"
+
+extern int gap_debug; /* ==0 ... dont print debug infos */
+
+
+/* -----------------------------
+ * gap_base_shorten_filename
+ * -----------------------------
+ * resulting string is built from prefix filename and suffix
+ * filename will be shortened when
+ * prefix + " " + filename + " " + suffix
+ * is longer then max_chars.
+ * examples:
+ * gap_base_shorten_filenam("prefix", "this_is_a_very_long_filename", NULL, 20)
+ * returns: "prefix ...g_filename"
+ *
+ * gap_base_shorten_filenam("prefix", "shortname", NULL, 20)
+ * returns: "prefix shortname"
+ *
+ * the caller is responsible to g_free the returned string
+ */
+char *
+gap_base_shorten_filename(const char *prefix
+ ,const char *filename
+ ,const char *suffix
+ ,gint32 max_chars
+ )
+{
+ gint len_prefix;
+ gint len_fname;
+ const char *pfx;
+ char *fnam;
+ char *ret_string;
+
+ len_prefix = 0;
+ len_fname = 0;
+ ret_string = NULL;
+ pfx = prefix;
+ if(prefix)
+ {
+ len_prefix = strlen(prefix);
+ if((len_prefix + 10) > max_chars)
+ {
+ pfx = NULL;
+ len_prefix = 0;
+ }
+ else
+ {
+ len_prefix++; /* for the space between prefix and fname */
+ }
+ }
+
+
+ if(filename)
+ {
+ fnam = NULL;
+
+ if(suffix)
+ {
+ fnam = g_strdup_printf("%s %s", filename, suffix);
+ }
+ else
+ {
+ fnam = g_strdup(filename);
+ }
+
+
+ len_fname = strlen(fnam);
+ if((len_fname + len_prefix) <= max_chars)
+ {
+ if(pfx)
+ {
+ ret_string = g_strdup_printf("%s %s"
+ ,pfx
+ ,fnam
+ );
+ }
+ else
+ {
+ ret_string = g_strdup_printf("%s"
+ ,fnam
+ );
+ }
+ }
+ else
+ {
+ gint fname_idx;
+ gint len_rest;
+
+ len_rest = (max_chars - len_prefix - 3);
+ fname_idx = len_fname - len_rest;
+
+ if(pfx)
+ {
+ ret_string = g_strdup_printf("%s ...%s"
+ ,pfx
+ ,&fnam[fname_idx]
+ );
+ }
+ else
+ {
+ ret_string = g_strdup_printf("...%s"
+ ,&fnam[fname_idx]
+ );
+ }
+ }
+
+ g_free(fnam);
+ return (ret_string);
+
+ }
+
+ ret_string = g_strdup(prefix);
+ return(ret_string);
+} /* end gap_base_shorten_filename */
+
+
+/* -----------------------------
+ * gap_base_strdup_add_underscore
+ * -----------------------------
+ * duplicates the specifed string and if last character is no underscore add one at end.
+ * the caller is responsible to g_free the result after usage.
+ */
+char *
+gap_base_strdup_add_underscore(char *name)
+{
+ int l_len;
+ char *l_str;
+ if(name == NULL)
+ {
+ return(g_strdup("\0"));
+ }
+
+ l_len = strlen(name);
+ l_str = g_malloc(l_len+2);
+ strcpy(l_str, name);
+ if(l_len > 0)
+ {
+ if (name[l_len-1] != '_')
+ {
+ l_str[l_len ] = '_';
+ l_str[l_len +1 ] = '\0';
+ }
+
+ }
+ return(l_str);
+}
+
+/* -----------------------------
+ * gap_base_strdup_del_underscore
+ * -----------------------------
+ * duplicates the specifed string and delete the last character
+ * if it is the underscore
+ * the caller is responsible to g_free the result after usage.
+ */
+char *
+gap_base_strdup_del_underscore(char *name)
+{
+ int l_len;
+ char *l_str;
+ if(name == NULL)
+ {
+ return(g_strdup("\0"));
+ }
+
+ l_len = strlen(name);
+ l_str = g_strdup(name);
+ if(l_len > 0)
+ {
+ if (l_str[l_len-1] == '_')
+ {
+ l_str[l_len -1 ] = '\0';
+ }
+
+ }
+ return(l_str);
+}
+
+
+/* --------------------------------------------------------
+ * gap_base_dup_filename_and_replace_extension_by_underscore
+ * --------------------------------------------------------
+ * returns a duplicate of the specified filename where the extension
+ * (.xcf .jpg ...) is cut off and rplaced by the underscore character.
+ * example: filename = "image_000001.xcf"
+ * returns "image_000001_"
+ *
+ * the caller is responsible to g_free the result after usage.
+ */
+char *
+gap_base_dup_filename_and_replace_extension_by_underscore(const char *filename)
+{
+ int l_len;
+ int l_idx;
+ char *l_str;
+ char *l_nameWithUnderscore;
+
+ if(filename == NULL)
+ {
+ return (g_strdup("_"));
+ }
+
+ l_len = strlen(filename);
+ l_str = g_strdup(filename);
+
+ /* cut off the trailing .extension */
+ for(l_idx = l_len -1; l_idx >= 0; l_idx--)
+ {
+ if (l_str[l_idx] == '.')
+ {
+ l_str[l_idx] = '\0';
+ break;
+ }
+ }
+
+ /* add underscore (if not already there) */
+ l_nameWithUnderscore = gap_base_strdup_add_underscore(l_str);
+
+ g_free(l_str);
+
+ return (l_nameWithUnderscore);
+
+} /* end gap_base_dup_filename_and_replace_extension_by_underscore */
+
+
+/* --------------------------------
+ * gap_base_fprintf_gdouble
+ * --------------------------------
+ * print prefix and gdouble value to file
+ * (always use "." as decimalpoint, independent of LOCALE language settings)
+ */
+void
+gap_base_fprintf_gdouble(FILE *fp, gdouble value, gint digits, gint precision_digits, const char *pfx)
+{
+ gchar l_dbl_str[G_ASCII_DTOSTR_BUF_SIZE];
+ gchar l_fmt_str[20];
+ gint l_len;
+
+ g_snprintf(l_fmt_str, sizeof(l_fmt_str), "%%.%df", (int)precision_digits);
+ g_ascii_formatd(l_dbl_str, sizeof(l_dbl_str), l_fmt_str, value);
+
+ fprintf(fp, "%s", pfx);
+
+ /* make leading blanks */
+ l_len = strlen(l_dbl_str) - (digits + 1 + precision_digits);
+ while(l_len < 0)
+ {
+ fprintf(fp, " ");
+ l_len++;
+ }
+ fprintf(fp, "%s", l_dbl_str);
+} /* end gap_base_fprintf_gdouble */
+
+
+/* ============================================================================
+ * gap_base_sscan_flt_numbers
+ * ============================================================================
+ * scan the blank separated buffer for 2 integer and 13 float numbers.
+ * always use "." as decimalpoint in the float numbers regardless to LANGUAGE settings
+ * return a counter that tells how many numbers were scanned successfully
+ */
+gint
+gap_base_sscan_flt_numbers(gchar *buf
+ , gdouble *farr
+ , gint farr_max
+ )
+{
+ gint l_cnt;
+ gchar *nptr;
+ gchar *endptr;
+
+ l_cnt =0;
+ nptr = buf;
+ while(l_cnt < farr_max)
+ {
+ endptr = nptr;
+ farr[l_cnt] = g_ascii_strtod(nptr, &endptr);
+ if(nptr == endptr)
+ {
+ break; /* pointer was not advanced because no valid floatnumber was scanned */
+ }
+ nptr = endptr;
+
+ l_cnt++; /* count successful scans */
+ }
+
+ return (l_cnt);
+} /* end gap_base_sscan_flt_numbers */
+
+
+/* --------------------------------
+ * gap_base_check_tooltips
+ * --------------------------------
+ * check and enable/disable tooltips according to global gimprc settings
+ */
+gboolean
+gap_base_check_tooltips(gboolean *old_state)
+{
+ char *value_string;
+ gboolean new_state;
+ gboolean changed;
+
+ new_state = TRUE;
+ changed = TRUE;
+
+ value_string = gimp_gimprc_query("show-tooltips");
+ if(value_string != NULL)
+ {
+ if (strcmp(value_string, "no") == 0)
+ {
+ new_state = FALSE;
+ }
+ }
+
+ if (old_state != NULL)
+ {
+ if(*old_state == new_state)
+ {
+ changed = FALSE;
+ }
+ }
+
+ if (changed == TRUE)
+ {
+ if(new_state == TRUE)
+ {
+ gimp_help_enable_tooltips ();
+ }
+ else
+ {
+ gimp_help_disable_tooltips ();
+ }
+ }
+
+ return (new_state);
+
+} /* end gap_base_check_tooltips */
+
+
+/* -----------------------------------------
+ * gap_base_get_gimprc_int_value
+ * -----------------------------------------
+ * get integer configuration value for the keyname gimprc_option_name from the gimprc file.
+ * returns the configure value in constaint to the specified range
+ * (between min_value and max_value)
+ * the specified default_value is returned in case the gimprc
+ * has no entry for the specified gimprc_option_name.
+ */
+gint32
+gap_base_get_gimprc_int_value (const char *gimprc_option_name
+ , gint32 default_value, gint32 min_value, gint32 max_value)
+{
+ char *value_string;
+ gint32 value;
+
+ value = default_value;
+
+ value_string = gimp_gimprc_query(gimprc_option_name);
+ if(value_string)
+ {
+ value = atol(value_string);
+ g_free(value_string);
+ }
+ return (CLAMP(value, min_value, max_value));
+
+} /* end p_get_gimprc_int_value */
+
+
+/* -----------------------------------------
+ * gap_base_get_gimprc_gboolean_value
+ * -----------------------------------------
+ */
+gboolean
+gap_base_get_gimprc_gboolean_value (const char *gimprc_option_name
+ , gboolean default_value)
+{
+ char *value_string;
+ gboolean value;
+
+ value = default_value;
+
+ value_string = gimp_gimprc_query(gimprc_option_name);
+ if(value_string)
+ {
+ value = FALSE;
+ if((*value_string == 'y') || (*value_string == 'Y'))
+ {
+ value = FALSE;
+ }
+ g_free(value_string);
+ }
+ return (value);
+
+} /* end gap_base_get_gimprc_gboolean_value */
+
+/* --------------------------------
+ * gap_base_getpid
+ * --------------------------------
+ * get process id of the current process
+ */
+gint32
+gap_base_getpid(void)
+{
+ return ((gint32)getpid());
+}
+
+/* --------------------------------
+ * gap_base_is_pid_alive
+ * --------------------------------
+ * return TRUE if the process with the specified pid
+ * is alive.
+ * WARNING:
+ * there is no implementation for the WINDOWS operating system
+ * where the return value is always TRUE.
+ */
+gboolean
+gap_base_is_pid_alive(gint32 pid)
+{
+#ifndef G_OS_WIN32
+ /* for UNIX */
+
+ /* kill with signal 0 checks only if the process is alive (no signal is sent)
+ * returns 0 if alive, 1 if no process with given pid found.
+ */
+ if (0 == kill(pid, 0))
+ {
+ return(TRUE);
+ }
+ return (FALSE);
+#else
+ /* hof: dont know how to check on Windows
+ * assume that process is always alive
+ * (therefore on Windows locks will not be cleared
+ * automatically after crashes of the locking process)
+ */
+ return(TRUE);
+#endif
+}
+
+
+/* --------------------------------
+ * gap_base_get_current_time
+ * --------------------------------
+ * get curent system time in utc timecode
+ */
+gint32
+gap_base_get_current_time(void)
+{
+ return ((gint32)time(0));
+}
+
Added: trunk/libgapbase/gap_base.h
==============================================================================
--- (empty file)
+++ trunk/libgapbase/gap_base.h Sun Mar 8 13:53:32 2009
@@ -0,0 +1,181 @@
+/* gap_base.h
+ * 1997.11.01 hof (Wolfgang Hofer)
+ *
+ * GAP ... Gimp Animation Plugins
+ *
+ * basic GAP types and utility procedures
+ *
+ */
+/* The GIMP -- an image manipulation program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* revision history:
+ * 2.5.0 2009.03.07 hof: created
+ */
+
+#ifndef _GAP_BASE_H
+#define _GAP_BASE_H
+
+#include "libgimp/gimp.h"
+
+/* -----------------------------
+ * gap_base_shorten_filename
+ * -----------------------------
+ * resulting string is built from prefix filename and suffix
+ * filename will be shortened when
+ * prefix + " " + filename + " " + suffix
+ * is longer then max_chars.
+ * examples:
+ * gap_base_shorten_filenam("prefix", "this_is_a_very_long_filename", NULL, 20)
+ * returns: "prefix ...g_filename"
+ *
+ * gap_base_shorten_filenam("prefix", "shortname", NULL, 20)
+ * returns: "prefix shortname"
+ *
+ * the caller is responsible to g_free the returned string
+ */
+char *
+gap_base_shorten_filename(const char *prefix
+ ,const char *filename
+ ,const char *suffix
+ ,gint32 max_chars
+ );
+
+
+/* -----------------------------
+ * gap_base_strdup_add_underscore
+ * -----------------------------
+ * duplicates the specifed string and if last character is no underscore add one at end.
+ * the caller is responsible to g_free the result after usage.
+ */
+char *
+gap_base_strdup_add_underscore(char *name);
+
+
+/* -----------------------------
+ * gap_base_strdup_del_underscore
+ * -----------------------------
+ * duplicates the specifed string and delete the last character
+ * if it is the underscore
+ * the caller is responsible to g_free the result after usage.
+ */
+char *
+gap_base_strdup_del_underscore(char *name);
+
+
+
+/* --------------------------------------------------------
+ * gap_base_dup_filename_and_replace_extension_by_underscore
+ * --------------------------------------------------------
+ * returns a duplicate of the specified filename where the extension
+ * (.xcf .jpg ...) is cut off and rplaced by the underscore character.
+ * example: filename = "image_000001.xcf"
+ * returns "image_000001_"
+ *
+ * the caller is responsible to g_free the result after usage.
+ */
+char *
+gap_base_dup_filename_and_replace_extension_by_underscore(const char *filename);
+
+
+/* --------------------------------
+ * gap_base_fprintf_gdouble
+ * --------------------------------
+ * print prefix and gdouble value to file
+ * (always use "." as decimalpoint, independent of LOCALE language settings)
+ */
+void
+gap_base_fprintf_gdouble(FILE *fp, gdouble value, gint digits, gint precision_digits, const char *pfx);
+
+
+/* --------------------------------
+ * gap_base_sscan_flt_numbers
+ * --------------------------------
+ * scan the blank separated buffer for 2 integer and 13 float numbers.
+ * always use "." as decimalpoint in the float numbers regardless to LANGUAGE settings
+ * return a counter that tells how many numbers were scanned successfully
+ */
+gint
+gap_base_sscan_flt_numbers(gchar *buf
+ , gdouble *farr
+ , gint farr_max
+ );
+
+
+/* --------------------------------
+ * gap_base_check_tooltips
+ * --------------------------------
+ * check and enable/disable tooltips according to global gimprc settings
+ */
+gboolean
+gap_base_check_tooltips(gboolean *old_state);
+
+
+/* -----------------------------------------
+ * gap_base_get_gimprc_int_value
+ * -----------------------------------------
+ * get integer configuration value for the keyname gimprc_option_name from the gimprc file.
+ * returns the configure value in constaint to the specified range
+ * (between min_value and max_value)
+ * the specified default_value is returned in case the gimprc
+ * has no entry for the specified gimprc_option_name.
+ */
+gint32
+gap_base_get_gimprc_int_value (const char *gimprc_option_name
+ , gint32 default_value, gint32 min_value, gint32 max_value);
+
+/* -----------------------------------------
+ * gap_base_get_gimprc_gboolean_value
+ * -----------------------------------------
+ */
+gboolean
+gap_base_get_gimprc_gboolean_value (const char *gimprc_option_name
+ , gboolean default_value);
+
+
+/* --------------------------------
+ * gap_base_getpid
+ * --------------------------------
+ * get process id of the current process
+ */
+gint32
+gap_base_getpid(void);
+
+/* --------------------------------
+ * gap_base_is_pid_alive
+ * --------------------------------
+ * return TRUE if the process with the specified pid
+ * is alive.
+ * WARNING:
+ * there is no implementation for the WINDOWS operating system
+ * where the return value is always TRUE.
+ */
+gboolean
+gap_base_is_pid_alive(gint32 pid);
+
+
+/* --------------------------------
+ * gap_base_get_current_time
+ * --------------------------------
+ * get curent system time in utc timecode
+ */
+gint32
+gap_base_get_current_time(void);
+
+
+#endif
Added: trunk/libgapbase/gap_file_util.c
==============================================================================
--- (empty file)
+++ trunk/libgapbase/gap_file_util.c Sun Mar 8 13:53:32 2009
@@ -0,0 +1,343 @@
+/* gap_file_util.c
+ *
+ * GAP video encoder tool procedures
+ * - filehandling
+ * - GAP filename (framename) handling
+ *
+ */
+/* The GIMP -- an image manipulation program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* revision history:
+ * version 1.2.1a; 2004.05.14 hof: created
+ */
+
+/* SYTEM (UNIX) includes */
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include <glib/gstdio.h>
+
+/* GIMP includes */
+#include "gtk/gtk.h"
+#include "libgimp/gimp.h"
+
+
+#include "gap_file_util.h"
+
+extern int gap_debug; /* ==0 ... dont print debug infos */
+
+/*************************************************************
+ * TOOL FUNCTIONS *
+ *************************************************************/
+
+
+/* --------------------
+ * gap_file_get_filesize
+ * --------------------
+ * get the filesize of a file.
+ * in: fname: The filename of the file to check.
+ * returns: The filesize.
+ */
+gint32
+gap_file_get_filesize(const char *fname)
+{
+ struct stat stat_buf;
+
+ if (0 != g_stat(fname, &stat_buf))
+ {
+ printf ("stat error on '%s'\n", fname);
+ return(0);
+ }
+
+ return((gint32)(stat_buf.st_size));
+}
+
+
+/* -----------------------
+ * gap_file_load_file_segment
+ * -----------------------
+ * load one segment of (audio)data from a file.
+ * into the buffer segment_data_ptr (must be allocated by the calling program)
+ *
+ * return number of bytes read from file
+ */
+gint32
+gap_file_load_file_segment(const char *filename
+ ,guchar *segment_data_ptr /* IN: pointer to memory at least segent_size large, OUT: filled with segment data */
+ ,gint32 seek_index /* start byte of datasegment in file */
+ ,gint32 segment_size /* segment size in byets (must be a multiple of 4) */
+ )
+{
+ FILE *fp;
+ gint32 l_bytes_read;
+
+
+ l_bytes_read = 0;
+
+ fp = g_fopen(filename, "rb");
+ if (fp)
+ {
+
+ fseek(fp, seek_index, SEEK_SET);
+
+ /* read full segement size (or smaller rest until EOF) */
+ l_bytes_read = fread(segment_data_ptr, 1, (size_t)segment_size, fp);
+
+ fclose(fp);
+ }
+
+ if(gap_debug) printf("gap_file_load_file_segment: %s seek_idx:%d bytes_read:%d\n", filename, (int)seek_index, (int)l_bytes_read);
+
+ return(l_bytes_read);
+
+} /* end gap_file_load_file_segment */
+
+
+/* -------------------------
+ * gap_file_load_file_len
+ * -------------------------
+ * Load a file into a memory buffer
+ * in: fname: The name of the file to load
+ * returns: A pointer to the allocated buffer with the file content.
+ */
+char *
+gap_file_load_file_len(const char *fname, gint32 *filelen)
+{
+ FILE *fp;
+ char *l_buff_ptr;
+ long len;
+
+ *filelen = 0;
+
+ /* File Laenge ermitteln */
+ len = gap_file_get_filesize(fname);
+ if (len < 1)
+ {
+ return(NULL);
+ }
+
+ /* Buffer allocate */
+ l_buff_ptr=(char *)g_malloc(len+1);
+ if(l_buff_ptr == NULL)
+ {
+ printf ("calloc error (%d Bytes not available)\n", (int)len);
+ return(NULL);
+ }
+ l_buff_ptr[len] = '\0';
+
+ /* File in eine Buffer laden */
+ fp = g_fopen(fname, "rb"); /* open read */
+ if(fp == NULL)
+ {
+ printf ("open(read) error on '%s'\n", fname);
+ return(NULL);
+ }
+ fread(l_buff_ptr, 1, (size_t)len, fp); /* read */
+ fclose(fp); /* close */
+
+ *filelen = len;
+ return(l_buff_ptr);
+} /* end gap_file_load_file_len */
+
+/* -------------------------
+ * gap_file_load_file
+ * -------------------------
+ */
+char *
+gap_file_load_file(const char *fname)
+{
+ gint32 l_filelen;
+
+ return(gap_file_load_file_len(fname, &l_filelen));
+} /* end gap_file_load_file */
+
+/* -------------------------
+ * gap_file_chmod
+ * -------------------------
+ */
+int
+gap_file_chmod (const char *fname, int mode)
+{
+ return(g_chmod(fname, mode));
+}
+
+/* -------------------------
+ * gap_file_mkdir
+ * -------------------------
+ */
+int
+gap_file_mkdir (const char *fname, int mode)
+{
+ return(g_mkdir(fname, mode));
+}
+
+
+
+/* ----------------------------------------------------
+ * gap_file_chop_trailingspace_and_nl
+ * ----------------------------------------------------
+ * requires a '\0' terminated input buffer
+ * chop trailing white space and newline chars
+ * (by replacing those chars with \0 directly in the
+ * specified buffer)
+ */
+void
+gap_file_chop_trailingspace_and_nl(char *buffer)
+{
+ int len;
+ len = strlen(buffer);
+ while(len > 0)
+ {
+ len--;
+ if((buffer[len] == '\n')
+ || (buffer[len] == '\r')
+ || (buffer[len] == '\t')
+ || (buffer[len] == ' '))
+ {
+ buffer[len] = '\0';
+ }
+ else
+ {
+ break;
+ }
+ }
+} /* end gap_file_chop_trailingspace_and_nl */
+
+
+/* ----------------------------------------------------
+ * gap_file_make_abspath_filename
+ * ----------------------------------------------------
+ * check if filename is specified with absolute path,
+ * if true: return 1:1 copy of filename
+ * if false: prefix filename with path from container file.
+ */
+char *
+gap_file_make_abspath_filename(const char *filename, const char *container_file)
+{
+ gboolean l_path_is_relative;
+ char *l_container_path;
+ char *l_ptr;
+ char *l_abs_name;
+
+ l_abs_name = NULL;
+ l_path_is_relative = TRUE;
+ if(filename[0] == G_DIR_SEPARATOR)
+ {
+ l_path_is_relative = FALSE;
+ }
+#ifdef G_OS_WIN32
+ {
+ gint l_idx;
+
+ /* check for WIN/DOS styled abs pathname "Drive:\dir\file" */
+ for(l_idx=0; filename[l_idx] != '\0'; l_idx++)
+ {
+ if(filename[l_idx] == DIR_ROOT)
+ {
+ l_path_is_relative = FALSE;
+ break;
+ }
+ }
+ }
+#endif
+
+ if((l_path_is_relative) && (container_file != NULL))
+ {
+ l_container_path = g_strdup(container_file);
+ l_ptr = &l_container_path[strlen(l_container_path)];
+ while(l_ptr != l_container_path)
+ {
+ if((*l_ptr == G_DIR_SEPARATOR) || (*l_ptr == DIR_ROOT))
+ {
+ l_ptr++;
+ *l_ptr = '\0'; /* terminate the string after the directorypath */
+ break;
+ }
+ l_ptr--;
+ }
+ if(l_ptr != l_container_path)
+ {
+ /* prefix the filename with the container_path */
+ l_abs_name = g_strdup_printf("%s%s", l_container_path, filename);
+ }
+ else
+ {
+ /* container_file has no path at all (and must be in the current dir)
+ * (therefore we cant expand absolute path name)
+ */
+ l_abs_name = g_strdup(filename);
+ }
+ g_free(l_container_path);
+ }
+ else
+ {
+ /* use absolute filename as it is */
+ l_abs_name = g_strdup(filename);
+ }
+
+ return(l_abs_name);
+
+} /* end gap_file_make_abspath_filename */
+
+
+/* --------------------------------
+ * gap_file_build_absolute_filename
+ * --------------------------------
+ */
+char *
+gap_file_build_absolute_filename(const char * filename)
+{
+ gchar *absolute;
+ if (! g_path_is_absolute (filename))
+ {
+ gchar *current;
+
+ current = g_get_current_dir ();
+ absolute = g_build_filename (current, filename, NULL);
+ g_free (current);
+ }
+ else
+ {
+ absolute = g_strdup (filename);
+ }
+ return (absolute);
+} /* end gap_file_build_absolute_filename */
+
+/* --------------------------------
+ * gap_file_get_mtime
+ * --------------------------------
+ */
+gint32
+gap_file_get_mtime(const char *filename)
+{
+ struct stat l_stat;
+
+ if(filename != NULL)
+ {
+ if (0 == g_stat(filename, &l_stat))
+ {
+ return(l_stat.st_mtime);
+ }
+ }
+ return(0);
+
+} /* end gap_file_get_mtime */
Added: trunk/libgapbase/gap_file_util.h
==============================================================================
--- (empty file)
+++ trunk/libgapbase/gap_file_util.h Sun Mar 8 13:53:32 2009
@@ -0,0 +1,88 @@
+/* gap_file_util.h
+ *
+ * GAP common encoder tool procedures
+ * with no dependencies to external libraries.
+ *
+ */
+/* The GIMP -- an image manipulation program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* revision history:
+ * version 1.2.1a; 2004.05.14 hof: created
+ */
+
+#ifndef GAP_FILE_UTIL_H
+#define GAP_FILE_UTIL_H
+
+#include "libgimp/gimp.h"
+
+/* G_DIR_SEPARATOR (is defined in glib.h if you have glib-1.2.0 or later) */
+#ifdef G_OS_WIN32
+
+/* Filenames in WIN/DOS Style */
+#ifndef G_DIR_SEPARATOR
+#define G_DIR_SEPARATOR '\\'
+#endif
+#define DIR_ROOT ':'
+
+#else /* !G_OS_WIN32 */
+
+/* Filenames in UNIX Style */
+#ifndef G_DIR_SEPARATOR
+#define G_DIR_SEPARATOR '/'
+#endif
+#define DIR_ROOT '/'
+
+#endif /* !G_OS_WIN32 */
+
+#ifdef G_OS_WIN32
+#include <direct.h> /* For _mkdir() */
+#define mkdir(path,mode) _mkdir(path)
+#endif
+
+
+#ifdef G_OS_WIN32
+#define GAP_FILE_MKDIR_MODE 0 /* not relevant for WIN mkdir */
+#else
+#define GAP_FILE_MKDIR_MODE (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH )
+#endif
+
+/* --------------------------*/
+/* PROCEDURE DECLARATIONS */
+/* --------------------------*/
+
+gint32 gap_file_get_filesize(const char *fname);
+char* gap_file_load_file(const char *fname);
+char* gap_file_load_file_len(const char *fname, gint32 *filelen);
+gint32 gap_file_load_file_segment(const char *filename
+ ,guchar *segment_data_ptr /* IN: pointer to memory at least segent_size large, OUT: filled with segment data */
+ ,gint32 seek_index /* start byte of datasegment in file */
+ ,gint32 segment_size /* segment size in byets (must be a multiple of 4) */
+ );
+
+int gap_file_chmod (const char *fname, int mode);
+int gap_file_mkdir (const char *fname, int mode);
+void gap_file_chop_trailingspace_and_nl(char *buff);
+char * gap_file_make_abspath_filename(const char *filename
+ , const char *container_file);
+
+char * gap_file_build_absolute_filename(const char * filename);
+gint32 gap_file_get_mtime(const char *filename);
+
+
+#endif /* GAP_FILE_UTIL_H */
Added: trunk/libgapbase/gap_libgapbase.h
==============================================================================
--- (empty file)
+++ trunk/libgapbase/gap_libgapbase.h Sun Mar 8 13:53:32 2009
@@ -0,0 +1,40 @@
+/* gap_libgapbase.h
+ * 2009.03.07 hof (Wolfgang Hofer)
+ *
+ * GAP ... Gimp Animation Plugins
+ *
+ * Master includefile for the library libgapbase
+ *
+ */
+/* The GIMP -- an image manipulation program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* revision history:
+ * 2.5.0 2009.03.07 hof: created
+ */
+
+#ifndef _LIBGAPBASE_H
+#define _LIBGAPBASE_H
+
+#include "libgimp/gimp.h"
+
+#include "gap_val_file.h"
+#include "gap_file_util.h"
+#include "gap_base.h"
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]