Skip to content
Snippets Groups Projects
Commit 2cb099b3 authored by rswindell's avatar rswindell
Browse files

New options:

 -<columns> insert conditional-newlines to force wrap (e.g. -80)
 -newline   append a newline (CRLF) sequence to the output filea

The -<columns> option allows you to take "80-column ANSIs", artwork which
uses 80 columns and assumes the cursor will wrap to the next line
automatically, and insert Ctrl-A/ (conditional-newline) which allows the
file to be viewed nicely on wider terminals. Very cool.

Also added -newline (which can be used multiple times) to append one
(or more) newline sequences to the output file.

Use uppercase for Ctrl-AN and Ctrl-AL when -clear is used.
parent 3944d046
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,8 @@ static void print_usage(const char* prog)
fprintf(stderr,"\nSynchronet ANSI-Terminal-Sequence to Ctrl-A-Code Conversion Utility v%s\n",revision);
fprintf(stderr,"\nusage: %s infile.ans [outfile.asc | outfile.msg] [[option] [...]]\n",prog);
fprintf(stderr,"\noptions:\n\n");
fprintf(stderr,"-<columns> insert conditional-newlines to force wrap (e.g. -80)\n");
fprintf(stderr,"-newline append a newline (CRLF) sequence to output file\n");
fprintf(stderr,"-clear insert a clear screen code at beginning of output file\n");
fprintf(stderr,"-pause append a pause (hit a key) code to end of output file\n");
fprintf(stderr,"-space use space characters for cursor-right movement/alignment\n");
......@@ -66,10 +68,13 @@ int main(int argc, char **argv)
int i,ch,ni;
FILE *in=stdin;
FILE *out=stdout;
int cols=0;
int column=0;
int delay=0;
int clear=0;
int pause=0;
int space=0;
int newline=0;
if(argc<2) {
print_usage(argv[0]);
......@@ -94,6 +99,10 @@ int main(int argc, char **argv)
pause = 1;
else if(strcmp(argv[i], "-space") == 0)
space = 1;
else if(strcmp(argv[i], "-newline") == 0)
newline++;
else if(isdigit(argv[i][1]))
cols = atoi(argv[i] + 1);
else {
print_usage(argv[0]);
return 0;
......@@ -112,7 +121,7 @@ int main(int argc, char **argv)
}
if(clear)
fprintf(out,"\1n\1l");
fprintf(out,"\1N\1L");
esc=0;
while((ch=fgetc(in))!=EOF && ch != CTRL_Z) {
if(ch=='[' && esc) { /* ANSI escape sequence */
......@@ -152,15 +161,18 @@ int main(int argc, char **argv)
case 'H':
if(n[0]<=1 && n[1]<=1) /* home cursor */
fputs("\1`", out);
column = 0;
break;
case 'J':
if(n[0]==2) /* clear screen */
fputs("\1L",out); /* ctrl-aL */
else if(n[0]==0) /* clear to EOS */
fputs("\1J",out); /* ctrl-aJ */
column = 0;
break;
case 'K':
fputs("\1>",out); /* clear to eol */
column = cols ? (cols - 1) : 79;
break;
case 'm':
for(i=0;i<ni;i++) {
......@@ -248,9 +260,11 @@ int main(int argc, char **argv)
fprintf(out, "%*s", n[0], " ");
else
fprintf(out,"\1%c",0x7f+n[0]);
column += n[0];
break;
case 'D': /* cursor left */
if(n[0]>=80)
column -= n[0];
if(n[0] >= column)
fprintf(out,"\1[");
else
while(n[0]) {
......@@ -271,11 +285,29 @@ int main(int argc, char **argv)
esc=1;
else {
esc=0;
fputc(ch,out);
switch(ch) {
case '\r':
case '\n':
fputc(ch,out);
column = 0;
break;
default:
if(cols && column >= cols) {
fprintf(out, "\1/"); // Conditional-newline
column = 0;
}
fputc(ch,out);
column++;
break;
}
if(delay && (ftell(out)%delay)==0)
fprintf(out,"\1,");
}
if(delay && (ftell(out)%delay)==0)
fprintf(out,"\1,");
if(column < 0)
column = 0;
}
while(newline--)
fprintf(out,"\r\n");
if(pause)
fprintf(out,"\1p");
return(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment