[lwatch-cvs] files/src acolors.c,1.4,1.5
Brought to you by:
arturcz
|
From: <ar...@us...> - 2002-07-19 00:09:54
|
Update of /cvsroot/lwatch/files/src In directory usw-pr-cvs1:/tmp/cvs-serv9658 Modified Files: acolors.c Log Message: New color system is ugly but it works. Index: acolors.c =================================================================== RCS file: /cvsroot/lwatch/files/src/acolors.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** acolors.c 16 Jul 2002 19:27:31 -0000 1.4 --- acolors.c 19 Jul 2002 00:09:44 -0000 1.5 *************** *** 101,112 **** * This idea have been taken from LIB - http://sf.net/projects/lib */ ! int scprintf(char *str, char *format) { ! strcpy(str,format); /* temporary workaround */ ! return(strlen(str)); ! } int ascprintf(char **pstr, char *format) { ! *pstr=(char*)malloc(strlen(format)+1); ! return(scprintf(*pstr,format)); } --- 101,167 ---- * This idea have been taken from LIB - http://sf.net/projects/lib */ ! ! #define CP_ALLOC 16 ! #define MAX_COL_STACK 20 int ascprintf(char **pstr, char *format) { ! int col_stack[MAX_COL_STACK]; ! int col_stack_ptr=0; ! int allocated=0; ! int len=0; ! char *outstr; ! char *src; ! char numer[3]; ! int val; ! outstr=(char*)malloc(CP_ALLOC); ! allocated=CP_ALLOC; ! src=format; ! while(*src) { ! if(*src=='^') { ! if(((src[1]>='0')&&(src[1]<='9'))&& ! ((src[2]>='0')&&(src[2]<='9'))) { ! const char *color; ! src++; ! numer[0]=*src; ! src++; ! numer[1]=*src; ! src++; ! numer[2]='\0'; ! val=atoi(numer); ! printf("val in: %2i",val); ! if(val) { ! printf(" "); ! col_stack[++col_stack_ptr]=val; ! } else { ! printf(" -"); ! val=col_stack[--col_stack_ptr]; ! } ! printf("SP: %2i top: %2i val out: %2i\n",col_stack_ptr-1,col_stack[col_stack_ptr-1],val); ! color=colmode[val]; ! while(*color) { ! outstr[len++]=*color++; ! if(len==allocated) { ! allocated+=CP_ALLOC; ! outstr=(char*)realloc((void*)outstr,allocated); ! } ! } ! continue; ! } ! } ! outstr[len++]=*src++; ! if(len==allocated) { ! allocated+=CP_ALLOC; ! outstr=(char*)realloc((void*)outstr,allocated); ! } ! } ! outstr[len]='\0'; ! *pstr=outstr; ! return(len-1); ! } ! ! int scprintf(char *str, char *format) { ! /* *pstr=(char*)malloc(strlen(format)+1); ! return(scprintf(*pstr,format)); */ ! return(0); } |