Пример #1
0
Файл: hand.c Проект: winks/hand
int handle_input(char *buf, int new_fd)
{
    size_t buflen = strlen(buf);
    fprintf(stderr, "  recv: %zu/%d\n", buflen, MAXDATASIZE);
    // This is a bogus case, ignore
    if (buflen < 2 ) {
        fprintf(stderr, "  bogus\n");
        return 11;
    }

    char *right = strdup(buf);
    char *left = strsep(&right, "\r");
    fprintf(stderr, "  sep : %zu+%zu\n", strlen(left), strlen(right)+1);

    // This is a bogus case, ignore
    if (right == NULL || right[0] != '\n') {
        fprintf(stderr, "  bogus\n");
        return 12;
    // This is {Q1} = "<CRLF>"
    } else if (strlen(left) == 0) {
        if (ENABLE_FEATURE_LIST) {
            sender(new_fd, MSG_LIST_YES, 1);
        } else {
            sender(new_fd, MSG_LIST_NO, 1);
        }
    // This is the default, {Q1} = "INPUT<CRLF>"
    } else {
        char out_hdr[MAXFILESIZE+2];
        char out_plan[MAXFILESIZE+2];
        char out_all[(MAXFILESIZE+2)*2];

        struct passwd *p;
        if ((p = getpwnam(left)) == NULL) {
            printf("SRV : user not found\n");
            sender(new_fd, MSG_NO_INFO, 1);
            return 13;
        }
        if (IGNORE_SYSTEM_USERS) {
            if(p->pw_uid < 1000 || p->pw_uid >= 65534) {
            printf("SRV : user not allowed to be found: %s:%d:%d\n",
                    p->pw_name, p->pw_uid, p->pw_gid);
            sender(new_fd, MSG_NO_INFO, 1);
            return 14;
            }
        }
        if(reader(p->pw_name, ".nofinger", out_plan) != 2) {
            sender(new_fd, MSG_NO_INFO, 1);
            return 15;
        }

        xfmt(p, out_hdr, sizeof out_hdr);
        fprintf(stderr, "   hdr:\n%s\n---\n", out_hdr);

        if(reader(p->pw_name, ".plan", out_plan) != 0) {
            snprintf(out_plan, sizeof out_plan, "No Plan.\n");
        }

        fprintf(stderr, "  plan:\n%s\n---\n", out_plan);

        snprintf(out_all, sizeof out_all, "%s%s", out_hdr, out_plan);
        sender(new_fd, out_all, 0);
    }

    return 0;
}
Пример #2
0
// DataIO_Std::WriteSet3D()
int DataIO_Std::WriteSet3D( DataSet const& setIn, CpptrajFile& file ) {
  if (setIn.Ndim() != 3) {
    mprinterr("Internal Error: DataSet %s in DataFile %s has %zu dimensions, expected 3.\n",
              setIn.legend(), file.Filename().full(), setIn.Ndim());
    return 1;
  }
  DataSet_3D const& set = static_cast<DataSet_3D const&>( setIn );
  Dimension const& Xdim = static_cast<Dimension const&>(set.Dim(0));
  Dimension const& Ydim = static_cast<Dimension const&>(set.Dim(1));
  Dimension const& Zdim = static_cast<Dimension const&>(set.Dim(2));
  //if (Xdim.Step() == 1.0) xcol_precision = 0;
  if (sparse_)
    mprintf("\tOnly writing voxels with value > %g\n", cut_);
  // Print X Y Z Values
  // x y z val(x,y,z)
  DataSet::SizeArray pos(3);
  if (writeHeader_) {
    file.Printf("#counts %zu %zu %zu\n", set.NX(), set.NY(), set.NZ());
    file.Printf("#origin %12.7f %12.7f %12.7f\n",
                set.Bin().GridOrigin()[0],
                set.Bin().GridOrigin()[1],
                set.Bin().GridOrigin()[2]);
    if (set.Bin().IsOrthoGrid()) {
      GridBin_Ortho const& b = static_cast<GridBin_Ortho const&>( set.Bin() );
      file.Printf("#delta %12.7f %12.7f %12.7f\n", b.DX(), b.DY(), b.DZ());
    } else {
      GridBin_Nonortho const& b = static_cast<GridBin_Nonortho const&>( set.Bin() );
      file.Printf("#delta %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f\n",
                  b.Ucell()[0]/set.NX(),
                  b.Ucell()[1]/set.NX(),
                  b.Ucell()[2]/set.NX(),
                  b.Ucell()[3]/set.NY(),
                  b.Ucell()[4]/set.NY(),
                  b.Ucell()[5]/set.NY(),
                  b.Ucell()[6]/set.NZ(),
                  b.Ucell()[7]/set.NZ(),
                  b.Ucell()[8]/set.NZ());
    }
    file.Printf("#%s %s %s %s\n", Xdim.Label().c_str(), 
                Ydim.Label().c_str(), Zdim.Label().c_str(), set.legend());
  }
  std::string xyz_fmt;
  if (XcolPrecSet()) {
    TextFormat nfmt( XcolFmt(), XcolWidth(), XcolPrec() );
    xyz_fmt = nfmt.Fmt() + " " + nfmt.Fmt() + " " + nfmt.Fmt() + " ";
  } else {
    TextFormat xfmt( XcolFmt(), set.NX(), Xdim.Min(), Xdim.Step(), 8, 3 );
    TextFormat yfmt( XcolFmt(), set.NY(), Ydim.Min(), Ydim.Step(), 8, 3 );
    TextFormat zfmt( XcolFmt(), set.NZ(), Zdim.Min(), Zdim.Step(), 8, 3 );
    xyz_fmt = xfmt.Fmt() + " " + yfmt.Fmt() + " " + zfmt.Fmt() + " ";
  }
  if (sparse_) {
    for (pos[2] = 0; pos[2] < set.NZ(); ++pos[2]) {
      for (pos[1] = 0; pos[1] < set.NY(); ++pos[1]) {
        for (pos[0] = 0; pos[0] < set.NX(); ++pos[0]) {
          double val = set.GetElement(pos[0], pos[1], pos[2]);
          if (val > cut_) {
            Vec3 xyz = set.Bin().Corner(pos[0], pos[1], pos[2]);
            file.Printf( xyz_fmt.c_str(), xyz[0], xyz[1], xyz[2] );
            set.WriteBuffer( file, pos );
            file.Printf("\n");
          }
        }
      }
    }
  } else {
    for (pos[2] = 0; pos[2] < set.NZ(); ++pos[2]) {
      for (pos[1] = 0; pos[1] < set.NY(); ++pos[1]) {
        for (pos[0] = 0; pos[0] < set.NX(); ++pos[0]) {
          Vec3 xyz = set.Bin().Corner(pos[0], pos[1], pos[2]);
          file.Printf( xyz_fmt.c_str(), xyz[0], xyz[1], xyz[2] );
          set.WriteBuffer( file, pos );
          file.Printf("\n");
        }
      }
    }
  }
  return 0;
}