--- sbbs/src/sbbs3/asc2ans.c 2018/04/24 16:41:23 1.1.1.1 +++ sbbs/src/sbbs3/asc2ans.c 2018/04/24 16:43:38 1.1.1.2 @@ -2,13 +2,13 @@ /* Converts Synchronet Ctrl-A codes into ANSI escape sequences */ -/* $Id: asc2ans.c,v 1.1.1.1 2018/04/24 16:41:23 root Exp $ */ +/* $Id: asc2ans.c,v 1.1.1.2 2018/04/24 16:43:38 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -36,10 +36,11 @@ ****************************************************************************/ #include -#include /* toupper */ -#include /* strcmp */ +#include /* toupper */ +#include /* strcmp */ -#define ANSI fprintf(out,"\x1b[") +#define CTRL_A '\1' +#define ANSI fprintf(out,"\x1b[") int main(int argc, char **argv) { @@ -48,7 +49,7 @@ int main(int argc, char **argv) FILE* in; FILE* out; - sscanf("$Revision: 1.1.1.1 $", "%*s %s", revision); + sscanf("$Revision: 1.1.1.2 $", "%*s %s", revision); if(argc<2) { fprintf(stderr,"\nasc2ans %s\n",revision); @@ -75,13 +76,16 @@ int main(int argc, char **argv) out=stdout; while((ch=fgetc(in))!=EOF) { - if(ch==1) { /* ctrl-a */ + if(ch==CTRL_A) { /* ctrl-a */ ch=fgetc(in); - if(ch==EOF) + if(ch==EOF || toupper(ch)=='Z') /* EOF */ break; - if(ch>=0x7f) { /* move cursor right x columns */ + if(ch>0x7f) { /* move cursor right x columns */ + int cnt=ch-0x7f; ANSI; - fprintf(out,"%uC",ch-0x7f); + if(cnt>1) + fprintf(out,"%u",cnt); + fputc('C',out); continue; } switch(toupper(ch)) { @@ -102,8 +106,10 @@ int main(int argc, char **argv) fputc('\n',out); break; case 'L': - ANSI; - fprintf(out,"2J"); + ANSI; + fprintf(out,"2J"); /* clear screen */ + ANSI; + fprintf(out,"H"); /* home cursor */ break; case '-': case '_':