Permalink
Browse files

Better handling of boolean options (genconfig); added input clock (/s…

…et its)
  • Loading branch information...
1 parent 8bd79a8 commit 42b702293a985ea50814305589406ab3aee2b1ac ec429 committed May 22, 2011
Showing with 261 additions and 51 deletions.
  1. +4 −0 README
  2. +53 −17 buffer.c
  3. +1 −0 config.cdl
  4. +1 −0 config_def.c
  5. +1 −0 config_globals.h
  6. +1 −1 config_help.c
  7. +2 −0 config_need.c
  8. +4 −0 config_pargs.c
  9. +10 −0 config_rcread.c
  10. +141 −20 config_set.c
  11. +38 −9 genconfig.c
  12. +1 −3 plans
  13. +4 −1 readme.htm
View
4 README
@@ -158,6 +158,7 @@ By default fwc, hts and quiet are turned off; tsb is turned on.
You can control the timestamping settings:
ts ts-level
utc
+its
The timestamping levels are:
ts-level Meaning
0 No timestamps will be displayed
@@ -168,6 +169,9 @@ ts-level Meaning
4 Pointlessly, display timestamps as seconds since the Epoch
If utc is enabled, timestamps will be displayed as UTC instead of local time,
and +hhmm will be replaced by UTC.
+If its is enabled, a clock will be displayed at the left-hand end of the input
+line, using the format specified by the current ts setting.
+The default setting is ts-level 1, no-utc, no-its.
These settings and others can be overridden at runtime with commandline
options. For details run "quirc --help".
You can also customise the colours quIRC uses. A custom colour line starts with
View
@@ -550,55 +550,91 @@ void in_update(iline inp)
printf(CLR);
resetcol();
printf("\n");
+ unsigned int wwidth=width;
+ char stamp[32];
+ stamp[0]=0;
+ if(its)
+ {
+ time_t t=time(NULL);
+ struct tm *td=(utc?gmtime:localtime)(&t);
+ switch(ts)
+ {
+ case 1:
+ strftime(stamp, 32, "[%H:%M] ", td);
+ break;
+ case 2:
+ strftime(stamp, 32, "[%H:%M:%S] ", td);
+ break;
+ case 3:
+ if(utc)
+ strftime(stamp, 32, "[%H:%M:%S UTC] ", td);
+ else
+ strftime(stamp, 32, "[%H:%M:%S %z] ", td);
+ break;
+ case 4:
+ snprintf(stamp, 32, "[u+%lu] ", (unsigned long)t);
+ break;
+ case 0: // no timestamps
+ default:
+ break;
+ }
+ if(strlen(stamp)+25>wwidth)
+ {
+ stamp[0]=0;
+ its=false;
+ add_to_buffer(0, c_status, "disabled due to insufficient display width", "its: ");
+ }
+ wwidth-=strlen(stamp);
+ }
// input
- if((unsigned)inp.left.i+(unsigned)inp.right.i+1<width)
+ if((unsigned)inp.left.i+(unsigned)inp.right.i+1<wwidth)
{
char *lh=highlight(inp.left.data?inp.left.data:"");
char *rh=highlight(inp.right.data?inp.right.data:"");
- printf("%s" SAVEPOS "%s" CLR RESTPOS, lh, rh);
+ printf("%s%s" SAVEPOS "%s" CLR RESTPOS, stamp, lh, rh);
free(lh);
free(rh);
}
else
{
- if(inp.left.i<width*0.75)
+ if(inp.left.i<wwidth*0.75)
{
char *lh=highlight(inp.left.data?inp.left.data:"");
- char rl[width-inp.left.i-3-max(3, (width-inp.left.i)/4)];
- snprintf(rl, width-inp.left.i-3-max(3, (width-inp.left.i)/4), "%s", inp.right.data);
+ char rl[wwidth-inp.left.i-3-max(3, (wwidth-inp.left.i)/4)];
+ snprintf(rl, wwidth-inp.left.i-3-max(3, (wwidth-inp.left.i)/4), "%s", inp.right.data);
char *rlh=highlight(rl);
- char *rrh=highlight(inp.right.data+inp.right.i-max(3, (width-inp.left.i)/4));
- printf("%s" SAVEPOS "%s...%s" CLR RESTPOS, lh, rlh, rrh);
+ char *rrh=highlight(inp.right.data+inp.right.i-max(3, (wwidth-inp.left.i)/4));
+ printf("%s%s" SAVEPOS "%s...%s" CLR RESTPOS, stamp, lh, rlh, rrh);
free(lh);
free(rlh);
free(rrh);
}
- else if(inp.right.i<width*0.75)
+ else if(inp.right.i<wwidth*0.75)
{
- char ll[max(3, (width-inp.right.i)/4)];
- snprintf(ll, max(3, (width-inp.right.i)/4), "%s", inp.left.data);
+ char ll[max(3, (wwidth-inp.right.i)/4)];
+ snprintf(ll, max(3, (wwidth-inp.right.i)/4), "%s", inp.left.data);
char *llh=highlight(ll);
- char *lrh=highlight(inp.left.data+inp.left.i-width+3+inp.right.i+max(3, (width-inp.right.i)/4));
+ char *lrh=highlight(inp.left.data+inp.left.i-wwidth+3+inp.right.i+max(3, (wwidth-inp.right.i)/4));
char *rh=highlight(inp.right.data?inp.right.data:"");
- printf("%s...%s" SAVEPOS "%s" CLR RESTPOS, llh, lrh, rh);
+ printf("%s%s...%s" SAVEPOS "%s" CLR RESTPOS, stamp, llh, lrh, rh);
free(llh);
free(lrh);
free(rh);
}
else
{
- int torem=floor((width/4.0)*floor(((inp.left.i-(width/2.0))*4.0/width)+0.5));
+ int torem=floor((wwidth/4.0)*floor(((inp.left.i-(wwidth/2.0))*4.0/wwidth)+0.5));
torem=min(torem, inp.left.i-3);
int c=inp.left.i+4-torem;
char ll[max(3, c/4)+1];
snprintf(ll, max(3, c/4)+1, "%s", inp.left.data);
char *llh=highlight(ll);
char *lrh=highlight(inp.left.data+torem+max(3, c/4));
- char rl[width-c-2-max(3, (width-c)/4)];
- snprintf(rl, width-c-2-max(3, (width-c)/4), "%s", inp.right.data);
+ char rl[wwidth-c-2-max(3, (wwidth-c)/4)];
+ snprintf(rl, wwidth-c-2-max(3, (wwidth-c)/4), "%s", inp.right.data);
char *rlh=highlight(rl);
- char *rrh=highlight(inp.right.data+inp.right.i-max(3, (width-c)/4));
- printf("%s...%s" SAVEPOS "%s...%s" CLR RESTPOS, llh, lrh, rlh, rrh);
+ char *rrh=highlight(inp.right.data+inp.right.i-max(3, (wwidth-c)/4));
+ printf("%s%s...%s" SAVEPOS "%s...%s" CLR RESTPOS, stamp, llh, lrh, rlh, rrh);
free(llh);
free(lrh);
free(rlh);
View
@@ -10,4 +10,5 @@ bool:tsb:true:::tsb:tsb:tsb:B:top status bar
int:tping:30:15::tping:tping:tping:S:outbound ping time
int:ts:1:0:4:ts:timestamps:ts:L:timestamping
bool:utc:false:::utc:utc:utc:B:UTC timestamps
+bool:its:false:::its:input clock:its:B:input clock
bool:quiet:false:::quiet:quiet:quiet:B:quiet mode
View
@@ -11,4 +11,5 @@
tping=30;
ts=1;
utc=0;
+ its=0;
quiet=0;
View
@@ -11,4 +11,5 @@ bool tsb; // top status bar
unsigned int tping; // outbound ping time
unsigned int ts; // timestamping
bool utc; // UTC timestamps
+bool its; // input clock
bool quiet; // quiet mode
View
@@ -1,2 +1,2 @@
/* Generated by genconfig */
- fprintf(stderr, "\t--width=<numeric> : display width\n"); fprintf(stderr, "\t--height=<numeric> : display height\n"); fprintf(stderr, "\t--mcc=<0 to 2> : mirc colour compatibility\n"); fprintf(stderr, "\t--fred=<0 to 3> : force-redraw\n"); fprintf(stderr, "\t--buf-lines=<numeric> : buffer lines\n"); fprintf(stderr, "\t--maxnicklen=<numeric> : max nick length\n"); fprintf(stderr, "\t--[no-]fwc : full width colour\n"); fprintf(stderr, "\t--[no-]hts : highlight tabstrip\n"); fprintf(stderr, "\t--[no-]tsb : top status bar\n"); fprintf(stderr, "\t--tping=<numeric> : outbound ping time\n"); fprintf(stderr, "\t--timestamps=<0 to 4> : timestamping\n"); fprintf(stderr, "\t--[no-]utc : UTC timestamps\n"); fprintf(stderr, "\t--[no-]quiet : quiet mode\n");
+ fprintf(stderr, "\t--width=<numeric> : display width\n"); fprintf(stderr, "\t--height=<numeric> : display height\n"); fprintf(stderr, "\t--mcc=<0 to 2> : mirc colour compatibility\n"); fprintf(stderr, "\t--fred=<0 to 3> : force-redraw\n"); fprintf(stderr, "\t--buf-lines=<numeric> : buffer lines\n"); fprintf(stderr, "\t--maxnicklen=<numeric> : max nick length\n"); fprintf(stderr, "\t--[no-]fwc : full width colour\n"); fprintf(stderr, "\t--[no-]hts : highlight tabstrip\n"); fprintf(stderr, "\t--[no-]tsb : top status bar\n"); fprintf(stderr, "\t--tping=<numeric> : outbound ping time\n"); fprintf(stderr, "\t--timestamps=<0 to 4> : timestamping\n"); fprintf(stderr, "\t--[no-]utc : UTC timestamps\n"); fprintf(stderr, "\t--[no-]input clock : input clock\n"); fprintf(stderr, "\t--[no-]quiet : quiet mode\n");
View
@@ -18,5 +18,7 @@
if(strcmp(cmd, "no-ts")==0) need=false;
if(strcmp(cmd, "utc")==0) need=false;
if(strcmp(cmd, "no-utc")==0) need=false;
+ if(strcmp(cmd, "its")==0) need=false;
+ if(strcmp(cmd, "no-its")==0) need=false;
if(strcmp(cmd, "quiet")==0) need=false;
if(strcmp(cmd, "no-quiet")==0) need=false;
View
@@ -31,6 +31,10 @@
utc=true;
else if(strcmp(argv[arg], "--no-utc")==0)
utc=false;
+ else if(strcmp(argv[arg], "--input clock")==0)
+ its=true;
+ else if(strcmp(argv[arg], "--no-input clock")==0)
+ its=false;
else if(strcmp(argv[arg], "--quiet")==0)
quiet=true;
else if(strcmp(argv[arg], "--no-quiet")==0)
View
@@ -111,6 +111,16 @@
else
utc=true;
}
+ else if(strcmp(cmd, "no-its")==0)
+ its=false;
+ else if(strcmp(cmd, "its")==0)
+ {
+ unsigned int value;
+ if(rest&&sscanf(rest, "%u", &value))
+ its=value;
+ else
+ its=true;
+ }
else if(strcmp(cmd, "no-quiet")==0)
quiet=false;
else if(strcmp(cmd, "quiet")==0)
View
@@ -157,12 +157,27 @@
{
if(val)
{
- unsigned int value;
- sscanf(val, "%u", &value);
- full_width_colour=value;
+ if(isdigit(*val))
+ {
+ unsigned int value;
+ sscanf(val, "%u", &value);
+ full_width_colour=value;
+ }
+ else if(strcmp(val, "+")==0)
+ {
+ full_width_colour=true;
+ }
+ else if(strcmp(val, "-")==0)
+ {
+ full_width_colour=false;
+ }
+ else
+ {
+ add_to_buffer(cbuf, c_err, "option 'fwc' is boolean, use only 0/1 or -/+ to set", "/set: ");
+ }
}
else
- full_width_colour=0;
+ full_width_colour=true;
if(!quiet)
{
if(full_width_colour)
@@ -188,12 +203,27 @@
{
if(val)
{
- unsigned int value;
- sscanf(val, "%u", &value);
- hilite_tabstrip=value;
+ if(isdigit(*val))
+ {
+ unsigned int value;
+ sscanf(val, "%u", &value);
+ hilite_tabstrip=value;
+ }
+ else if(strcmp(val, "+")==0)
+ {
+ hilite_tabstrip=true;
+ }
+ else if(strcmp(val, "-")==0)
+ {
+ hilite_tabstrip=false;
+ }
+ else
+ {
+ add_to_buffer(cbuf, c_err, "option 'hts' is boolean, use only 0/1 or -/+ to set", "/set: ");
+ }
}
else
- hilite_tabstrip=0;
+ hilite_tabstrip=true;
if(!quiet)
{
if(hilite_tabstrip)
@@ -219,12 +249,27 @@
{
if(val)
{
- unsigned int value;
- sscanf(val, "%u", &value);
- tsb=value;
+ if(isdigit(*val))
+ {
+ unsigned int value;
+ sscanf(val, "%u", &value);
+ tsb=value;
+ }
+ else if(strcmp(val, "+")==0)
+ {
+ tsb=true;
+ }
+ else if(strcmp(val, "-")==0)
+ {
+ tsb=false;
+ }
+ else
+ {
+ add_to_buffer(cbuf, c_err, "option 'tsb' is boolean, use only 0/1 or -/+ to set", "/set: ");
+ }
}
else
- tsb=1;
+ tsb=true;
if(!quiet)
{
if(tsb)
@@ -306,12 +351,27 @@
{
if(val)
{
- unsigned int value;
- sscanf(val, "%u", &value);
- utc=value;
+ if(isdigit(*val))
+ {
+ unsigned int value;
+ sscanf(val, "%u", &value);
+ utc=value;
+ }
+ else if(strcmp(val, "+")==0)
+ {
+ utc=true;
+ }
+ else if(strcmp(val, "-")==0)
+ {
+ utc=false;
+ }
+ else
+ {
+ add_to_buffer(cbuf, c_err, "option 'utc' is boolean, use only 0/1 or -/+ to set", "/set: ");
+ }
}
else
- utc=0;
+ utc=true;
if(!quiet)
{
if(utc)
@@ -333,16 +393,77 @@
bufs[buf].dirty=true;
redraw_buffer();
}
+ else if(strcmp(opt, "its")==0)
+ {
+ if(val)
+ {
+ if(isdigit(*val))
+ {
+ unsigned int value;
+ sscanf(val, "%u", &value);
+ its=value;
+ }
+ else if(strcmp(val, "+")==0)
+ {
+ its=true;
+ }
+ else if(strcmp(val, "-")==0)
+ {
+ its=false;
+ }
+ else
+ {
+ add_to_buffer(cbuf, c_err, "option 'its' is boolean, use only 0/1 or -/+ to set", "/set: ");
+ }
+ }
+ else
+ its=true;
+ if(!quiet)
+ {
+ if(its)
+ add_to_buffer(cbuf, c_status, "input clock enabled", "/set: ");
+ else
+ add_to_buffer(cbuf, c_status, "input clock disabled", "/set: ");
+ }
+ int buf;
+ for(buf=0;buf<nbufs;buf++)
+ bufs[buf].dirty=true;
+ redraw_buffer();
+ }
+ else if(strcmp(opt, "no-its")==0)
+ {
+ its=0;
+ if(!quiet) add_to_buffer(cbuf, c_status, "input clock disabled", "/set: ");
+ int buf;
+ for(buf=0;buf<nbufs;buf++)
+ bufs[buf].dirty=true;
+ redraw_buffer();
+ }
else if(strcmp(opt, "quiet")==0)
{
if(val)
{
- unsigned int value;
- sscanf(val, "%u", &value);
- quiet=value;
+ if(isdigit(*val))
+ {
+ unsigned int value;
+ sscanf(val, "%u", &value);
+ quiet=value;
+ }
+ else if(strcmp(val, "+")==0)
+ {
+ quiet=true;
+ }
+ else if(strcmp(val, "-")==0)
+ {
+ quiet=false;
+ }
+ else
+ {
+ add_to_buffer(cbuf, c_err, "option 'quiet' is boolean, use only 0/1 or -/+ to set", "/set: ");
+ }
}
else
- quiet=0;
+ quiet=true;
if(!quiet)
{
if(quiet)
Oops, something went wrong.

0 comments on commit 42b7022

Please sign in to comment.