src/shlss.c

00001 
00006 /*
00007  *  PROGRAM NAME:  sh
00008  *
00009  *  (c) COPYRIGHT INTERNATIONAL BUSINESS MACHINES
00010  *  CORPORATION 12/1/2001.  ALL RIGHTS RESERVED.
00011  *
00012  *  Please refer to the LICENSE file in the top directory
00013  *
00014  *      author: Mike Henderson mhender@watson.ibm.com
00015  */
00016 
00017 static char *id="@(#) $Id: shlss.c,v 1.2 2006/08/17 19:28:17 mhender Exp $";
00018 
00019 #include <shInternal.h>
00020 #include <stdio.h>
00021 #include <math.h>
00022 
00025 #define     Q( X )   #X
00026 #define QUOTE( X ) Q( X )
00027 
00040 void shlss(char *name,int *lname,int *pmag,int *ifnt,int *ierr,int ln)
00041  {
00042 
00043 /*        loads a symbol set */
00044 
00045   char *ssname;
00046   char *cname;
00047   char *file;
00048 
00049   int i,k;
00050   int len=0;
00051   int irem;
00052   int irec,nrec;
00053 
00054   FILE *fid;
00055 
00056   int xref,yref;
00057   char fontnm[20];
00058 
00059 /*                  loads a symbol set */
00060 
00061   *ierr=0;
00062 
00063   cname=(char*)malloc(((*lname)+1)*sizeof(char));
00064   ssname=(char*)malloc(((*lname)+5)*sizeof(char));
00065   strncpy(cname,name,(*lname));
00066   cname[(*lname)]=0x0;
00067   sprintf(ssname,"%s.%4.4d",cname,*pmag);
00068 
00069   file=(char*)malloc((strlen(QUOTE( FONTPATH ))+(*lname)+10)*sizeof(char));
00070   strcpy(file,QUOTE( FONTPATH ) );
00071   strcat(file,ssname);
00072   strcat(file,"IAX");
00073   free(cname);
00074   free(ssname);
00075 
00076 /*   Is it loaded already? */
00077 
00078   if(*ifnt>=sh_kFonts)
00079    {
00080     if(sh_kfont==(int*)NULL)
00081      {
00082       sh_kFonts=10;
00083       sh_kfont=(int*)malloc(sh_kFonts*sizeof(int));
00084      }else{
00085       sh_kFonts=*ifnt+10;
00086       sh_kfont=(int*)realloc((void*)sh_kfont,sh_kFonts*sizeof(int));
00087      }
00088    }
00089 
00090   if(sh_nFonts>0)
00091    {
00092     k=0;
00093     for(i=0;i<sh_nFonts;i++)
00094      {
00095       if(!strcmp(sh_fontnm[i],ssname))k=i;
00096      }
00097    }
00098   if(k!=0)
00099    {
00100     sh_kfont[*ifnt]=k;
00101     *ierr=1;
00102     return;
00103    }
00104 
00105   if((fid=fopen(file,"r"))==(FILE*)NULL)
00106     {
00107      fprintf(stderr,"shSoft Font file -->%s<-- not found\n",file);
00108      free(file);
00109      return;
00110     }
00111   free(file);
00112 
00113 /*                  read in character set */
00114 
00115   if(sh_nFonts>=sh_mFonts)
00116    {
00117     if(sh_mFonts==0)
00118      {
00119       sh_mFonts=10;
00120       sh_dir=(int*)malloc(sh_mFonts*sizeof(int));
00121       sh_fmag=(int*)malloc(sh_mFonts*sizeof(int));
00122       sh_fontnm=(char**)malloc(sh_mFonts*sizeof(char*));
00123      }else{
00124       sh_mFonts=*ifnt+10;
00125       sh_dir=(int*)realloc((void*)sh_dir,sh_mFonts*sizeof(int));
00126       sh_fmag=(int*)realloc((void*)sh_fmag,sh_mFonts*sizeof(int));
00127       sh_fontnm=(char**)realloc((void*)sh_fontnm,sh_mFonts*sizeof(char*));
00128      }
00129    }
00130 
00131   sh_kfont[*ifnt]=sh_nFonts;
00132 
00133   fscanf(fid,"%d",&len);
00134   if(sh_nimg+len>=sh_lenimg)
00135    {
00136     if(sh_lenimg==0)
00137      {
00138       sh_lenimg=sh_nimg+len;
00139       sh_image=(char*)malloc(sh_lenimg*sizeof(char));
00140      }else{
00141       sh_lenimg+=sh_nimg+len;
00142       sh_image=(char*)realloc((void*)sh_image,sh_lenimg*sizeof(char));
00143      }
00144    }
00145 
00146   nrec=floor(len/512);
00147   for(irec=0;irec<nrec;irec++);
00148    {
00149     for(i=0;i<512;i++)sh_image[sh_nimg+512*irec+i]=fgetc(fid);
00150     fgetc(fid);
00151    }
00152   irem=len%512;
00153   if(irem>0)
00154     for(i=0;i<irem;i++)sh_image[sh_nimg+512*nrec+i]=fgetc(fid);
00155   fclose(fid);
00156 
00157   sh_dir[sh_nFonts]=sh_nimg;
00158   sh_fmag[sh_nFonts]=*pmag;
00159   sh_fontnm[sh_nFonts]=(char*)malloc((strlen(ssname)+1)*sizeof(char));
00160   strcpy(sh_fontnm[sh_nFonts],ssname);
00161   sh_nimg+=len;
00162   sh_nFonts++;
00163 
00164   return;
00165  }

Generated on Thu Aug 17 15:29:43 2006 for sh by  doxygen 1.4.6