Exemple #1
0
static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
                                       const char *e, int tr) {
  lua_State *L = ms->L;
  switch (tr) {
    case LUA_TFUNCTION: {
      int n;
      lua_pushvalue(L, 3);
      n = push_captures(ms, s, e);
      lua_call(L, n, 1);
      break;
    }
    case LUA_TTABLE: {
      push_onecapture(ms, 0, s, e);
      lua_gettable(L, 3);
      break;
    }
    default: {  /* LUA_TNUMBER or LUA_TSTRING */
      add_s(ms, b, s, e);
      return;
    }
  }
  if (!lua_toboolean(L, -1)) {  /* nil or false? */
    lua_pop(L, 1);
    lua_pushlstring(L, s, e - s);  /* keep original text */
  }
  else if (!lua_isstring(L, -1))
    luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1));
  luaL_addvalue(b);  /* add result to accumulator */
}
Exemple #2
0
static int str_gsub (lua_State *L) {
  size_t srcl;
  const char *src = luaL_check_lstr(L, 1, &srcl);
  const char *p = luaL_check_string(L, 2);
  int max_s = luaL_opt_int(L, 4, srcl+1);
  int anchor = (*p == '^') ? (p++, 1) : 0;
  int n = 0;
  struct Capture cap;
  luaL_Buffer b;
  luaL_arg_check(L,
    lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)),
    3, "string or function expected");
  luaL_buffinit(L, &b);
  cap.src_end = src+srcl;
  while (n < max_s) {
    const char *e;
    cap.level = 0;
    e = match(L, src, p, &cap);
    if (e) {
      n++;
      add_s(L, &b, &cap);
    }
    if (e && e>src) /* non empty match? */
      src = e;  /* skip it */
    else if (src < cap.src_end)
      luaL_putchar(&b, *src++);
    else break;
    if (anchor) break;
  }
  luaL_addlstring(&b, src, cap.src_end-src);
  luaL_pushresult(&b);
  lua_pushnumber(L, n);  /* number of substitutions */
  return 2;
}
Exemple #3
0
void dump_processor(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {
	if (hardware->dmi.processor.filled == false) {
		CREATE_NEW_OBJECT;
			add_s("dmi.warning","no processor structure found");
		FLUSH_OBJECT;
		return;
	}

	char voltage[16]={0};
	snprintf(voltage,sizeof(voltage),"%d.%02d",
		hardware->dmi.processor.voltage_mv / 1000,
		hardware->dmi.processor.voltage_mv - ((hardware->dmi.processor.voltage_mv / 1000) * 1000));

	CREATE_NEW_OBJECT;
	add_s("dmi.item","processor");
	add_hs(dmi.processor.socket_designation);
	add_hs(dmi.processor.type);
	add_hs(dmi.processor.family);
	add_hs(dmi.processor.manufacturer);
	add_hs(dmi.processor.version);
	add_hi(dmi.processor.external_clock);
	add_hi(dmi.processor.max_speed);
	add_hi(dmi.processor.current_speed);
	add_hi(dmi.processor.signature.type);
	add_hi(dmi.processor.signature.family);
	add_hi(dmi.processor.signature.model);
	add_hi(dmi.processor.signature.stepping);
	add_hi(dmi.processor.signature.minor_stepping);
	add_s("dmi.processor.voltage",voltage);
	add_hs(dmi.processor.status);
	add_hs(dmi.processor.upgrade);
	add_hs(dmi.processor.cache1);
	add_hs(dmi.processor.cache2);
	add_hs(dmi.processor.cache3);
	add_hs(dmi.processor.serial);
	add_hs(dmi.processor.part_number);
	add_hi(dmi.processor.core_count);
	add_hi(dmi.processor.core_enabled);
	add_hi(dmi.processor.thread_count);
	add_hs(dmi.processor.id);
	for (int i = 0; i < PROCESSOR_FLAGS_ELEMENTS; i++) {
	        if (((bool *) (&hardware->dmi.processor.cpu_flags))[i] == true) {
	            add_s("dmi.processor.flag",(char *)cpu_flags_strings[i]);
		}
	}
	FLUSH_OBJECT;
}
Exemple #4
0
		clock::clock( int days, int hours, int minutes, int seconds, int milliseconds ) {
			m_time = 0;
			add_days( days );
			add_hours( hours );
			add_min( minutes );
			add_s( seconds );
			add_ms( milliseconds );
		}
Exemple #5
0
void dump_88(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {

	(void) hardware;
	int mem_size = 0;
	CREATE_NEW_OBJECT;
	if (detect_memory_88(&mem_size)) {
		add_s("memory.error","8800h memory configuration is invalid");
		FLUSH_OBJECT
		return;
	}
Exemple #6
0
void dump_battery(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {
	if (hardware->dmi.battery.filled == false) {
		CREATE_NEW_OBJECT;
			add_s("dmi.warning","no battery structure found");
		FLUSH_OBJECT;
		return;
	}

	CREATE_NEW_OBJECT;
	add_s("dmi.item","battery");
	add_hs(dmi.battery.manufacturer);
	add_hs(dmi.battery.manufacture_date);
	add_hs(dmi.battery.serial);
	add_hs(dmi.battery.name);
	add_hs(dmi.battery.chemistry);
	add_hs(dmi.battery.design_capacity);
	add_hs(dmi.battery.design_voltage);
	add_hs(dmi.battery.sbds);
	add_hs(dmi.battery.sbds_manufacture_date);
	add_hs(dmi.battery.sbds_chemistry);
	add_hs(dmi.battery.maximum_error);
	add_hs(dmi.battery.oem_info);
	FLUSH_OBJECT;
}
Exemple #7
0
void dump_hdt(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {

	(void) hardware;
	CREATE_NEW_OBJECT;
	add_s("hdt.product_name",PRODUCT_NAME);
	add_s("hdt.version",VERSION);
	add_s("hdt.code_name",CODENAME);
	add_s("hdt.author", AUTHOR);
	add_s("hdt.core_developer", CORE_DEVELOPER);
	char *contributors[NB_CONTRIBUTORS] = CONTRIBUTORS;
	for (int c = 0; c < NB_CONTRIBUTORS; c++) {
		add_s("hdt.contributor", contributors[c]);
	}
	add_s("hdt.website",WEBSITE_URL);
	add_s("hdt.irc_channel",IRC_CHANNEL);
	FLUSH_OBJECT
	to_cpio("hdt");
}
Exemple #8
0
void dump_bios(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {
	if (hardware->dmi.bios.filled == false) {
		CREATE_NEW_OBJECT;
			add_s("dmi.warning","no bios structure found");
		FLUSH_OBJECT;
		return;
	}
	char address[16]={0};
	char runtime[16]={0};
	char rom[16]={0};
	snprintf(address,sizeof(address),"0x%04X0",hardware->dmi.bios.address);
	snprintf(runtime,sizeof(runtime),"%u %s",hardware->dmi.bios.runtime_size, hardware->dmi.bios.runtime_size_unit);
	snprintf(rom,sizeof(rom),"%u %s",hardware->dmi.bios.rom_size, hardware->dmi.bios.rom_size_unit);

	CREATE_NEW_OBJECT;
	add_s("dmi.item","bios");
	add_hs(dmi.bios.vendor);
	add_hs(dmi.bios.version);
	add_hs(dmi.bios.release_date);
	add_hs(dmi.bios.bios_revision);
	add_hs(dmi.bios.firmware_revision);
	add_s("dmi.bios.address",address);
	add_s("dmi.bios.runtime_size",runtime);
	add_s("dmi.bios.rom_size",rom);
	for (int i = 0; i < BIOS_CHAR_NB_ELEMENTS; i++) {
	        if (((bool *) (&hardware->dmi.bios.characteristics))[i] == true) {
			add_s("dmi.bios.characteristics",(char *)bios_charac_strings[i]);
		}
	}
	
	for (int i = 0; i < BIOS_CHAR_X1_NB_ELEMENTS; i++) {
	        if (((bool *) (&hardware->dmi.bios.characteristics_x1))[i] == true) {
			add_s("dmi.bios.characteristics",(char *)bios_charac_x1_strings[i]);
		}
	}

	for (int i = 0; i < BIOS_CHAR_X2_NB_ELEMENTS; i++) {
	        if (((bool *) (&hardware->dmi.bios.characteristics_x2))[i] == true) {
			add_s("dmi.bios.characteristics",(char *)bios_charac_x2_strings[i]);
		}
	}
	FLUSH_OBJECT;
}
Exemple #9
0
static int str_gsub (lua_State *L) {
  size_t srcl;
  const lua_WChar *src = luaL_checklwstring(L, 1, &srcl);
  const lua_WChar *p = luaL_checkwstring(L, 2);
  int max_s = luaL_optint(L, 4, srcl+1);
  int anchor = (*p == '^') ? (p++, 1) : 0;
  int n = 0;
  MatchState ms;
  luaL_Buffer b;
  luaL_argcheck(L,
    lua_gettop(L) >= 3 && (lua_iswstring(L, 3) || lua_isfunction(L, 3)),
    3, "string or function expected");
  luaL_wbuffinit(L, &b);
  ms.L = L;
  ms.src_init = src;
  ms.src_end = src+srcl;
  while (n < max_s) {
    const lua_WChar *e;
    ms.level = 0;
    e = match(&ms, src, p);
    if (e) {
      n++;
      add_s(&ms, &b, src, e);
    }
    if (e && e>src) /* non empty match? */
      src = e;  /* skip it */
    else if (src < ms.src_end)
      luaL_putwchar(&b, *src++);
    else break;
    if (anchor) break;
  }
  luaL_addlwstring(&b, src, ms.src_end-src);
  luaL_pushresult(&b);
  lua_pushnumber(L, n);  /* number of substitutions */
  return 2;
}
static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
                                                       const char *e) {
  lua_State *L = ms->L;
  switch (lua_type(L, 3)) {
    case LUA_TNUMBER:
    case LUA_TSTRING: {
      add_s(ms, b, s, e);
      return;
    }
    case LUA_TFUNCTION: 
	case LUA_TUSERDATA: // User data items are also callable in some circumstances (i.e. LuaInterface static methods)
	{
      int n;
      lua_pushvalue(L, 3);
      n = push_captures(ms, s, e);
      lua_call(L, n, 1);
      break;
    }
    case LUA_TTABLE: {
      push_onecapture(ms, 0, s, e);
      lua_gettable(L, 3);
      break;
    }
    default: {
      luaL_argerror(L, 3, "string/function/table expected"); 
      return;
    }
  }
  if (!lua_toboolean(L, -1)) {  /* nil or false? */
    lua_pop(L, 1);
    lua_pushlstring(L, s, e - s);  /* keep original text */
  }
  else if (!lua_isstring(L, -1))
    luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); 
  luaL_addvalue(b);  /* add result to accumulator */
}
Exemple #11
0
int exe(FILE* program)  //program指向存有待执行程序机器码的文件
{

     char* tmp_instru=(char*)malloc(33*sizeof(char)); //读机器码
     programTail=programHead;
     while(fscanf(program,"%s",tmp_instru)!=EOF)
     {
         instru=0;
         int i=0;
         unsigned j=1;
         for(i=31;i>=0;i--)
         {
            if(tmp_instru[i]=='1')
            {
                instru+=j;
                j*=2;
            }
            else
            {
                j*=2;
            }
         }//将机器码转为unsi
         unsigned char* tmp_R=&instru;
         for(i=0;i<4;i++)
         {
             writeMymemory(programTail+i,tmp_R+i);//装载指令
         }
         programTail+=4;//最后一条指令的下一条指令的地址,用来判断程序是否执行完
     }
     pcShort=programHead;
     pc=pcShort;
     while(pcShort!=programTail)
    {
        instru=0;   //指令寄存器清零
    unsigned char* tmp_R=&instru;
    unsigned short addr=addrToMyAddr(pc);
    int i;
    for(i=0;i<4;i++)
    {
        readMymemory(addr+i,tmp_R+i);//取指令
    }
    unsigned tmp=instru>>26;//得到指令op

    //printf("the op is :  %u\n",tmp);

    unsigned numRs=0,numRt=0,numRd=0,numFs=0,numFt=0,numFd=0,tmp_fuc=0;
    switch(tmp)
    {
    case 0x00000023:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=lw(pc);
        break;
    case 0x0000002B:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=sw(pc);
        break;
    case 0x00000008:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=addi(pc);
        break;
    case 0x00000009:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=addiu(pc);
        break;
    case 0x0000000A:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=slti(pc);
        break;
    case 0x0000000B:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=sltiu(pc);
        break;
    case 0x0000000C:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=andi(pc);
        break;
    case 0x0000000D:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=ori(pc);
        break;
    case 0x0000000E:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=xori(pc);
        break;
    case 0x00000024:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=lbu(pc);
        break;
    case 0x00000020:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=lb(pc);
        break;
    case 0x00000028:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=sb(pc);
        break;
    case 0x0000000F:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=lui(pc);
        break;
    case 0x00000004:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=beq(pc);
        break;
    case 0x00000005:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        //printf("%u,%u,%u,%u\n",numRt,numRs,*RS1,*RS2);
        lig=instru<<16>>16;
       // printf("%u\n",lig);
        pc=bne(pc);
        break;
    case 0x00000006:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=blez(pc);
        break;
    case 0x00000007:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=bgtz(pc);
        break;
    case 0x00000001:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        lig=instru<<16>>16;
        pc=bltz(pc);
        break;
    case 0x00000002:
        pc=j(pc);
        break;
    case 0x00000003:
        pc=jal(pc);
        break;
    case 0x00000000:
        numRs=instru<<6>>27;
        numRt=instru<<11>>27;
        numRd=instru<<16>>27;
        RS1=myRegister+numRt;
        RS2=myRegister+numRs;
        RD=myRegister+numRd;
        tmp_fuc=instru%64;
        switch(tmp_fuc)
        {
        case 32:
            pc=add(pc);
            break;
        case 33:
            pc=addu(pc);
            break;
        case 34:
            pc=sub(pc);
            break;
        case 35:
            pc=subu(pc);
            break;
        case 24:
            pc=mul(pc);
            break;
        case 25:
            pc=mulu(pc);
            break;
        case 26:
            pc=myDiv(pc);
            break;
        case 27:
            pc=divu(pc);
            break;
        case 42:
            pc=slt(pc);
            break;
        case 43:
            pc=sltu(pc);
            break;
        case 36:
            pc=myAnd(pc);
            break;
        case 37:
            pc=myOr(pc);
            break;
        case 39:
            pc=nor(pc);
            break;
        case 40:
            pc=myXor(pc);
            break;
        case 8:
            pc=jr(pc);
            break;
        case 9:
            pc=jalr(pc);
            break;
        case 0:
            pc=nop(pc);
            break;
        case 16:
            pc=mfhi(pc);
            break;
        case 18:
            pc=mflo(pc);
            break;
        default:
            break;
        }
        break;
    case 0x00000010:
        numRt=instru<<11>>27;
        numRd=instru<<16>>27;
        RS1=myRegister+numRt;
        if(numRd==14)
        {
            pc=mfepc(pc);
        }
        else if(numRd==13)
        {
            pc=mfco(pc);
        }
        else return -1;
        break;
    case 0x00000031:
        numRs=instru<<6>>27;
        numFt=instru<<11>>27;
        RS2=myRegister+numRs;
        FS1=myFloatReg+numFt;
        lig=instru<<16>>16;
        pc=lwc1(pc);


            //printf("/********\nL.S %u %u\n****************/\n",numFt,numRs);

        break;
    case 0x0000001F:
        numRs=instru<<6>>27;
        numFt=instru<<11>>27;
        RS2=myRegister+numRs;
        FS1=myFloatReg+numFt;
        lig=instru<<16>>16;
        pc=S_D(pc);


            //printf("/********\nL.D %u %u\n****************/\n",numFt,numRs);

        break;
    case 0x0000001E:
        numRs=instru<<6>>27;
        numFt=instru<<11>>27;
        RS2=myRegister+numRs;
        FS1=myFloatReg+numFt;
        lig=instru<<16>>16;
        //printf("/********\nS.D %u %u\n****************/\n",numFt,numRs);
        pc=S_D(pc);
        break;

    case 0x00000039:
        numRs=instru<<6>>27;
        numFt=instru<<11>>27;
        RS2=myRegister+numRs;
        FS1=myFloatReg+numFt;
        lig=instru<<16>>16;
        //printf("/********\nS.S %u %u\n****************/\n",numFt,numRs);
        pc=swc1(pc);
        break;
    case 0x00000011:
        numFt=instru<<11>>27;
        numFs=instru<<16>>27;
        numFd=instru<<21>>27;
        FS1=myFloatReg+numFt;
        FS2=myFloatReg+numFs;
        FD=myFloatReg+numFd;
        numRs=instru<<6>>27;
        tmp_fuc=instru%64;
        //printf("%u %u\n",tmp_fuc,numRs);
        if(numRs==0)
        {
            switch(tmp_fuc)
            {
            case 0:
                pc=add_s(pc);
                break;
            case 1:
                pc=sub_s(pc);
                break;
            case 2:
                pc=mul_s(pc);
            case 3:
                pc=div_s(pc);
            default:
                break;
            }
        }
        else if(numRs==1)
        {
            switch(tmp_fuc)
            {
            case 0:
                pc=add_d(pc);
                //printf("/****************\nADD.D %u %u %u\n*****************/\n",numFd,numFt,numFs);
                break;
            case 1:
                pc=sub_d(pc);
                break;
            case 2:
                pc=mul_d(pc);
            case 3:
                pc=div_d(pc);
            default:
                break;
            }
        }
        default:break;
    }
    pcShort=pc%0x00010000;
    //printf("%u %u\n",pc,pcShort);
    //printf("%u %u\n",pcShort,programTail);
    }
    return 0;
}
Exemple #12
0
void dump_memory_banks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {

	if (hardware->dmi.memory_count == 0) {
			CREATE_NEW_OBJECT;
				add_s("dmi.warning","No memory bank structure found");
			FLUSH_OBJECT;
			return;
	}

	for (int bank=0; bank<hardware->dmi.memory_count;bank++) {

		if (hardware->dmi.memory[bank].filled == false) {
			char msg[64]={0};
			snprintf(msg,sizeof(msg),"Bank %d doesn't contain any information", bank);

			CREATE_NEW_OBJECT;
				add_s("dmi.warning",msg);
			FLUSH_OBJECT;
			continue;
		}

		CREATE_NEW_OBJECT;
		add_i("Memory Bank", bank);
		add_s("dmi.memory.form_factor", hardware->dmi.memory[bank].form_factor);
		add_s("dmi.memory.type", hardware->dmi.memory[bank].type);
		add_s("dmi.memory.type_detail", hardware->dmi.memory[bank].type_detail);
		add_s("dmi.memory.speed", hardware->dmi.memory[bank].speed);
		add_s("dmi.memory.size", hardware->dmi.memory[bank].size);
		add_s("dmi.memory.device_set", hardware->dmi.memory[bank].device_set);
		add_s("dmi.memory.device_locator", hardware->dmi.memory[bank].device_locator);
		add_s("dmi.memory.bank_locator", hardware->dmi.memory[bank].bank_locator);
		add_s("dmi.memory.total_width", hardware->dmi.memory[bank].total_width);
		add_s("dmi.memory.data_width", hardware->dmi.memory[bank].data_width);
		add_s("dmi.memory.error", hardware->dmi.memory[bank].error);
		add_s("dmi.memory.vendor", hardware->dmi.memory[bank].manufacturer);
		add_s("dmi.memory.serial", hardware->dmi.memory[bank].serial);
		add_s("dmi.memory.asset_tag", hardware->dmi.memory[bank].asset_tag);
		add_s("dmi.memory.part_number", hardware->dmi.memory[bank].part_number);
		FLUSH_OBJECT;
	}
}
Exemple #13
0
static int arx(char *fn) {
  if((arxfd=open(arxfn=fn,O_RDONLY))==-1) {
    (*er_printf)("error (%s): %s\n",arxfn,strerror(errno));
    return 0;
  } else {
    errors=0;
    len_b=read(arxfd,buf,BUFSIZE); i_b=u_bom(buf,len_b);
    prevline=-1; line=1; col=0; rnc=0;
    cc=' '; getsym();
    chk_get(SYM_GRMS); chk_get(SYM_LCUR);
    do {
      if(i_2==len_2) t2s=(int(*)[2])m_stretch(t2s,len_2=i_2*2,i_2,sizeof(int[2]));
      if(chksym(SYM_IDNT)) t2s[i_2][0]=add_s(value);
      getsym();
      chk_get(SYM_ASGN);
      if(chksym(SYM_LTRL)) {
	if(path2abs) {
	  int len=strlen(arxfn)+strlen(value)+1;
	  if(len>len_v) {value=(char*)m_stretch(value,len,len_v,sizeof(char)); len_v=len;}
	  s_abspath(value,arxfn);
	}
	t2s[i_2][1]=add_s(value);
      }
      getsym();
      ++i_2;
    } while(sym==SYM_IDNT);
    chk_get(SYM_RCUR);
    for(;;) {
      if(i_r==len_r) rules=(int(*)[3])m_stretch(rules,len_r=i_r*2,i_r,sizeof(int[3]));
      switch(sym) {
      case SYM_MTCH: rules[i_r][0]=MATCH; goto REGEXP;
      case SYM_NMTC: rules[i_r][0]=NOMAT; goto REGEXP;
      REGEXP: getsym();
	if(chksym(SYM_RGXP)) {
	  if(!rx_check(value)) error(ARX_ER_REX);
	  rules[i_r][1]=add_s(value);
	}
	getsym();
	if(chksym(SYM_IDNT)) rules[i_r][2]=typ2str();
	goto NEXT;
      case SYM_VALD: rules[i_r][0]=VALID; goto RNG;
      case SYM_NVAL: rules[i_r][0]=INVAL; goto RNG;
      RNG: getsym();
	if(chksym(SYM_RENG)) {
	  char *rncfn=(char*)m_alloc(strlen(arxfn)+strlen("#rnc[]")+12,sizeof(char));
	  sprintf(rncfn,"%s#rnc[%i]",arxfn,rnc++);
	  if(!(rules[i_r][1]=rnl_s(rncfn,value,strlen(value)))) error(ARX_ER_RNG);
	  m_free(rncfn);
	}
	getsym();
	if(chksym(SYM_IDNT)) rules[i_r][2]=typ2str();
	goto NEXT;
      default: goto LAST;
      }
      NEXT: ++i_r; getsym();
    }
    LAST: chk_get(SYM_EOF);
    close(arxfd);
    return !errors;
  }
}
Exemple #14
0
static int typ2str(void) {
  int i=i_2,typ=add_s(value);
  t2s[0][0]=typ; for(;;) if(t2s[--i][0]==typ) break;
  if(i==0) error(ARX_ER_TYP,value);
  return t2s[i][1];
}
Exemple #15
0
void ADD_S(void)
{
   if (check_cop1_unusable()) return;
   add_s(reg_cop1_simple[cffs], reg_cop1_simple[cfft], reg_cop1_simple[cffd]);
   PC++;
}
Exemple #16
0
void
location_production()
{
  int where;
  int i, enclosed;
  int terr, encl_terr;
  int has_city;
  float pop_grow = 0.0;
  int pop_limit = 200, pop, dpop = 0;

  loop_loc(where) {
    terr = subkind(where);
    has_city = 0;

    for (i = 0; terr_prod[i].terr; i++)
      if (terr_prod[i].terr == terr) {
        replenish(where, terr_prod[i].item, terr_prod[i].qty,
                  terr_prod[i].max);
      }

    /*
     *  Mon Sep 16 11:42:22 1996 -- Scott Turner
     *
     *  Now check for production from enclosed locations...
     *
     */
    loop_here(where, enclosed) {
      encl_terr = subkind(enclosed);
      if (encl_terr == sub_city)
        has_city = 1;
      for (i = 0; terr_prod2[i].terr; i++)
        if (terr_prod2[i].terr == encl_terr) {
          replenish(where, terr_prod2[i].item, terr_prod2[i].qty,
                    terr_prod2[i].max);
        };
    }
    next_here;

    /*
     *  First limit poppy fields to normal production level.
     *  Then double opium if poppy field was specially tended.
     */
    if (terr == sub_poppy_field) {
      int n;

      n = has_item(where, item_opium);
      if (n > POPPY_OPIUM)
        consume_item(where, item_opium, n - POPPY_OPIUM);

      if (rp_misc(where) && rp_misc(where)->opium_double) {
        rp_misc(where)->opium_double = FALSE;
        gen_item(where, item_opium, has_item(where, item_opium));
      }
    }

    if (terr == sub_island ||
        (loc_depth(where) == LOC_province && has_ocean_access(where)))
      replenish(where, item_flotsam, 30, 30);

    /*
     *  Sun Dec  1 10:34:41 1996 -- Scott Turner
     *
     *  Peasant production.  Depends upon the location (and
     *  whether it contains a city).
     *
     *  Has_city is set up above...
     *
     *  Tue Sep 22 13:20:18 1998 -- Scott Turner
     *
     *  Faery ought not have peasants.  It should have (I guess)
     *  elf peasants, although what you can do with those is
     *  open to conjecture :-)
     *
     */
    if (pop = has_item(where, item_peasant)) {
      if (has_city) {
        pop_grow = 0.03;
        pop_limit = 10000;
      }
      else {
        switch (terr) {
        case sub_plain:
        case sub_forest:
          pop_grow = 0.01;
          pop_limit = 1000;
          break;
        case sub_mountain:
        case sub_swamp:
          pop_grow = 0.005;
          pop_limit = 1000;
          break;
        default:
          pop_grow = 0.000;
          pop_limit = 500;
          break;
        };
      };

      /*
       *  Might be an effect here.
       *
       */
      if (get_effect(where, ef_grow, 0, 0)) {
        wout(where, "The peasants seem particularly happy this month.");
        pop_grow += 0.02;
      };

      dpop = pop * pop_grow;
      if (pop_grow > 0.0 && dpop < 1)
        dpop = 1;
      /*
       *  Lose population at a reasonable rate.
       *
       */
      if (pop > pop_limit)
        dpop = -(pop - pop_limit) / 10;

      if (p_subloc(province(where))->loot && dpop > 0) {
        wout(where,
             "Pillaging traumatizes the population and no growth occurs.");
      }
      else if (dpop > 0) {
        if (pop > 100)
          wout(where, "The population grows by %s peasant%s.",
               nice_num(dpop), add_s(dpop));
        gen_item(where, item_peasant, dpop);
      }
      else {
        if (pop > 100)
          wout(where, "Overcrowding causes %s peasant death%s.",
               nice_num(-dpop), add_s(-dpop));
        consume_item(where, item_peasant, -dpop);
      };
    };

    /*
     *  Sat Apr 18 16:57:53 1998 -- Scott Turner
     *
     *  Special case for gold production from peasants.
     *  They generate 1 gold per 20 peasants (1/10 in cities)
     *  which accumulates to be removed by various means.
     *
     *  Only in civilized (> 100) provinces
     */
    if ((pop = has_item(where, item_peasant)) > 100) {
      if (has_city) {
        dpop = pop * 0.10;
      }
      else {
        dpop = pop * 0.05;
      };
      gen_item(where, item_gold, dpop);
    };
  }