Пример #1
0
// bubble sort
void CShipTexturesDlg::sort_textures(int test)
{
	int i, j, str_check = 0;

	for (i = 0; i < texture_count; i++)
	{
		for (j = 0; j < i; j++)
		{
			switch(test)
			{
				case SORT_OLD:
					str_check = stricmp(old_texture_name[i], old_texture_name[j]);
					break;
				case SORT_NEW:
					str_check = stricmp(new_texture_name[i], new_texture_name[j]);
					break;
				default:
					Int3();
			}

			if (str_check < 0)
			{
				// swap old
				swap_strings(old_texture_name[i], old_texture_name[j]);

				// swap new
				swap_strings(new_texture_name[i], new_texture_name[j]);
			}
		}
	}
}
Пример #2
0
void
choose_ff(const char *ffsel,
          char *forcefield, int ff_maxlen,
          char *ffdir, int ffdir_maxlen)
{
    int  nff;
    char **ffdirs,**ffs,**ffs_dir,*ptr;
    int  i,j,sel,cwdsel,nfound;
    char buf[STRLEN],**desc;
    FILE *fp;
    char *pret;
    
    nff = fflib_search_file_in_dirend(fflib_forcefield_itp(),
                                      fflib_forcefield_dir_ext(),
                                      &ffdirs);

    if (nff == 0)
    {
        gmx_fatal(FARGS,"No force fields found (files with name '%s' in subdirectories ending on '%s')",
                  fflib_forcefield_itp(),fflib_forcefield_dir_ext());
    }

    /* Replace with unix path separators */
    if(DIR_SEPARATOR!='/')
    {
        for(i=0;i<nff;i++)
        {
            while( (ptr=strchr(ffdirs[i],DIR_SEPARATOR))!=NULL )
            {
                *ptr='/';
            }
        }
    }
    
    /* Store the force field names in ffs */
    snew(ffs,nff);
    snew(ffs_dir,nff);
    for(i=0; i<nff; i++)
    {
        /* Remove the path from the ffdir name - use our unix standard here! */
        ptr = strrchr(ffdirs[i],'/');
        if (ptr == NULL)
        {
            ffs[i] = strdup(ffdirs[i]);
            ffs_dir[i] = low_gmxlibfn(ffdirs[i],FALSE,FALSE);
            if (ffs_dir[i] == NULL)
            {
                gmx_fatal(FARGS,"Can no longer find file '%s'",ffdirs[i]);
            }
        }
        else
        {
            ffs[i] = strdup(ptr+1);
            ffs_dir[i] = strdup(ffdirs[i]);
        }
        ffs_dir[i][strlen(ffs_dir[i])-strlen(ffs[i])-1] = '\0';
        /* Remove the extension from the ffdir name */
        ffs[i][strlen(ffs[i])-strlen(fflib_forcefield_dir_ext())] = '\0';
    }

    if (ffsel != NULL)
    {
        sel     = -1;
        cwdsel  = -1;
        nfound  = 0;
        for(i=0; i<nff; i++)
        {
            if ( strcmp(ffs[i],ffsel)==0 )
            {
                /* Matching ff name */
                sel = i;
                nfound++;
                
                if( strncmp(ffs_dir[i],".",1)==0 )
                {
                    cwdsel = i;
                }
            }
        }
        
        if(cwdsel != -1)
        {
            sel = cwdsel;
        }
        
        if(nfound>1)
        {
            if(cwdsel!=-1)
            {
                fprintf(stderr,
                        "Force field '%s' occurs in %d places. pdb2gmx is using the one in the\n"
                        "current directory. Use interactive selection (not the -ff option) if\n"
                        "you would prefer a different one.\n",ffsel,nfound);
            }
            else
            {
                gmx_fatal(FARGS,
                          "Force field '%s' occurs in %d places, but not in the current directory.\n"
                          "Run without the -ff switch and select the force field interactively.",ffsel,nfound);
            }
        }
        else if (nfound==0)
        {
            gmx_fatal(FARGS,"Could not find force field '%s' in current directory, install tree or GMXDATA path.",ffsel);
        }
    }
    else if (nff > 1)
    {
        snew(desc,nff);
        for(i=0; (i<nff); i++)
        {
            sprintf(buf,"%s%c%s%s%c%s",
                    ffs_dir[i],DIR_SEPARATOR,
                    ffs[i],fflib_forcefield_dir_ext(),DIR_SEPARATOR,
                    fflib_forcefield_doc());
            if (gmx_fexist(buf))
            {
                /* We don't use fflib_open, because we don't want printf's */
                fp = ffopen(buf,"r");
                snew(desc[i],STRLEN);
                get_a_line(fp,desc[i],STRLEN);
                ffclose(fp);
            }
            else
            {
                desc[i] = strdup(ffs[i]);
            }
        }
        /* Order force fields from the same dir alphabetically
         * and put deprecated force fields at the end.
         */
        for(i=0; (i<nff); i++)
        {
            for(j=i+1; (j<nff); j++)
            {
                if (strcmp(ffs_dir[i],ffs_dir[j]) == 0 &&
                    ((desc[i][0] == '[' && desc[j][0] != '[') ||
                     ((desc[i][0] == '[' || desc[j][0] != '[') &&
                      gmx_strcasecmp(desc[i],desc[j]) > 0)))
                {
                    swap_strings(ffdirs,i,j);
                    swap_strings(ffs   ,i,j);
                    swap_strings(desc  ,i,j);
                }
            }
        }

        printf("\nSelect the Force Field:\n");
        for(i=0; (i<nff); i++)
        {
            if (i == 0 || strcmp(ffs_dir[i-1],ffs_dir[i]) != 0)
            {
                if( strcmp(ffs_dir[i],".")==0 )
                {
                    printf("From current directory:\n");
                }
                else
                {
                    printf("From '%s':\n",ffs_dir[i]);
                }
            }
            printf("%2d: %s\n",i+1,desc[i]);
            sfree(desc[i]);
        }
        sfree(desc);

        do
        {
            pret = fgets(buf,STRLEN,stdin);
            
            if (pret != NULL)
            {
                sscanf(buf,"%d",&sel);
                sel--;
            }
        }
        while ( pret==NULL || (sel < 0) || (sel >= nff));
    }
    else
    {
        sel = 0;
    }

    if (strlen(ffs[sel]) >= (size_t)ff_maxlen)
    {
        gmx_fatal(FARGS,"Length of force field name (%d) >= maxlen (%d)",
                  strlen(ffs[sel]),ff_maxlen);
    }
    strcpy(forcefield,ffs[sel]);

    if (strlen(ffdirs[sel]) >= (size_t)ffdir_maxlen)
    {
        gmx_fatal(FARGS,"Length of force field dir (%d) >= maxlen (%d)",
                  strlen(ffdirs[sel]),ffdir_maxlen);
    }
    strcpy(ffdir,ffdirs[sel]);

    for(i=0; (i<nff); i++)
    {
        sfree(ffdirs[i]);
        sfree(ffs[i]);
        sfree(ffs_dir[i]);
    }
    sfree(ffdirs);
    sfree(ffs);
    sfree(ffs_dir);
}