Beispiel #1
0
struct vfs_file* vfs_open_file(struct vfs_filesystem* filesystem,struct vfs_file* file,char* name)
{
    if(filesystem->mountpointcount==0){
    //Attempt to load the file in this filesystem
        return _vfs_open_file(filesystem,file,name);
    }else{
    //Loop through mountpoints to check if the file is in one
        unsigned int i=0;
        for(i=0;i<filesystem->mountpointcount;i++){
        //Check if this mountpoint contains this file
            unsigned int mpsize=strcmpbegin(filesystem->mountpoints[i].mountpoint,name);
            if(mpsize>0 && name[mpsize]=='/'){
            //It does, call this function for this mountpoint
                return vfs_open_file(&filesystem->mountpoints[i],file,(char*)((void*)name)+mpsize);
            }
        }
    //Attempt to load the file in this filesystem
        return _vfs_open_file(filesystem,file,name);
    }
    return 0;
}
Beispiel #2
0
void CLI_parse(u32_t len, u8_t *buf) {
#ifndef CONFIG_ANNOYATRON
  if (strcmpbegin("def", (char*)buf)==0) {
    if (buf[len-1] == '\r' || buf[len-1] == '\n') {
      len--;
    }
    memset(&buf[len], 0, sizeof(in)-len);
    def_config pindef;
    bool ok = def_config_parse(&pindef, (char*)&buf[4], len-4);
    if (ok) {
      def_config_print(&pindef);
      print("OK\n");
      APP_cfg_set_pin(&pindef);
    }
    print(CLI_PROMPT);
    return;
  }
#endif // CONFIG_ANNOYATRON

  cursor cursor;
  strarg_init(&cursor, (char*) buf, len);
  strarg arg;
  _argc = 0;
  func fn = NULL;
  int ix = 0;

  // parse command and args
  while (strarg_next(&cursor, &arg)) {
    if (arg.type == INT) {
      //DBG(D_CLI, D_DEBUG, "CONS arg %i:\tlen:%i\tint:%i\n",arg_c, arg.len, arg.val);
    } else if (arg.type == STR) {
      //DBG(D_CLI, D_DEBUG, "CONS arg %i:\tlen:%i\tstr:\"%s\"\n", arg_c, arg.len, arg.str);
    }
    if (_argc == 0) {
      // first argument, look for command function
      if (arg.type != STR) {
        break;
      } else {
        while (c_tbl[ix].name != NULL ) {
          if (strcmp(arg.str, c_tbl[ix].name) == 0) {
            fn = c_tbl[ix].fn;
            break;
          }
          ix++;
        }
        if (fn == NULL ) {
          break;
        }
      }
    } else {
      // succeeding arguments¸ store them in global vector
      if (_argc - 1 >= 16) {
        DBG(D_CLI, D_WARN, "CONS too many args\n");
        fn = NULL;
        break;
      }
      _args[_argc - 1] = (void*) arg.val;
    }
    _argc++;
  }

  // execute command
  if (fn) {
    _argc--;
    DBG(D_CLI, D_DEBUG, "CONS calling [%p] with %i args\n", fn, _argc);
    int res = (int) _variadic_call(fn, _argc, _args);
    if (res == -1) {
      print("%s", c_tbl[ix].help);
    } else {
      print("OK\n");
    }
  } else {
    print("unknown command - try help\n");
  }
  print(CLI_PROMPT);
}