예제 #1
0
void exec_fread(int oid, char* format){
    Odescr *specifier = pop_tstack();
    FILE *in_file = fopen(specifier->inst.sval, "r");
    if(in_file == NULL){
        machine_error("Could not open input file.");
    }
    exec_read(oid, format, 0, in_file);
    free_odescr(specifier);
    fclose(in_file);
}
예제 #2
0
void
show_photos(const struct user_attribute *attrs,
	    int count,PKT_public_key *pk,PKT_secret_key *sk,
	    PKT_user_id *uid)
{
#ifndef DISABLE_PHOTO_VIEWER
  int i;
  struct expando_args args;
  u32 len;
  u32 kid[2]={0,0};

  memset(&args,0,sizeof(args));
  args.pk=pk;
  args.sk=sk;
  args.validity_info=get_validity_info(pk,uid);
  args.validity_string=get_validity_string(pk,uid);

  if(pk)
    keyid_from_pk(pk,kid);
  else if(sk)
    keyid_from_sk(sk,kid);

  for(i=0;i<count;i++)
    if(attrs[i].type==ATTRIB_IMAGE &&
       parse_image_header(&attrs[i],&args.imagetype,&len))
      {
	char *command,*name;
	struct exec_info *spawn;
	int offset=attrs[i].len-len;

#ifdef FIXED_PHOTO_VIEWER
	opt.photo_viewer=FIXED_PHOTO_VIEWER;
#else
	if(!opt.photo_viewer)
	  opt.photo_viewer=get_default_photo_command();
#endif

	/* make command grow */
	command=pct_expando(opt.photo_viewer,&args);
	if(!command)
	  goto fail;

	name=xmalloc(16+strlen(EXTSEP_S)+
		     strlen(image_type_to_string(args.imagetype,0))+1);

	/* Make the filename.  Notice we are not using the image
           encoding type for more than cosmetics.  Most external image
           viewers can handle a multitude of types, and even if one
           cannot understand a particular type, we have no way to know
           which.  The spec permits this, by the way. -dms */

#ifdef USE_ONLY_8DOT3
	sprintf(name,"%08lX" EXTSEP_S "%s",(ulong)kid[1],
		image_type_to_string(args.imagetype,0));
#else
	sprintf(name,"%08lX%08lX" EXTSEP_S "%s",(ulong)kid[0],(ulong)kid[1],
		image_type_to_string(args.imagetype,0));
#endif

	if(exec_write(&spawn,NULL,command,name,1,1)!=0)
	  {
	    xfree(name);
	    goto fail;
	  }

#ifdef __riscos__
        riscos_set_filetype_by_mimetype(spawn->tempfile_in,
                                        image_type_to_string(args.imagetype,2));
#endif

	xfree(name);

	fwrite(&attrs[i].data[offset],attrs[i].len-offset,1,spawn->tochild);

	if(exec_read(spawn)!=0)
	  {
	    exec_finish(spawn);
	    goto fail;
	  }

	if(exec_finish(spawn)!=0)
	  goto fail;
      }

  return;

 fail:
  log_error(_("unable to display photo ID!\n"));
#endif
}
예제 #3
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;
        }
    }
}
예제 #4
0
파일: volstd.c 프로젝트: kobara/siso
void *volstd_exec(void *arg)
{
    struct volume *vol;
    struct volume_standard *volstd;
    struct volume_cmd *cmd = NULL;
    
    vol = (struct volume *)arg;

    ASSERT(vol != NULL, "vol == NULL\n");
    ASSERT(vol->type == VOLTYPE_STANDARD,
	   "vol->type(%d) != VOLTYPE_STANDARD(%d)\n",
	   vol->type, VOLTYPE_STANDARD);
    volstd = (struct volume_standard *)vol->ext;

    log_dbg3("lock\n");
    LOCK_LIST_CMD(vol);
    {
loop:
	cmd = vol_dequeue_cmd(vol);
	log_dbg3("cmd=%p\n", cmd);
	if (cmd == NULL) {
	    log_dbg3("sleep...\n");
	    // wait for enqueue notification
	    pthread_cond_wait(&(volstd->cond_cmdq), &(vol->lock_list_cmd));
	    // dequeue
	    log_dbg3("wakeup.\n");
	    goto loop;
	}
    }
    UNLOCK_LIST_CMD(vol);
    log_dbg3("unlock\n");

#ifdef __DEBUG
    vol_dump_cmd(cmd);
#endif // __DEBUG

    int rv = 0;

    vol_record_start_time(vol, cmd);

    switch (cmd->opcode) {
    case VOLUME_OP_READ:
	rv = exec_read(volstd, cmd);
	break;
    case VOLUME_OP_WRITE:
	rv = exec_write(volstd, cmd);
	break;
    default:
	ASSERT(0, "NOT IMPLEMENTED YET\n");
	abort();
    }

    vol_record_finish_time(vol, cmd);

    vol_dump_iotrace(vol, cmd);

    if (rv) {
	goto failure;
    }

    rv = vol_send_cmd_completion(cmd, VOLCMD_RESULT_SUCCESS);
    if (rv) {
	goto failure;
    }

    goto loop;

failure:
    return NULL;
} // volstd_exec
예제 #5
0
파일: fl.c 프로젝트: pavel-krush/fl
void do_command(const char *command_line) {
	skip_spaces(&command_line);

	char *command = parse_word(&command_line);
	if (command == NULL)
		return;

	skip_spaces(&command_line);

	int command_length = strlen(command);

	#define CMD_COND1(str) ( ( command_length == sizeof(str) - 1 && !strcmp(command, str) ) )
	#define CMD_COND2(str) ( ( command_length == 1 && command[0] == str[0] ) || ( ( command_length == sizeof(str) - 1 ) && !strcmp(command, str) ) )

	#define  PARSE_ID(fail_label) int *id; id = parse_int(&command_line); \
		if (!id) { printf("ID required\n"); goto fail_label; } \
		if (*id < 0 || *id >= files_count) { printf("Invalid ID. Valid values are from %d to %d\n", 0, files_count); goto fail_label; }

	if (CMD_COND2("help")) {
		exec_help();
	}
	else if (CMD_COND2("info")) {
		exec_info();
	}
	// open ID mode
	else if (CMD_COND2("open")) {
		char *mode = NULL;
		PARSE_ID(open_cleanup)

		skip_spaces(&command_line);

		mode = parse_until_space(&command_line);
		if (!mode) {
			printf("MODE required\n");
			goto open_cleanup;
		}

		exec_open(*id, mode);

		open_cleanup:
			if (id) free(id);
			if (mode) free(mode);
			goto cleanup;
	}
	else if (CMD_COND2("lock")) {
		char *operation = NULL;

		PARSE_ID(lock_cleanup)

		skip_spaces(&command_line);

		operation = parse_until_space(&command_line);
		if (!operation) {
			printf("Operation required\n");
			goto lock_cleanup;
		}

		int op;

		if (!strcmp(operation, "shnb"))
			op = LOCK_SH | LOCK_NB;
		else if (!strcmp(operation, "sh"))
			op = LOCK_SH;
		else if (!strcmp(operation ,"exnb"))
			op = LOCK_EX | LOCK_NB;
		else if (!strcmp(operation, "ex"))
			op = LOCK_EX;
		else if (!strcmp(operation, "unnb"))
			op = LOCK_UN | LOCK_NB;
		else if (!strcmp(operation, "un"))
			op = LOCK_UN;
		else {
			printf("Invalid <operation>\n");
			goto lock_cleanup;
		}

		exec_lock(*id, op);

		lock_cleanup:
			if (id) free(id);
			if (operation) free(operation);
			goto cleanup;
	}
	else if (CMD_COND2("close")) {
		PARSE_ID(close_cleaup)

		exec_close(*id);

		close_cleaup:
			if (id) free(id);
			goto cleanup;
	}
	else if (CMD_COND2("seek")) {
		int *offset = NULL;
		char *whence_str = NULL;

		PARSE_ID(seek_cleanup)

		skip_spaces(&command_line);

		int sign = 1;
		if (command_line[0] == '-') {
			sign = -1;
			command_line++;
		}

		offset = parse_int(&command_line);
		if (!offset) {
			printf("Invalid <offset>\n");
			goto seek_cleanup;
		}
		*offset = *offset * sign;

		skip_spaces(&command_line);

		whence_str = parse_until_space(&command_line);
		if (!whence_str) {
			printf("Invalid <whence>. Valid values are: set, end, cur\n");
			goto seek_cleanup;
		}

		int whence = 0;

		if (!strcmp(whence_str, "set")) {
			whence = SEEK_SET;
		}
		else if (!strcmp(whence_str, "end")) {
			whence = SEEK_END;
		}
		else if (!strcmp(whence_str, "cur")) {
			whence = SEEK_CUR;
		}

		exec_seek(*id, *offset, whence);

		seek_cleanup:
			if (id) free(id);
			if (offset) free(offset);
			if (whence_str) free(whence_str);
			goto cleanup;
	}
	else if (CMD_COND2("tell")) {
		PARSE_ID(tell_cleanup)

		skip_spaces(&command_line);

		exec_tell(*id);

		tell_cleanup:
			if (id) free(id);
			goto cleanup;
	}
	else if (CMD_COND2("write")) {
		printf("not implemented\n");
		goto write_cleanup;
		write_cleanup:
			goto cleanup;
	}
	else if (CMD_COND2("read")) {
		int *length = NULL;
		PARSE_ID(read_cleanup);

		skip_spaces(&command_line);

		int hex = 0;

		if (command_line[0] == 'x') {
			hex = 1;
			command_line++;
			skip_spaces(&command_line);
		}

		length = parse_int(&command_line);
		if (!length) {
			printf("Invalid <length>\n");
			goto read_cleanup;
		}

		exec_read(*id, *length, hex);

		read_cleanup:
			if (id) free(id);
			if (length) free(length);
			goto cleanup;
	}
	else if (CMD_COND1("truncate")) {
		int *length = NULL;
		PARSE_ID(truncate_cleanup)

		skip_spaces(&command_line);

		length = parse_int(&command_line);
		if (!length) {
			printf("Invalid <length>\n");
			goto truncate_cleanup;
		}

		exec_truncate(*id, *length);

		truncate_cleanup:
			if (id) free(id);
			if (length) free(length);
			goto cleanup;
	}
	else {
		printf("Unknown command\n");
	}

cleanup:
	free(command);
}
예제 #6
0
int exec_command(int fd, LPS331AP_COMMAND cmd, uint8_t write_val, uint32_t *read_val)
{
    uint8_t buf[2];
    uint32_t value;

    memset(buf, 0, sizeof(buf));

    switch (cmd) {
    case CMD_WHO_AM_I:
        exec_read(fd, REG_WHO_AM_I, buf, ARRAY_SIZE_OF(buf));
        if (buf[0] != 0xBB) {
            fprintf(stderr, "ERROR: invalid value\n");
            exit(EXIT_FAILURE);
        }
        break;
    case CMD_CTRL1:
        exec_write(fd, REG_CTRL_REG1, write_val);
        break;
    case CMD_CTRL2:
        exec_write(fd, REG_CTRL_REG2, write_val);
        break;
    case CMD_WAIT_BOTH:
        for (uint8_t i = 0; i < WAIT_COUNT; i++) {
            exec_read(fd, REG_STATUS, buf, ARRAY_SIZE_OF(buf));
            if ((buf[0] & 0x3) == 0x3) {
                break;
            }
            usleep(100000); // wait 100ms
        }
        if ((buf[0] & 0x3) != 0x3) {
            fprintf(stderr, "ERROR: data not ready\n");
            // something is wrong, so power down
            exec_write(fd, REG_CTRL_REG1, PD_DOWN);
            exit(EXIT_FAILURE);
        }
        break;
    case CMD_PRESS_OUT:
        value = 0;
        exec_read(fd, REG_PRESS_OUT_XL, buf, ARRAY_SIZE_OF(buf));
        value = buf[0] << 0 | value;
        exec_read(fd, REG_PRESS_OUT_L, buf, ARRAY_SIZE_OF(buf));
        value = buf[0] << 8 | value;
        exec_read(fd, REG_PRESS_OUT_H, buf, ARRAY_SIZE_OF(buf));
        value = buf[0] << 16 | value;
        *read_val = value;
        break;
    case CMD_TEMP_OUT:
        value = 0;
        exec_read(fd, REG_TEMP_OUT_L, buf, ARRAY_SIZE_OF(buf));
        value = buf[0] << 0 | value;
        exec_read(fd, REG_TEMP_OUT_H, buf, ARRAY_SIZE_OF(buf));
        value = buf[0] << 8 | value;
        *read_val = value;
        break;
    }


    usleep(10000); // wait 10ms

    return 0;
}