Providers
Debian Linux
System76
SDF
MinGW-W64
Verizon
Research
Search Engines
Bing
DuckDuckGo
Google
Metacrawler
SearX
Miscellaneous
Faqs and RFCs
Grokipedia
Open Directory Project
W3Schools Online Web Tutorials
Wikipedia
Multimedia
CTIS
For the Pigs Among Us
Family Photos
My House
My Photos (1999-2002?)
My Photos (2005)
Retro Computers
Minions of Mirth
Main
Criticals
Criticals (Single Player)
Ghaqua
Maps and Points of Interest
Miscellaneous
Monster Templates
Miscellaneous
Area Codes
Bard’s Tale
Dungeons & Dragons Online
My Blog
Quote of the Day
RogueBasin
Slashdot
The Adventuer’s Guild
Weather
GitHub:eprive/Z80-MBC3
Programming
Main
Across
Biorhythm
BMP Chips
Complex Roots
Magic Square
Magic Square(js)
Matrix(js)
More DOS Programs
Roll
Strip Dups (bash)
Wacky Wood-Worker
How To
Enlightenment 0.16.7.2 Startup Patch
How to Create an OS X Iconset
My RedHat Howto
SSH to VMS (Deathrow OpenVMS Cluster)
Tools
Allowable Mortgage Interest
Dates and Mileage
Day of the Year
Fun With Time
Downloads
Educational
Utilities
frame.c
/**************************************************************************/ /* FRAME.C M. CHAPPELL 20260606 */ /* */ /* Allow creating of a menu frame in a terminal */ /* */ /* Usage : frame line_type string [screen_width] */ /* */ /* Where line_type is */ /* */ /* T: Top Border */ /* M: Middle Border */ /* B: Bottom Border */ /* F: Framed Line */ /* E: Emphasized Line (Bold) */ /* C: Centered Line (No Frame) */ /* */ /* Default to 80 column screen-width */ /* */ /* Length of the string to be centered is increased by 2 for the borders. */ /* */ /* Borders ignore contents but use string for length. */ /* */ /* Max string width is screen_width - 3 */ /* */ /* Assumes: */ /* */ /* Graphics On : "\x1b(0" */ /* Graphics Off : "\x1b(B" */ /* Bold : "\x1b[1m" */ /* Normal : "\x1b[22m" */ /* */ /* Frame: */ /* */ /* lqqk */ /* x x */ /* tqqu */ /* x x */ /* mqqj */ /* */ /* Returns Offset to center string, -1 on error */ /**************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define VERSION "Version 0.1" #define GRON "\x1b(0" #define GOFF "\x1b(B" #define BOLD "\x1b[1m" #define NORM "\x1b[22m" #define HZ 'q' #define VR GRON "x" GOFF #define TL "l" #define TR "k" #define ML "t" #define MR "u" #define BL "m" #define BR "j" void usage(void) { fprintf(stderr, "Usage : frame line_type string [screen_width]\n" "\n" "Where line_type is:\n" "\n" "-T: Top Border\n" "-M: Middle Border\n" "-B: Bottom Border\n" "-F: Framed Line\n" "-E: Emphasized Line (Bold)\n" "-C: Centered Line (No Frame)\n" "\n" "-H: Usage\n" "-U: Usage\n" "-V: Version info\n" "\n" "Default to 80 column screen-width.\n" ); } void repeat(int c, int n) { int i; for (i=0; i<n; i++) putchar(c); } int main(int argc, char **argv) { int width = 80; int offset; int length; int c; /* for (int i=0; i<argc; i++) printf("%d: %s\n", i, argv[i]); */ if (argc==1) { usage(); return -1; } c = tolower(argv[1][1]); switch (c) { case 't': case 'm': case 'b': case 'f': case 'e': case 'c': break; case 'h': case 'u': usage(); return 0; break; case 'v': printf("FRAME " VERSION "\n"); return 0; break; default: fprintf(stderr, "Line_type must be -T, -M, -B, -F, -E, -C.\n"); return -1; break; }; if ((argc<3)||(argc>4)) { usage(); return -1; } if (argc==4) { width = atoi(argv[3]); } if (width<3) { fprintf(stderr, "Screen_width must be greater than 2.\n"); return -1; } /* printf("LINE: %d\n", __LINE__); */ length = strlen(argv[2]); length = (length>width-3)?width-3:length; /* max length must fit screen */ offset = (width-length)/2-1; offset = (offset>1)?offset:0; /* offset cannot be less than 0 */ repeat(' ', offset); switch (c) { case 't': printf(GRON TL); repeat(HZ, length); printf(TR GOFF "\n"); break; case 'm': printf(GRON ML); repeat(HZ, length); printf(MR GOFF "\n"); break; case 'b': printf(GRON BL); repeat(HZ, length); printf(BR GOFF "\n"); break; case 'f': printf(VR "%.*s" VR "\n", length, argv[2]); break; case 'e': printf(VR BOLD "%.*s" NORM VR "\n", length, argv[2]); break; case 'c': printf("%.*s\n", length, argv[2]); break; }; return offset; }
This source has been viewed 3 times.
Wednesday, 12 August 2026
Michael J. Chappell
Contact me at:
mcsuper5@freeshell.org