/* * PROGRAM NAME: * ------------- * INDENT.CPL * Concordance(tm) Information Retrieval System, Professional Edition * * COPYRIGHT: * ---------- * Copyright (c) 1996 Dataflight Software. * All Rights Reserved. * 2337 Roscomare Road, Suite 11 * Los Angeles, CA 90077 * * ALL RIGHTS RESERVED. * * Unauthorized distribution, adaptation or use may be * subject to civil and criminal penalties. * * SYNOPSIS: * --------- * This is a program to be used with report writer. It indents a * given field to a specified column and width. This is particularly * useful with single column reports. It allows the report writer * to make Browse-like print-outs. * * Use the function as follows; * * indent("FIELD", "PROMPT", STARTATCOLUMN, WRAPWIDTH) * * for example; * * indent("AUTHOR", "Authored by", 10, 20) * * This would produce output [Authored by: + AUTHOR field contents], starting at * column 10, printing 20 characters, then wrapping and starting again at column 10. */ main () { reportfs(0); } indent (text fieldName, fieldText; int column, width) { text buffer; int db; int start; int i, endChar; char CR[2], LF[2], CRLF[3]; /* CR */ CR[0] = 13; CR[1] = 0; LF[0] = 10; LF[1] = 0; CRLF[0] = 13; CRLF[1] = 10; CRLF[2] = 0; /* Set the buffer */ buffer = db->fieldName; /* Wrap the field into width characters */ wrap(buffer, width); /* Search through the buffer, look for CR's */ /* replace them with spaces */ start = 1; while (i = match(buffer, CR, start)) { endChar = i - 1; if (start == 1) { if (substr(buffer, i+1, 1) == LF) i = i + 1; buffer = fieldText + rep(" ", (column - len(fieldText))) + substr(buffer, 1, endChar) + CRLF + rep(" ", column) + substr(buffer, i + 1); start = i + column + 1; } else { /* Make sure that the next character is not LF */ if (substr(buffer, i+1, 1) == LF) i = i + 1; /* Set the buffer */ buffer = substr(buffer, 1, endChar) + CRLF + rep(" ", column) + substr(buffer, i + 1); /* Set the next offset */ start = i + column + 1; } } /* Account for single entry text fields as well */ if ((i == 0) and (start == 1)) buffer = fieldText + rep(" ", (column - len(fieldText))) + buffer; return (buffer); }