Index: trunk/src/hid/common/hidinit.c =================================================================== --- trunk/src/hid/common/hidinit.c (revision 274) +++ trunk/src/hid/common/hidinit.c (revision 275) @@ -32,6 +32,7 @@ #include "error.h" #include "global.h" #include "misc.h" +#include "portability.h" /* MKDIR() */ #include "pcb-printf.h" #ifdef HAVE_LIBDMALLOC Index: trunk/src/hid/gtk/gui-config.c =================================================================== --- trunk/src/hid/gtk/gui-config.c (revision 274) +++ trunk/src/hid/gtk/gui-config.c (revision 275) @@ -45,7 +45,8 @@ #include "file.h" #include "error.h" #include "draw.h" -#include "misc.h" /* MKDIR() */ +#include "misc.h" +#include "portability.h" /* MKDIR() */ #include "pcb-printf.h" #include "set.h" Index: trunk/src/misc.c =================================================================== --- trunk/src/misc.c (revision 274) +++ trunk/src/misc.c (revision 275) @@ -73,6 +73,7 @@ #include "set.h" #include "undo.h" #include "action.h" +#include "portability.h" #ifdef HAVE_LIBDMALLOC #include @@ -1162,55 +1163,6 @@ } /* --------------------------------------------------------------------------- - * concatenates directory and filename if directory != NULL, - * expands them with a shell and returns the found name(s) or NULL - */ -char * -ExpandFilename (char *Dirname, char *Filename) -{ - static DynamicStringType answer; - char *command; - FILE *pipe; - int c; - - /* allocate memory for commandline and build it */ - DSClearString (&answer); - if (Dirname) - { - command = (char *)calloc (strlen (Filename) + strlen (Dirname) + 7, - sizeof (char)); - sprintf (command, "echo %s/%s", Dirname, Filename); - } - else - { - command = (char *)calloc (strlen (Filename) + 6, sizeof (char)); - sprintf (command, "echo %s", Filename); - } - - /* execute it with shell */ - if ((pipe = popen (command, "r")) != NULL) - { - /* discard all but the first returned line */ - for (;;) - { - if ((c = fgetc (pipe)) == EOF || c == '\n' || c == '\r') - break; - else - DSAddCharacter (&answer, c); - } - - free (command); - return (pclose (pipe) ? NULL : answer.Data); - } - - /* couldn't be expanded by the shell */ - PopenErrorMessage (command); - free (command); - return (NULL); -} - - -/* --------------------------------------------------------------------------- * returns the layer number for the passed pointer */ int @@ -2207,20 +2159,15 @@ return info.Data; } -/* --------------------------------------------------------------------------- - * mkdir() implentation, mostly for plugins, which don't have our config.h. - */ - -#ifdef MKDIR_IS_PCBMKDIR -#error "Don't know how to create a directory on this system." -#endif - -int -pcb_mkdir (const char *path, int mode) +char *pcb_author (void) { - return MKDIR (path, mode); + if (Settings.FabAuthor && Settings.FabAuthor[0]) + return Settings.FabAuthor; + else + return get_user_name(); } + /* --------------------------------------------------------------------------- * Returns a best guess about the orientation of an element. The * value corresponds to the rotation; a difference is the right value Index: trunk/src/misc.h =================================================================== --- trunk/src/misc.h (revision 274) +++ trunk/src/misc.h (revision 275) @@ -46,6 +46,8 @@ double Distance (double x1, double y1, double x2, double y2); Angle NormalizeAngle (Angle a); +char *pcb_author (void); + void r_delete_element (DataTypePtr, ElementTypePtr); void SetLineBoundingBox (LineTypePtr); void SetArcBoundingBox (ArcTypePtr); @@ -68,7 +70,6 @@ int ParseRouteString (char *, RouteStyleTypePtr, const char *); void QuitApplication (void); char *EvaluateFilename (char *, char *, char *, char *); -char *ExpandFilename (char *, char *); void SetTextBoundingBox (FontTypePtr, TextTypePtr); void SaveOutputWindow (void); @@ -142,30 +143,6 @@ void NetlistChanged (int force_unfreeze); -/* - * Check whether mkdir() is mkdir or _mkdir, and whether it takes one - * or two arguments. WIN32 mkdir takes one argument and POSIX takes - * two. - */ -#if HAVE_MKDIR - #if MKDIR_TAKES_ONE_ARG - /* MinGW32 */ -#include /* mkdir under MinGW only takes one argument */ - #define MKDIR(a, b) mkdir(a) - #else - #define MKDIR(a, b) mkdir(a, b) - #endif -#else - #if HAVE__MKDIR - /* plain Windows 32 */ - #define MKDIR(a, b) _mkdir(a) - #else - #define MKDIR(a, b) pcb_mkdir(a, b) - #define MKDIR_IS_PCBMKDIR 1 - int pcb_mkdir (const char *path, int mode); - #endif -#endif - #endif /* PCB_MISC_H */ Index: trunk/src/portability.c =================================================================== --- trunk/src/portability.c (revision 274) +++ trunk/src/portability.c (revision 275) @@ -56,26 +56,8 @@ #include "global.h" -#include "box.h" -#include "crosshair.h" -#include "create.h" -#include "data.h" -#include "draw.h" -#include "file.h" #include "error.h" #include "mymem.h" -#include "misc.h" -#include "move.h" -#include "pcb-printf.h" -#include "polygon.h" -#include "remove.h" -#include "rtree.h" -#include "rotate.h" -#include "rubberband.h" -#include "search.h" -#include "set.h" -#include "undo.h" -#include "action.h" /* ---------------------------------------------------------------------- * returns pointer to current working directory. If 'path' is not @@ -94,21 +76,13 @@ } - -char *pcb_author (void) +const char *get_user_name(void) { #ifdef HAVE_GETPWUID static struct passwd *pwentry; - static char *fab_author = 0; - if (!fab_author) - { - if (Settings.FabAuthor && Settings.FabAuthor[0]) - fab_author = Settings.FabAuthor; - else - { int len; - char *comma, *gecos; + char *comma, *gecos, *fab_author; /* ID the user. */ pwentry = getpwuid (getuid ()); @@ -126,10 +100,60 @@ } memcpy (fab_author, gecos, len); fab_author[len] = 0; - } - } - return fab_author; #else return "Unknown"; #endif + } + +char *ExpandFilename (char *Dirname, char *Filename) +{ + static DynamicStringType answer; + char *command; + FILE *pipe; + int c; + + /* allocate memory for commandline and build it */ + DSClearString (&answer); + if (Dirname) + { + command = (char *)calloc (strlen (Filename) + strlen (Dirname) + 7, + sizeof (char)); + sprintf (command, "echo %s/%s", Dirname, Filename); + } + else + { + command = (char *)calloc (strlen (Filename) + 6, sizeof (char)); + sprintf (command, "echo %s", Filename); + } + + /* execute it with shell */ + if ((pipe = popen (command, "r")) != NULL) + { + /* discard all but the first returned line */ + for (;;) + { + if ((c = fgetc (pipe)) == EOF || c == '\n' || c == '\r') + break; + else + DSAddCharacter (&answer, c); + } + + free (command); + return (pclose (pipe) ? NULL : answer.Data); + } + + /* couldn't be expanded by the shell */ + PopenErrorMessage (command); + free (command); + return (NULL); +} + + +#ifdef MKDIR_IS_PCBMKDIR +#error "Don't know how to create a directory on this system." +int pcb_mkdir (const char *path, int mode) +{ + return MKDIR (path, mode); +} +#endif Index: trunk/src/portability.h =================================================================== --- trunk/src/portability.h (revision 274) +++ trunk/src/portability.h (revision 275) @@ -1,2 +1,31 @@ char *GetWorkingDirectory (char *); -char *pcb_author (void); +const char *get_user_name(void); + +/* concatenates directory and filename if directory != NULL, + * expands them with a shell and returns the found name(s) or NULL + */ +char *ExpandFilename (char *dirname, char *filename); + +/* mkdir() implentation, mostly for plugins, which don't have our config.h. + * Check whether mkdir() is mkdir or _mkdir, and whether it takes one + * or two arguments. WIN32 mkdir takes one argument and POSIX takes + * two. + */ +#if HAVE_MKDIR + #if MKDIR_TAKES_ONE_ARG + /* MinGW32 */ +#include /* mkdir under MinGW only takes one argument */ + #define MKDIR(a, b) mkdir(a) + #else + #define MKDIR(a, b) mkdir(a, b) + #endif +#else + #if HAVE__MKDIR + /* plain Windows 32 */ + #define MKDIR(a, b) _mkdir(a) + #else + #define MKDIR(a, b) pcb_mkdir(a, b) + #define MKDIR_IS_PCBMKDIR 1 + int pcb_mkdir (const char *path, int mode); + #endif +#endif