]> arthur.barton.de Git - netatalk.git/blobdiff - bin/megatron/megatron.c
Writing metadata xattr on directories with sticky bit set, FR#94
[netatalk.git] / bin / megatron / megatron.c
index 8d9ffe442be360fdea9113fd403a901dc7af6838..573a3dc88696c408e92a2173687cec417c978107 100644 (file)
@@ -1,22 +1,26 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#endif /* HAVE_CONFIG_H */
 
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/uio.h>
 #include <fcntl.h>
+#include <time.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
-#include <syslog.h>
 #include <netatalk/endian.h>
+#include "asingle.h"
 #include "megatron.h"
+#include "hqx.h"
+#include "macbin.h"
+#include "nad.h"
 
-char           forkbuf[8192];
 char           *forkname[] = { "data", "resource" };
-char           *name[] = { "unhex",
+static char    forkbuf[8192];
+static char    *name[] = { "unhex",
                            "unbin",
                            "unsingle",
                            "macbinary",
@@ -26,10 +30,7 @@ char         *name[] = { "unhex",
                            "binheader",
                            "megatron" };
 
-int from_open( un, file, fh, flags )
-    int                        un, flags;
-    char               *file;
-    struct FHeader     *fh;
+static int from_open(int un, char *file, struct FHeader *fh, int flags)
 {
     switch ( un ) {
        case MEGATRON :
@@ -54,11 +55,7 @@ int from_open( un, file, fh, flags )
     }
 }
 
-int from_read( un, fork, buf, len )
-    int                        un;
-    int                        fork;
-    char               *buf;
-    int                        len;
+static ssize_t from_read(int un, int fork, char *buf, size_t len)
 {
     switch ( un ) {
        case MEGATRON :
@@ -81,8 +78,7 @@ int from_read( un, fork, buf, len )
     }
 }
 
-int from_close( un )
-    int                        un;
+static int from_close(int un)
 {
     switch ( un ) {
        case MEGATRON :
@@ -105,10 +101,7 @@ int from_close( un )
     }
 }
 
-int to_open( to, file, fh, flags )
-    int                        to, flags;
-    char               *file;
-    struct FHeader     *fh;
+static int to_open(int to, char *file, struct FHeader *fh, int flags)
 {
     switch ( to ) {
        case MEGATRON :
@@ -128,10 +121,7 @@ int to_open( to, file, fh, flags )
     }
 }
 
-int to_write( to, fork, bufc )
-    int                        to;
-    int                        fork;
-    int                        bufc;
+static ssize_t to_write(int to, int fork, size_t bufc)
 {
     switch ( to ) {
        case MEGATRON :
@@ -151,9 +141,7 @@ int to_write( to, fork, bufc )
     }
 }
 
-int to_close( to, keepflag )
-    int                        to;
-    int                        keepflag;
+static int to_close(int to, int keepflag)
 {
     switch ( to ) {
        case MEGATRON :
@@ -173,15 +161,13 @@ int to_close( to, keepflag )
     }
 }
 
-int megatron( path, module, newname, flags )
-    char       *path, *newname;
-    int                module, flags;
+static int megatron( char *path, int module, char *newname, int flags)
 {
     struct stat                st;
     struct FHeader     fh;
-    int                        bufc;
+    ssize_t            bufc;
     int                        fork;
-    int                        forkred;
+    size_t             forkred;
 
 /*
  * If the source file is not stdin, make sure it exists and
@@ -204,7 +190,7 @@ int megatron( path, module, newname, flags )
  */
 
     memset( &fh, 0, sizeof( fh ));
-    if ( from_open( module, path, &fh ) < 0 ) {
+    if ( from_open( module, path, &fh, flags ) < 0 ) {
        return( -1 );
     }
 
@@ -263,7 +249,7 @@ int megatron( path, module, newname, flags )
        fprintf( stderr, "megatron: forkred is \t\t%d\n", forkred );
        fprintf( stderr, "megatron: fh.forklen[%d] is \t%d\n", fork, 
                ntohl( fh.forklen[ fork ] ));
-#endif
+#endif /* DEBUG */
        if (( bufc < 0 ) || ( forkred != ntohl( fh.forklen[ fork ] ))) {
            fprintf( stderr, "%s: Problem with input, dude\n", path );
            to_close( module, TRASH );
@@ -283,9 +269,7 @@ int megatron( path, module, newname, flags )
     return( from_close( module ));
 }
 
-int main( argc, argv )
-    int                argc;
-    char       **argv;
+int main(int argc, char **argv)
 {
     int                rc, c;
     int                rv = 0;
@@ -295,7 +279,7 @@ int main( argc, argv )
     char       *progname, newname[ADEDLEN_NAME + 1];
 
     progname = strrchr( argv[ 0 ], '/' );
-    if (( progname == NULL ) || ( progname == '\0' )) {
+    if (( progname == NULL ) || ( *progname == '\0' )) {
        progname = argv[ 0 ];
     } else progname++;
 
@@ -304,7 +288,7 @@ int main( argc, argv )
        fprintf( stderr, "megatron: list of program links messed up\n" );
        return( -1 );
     }
-#endif
+#endif /* DEBUG */
 
     for ( c = 0 ; (( c < converts ) && ( module < 0 )) ; ++c ) {
        if ( strcmp( name[ c ], progname ) == 0 ) module = c;
@@ -319,6 +303,14 @@ int main( argc, argv )
 
     *newname = '\0';
     for ( c = 1 ; c < argc ; ++c ) {
+        if ( strcmp( argv [ c ], "--version" ) == 0 ) {
+           printf("%s (Netatalk %s megatron)\n", argv[0], VERSION);
+           return( -1 );
+       }
+        if ( strcmp( argv [ c ], "-v" ) == 0 ) {
+           printf("%s (Netatalk %s megatron)\n", argv[0], VERSION);
+           return( -1 );
+       }
         if ( strcmp( argv [ c ], "--header" ) == 0 ) {
            flags |= OPTION_HEADERONLY;
            continue;
@@ -331,12 +323,19 @@ int main( argc, argv )
          flags |= OPTION_STDOUT;
          continue;
        }
-         
-       if ( rc = megatron( argv[ c ], module, newname, flags) != 0 ) {
+       if (strcmp(argv[c], "--euc") == 0) {
+         flags |= OPTION_EUCJP;
+         continue;
+       }  
+       if (strcmp(argv[c], "--sjis") == 0) {
+         flags |= OPTION_SJIS;
+         continue;
+       }  
+       rc = megatron( argv[ c ], module, newname, flags);
+       if ( rc != 0 ) {
            rv = rc;
        }
        *newname = '\0';
     }
     return( rv );
 }
-