Example #1
0
String *dScat(String *dest, const char *src, const char *file, int line)
{
    int oldlen = dest->len;

    dest->len += strlen(src);
    lcheck(dest, file, line);
    memcpy(dest->data + oldlen, src, dest->len - oldlen + 1);
    if (dest->charattrs) extend_charattrs(dest, oldlen, 0);
    return dest;
}
Example #2
0
String *dSadd(String *str, int c, const char *file, int line)
{
    str->len++;
    lcheck(str, file, line);
    str->data[str->len - 1] = c;
    str->data[str->len] = '\0';
    if (str->charattrs) {
        str->charattrs[str->len] = str->charattrs[str->len-1];
    }
    return str;
}
Example #3
0
String *dScpy(String *dest, const char *src, const char *file, int line)
{
    dest->len = strlen(src);
    if (dest->charattrs) {
        Sfree(dest, dest->charattrs);
        dest->charattrs = NULL;
    }
    lcheck(dest, file, line);
    memcpy(dest->data, src, dest->len + 1);
    return dest;
}
Example #4
0
/* fast version of dSncat, assumes length of input >= n */
String *dSfncat(String *dest, const char *src, int n, const char *file, int line)
{
    unsigned int oldlen = dest->len;

    if ((int)n < 0) core("dSfncat: n==%ld", file, line, (long)n);
    dest->len += n;
    lcheck(dest, file, line);
    memcpy(dest->data + oldlen, src, n);
    dest->data[dest->len] = '\0';
    if (dest->charattrs) extend_charattrs(dest, oldlen, 0);
    return dest;
}
Example #5
0
String *dSnadd(String *str, int c, int n, const char *file, int line)
{
    int oldlen = str->len;
    if (n < 0) core("dSnadd: n==%ld", file, line, (long)n);
    str->len += n;
    lcheck(str, file, line);
    for (n = oldlen; n < str->len; n++)
        str->data[n] = c;
    str->data[str->len] = '\0';
    if (str->charattrs) extend_charattrs(str, oldlen, 0);
    return str;
}
Example #6
0
String *dStrunc(String *str, int len, const char *file, int line)
{
    /* if (str->size && str->len < len) return str; */
    unsigned int oldlen = str->len;
    str->len = len;
    lcheck(str, file, line);
    if (len <= oldlen) {
        str->data[len] = '\0';
    } else {
        str->len = oldlen;
    }
    return str;
}
/* currently just ignores composites */
void makecomposites(void) {
    BOOL incomp = TRUE;
    char *key, *value;
    key = line;
    if (strncmp(key, "StartComposites",15)!=0)
	return;
    if (warnflag)
        fprintf(stderr,"Warning on line %d, ignoring %s\n",linecount,key);
    while ( incomp && (fgets(line, sizeof(line), inf)!=(char *)NULL) ) {
    	linecount++;
	lcheck();
	value = strchr(line, '\n');
	if (value)
	    *value = '\0';	/* remove trailine \n */
        if (strcmp(key, "EndComposites")==0) {
            incomp = FALSE;
            continue;
        }
    }
    fgets(line, sizeof(line), inf);
    linecount++;
    lcheck();
}
Example #8
0
/* slow version of dSncat, verifies that length of input >= n */
String *dSncat(String *dest, const char *src, int n, const char *file, int line)
{
    int oldlen = dest->len;
    int len = strlen(src);

    if (n < 0) core("dSncat: n==%ld", file, line, (long)n);
    if (n > len) n = len;
    dest->len += n;
    lcheck(dest, file, line);
    memcpy(dest->data + oldlen, src, n);
    dest->data[dest->len] = '\0';
    if (dest->charattrs) extend_charattrs(dest, oldlen, 0);
    return dest;
}
Example #9
0
/* Make the position 'start' the beginning of the string.
 * Another way to think about it is it removes the first 'start'
 * number of bytes from the string, shifting it over.
 * Tight error-checking, because we're in a critical section.
 */
String *dSshift(String *str, int start, const char *file, int line)
{
    if (start < 0)
        core("dSshift: start==%ld (<0)", file, line, (long)start);
    if (start > str->len)
        core("dSshift: start==%ld (>str->len)", file, line, (long)start);
/*    if (start == str->len)
        return dStrunc(str, 0, file, line); */
    if (start == 0)
        return str;
    str->len = str->len - start;
    lcheck(str, file, line); /* Don't really need this... */
    memmove(str->data, str->data + start, str->len + 1);
    return str;
}
Example #10
0
/** Parse identifier.
 *
 * @param parse		Parser object.
 * @return		New syntax tree node.
 */
stree_ident_t *parse_ident(parse_t *parse)
{
	stree_ident_t *ident;

#ifdef DEBUG_PARSE_TRACE
	printf("Parse identifier.\n");
#endif
	lcheck(parse, lc_ident);
	ident = stree_ident_new();
	ident->sid = lcur(parse)->u.ident.sid;
	ident->cspan = lcur_span(parse);
	lskip(parse);

	return ident;
}
Example #11
0
String *dSScpy(String *dest, const conString *src, const char *file, int line)
{
    if (dest->charattrs && !src->charattrs) {
        Sfree(dest, dest->charattrs);
        dest->charattrs = NULL;
    }
    dest->len = src->len;
    lcheck(dest, file, line);
    memcpy(dest->data, src->data ? src->data : "", src->len+1);
    if (src->charattrs) {
        check_charattrs(dest, 0, 0, file, line);
        memcpy(dest->charattrs, src->charattrs, sizeof(cattr_t) * (src->len+1));
    }
    dest->attrs = src->attrs;
    return dest;
}
Example #12
0
String *dSncpy(String *dest, const char *src, int n, const char *file, int line)
{
    int len = strlen(src);

    if (n < 0) core("dSncpy: n==%ld", file, line, (long)n);
    if (n > len) n = len;
    dest->len = n;
    if (dest->charattrs) {
        Sfree(dest, dest->charattrs);
        dest->charattrs = NULL;
    }
    lcheck(dest, file, line);
    memcpy(dest->data, src, n);
    dest->data[n] = '\0';
    return dest;
}
Example #13
0
/* if len is negative, copy from 'start' to src->len */
String *dSSoncat(String *dest, const conString *src, int start, int len,
    const char *file, int line)
{
    int oldlen = dest->len;
    int i, j;
    cattr_t cattrs;

    if (len < 0)
        len = src->len - start;
    dest->len += len;
    lcheck(dest, file, line);
    /* memcpy(dest->data + oldlen, src->data ? src->data + start: "", len); */
    memcpy(dest->data + oldlen, src->data + start, len);
    dest->data[dest->len] = '\0';

    if (src->charattrs || dest->charattrs || src->attrs != dest->attrs) {
        if (dest->charattrs && dest->attrs) {
	    cattrs = attr2cattr(dest->attrs);
            for (i = 0; i < oldlen; i++)
                dest->charattrs[i] = adj_attr(cattrs, dest->charattrs[i]);
        } else {
            check_charattrs(dest, oldlen, dest->attrs, file, line);
        }
        dest->attrs = 0;

        if (src->charattrs && src->attrs) {
	    cattrs = attr2cattr(src->attrs);
	    for (i = oldlen, j = start; i < dest->len; i++, j++)
                dest->charattrs[i] = adj_attr(cattrs, src->charattrs[j]);
        } else if (src->charattrs) {
            memcpy(dest->charattrs + oldlen, src->charattrs + start,
                sizeof(cattr_t) * len);
        } else {
	    for (i = oldlen; i < dest->len; i++)
                dest->charattrs[i] = src->attrs;
        }
        dest->charattrs[dest->len] = 0;
    }

    return dest;
}
Example #14
0
/** Verify that lclass of current lem is @a lc and go to next lem.
 *
 * If a lem of different lclass is found, a parse error is raised and
 * a message is printed.
 *
 * @param parse		Parser object.
 * @param lc		Expected lclass.
 */
void lmatch(parse_t *parse, lclass_t lc)
{
#ifdef DEBUG_LPARSE_TRACE
	printf("lmatch(");
	lclass_print(lc);
	printf(")\n");
#endif
	/*
	 * This allows us to skip error checking in many places. If there is an
	 * active error, lmatch() does nothing (similar to parse_block(), etc.
	 *
	 * Without this measure we would have to check for error all the time
	 * or risk requiring extra input from the user (in interactive mode)
	 * before actually bailing out from the parser.
	 */
	if (parse_is_error(parse))
		return;

	lcheck(parse, lc);
	lskip(parse);
}
void makeheader(void) {
    BOOL inhdr = TRUE;
    BOOL isafm = FALSE;
    BOOL gotcopyright = FALSE;
    char *key, *value;
    key = line;
    while ( inhdr && (fgets(line, sizeof(line), inf)!=(char *)NULL) ) {
    	linecount++;
	lcheck();
	value = strchr(line, '\n');
	if (value)
	    *value = '\0';	/* remove trailine \n */
	value = strchr(line, ' ');
	if (value)
	    *value++ = '\0';	/* separate key from value */
	if (strcmp(key, "StartFontMetrics")==0) {
	    isafm = TRUE;
	    vcheck(key, value);
	    continue;
	}
	if (!isafm) {
	    fputs("Error: Not an AFM file\n", stderr);
	    exit(2);
	}
	if (strcmp(key, "FontName")==0) {
	    vcheck(key, value);
	    strcpy(fontname, value);
	    if (strstr(fontname, "Italic")!=(char *)NULL)
		pfm.dfItalic = 1;
	}
	else if (strcmp(key, "FamilyName")==0) {
	    vcheck(key, value);
	    strcpy(facename, value);
	    /* should scan name and guess dfPitchAndFamily field */
	}
	else if (strcmp(key, "Notice")==0) {
	    vcheck(key, value);
	    strncpy(pfm.dfCopyright, value, sizeof(pfm.dfCopyright)-1);
	}
	else if (strcmp(key, "EncodingScheme")==0) {
		vcheck(key, value);
		if (strcmp(value, "AdobeStandardEncoding")!=0)
		    pfm.dfCharSet = 2;   /* use Symbol */
	}
	else if (strcmp(key, "Weight")==0) {
	    vcheck(key, value);
	    if (strcmp(value,"Bold")==0)
	    	pfm.dfWeight = 700;
	    else if (strcmp(value,"Light")==0)
	        pfm.dfWeight = 300;
	    else
	        pfm.dfWeight = 400;
	}
	else if (strcmp(key, "IsFixedPitch")==0) {
	    vcheck(key, value);
	    if (strcmp(value,"false")==0) 
	        pfm.dfPitchAndFamily |= 1;	/* variable width */
	}
	else if (strcmp(key, "FontBBox")==0) {
	    vcheck(key, value);
	    if (sscanf(value,"%d %d %d %d", &fbbox.llx, &fbbox.lly, &fbbox.urx, &fbbox.ury)!=4) {
	    	fprintf(stderr,"Error on line %d, missing value\n",linecount);
		exit(2);
	    }
	}
	else if (strcmp(key, "CapHeight")==0) {
	    vcheck(key, value);
	    etm.etmCapHeight = atoi(value);
	}
	else if (strcmp(key, "XHeight")==0) {
	    vcheck(key, value);
	    etm.etmXHeight = atoi(value);
	}
	else if (strcmp(key, "Ascender")==0) {
	    vcheck(key, value);
	    ascender = atoi(value);
	}
	else if (strcmp(key, "Descender")==0) {
	    vcheck(key, value);
	    descender = atoi(value);
	}
	else if (strcmp(key, "ItalicAngle")==0) {
	    vcheck(key, value);
	    etm.etmSlant = (short)(atof(value)*10);
	    if (etm.etmSlant)
		pfm.dfItalic = 1;
	}
	else if (strcmp(key, "UnderlinePosition")==0) {
	    vcheck(key, value);
	    etm.etmUnderlineOffset = -atoi(value);
	}
	else if (strcmp(key, "UnderlineThickness")==0) {
	    vcheck(key, value);
	    etm.etmUnderlineWidth = atoi(value);
	}
	else if (strcmp(key, "StartCharMetrics")==0) {
	    vcheck(key, value);
	    charcount = atoi(value);
	    inhdr = FALSE;
	}
	else if (strcmp(key, "FullName")==0) {
	    /* nop */
	}
	else if (strcmp(key, "Comment")==0) {
	    /* nop */
	}
	else if (strcmp(key, "Version")==0) {
	    /* nop */
	}
    	else {
	    if (warnflag) {
		fprintf(stderr,"Warning on line %d: Unknown key: %s ",linecount,key);
    	        if (value)
    	           fputs(value,stderr);
	        fputc('\n',stderr);
	    }
    	}
    }
    /* time for StartCharMetric */
}
Example #16
0
int main (int argc, char *argv[])
   {
      stat   *a,*b;
      hit     h;
      int     p[FIELDS];
      char    str[256], str_last[256];
      char   *s;

      int     i, j, w, c, len = 0;
      idtype     id, threshold, sizelog = SIZELOG;
      

      a = (stat *) malloc ( sizeof (stat) * 1 << sizelog );
      b = (stat *) malloc ( sizeof (stat) * 1 << sizelog );

      threshold = atol ( argv[1] );

      while ( gets (str) )
	 {
	    s = rindex (str, ' ') + 1;
	    
	    str [ s - str - 1 ] = '\0';

	    readhit (str, &h);
	    c = atol (s);

	    if ( c < threshold ) lcheck (&h);

	    id = getid ( &h );

	    if ( !len ) 
	       { 
		  a[0].n = id; 
		  a[0].c = c; 

		  len++; 
	       }
	    else 
	       {
		  w = bfind (a, id, len);

		  if ( w == len )
		    {
		      a[w].n = id;
		      a[w].c = c;

		      len++;
		    }
		  else if ( a[w].n == id ) a[w].c+=c;
		  else 
		    {
		      memcpy ((char *)b, (char *)a + w * sizeof(stat), (len - w) * sizeof(stat));
		      a[w].n = id;
		      a[w].c = c;

		      memcpy ((char *)a + (w + 1) * sizeof(stat), (char *)b, (len - w) * sizeof(stat)); 

		      len++;
		      /*fprintf (stderr, "%d\n", len);*/
/*
		      if ( len == 2 << sizelog )
			{
			  sizelog++;
			  a = (stat *) realloc ( a, sizeof (stat) * 1 << sizelog );
			  b = (stat *) realloc ( b, sizeof (stat) * 1 << sizelog );
			}
 */
		    }
		}
	  }


      for ( i = 0; i < len; i++ )
	 {
	    unpackid (a[i].n, &h);

	    printf ("%d", h.i[0]);

	    for ( j = 1; j < FIELDS; j++ )
	       printf ("_%d", h.i[j]);

	    printf (" %d\n", a[i].c);
	 }

      return 0;

   }
/* ignores kern track info */
void makekern(void) {
    BOOL inkern = TRUE;
    BOOL inpair = FALSE;
    BOOL intrack = FALSE;
    char *key, *value, *p, *pair1, *pair2;
    int i, c1, c2, kerncount, kerncount2;
    key = line;
    value = strchr(line, '\n');
    if (value)
        *value = '\0';	/* remove trailine \n */
    if (strncmp(key, "StartKernData",13)!=0)
	return;
    while ( inkern && (fgets(line, sizeof(line), inf)!=(char *)NULL) ) {
    	linecount++;
	lcheck();
	value = strchr(line, '\n');
	if (value)
	    *value = '\0';	/* remove trailine \n */
        if (strcmp(key, "EndKernData")==0) {
            inkern = FALSE;
            if (inpair && warnflag)
		fprintf(stderr,"Warning on line %d, expecting EndKernPairs\n",linecount);
            continue;
        }
        else if (strncmp(key, "StartKernTrack", 14)==0) {
	    intrack = TRUE;
	    if (warnflag)
	        fprintf(stderr,"Warning on line %d, ignoring StartKernTrack\n",linecount);
	}
        else if (strcmp(key, "EndKernTrack")==0) {
	    intrack = FALSE;
	}
        else if (strncmp(key, "StartKernPairs", 14)==0) {
            inpair = TRUE;
	    value = strchr(line, ' ');
	    vcheck(key, value);
	    kerncount = atoi(value);
	    kerncount2 = 0;
	    continue;
        }
        else if (strcmp(key, "EndKernPairs")==0) {
            inpair = FALSE;
            etm.etmKernPairs = ckernpair;
            continue;
        }
        else if (inpair) {
	    key = strtok(line, " ");
	    if (!key)
	        continue;
	    if (strcmp(key, "KPX")==0) {
	        pair1 = strtok(NULL," ");
	        vcheck(key, pair1);
	        pair2 = strtok(NULL," ");
	        vcheck(key, pair2);
	        value = strtok(NULL," ");
	        vcheck(key, value);
	        c1 = c2 = -1;
	        for (i = 0; i < 256; i++)
	            if (name[i] && (strcmp(name[i],pair1)==0)) {
	                c1 = i;
	                break;
	            }
	        for (i = 0; i < 256; i++)
	            if (name[i] && (strcmp(name[i],pair2)==0)) {
	                c2 = i;
	                break;
	            }
		kerncount2++;
		if (kerncount2 > kerncount) {
		    if (warnflag)
	    	        fprintf(stderr,"Warning on line %d, too many kern pairs, ignoring extras\n",linecount);
		}
		else if (ckernpair > sizeof(kernpair)/sizeof(KERNPAIR)) {
		    if (warnflag)
	    	        fprintf(stderr,"Warning on line %d, too many kern pairs, ignoring extras\n",linecount);
		}
		else if (c1==-1) {
		    if (warnflag)
	    	        fprintf(stderr,"Warning on line %d, ignoring kerning for unencoded character: %s\n",linecount, pair1);
		}
		else if (c2==-1) {
		    if (warnflag)
	    	        fprintf(stderr,"Warning on line %d, ignoring kerning for unencoded character: %s\n",linecount, pair2);
		}
		else {
		    kernpair[ckernpair].kpPair.each[0] = c1;
		    kernpair[ckernpair].kpPair.each[1] = c2;
		    kernpair[ckernpair].kpKernAmount = atoi(value);
		    ckernpair++;
		}
	    }
	    else {
		if (warnflag)
	    	    fprintf(stderr,"Warning on line %d, ignoring %s\n",linecount,key);
	    }
	    if (pair1)
	        value++;
	    while (value && (*value == ' '))
		value++;
        }
	else if (intrack) {
	    /* ignore it */
	}
	else {
	    if (warnflag)
    	        fprintf(stderr,"Warning on line %d, ignoring %s\n",linecount,key);
	}
    }
    fgets(line, sizeof(line), inf);
    linecount++;
    lcheck();
}
void makeextent(void) {
    int c, len;
    BOOL inmetric = TRUE;
    char *key, *value, *p;
    pfm.dfFirstChar = 255;
    pfm.dfLastChar = 0;
    if (strncmp(line, "StartCharMetrics",16)!=0) {
        fprintf(stderr,"Error on line %d, expecting StartCharMetrics\n",linecount);
        exit(2);
    }
    while ( inmetric && (fgets(line, sizeof(line), inf)!=(char *)NULL) ) {
    	linecount++;
	lcheck();
    	c = 0;
        key = line;
	value = strchr(line, '\n');
	if (value)
	    *value = '\0';	/* remove trailine \n */
        if (strcmp(key, "EndCharMetrics")==0) {
            pfm.dfAvgWidth = sumwidth / (pfm.dfLastChar - pfm.dfFirstChar + 1); /* wrong - should be weighted */
            pfm.dfMaxWidth = maxwidth;
            inmetric = FALSE;
        }
	key = strtok(line, ";");
	while (inmetric && key) {
	    while (*key == ' ')
		key++;
	    value = strchr(key,' ');
	    if (value)
	        value++;
	    while (value && (*value == ' '))
		value++;
	    if (strncmp(key, "C ", 2)==0) {
	        vcheck(key, value);
	        c = atoi(value);
	        if ((c>0) && (c<pfm.dfFirstChar))
	            pfm.dfFirstChar = c;
	        if ((c>0) && (c>pfm.dfLastChar))
	            pfm.dfLastChar = c;
	        if ( (c<0) && warnflag )
	    	    fprintf(stderr,"Warning on line %d, ignoring %s\n",linecount,key);
	    }
	    else if (strncmp(key, "WX ",3)==0) {
	        vcheck(key, value);
	        if (c>=0) {
	            extent[c] = atoi(value);
		    sumwidth += extent[c];
		    if (extent[c] > maxwidth)
		        maxwidth = extent[c];
	        }
	    }
	    else if (strncmp(key, "N ",2)==0) {
		vcheck(key, value);
	        if (c>=0) {
		    p = strchr(value, ' ');
		    if (p)
		        len = p - value;
	            else
	                len = strlen(value);
	            if ( (len+1) < BUFSIZE-(ntail-nbuffer) ) {
	                name[c] = ntail;
	                strncpy(ntail, value, len);
	                ntail += len;
	                *ntail++ = '\0';
	            }
	            else {
	                fprintf(stderr,"Error on line %d: out of memory for names\n",
	                    linecount);
	                exit(2);
	            }
		}
	    }
	    else if (strncmp(key, "B ",2)==0) {
		vcheck(key, value);
	        if (c>=0) {
	            if (sscanf(value,"%d %d %d %d", &cbbox[c].llx, &cbbox[c].lly, 
				&cbbox[c].urx, &cbbox[c].ury)!=4) {
	    	        fprintf(stderr,"Error on line %d, missing BoundingBox value\n",linecount);
		        exit(2);
	            }
		}
	    }
	    else if (strncmp(key, "L ",2)==0) {
	    	/* ignore it */
	    }
	    else {
		if (warnflag)
	    	    fprintf(stderr,"Warning on line %d, ignoring %s\n",linecount,key);
	    }
	    key = strtok(NULL, ";");
	}
    }
    fgets(line, sizeof(line), inf);
    linecount++;
    lcheck();
    if (pfm.dfFirstChar > pfm.dfLastChar)
	pfm.dfFirstChar = pfm.dfLastChar;
    /* now fix up some dimensions */
    if (pfm.dfMaxWidth == 0)
	pfm.dfMaxWidth = fbbox.urx - fbbox.llx;	/* guess from font bbox */
    pfm.dfAscent = fbbox.ury;
    if ((pfm.dfCharSet==0) && name['d'] && *name['d'] && (strcmp(name['d'], "d")==0) && (cbbox['d'].ury))
        etm.etmLowerCaseAscent = cbbox['d'].ury;
    else {
	if (ascender) {
	    if (warnflag)
	        fprintf(stderr,"Warning: setting lower case ascent from AFM Ascender\n");
            etm.etmLowerCaseAscent = ascender;
	}
	else {
	    if (warnflag)
	        fprintf(stderr,"Warning: setting lower case ascent from font bounding box\n");
            etm.etmLowerCaseAscent = fbbox.ury;
        }
    }
    if ((pfm.dfCharSet==0) && name['p'] && *name['p'] && (strcmp(name['p'], "p")==0) && (cbbox['p'].lly))
        etm.etmUpperCaseDescent = cbbox['p'].lly;
    else {
	if (descender) {
	    if (warnflag)
	        fprintf(stderr,"Warning: setting upper case descent from AFM Descender\n");
            etm.etmUpperCaseDescent = descender;
	}
	else {
	    if (warnflag)
	        fprintf(stderr,"Warning: setting upper case descent from font bounding box\n");
            etm.etmUpperCaseDescent = fbbox.lly;
        }
    }
    if ((etm.etmXHeight==0) && (pfm.dfCharSet==0) && *name['x'] && 
        (strcmp(name['x'], "x")==0) && (cbbox['x'].ury))
        etm.etmXHeight = cbbox['x'].ury;
    if ((etm.etmCapHeight==0) && (pfm.dfCharSet==0) && *name['H'] && 
        (strcmp(name['H'], "H")==0) && (cbbox['H'].ury))
        etm.etmCapHeight = cbbox['H'].ury;
    pfm.dfPixHeight = fbbox.ury - fbbox.lly;
    pfm.dfPixWidth  = fbbox.urx - fbbox.llx;
    makeaverage();
}