- Adapted indenation to new agreed upon system
This commit is contained in:
@@ -154,7 +154,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef FORTIFY
|
||||
#include <fortify.h>
|
||||
#include <fortify.h>
|
||||
#endif
|
||||
|
||||
#include <sinq_prototypes.h>
|
||||
@@ -167,110 +167,157 @@
|
||||
**--------------------------------------------------------------------------
|
||||
** MakeCharPrintable: makes a single character printable.
|
||||
*/
|
||||
int MakeCharPrintable (char *out, int out_size, char in) {
|
||||
int MakeCharPrintable(char *out, int out_size, char in)
|
||||
{
|
||||
/* =================
|
||||
**
|
||||
** Return value is number of chars put into *out.
|
||||
*/
|
||||
char buff[8], *pntr;
|
||||
char buff[8], *pntr;
|
||||
|
||||
pntr = buff;
|
||||
pntr = buff;
|
||||
|
||||
if ((in & 0x80) != 0) { /* Parity bit set? */
|
||||
*pntr++ = '^'; /* Yes. Put a '^' in the buffer .. */
|
||||
in = in & 0x7f; /* .. and remove the parity bit. */
|
||||
}
|
||||
|
||||
switch (in) {
|
||||
case '^': *pntr++ = '\\'; *pntr++ = '^'; break;
|
||||
case '\\': *pntr++ = '\\'; *pntr++ = '\\'; break;
|
||||
case '\000': *pntr++ = '\\'; *pntr++ = '0'; break;
|
||||
case '\007': *pntr++ = '\\'; *pntr++ = 'a'; break;
|
||||
case '\010': *pntr++ = '\\'; *pntr++ = 'b'; break;
|
||||
case '\011': *pntr++ = '\\'; *pntr++ = 't'; break;
|
||||
case '\012': *pntr++ = '\\'; *pntr++ = 'n'; break;
|
||||
case '\013': *pntr++ = '\\'; *pntr++ = 'v'; break;
|
||||
case '\014': *pntr++ = '\\'; *pntr++ = 'f'; break;
|
||||
case '\015': *pntr++ = '\\'; *pntr++ = 'r'; break;
|
||||
default:
|
||||
if ((in < ' ') || (in > '~')) {
|
||||
pntr += sprintf (pntr, "\\%3.3o", in);
|
||||
}else {
|
||||
*pntr++ = in;
|
||||
}
|
||||
}
|
||||
out_size = (out_size > (pntr - buff)) ? (pntr - buff) : out_size;
|
||||
memcpy (out, buff, out_size);
|
||||
return out_size;
|
||||
if ((in & 0x80) != 0) { /* Parity bit set? */
|
||||
*pntr++ = '^'; /* Yes. Put a '^' in the buffer .. */
|
||||
in = in & 0x7f; /* .. and remove the parity bit. */
|
||||
}
|
||||
|
||||
switch (in) {
|
||||
case '^':
|
||||
*pntr++ = '\\';
|
||||
*pntr++ = '^';
|
||||
break;
|
||||
case '\\':
|
||||
*pntr++ = '\\';
|
||||
*pntr++ = '\\';
|
||||
break;
|
||||
case '\000':
|
||||
*pntr++ = '\\';
|
||||
*pntr++ = '0';
|
||||
break;
|
||||
case '\007':
|
||||
*pntr++ = '\\';
|
||||
*pntr++ = 'a';
|
||||
break;
|
||||
case '\010':
|
||||
*pntr++ = '\\';
|
||||
*pntr++ = 'b';
|
||||
break;
|
||||
case '\011':
|
||||
*pntr++ = '\\';
|
||||
*pntr++ = 't';
|
||||
break;
|
||||
case '\012':
|
||||
*pntr++ = '\\';
|
||||
*pntr++ = 'n';
|
||||
break;
|
||||
case '\013':
|
||||
*pntr++ = '\\';
|
||||
*pntr++ = 'v';
|
||||
break;
|
||||
case '\014':
|
||||
*pntr++ = '\\';
|
||||
*pntr++ = 'f';
|
||||
break;
|
||||
case '\015':
|
||||
*pntr++ = '\\';
|
||||
*pntr++ = 'r';
|
||||
break;
|
||||
default:
|
||||
if ((in < ' ') || (in > '~')) {
|
||||
pntr += sprintf(pntr, "\\%3.3o", in);
|
||||
} else {
|
||||
*pntr++ = in;
|
||||
}
|
||||
}
|
||||
out_size = (out_size > (pntr - buff)) ? (pntr - buff) : out_size;
|
||||
memcpy(out, buff, out_size);
|
||||
return out_size;
|
||||
}
|
||||
|
||||
/*
|
||||
**--------------------------------------------------------------------------
|
||||
** MakeMemPrintable: alternative version of MakePrintable.
|
||||
*/
|
||||
char *MakeMemPrintable (
|
||||
char *MakeMemPrintable(
|
||||
/* ================
|
||||
*/ char *out,
|
||||
int out_size,
|
||||
char *in,
|
||||
int in_len) {
|
||||
*/ char *out,
|
||||
int out_size, char *in, int in_len)
|
||||
{
|
||||
|
||||
int i;
|
||||
char *pntr;
|
||||
int i;
|
||||
char *pntr;
|
||||
|
||||
if (out_size <= 0) return out;
|
||||
|
||||
while ((out_size > 1) && (in_len > 0)) {
|
||||
i = MakeCharPrintable (out, (out_size - 1), *in);
|
||||
out += i; out_size -= i;
|
||||
in++; in_len--;
|
||||
}
|
||||
*out = NIL;
|
||||
if (out_size <= 0)
|
||||
return out;
|
||||
|
||||
while ((out_size > 1) && (in_len > 0)) {
|
||||
i = MakeCharPrintable(out, (out_size - 1), *in);
|
||||
out += i;
|
||||
out_size -= i;
|
||||
in++;
|
||||
in_len--;
|
||||
}
|
||||
*out = NIL;
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
**--------------------------------------------------------------------------
|
||||
** MakePrint: Make all characters in a buffer printable.
|
||||
*/
|
||||
char *MakePrint (char *chr) {
|
||||
char *MakePrint(char *chr)
|
||||
{
|
||||
/* =========
|
||||
*/
|
||||
int len, i;
|
||||
|
||||
for (i = 0; chr[i] != NIL; i++) chr[i] &= 0x7F;
|
||||
int len, i;
|
||||
|
||||
len = strlen (chr);
|
||||
if (len <= 0) return chr;
|
||||
|
||||
if (chr[len-1] == '\r') chr[len-1] = NIL;
|
||||
if (chr[len-1] == '\n') chr[len-1] = NIL;
|
||||
|
||||
for (i = 0; chr[i] != NIL; i++) {
|
||||
if (chr[i] < ' ') chr[i] = '.';
|
||||
if (chr[i] == 0x7F) chr[i] = '.';
|
||||
}
|
||||
for (i = 0; chr[i] != NIL; i++)
|
||||
chr[i] &= 0x7F;
|
||||
|
||||
len = strlen(chr);
|
||||
if (len <= 0)
|
||||
return chr;
|
||||
|
||||
if (chr[len - 1] == '\r')
|
||||
chr[len - 1] = NIL;
|
||||
if (chr[len - 1] == '\n')
|
||||
chr[len - 1] = NIL;
|
||||
|
||||
for (i = 0; chr[i] != NIL; i++) {
|
||||
if (chr[i] < ' ')
|
||||
chr[i] = '.';
|
||||
if (chr[i] == 0x7F)
|
||||
chr[i] = '.';
|
||||
}
|
||||
|
||||
return chr;
|
||||
}
|
||||
|
||||
/*
|
||||
**--------------------------------------------------------------------------
|
||||
** MakePrintable: improved version of MakePrint.
|
||||
*/
|
||||
char *MakePrintable (
|
||||
char *MakePrintable(
|
||||
/* =============
|
||||
*/ char *out,
|
||||
int out_size,
|
||||
char *in) {
|
||||
*/ char *out,
|
||||
int out_size, char *in)
|
||||
{
|
||||
|
||||
int i;
|
||||
char *pntr;
|
||||
int i;
|
||||
char *pntr;
|
||||
|
||||
if (out_size <= 0) return out;
|
||||
|
||||
while ((out_size > 1) && (*in != NIL)) {
|
||||
i = MakeCharPrintable (out, (out_size - 1), *in);
|
||||
in++; out += i; out_size -= i;
|
||||
}
|
||||
*out = NIL;
|
||||
if (out_size <= 0)
|
||||
return out;
|
||||
|
||||
while ((out_size > 1) && (*in != NIL)) {
|
||||
i = MakeCharPrintable(out, (out_size - 1), *in);
|
||||
in++;
|
||||
out += i;
|
||||
out_size -= i;
|
||||
}
|
||||
*out = NIL;
|
||||
return out;
|
||||
}
|
||||
|
||||
/*-------------------------------------------- End of MakePrint.C =======*/
|
||||
|
||||
Reference in New Issue
Block a user