michael@0: /* michael@0: * Simple test driver for MPI library michael@0: * michael@0: * Test 6: Output functions michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "mpi.h" michael@0: michael@0: void print_buf(FILE *ofp, char *buf, int len) michael@0: { michael@0: int ix, brk = 0; michael@0: michael@0: for(ix = 0; ix < len; ix++) { michael@0: fprintf(ofp, "%02X ", buf[ix]); michael@0: michael@0: brk = (brk + 1) & 0xF; michael@0: if(!brk) michael@0: fputc('\n', ofp); michael@0: } michael@0: michael@0: if(brk) michael@0: fputc('\n', ofp); michael@0: michael@0: } michael@0: michael@0: int main(int argc, char *argv[]) michael@0: { michael@0: int ix, size; michael@0: mp_int a; michael@0: char *buf; michael@0: michael@0: if(argc < 2) { michael@0: fprintf(stderr, "Usage: %s \n", argv[0]); michael@0: return 1; michael@0: } michael@0: michael@0: printf("Test 6: Output functions\n\n"); michael@0: michael@0: mp_init(&a); michael@0: michael@0: mp_read_radix(&a, argv[1], 10); michael@0: michael@0: printf("\nConverting to a string:\n"); michael@0: michael@0: printf("Rx Size Representation\n"); michael@0: for(ix = 2; ix <= MAX_RADIX; ix++) { michael@0: size = mp_radix_size(&a, ix); michael@0: michael@0: buf = calloc(size, sizeof(char)); michael@0: mp_toradix(&a, buf, ix); michael@0: printf("%2d: %3d: %s\n", ix, size, buf); michael@0: free(buf); michael@0: michael@0: } michael@0: michael@0: printf("\nRaw output:\n"); michael@0: size = mp_raw_size(&a); michael@0: buf = calloc(size, sizeof(char)); michael@0: michael@0: printf("Size: %d bytes\n", size); michael@0: michael@0: mp_toraw(&a, buf); michael@0: print_buf(stdout, buf, size); michael@0: free(buf); michael@0: michael@0: mp_clear(&a); michael@0: michael@0: return 0; michael@0: }