Beispiel #1
0
int __dmemory_load_exceptions_file(void)
{
	char *filename = NULL;
	FILE *FExceptions = NULL;
	char tmpbuf[MAX_BUF];
	char *itmp = NULL;
	int line;

	NumExceptions = 0;
	Exceptions = NULL;

	/* Load the variable in the filename */
	if ((filename = getenv(VAR_EXCEPTIONS_FILENAME)) == NULL) {
		debug(INFO, "%s not defined, no exceptions will be used\n", "LIBRARY", 0, VAR_EXCEPTIONS_FILENAME);
		return 1;
	}

	/* Check if it was defined and not empty */
	if (*filename == '\0') {
		debug(INFO, "%s defined but empty, no exceptions defined\n", "LIBRARY", 0, VAR_EXCEPTIONS_FILENAME);
		return 1;
	}

	/* Open the exceptions file */
	if ((FExceptions = fopen(filename, "r")) == NULL) {
		debug(INFO, "opening %s\n", strerror(errno), errno, filename);
		return 1;
	}

	/* Load the exceptions to an array */
	while (fgets(tmpbuf, MAX_BUF, FExceptions) != NULL) {

		/* Check if the user try to screw us with junk */
		if (max_strlen(tmpbuf, MAX_BUF) == MAX_BUF) {
			debug(INFO, "Exception filename too large at line %d\n", "LIBRARY", 0, NumExceptions + 1);
			continue;
		}
		/* Save space for one more */
		Exceptions = realloc(Exceptions, sizeof(TExceptions) * (NumExceptions + 1));

		/* If no field separator was given, then he wants the whole exception */
		if ((itmp = strchr(tmpbuf, FIELD_SEPARATOR)) != NULL) {
			Exceptions[NumExceptions].line = atoi(itmp + 1);
			*itmp = '\0';
		}
		else
			Exceptions[NumExceptions].line = -1;
		Exceptions[NumExceptions].filename = strdup(tmpbuf);
		if ((itmp = strchr(Exceptions[NumExceptions].filename, '\n')) != NULL)
			*itmp = '\0';

		NumExceptions += 1;
	}
	return 0;
}
Beispiel #2
0
std::string library_versions_report()
{
	std::ostringstream o;

	const size_t col2_start = max_strlen(versions.names) + 2;
	const size_t col3_start = max_strlen(versions.compiled) + 1;

	for(unsigned n = 0; n < LIB_COUNT; ++n)
	{
		const std::string& name = versions.names[n];
		const std::string& compiled = versions.compiled[n];
		const std::string& linked = versions.linked[n];

		if(name.empty()) {
			continue;
		}

		o << name << ": ";

		const size_t pos2 = name.length() + 2;
		if(pos2 < col2_start) {
			o << std::string(col2_start - pos2, ' ');
		}

		o << compiled;

		if(!linked.empty()) {
			const size_t pos3 = compiled.length() + 1;
			if(pos3 < col3_start) {
				o << std::string(col3_start - pos3, ' ');
			}
			o << " (runtime " << linked << ")";
		}

		o << '\n';
	}

	return o.str();
}
Beispiel #3
0
//
// Affiche une fenêtre de menu.
//
int displayMenu(char **choices, int nbChoices, char title[], bool logo) {
    if(choices == NULL || nbChoices < 1) return -1;
    
    //variables pour l'affichage du menu
    ITEM **menuItems = NULL;
    MENU *menu = NULL;
    WINDOW *menuWin = NULL;
    
    int i = 0, c;
    int winWidth = POPUP_WINDOW_WIDTH;
    //largeur du menu = longueur du plus grand des choix possibles
    int menuWidth = max_strlen(choices, nbChoices) + 2;
    
    //on alloue de la mémoire pour initialiser les éléments du menu
    menuItems = (ITEM **) calloc(nbChoices + 1, sizeof(ITEM *));
    
    //on créé de nouveaux éléments à partir des choix fournis
    for(i = 0; i < nbChoices; i++) {
        menuItems[i] = new_item(choices[i], NULL);
    }
    
    //on met un élément nul à la fin du tableau
    menuItems[nbChoices] = (ITEM *) NULL;
    
    while(true) {
        clear();
        
        menuWin = (logo) ? getMenuWindow(nbChoices, title) : getMenuWindowNoLogo(nbChoices, title, -1, -1);
        
        //on initialise le menu
        menu = new_menu((ITEM **) menuItems);
        
        //on lui précise bien que le menu fait N lignes et 1 colonne
        set_menu_format(menu, nbChoices, 1);
        
        menu_opts_off(menu, O_NONCYCLIC);
        set_menu_mark(menu, "> ");
        
        //on associe le menu à une fenêtre et une sous-fenêtre
        set_menu_win(menu, menuWin);
        //fenêtre hauteur largeur x y
        set_menu_sub(menu, derwin(menuWin, nbChoices, menuWidth, (logo) ? 15 : 4, (winWidth - menuWidth) / 2));
        
        //et hop, on affiche le menu et on rafraîchit.
        post_menu(menu);
        
        refresh();
        wrefresh(menuWin);
        
        curs_set(0);
        noecho();
        
        //boucle pour le menu
        while((c = getch())) {
            bool resized = false;
            
            switch(c) {
                case KEY_DOWN:
                    menu_driver(menu, REQ_DOWN_ITEM);
                    break;
                case KEY_UP:
                    menu_driver(menu, REQ_UP_ITEM);
                    break;
                case KEY_ESC_ALT:
                    return -1;
                case KEY_RESIZE:
                    //si on a redimensionné le terminal, on ré-exécute la boucle d'affichage
                    resized = true;
                    break;
                case KEY_MENU_ENTER: {
                    int choice = item_index(current_item(menu));
                    
                    //on libère la mémoire pour le menu, les choix, la fenêtre
                    unpost_menu(menu);
                    free_menu(menu);
                    
                    for(i = 0; i < nbChoices; ++i)
                        free_item(menuItems[i]);
                    
                    clear();
                    refresh();
                    
                    delwin(menuWin);
                    
                    //on réactive l'affichage des caractères tapés et du curseur
                    echo();
                    curs_set(1);
                    
                    return choice;
                }
            }
            
            if(resized) break;
            wrefresh(menuWin);
        }

    }
    
    return 0;
}