?? dkchcbd.c
字號:
/*
Copyright (c) 2003, Dan Kranz and Arnold Rom
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* The names of its contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* The nf binary integers stored in array are converted to ASCII tokens.
These are stored in block at the nf fields.
The entries in field are paired, i.e. field start, field length.
The length parameters of the field entries are used to control
conversion as follows:
field length = 0 The number is ignored.
field length > 0 The number is converted and stored.
The output field is set to blanks before
conversion. The resulting ASCII number is right
justified in the field. Zero valued numbers are
not moved to block.
field length < 0 Use the absolute value of field length to
determine the output field length. The output
field is set to zeros before conversion. This
allows us to produce numbers with leading zeros.
Oversized numbers are truncated on the left.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <roots.h>
void chcbd(long *array, void *block, long *fields, long *nf)
{
char number[80];
BYTE *bpt;
long n, field_start, field_length;
int digits;
for (n = *nf; n--;) {
field_start = *fields++;
field_length = *fields++;
/* Ignore number if output field length equal zero */
if (field_length != 0) {
bpt = (BYTE*) block - 1 + field_start;
/* Initialize field with leading zeros if field_length < 0 */
if (field_length < 0) {
field_length = -field_length;
memset(bpt,'0', (size_t) field_length);
}
/* Otherwise fill field with blanks */
else memset(bpt,' ', (size_t) field_length);
/* No conversion if number = zero */
if (*array != 0) {
/* Convert to ascii */
sprintf(number,"%ld", *array);
digits = strlen(number);
/* If the number doesn't fit field */
if (digits > field_length) {
/* Output field width is greater than zero */
if (*(fields-1) > 0)
memset(bpt,'*', (size_t) field_length);
/* Truncate digits on left, move remaining digits to block */
else
memcpy(bpt,&number[digits-field_length],digits);
}
/* Move number to block(field) */
else {
bpt += (field_length - digits);
memcpy(bpt,number,digits);
}
}
}
/* Next number */
++array;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -