void do_stuff(int arg_sock) {
    // rsp -- 0x990 bytes for locals -- rbp
    int sock = arg_sock; // -0x984(rbp)
    int i; // -0x978(rbp)
    int len; // -0x974(rbp)
    char* p1, p2 // -0x970(rbp), -0x968(rbp)
    // -0x960(rbp), 1224 bytes total
    struct {
        int sock; // -0x960(rbp)
        char* something1; // -0x950(rbp)
        char* something2; // -0x948(rbp)
        char* username; // offset 0x20, -0x940(rbp)
        char* password; // offset 0x28
        char dir[1024]; // offset 0xc0
    } state;
    int logged_in; // -0x4a0(rbp), overlap with dir?
    char buf[0x80]; // -0x490(rbp)
    char directory[1024]; // -0x410(rbp)
    alarm(65);
    srand(time(0));
    memset(state, 0, 1224);
    state->sock = sock;
    if(getcwd(directory, 0x400)) {
        strcpy(state->dir, directory);
    } else {
        error("CWD");
    }
    send_(sock, "Welcome to FTP server\n");
    for(;; free(p2)) {
        memset(buf, 0, 0x80);
        p1 = p2 = recv_(sock);
        len = strlen(p1);
        for(i=0; (*p1 != ' ') && (i < len-1); i++) {
            buf[i] = *p1++;
        }
        if(*p1 == ' ') { p1++; }
        p1[strlen(p1)-1] = 0;
        if(!strncasecmp("USER", buf, 4)) {
            if(logged_in) {
                send_(sock, "Cannot change user  ");
                send_(sock, state->username);
                send_(sock, "\n");
                continue;
            } else {
                state->username = p1;
                state->something2 = p1;
                do_login(state);
                continue;
            }
        }
        if(!strncasecmp("PASS", buf, 4)) {
            send_(sock, "send user first.\n");
            continue;
        }
        if(!strncasecmp("HELP", buf, 4)) {
            send_(sock, "USER PASS PASV PORT\nNOOP REIN LIST SYST SIZE\nRETR STOR PWD CWD\n");
            continue;
        }
        if(!logged_in) {
            send_(sock, "login with USER first.\n");
            continue;
        }
        if(!strncasecmp("REIN", buf, 4)) {
            logged_in = 0;
            continue;
        }
        if(!strncasecmp("PORT", buf, 4)) {
            do_port(...);
        }
        if(!strncasecmp("PASV", buf, 4)) {
            do_pasv(...);
        }
        if(!strncasecmp("STOR", buf, 4)) {
            do_stor(...);
        }
        if(!strncasecmp("RETR", buf, 4)) {
            do_retr(...);
        }
        if(!strncasecmp("QUIT", buf, 4)) {
            do_quit(...);
        }
        if(!strncasecmp("LIST", buf, 4)) {
            do_list(...);
        }
        if(!strncasecmp("SYST", buf, 4)) {
            do_syst(...);
        }
        if(!strncasecmp("NOOP", buf, 4)) {
            do_noop(...);
        }
        if(!strncasecmp("PWD", buf, 4)) {
            do_pwd(...);
        }
        if(!strncasecmp("CWD", buf, 4)) {
            do_cwd(...);
        }
        if(!strncasecmp("RDF", buf, 4)) {
            state->something1 = p1;
            state->something2 = buf;
            do_rdf(state);
        }
    }
}
Beispiel #2
0
int gmx_rdf(int argc,char *argv[])
{
  static char *desc[] = {
    "The structure of liquids can be studied by either neutron or X-ray",
    "scattering. The most common way to describe liquid structure is by a",
    "radial distribution function. However, this is not easy to obtain from",
    "a scattering experiment.[PAR]",
    "g_rdf calculates radial distribution functions in different ways.",
    "The normal method is around a (set of) particle(s), the other method",
    "is around the center of mass of a set of particles.",
    "With both methods rdf's can also be calculated around axes parallel",
    "to the z-axis with option [TT]-xy[tt].[PAR]",
    "The option [TT]-rdf[tt] sets the type of rdf to be computed.",
    "Default is for atoms or particles, but one can also select center",
    "of mass or geometry of molecules or residues. In all cases only",
    "the atoms in the index groups are taken into account.",
    "For molecules and/or the center of mass option a run input file",
    "is required.",
    "Other weighting than COM or COG can currently only be achieved",
    "by providing a run input file with different masses.",
    "Option [TT]-com[tt] also works in conjunction with [TT]-rdf[tt].[PAR]"
    "If a run input file is supplied ([TT]-s[tt]) and [TT]-rdf[tt] is set",
    "to [TT]atom[tt], exclusions defined",
    "in that file are taken into account when calculating the rdf.",
    "The option [TT]-cut[tt] is meant as an alternative way to avoid",
    "intramolecular peaks in the rdf plot.",
    "It is however better to supply a run input file with a higher number of",
    "exclusions. For eg. benzene a topology with nrexcl set to 5",
    "would eliminate all intramolecular contributions to the rdf.",
    "Note that all atoms in the selected groups are used, also the ones",
    "that don't have Lennard-Jones interactions.[PAR]",
    "Option [TT]-cn[tt] produces the cumulative number rdf,",
    "i.e. the average number of particles within a distance r.[PAR]",
    "To bridge the gap between theory and experiment structure factors can",
    "be computed (option [TT]-sq[tt]). The algorithm uses FFT, the grid"
    "spacing of which is determined by option [TT]-grid[tt]."
  };
  static bool bCM=FALSE,bXY=FALSE,bPBC=TRUE,bNormalize=TRUE;
  static real cutoff=0,binwidth=0.002,grid=0.05,fade=0.0,lambda=0.1,distance=10;
  static int  npixel=256,nlevel=20,ngroups=1;
  static real start_q=0.0, end_q=60.0, energy=12.0;

  static char *rdft[]={ NULL, "atom", "mol_com", "mol_cog", "res_com", "res_cog", NULL };

  t_pargs pa[] = {
    { "-bin",      FALSE, etREAL, {&binwidth},
      "Binwidth (nm)" },
    { "-com",      FALSE, etBOOL, {&bCM},
      "RDF with respect to the center of mass of first group" },
    { "-rdf",   FALSE, etENUM, {rdft}, 
      "RDF type" },
    { "-pbc",      FALSE, etBOOL, {&bPBC},
      "Use periodic boundary conditions for computing distances. Without PBC the maximum range will be three times the larges box edge." },
    { "-norm",     FALSE, etBOOL, {&bNormalize},
      "Normalize for volume and density" },
    { "-xy",       FALSE, etBOOL, {&bXY},
      "Use only the x and y components of the distance" },
    { "-cut",      FALSE, etREAL, {&cutoff},
      "Shortest distance (nm) to be considered"},
    { "-ng",       FALSE, etINT, {&ngroups},
      "Number of secondary groups to compute RDFs around a central group" },
    { "-fade",     FALSE, etREAL, {&fade},
      "From this distance onwards the RDF is tranformed by g'(r) = 1 + [g(r)-1] exp(-(r/fade-1)^2 to make it go to 1 smoothly. If fade is 0.0 nothing is done." },
    { "-grid",     FALSE, etREAL, {&grid},
      "[HIDDEN]Grid spacing (in nm) for FFTs when computing structure factors" },
    { "-npixel",   FALSE, etINT,  {&npixel},
      "[HIDDEN]# pixels per edge of the square detector plate" },
    { "-nlevel",   FALSE, etINT,  {&nlevel},
      "Number of different colors in the diffraction image" },
    { "-distance", FALSE, etREAL, {&distance},
      "[HIDDEN]Distance (in cm) from the sample to the detector" },
    { "-wave",     FALSE, etREAL, {&lambda},
      "[HIDDEN]Wavelength for X-rays/Neutrons for scattering. 0.1 nm corresponds to roughly 12 keV" },
    
    {"-startq", FALSE, etREAL, {&start_q},
     "Starting q (1/nm) "},
    {"-endq", FALSE, etREAL, {&end_q},
     "Ending q (1/nm)"},
    {"-energy", FALSE, etREAL, {&energy},
     "Energy of the incoming X-ray (keV) "}
  };
#define NPA asize(pa)
  char       *fnTPS,*fnNDX;
  bool       bSQ,bRDF;
  
  t_filenm   fnm[] = {
    { efTRX, "-f",  NULL,     ffREAD },
    { efTPS, NULL,  NULL,     ffOPTRD },
    { efNDX, NULL,  NULL,     ffOPTRD },
    { efXVG, "-o",  "rdf",    ffOPTWR },
    { efXVG, "-sq", "sq",     ffOPTWR },
    { efXVG, "-cn", "rdf_cn", ffOPTWR },
    { efXVG, "-hq", "hq",     ffOPTWR },
/*    { efXPM, "-image", "sq",  ffOPTWR }*/
  };
#define NFILE asize(fnm)
  
  CopyRight(stderr,argv[0]);
  parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE,
		    NFILE,fnm,NPA,pa,asize(desc),desc,0,NULL);

  bSQ   = opt2bSet("-sq",NFILE,fnm);
  bRDF  = opt2bSet("-o",NFILE,fnm) || !bSQ;
  if (bSQ || bCM || rdft[0][0]=='m' || rdft[0][6]=='m') {
    fnTPS = ftp2fn(efTPS,NFILE,fnm);
  } else {
    fnTPS = ftp2fn_null(efTPS,NFILE,fnm);
  }
  fnNDX = ftp2fn_null(efNDX,NFILE,fnm);

  if (!bSQ && (!fnTPS && !fnNDX))
    gmx_fatal(FARGS,"Neither index file nor topology file specified\n"
	      "Nothing to do!");
 
  if  (bSQ) 
   do_scattering_intensity(fnTPS,fnNDX,opt2fn("-sq",NFILE,fnm),ftp2fn(efTRX,NFILE,fnm),
		           start_q, end_q, energy, ngroups  );

  if (bRDF) 
    do_rdf(fnNDX,fnTPS,ftp2fn(efTRX,NFILE,fnm),
	   opt2fn("-o",NFILE,fnm),opt2fn_null("-cn",NFILE,fnm),
	   opt2fn_null("-hq",NFILE,fnm),
	   bCM,rdft,bXY,bPBC,bNormalize,cutoff,binwidth,fade,ngroups);

  thanx(stderr);
  
  return 0;
}