Esempio n. 1
0
static UINT search_sig_name( MSIPACKAGE *package, const WCHAR *sigName, MSISIGNATURE *sig, WCHAR **appValue )
{
    UINT rc;

    *appValue = NULL;
    rc = get_signature( package, sig, sigName );
    if (rc == ERROR_SUCCESS)
    {
        rc = search_components( package, appValue, sig );
        if (rc == ERROR_SUCCESS && !*appValue)
        {
            rc = search_reg( package, appValue, sig );
            if (rc == ERROR_SUCCESS && !*appValue)
            {
                rc = search_ini( package, appValue, sig );
                if (rc == ERROR_SUCCESS && !*appValue)
                    rc = search_dr( package, appValue, sig );
            }
        }
    }
    return rc;
}
Esempio n. 2
0
File: 7a.c Progetto: 7shi/Betelgeuse
int parse_reg(enum Regs *reg, const char *s)
{
    char ch = s[0];
    if ((ch == 'r' || ch == 'R' || ch == 'f' || ch == 'F') && isdigit(s[1])
        && (s[2] == 0 || (isdigit(s[2]) && s[3] == 0)))
    {
        int r = (int)strtoul(s + 1, &dummy, 10);
        if (0 <= r && r <= 31)
        {
            *reg = (enum Regs)r;
            return 1;
        }
    }
    else
    {
        int r = search_reg(s);
        if (r != -1)
        {
            *reg = (enum Regs)r;
            return 1;
        }
    }
    return 0;
}
Esempio n. 3
0
int main()
{

	int start_loc = 0, locctr = 0 , end_loc, program_length = 0, instr_length = 0;
	char program_name[8] = {'\0'}, filename[] = "fig2.5.txt";
	
	FILE *fptr;
	
	char accept[100] = {'\0'};
   	char label[30], opcode[30], operand[30];

	int A = 0, X = 0, L = 0,PC = 0, SW = 0, B = 0, S = 0, T = 0, F = 0;
	int n = 1, i = 1, x = 0, b = 0, p = 0, e = 0, address = 0;

/************************************ pass 1 ****************************************/  	
	if((fptr = fopen(filename, "r")) != NULL)
	{
        //printf("file found\n");
        
        fgets(accept, 30, fptr);
		read(label, opcode, operand, accept);

        if(strcmp(opcode,"START") == 0)
        {
			int k, six = 1, hvalue = 0;
			strcpy(program_name, label);
			if(isHexadecimal(operand) == 1)
			{
				for(k = strlen(operand) - 1, six ; k >= 0 ; k--, six *= 16)
				{
					int temp = (int)operand[k] - 48;
					if(temp > 9)
					{
						temp = 10 + (int)operand[k] - 65;
					}

					hvalue += temp * six;
				}
				start_loc = hvalue;
				locctr = hvalue;
			}
			else
			{
				sscanf(operand, "%d", &start_loc);
				sscanf(operand, "%d", &locctr);
			}
        }
		else
		{
			locctr = 0;
		}

		fgets(accept, 30, fptr);
		read(label, opcode, operand, accept);


        while(!feof(fptr) && strcmp(opcode,"END") != 0)
        {
            if(isComment(accept) == 0) // not a comment
            {
				if(strlen(label) != 0)
				{
					if(inSymbol(label) != -1)
					{
						printf("error, duplicate symbol !!");
						return 0;
					}
					else
					{
						strcpy(SymbolTable[STindex].label, label);
						SymbolTable[STindex++].address = locctr; 
					}
				}

				if(isInstruction(opcode, "FORMAT") != 0)
				{
					if(opcode[0] == '+')
					{
						instr_length = 4;
					}
					else
					{
						instr_length = isInstruction(opcode, "FORMAT");
					}
				}
				else if(strcmp(opcode,"WORD") == 0)
				{
					instr_length = 3;
				}
				else if(strcmp(opcode,"RESW") == 0)
				{
					instr_length = 3 * ctoi(operand, "RESW");
				}
				else if(strcmp(opcode,"RESB") == 0)
				{
					instr_length = ctoi(operand, "RESB");
				}
				else if(strcmp(opcode,"BYTE") == 0)
				{
					instr_length = ctoi(operand, "BYTE");
				}
				else if(strcmp(opcode,"BASE") == 0)
				{
					instr_length = 0;
					int bp = inSymbol(operand);
					B = bp;
				}
				else if(strcmp(opcode,"END") == 0)
				{
					instr_length = 0;
				}
				else
				{
					printf("error, invaild operation code !!");
					return 0;
				}
            }

			locctr += instr_length;
			instr_length = 0;
			fgets(accept, 30, fptr);
			read(label, opcode, operand, accept);
        }

		end_loc = locctr;
		program_length =  end_loc - start_loc;
		fclose(fptr);
    }
    else
    {
        printf("file not found\n");
    }
/************************************ pass 2 ****************************************//*H T E M*/

	locctr = 0;
	instr_length = 0;

	if((fptr = fopen(filename, "r")) != NULL)
	{
        //printf("file found\n");

        fgets(accept, 30, fptr);
		read(label, opcode, operand, accept);

        if(strcmp(opcode,"START") == 0)
        {
			int k, six = 1, hvalue = 0;
			strcpy(program_name, label);
			if(isHexadecimal(operand) == 1)
			{
				for(k = strlen(operand) - 1, six ; k >= 0 ; k--, six *= 16)
				{
					int temp = (int)operand[k] - 48;
					if(temp > 9)
					{
						temp = 10 + (int)operand[k] - 65;
					}

					hvalue += temp * six;
				}
				locctr = hvalue;
			}
			else
			{
				sscanf(operand, "%d", &locctr);
			}
        }
		else
		{
			locctr = 0;
		}

		fgets(accept, 30, fptr);
		read(label, opcode, operand, accept);

		printf("H %-6s %06X %06X\n",program_name, start_loc, program_length);

        while(!feof(fptr) && strcmp(opcode,"END") != 0)
        {
			n = i = 1;
			x = b = p = e = 0;

			char object_code[50] = {'\0'};
            if(isComment(accept) == 0) // not a comment
            {
				if(strcmp(opcode,"WORD") == 0)
				{
					instr_length = 3;
					generate_objcode(object_code, operand, "WORD");
				}
				else if(strcmp(opcode,"RESW") == 0)
				{
					instr_length = 3 * ctoi(operand, "RESW");
				}
				else if(strcmp(opcode,"RESB") == 0)
				{
					instr_length = ctoi(operand, "RESB");
				}
				else if(strcmp(opcode,"BYTE") == 0)
				{
					instr_length = ctoi(operand, "BYTE");
					generate_objcode(object_code, operand, "BYTE");
				}
				else if(strcmp(opcode,"BASE") == 0)
				{
					instr_length = 0;
					noobj = 1;
				}
				else if(strcmp(opcode,"END") == 0)
				{
					instr_length = 0;
					noobj = 1;
				}
				else if(isInstruction(opcode, "FORMAT") != 0)
				{
					if(opcode[0] == '+')
					{			
						char temp[10] = {'\0'};
						strcpy(temp,strtok(operand,"#@"));
						if(inSymbol(temp) != -1)
						{
							Mrecord[Mindex++] = locctr + 1;  
						}

						instr_length = 4;
						e = 1;
						b = p = 0;
					}
					else
					{
						instr_length = isInstruction(opcode, "FORMAT");
					}
				}
				else
				{
					printf("error, invaild operation code !!");
					return 0;
				}
            }
/****************************************************************************************/			
			switch (operand[0])
			{
				case '@':
					n = 1; i = 0;
					break;
				case '#':
					n = 0; i = 1;
					break;
				default:
					n = i = 1;
					if(strstr(operand,",X")!=NULL)
					{
						x = 1;
						strtok(operand,",");
					}
					break;
			}

			if(inSymbol(operand) != -1)
			{
				b = 0; p = 1;
				if(opcode[0] == '+')
				{
					e = 1; b = p = 0;
				}
				address=inSymbol(operand);
			}
			else if(isdigit(operand[1])!=0)
			{
				sscanf(operand + 1,"%d",&address);
			}
			

			if(p == 1)
			{
				address = address - (locctr + instr_length);

				if(address > 2047 || address < -2048)
				{
					b = 1; p = 0;
					address = inSymbol(operand) - B;
				}
			}

			int format = isInstruction(opcode, "FORMAT"), op = isInstruction(opcode, "OPCODE");

			if(strcmp(opcode,"RSUB") == 0)
			{
				b = p = 0;
				address = 0;
			}
						
/******************************************************************************/
			char *head = (char*)malloc(4 * sizeof(char));
			if(format>=3)
			{
				op *= 16;	n *= 32;	i *= 16;	x *= 8;		b *= 4;		p *= 2;
				op += n + i + x + b + p + e;
				sprintf(object_code,"%03X",op);
			}
			else if(format==2)
				sprintf(object_code,"%02X",op);

			if(opcode[0]=='+')
				sprintf(object_code+3,"%05X",address);
			else if(format==3)
			{
				if(address<0)
				{
					sprintf(head,"%3hX",address);
					strcpy(object_code+3,head+1);
				}
				else
					sprintf(object_code+3,"%03X",address);
			}
			else if(format==2)
			{
				sprintf(object_code+2,"%1X",search_reg(operand[0]));
				if(strlen(operand) > 2)
					sprintf(object_code+3,"%1X",search_reg(operand[2]));
				else
					sprintf(object_code+3,"%1X",0);
			}

/*******************************************************************************/

			printf("T %06X %02X %s\n",locctr, strlen(object_code), object_code);

			locctr += instr_length;
			instr_length = 0;

			fgets(accept, 30, fptr);
			read(label, opcode, operand, accept);
        }
		printMrecord();
		printf("E %06X\n",start_loc);
		fclose(fptr);
    }
    else
    {
        printf("file not found\n");
    }

	//system("pause");
	return 0;	
}