utils

sarlacc_schem.c

Go to the documentation of this file.
00001 /*   Orcad.c  v 0.92
00002  *   Copyright (C) 1999-2010 Matthew Ettus
00003  *   For more info email matt@ettus.com
00004  *   Ths code is released under the terms of the GNU GPL
00005  *   See www.fsf.org for a copy of the license
00006  *
00007  *  Changes 0.94 by <egil@kvaleberg.no>, october 5th 2002
00008  *    Scaling defaults to 200%
00009  *    Bus implemented - but still no bus entries!
00010  *    Check for stack overwrite and other horrors
00011  *    Changed orcad_xsize/orcad_ysize to sarlacc_dim
00012  *    Port improved
00013  *    Command line options
00014  *
00015  *  Todo:
00016  *    Hierarchy
00017  *    Bus entries
00018  *    Many details - see BAD
00019  */
00020 
00021 /*   This program will convert an ORCAD SDT IV file to geda format */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include "config.h"
00025 #endif
00026 
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <ctype.h>
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032 #include <fcntl.h>
00033 #include <unistd.h>
00034 #include <string.h>
00035 #ifdef HAVE_GETOPT_H
00036 #include <getopt.h>
00037 #endif
00038 
00039 #include <libgeda/colors.h>
00040 
00041 #ifdef HAVE_LIBDMALLOC
00042 #include <dmalloc.h>
00043 #endif
00044 
00045 /*
00046  *  command line options
00047  */
00048 #define SARVERSION "0.94"
00049 #define GEDAVERSION "20020825"
00050 
00051 #define DEFAULT_SCALE 200 /* was 100 */
00052 
00053 char *symbol_dir = 0;
00054 int scale = DEFAULT_SCALE;
00055 
00056 #define TEXTSIZE ((scale <= 100) ? 6 : 10)
00057 
00058 /*
00059  *  orcad
00060  */
00061 #define GET_TAG(VAL) (VAL & 0x0F) 
00062 
00063 int CONV16(char *base,int offset)
00064 {
00065     int retval;
00066     retval = ((base[offset+1] & 255) <<8) | (base[offset] & 255);
00067     if(base[offset+1]&128)
00068         retval = retval | (65535U << 16);
00069     return retval;
00070 }
00071 
00072 #define CONV32(VAR,POS) (VAR[POS]+VAR[POS+1]*256+VAR[POS+2]*65536+VAR[POS+3]*256*16777216)
00073 
00074 #define CONV(X)  ( (scale/10)*X )
00075 #define CONVX(X) CONV(X)
00076 #define CONVY(Y) ( 32700 - ((scale/10)*Y) )
00077 
00078 #define HDR_LEN 0x20
00079 #define BYTECOUNT       0x16
00080 #define DATE    0x05
00081 #define PATH    0x3B
00082 #define REV     0x60
00083 #define TITLE   0x64
00084 #define ORG     0x91
00085 #define ADDR1   0xBE
00086 #define ADDR2   0xEB
00087 #define ADDR3   0x118
00088 #define ADDR4   0x145
00089 
00090 void remove_spaces(char *src)
00091 {
00092     char *ptr=src;
00093     while (*ptr != 0)
00094     {
00095         if(*ptr == ' ')
00096             *ptr = '_';
00097         ptr++;
00098     }
00099 }
00100 
00101 /*
00102  *  read block from Orcad file
00103  *  return size
00104  */
00105 unsigned read_block(int fd, char *block, int block_min_size,int block_max_size)
00106 {
00107     char sizebuf[2];
00108     unsigned size;
00109 
00110     read(fd,sizebuf,2);
00111     size = CONV16(sizebuf,0);
00112     if (size < block_min_size) {
00113     fprintf(stderr,"Segment too small; size %d, min is %d\n",
00114                         size, block_min_size);
00115     exit(1);
00116     }
00117     if (size > block_max_size) {
00118     fprintf(stderr,"Segment too large; size %d, max is %d\n",
00119                         size, block_max_size);
00120     exit(1);
00121     }
00122     if (read(fd,block,size) != size) {
00123     fprintf(stderr,"File truncated\n");
00124     exit(1);
00125     }
00126     return size;
00127 }
00128 
00129 unsigned read_string(char *dest, int dest_size, char *src)
00130 {
00131     unsigned size = ((unsigned char *)src)[0];
00132 
00133     if (size+1 > dest_size) {
00134     fprintf(stderr,"Text too large; size %d, max is %d\n",
00135                         size, dest_size-1);
00136     exit(1);
00137     }
00138     strncpy(dest,src+1,size);
00139     dest[size] = '\0';
00140     return size;
00141 }
00142 
00143 void read_string_file(int fd,char *dest, int dest_size)
00144 {
00145     unsigned char len;
00146 
00147     if (read(fd,&len,1) != 1) {
00148     fprintf(stderr,"File truncated\n");
00149     exit(1);
00150     }
00151     if (len+1 > dest_size) {
00152     fprintf(stderr,"Text too large; size %d, max is %d\n",
00153                         len, dest_size-1);
00154     exit(1);
00155     }
00156     if (len > 0) {
00157     if (read(fd,dest,len) != len) {
00158         fprintf(stderr,"File truncated\n");
00159         exit(1);
00160     }
00161     }
00162     dest[len] = '\0';
00163 }
00164 
00165 /*
00166  *
00167  */
00168 void parse_header(int fd1,int fd2)
00169 {
00170     unsigned char localbuf[32];
00171     int length;
00172 
00173     read(fd1,localbuf,32);
00174     if( strncmp((char *) localbuf,"Schematic FILE",14) )
00175     {
00176     fprintf(stderr,"\nFile is not an ORCAD 16 Bit Schematic\n");
00177     exit(1);
00178     }
00179 
00180     length=CONV32(localbuf,BYTECOUNT);    
00181     fprintf(stderr,"length: %d\n",length);
00182 
00183     lseek(fd2,length+HDR_LEN,SEEK_SET);
00184 }
00185 
00186 /* BAD more titleblock stuff */
00187 void parse_titleblock(int fd)
00188 {
00189     int size,sheet,total,ypos;
00190     char localbuf[1000];
00191     char data[100];
00192     char pagesize;
00193     
00194     size = read_block(fd,localbuf,5,sizeof(localbuf));
00195     // fprintf(stderr,"\nTitleblock %d bytes\n",size);
00196 
00197     sheet=CONV16(localbuf,0x00);
00198     total=CONV16(localbuf,0x02);
00199     fprintf(stderr,"Sheet #%d of %d\n",sheet,total);
00200     read_string(data,sizeof(data),localbuf+DATE);
00201     fprintf(stderr,"%s\n",data);
00202 
00203     switch(localbuf[4] && 0x0F)
00204     {
00205     case 0: pagesize = 'A'; ypos = 8*scale+scale/2; break;
00206     case 1: pagesize = 'B'; ypos = 11*scale; break;
00207     case 2: pagesize = 'C'; ypos = 17*scale; break;
00208     case 3: pagesize = 'D'; ypos = 22*scale; break;
00209     case 4: pagesize = 'E'; ypos = 34*scale; break;
00210     default:  fprintf(stderr,"Unknown Page Size\n");exit(-1);
00211     }
00212     if (scale==100) {
00213     fprintf(stdout,"C %d %d 0 0 0 title-%c.sym\n",CONVX(0),CONVY(ypos),pagesize);
00214     }
00215 }
00216 
00217 /*  BAD  Rotation and mirroring origin issues */
00218 /* Other component label issues */
00219 void parse_component(int fd1,int fd2)
00220 {
00221     char localbuf[1000];
00222     char partname[256];
00223     char filename[512];
00224     char full_filename[1024];
00225     int size;
00226     int x,y;
00227     int xpos = 0,ypos = 0,xpossav,ypossav;
00228     int xgeda,ygeda;
00229     int angle,mirror;
00230     int i = 0;
00231     int sarlacc_xsize = 0, sarlacc_ysize = 0;
00232     int sarlacc_xoffset = 0, sarlacc_yoffset = 0;
00233     int attribcnt;
00234 
00235     int refx,refy,ref_vis;
00236     char refdes[32];
00237     int valx,valy,val_vis;
00238     char value[64];
00239     char attrib[64];
00240     char attribsav[64];
00241 
00242     char flags;
00243     char vis;
00244     
00245     int pointer;
00246     FILE *cfp;
00247     char buff[128];
00248     
00249     size = read_block(fd1,localbuf,29,sizeof(localbuf));
00250 
00251     x=CONV16(localbuf,0);
00252     y=CONV16(localbuf,2);
00253 
00254     refx = CONVX(x + CONV16(localbuf,4));
00255     refy = CONVY(y + CONV16(localbuf,6));
00256     
00257     valx = CONVX(x + CONV16(localbuf,8));
00258     valy = CONVY(y + CONV16(localbuf,10));
00259 
00260     xgeda = CONVX(x);
00261     ygeda = CONVY(y);
00262 
00263     if(localbuf[12] & 0x80) mirror=1;
00264     else mirror=0;
00265 
00266     angle=0;
00267     if (localbuf[12] & 0x20) angle=90;
00268     if (localbuf[12] & 0x40) angle+=180;
00269 /* BAD decode and use device number, fix rotation offset */
00270 
00271     ref_vis=val_vis=1;
00272 
00273     flags = localbuf[13];
00274     if (flags & 2) ref_vis=0;
00275     if (flags & 4) val_vis=0;
00276 /* BAD decode more flags */
00277 
00278     vis = localbuf[14];
00279 
00280     /* 14-27 */
00281 
00282     pointer = 28 + read_string(refdes,sizeof(refdes),localbuf+28) +1;
00283     pointer = pointer + 1 +read_string(value,sizeof(value),localbuf+pointer);
00284 
00285     read_string_file(fd2,partname,sizeof(partname));
00286     remove_spaces(partname);
00287  // fprintf(stderr,"Component %s: %s\n",refdes,partname);
00288     snprintf(filename,sizeof(filename),"%s-1.sym", partname);
00289     if (symbol_dir) {
00290     snprintf(full_filename,sizeof(full_filename),"%s/%s", 
00291                            symbol_dir, filename);
00292     } else {
00293     snprintf(full_filename,sizeof(full_filename),"%s", filename);
00294     }
00295 
00296     cfp = fopen(full_filename, "r");
00297     if (cfp != NULL) {
00298     /* "sarlacc_dim=" set by sarlacc_sym */
00299     while (!feof(cfp)) {
00300       fgets(buff, 128, cfp);
00301       if (!strncmp(buff, "sarlacc_dim=", 12)) {
00302         sscanf(buff+12, "%d,%d,%d,%d", 
00303         &sarlacc_xoffset,&sarlacc_yoffset,&sarlacc_xsize,&sarlacc_ysize);
00304       }
00305     }
00306     fclose(cfp);
00307 
00308     fprintf(stderr,"ref: %s dim = %d %d %d %d angle = %d mirror = %d\n",
00309           refdes,
00310           sarlacc_xoffset, sarlacc_yoffset,
00311           sarlacc_xsize, sarlacc_ysize, angle, mirror);
00312 
00313     switch (angle) {
00314     default: /* 0 */
00315         if (mirror) {
00316         xgeda = xgeda + sarlacc_xsize + sarlacc_xoffset;
00317         } else {
00318         xgeda = xgeda - sarlacc_xoffset;
00319         }
00320         ygeda = ygeda - (sarlacc_ysize + sarlacc_yoffset);
00321         break;
00322     case 90:
00323         xgeda = xgeda + sarlacc_ysize + sarlacc_yoffset;
00324         if (mirror) {
00325         /* BAD untested */
00326         ygeda = ygeda + sarlacc_xoffset;
00327         } else {
00328         ygeda = ygeda - (sarlacc_xsize + sarlacc_xoffset);
00329         }
00330         break;
00331     case 180:
00332         if (mirror) {
00333         xgeda = xgeda - sarlacc_xoffset;
00334         } else {
00335         xgeda = xgeda + sarlacc_xsize + sarlacc_xoffset;
00336         }
00337         ygeda = ygeda + sarlacc_yoffset;
00338         break;
00339     case 270:
00340         xgeda = xgeda - sarlacc_yoffset;
00341         if (mirror) {
00342         /* BAD untested */
00343         ygeda = ygeda - (sarlacc_xsize + sarlacc_xoffset);
00344         } else {
00345         ygeda = ygeda + sarlacc_xoffset;
00346         }
00347         break;
00348     }
00349     } else {
00350     fprintf(stderr,"Couldn't find symbol %s in file: %s\n"
00351                "Position on sheet will be uncertain\n", partname, full_filename);
00352     }
00353 
00354     fprintf(stdout,"C %d %d 1 %d %d %s\n",
00355     xgeda,ygeda,angle,mirror,filename);
00356     fprintf(stdout,"{\n");
00357 
00358 #if 0
00359     /* For sarlacc debugging purposes, it's useful to see
00360        if a component is mirrored and how much it's rotated */
00361        fprintf(stdout,"T %d %d %d %d %d 1 0 0\nmirror=%d\n",
00362                 refx,refy,GRAPHIC_COLOR,TEXTSIZE,0,mirror);
00363        fprintf(stdout,"T %d %d %d %d %d 1 0 0\nrotation=%d\n",
00364                 refx,refy,GRAPHIC_COLOR,TEXTSIZE,0,angle);
00365 #endif
00366     if (refdes[0] != 0) {
00367       if (value[0] && refx==valx && refy==valy) {
00368     /* prevent text overlap */
00369     refy += scale;
00370       }
00371       fprintf(stdout,"T %d %d %d %d %d 1 0 0\nrefdes=%s\n",
00372           refx,refy,ATTRIBUTE_COLOR,TEXTSIZE,ref_vis,refdes);
00373     }
00374 
00375     if (value[0] != 0) {
00376       fprintf(stdout,"T %d %d %d %d %d 1 0 0\nvalue=%s\n",
00377           valx,valy,ATTRIBUTE_COLOR,TEXTSIZE,val_vis,value);
00378     }
00379 
00380     attribcnt = 0;
00381     if(flags & 0x40) {
00382     for(i=0;i<8;i++) {
00383       /* This assumes that the last attribute is the footprint */
00384         xpos = CONVX(x + CONV16(localbuf,pointer));
00385         ypos = CONVY(y + CONV16(localbuf,pointer+2));
00386         pointer += 4;
00387         size = read_string(attrib,sizeof(attrib),localbuf+pointer);
00388         pointer += size + 1;
00389         if (size > 0) {
00390           attribcnt++;
00391           fprintf(stdout,"T %d %d %d %d %d 1 0 0\npattern=%s\n",
00392                 xpos,ypos,ATTRIBUTE_COLOR,TEXTSIZE,
00393               ( (flags & (1<<i))?1:0 ),attrib);
00394           xpossav = xpos;
00395           ypossav = ypos;
00396           strcpy(attribsav, attrib);
00397         }
00398     }
00399     }
00400     if (attribcnt > 0 && attrib[0]) {
00401       fprintf(stdout,"T %d %d %d %d %d 1 0 0\n"
00402              "footprint=%s\n",
00403              xpos,ypos,ATTRIBUTE_COLOR,TEXTSIZE,
00404           ( (flags & (1<<i))?1:0 ),attrib);
00405     }
00406     fprintf(stdout,"}\n");
00407 }
00408 
00409 /*  BAD  Sheets need work  */
00410 void parse_sheet (int fd)
00411 {
00412     char localbuf[1000];
00413     char filename[1000];
00414     char filetext[1000];
00415     int size;
00416     int index;
00417     int n;
00418     int x1,y1,x2,y2;
00419 
00420     size = read_block(fd,localbuf,15,sizeof(localbuf));
00421     // fprintf(stderr,"Sheet %d bytes\n",size);
00422 
00423     x1=CONVX(CONV16(localbuf,0));
00424     y1=CONVY(CONV16(localbuf,2));    
00425 
00426     x2=CONV(CONV16(localbuf,4));
00427     y2=CONV(CONV16(localbuf,6));
00428     index = 8;
00429 
00430     /* BAD 5 bytes - dunno? */
00431     index += 5;
00432 
00433     n = 1+read_string(filename,sizeof(filename),localbuf+index);
00434     index += n;
00435     n = 1+read_string(filetext,sizeof(filetext),localbuf+index);
00436     index += n;
00437 
00438     /* BAD Implement Hierarchy properly! */
00439     fprintf(stderr,"Hierarchy\n");
00440     fprintf(stderr,"xy = %d %d %d %d\n",x1,y1,x2,y2);
00441     for (n=8; n<13; ++n) fprintf(stderr,"%02x ",localbuf[n] & 0xff);
00442     fprintf(stderr,"\nfile = %s\n",filename);
00443     fprintf(stderr,"text = %s\n",filetext);
00444 
00445     /* BAD not the way to do it... */
00446     fprintf(stdout,"C %d %d 0 0 0 include-1.sym\n",x1,y1-y2);
00447     fprintf(stdout,"{\n");
00448     fprintf(stdout,"B %d %d %d %d %d 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n",
00449                     x1,y1-y2,x2,y2,GRAPHIC_COLOR);
00450     fprintf(stdout,"T %d %d %d %d 0 1 0 0\n"
00451            "source=%s\n",x1,y1-y2,ATTRIBUTE_COLOR,TEXTSIZE,filename);
00452     fprintf(stdout,"T %d %d %d %d 1 1 0 0\n"
00453            "%s\n",x1,(y1-y2)-scale,ATTRIBUTE_COLOR,TEXTSIZE,filetext);
00454     fprintf(stdout,"}\n");
00455 }
00456     
00457 static int pending_netlabel=0;
00458 static char netlabel[256];
00459 static int netlabel_x, netlabel_y, netlabel_angle;
00460 
00461 /* BAD Set wire color properly  */
00462 static void wire_or_bus(int fd, char kind, int color)
00463 {
00464     char localbuf[32];
00465     int size;
00466     int x1,y1,x2,y2;
00467 
00468     size = read_block(fd,localbuf,8,sizeof(localbuf));
00469 
00470     x1=CONVX(CONV16(localbuf,0));
00471     y1=CONVY(CONV16(localbuf,2));
00472 
00473     x2=CONVX(CONV16(localbuf,4));
00474     y2=CONVY(CONV16(localbuf,6));                         
00475     fprintf(stdout,"%c %d %d %d %d %d 0 0 0 -1 -1\n",kind,x1,y1,x2,y2,color);
00476     if (pending_netlabel) {
00477       fprintf(stdout,"{\n");
00478       fprintf(stdout,"T %d %d %d %d 1 1 %d 0\n", netlabel_x, netlabel_y,
00479                   ATTRIBUTE_COLOR, TEXTSIZE, netlabel_angle);
00480       fprintf(stdout,"label=%s\n", netlabel); /* BAD netname= */
00481       fprintf(stdout,"}\n");
00482       pending_netlabel = 0;
00483     }
00484 }
00485 
00486 void parse_wire (int fd)
00487 {
00488     wire_or_bus(fd, 'N', NET_COLOR);
00489 }
00490 
00491 /*  BAD Haven't implemented GEDA buses */
00492 /*  but guessing that Orcad busses are parsed just like wires... */
00493 void parse_bus (int fd)
00494 {
00495     wire_or_bus(fd, 'U', BUS_COLOR);
00496 }  
00497 
00498 /*  BAD How do we handle junctions in GEDA? */
00499 /* 19990726 I think we don't need to worry
00500  * ORCAD splits wires at junction points
00501  */
00502 
00503 void parse_junction (int fd)
00504 {
00505     char localbuf[32];
00506     int size;
00507 
00508     size = read_block(fd,localbuf,4,sizeof(localbuf));
00509 
00510 /*
00511     x=CONVX(CONV16(localbuf,0));
00512     y=CONVY(CONV16(localbuf,2));
00513     fprintf(stderr,"Junctions %d %d\n",x,y); 
00514 */
00515 
00516 }
00517 
00518 /* BAD Fix handling of ports */
00519 
00520 void parse_port (int fd)
00521 {
00522     char localbuf[1024];
00523     char textbuf[1024];
00524     int size;
00525     int x,y;
00526     int w;
00527     int m;
00528     int mirror = 0;
00529 
00530     size = read_block(fd,localbuf,7,sizeof(localbuf));
00531 
00532     x = CONVX(CONV16(localbuf,0));
00533     y = CONVY(CONV16(localbuf,2));
00534     w = localbuf[4] & 0xff;
00535     m = localbuf[5] & 0xff;
00536     read_string(textbuf,sizeof(textbuf),localbuf+6);
00537 
00538     // fprintf(stderr,"PORT %s %d %d %d 0x%x\n",textbuf,x,y,w,m);
00539 
00540     switch (m & 0x60) {
00541     case 0x40: /* 0101 */
00542     case 0x20: /* 1010 */
00543     x += scale + w * (scale/10);
00544     break;
00545     case 0x00: /* 0000 */
00546            /* 1001 */
00547     case 0x60: /* 1111 */
00548     mirror = 1;
00549     break;
00550     }
00551     fprintf(stdout,"C %d %d 1 0 %d input-orcad-1.sym\n",x,y,mirror);
00552     fprintf(stdout,"{\n"
00553            "T %d %d %d 8 1 1 0 0\nvalue=%s\n"
00554            "}\n",x,y,GRAPHIC_COLOR,
00555                                       textbuf);
00556 }  
00557 
00558 /* BAD Fix Labels attach to wire.  Multiline issues?*/
00559 /* Fix text sizing */
00560 void parse_label (int fd)
00561 {
00562     char localbuf[1000];
00563     char textbuf[1000];
00564     int size;
00565     int x,y;
00566     int angle;
00567     int textsize;
00568 
00569     size = read_block(fd,localbuf,5,sizeof(localbuf));
00570 
00571     x=CONVX(CONV16(localbuf,0));
00572     y=CONVY(CONV16(localbuf,2));
00573 
00574     read_string(textbuf,sizeof(textbuf),localbuf+0x06);
00575 
00576     angle=0;
00577     textsize = 5* CONV16(localbuf,4);
00578     if (textsize<0)
00579     {
00580     textsize *= -1;
00581     angle = 90;
00582     }
00583     /*    fprintf(stdout,"T %d %d %d %d 1 1 %d 0\n",x,y,GRAPHIC_COLOR, TEXTSIZE, angle);
00584       fprintf(stdout,"net=%s ATTACHME\n",textbuf);                    */
00585     pending_netlabel = 1;
00586     strncpy(netlabel, textbuf, 256);
00587     netlabel_x = x;
00588     netlabel_y = y;
00589     netlabel_angle = angle;
00590 }  
00591 
00592 /* BAD Fix Entries */
00593 
00594 void parse_entry (int fd)
00595 {
00596     char localbuf[32];
00597     int size;
00598     int x,y,type;
00599 
00600     size = read_block(fd,localbuf,5,sizeof(localbuf));
00601     // fprintf(stderr,"Entry %d bytes\n",size);
00602 
00603     x=CONVX(CONV16(localbuf,0));
00604     y=CONVY(CONV16(localbuf,2));
00605     type=localbuf[4];
00606     fprintf(stderr,"Entry %d %d type %d\n",x,y,type);
00607 }
00608 
00609 /* BAD Fix Dashed Lines */
00610 
00611 void parse_dashed (int fd)
00612 {
00613     char localbuf[32];
00614     int size;
00615     int x,y,type;
00616 
00617     size = read_block(fd,localbuf,4,sizeof(localbuf));
00618     fprintf(stderr,"Dashed  %d bytes\n",size);
00619 
00620     x=CONVX(CONV16(localbuf,0));
00621     y=CONVY(CONV16(localbuf,2));
00622     type=localbuf[4];                                    
00623 }
00624 
00625 /* BAD Fix power */
00626 /* How do netlisters handle power connections/nets? */
00627 
00628 void parse_power (int fd)
00629 {
00630     char localbuf[256];
00631     char textbuf[256];
00632     char *symbol;
00633     int size;
00634     int x,y,xtext,ytext;
00635     int angle;
00636     char type;
00637 
00638     size = read_block(fd,localbuf,5,sizeof(localbuf));
00639     // fprintf(stderr,"POWER %d bytes\n",size);
00640 
00641     read_string(textbuf,sizeof(textbuf),localbuf+0x05);
00642 
00643     x=CONVX(CONV16(localbuf,0));
00644     y=CONVY(CONV16(localbuf,2));
00645     type = localbuf[4];
00646     switch(type & 0x0C)
00647     {
00648     case 0x04: angle = 180; xtext = x; ytext = y - 600; break;
00649     case 0x08: angle = 90; ytext = y; xtext = x-600; break;
00650     case 0x0C: angle = 270;ytext = y; xtext = x+600; break;
00651     default: angle = 0; xtext=x;ytext = y+600;
00652     }
00653     switch(type & 0x03)
00654     {
00655 /*  BAD  GEDA only has bar and circle pix.  Also, they 
00656  *  All say VCC or VDD, which they should not */
00657     case 0x02:
00658         symbol = "vcc-orcad-bar-1.sym";break; /* BAR */
00659     case 0x00: /* circle */
00660     case 0x01: /* arrow */
00661     case 0x03: /* wave */
00662     default:
00663         symbol = "vcc-orcad-circle-1.sym";break;
00664     }
00665     fprintf(stdout,"C %d %d 1 %d 0 %s\n",x,y,angle,symbol);
00666     /*    fprintf(stdout,"{\n"
00667              "T %d %d %d %d 1 1 %d 0\n"
00668              "value=%s\n"
00669              "}\n",
00670         xtext,ytext,GRAPHIC_COLOR,TEXTSIZE,angle%180,textbuf);*/
00671     fprintf(stdout,"{\n"
00672            "T %d %d %d %d 1 1 %d 0\n"
00673            "net=%s:1\n"
00674            "}\n",
00675         xtext,ytext,GRAPHIC_COLOR,TEXTSIZE,angle%180,textbuf);
00676 }
00677 
00678 /*  BAD Fix Text color and check rotation */
00679 /*  BAD Fix multi-line text */
00680 
00681 void parse_text (int fd)
00682 {
00683     char localbuf[1024];
00684     char textbuf[1024];
00685     int size;
00686     int x,y,textsize,angle;
00687 
00688     size = read_block(fd,localbuf,7,sizeof(localbuf));
00689 
00690     x=CONVX(CONV16(localbuf,0));
00691     y=CONVY(CONV16(localbuf,2));
00692     read_string(textbuf,sizeof(textbuf),localbuf+6);
00693 
00694     angle=0;
00695     textsize = TEXTSIZE * CONV16(localbuf,4);
00696     if (textsize<0)
00697     {
00698     textsize *= -1;
00699     angle = 90;
00700     }
00701     fprintf(stdout,"T %d %d %d %d 1 1 %d 0\n",x,y,GRAPHIC_COLOR,textsize,angle);
00702     fprintf(stdout,"%s\n",textbuf);
00703 }
00704 
00705 /* BAD - Markers are unimplemented in gEDA (yet).  
00706  * They are the no-connects that you can place on pins to
00707  * exempt them from the connectivity checks in DRC/ERC 
00708  */
00709 
00710 void parse_marker (int fd)
00711 {
00712     char localbuf[1024];
00713     int size;
00714 
00715     size = read_block(fd,localbuf,0,sizeof(localbuf));
00716 
00717     /* fprintf(stderr,"MARKER %d\n",size); */
00718 }
00719 
00720 
00721 int parse_block(int fd1,int fd2)
00722 {
00723     char tag;
00724     read(fd1,&tag,1);
00725     switch(GET_TAG(tag))
00726     {
00727     case 0x00:
00728         parse_titleblock(fd1);
00729         break;
00730     case 0x01:
00731         parse_sheet(fd1);
00732         break;
00733     case 0x02:
00734         parse_component(fd1,fd2);
00735         break;
00736     case 0x03:
00737         parse_wire(fd1);
00738         break;
00739     case 0x04:
00740         parse_bus(fd1);
00741         break;
00742     case 0x05:
00743         parse_junction(fd1);
00744         break;
00745     case 0x06:
00746         parse_port(fd1);
00747         break;
00748     case 0x07:
00749         parse_label(fd1);
00750         break;
00751     case 0x08:
00752         parse_entry(fd1);
00753         break;
00754     case 0x09:
00755         parse_dashed(fd1);
00756         break;
00757     case 0x0a:
00758         parse_power(fd1);
00759         break;
00760     case 0x0b:
00761         parse_text(fd1);
00762         break;
00763     case 0x0c:
00764         parse_marker(fd1);
00765         break;
00766     case 0x0f:
00767         return 0;
00768         break;
00769     default:
00770         fprintf(stderr,"\nUnknown Block Tag\n");
00771         exit(-1);
00772         break;
00773     }
00774     
00775         
00776     return 1;
00777 }
00778 
00779 int
00780 main(int argc, char **argv)
00781 {
00782     int c;
00783     int fd1,fd2;
00784 
00785     while ((c = getopt(argc, argv, "d:hs:v")) > 0) {
00786     switch (c) {
00787     case 'd':
00788         symbol_dir = optarg;
00789         break;
00790     case 's':
00791         scale = atoi(optarg);
00792         break;
00793     case 'v':
00794         fprintf(stderr,"sarlacc_scheme ver %s\n", SARVERSION);
00795         exit(0);
00796         break;
00797     case 'h':
00798     default:
00799         fprintf(stderr,"Convert Oracd schematics file (16 bit format) to gEDA\n");
00800       usage:
00801         fprintf(stderr,"\nUsage:   %s [options] infile >outfile\n"
00802                "\nOptions:"
00803                "\n         -d<dir>  directory for symbols (from sarlacc_sym)"
00804                "\n         -h       help"
00805                "\n         -s<n>    scale <n>%%, default is %d"
00806                "\n         -v       version"
00807                "\n\n",
00808                argv[0],DEFAULT_SCALE);
00809         exit(1);
00810         break;
00811     }
00812     }
00813 
00814     if( optind+1 != argc )
00815     {
00816     goto usage;
00817     }
00818     
00819     /* BAD update to latest file format.. */
00820     fprintf(stdout,"v %s\n",GEDAVERSION);
00821 
00822     fd1 = open(argv[optind],O_RDONLY);
00823     if( fd1 < 0 )
00824     {
00825     fprintf(stderr,"\nCould not open input file: %s\n",argv[optind]);
00826     exit(1);
00827     }
00828     fd2 = open(argv[optind],O_RDONLY);
00829     if( fd2 < 0 )
00830     {
00831     fprintf(stderr,"\n  Could not open input file part deux\n");
00832     exit(-1);
00833     }
00834     
00835     parse_header(fd1,fd2);
00836     
00837     while(parse_block(fd1,fd2));
00838     fprintf(stderr,"\n Normal End\n");
00839 
00840     return(0);    
00841 }
00842 
00843 
00844 
00845 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines