Skip to content
Browse files

Decode (and optionally use for display) mIRC colour codes

  • Loading branch information...
1 parent 923517a commit 94183bcff8bcba66a70572e1f04bc32ca53d4d38 Sound and Fury committed Jul 29, 2010
Showing with 69 additions and 4 deletions.
  1. +31 −1 bits.c
  2. +4 −1 bits.h
  3. +24 −0 colour.c
  4. +1 −0 colour.h
  5. +9 −2 quirc.c
View
32 bits.c
@@ -55,7 +55,37 @@ int wordline(char *msg, int x, char **out)
strcat(*out, " ");
ol++;
}
- strcat(*out, ptr);
+ int optr=strlen(*out);
+ while(*ptr)
+ {
+ if((*ptr==3) && mirc_colour_compat)
+ {
+ int fore=0, back=0;
+ ssize_t bytes=0;
+ if(sscanf(ptr, "\003%u,%u%zn", &fore, &back, &bytes))
+ {
+ ptr+=bytes;
+ if(mirc_colour_compat==2)
+ {
+ ol+=10;
+ *out=(char *)realloc(*out, ol+pl+8+strlen(CLR));
+ colour mcc=c_mirc(fore, back);
+ (*out)[optr++]='\033';
+ (*out)[optr++]='[';
+ (*out)[optr++]='0';
+ (*out)[optr++]=';';
+ (*out)[optr++]='3';
+ (*out)[optr++]='0'+mcc.fore;
+ (*out)[optr++]=';';
+ (*out)[optr++]='4';
+ (*out)[optr++]='0'+mcc.back;
+ (*out)[optr++]='m';
+ }
+ }
+ }
+ (*out)[optr++]=*ptr++;
+ }
+ (*out)[optr]=0;
ol+=pl;
ptr=strtok(NULL, " ");
}
View
5 bits.h
@@ -10,12 +10,15 @@
#include <stdlib.h>
#include <string.h>
#include "ttyesc.h"
+#include "colour.h"
// helper fn macros
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
-int width, height; // term size (set in quirc.c)
+// global settings & state (set in quirc.c)
+int width, height; // term size
+int mirc_colour_compat;
char * fgetl(FILE *); // gets a line of string data; returns a malloc-like pointer (preserves trailing \n)
int wordline(char *, int x, char **); // prepares a string for printing, breaking lines in between words
View
24 colour.c
@@ -4,3 +4,27 @@ int setcolour(colour c)
{
return(setcol(c.fore, c.back, c.hi, c.ul));
}
+
+colour c_mirc(int fore, int back)
+{
+ /*mIRC colours:
+0=white, 1=black, 2=dk blue, 3=green, 4=red, 5=maroon, 6=purple, 7=orange, 8=yellow, 9=lt green, 10=teal, 11=cyan, 12=blue, 13=fuchsia, 14=dk gray, 15=lt gray
+converted:
+0->7, 1->0, 2->4, 3->2, 4->1, 5->1, 6->5, 7->3, 8->3, 9->2, 10->6, 11->6, 12->4, 13->5, 14->0(7), 15->7
+*/
+ const int col[16]={7, 0, 4, 2, 1, 1, 5, 3, 3, 2, 6, 6, 4, 5, 0, 7};
+ colour rv={7, 0, false, false};
+ if((fore>=0) && (fore<16))
+ {
+ rv.fore=col[fore];
+ }
+ if((back>=0) && (back<16))
+ {
+ rv.back=col[back];
+ }
+ if(rv.fore==rv.back)
+ {
+ rv.fore=7-rv.back;
+ }
+ return(rv);
+}
View
1 colour.h
@@ -12,6 +12,7 @@ typedef struct
colour;
int setcolour(colour);
+colour c_mirc(int, int);
#ifdef COLOURS
colour c_msg[2]={{7, 0, false, true}, {7, 0, false, false}};
View
11 quirc.c
@@ -27,10 +27,10 @@
#include "ttyraw.h"
#include "ttyesc.h"
-#include "irc.h"
-#include "bits.h"
#define COLOURS 0 // activate default colours in colour.h
#include "colour.h"
+#include "irc.h"
+#include "bits.h"
#include "buffer.h"
#include "numeric.h"
#include "version.h"
@@ -53,6 +53,7 @@
int main(int argc, char *argv[])
{
int buflines=256; // will make configable later
+ mirc_colour_compat=1; // silently strip
char *cols=getenv("COLUMNS"), *rows=getenv("ROWS");
if(cols) sscanf(cols, "%u", &width);
if(rows) sscanf(rows, "%u", &height);
@@ -170,6 +171,8 @@ int main(int argc, char *argv[])
chan=strdup(rest);
else if(strcmp(cmd, "mnln")==0)
sscanf(rest, "%u", &maxnlen);
+ else if(strcmp(cmd, "mcc")==0)
+ sscanf(rest, "%u", &mirc_colour_compat);
else
{
fprintf(stderr, "Unrecognised cmd %s in .quirc (ignoring)\n", cmd);
@@ -218,6 +221,10 @@ int main(int argc, char *argv[])
{
sscanf(argv[arg]+13, "%u", &maxnlen);
}
+ else if(strncmp(argv[arg], "--mcc=", 6)==0)
+ {
+ sscanf(argv[arg]+6, "%u", &mirc_colour_compat);
+ }
else if(strcmp(argv[arg], "--no-auto-connect")==0)
{
server=NULL;

0 comments on commit 94183bc

Please sign in to comment.
Something went wrong with that request. Please try again.