/** * Nullprompt is a fast, pretty, and basic PS1 prompt program * Copyright (C) 2024 Aaron Ball, nullspoon at oper dot io * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "common.h" void rtrim(char* buf) { char* c = &buf[0]; while(*c != 0) // Find the end c++; while(*c == ' ' || *c == '\t' || *c == '\n' || *c == 0) // Back it up c--; *(c+1) = 0; // null terminate } // Ellipses a string to the specified length void ellipt(char* buf, char* outbuf, int size) { int buflen = strlen(buf); // Clear the out buffer memset(outbuf, 0, size); if(buflen < size) { strcpy(outbuf, buf); return; } // Copy in the front with the ellipse strncpy(outbuf, buf, (size/2)-3); strcat(outbuf, "..."); // Copy in the back end // NOTE: Extra +1 for rounding errors to prevent buffer overflows strcpy(&outbuf[(size/2)], &buf[buflen - (size/2) +1]); }