Ejemplo n.º 1
0
  bool get_word_NEXUS(string& word, int& i, const string& s)
  {
    //  static const string delimiters = "()[]{}/\\,;:=*`'\"+-<>";
    // REMOVE apostrophe... how to handle this?
    static const string delimiters = "(){}/\\,;:=*`\"+-<>";
    static const string whitespace = "\t\n\r ";

    if (i >= s.size()) 
      return false;

    NEXUS_skip_ws(i,s);

    if (i >= s.size()) 
      return false;

    int start = i;
    if (contains_char(delimiters,s[i])) {
      word = s.substr(i,1);
      i++;
      return true;
    }

    do { i++; }
    while(not contains_char(delimiters,s[i]) and not contains_char(whitespace,s[i])
	  and i < s.size());

    word = s.substr(start,i-start);

    return true;
  }
void Grammar::kill_chains() {
	std::vector<SymbolList> temp;
	for( auto &nT : non_terminals ) {
		SymbolList set;
		set.push_back(nT);
		for( auto rule : production_rules[get_nt_index(nT)] ) {
			if( rule.size() == 1 ) {
				if( contains_char(set, rule[0]) ) {
					continue;
				} else {
					set.push_back(rule[0]);
				}
			}
		}
		for( auto &ch : set ) {
			for( auto rule : production_rules[get_nt_index(ch)] ) {
				if( rule.size() == 1 && subset_of(rule, non_terminals) ) {
					continue;
				} else {
					temp.push_back(rule);
				}
			}
		}
		production_rules[get_nt_index(nT)] = temp;
		temp.clear();
	}
}
SymbolList Grammar::get_actives() {
	SymbolList actives(terminals);
	//std::vector<char> active_vector;
	for( auto &nT : non_terminals ) {
		for( auto rule : production_rules[get_nt_index(nT)] ) {
			if( subset_of(rule, terminals) ) {
				actives.push_back(nT);
				break;
			}
		}
	}
	SymbolList prev_actives;
	do {
		//std::cout << "get_actives do-while\n";
		prev_actives = actives;
		for( auto& nT : non_terminals ) {
			if( contains_char(actives, nT) ) { continue; }
			for( auto rule : production_rules[get_nt_index(nT)] ) {
				if( subset_of(rule, actives) ) {
					actives.push_back(nT);
					break;
				}
			}
		}
	} while( prev_actives != actives );
	return intersection(actives, non_terminals);
}
SymbolList Grammar::get_reachables() {
	SymbolList reachables;
	reachables.push_back(starting_symbol);
	SymbolList prev_reachables;
	do {
		prev_reachables = reachables;
		for( auto &ch : prev_reachables ) {
			for( auto rule : production_rules[get_nt_index(ch)] ) {
				for( auto &symbol : rule ) {
					if( contains_char(reachables, symbol) || contains_char(terminals, symbol) ) { continue; }
					reachables.push_back(symbol);
				}
			}
		}
	} while( prev_reachables != reachables );
	return reachables;
}
SymbolList unite(const SymbolList& str1, const SymbolList& str2) {
	SymbolList ret_val = str2;
	for( auto &ch : str1 ) {
		if( contains_char(str2, ch) ) { continue; }
		ret_val.push_back(ch);
	}
	return ret_val;
}
bool empty_intersection(const SymbolList& str1, const SymbolList& str2) {
	for( auto &ch : str1 ) {
		if( contains_char(str2, ch) ) {
			return false;
		}
	}
	return true;
}
SymbolList intersection(const SymbolList& str1, const SymbolList& str2) {
	SymbolList ret;
	for( auto &ch : str1 ) {
		if( contains_char(str2, ch) ) {
			ret.push_back(ch);
		}
	}
	return ret;
}
void Grammar::pseudo_non_terminals() {
	auto current = get_first(unite(non_terminals, terminals), 'Q');
	SymbolList temp_non_terms = non_terminals;
	SymbolList pseudo_non_terms;
	unsigned int c = 0;
	for( auto T : terminals ) {
		SymbolList temp;
		temp.push_back(T);
		non_terminals.push_back(current);
		pseudo_non_terms.push_back(current);
		production_rules[get_nt_index(current)].push_back(temp);
		//std::cout << current << " " << production_rules[get_nt_index(current)].back() << " " << production_rules[get_nt_index(current)].size() << '\n';
		get_next(current, ++c);
	}

	for( auto nT : temp_non_terms ) {
		std::vector<SymbolList> temp_rules;
		for( auto rule : production_rules[get_nt_index(nT)] ) {
			//std::cout << "rule: " << rule << " => ";
			if( rule.size() == 1 ) {
				//std::cout << "unchanged\n";
				temp_rules.push_back(rule);
				continue;
			}
			for( auto ch : rule ) {
				//std::cout << "ch: " << ch << '\n';
				if( contains_char(terminals, ch) ) {
					unsigned int i = pseudo_non_terms.size();
					while( i --> 0 ) {
						//std::cout << "while( "<<i<<" --> 0)\n";
						auto x = production_rules[get_nt_index(pseudo_non_terms[i])];
						//std::cout << production_rules[get_nt_index(pseudo_non_terms[i])][0];
						//std::cout << x[0][0] << " =?= " << ch << '\n';
						if( ch == x[0][0] ) {
							//std::cout << " :: TRUE\n";
							break;
						}
					}
					auto t = pseudo_non_terms[i];
					replace_first_of(rule, ch, t);
				}
			}
			//std::cout << rule << '\n';
			temp_rules.push_back(rule);
		}
		production_rules[get_nt_index(nT)] = temp_rules;
	}

}
Ejemplo n.º 9
0
gmx_bool merge_t_bondeds(t_rbondeds s[], t_rbondeds d[], gmx_bool bMin, gmx_bool bPlus)
{
    int      i, j;
    gmx_bool bBondsRemoved;

    bBondsRemoved = FALSE;
    for (i = 0; i < ebtsNR; i++)
    {
        if (s[i].nb > 0)
        {
            /* make space */
            srenew(d[i].b, d[i].nb + s[i].nb);
            for (j = 0; j < s[i].nb; j++)
            {
                /* Check if this bonded string already exists before adding.
                 * We are merging from the main rtp to the hackblocks, so this
                 * will mean the hackblocks overwrite the man rtp, as intended.
                 */
                if (!rbonded_atoms_exist_in_list(&s[i].b[j], d[i].b, d[i].nb, btsNiatoms[i]))
                {
                    if (!(bMin && contains_char(&s[i].b[j], '-'))
                        && !(bPlus && contains_char(&s[i].b[j], '+')))
                    {
                        copy_t_rbonded(&s[i].b[j], &d[i].b[ d[i].nb ]);
                        d[i].nb++;
                    }
                    else if (i == ebtsBONDS)
                    {
                        bBondsRemoved = TRUE;
                    }
                }
            }
        }
    }
    return bBondsRemoved;
}
Ejemplo n.º 10
0
std::vector<std::string> StringHelper::split(const std::string &str, const std::vector<char>& delim)
{
	std::vector<std::string> elems;
	int len = str.length();
	std::string s = "";	
	for(int i=0;i<len;i++) {
		if(contains_char(delim,str[i])) {
			elems.push_back(s);
			s = "";
		}
		else {
			s.push_back(str[i]);
		}
	}
	if(s!="")
		elems.push_back(s);
	return elems;
}
char *get_value(Instruction *ins, Word *word, char line[]) {
  CHECK(!read_word_prog(word, line, word->new_index),
      "Instruction lacks argument.");

  if ('N' == word->word[0]) {
    ins->type = NONE;
  } else if ('\'' == word->word[0]) {
    ins->type = STRING_INS;
    return get_string(word->word);
  } else if (ends_with(word->word, "f") || contains_char(word->word, '.')) {
    ins->float_val = get_double(word->word);
    ins->type = FLOATING;
  } else {
    ins->int_val = get_int(word->word);
    ins->type = INTEGER;
  }

  return NULL;
}
Ejemplo n.º 12
0
  void NEXUS_skip_ws(int& i, const string& s)
  {
    static const string whitespace = "\t\n\r ";

    bool in_comment = false;

    while(contains_char(whitespace,s[i]) or in_comment or s[i]=='[') 
      {
	if (s[i] == '[')
	  in_comment = true;
	else if (s[i] == ']')
	  in_comment = false;

	i++;

	if (i >= s.size()) 
	  return;
      } 
  }
void Grammar::kill_epsilon_rules() {
	SymbolList epsilon_rules;
	epsilon_rules.push_back(epsilon);
	SymbolList prev;
	do {
		prev = epsilon_rules;
		for( auto &nT : non_terminals ) {
			if( contains_char(epsilon_rules, nT) ) { continue; }
			for( auto rule : production_rules[get_nt_index(nT)] ) {
				if( subset_of(rule, epsilon_rules) ) {
					epsilon_rules.push_back(nT);
				}
			}
		}
	} while( prev != epsilon_rules );
	
	auto map_copy = production_rules;
	for( auto &nT : non_terminals ) {
		//std::cout << "running for " << nT << std::endl;
		for( auto rule : map_copy[get_nt_index(nT)] ) {
			//std::cout << "running for " << rule << std::endl;
			if( !empty_intersection(rule, epsilon_rules) ) {
				for( auto str : permutations(rule, epsilon_rules) ) {
					production_rules[get_nt_index(nT)].push_back(str);
				}
			}
			//std::cout << "finished for " << rule << std::endl;
		}
		//std::cout << "finished for " << nT << std::endl;
	}
	
	//map_copy = production_rules;
	SymbolList str_epsilon;
	str_epsilon.push_back(epsilon);
	for( auto &nT : non_terminals ) {
		for( auto it = production_rules[get_nt_index(nT)].begin(); it != production_rules[get_nt_index(nT)].end(); ++it ) {
			if( str_epsilon == *it ) {
				production_rules[get_nt_index(nT)].erase(it);
				break;
			}
		}
	}
}
std::vector<SymbolList> permutations(const SymbolList& str, const SymbolList& of) {
	std::vector<SymbolList> ret;
	unsigned int size = of.size();
	unsigned int n = factorial(size);
	SymbolList temp = str;
	//std::cout << temp << '\n';
	while( !empty_intersection(temp, of) && temp.size() > 1 ) {
		SymbolList copy = temp;
		for( unsigned int i = 0; i < copy.size(); ++i ) {
			if( contains_char(of, copy[i]) ) {
				copy.erase(copy.begin() + i);
				ret.push_back(copy);
				//std::cout << copy << std::endl;
				break;
			}
		}
		temp = ret.back();
	}
	return ret;
}
Ejemplo n.º 15
0
std::vector<SyntaxHighlightToken> PolycodeSyntaxHighlighter::parseLua(String text, SyntaxHighlightToken overrideToken) {
	std::vector<SyntaxHighlightToken> tokens;
	
	text = text+"\n";
	
	const int MODE_GENERAL = 0;
	const int MODE_COMMENT = 1;
	const int MODE_STRING = 2;
	const int MODE_METHOD = 3;
	const int MODE_KEYWORD = 4;
	const int MODE_NUMBER = 5;
	const int MODE_MEMBER = 6;
						
	int mode = MODE_GENERAL;	
	bool isComment = false;
	
	if(text.find_first_of("]]") != -1) {
		if(overrideToken.overrideType == SyntaxHighlightToken::TOKEN_TYPE_OVERRIDE_LINE || overrideToken.overrideType == SyntaxHighlightToken::TOKEN_TYPE_OVERRIDE_START ) {
		mode = MODE_COMMENT;
		}
	}
				
	String line = "";
	
	char lastSeparator = ' ';

	for(int i=0; i < text.length(); i++) {
		char ch = text[i];				
		if(contains_char(ch, &separators)) {			

			unsigned int type = mode;
			unsigned int ch_type = mode;
	
			if(ch == '\"' && mode != MODE_COMMENT)
				ch_type = MODE_STRING;
	
			if(mode != MODE_STRING && ch == '('  && mode != MODE_COMMENT) {
				type = MODE_METHOD;
			}

			if(mode != MODE_STRING  && mode != MODE_COMMENT) {
				if(contains(line, &keywords)) {
					type = MODE_KEYWORD;
				}
			}
	
			if(mode != MODE_STRING && !isComment && mode != MODE_COMMENT) {
			
				if(line.isNumber()) {
					type = MODE_NUMBER;
				} else {
					if(lastSeparator == '.' && ch != '.' && ch != ':') {
						type = MODE_MEMBER;
					}							
				}
			}		
	
			if(isComment) {
				type = MODE_COMMENT;
				ch_type = MODE_COMMENT;
			}
				
			if(mode == MODE_COMMENT) {
				type = MODE_COMMENT;
				ch_type = MODE_COMMENT;
			}
			
	
			if(line != "")
				tokens.push_back(SyntaxHighlightToken(line, type));
			tokens.push_back(SyntaxHighlightToken(ch, ch_type));

			if(ch == '-' && lastSeparator == '-' && text[i-1] == lastSeparator && mode != MODE_STRING) {
				isComment = true;
				tokens[tokens.size()-1].type = MODE_COMMENT;
				tokens[tokens.size()-2].type = MODE_COMMENT;				
			}

			if(ch == '[' && lastSeparator == '[' && isComment && mode != MODE_STRING) {
				unsigned int old_mode = mode;
				mode = MODE_COMMENT;
				tokens[tokens.size()-1].overrideType = SyntaxHighlightToken::TOKEN_TYPE_OVERRIDE_START;
				
				// ugly hack for ---[[, which is not a block comment
				if(tokens.size() > 4) {
					if(tokens[tokens.size()-5].text == "-") {
						mode = old_mode;
						tokens[tokens.size()-1].overrideType = SyntaxHighlightToken::TOKEN_TYPE_NO_OVERRIDE;						
					}
				}
			}
			
			if(ch == ']' && lastSeparator == ']') {
				if(mode == MODE_COMMENT) 
					mode = MODE_GENERAL;
				if(mode != MODE_STRING)
					tokens[tokens.size()-1].overrideType = SyntaxHighlightToken::TOKEN_TYPE_OVERRIDE_END;
			}
			
			if(ch == '\n' ) {
				isComment = false;
				mode = MODE_GENERAL;
			}
				

			if(ch == '\"'  && mode != MODE_COMMENT) {
				if(mode == MODE_STRING) {
					mode = MODE_GENERAL;	
				} else {
					mode = MODE_STRING;
				}
			}	
						
			line = "";
			lastSeparator = ch;			
		} else {
			line.append(ch);
		}
	}
	
	for(int i=0; i < tokens.size(); i++) {
		switch(tokens[i].type) {
			case MODE_STRING:
				tokens[i].color = globalSyntaxTheme->colors[4];			
			break;
			case MODE_COMMENT:
				tokens[i].color = globalSyntaxTheme->colors[1];
			break;			
			case MODE_METHOD:
				tokens[i].color = globalSyntaxTheme->colors[3];			
			break;			
			case MODE_KEYWORD:
				tokens[i].color = globalSyntaxTheme->colors[2];
			break;		
			case MODE_NUMBER:
				tokens[i].color = globalSyntaxTheme->colors[6];
			break;		
			case MODE_MEMBER:
				tokens[i].color = globalSyntaxTheme->colors[5];
			break;															
			default:
				tokens[i].color = globalSyntaxTheme->colors[0];
			break;
		}
	}
	
	return tokens;
}
Ejemplo n.º 16
0
static int save_spec(char * project_directory,
                     char * directory,
                     int no_of_binaries, char ** binaries)
{
    char filename[BLOCK_SIZE];
    char project_name[BLOCK_SIZE];
    char project_type[BLOCK_SIZE];
    char version[BLOCK_SIZE];
    char description_brief[BLOCK_SIZE];
    char description[BLOCK_SIZE];
    char homepage[BLOCK_SIZE];
    char email_address[BLOCK_SIZE];
    char requires[BLOCK_SIZE];
    char requires_distro[BLOCK_SIZE];
    char build_requires[BLOCK_SIZE];
    char build_requires_distro[BLOCK_SIZE];
    char license[BLOCK_SIZE];
    char svg_filename[BLOCK_SIZE];
    char source_package[BLOCK_SIZE];
    char categories[BLOCK_SIZE];
    char release[BLOCK_SIZE];
    char commandline[BLOCK_SIZE];
    char * directories[MAX_FILES];
    char group_main[BLOCK_SIZE];
    char group_additional[BLOCK_SIZE];
    FILE * fp;
    int i,j=0,no_of_directories;
    const char * dayname[] = {
        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
    };
    const char * monthname[] = {
        "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
    };
    time_t rawtime;
    struct tm * timeinfo;
    int year,month,day,weekday;

    /* get the current year */
    time(&rawtime);
    timeinfo = localtime(&rawtime);
    year = timeinfo->tm_year + 1900;
    month = timeinfo->tm_mon;
    day = timeinfo->tm_mday;
    weekday = timeinfo->tm_wday;

    get_setting("project name", project_name);
    if (strlen(project_name) == 0) return -1;

    sprintf(filename,"%s%c%s.spec",
            directory, DIRECTORY_SEPARATOR,
            project_name);

    /* don't overwrite existing spec file */
    if (file_exists(filename) != 0) return 0;

    fp = fopen(filename,"w");
    if (!fp) return -1;

    get_setting("version", version);
    get_setting("description brief", description_brief);
    get_setting("description", description);
    get_setting("license", license);
    get_setting("homepage", homepage);
    get_setting("email", email_address);
    get_setting("depends rpm", requires);
    get_setting("depends rpm distro", requires_distro);
    get_setting("build rpm", build_requires);
    get_setting("build rpm distro", build_requires_distro);
    get_setting("source package", source_package);
    get_setting("categories", categories);
    get_setting("release", release);
    get_setting("commandline", commandline);
    get_setting("project type", project_type);

    fprintf(fp, "Name: %s\n", project_name);
    fprintf(fp, "Version: %s\n", version);
    fprintf(fp, "Release: %s%%{?dist}\n", release);
    fprintf(fp, "Summary: %s\n", description_brief);
    fprintf(fp, "License: %s\n", license);
    fprintf(fp, "URL: %s\n", homepage);
    fprintf(fp, "Packager: %s\n", email_address);

    if (strlen(source_package) > 0) {
        fprintf(fp, "Source0: %s\n", source_package);
    }
    else {
        fprintf(fp, "%s",
                "Source0: http://yourdomainname.com/src/" \
                "%{name}_%{version}.orig.tar.gz\n");
    }

    if (is_script_language(project_type) != 0) {
        fprintf(fp, "%s", "BuildArch: noarch\n");
    }

    if (strlen(categories) > 0) {
        parse_desktop_category(categories,
                               group_main, group_additional);
        fprintf(fp, "Group: %s/%s\n",
                group_main,group_additional);
    }
    else {
        fprintf(fp,"%s","Group: Application/Utility\n");
    }

    conditional_requires(fp, "Requires",
                         requires, requires_distro);
    conditional_requires(fp, "BuildRequires",
                         build_requires, build_requires_distro);

    fprintf(fp, "%s", "\n%description\n");
    save_description(fp, description, 0);

    sprintf(svg_filename, "%s%cdesktop%cicon.svg",
            project_directory, DIRECTORY_SEPARATOR,
            DIRECTORY_SEPARATOR);

    fprintf(fp, "%s", "\n%prep\n");
    fprintf(fp, "%s", "%setup -q\n\n");

    fprintf(fp, "%s", "%build\n");
    fprintf(fp, "%s", "%configure\n");
    fprintf(fp, "%s", "make %{?_smp_mflags}\n\n");

    fprintf(fp, "%s", "%install\n");
    fprintf(fp, "%s", "rm -rf %{buildroot}\n");
    fprintf(fp, "%s", "mkdir -p %{buildroot}\n");
    fprintf(fp, "%s", "mkdir -p %{buildroot}/etc\n");
    fprintf(fp, "%s", "mkdir -p %{buildroot}/etc/%{name}\n");
    fprintf(fp, "%s", "mkdir -p %{buildroot}/usr\n");
    fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/bin\n");

    /* create directories for binaries */
    if (no_of_binaries > 0) {
        no_of_directories =
            get_directories(binaries, no_of_binaries,
                            directories);
        for (i = 0; i < no_of_directories; i++) {
            if (get_subdirectory_string(directories[i]) != 0) {
                fprintf(fp, "mkdir -p \"%%{buildroot}/%s\"\n",
                        get_subdirectory_string(directories[i]));
            }
            free(directories[i]);
        }
    }

    if (is_library(project_name) != 0) {
        fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/lib\n");
        fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/lib/%{name}\n");
    }
    fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/share\n");
    fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/share/man\n");
    fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/share/man/man1\n");

    if (strlen(commandline) == 0) {
        fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/share/%{name}\n");
        fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/share/applications\n");
        fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/share/icons\n");
        fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/share/icons/hicolor\n");
        fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/share/icons/hicolor/24x24\n");
        fprintf(fp, "%s",
                "mkdir -p %{buildroot}/usr/share/icons/hicolor/24x24/apps\n\n");
        if (strlen(svg_filename) > 0) {
            fprintf(fp, "%s", "mkdir -p %{buildroot}/usr/share/pixmaps\n");
            fprintf(fp, "%s",
                    "mkdir -p %{buildroot}/usr/share/icons/hicolor/scalable\n");
            fprintf(fp, "%s",
                    "mkdir -p %{buildroot}/usr/share/icons/hicolor/scalable/apps\n");
        }
    }

    fprintf(fp, "%s", "# Make install but to the RPM BUILDROOT directory\n");
    if (is_library(project_name) == 0) {
        fprintf(fp, "%s", "make install -B DESTDIR=%{buildroot} PREFIX=/usr\n\n");
    }
    else {
        fprintf(fp, "%s", "make instlib -B DESTDIR=%{buildroot} PREFIX=/usr\n\n");
    }

    fprintf(fp, "%s", "%files\n");
    fprintf(fp, "%s", "%doc README.md LICENSE\n");
    fprintf(fp, "%s", "%defattr(-,root,root,-)\n");

    /* claim ownership of directories */
    no_of_directories =
        get_directories(binaries, no_of_binaries,
                        directories);
    for (i = 0; i < no_of_directories; i++) {
        if (get_subdirectory_string(directories[i]) != 0) {
            if (contains_char(get_subdirectory_string(directories[i]), ' ') == 0) {
                fprintf(fp, "%%dir /%s\n",get_subdirectory_string(directories[i]));
            }
            else {
                fprintf(fp, "%%dir \"/%s\"\n",get_subdirectory_string(directories[i]));
            }
        }
        free(directories[i]);
    }

    if (strlen(commandline) == 0) {
        fprintf(fp, "%s", "%dir /usr/share/%{name}\n");
        fprintf(fp, "%s", "%dir /usr/share/applications\n");
        fprintf(fp, "%s", "%dir /usr/share/icons/hicolor\n");
        fprintf(fp, "%s", "%dir /usr/share/icons/hicolor/24x24\n");
        fprintf(fp, "%s", "%dir /usr/share/icons/hicolor/24x24/apps\n");
        if (strlen(svg_filename) > 0) {
            fprintf(fp, "%s", "%dir /usr/share/pixmaps\n");
            fprintf(fp, "%s", "%dir /usr/share/icons/hicolor/scalable\n");
            fprintf(fp, "%s", "%dir /usr/share/icons/hicolor/scalable/apps\n");
        }
    }

    if (is_script_language(project_type) != 0) {
        fprintf(fp, "%s", "/usr/share/%{name}/*\n");
    }

    fprintf(fp, "%s", "%{_bindir}/*\n");
    fprintf(fp, "%s", "%{_mandir}/man1/*\n");
    if (strlen(commandline) == 0) {
        fprintf(fp, "%s", "%attr(644,root,root) " \
                "/usr/share/applications/%{name}.desktop\n");
        fprintf(fp, "%s", "%attr(644,root,root) " \
                "/usr/share/icons/hicolor/24x24/apps/%{name}.png\n");
        if (file_exists(svg_filename) != 0) {
            fprintf(fp, "%s", "%attr(644,root,root) " \
                    "/usr/share/icons/hicolor/scalable/apps/%{name}.svg\n");
            fprintf(fp, "%s", "%attr(644,root,root) " \
                    "/usr/share/pixmaps/%{name}.svg\n");
        }
    }
    if (is_library(project_name) == 0) {
        /* install some binaries */
        for (i = 0; i < no_of_binaries; i++) {
            if (contains_char(get_subdirectory_string(binaries[i]),' ') == 0) {
                fprintf(fp, "%%attr(755,root,root) /%s\n",
                        get_subdirectory_string(binaries[i]));
            }
            else {
                fprintf(fp, "%%attr(755,root,root) \"/%s\"\n",
                        get_subdirectory_string(binaries[i]));
            }
        }
    }
    else {
        /* install libraries */
        for (i = 0; i < no_of_binaries; i++) {
            fprintf(fp, "%%attr(755,root,root) /usr/lib/%%{name}/%s\n",
                    get_subdirectory_string(binaries[i]));
        }
    }

    fprintf(fp,"%s","\n");

    if (is_library(project_name) != 0) {
        fprintf(fp, "%s", "%post\n");
        fprintf(fp, "%s", "umask 007\n");
        fprintf(fp, "%s", "ldconfig > /dev/null 2>&1\n");

        for (i = 0; i < no_of_binaries; i++) {
            for (j = strlen(binaries[i])-1; j >= 0; j--) {
                if (binaries[i][j] == DIRECTORY_SEPARATOR) {
                    j++;
                    break;
                }
            }
            if (file_is_library(&binaries[i][j]) != 0) {
                fprintf(fp,
                        "ln -sf /usr/lib/%s.0.0.1 /usr/lib/%%{name}/%s\n",
                        &binaries[i][j], &binaries[i][j]);
            }
        }
        fprintf(fp, "%s", "\n");

        fprintf(fp, "%s", "%postun\n");
        fprintf(fp, "%s", "umask 007\n");
        fprintf(fp, "%s", "ldconfig > /dev/null 2>&1\n");
        for (i = 0; i < no_of_binaries; i++) {
            for (j = strlen(binaries[i])-1; j >= 0; j--) {
                if (binaries[i][j] == DIRECTORY_SEPARATOR) {
                    j++;
                    break;
                }
            }
            if (file_is_library(&binaries[i][j]) != 0) {
                fprintf(fp, "rm /usr/lib/%s\n", &binaries[i][j]);
            }
        }
        fprintf(fp, "%s", "\n");
    }

    fprintf(fp, "%s", "%changelog\n");
    fprintf(fp, "* %s %s %d %d  %s\n",
            dayname[weekday], monthname[month],
            day, year, email_address);
    fprintf(fp, "%s", "- Spec file created\n");

    fclose(fp);
    return 0;
}