Пример #1
0
/* cmdlcd -
 *     Change local current working directory.
 *     Returns 0 on success, -1 on error.
 */
int
cmdlcd (int argc, char *argv[])
{
  char dirbuf[256];

  if (argc == 1)
    argv[1] = ".";
  if (argc > 2)
    {
      nsprintf (msgbuf, sizeof (msgbuf), "usage: %s directory-spec\n", argv[0]);
      Lstrout (msgbuf);
      code = -1;
      return (0);
    }
  if (0 > chdir (argv[1]))
    {
      nsprintf (msgbuf, sizeof (msgbuf), "Could not change to '%s'\n", argv[1]);
      Lstrout (msgbuf);
      code = -1;
      return (0);
    }
  else
    {
      getcwd (dirbuf, sizeof (dirbuf));
      nsprintf (msgbuf, sizeof (msgbuf), "Local directory is now '%s'\n", dirbuf);
      Lstrout (msgbuf);
      code = 0;
      return (0);
    }
}				/* cmdlcd() */
Пример #2
0
/* cmduser -
 *
 *    Returns 0 on success, -1 on error.
 */
int
cmduser (int argc, char *argv[])
{
  char acct[80];
  int n, aflag = 0;

  if (argc < 2)
    if (0 > another (&argc, &argv, "username"))
      return (-1);
  if (argc < 2 || argc > 4)
    {
      printf ("usage: %s username [password] [account]\n", argv[0]);
      code = -1;
      return (-1);
    }
  nsprintf (msgbuf, sizeof (msgbuf), "USER %s", argv[1]);
  n = sendcommand (msgbuf);
  if (n == CONTINUE)
    {
      if (argc < 3)
#if defined(SUNOS) || defined(__BSD__)
	argv[2] = gpass ("Password: "******"Password: "******"PASS %s", argv[2]);
      n = sendcommand (msgbuf);
      memset (argv[2], 0, strlen (argv[2]));
    }
  if (n == CONTINUE)
    {
      if (argc < 4)
	{
	  printf ("Account: ");
	  (void) fflush (stdout);
	  (void) fgets (acct, sizeof (acct) - 1, stdin);
	  acct[strlen (acct) - 1] = '\0';
	  argv[3] = acct;
	  argc++;
	}
      nsprintf (msgbuf, sizeof (msgbuf), "ACCT %s", argv[3]);
      n = sendcommand (msgbuf);
      aflag++;
    }
  if (n != COMPLETE)
    {
      fprintf (stdout, "Login failed.\n");
      return (-1);
    }
  if (!aflag && argc == 4)
    {
      nsprintf (msgbuf, sizeof (msgbuf), "ACCT %s", argv[3]);
      (void) sendcommand (msgbuf);
    }
  return 0;
}				/* cmduser() */
Пример #3
0
/* cmdcd -
 *     Change remote current working directory.
 *     Returns 0 on success, -1 on error.
 */
int
cmdcd (int argc, char *argv[])
{
  if (argc == 1)
    argv[1] = ".";
  if (argc > 2)
    {
      nsprintf (msgbuf, sizeof (msgbuf), "usage: %s directory-spec\n", argv[0]);
      Lstrout (msgbuf);
      code = -1;
      return (0);
    }
  nsprintf (msgbuf, sizeof (msgbuf), "CWD %s", argv[1]);
  return (COMPLETE == sendcommand (msgbuf) ? 0 : -1);
}				/* cmdcd() */
Пример #4
0
/***
 *  check_max_uses()
 *
 *      Check if a share has a /USERS:n switch or a /UNLIMITED
 *      switch.  If not, set max_users to the value of num_admin.
 *
 *      Currently used only on the ADMIN$ share.
 *
 *  Args:
 *      none
 *
 *  Returns:
 *      nothing - success
 *      exit(2) - command failed
 */
VOID NEAR check_max_uses(VOID)
{
    USHORT          err;                /* API return status */
    int                     i;
    struct server_info_2 FAR *      server_entry;
    TCHAR FAR *              ptr;
    USHORT2ULONG            swlen1, swlen2 ;
    static TCHAR             users_switch[20] ;

    _tcscpy(users_switch,swtxt_SW_SHARE_USERS);
    swlen1 = _tcslen(users_switch);
    swlen2 = _tcslen(swtxt_SW_SHARE_UNLIMITED);
    for (i = 0; SwitchList[i]; i++)
    {
        if ( (strncmpf(SwitchList[i], users_switch, swlen1) == 0) ||
             (strncmpf(SwitchList[i], swtxt_SW_SHARE_UNLIMITED, swlen2) == 0)
           )
        {
            return;     //  A specific switch exists; return without
                        //  further action.
        }
    }

    if (err = MNetServerGetInfo(NULL,
                                2,
                                (LPBYTE*)&server_entry))
        ErrorExit (err);

    ptr = _tcschr(users_switch, NULLC);
    nsprintf(ptr, TEXT(":%u"), server_entry->sv2_numadmin);

    SwitchList[i] = users_switch;
    NetApiBufferFree((TCHAR FAR *) server_entry);
}
Пример #5
0
static char* parseIdent(B& in, vec<char>& tmp) {   // 'tmp' is cleared, then filled with the parsed string. '(char*)tmp' is returned for convenience.
    skipWhitespace(in);
    if ((*in < 'a' || *in > 'z') && (*in < 'A' || *in > 'Z') && *in != '_') throw nsprintf("Expected start of identifier, not: %c", *in);
    tmp.clear();
    tmp.push(*in);
    ++in;
    while ((*in >= 'a' && *in <= 'z') || (*in >= 'A' && *in <= 'Z') || (*in >= '0' && *in <= '9') || *in == '_')
        tmp.push(*in),
        ++in;
    tmp.push(0);
    return (char*)tmp; }
Пример #6
0
/* cmdrmdir -
 *     Remove a directory
 */
int
cmdrmdir (int argc, char *argv[])
{
  char buf[256];

  if (argc < 2 && !another (&argc, &argv, "directory-name"))
    {
      printf ("usage: %s directory-name\n", argv[0]);
      code = -1;
      return 0;
    }
  nsprintf (buf, sizeof (buf), "RMD %s", argv[1]);
  return (COMPLETE == sendcommand (buf) ? 0 : -1);
}				/* cmdrmdir() */
Пример #7
0
/* cmdrename -
 *     Rename a remote file.
 */
int
cmdrename (int argc, char *argv[])
{
  char buf[80];

  if (argc < 2 && !another (&argc, &argv, "from-name"))
    goto usage;
  if (argc < 3 && !another (&argc, &argv, "to-name"))
    {
    usage:
      printf ("%s from-name to-name\n", argv[0]);
      code = -1;
      return 0;
    }
  nsprintf (buf, sizeof (buf), "RNFR %s", argv[1]);
  if (sendcommand (buf) == CONTINUE)
    {
      nsprintf (buf, sizeof (buf), "RNTO %s", argv[2]);
      return (COMPLETE == sendcommand (buf) ? 0 : -1);
    }
  else
    return -1;
}				/* cmdrename() */
Пример #8
0
/* cmdcp -
 *     Execute a remote file copy.
 */
int
cmdcp (int argc, char *argv[])
{
  char buf[80];

  if (argc < 2 && !another (&argc, &argv, "from-name"))
    goto usage;
  if (argc < 3 && !another (&argc, &argv, "to-name"))
    {
    usage:
      printf ("%s from-name to-name\n", argv[0]);
      code = -1;
      return 0;
    }
  nsprintf (buf, sizeof (buf), "COPY %s %s", argv[1], argv[2]);
  return (COMPLETE == sendcommand (buf) ? 0 : -1);
}				/* cmdcp() */
Пример #9
0
static Int parseInt(B& in) {
    Int     val(0);
    bool    neg = false;
    skipWhitespace(in);
    if      (*in == '-') neg = true, ++in;
    else if (*in == '+') ++in;
    skipWhitespace(in);     // BE NICE: allow "- 3" and "+  4" etc.
    if (*in < '0' || *in > '9')
        throw nsprintf("Expected digit, not: %c", *in);
    while (*in >= '0' && *in <= '9'){
      #ifdef NO_GMP
        val *= 2;
        if (val < 0 || val > Int(9223372036854775807LL >> 20)) throw xstrdup("Integer overflow. Use BigNum-version.");      // (20 extra bits should be enough...)
        val *= 5;
      #else
        val *= 10;
      #endif
        val += (*in - '0');
        ++in; }
    return neg ? -val : val; }
Пример #10
0
// return length
unsigned array_implode(char** line, unsigned fields_num, MYSQL_ROW row, unsigned long* lengths, unsigned new_field) {
	// field1\tfield2\t...fieldn\tnewfield\n
	char *newfield_s = nsprintf("%u\n", new_field);
	unsigned len = strlen(newfield_s);
	unsigned i;
	for (i=0; i<fields_num; i++) {
		len += lengths[i] + 1;
	}
	char* lp = malloc(len + 1); // the last byte for \0
	*line = lp;
	*(lp+len) = '\0';
	for (i=0; i<fields_num; i++) {
		memcpy(lp, row[i], lengths[i]);
		lp += lengths[i];
		*(lp++) = '\t';
	}
	memcpy(lp, newfield_s, strlen(newfield_s));
	free(newfield_s);
	return len;
}
Пример #11
0
int parseInequality(B& in)
{
    int ineq;
    skipWhitespace(in);
    if (*in == '<'){
        ++in;
        if (*in == '=') ineq = -1, ++in;
        else            ineq = -2;
    }else if (*in == '>'){
        ++in;
        if (*in == '=') ineq = +1, ++in;
        else            ineq = +2;
    }else{
        if (*in == '='){
            ++in;
            if (*in == '=') ++in;
            ineq = 0;
        }else
            throw nsprintf("Expected inequality, not: %c", *in);
    }
    return ineq;
}
Пример #12
0
void verifyModel(cchar* name, cchar* model)
{
    // Parse CNF:
    VSolver S;
    int     len  = strlen(name);
    char*   tmp  = NULL;
    int     stat = 0;
    FILE*   in;
    if (len > 5 && strcmp(name+len-5, ".bcnf") == 0){
        reportf("(cannot verify BCNF files)\n"); return; }
    if (len > 3 && strcmp(name+len-3, ".gz") == 0){
        tmp = xstrdup("tmp_XXXXXX");
        int fd = mkstemp(tmp);
        if (fd == -1)
            fprintf(stderr, "ERROR! Could not create temporary file for unpacking problem.\n"),
            exit(1);
        else
            close(fd);
        stat = system(sFree(nsprintf("zcat %s  > %s", name, tmp)));
        in = fopen(tmp, "rb");
    }else
        in = fopen(name, "rb");
    if (stat != 0 || in == NULL)
        fprintf(stderr, "ERROR! Could not open file: %s\n", name),
        exit(1);
    parse_DIMACS(in, S);
    fclose(in);
    if (tmp != NULL)
        remove(tmp);

    // Parse model:
    vec<bool>   true_lits(S.nVars()*2, false);
    int         lit;
    in = fopen(model, "rb"); assert(in != NULL);
    for(;;){
        int n = fscanf(in, "%d", &lit);
        if (n != 1 || lit == 0) break;
        if (lit < 0)
            true_lits[index(~Lit(-lit-1))] = true;
        else
            true_lits[index( Lit( lit-1))] = true;
    }
    fclose(in);

    //for (int i = 0; i < true_lits.size(); i++)
    //    if (true_lits[i]) printf(L_LIT" ", L_lit(toLit(i)));
    //printf("\n");

    // Check satisfaction:
    for (int i = 0; i < S.clauses.size(); i++){
        VClause& c = *S.clauses[i];
        for (int j = 0; j < c.size(); j++){
            if (true_lits[index(c[j])])
                goto Satisfied;
        }

        printf("FALSE MODEL!!!\n");
        printf("{");
        for (int j = 0; j < c.size(); j++)
            printf(" x%d:%d", var(c[j]), true_lits[index(c[j])]);
        printf(" }\n");
        exit(0);

      Satisfied:;
    }
}
Пример #13
0
inline void init_get_next_url(MYSQL* sock, char* table_name) {
	char *query = nsprintf("SELECT url FROM %s", table_name);
	init_buffered_get_next_row(sock, query);
	free(query);
}