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 >
Wrap
Text File
|
1988-01-28
|
6KB
|
276 lines
#include "parser.h"
#include "ciftomann.h"
#include "fd.h"
#include <stdio.h>
#include <math.h>
#define HORIZONTAL 0
#define VERTICAL 1
#define IDENTICAL 2
#define NON_MANHATTEN 3
FILE *popen();
extern char *ProgName;
extern char *bin_lib_name;
char sort_cmd[101];
int out_desc;
char *basename;
static double circle_x1, circle_x2, circle_x3;
static double circle_y1, circle_y2, circle_y3;
main(argc,argv)
int argc;
char **argv;
{
basename = argv[1];
ProgName = "edger";
sprintf(sort_cmd,"%s/sort",bin_lib_name);
circle_y1 = .48;
circle_y2 = .74;
circle_y3 = 1.0;
circle_x1 = 1.0;
circle_x2 = sqrt(1 - circle_y1*circle_y1);
circle_x3 = sqrt(1 - circle_y2*circle_y2);
parse(stdin);
exit(0);
}
EmitEdge(x,xend,y,sense)
int x,xend,y,sense;
{
EDGE edge;
edge.x = x;
edge.y = y;
edge.sense = sense;
edge.xend = xend;
if (write(out_desc,&edge,sizeof(edge)) != sizeof(edge))
panic("Bad write in EmitEdge");
}
proc_box(length,width,center,dir)
int length,width;
point *center,*dir;
{
int xmax,ymax,xmin,ymin;
if (dir != NIL(point)) {
if (dir->x*dir->y != 0) {
error("Non-Manhatten box",center->x,center->y);
} else if (dir->x == dir->y) {
error("Degenerate direction given for box",center->x,center->y);
} else if (dir->x == 0) {
int temp;
temp = length;
length = width;
width = temp;
}
}
xmax = center->x + length/2;
xmin = center->x - length/2;
ymax = center->y + width/2;
ymin = center->y - width/2;
EmitEdge(xmin,xmax,ymax,DOWN);
EmitEdge(xmin,xmax,ymin,UP);
}
proc_wire(width,path)
int width;
point *path;
{
point *first,*last;
last = first = path;
if (path->next == NIL(point)) {
proc_roundflash(width,first);
}
while (path->next != NIL(point)) {
path = path->next;
if (ProcessSegment(last,path,width) == ERROR)
return;
last = path;
}
}
#define EdgeType(first,last) \
( first->x == last->x ? \
( first->y == last->y ? IDENTICAL : VERTICAL ) :\
( first->y == last->y ? HORIZONTAL : NON_MANHATTEN ) )
ProcessSegment(last,next,Width)
point *last,*next;
{
int x,xend,miny,maxy;
switch ( EdgeType(last,next) ) {
case HORIZONTAL :
x = Min(last->x,next->x) - Width/2;
xend = Max(last->x,next->x) + Width/2;
EmitEdge(x,xend,last->y + Width/2,DOWN);
EmitEdge(x,xend,last->y - Width/2,UP);
break;
case VERTICAL :
x = last->x - Width/2;
xend = last->x + Width/2;
maxy = Max(last->y,next->y) + Width/2;
miny = Min(last->y,next->y) - Width/2;
EmitEdge(x,xend,maxy,DOWN);
EmitEdge(x,xend,miny,UP);
break;
case IDENTICAL :
break;
case NON_MANHATTEN :
error("Non-Manhatten segment in wire\n",next->x,next->y);
return(ERROR);
}
return(GOOD);
}
proc_roundflash(diameter,center)
int diameter;
point *center;
{
double radius = diameter/2.;
double x1, x2, x3, y1, y2, y3;
x1 = circle_x1*radius;
x2 = circle_x2*radius;
x3 = circle_x3*radius;
y1 = circle_y1*radius;
y2 = circle_y2*radius;
y3 = circle_y3*radius;
EmitEdge(center->x - (int) x3, center->x + (int) x3,
center->y + (int)y3, DOWN);
EmitEdge(center->x - (int) x2, center->x - (int) x3,
center->y + (int)y2, DOWN);
EmitEdge(center->x + (int) x3, center->x + (int) x2,
center->y + (int)y2, DOWN);
EmitEdge(center->x - (int) x1, center->x - (int) x2,
center->y + (int)y1, DOWN);
EmitEdge(center->x + (int) x2, center->x + (int) x1,
center->y + (int)y1, DOWN);
EmitEdge(center->x - (int) x1, center->x - (int) x2,
center->y - (int)y1, UP);
EmitEdge(center->x + (int) x2, center->x + (int) x1,
center->y - (int)y1, UP);
EmitEdge(center->x - (int) x2, center->x - (int) x3,
center->y - (int)y2, UP);
EmitEdge(center->x + (int) x3, center->x + (int) x2,
center->y - (int)y2, UP);
EmitEdge(center->x - (int) x3, center->x + (int) x3,
center->y - (int)y3, UP);
}
proc_call(cell_num)
int cell_num;
{
panic("Call command found in allegedly flattened cif");
}
proc_defstart(cell_num,a,b)
int cell_num,a,b;
{
panic("Definition Start command found in allegedly flattened cif");
}
proc_deffinish()
{
panic("Definition Finish command found in allegedly flattened cif");
}
proc_defdelete(cell_num)
int cell_num;
{
panic("Definition Delete command found in allegedly flattened cif");
}
proc_userextension(extension_num)
int extension_num;
{
panic("user extension command found in allegedly flattened cif");
}
FILE *sort_file = NULL;
proc_end()
{
if ( pclose(sort_file) != 0 ) {
fprintf(stderr,"Panic in edger : bad return status from sort\n");
exit(1);
}
}
proc_layer(name)
char *name;
{
char file[15];
int desc;
sprintf(file,"%s.%s",basename,name);
if (sort_file != NULL) {
int status;
status = pclose(sort_file);
if (status != 0) {
fprintf(stderr,"Panic in edger : bad return status from sort\n");
exit(1);
}
}
if ( (desc = creat(file,0644)) < 0 ) {
fprintf(stderr,"Panic in edger : cannot open temp file %s\n",
file);
exit(1);
}
dup2(desc,STDOUT);
close(desc);
if ( (sort_file = popen(sort_cmd,"w")) == NULL) {
fprintf(stderr,"Panic in edger : cannot fork off the sorter\n");
exit(1);
}
out_desc = fileno(sort_file);
}
error(str,x,y)
char *str;
int x,y;
{
fprintf(stderr,"Error in flattened cif : %s at (%d,%d)\n",str,x,y);
}