예제 #1
0
int main(int argc, char *argv[])
{
	FILE* rom_file;

	unsigned int pc = 0x200;
	unsigned int file_size;

	unsigned char *buffer;

	if((rom_file = fopen(argv[1], "rb")) == NULL)
	{
		printf("[ERROR] - Couldn't open file!\n");
		exit(EXIT_FAILURE);
	}

	fseek(rom_file, 0L, SEEK_END);
	file_size = ftell(rom_file);
	fseek(rom_file, 0L, SEEK_SET);

	buffer = malloc(file_size + pc);
	fread(buffer + pc, file_size, 1, rom_file);
	fclose(rom_file);

	while(pc < (file_size + 0x200))
	{
		print_opcode(buffer, pc);
		pc += 2;
	}

	putchar('\n');

	free(buffer);

	return 0;
}
예제 #2
0
void print_command (unsigned char *command) {
  int i,s;
  print_opcode(command[0]);
  for ( i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i) 
  	printk("%02x ", command[i]);
  printk("\n");
}
예제 #3
0
static void brw_wm_print_fp_insn( struct brw_wm_compile *c,
                                  struct brw_fp_instruction *inst )
{
   GLuint i;
   GLuint nr_args = brw_wm_nr_args(inst->opcode);

   print_opcode(inst->opcode);
   if (inst->dst.saturate)
      debug_printf("_SAT");
   debug_printf(" ");

   if (inst->dst.indirect)
      debug_printf("[");

   debug_printf("%s[%d]",
                file_strings[inst->dst.file],
                inst->dst.index );
   print_writemask(inst->dst.writemask);

   if (inst->dst.indirect)
      debug_printf("]");

   debug_printf(nr_args ? ", " : "\n");
   
   for (i = 0; i < nr_args; i++) {
      debug_printf("%s%s%s[%d]%s",
                   inst->src[i].negate ? "-" : "",
                   inst->src[i].abs ? "ABS(" : "",
                   file_strings[inst->src[i].file],
                   inst->src[i].index,
                   inst->src[i].abs ? ")" : "");
      print_swizzle(inst->src[i].swizzle);
      debug_printf("%s", i == nr_args - 1 ? "\n" : ", ");
   }
}
예제 #4
0
파일: handle.c 프로젝트: aosm/X11apps
void 
print_work_queue(void)
{
    union op *op;

    printf ("! dump of work queue\n");
    for (op = work_queue.head; op; op = op->generic.next) {
	print_opcode (op);
    }
    return;
}
예제 #5
0
t_stat
fprint_sym(FILE * of, t_addr addr, t_value * val, UNIT * uptr, int32 sw)
{
    t_value             inst = *val;
    int                 i;

    fputc(' ', of);
    fprint_val(of, inst, 8, 48, PV_RZRO);

    if (sw & SWMASK('W')) {     /* Word mode opcodes */
        fputs("   ", of);
        for (i = 36; i >= 0; i-=12) {
                int     op = (int)(inst >> i) & 07777;
                print_opcode(of, op, word_ops);
        }
    }
예제 #6
0
파일: handle.c 프로젝트: aosm/X11apps
/*
 * The action routines.
 *
 * This is where the real work gets done.  Each routine is responsible for
 * parsing its input (note that the command keyword has been stripped off)
 * and adding to the work queue.  They are also in charge of outputting
 * error messages and returning non-zero if there is a problem.
 *
 * The following global variables are available:
 *     dpy                the display descriptor
 *     work_queue         linked list of opcodes
 *     inputFilename      name of the file being processed
 *     lineno             line number of current line in input file
 */
static void
add_to_work_queue(union op *p)	/* this can become a macro someday */
{
    if (work_queue.head == NULL) {	/* nothing on the list */
	work_queue.head = work_queue.tail = p;	/* head, tail, no prev */
    } else {
	work_queue.tail->generic.next = p;  /* head okay, prev */
	work_queue.tail = p;		/* tail */
    }
    p->generic.next = NULL;

    if (verbose) {
	print_opcode (p);
    }
    return;
}
예제 #7
0
void brw_wm_print_insn( struct brw_wm_compile *c,
			struct brw_wm_instruction *inst )
{
   GLuint i, arg;
   GLuint nr_args = brw_wm_nr_args(inst->opcode);

   debug_printf("[");
   for (i = 0; i < 4; i++) {
      if (inst->dst[i]) {
	 brw_wm_print_value(c, inst->dst[i]);
	 if (inst->dst[i]->spill_slot)
	    debug_printf("/SPILL(%x)",inst->dst[i]->spill_slot);
      }
      else
	 debug_printf("#");
      if (i < 3)      
	 debug_printf(",");
   }
   debug_printf("]");
   print_writemask(inst->writemask);
   
   debug_printf(" = ");
   print_opcode(inst->opcode);
  
   if (inst->saturate)
      debug_printf("_SAT");

   for (arg = 0; arg < nr_args; arg++) {

      debug_printf(" [");

      for (i = 0; i < 4; i++) {
	 if (inst->src[arg][i]) {
	    brw_wm_print_ref(c, inst->src[arg][i]);
	 }
	 else
	    debug_printf("%%");

	 if (i < 3) 
	    debug_printf(",");
	 else
	    debug_printf("]");
      }
   }
   debug_printf("\n");
}
예제 #8
0
파일: wud.c 프로젝트: carriercomm/Exult
void printcodeseg(FILE* f, unsigned int ds, unsigned int s,
				const char **func_table, int funsize, int extended)
{
	long pos;
	unsigned int size;
	unsigned int externsize;
	unsigned int i;
	unsigned int offset;
	unsigned int nbytes;
	unsigned char* p;
	unsigned char* pp;
	unsigned char* pdata;
	unsigned short* pextern;
	pos = ftell(f);
	if (extended == 0) {
		size = s - ds - sizeof(unsigned short);
	} else {
		size = s - ds - sizeof(unsigned int);
	}

	pp = p = malloc(size);
	pdata = malloc(ds);
	fread(pdata, 1, ds, f);
	printf("\t\t.code\n");
	fread(p, 1, size, f);
	fseek(f, pos, SEEK_SET);
	// Print code segment header
	if( size < 3 * sizeof(unsigned short) )
	{
		printf("Code segment bad!\n");
		free(p);
		free(pdata);
		return;
	}
	// Print argument counter
	printf("\t\t.argc %04XH\n", *(unsigned short*)pp);
	pp += sizeof(unsigned short);
	// Print locals counter
	printf("\t\t.localc %04XH\n", *(unsigned short*)pp);
	pp += sizeof(unsigned short);
	// Print externs section
	externsize = *(unsigned short*)pp;
	printf("\t\t.externsize %04XH\n", externsize);
	pp += sizeof(unsigned short);
	if( size < ( ( 3 + externsize ) * sizeof(unsigned short) ) )
	{
		printf("Code segment bad!\n");
		free(p);
		free(pdata);
		return;
	}
	size -= ( ( 3 + externsize ) * sizeof(unsigned short) );
	pextern = (unsigned short*)pp;
	for( i = 0; i < externsize; i++ )
	{
		printf("\t\t.extern %04XH\n", *(unsigned short*)pp);
		pp += sizeof(unsigned short);
	}
	offset = 0;
	// Print opcodes
	while( offset < size )
	{
		nbytes = print_opcode(pp, offset, pdata, pextern, externsize,
						func_table, funsize);
		pp += nbytes;
		offset += nbytes;
	}
	free(p);
	free(pdata);
}
예제 #9
0
파일: brw_disasm.c 프로젝트: nikai3d/mesa
int brw_disasm (FILE *file, struct brw_instruction *inst, int gen)
{
    int	err = 0;
    int space = 0;

    if (inst->header.predicate_control) {
	string (file, "(");
	err |= control (file, "predicate inverse", pred_inv, inst->header.predicate_inverse, NULL);
	string (file, "f0");
	if (inst->bits2.da1.flag_reg_nr)
	    format (file, ".%d", inst->bits2.da1.flag_reg_nr);
	if (inst->header.access_mode == BRW_ALIGN_1)
	    err |= control (file, "predicate control align1", pred_ctrl_align1,
			    inst->header.predicate_control, NULL);
	else
	    err |= control (file, "predicate control align16", pred_ctrl_align16,
			    inst->header.predicate_control, NULL);
	string (file, ") ");
    }

    err |= print_opcode (file, inst->header.opcode);
    err |= control (file, "saturate", saturate, inst->header.saturate, NULL);
    err |= control (file, "debug control", debug_ctrl, inst->header.debug_control, NULL);

    if (inst->header.opcode == BRW_OPCODE_MATH) {
	string (file, " ");
	err |= control (file, "function", math_function,
			inst->header.destreg__conditionalmod, NULL);
    } else if (inst->header.opcode != BRW_OPCODE_SEND &&
	       inst->header.opcode != BRW_OPCODE_SENDC)
	err |= control (file, "conditional modifier", conditional_modifier,
			inst->header.destreg__conditionalmod, NULL);

    if (inst->header.opcode != BRW_OPCODE_NOP) {
	string (file, "(");
	err |= control (file, "execution size", exec_size, inst->header.execution_size, NULL);
	string (file, ")");
    }

    if (inst->header.opcode == BRW_OPCODE_SEND && gen < 6)
	format (file, " %d", inst->header.destreg__conditionalmod);

    if (opcode[inst->header.opcode].ndst > 0) {
	pad (file, 16);
	err |= dest (file, inst);
    } else if (gen >= 6 && (inst->header.opcode == BRW_OPCODE_IF ||
			    inst->header.opcode == BRW_OPCODE_ELSE ||
			    inst->header.opcode == BRW_OPCODE_ENDIF ||
			    inst->header.opcode == BRW_OPCODE_WHILE)) {
       format (file, " %d", inst->bits1.branch_gen6.jump_count);
    }

    if (opcode[inst->header.opcode].nsrc > 0) {
	pad (file, 32);
	err |= src0 (file, inst);
    }
    if (opcode[inst->header.opcode].nsrc > 1) {
	pad (file, 48);
	err |= src1 (file, inst);
    }

    if (inst->header.opcode == BRW_OPCODE_SEND ||
	inst->header.opcode == BRW_OPCODE_SENDC) {
	int target;

	if (gen >= 6)
	    target = inst->header.destreg__conditionalmod;
	else if (gen == 5)
	    target = inst->bits2.send_gen5.sfid;
	else
	    target = inst->bits3.generic.msg_target;

	newline (file);
	pad (file, 16);
	space = 0;

	if (gen >= 6) {
	   err |= control (file, "target function", target_function_gen6,
			   target, &space);
	} else {
	   err |= control (file, "target function", target_function,
			   target, &space);
	}

	switch (target) {
	case BRW_MESSAGE_TARGET_MATH:
	    err |= control (file, "math function", math_function,
			    inst->bits3.math.function, &space);
	    err |= control (file, "math saturate", math_saturate,
			    inst->bits3.math.saturate, &space);
	    err |= control (file, "math signed", math_signed,
			    inst->bits3.math.int_type, &space);
	    err |= control (file, "math scalar", math_scalar,
			    inst->bits3.math.data_type, &space);
	    err |= control (file, "math precision", math_precision,
			    inst->bits3.math.precision, &space);
	    break;
	case BRW_MESSAGE_TARGET_SAMPLER:
	    if (gen >= 5) {
		format (file, " (%d, %d, %d, %d)",
			inst->bits3.sampler_gen5.binding_table_index,
			inst->bits3.sampler_gen5.sampler,
			inst->bits3.sampler_gen5.msg_type,
			inst->bits3.sampler_gen5.simd_mode);
	    } else if (0 /* FINISHME: is_g4x */) {
		format (file, " (%d, %d)",
			inst->bits3.sampler_g4x.binding_table_index,
			inst->bits3.sampler_g4x.sampler);
	    } else {
		format (file, " (%d, %d, ",
			inst->bits3.sampler.binding_table_index,
			inst->bits3.sampler.sampler);
		err |= control (file, "sampler target format",
				sampler_target_format,
				inst->bits3.sampler.return_format, NULL);
		string (file, ")");
	    }
	    break;
	case BRW_MESSAGE_TARGET_DATAPORT_READ:
	    if (gen >= 6) {
		format (file, " (%d, %d, %d, %d, %d, %d)",
			inst->bits3.gen6_dp.binding_table_index,
			inst->bits3.gen6_dp.msg_control,
			inst->bits3.gen6_dp.msg_type,
			inst->bits3.gen6_dp.send_commit_msg,
			inst->bits3.gen6_dp.msg_length,
			inst->bits3.gen6_dp.response_length);
	    } else if (gen >= 5 /* FINISHME: || is_g4x */) {
		format (file, " (%d, %d, %d)",
			inst->bits3.dp_read_gen5.binding_table_index,
			inst->bits3.dp_read_gen5.msg_control,
			inst->bits3.dp_read_gen5.msg_type);
	    } else {
		format (file, " (%d, %d, %d)",
			inst->bits3.dp_read.binding_table_index,
			inst->bits3.dp_read.msg_control,
			inst->bits3.dp_read.msg_type);
	    }
	    break;

	case BRW_MESSAGE_TARGET_DATAPORT_WRITE:
	    if (gen >= 6) {
		format (file, " (");

		err |= control (file, "DP rc message type",
				dp_rc_msg_type_gen6,
				inst->bits3.gen6_dp.msg_type, &space);

		format (file, ", %d, %d, %d, %d, %d, %d)",
			inst->bits3.gen6_dp.binding_table_index,
			inst->bits3.gen6_dp.msg_control,
			inst->bits3.gen6_dp.msg_type,
			inst->bits3.gen6_dp.send_commit_msg,
			inst->bits3.gen6_dp.msg_length,
			inst->bits3.gen6_dp.response_length);
	    } else {
		format (file, " (%d, %d, %d, %d)",
			inst->bits3.dp_write.binding_table_index,
			(inst->bits3.dp_write.pixel_scoreboard_clear << 3) |
			inst->bits3.dp_write.msg_control,
			inst->bits3.dp_write.msg_type,
			inst->bits3.dp_write.send_commit_msg);
	    }
	    break;

	case BRW_MESSAGE_TARGET_URB:
	    if (gen >= 5) {
		format (file, " %d", inst->bits3.urb_gen5.offset);
	    } else {
		format (file, " %d", inst->bits3.urb.offset);
	    }

	    space = 1;
	    if (gen >= 5) {
		err |= control (file, "urb opcode", urb_opcode,
				inst->bits3.urb_gen5.opcode, &space);
	    }
	    err |= control (file, "urb swizzle", urb_swizzle,
			    inst->bits3.urb.swizzle_control, &space);
	    err |= control (file, "urb allocate", urb_allocate,
			    inst->bits3.urb.allocate, &space);
	    err |= control (file, "urb used", urb_used,
			    inst->bits3.urb.used, &space);
	    err |= control (file, "urb complete", urb_complete,
			    inst->bits3.urb.complete, &space);
	    if (gen >= 5) {
		format (file, " mlen %d, rlen %d\n",
			inst->bits3.urb_gen5.msg_length,
			inst->bits3.urb_gen5.response_length);
	    }
	    break;
	case BRW_MESSAGE_TARGET_THREAD_SPAWNER:
	    break;
	default:
	    format (file, "unsupported target %d", target);
	    break;
	}
	if (space)
	    string (file, " ");
	if (gen >= 5) {
	   format (file, "mlen %d",
		   inst->bits3.generic_gen5.msg_length);
	   format (file, " rlen %d",
		   inst->bits3.generic_gen5.response_length);
	} else {
	   format (file, "mlen %d",
		   inst->bits3.generic.msg_length);
	   format (file, " rlen %d",
		   inst->bits3.generic.response_length);
	}
    }
    pad (file, 64);
    if (inst->header.opcode != BRW_OPCODE_NOP) {
	string (file, "{");
	space = 1;
	err |= control(file, "access mode", access_mode, inst->header.access_mode, &space);
	if (gen >= 6)
	    err |= control (file, "write enable control", wectrl, inst->header.mask_control, &space);
	else
	    err |= control (file, "mask control", mask_ctrl, inst->header.mask_control, &space);
	err |= control (file, "dependency control", dep_ctrl, inst->header.dependency_control, &space);

	if (gen >= 6)
	    err |= qtr_ctrl (file, inst);
	else {
	    if (inst->header.compression_control == BRW_COMPRESSION_COMPRESSED &&
		opcode[inst->header.opcode].ndst > 0 &&
		inst->bits1.da1.dest_reg_file == BRW_MESSAGE_REGISTER_FILE &&
		inst->bits1.da1.dest_reg_nr & (1 << 7)) {
		format (file, " compr4");
	    } else {
		err |= control (file, "compression control", compr_ctrl,
				inst->header.compression_control, &space);
	    }
	}

	err |= control (file, "thread control", thread_ctrl, inst->header.thread_control, &space);
	if (gen >= 6)
	    err |= control (file, "acc write control", accwr, inst->header.acc_wr_control, &space);
	if (inst->header.opcode == BRW_OPCODE_SEND ||
	    inst->header.opcode == BRW_OPCODE_SENDC)
	    err |= control (file, "end of thread", end_of_thread,
			    inst->bits3.generic.end_of_thread, &space);
	if (space)
	    string (file, " ");
	string (file, "}");
    }
    string (file, ";");
    newline (file);
    return err;
}
예제 #10
0
파일: ucdump.c 프로젝트: carriercomm/Exult
void process_code_seg(FILE* f, unsigned short ds, unsigned short s, unsigned char* opcode_buf,
							unsigned char* intrinsic_buf,
							int mute, int count_all_opcodes,
								int count_all_intrinsic)
{
	long pos;
	unsigned short size;
	unsigned short externsize;
	unsigned short i;
	unsigned short offset;
	unsigned short nbytes;
	unsigned char* p;
	unsigned char* pp;
	unsigned char* pdata;
	unsigned short* pextern;
	pos = ftell(f);
	size = s - ds - sizeof(unsigned short);
	pp = p = malloc(size);
	pdata = malloc(ds);
	fread(pdata, 1, ds, f);
	if( !mute )
		printf("Code segment at file offset %08lXH\n", ftell(f));
	fread(p, 1, size, f);
	fseek(f, pos, SEEK_SET);
	/* Print code segment header */
	if( size < 3 * sizeof(unsigned short) )
	{
		printf("Code segment bad!\n");
		free(p);
		free(pdata);
		return;
	}
	/* Print argument counter */
	if( !mute )
		printf("\t\t.argc %04XH\n", *(unsigned short*)pp);
	pp += sizeof(unsigned short);
	/* Print locals counter */ 
	if( !mute )
		printf("\t\t.localc %04XH\n", *(unsigned short*)pp);
	pp += sizeof(unsigned short);
	/* Print externs section */
	externsize = *(unsigned short*)pp;
	if( !mute )
		printf("\t\t.externsize %04XH\n", externsize);
	pp += sizeof(unsigned short);
	if( size < ( ( 3 + externsize ) * sizeof(unsigned short) ) )
	{
		printf("Code segment bad!\n");
		free(p);
		free(pdata);
		return;
	}
	size -= ( ( 3 + externsize ) * sizeof(unsigned short) );
	pextern = (unsigned short*)pp;
	for( i = 0; i < externsize; i++ )
	{
		if( !mute )
			printf("\t\t.extern %04XH\n", *(unsigned short*)pp);
		pp += sizeof(unsigned short);
	}
	offset = 0;
	/* Print opcodes */
	while( offset < size )
	{
		nbytes = print_opcode(pp, offset, pdata, pextern, externsize,
							opcode_buf, intrinsic_buf, mute,
							count_all_opcodes,
							count_all_intrinsic);
		pp += nbytes;
		offset += nbytes;
	}
	free(p);
	free(pdata);
}
예제 #11
0
int brw_disasm (FILE *file, struct brw_instruction *inst)
{
    int	err = 0;
    int space = 0;

    if (inst->header.predicate_control) {
	string (file, "(");
	err |= control (file, "predicate inverse", pred_inv, inst->header.predicate_inverse, NULL);
	string (file, "f0");
	if (inst->bits2.da1.flag_reg_nr)
	    format (file, ".%d", inst->bits2.da1.flag_reg_nr);
	if (inst->header.access_mode == BRW_ALIGN_1)
	    err |= control (file, "predicate control align1", pred_ctrl_align1,
			    inst->header.predicate_control, NULL);
	else
	    err |= control (file, "predicate control align16", pred_ctrl_align16,
			    inst->header.predicate_control, NULL);
	string (file, ") ");
    }

    err |= print_opcode (file, inst->header.opcode);
    err |= control (file, "saturate", saturate, inst->header.saturate, NULL);
    err |= control (file, "debug control", debug_ctrl, inst->header.debug_control, NULL);

    if (inst->header.opcode != BRW_OPCODE_SEND)
	err |= control (file, "conditional modifier", conditional_modifier,
			inst->header.destreg__conditionalmod, NULL);

    if (inst->header.opcode != BRW_OPCODE_NOP) {
	string (file, "(");
	err |= control (file, "execution size", exec_size, inst->header.execution_size, NULL);
	string (file, ")");
    }

    if (inst->header.opcode == BRW_OPCODE_SEND)
	format (file, " %d", inst->header.destreg__conditionalmod);

    if (opcode[inst->header.opcode].ndst > 0) {
	pad (file, 16);
	err |= dest (file, inst);
    }
    if (opcode[inst->header.opcode].nsrc > 0) {
	pad (file, 32);
	err |= src0 (file, inst);
    }
    if (opcode[inst->header.opcode].nsrc > 1) {
	pad (file, 48);
	err |= src1 (file, inst);
    }

    if (inst->header.opcode == BRW_OPCODE_SEND) {
	newline (file);
	pad (file, 16);
	space = 0;
	err |= control (file, "target function", target_function,
			inst->bits3.generic.msg_target, &space);
	switch (inst->bits3.generic.msg_target) {
	case BRW_MESSAGE_TARGET_MATH:
	    err |= control (file, "math function", math_function,
			    inst->bits3.math.function, &space);
	    err |= control (file, "math saturate", math_saturate,
			    inst->bits3.math.saturate, &space);
	    err |= control (file, "math signed", math_signed,
			    inst->bits3.math.int_type, &space);
	    err |= control (file, "math scalar", math_scalar,
			    inst->bits3.math.data_type, &space);
	    err |= control (file, "math precision", math_precision,
			    inst->bits3.math.precision, &space);
	    break;
	case BRW_MESSAGE_TARGET_SAMPLER:
	    format (file, " (%d, %d, ",
		    inst->bits3.sampler.binding_table_index,
		    inst->bits3.sampler.sampler);
	    err |= control (file, "sampler target format", sampler_target_format,
			    inst->bits3.sampler.return_format, NULL);
	    string (file, ")");
	    break;
	case BRW_MESSAGE_TARGET_DATAPORT_WRITE:
	    format (file, " (%d, %d, %d, %d)",
		    inst->bits3.dp_write.binding_table_index,
		    (inst->bits3.dp_write.pixel_scoreboard_clear << 3) |
		    inst->bits3.dp_write.msg_control,
		    inst->bits3.dp_write.msg_type,
		    inst->bits3.dp_write.send_commit_msg);
	    break;
	case BRW_MESSAGE_TARGET_URB:
	    format (file, " %d", inst->bits3.urb.offset);
	    space = 1;
	    err |= control (file, "urb swizzle", urb_swizzle,
			    inst->bits3.urb.swizzle_control, &space);
	    err |= control (file, "urb allocate", urb_allocate,
			    inst->bits3.urb.allocate, &space);
	    err |= control (file, "urb used", urb_used,
			    inst->bits3.urb.used, &space);
	    err |= control (file, "urb complete", urb_complete,
			    inst->bits3.urb.complete, &space);
	    break;
	case BRW_MESSAGE_TARGET_THREAD_SPAWNER:
	    break;
	default:
	    format (file, "unsupported target %d", inst->bits3.generic.msg_target);
	    break;
	}
	if (space)
	    string (file, " ");
	format (file, "mlen %d",
		inst->bits3.generic.msg_length);
	format (file, " rlen %d",
		inst->bits3.generic.response_length);
    }
    pad (file, 64);
    if (inst->header.opcode != BRW_OPCODE_NOP) {
	string (file, "{");
	space = 1;
	err |= control(file, "access mode", access_mode, inst->header.access_mode, &space);
	err |= control (file, "mask control", mask_ctrl, inst->header.mask_control, &space);
	err |= control (file, "dependency control", dep_ctrl, inst->header.dependency_control, &space);
	err |= control (file, "compression control", compr_ctrl, inst->header.compression_control, &space);
	err |= control (file, "thread control", thread_ctrl, inst->header.thread_control, &space);
	if (inst->header.opcode == BRW_OPCODE_SEND)
	    err |= control (file, "end of thread", end_of_thread,
			    inst->bits3.generic.end_of_thread, &space);
	if (space)
	    string (file, " ");
	string (file, "}");
    }
    string (file, ";");
    newline (file);
    return err;
}
예제 #12
0
파일: handle.c 프로젝트: aosm/X11apps
int 
execute_work_queue (void)
{
    union op *op;
    int errors;
    Bool update_map = False;
    int dosync;

    if (verbose) {
	printf ("!\n");
	printf ("! executing work queue\n");
	printf ("!\n");
    }

    errors = 0;
    dosync = 0;

    for (op = work_queue.head; op; op = op->generic.next) {
	if (verbose) print_opcode (op);

	/* check to see if we have to update the keyboard mapping */
	if (dosync &&
	    (dosync < 0 ||
	     op->generic.type != doKeycode ||
	     !op->keycode.target_keycode)) {
	    XSync (dpy, 0);
	    while (XEventsQueued (dpy, QueuedAlready) > 0) {
		XEvent event;
		XNextEvent (dpy, &event);
		if (event.type == MappingNotify) {
		    /* read all MappingNotify events */
		    while (XCheckTypedEvent (dpy, MappingNotify, &event)) ;
		    XRefreshKeyboardMapping (&event.xmapping);
		} else {
		    fprintf (stderr, "%s:  unknown event %ld\n", 
		    	     ProgramName, (long) event.type);
		}
	    }
	}
	dosync = 0;
	switch (op->generic.type) {
	  case doKeycode:
	    if (exec_keycode (&op->keycode) < 0) errors++;
	    if (op->keycode.target_keycode)
		dosync = 1;
	    else
		dosync = -1;
	    break;
	  case doAddModifier:
	    if (exec_add (&op->addmodifier) < 0) errors++;
	    else update_map = True;
	    break;
	  case doRemoveModifier:
	    if (exec_remove (&op->removemodifier) < 0) errors++;
	    else update_map = True;
	    break;
	  case doClearModifier:
	    if (exec_clear (&op->clearmodifier) < 0) errors++;
	    else update_map = True;
	    break;
	  case doPointer:
	    if (exec_pointer (&op->pointer) < 0) errors++;
	    break;
	  default:
	    fprintf (stderr, "%s:  unknown opcode %d\n", 
		     ProgramName, op->generic.type);
	    break;
	}
    }

    if (update_map) {
	if (UpdateModifierMapping (map) < 0) errors++;
    }

    return (errors > 0 ? -1 : 0);
}