HP 9000 User Manual page 155

Computers
Hide thumbs Also See for 9000:
Table of Contents

Advertisement

A
Version #2 (Code Set Independent)
The following program also folds character strings to fit within a designated
text region. By using
C_COLWIDTH, FIRSTof2,
and
SECof2
macros, the program
now operates correctly on single-byte and multi-byte data. This program works
for both HP15 and the EUC encoding schemes.
#include <stdio.h>
#include <locale.h>
#include <nl_ctype .h>
#define WIDTH 5
main (argc, argv)
int argcj
char **argvj
{
/* allocate additional array storage to accommodate multi-byte data */
unsigned char output_array[WIDTH * 2 + 1], *output_ptr, *input_ptrj
int c, counter, screen_sizej
if (!setlocale(LC_ALL,""» {
/* set correct locale */
fprintf(stderr, "error: cannot set locale\n")j
}
input_ptr = argv[l]j
counter = 0
output_ptr = output_array
while (c = *input_ptr++) {
screen_size = C_COLWIDTH(c)j
of current character */
/* set input_ptr to beginning
of the string to be folded */
/* initialize character counter */
/* set output_ptr to beginning
of the output array */
/* get a char until end of string */
/* determine display column width
if (counter + screen_size > WIDTH) {
/* if output array is complete,
}
process it */
output_ptr = '\O'j
array */
puts(output_arraY)j
counter = OJ
output_ptr = output_array
beginning of array
*/
counter += screen_size;
increment counter */
/* null terminate the output
/* print the output array */
/* reset counter */
/* reset output pointer to
/* if output array not complete,
*output_ptr++ = Cj
/* set area pointed to by output_ptr
to c, then increment output_ptr */
if (FIRSTof2(c)
&
SECof2(*input_ptr»
/* if valid two-byte character, */
*output_ptr++ = *input_ptr++j
/* put second byte in output
array and increment input and
A-8
SpeCial Topics for HP's 16-bit Interfaces

Advertisement

Table of Contents
loading

Table of Contents