home *** CD-ROM | disk | FTP | other *** search
- /* m4convert.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved. */
-
- #include "p4misc.h"
- #include "d4all.h"
- #include "u4error.h"
-
- #include <string.h>
- #ifndef UNIX
- #include <io.h>
- #endif
-
- typedef struct memo_header_st
- {
- long next_block ;
- char zero[4] ;
- char file_name[8] ;
- char zero2[2] ;
- int x102 ;
- int block_size ;
- char zero3[2] ;
- } MEMO_HEADER ;
-
-
- m4renamed( char *file_name )
- {
- int rc, hand ;
- MEMO_HEADER hdr ;
- char name[90] ;
-
- u4name_full( name, file_name, "DBT" ) ;
- hand = u4open( name, 0 ) ;
- if ( hand < 0 ) return -1 ;
-
- lseek( hand, 0L, 0 ) ;
- rc = read( hand, (char *) &hdr, (unsigned int) sizeof(hdr) ) ;
- if ( rc != (int) sizeof(hdr) )
- {
- u4error( E_READ, "Memo File: ", file_name, (char *) 0 ) ;
- return -1 ;
- }
-
- u4name_part( hdr.file_name, file_name, 0,0 ) ;
- u4upper( hdr.file_name ) ;
-
- lseek( hand, 0L, 0 ) ;
- rc = write( hand, (char *) &hdr, (unsigned int) sizeof(hdr) ) ;
- if ( rc != (int) sizeof(hdr) )
- {
- u4error( E_WRITE, "Memo File: ", file_name, (char *) 0 ) ;
- return -1 ;
- }
-
- close( hand ) ;
-
- return 0 ;
- }
-
-
- m4convert( char *file_name )
- {
- char memo_name[90] ;
- int hand, rc ;
- MEMO_HEADER m_hdr ;
- long len ;
-
- memset( (char *) &m_hdr, 0, sizeof(m_hdr) ) ;
-
- u4name_part( memo_name, file_name, 1,0 ) ;
- u4name_full( memo_name, memo_name, ".DBT" ) ;
-
- hand = u4open( memo_name, 0 ) ;
- if ( hand < 0 ) return -1 ;
-
- lseek( hand, 0L, 0 ) ;
- rc = read( hand, (char *) &m_hdr, (unsigned int) sizeof(long) ) ;
- if ( rc != sizeof(long) )
- {
- u4error( E_READ, "Memo File: ", file_name, (char *) 0 ) ;
- return -1 ;
- }
-
- if ( (len = filelength(hand)) < 0L)
- {
- u4error( E_INTERNAL, (char *) 0 ) ;
- return -1L ;
- }
- m_hdr.next_block = (len+0x1FF)/0x200 ;
-
- u4name_part( m_hdr.file_name, file_name, 0,0 ) ;
- u4upper( m_hdr.file_name ) ;
- m_hdr.x102 = 0x102 ;
- m_hdr.block_size = 0x200 ; /* 512 */
-
- lseek( hand, 0L, 0 ) ;
- if ( write( hand, (char *) &m_hdr, (unsigned int) sizeof(m_hdr))
- != (int) sizeof(m_hdr) )
- {
- close( hand ) ;
- u4error( E_WRITE, memo_name, (char *) 0 ) ;
- return( -1 ) ;
- }
-
- close( hand ) ;
-
- return 0 ;
- }
-