static int parsenumber(Parser *p, JSON *parent, JSON **prev) { char c; JSON *v = inititem(p, parent, prev, '0'); if (*p->s == '-') { p->s++; } c = *p->s; if ('0' <= c && c <= '9') { p->s++; if (c != '0') { scandigits(p); } } else { return 0; } if (*p->s == '.') { p->s++; must('0' <= *p->s && *p->s <= '9'); scandigits(p); } if (*p->s == 'e' || *p->s == 'E') { p->s++; if (*p->s == '+' || *p->s == '-') { p->s++; } must('0' <= *p->s && *p->s <= '9'); scandigits(p); } if (v) { v->end = p->s; } return 1; }
static int parsestring(Parser *p, JSON *parent, JSON **prev) { JSON *v = inititem(p, parent, prev, '"'); p->s++; // consume " while (*p->s != '"') { char c = *p->s; must(c >= ' '); // no control chars p->s++; if (c == '\\') { switch (c = *p->s++) { case 'b': case 'f': case 'n': case 'r': case 't': case '"': case '\\': case '/': continue; case 'u': must(scanhex4(p)); continue; } return 0; } } p->s++; // consume " if (v) { v->end = p->s; } return 1; }
static int parsetrue(Parser *p, JSON *parent, JSON **prev) { JSON *v = inititem(p, parent, prev, 't'); must(consume(p, "true")); if (v) { v->end = p->s; } return 1; }
static int parsenull(Parser *p, JSON *parent, JSON **prev) { JSON *v = inititem(p, parent, prev, 'n'); must(consume(p, "null")); if (v) { v->end = p->s; } return 1; }
int moveitem(char *path,int num) { if(inititem(path)) return 1; if(num<=0) num=1; if(num>=total) num=total; if(num==index_infile[0]) { printf("顺序一样,没有移动"); return 1; } char fpath[PATHLEN]; sprintf(fpath,"%s/.Names",path); FILE *fp=fopen(fpath,"w+"); if(fp==0) return 1; addtitle(fp,title); int j=0; int i; if(index_infile[0]<num)//后移 for(i=0;i<total;i++) { if(i==(index_infile[0]-1)) continue; additem(fp,a[i].title,a[i].path,++j); if((i+1)==num) additem(fp,a[index_infile[0]-1].title,a[index_infile[0]-1].path,++j); } else//前移 for(i=0;i<total;i++) { if(i==(index_infile[0]-1)) continue; if((i+1)==num) additem(fp,a[index_infile[0]-1].title,a[index_infile[0]-1].path,++j); additem(fp,a[i].title,a[i].path,++j); } fclose(fp); return 0; }
static int parsearray(Parser *p, JSON *parent, JSON **prev) { JSON *v = inititem(p, parent, prev, '['); must(consume(p, "[")); skipws(p); if (*p->s != ']') { JSON *aprev = nil; must(parsevalue(p, v, &aprev)); for (skipws(p); *p->s == ','; skipws(p)) { p->s++; // consume , skipws(p); must(parsevalue(p, v, &aprev)); } } must(consume(p, "]")); if (v) { v->end = p->s; } return 1; }
static int parseobject(Parser *p, JSON *parent, JSON **prev) { JSON *kprev = nil, *vprev = nil; JSON *v = inititem(p, parent, prev, '{'); must(consume(p, "{")); skipws(p); if (*p->s != '}') { must(parsepair(p, v, &kprev, &vprev)); for (skipws(p); *p->s == ','; skipws(p)) { p->s++; // consume , skipws(p); must(parsepair(p, v, &kprev, &vprev)); } } must(consume(p, "}")); if (v) { v->end = p->s; } return 1; }
int main(int argc, char *argv[]) { int continuing = 0; int count; int scores_only = 0; int i; #ifndef NOGETOPT while(( i= getopt( argc, argv, "dsh")) != -1) { switch (i) { case 'd': #ifdef DEBUG DG_debug_flag++; #endif break; case 's': scores_only = 1; break; case 'h': #ifdef DEBUG printf("Usage: omega [-shd] [savefile]\n"); #else printf("Usage: omega [-sh] [savefile]\n"); #endif printf("Options:\n"); printf(" -s Display high score list\n"); printf(" -h Display this message\n"); #ifdef DEBUG printf(" -d Enable debug mode\n"); #endif exit(0); break; case '?': /* error parsing args... ignore? */ printf("'%c' is an invalid option, ignoring\n", optopt ); break; } } if (optind >= argc ) { /* no save file given */ #if defined( BSD ) || defined( SYSV ) sprintf( SaveFileName, "Omega%d", getuid() ); #else strcpy( SaveFileName,"Omega"); #endif } else { /* savefile given */ continuing = 1; strcpy(SaveFileName,argv[optind]); } #else /* alternate code for people who don't support getopt() -- no enhancement */ if (argc ==2) { strcpy( SaveFileName, argv[1]); continuing = 1; } else { strcpy( SaveFileName,"Omega"); } #endif /* always catch ^c and hang-up signals */ #ifdef SIGINT signal(SIGINT,signalquit); #endif #ifdef SIGHUP signal(SIGHUP,signalsave); #endif #ifndef MSDOS if (CATCH_SIGNALS) { signal(SIGQUIT,signalexit); signal(SIGILL,signalexit); #ifdef DEBUG if( DG_debug_flag ) { #endif signal(SIGTRAP,signalexit); signal(SIGFPE,signalexit); signal(SIGSEGV,signalexit); #ifdef DEBUG } #endif #ifdef SIGIOT signal(SIGIOT,signalexit); #endif #ifdef SIGABRT signal(SIGABRT,signalexit); #endif #ifdef SIGEMT signal(SIGEMT,signalexit); #endif #ifdef SIGBUS signal(SIGBUS,signalexit); #endif #ifdef SIGSYS signal(SIGSYS,signalexit); #endif } #endif #ifndef FIXED_OMEGALIB if (!(Omegalib = getenv("OMEGALIB"))) #endif Omegalib = OMEGALIB; /* if filecheck is 0, some necessary data files are missing */ if (filecheck() == 0) exit(0); /* all kinds of initialization */ init_perms(); initgraf(); #ifndef MSDOS_SUPPORTED_ANTIQUE initdirs(); #endif initrand(E_RANDOM, 0); initspells(); #ifdef DEBUG /* initialize debug log file */ DG_debug_log = fopen( "/tmp/omega_dbg_log", "a" ); assert( DG_debug_log ); /* WDT :) */ setvbuf( DG_debug_log, NULL, _IOLBF, 0); fprintf(DG_debug_log, "############## new game started ##############\n"); #endif for (count = 0; count < STRING_BUFFER_SIZE; count++) strcpy(Stringbuffer[count],"<nothing>"); #ifdef SAVE_LEVELS msdos_init(); #endif omega_title(); showscores(); if (scores_only ) { endgraf(); exit(0); } /* game restore attempts to restore game if there is an argument */ if (continuing) { game_restore(SaveFileName); mprint("Your adventure continues...."); } else { /* monsters initialized in game_restore if game is being restored */ /* items initialized in game_restore if game is being restored */ inititem(TRUE); Date = random_range(360); Phase = random_range(24); #ifdef NEW_BANK bank_init(); #else strcpy(Password,""); #endif continuing = initplayer(); /* RM: 04-19-2000 loading patch */ } if (!continuing) { init_world(); /* RM: 04-19-2000 loading patch */ mprint("'?' for help or commandlist, 'Q' to quit."); } timeprint(); calc_melee(); if (Current_Environment != E_COUNTRYSIDE) showroom(Level->site[Player.x][Player.y].roomnumber); else terrain_check(FALSE); if (optionp(SHOW_COLOUR)) colour_on(); else colour_off(); screencheck(Player.x,Player.y); /* game cycle */ if (!continuing) time_clock(TRUE); while (TRUE) { if (Current_Environment == E_COUNTRYSIDE) p_country_process(); else time_clock(FALSE); } }