Ejemplo n.º 1
0
int	read_cat(t_opt opts)
{
  int	nl;
  int	nb;
  char	str[BUFF_SIZE + 1];

  my_init(&nl, &nb);
  clean_str(&str[0]);
  while (read(0, &str, BUFF_SIZE) > 0)
    {
      str[BUFF_SIZE] = 0;
      exec_cat(str, opts, &nb, &nl);
      clean_str(&str[0]);
    }
  return (0);
}
Ejemplo n.º 2
0
static void exec_cmd(Pcs pcs, struct params *params)
{
	switch (params->action)
	{
	case ACTION_QUOTA:
		break;
	case ACTION_META: /*获取元数据*/
		exec_meta(pcs, params);
		break;
	case ACTION_LIST: /* 列出目录 */
		exec_list(pcs, params);
		break;
	case ACTION_RENAME: /* 重命名文件或目录 */
		exec_rename(pcs, params);
		break;
	case ACTION_MOVE: /* 移动文件或目录 */
		exec_move(pcs, params);
		break;
	case ACTION_COPY: /* 复制文件或目录 */
		exec_copy(pcs, params);
		break;
	case ACTION_MKDIR: /* 创建目录 */
		exec_mkdir(pcs, params);
		break;
	case ACTION_DELETE: /* 删除文件或目录 */
		exec_delete(pcs, params);
		break;
	case ACTION_CAT: /* 直接显示网盘中文本文件的内容 */
		exec_cat(pcs, params);
		break;
	case ACTION_ECHO: /* 直接把文本保存到网盘文件中 */
		exec_echo(pcs, params);
		break;
	case ACTION_SEARCH: /* 搜索网盘文件 */
		exec_search(pcs, params);
		break;
	case ACTION_DOWNLOAD: /* 下载网盘文件或目录 */
		exec_download(pcs, params);
		break;
	case ACTION_UPLOAD: /* 上传文件或目录到网盘中 */
		exec_upload(pcs, params);
		break;
	default:
		printf("Unknown command, use `--help` to view help.\n");
		break;
	}
}
Ejemplo n.º 3
0
int	my_cat(char *filename, t_opt opts)
{
  int	nl;
  int	nb;
  int	file;
  char	str[BUFF_SIZE + 1];

  file = open(filename, O_RDONLY, BUFF_SIZE);
  if (file == -1)
    return (my_error(filename));
  my_init(&nl, &nb);
  while (read(file, &str, BUFF_SIZE) > 0)
    {
      str[BUFF_SIZE] = 0;
      exec_cat(str, opts, &nb, &nl);
    }
  close(file);
  return (0);
}
Ejemplo n.º 4
0
void input_schema(Pschema s, char *attr_name, int spaces, int pretty, FILE *in_file){ // reads a schema and puts it on the top op tstack
    if(attr_name!=NULL && pretty){
        print_spaces(spaces, stdout);
        fprintf(stdout, "Input record attribute \"%s\"\n",attr_name);
    }
    if(pretty){
        print_spaces(spaces, stdout);
    }
    if(s->type == TY_RECORD || s->type == TY_ARRAY || s->type == TY_ATTR){
        int size = get_schema_size(s);
        int nfields = 0;
        switch(s->type){
            case TY_RECORD:{
                if(pretty){
                    fprintf(stdout,"Input for a record\n");
                }
                Pschema temp = s->child;
                while(temp){
                    input_schema(temp->child, temp->id, spaces+1, pretty, in_file);
                    nfields++;
                    temp = temp->brother;
                }
                break;
            }
            case TY_ARRAY:{
                int i;
                if(pretty){
                    fprintf(stdout, "Input for an array\n");
                }
                nfields = s->size;
                for(i=0; i<nfields; i++){
                    input_schema(s->child, NULL, spaces+1, pretty, in_file);
                }
                break;
            }
            default: print_schema(s,0); machine_error("TY_ATTR cannot be used in input_schema()."); break;
        }
        exec_cat(nfields,size);
    } else{
        switch(s->type){
            case TY_INT: {
                int in = read_int(stdout, in_file, "Insert an integer: ", pretty);
                push_int(in);
                break;
            }
            case TY_CHAR: {
                char in = read_char(stdout, in_file, "Insert a char: ", pretty);
                push_char(in);
                break;
            }
            case TY_REAL: {
                float in = read_real(stdout, in_file, "Insert a number of type real: ", pretty);
                push_real(in);
                break;
            }
            case TY_STRING: {
                char *in = read_string(stdout, in_file, "Insert a string: ", pretty);
                char *strig_to_store = stringtable_store(in, stringtable);
                freemem(in, strlen(in) + 1);
                push_string(strig_to_store);
                break;
            }
            case TY_BOOL: {
                char in = read_char(stdout, in_file, "Insert a boolean (0 or 1): ", pretty);
                push_bool(in == '1');
                break;
            }
            default: {machine_error("Unknown type of schema in input_schema()."); break;}
        }
    }
}
Ejemplo n.º 5
0
void exec(Pystat stat){
    Arg arg0 = stat->args[0];
    Arg arg1 = stat->args[1];
    switch(stat->op){
        case Y_PUSH: {
            exec_push(arg0.ival, pc+1); // num_objects
            break;
        }
        case Y_GOTO: {
            exec_goto(arg0.ival); // absolute line
            break;
        }
        case Y_POP: {
            exec_pop();
            break;
        }
        case Y_NEW: {
            exec_new(arg0.ival); // obj size
            break;
        }
        case Y_NEWS: {
            exec_news(arg0.ival); // obj size
            break;
        }
        case Y_LDC: {
            exec_ldc(arg0.ival);
            break;
        }
        case Y_LDI: {
            exec_ldi(arg0.ival);
            break;
        }
        case Y_LDR: {
            exec_ldr(arg0.rval);
            break;
        }
        case Y_LDS: {
            exec_lds(arg0.sval);
            break;
        }
        case Y_LOD: {
            exec_lod(arg0.ival); // oid
            break;
        }
        case Y_GLOD: {
            exec_glod(arg0.ival); // oid
            break;
        }
        case Y_CAT: {
            exec_cat(arg0.ival, arg1.ival); // num fields, record/array size
            break;
        }
        case Y_LDA: {
            exec_lda(arg0.ival); // oid
            break;
        }
        case Y_GLDA: {
            exec_glda(arg0.ival); // oid
            break;
        }
        case Y_FDA: {
            exec_fda(arg0.ival); // field offset
            break;
        }
        case Y_EIL: {
            exec_eil(arg0.ival); // field size, embedded
            break;
        }
        case Y_SIL: {
            exec_sil(arg0.ival); // field size, on stack
            break;
        }
        case Y_IXA: {
            exec_ixa(arg0.ival); // elem size
            break;
        }
        case Y_STO: {
            exec_sto(arg0.ival); // oid
            break;
        }
        case Y_GSTO: {
            exec_gsto(arg0.ival); // oid
            break;
        }
        case Y_IST: {
            exec_ist(); // indirect store
            break;
        }
        case Y_JMF: {
            exec_jmf(arg0.ival); // offset
            break;
        }
        case Y_JMP: {
            exec_jmp(arg0.ival); // offset
            break;
        }
        case Y_EQU: {
            exec_equ(); // for all types of objects
            break;
        }
        case Y_NEQ: {
            exec_neq(); // for all types of objects
            break;
        }
        case Y_IGT: {
            exec_igt();
            break;
        }
        case Y_IGE: {
            exec_ige();
            break;
        }
        case Y_ILT: {
            exec_ilt();
            break;
        }
        case Y_ILE: {
            exec_ile();
            break;
        }
        case Y_RGT: {
            exec_rgt();
            break;
        }
        case Y_RGE: {
            exec_rge();
            break;
        }
        case Y_RLT: {
            exec_rlt();
            break;
        }
        case Y_RLE: {
            exec_rle();
            break;
        }
        case Y_SGT: {
            exec_sgt();
            break;
        }
        case Y_SGE: {
            exec_sge();
            break;
        }
        case Y_SLT: {
            exec_slt();
            break;
        }
        case Y_SLE: {
            exec_sle();
            break;
        }
        case Y_IPLUS: {
            exec_iplus();
            break;
        }
        case Y_IMINUS: {
            exec_iminus();
            break;
        }
        case Y_ITIMES: {
            exec_itimes();
            break;
        }
        case Y_IDIV: {
            exec_idiv();
            break;
        }
        case Y_RPLUS: {
            exec_rplus();
            break;
        }
        case Y_RMINUS: {
            exec_rminus();
            break;
        }
        case Y_RTIMES: {
            exec_rtimes();
            break;
        }
        case Y_RDIV: {
            exec_rdiv();
            break;
        }
        case Y_IUMI: {
            exec_iumi();
            break;
        }
        case Y_RUMI: {
            exec_rumi();
            break;
        }
        case Y_NEG: {
            exec_neg();
            break;
        }
        case Y_WR: {
            exec_wr(arg0.sval, 1, stdout); // schema
            break;
        }
        case Y_FWR: {
            exec_fwr(arg0.sval); // schema
            break;
        }
        case Y_RD: {
            exec_rd(arg0.sval, 1, stdin); // schema
            break;
        }
        case Y_FRD: {
            exec_frd(arg0.sval); // schema
            break;
        }
        case Y_TOINT: {
            exec_toint();
            break;
        }
        case Y_TOINTUP: {
            exec_tointup();
            break;
        }
        case Y_TOREAL: {
            exec_toreal();
            break;
        }
        case Y_READ: {
            exec_read(arg0.ival, arg1.sval, 1, stdin); // oid, schema
            break;
        }
        case Y_GREAD: {
            exec_gread(arg0.ival, arg1.sval, 1, stdin); // oid, schema
            break;
        }
        case Y_FREAD: {
            exec_fread(arg0.ival, arg1.sval); // oid, schema
            break;
        }
        case Y_GFREAD: {
            exec_gfread(arg0.ival, arg1.sval); // oid, schema
            break;
        }
        case Y_WRITE: {
            exec_write(arg0.sval); // schema
            break;
        }
        case Y_FWRITE: {
            exec_fwrite(arg0.sval); // schema
            break;
        }
        case Y_TDUP: {
            exec_tdup();
            break;
        }
        case Y_TPOP: {
            exec_tpop(arg0.ival); // num objects
            break;
        }
        case Y_MODULE: {
            // nothing to do here, the instruction is useless
            break;
        }
        case Y_RETURN: {
            exec_return();
            break;
        }
        default: {
            machine_error("Unknown instruction.");
            break;
        }
    }
}