home *** CD-ROM | disk | FTP | other *** search
/ gdead.berkeley.edu / gdead.berkeley.edu.tar / gdead.berkeley.edu / pub / cad-tools / ciftomann.tar / edger_dir / edger.c.backup < prev    next >
Text File  |  1988-01-28  |  6KB  |  276 lines

  1. #include "parser.h"
  2. #include "ciftomann.h"
  3. #include "fd.h"
  4. #include <stdio.h>
  5. #include <math.h>
  6.  
  7. #define HORIZONTAL    0
  8. #define VERTICAL    1
  9. #define IDENTICAL    2
  10. #define NON_MANHATTEN    3
  11.  
  12. FILE *popen();
  13.  
  14. extern char *ProgName;
  15. extern char *bin_lib_name;
  16.  
  17. char sort_cmd[101];
  18.  
  19. int out_desc;
  20.  
  21. char *basename;
  22.  
  23. static double circle_x1, circle_x2, circle_x3;
  24. static double circle_y1, circle_y2, circle_y3;
  25.  
  26. main(argc,argv) 
  27. int argc;
  28. char **argv;
  29. {
  30.     basename = argv[1];
  31.     ProgName = "edger";
  32.     sprintf(sort_cmd,"%s/sort",bin_lib_name);
  33.  
  34.     circle_y1 = .48;
  35.     circle_y2 = .74;
  36.     circle_y3 = 1.0;
  37.  
  38.     circle_x1 = 1.0;
  39.     circle_x2 = sqrt(1 - circle_y1*circle_y1);
  40.     circle_x3 = sqrt(1 - circle_y2*circle_y2);
  41.  
  42.     parse(stdin);
  43.     exit(0);
  44. }
  45.  
  46. EmitEdge(x,xend,y,sense) 
  47. int x,xend,y,sense;
  48. {
  49.     EDGE edge;
  50.  
  51.     edge.x = x;
  52.     edge.y = y;
  53.     edge.sense = sense;
  54.     edge.xend = xend;
  55.  
  56.     if (write(out_desc,&edge,sizeof(edge)) != sizeof(edge))
  57.     panic("Bad write in EmitEdge");
  58. }
  59.  
  60. proc_box(length,width,center,dir)
  61. int length,width;
  62. point *center,*dir;
  63. {
  64.     int xmax,ymax,xmin,ymin;
  65.  
  66.     if (dir != NIL(point)) {
  67.     if (dir->x*dir->y != 0) {
  68.         error("Non-Manhatten box",center->x,center->y);
  69.     } else if (dir->x == dir->y) {
  70.         error("Degenerate direction given for box",center->x,center->y);
  71.     } else if (dir->x == 0) {
  72.         int temp;
  73.  
  74.         temp = length;
  75.         length = width;
  76.         width = temp;
  77.     }
  78.     }
  79.  
  80.     xmax = center->x + length/2;
  81.     xmin = center->x - length/2;
  82.     ymax = center->y + width/2;
  83.     ymin = center->y - width/2;
  84.  
  85.     EmitEdge(xmin,xmax,ymax,DOWN);
  86.     EmitEdge(xmin,xmax,ymin,UP);
  87. }
  88.  
  89. proc_wire(width,path)
  90. int width;
  91. point *path;
  92. {
  93.     
  94.     point *first,*last;
  95.  
  96.     last = first = path;
  97.  
  98.     if (path->next == NIL(point)) {
  99.     proc_roundflash(width,first);
  100.     }
  101.  
  102.     while (path->next != NIL(point)) {
  103.  
  104.     path = path->next;
  105.  
  106.     if (ProcessSegment(last,path,width) == ERROR)
  107.         return;
  108.     last = path;
  109.     }
  110.  
  111. }
  112.  
  113. #define EdgeType(first,last) \
  114.     ( first->x == last->x ? \
  115.     ( first->y == last->y ? IDENTICAL : VERTICAL ) :\
  116.     ( first->y == last->y ? HORIZONTAL : NON_MANHATTEN ) )
  117.  
  118.  
  119. ProcessSegment(last,next,Width)
  120. point *last,*next;
  121. {
  122.  
  123.     int x,xend,miny,maxy;
  124.  
  125.     switch ( EdgeType(last,next) ) {
  126.     
  127.     case HORIZONTAL :
  128.         x = Min(last->x,next->x) - Width/2;
  129.         xend = Max(last->x,next->x) + Width/2;
  130.         EmitEdge(x,xend,last->y + Width/2,DOWN);
  131.         EmitEdge(x,xend,last->y - Width/2,UP);
  132.         break;
  133.  
  134.     case VERTICAL :
  135.         x = last->x - Width/2;
  136.         xend = last->x + Width/2;
  137.         maxy = Max(last->y,next->y) + Width/2;
  138.         miny = Min(last->y,next->y) - Width/2;
  139.         EmitEdge(x,xend,maxy,DOWN);
  140.         EmitEdge(x,xend,miny,UP);
  141.         break;
  142.  
  143.     case IDENTICAL :
  144.         break;
  145.  
  146.     case NON_MANHATTEN :
  147.         error("Non-Manhatten segment in wire\n",next->x,next->y);
  148.         return(ERROR);
  149.     
  150.     }
  151.     return(GOOD);
  152. }
  153.  
  154. proc_roundflash(diameter,center)
  155. int diameter;
  156. point *center;
  157. {
  158.     double radius = diameter/2.;
  159.     double x1, x2, x3, y1, y2, y3;
  160.  
  161.     x1 = circle_x1*radius;
  162.     x2 = circle_x2*radius;
  163.     x3 = circle_x3*radius;
  164.     y1 = circle_y1*radius;
  165.     y2 = circle_y2*radius;
  166.     y3 = circle_y3*radius;
  167.  
  168.     EmitEdge(center->x - (int) x3, center->x + (int) x3,
  169.          center->y + (int)y3, DOWN);
  170.  
  171.     EmitEdge(center->x - (int) x2, center->x - (int) x3,
  172.          center->y + (int)y2, DOWN);
  173.     EmitEdge(center->x + (int) x3, center->x + (int) x2,
  174.          center->y + (int)y2, DOWN);
  175.  
  176.     EmitEdge(center->x - (int) x1, center->x - (int) x2,
  177.          center->y + (int)y1, DOWN);
  178.     EmitEdge(center->x + (int) x2, center->x + (int) x1,
  179.          center->y + (int)y1, DOWN);
  180.  
  181.     EmitEdge(center->x - (int) x1, center->x - (int) x2,
  182.          center->y - (int)y1, UP);
  183.     EmitEdge(center->x + (int) x2, center->x + (int) x1,
  184.          center->y - (int)y1, UP);
  185.  
  186.     EmitEdge(center->x - (int) x2, center->x - (int) x3,
  187.          center->y - (int)y2, UP);
  188.     EmitEdge(center->x + (int) x3, center->x + (int) x2,
  189.          center->y - (int)y2, UP);
  190.  
  191.     EmitEdge(center->x - (int) x3, center->x + (int) x3,
  192.          center->y - (int)y3, UP);
  193. }
  194.  
  195. proc_call(cell_num)
  196. int cell_num;
  197. {
  198.     panic("Call command found in allegedly flattened cif");
  199. }
  200.  
  201. proc_defstart(cell_num,a,b)
  202. int cell_num,a,b;
  203. {
  204.     panic("Definition Start command found in allegedly flattened cif");
  205. }
  206.  
  207. proc_deffinish()
  208. {
  209.     panic("Definition Finish command found in allegedly flattened cif");
  210. }
  211.  
  212. proc_defdelete(cell_num)
  213. int cell_num;
  214. {
  215.     panic("Definition Delete command found in allegedly flattened cif");
  216. }
  217.  
  218. proc_userextension(extension_num)
  219. int extension_num;
  220. {
  221.     panic("user extension command found in allegedly flattened cif");
  222. }
  223.  
  224. FILE *sort_file = NULL;
  225.  
  226. proc_end()
  227. {
  228.     if ( pclose(sort_file) != 0 ) {
  229.     fprintf(stderr,"Panic in edger : bad return status from sort\n");
  230.     exit(1);
  231.     }
  232.     
  233. }
  234.  
  235. proc_layer(name)
  236. char *name;
  237. {
  238.     char file[15];
  239.     int desc;
  240.  
  241.     sprintf(file,"%s.%s",basename,name);
  242.  
  243.     if (sort_file != NULL) {
  244.     int status;
  245.     status = pclose(sort_file);
  246.     if (status != 0) {
  247.         fprintf(stderr,"Panic in edger : bad return status from sort\n");
  248.         exit(1);
  249.     }
  250.     }
  251.  
  252.     if ( (desc = creat(file,0644)) < 0 ) {
  253.     fprintf(stderr,"Panic in edger : cannot open temp file %s\n",
  254.         file);
  255.     exit(1);
  256.     }
  257.  
  258.     dup2(desc,STDOUT);
  259.     close(desc);
  260.  
  261.     if ( (sort_file = popen(sort_cmd,"w")) == NULL) {
  262.     fprintf(stderr,"Panic in edger : cannot fork off the sorter\n");
  263.     exit(1);
  264.     }
  265.  
  266.     out_desc = fileno(sort_file);
  267.  
  268. }
  269.  
  270. error(str,x,y)
  271. char *str;
  272. int x,y;
  273. {
  274.     fprintf(stderr,"Error in flattened cif : %s at (%d,%d)\n",str,x,y);
  275. }
  276.