utils

gmk_sym.c

Go to the documentation of this file.
00001 /*************************************************************************/
00002 /* gmk_sym, a program to create rectangular symbols for gschem           */
00003 /* from a file composed of comma separated lines                         */
00004 /*  From: Jerry O'Keefe, jerryok@pacbell.net                             */
00005 /* Version: 0.000005                             */
00006 /*                                   */
00007 /* History:                              */
00008 /* 99/03/23 Fixed pin#= placeholder as define in Component Symbol Guide  */
00009 /* 99/04/02 Fixed pin spacing on right side and changed name to gmk_sym  */
00010 /* 99/04/27 Add Mike Jarabek's updates, alphanumeric pin name support    */
00011 /*          and improved text spacing                                    */
00012 /* 99/05/02 Add char_width.c support                     */
00013 /*                                   */
00014 /* 00/07/12 Major changes to match new styles for text and attributes    */
00015 /* 02/01/19 Changed the way pin labels and numbers are anchored to the   */
00016 /*          pins.  They make use of the text origin feature so that      */
00017 /*          calculation of the string width is no longer needed.  This   */
00018 /*          results in much more uniformly placed pins on the left and   */
00019 /*          bottom side of the device.  Also added the ability to        */
00020 /*          place the device name in the center of the symbol, useful    */
00021 /*          for large symbols containing pins on all sides.  Top and     */
00022 /*          bottom pin numbers are rotated by 90 degrees to match the    */
00023 /*          pin rotation.  Added pin type attribute capability. (Roberto */
00024 /*          Puon)                                                        */
00025 /*                                   */
00026 /* 2002/05/15 Added checks to prevent segfaults on invalid       */
00027 /*           input data (Chris Ellec)                            */
00028 /* 2002/08/14 Check for multiple instances of the same pin number and quit */
00029 /*            when this happens, give Fatal error messsage. (Chris Ellec)  */
00030 /* 2002/12/30 Change to new file format (Chris Ellec), version 20021103  */
00031 /*-----------------------------------------------------------------------*/
00032 /* This program is free software; you can redistribute it and/or modify  */
00033 /* it under the terms of the GNU General Public License as published by  */
00034 /* the Free Software Foundation; either version 2 of the License, or     */
00035 /* (at your option) any later version.                   */
00036 /*                                   */
00037 /* This program is distributed in the hope that it will be useful,   */
00038 /* but WITHOUT ANY WARRANTY; without even the implied warranty of    */
00039 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     */
00040 /* GNU General Public License for more details.                          */
00041 /*                                   */
00042 /*-----------------------------------------------------------------------*/
00043 /* GMK_SYM typical use:                                                  */
00044 /*  gk_sym 7474.txt >7474-3.sym                                          */
00045 /* To build:                                 */
00046 /*    gcc -O2 -Wall gmk_sym.c -o gmk_sym                     */
00047 /*-----------------------------------------------------------------------*/
00048 /*-----------------------------------------------------------------------*/
00049 /* The input file format:                        */
00050 /*  1. lines starting with ';' are comment lines, and            */
00051 /*     are not processed.                        */
00052 /*  2. The 1st valid line describes a device                 */
00053 /*     1st value: device name                        */
00054 /*     2nd value: visible name                           */
00055 /*     3rd value: visible name location on package,          */
00056 /*     4th value: box's hoz size, in pins spacings                   */
00057 /*     5th value: box's ver size, in pins spacings           */
00058 /*     6th value: uref prefix, like U or J                       */
00059 /*     7th value: Footprint                      */
00060 /*     8th value: Total number of pins on device (including hidden)  */
00061 /*  3. All other valid lines describes the symbol's pins         */
00062 /*     1st value: pin name                       */
00063 /*     2nd value: pin number                         */
00064 /*     3rd value: pin shape, choice of: line, clock, dot&line            */
00065 /*     4th value: side of box to attach the pin,choice of: R, L, T, B    */
00066 /*     5th value: location of pin on side of box, in pin spacings    */
00067 /*     6th value: (optional) pin type attribute: in, out, io, oc, oe,    */
00068 /*                pas, tp, tri, clk, pwr                                 */
00069 /*  See the 7474 sample file below                   */
00070 /*************************************************************************/
00071 #if 0
00072 /****************************************************/
00073 ;; Filename: 7474.txt
00074 ;;   An example of a 7474 symbol make file
00075 ; This is a comment line
00076 /* puon: added "cc" */
00077 ;; device name ,name, name location(tl,tc,tr,bl,bc,br,cc),X size in pins,Y size in pins 
00078 7474,74HC74,tr,3,5
00079 ;;
00080 ;; pin name,pin number,shape(line,clock,dot),side(r,l,t,b),pin position
00081 D,2,line,L,1
00082 CLK,3,clock,L,4
00083 
00084 Q,5,line,R,1
00085 /Q,6,dot,R,4
00086 
00087 CLR,4,dot,T,1
00088 PRE,1,dot,B,1
00089 /****************************************************/
00090 #endif
00091 
00092 #ifdef HAVE_CONFIG_H
00093 #include "config.h"
00094 #endif
00095 
00096 #include <stdio.h>
00097 #include <unistd.h>
00098 #include <stdlib.h>
00099 #include <string.h>
00100 #include <ctype.h>
00101 #include <sys/time.h>
00102 #include <time.h>
00103 #include <errno.h>
00104 
00105 #ifdef HAVE_LIBDMALLOC
00106 #include <dmalloc.h>
00107 #endif
00108 
00109 #define BLACK       0
00110 #define WHITE       1
00111 #define RED     2
00112 #define GREEN       3
00113 #define BLUE        4
00114 #define YELLOW      5
00115 #define CYAN        6
00116 #define GREY        7
00117 
00118 #define MAX_FIELDS      10
00119 
00120 #define L_SIDE  0
00121 #define R_SIDE  1
00122 #define B_SIDE  2
00123 #define T_SIDE  3
00124 
00125 #define LINE_SHAPE  0
00126 #define DOT_SHAPE   1
00127 #define CLOCK_SHAPE 2
00128 
00129 #define PINTYPE_IN  "IN"
00130 #define PINTYPE_OUT "OUT"
00131 #define PINTYPE_IO  "IO"
00132 #define PINTYPE_OC  "OC"
00133 #define PINTYPE_OE  "OE"
00134 #define PINTYPE_PAS "PAS"
00135 #define PINTYPE_TP  "TP"
00136 #define PINTYPE_TRI "TRI"
00137 #define PINTYPE_CLK "CLK"
00138 #define PINTYPE_PWR "PWR"
00139 
00140 extern char *optarg;
00141 extern int optind,opterr,optopt;
00142 
00143 /* externals */
00144 int GetStringDisplayLength(char *str,int font_size);
00145 
00146 int line2fields(char *pBuf,int field_cnt,char *pField[]);
00147 int fields_free(char *pField[]);
00148 int make_pin(int fldcnt,char *pFields[]);
00149 int make_box(int fldcnt,char *pFields[]);
00150 static char *strLabel(char *p, char *pTemp);
00151 void strtrail(char *wrk);
00152 int line_chk(char *pBuf);
00153 #if !defined(HAVE_STRCASECMP) && defined(HAVE_STRICMP) && !defined(stricmp)
00154 #define strcasecmp stricmp
00155 #endif
00156 #if !defined(HAVE_STRNCASECMP) && defined(HAVE_STRNICMP) && !defined(strnicmp)
00157 #define strncasecmp strnicmp
00158 #endif
00159 
00160 int pin_len=300;
00161 int pin_spacing=300;
00162 int pin_0_x,pin_0_y;
00163 int BoxHeight,BoxWidth;
00164 int net_pin=0;
00165 
00166 char pin_used[300][5];       /* keep track of pin number used. Assume 300 pins max */
00167 int pin_counter=0;
00168 
00169 /***************************************************/
00170 /***************************************************/
00171 int main(int argc,char **argv)
00172 {
00173   FILE *stream;
00174   char LineBuf[256];
00175   int fldcnt,i,c,Debug=0;
00176   char *pFields[MAX_FIELDS];
00177   int line_nub=0;
00178 
00179   while ((c = getopt(argc, argv, "?hd:")) != EOF)
00180         {
00181         switch (c)
00182           {
00183       case 'd': Debug = 1;
00184                 break;
00185       case '?':
00186           case 'h': 
00187                     fprintf(stderr,"usage: %s -dh?\n",argv[0]);
00188             exit(0);
00189             break;
00190       }
00191         }
00192 
00193   for(i=0;i<MAX_FIELDS;i++)
00194      pFields[i]=NULL;
00195 
00196   stream=stdin;
00197   if (argc > 1)
00198       {
00199       if ((stream = fopen(argv[1],"r")) == NULL)
00200          {
00201          fprintf(stderr, "Cannot open file: %s\n",argv[1]);
00202          exit(-1);
00203          }
00204       }
00205   line_nub=-1;
00206 
00207   printf("v 20030525\n"); /* The v character is the version of the file */
00208 
00209   while (fgets(LineBuf,sizeof(LineBuf)-1,stream) != NULL)
00210         {
00211         if (line_chk(LineBuf) < 0)
00212        continue;
00213     if ((fldcnt = line2fields(LineBuf,10,pFields)) > 0)
00214        {
00215        line_nub++;
00216        if (line_nub == 0)
00217               make_box(fldcnt,pFields);
00218        else
00219               if (make_pin(fldcnt,pFields)< 0) {
00220                     fields_free(pFields);
00221                     break;                /* error processing the pin, get out */
00222               }      
00223            fields_free(pFields);
00224        }
00225     }
00226   fclose(stream);
00227   return 0;
00228 }
00229 
00230 /***************************************************/
00231 /***************************************************/
00232 int fields_free(char *pField[])
00233 { int i;
00234   for (i=0; (i<MAX_FIELDS) && (pField[i] != NULL) ;i++)
00235       {
00236       free(pField[i]);
00237       pField[i] = NULL;
00238       }
00239   return 0;
00240 }
00241 
00242 /***************************************************/
00243 /***************************************************/
00244 int line2fields(char *pBuf,int max_fields,char *pField[])
00245 { char *p,temp[100];
00246   int fld_cnt=0;
00247 
00248  if ((p = strchr(pBuf,'\n')) != NULL)
00249      *p = 0;
00250  if ((p = strchr(pBuf,'\r')) != NULL)
00251      *p = 0;
00252  p = pBuf;
00253  do {
00254     pField[fld_cnt] = NULL;
00255     p = strLabel(p, temp); /* copy the tokens from the string to array */
00256     pField[fld_cnt] = (char *) malloc(strlen(temp) + 1);
00257     strcpy(pField[fld_cnt++], temp);
00258   }  while (*p != 0);
00259  return fld_cnt;
00260 }
00261 
00262 /***************************************************/
00263 /***************************************************/
00264 void cross(int pos_x,int pos_y,int color)
00265 {
00266    printf("L %d %d %d %d %d 0 0 0 -1 -1\n",pos_x+-50,pos_y,pos_x+50,pos_y,color);
00267    printf("L %d %d %d %d %d 0 0 0 -1 -1\n",pos_x,pos_y+50,pos_x,pos_y-50,color);
00268 }
00269 
00270 /***************************************************/
00271 /***************************************************/
00272 void pin_add(int pos_x,int pos_y,char *pin,int shape,int dir,char *name, char *type)
00273 { int x,y;
00274   int xdir=0,ydir=0,font_size=8;
00275 
00276   switch (dir)
00277     {
00278     case L_SIDE: xdir =  1; ydir =  0;
00279         break;
00280     case R_SIDE: xdir = -1; ydir =  0;
00281         break;
00282     case B_SIDE: xdir =  0; ydir =  1;
00283         break;
00284     case T_SIDE: xdir =  0; ydir = -1;
00285         break;
00286     }
00287 
00288   if (shape == LINE_SHAPE)
00289      {
00290      /* Added "0 1" to match the new file format for pins - Chris Ellec */
00291      printf("P %d %d %d %d %d 0 1\n",pos_x,pos_y,
00292                                  pos_x-pin_len*xdir,pos_y-pin_len*ydir,
00293                      WHITE);
00294      printf("{\n");
00295      }
00296   else if (shape == DOT_SHAPE)
00297      {
00298      printf("V %d %d 50 %d 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n",
00299                              pos_x-50*xdir,pos_y-50*ydir,CYAN);
00300      printf("P %d %d %d %d %d 0 1\n",pos_x-100*xdir,pos_y-100*ydir,
00301                                  pos_x-pin_len*xdir,pos_y-pin_len*ydir,
00302                      WHITE);
00303      printf("{\n");
00304      }
00305   else if (shape == CLOCK_SHAPE)
00306      {
00307      printf("L %d %d %d %d %d 0 0 0 -1 -1\n",pos_x-100*ydir,pos_y-100*xdir,
00308                                  pos_x+100*xdir,pos_y+100*ydir,GREEN);
00309      printf("L %d %d %d %d %d 0 0 0 -1 -1\n",pos_x+100*ydir,pos_y+100*xdir,
00310                                  pos_x+100*xdir,pos_y+100*ydir,GREEN);
00311      printf("P %d %d %d %d %d 0 1\n",pos_x,pos_y,
00312                                  pos_x-pin_len*xdir,pos_y-pin_len*ydir,
00313                  WHITE);
00314      printf("{\n");
00315      }
00316    x = pos_x;
00317    y = pos_y;
00318 
00319    /* pin_xy(dir,pin,font_size,&x,&y); */
00320    /* output pinseq */
00321    switch (dir)
00322      {
00323      case L_SIDE:
00324        printf("T %d %d %d %d 0 1 0 6\n",x-50,y+50,YELLOW,font_size);
00325        break;
00326      case R_SIDE:
00327        printf("T %d %d %d %d 0 1 0 0\n",x+50,y+50,YELLOW,font_size);
00328        break;
00329      case B_SIDE:
00330        printf("T %d %d %d %d 0 1 90 6\n",x-50,y-50,YELLOW,font_size);
00331        break;
00332      case T_SIDE:
00333        printf("T %d %d %d %d 0 1 90 0\n",x-50,y+50,YELLOW,font_size);
00334        break;
00335      }
00336    printf("pinseq=%d\n",++net_pin);
00337 
00338    /* output pinnumber */
00339    switch (dir)
00340      {
00341      case L_SIDE:
00342        printf("T %d %d %d %d 1 1 0 6\n",x-50,y+50,YELLOW,font_size);
00343        break;
00344      case R_SIDE:
00345        printf("T %d %d %d %d 1 1 0 0\n",x+50,y+50,YELLOW,font_size);
00346        break;
00347      case B_SIDE:
00348        printf("T %d %d %d %d 1 1 90 6\n",x-50,y-50,YELLOW,font_size);
00349        break;
00350      case T_SIDE:
00351        printf("T %d %d %d %d 1 1 90 0\n",x-50,y+50,YELLOW,font_size);
00352        break;
00353      }
00354    printf("pinnumber=%s\n",pin);
00355 
00356 
00357    if (type)
00358      {
00359        switch (dir)
00360      {
00361      case L_SIDE:
00362        printf("T %d %d %d %d 0 0 0 7\n",pos_x-400,pos_y,YELLOW,font_size);
00363        break;
00364      case R_SIDE:
00365        printf("T %d %d %d %d 0 0 0 1\n",pos_x+400,pos_y,YELLOW,font_size);
00366        break;
00367      case B_SIDE:
00368        printf("T %d %d %d %d 0 0 90 7\n",pos_x,pos_y-400,YELLOW,font_size);
00369        break;
00370      case T_SIDE:
00371        printf("T %d %d %d %d 0 0 90 1\n",pos_x,pos_y+400,YELLOW,font_size);
00372        break;
00373      }
00374        printf("pintype=%s\n",type);
00375      }
00376 
00377   if (strlen(name))
00378     {
00379       switch (dir)
00380     {
00381     case L_SIDE:
00382       printf("T %d %d %d %d 1 1 0 1\n",pos_x+100,pos_y,GREEN,font_size);
00383       break;
00384     case R_SIDE:
00385       printf("T %d %d %d %d 1 1 0 7\n",pos_x-100,pos_y,GREEN,font_size);
00386       break;
00387     case B_SIDE:
00388       printf("T %d %d %d %d 1 1 90 1\n",pos_x,pos_y+100,GREEN,font_size);
00389       break;
00390     case T_SIDE:
00391       printf("T %d %d %d %d 1 1 90 7\n",pos_x,pos_y-100,GREEN,font_size);
00392       break;
00393     }
00394       printf("pinlabel=%s\n",name);
00395     }
00396 
00397 
00398   printf("}\n");
00399 
00400 
00401 
00402 }
00403 
00404 /***************************************************/
00405 /***************************************************/
00406 int make_box(int fldcnt,char *pFields[])
00407 { int pos_x=300,pos_y=300;
00408   char name[100],device[100],name_pos[100];
00409   char uref[100],class[100];
00410   int pin_width,pin_height,font_size=10;
00411   int name_size=0;
00412   int pincount;
00413   char footprint[100];
00414 
00415   strcpy(device,pFields[0]);
00416   strcpy(name,pFields[1]);
00417   strcpy(name_pos,pFields[2]);
00418   pin_width  = atoi(pFields[3]);
00419   pin_height = atoi(pFields[4]);
00420 
00421   pin_0_x  = pin_spacing;
00422   pin_0_y  = pin_spacing*(pin_height + 1);
00423   BoxWidth = pin_width * pin_spacing;
00424   BoxHeight = pin_height * pin_spacing;
00425 
00426   if(fldcnt >=8)
00427   {
00428     strcpy(uref,pFields[5]);
00429     strcat(uref,"?");
00430     if(uref[0]=='U' || uref[0]=='u')strcpy(class,"IC");
00431     if(uref[0]=='J' || uref[0]=='j')strcpy(class,"IO");
00432     if(uref[0]=='C' || uref[0]=='c')strcpy(class,"IO");
00433     /* U is for ICs, J or CONN for IO.  We assume no discretes
00434          *  with this tool */
00435     strcpy(footprint,pFields[6]);
00436     pincount = atoi(pFields[7]);
00437         printf("T %d %d %d %d 0 0 0 0\n",pos_x,pos_y+BoxHeight+1100,YELLOW,font_size);
00438         printf("footprint=%s\n",footprint);
00439         printf("T %d %d %d %d 0 0 0 0\n",pos_x,pos_y+BoxHeight+1300,YELLOW,font_size);
00440         printf("pins=%d\n",pincount);
00441   }
00442   else
00443   {
00444     strcpy(class,"IC");
00445     strcpy(uref,"U?");
00446   }
00447 
00448 
00449      /* new file format: x y width height color width 
00450      end type length space filling fillwidth angle1 pitch1 angle2 pitch2 */
00451   printf("B %d %d %d %d %d 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n",pos_x,pos_y,BoxWidth,BoxHeight,GREEN);
00452   printf("T %d %d %d %d 0 0 0 0\n",pos_x,pos_y+BoxHeight+700,YELLOW,font_size);
00453   printf("device=%s\n",device);
00454   printf("T %d %d %d %d 0 0 0 0\n",pos_x,pos_y+BoxHeight+900,YELLOW,font_size);
00455   printf("class=%s\n",class);
00456   printf("T %d %d %d %d 1 1 0 0\n",pos_x,pos_y+BoxHeight+500,RED,font_size);
00457   printf("refdes=%s\n",uref);
00458 
00459 #if 0
00460   /* Display pin locations */
00461   for (i=0;i <= (BoxHeight/pin_spacing);i++)
00462       cross(pos_x,pos_y+i*pin_spacing,BLUE);
00463 
00464   for (i=0;i <= (BoxWidth/pin_spacing);i++)
00465       cross(pos_x+i*pin_spacing,pos_y,BLUE);
00466 
00467   cross(pin_0_x,pin_0_y,RED);
00468 #endif
00469   if (strlen(name))
00470      {
00471      name_size = GetStringDisplayLength(name,font_size);
00472      /* Vaild positions: tl,tc,tr, bl,bc,br cc */
00473      if (!strcasecmp(name_pos,"tl"))
00474         {
00475         pos_x = pin_0_x;
00476         pos_y = pin_0_y+50;
00477     }
00478      else if (!strcasecmp(name_pos,"tc"))
00479         {
00480         pos_x = pin_0_x+BoxWidth/2-name_size/2;
00481         pos_y = pin_0_y+50;
00482     }
00483      else if (!strcasecmp(name_pos,"tr"))
00484         {
00485         pos_x = pin_0_x+BoxWidth-name_size/2;
00486         pos_y = pin_0_y+50;
00487     }
00488      else if (!strcasecmp(name_pos,"bl"))
00489         {
00490         pos_x = pin_0_x;
00491         pos_y = pin_0_y-BoxHeight-175;
00492     }
00493      else if (!strcasecmp(name_pos,"bc"))
00494         {
00495         pos_x = pin_0_x+BoxWidth/2-name_size/2;
00496         pos_y = pin_0_y-BoxHeight-175;
00497     }
00498      else if (!strcasecmp(name_pos,"br"))
00499         {
00500         pos_x = pin_0_x+BoxWidth-(name_size)/2;
00501         pos_y = pin_0_y-BoxHeight-175;
00502     }
00503      /* puon: begin */
00504      else if (!strcmp(name_pos,"cc"))
00505        {
00506      pos_x = pin_0_x+BoxWidth/2-(name_size)/2;
00507      pos_y = pin_0_y-BoxHeight/2;
00508        }
00509      /* puon: end */
00510      else
00511         {
00512         pos_x = pin_0_x;
00513         pos_y = pin_0_y+50;
00514         }
00515      printf("T %d %d %d %d 1 0 0 0\n",pos_x,pos_y,GREEN,font_size);
00516      printf("%s\n",name);
00517      }
00518   return 0;
00519 }
00520 
00521 /***************************************************/
00522 /***************************************************/
00523 int make_pin(int fldcnt,char *pFields[]) {
00524   int pos_x=0,pos_y=0,shape,side=0,i;
00525   char pin_name[40];
00526   char pin[40];
00527   int pin_pos;
00528   char *type;
00529 
00530   if (fldcnt < 5) {
00531     fprintf (stderr,"\nError, not enough parameters on input line:%i instead of 5 !\n",fldcnt);
00532     fprintf (stderr,"\nPlease fix the input file then try again.\n\n");
00533     return -1;
00534   }
00535   
00536   strcpy(pin_name,pFields[0]);
00537   strcpy(pin,pFields[1]);         /* get pin number */
00538   
00539   for (i=0;i<pin_counter;i++)
00540      if (!strcmp(pin,pin_used[i])) {
00541           fprintf (stderr,"\nFatal Error, pin %s is used more that once !\n\n",pin);
00542           return -1;
00543      }
00544   strncpy(pin_used[pin_counter++],pin,5);    /* save the current pin, the first 5 char */
00545   
00546   shape = LINE_SHAPE;
00547   if (!strcasecmp(pFields[2],"dot"))     /* get shape */
00548      shape = DOT_SHAPE;
00549   if (!strcasecmp(pFields[2],"clock"))   /* get shape */
00550      shape = CLOCK_SHAPE;
00551   if (!strcasecmp(pFields[3],"L")) side = L_SIDE;
00552   else
00553     if (!strcasecmp(pFields[3],"R")) side = R_SIDE;
00554     else      
00555       if (!strcasecmp(pFields[3],"B")) side = B_SIDE;
00556       else    
00557         if (!strcasecmp(pFields[3],"T")) side = T_SIDE;
00558         else {
00559            fprintf (stderr,"\nError, %s not a valid position, should be l,t,b or r.\n",pFields[3]);
00560            return -1;
00561         }
00562           
00563   pin_pos = atoi(pFields[4]);
00564 
00565   type = NULL;
00566   if (pFields[5])
00567   {
00568     if (!strcasecmp(pFields[5],"in"))
00569         type = PINTYPE_IN;
00570     else if ( !strcasecmp(pFields[5],"out"))
00571         type = PINTYPE_OUT;
00572     else if ( !strcasecmp(pFields[5],"io"))
00573         type = PINTYPE_IO;
00574     else if ( !strcasecmp(pFields[5],"oc"))
00575         type = PINTYPE_OC;
00576     else if ( !strcasecmp(pFields[5],"oe"))
00577         type = PINTYPE_OE;
00578     else if ( !strcasecmp(pFields[5],"pas"))
00579         type = PINTYPE_PAS;
00580     else if ( !strcasecmp(pFields[5],"tp"))
00581         type = PINTYPE_TP;
00582     else if ( !strcasecmp(pFields[5],"tri"))
00583         type = PINTYPE_TRI;
00584     else if ( !strcasecmp(pFields[5],"clk"))
00585         type = PINTYPE_CLK;
00586     else if ( !strcasecmp(pFields[5],"pwr"))
00587         type = PINTYPE_PWR;
00588     else
00589       fprintf( stderr, "WARNING: Invalid pin type attribute for pin %s: %s\n", pin_name, pFields[5] );
00590   }
00591 
00592   pos_x = pin_spacing;
00593   if (side == L_SIDE)
00594      {
00595      pos_y = pin_0_y - (pin_spacing*pin_pos);
00596      pos_x = pin_spacing;
00597      }
00598   if (side == R_SIDE)
00599      {
00600      pos_y = pin_0_y - (pin_spacing*pin_pos);
00601      pos_x = pin_spacing + BoxWidth;
00602      }
00603   if (side == B_SIDE)
00604      {
00605      pos_x = pin_0_x + (pin_spacing*pin_pos);
00606      pos_y = pin_spacing;
00607      }
00608   if (side == T_SIDE)
00609      {
00610      pos_x = pin_0_x + (pin_spacing*pin_pos);
00611      pos_y = pin_0_y;
00612      }
00613   pin_add(pos_x,pos_y,pin,shape,side,pin_name,type);
00614   return 0;
00615 }
00616 
00617 /***************************************************/
00618 /* Pull a token from a comma separate string       */
00619 /* delete leading and trailing spaces              */
00620 /***************************************************/
00621 static char *strLabel(char *p, char *pTemp)
00622 {
00623   char *q;
00624   *pTemp = 0;
00625   if ((p == NULL) || (pTemp == NULL))
00626     return NULL;
00627   q = pTemp;
00628   while ((*p == ' ') || (*p == '\t'))
00629     p++;
00630   while (isprint((int) *p) && (*p != ','))    /* copy string to pTemp */
00631     *q++ = *p++;
00632   *q = 0;                       /* terminate the string     */
00633   strtrail(pTemp);              /* drop any trailing spaces */
00634   if (*p == ',')
00635     p++;
00636   return p;
00637 }
00638 
00639 /************************************************/
00640 /* Clear white spaces from the end of a string  */
00641 /************************************************/
00642 void strtrail(char *wrk)
00643 {
00644   char *p;
00645   if (wrk == NULL)
00646     return;
00647  if ((p = strchr(wrk,'\n')) != NULL)
00648      *p = 0;
00649  if ((p = strchr(wrk,'\r')) != NULL)
00650      *p = 0;
00651   while (isspace((int) *(wrk + strlen(wrk) - 1)))     /* Clear any trailing spaces */
00652     *(wrk + strlen(wrk) - 1) = 0;
00653 }
00654 
00655 /************************************************/
00656 /* Check for empty or comment lines             */
00657 /************************************************/
00658 int line_chk(char *pBuf)
00659 {
00660   char *p;
00661   if (pBuf == NULL)
00662     return -1;
00663   if ((p = strchr(pBuf,'\n')) != NULL)
00664      *p = 0;
00665  if ((p = strchr(pBuf,'\r')) != NULL)
00666      *p = 0;
00667   while (isspace((int) *(pBuf + strlen(pBuf) - 1)))     /* Clear any trailing spaces */
00668     *(pBuf + strlen(pBuf) - 1) = 0;
00669   if (*pBuf == ';')
00670      return -1;
00671   if (strchr(pBuf,',') == NULL)
00672       return -1;
00673   return 0;
00674 }
00675 
00676 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines