AD原理图生成引脚约束文件的小工具

前端时间做的,先上代码,以后有空解释用途

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int str_find (char *a,char *b) {  //find if b in a .
char *p=	strstr (a,b) ;
	return p!=NULL ;
}

	static char buff[1000][100] ;
	static int idx=0;
	
	
	
	void prt_len(char *p,int len ){
	int r = len - strlen(p) ;
	printf("%s",p ) ;
	while(r -- )	printf(" ");
	}
	
	
	void print_buff(){
		int i ;int valid=0 ;
		for(i=0;i<idx;++i) 		if ( strstr(buff[i], "U1-" )  ) valid++;
		
		if (valid>=2)  return ;
		if (valid==0)  return ;
		if (idx==1)  return ;
		if (idx!=2)  return ;
		
		for(i=0;i<idx;++i)   prt_len(buff[i] ,30 ); 	printf("%s \t",buff[i]) ;
		
		puts(" ");
		
	}
	
int feed_a_line (char *p ){
	///puts(p);
	if (p) {  strcpy(buff[idx++] , p ); return idx  ; }
	print_buff();
	idx =0; 
}


int check_a_line (char *p ){
	
	static int st = 0;
	if (st==0){
		if (p[0] == '(') st = 1;
		return st;
	}else if (st==1) {
		if (p[0] == ')') {st=0;feed_a_line(NULL);return st; }
		if ( strstr (p,"U1-" )) feed_a_line(  p  ) ;else if ( strstr(p,"-") ==NULL )  feed_a_line(p) ;
	}
	
}


static     char line[1024];
int main() {
    FILE *file;
    file = fopen("oct_sdr.net", "r");
    if (file == NULL) {
        printf("无法打开文件.\n");
        return 1;
    }

    while (fgets(line, sizeof(line), file) != NULL) {
        line[strcspn(line, "\n")] = '\0';
        check_a_line(line ) ;
    }

    fclose(file);
    return 0;
}


 

下面这个是将每行进行排序的小工具。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


static char buff[2000][1024] ;
static int idx = 0 ;

void print_buff(){
int i ;
for (i=0; i<idx;++i) 
printf("%s \n",buff[i]) ;
}
 
void bubble_sort(void ) {
    static char temp[1000] ;
	int n = idx ;
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (strcmp(buff[j+0], buff[j + 1]) > 0)
			 {
                 strcpy(temp,buff[j]);
                 strcpy(buff[j],buff[j+1]);
                 strcpy(buff[j+1],temp);
            }
        }
    }
}
 
static  char line[1024];
int main() {
    FILE *file; 
    file = fopen("mmm.txt", "r");
    if (file == NULL) {
        printf("can not read file.\n");
        return 1;
    } 
    while (fgets(line, sizeof(line), file) != NULL) {
        line[strcspn(line, "\n")] = '\0';
    //    puts( line );
        strcpy(buff[idx++] , line ) ;
     ///   feed_a_line (line ) ;
    }
    
    fclose(file);    //now all line in buff  
	printf("find line is %d \r\n", idx  ) ;  
	bubble_sort (  ) ; 
    print_buff(); 
    return 0;
    
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值