Beispiel #1
0
bool GCodeReader::GCodeLine::has_value(char axis, float &value) const
{
    const char *c = m_raw.c_str();
    // Skip the whitespaces.
    c = skip_whitespaces(c);
    // Skip the command.
    c = skip_word(c);
    // Up to the end of line or comment.
    while (! is_end_of_gcode_line(*c)) {
        // Skip whitespaces.
        c = skip_whitespaces(c);
        if (is_end_of_gcode_line(*c))
            break;
        // Check the name of the axis.
        if (*c == axis) {
            // Try to parse the numeric value.
            char   *pend = nullptr;
            double  v = strtod(++ c, &pend);
            if (pend != nullptr && is_end_of_word(*pend)) {
                // The axis value has been parsed correctly.
                value = float(v);
                return true;
            }
        }
        // Skip the rest of the word.
        c = skip_word(c);
    }
    return false;
}
Beispiel #2
0
static int fs_cmd_cd(struct fs_info *session) {
	/* Usage: cd <remote-directory> */
	int ret;
	char *tmp, *arg_remotedir;

	if (!session->is_connected) {
		fprintf(stderr, "Not connected.\n");
		return FTP_RET_FAIL;
	}

	/* Get args */
	tmp = &session->cmd_buff[0];
	skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp);
	arg_remotedir = tmp;

	split_word(arg_remotedir);

	if (*arg_remotedir == '\0') {
		fprintf(stderr, "Remote directory is not specified.\n");
		errno = EINVAL;
		return FTP_RET_ERROR;
	}
	/* --- END OF Get args --- */

	ret = fs_execute(session, "CWD %s\r\n", arg_remotedir);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	return FTP_RET_OK;
}
Beispiel #3
0
int leadOptions(char **Xline, optScanner fct, void * arg)
{   int ec = E_None;
    char *p, *q, *line;

    assert(Xline);

    p = *Xline;
    if(!p)
        p = *Xline = "";

    while(*(line = skipdm(p))) {
        q = unquote(line, p = skip_word(line));
        if(!q) {
            error_out_of_memory();
            return E_NoMem;
        }

        if(!isoption(q)
                || ((ec = scanOption(fct, arg, q)) != E_None
                    && ec != E_Ignore)) {
            myfree(q);
            break;
        }

        myfree(q);
    }

    *Xline = line;

    return ec;
}
Beispiel #4
0
static int addArg(char ***Xarg, int *argc, char *sBeg, char **sEnd)
{   char **arg;

    assert(Xarg);
    assert(argc);
    assert(sEnd);
    assert(sBeg);

    *sEnd = skip_word(sBeg);   /* find end of argument */

    /* Because *start != '\0' && !isargdelim(*start) ==> s != start */
    assert(*sEnd > sBeg);

    /* add new entry for new argument */
    if((arg = realloc(*Xarg, (*argc + 2) * sizeof(char *))) ==  0) {
        freep(*Xarg);
        return 1;
    }
    /* create new entry */
    if((arg[*argc] = unquote(sBeg, *sEnd)) == 0) {
        freep(arg);
        return 1;
    }
    arg[++*argc] = 0;		/* keep it a correct argv[] array if a freep()
      							is triggered above */
    *Xarg = arg;

    return 0;
}
Beispiel #5
0
static int fs_cmd_rm(struct fs_info *session) {
	/* Usage: rm <remote-file> */
	int ret;
	char *tmp, *arg_remotefile;

	if (!session->is_connected) {
		fprintf(stderr, "Not connected.\n");
		return FTP_RET_FAIL;
	}

	/* Get args */
	tmp = &session->cmd_buff[0];
	skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp);
	arg_remotefile = tmp;

	split_word(arg_remotefile);

	if (*arg_remotefile == '\0') {
		fprintf(stderr, "File name is not specified.\n");
		errno = EINVAL;
		return FTP_RET_ERROR;
	}
	/* --- END OF Get args --- */

	ret = fs_execute(session, "DELE %s\r\n", arg_remotefile);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	return FTP_RET_OK;
}
Beispiel #6
0
static void skip_until_ordinal (SIDE *side, int ordinal)
{
	while (side->position < ordinal) {
		skip_whitespace (side);
		skip_word (side);
	}
}
Beispiel #7
0
int write_message(
	int format,	/* if true - extended message format */ 
	char *line	/* write parameter line */
	)
{
unsigned char data[8] = {8, 7, 6, 5, 4, 3 , 2, 1};
unsigned char *lptr;
int len = 0;
/* unsigned char **endptr; */
unsigned char *endptr;
canmsg_t tx;			/* build transmit message */



    /* May be some check is needed if we have a valid and useful message */

    lptr = &line[0];
    skip_space(lptr);

    tx.flags = 0;
    if(format == 1) {
	tx.flags |= MSG_EXT;
    } else {
    }
    if(*lptr == 'r' || *lptr == 'R') {
	tx.flags |= MSG_RTR;
	skip_word(lptr);
    }
    skip_space(lptr);
    tx.id  = strtoul(lptr, &endptr, 0);
    tx.cob = 0;

    while( lptr != endptr) {
        lptr = endptr;
        tx.data[len] = (signed char)strtol(lptr, &endptr, 0);
	if(lptr != endptr) len++;
	if (len == 8 ) break; 
    }

    tx.length = len;

BDEBUG("Transmit %d, RTR=%s, len=%d\n", tx.id,
			((tx.flags == 0) ? "F" : "T"),
			tx.length);
			
    len = write(can_fd, &tx, 1);

    if (len < 0) {
    	/* Write Error */
printf("Write Error: %d\n", len);
    }
    
    if (len == 0) {
    	/* Transmit Timeout */
printf("Write Error: Transmit fehlgeschlagen\n", len);
    }

    return 0;
}	
Beispiel #8
0
// reads addr:size (hex) or addr size (dec) from a string; returns the number of
// chars used up, or 0 if an error occurred
int read_addr_size(const char* str, unsigned long long* addr,
    unsigned long long* size) {

  // read address
  sscanf(str, "%llX", addr);

  // : means size is hex; space means it's decimal
  const char* next_col = skip_word(str, ':');
  const char* next_spc = skip_word(str, ' ');
  if (next_spc - next_col > 0 && next_col[0]) {
    sscanf(next_col, "%llX", size);
    return skip_word(next_col, ' ') - str;
  } else if (next_spc[0]) {
    sscanf(next_spc, "%llu", size);
    return skip_word(next_spc, ' ') - str;
  }
  return 0;
}
Beispiel #9
0
/** Parse SIP <word "@" word> construct used in @CallID. */
char *sip_word_at_word_d(char **ss)
{
  char *rv = *ss, *s0 = *ss;

  skip_word(ss);
  if (s0 == *ss)
    return NULL;
  if (**ss == '@') {
    (*ss)++;
    s0 = *ss;
    skip_word(ss);
    if (s0 == *ss)
      return NULL;
  }
  if (IS_LWS(**ss))
    (*ss)++;
  skip_lws(ss);

  return rv;
}
Beispiel #10
0
static int fs_cmd_mv(struct fs_info *session) {
	/* Usage: mv <from-name> <to-name> */
	int ret;
	char *tmp, *arg_fromname, *arg_toname;

	if (!session->is_connected) {
		fprintf(stderr, "Not connected.\n");
		return FTP_RET_FAIL;
	}

	/* Get args */
	tmp = &session->cmd_buff[0];
	skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp);
	arg_fromname = tmp;
	skip_word(tmp); skip_spaces(tmp);
	arg_toname = tmp;

	split_word(arg_fromname);
	split_word(arg_toname);

	if ((*arg_fromname == '\0') || (*arg_toname == '\0')) {
		fprintf(stderr, "Please specify source and destonation names.\n");
		errno = EINVAL;
		return FTP_RET_ERROR;
	}
	/* --- END OF Get args --- */

	fprintf(stdout, "from: '%s`, to: '%s`\n", arg_fromname, arg_toname);

	ret = fs_execute(session, "RNFR %s\r\n", arg_fromname);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	ret = fs_execute(session, "RNTO %s\r\n", arg_toname);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	return FTP_RET_OK;
}
Beispiel #11
0
static int fs_cmd_ls(struct fs_info *session) {
	/* Usage: ls [remote-directory] */
	int ret, data_sock;
	char *tmp, *arg_remotedir;

	if (!session->is_connected) {
		fprintf(stderr, "Not connected.\n");
		return FTP_RET_FAIL;
	}

	/* Get args */
	tmp = &session->cmd_buff[0];
	skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp);
	arg_remotedir = tmp;

	split_word(arg_remotedir);

	if (*arg_remotedir == '\0') {
		arg_remotedir = NULL;
	}
	/* --- END OF Get args --- */

	ret = make_data_socket(session, &data_sock);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	ret = (arg_remotedir == NULL)
		? fs_execute(session, "LIST\r\n")
		: fs_execute(session, "LIST %s\r\n", arg_remotedir);
	if (ret != FTP_RET_OK) {
		close(data_sock);
		return ret;
	}

	ret = fill_file_from_socket(stdout, data_sock, &session->buff[0], sizeof session->buff);
	if (ret != FTP_RET_OK) {
		close(data_sock);
		return ret;
	}

	close(data_sock);

	if (FTP_STAT_TYPE_POSITIVE_PRELIMINARY
			== FTP_STAT_TYPE(session->stat_code)) {
		ret = fs_rcv_reply(session, &session->buff[0], sizeof session->buff);
		if (ret != FTP_RET_OK) {
			return ret;
		}
	}

	return FTP_RET_OK;
}
Beispiel #12
0
bool match_pattern(PatternNode *node, const char *i, const char *j)
{
    assert(node != NULL);
    switch (node->type)
    {
    case PN_WORD:
        if (starts_with(i, node->text))
        {
            return skip_word(i) == j;
        }
        return false;

    case PN_SEQ:
        {
            const char *k = i;
            for (;;)
            {
                if (match_pattern(node->left,  i, k) &&
                    match_pattern(node->right, k, j))
                {
                    return true;
                }
                if (*k == '\0') break;
                k = skip_word(k);
            }
        } break;

    case PN_ALT:
        return match_pattern(node->left,  i, j) ||
               match_pattern(node->right, i, j);

    case PN_OPT:
        return i == j || match_pattern(node->left, i, j);

    default:
        assert(false);
    }
    return false;
}
Beispiel #13
0
int cmd_goto(char *rest)
{
/*
 * Perform GOTO command.
 *
 * Only valid if batch file current.
 */

  char *tmp;

  while(bc && bc->forvar)   /* is FOR context */
    exit_batch();       /* remove it */

  if (bc == NULL)
  {
    /*!! not in batch error */

    return 1;
  }
  assert(rest);

  if(*rest == ':')    /* some old DOS shell excepts a colon */
    rest = skipdm(rest + 1);

  if (*rest == '\0')
  {
    displayString(TEXT_ERROR_NO_GOTO_LABEL);
    exit_batch();
    return 1;
  }

  tmp = skip_word(rest);
  *tmp = '\0';

  tmp = strdup(rest);
  if (!tmp)
  {
    error_out_of_memory();
    return 1;
  }

  /* Restart the batch file from the beginning */
  bc->brewind = 1;
  bc->blabel = tmp;

  return 0;
}
Beispiel #14
0
/*
 *  コマンドのデスパッチ
 */
static INT
dispatch_command(B *command, INT *point)
{
	int no, count;

	count = sizeof(mon_dispatch) / sizeof(struct COMMAND_TABLE);
	skip_space(command, point);
	if(command[*point]){
		for(no = 0 ; no < count ; no++){
			if(compare_word(mon_dispatch[no].command, &command[*point], mon_mode)){
				skip_word(command, point);
				return no;
			}
		}
	}
	return -1;
}
Beispiel #15
0
static int fs_cmd_user(struct fs_info *session) {
	/* Usage: user <user-name> */
	int ret;
	char *tmp, *arg_username, *password;

	if (!session->is_connected) {
		fprintf(stderr, "Not connected.\n");
		return FTP_RET_FAIL;
	}

	/* Get args */
	tmp = &session->cmd_buff[0];
	skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp);
	arg_username = tmp;

	split_word(arg_username);

	if (*arg_username == '\0') {
		fprintf(stderr, "User name is not specified.\n");
		errno = EINVAL;
		return FTP_RET_ERROR;
	}
	/* --- END OF Get args --- */

	ret = fs_execute(session, "USER %s\r\n", arg_username);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	password = getpass("Password: "******"Cant get password for %s.\n", arg_username);
		errno = EINVAL;
		return FTP_RET_ERROR;
	}

	ret = fs_execute(session, "PASS %s\r\n", password);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	return FTP_RET_OK;
}
Beispiel #16
0
static int parse_month(const char *buf, int i, int len, int *val_return)
{
	int j, k, l;
	j = skip_word(buf, i, len);
	if (j != i + 3)
		return -1;
	for (k = 0; k < 12; k++) {
		for (l = 0; l < 3; l++) {
			if (lwr(buf[i + l]) != month_names[k][l])
				break;
		}
		if (l == 3)
			break;
	}
	if (k >= 12)
		return -1;
	*val_return = k;
	return j;
}
Beispiel #17
0
    virtual void handle_jcc(UByte opcode, size_t word_size) {
        UByte fault = opcode;

        if (opcode == 0x0F) {
            _scanner.get(&opcode);
        }

        switch (opcode & 0x0F) {
        // JA <-> JAE
        // JB <-> JBE
        // JNA <-> JNAE
        // JNB <-> JNBE
        case 0x02:
        case 0x03:
            fault = opcode + 4;
            break;
        case 0x06:
        case 0x07:
            fault = opcode - 4;
            break;
        // JG <-> JGE
        // JL <-> JLE
        // JNG <-> JNGE
        // JNL <-> JNLE
        case 0x0C:
        case 0x0D:
            fault = opcode + 2;
            break;
        case 0x0E:
        case 0x0F:
            fault = opcode - 2;
            break;
        default:
            goto exit;
        }

        _scanner.seek(-1, scanner::SEEK_CUR);
        _scanner.put(fault);
        System.Print("FI: JCC(%.2X) OFF-BY-ONE %.2X\n", opcode, fault);
exit:
        skip_word(word_size);
    }
Beispiel #18
0
const char      *token_type_to_string(t_token_type type)
{
  const char    *types_string;

  types_string = ("instruction\0"
                  "integer\0string\0"
                  "directive\0comment\0"
                  "label definition\0label reference\0"
                  "comma\0percent\0"
                  "new line\0\0");
  while (*types_string)
    {
      if (!type)
        return (types_string);
      type--;
      skip_word(&types_string);
      types_string++;
    }
  return (NULL);
}
Beispiel #19
0
    virtual void handle_jcc(UByte opcode, size_t word_size) {
        //
        // Change the condition
        //

        if (opcode == 0x0F) {
            _scanner.get(&opcode);
        }

        if ((opcode & 0xF) % 2 == 0) {
            opcode++;
        }
        else {
            opcode--;
        }

        _scanner.seek(-1, scanner::SEEK_CUR);
        _scanner.put(opcode);

        skip_word(word_size);
    }
Beispiel #20
0
int initialize(void)
{
  int comPath;                /* path to COMMAND.COM (for COMSPEC/reload) */
  char *newTTY;                 /* what to change TTY to */
  int showinfo;                 /* show initial info only if no command line options */
  int key;

  int ec;           /* error code */
  unsigned offs;        /* offset into environment segment */

  int cmdlen;         /* length of command line */
  char *cmdline;        /* command line duplicated into heap */
  char *p, *h, *q;
#ifdef FEATURE_CALL_LOGGING
  FILE *f;
#endif

/* Set up the host environment of COMMAND.COM */

  /* Install the ^Break handler (see chkCBreak() for more details) */
  extern void initCBreakCatcher(void);
  initCBreakCatcher();

  /* Install INT 24 Critical error handler */
  init_error_handler();

  /* DOS shells patch the PPID to the own PID, how stupid this is, however,
    because then DOS won't terminate them, e.g. when a Critical Error
    occurs that is not detected by COMMAND.COM */

  oldPSP = OwnerPSP;
  atexit(exitfct);
  OwnerPSP = _psp;

  /* Some elder DOSs may not pass an initialzied environment segment */
  if (env_glbSeg && !isMCB(SEG2MCB(env_glbSeg)))
    env_setGlbSeg(0);       /* Disable the environment */

/* Now parse the command line parameters passed to COMMAND.COM */
  /* Preparations */
  newTTY = NULL;
  comPath = tracemode = 0;
  showinfo = 1;

  /* Because FreeCom should be executed in a DOS3+ compatible
    environment most of the time, it is assumed that its path
    can be determined from the environment.
    This has the advantage that the string area is accessable
    very early in the run.
    The name of the current file is string #0. */
  if((offs = env_string(0, 0)) != 0)    /* OK, environment filled */
    grabComFilename(0, (char far *)MK_FP(env_glbSeg, offs));

  /* Aquire the command line, there are three possible sources:
    1) DOS command line @PSP:0x80 as pascal string,
    2) extended DOS command line environment variable CMDLINE,
      if peekb(PSP, 0x80) == 127,&
    3) MKS command line @ENV:2, if peekb(ENV, 0) == '~'

    Currently implemented is version #1 only
  */
  cmdlen = peekb(_psp, 0x80);
  if(cmdlen < 0 || cmdlen > 126) {
    error_corrupt_command_line();
    cmdlen = 0;
  }
    /* duplicate the command line into the local address space */
  if((cmdline = malloc(cmdlen + 1)) == NULL) {
    error_out_of_memory();  /* Cannot recover from this problem */
    return E_NoMem;
  }
  _fmemcpy((char far*)cmdline, MK_FP(_psp, 0x81), cmdlen);
  cmdline[cmdlen] = '\0';
#ifdef FEATURE_CALL_LOGGING
  if((f = fopen(logFilename, "at")) == NULL) {
    fprintf(stderr, "Cannot open logfile: \"%s\"\n", logFilename);
    exit(125);
  }

  putc('"', f);
  if(ComPath)   /* path to command.com already known */
    fputs(ComPath, f);
  putc('"', f);
  putc(':', f);

  fputs(cmdline, f);
  putc('\n', f);
  fclose(f);
#endif

  p = cmdline;    /* start of the command line */
  do {
  ec = leadOptions(&p, opt_init, NULL);
  if(ec == E_NoOption) {    /* /C or /K */
    assert(p && *p);
    if(!isoption(p)) {
      error_quoted_c_k();
      p = NULL;
      break;
    }
    assert(p[1] && strchr("kKcC", p[1]));
    p += 2;   /* p := start of command line to execute */
    break;
  } else if(ec != E_None) {
        showhelp = 1;
    p = NULL;
    break;
  }

  assert(p && !isoption(p) && !isspace(*p));
  if(!*p) {
    p = NULL;
    break;      /* end of line reached */
  }
  q = unquote(p, h = skip_word(p));
  p = h;      /* Skip this word */
  if(!q) {
    error_out_of_memory();
    p = NULL;
    break;
  }
  if(!comPath) {      /* 1st argument */
    grabComFilename(1, (char far*)q);
    comPath = 1;
    free(q);
  } else if(!newTTY) {  /* 2nd argument */
#ifdef INCLUDE_CMD_CTTY
    newTTY = q;
#else
      error_ctty_excluded();
    free(q);
#endif
      } else {
        error_too_many_parameters(q);
        showhelp = 1;
        free(q);
        break;
      }
   } while(1);

   /*
    * Now:
    * + autoexec: AUTOEXEC.BAT file to be executed if /P switch
    *   is enabled; if NULL, use default
    * + comPath: user-defined PATH to COMMAND.COM; if NULL, use
    *   the one from the environment
    * + newTTY: the name of the device to be CTTY'ed; if NULL,
    *   no change
    * + p: pointer to the command to be executed:
    *   *p == 'c' or 'C' --> spawn command, then terminate shell
    *   *p == 'k' or 'K' --> spawn command, then go interactive
    *   &p[1] --> command line, unless the first character is an
    *   argument character
    */

/* Now process the options */

#ifdef INCLUDE_CMD_CTTY
  if (newTTY) {                   /* change TTY as early as possible so the caller gets
                                   the messages into the correct channel */
    cmd_ctty(newTTY);
    free(newTTY);
  }
#endif

  if(!ComPath) {
    /* FreeCom is unable to find itself --> print error message */
    /* Emergency error */
    puts("You must specify the complete path to " COM_NAME);
    puts("as the first argument of COMMAND,");
    puts("for instance: C:\\FDOS");
    return E_Useage;
  }

  /* First of all, set up the environment */
  env_resizeCtrl |= ENV_USEUMB | ENV_ALLOWMOVE;
  if (envSize < 0)
    envSize = 32767;        /* Numeric overflow (number > 32767 specified) */
  else if (envSize < 256)
    envSize = 256;          /* Minimum size of 256. */
	if(envSize > env_resize(0, 0))	/* Test if to enlarge environment */
		env_setsize(0, envSize);
    /* Set the COMSPEC variable. */
#if 0
  if (chgEnv("COMSPEC", ComPath)) error_env_var("COMSPEC");
#else
  if (chgEnv("COMSPEC", ComPath)) {
    /* Failed to add this variable, the most likely problem should be that
      the environment is too small --> it is increased and the
      operation is redone */
    env_resize(0, strlen(ComPath) + 10);
    if (chgEnv("COMSPEC", ComPath))
    error_env_var("COMSPEC");
  }
#endif

  if(internalBufLen)
    error_l_notimplemented();
  if(inputBufLen)
    error_u_notimplemented();

  if(tracemode)
    showinfo = 0;

  if (showhelp)
    displayString(TEXT_CMDHELP_COMMAND);

  if ((showhelp || exitflag) && canexit)
    return E_None;

  /* Now the /P option can be processed */
  if (!canexit)
  {
    char *autoexec;

    autoexec = user_autoexec? user_autoexec: AUTO_EXEC;

    showinfo = 0;
    short_version();

    /* JP: changed so that if autoexec does not exist, then don't ask
       to trace or bypass.
     */
    if (exist(autoexec))
    {
      printf("\nPress F8 for trace mode, or F5 to bypass %s... ", autoexec);
      key = WaitForFkeys();
      putchar('\n');

      if (key == KEY_F8)
      {
        tracemode = 1;
      }

      if (key == KEY_F5)
      {
        printf("Bypassing %s\n", autoexec);
      }
      else
        process_input(1, autoexec);
    }
    else
    {
      if(user_autoexec)
        printf("%s not found.\n", autoexec);
#ifdef INCLUDE_CMD_DATE
      cmd_date(NULL);
#endif
#ifdef INCLUDE_CMD_TIME
      cmd_time(NULL);
#endif
    }

    free(user_autoexec);
  }
  else
  {
    assert(user_autoexec == NULL);
  }

  /* Now the /C or /K option can be processed */
  if (p)
  {
    process_input(1, p);
    return spawnAndExit;
  }

  /* Don't place something here that must be executed after a /K or /C */

  if (showinfo)
  {
    short_version();
    putchar('\n');
    showcmds(NULL);
    putchar('\n');
  }

  return E_None;
}
Beispiel #21
0
static void docommand(char *line)
{
  /*
   * look through the internal commands and determine whether or not this
   * command is one of them.  If it is, call the command.  If not, call
   * execute to run it as an external program.
   *
   * line - the command line of the program to run
   */

#ifdef FEATURE_INSTALLABLE_COMMANDS
	/* Duplicate the command line into such buffer in order to
		allow Installable Commands to alter the command line.
		*line cannot be modified as pipes would be destroyed. */
	/* Place both buffers immediately following each other in
		order to make sure the contents of args can be appended
		to com without any buffer overflow checks.
		*2 -> one buffer for com and one for args
		+2 -> max length byte of com + cur length of com
		+3 -> max length byte of args + cur length of args + additional '\0'
	*/
	char buf[2*BUFFER_SIZE_MUX_AE+3+1];
#define com  (buf + 1)
#define args (buf + 1 + BUFFER_SIZE_MUX_AE + 2)
#define BUFFER_SIZE BUFFER_SIZE_MUX_AE
#else
	char com[MAX_INTERNAL_COMMAND_SIZE];
#define BUFFER_SIZE MAX_INTERNAL_COMMAND_SIZE
#endif
  char *cp;
  char *rest;            /* pointer to the rest of the command line */

  struct CMD *cmdptr;

  assert(line);

  /* delete leading & trailing whitespaces */
  line = trim(line);

#ifdef FEATURE_INSTALLABLE_COMMANDS
#if BUFFER_SIZE < MAX_INTERNAL_COMMAND_SIZE
	if(strlen(line) > BUFFER_SIZE) {
		error_line_too_long();
		return;
	}
#endif
	line = strcpy(args, line);
#endif

  if (*(rest = line))                    /* Anything to do ? */
  {
    cp = com;

  /* Copy over 1st word as lower case */
  /* Internal commands are constructed out of non-delimiter
  	characters; ? had been parsed already */
    while(*rest && !is_delim(*rest) && !strchr(QUOTE_STR, *rest))
      *cp++ = toupper(*rest++);

    if(*rest && strchr(QUOTE_STR, *rest))
      /* If the first word is quoted, it is no internal command */
      cp = com;   /* invalidate it */
    *cp = '\0';                 /* Terminate first word */

	if(*com) {
#ifdef FEATURE_INSTALLABLE_COMMANDS
		/* Check for installed COMMAND extension */
		if(runExtension(com, args))
			return;		/* OK, executed! */

		dprintf( ("[Command on return of Installable Commands check: >%s<]\n", com) );
#endif

		/* Scan internal command table */
		for (cmdptr = cmds; cmdptr->name && strcmp(com, cmdptr->name) != 0
		; cmdptr++);

	}

    if(*com && cmdptr->name) {    /* internal command found */
      switch(cmdptr->flags & (CMD_SPECIAL_ALL | CMD_SPECIAL_DIR)) {
      case CMD_SPECIAL_ALL: /* pass everything into command */
        break;
      case CMD_SPECIAL_DIR: /* pass '\\' & '.' too */
        if(*rest == '\\' || *rest == '.') break;
      default:        /* pass '/', ignore ',', ';' & '=' */
        if(*rest == '/') break;
        if(!*rest || isspace(*rest)) {  /* normal delimiter */
          rest = ltrim(rest);
          break;
        }
        if(strchr(",;=", *rest)) {
          rest = ltrim(rest + 1);
          break;
        }

        /* else syntax error */
        error_syntax(NULL);
        return;
      }

        /* JPP this will print help for any command */
        if (strstr(rest, "/?"))
        {
          displayString(cmdptr->help_id);
        }
        else
        {
          dprintf(("CMD '%s' : '%s'\n", com, rest));
          cmdptr->func(rest);
        }
      } else {
#ifdef FEATURE_INSTALLABLE_COMMANDS
		if(*com) {		/* external command */
			/* Installable Commands are allowed to change both:
				"com" and "args". Therefore, we may need to
				reconstruct the external command line */
			/* Because com and *rest are located within the very same
				buffer and rest is definitely terminated with '\0',
				the followinf memmove() operation is fully robust
				against buffer overflows */
			memmove(com + strlen(com), rest, strlen(rest) + 1);
			/* Unsave, but probably more efficient operation:
				strcat(com, rest);
					-- 2000/12/10 ska*/
			line = com;
		}
#endif
        /* no internal command --> spawn an external one */
        cp = unquote(line, rest = skip_word(line));
        if(!cp) {
          error_out_of_memory();
          return;
        }
		execute(cp, ltrim(rest));
		free(cp);
      }
  }
#undef line
#undef com
#undef args
#undef BUFFER_SIZE
}
Beispiel #22
0
const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, std::pair<const char*, const char*> &command)
{
    PROFILE_FUNC();
    
    // command and args
    const char *c = ptr;
    {
        PROFILE_BLOCK(command_and_args);
        // Skip the whitespaces.
        command.first = skip_whitespaces(c);
        // Skip the command.
        c = command.second = skip_word(command.first);
        // Up to the end of line or comment.
		while (! is_end_of_gcode_line(*c)) {
            // Skip whitespaces.
            c = skip_whitespaces(c);
			if (is_end_of_gcode_line(*c))
				break;
            // Check the name of the axis.
            Axis axis = NUM_AXES;
            switch (*c) {
            case 'X': axis = X; break;
            case 'Y': axis = Y; break;
            case 'Z': axis = Z; break;
            case 'F': axis = F; break;
            default:
                if (*c == m_extrusion_axis)
                    axis = E;
                break;
            }
            if (axis != NUM_AXES) {
                // Try to parse the numeric value.
                char   *pend = nullptr;
                double  v = strtod(++ c, &pend);
                if (pend != nullptr && is_end_of_word(*pend)) {
                    // The axis value has been parsed correctly.
                    gline.m_axis[int(axis)] = float(v);
                    gline.m_mask |= 1 << int(axis);
                    c = pend;
                } else
                    // Skip the rest of the word.
                    c = skip_word(c);
            } else
                // Skip the rest of the word.
                c = skip_word(c);
        }
    }
    
    if (gline.has(E) && m_config.use_relative_e_distances)
        m_position[E] = 0;

    // Skip the rest of the line.
    for (; ! is_end_of_line(*c); ++ c);

    // Copy the raw string including the comment, without the trailing newlines.
    if (c > ptr) {
        PROFILE_BLOCK(copy_raw_string);
        gline.m_raw.assign(ptr, c);
    }

    // Skip the trailing newlines.
	if (*c == '\r')
		++ c;
	if (*c == '\n')
		++ c;

    if (m_verbose)
        std::cout << gline.m_raw << std::endl;

    return c;
}
Beispiel #23
0
Datei: if.c Projekt: FDOS/freecom
int cmd_if(char *param)
{

#define X_EXEC 1

	char *pp;

	int x_flag = 0;       /* when set cause 'then' clause to be exec'ed */
	int negate = 0;       /* NOT keyword present */
	int ignore_case = 0;  /* /I option, case insensitive compare */


	/* First check if param exists */
	assert(param);

	/* check for options, note non-options must be treated as part of comparision */
      if (matchtok(param, "/I")||matchtok(param, "/i"))
        ignore_case++;

	/* next check if param string begins with word 'not' */
	if(matchtok(param, "not"))
		negate = X_EXEC;            /* Remember 'NOT' */

	/* Check for 'exist' form */

	if(matchtok(param, "exist")) {
		struct dos_ffblk f;
		isr olderrhandler;

		if(!*param) {
			/* syntax error */
			error_if_exist();
			return 0;
		}

		pp = skip_word(param);
		*pp++ = '\0';

		/* don't show abort/retry/fail if no disk in drive */
		get_isr(0x24, olderrhandler);
#ifdef XMS_SWAP
		set_isrfct(0x24, autofail_err_handler);  /* always fails */
#else
		set_isrfct(0x24, dummy_criter_handler);  /* always fails */
#endif

		if(dos_findfirst(param, &f, FA_NORMAL|FA_ARCH|FA_SYSTEM|FA_RDONLY|FA_HIDDEN) == 0)
			x_flag = X_EXEC;
		dos_findclose(&f);
        
		/* restore critical error handler */
		set_isrfct(0x24, olderrhandler);
	}

	/* Check for 'errorlevel' form */

	else if(matchtok(param, "errorlevel")) {
		int n = 0;

#if 0
		if(!isdigit(*param)) {
			error_if_errorlevel();
			return 0;
		}

		pp = param;
		do  n = n * 10 + (*pp - '0');
		while (isdigit(*++pp));

		if(*pp && !isargdelim(*pp)) {
			error_if_errorlevel_number();
			return 0;
		}
#else
		/* Add this COMMAND bug as someone tries to use:
			IF ERRORLEVEL H<upper-case_letter>
			-or-
			IF ERRORLEVEL x<lower-case_letter>

			to match the errorlevel against drive letters.
			NOT supported by 4dos or WinNT.

			HA --> maps to errorlevel 1
			xa --> same

			HB & xb --> to 2
			a.s.o.
		*/

		if(!*param) {
			error_if_errorlevel();
			return 0;
		}
		pp = param;
		do  n = n * 10 + (*pp - '0');
		while(*++pp && !isargdelim(*pp));
		n &= 255;
		dprintf( ("IF: checking for ERRORLEVEL >= %u\n", n) );
#endif

		if(errorlevel >= n)
			x_flag = X_EXEC;
	}

	/* Check that '==' is present, syntax error if not */
	else {
		size_t len;
		char *r;      /* right operand */

		pp = skipqword(param, "==");

		if(*pp != '=' || pp[1] != '=') {
			error_syntax(0);
			return 0;
		}

		*pp = '\0';     /* param[] points to the left operand */

		/* skip over the '==' and subsquent spaces and
			assign the end of the right operator to pp */
		pp = skipqword(r = ltrimcl(pp + 2), 0);

		/*	now: param := beginning of the left operand
			r := beginning of the right operand
			pp := end of right operand
		*/

		rtrimcl(param);      /* ensure that spurious whitespaces are ignored */
		len = strlen(param);

		/* check if strings differ */
		if ( ((pp - r) == len) &&
		     ((ignore_case && strnicmp(param, r, len) == 0) ||
		      (memcmp(param, r, len) == 0)) )
			x_flag = X_EXEC;
	}

	if(x_flag ^ negate)		/* perform the command */
		if(!*(pp = ltrimcl(pp)))
			error_if_command();
		else
			parsecommandline(pp, FALSE);

	return 0;
}
Beispiel #24
0
int main(int argc, char **argv) {
	int ret;
	size_t i;
	struct fs_info fsi;
	char old_value, *cmd_name, *first_space;

	fsi.is_connected = 0; /* initialize FTP Session Information structure */

	if (argc > 3) {
		return -EINVAL;
	}
	else if (argc > 1) {
		if (strcmp(argv[1], "-h") == 0) {
			printf("Usage: %s [address [port]]\n", argv[0]);
			return 0;
		}
		cmd_name = &fsi.cmd_buff[0];
		snprintf(&fsi.cmd_buff[0], sizeof fsi.cmd_buff, "open %s %s",
				argv[1], argc == 3 ? argv[2] : "");
		goto parse_cmd;
	}

	while (1) {
		fprintf(stdout, "%s> ", argv[0]);

		cmd_name = fgets(&fsi.cmd_buff[0], sizeof fsi.cmd_buff, stdin);
		if (cmd_name == NULL) {
			fprintf(stderr, "%s: fatal error: fgets return null.\n", argv[0]);
			break;
		}

parse_cmd:
		/* Skip spaces */
		skip_spaces(cmd_name);

		/* Skip empty commands */
		if (*cmd_name == '\0') {
			continue;
		}

		/* Set '\0' to the end of command's name */
		first_space = cmd_name;
		skip_word(first_space);
		if (*first_space == '\0') {
			first_space = NULL;
		}
		else {
			old_value = *first_space;
			*first_space = '\0';
		}

		/* Try find this command */
		for (i = 0; i < sizeof ftp_mtds / sizeof ftp_mtds[0]; ++i) {
			if (strcmp(ftp_mtds[i].mtd_name, cmd_name) == 0) {
				break;
			}
		}
		if (i == sizeof ftp_mtds / sizeof ftp_mtds[0]) {
			fprintf(stderr, "%s: unknown command `%s'.\n", argv[0], cmd_name);
			continue;
		}

		/* Restore original string */
		if (first_space != NULL) {
			*first_space = old_value;
		}

		/* Remove spaces before command */
		memmove(&fsi.cmd_buff[0], cmd_name, strlen(cmd_name) + 1);

		/* Execute user command by its idx */
		ret = (*ftp_mtds[i].mtd_hnd)(&fsi);
		if (ret == FTP_RET_FAIL) {
			continue; /* nothing to do */
		}
		else if (ret == FTP_RET_ERROR) {
			fprintf(stderr, "%s: error occurred: code=%d, description=%s.\n", argv[0], errno, strerror(errno));
			continue;
		}
		else if (ret == FTP_RET_EXIT) {
			break; /* wanna exit from ftp client */
		}
		/* ASSERT ret is FTP_RET_OK */
		/* nothing to do */
	}

	return 0;
}
Beispiel #25
0
static int fs_cmd_put(struct fs_info *session) {
	/* Usage: put <local-file> <remote-file> */
	int ret, data_sock;
	char *tmp, *arg_localfile, *arg_remotefile;
	FILE *file;

	if (!session->is_connected) {
		fprintf(stderr, "Not connected.\n");
		return FTP_RET_FAIL;
	}

	/* Get args */
	tmp = &session->cmd_buff[0];
	skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp);
	arg_localfile = tmp;
	skip_word(tmp); skip_spaces(tmp);
	arg_remotefile = tmp;

	split_word(arg_localfile);
	split_word(arg_remotefile);

	if ((*arg_localfile == '\0') && (*arg_remotefile == '\0')) {
		fprintf(stderr, "Please specify names of local and remote files.\n");
		errno = EINVAL;
		return FTP_RET_ERROR;
	}
	/* --- END OF Get args --- */

	fprintf(stdout, "local: '%s`, remote: '%s`\n", arg_localfile, arg_remotefile);

	file = fopen(arg_localfile, "r");
	if (file == NULL) {
		fprintf(stderr, "Can't open file '%s` for reading.\n", arg_localfile);
		return FTP_RET_ERROR;
	}

	ret = make_data_socket(session, &data_sock);
	if (ret != FTP_RET_OK) {
		fclose(file);
		return ret;
	}

	ret = fs_execute(session, "STOR %s\r\n", arg_remotefile);
	if (ret != FTP_RET_OK) {
		fclose(file);
		close(data_sock);
		return ret;
	}

	ret = flush_file_to_socket(file, data_sock, &session->buff[0], sizeof session->buff);
	if (ret != FTP_RET_OK) {
		fclose(file);
		close(data_sock);
		return ret;
	}

	fclose(file);
	close(data_sock);

	ret = fs_rcv_reply(session, &session->buff[0], sizeof session->buff);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	return FTP_RET_OK;
}
Beispiel #26
0
static int fs_cmd_get(struct fs_info *session) {
	/* Usage: get <remote-file> [local-file] */
	int ret, data_sock;
	char *tmp, *arg_remotefile, *arg_localfile;
	FILE *file;

	if (!session->is_connected) {
		fprintf(stderr, "Not connected.\n");
		return FTP_RET_FAIL;
	}

	/* Get args */
	tmp = &session->cmd_buff[0];
	skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp);
	arg_remotefile = tmp;
	skip_word(tmp); skip_spaces(tmp);
	arg_localfile = tmp;

	split_word(arg_remotefile);
	split_word(arg_localfile);

	if (*arg_remotefile == '\0') {
		fprintf(stderr, "Remote file name is not specified.\n");
		errno = EINVAL;
		return FTP_RET_ERROR;
	}
	if (*arg_localfile == '\0') {
		arg_localfile = strchr(arg_remotefile, '/');
		if (arg_localfile != NULL) {
			arg_localfile += 1; /* skip '/' character */
		}
		else {
			arg_localfile = arg_remotefile;
		}
	}
	/* --- END OF Get args --- */

	fprintf(stdout, "remote: '%s`, local: '%s`\n", arg_remotefile, arg_localfile);

	file = fopen(arg_localfile, "w");
	if (file == NULL) {
		fprintf(stderr, "Can't open file '%s` for writing.\n", arg_localfile);
		return FTP_RET_ERROR;
	}

	ret = make_data_socket(session, &data_sock);
	if (ret != FTP_RET_OK) {
		fclose(file);
		return ret;
	}

	ret = fs_execute(session, "RETR %s\r\n", arg_remotefile);
	if (ret != FTP_RET_OK) {
		fclose(file);
		close(data_sock);
		return ret;
	}

	ret = fill_file_from_socket(file, data_sock, &session->buff[0], sizeof session->buff);
	if (ret != FTP_RET_OK) {
		fclose(file);
		close(data_sock);
		return ret;
	}

	fclose(file);
	close(data_sock);

	ret = fs_rcv_reply(session, &session->buff[0], sizeof session->buff);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	return FTP_RET_OK;
}
Beispiel #27
0
static void docommand(char *line)
{
  /*
   * look through the internal commands and determine whether or not this
   * command is one of them.  If it is, call the command.  If not, call
   * execute to run it as an external program.
   *
   * line - the command line of the program to run
   */
  char *cp;
  char *rest;            /* pointer to the rest of the command line */
  struct CMD *cmdptr = 0;

#ifdef FEATURE_INSTALLABLE_COMMANDS
	/* Duplicate the command line into such buffer in order to
		allow Installable Commands to alter the command line.
		*line cannot be modified as pipes would be destroyed. */
	/* Place both buffers immediately following each other in
		order to make sure the contents of args can be appended
		to com without any buffer overflow checks.
		*2 -> one buffer for com and one for args
		+2 -> max length byte of com + cur length of com
		+3 -> max length byte of args + cur length of args + additional '\0'
	*/
	char *buf = malloc(2+2*BUFFER_SIZE_MUX_AE+2+1);
#define args  (buf + 2)
#define ARGS_BUFFER_SIZE (2 + BUFFER_SIZE_MUX_AE + 3)
#define com (buf + ARGS_BUFFER_SIZE)
#define BUFFER_SIZE BUFFER_SIZE_MUX_AE
#else
	char *com = malloc(MAX_INTERNAL_COMMAND_SIZE);
#define args line
#define buf com
#define BUFFER_SIZE MAX_INTERNAL_COMMAND_SIZE
#endif

  assert(line);

	if(!buf) {
	  error_out_of_memory();
	  return;
	}

  /* delete leading spaces, but keep trailing whitespaces */
  line = ltrimcl(line);

#ifdef FEATURE_INSTALLABLE_COMMANDS
#if BUFFER_SIZE < MAX_INTERNAL_COMMAND_SIZE
	if(strlen(line) > BUFFER_SIZE) {
		error_line_too_long();
		goto errRet;
	}
#endif
	strcpy(args, line);
#endif

  if (*(rest = args))                    /* Anything to do ? */
  {
    cp = com;

  /* Copy over 1st word as upper case */
  /* Internal commands are constructed out of non-delimiter
  	characters; ? had been parsed already */
    while(*rest && is_fnchar(*rest) && !strchr(QUOTE_STR, *rest))
      *cp++ = toupper(*rest++);

    if(*rest && strchr(QUOTE_STR, *rest))
      /* If the first word is quoted, it is no internal command */
      cp = com;   /* invalidate it */
    *cp = '\0';                 /* Terminate first word */

	if(*com) {
#ifdef FEATURE_INSTALLABLE_COMMANDS
		int tryMUXAE;
		for(tryMUXAE = MUX_AE_MAX_REPEAT_CALL; tryMUXAE > 0; --tryMUXAE) {
			/* Check for installed COMMAND extension */
			switch(runExtension(com, args)) {
				case 1:		/* OK, done */
					goto errRet;
				case 0:		/* no extension */
					tryMUXAE = 0;
			}
			/* reset the argument pointer */
			rest = &args[(unsigned char)com[-1]];

			dprintf( ("[Command on return of Installable Commands check: >%s]\n", com) );
#ifndef NDEBUG
			dprintf( ("[Command line: >") );
			for(cp = args; cp < rest; ++cp)
				dprintf( ("%c", *cp) );
			dprintf( ("|%s]\n", rest) );
#endif	/* !defined(NDEBUG) */

#endif

		/* Scan internal command table */
		for (cmdptr = internalCommands
		 ; cmdptr->name && strcmp(com, cmdptr->name) != 0
		 ; cmdptr++);

    if(cmdptr && cmdptr->name) {    /* internal command found */

#ifdef FEATURE_INSTALLABLE_COMMANDS
	cp = realloc(buf, ARGS_BUFFER_SIZE);
#ifndef NDEBUG
	if(cp != buf) {
		dprintf( ("[INTERNAL error: realloc() returned wrong result]") );
		buf = cp;
	}
#endif
#else
	free(buf);  buf = 0;	/* no further useage of this buffer */
#endif
      switch(cmdptr->flags & (CMD_SPECIAL_ALL | CMD_SPECIAL_DIR)) {
      case CMD_SPECIAL_ALL: /* pass everything into command */
        break;
      case CMD_SPECIAL_DIR: /* pass '\\' & '.' too */
        if(*rest == '\\' || *rest == '.' || *rest == ':') break;
      default:        /* pass '/', ignore ',', ';' & '=' */
        if(!*rest || *rest == '/') break;
        if(isargdelim(*rest)) {
			rest = ltrimcl(rest);
			break;
		}

        /* else syntax error */
        error_syntax(0);
        goto errRet;
      }

        currCmdHelpScreen = cmdptr->help_id;
        /* JPP this will print help for any command */
        if(memcmp(ltrimcl(rest), "/?", 2) == 0)  {
          displayString(currCmdHelpScreen);
        } else {
          dprintf(("CMD '%s' : '%s'\n", cmdptr->name, rest));
          cmdptr->func(rest);
        }
        goto errRet;
	}
#ifdef FEATURE_INSTALLABLE_COMMANDS
	  }
#endif
      }

        free(buf); buf = 0;		/* no longer used */
        /* no internal command --> spawn an external one */
        cp = unquote(line, rest = skip_word(line));
        if(!cp) {
          error_out_of_memory();
          goto errRet;
        }
		execute(cp, rest);
		free(cp);
      }

#undef com
#undef args
#undef BUFFER_SIZE
#undef ARGS_BUFFER_SIZE

errRet:
	  free(buf);
}
int read_all_data(par_info *pi,sa_par_info *spi,subject **sub,int *nsubptr,char names[MAX_LOCI][20],char comments[MAX_LOCI][MAX_COMMENT_LENGTH],float func_weight[MAX_LOCI])
{
	char aline[1000],pos[100],effect[100],*ptr;
	int func_pos,l,f,use;
	float wt;
	std::map<std::string,float> weightMap;
	std::map<std::string,std::string> effectMap;
	if (spi->df[WEIGHTFILE].fp)
	{
		while (fgets(aline, 999, spi->df[WEIGHTFILE].fp))
		{
			sscanf(aline,"%s %f",effect,&wt);
			weightMap[effect]=wt;
		}
	}
	if (spi->df[ANNOTFILE].fp)
	{
		fgets(aline, 999, spi->df[ANNOTFILE].fp); // ignore first line (though could use it to see how many cohorts there are)
		for (func_pos=0,ptr=aline;strncmp(ptr,"FUNC",4);ptr=skip_word(ptr))
			if (!*ptr)
			{
				dcerror(1, "Could not find FUNC in annotation file %s:\n%s\n", spi->df[ANNOTFILE].fn, aline); exit(1);
			}
			else
				++func_pos;
		while (fgets(aline, 999, spi->df[ANNOTFILE].fp))
		{
			sscanf(aline,"%s",pos);
			ptr=aline;
			for (f=0;f<func_pos;++f)
				ptr=skip_word(ptr);
			sscanf(ptr,"%s",effect);
			effectMap[pos]=effect;
		}
	}
	if (spi->df[PSDATAFILE].fp)
		read_ps_datafile(pi,spi,sub,nsubptr,names,comments, func_weight,weightMap,effectMap);
	else if (spi->df[GCDATAFILE].fp)
		read_all_subjects(spi->df[GCDATAFILE].fp,sub,nsubptr,pi);
	else if (spi->df[GENDATAFILE].fp)
		read_all_gen_subjects(spi->df[GENDATAFILE].fp,sub,nsubptr,pi);
	if (spi->df[LOCUSFILTERFILE].fp)
	{
		pi->n_loci_to_use=0;
		for (l = 0; l < pi->nloci; ++l)
		{
			if (fscanf(spi->df[LOCUSFILTERFILE].fp, " %d", &use) != 1)
			{
				dcerror(1, "Not enough values in locusfilterfile %s\n", spi->df[LOCUSFILTERFILE].fn); exit(1);
			}
			else if (use==1)
				pi->loci_to_use[pi->n_loci_to_use++]=l;
		}
	}
	else
	{
		pi->n_loci_to_use = pi->nloci;
		for (l = 0; l < pi->nloci; ++l)
			pi->loci_to_use[l] = l;
	}
	if (spi->df[LOCUSWEIGHTFILE].fp)
	{
		for (l = 0; l < pi->nloci; ++l)
			if (fscanf(spi->df[LOCUSWEIGHTFILE].fp,"%f ",&func_weight[l])!=1)
			{
				dcerror(1, "Not enough values in locusweightfile %s\n", spi->df[LOCUSWEIGHTFILE].fn); exit(1);
			}
	}
	else if (spi->df[WEIGHTFILE].fp ==0)
		for (l = 0; l < pi->nloci; ++l)
			func_weight[l]=1;
	if (spi->df[LOCUSNAMEFILE].fp)
	{
		for (l = 0; l < pi->nloci; ++l)
			if (fscanf(spi->df[LOCUSNAMEFILE].fp,"%s ",&comments[l])!=1)
			{
				dcerror(1, "Not enough values in locusnamefile %s\n", spi->df[LOCUSNAMEFILE].fn); exit(1);
			}
	}
	for (l = 0; l < pi->nloci; ++l)
	{
		strncpy(names[l],comments[l],NAME_LENGTH-1);
		names[l][NAME_LENGTH-1]='\0';
	}

	return 1;
}
Beispiel #29
0
static int fs_cmd_open(struct fs_info *session) {
	/* Usage: open <host-name> [port] */
	int ret;
	char *tmp, *arg_hostname, *arg_port;
	struct in_addr remote_ip;
	unsigned int remote_port;

	if (session->is_connected) {
		fprintf(stderr, "Already connected, use close first.\n");
		return FTP_RET_FAIL;
	}

	/* Get args */
	tmp = &session->cmd_buff[0];
	skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp);
	arg_hostname = tmp;
	skip_word(tmp); skip_spaces(tmp);
	arg_port = tmp;

	split_word(arg_hostname);
	split_word(arg_port);

	if (*arg_hostname == '\0') {
		fprintf(stderr, "Remote address is not specified.\n");
		errno = EINVAL;
		return FTP_RET_ERROR;
	}

	if (*arg_port == '\0') {
		arg_port = NULL;
	}
	/* --- END OF Get args --- */

	if (!inet_aton(arg_hostname, &remote_ip)) {
		fprintf(stderr, "Can't parse IP address.\n");
		errno = EINVAL;
		return FTP_RET_ERROR;
	}
	if (arg_port == NULL) {
		remote_port = FTP_PORT; /* Use default settings */
	}
	else {
		if (sscanf(arg_port, "%u", &remote_port) != 1) {
			fprintf(stderr, "Can't parse port '%s`.\n", arg_port);
			errno = EINVAL;
			return FTP_RET_ERROR;
		}
	}

	ret = make_active_socket(remote_ip.s_addr, (uint16_t)remote_port, &session->cmd_sock);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	fprintf(stdout, "Connected to %s:%u.\n", arg_hostname, remote_port);
	session->is_connected = 1;

	ret = fs_rcv_reply(session, &session->buff[0], sizeof session->buff);
	if (ret != FTP_RET_OK) {
		return ret;
	}

	return FTP_RET_OK;
}
Beispiel #30
0
static void split_word(char *ptr) { skip_word(ptr); *ptr = '\0'; }