/* is_get: get first value from the if-stack */ BOOL is_get( VOID ) { BOOL value = FALSE; if ( IF_stack ) { STRPTR stkstr = estr2str( IF_stack ); DIF( fprintf( stderr, "** get IF-stack: \"%s\"\n", stkstr ) ); if ( stkstr && (stkstr[0]) ) { char lastch = stkstr[strlen(stkstr)-1]; if ( lastch == ISTK_TRUE ) value = TRUE; else if ( lastch != ISTK_FALSE ) DIF( panic( "Illegal value on IF_stack" ) ); } else DIF( panic( "IF_stack EMPTY" ) ); } else DIF( panic( "IF_stack UNDEFINED" ) ); DIF( fprintf( stderr, "** get IF-stack: value=%d\n", value ) ); return( value ); }
/* is_pop: remove first value of the if-stack */ BOOL is_pop( VOID ) { BOOL value = is_get(); if ( !strlen(estr2str(IF_stack)) ) DIF( panic( "Popping empty IF_stack" ) ); if ( !get_left_estr( IF_stack, IF_stack, strlen(estr2str(IF_stack))-1 ) ) err_mem( NULL ); DIF( fprintf( stderr, "** pop IF-stack: \"%s\"\n", estr2str( IF_stack ) ) ); return( value ); }
/* ** remove_cif_tag ** ** remove </$IF> from closing tag stack */ VOID remove_cif_tag( INFILE *inpf ) { HSCTAG ciftag; /* artificial if-tag to remove */ ciftag.name = HSC_IF_STR; remove_ctag( &ciftag, inpf ); /* remove closing tag from stack */ DIF( fprintf( stderr, "** </$IF> removed\n" ) ); }
DIF _do(istream& is){ string a,b,c; getline(is,a); getline(is,b); getline(is,c); return DIF(a,b,c); }
static inline int atoi5( char *s, int l ) { int v=0; switch(l){ case 0: return 0; case 1: return DIF(0); case 2: SWSW(s[0],10); v+=DIF(1); return v; case 3: SWSW(s[0],100); SWSW(s[1],10); v+=DIF(2); return v; case 4: SWSW(s[0],1000); SWSW(s[1],100); SWSW(s[2],10); v+=DIF(3); return v; case 5: SWSW(s[0],10000);SWSW(s[1],1000); SWSW(s[2],100); SWSW(s[3],10); v+=DIF(4); return v; } }
/* is_push: add a new value to the if-stack */ VOID is_push( BOOL value ) { BYTE ch; if ( value ) ch = ISTK_TRUE; else ch = ISTK_FALSE; if ( !app_estrch( IF_stack, ch ) ) err_mem( NULL ); DIF( fprintf( stderr, "** push IF-stack: \"%s\"\n", estr2str( IF_stack ) ) ); }
/* ** skip_if ** ** skip text, until <$/IF> or <$ELSE> is found ** also handle recursive IFs ** ** params: inpf..input file ** result: IFST_CIF, if exited with </$IF>, ** IFST_ELSE, if exited with </$ELSE> ** errors: call err_eof(), if end-of-file, ** return IFST_ERR */ BYTE skip_if( INFILE *inpf ) { BOOL quit = FALSE; /* TRUE, if end-of-if found */ STRPTR nw = NULL; /* word read from input */ BYTE state = IFST_TEXT; /* current state */ LONG if_nest = 0; /* counter for $IF nesting */ do { if ( state != IFST_TAG ) nw = infgetw( inpf ); if ( nw ) { if ( state == IFST_TAG ) { /* ** skip inside tags */ BYTE tag_state = TGST_TAG; /* state var passe to */ /* eot_reached() */ do { if ( eot_reached( inpf, &tag_state ) ); state = IFST_TEXT; } while ( (tag_state!=TGST_END) && !fatal_error ); } else { /* ** NOTE: I know that this section could be ** shorter, but it would also make the ** source less readable */ /* ** evaluate next state depending on ** previous state */ switch ( state ) { case IFST_TEXT: if ( !strcmp( nw, "<" ) ) state = IFST_LT; break; case IFST_LT: if ( !strcmp( nw, "$" ) ) state = IFST_HSC; else if ( !strcmp( nw, "/" ) ) state = IFST_SLASH; else if ( !upstrcmp( nw, HSC_COMMENT_STR ) ) { skip_hsc_comment( inpf ); state = IFST_TEXT; } else state = IFST_TAG; break; case IFST_HSC: if ( !upstrcmp( nw, "ELSE" ) ) state = IFST_ELSE; else if ( !upstrcmp( nw, "IF" ) ) state = IFST_IF; else state = IFST_TAG; break; case IFST_SLASH: if ( !strcmp( nw, "$" ) ) state = IFST_SLHSC; else state = IFST_TAG; break; case IFST_SLHSC: if ( !upstrcmp( nw, "IF" ) ) state = IFST_CIF; else state = IFST_TAG; break; } /* ** handle special states */ switch ( state ) { case IFST_IF: state = IFST_TAG; if_nest++; DIF( fprintf( stderr, "** skip <$IF> (%d)\n", if_nest ) ); break; case IFST_ELSE: if ( if_nest ) { state = IFST_TAG; DIF( fprintf( stderr, "** skip <$ELSE> (%d)\n", if_nest ) ); } else { /* TODO: check for 2nd <$ELSE> */ quit = TRUE; } break; case IFST_CIF: if ( if_nest ) { state = IFST_TAG; if_nest--; DIF( fprintf( stderr, "** skip </$IF> (%d)\n", if_nest+1 ) ); } else quit = TRUE; break; } } } else { err_eof( inpf, "missing </" HSC_IF_STR ">" ); state = IFST_ERR; } } while ( !quit && nw ); /* check for legal end state */ if ( (state == IFST_CIF) || (state == IFST_ELSE) ) { #if 0 /* remove closing if-tag from stack */ if ( state == IFST_CIF ) { remove_cif_tag( inpf ); is_pop(); } #endif if ( !parse_wd( inpf, ">" ) ) skip_until_eot( inpf ); DIF( { if ( state==IFST_CIF ) fprintf( stderr, "** </$IF> reached\n" ); else fprintf( stderr, "** <$ELSE> reached\n" ); } ); }
void umass_scsi_cmd(struct scsi_xfer *xs) { struct scsi_link *sc_link = xs->sc_link; struct umass_softc *sc = sc_link->adapter_softc; struct scsi_generic *cmd; int cmdlen, dir; #ifdef UMASS_DEBUG microtime(&sc->tv); #endif DIF(UDMASS_UPPER, sc_link->flags |= SCSIDEBUG_LEVEL); DPRINTF(UDMASS_CMD, ("%s: umass_scsi_cmd: at %lld.%06ld: %d:%d " "xs=%p cmd=0x%02x datalen=%d (quirks=0x%x, poll=%d)\n", sc->sc_dev.dv_xname, (long long)sc->tv.tv_sec, sc->tv.tv_usec, sc_link->target, sc_link->lun, xs, xs->cmd->opcode, xs->datalen, sc_link->quirks, xs->flags & SCSI_POLL)); if (usbd_is_dying(sc->sc_udev)) { xs->error = XS_DRIVER_STUFFUP; goto done; } #if defined(UMASS_DEBUG) if (sc_link->target != UMASS_SCSIID_DEVICE) { DPRINTF(UDMASS_SCSI, ("%s: wrong SCSI ID %d\n", sc->sc_dev.dv_xname, sc_link->target)); xs->error = XS_DRIVER_STUFFUP; goto done; } #endif cmd = xs->cmd; cmdlen = xs->cmdlen; dir = DIR_NONE; if (xs->datalen) { switch (xs->flags & (SCSI_DATA_IN | SCSI_DATA_OUT)) { case SCSI_DATA_IN: dir = DIR_IN; break; case SCSI_DATA_OUT: dir = DIR_OUT; break; } } if (xs->datalen > UMASS_MAX_TRANSFER_SIZE) { printf("umass_cmd: large datalen, %d\n", xs->datalen); xs->error = XS_DRIVER_STUFFUP; goto done; } if (xs->flags & SCSI_POLL) { DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: sync dir=%d\n", dir)); usbd_set_polling(sc->sc_udev, 1); sc->sc_xfer_flags = USBD_SYNCHRONOUS; sc->polled_xfer_status = USBD_INVAL; sc->sc_methods->wire_xfer(sc, sc_link->lun, cmd, cmdlen, xs->data, xs->datalen, dir, xs->timeout, umass_scsi_cb, xs); sc->sc_xfer_flags = 0; DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: done err=%d\n", sc->polled_xfer_status)); usbd_set_polling(sc->sc_udev, 0); /* scsi_done() has already been called. */ return; } else { DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: async dir=%d, cmdlen=%d" " datalen=%d\n", dir, cmdlen, xs->datalen)); sc->sc_methods->wire_xfer(sc, sc_link->lun, cmd, cmdlen, xs->data, xs->datalen, dir, xs->timeout, umass_scsi_cb, xs); /* scsi_done() has already been called. */ return; } /* Return if command finishes early. */ done: scsi_done(xs); }
Static void umass_atapi_probe_device(struct atapibus_softc *atapi, int target) { struct scsipi_channel *chan = atapi->sc_channel; struct scsipi_periph *periph; struct scsipibus_attach_args sa; char vendor[33], product[65], revision[17]; struct scsipi_inquiry_data inqbuf; DPRINTF(UDMASS_SCSI,("umass_atapi_probe_device: atapi=%p target=%d\n", atapi, target)); if (target != UMASS_ATAPI_DRIVE) /* only probe drive 0 */ return; KERNEL_LOCK(1, curlwp); /* skip if already attached */ if (scsipi_lookup_periph(chan, target, 0) != NULL) { KERNEL_UNLOCK_ONE(curlwp); return; } periph = scsipi_alloc_periph(M_NOWAIT); if (periph == NULL) { KERNEL_UNLOCK_ONE(curlwp); aprint_error_dev(atapi->sc_dev, "can't allocate link for drive %d\n", target); return; } DIF(UDMASS_UPPER, periph->periph_dbflags |= 1); /* XXX 1 */ periph->periph_channel = chan; periph->periph_switch = &atapi_probe_periphsw; periph->periph_target = target; periph->periph_quirks = chan->chan_defquirks; DPRINTF(UDMASS_SCSI, ("umass_atapi_probe_device: doing inquiry\n")); /* Now go ask the device all about itself. */ memset(&inqbuf, 0, sizeof(inqbuf)); if (scsipi_inquire(periph, &inqbuf, XS_CTL_DISCOVERY) != 0) { KERNEL_UNLOCK_ONE(curlwp); DPRINTF(UDMASS_SCSI, ("umass_atapi_probe_device: " "scsipi_inquire failed\n")); free(periph, M_DEVBUF); return; } scsipi_strvis(vendor, 33, inqbuf.vendor, 8); scsipi_strvis(product, 65, inqbuf.product, 16); scsipi_strvis(revision, 17, inqbuf.revision, 4); sa.sa_periph = periph; sa.sa_inqbuf.type = inqbuf.device; sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ? T_REMOV : T_FIXED; if (sa.sa_inqbuf.removable) periph->periph_flags |= PERIPH_REMOVABLE; sa.sa_inqbuf.vendor = vendor; sa.sa_inqbuf.product = product; sa.sa_inqbuf.revision = revision; sa.sa_inqptr = NULL; DPRINTF(UDMASS_SCSI, ("umass_atapi_probedev: doing atapi_probedev on " "'%s' '%s' '%s'\n", vendor, product, revision)); atapi_probe_device(atapi, target, periph, &sa); /* atapi_probe_device() frees the periph when there is no device.*/ KERNEL_UNLOCK_ONE(curlwp); }
Static void umass_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req, void *arg) { struct scsipi_adapter *adapt = chan->chan_adapter; struct scsipi_periph *periph; struct scsipi_xfer *xs; struct umass_softc *sc = device_private(adapt->adapt_dev); struct umass_scsipi_softc *scbus = (struct umass_scsipi_softc *)sc->bus; struct scsipi_generic *cmd; int cmdlen; int dir; #ifdef UMASS_DEBUG microtime(&sc->tv); #endif switch(req) { case ADAPTER_REQ_RUN_XFER: xs = arg; periph = xs->xs_periph; DIF(UDMASS_UPPER, periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS); DPRINTF(UDMASS_CMD, ("%s: umass_scsi_cmd: at %"PRIu64".%06"PRIu64": %d:%d " "xs=%p cmd=0x%02x datalen=%d (quirks=0x%x, poll=%d)\n", device_xname(sc->sc_dev), sc->tv.tv_sec, (uint64_t)sc->tv.tv_usec, periph->periph_target, periph->periph_lun, xs, xs->cmd->opcode, xs->datalen, periph->periph_quirks, xs->xs_control & XS_CTL_POLL)); #if defined(UMASS_DEBUG) && defined(SCSIPI_DEBUG) if (umassdebug & UDMASS_SCSI) show_scsipi_xs(xs); else if (umassdebug & ~UDMASS_CMD) show_scsipi_cmd(xs); #endif if (sc->sc_dying) { xs->error = XS_DRIVER_STUFFUP; goto done; } #ifdef UMASS_DEBUG if (SCSIPI_BUSTYPE_TYPE(chan->chan_bustype->bustype_type) == SCSIPI_BUSTYPE_ATAPI ? periph->periph_target != UMASS_ATAPI_DRIVE : periph->periph_target == chan->chan_id) { DPRINTF(UDMASS_SCSI, ("%s: wrong SCSI ID %d\n", device_xname(sc->sc_dev), periph->periph_target)); xs->error = XS_DRIVER_STUFFUP; goto done; } #endif cmd = xs->cmd; cmdlen = xs->cmdlen; dir = DIR_NONE; if (xs->datalen) { switch (xs->xs_control & (XS_CTL_DATA_IN | XS_CTL_DATA_OUT)) { case XS_CTL_DATA_IN: dir = DIR_IN; break; case XS_CTL_DATA_OUT: dir = DIR_OUT; break; } } if (xs->datalen > UMASS_MAX_TRANSFER_SIZE) { printf("umass_cmd: large datalen, %d\n", xs->datalen); xs->error = XS_DRIVER_STUFFUP; goto done; } if (xs->xs_control & XS_CTL_POLL) { /* Use sync transfer. XXX Broken! */ DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: sync dir=%d\n", dir)); scbus->sc_sync_status = USBD_INVAL; sc->sc_methods->wire_xfer(sc, periph->periph_lun, cmd, cmdlen, xs->data, xs->datalen, dir, xs->timeout, USBD_SYNCHRONOUS, 0, xs); DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: done err=%d\n", scbus->sc_sync_status)); switch (scbus->sc_sync_status) { case USBD_NORMAL_COMPLETION: xs->error = XS_NOERROR; break; case USBD_TIMEOUT: xs->error = XS_TIMEOUT; break; default: xs->error = XS_DRIVER_STUFFUP; break; } goto done; } else { DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: async dir=%d, cmdlen=%d" " datalen=%d\n", dir, cmdlen, xs->datalen)); sc->sc_methods->wire_xfer(sc, periph->periph_lun, cmd, cmdlen, xs->data, xs->datalen, dir, xs->timeout, 0, umass_scsipi_cb, xs); return; } /* Return if command finishes early. */ done: KERNEL_LOCK(1, curlwp); scsipi_done(xs); KERNEL_UNLOCK_ONE(curlwp); return; default: /* Not supported, nothing to do. */ ; } }
int main(int argc, char* argv[]){ if(argc != 3){ printf("Useage: input_name output_name"); exit(0); } char file_answer; printf("Select mode:\n" "1.bin to bmp\n" "2.bmp to bmp\n" "3.bin to bin\n"); file_answer=getchar(); fflush(stdin); char *Input=argv[1], *Output=argv[2];//retrive input/output name from commandline BmpHead *pBmpHeader = new BmpHead; unsigned char **pucImageData; char *pcColorMap=NULL; if((file_answer == '1')||(file_answer == '3')){ //read bin file system("cls"); //assign header information courtersy of Lena.bin (*pBmpHeader).bfType=19778; (*pBmpHeader).bfSize=54 + 1024+ 512*512 ; // raw data size = 512*512 = 262144 bytes, modify when necessary (*pBmpHeader).bfReserved=0; (*pBmpHeader).bfOffBits=1078; (*pBmpHeader).biSize=40; (*pBmpHeader).biWidth= 512; //number of columns of the image (*pBmpHeader).biHeight= 512; //number of rows of the image (*pBmpHeader).biPlanes=1; (*pBmpHeader).biBitCount=8; (*pBmpHeader).biCompression=0; (*pBmpHeader).biSizeImage= 512*512; //raw data size = 512*512 = 26144 bytes, modify when necessary, e.g., a 256x256 image: raw data size = 256*256 (*pBmpHeader).biXPelsPerMeter=2834; (*pBmpHeader).biYpelsPerMeter=2834; (*pBmpHeader).biClrUsed=0; (*pBmpHeader).biClrImportant=0; //read provided colormap FILE *colormap=NULL; pcColorMap = new char [1024]; if((colormap=fopen("colormap.bin", "rb")) == NULL){ printf("Failed to find colormap.bin\n"); exit(0); } fread(pcColorMap, sizeof(char), pBmpHeader->bfOffBits-64, colormap); fclose(colormap); //read raw data fron input pucImageData = ReadImage( Input, pBmpHeader->biWidth, 0); printf("successfully read raw data from %s.\n\n", Input); } else if(file_answer == '2'){ //read bmp file system("cls"); //read input header infomation pBmpHeader=ReadBmpHeader(Input); printf("raw data size: %d\n", pBmpHeader->biSizeImage); printf("Image Width: %d\n", pBmpHeader->biWidth); printf("Image Height %d\n", pBmpHeader->biHeight); printf("Header occupies 54 bytes\n"); printf("Color map occupies 1024 bytes\n"); //read input colormap pcColorMap=ReadColorMap(Input, 1024); //read raw data from input //set offset=1024+54 pucImageData=ReadImage(Input, pBmpHeader->biWidth, 1078); printf("successfully read raw data from %s.\n\n", Input); } srand(time(NULL));//plant random seed //function menu char fx_answer; int width, cutoff; do{ printf( "Select function:\n" "A.Turn Lena upside down\n" "B.Turn Lena around\n" "C.Rotate Lena by 45 deg clockwise\n" "D.Shrink Lena by half\n" "E.Invert Lena\n" "F.Add normal noise to Lena\n" "G.Add impluse noise to Lena\n" "H.Moving average filtering\n" "I.Midian filtering\n" "J.Differential flitering\n" "K.LPF\n" "L.HPF\n" "\n0.Exit\n"); printf("Your choice: [_]\b\b"); fx_answer = getchar(); fx_answer = tolower(fx_answer); fflush(stdin); switch(fx_answer){//savefile(): ask user to save as picture or not case 'a':// selected: turn lena upside down UpsideDown(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'b'://selected: turn lena around LeftRight(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'c'://selected: rotate lena ImgRotate(pucImageData, pBmpHeader->biWidth, 45); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'd'://selected: shrink lena Shrink(pucImageData, pBmpHeader->biWidth, pBmpHeader, 2); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'e'://selected: invert lena Invert(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'f'://selected: add noise NormalNoise(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'g'://selected: add paper n salt noise ImpluseNoise(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'h'://selected: moving average filter //ask user to input sampling width printf("Enter sampling width:"); scanf("%d", &width); fflush(stdin); MAF(pucImageData, pBmpHeader->biWidth, width); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'i'://selected: moving midian filter //ask user to input sampling width printf("Enter sampling width:"); scanf("%d", &width); fflush(stdin); MF(pucImageData, pBmpHeader->biWidth, width); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'j'://selected: differential filter DIF(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'k'://selected: low-pass filter //ask user to input cutoff frequency printf("Enter cutoff frenquency(0~%d):", (int)pBmpHeader->biWidth/2); scanf("%d", &cutoff); fflush(stdin); LPF(pucImageData, pBmpHeader->biWidth, cutoff); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'l'://selected: high-pass filter //ask user to input cutoff frequency printf("Enter cutoff frenquency(0~%d):", (int)pBmpHeader->biWidth/2); scanf("%d", &cutoff); fflush(stdin); HPF(pucImageData, pBmpHeader->biWidth, cutoff); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case '0'://selected: exit //ask one last time whether user want to save or not savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; default: system("cls"); printf("Your choice is not in the list!\n"); break; } if(fx_answer == 0) break;//selected: exit. break the loop } while(fx_answer != '0'); //returning dynamic allocated memory delete [] pcColorMap; delete [] pucImageData; delete pBmpHeader; pcColorMap=NULL; pucImageData=NULL; pBmpHeader=NULL; printf("EOP\n"); }
/***************************************************************************** Name: save_mobile Purpose: Save one mobile to file, new format -- Hugin Called by: save_mobiles (below). ****************************************************************************/ void save_mobile( FILE *fp, MOB_INDEX_DATA *pMobIndex ) { sh_int race = pMobIndex->race; long temp; char buf[MAX_STRING_LENGTH]; MPROG_LIST *pMprog; fprintf( fp, "#%d\n", pMobIndex->vnum ); fprintf( fp, "%s~\n", pMobIndex->player_name ); fprintf( fp, "%s~\n", pMobIndex->short_descr ); fprintf( fp, "%s~\n", fix_string( pMobIndex->long_descr ) ); fprintf( fp, "%s~\n", fix_string( pMobIndex->description) ); fprintf( fp, "%s~\n", race_table[race].name ); temp = DIF( pMobIndex->act, race_table[race].act ); fprintf( fp, "%s ", fwrite_flag( temp, buf ) ); temp = DIF( pMobIndex->affected_by, race_table[race].aff ); fprintf( fp, "%s ", fwrite_flag( temp, buf ) ); fprintf( fp, "%d %d\n", pMobIndex->alignment , pMobIndex->group); fprintf( fp, "%d ", pMobIndex->level ); fprintf( fp, "%d ", pMobIndex->hitroll ); fprintf( fp, "%dd%d+%d ", pMobIndex->hit[DICE_NUMBER], pMobIndex->hit[DICE_TYPE], pMobIndex->hit[DICE_BONUS] ); fprintf( fp, "%dd%d+%d ", pMobIndex->mana[DICE_NUMBER], pMobIndex->mana[DICE_TYPE], pMobIndex->mana[DICE_BONUS] ); fprintf( fp, "%dd%d+%d ", pMobIndex->damage[DICE_NUMBER], pMobIndex->damage[DICE_TYPE], pMobIndex->damage[DICE_BONUS] ); fprintf( fp, "%s\n", attack_table[pMobIndex->dam_type].name ); fprintf( fp, "%d %d %d %d\n", pMobIndex->ac[AC_PIERCE] / 10, pMobIndex->ac[AC_BASH] / 10, pMobIndex->ac[AC_SLASH] / 10, pMobIndex->ac[AC_EXOTIC] / 10 ); temp = DIF( pMobIndex->off_flags, race_table[race].off ); fprintf( fp, "%s ", fwrite_flag( temp, buf ) ); temp = DIF( pMobIndex->imm_flags, race_table[race].imm ); fprintf( fp, "%s ", fwrite_flag( temp, buf ) ); temp = DIF( pMobIndex->res_flags, race_table[race].res ); fprintf( fp, "%s ", fwrite_flag( temp, buf ) ); temp = DIF( pMobIndex->vuln_flags, race_table[race].vuln ); fprintf( fp, "%s\n", fwrite_flag( temp, buf ) ); fprintf( fp, "%s %s %s %ld\n", position_table[pMobIndex->start_pos].short_name, position_table[pMobIndex->default_pos].short_name, sex_table[pMobIndex->sex].name, pMobIndex->wealth ); temp = DIF( pMobIndex->form, race_table[race].form ); fprintf( fp, "%s ", fwrite_flag( temp, buf ) ); temp = DIF( pMobIndex->parts, race_table[race].parts ); fprintf( fp, "%s ", fwrite_flag( temp, buf ) ); fprintf( fp, "%s ", size_table[pMobIndex->size].name ); fprintf( fp, "'%s'\n", ((pMobIndex->material[0] != '\0') ? pMobIndex->material : "unknown") ); if ((temp = DIF(race_table[race].act,pMobIndex->act))) fprintf( fp, "F act %s\n", fwrite_flag(temp, buf) ); if ((temp = DIF(race_table[race].aff,pMobIndex->affected_by))) fprintf( fp, "F aff %s\n", fwrite_flag(temp, buf) ); if ((temp = DIF(race_table[race].off,pMobIndex->off_flags))) fprintf( fp, "F off %s\n", fwrite_flag(temp, buf) ); if ((temp = DIF(race_table[race].imm,pMobIndex->imm_flags))) fprintf( fp, "F imm %s\n", fwrite_flag(temp, buf) ); if ((temp = DIF(race_table[race].res,pMobIndex->res_flags))) fprintf( fp, "F res %s\n", fwrite_flag(temp, buf) ); if ((temp = DIF(race_table[race].vuln,pMobIndex->vuln_flags))) fprintf( fp, "F vul %s\n", fwrite_flag(temp, buf) ); if ((temp = DIF(race_table[race].form,pMobIndex->form))) fprintf( fp, "F for %s\n", fwrite_flag(temp, buf) ); if ((temp = DIF(race_table[race].parts,pMobIndex->parts))) fprintf( fp, "F par %s\n", fwrite_flag(temp, buf) ); for (pMprog=pMobIndex->mprogs;pMprog;pMprog=pMprog->next) { fprintf(fp, "M '%s' %d %s~\n", mprog_type_to_name(pMprog->trig_type), pMprog->vnum, pMprog->trig_phrase); } return; }
/* 自前でつくると、 inline にできるから、ふつうのatoiより速い。 */ static inline int fastatoi( char *s , int l ) { int minus = 1; #define DIF(d) ( s[d] - '0' ) if( s[0] == '-' ){ minus = -1; l--; s++;} switch(l){ case 0: return 0; case 1: return (DIF(0)) * minus; case 2: return (DIF(0)*10+DIF(1))*minus; case 3: return (DIF(0)*100+DIF(1)*10+DIF(2))*minus; case 4: return (DIF(0)*1000+DIF(1)*100+DIF(2)*10+DIF(3))*minus; case 5: return (DIF(0)*10000+DIF(1)*1000+DIF(2)*100 +DIF(3)*10+DIF(4))*minus; case 6: return (DIF(0)*100000+DIF(1)*10000+DIF(2)*1000+DIF(3)*100 +DIF(4)*10+DIF(5))*minus; case 7: return (DIF(0)*1000000+DIF(1)*100000+DIF(2)*10000 +DIF(3)*1000+DIF(4)*100+DIF(5)*10+DIF(6))*minus; case 8: return (DIF(0)*10000000+DIF(1)*1000000+DIF(2)*100000 +DIF(3)*10000+DIF(4)*1000+DIF(5)*100 +DIF(6)*10+DIF(7))*minus; case 9: return (DIF(0)*100000000+DIF(1)*10000000+DIF(2)*1000000 +DIF(3)*100000+DIF(4)*10000+DIF(5)*1000 +DIF(6)*100+DIF(7)*10+DIF(8))*minus; case 10: return (DIF(0)*1000000000+DIF(1)*100000000+DIF(2)*10000000 +DIF(3)*1000000+DIF(4)*100000+DIF(5)*10000 +DIF(6)*1000+DIF(7)*100+DIF(8)*10+DIF(9))*minus; default: printf( "asdfa\n" ); return 0; } }