📄 make_lrec.c
字号:
/*===========================================================================*//* DMC Interim out | | *//*===========================================================================*//* Name: Purpose: Usage: Input: Output: error = error value; FALSE if no error, nonzero otherwise. It contains values of MESSAGE, WARNING, ERROR, or FATAL (see constants.h) Externals: Debug - setting of environment variable DEBUG (globals.h) Messages: Warnings: Errors: Fatals: Called by: Calls to: error_handler - handle error conditions Algorithm: Notes: none Problems: none known Debug: level D_MIN - print out start and finish notices level D_MED - level D_MAX - References: none Language: C, more or less ANSI standard, under Sun OS 3.5 Revisions: 02/ /89 Dennis O'Neill original version 03/06/89 Mark Wiederspahn re-written to remove double move 06/27/89 mw use %c in scanf of btype and blen to avoid errors with leading spaces*/#include "output.h"int make_lrec (blockettes, type, length, count )char *blockettes; /* bytes to be logical rec'd */char type; /* data type V, A, S, T */int length; /* length of blockettes */int *count; /* number of log recs we made */{ int n; /* general purpose int */ int continuation; /* continuation flag */ int next_continuation; /* continuation flag */ char *bottom; /* bottom addr of chunk */ char *top; /* top addr of chunk */ int data_len; /* size of data area in Lrecl */ int btype; /* type of a blockette */ int blen; /* length of a blockette */ int error; /* error flag */ char ctype[3+1]; /* char version of btype */ char clen[4+1]; /* char version of blen */ if (Debug >= D_MIN) fprintf (D_OUT, "[make_lrec] Start\n"); /*=====================================*//*=================| make logical records |=================*/ /*=====================================*/ continuation = FALSE; top = bottom = blockettes; data_len = Lrecl - sizeof( struct hdr_logrec ); *count = 0; ctype[3] = '\0'; clen[4] = '\0'; error = 0; while( length > 0 ) {/* * while another blockette will fit, include it in this record. */ if( Debug >= D_SOME ) fprintf( D_OUT,"[make_lrecl] len=%d\n",length ); while( (n = top-bottom) < data_len && length > 0 ) { if( sscanf( top, "%3c%4c", ctype, clen ) != 2 ) if( error=error_handler(FATAL,"[make_lrecl] bad blockette")) return( error ); btype = atoi( ctype ); blen = atoi( clen ); if( Debug >= D_SOME ) fprintf( D_OUT,"[make_lrecl] %c %d %d %.*s\n", type, btype, blen, min(blen-7,30), top+7 ); top += blen; length -= blen; }/* * if we did not run out of blockettes, then we are beyond a lrecl size. * if the end of the previous blockette is close to the end of the record, * then blank pad it to the end, and start the next blockette in the next * record. If the length of these blockettes is longer than the record, * then just output to logical records in pieces. */ if( Debug >= D_SOME ) fprintf( D_OUT,"[make_lrecl] before pad blen=%d n=%d len=%d\n", blen, n, length ); next_continuation = FALSE; if( n >= data_len ) { if( n-blen > data_len - ENDPAD ) { n = n - blen; if( Debug >= D_SOME ) fprintf( D_OUT, "[make_lrecl] pad from %d. next blockette len is %d\n", n, blen ); } } if( n > data_len ) { next_continuation = TRUE; n = data_len; } if( Debug >= D_SOME ) fprintf( D_OUT,"[make_lrecl] flush %d\n", n); if( error=build_lrec( bottom, type, continuation, n ) ) if( error=error_handler( FATAL,"[make_lrec] build_lrec failed") ) return( error ); (*count)++; continuation = next_continuation; bottom += n; } while( (n=top-bottom) > 0 ) { next_continuation = FALSE; if( n > data_len ) { next_continuation = TRUE; n = data_len; } if( Debug >= D_SOME ) fprintf( D_OUT,"[make_lrecl] flush %d\n", n); if( error=build_lrec( bottom, type, continuation, n ) ) if( error=error_handler( FATAL,"[make_lrec] build_lrec failed") ) return( error ); (*count)++; bottom += n; continuation = next_continuation; } if (Debug >= D_MIN) fprintf (D_OUT, "[make_lrec] end\n"); return( error );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -