Пример #1
0
void LoadPluginDir(char *dir) {
    DIR *diro;
    struct dirent *ent;
    char buffer[1025];

    if ( dir==NULL ) {
	/* First load system plug-ins */
#if defined( PLUGINDIR )
	LoadPluginDir( PLUGINDIR );
#else
	char *pt = getFontForgeShareDir();
	if ( pt!=NULL ) {
	    snprintf(buffer, sizeof(buffer), "%s/plugins", pt );
	    LoadPluginDir( buffer );
	}
#endif
	/* Then load user defined ones */
	if ( getPfaEditDir(buffer)!=NULL ) {
	    strcpy(buffer,getPfaEditDir(buffer));
	    strcat(buffer,"/plugins");
	    LoadPluginDir(buffer);
	}
return;
    }

    diro = opendir(dir);
    if ( diro==NULL )		/* It's ok not to have any plugins */
return;

    while ( (ent = readdir(diro))!=NULL ) {
	if ( isdyname(ent->d_name) ) {
	    sprintf( buffer, "%s/%s", dir, ent->d_name );
	    LoadPlugin(buffer);
	}
    }
    closedir(diro);
}
struct cidmap *AskUserForCIDMap(void) {
    struct block block;
    struct cidmap *map = NULL;
    char buffer[200];
    char **choices;
    int i,ret;
    char *filename=NULL;
    char *reg, *ord, *pt;
    int supplement;

    memset(&block,'\0',sizeof(block));
    for ( map = cidmaps; map!=NULL; map = map->next ) {
        sprintf(buffer,"%s-%s-%d", map->registry, map->ordering, map->supplement);
        AddToBlock(&block,buffer,NULL);
    }
    FindMapsInDir(&block,".");
    FindMapsInDir(&block,GResourceProgramDir);
    FindMapsInNoLibsDir(&block,GResourceProgramDir);
    FindMapsInDir(&block,getFontForgeShareDir());
    FindMapsInDir(&block,"/usr/share/fontforge");

    choices = gcalloc(block.cur+2,sizeof(unichar_t *));
    choices[0] = copy(_("Browse..."));
    for ( i=0; i<block.cur; ++i )
        choices[i+1] = copy(block.maps[i]);
    ret = gwwv_choose(_("Find a cidmap file..."),(const char **) choices,i+1,0,_("Please select a CID ordering"));
    for ( i=0; i<=block.cur; ++i )
        free( choices[i] );
    free(choices);
    if ( ret==0 ) {
        filename = gwwv_open_filename(_("Find a cidmap file..."),NULL,
                                      "?*-?*-[0-9]*.cidmap",NULL);
        if ( filename==NULL )
            ret = -1;
    }
    if ( ret!=-1 ) {
        if ( filename!=NULL )
            /* Do nothing for now */;
        else if ( block.dirs[ret-1]!=NULL ) {
            filename = galloc(strlen(block.dirs[ret-1])+strlen(block.maps[ret-1])+3+8);
            strcpy(filename,block.dirs[ret-1]);
            strcat(filename,"/");
            strcat(filename,block.maps[ret-1]);
            strcat(filename,".cidmap");
        }
        if ( ret!=0 )
            reg = block.maps[ret-1];
        else {
            reg = strrchr(filename,'/');
            if ( reg==NULL ) reg = filename;
            else ++reg;
            reg = copy(reg);
        }
        pt = strchr(reg,'-');
        if ( pt==NULL )
            ret = -1;
        else {
            *pt = '\0';
            ord = pt+1;
            pt = strchr(ord,'-');
            if ( pt==NULL )
                ret = -1;
            else {
                *pt = '\0';
                supplement = strtol(pt+1,NULL,10);
            }
        }
        if ( ret == -1 )
            /* No map */;
        else if ( filename==NULL )
            map = FindCidMap(reg,ord,supplement,NULL);
        else {
            map = LoadMapFromFile(filename,reg,ord,supplement);
            free(filename);
        }
        if ( ret!=0 && reg!=block.maps[ret-1] )
            free(reg);
        /*free(filename);*/	/* Freed by loadmap */
    }
    for ( i=0; i<block.cur; ++i )
        free( block.maps[i]);
    free(block.maps);
    free(block.dirs);
    return( map );
}