]> arthur.barton.de Git - netatalk.git/blobdiff - bin/megatron/hqx.c
Include path fixes.
[netatalk.git] / bin / megatron / hqx.c
index b7099b5ccfef43cffce074eecfb6607a28ca5e70..819f5ca727b5ff27e8898c95789b343abd533c2b 100644 (file)
@@ -1,27 +1,35 @@
+/*
+ * $Id: hqx.c,v 1.13 2003-06-06 21:17:19 srittau Exp $
+ */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#endif /* HAVE_CONFIG_H */
 
-#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <sys/time.h>
 #include <sys/param.h>
-#ifdef notdef
-#if BSD >= 199006
-# include <machine/endian.h>
-#else
-# include <netinet/in.h>
-#endif
-#endif notdef
-#include <fcntl.h>
+
 #include <string.h>
-#include <syslog.h>
 #include <ctype.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include <unistd.h>
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif /* HAVE_FCNTL_H */
+
+#include <netinet/in.h>
+
 #include <atalk/adouble.h>
 #include <netatalk/endian.h>
+
 #include "megatron.h"
+#include "nad.h"
+#include "hqx.h"
 
 #define HEXOUTPUT      0
 
@@ -30,7 +38,7 @@
  */
 #ifndef        STDIN
 #      define  STDIN   "-"
-#endif
+#endif /* ! STDIN */
 
 /*     Yes and no
  */
 /*     These are field sizes in bytes of various pieces of the
        binhex header
  */
-#define        VERSION         1
-#define        TCSIZ           8
-#define        FLAGSIZ         2
-#define        DATASIZ         4
-#define        RESSIZ          4
-#define CRCSIZ         2
-#define HEADSIZ                21
+#define        BHH_VERSION             1
+#define        BHH_TCSIZ               8
+#define        BHH_FLAGSIZ             2
+#define        BHH_DATASIZ             4
+#define        BHH_RESSIZ              4
+#define BHH_CRCSIZ             2
+#define BHH_HEADSIZ            21
 
 u_short                updcrc();
 
+/*     Forward declarations.
+ */
+int skip_junk(int line);
+int hqx_close(int keepflag);
+int hqx_header_read(struct FHeader *fh);
+int hqx_header_write(struct FHeader *fh);
+int hqx_7tobin(char *outbuf, int datalen);
+int hqx7_fill(u_char *hqx7_ptr);
+
 #if HEXOUTPUT
 FILE           *rawhex, *expandhex;
-#endif
+#endif /* HEXOUTPUT */
 
 struct hqx_file_data {
     u_int32_t          forklen[ NUMFORKS ];
@@ -84,7 +101,7 @@ somewhat initialized; hqx_fd is set.  skip_junk is called from
 here; skip_junk leaves hqx7_first and hqx7_last set.
  */
 
-hqx_open( hqxfile, flags, fh, options )
+int hqx_open( hqxfile, flags, fh, options )
     char               *hqxfile;
     int                        flags, options;
     struct FHeader     *fh;
@@ -93,13 +110,14 @@ hqx_open( hqxfile, flags, fh, options )
 
 #if DEBUG
     fprintf( stderr, "megatron: entering hqx_open\n" );
-#endif
+#endif /* DEBUG */
+    select_charset( options);
     if ( flags == O_RDONLY ) {
 
 #if HEXOUTPUT
        rawhex = fopen( "rawhex.unhex", "w" );
        expandhex = fopen( "expandhex.unhex", "w" );
-#endif
+#endif /* HEXOUTPUT */
 
        first_flag = 0;
 
@@ -115,9 +133,9 @@ hqx_open( hqxfile, flags, fh, options )
 #if DEBUG
                off_t   pos;
 
-               pos = lseek( hqx.filed, 0, L_INCR );
+               pos = lseek( hqx.filed, 0, SEEK_CUR );
                fprintf( stderr, "megatron: current position is %ld\n", pos );
-#endif
+#endif /* DEBUG */
                return( 0 );
            }
        }
@@ -148,7 +166,7 @@ hqx_open( hqxfile, flags, fh, options )
  * Otherwise, a value of -1 is returned.
  */
 
-hqx_close( keepflag )
+int hqx_close( keepflag )
     int                        keepflag;
 {
     if ( keepflag == KEEP ) {
@@ -170,7 +188,7 @@ hqx_close( keepflag )
  * return zero and no more than that.
  */
 
-hqx_read( fork, buffer, length )
+int hqx_read( fork, buffer, length )
     int                        fork;
     char               *buffer;
     int                        length;
@@ -182,12 +200,12 @@ hqx_read( fork, buffer, length )
 #if DEBUG >= 3
     {
        off_t   pos;
-       pos = lseek( hqx.filed, 0, L_INCR );
+       pos = lseek( hqx.filed, 0, SEEK_CUR );
        fprintf( stderr, "hqx_read: current position is %ld\n", pos );
     }
     fprintf( stderr, "hqx_read: fork is %s\n", forkname[ fork ] );
     fprintf( stderr, "hqx_read: remaining length is %d\n", hqx.forklen[fork] );
-#endif
+#endif /* DEBUG >= 3 */
 
     if ( hqx.forklen[ fork ] < 0 ) {
        fprintf( stderr, "This should never happen, dude!\n" );
@@ -201,7 +219,7 @@ hqx_read( fork, buffer, length )
 #if DEBUG >= 4
     fprintf( stderr, "hqx_read: storedcrc\t\t%x\n", storedcrc );
     fprintf( stderr, "hqx_read: observed crc\t\t%x\n\n", hqx.forkcrc[fork] );
-#endif
+#endif /* DEBUG >= 4 */
            if ( storedcrc == hqx.forkcrc[ fork ] ) {
                return( 0 );
            }
@@ -218,7 +236,7 @@ hqx_read( fork, buffer, length )
     }
 #if DEBUG >= 3
     fprintf( stderr, "hqx_read: readlen is %d\n", readlen );
-#endif
+#endif /* DEBUG >= 3 */
 
     cc = hqx_7tobin( buffer, readlen );
     if ( cc > 0 ) {
@@ -228,7 +246,7 @@ hqx_read( fork, buffer, length )
     }
 #if DEBUG >= 3
     fprintf( stderr, "hqx_read: chars read is %d\n", cc );
-#endif
+#endif /* DEBUG >= 3 */
     return( cc );
 }
 
@@ -240,7 +258,7 @@ hqx_read( fork, buffer, length )
  * to fill the hqx_header fields.
  */
 
-hqx_header_read( fh )
+int hqx_header_read( fh )
     struct FHeader     *fh;
 {
     char               *headerbuf, *headerptr;
@@ -252,7 +270,7 @@ hqx_header_read( fh )
 #if HEXOUTPUT
     int                headerfork;
     headerfork = open( "headerfork", O_WRONLY|O_CREAT, 0622 );
-#endif
+#endif /* HEXOUTPUT */
 
     mask = htons( 0xfcee );
     hqx.headercrc = 0;
@@ -266,24 +284,24 @@ hqx_header_read( fh )
 
 #if HEXOUTPUT
     write( headerfork, &namelen, sizeof( namelen ));
-#endif
+#endif /* HEXOUTPUT */
 
     if (( headerbuf = 
-           (char *)malloc( (unsigned int)( namelen + HEADSIZ ))) == 0 ) {
+           (char *)malloc( (unsigned int)( namelen + BHH_HEADSIZ ))) == 0 ) {
        return( -1 );
     }
-    if ( hqx_7tobin( headerbuf, ( namelen + HEADSIZ )) == 0 ) {
+    if ( hqx_7tobin( headerbuf, ( namelen + BHH_HEADSIZ )) == 0 ) {
        free( headerbuf );
        fprintf( stderr, "Premature end of file :" );
        return( -2 );
     }
     headerptr = headerbuf;
     hqx.headercrc = updcrc( hqx.headercrc, 
-           (u_char *)headerbuf, ( namelen + HEADSIZ - CRCSIZ ));
+           (u_char *)headerbuf, ( namelen + BHH_HEADSIZ - BHH_CRCSIZ ));
 
 #if HEXOUTPUT
-    write( headerfork, headerbuf, ( namelen + HEADSIZ ));
-#endif
+    write( headerfork, headerbuf, ( namelen + BHH_HEADSIZ ));
+#endif /* HEXOUTPUT */
 
 /*
  * stuff from the hqx file header
@@ -291,20 +309,20 @@ hqx_header_read( fh )
 
     memcpy( fh->name, headerptr, (int)namelen );
     headerptr += namelen;
-    headerptr += VERSION;
-    memcpy(&fh->finder_info,  headerptr, TCSIZ );
-    headerptr += TCSIZ;
-    memcpy(&fh->finder_info.fdFlags,  headerptr, FLAGSIZ );
+    headerptr += BHH_VERSION;
+    memcpy(&fh->finder_info,  headerptr, BHH_TCSIZ );
+    headerptr += BHH_TCSIZ;
+    memcpy(&fh->finder_info.fdFlags,  headerptr, BHH_FLAGSIZ );
     fh->finder_info.fdFlags = fh->finder_info.fdFlags & mask;
-    headerptr += FLAGSIZ;
-    memcpy(&fh->forklen[ DATA ],  headerptr, DATASIZ );
+    headerptr += BHH_FLAGSIZ;
+    memcpy(&fh->forklen[ DATA ],  headerptr, BHH_DATASIZ );
     hqx.forklen[ DATA ] = ntohl( fh->forklen[ DATA ] );
-    headerptr += DATASIZ;
-    memcpy( &fh->forklen[ RESOURCE ], headerptr, RESSIZ );
+    headerptr += BHH_DATASIZ;
+    memcpy( &fh->forklen[ RESOURCE ], headerptr, BHH_RESSIZ );
     hqx.forklen[ RESOURCE ] = ntohl( fh->forklen[ RESOURCE ] );
-    headerptr += RESSIZ;
-    memcpy(&header_crc,  headerptr, CRCSIZ );
-    headerptr += CRCSIZ;
+    headerptr += BHH_RESSIZ;
+    memcpy(&header_crc,  headerptr, BHH_CRCSIZ );
+    headerptr += BHH_CRCSIZ;
     header_crc = ntohs( header_crc );
 
 /*
@@ -337,7 +355,7 @@ hqx_header_read( fh )
        fprintf( stderr, "observed crc\t\t%x\n", hqx.headercrc );
        fprintf( stderr, "\n" );
     }
-#endif
+#endif /* DEBUG >= 5 */
 
 /*
  * create and modify times are figured from right now
@@ -374,7 +392,7 @@ hqx_header_read( fh )
  * hqx_header_write.
  */
 
-hqx_header_write( fh )
+int hqx_header_write( fh )
     struct FHeader     *fh;
 {
     return( -1 );
@@ -387,7 +405,7 @@ hqx_header_write( fh )
  * it sets the pointers to the hqx7 buffer up to point to the valid data.
  */
 
-hqx7_fill( hqx7_ptr )
+int hqx7_fill( hqx7_ptr )
     u_char             *hqx7_ptr;
 {
     int                        cc;
@@ -458,7 +476,7 @@ u_char hqxlookup[] = {
  * OTHER when looking for any subsequent line.
  */
 
-skip_junk( line )
+int skip_junk( line )
 int                    line;
 {
     int                        found = NOWAY;
@@ -560,25 +578,25 @@ int                       line;
  * file is reached.
  */
 
-hqx_7tobin( outbuf, datalen ) 
+int hqx_7tobin( outbuf, datalen ) 
     char               *outbuf;
     int                        datalen;
 {
     static u_char      hqx8[3];
-    static char                hqx8i;
+    static int         hqx8i;
     static u_char      prev_hqx8;
     static u_char      prev_out;
     static u_char      prev_hqx7;
     static int         eofflag;
     u_char             hqx7[4];
-    char               hqx7i = 0;
+    int                        hqx7i = 0;
     char               *out_first;
     char               *out_last;
 
 #if DEBUG
     fprintf( stderr, "hqx_7tobin: datalen entering %d\n", datalen );
     fprintf( stderr, "hqx_7tobin: hqx8i entering %d\n", hqx8i );
-#endif
+#endif /* DEBUG */
 
     if ( first_flag == 0 ) {
        prev_hqx8 = 0;
@@ -591,7 +609,7 @@ hqx_7tobin( outbuf, datalen )
 
 #if DEBUG
     fprintf( stderr, "hqx_7tobin: hqx8i entering %d\n", hqx8i );
-#endif
+#endif /* DEBUG */
 
     out_first = outbuf;
     out_last = out_first + datalen;
@@ -651,14 +669,14 @@ hqx_7tobin( outbuf, datalen )
 #if HEXOUTPUT
            putc( hqx8i, rawhex );
             putc( hqx8[ hqx8i ], rawhex );
-#endif
+#endif /* HEXOUTPUT */
 
            if ( prev_hqx8 == RUNCHAR ) {
                if ( hqx8[ hqx8i ] == 0 ) {
                    *out_first = prev_hqx8;
 #if HEXOUTPUT
                    putc( *out_first, expandhex );
-#endif
+#endif /* HEXOUTPUT */
                    prev_out = prev_hqx8;
                    out_first++;
                }
@@ -666,7 +684,7 @@ hqx_7tobin( outbuf, datalen )
                    *out_first = prev_out;
 #if HEXOUTPUT
                    putc( *out_first, expandhex );
-#endif
+#endif /* HEXOUTPUT */
                    hqx8[ hqx8i ]--;
                    out_first++;
                }
@@ -682,7 +700,7 @@ hqx_7tobin( outbuf, datalen )
                *out_first = prev_hqx8;
 #if HEXOUTPUT
                putc( *out_first, expandhex );
-#endif
+#endif /* HEXOUTPUT */
                prev_out = prev_hqx8;
                out_first++;
            }