From 11d86ad9acd8007d0386f8bf776d18fa6bdc145b Mon Sep 17 00:00:00 2001 From: Toni Corvera Date: Mon, 30 Oct 2006 05:22:35 +0000 Subject: [PATCH] Retro-fitted branch 0.9.0 git-svn-id: https://svn.outlyer.net/svn/pub/nautilus-follow-symlink/branches/0.9.0@22 da2faf11-d50b-4b07-92cd-6070d1bd8887 --- BUILD | 9 + ChangeLog | 9 + GPL | 340 ++++++++++++++++++++++++++++++ configure.in | 11 +- debian/changelog | 6 + debian/docs | 1 - dist | 21 +- src/common.h | 185 +++++++++++++--- src/follow-symlink.c | 89 ++++---- src/follow-symlink.h | 17 +- src/nautilus-ext-follow-symlink.c | 22 +- src/nautilus-ext-follow-symlink.h | 8 +- 12 files changed, 627 insertions(+), 91 deletions(-) create mode 100644 GPL diff --git a/BUILD b/BUILD index 5046153..32552c5 100644 --- a/BUILD +++ b/BUILD @@ -1,4 +1,13 @@ +COMPILER NOTES +============== + +This program is meant to be built whith gcc. +While where possible care has been taken to not rely on GCC, the code is (and +will remain) only tested to build with it. Additionally, future versions +might use GCC's extension to the C syntax. + + COMPILATION =========== diff --git a/ChangeLog b/ChangeLog index ec482c1..a6eaa92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,15 @@ Iterim milestones These private versions, the version numbering bumps just denote that a development milestone is achieved +0.9.0 (30 oct 2006): + * INTERNAL: function tagging for optimization/semantics with GCC's C + extensions + * INTERNAL: stricter parameter attributes + * INTERNAL: Use of inlined variadic functions for debugging instead of macros + * FEATURE: Display icon in the menu entry/entries + * INTERNAL: Debugging macros/functions cleanup + * FEATURE: Support for different verbosity levels on debug + 0.8.0 (25 oct 2006): * INTERNAL: Changed the use of lstat() and realpath() to GnomeVFS versions * BUGFIX: Resolve realpaths correctly for paths with non-ascii characters diff --git a/GPL b/GPL new file mode 100644 index 0000000..b7b5f53 --- /dev/null +++ b/GPL @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/configure.in b/configure.in index fd681b4..30fff8a 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ AC_INIT(src/follow-symlink.c) -AM_INIT_AUTOMAKE(libnautilus-follow-symlink, "0.8.0") +AM_INIT_AUTOMAKE(libnautilus-follow-symlink, "0.9.0") AC_CONFIG_HEADER(src/config.h) dnl default FLAGS @@ -8,9 +8,14 @@ CPPFLAGS="$CPPFLAGS -std=gnu99 -pedantic-errors -Wall" CFLAGS="$CFLAGS -O -Wall -Werror" LDFLAGS="$LDFLAGS -Wl,--as-needed" -# libtool -AM_PROG_LIBTOOL +# FIXME: Make this better +FSL_ICON="/usr/share/icons/gnome/48x48/emblems/emblem-symbolic-link.png" +AC_SUBST(FSL_ICON) +AC_DEFINE_UNQUOTED(FSL_ICON, "$FSL_ICON", [follow-symlink menu icon]) + +# libtool, DISABLE_STATIC should go before PROG_LIBTOOL AM_DISABLE_STATIC +AM_PROG_LIBTOOL AC_PROG_INSTALL AC_LANG_C diff --git a/debian/changelog b/debian/changelog index 50c53bd..d242639 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +nautilus-follow-symlink (0.9.0-out.1) unstable; urgency=low + + * New upstream release + + -- Toni Corvera Mon, 30 Oct 2006 06:16:26 +0100 + nautilus-follow-symlink (0.8.0-out.1) unstable; urgency=low * New upstream release diff --git a/debian/docs b/debian/docs index dfbf933..89620f3 100644 --- a/debian/docs +++ b/debian/docs @@ -1,2 +1 @@ -ROADMAP BUILD diff --git a/dist b/dist index 5d08355..25887a1 100755 --- a/dist +++ b/dist @@ -8,7 +8,7 @@ dist: gen # whitout it is /usr/share/libtool/m4, altough it will fail # on finding ltmain.sh -gen: +gen: check-gen-deps libtoolize intltoolize aclocal -I . @@ -16,6 +16,25 @@ gen: autoheader automake --add-missing --foreign +# This rule serves as a replacement for which for systems in which it +# isn't installed +# Use: ./dist which-PROGNAME or +# a rule that depends on which-PROGNAME1, which-PROGNAME2, ... +which-%: + @bash -c "type -p $*" || { \ + echo "*** Couldn't find $*, can't continue without"\ + "all requirements">&2 ;\ + false ; \ + } + +check-gen-deps: \ + which-libtoolize \ + which-intltoolize \ + which-aclocal \ + which-autoconf \ + which-autoheader \ + which-automake + help: @echo "This file is used to aid in the setup of the build" @echo "environment, there are the following available targets" diff --git a/src/common.h b/src/common.h index 008039b..0e011fb 100644 --- a/src/common.h +++ b/src/common.h @@ -12,6 +12,10 @@ #include /* getenv() (3) */ #include /* strcmp() (3) */ +#ifdef _DEBUG + #include /* va_list, va_start ... */ +#endif + #include "libintl.h" #define _(STR) gettext(STR) @@ -26,13 +30,52 @@ #define __inline #endif -#if !defined(__fsl_unused) - // Xref: http://rlove.org/log/2005102601 - #if __GNUC__ >= 3 - #define __fsl_unused __attribute__ ((unused)) - #else - #define __fsl_unused - #endif +// Based on : http://rlove.org/log/2005102601 +#if __GNUC__ >= 3 + #define inline inline __attribute__((always_inline)) + #define __pure __attribute__((pure)) + //#define __const __attribute__((const)) // fails + #define __constfn __attribute__((const)) + #define __noreturn __attribute__((noreturn)) + #define __malloc __attribute__((malloc)) + #define __must_check __attribute__((warn_unused_result)) + #define __deprecated __attribute__((deprecated)) + #define __used __attribute__((used)) + #define __unused __attribute__((unused)) + #define __packed __attribute__((packed)) + #define likely(x) __builtin_expect (!!(x), 1) + #define unlikely(x) __builtin_expect (!!(x), 0) + + /* These are mine: used to hint the compiler in variadic printf-like + * functions, this way it will warn if format/arguments are incorrect */ + /* printf-like variadic arguments (format is first, args from second) */ + #define __va_printf __attribute__((format(printf, 1, 2))) + /* fprintf-like variadic arguments (format is second, args from third */ + #define __va_fprintf __attribute__((format(printf, 2, 3))) +#else + #define inline /* no inline */ + #define __pure /* no pure */ + #define __constfn /* no const */ + #define __noreturn /* no noreturn */ + #define __malloc /* no malloc */ + #define __must_check /* no warn_unused_result */ + #define __deprecated /* no deprecated */ + #define __used /* no used */ + #define __unused /* no unused */ + #define __packed /* no packed */ + #define likely(x) (x) + #define unlikely(x) (x) + + #define __va_printf + #define __va_fprintf +#endif + +/* + * Uber-anal glib usage: disallow stdlib's functions where glib provides + * their own + */ +#if 0 && __GNUC__ + #pragma GCC poison printf sprintf #endif #ifdef _DEBUG @@ -40,35 +83,121 @@ /* Prefix for messages */ #define FSL_ "nautilus-follow-symlink: " - /* Environment variable, set to 1 to enable verbosity */ - #define DBGENV_ (getenv("FSL_DBG")) - /* Check on runtime the environment variable's value */ - #define DEBUG_ON_() (DBGENV_ != NULL && 0 == strcmp(DBGENV_,"1")) - /* Informational message shown on initialisation */ - #define FSL_DEBUG_INIT() { \ - const int ENABLED = DEBUG_ON_(); \ - g_print( FSL_ "DEBUG mode is available, and "); \ - g_print( (ENABLED) ? "enabled.\n" : "disabled.\n"); \ - g_print( FSL_ "set the environment variable FSL_DBG to \n" \ - FSL_ "1 to enable it or to any other value to disable it.\n"); \ + enum { + FINE = 1, + FINER, + + TRACE = FINER, }; + /* Check on runtime the environment variable's value + * + * (set to 1 to enable verbosity, to 2 for extra verbosity) + */ + static inline int VERBOSITY_LEVEL(void) + { + const char * const DBGENV = getenv("FSL_DBG"); + if (NULL == DBGENV || 0 == strcmp(DBGENV, "0")) { + return 0; + } + else if (0 == strcmp(DBGENV, "2")) { + return 2; + } + return 1; + } + + /* Informational message shown on initialisation */ + static inline void FSL_DEBUG_INIT(void) + { + g_print( FSL_ "DEBUG mode is available, and "); + g_printf(" set to %d.\n", VERBOSITY_LEVEL()); + g_print( FSL_ "set the environment variable FSL_DBG to \n" + FSL_ "1 to enable it or to any other value to disable it.\n"); + } + /* Display the name of the current function name */ - #define TRACE() if (DEBUG_ON_())\ - g_printf("nautilus-follow-symlink trace: %s()\n", __FUNCTION__); - /* Display a message */ - #define FSL_LOG(str) if (DEBUG_ON_()) g_printf("%s\n", (str)); - /* Display a formatted message with one string argument */ - #define FSL_LOG1(str1, str2) if (DEBUG_ON_()) g_printf("%s %s\n", (str1), (str2)); - #define FSL_LOG_SPRINTF1(s1, s2) if (DEBUG_ON_()) g_printf((s1), (s2)); + #define TRACE() FSL_LOG_WITH_LEVEL(TRACE, FSL_ "trace: %s()", __func__); + + /* + * Display a log message with a given log level if the level + * is at least VERBOSITY_LEVEL(). + * Same as FSL_LOG_WITH_LEVEL but taking a va_list, this function + * provides the implementation used by the other FSL_LOG_*'s + */ + static inline void __unused FSL_LOG_WITH_LEVEL_IMPL(int level, + gchar * const format, + va_list ap) + { + if (VERBOSITY_LEVEL() >= level) { + g_vprintf(format, ap); + g_print("\n"); + } + } + + /* + * Display a log message with a given log level if the level + * is at least VERBOSITY_LEVEL(). + */ + static void __unused __va_fprintf FSL_LOG_WITH_LEVEL(int level, + gchar * const format, + ...) + { + va_list ap; + va_start(ap, format); + + FSL_LOG_WITH_LEVEL_IMPL(level, format, ap); + + va_end(ap); + } + + /* Display a message + * + * NOTE: Variadic functions can't be inlined + */ + static void __unused __va_printf FSL_LOG(gchar * const format, ...) + { + va_list ap; + va_start(ap, format); + + FSL_LOG_WITH_LEVEL_IMPL(FINE, format, ap); + + va_end(ap); + } + + /* Display a message if a condition is true + * + * NOTE: Variadic functions can't be inlined + */ + static void __unused __va_fprintf FSL_LOG_COND(int cond, gchar * const format, ...) + { + if (cond) { + va_list ap; + va_start(ap, format); + + FSL_LOG_WITH_LEVEL_IMPL(FINE, format, ap); + + va_end(ap); + } + } + + /* see below for an explanation */ + #define FSL_LOG1(s) FSL_LOG(s) #else /* Debugging facilities disabled */ + #define FINE + #define FINER #define TRACE() - #define FSL_LOG(a) - #define FSL_LOG1(a,b) #define FSL_DEBUG_INIT() - #define FSL_LOG_SPRINTF1(a,b) + /* With variadic functions there's no way (AFAIK) to provide empty + * alternative macros that won't raise a compiler error if no variable + * arguments are given, hence this hackish FSL_LOG1, for the cases + * in which just an argument is used + */ + #define FSL_LOG1(s) + #define FSL_LOG(f, ...) + ///* Unneeded for the time being */ #define FSL_LOG_WITH_LEVEL(l,f,rest...) + #define FSL_LOG_COND(c,f,...) #endif #endif /* FOLLOW_SYMLINK_COMMON_H */ diff --git a/src/follow-symlink.c b/src/follow-symlink.c index a3b3ce5..4bf7994 100644 --- a/src/follow-symlink.c +++ b/src/follow-symlink.c @@ -33,7 +33,7 @@ GList * fsl_get_items_impl(GtkWidget * window, // TODO: what about GnomeVFSFileInfo's is_local ? gchar * uri_scheme = nautilus_file_info_get_uri_scheme(file_info); if (strcmp(uri_scheme, "file") != 0) { - FSL_LOG( "Not file scheme" ); + FSL_LOG1( "Not file scheme" ); return NULL; } g_free(uri_scheme); @@ -49,7 +49,7 @@ GList * fsl_get_items_impl(GtkWidget * window, g_assert( (gfi->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_FLAGS) > 0 ); if ( (gfi->flags & GNOME_VFS_FILE_FLAGS_SYMLINK) == 0 ) { - FSL_LOG1("GnomeVFS Flags: ! SYMLINK: ", nautilus_file_info_get_uri(file_info)); + FSL_LOG("GnomeVFS Flags: ! SYMLINK in %s", nautilus_file_info_get_uri(file_info)); return NULL; } @@ -62,20 +62,20 @@ GList * fsl_get_items_impl(GtkWidget * window, } GList * -fsl_get_background_items(NautilusMenuProvider * provider, +fsl_get_background_items(NautilusMenuProvider * provider __unused, GtkWidget * window, NautilusFileInfo * current_folder) { TRACE(); if (NULL == current_folder) { // XXX: Does this ever happen? - FSL_LOG( "No folder selected" ); + FSL_LOG1( "No folder selected"); } return fsl_get_items_impl(window, current_folder, FALSE, NULL); } -gboolean file_is_directory (gpointer file_data) +gboolean file_is_directory (const gpointer const file_data) { TRACE(); @@ -87,45 +87,38 @@ gboolean file_is_directory (gpointer file_data) return gfi->type == GNOME_VFS_FILE_TYPE_DIRECTORY; } -/* Bind to menu if needed */ -GList * -fsl_get_file_items (NautilusMenuProvider * provider, - GtkWidget * window, - GList * files) +/* + * Bind to the menu if needed + * + * + */ +GList * fsl_get_file_items (NautilusMenuProvider * provider __unused, + GtkWidget * window, + GList * files) { TRACE(); // Number of files = g_list_length(files) // Directory = nautilus_file_info_is_directory(files->data) if (NULL == files) { - FSL_LOG("No file selected"); + FSL_LOG1("No file selected"); return NULL; } + assert( g_list_length(files) > 0 ); - if (g_list_length(files) == 1) { - if (!file_is_directory(files->data)) { - FSL_LOG("File is not a directory"); - return NULL; - } - return fsl_get_items_impl(window, files->data, TRUE, NULL); - } - - // More than one selected file - assert( g_list_length(files) > 1 ); - - FSL_LOG( "More than one file selected" ); + FSL_LOG_COND( g_list_length(files) > 1, "More than one file selected (%d)", g_list_length(files) ); GList * items = NULL; for (int i=0; isymlink_name; const gchar const * BASE_CMD = "nautilus --no-desktop --no-default-window '%s'"; @@ -159,12 +154,9 @@ void fsl_callback (NautilusMenuItem * item, NautilusFileInfo * file_info) g_printf("nautilus-follow-symlink: Spawning nautilus with\n '%s'\n", command_line); - const gchar * cwd = "."; // FIXME: const gchar * cwd = nautilus_file_info_get_parent_uri(file_info) + URI_OFFSET; // TODO: does the cwd used for spawn have any side-effect ? - FSL_LOG_SPRINTF1 ("\tusing pwd=%s\n", cwd ); - - g_spawn_async( cwd, + g_spawn_async( ".", argv, NULL, G_SPAWN_SEARCH_PATH, @@ -173,9 +165,17 @@ void fsl_callback (NautilusMenuItem * item, NautilusFileInfo * file_info) g_free(command_line); g_strfreev(argv); } -/* Create the new menu item */ -NautilusMenuItem * -fsl_menu_item_new(GdkScreen *screen, gboolean is_file_item, const gchar * base_name) + +/* + * Creates the new menu item + * + * is_file_item: TRUE if we're working over a (selected) file, FALSE if working + * over a (opened) folder + * base_name: file name, without path, of the given file + */ +NautilusMenuItem * fsl_menu_item_new(GdkScreen *screen __unused, + gboolean is_file_item, + const gchar * base_name) { TRACE(); @@ -205,17 +205,16 @@ fsl_menu_item_new(GdkScreen *screen, gboolean is_file_item, const gchar * base_n g_sprintf(tooltip, fmt_tooltip, base_name); } - // Trial and error shows that the menu item name must be different + // Trial and error showed that the menu item name must be different // when various are to be shown, and also that the name should always be // the same for a given file - static const gchar * ITEM_NAME_FMT = "FsymlinkExtension::follow_symlink_%s"; - // TODO: Check g_alloca() error conditions - gchar * unique_name = g_alloca(strlen(ITEM_NAME_FMT) + strlen(base_name)); // 10 = strlen("4294967296")); + static const gchar * const ITEM_NAME_FMT = "FsymlinkExtension::follow_symlink_%s"; + gchar * unique_name = g_malloc(strlen(ITEM_NAME_FMT) + strlen(base_name)); g_sprintf(unique_name, ITEM_NAME_FMT, base_name); // (name, label, tip, icon) - ret = nautilus_menu_item_new(//"FsymlinkExtension::follow_symlink", - unique_name, - name, tooltip, NULL); + ret = nautilus_menu_item_new(unique_name, name, tooltip, FSL_ICON); + + g_free(unique_name); g_free(name); g_free(tooltip); diff --git a/src/follow-symlink.h b/src/follow-symlink.h index a914cc2..1007e27 100644 --- a/src/follow-symlink.h +++ b/src/follow-symlink.h @@ -19,15 +19,24 @@ static void fsl_callback(NautilusMenuItem *, NautilusFileInfo *); -static GList * fsl_get_file_items(NautilusMenuProvider *, GtkWidget *, GList *); +// This signature can't be changed +static GList * fsl_get_file_items(NautilusMenuProvider *, + GtkWidget *, + GList *); -static GList * fsl_get_background_items(NautilusMenuProvider *, GtkWidget *, NautilusFileInfo *); +// This signature can't be changed +static GList * fsl_get_background_items(NautilusMenuProvider *, + GtkWidget *, + NautilusFileInfo *); -static __inline GList * fsl_get_items_impl(GtkWidget *, NautilusFileInfo *, gboolean,GList*); +static inline GList * fsl_get_items_impl(GtkWidget *, + NautilusFileInfo *, + gboolean, + GList *); static NautilusMenuItem * fsl_menu_item_new(GdkScreen *, gboolean, const gchar *); -static __inline gboolean file_is_directory(gpointer); +static inline __pure gboolean file_is_directory(const gpointer const); /* Exported Prototypes * Here the namespace is a bit more explicit just in case diff --git a/src/nautilus-ext-follow-symlink.c b/src/nautilus-ext-follow-symlink.c index 10146f4..7831b43 100644 --- a/src/nautilus-ext-follow-symlink.c +++ b/src/nautilus-ext-follow-symlink.c @@ -16,7 +16,10 @@ void nautilus_module_initialize (GTypeModule *module) g_printf("Initializing nautilus-follow-symlink extension (v.%s)\n", VERSION); fsl_register_type(module); +# if 0 provider_types[0] = fsl_get_type(); +#endif + provider_types[0] = fsl_type; } void nautilus_module_shutdown (void) @@ -35,7 +38,7 @@ void nautilus_module_list_types (const GType **types, int *num_types) *num_types = G_N_ELEMENTS(provider_types); } -void fsl_register_type (GTypeModule *module) +void fsl_register_type (GTypeModule * module) { TRACE(); @@ -43,18 +46,19 @@ void fsl_register_type (GTypeModule *module) sizeof(FsymlinkExtensionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, - (GClassInitFunc) fsl_class_init, + //TODO: Does nullifyng this have side effects? + NULL, //(GClassInitFunc) fsl_class_init, NULL, NULL, sizeof (FsymlinkExtension), 0, - (GInstanceInitFunc) fsl_instance_init, + NULL, //(GInstanceInitFunc) fsl_instance_init, }; fsl_type = g_type_module_register_type (module, - G_TYPE_OBJECT, - "FsymlinkExtension", - &info, 0); + G_TYPE_OBJECT, + "FsymlinkExtension", + &info, 0); /* Menu provider interface */ static const GInterfaceInfo menu_provider_iface_info = { (GInterfaceInitFunc)fsl_extension_menu_provider_iface_init, @@ -68,14 +72,17 @@ void fsl_register_type (GTypeModule *module) /* Other Interfaces */ } +#if 0 GType fsl_get_type(void) { TRACE(); return fsl_type; } +#endif -void fsl_instance_init(FsymlinkExtension *cvs) +#if 0 +void fsl_instance_init(FsymlinkExtension *instance) { TRACE(); } @@ -84,5 +91,6 @@ void fsl_class_init(FsymlinkExtensionClass *class) { TRACE(); } +#endif /* vim:set ts=4 et ai: */ diff --git a/src/nautilus-ext-follow-symlink.h b/src/nautilus-ext-follow-symlink.h index 3f31f63..b8e0094 100644 --- a/src/nautilus-ext-follow-symlink.h +++ b/src/nautilus-ext-follow-symlink.h @@ -26,7 +26,9 @@ void nautilus_module_list_types(const GType **, int *); static void fsl_register_type(GTypeModule *); -static GType fsl_get_type(void); +#if 0 +static __constfn GType fsl_get_type(void); +#endif /* Data Types */ @@ -42,10 +44,12 @@ typedef struct _FsymlinkExtensionClass FsymlinkExtensionClass; typedef struct _FsymlinkExtension FsymlinkExtension; -/* Data initializers */ +/* Data initializers, not really needed */ +#if 0 static void fsl_class_init (FsymlinkExtensionClass *class); static void fsl_instance_init (FsymlinkExtension *cvs); +#endif /* Defined in the private interface */ extern void fsl_extension_menu_provider_iface_init(NautilusMenuProviderIface *iface);