/* * Retrieve the block containing the entry for r. * If a snapshot has happened, we might need * to get a new copy of the block. We avoid this * in the common case by caching the score for * the block and the last epoch in which it was valid. * * We use r->mode to tell the difference between active * file system VtFiles (VtORDWR) and VtFiles for the * snapshot file system (VtOREAD). */ static VtBlock* fileloadblock(VtFile *r, int mode) { char e[ERRMAX]; u32int addr; VtBlock *b; switch(r->mode){ default: assert(0); case VtOWRITE: assert(r->mode == VtORDWR); if(r->local == 1){ b = vtcacheglobal(r->c, r->score, VtDirType); if(b == nil) return nil; b->pc = getcallerpc(&r); return b; } assert(r->parent != nil); if(vtfilelock(r->parent, VtORDWR) < 0) return nil; b = vtfileblock(r->parent, r->offset/r->epb, VtORDWR); if(b == nil) b = vtfileblock(r->parent, r->offset/r->epb, VtOWRITE); vtfileunlock(r->parent); if(b == nil) return nil; memmove(r->score, b->score, VtScoreSize); r->local = 1; return b; case VtORDWR: assert(r->mode == VtORDWR); if(r->local == 1){ b = vtcacheglobal(r->c, r->score, VtDirType); if(b == nil) return nil; b->pc = getcallerpc(&r); return b; } assert(r->parent != nil); if(vtfilelock(r->parent, VtORDWR) < 0) return nil; b = vtfileblock(r->parent, r->offset/r->epb, VtORDWR); vtfileunlock(r->parent); if(b == nil) return nil; memmove(r->score, b->score, VtScoreSize); r->local = 1; return b; case VtOREAD: if(mode == VtORDWR){ werrstr("read/write lock of read-only file"); return nil; } addr = vtglobaltolocal(r->score); if(addr == NilBlock) return vtcacheglobal(r->c, r->score, VtDirType); b = vtcachelocal(r->c, addr, VtDirType); if(b) return b; /* * If it failed because the epochs don't match, the block has been * archived and reclaimed. Rewalk from the parent and get the * new pointer. This can't happen in the VtORDWR case * above because blocks in the current epoch don't get * reclaimed. The fact that we're VtOREAD means we're * a snapshot. (Or else the file system is read-only, but then * the archiver isn't going around deleting blocks.) */ rerrstr(e, sizeof e); if(strcmp(e, ELabelMismatch) == 0){ if(vtfilelock(r->parent, VtOREAD) < 0) return nil; b = vtfileblock(r->parent, r->offset/r->epb, VtOREAD); vtfileunlock(r->parent); if(b){ fprint(2, "vtfilealloc: lost %V found %V\n", r->score, b->score); memmove(r->score, b->score, VtScoreSize); return b; } } return nil; } }
static int NPC_readCreateFile( char* filename ) { FILE* f; char line[512]; int linenum=0; int start=OFF; NPC_Create cr; int enemyreadindex=0; typedef struct tagPOINT { int x,y; }POINT; typedef struct tagREC { int w,h; }REC; POINT center[2]={{0,0},{0,0}}; /* born が 0 で move が 1 */ REC wh[2] ={{0,0},{0,0}}; /* born が 0 で move が 1 */ POINT lu[2] ={{0,0},{0,0}}; /* born が 0 で move が 1 */ POINT rd[2] ={{0,0},{0,0}}; /* born が 0 で move が 1 */ int defborn=FALSE; /* born を設定したかどうか */ int defmove=FALSE; /* move を設定したかどうか */ int deflurd[2]={FALSE,FALSE}; /* lu,rd で設定したかどうか */ char* ret; if( NPC_create_readindex >= NPC_createnum ){ print("Create Exceed configured buffer\n" ); print("configured createnumber is %d\n",NPC_createnum); print("Unread File:%s\n",filename); return FALSE; } NPC_setDefaultNPCCreate( &cr ); f= fopen( filename ,"r"); if( f == NULL )return FALSE; ret = fgets( line, sizeof( line ), f ); if( ret == NULL )goto FCLOSERETURNFALSE; if( strcmp( NPC_CREATEFILEMAGIC, line ) != 0 ){ print( "This file is not a create file.\n" ); goto FCLOSERETURNFALSE; } linenum = 1; while( fgets( line , sizeof( line ) , f ) ){ linenum++; if( line[0] == '#' )continue; /* comment */ if( line[0] == '\n' )continue; /* none */ chomp( line ); switch( line[0] ){ case '{': if( start == ON ){ fprint( "Find {. But already START state. %s:%d\n", filename, linenum); fprint( "exit\n" ); goto FCLOSERETURNFALSE; }else{ NPC_setDefaultNPCCreate( &cr ); start = ON; } break; case '}': if( start == ON ){ int err = FALSE; if( enemyreadindex == 0 ){ err = TRUE; print( "There is no enemydata %s:%d\n", filename,linenum); }else if( MAP_IsThereSpecificFloorid( cr.intdata[NPC_CREATEFLOORID]) == FALSE ){ err = TRUE; print( "Invalid Floor ID arround %s:%d-floor:%d\n", filename,linenum, cr.intdata[NPC_CREATEFLOORID]); }else if( defborn == FALSE ){ err = TRUE; print( "There is no born setting %s:%d\n", filename,linenum); } if( err == FALSE ){ cr.intdata[NPC_CREATEENEMYNUM] = enemyreadindex; if( deflurd[0] ){ cr.intdata[NPC_CREATEBORNLEFTUPX] = min(lu[0].x,rd[0].x); cr.intdata[NPC_CREATEBORNRIGHTDOWNX] = max(lu[0].x,rd[0].x); cr.intdata[NPC_CREATEBORNLEFTUPY] = min(lu[0].y,rd[0].y); cr.intdata[NPC_CREATEBORNRIGHTDOWNY] = max(lu[0].y,rd[0].y); }else{ cr.intdata[NPC_CREATEBORNLEFTUPX] = center[0].x-wh[0].w/2; cr.intdata[NPC_CREATEBORNRIGHTDOWNX] = center[0].x+wh[0].w/2; cr.intdata[NPC_CREATEBORNLEFTUPY] = center[0].y-wh[0].h/2; cr.intdata[NPC_CREATEBORNRIGHTDOWNY] = center[0].y+wh[0].h/2; } /* 99/01/21 河田 [0]-->[1]に修正 */ if( defmove ){ if( deflurd[0] ){ cr.intdata[NPC_CREATEMOVELEFTUPX] = min(lu[1].x,rd[1].x); cr.intdata[NPC_CREATEMOVERIGHTDOWNX] = max(lu[1].x,rd[1].x); cr.intdata[NPC_CREATEMOVELEFTUPY] = min(lu[1].y,rd[1].y); cr.intdata[NPC_CREATEMOVERIGHTDOWNY] = max(lu[1].y,rd[1].y); }else{ cr.intdata[NPC_CREATEMOVELEFTUPX] = center[1].x-wh[1].w/2; cr.intdata[NPC_CREATEMOVERIGHTDOWNX] = center[1].x+wh[1].w/2; cr.intdata[NPC_CREATEMOVELEFTUPY] = center[1].y-wh[1].h/2; cr.intdata[NPC_CREATEMOVERIGHTDOWNY] = center[1].y+wh[1].h/2; } }else{ /* born をコピーする */ cr.intdata[NPC_CREATEMOVELEFTUPX] = cr.intdata[NPC_CREATEBORNLEFTUPX]; cr.intdata[NPC_CREATEMOVERIGHTDOWNX] = cr.intdata[NPC_CREATEBORNRIGHTDOWNX]; cr.intdata[NPC_CREATEMOVELEFTUPY] = cr.intdata[NPC_CREATEBORNLEFTUPY]; cr.intdata[NPC_CREATEMOVERIGHTDOWNY] = cr.intdata[NPC_CREATEBORNRIGHTDOWNY]; } memcpy( &NPC_create[NPC_create_readindex], &cr, sizeof( NPC_Create ) ); NPC_create_readindex++; if( NPC_create_readindex >= NPC_createnum ){ print("Create Exceed configured buffer\n" ); print("configured createnumber is %d\n", NPC_createnum); print("Unread File:%s\n",filename); goto FCLOSERETURNFALSE; } } /* 初期値に戻しておく */ NPC_setDefaultNPCCreate( &cr ); enemyreadindex=0; defborn=FALSE; defmove=FALSE; deflurd[0]=FALSE; deflurd[1]=FALSE; start = OFF; }else{ fprint( "Unresolved '}' at %s:%d\n",filename,linenum); goto FCLOSERETURNFALSE; } break; default: { char firstToken[256]; char secondToken[256]; int ret; ret = getStringFromIndexWithDelim( line, "=", 1, firstToken, sizeof( firstToken ) ); if( ret == FALSE ){ print( "Find error at %s in line %d. Ignore\n", filename , linenum); break; } ret = getStringFromIndexWithDelim( line, "=", 2, secondToken, sizeof( secondToken ) ); if( ret == FALSE ){ print( "Find error at %s in line %d. Ignore\n", filename , linenum); break; } if( strcasecmp("floorid",firstToken) == 0 ){ cr.intdata[NPC_CREATEFLOORID] = atoi(secondToken); }else if( strcasecmp("borncenter", firstToken) == 0 ){ getFourIntsFromString(secondToken,¢er[0].x, ¢er[0].y,&wh[0].w,&wh[0].h ); defborn = TRUE; }else if( strcasecmp("borncorner", firstToken) == 0 ){ getFourIntsFromString(secondToken,&lu[0].x,&lu[0].y, &rd[0].x,&rd[0].y ); defborn = TRUE; deflurd[0]=TRUE; }else if( strcasecmp("movecenter", firstToken) == 0 ){ getFourIntsFromString(secondToken,¢er[1].x, ¢er[1].y,&wh[1].w,&wh[1].h ); defmove = TRUE; }else if( strcasecmp("movecorner", firstToken) == 0 ){ getFourIntsFromString(secondToken,&lu[1].x,&lu[1].y, &rd[1].x,&rd[1].y ); defmove = TRUE; deflurd[1]=TRUE; }else if( strcasecmp("dir",firstToken) == 0 ){ cr.intdata[NPC_CREATEDIR] = atoi( secondToken ); }else if( strcasecmp("graphicname",firstToken) == 0 ){ cr.intdata[NPC_CREATEBASEIMAGENUMBER] = CHAR_seekGraphicNumberFromString(secondToken); }else if( strcasecmp("name",firstToken) == 0 ){ strcpysafe( cr.chardata[NPC_CREATENAME].string, sizeof(cr.chardata[NPC_CREATENAME].string), secondToken ); }else if( strcasecmp("time",firstToken) == 0 ){ cr.intdata[NPC_CREATETIME] = atoi( secondToken ); }else if( strcasecmp("date",firstToken) == 0 ){ cr.intdata[NPC_CREATEDATE] = atoi( secondToken ); }else if( strcasecmp("createnum",firstToken) == 0 ){ cr.intdata[NPC_CREATEBORNNUM] = atoi( secondToken ); }else if( strcasecmp( "boundary", firstToken) == 0 ){ cr.intdata[NPC_CREATEBOUNDARY] = atoi( secondToken ); }else if( strcasecmp( "ignoreinvincible", firstToken) == 0 ){ cr.intdata[NPC_CREATEIGNOREINVINCIBLE] = atoi( secondToken ); //jeffrey 1231 #ifdef _ADD_ACTION }else if( strcasecmp( "action", firstToken) == 0 ){ cr.intdata[NPC_CREATEACTION] = atoi( secondToken ); #endif // Robin 0731 }else if( strcasecmp( "family", firstToken) == 0 ){ cr.intdata[NPC_CREATEFAMILY] = atoi( secondToken ); }else if( strcasecmp("enemy", firstToken) == 0 ){ /* 引数を渡せるようにする */ int templateindex; char enemyname[64]; /* 境界線チェック */ if( enemyreadindex <= arraysizeof(cr.templateindex) ) /* OK */ ; else break; /* secondToken を文字列に分解する */ getStringFromIndexWithDelim(secondToken,"|",1,enemyname, sizeof(enemyname) ); templateindex= NPC_templateGetTemplateIndex(enemyname); if( templateindex != -1 ){ cr.templateindex[enemyreadindex] = templateindex; { /* 引数を処理する */ char tmp[2]; int ret; ret = getStringFromIndexWithDelim( secondToken, "|",2,tmp, sizeof(tmp) ); if( ret == FALSE ) cr.arg[enemyreadindex].string[0] = '\0'; else strcpysafe( cr.arg[enemyreadindex].string, sizeof( cr.arg[enemyreadindex]. string ), secondToken+strlen(enemyname)+1 ); } enemyreadindex++; }else fprint( "No such template:\n[%s(%d)%s] enemy:%s\n", filename ,linenum,secondToken, enemyname); }else{ fprint( "No such entry %s %s:%d\n",firstToken,filename, linenum ); } } } } fclose(f); return TRUE; FCLOSERETURNFALSE: fclose(f); return FALSE; }
void usage(void) { fprint(2, "usage: %s [-in] [-p proto] [network-dir]\n", argv0); exits("usage"); }
void usage(void) { fprint(2, "usage: 6l [-options] [-E entry] [-H head] [-I interpreter] [-L dir] [-T text] [-R rnd] [-r path] [-o out] main.6\n"); exits("usage"); }
inline bool fprint(FILE *stream, const int indent) { return fprint(stream, indent, this); }
void threadmain(int argc, char *argv[]) { char *mtpt, *s; char *secstorepw; char err[ERRMAX]; Dir d; rfork(RFNOTEG); mtpt = "/mnt"; extrafactotumdir = 1; secstorepw = nil; quotefmtinstall(); fmtinstall('A', attrfmt); fmtinstall('H', encodefmt); fmtinstall('N', attrnamefmt); if(argc == 3 && strcmp(argv[1], "-g") == 0){ gflag(argv[2]); threadexitsall(nil); } ARGBEGIN{ default: usage(); case 'D': chatty9p++; break; case 'S': /* server: read nvram, no prompting for keys */ askforkeys = 0; trysecstore = 0; sflag = 1; break; case 'a': authaddr = EARGF(usage()); break; case 'd': debug = 1; doprivate = 0; break; case 'g': usage(); case 'k': /* reinitialize nvram */ kflag = 1; break; case 'm': mtpt = EARGF(usage()); break; case 'n': trysecstore = 0; break; case 'p': doprivate = 0; break; case 's': service = EARGF(usage()); break; case 'u': /* user: set hostowner */ uflag = 1; break; case 'x': extrafactotumdir = 0; break; }ARGEND if(argc != 0) usage(); if(doprivate) private(); initcap(); if(sflag){ s = getnvramkey(kflag ? NVwrite : NVwriteonerr, &secstorepw); if(s == nil) fprint(2, "factotum warning: cannot read nvram: %r\n"); else if(ctlwrite(s) < 0) fprint(2, "factotum warning: cannot add nvram key: %r\n"); if(secstorepw != nil) trysecstore = 1; if (s != nil) { memset(s, 0, strlen(s)); free(s); } } else if(uflag) promptforhostowner(); owner = getuser(); if(trysecstore && havesecstore()){ while(secstorefetch(secstorepw) < 0){ rerrstr(err, sizeof err); if(strcmp(err, "cancel") == 0) break; fprint(2, "secstorefetch: %r\n"); fprint(2, "Enter an empty password to quit.\n"); free(secstorepw); secstorepw = nil; /* just try nvram pw once */ } } fsinit0(); threadpostmountsrv(&fs, service, mtpt, MBEFORE); if(service){ nulldir(&d); d.mode = 0666; s = emalloc(10+strlen(service)); strcpy(s, "/srv/"); strcat(s, service); if(dirwstat(s, &d) < 0) fprint(2, "factotum warning: cannot chmod 666 %s: %r\n", s); free(s); } threadexits(nil); }
void usage(void) { fprint(2, "usage: auth/dsagen [-t 'attr=value attr=value ...']\n"); exits("usage"); }
void NPC_DepotPet_Add( int meindex, int talker, int select, char *token) { int petindex; int selectpet; int emptyindex; char szPet[128]; int fd = getfdFromCharaIndex( talker ); if( fd == -1 ) { fprint( "err\n"); return; } // ʸÓÀÐþ·¸¡õÕý µÊ£ÛʸÓÀÐþ Øê ľ selectpet = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) -1; //print("\n selectpet:%d ", selectpet); petindex = CHAR_getCharPet( talker, selectpet); if( !CHAR_CHECKINDEX( petindex) ) return; // Robin 0725 if (CHAR_getInt( talker, CHAR_RIDEPET ) == selectpet ) { sprintf(token,"\n\nÆï³ËÖеijèÎïÎÞ·¨´æÈë²Ö¿âร¡"); return; } if( CHAR_getInt( petindex, CHAR_PETFAMILY) == 1 ) { sprintf(token,"\n\n¼Ò×åÊØ»¤ÊÞÎÞ·¨´æÈë²Ö¿âร¡"); return; } #ifdef _CHECK_ENEMY_PET { int j; for( j=0;j<ENEMYTEMP_getEnemyNum();j++ ) {//ENEMY_getEnemyNum() if( CHAR_getInt( petindex, CHAR_PETID) == ENEMYTEMP_getInt( j, E_T_TEMPNO ) ) {//ENEMY_getInt( j, ENEMY_TEMPNO) if( ENEMYTEMP_getInt( j, E_T_PETFLG ) == 0 ){//ENEMY_getInt( j, ENEMY_PETFLG) sprintf(token,"\n\nÕâÊDz»ÄܳÖÓеijèÎïร¡"); return; } } } } #endif // ÎëÎåë¼ëÔÊ£Ûó¡±å¼ëØÆ»¯ÃñÄáÓÀÛÍØÆ»¯ÖÐÔ¼°Æ¥£Ý³ð³ðÆ¥ÎëÖл¯ÖÐئÖм°·´Ôƾ®ØÆÖÐ emptyindex = CHAR_getCharDepotPetElement( talker); if( emptyindex == -1 ) { fprint( "err\n"); return; } // ¾ô ÉÍ åÃʸÓÀÐþئÈգݹ«Ä¾¼°è¶ ëÛÕÔÊ£Û if( CHAR_getInt( talker, CHAR_DEFAULTPET) == selectpet) { CHAR_setInt( talker, CHAR_DEFAULTPET, -1); lssproto_KS_send( fd, -1, TRUE); } // Øê ľ ±å£ÝʸÓÀÐþ¼°Ä̼þ·¸ÓÀÛ͵©Ã«Îìñâ¡õ CHAR_setDepotPetIndex( talker, emptyindex, petindex); // ʸÓÀÐþ ¾®ÈÕÛÕÔÊ CHAR_setCharPet( talker, selectpet, -1); // ¶ªÓÀ±¾¡õ³âäú NPC_MaxGoldOver( meindex, talker, NPC_PETSHOP_MSG_POOLTHANKS, token); // ÔÆàÅÓ¼ÈÕÔÊ CHAR_DelGold( talker, NPC_GETPOOLCOST( talker) ); // ÔÆàÅ·¸¡õÕý˪Ô CHAR_send_P_StatusString(talker,CHAR_P_STRING_GOLD); snprintf( szPet, sizeof( szPet ), "K%d", selectpet); // Þ¥ØÆÖÐʸÓÀÐþµ© ¡õÕýµ©ËªÔ»¹´ØêÔ CHAR_sendStatusString( talker, szPet ); // ʸÓÀÐþë ØêÐ×·òºë if( NPC_DepotPet_CheckRepeat( talker) == 0) // ¼ì²é±àÂëÖظ´³è { LogPet( CHAR_getChar( talker, CHAR_NAME ), /* ƽÅÒ·Â */ CHAR_getChar( talker, CHAR_CDKEY ), CHAR_getChar( petindex, CHAR_NAME), CHAR_getInt( petindex, CHAR_LV), "pool(´æÈë³èÎï²Ö¿â)", CHAR_getInt( talker,CHAR_FLOOR), CHAR_getInt( talker,CHAR_X ), CHAR_getInt( talker,CHAR_Y ), CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 ); } else { CHAR_talkToCli( talker, -1, "ÕâÊÇ·Ç·¨µÄ³èÎïà¸!!", CHAR_COLORYELLOW); } }
static void NPC_PetShop_selectWindow( int meindex, int toindex, int num,int select) { char token[1024]; int buttontype=0,windowtype=0,windowno=0; char buf[1024]; int fd = getfdFromCharaIndex( toindex); //print("\n NPC_PetShop_selectWindow num:%d select:%d ", num, select); if( fd == -1 ) { fprint( "getfd err\n"); return; } token[0] = '\0'; switch(num){ // âÙ¼°ËüÅ«¼þÓñËü case 0: NPC_MaxGoldOver( meindex, toindex, NPC_PETSHOP_MSG_MAIN, buf); #ifdef _NPC_DEPOTPET if( !CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG)) { sprintf(token, "4\n¡¡¡¡¡¡¡¡¡¡¡¡¡î³èÎïÉ̵ê¡î" "%s" "\n" "\n¡¡¡¡¡¡¡¡¡¡¡¡ ¡¶ Âô³èÎï ¡·" "\n" "\n" "\n ¡¶ À뿪 ¡·", buf); }else { sprintf(token, "4\n¡¡¡¡¡¡¡¡¡¡¡¡¡î³èÎïÉ̵ê¡î" "%s" "\n ¡¶ ¼Ä·Å³èÎï ¡·" "\n ¡¶ ÁìÈ¡³èÎï ¡·" "\n¡¡¡¡¡¡¡¡¡¡¡¡ ¡¶ Âô³èÎï ¡·" "\n ¡¶ ʹÓòֿ⠡·" "\n ¡¶ À뿪 ¡·", buf); } #else if( !CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG)) { sprintf(token, "4\n¡¡¡¡¡¡¡¡¡¡¡¡¡î³èÎïÉ̵ê¡î" "%s" "\n" "\n¡¡¡¡¡¡¡¡¡¡¡¡ ¡¶ Âô³èÎï ¡·" "\n" "\n ¡¶ À뿪 ¡·", buf); }else { sprintf(token, "4\n¡¡¡¡¡¡¡¡¡¡¡¡¡î³èÎïÉ̵ê¡î" "%s" "\n ¡¶ ¼Ä·Å³èÎï ¡·" "\n ¡¶ ÁìÈ¡³èÎï ¡·" "\n¡¡¡¡¡¡¡¡¡¡¡¡ ¡¶ Âô³èÎï ¡·" "\n ¡¶ À뿪 ¡·", buf); } #endif buttontype=WINDOW_BUTTONTYPE_NONE; windowtype=WINDOW_MESSAGETYPE_SELECT; windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_START; break; case 1: buttontype=WINDOW_BUTTONTYPE_CANCEL; windowtype=WINDOW_MESSAGETYPE_PETSELECT; windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_PETSELECT; break; case 2: NPC_PetDate(meindex,toindex,select,token); buttontype=WINDOW_BUTTONTYPE_YESNO; windowtype=WINDOW_MESSAGETYPE_MESSAGE; windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_MAIN; break; case 3: if( (CHAR_getInt(toindex,CHAR_GOLD)+CHAR_getWorkInt(toindex,CHAR_WORKSHOPRELEVANTSEC)) > CHAR_getMaxHaveGold( toindex) ){ NPC_MaxGoldOver( meindex, toindex, NPC_PETSHOP_MSG_OVER, token); windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_GOLDOVER; buttontype=WINDOW_BUTTONTYPE_YESNO; }else{ NPC_PetDel(meindex,toindex,select,token); buttontype=WINDOW_BUTTONTYPE_OK; windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_END; } windowtype=WINDOW_MESSAGETYPE_MESSAGE; break; case 4: NPC_PetDel(meindex,toindex,select,token); buttontype=WINDOW_BUTTONTYPE_OK; windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_END; windowtype=WINDOW_MESSAGETYPE_MESSAGE; break; case 5: // ÁìÈ¡¼Ä·Å³èÁбí if( CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG ) != 1 ) return; buttontype=WINDOW_BUTTONTYPE_CANCEL; windowtype=WINDOW_MESSAGETYPE_PETSELECT; windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_PETSELECT2; break; case 6: if( CHAR_getInt( toindex, CHAR_GOLD) < NPC_GETPOOLCOST( toindex)) { NPC_MaxGoldOver(meindex, toindex, NPC_PETSHOP_MSG_COST, token); buttontype = WINDOW_BUTTONTYPE_OK; } else { NPC_PetDate2( meindex, toindex, select, token); buttontype = WINDOW_BUTTONTYPE_YESNO; } windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_MAIN2; break; case 7: if( CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG ) != 1 ) return; if( CHAR_getInt( toindex, CHAR_GOLD) < NPC_GETPOOLCOST( toindex)){ NPC_MaxGoldOver(meindex, toindex, NPC_PETSHOP_MSG_COST, token); }else { NPC_PetDel2( meindex, toindex, select, token); } buttontype = WINDOW_BUTTONTYPE_OK; windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; break; // Øê ľ »¥Óò case 8: NPC_MaxGoldOver( meindex, toindex, NPC_PETSHOP_MSG_POOLFULL, token); buttontype = WINDOW_BUTTONTYPE_OK; windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; break; // ¦ÎåäúԻʸÓÀÐþÓò ËüÅ«¼þÓñËü case 9: // È¡³ö¼Ä·Å³èÁбí if( CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG) != 1 ) return; NPC_getDrawPet( meindex, toindex, token, &buttontype, select); windowtype = WINDOW_MESSAGETYPE_SELECT; windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_DRAWSELECT; break; // ¦ÎåäúÔ» £¢ case 10: NPC_PetDate3( meindex, toindex, select, token); buttontype = WINDOW_BUTTONTYPE_YESNO; windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_ASKDRAW; break; // ߯ÔÊ case 11: if( CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG ) != 1 ) return; NPC_PetDel3( meindex, toindex, select, token); buttontype = WINDOW_BUTTONTYPE_OK; windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; break; // ʸÓÀÐþ »¥Óò case 12: NPC_MaxGoldOver( meindex, toindex, NPC_PETSHOP_MSG_GETFULL, token); buttontype = WINDOW_BUTTONTYPE_OK; windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; break; #ifdef _NPC_DEPOTPET case 13: // ´æÈë²Ö¿âÁбí if( !CHAR_CheckDepotPet( toindex) ) return; buttontype=WINDOW_BUTTONTYPE_CANCEL; windowtype=WINDOW_MESSAGETYPE_PETSELECT; windowno=CHAR_WINDOWTYPE_DEPOTPETSHOP_ADD; break; case 14: // È¡³ö²Ö¿âÁбí if( !CHAR_CheckDepotPet( toindex) ) return; NPC_DepotPet_List( meindex, toindex, token, &buttontype, select); //buttontype=WINDOW_BUTTONTYPE_CANCEL; windowtype = WINDOW_MESSAGETYPE_SELECT; windowno = CHAR_WINDOWTYPE_DEPOTPETSHOP_GET; break; case 15: // ѯÎÊÈ·ÈÏ´æÈë²Ö¿â if( CHAR_getInt( toindex, CHAR_GOLD) < NPC_GETPOOLCOST( toindex)) { NPC_MaxGoldOver(meindex, toindex, NPC_PETSHOP_MSG_COST, token); buttontype = WINDOW_BUTTONTYPE_OK; } else { NPC_PetDate2( meindex, toindex, select, token); buttontype = WINDOW_BUTTONTYPE_YESNO; } windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_DEPOTPETSHOP_ASKADD; break; case 16: // ѯÎÊÈ·ÈÏÈ¡³ö²Ö¿â NPC_DepotPet_AskGet( meindex, toindex, select, token); buttontype = WINDOW_BUTTONTYPE_YESNO; windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_DEPOTPETSHOP_ASKGET; break; case 17: // È·ÈÏ´æÈë²Ö¿â if( !CHAR_CheckDepotPet(toindex) ) return; if( CHAR_getInt( toindex, CHAR_GOLD) < NPC_GETPOOLCOST( toindex)){ NPC_MaxGoldOver(meindex, toindex, NPC_PETSHOP_MSG_COST, token); }else { NPC_DepotPet_Add( meindex, toindex, select, token); } buttontype = WINDOW_BUTTONTYPE_OK; windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; break; case 18: // È·ÈÏÈ¡³ö²Ö¿â if( CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG ) != 1 ) return; if( NPC_DepotPet_CheckLevel( meindex, toindex, select, token) == TRUE) { NPC_DepotPet_Get( meindex, toindex, select, token); buttontype = WINDOW_BUTTONTYPE_OK; windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; } else { sprintf( token, "\nÄãÎÞ·¨ÕÕ¹ËÕâÖ»³èÎï¡£"); buttontype = WINDOW_BUTTONTYPE_OK; windowtype = WINDOW_MESSAGETYPE_MESSAGE; windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; } break; #endif // CoolFish: Add 2001/7/4 default: break; } /*--¾Þµ©¸¥¡õÃó--*/ //makeEscapeString( token, escapedname, sizeof(escapedname)); /*--˪ññ--*/ lssproto_WN_send( fd, windowtype, buttontype, windowno, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); }
/* * send mail */ int mail(Fs *f, char *rcvr, char *user, long et) { int pid, i, fd; int pfd[2]; char *ct, *p; Waitmsg *w; char buf[128]; if(pipe(pfd) < 0){ complain("out of pipes: %r"); return 0; } switch(pid = fork()){ case -1: complain("can't fork: %r"); return 0; case 0: break; default: if(debug) fprint(2, "started %d\n", pid); close(pfd[0]); ct = ctime(et); p = strchr(ct, '\n'); *p = '.'; fprint(pfd[1], "User '%s's %s expires on %s\n", user, f->msg, ct); if(f != fs) fprint(pfd[1], "If you wish to renew contact your local administrator.\n"); p = strrchr(f->keys, '/'); if(p) p++; else p = f->keys; snprint(buf, sizeof buf, "/adm/warn.%s", p); fd = open(buf, OREAD); if(fd >= 0){ while((i = read(fd, buf, sizeof(buf))) > 0) write(pfd[1], buf, i); close(fd); } close(pfd[1]); /* wait for warning to be mailed */ for(;;){ w = wait(); if(w == nil) break; if(w->pid == pid){ if(debug) fprint(2, "%d terminated: %s\n", pid, w->msg); if(w->msg[0] == 0){ free(w); break; }else{ free(w); return 0; } }else free(w); } return 1; } /* get out of the current namespace */ newns("none", 0); dup(pfd[0], 0); close(pfd[0]); close(pfd[1]); putenv("upasname", "netkeys"); if(debug){ print("\nto %s\n", rcvr); execl("/bin/cat", "cat", nil); } execl("/bin/upas/send", "send", "-r", rcvr, nil); /* just in case */ sysfatal("can't exec send: %r"); return 0; /* for compiler */ }
void usage(void) { fprint(2, "usage: %s [-n] [-p]\n", argv0); exits("usage"); }
/* * Write a Rock Ridge SUSP set of records for a directory entry. */ int Cputsysuse(Cdimg *cd, Direc *d, int dot, int dowrite, int initlen) { char buf[256], buf0[256], *nextpath, *p, *path, *q; int flags, free, m, what; uint64_t o; Cbuf cn, co, *cp; assert(cd != nil); assert((initlen&1) == 0); if(dot == DTroot) return 0; co.len = initlen; o = Cwoffset(cd); assert(dowrite==0 || Cwoffset(cd) == o+co.len-initlen); cp = &co; if (dot == DTrootdot) { m = CputsuspSP(cd, 0); cp = ensurespace(cd, m, cp, &cn, dowrite); CputsuspSP(cd, dowrite); m = CputsuspER(cd, 0); cp = ensurespace(cd, m, cp, &cn, dowrite); CputsuspER(cd, dowrite); } /* * In a perfect world, we'd be able to omit the NM * entries when our name was all lowercase and conformant, * but OpenBSD insists on uppercasing (really, not lowercasing) * the ISO9660 names. */ what = RR_PX | RR_TF | RR_NM; if(d != nil && (d->mode & CHLINK)) what |= RR_SL; m = CputsuspRR(cd, what, 0); cp = ensurespace(cd, m, cp, &cn, dowrite); CputsuspRR(cd, what, dowrite); if(what & RR_PX) { m = CputrripPX(cd, d, dot, 0); cp = ensurespace(cd, m, cp, &cn, dowrite); CputrripPX(cd, d, dot, dowrite); } if(what & RR_NM) { if(dot == DTiden) p = d->name; else if(dot == DTdotdot) p = ".."; else p = "."; flags = suspdirflags(d, dot); assert(dowrite==0 || cp != &co || Cwoffset(cd) == o+co.len-initlen); cp = Cputstring(cd, cp, &cn, "NM", p, flags, dowrite); } /* * Put down the symbolic link. This is even more of a crock. * Not only are the individual elements potentially split, * but the whole path itself can be split across SL blocks. * To keep the code simple as possible (really), we write * only one element per SL block, wasting 6 bytes per element. */ if(what & RR_SL) { for(path=d->symlink; path[0] != '\0'; path=nextpath) { /* break off one component */ if((nextpath = strchr(path, '/')) == nil) nextpath = path+strlen(path); strncpy(buf0, path, nextpath-path); buf0[nextpath-path] = '\0'; if(nextpath[0] == '/') nextpath++; p = buf0; /* write the name, perhaps broken into pieces */ if(strcmp(p, "") == 0) flags = NMroot; else if(strcmp(p, ".") == 0) flags = NMcurrent; else if(strcmp(p, "..") == 0) flags = NMparent; else flags = 0; /* the do-while handles the empty string properly */ do { /* must have room for at least 1 byte of name */ cp = ensurespace(cd, 7+1, cp, &cn, dowrite); cp->len -= 7+1; free = freespace(cp); assert(7+1 <= free && free < 256); strncpy(buf, p, free-7); buf[free-7] = '\0'; q = p+strlen(buf); p = buf; /* nil: better not need to expand */ assert(7+strlen(p) <= free); ensurespace(cd, 7+strlen(p), cp, nil, dowrite); CputrripSL(cd, nextpath[0], flags | (q[0] ? NMcontinue : 0), p, dowrite); p = q; } while(p[0] != '\0'); } } assert(dowrite==0 || cp != &co || Cwoffset(cd) == o+co.len-initlen); if(what & RR_TF) { m = CputrripTF(cd, d, TFcreation|TFmodify|TFaccess|TFattributes, 0); cp = ensurespace(cd, m, cp, &cn, dowrite); CputrripTF(cd, d, TFcreation|TFmodify|TFaccess|TFattributes, dowrite); } assert(dowrite==0 || cp != &co || Cwoffset(cd) == o+co.len-initlen); if(cp == &cn && dowrite) { /* seek out of continuation, but mark our place */ cd->rrcontin = Cwoffset(cd); setcelen(cd, cn.ceoffset, cn.len); Cwseek(cd, o+co.len-initlen); } if(co.len & 1) { co.len++; if(dowrite) Cputc(cd, 0); } if(dowrite) { if(Cwoffset(cd) != o+co.len-initlen) fprint(2, "offset %llu o+co.len-initlen %llu\n", Cwoffset(cd), o+co.len-initlen); assert(Cwoffset(cd) == o+co.len-initlen); } else assert(Cwoffset(cd) == o); assert(co.len <= 255); return co.len - initlen; }
int ctlproc(int id, char *msg) { Thread *t; int status; // Hang/attached dance is for debugging newly exec'ed programs. // After fork, the child does ctlproc("hang") before exec, // and the parent does ctlproc("attached") and then waitstop. // Using these requires the BSD ptrace interface, unlike everything // else we do, which uses only the Mach interface. Our goal here // is to do as little as possible using ptrace and then flip over to Mach. if(strcmp(msg, "hang") == 0) return ptrace(PT_TRACE_ME, 0, 0, 0); if(strcmp(msg, "attached") == 0){ // The pid "id" has done a ctlproc "hang" and then // exec, so we should find it stoppped just before exec // of the new program. #undef waitpid if(waitpid(id, &status, WUNTRACED) < 0){ fprint(2, "ctlproc attached waitpid: %r\n"); return -1; } if(WIFEXITED(status) || !WIFSTOPPED(status)){ fprint(2, "ctlproc attached: bad process state\n"); return -1; } // Find Mach thread for pid and suspend it. t = addpid(id, 1); if(t == nil) return -1; if(me(thread_suspend(t->thread)) < 0){ fprint(2, "ctlproc attached: thread_suspend: %r\n"); return -1; } // Let ptrace tell the process to keep going: // then ptrace is out of the way and we're back in Mach land. return ptrace(PT_CONTINUE, id, (caddr_t)1, 0); } // All the other control messages require a Thread structure. if((t = idtotable(id)) == nil){ werrstr("no such thread"); return -1; } if(strcmp(msg, "kill") == 0) return ptrace(PT_KILL, t->pid, 0, 0); if(strcmp(msg, "start") == 0) return threadstart(t, 0); if(strcmp(msg, "stop") == 0) return threadstop(t); if(strcmp(msg, "startstop") == 0){ if(threadstart(t, 0) < 0) return -1; return waitstop(t); } if(strcmp(msg, "step") == 0){ if(threadstart(t, 1) < 0) return -1; return waitstop(t); } if(strcmp(msg, "waitstop") == 0) return waitstop(t); // sysstop not available on OS X werrstr("unknown control message"); return -1; }
// Add process pid to the thread table. // If it's already there, don't re-add it (unless force != 0). static Thread* addpid(int pid, int force) { int i, j; mach_port_t task; mach_port_t *thread; uint nthread; Thread *ret; static int first = 1; if(first){ // Allocate a port for exception messages and // send all thread exceptions to that port. // The excthread reads that port and signals // us if we are waiting on that thread. pthread_t p; excport = mach_reply_port(); pthread_mutex_init(&mu, nil); pthread_cond_init(&cond, nil); pthread_create(&p, nil, excthread, nil); pthread_create(&p, nil, waitthread, (void*)(uintptr)pid); first = 0; } if(!force){ for(i=0; i<nthr; i++) if(thr[i].pid == pid) return &thr[i]; } if(me(task_for_pid(mach_task_self(), pid, &task)) < 0) return nil; if(me(task_threads(task, &thread, &nthread)) < 0) return nil; mach_port_insert_right(mach_task_self(), excport, excport, MACH_MSG_TYPE_MAKE_SEND); if(me(task_set_exception_ports(task, ExcMask, excport, EXCEPTION_DEFAULT, MACHINE_THREAD_STATE)) < 0){ fprint(2, "warning: cannot set excport: %r\n"); } ret = nil; for(j=0; j<nthread; j++){ if(force){ // If we're forcing a refresh, don't re-add existing threads. for(i=0; i<nthr; i++) if(thr[i].pid == pid && thr[i].thread == thread[j]){ if(ret == nil) ret = &thr[i]; goto skip; } } if(nthr >= nelem(thr)) return nil; // TODO: We probably should save the old thread exception // ports for each bit and then put them back when we exit. // Probably the BSD signal handlers have put stuff there. mach_port_insert_right(mach_task_self(), excport, excport, MACH_MSG_TYPE_MAKE_SEND); if(me(thread_set_exception_ports(thread[j], ExcMask, excport, EXCEPTION_DEFAULT, MACHINE_THREAD_STATE)) < 0){ fprint(2, "warning: cannot set excport: %r\n"); } thr[nthr].pid = pid; thr[nthr].task = task; thr[nthr].thread = thread[j]; if(ret == nil) ret = &thr[nthr]; nthr++; skip:; } return ret; }
void die(char *s) { fprint(2, "%s\n", s); exits(s); }
void NPC_PetDel2( int meindex, int talker, int select, char *token) { int petindex; int selectpet; int emptyindex; char szPet[128]; int fd = getfdFromCharaIndex( talker ); if( fd == -1 ) { fprint( "err\n"); return; } // ʸÓÀÐþ·¸¡õÕý µÊ£ÛʸÓÀÐþ Øê ľ selectpet = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) -1; petindex = CHAR_getCharPet( talker, selectpet); if( !CHAR_CHECKINDEX( petindex) ) return; // Robin 0725 if (CHAR_getInt( talker, CHAR_RIDEPET ) == selectpet ) { /* char buf[1024]; lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OK, -1, -1, makeEscapeString("\n\nÆï³ËÖеijèÎïÎÞ·¨¼Ä·Åร¡", buf, sizeof(buf))); */ sprintf(token,"\n\nÆï³ËÖеijèÎïÎÞ·¨¼Ä·Åร¡"); return; } // ÎëÎåë¼ëÔÊ£Ûó¡±å¼ëØÆ»¯ÃñÄáÓÀÛÍØÆ»¯ÖÐÔ¼°Æ¥£Ý³ð³ðÆ¥ÎëÖл¯ÖÐئÖм°·´Ôƾ®ØÆÖÐ emptyindex = CHAR_getCharPoolPetElement( talker); if( emptyindex == -1 ) { fprint( "err\n"); return; } // ¾ô ÉÍ åÃʸÓÀÐþئÈգݹ«Ä¾¼°è¶ ëÛÕÔÊ£Û if( CHAR_getInt( talker, CHAR_DEFAULTPET) == selectpet) { CHAR_setInt( talker, CHAR_DEFAULTPET, -1); lssproto_KS_send( fd, -1, TRUE); } // Øê ľ ±å£ÝʸÓÀÐþ¼°Ä̼þ·¸ÓÀÛ͵©Ã«Îìñâ¡õ CHAR_setCharPoolPet( talker, emptyindex, petindex); // ʸÓÀÐþ ¾®ÈÕÛÕÔÊ CHAR_setCharPet( talker, selectpet, -1); // ¶ªÓÀ±¾¡õ³âäú NPC_MaxGoldOver( meindex, talker, NPC_PETSHOP_MSG_POOLTHANKS, token); // ÔÆàÅÓ¼ÈÕÔÊ CHAR_DelGold( talker, NPC_GETPOOLCOST( talker) ); // ÔÆàÅ·¸¡õÕý˪Ô CHAR_send_P_StatusString(talker,CHAR_P_STRING_GOLD); snprintf( szPet, sizeof( szPet ), "K%d", selectpet); // Þ¥ØÆÖÐʸÓÀÐþµ© ¡õÕýµ©ËªÔ»¹´ØêÔ CHAR_sendStatusString( talker, szPet ); // ʸÓÀÐþë ØêÐ×·òºë LogPet( CHAR_getChar( talker, CHAR_NAME ), /* ƽÅÒ·Â */ CHAR_getChar( talker, CHAR_CDKEY ), CHAR_getChar( petindex, CHAR_NAME), CHAR_getInt( petindex, CHAR_LV), "pool(¼Ä·Å³èÎïµê)", CHAR_getInt( talker,CHAR_FLOOR), CHAR_getInt( talker,CHAR_X ), CHAR_getInt( talker,CHAR_Y ), CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 ); }
void reader(void *v) { int cfd, tfd, forking = 0, exiting, pid; uintptr_t newpid; char *ctl, *truss; Str *s; static char start[] = "start"; static char waitstop[] = "waitstop"; pid = (int)(uintptr)v; if (debug) fprint(2, "DEBUG: -------------> reader starts with pid %d\n", pid); ctl = smprint("/proc/%d/ctl", pid); if ((cfd = open(ctl, OWRITE)) < 0) die(smprint("%s: %r", ctl)); truss = smprint("/proc/%d/syscall", pid); if ((tfd = open(truss, OREAD)) < 0) die(smprint("%s: %r", truss)); if (debug) fprint(2, "DEBUG: Send %s to pid %d ...", waitstop, pid); /* child was stopped by hang msg earlier */ cwrite(cfd, ctl, waitstop, sizeof waitstop - 1); if (debug) fprint(2, "DEBUG: back for %d\n", pid); if (debug) fprint(2, "DEBUG: Send %s to pid %d\n", "startsyscall", pid); cwrite(cfd, ctl, "startsyscall", 12); if (debug) fprint(2, "DEBUG: back for %d\n", pid); s = newstr(); exiting = 0; while((s->len = pread(tfd, s->buf, Bufsize - 1, 0)) >= 0){ if (s->buf[0] == 'F') { char *val = strstr(s->buf, "= "); if (val) { newpid = strtol(&val[2], 0, 0); sendp(forkc, (void*)newpid); procrfork(reader, (void*)newpid, Stacksize, 0); } } if (strstr(s->buf, " Exits") != nil) exiting = 1; sendp(out, s); /* print line from /proc/$child/syscall */ if (exiting) { s = newstr(); strcpy(s->buf, "\n"); sendp(out, s); break; } /* flush syscall trace buffer */ if (debug) fprint(2, "DEBUG: Send %s to pid %d\n", "startsyscall", pid); cwrite(cfd, ctl, "startsyscall", 12); if (debug) fprint(2, "DEBUG: back for %d\n", pid); s = newstr(); } sendp(quit, nil); threadexitsall(nil); }
void NPC_PetDel3( int meindex, int talker, int select, char *token) { int petindex; int selectpet; int emptyindex; char szPet[128]; int workindex[CHAR_MAXPOOLPETHAVE]; int i; int cnt; selectpet = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) ; petindex = CHAR_getCharPoolPet( talker, selectpet); if( !CHAR_CHECKINDEX( petindex) ) return; emptyindex = CHAR_getCharPetElement( talker); if( emptyindex == -1 ) { fprint( "err\n"); return; } // Èç¹ûÊÇÊØ»¤ÊÞ¸ÄΪÆÕͨÊÞ if( CHAR_getInt( petindex, CHAR_PETFAMILY) == 1 && CHAR_getInt( talker, CHAR_FMLEADERFLAG) != 3 ) { CHAR_setInt( petindex, CHAR_PETFAMILY, 0); CHAR_talkToCli( talker, -1, "ÊØ»¤ÊÞ¸ÄΪÆÕͨÊÞ", CHAR_COLORYELLOW); } CHAR_setCharPet( talker, emptyindex, petindex); CHAR_setCharPoolPet( talker, selectpet, -1); NPC_MaxGoldOver( meindex, talker, NPC_PETSHOP_MSG_POOLTHANKS, token); snprintf( szPet, sizeof( szPet ), "K%d", emptyindex); CHAR_sendStatusString( talker, szPet ); snprintf( szPet, sizeof( szPet), "W%d",emptyindex); CHAR_sendStatusString( talker, szPet ); for( i = 0; i < CHAR_MAXPOOLPETHAVE; i ++ ) { workindex[i] = -1; } cnt = 0; for( i = 0; i < CHAR_MAXPOOLPETHAVE; i ++ ) { int petindex = CHAR_getCharPoolPet( talker, i); if( CHAR_CHECKINDEX( petindex) ) { workindex[cnt++] = petindex; } } for( i = 0; i < CHAR_MAXPOOLPETHAVE; i ++ ) { CHAR_setCharPoolPet( talker, i, workindex[i]); } LogPet( CHAR_getChar( talker, CHAR_NAME ), CHAR_getChar( talker, CHAR_CDKEY ), CHAR_getChar( petindex, CHAR_NAME), CHAR_getInt( petindex, CHAR_LV), "draw(ÁìÈ¡³èÎïµê)", CHAR_getInt( talker,CHAR_FLOOR), CHAR_getInt( talker,CHAR_X ), CHAR_getInt( talker,CHAR_Y ), CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 ); #ifdef _PET_EVOLUTION if( CHAR_getInt( petindex, CHAR_FUSIONBEIT) == 1 && CHAR_getInt( petindex, CHAR_FUSIONRAISE) > 0 ){//¼ì²éÊÇ·ñΪÈںϳè CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, (int)time( NULL)); } #endif }
static int uboxInit(char* users, int len) { User *g, *u; Ubox *box, *obox; int blank, comment, i, nline, nuser; char *buf, *f[5], **line, *p, *q, *s; /* * Strip out whitespace and comments. * Note that comments are pointless, they disappear * when the server writes the database back out. */ blank = 1; comment = nline = 0; s = p = buf = vtMemAlloc(len+1); for(q = users; *q != '\0'; q++){ if(*q == '\r' || *q == '\t' || *q == ' ') continue; if(*q == '\n'){ if(!blank){ if(p != s){ *p++ = '\n'; nline++; s = p; } blank = 1; } comment = 0; continue; } if(*q == '#') comment = 1; blank = 0; if(!comment) *p++ = *q; } *p = '\0'; line = vtMemAllocZ((nline+2)*sizeof(char*)); if((i = gettokens(buf, line, nline+2, "\n")) != nline){ fprint(2, "nline %d (%d) botch\n", nline, i); vtMemFree(line); vtMemFree(buf); return 0; } /* * Everything is updated in a local Ubox until verified. */ box = vtMemAllocZ(sizeof(Ubox)); /* * First pass - check format, check for duplicates * and enter in hash buckets. */ nuser = 0; for(i = 0; i < nline; i++){ s = vtStrDup(line[i]); if(getfields(s, f, nelem(f), 0, ":") != 4){ fprint(2, "bad line '%s'\n", line[i]); vtMemFree(s); continue; } if(*f[0] == '\0' || *f[1] == '\0'){ fprint(2, "bad line '%s'\n", line[i]); vtMemFree(s); continue; } if(!validUserName(f[0])){ fprint(2, "invalid uid '%s'\n", f[0]); vtMemFree(s); continue; } if(_userByUid(box, f[0]) != nil){ fprint(2, "duplicate uid '%s'\n", f[0]); vtMemFree(s); continue; } if(!validUserName(f[1])){ fprint(2, "invalid uname '%s'\n", f[0]); vtMemFree(s); continue; } if(_userByUname(box, f[1]) != nil){ fprint(2, "duplicate uname '%s'\n", f[1]); vtMemFree(s); continue; } u = userAlloc(f[0], f[1]); uboxAddUser(box, u); line[nuser] = line[i]; nuser++; vtMemFree(s); } assert(box->nuser == nuser); /* * Second pass - fill in leader and group information. */ for(i = 0; i < nuser; i++){ s = vtStrDup(line[i]); getfields(s, f, nelem(f), 0, ":"); assert(g = _userByUname(box, f[1])); if(*f[2] != '\0'){ if((u = _userByUname(box, f[2])) == nil) g->leader = vtStrDup(g->uname); else g->leader = vtStrDup(u->uname); box->len += strlen(g->leader); } for(p = f[3]; p != nil; p = q){ if((q = utfrune(p, L',')) != nil) *q++ = '\0'; if(!_groupAddMember(box, g, p)){ // print/log error here } } vtMemFree(s); } vtMemFree(line); vtMemFree(buf); for(i = 0; usersMandatory[i] != nil; i++){ if((u = _userByUid(box, usersMandatory[i])) == nil){ vtSetError("user '%s' is mandatory", usersMandatory[i]); uboxFree(box); return 0; } if(strcmp(u->uid, u->uname) != 0){ vtSetError("uid/uname for user '%s' must match", usersMandatory[i]); uboxFree(box); return 0; } } vtLock(ubox.lock); obox = ubox.box; ubox.box = box; vtUnlock(ubox.lock); if(obox != nil) uboxFree(obox); return 1; }
int replacekey(char *keyfile, char *host, RSApub *hostkey) { char *h, *nkey, *p; Biobuf *br, *bw; Dir *d, nd; RSApub *k; nkey = smprint("%s.new", keyfile); if(nkey == nil) return -1; if((br = Bopen(keyfile, OREAD)) == nil){ free(nkey); return -1; } if((bw = Bopen(nkey, OWRITE)) == nil){ Bterm(br); free(nkey); return -1; } while((k = readpublickey(br, &h)) != nil){ if(match(h, host) != 0){ Bprint(bw, "%s %d %.10B %.10B\n", h, mpsignif(k->n), k->ek, k->n); } free(h); rsapubfree(k); } Bprint(bw, "%s %d %.10B %.10B\n", host, mpsignif(hostkey->n), hostkey->ek, hostkey->n); Bterm(bw); Bterm(br); d = dirstat(nkey); if(d == nil){ fprint(2, "new key file disappeared?\n"); free(nkey); return -1; } p = strrchr(d->name, '.'); if(p==nil || strcmp(p, ".new")!=0){ fprint(2, "new key file changed names? %s to %s\n", nkey, d->name); free(d); free(nkey); return -1; } *p = '\0'; nulldir(&nd); nd.name = d->name; if(remove(keyfile) < 0){ fprint(2, "error removing %s: %r\n", keyfile); free(d); free(nkey); return -1; } if(dirwstat(nkey, &nd) < 0){ fprint(2, "error renaming %s to %s: %r\n", nkey, d->name); free(nkey); free(d); return -1; } free(d); free(nkey); return 0; }
void ldobj1(Biobuf *f, char *pkg, int64 len, char *pn) { vlong ipc; Prog *p; int v, o, r, skip, mode; Sym *h[NSYM], *s; uint32 sig; char *name, *x; int ntext; vlong eof; char src[1024]; Prog *lastp; lastp = nil; ntext = 0; eof = Boffset(f) + len; src[0] = 0; newloop: memset(h, 0, sizeof(h)); version++; histfrogp = 0; ipc = pc; skip = 0; mode = 64; loop: if(f->state == Bracteof || Boffset(f) >= eof) goto eof; o = BGETC(f); if(o == Beof) goto eof; o |= BGETC(f) << 8; if(o <= AXXX || o >= ALAST) { if(o < 0) goto eof; diag("%s:#%lld: opcode out of range: %#ux", pn, Boffset(f), o); print(" probably not a .6 file\n"); errorexit(); } if(o == ANAME || o == ASIGNAME) { sig = 0; if(o == ASIGNAME) sig = Bget4(f); v = BGETC(f); /* type */ o = BGETC(f); /* sym */ r = 0; if(v == D_STATIC) r = version; name = Brdline(f, '\0'); if(name == nil) { if(Blinelen(f) > 0) { fprint(2, "%s: name too long\n", pn); errorexit(); } goto eof; } x = expandpkg(name, pkg); s = lookup(x, r); if(x != name) free(x); if(debug['S'] && r == 0) sig = 1729; if(sig != 0) { if(s->sig != 0 && s->sig != sig) diag("incompatible type signatures " "%ux(%s) and %ux(%s) for %s", s->sig, s->file, sig, pn, s->name); s->sig = sig; s->file = pn; } if(debug['W']) print(" ANAME %s\n", s->name); if(o < 0 || o >= nelem(h)) mangle(pn); h[o] = s; if((v == D_EXTERN || v == D_STATIC) && s->type == 0) s->type = SXREF; if(v == D_FILE) { if(s->type != SFILE) { histgen++; s->type = SFILE; s->value = histgen; } if(histfrogp < MAXHIST) { histfrog[histfrogp] = s; histfrogp++; } else collapsefrog(s); dwarfaddfrag(s->value, s->name); } goto loop; } p = mal(sizeof(*p)); p->as = o; p->line = Bget4(f); p->back = 2; p->mode = mode; p->ft = 0; p->tt = 0; zaddr(pn, f, &p->from, h); fromgotype = adrgotype; zaddr(pn, f, &p->to, h); switch(p->as) { case ATEXT: case ADATA: case AGLOBL: if(p->from.sym == S) mangle(pn); break; } if(debug['W']) print("%P\n", p); switch(p->as) { case AHISTORY: if(p->to.offset == -1) { addlib(src, pn); histfrogp = 0; goto loop; } if(src[0] == '\0') copyhistfrog(src, sizeof src); addhist(p->line, D_FILE); /* 'z' */ if(p->to.offset) addhist(p->to.offset, D_FILE1); /* 'Z' */ histfrogp = 0; goto loop; case AEND: histtoauto(); if(cursym != nil && cursym->text) cursym->autom = curauto; curauto = 0; cursym = nil; if(Boffset(f) == eof) return; goto newloop; case AGLOBL: s = p->from.sym; if(s->type == 0 || s->type == SXREF) { s->type = SBSS; s->size = 0; } if(s->type != SBSS && s->type != SNOPTRBSS && !s->dupok) { diag("%s: redefinition: %s in %s", pn, s->name, TNAME); s->type = SBSS; s->size = 0; } if(p->to.offset > s->size) s->size = p->to.offset; if(p->from.scale & DUPOK) s->dupok = 1; if(p->from.scale & RODATA) s->type = SRODATA; else if(p->from.scale & NOPTR) s->type = SNOPTRBSS; goto loop; case ADATA: // Assume that AGLOBL comes after ADATA. // If we've seen an AGLOBL that said this sym was DUPOK, // ignore any more ADATA we see, which must be // redefinitions. s = p->from.sym; if(s->dupok) { // if(debug['v']) // Bprint(&bso, "skipping %s in %s: dupok\n", s->name, pn); goto loop; } if(s->file == nil) s->file = pn; else if(s->file != pn) { diag("multiple initialization for %s: in both %s and %s", s->name, s->file, pn); errorexit(); } savedata(s, p, pn); unmal(p, sizeof *p); goto loop; case AGOK: diag("%s: GOK opcode in %s", pn, TNAME); pc++; goto loop; case ATEXT: s = p->from.sym; if(s->text != nil) { if(p->from.scale & DUPOK) { skip = 1; goto casdef; } diag("%s: %s: redefinition", pn, s->name); return; } if(ntext++ == 0 && s->type != 0 && s->type != SXREF) { /* redefinition, so file has probably been seen before */ if(debug['v']) Bprint(&bso, "skipping: %s: redefinition: %s", pn, s->name); return; } if(cursym != nil && cursym->text) { histtoauto(); cursym->autom = curauto; curauto = 0; } skip = 0; if(etextp) etextp->next = s; else textp = s; etextp = s; s->text = p; cursym = s; if(s->type != 0 && s->type != SXREF) { if(p->from.scale & DUPOK) { skip = 1; goto casdef; } diag("%s: redefinition: %s\n%P", pn, s->name, p); } if(fromgotype) { if(s->gotype && s->gotype != fromgotype) diag("%s: type mismatch for %s", pn, s->name); s->gotype = fromgotype; } s->type = STEXT; s->value = pc; lastp = p; p->pc = pc++; goto loop; case AMODE: if(p->from.type == D_CONST || p->from.type == D_INDIR+D_NONE) { switch((int)p->from.offset) { case 16: case 32: case 64: mode = p->from.offset; break; } } goto loop; case AFMOVF: case AFADDF: case AFSUBF: case AFSUBRF: case AFMULF: case AFDIVF: case AFDIVRF: case AFCOMF: case AFCOMFP: case AMOVSS: case AADDSS: case ASUBSS: case AMULSS: case ADIVSS: case ACOMISS: case AUCOMISS: if(skip) goto casdef; if(p->from.type == D_FCONST) { /* size sb 9 max */ sprint(literal, "$%ux", ieeedtof(&p->from.ieee)); s = lookup(literal, 0); if(s->type == 0) { s->type = SRODATA; adduint32(s, ieeedtof(&p->from.ieee)); s->reachable = 0; } p->from.type = D_EXTERN; p->from.sym = s; p->from.offset = 0; } goto casdef; case AFMOVD: case AFADDD: case AFSUBD: case AFSUBRD: case AFMULD: case AFDIVD: case AFDIVRD: case AFCOMD: case AFCOMDP: case AMOVSD: case AADDSD: case ASUBSD: case AMULSD: case ADIVSD: case ACOMISD: case AUCOMISD: if(skip) goto casdef; if(p->from.type == D_FCONST) { /* size sb 18 max */ sprint(literal, "$%ux.%ux", p->from.ieee.l, p->from.ieee.h); s = lookup(literal, 0); if(s->type == 0) { s->type = SRODATA; adduint32(s, p->from.ieee.l); adduint32(s, p->from.ieee.h); s->reachable = 0; } p->from.type = D_EXTERN; p->from.sym = s; p->from.offset = 0; } goto casdef; casdef: default: if(skip) nopout(p); p->pc = pc; pc++; if(p->to.type == D_BRANCH) p->to.offset += ipc; if(lastp == nil) { if(p->as != ANOP) diag("unexpected instruction: %P", p); goto loop; } lastp->link = p; lastp = p; goto loop; } eof: diag("truncated object file: %s", pn); }
void usage(void) { fprint(2, "usage: rdarena [-v] arenapart arena\n"); threadexitsall(0); }
int work(Node *node, Node *p, Arc *parc) { Arc *a, *ra; int weoutofdate; int ready; int did = 0; /*print("work(%s) flags=0x%x time=%ld\n", node->name, node->flags, node->time); */ if(node->flags&BEINGMADE) return(did); if((node->flags&MADE) && (node->flags&PRETENDING) && p && outofdate(p, parc, 0)){ if(explain) fprint(1, "unpretending %s(%ld) because %s is out of date(%ld)\n", node->name, node->time, p->name, p->time); unpretend(node); } /* have a look if we are pretending in case someone has been unpretended out from underneath us */ if(node->flags&MADE){ if(node->flags&PRETENDING){ node->time = 0; }else return(did); } /* consider no prerequsite case */ if(node->prereqs == 0){ if(node->time == 0){ fprint(2, "mk: don't know how to make '%s' in %s\n", node->name, dir()); if(kflag){ node->flags |= BEINGMADE; runerrs++; } else Exit(); } else MADESET(node, MADE); return(did); } /* now see if we are out of date or what */ ready = 1; weoutofdate = aflag; ra = 0; for(a = node->prereqs; a; a = a->next) if(a->n){ did = work(a->n, node, a) || did; if(a->n->flags&(NOTMADE|BEINGMADE)) ready = 0; if(outofdate(node, a, 0)){ weoutofdate = 1; if((ra == 0) || (ra->n == 0) || (ra->n->time < a->n->time)) ra = a; } } else { if(node->time == 0){ if(ra == 0) ra = a; weoutofdate = 1; } } if(ready == 0) /* can't do anything now */ return(did); if(weoutofdate == 0){ MADESET(node, MADE); return(did); } /* can we pretend to be made? */ if((iflag == 0) && (node->time == 0) && (node->flags&(PRETENDING|CANPRETEND)) && p && ra->n && !outofdate(p, ra, 0)){ node->flags &= ~CANPRETEND; MADESET(node, MADE); if(explain && ((node->flags&PRETENDING) == 0)) fprint(1, "pretending %s has time %ld\n", node->name, node->time); node->flags |= PRETENDING; return(did); } /* node is out of date and we REALLY do have to do something. quickly rescan for pretenders */ for(a = node->prereqs; a; a = a->next) if(a->n && (a->n->flags&PRETENDING)){ if(explain) Bprint(&bout, "unpretending %s because of %s because of %s\n", a->n->name, node->name, ra->n? ra->n->name : "rule with no prerequisites"); unpretend(a->n); did = work(a->n, node, a) || did; ready = 0; } if(ready == 0) /* try later unless nothing has happened for -k's sake */ return(did || work(node, p, parc)); did = dorecipe(node) || did; return(did); }
static void loadfont(int n, int s) { char file[100]; int i, fd, t, deep; static char *try[3] = {"", "times/R.", "pelm/"}; Subfont *f; Font *ff; try[0] = fname[n]; dprint(2, "loadfont %d %d\n", n, s); for (t = 0; t < 3; t++){ i = s * mag * charmap[fmap[n]].xheight/0.72; /* a pixel is 0.72 points */ if (i < MINSIZE) i = MINSIZE; dprint(2, "size %d, i %d, mag %g\n", s, i, mag); for(; i >= MINSIZE; i--){ /* if .font file exists, take that */ sprint(file, "%s/%s%d.font", libfont, try[t], i); ff = openfont(display, file); if(ff != 0){ fonttab[n][s] = ff; dprint(2, "using %s for font %d %d\n", file, n, s); return; } /* else look for a subfont file */ for (deep = drawlog2[screen->depth]; deep >= 0; deep--){ sprint(file, "%s/%s%d.%d", libfont, try[t], i, deep); dprint(2, "trying %s for %d\n", file, i); if ((fd = open(file, 0)) >= 0){ f = readsubfont(display, file, fd, 0); if (f == 0) { fprint(2, "can't rdsubfontfile %s: %r\n", file); exits("rdsubfont"); } close(fd); ff = mkfont(f, 0); if(ff == 0){ fprint(2, "can't mkfont %s: %r\n", file); exits("rdsubfont"); } fonttab[n][s] = ff; dprint(2, "using %s for font %d %d\n", file, n, s); return; } } } } fprint(2, "can't find font %s.%d or substitute, quitting\n", fname[n], s); exits("no font"); } void loadfontname(int n, char *s) { int i; Font *f, *g = 0; if (strcmp(s, fname[n]) == 0) return; if(fname[n] && fname[n][0]){ if(lastload[n] && strcmp(lastload[n], fname[n]) == 0) return; strcpy(lastload[n], fname[n]); } fontlookup(n, s); for (i = 0; i < NSIZE; i++) if (f = fonttab[n][i]){ if (f != g) { freefont(f); g = f; } fonttab[n][i] = 0; } } void allfree(void) { int i; for (i=0; i<NFONT; i++) loadfontname(i, "??"); } void readmapfile(char *file) { Biobuf *fp; char *p, cmd[100]; if ((fp=Bopen(file, OREAD)) == 0){ fprint(2, "proof: can't open map file %s\n", file); exits("urk"); } while((p=Brdline(fp, '\n')) != 0) { p[Blinelen(fp)-1] = 0; scanstr(p, cmd, 0); if(p[0]=='\0' || eq(cmd, "#")) /* skip comments, empty */ continue; else if(eq(cmd, "xheight")) buildxheight(fp); else if(eq(cmd, "map")) buildmap(fp); else if(eq(cmd, "special")) buildtroff(p); else if(eq(cmd, "troff")) buildtroff(p); else fprint(2, "weird map line %s\n", p); } Bterm(fp); }
void usage(void) { fprint(2, "usage: %s [-d dictname] [pattern]\n", argv0); threadexitsall(nil); }
void usage(void) { fprint(2, "usage: fossil/view /dev/sdC0/fossil\n"); threadexitsall("usage"); }
void interrupt_handler(registers_t registers) { fprint("Interrupt received: %d\n", registers.int_no); }
void usage(void) { fprint(2, "Usage: ratrace [-c cmd [arg...]] | [pid]\n"); exits("usage"); }
void main(int argc, char *argv[]) { int y, i, j, m; if(argc > 3) { fprint(2, "usage: cal [month] [year]\n"); exits("usage"); } Binit(&bout, 1, OWRITE); /* * no arg, print current month */ if(argc == 1) { m = curmo(); y = curyr(); goto xshort; } /* * one arg * if looks like a month, print month * else print year */ if(argc == 2) { y = number(argv[1]); if(y < 0) y = -y; if(y >= 1 && y <= 12) { m = y; y = curyr(); goto xshort; } goto xlong; } /* * two arg, month and year */ m = number(argv[1]); if(m < 0) m = -m; y = number(argv[2]); goto xshort; /* * print out just month */ xshort: if(m < 1 || m > 12) goto badarg; if(y < 1 || y > 9999) goto badarg; Bprint(&bout, " %s %ud\n", smon[m-1], y); Bprint(&bout, "%s\n", dayw); cal(m, y, string, 24); for(i=0; i<6*24; i+=24) pstr(string+i, 24); exits(0); /* * print out complete year */ xlong: y = number(argv[1]); if(y<1 || y>9999) goto badarg; Bprint(&bout, "\n\n\n"); Bprint(&bout, " %ud\n", y); Bprint(&bout, "\n"); for(i=0; i<12; i+=3) { for(j=0; j<6*72; j++) string[j] = '\0'; Bprint(&bout, " %.3s", smon[i]); Bprint(&bout, " %.3s", smon[i+1]); Bprint(&bout, " %.3s\n", smon[i+2]); Bprint(&bout, "%s %s %s\n", dayw, dayw, dayw); cal(i+1, y, string, 72); cal(i+2, y, string+23, 72); cal(i+3, y, string+46, 72); for(j=0; j<6*72; j+=72) pstr(string+j, 72); } Bprint(&bout, "\n\n\n"); exits(0); badarg: Bprint(&bout, "cal: bad argument\n"); }
static VtFile * vtfilealloc(VtCache *c, VtBlock *b, VtFile *p, u32int offset, int mode) { int epb; u32int size; VtEntry e; VtFile *r; assert(p==nil || ISLOCKED(p)); if(p == nil){ assert(offset == 0); epb = 1; }else epb = p->dsize / VtEntrySize; if(b->type != VtDirType){ werrstr("bad block type %#uo", b->type); return nil; } /* * a non-active entry is the only thing that * can legitimately happen here. all the others * get prints. */ if(vtentryunpack(&e, b->data, offset % epb) < 0){ fprint(2, "vtentryunpack failed: %r (%.*H)\n", VtEntrySize, b->data+VtEntrySize*(offset%epb)); return nil; } if(!(e.flags & VtEntryActive)){ werrstr("entry not active"); return nil; } if(DEPTH(e.type) < sizetodepth(e.size, e.psize, e.dsize)){ fprint(2, "depth %ud size %llud psize %ud dsize %ud\n", DEPTH(e.type), e.size, e.psize, e.dsize); werrstr("bad depth"); return nil; } size = vtcacheblocksize(c); if(e.dsize > size || e.psize > size){ werrstr("block sizes %ud, %ud bigger than cache block size %ud", e.psize, e.dsize, size); return nil; } r = vtmallocz(sizeof(VtFile)); r->c = c; r->mode = mode; r->dsize = e.dsize; r->psize = e.psize; r->gen = e.gen; r->dir = (e.type & VtTypeBaseMask) == VtDirType; r->ref = 1; r->parent = p; if(p){ qlock(&p->lk); assert(mode == VtOREAD || p->mode == VtORDWR); p->ref++; qunlock(&p->lk); }else{ assert(b->addr != NilBlock); r->local = 1; } memmove(r->score, b->score, VtScoreSize); r->offset = offset; r->epb = epb; return r; }