📄 starbox.cc
字号:
/*
Name starbox - puts title in a centered box of stars.
Usage #include "usual.h"
#include "tools.h"
char* starbox(char *title, char terminator);
Prototype in tools.h
Description title is a character string. The string is made up of
concatonated lines. A line is made up of 0-68 characters
followed by a slash (default). Examples are:
cout << starbox("//line 1/line 2/line 3///");
cout << starbox("\n\nline 1\nline 2\nline 3\n\n\n",'\n');
Return value Character string.
Functions Library: strcat, strchr, strlen
called Tools: (none)
Sublib: (none)
*/
#include "usual.h"
#include "tools.h"
char * starbox(char *title, char terminator)
{
char border[81],tab[81],work[256],middle[81];
char *line, *begin, *end, *t;
int i,pad,mpad,linesize;
long int length, cum_length;
char starbox_str_pointer[1024];
long int starbox_str_length = 1024;
cum_length = 0;
*starbox_str_pointer = '\0';
for (i=0; i<70; i++)
border[i] = '*';
border[70] = '\n'; border[71] = '\0';
((LINESIZE<72)||(LINESIZE>133)) ? (linesize=133) : (linesize=LINESIZE);
pad = (linesize-72)/2+1;
for (i=0; i<pad; i++)
tab[i] = ' ';
tab[pad] = '\0';
work[0]='\n'; work[1]='\n'; work[2]='\0';
line = strcat(work,tab);
line = strcat(work,border);
cum_length += strlen(line);
if (cum_length < starbox_str_length)
strcat(starbox_str_pointer,line);
else
return "Error, starbox, title too long.";
begin = title;
while ( (end=strchr(begin,terminator)) != NULL ) {
length = end - begin;
if (length > 68) return "Error, starbox, line too long.";
middle[0] = '*';
mpad = (68-length)/2+1;
for (i=1; i<=mpad; i++) middle[i] = ' ';
t = &middle[mpad];
while (begin < end) *t++ = *begin++;
begin++;
for (i=mpad+length; i<=68; i++) middle[i]=' ';
middle[69]='*'; middle[70]='\n'; middle[71]='\0';
work[0]='\0';
line = strcat(work,tab);
line = strcat(work,middle);
if (cum_length < starbox_str_length)
strcat(starbox_str_pointer,line);
else
return "Error, starbox, title too long.";
}
work[0]='\0';
line = strcat(work,tab);
line = strcat(work,border);
if (cum_length < starbox_str_length)
strcat(starbox_str_pointer,line);
else
return "Error, starbox, title too long.";
return starbox_str_pointer;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -