fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <time.h>
  6. #define POINT_NUM1 inputNum1+outputNum1+wireNum1
  7. #define POINT_NUM2 inputNum2+outputNum2+wireNum2
  8.  
  9.  
  10. int inputNum1,outputNum1,wireNum1;
  11. int inputNum2,outputNum2,wireNum2;
  12. FILE *out;
  13.  
  14. typedef struct tPoint{
  15. char type;
  16. char *name;
  17. int value;
  18. int level;
  19. struct tPoint *incone;
  20. struct tPoint *gateInput;
  21. struct tPoint *gateOutput;
  22. }Point;
  23. Point *pointG1,*pointG2;
  24.  
  25. typedef struct tHashTable{
  26. char valid;
  27. char *data;
  28. struct tHashTable *next;
  29. }HashTable;
  30. int HashTable_CollisoinMax;
  31. HashTable *h1,*h2;
  32.  
  33. int strGetHashKey(char *str , int gSeq);
  34.  
  35.  
  36. void initialize();
  37. void readCircuit(char **);
  38. void buildGraph();
  39. void resourceRelease();
  40.  
  41. int main(int argc , char **argv){
  42. initialize();
  43. out = fopen (argv[3],"w");
  44.  
  45. readCircuit(argv);
  46.  
  47. printf("i,o,w=%d,%d,%d\n",inputNum1,outputNum1,wireNum1);
  48. printf("i,o,w=%d,%d,%d\n",inputNum2,outputNum2,wireNum2);
  49. buildGraph();
  50. resourceRelease();
  51.  
  52. // fclose(out);
  53. }
  54. void initialize(){
  55. inputNum1=0; outputNum1=0; wireNum1=0;
  56. inputNum2=0; outputNum2=0; wireNum2=0;
  57. HashTable_CollisoinMax=0;
  58. }
  59. void readCircuit(char **argv){
  60.  
  61.  
  62. char str[10000],key[10],strcat[5000000],*token;
  63. int w_now,in_now,gate_o,edgeType;
  64. int i,j,k;
  65. FILE *in1,*in2;
  66.  
  67. in1 = fopen (argv[1],"r");
  68. in2 = fopen (argv[2],"r");
  69. out = fopen (argv[3],"w");
  70. if(in1==NULL || in2==NULL)
  71. {
  72. perror("Error opening file");
  73. }
  74. else{
  75. /*------------------1pass of input1----------------------------------*/
  76. while(!feof(in1)){
  77.  
  78. fgets(str,10000,in1);
  79. i=0; j=0; k=0;
  80. //fprintf(out,"nowline:%s , length=%d\n",str,strlen(str));
  81. while(str[i]==' ' || str[i]=='\t' || str[i]=='\n') i++; //Note 過濾tab用\t
  82. while((str[i]!=' ') && (str[i]!='\n') ){
  83. key[k]=str[i];
  84. i++; k++;
  85. }
  86. key[k]='\0';
  87. //fprintf(out,"+--key=%s\n",key);
  88. if(strcmp(key,"module")==0){
  89. if(str[strlen(str)-2]!=';'){
  90. do{
  91. // fprintf(out," filter:%s %d %d\n",str,str[strlen(str)-1],'\n');
  92. fgets(str,10000,in1); //換行字元不會中斷此函式
  93. }while(str[strlen(str)-2]!=';');
  94. }
  95. }
  96. else if(key[0]=='/' && key[1]=='/') { fprintf(out,"comment\n"); ;continue;}
  97. else if(key[0]=='\0') { fprintf(out,"blank line\n");continue;}
  98. else if(strcmp(key,"endmodule")==0) break;
  99. else{
  100. if(str[strlen(str)-2]!=';'){
  101.  
  102. do{
  103. //fprintf(out,"muti? %c\n",str[strlen(str)-2]);
  104. while(str[i]==' ') i++;
  105. while(str[i]!='\n'){
  106. strcat[j]=str[i];
  107. i++; j++;
  108. }
  109. //fprintf(out," filter:%s",str);
  110. fgets(str,10000,in1); //換行字元不會中斷此函式
  111. i=0;
  112. }while(str[strlen(str)-2]!=';');
  113. while(str[i]==' ') i++;
  114. while(str[i]!='\n'){
  115. strcat[j]=str[i];
  116. i++; j++;
  117. }
  118. strcat[j]='\0';
  119. }
  120. else{ // single line
  121. while(str[i]==' ') i++;
  122. while(str[i]!=';'){
  123. strcat[j]= str[i];
  124. i++; j++;
  125. }
  126. strcat[j]='\0';
  127. }
  128. //fprintf(out,"Multi-Line Merged/single str:\n%s\n",strcat);
  129.  
  130. if(strcmp(key,"input")==0){
  131. token = strtok(strcat," ,\t;");
  132. while(token!=NULL){
  133. token = strtok(NULL," ,\t;");
  134. inputNum1++;
  135. }
  136.  
  137. }
  138. else if(strcmp(key,"output")==0){
  139. token = strtok(strcat," ,\t;");
  140. while(token!=NULL){
  141. token = strtok(NULL," ,\t;");
  142. outputNum1++;
  143. }
  144. }
  145. else if(strcmp(key,"wire")==0){
  146. token = strtok(strcat," ,\t;");
  147. while(token!=NULL){
  148. //fprintf(out,"token=%s\n",token);
  149. token = strtok(NULL," ,\t;");
  150. wireNum1++;
  151. }
  152. }
  153. else{
  154.  
  155. // printf("this key word \"%s\" is invalid\n",key);
  156. }
  157. }
  158.  
  159. }//end read line
  160. fprintf(out,"-------First pass of in1 Done--------------\n");
  161. /*------------------1pass of input2----------------------------------*/
  162. while(!feof(in2)){
  163.  
  164. fgets(str,10000,in2);
  165. i=0; j=0; k=0;
  166. //fprintf(out,"nowline:%s , length=%d\n",str,strlen(str));
  167. while(str[i]==' ' || str[i]=='\t' || str[i]=='\n') i++; //Note 過濾tab用\t
  168. while((str[i]!=' ') && (str[i]!='\n') ){
  169. key[k]=str[i];
  170. i++; k++;
  171. }
  172. key[k]='\0';
  173. //fprintf(out,"+--key=%s\n",key);
  174. if(strcmp(key,"module")==0){
  175. if(str[strlen(str)-2]!=';'){
  176. do{
  177. // fprintf(out," filter:%s %d %d\n",str,str[strlen(str)-1],'\n');
  178. fgets(str,10000,in2); //換行字元不會中斷此函式
  179. }while(str[strlen(str)-2]!=';');
  180. }
  181. }
  182. else if(key[0]=='/' && key[1]=='/') { fprintf(out,"comment\n"); ;continue;}
  183. else if(key[0]=='\0') { fprintf(out,"blank line\n");continue;}
  184. else if(strcmp(key,"endmodule")==0) break;
  185. else{
  186. if(str[strlen(str)-2]!=';'){
  187.  
  188. do{
  189. //fprintf(out,"muti? %c\n",str[strlen(str)-2]);
  190. while(str[i]==' ') i++;
  191. while(str[i]!='\n'){
  192. strcat[j]=str[i];
  193. i++; j++;
  194. }
  195. //fprintf(out," filter:%s",str);
  196. fgets(str,10000,in2); //換行字元不會中斷此函式
  197. i=0;
  198. }while(str[strlen(str)-2]!=';');
  199. while(str[i]==' ') i++;
  200. while(str[i]!='\n'){
  201. strcat[j]=str[i];
  202. i++; j++;
  203. }
  204. strcat[j]='\0';
  205. }
  206. else{ // single line
  207. while(str[i]==' ') i++;
  208. while(str[i]!=';'){
  209. strcat[j]= str[i];
  210. i++; j++;
  211. }
  212. strcat[j]='\0';
  213. }
  214. //fprintf(out,"Multi-Line Merged/single str:\n%s\n",strcat);
  215.  
  216. if(strcmp(key,"input")==0){
  217. token = strtok(strcat," ,\t;");
  218. while(token!=NULL){
  219. token = strtok(NULL," ,\t;");
  220. inputNum2++;
  221. }
  222.  
  223. }
  224. else if(strcmp(key,"output")==0){
  225. token = strtok(strcat," ,\t;");
  226. while(token!=NULL){
  227. token = strtok(NULL," ,\t;");
  228. outputNum2++;
  229. }
  230. }
  231. else if(strcmp(key,"wire")==0){
  232. token = strtok(strcat," ,\t;");
  233. while(token!=NULL){
  234. //fprintf(out,"token=%s\n",token);
  235. token = strtok(NULL," ,\t;");
  236. wireNum2++;
  237. }
  238. }
  239. else{
  240.  
  241. // printf("this key word \"%s\" is invalid\n",key);
  242. }
  243. }
  244.  
  245. }//end read line
  246. fprintf(out,"-------First pass of in2 Done--------------\n");
  247.  
  248. }//valid FILE ptr
  249. fclose(in1);
  250. fclose(in2);
  251. fclose(out);
  252. }
  253.  
  254. void buildGraph(){
  255. int i;
  256. pointG1 = (Point *)malloc((POINT_NUM1+2)*sizeof(Point));
  257. for(i=0;i<POINT_NUM1+2;i++){
  258. (pointG1+i)->type ='e';
  259. (pointG1+i)->value=0;
  260. (pointG1+i)->level=-1;
  261. (pointG1+i)->incone=NULL;
  262. (pointG1+i)->gateInput=NULL;
  263. (pointG1+i)->gateOutput=NULL;
  264. }
  265. printf("part1,pNUm1=%d\n",POINT_NUM1);
  266. h1 = (HashTable *)malloc(POINT_NUM1*sizeof(HashTable));
  267. printf("part2\n");
  268. for(i=0;i<POINT_NUM1;i++){
  269. printf("part3,i=%d,%d\n",i,POINT_NUM1);
  270. (h1+i)->valid ='i';
  271. (h1+i)->data=NULL;
  272. (h1+i)->next=NULL;
  273. }
  274. printf("part4\n");
  275. }
  276. void resourceRelease(){
  277.  
  278. free(pointG1); free(pointG2);
  279. free(h1); free(h2);
  280. }
  281.  
  282. int strGetHashKey(char *str , int gSeq){
  283. int i,x=0;
  284. for(i=0;i<strlen(str);i++) x=x+str[i];
  285. x = (gSeq==1)? x%POINT_NUM1 : POINT_NUM2;
  286. return x;
  287. }
Runtime error #stdin #stdout #stderr 0s 6968KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error opening file: No such file or directory