Exemplo n.º 1
0
int main(int argc, char **argv) {
    char s[] = "viva las vegas";
    strip_char(s, 'v');
    printf("\n\nNew string is: %s\n", s);
    cheers();
    return 0;
}
Exemplo n.º 2
0
/* get the macos name for the font instance and mangle it into a PS
   fontname */
static char *makePSFontName(FMFontFamily Family, FMFontStyle Style)
{
        Str255 Name;
        OSStatus result;
        int length;
        char *stylename, *fontname;
        char *psname;

        result = FMGetFontFamilyName(Family, Name);
        if (result != noErr) return NULL;
        fontname = MacStr2c(Name);
        if (fontname == NULL) return NULL;
        strip_char(fontname, strlen(fontname), ' ');

        switch (Style) {
                case 0: stylename=""; break;;
                case 1: stylename="Bold"; break;;
                case 2: stylename="Italic"; break;;
                case 3: stylename="BoldItalic"; break;;
                default: stylename="Unknown"; break;;
        }

        length = strlen(fontname) + strlen(stylename) + 2;
        psname = malloc(length);
        if (Style != 0)
                snprintf(psname, length, "%s-%s", fontname, stylename);
        else
                snprintf(psname, length, "%s", fontname);

        free(fontname);

        return psname;
}
Exemplo n.º 3
0
static char * read_win_text (VFSFile * file)
{
    int64_t size = vfs_fsize (file);
    if (size < 1)
        return NULL;

    char * raw = malloc (size + 1);
    size = vfs_fread (raw, 1, size, file);
    raw[size] = 0;

    strip_char (raw, '\r');
    char * text = str_to_utf8 (raw);
    free (raw);
    return text;
}
Exemplo n.º 4
0
int read_pdb(FILE *pdbInFile, Str *str, int coarse, int hydrogens)
{
	unsigned int i, j;
	unsigned int k = 0;
	char line[80];
	char stopline[80] = "";
    int stopflag = 0;
	unsigned int allocated_atom = 64;
	unsigned int allocated_residue = 64;
	char atomName[] = "    ";
	char resbuf;
	int ca_p = 0;
	/* for HETATM entries */
	regex_t *regexPattern; /* regular atom patterns */
	/* allowed HETATM atom types (standard N,CA,C,O) and elements (any N,C,O,P,S) */
	const int nHetAtom = 9;
	char hetAtomPattern[9][32] = {{" N  "},{" CA "},{" C  "},{" O  "},{".{1}C[[:print:]]{1,3}"},{".{1}N[[:print:]]{1,3}"},{".{1}O[[:print:]]{1,3}"},{".{1}P[[:print:]]{1,3}"},{".{1}S[[:print:]]{1,3}"}};
	char hetAtomNewname[9][32] = {{" N  "},{" CA "},{" C  "},{" O  "},{" C_ "},{" N_ "},{" O_ "},{" P_ "},{" S_ "}};

	/*____________________________________________________________________________*/
	/* initialise/allocate memory for set of (64) selected (CA) atom entries */
	str->nAtom = 0;
	str->nAllAtom = 0;
	str->nResidue = 0;
	str->nAllResidue = 0;
	str->nChain = 0;
	
	str->atom = safe_malloc(allocated_atom * sizeof(Atom));
	str->atomMap = safe_malloc(allocated_atom * sizeof(int));

	/* allocate memory for sequence residues */
	str->sequence.res = safe_malloc(allocated_residue * sizeof(char));

	/* compile allowed HETATM element patterns */
	regexPattern = safe_malloc(nHetAtom * sizeof(regex_t));
	compile_patterns(regexPattern, &(hetAtomPattern[0]), nHetAtom);

	/*____________________________________________________________________________*/
    /* count the number of models */
    while(fgets(line, 80, pdbInFile) != 0) {
        if (strncmp(line, "MODEL ", 6) == 0) {
            if (stopflag == 0) {
                stopflag = 1;
                continue;
            } else {
                strcpy(stopline, line);
                break;
            }
        }
    }

    /* rewind the file handle to the start */
	if (fseek(pdbInFile, 0L, SEEK_SET) != 0) {
		/* handle repositioning error */
	}

	/*____________________________________________________________________________*/
	/* not all PDB data types are used in this program to save resources */
    while(fgets(line, 80, pdbInFile) != 0) {
		ca_p = 0; /* CA or P flag */

		/*____________________________________________________________________________*/
		/* check conditions to start assigning this entry */
		/* skip other models */
		if((strcmp(line, stopline) == 0) && (stopflag == 1))
			break;

		/* read only ATOM/HETATM records */
		if((strncmp(line, "ATOM  ", 6) != 0) && (strncmp(line, "HETATM", 6) != 0))
			continue;

        /* skip alternative locations except for location 'A' */ 
		if (line[16] != 32 && line[16] != 65) {
			/*fprintf(stderr, "Warning: Skipping atom %d in alternative location %c\n",
				atoi(&line[6]), line[16]);*/
			continue;
		}

		/*____________________________________________________________________________*/
		/* read this entry */
		/* atom number */
		str->atom[str->nAtom].atomNumber = atoi(&line[6]);

		/* atom name */
		for (i = 12, j = 0; i < 16; )
			str->atom[str->nAtom].atomName[j++] = line[i++];
		str->atom[str->nAtom].atomName[j] = '\0';

		/* alternative location */
		/*str->atom[str->nAtom].alternativeLocation[0] = line[16];	
		str->atom[str->nAtom].alternativeLocation[1] = '\0';*/

		/* residue name */
		for (i = 17, j = 0; i < 20; )
			str->atom[str->nAtom].residueName[j++] = line[i++];
		str->atom[str->nAtom].residueName[j] = '\0';

		/* chain identifier */
		str->atom[str->nAtom].chainIdentifier[0] = line[21];
		str->atom[str->nAtom].chainIdentifier[1] = '\0';

		/* residue number */
		str->atom[str->nAtom].residueNumber = atoi(&line[22]);

		/* code for insertion of residues */
		/*str->atom[str->nAtom].icode[0] = line[26];
		str->atom[str->nAtom].icode[1] = '\0';*/

		/* coordinates */
		str->atom[str->nAtom].pos.x = atof(&line[30]);
		str->atom[str->nAtom].pos.y = atof(&line[38]);
		str->atom[str->nAtom].pos.z = atof(&line[46]);

		/*printf("x %6.4f, y %6.4f, z %6.4f\n", str->atom[str->nAtom].x,
			str->atom[str->nAtom].y, str->atom[str->nAtom].z);*/

		/* occupancy */
		/*str->atom[str->nAtom].occupancy = atof(&line[54]);*/

		/* temperature factor */
		/*str->atom[str->nAtom].temp_f = atof(&line[60]);*/

		/* segment identifier */
		/*for (i = 72, j = 0; i < 76; )
			str->atom[str->nAtom].segmentIdentifier[j++] = line[i++];
		str->atom[str->nAtom].segmentIdentifier[j] = '\0';*/

		/* element */
		for (i = 76, j = 0; i < 78; )
			str->atom[str->nAtom].element[j++] = line[i++];
		str->atom[str->nAtom].element[j] = '\0';

		/* charge */
		/*for (i = 78, j = 0; i < 80; )
			str->atom[str->nAtom].charge[j++] = line[i++];
		str->atom[str->nAtom].charge[j] = '\0';*/

		/* description: everything before coordinates */
		for (i = 0, j = 0; i < 30; )
			str->atom[str->nAtom].description[j++] = line[i++];
		str->atom[str->nAtom].description[j] = '\0';

		/*____________________________________________________________________________*/
		/* check conditions to record this entry */
		/* if no hydrogens set, skip hydrogen lines */
		if (! hydrogens) {
			strip_char(str->atom[str->nAtom].atomName, &(atomName[0]));
			/* skip patterns 'H...' and '?H..', where '?' is a digit */
			if ((atomName[0] == 'H') || \
				((atomName[0] >= 48) && (atomName[0] <= 57) && (atomName[1] == 'H'))) {
				++ str->nAllAtom;
				continue;
			}
		}

		/* check whether ATOM residue name is standard */
		if (strncmp(line, "ATOM  ", 6) == 0)
			resbuf = aacode(str->atom[str->nAtom].residueName);
			
		/* detect CA and P atoms of standard residues for residue allocation */
		if ((strncmp(line, "ATOM  ", 6) == 0) &&
			((strncmp(str->atom[str->nAtom].atomName, " CA ", 4) == 0) ||
			(strncmp(str->atom[str->nAtom].atomName, " P  ", 4) == 0))) {
			str->sequence.res[k++] = aacode(str->atom[str->nAtom].residueName);
			++ ca_p;
			if (k == allocated_residue)
				str->sequence.res = safe_realloc(str->sequence.res, (allocated_residue += 64) * sizeof(char));
		}

		/* standardise non-standard atom names */
		standardise_name(str->atom[str->nAtom].residueName, str->atom[str->nAtom].atomName);

		/* process HETATM entries */
		if (strncmp(line, "HETATM", 6) == 0)
			if (process_het(str, &(line[0]), regexPattern, &(hetAtomNewname[0]), nHetAtom) != 0)
				continue;

		/* in coarse mode record only CA and P entries */
		if (!ca_p && coarse)
			continue;

		/*____________________________________________________________________________*/
		/* count number of allResidues (including HETATM residues) */
        if (str->nAtom == 0 || str->atom[str->nAtom].residueNumber != str->atom[str->nAtom - 1].residueNumber)
			++ str->nAllResidue;

		/*____________________________________________________________________________*/
		/* count number of chains */
        if (str->nAtom == 0 || str->atom[str->nAtom].chainIdentifier[0] != str->atom[str->nAtom - 1].chainIdentifier[0])
			++ str->nChain;

		/*____________________________________________________________________________*/
		/* recors original atom order (count) */
		str->atomMap[str->nAtom] = str->nAllAtom;
		/* increment to next atom entry */
		++ str->nAtom;
		++ str->nAllAtom;

		/*____________________________________________________________________________*/
		/* allocate more memory if needed */
		if (str->nAtom == allocated_atom) {
			allocated_atom += 64;
			str->atom = safe_realloc(str->atom, allocated_atom * sizeof(Atom));
			str->atomMap = safe_realloc(str->atomMap, allocated_atom * sizeof(int));
		}
	}
	str->sequence.res[k] = '\0';
	str->nResidue = k;

	/*____________________________________________________________________________*/
	/* free the compiled regular expressions */
	free_patterns(regexPattern, nHetAtom);
	free(regexPattern);

	/*____________________________________________________________________________*/
	return 0;
}
/**
 * Parse a single property from the raw CSS data. Ignore any property
 * not beginning with "-aese-". Such properties specify
 * the xml attribute name and its corresponding html name. The attribute
 * value is the same in both cases. Such properties are supposed to be
 * ignored by browser-based css parsers
 * @param data the raw CSS data read from the file
 * @param len the length of the property in data
 * @return an allocated css_property (caller must eventually dispose it)
 */
css_property *css_property_parse( const char *data, int len )
{
    // format: -aese-xml_name: html_name;
    // copy the attribute value over from the xml unchanged (not here)
	int i,start=0, end=len;
    css_property *prop_temp = NULL;
    // the property name had an escaped ":"
	int escaped = 0;
    while ( start<end && isspace(data[start]) )
    {
		start++;
        end--;
    }
	if ( strncmp(&data[start],AESE_PREFIX,AESE_PREFIX_LEN)==0 )
    {
        start += AESE_PREFIX_LEN;
        i = start;
        while ( i < end )
        {
            if ( data[i]=='\\' )
            {
                escaped = 1;
                i+=2;
            }
            else if ( data[i] == ':' )
            {
                // parse left hand side
                prop_temp = calloc( 1, sizeof(css_property) );
                if ( prop_temp != NULL )
                {
                    int lhs_len = i-start;
                    prop_temp->xml_name = calloc( 1, lhs_len+1 );
                    if ( prop_temp->xml_name != NULL )
                    {
                        strncpy( prop_temp->xml_name, &data[start], lhs_len );
                        if ( escaped )
                            strip_char(prop_temp->xml_name,'\\');
                        // parse right hand side
                        i++;
                        while ( i<end && isspace(data[i]) )
                            i++;
                        while ( end>i && isspace(data[end]) )
                            end--;
                        if ( i < end )
                        {
                            int rhs_len = (end-i)+1;
                            prop_temp->html_name = calloc( 1, rhs_len+1 );
                            if ( prop_temp->html_name != NULL )
                            {
                                strncpy( prop_temp->html_name, &data[i], 
                                    rhs_len );
                                break;
                            }
                            else
                            {
                                css_property_dispose( prop_temp );
                                warning("css_property: failed to allocate"
                                    "html name\n");
                                prop_temp = NULL;
                            }
                        }
                        else
                        {
                            warning("css_property: missing html name\n");
                            css_property_dispose( prop_temp );
                            prop_temp = NULL;
                        }
                    }
                    else
                    {
                        css_property_dispose( prop_temp );
                        warning( "css_property: failed to allocate xml_name\n");
                        prop_temp = NULL;
                    }
                }
                else
                {
                    warning("css_property: failed to allocate css_property\n");
                }
            }
            i++;
        }
    }
	return prop_temp;
}