Suppress warnings from GTK headers
[geda-gaf.git] / contrib / sarlacc_schem / sarlacc_schem.c
blob9b022d2c64cffeed13fe3042443c625c4535ec84
1 /* Orcad.c v 0.92
2 * Copyright (C) 1999-2010 Matthew Ettus
3 * For more info email matt@ettus.com
4 * Ths code is released under the terms of the GNU GPL
5 * See www.fsf.org for a copy of the license
7 * Changes 0.94 by <egil@kvaleberg.no>, october 5th 2002
8 * Scaling defaults to 200%
9 * Bus implemented - but still no bus entries!
10 * Check for stack overwrite and other horrors
11 * Changed orcad_xsize/orcad_ysize to sarlacc_dim
12 * Port improved
13 * Command line options
15 * Todo:
16 * Hierarchy
17 * Bus entries
18 * Many details - see BAD
21 /* This program will convert an ORCAD SDT IV file to geda format */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 #include <unistd.h>
34 #include <string.h>
35 #ifdef HAVE_GETOPT_H
36 #include <getopt.h>
37 #endif
39 #include <libgeda/colors.h>
42 * command line options
44 #define SARVERSION "0.94"
45 #define GEDAVERSION "20020825"
47 #define DEFAULT_SCALE 200 /* was 100 */
49 char *symbol_dir = 0;
50 int scale = DEFAULT_SCALE;
52 #define TEXTSIZE ((scale <= 100) ? 6 : 10)
55 * orcad
57 #define GET_TAG(VAL) (VAL & 0x0F)
59 int CONV16(char *base,int offset)
61 int retval;
62 retval = ((base[offset+1] & 255) <<8) | (base[offset] & 255);
63 if(base[offset+1]&128)
64 retval = retval | (65535U << 16);
65 return retval;
68 #define CONV32(VAR,POS) (VAR[POS]+VAR[POS+1]*256+VAR[POS+2]*65536+VAR[POS+3]*256*16777216)
70 #define CONV(X) ( (scale/10)*X )
71 #define CONVX(X) CONV(X)
72 #define CONVY(Y) ( 32700 - ((scale/10)*Y) )
74 #define HDR_LEN 0x20
75 #define BYTECOUNT 0x16
76 #define DATE 0x05
77 #define PATH 0x3B
78 #define REV 0x60
79 #define TITLE 0x64
80 #define ORG 0x91
81 #define ADDR1 0xBE
82 #define ADDR2 0xEB
83 #define ADDR3 0x118
84 #define ADDR4 0x145
86 void remove_spaces(char *src)
88 char *ptr=src;
89 while (*ptr != 0)
91 if(*ptr == ' ')
92 *ptr = '_';
93 ptr++;
98 * read block from Orcad file
99 * return size
101 unsigned read_block(int fd, char *block, int block_min_size,int block_max_size)
103 char sizebuf[2];
104 unsigned size;
106 read(fd,sizebuf,2);
107 size = CONV16(sizebuf,0);
108 if (size < block_min_size) {
109 fprintf(stderr,"Segment too small; size %d, min is %d\n",
110 size, block_min_size);
111 exit(1);
113 if (size > block_max_size) {
114 fprintf(stderr,"Segment too large; size %d, max is %d\n",
115 size, block_max_size);
116 exit(1);
118 if (read(fd,block,size) != size) {
119 fprintf(stderr,"File truncated\n");
120 exit(1);
122 return size;
125 unsigned read_string(char *dest, int dest_size, char *src)
127 unsigned size = ((unsigned char *)src)[0];
129 if (size+1 > dest_size) {
130 fprintf(stderr,"Text too large; size %d, max is %d\n",
131 size, dest_size-1);
132 exit(1);
134 strncpy(dest,src+1,size);
135 dest[size] = '\0';
136 return size;
139 void read_string_file(int fd,char *dest, int dest_size)
141 unsigned char len;
143 if (read(fd,&len,1) != 1) {
144 fprintf(stderr,"File truncated\n");
145 exit(1);
147 if (len+1 > dest_size) {
148 fprintf(stderr,"Text too large; size %d, max is %d\n",
149 len, dest_size-1);
150 exit(1);
152 if (len > 0) {
153 if (read(fd,dest,len) != len) {
154 fprintf(stderr,"File truncated\n");
155 exit(1);
158 dest[len] = '\0';
164 void parse_header(int fd1,int fd2)
166 unsigned char localbuf[32];
167 int length;
169 read(fd1,localbuf,32);
170 if( strncmp((char *) localbuf,"Schematic FILE",14) )
172 fprintf(stderr,"\nFile is not an ORCAD 16 Bit Schematic\n");
173 exit(1);
176 length=CONV32(localbuf,BYTECOUNT);
177 fprintf(stderr,"length: %d\n",length);
179 lseek(fd2,length+HDR_LEN,SEEK_SET);
182 /* BAD more titleblock stuff */
183 void parse_titleblock(int fd)
185 int size,sheet,total,ypos;
186 char localbuf[1000];
187 char data[100];
188 char pagesize;
190 size = read_block(fd,localbuf,5,sizeof(localbuf));
191 // fprintf(stderr,"\nTitleblock %d bytes\n",size);
193 sheet=CONV16(localbuf,0x00);
194 total=CONV16(localbuf,0x02);
195 fprintf(stderr,"Sheet #%d of %d\n",sheet,total);
196 read_string(data,sizeof(data),localbuf+DATE);
197 fprintf(stderr,"%s\n",data);
199 switch(localbuf[4] & 0x0F)
201 case 0: pagesize = 'A'; ypos = 8*scale+scale/2; break;
202 case 1: pagesize = 'B'; ypos = 11*scale; break;
203 case 2: pagesize = 'C'; ypos = 17*scale; break;
204 case 3: pagesize = 'D'; ypos = 22*scale; break;
205 case 4: pagesize = 'E'; ypos = 34*scale; break;
206 default: fprintf(stderr,"Unknown Page Size\n");exit(-1);
208 if (scale==100) {
209 fprintf(stdout,"C %d %d 0 0 0 title-%c.sym\n",CONVX(0),CONVY(ypos),pagesize);
213 /* BAD Rotation and mirroring origin issues */
214 /* Other component label issues */
215 void parse_component(int fd1,int fd2)
217 char localbuf[1000];
218 char partname[256];
219 char filename[512];
220 char full_filename[1024];
221 int size;
222 int x,y;
223 int xpos = 0,ypos = 0,xpossav,ypossav;
224 int xgeda,ygeda;
225 int angle,mirror;
226 int i = 0;
227 int sarlacc_xsize = 0, sarlacc_ysize = 0;
228 int sarlacc_xoffset = 0, sarlacc_yoffset = 0;
229 int attribcnt;
231 int refx,refy,ref_vis;
232 char refdes[32];
233 int valx,valy,val_vis;
234 char value[64];
235 char attrib[64];
236 char attribsav[64];
238 char flags;
239 char vis;
241 int pointer;
242 FILE *cfp;
243 char buff[128];
245 size = read_block(fd1,localbuf,29,sizeof(localbuf));
247 x=CONV16(localbuf,0);
248 y=CONV16(localbuf,2);
250 refx = CONVX(x + CONV16(localbuf,4));
251 refy = CONVY(y + CONV16(localbuf,6));
253 valx = CONVX(x + CONV16(localbuf,8));
254 valy = CONVY(y + CONV16(localbuf,10));
256 xgeda = CONVX(x);
257 ygeda = CONVY(y);
259 if(localbuf[12] & 0x80) mirror=1;
260 else mirror=0;
262 angle=0;
263 if (localbuf[12] & 0x20) angle=90;
264 if (localbuf[12] & 0x40) angle+=180;
265 /* BAD decode and use device number, fix rotation offset */
267 ref_vis=val_vis=1;
269 flags = localbuf[13];
270 if (flags & 2) ref_vis=0;
271 if (flags & 4) val_vis=0;
272 /* BAD decode more flags */
274 vis = localbuf[14];
276 /* 14-27 */
278 pointer = 28 + read_string(refdes,sizeof(refdes),localbuf+28) +1;
279 pointer = pointer + 1 +read_string(value,sizeof(value),localbuf+pointer);
281 read_string_file(fd2,partname,sizeof(partname));
282 remove_spaces(partname);
283 // fprintf(stderr,"Component %s: %s\n",refdes,partname);
284 snprintf(filename,sizeof(filename),"%s-1.sym", partname);
285 if (symbol_dir) {
286 snprintf(full_filename,sizeof(full_filename),"%s/%s",
287 symbol_dir, filename);
288 } else {
289 snprintf(full_filename,sizeof(full_filename),"%s", filename);
292 cfp = fopen(full_filename, "r");
293 if (cfp != NULL) {
294 /* "sarlacc_dim=" set by sarlacc_sym */
295 while (!feof(cfp)) {
296 fgets(buff, 128, cfp);
297 if (!strncmp(buff, "sarlacc_dim=", 12)) {
298 sscanf(buff+12, "%d,%d,%d,%d",
299 &sarlacc_xoffset,&sarlacc_yoffset,&sarlacc_xsize,&sarlacc_ysize);
302 fclose(cfp);
304 fprintf(stderr,"ref: %s dim = %d %d %d %d angle = %d mirror = %d\n",
305 refdes,
306 sarlacc_xoffset, sarlacc_yoffset,
307 sarlacc_xsize, sarlacc_ysize, angle, mirror);
309 switch (angle) {
310 default: /* 0 */
311 if (mirror) {
312 xgeda = xgeda + sarlacc_xsize + sarlacc_xoffset;
313 } else {
314 xgeda = xgeda - sarlacc_xoffset;
316 ygeda = ygeda - (sarlacc_ysize + sarlacc_yoffset);
317 break;
318 case 90:
319 xgeda = xgeda + sarlacc_ysize + sarlacc_yoffset;
320 if (mirror) {
321 /* BAD untested */
322 ygeda = ygeda + sarlacc_xoffset;
323 } else {
324 ygeda = ygeda - (sarlacc_xsize + sarlacc_xoffset);
326 break;
327 case 180:
328 if (mirror) {
329 xgeda = xgeda - sarlacc_xoffset;
330 } else {
331 xgeda = xgeda + sarlacc_xsize + sarlacc_xoffset;
333 ygeda = ygeda + sarlacc_yoffset;
334 break;
335 case 270:
336 xgeda = xgeda - sarlacc_yoffset;
337 if (mirror) {
338 /* BAD untested */
339 ygeda = ygeda - (sarlacc_xsize + sarlacc_xoffset);
340 } else {
341 ygeda = ygeda + sarlacc_xoffset;
343 break;
345 } else {
346 fprintf(stderr,"Couldn't find symbol %s in file: %s\n"
347 "Position on sheet will be uncertain\n", partname, full_filename);
350 fprintf(stdout,"C %d %d 1 %d %d %s\n",
351 xgeda,ygeda,angle,mirror,filename);
352 fprintf(stdout,"{\n");
354 #if 0
355 /* For sarlacc debugging purposes, it's useful to see
356 if a component is mirrored and how much it's rotated */
357 fprintf(stdout,"T %d %d %d %d %d 1 0 0\nmirror=%d\n",
358 refx,refy,GRAPHIC_COLOR,TEXTSIZE,0,mirror);
359 fprintf(stdout,"T %d %d %d %d %d 1 0 0\nrotation=%d\n",
360 refx,refy,GRAPHIC_COLOR,TEXTSIZE,0,angle);
361 #endif
362 if (refdes[0] != 0) {
363 if (value[0] && refx==valx && refy==valy) {
364 /* prevent text overlap */
365 refy += scale;
367 fprintf(stdout,"T %d %d %d %d %d 1 0 0\nrefdes=%s\n",
368 refx,refy,ATTRIBUTE_COLOR,TEXTSIZE,ref_vis,refdes);
371 if (value[0] != 0) {
372 fprintf(stdout,"T %d %d %d %d %d 1 0 0\nvalue=%s\n",
373 valx,valy,ATTRIBUTE_COLOR,TEXTSIZE,val_vis,value);
376 attribcnt = 0;
377 if(flags & 0x40) {
378 for(i=0;i<8;i++) {
379 /* This assumes that the last attribute is the footprint */
380 xpos = CONVX(x + CONV16(localbuf,pointer));
381 ypos = CONVY(y + CONV16(localbuf,pointer+2));
382 pointer += 4;
383 size = read_string(attrib,sizeof(attrib),localbuf+pointer);
384 pointer += size + 1;
385 if (size > 0) {
386 attribcnt++;
387 fprintf(stdout,"T %d %d %d %d %d 1 0 0\npattern=%s\n",
388 xpos,ypos,ATTRIBUTE_COLOR,TEXTSIZE,
389 ( (flags & (1<<i))?1:0 ),attrib);
390 xpossav = xpos;
391 ypossav = ypos;
392 strcpy(attribsav, attrib);
396 if (attribcnt > 0 && attrib[0]) {
397 fprintf(stdout,"T %d %d %d %d %d 1 0 0\n"
398 "footprint=%s\n",
399 xpos,ypos,ATTRIBUTE_COLOR,TEXTSIZE,
400 ( (flags & (1<<i))?1:0 ),attrib);
402 fprintf(stdout,"}\n");
405 /* BAD Sheets need work */
406 void parse_sheet (int fd)
408 char localbuf[1000];
409 char filename[1000];
410 char filetext[1000];
411 int size;
412 int index;
413 int n;
414 int x1,y1,x2,y2;
416 size = read_block(fd,localbuf,15,sizeof(localbuf));
417 // fprintf(stderr,"Sheet %d bytes\n",size);
419 x1=CONVX(CONV16(localbuf,0));
420 y1=CONVY(CONV16(localbuf,2));
422 x2=CONV(CONV16(localbuf,4));
423 y2=CONV(CONV16(localbuf,6));
424 index = 8;
426 /* BAD 5 bytes - dunno? */
427 index += 5;
429 n = 1+read_string(filename,sizeof(filename),localbuf+index);
430 index += n;
431 n = 1+read_string(filetext,sizeof(filetext),localbuf+index);
432 index += n;
434 /* BAD Implement Hierarchy properly! */
435 fprintf(stderr,"Hierarchy\n");
436 fprintf(stderr,"xy = %d %d %d %d\n",x1,y1,x2,y2);
437 for (n=8; n<13; ++n) fprintf(stderr,"%02x ",localbuf[n] & 0xff);
438 fprintf(stderr,"\nfile = %s\n",filename);
439 fprintf(stderr,"text = %s\n",filetext);
441 /* BAD not the way to do it... */
442 fprintf(stdout,"C %d %d 0 0 0 include-1.sym\n",x1,y1-y2);
443 fprintf(stdout,"{\n");
444 fprintf(stdout,"B %d %d %d %d %d 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n",
445 x1,y1-y2,x2,y2,GRAPHIC_COLOR);
446 fprintf(stdout,"T %d %d %d %d 0 1 0 0\n"
447 "source=%s\n",x1,y1-y2,ATTRIBUTE_COLOR,TEXTSIZE,filename);
448 fprintf(stdout,"T %d %d %d %d 1 1 0 0\n"
449 "%s\n",x1,(y1-y2)-scale,ATTRIBUTE_COLOR,TEXTSIZE,filetext);
450 fprintf(stdout,"}\n");
453 static int pending_netlabel=0;
454 static char netlabel[256];
455 static int netlabel_x, netlabel_y, netlabel_angle;
457 /* BAD Set wire color properly */
458 static void wire_or_bus(int fd, char kind, int color)
460 char localbuf[32];
461 int size;
462 int x1,y1,x2,y2;
464 size = read_block(fd,localbuf,8,sizeof(localbuf));
466 x1=CONVX(CONV16(localbuf,0));
467 y1=CONVY(CONV16(localbuf,2));
469 x2=CONVX(CONV16(localbuf,4));
470 y2=CONVY(CONV16(localbuf,6));
471 fprintf(stdout,"%c %d %d %d %d %d 0 0 0 -1 -1\n",kind,x1,y1,x2,y2,color);
472 if (pending_netlabel) {
473 fprintf(stdout,"{\n");
474 fprintf(stdout,"T %d %d %d %d 1 1 %d 0\n", netlabel_x, netlabel_y,
475 ATTRIBUTE_COLOR, TEXTSIZE, netlabel_angle);
476 fprintf(stdout,"label=%s\n", netlabel); /* BAD netname= */
477 fprintf(stdout,"}\n");
478 pending_netlabel = 0;
482 void parse_wire (int fd)
484 wire_or_bus(fd, 'N', NET_COLOR);
487 /* BAD Haven't implemented GEDA buses */
488 /* but guessing that Orcad busses are parsed just like wires... */
489 void parse_bus (int fd)
491 wire_or_bus(fd, 'U', BUS_COLOR);
494 /* BAD How do we handle junctions in GEDA? */
495 /* 19990726 I think we don't need to worry
496 * ORCAD splits wires at junction points
499 void parse_junction (int fd)
501 char localbuf[32];
502 int size;
504 size = read_block(fd,localbuf,4,sizeof(localbuf));
507 x=CONVX(CONV16(localbuf,0));
508 y=CONVY(CONV16(localbuf,2));
509 fprintf(stderr,"Junctions %d %d\n",x,y);
514 /* BAD Fix handling of ports */
516 void parse_port (int fd)
518 char localbuf[1024];
519 char textbuf[1024];
520 int size;
521 int x,y;
522 int w;
523 int m;
524 int mirror = 0;
526 size = read_block(fd,localbuf,7,sizeof(localbuf));
528 x = CONVX(CONV16(localbuf,0));
529 y = CONVY(CONV16(localbuf,2));
530 w = localbuf[4] & 0xff;
531 m = localbuf[5] & 0xff;
532 read_string(textbuf,sizeof(textbuf),localbuf+6);
534 // fprintf(stderr,"PORT %s %d %d %d 0x%x\n",textbuf,x,y,w,m);
536 switch (m & 0x60) {
537 case 0x40: /* 0101 */
538 case 0x20: /* 1010 */
539 x += scale + w * (scale/10);
540 break;
541 case 0x00: /* 0000 */
542 /* 1001 */
543 case 0x60: /* 1111 */
544 mirror = 1;
545 break;
547 fprintf(stdout,"C %d %d 1 0 %d input-orcad-1.sym\n",x,y,mirror);
548 fprintf(stdout,"{\n"
549 "T %d %d %d 8 1 1 0 0\nvalue=%s\n"
550 "}\n",x,y,GRAPHIC_COLOR,
551 textbuf);
554 /* BAD Fix Labels attach to wire. Multiline issues?*/
555 /* Fix text sizing */
556 void parse_label (int fd)
558 char localbuf[1000];
559 char textbuf[1000];
560 int size;
561 int x,y;
562 int angle;
563 int textsize;
565 size = read_block(fd,localbuf,5,sizeof(localbuf));
567 x=CONVX(CONV16(localbuf,0));
568 y=CONVY(CONV16(localbuf,2));
570 read_string(textbuf,sizeof(textbuf),localbuf+0x06);
572 angle=0;
573 textsize = 5* CONV16(localbuf,4);
574 if (textsize<0)
576 textsize *= -1;
577 angle = 90;
579 /* fprintf(stdout,"T %d %d %d %d 1 1 %d 0\n",x,y,GRAPHIC_COLOR, TEXTSIZE, angle);
580 fprintf(stdout,"net=%s ATTACHME\n",textbuf); */
581 pending_netlabel = 1;
582 strncpy(netlabel, textbuf, 256);
583 netlabel_x = x;
584 netlabel_y = y;
585 netlabel_angle = angle;
588 /* BAD Fix Entries */
590 void parse_entry (int fd)
592 char localbuf[32];
593 int size;
594 int x,y,type;
596 size = read_block(fd,localbuf,5,sizeof(localbuf));
597 // fprintf(stderr,"Entry %d bytes\n",size);
599 x=CONVX(CONV16(localbuf,0));
600 y=CONVY(CONV16(localbuf,2));
601 type=localbuf[4];
602 fprintf(stderr,"Entry %d %d type %d\n",x,y,type);
605 /* BAD Fix Dashed Lines */
607 void parse_dashed (int fd)
609 char localbuf[32];
610 int size;
611 int x,y,type;
613 size = read_block(fd,localbuf,4,sizeof(localbuf));
614 fprintf(stderr,"Dashed %d bytes\n",size);
616 x=CONVX(CONV16(localbuf,0));
617 y=CONVY(CONV16(localbuf,2));
618 type=localbuf[4];
621 /* BAD Fix power */
622 /* How do netlisters handle power connections/nets? */
624 void parse_power (int fd)
626 char localbuf[256];
627 char textbuf[256];
628 char *symbol;
629 int size;
630 int x,y,xtext,ytext;
631 int angle;
632 char type;
634 size = read_block(fd,localbuf,5,sizeof(localbuf));
635 // fprintf(stderr,"POWER %d bytes\n",size);
637 read_string(textbuf,sizeof(textbuf),localbuf+0x05);
639 x=CONVX(CONV16(localbuf,0));
640 y=CONVY(CONV16(localbuf,2));
641 type = localbuf[4];
642 switch(type & 0x0C)
644 case 0x04: angle = 180; xtext = x; ytext = y - 600; break;
645 case 0x08: angle = 90; ytext = y; xtext = x-600; break;
646 case 0x0C: angle = 270;ytext = y; xtext = x+600; break;
647 default: angle = 0; xtext=x;ytext = y+600;
649 switch(type & 0x03)
651 /* BAD GEDA only has bar and circle pix. Also, they
652 * All say VCC or VDD, which they should not */
653 case 0x02:
654 symbol = "vcc-orcad-bar-1.sym";break; /* BAR */
655 case 0x00: /* circle */
656 case 0x01: /* arrow */
657 case 0x03: /* wave */
658 default:
659 symbol = "vcc-orcad-circle-1.sym";break;
661 fprintf(stdout,"C %d %d 1 %d 0 %s\n",x,y,angle,symbol);
662 /* fprintf(stdout,"{\n"
663 "T %d %d %d %d 1 1 %d 0\n"
664 "value=%s\n"
665 "}\n",
666 xtext,ytext,GRAPHIC_COLOR,TEXTSIZE,angle%180,textbuf);*/
667 fprintf(stdout,"{\n"
668 "T %d %d %d %d 1 1 %d 0\n"
669 "net=%s:1\n"
670 "}\n",
671 xtext,ytext,GRAPHIC_COLOR,TEXTSIZE,angle%180,textbuf);
674 /* BAD Fix Text color and check rotation */
675 /* BAD Fix multi-line text */
677 void parse_text (int fd)
679 char localbuf[1024];
680 char textbuf[1024];
681 int size;
682 int x,y,textsize,angle;
684 size = read_block(fd,localbuf,7,sizeof(localbuf));
686 x=CONVX(CONV16(localbuf,0));
687 y=CONVY(CONV16(localbuf,2));
688 read_string(textbuf,sizeof(textbuf),localbuf+6);
690 angle=0;
691 textsize = TEXTSIZE * CONV16(localbuf,4);
692 if (textsize<0)
694 textsize *= -1;
695 angle = 90;
697 fprintf(stdout,"T %d %d %d %d 1 1 %d 0\n",x,y,GRAPHIC_COLOR,textsize,angle);
698 fprintf(stdout,"%s\n",textbuf);
701 /* BAD - Markers are unimplemented in gEDA (yet).
702 * They are the no-connects that you can place on pins to
703 * exempt them from the connectivity checks in DRC/ERC
706 void parse_marker (int fd)
708 char localbuf[1024];
709 int size;
711 size = read_block(fd,localbuf,0,sizeof(localbuf));
713 /* fprintf(stderr,"MARKER %d\n",size); */
717 int parse_block(int fd1,int fd2)
719 char tag;
720 read(fd1,&tag,1);
721 switch(GET_TAG(tag))
723 case 0x00:
724 parse_titleblock(fd1);
725 break;
726 case 0x01:
727 parse_sheet(fd1);
728 break;
729 case 0x02:
730 parse_component(fd1,fd2);
731 break;
732 case 0x03:
733 parse_wire(fd1);
734 break;
735 case 0x04:
736 parse_bus(fd1);
737 break;
738 case 0x05:
739 parse_junction(fd1);
740 break;
741 case 0x06:
742 parse_port(fd1);
743 break;
744 case 0x07:
745 parse_label(fd1);
746 break;
747 case 0x08:
748 parse_entry(fd1);
749 break;
750 case 0x09:
751 parse_dashed(fd1);
752 break;
753 case 0x0a:
754 parse_power(fd1);
755 break;
756 case 0x0b:
757 parse_text(fd1);
758 break;
759 case 0x0c:
760 parse_marker(fd1);
761 break;
762 case 0x0f:
763 return 0;
764 break;
765 default:
766 fprintf(stderr,"\nUnknown Block Tag\n");
767 exit(-1);
768 break;
772 return 1;
776 main(int argc, char **argv)
778 int c;
779 int fd1,fd2;
781 while ((c = getopt(argc, argv, "d:hs:v")) > 0) {
782 switch (c) {
783 case 'd':
784 symbol_dir = optarg;
785 break;
786 case 's':
787 scale = atoi(optarg);
788 break;
789 case 'v':
790 fprintf(stderr,"sarlacc_scheme ver %s\n", SARVERSION);
791 exit(0);
792 break;
793 case 'h':
794 default:
795 fprintf(stderr,"Convert Oracd schematics file (16 bit format) to gEDA\n");
796 usage:
797 fprintf(stderr,"\nUsage: %s [options] infile >outfile\n"
798 "\nOptions:"
799 "\n -d<dir> directory for symbols (from sarlacc_sym)"
800 "\n -h help"
801 "\n -s<n> scale <n>%%, default is %d"
802 "\n -v version"
803 "\n\n",
804 argv[0],DEFAULT_SCALE);
805 exit(1);
806 break;
810 if( optind+1 != argc )
812 goto usage;
815 /* BAD update to latest file format.. */
816 fprintf(stdout,"v %s\n",GEDAVERSION);
818 fd1 = open(argv[optind],O_RDONLY);
819 if( fd1 < 0 )
821 fprintf(stderr,"\nCould not open input file: %s\n",argv[optind]);
822 exit(1);
824 fd2 = open(argv[optind],O_RDONLY);
825 if( fd2 < 0 )
827 fprintf(stderr,"\n Could not open input file part deux\n");
828 exit(-1);
831 parse_header(fd1,fd2);
833 while(parse_block(fd1,fd2));
834 fprintf(stderr,"\n Normal End\n");
836 return(0);