/* * Copyright 1998 by Albert Cahalan; all rights resered. * This file may be used subject to the terms and conditions of the * GNU Library General Public License Version 2, or any later version * at your option, as published by the Free Software Foundation. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. */ #include #include "../proc/procps.h" #include "common.h" /* sanitize a string, without the nice BSD library function: */ /* strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH) */ int octal_escape_str(char *restrict dst, const char *restrict src, size_t n){ unsigned char c; char d; size_t i; const char codes[] = "Z------abtnvfr-------------e----" " *******************************" /* better: do not print any space */ "****************************\\***" "*******************************-" "--------------------------------" "********************************" "********************************" "********************************"; for(i=0; i n) goto leave; i += 4; *(dst++) = '\\'; *(dst++) = "01234567"[c>>6]; *(dst++) = "01234567"[(c>>3)&07]; *(dst++) = "01234567"[c&07]; break; default: if(i+2 > n) goto leave; i += 2; *(dst++) = '\\'; *(dst++) = d; break; } } leave: *(dst++) = '\0'; return i; } /* sanitize a string via one-way mangle */ int simple_escape_str(char *restrict dst, const char *restrict src, size_t n){ unsigned char c; size_t i; const char codes[] = "Z-------------------------------" "********************************" "********************************" "*******************************-" "--------------------------------" "********************************" "********************************" "********************************"; for(i=0; i 1) && src[1]) dst[i++] = ' '; src++; } return i; }