Esempio n. 1
0
/*
 * scan:
 *	Turn on or increase length of a scan
 */
static void
scan(PLAYER *pp)
{
	/* Check configuration: */
	if (!conf_scan)
		return;

	/* Can we afford it?: */
	if (pp->p_ammo <= 0) {
		message(pp, "No more charges");
		return;
	}

	/* Consume one unit of ammo: */
	pp->p_ammo--;
	ammo_update(pp);

	/* Increase the scan time: */
	pp->p_scan += Nplayer * conf_scanlen;

	/* Disable cloak, if enabled: */
	if (pp->p_cloak >= 0)
		pp->p_cloak = -1;

	/* Re-draw the player's scan/cloak status: */
	showstat(pp);
}
Esempio n. 2
0
/*
 * cloak:
 *	Turn on or increase length of a cloak
 */
static void
cloak(PLAYER *pp)
{
	/* Check configuration: */
	if (!conf_cloak)
		return;

	/* Can we afford it?: */
	if (pp->p_ammo <= 0) {
		message(pp, "No more charges");
		return;
	}

	/* Can't cloak with boots: */
	if (pp->p_nboots > 0) {
		message(pp, "Boots are too noisy to cloak!");
		return;
	}

	/* Consume a unit of ammo: */
	pp->p_ammo--;
	ammo_update(pp);

	/* Add to the duration of a cloak: */
	pp->p_cloak += conf_cloaklen;

	/* Disable scan, if enabled: */
	if (pp->p_scan >= 0)
		pp->p_scan = -1;

	/* Re-draw the player's scan/cloak status: */
	showstat(pp);
}
Esempio n. 3
0
/*
 * scan:
 *	Turn on or increase length of a scan
 */
static void
scan(PLAYER *pp)
{
	if (pp->p_ammo <= 0) {
		message(pp, "No more charges");
		return;
	}
	(void) snprintf(Buf, sizeof(Buf), "%3d", --pp->p_ammo);
	cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
	outstr(pp, Buf, 3);

	pp->p_scan += SCANLEN;

	if (pp->p_cloak >= 0)
		pp->p_cloak = -1;

	showstat(pp);
}
Esempio n. 4
0
/*
 * cloak:
 *	Turn on or increase length of a cloak
 */
static void
cloak(PLAYER *pp)
{
	if (pp->p_ammo <= 0) {
		message(pp, "No more charges");
		return;
	}
#ifdef BOOTS
	if (pp->p_nboots > 0) {
		message(pp, "Boots are too noisy to cloak!");
		return;
	}
#endif
	(void) snprintf(Buf, sizeof(Buf), "%3d", --pp->p_ammo);
	cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
	outstr(pp, Buf, 3);

	pp->p_cloak += CLOAKLEN;

	if (pp->p_scan >= 0)
		pp->p_scan = -1;

	showstat(pp);
}
Esempio n. 5
0
/*
 * move_flyer:
 *	Update the position of a player in flight
 */
static void
move_flyer(PLAYER *pp)
{
    int	x, y;

    if (pp->p_undershot) {
        fixshots(pp->p_y, pp->p_x, pp->p_over);
        pp->p_undershot = FALSE;
    }

    /* Restore what the flier was flying over */
    Maze[pp->p_y][pp->p_x] = pp->p_over;

    /* Fly: */
    x = pp->p_x + pp->p_flyx;
    y = pp->p_y + pp->p_flyy;

    /* Bouncing off the edges of the maze: */
    if (x < 1) {
        x = 1 - x;
        pp->p_flyx = -pp->p_flyx;
    }
    else if (x > WIDTH - 2) {
        x = (WIDTH - 2) - (x - (WIDTH - 2));
        pp->p_flyx = -pp->p_flyx;
    }
    if (y < 1) {
        y = 1 - y;
        pp->p_flyy = -pp->p_flyy;
    }
    else if (y > HEIGHT - 2) {
        y = (HEIGHT - 2) - (y - (HEIGHT - 2));
        pp->p_flyy = -pp->p_flyy;
    }

    /* Make sure we don't land on something we can't: */
again:
    switch (Maze[y][x]) {
    default:
        /*
         * Flier is over something other than space, a wall
         * or a door. Randomly move (drift) the flier a little bit
         * and then try again:
         */
        switch (rand_num(4)) {
        case 0:
            PLUS_DELTA(x, WIDTH - 2);
            break;
        case 1:
            MINUS_DELTA(x, 1);
            break;
        case 2:
            PLUS_DELTA(y, HEIGHT - 2);
            break;
        case 3:
            MINUS_DELTA(y, 1);
            break;
        }
        goto again;
    /* Give a little boost when about to land on a wall or door: */
    case WALL1:
    case WALL2:
    case WALL3:
    case WALL4:
    case WALL5:
    case DOOR:
        if (pp->p_flying == 0)
            pp->p_flying++;
        break;
    /* Spaces are okay: */
    case SPACE:
        break;
    }

    /* Update flier's coordinates: */
    pp->p_y = y;
    pp->p_x = x;

    /* Consume 'flying' time: */
    if (pp->p_flying-- == 0) {
        /* Land: */
        if (pp->p_face != BOOT && pp->p_face != BOOT_PAIR) {
            /* Land a player - they stustain a fall: */
            checkdam(pp, NULL, NULL,
                     rand_num(pp->p_damage / conf_fall_frac), FALL);
            pp->p_face = rand_dir();
            showstat(pp);
        } else {
            /* Land boots: */
            if (Maze[y][x] == BOOT)
                pp->p_face = BOOT_PAIR;
            Maze[y][x] = SPACE;
        }
    }

    /* Save under the flier: */
    pp->p_over = Maze[y][x];
    /* Draw in the flier: */
    Maze[y][x] = pp->p_face;
    showexpl(y, x, pp->p_face);
}
Esempio n. 6
0
/* set approx position -------------------------------------------------------*/
static void setapppos(strfile_t *str, rnxopt_t *opt)
{
    prcopt_t prcopt=prcopt_default;
    sol_t sol={{0}};
    char msg[128];
    
    prcopt.navsys=opt->navsys;
    
    /* point positioning with last obs data */
#ifdef WAAS_STUDY
    if (!pntpos(str->obs->data,str->obs->n,str->nav,&prcopt,&sol,NULL,NULL,
                NULL,msg)) {
#else
	if (!pntpos(str->obs->data,str->obs->n,str->nav,&prcopt,&sol,NULL,NULL,
			msg)) {
#endif
        trace(2,"point position error (%s)\n",msg);
        return;
    }
    matcpy(opt->apppos,sol.rr,3,1);
}
/* show status message -------------------------------------------------------*/
static int showstat(int sess, gtime_t ts, gtime_t te, int *n)
{
    const char type[]="ONGHQLSE";
    char msg[1024]="",*p=msg,s[64];
    int i;
    
    if (sess>0) {
        p+=sprintf(p,"(%d) ",sess);
    }
    if (ts.time!=0) {
        time2str(ts,s,0);
        p+=sprintf(p,"%s",s);
    }
    if (te.time!=0&&timediff(te,ts)>0.9) {
        time2str(te,s,0);
        p+=sprintf(p,"-%s",s+5);
    }
    p+=sprintf(p,": ");
    
    for (i=0;i<NOUTFILE+1;i++) {
        if (n[i]==0) continue;
        p+=sprintf(p,"%c=%d%s",type[i],n[i],i<NOUTFILE?" ":"");
    }
    return showmsg(msg);
}
/* rinex converter for single-session ----------------------------------------*/
static int convrnx_s(int sess, int format, rnxopt_t *opt, const char *file,
                     char **ofile)
{
    FILE *ofp[NOUTFILE]={NULL};
    strfile_t *str;
    gtime_t ts={0},te={0},tend={0},time={0};
    unsigned char slips[MAXSAT][NFREQ+NEXOBS]={{0}};
    int i,j,nf,type,n[NOUTFILE+1]={0},abort=0;
    char path[1024],*paths[NOUTFILE],s[NOUTFILE][1024];
    char *epath[MAXEXFILE]={0},*staid=*opt->staid?opt->staid:"0000";
    
    trace(3,"convrnx_s: sess=%d format=%d file=%s ofile=%s %s %s %s %s %s %s\n",
          sess,format,file,ofile[0],ofile[1],ofile[2],ofile[3],ofile[4],
          ofile[5],ofile[6]);
    
    /* replace keywords in input file */
    if (reppath(file,path,opt->ts,staid,"")<0) {
        showmsg("no time for input file: %s",file);
        return 0;
    }
    /* expand wild-cards in input file */
    for (i=0;i<MAXEXFILE;i++) {
        if (!(epath[i]=(char *)malloc(1024))) {
            for (i=0;i<MAXEXFILE;i++) free(epath[i]);
            return 0;
        }
    }
    nf=expath(path,epath,MAXEXFILE);
    
    if (format==STRFMT_RTCM2||format==STRFMT_RTCM3) time=opt->trtcm;
    
    if (opt->scanobs) {
        
        /* scan observation types */
        if (!scan_obstype(format,epath[0],opt,&time)) return 0;
    }
    else {
        /* set observation types by format */
        set_obstype(format,opt);
    }
    if (!(str=gen_strfile(format,opt->rcvopt,time))) {
        for (i=0;i<MAXEXFILE;i++) free(epath[i]);
        return 0;
    }
    time=opt->ts.time?opt->ts:(time.time?timeadd(time,TSTARTMARGIN):time);
    
    /* replace keywords in output file */
    for (i=0;i<NOUTFILE;i++) {
        paths[i]=s[i];
        if (reppath(ofile[i],paths[i],time,staid,"")<0) {
            showmsg("no time for output path: %s",ofile[i]);
            for (i=0;i<MAXEXFILE;i++) free(epath[i]);
            free_strfile(str);
            return 0;
        }
    }
    /* open output files */
    if (!openfile(ofp,paths,path,opt,str->nav)) {
        for (i=0;i<MAXEXFILE;i++) free(epath[i]);
        free_strfile(str);
        return 0;
    }
    for (i=0;i<nf&&!abort;i++) {
        
        /* open stream file */
        if (!open_strfile(str,epath[i])) continue;
        
        /* input message */
        for (j=0;(type=input_strfile(str))>=-1;j++) {
            
            if (j%11==1&&(abort=showstat(sess,te,te,n))) break;
            
            /* avioid duplicated if overlapped data */
            if (tend.time&&timediff(str->time,tend)<=0.0) continue;
            
            /* convert message */
            switch (type) {
                case  1: convobs(ofp,opt,str,n,slips); break;
                case  2: convnav(ofp,opt,str,n);       break;
                case  3: convsbs(ofp,opt,str,n);       break;
                case 31: convlex(ofp,opt,str,n);       break;
                case -1: n[NOUTFILE]++; break; /* error */
            }
            te=str->time; if (ts.time==0) ts=te;
            
            /* set approx position */
            if (type==1&&!opt->autopos&&norm(opt->apppos,3)<=0.0) {
                setapppos(str,opt);
            }
            if (opt->te.time&&timediff(te,opt->te)>10.0) break;
        }
        /* close stream file */
        close_strfile(str);
        
        tend=te; /* end time of a file */
    }
    /* set receiver and antenna information to option */
    if (format==STRFMT_RTCM2||format==STRFMT_RTCM3) {
        rtcm2opt(&str->rtcm,opt);
    }
    else if (format==STRFMT_RINEX) {
        rnx2opt(&str->rnx,opt);
    }
    /* close output files */
    closefile(ofp,opt,str->nav);
    
    /* remove empty output files */
    for (i=0;i<NOUTFILE;i++) {
        if (ofp[i]&&n[i]<=0) remove(ofile[i]);
    }
    if (ts.time>0) showstat(sess,ts,te,n);
    
    for (i=0;i<MAXEXFILE;i++) free(epath[i]);
    
    free_strfile(str);
    
    if (opt->tstart.time==0) opt->tstart=opt->ts;
    if (opt->tend  .time==0) opt->tend  =opt->te;
    
    return abort?-1:1;
}
Esempio n. 7
0
/* rinex converter for single-session ----------------------------------------*/
static int convrnx_s(int sess, int format, rnxopt_t *opt, const char *file,
                     char **ofile)
{
    FILE *ofp[NOUTFILE]={NULL};
    strfile_t *str;
    gtime_t ts={0},te={0},tend={0},time={0};
    unsigned char slips[MAXSAT][NFREQ+NEXOBS]={{0}};
    int i,j,nf,type,n[NOUTFILE+1]={0},abort=0;
    char path[1024],*paths[NOUTFILE],s[NOUTFILE][1024];
    char *epath[MAXEXFILE]={0},*staid=*opt->staid?opt->staid:"0000";
    
    trace(3,"convrnx_s: sess=%d format=%d file=%s ofile=%s %s %s %s %s %s %s\n",
          sess,format,file,ofile[0],ofile[1],ofile[2],ofile[3],ofile[4],
          ofile[5],ofile[6]);
    
    /* replace keywords in input file */
    if (reppath(file,path,opt->ts,staid,"")<0) {
        showmsg("no time for input file: %s",file);
        return 0;
    }
    /* expand wild-cards in input file */
    for (i=0;i<MAXEXFILE;i++) {
        if (!(epath[i]=(char *)malloc(1024))) {
            for (i=0;i<MAXEXFILE;i++) free(epath[i]);
            return 0;
        }
    }
    nf=expath(path,epath,MAXEXFILE);
    
    if (format==STRFMT_RTCM2||format==STRFMT_RTCM3) time=opt->trtcm;
    
    if (opt->scanobs) {
        
        /* scan observation types */
        if (!scan_obstype(format,epath[0],opt,&time)) return 0;
    }
    else {
        /* set observation types by format */
        set_obstype(format,opt);
    }
    if (!(str=gen_strfile(format,opt->rcvopt,time))) {
        for (i=0;i<MAXEXFILE;i++) free(epath[i]);
        return 0;
    }
    time=opt->ts.time?opt->ts:(time.time?timeadd(time,TSTARTMARGIN):time);
    
    /* replace keywords in output file */
    for (i=0;i<NOUTFILE;i++) {
        paths[i]=s[i];
        if (reppath(ofile[i],paths[i],time,staid,"")<0) {
            showmsg("no time for output path: %s",ofile[i]);
            for (i=0;i<MAXEXFILE;i++) free(epath[i]);
            free_strfile(str);
            return 0;
        }
    }
    /* open output files */
    if (!openfile(ofp,paths,path,opt,str->nav)) {
        for (i=0;i<MAXEXFILE;i++) free(epath[i]);
        free_strfile(str);
        return 0;
    }
    for (i=0;i<nf&&!abort;i++) {
        
        /* open stream file */
        if (!open_strfile(str,epath[i])) continue;
        
        /* input message */
        for (j=0;(type=input_strfile(str))>=-1;j++) {
            
            if (j%11==1&&(abort=showstat(sess,te,te,n))) break;
            
            /* avioid duplicated if overlapped data */
            if (tend.time&&timediff(str->time,tend)<=0.0) continue;
            
            /* convert message */
            switch (type) {
                case  1: convobs(ofp,opt,str,n,slips); break;
                case  2: convnav(ofp,opt,str,n);       break;
                case  3: convsbs(ofp,opt,str,n);       break;
                case 31: convlex(ofp,opt,str,n);       break;
                case -1: n[NOUTFILE]++; break; /* error */
            }
            te=str->time; if (ts.time==0) ts=te;
            
            /* set approx position */
            if (type==1&&!opt->autopos&&norm(opt->apppos,3)<=0.0) {
                setapppos(str,opt);
            }
            if (opt->te.time&&timediff(te,opt->te)>10.0) break;
        }
        /* close stream file */
        close_strfile(str);
        
        tend=te; /* end time of a file */
    }
    /* set receiver and antenna information to option */
    if (format==STRFMT_RTCM2||format==STRFMT_RTCM3) {
        rtcm2opt(&str->rtcm,opt);
    }
    else if (format==STRFMT_RINEX) {
        rnx2opt(&str->rnx,opt);
    }
    /* close output files */
    closefile(ofp,opt,str->nav);
    
    /* remove empty output files */
    for (i=0;i<NOUTFILE;i++) {
        if (ofp[i]&&n[i]<=0) remove(ofile[i]);
    }
    if (ts.time>0) showstat(sess,ts,te,n);
    
    for (i=0;i<MAXEXFILE;i++) free(epath[i]);
    
    free_strfile(str);
    
    if (opt->tstart.time==0) opt->tstart=opt->ts;
    if (opt->tend  .time==0) opt->tend  =opt->te;
    
    return abort?-1:1;
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
	struct option long_option[] =
	{
		{"help", 0, NULL, 'h'},
		{"pdevice", 1, NULL, 'P'},
		{"cdevice", 1, NULL, 'C'},
		{"min", 1, NULL, 'm'},
		{"max", 1, NULL, 'M'},
		{"frames", 1, NULL, 'F'},
		{"format", 1, NULL, 'f'},
		{"channels", 1, NULL, 'c'},
		{"rate", 1, NULL, 'r'},
		{"seconds", 1, NULL, 's'},
		{"block", 0, NULL, 'b'},
		{"time", 1, NULL, 't'},
		{"poll", 0, NULL, 'p'},
		{"effect", 0, NULL, 'e'},
		{NULL, 0, NULL, 0},
	};
	snd_pcm_t *phandle, *chandle;
	char *buffer;
	int err, latency, morehelp;
	int ok;
	snd_timestamp_t p_tstamp, c_tstamp;
	ssize_t r;
	size_t frames_in, frames_out, in_max;
	int effect = 0;
	morehelp = 0;
	while (1) {
		int c;
		if ((c = getopt_long(argc, argv, "hP:C:m:M:F:f:c:r:s:bt:pe", long_option, NULL)) < 0)
			break;
		switch (c) {
		case 'h':
			morehelp++;
			break;
		case 'P':
			pdevice = strdup(optarg);
			break;
		case 'C':
			cdevice = strdup(optarg);
			break;
		case 'm':
			err = atoi(optarg) / 2;
			latency_min = err >= 4 ? err : 4;
			if (latency_max < latency_min)
				latency_max = latency_min;
			break;
		case 'M':
			err = atoi(optarg) / 2;
			latency_max = latency_min > err ? latency_min : err;
			break;
		case 'f':
			format = snd_pcm_format_value(optarg);
			if (format == SND_PCM_FORMAT_UNKNOWN) {
				printf("Unknown format, setting to default S16_LE\n");
				format = SND_PCM_FORMAT_S16_LE;
			}
			break;
		case 'c':
			err = atoi(optarg);
			channels = err >= 1 && err < 1024 ? err : 1;
			break;
		case 'r':
			err = atoi(optarg);
			rate = err >= 4000 && err < 200000 ? err : 44100;
			break;
		case 's':
			err = atoi(optarg);
			loop_sec = err >= 1 && err <= 100000 ? err : 30;
			break;
		case 'b':
			block = 1;
			break;
		case 't':
			tick_time = atoi(optarg);
			tick_time = tick_time < 0 ? 0 : tick_time;
			break;
		case 'p':
			use_poll = 1;
			break;
		case 'e':
			effect = 1;
			break;
		}
	}

	if (morehelp) {
		help();
		return 0;
	}
	err = snd_output_stdio_attach(&output, stdout, 0);
	if (err < 0) {
		printf("Output failed: %s\n", snd_strerror(err));
		return 0;
	}

	loop_limit = loop_sec * rate;
	latency = latency_min - 4;
	buffer = malloc((latency_max * snd_pcm_format_width(format) / 8) * 2);

	setscheduler();

	printf("Playback device is %s\n", pdevice);
	printf("Capture device is %s\n", cdevice);
	printf("Parameters are %iHz, %s, %i channels, %s mode\n", rate, snd_pcm_format_name(format), channels, block ? "blocking" : "non-blocking");
	printf("Wanted tick time: %ius, poll mode: %s\n", tick_time, use_poll ? "yes" : "no");
	printf("Loop limit is %li frames, minimum latency = %i, maximum latency = %i\n", loop_limit, latency_min * 2, latency_max * 2);

	if ((err = snd_pcm_open(&phandle, pdevice, SND_PCM_STREAM_PLAYBACK, block ? 0 : SND_PCM_NONBLOCK)) < 0) {
		printf("Playback open error: %s\n", snd_strerror(err));
		return 0;
	}
	if ((err = snd_pcm_open(&chandle, cdevice, SND_PCM_STREAM_CAPTURE, block ? 0 : SND_PCM_NONBLOCK)) < 0) {
		printf("Record open error: %s\n", snd_strerror(err));
		return 0;
	}

	/* initialize the filter sweep variables */
	if (effect) {
		fs = (float) rate;
		BW = FILTER_BANDWIDTH;

		lfo = 0;
		dlfo = 2.*M_PI*FILTERSWEEP_LFO_FREQ/fs;

		x[0] = (float*) malloc(channels*sizeof(float));		
		x[1] = (float*) malloc(channels*sizeof(float));		
		x[2] = (float*) malloc(channels*sizeof(float));		
		y[0] = (float*) malloc(channels*sizeof(float));		
		y[1] = (float*) malloc(channels*sizeof(float));		
		y[2] = (float*) malloc(channels*sizeof(float));		
	}
			  
	while (1) {
		frames_in = frames_out = 0;
		if (setparams(phandle, chandle, &latency) < 0)
			break;
		showlatency(latency);
		if (tick_time_ok)
			printf("Using tick time %ius\n", tick_time_ok);
		if ((err = snd_pcm_link(chandle, phandle)) < 0) {
			printf("Streams link error: %s\n", snd_strerror(err));
			exit(0);
		}
		if (snd_pcm_format_set_silence(format, buffer, latency*channels) < 0) {
			fprintf(stderr, "silence error\n");
			break;
		}
		if (writebuf(phandle, buffer, latency, &frames_out) < 0) {
			fprintf(stderr, "write error\n");
			break;
		}
		if (writebuf(phandle, buffer, latency, &frames_out) < 0) {
			fprintf(stderr, "write error\n");
			break;
		}

		if ((err = snd_pcm_start(chandle)) < 0) {
			printf("Go error: %s\n", snd_strerror(err));
			exit(0);
		}
		gettimestamp(phandle, &p_tstamp);
		gettimestamp(chandle, &c_tstamp);
#if 0
		printf("Playback:\n");
		showstat(phandle, frames_out);
		printf("Capture:\n");
		showstat(chandle, frames_in);
#endif

		ok = 1;
		in_max = 0;
		while (ok && frames_in < loop_limit) {
			if (use_poll) {
				/* use poll to wait for next event */
				snd_pcm_wait(chandle, 1000);
			}
			if ((r = readbuf(chandle, buffer, latency, &frames_in, &in_max)) < 0)
				ok = 0;
			else {
				if (effect)
					applyeffect(buffer,r);
			 	if (writebuf(phandle, buffer, r, &frames_out) < 0)
					ok = 0;
			}
		}
		if (ok)
			printf("Success\n");
		else
			printf("Failure\n");
		printf("Playback:\n");
		showstat(phandle, frames_out);
		printf("Capture:\n");
		showstat(chandle, frames_in);
		showinmax(in_max);
		if (p_tstamp.tv_sec == p_tstamp.tv_sec &&
		    p_tstamp.tv_usec == c_tstamp.tv_usec)
			printf("Hardware sync\n");
		snd_pcm_drop(chandle);
		snd_pcm_nonblock(phandle, 0);
		snd_pcm_drain(phandle);
		snd_pcm_nonblock(phandle, !block ? 1 : 0);
		if (ok) {
#if 1
			printf("Playback time = %li.%i, Record time = %li.%i, diff = %li\n",
			       p_tstamp.tv_sec,
			       (int)p_tstamp.tv_usec,
			       c_tstamp.tv_sec,
			       (int)c_tstamp.tv_usec,
			       timediff(p_tstamp, c_tstamp));
#endif
			break;
		}
		snd_pcm_unlink(chandle);
		snd_pcm_hw_free(phandle);
		snd_pcm_hw_free(chandle);
	}
	snd_pcm_close(phandle);
	snd_pcm_close(chandle);
	return 0;
}
Esempio n. 9
0
void CWizDlg::from_readerwnd(short v, int v1, int v2, char *v3)
{
	switch ( v)
	{
	case 1: 
        // opened new file;                
        //MessageBeep(1);
		add_recent(CString(v3));					
        get_file_settings();
		m_name.SetWindowText(v3);
        wnd.update_viewPort(1);
        UpdateData();
		//check_bookm();
        first_e=false; // move mouse 		
        load_menub(NULL);	
        //*********************************


        //GetSettings(&Info,sizeof(Info),AfxGetApp()->m_pszRegistryKey);
        /*strcpy(str1,Info.key);              
        if ( !strchr(decode_b64(str1),'+') || ( (hash( strchr(str1+2,'+')+1 )/ 1000)+11 != strlen(str1+2) ) )
        {   
            str1[0] == '1';            
        } */                   
            
        //***************************************************
        
		/*{
			bool expiried=false;
			SYSTEMTIME time;
			FILETIME time2;
			char drv_str[MAX_PATH];
			char* s=drv_str;
			
			WIN32_FIND_DATA fnd;
			HANDLE done;
			bool find=false;
			char name[10];
			
			GetLocalTime(&time);
			if ( time.wMonth > 9 || time.wYear>2000)
			{
				expiried=true;			
			}
			SystemTimeToFileTime(&time,&time2);
			GetLogicalDriveStrings(49,drv_str);
			
				do
				{
					if ( GetDriveType(s)!=DRIVE_FIXED) { s+=4;      continue; }
					strcpy(name,s); strcat(name,"*.*");			
					if ( (done=FindFirstFile(name,&fnd))!=INVALID_HANDLE_VALUE )
						do
						{
							if ( CompareFileTime(&time2,&fnd.ftLastWriteTime)==-1 )
							{						
								expiried=true;
								break;						
							}
						}
						while ( FindNextFile(done,&fnd) );
						s+=4;
						
                } while ( *s );                
                
                GetWindowsDirectory(drv_str,MAX_PATH);
                strcat(drv_str,"\\*.*");		
                if ( (done=FindFirstFile(drv_str,&fnd))!=INVALID_HANDLE_VALUE )
                    do
                    {
                        if ( CompareFileTime(&time2,&fnd.ftLastWriteTime)==-1 )
                        {
                            expiried=true;
                            break;						
                        }
                    }
                    while ( FindNextFile(done,&fnd) );					                    
                    
                if (expiried)
                {
                    this->SendMessage(WM_SYSCOMMAND,SC_CLOSE	,0);
                    //this->EndDialog(1);	
                }
                if (expiried && wnd.isOpened() )
                {
                    wnd.CloseWindow();                                 
                }
        }*/
		
		//******************************
        //break;
    case 2:                 // page changed (pgUp/pgDn)		                
        showstat();
        check_bookm();            
        parse_templ(templ_str,Info.fonts[8].templ);            
        SetWindowText(templ_str);		        
        
        if (Info.show_bm && marked_page) wnd.draw_bm_lable(1);                
        break;
	case 3: OnBookText();                  // pressed "a"
		break;
	case 4: OnBookmm();                    // press "z"
		break;
	case 5: Info.lines=v1;                 // change number of lines ( sizes(); when ReadFile(); );
		    
		break;
	case 6:      //alt+a
		if ( marked_page ) break;		
		Recents.GetHead()->change_top(CString(""),wnd.get_dim(),0);
		load_menub();
		check_bookm();
        if (Info.show_bm && marked_page) wnd.draw_bm_lable(1);
		break;
	case 7:     //tab		
		if ( Recents.GetHead()->jmp_next() )
		wnd.Seek_to((Recents.GetHead())->cur_pos);
		break;
	case 8: // alt-m
		ShowTools(2);
		break;	
	case 9: //alt-f
		ShowTools(v1);
		break;	
    case 27: // close file;
        set_file_settings();
        break;


	}
	/*if (exprd)
		{
			this->SendMessage(WM_SYSCOMMAND,SC_CLOSE	,0);
			this->EndDialog(1);	
		}*/	
}
Esempio n. 10
0
void connection_client(int cfd, short event, void *arg)
{
    struct client_state *cs = arg;
    int cmd, break_out = 0;
    int uid = 0, index = 0;

    // ignore clients that timeout
    if (event & EV_TIMEOUT)
	cs->state = FSM_EXIT;

    if (event & EV_READ) {
	if (cs->state != FSM_ENTER) {
	    if (evbuffer_read(cs->evb, cfd, READ_BLOCK) <= 0)
		cs->state = FSM_EXIT;
	}
	else {
	    if (evbuffer_read(cs->evb, cfd, 4) <= 0)
		cs->state = FSM_EXIT;
	}
    }

    while (!break_out) {
	switch (cs->state) {
	    case FSM_ENTER:
		if (EVBUFFER_LENGTH(cs->evb) < sizeof(int)) {
		    break_out = 1;
		    break;
		}
		evbuffer_remove(cs->evb, &cmd, sizeof(cmd));
		if (cmd == -1)
		    cs->state = FSM_SYNC;
		else if (cmd == -2) {
		    fcntl(cfd, F_SETFL, fcntl(cfd, F_GETFL, 0) | O_NONBLOCK);
		    cs->state = FSM_LOGIN;
		}
		else if (cmd >= 0)
		    cs->state = FSM_EXIT;
		else {
		    printf("unknown cmd=%d\n",cmd);
		    cs->state = FSM_EXIT;
		}
		break;
	    case FSM_SYNC:
		syncutmp(cfd);
		firstsync = 1;
		cs->state = FSM_EXIT;
		break;
	    case FSM_LOGIN:
		if (firstsync) {
		    if (EVBUFFER_LENGTH(cs->evb) < (2 + MAX_FRIEND + MAX_REJECT) * sizeof(int)) {
			break_out = 1;
			break;
		    }
		    evbuffer_remove(cs->evb, &index, sizeof(index));
		    evbuffer_remove(cs->evb, &uid, sizeof(uid));
		    if (index >= USHM_SIZE || index < 0) {
			fprintf(stderr, "bad index=%d\n", index);
			cs->state = FSM_EXIT;
			break;
		    }
		    if (uid > MAX_USERS || uid <= 0) {
			fprintf(stderr, "bad uid=%d\n", uid);
			cs->state = FSM_EXIT;
			break;
		    }
		    count_login++;
		    processlogin(cs, uid, index);
		    if (count_login >= 4000 || (time(NULL) - begin_time) > 30*60)
			showstat();
		    cs->state = FSM_WRITEBACK;
		    break_out = 1;
		}
		else
		    cs->state = FSM_EXIT;
		break;
	    case FSM_WRITEBACK:
		if (event & EV_WRITE)
		    if (evbuffer_write(cs->evb, cfd) <= 0 && EVBUFFER_LENGTH(cs->evb) > 0)
			break_out = 1;
		if (EVBUFFER_LENGTH(cs->evb) == 0)
		    cs->state = FSM_EXIT;
		break;
	    case FSM_EXIT:
		if (clients == MAX_CLIENTS)
		    event_add(&ev, NULL);
		close(cfd);
		evbuffer_free(cs->evb);
		free(cs);
		clients--;
		return;
		break;
	}
    }
    if (cs->state == FSM_WRITEBACK)
	event_set(&cs->ev, cfd, EV_WRITE, (void *) connection_client, cs);
    event_add(&cs->ev, &tv);
}