⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rpg.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <util/utillib.h>#ifdef __STDC__# include <stdarg.h>#else# include <varargs.h>#endif#include <util/chars.h>#include <util/memory.h>#include <util/order.h>#include <util/macros.h>#include <util/rpg.h>#define MAX_COL   40#define MAX_ROW   100#define MAX_JUST  40#define MAX_SEP   10#define MAX_VALUE_LEN   500#define LOCKED		'l'#define UNLOCKED	'u'static int PAGE_WIDTH=80;static int CENTER_PAGE=0;static int static_rpt_dbg=0;static int static_parse_dbg=0;typedef struct column_justification_struct{    char format_str[40];    int min_just_width;    int num_col;    int col_just[MAX_COL];    int col_lock[MAX_COL];    int num_locked;    char col_inter_space[MAX_COL];} COLUMN_JUST;typedef struct report_justification_struct{    int width;    int tot_num_col;    int num_col_just;    COLUMN_JUST col[MAX_COL];    int tot_num_row;    char before_row_separations[MAX_ROW+1][MAX_SEP];    char after_row_separations[MAX_ROW+1][MAX_SEP];    int row_just[MAX_ROW];    char cell_values[MAX_COL][MAX_ROW][MAX_VALUE_LEN];    /*   These variables are for column sizing information */    int max_col_sizes[MAX_COL][MAX_COL];  /* this is dependent on the number of columns defined in the justification */} REPORT_JUST;static REPORT_JUST report_just;int char_in_set(char chr, char *set){    while (*set != '\0'){	printf("char in set %c -> %c\n",chr,*set);	if (chr == *set)	    return(TRUE);	set++;    }    return(FALSE);}void Desc_set_parse_verbose(int dbg){    static_parse_dbg = dbg;}void Desc_set_report_verbose(int dbg){    static_rpt_dbg = dbg;}void Desc_erase(void){    int r, c;    report_just.width = 80;    report_just.tot_num_col = 0;    report_just.num_col_just = 0;    report_just.tot_num_row = 0;        for (r=0 ; r<MAX_ROW; r++){	report_just.before_row_separations[r][0] = '\0';		report_just.after_row_separations[r][0] = '\0';	    }    for (c=0; c<MAX_COL; c++)	report_just.col[c].num_col = 0;}void Desc_set_page_center(int width){    PAGE_WIDTH = width;    CENTER_PAGE = 1;}int Desc_set_justification(char *just_str){     char *p;    int j, col=0;    for (j=0; j<report_just.num_col_just; j++)	if (strcmp(just_str,report_just.col[j].format_str) == 0)	    return(j);    if (j == MAX_JUST)	return(-1);    strcpy(report_just.col[j].format_str,just_str);    for (p=just_str; *p!='\0' && *p!=':'; ){	if (col >= MAX_COL){	    fprintf(stderr,"Error: too many columns defined > %d\n",MAX_COL);	    exit(-1);	}	if ((*p == 'c') || (*p == 'C') || (*p == 'l') || (*p == 'L') ||	    (*p == 'r') || (*p == 'R') || (*p == 'n') || (*p == 'a')){	    report_just.col[j].col_just[col] = *p;	    report_just.col[j].col_lock[col] = UNLOCKED;	    report_just.col[j].num_col++;	    p++;	}	if (*p == '|'){		    report_just.col[j].col_inter_space[col] = '|';	    p++;	} else 	    report_just.col[j].col_inter_space[col] = ' ';	col++;    }    report_just.num_col_just++;    if (col > report_just.tot_num_col)	report_just.tot_num_col = col;    /* now check for the locking column information */    report_just.col[j].num_locked=0;    if (*p == ':')	p++;    for (col=0; *p!='\0' ; col++, p++){	if (col >= MAX_COL){	    fprintf(stderr,"Error: too many columns defined > %d\n",MAX_COL);	    exit(-1);	}	if ((*p == 'l')){	    report_just.col[j].col_lock[col] = LOCKED;	    report_just.col[j].num_locked++;	} else 	    report_just.col[j].col_lock[col] = UNLOCKED;    }    return(j);       }char *get_next_string_value(char **str, int width){    static char buf[150];    char *p;    int x=0;    p = *str;    for (x=0; (x < width) && (*p != '\0') && !(*p == '/' && *(p+1) == '/'); x++, p++)	buf[x] = *p;    if (*p == '/' && *(p+1) == '/')	p+=2;    else if (*p != '\0' && ((*(p+1) != ' ') || (*(p+1) != '/'))){	/* backup to a space */	while ((p != *str) && (*p != ' ')){	    p--;	    x--;	}	if (*p == ' ')	    p++;    }    buf[x] = '\0';    *str = p;    return(buf);}void print_spaces(int n, FILE *fp){    int x;    for (x=0; x<n; x++)	fprintf(fp," ");}#define SPACES_LEN   100void Desc_dump_report(int space_pad, FILE *fp){    int c, r, x, text_width, c2, j;    int hit[MAX_COL], column_width;    char *p;    char fmt_str1[200];     char *spaces="                                                                                                    ";    if (static_rpt_dbg){	int i,c,r,j,startc;	printf("Dump of description:   %d Total Columns\n", report_just.tot_num_col);	printf("Columns definitions:   \n");	for (j=0; j<report_just.num_col_just; j++){	    printf("    %2d: %2d Col:  ",j,report_just.col[j].num_col);	    for (i=0; i<report_just.col[j].num_col; i++)		printf("%c - '%c' ", report_just.col[j].col_just[i],		       report_just.col[j].col_inter_space[i]);	    printf("\n");	    printf("          Lock:  ");	    for (i=0; i<report_just.col[j].num_col; i++)		printf("%c       ", report_just.col[j].col_lock[i]);	    printf("\n");	}	printf("Report Width:          %d\n",report_just.width);	printf("Before Row Separations:       ");	for (r=0; r<report_just.tot_num_row; r++){	    char *p;	    for (p = report_just.before_row_separations[r]; (*p != '\0'); p++)		printf("  %d-'%c'",r,*p);	}	printf("\n");	printf("After Row Separations:       ");	for (r=0; r<report_just.tot_num_row; r++){	    char *p;	    for (p = report_just.after_row_separations[r]; (*p != '\0'); p++)		printf("  %d-'%c'",r,*p);	}	printf("\n");	printf("Table Row Values:      %d Rows\n",report_just.tot_num_row);	for (r=0; r<report_just.tot_num_row; r++){	    printf("   %d:  (Just %d)  ",r,report_just.row_just[r]);	    for (c=0; c<report_just.col[report_just.row_just[r]].num_col; c++){		printf("  C%d",c);		startc = c;		if ((c < report_just.tot_num_col-1) && (report_just.col[report_just.row_just[r]].col_just[c+1] == 'a')){		    printf("-");		    c++;		    while ((c < report_just.tot_num_col-1) && (report_just.col[report_just.row_just[r]].col_just[c] == 'a'))			c++;		    if (c !=  report_just.tot_num_col-1)			c--;		    printf("%d  ",c);		} else		    printf("  ");		printf("%s  ",report_just.cell_values[startc][r]);	    }	    printf("\n");	}    }    /* initialize the sizes to the minumum */    for (c=0 ; c<MAX_COL; c++)        for (c2=0 ; c2<MAX_COL; c2++)	    report_just.max_col_sizes[c][c2]=0;    /* first comput the max sizes for rows without spanning columns */    for (r=0; r<report_just.tot_num_row; r++){	for (c=0 ; c<report_just.col[report_just.row_just[r]].num_col; c++){	    if (((c < report_just.col[report_just.row_just[r]].num_col-1) && 		 (report_just.col[report_just.row_just[r]].col_just[c+1] != 'a')) ||		(c == report_just.col[report_just.row_just[r]].num_col-1)){		/* compute the max size of this column */		p = report_just.cell_values[c][r];		while (*p != '\0'){		    if (isupper(report_just.col[report_just.row_just[r]].col_just[c]))			for (x=0; (*p != '\0') && !(*p == ' ') && !(*p == '/' && *(p+1) == '/'); x++, p++)			    ;		    else			for (x=0; (*p != '\0') && !(*p == '/' && *(p+1) == '/'); x++, p++)			    ;		    if (*p == '/' && *(p+1) == '/')			p+=2;		    if (*p == ' ')			p++;		    if (x >  report_just.max_col_sizes[report_just.col[report_just.row_just[r]].num_col][c])			 report_just.max_col_sizes[report_just.col[report_just.row_just[r]].num_col][c] = x;		}	    }	}    }    if (static_rpt_dbg) {	for (j=0; j<MAX_COL; j++)	    hit[j]=0;	printf("   Maxlen Columns (1st Pass):  \n");	for (j=0 ; j<report_just.num_col_just; j++){	    if (!hit[report_just.col[j].num_col]){		printf("      %d Col: ",report_just.col[j].num_col);	    	    		for (c2=0; c2<report_just.col[j].num_col; c2++)		    printf("  %2d", report_just.max_col_sizes[report_just.col[j].num_col][c2]);		printf("\n"); 		hit[report_just.col[j].num_col]=1;	    }	}	printf("\n");    }    /* SECOND compute the max sizes for rows WITH spanning columns */    for (r=0; r<report_just.tot_num_row; r++){	for (c=0 ; c<report_just.col[report_just.row_just[r]].num_col; c++){	    /* if this isn't the last column and the next column is spanning */	    if ((c < report_just.col[report_just.row_just[r]].num_col-1) &&		(report_just.col[report_just.row_just[r]].col_just[c+1] == 'a')){		int siz=0, span_siz=0, startc, c2, add;		/* compute the max size of this column */		startc=c;		p = report_just.cell_values[c][r];		while (*p != '\0'){		    if (isupper(report_just.col[report_just.row_just[r]].col_just[c]))			for (x=0; (*p != '\0') && !(*p == ' ') && !(*p == '/' && *(p+1) == '/'); x++, p++)			    ;		    else			for (x=0; (*p != '\0') && !(*p == '/' && *(p+1) == '/'); x++, p++)			    ;		    if (*p == '/' && *(p+1) == '/')			p+=2;		    if (*p == ' ')			p++;		    if (x > siz)			 siz = x;		}		/* compute the size of the columns spanned over */		span_siz=0;		while ((c < report_just.col[report_just.row_just[r]].num_col-1) && (report_just.col[report_just.row_just[r]].col_just[c+1] == 'a')){		    span_siz +=  report_just.max_col_sizes[report_just.col[report_just.row_just[r]].num_col][c] + 			         ((c < report_just.col[report_just.row_just[r]].num_col-1) ? 1 : 0) + space_pad*2;    		    c++;		}		span_siz +=  report_just.max_col_sizes[report_just.col[report_just.row_just[r]].num_col][c];		/* if the siz > span_size THEN redistribute the characters over the N columns */		if (siz > span_siz) {		    int num_unlocked=0;		    for (c2=startc; c2<=c; c2++)			if (report_just.col[report_just.row_just[r]].col_lock[c2] == UNLOCKED)			    num_unlocked++;		    if (static_rpt_dbg) printf("   Redistribute for Row %d, columns %d-%d  Unlocked Col %d ",r,startc,c,num_unlocked);		    if (static_rpt_dbg) printf(" Span_Size %d  adjusting column size %d   Adding  ",span_siz,siz);		    if (num_unlocked == 0){			if (static_rpt_dbg) printf("   NONE\n");		    } else {			for (c2=startc; c2<=c; c2++){			    if (report_just.col[report_just.row_just[r]].col_lock[c2] == UNLOCKED){				if (c2 != c)				    add = (int)((float)(siz - span_siz) / (float)(num_unlocked) + 0.5);				else				    add = siz - span_siz;				if (static_rpt_dbg) printf(" %2d",add);				report_just.max_col_sizes[report_just.col[report_just.row_just[r]].num_col][c2] += add;				span_siz += add;			    }			}			if (static_rpt_dbg) printf("\n");		    }		}	    }	}    }    if (static_rpt_dbg) {	for (j=0; j<MAX_COL; j++)	    hit[j]=0;	printf("   Maxlen Columns (2nd Pass):  \n");	for (j=0 ; j<report_just.num_col_just; j++){	    if (!hit[report_just.col[j].num_col]){		printf("      %d Col: ",report_just.col[j].num_col);	    	    		for (c2=0; c2<report_just.col[j].num_col; c2++)		    printf("  %2d", report_just.max_col_sizes[report_just.col[j].num_col][c2]);		printf("\n"); 		hit[report_just.col[j].num_col]=1;	    }	}	printf("\n");    }    report_just.width = 0;    for (j=0; j<MAX_COL; j++)	hit[j]=0;    if (static_rpt_dbg) printf("   Computing Report width per justification:  \n");    for (j=0 ; j<report_just.num_col_just; j++){	hit[report_just.col[j].num_col] = 2;	for (c2=0; c2<report_just.col[j].num_col; c2++)	    hit[report_just.col[j].num_col] +=  report_just.max_col_sizes[report_just.col[j].num_col][c2] + space_pad*2;	hit[report_just.col[j].num_col] +=  report_just.col[j].num_col - 1;	report_just.col[j].min_just_width =  hit[report_just.col[j].num_col] ;	if (report_just.width <  hit[report_just.col[j].num_col])	    report_just.width = hit[report_just.col[j].num_col];	if (static_rpt_dbg) printf("      Just %d: Col:%d   Width %d\n",j,report_just.col[j].num_col,hit[report_just.col[j].num_col]);    }    if (CENTER_PAGE && (report_just.width < PAGE_WIDTH))  print_spaces((PAGE_WIDTH - report_just.width)/2, fp);    print_start_line(report_just.width,fp);    /* produce the report */    for (r=0; r<report_just.tot_num_row; r++){	char *desc_column_ptr[MAX_COL], *p;	int desc_column_size[MAX_COL];	int desc_column_text_size[MAX_COL];	int row_not_done, c2, c;		int current_just, current_num_col, current_underage, current_add, size_adjustment, current_num_unlocked;	row_not_done = 1;	current_just = report_just.row_just[r];	current_num_col = report_just.col[current_just].num_col;	current_num_unlocked = report_just.col[current_just].num_col - report_just.col[current_just].num_locked; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -