示例#1
0
void displaysay(void) {
	struct SayString *pekare,*oldpek;
	int textlen;
	char tmpchar;
	pekare=Servermem->say[nodnr];
	Servermem->say[nodnr]=NULL;
	while(pekare) {
		if(pekare->fromuser == -1) strcpy(outbuffer,"\a\r\n\nSystemmeddelande");
		else sprintf(outbuffer,"\a\r\n\n%s",getusername(pekare->fromuser));
		textlen = strlen(pekare->text);
		puttekn(outbuffer,-1);
		if((strlen(outbuffer) + textlen) < 79) {
			sprintf(outbuffer,": %s\r\n",pekare->text);
			puttekn(outbuffer,-1);
		} else {
			puttekn(":\n\r",-1);
			if(textlen <= MAXSAYTKN-1) puttekn(pekare->text,-1);
			else {
				tmpchar = pekare->text[MAXSAYTKN-1];
				pekare->text[MAXSAYTKN-1] = 0;
				puttekn(pekare->text,-1);
				pekare->text[MAXSAYTKN-1] = tmpchar;
				puttekn(&pekare->text[MAXSAYTKN-1],-1);
			}
		}
		oldpek=pekare;
		pekare=oldpek->NextSay;
		FreeMem(oldpek,sizeof(struct SayString));
	}
	eka('\n');
}
示例#2
0
文件: NiKRexx.c 项目: dblarsson/NiKom
void rxsendchar(struct RexxMsg *mess) {
        char *arg;
        arg=hittaefter(mess->rm_Args[0]);
        if(arg[0]!='/' || arg[1]==0) {
                mess->rm_Result1=10;
                mess->rm_Result2=NULL;
                return;
        }
        eka(arg[1]);
        if(carrierdropped()) mess->rm_Result1=100;
        else mess->rm_Result1=0;
        mess->rm_Result2=NULL;
}
示例#3
0
void visafidobrev(struct ReadLetter *brevread, BPTR fh, int brev, int anv) {
        int length,x;
        char textbuf[100];
        if(anv!=inloggad && Servermem->inne[nodnr].status<Servermem->cfg.st.brev) {
                puttekn("\n\n\rDu har inte rätt att läsa det brevet!\n\r",-1);
                return;
        }
        Servermem->inne[nodnr].read++;
        Servermem->info.lasta++;
        Statstr.read++;
        sprintf(outbuffer,"\r\n\nText %d  i %s hos %s\r\n",brev,Servermem->cfg.brevnamn,getusername(anv));
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Fido-nätbrev,  %s\n\r",brevread->date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s\r\n",brevread->from);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Mottagare: %s\n\r",brevread->to);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Ärende: %s\r\n",brevread->subject);
        puttekn(outbuffer,-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(outbuffer);
                for(x=0;x<length-2;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else puttekn("\n",-1);

        while(FGets(fh,textbuf,99)) {
                if(textbuf[0]==1) {
                        if(!(Servermem->inne[nodnr].flaggor & SHOWKLUDGE)) continue;
                        puttekn("^A",-1);
                        if(puttekn(&textbuf[1],-1)) break;
                } else {
                        if(puttekn(textbuf,-1)) break;
                }
                eka('\r');
        }
        Close(fh);
        sprintf(outbuffer,"\r\n(S**t på text %d av %s)\r\n",brev,brevread->from);
        puttekn(outbuffer,-1);
        senast_text_typ=BREV;
        senast_brev_nr=brev;
        senast_brev_anv=anv;
}
示例#4
0
void initpersheader(void) {
        long tid,lappnr,length,x;
        struct tm *ts;
        struct User usr;
        char filnamn[40];
        Servermem->action[nodnr] = SKRIVER;
        Servermem->varmote[nodnr] = -1;
        memset(&brevspar,0,sizeof(struct ReadLetter));
        sprintf(brevspar.to,"%d",readhead.person);
        sprintf(brevspar.from,"%d",inloggad);
        readuser(readhead.person,&usr);
        if(usr.flaggor & LAPPBREV) {
                puttekn("\r\n\n",-1);
                lappnr=atoi(brevspar.to);
                sprintf(filnamn,"NiKom:Users/%d/%d/Lapp",lappnr/100,lappnr);
                if(!access(filnamn,0)) sendfile(filnamn);
                puttekn("\r\n",-1);
        }
        time(&tid);
        ts=localtime(&tid);
        sprintf(brevspar.date,"%2d%02d%02d %02d:%02d",ts->tm_year,ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min);
        strcpy(brevspar.systemid,"NiKom");
        sprintf(outbuffer,"\r\n\nMöte: %s\r\n",Servermem->cfg.brevnamn);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Lokalt brev,  %s\n\r",brevspar.date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s\r\n",getusername(inloggad));
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Mottagare: %s\n\r",getusername(readhead.person));
        puttekn(outbuffer,-1);
        puttekn("Ärende: ",-1);
        strcpy(brevspar.subject,readhead.arende);
        puttekn(brevspar.subject,-1);
        puttekn("\n\r",-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(brevspar.subject);
                for(x=0;x<length+8;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else eka('\n');
}
示例#5
0
/* moved to inside Searcher
inline float Alpha( const int nsearch, const float Tfactor ) {
	return std::pow(0.01/Tfactor,1.25/nsearch);	// emperically decided alpha
}
*/
int main( int argc, char* argv[] ) {
	if( argc < 2 ) {
		std::cerr<<"Usage: "<<argv[0]<<" [param file] "
					<<"[options (-ic=(stop after)initial-computation -io=(stop after)initial-outputs -pic=print-init-chiSquare -dm=debug-mode -oir=output-init-radpatterns "
					<<"-uev=use-estimated-variances -pt?=-perturb-type-(0/1/2) -rsa?-?=regular-SA -lc=linear-cooling -gi=good-initial -mco?=Monte-Carlo-only -nmc=No-Monte_Carlo)]"<<std::endl;
		return -1;
	}
		// option -v: output initial variances across the whole region

	try {
		// ********** options ********** //
		//std::vector<char> options;
		std::unordered_map<std::string, std::string> options;
		std::string fparam;
		for( int iarg=1; iarg<argc; iarg++ ) {
			std::string str(argv[iarg]);
			if( str[0] == '-' ) {
				int inum = str.find_first_of("0123456789");
				std::string arg;
				if(inum == std::string::npos) inum = str.size();
				else arg = str.substr(inum,str.size()-inum);
				options.emplace(str.substr(1,inum-1), arg);
				//for(int istr=1; istr<str.size(); istr++) options.push_back( str[istr] );
			} else {
				if( ! fparam.empty() )
					throw std::runtime_error(" ill-formed input! ");
				fparam = str;
			}
		}

		// ********** Preparations ********** //
		// initialize model space
		ModelSpace ms( fparam ); //ms.M0 = 1.3e23;
		// initialize eqk analyzer (do not move/save old outputs just yet)
		EQKAnalyzer eka( fparam, false );
		eka.LoadData();

		// option -pic: print out initial chiSquare
		//if( std::find(options.begin(), options.end(), 'c') != options.end() ) {
		if( options.find("pic") != options.end() ) {
			float chiS; int Ndata;
			eka.chiSquare( ms, chiS, Ndata );
			std::ofstream fout( eka.outname_misAll, std::ofstream::app );
			//if(fout) fout<<"### chiS="<<chiS<<" Ndata="<<Ndata<<" at ("<<static_cast<ModelInfo&>(ms)<<") ###\n";
			//float E; eka.Energy(ms, E, Ndata);
			std::cout<<"### chiS="<<chiS<<" Ndata="<<Ndata<<"   E="<<chiS*eka._indep_factor<<" at ("<<static_cast<ModelInfo&>(ms)<<") ###\n";
		}

		// option -dm: debug mode
		//if( std::find(options.begin(), options.end(), 'd') != options.end() ) {
		if( options.find("dm") != options.end() ) {
			for(int imodel=1; true; ) {
				std::cout<<"input model "<<imodel<<" (lon, lat, t0, stk, dip, rak, dep, M0; '#' to stop): ";
				std::string line; std::getline(std::cin, line);
				if( line == "#" ) {
					std::cout<<"  end of input\n";
					break;
				}
				try {
					ModelInfo mi(line); imodel++;
					float chiS; int Ndata;
					eka.chiSquare( mi, chiS, Ndata );
					//eka.Energy( mi, E, Ndata );
					std::cout<<"  chi square = "<<chiS<<" Ndata = "<<Ndata<<std::endl;
				} catch(...) {
					std::cout<<"  What was that? Try again please\n";
				}
			}
			return 0;
		}

		// option -ic(initial computation): stop before output initial fit and misfits
		if( options.find("ic") != options.end() ) return 0;

		// initial output
		eka.SaveOldOutputs();
		eka.OutputFits( ms );
		eka.OutputMisfits( ms );
		eka.OutputWaveforms( ms, eka.outdir_sac + "_init" );
		eka.OutputSigmas();
		// option -oir: output initial rad patterns
		if( options.find("oir") != options.end() ) eka.OutputSourcePatterns(ms);

		// option -io(initial output): stop after output initial fit and misfits
		if( options.find("io") != options.end() ) return 0;

		// option -pt (perturbation type):
		// 0 = use init pert sizes throughout, 1 = estimate (after SA) pert sizes for MC, 2 = estimate (before and after SA) pert sizes for both
		int pt = options.find("pt")==options.end() ? 1 : std::stoi(options["pt"]);
		if( pt == 2 ) ms.EstimatePerturbs( eka, 0.15 );

		// option -rsa: do a single big SA for all params instead of the iterative SA
		bool regularSA = options.find("rsa") != options.end();

		// option -gi: run only a fast SA to stablize, followed by the Monte-Carlo search (assuming close-enough input model info)
		// option -mco: start the Monte-Carlo search immediately (assuming a highly-optimized input model state)
		bool doSA1 = options.find("gi")==options.end() && options.find("mco") == options.end();
		bool doSA2 = options.find("mco")==options.end() && !regularSA;

		// option -nmc: do not run the Monte-Carlo search
		bool doMC = options.find("nmc") == options.end();

		// option -lc: use linear cooling schedule for SA
		int cooltype = options.find("lc") != options.end();	// 0 = exponential cooling, 1 = linear cooling

		// estimate Energy statistics
		eka.SetCorrectM0(true);	// M0 will be corrected to produce least chiS
		float Emean, Estd; int nthd = omp_get_max_threads();
		ms.SetFreeFocal();	// allow perturbing to any focal mechanism, but start at the input focal info
		Searcher::EStatistic<ModelInfo>(ms, eka, nthd>10?nthd*5:50, Emean, Estd);
		std::cout<<"### Energy Statistics: Emean = "<<Emean<<"  Estd = "<<Estd<<" ###"<<std::endl;

		// ********** Initialize simulated annealing to approach global optimum ********** //
		double Tinit = (cooltype==0?3:0.5) * (Emean+3*Estd), Tfinal = cooltype==0 ? 1e-4*Emean : 0;
		if( doSA1 ) {

			if( regularSA ) {
				// ********** single simulated annealing ********** //
				// search for epicenter and focal mechanism simultaneously
				//int nsearch = 7200, Tfactor = 8;
				int nsearch = 15000, niter = 1;//, Tfactor = 1000;
				std::stringstream ss(options["rsa"]); std::string tok; 
				if( std::getline(ss,tok,'-') ) nsearch = std::stoi(tok);
				if( std::getline(ss,tok,'-') ) niter = std::stoi(tok);
				//double alpha = Searcher::Alpha(nsearch, Tfactor);
				auto msbest = ms; float Ebest; int Ndata; eka.Energy( ms, Ebest, Ndata );
				for(int iter=0; iter<niter; iter++) {
					ms.SetPerturb( true, true, true, false, true, true, true, true );	// do not perturb M0
					//auto SIV = Searcher::SimulatedAnnealing<ModelInfo>( ms, eka, nsearch, alpha, Tfactor, std::cout, 0, true );	// save info for accepted searches
					auto SIV = Searcher::SimulatedAnnealing<ModelInfo>( ms, eka, nsearch*4/5, Tinit, Tfinal, cooltype, std::cout, 0, true );	// save info for accepted searches
					VO::Output( SIV, eka.outname_misL, true );	// append to file
					if( pt > 0 ) ms.Bound( 2.5, 0.03 );
					SIV = Searcher::SimulatedAnnealing<ModelInfo>( ms, eka, nsearch/5, Tinit*0.01, Tfinal*0.01, cooltype, std::cout, 0, true );	// save info for accepted searches
					VO::Output( SIV, eka.outname_misL, true );	// append to file
					// output
					eka.OutputFits( ms );
					eka.OutputMisfits( ms );
					// update msbest
					if( SIV.back().E < Ebest ) { msbest = ms; Ebest = SIV.back().E; }
					ms.SetFreeFocal(); ms.RandomState();
				}
				ms = msbest;
			} else {
				// ********** iterative simulated annealing ********** //
				// search for epicenter and focal mechanism separately
				int niterSA = 3, nsearch = 8192; //, Tfactor = 16;
				//int niterSA = 2, nsearch = 4096;
				auto Tinit2 = Tinit;
				for( int iter=0; iter<niterSA; iter++ ) {
					// search for epicenter
					ms.SetPerturb( true, true, true, false, false, false, false, false );	// have focal mechanism fixed
					eka.UpdatePreds( ms );	// not necessary, but following search runs faster since Focal is fixed
					if( iter==0 ) eka.SetInitSearch( true );			// use Love group data only!
					auto SIV = Searcher::SimulatedAnnealing<ModelInfo>( ms, eka, 500, 0., 0., 1, std::cout, 0, true );
					VO::Output( SIV, eka.outname_misL, true );	// append to file
					if( iter==0 ) eka.SetInitSearch( false );	// use all data
					// search for focal info
					ms.SetPerturb( false, false, false, false, true, true, true, true );	// have epicenter (and M0) fixed
					eka.UpdatePreds( ms );	// not necessary, but following search runs faster since Epic is fixed
					//double alpha = Searcher::Alpha(nsearch, Tfactor);
					SIV = Searcher::SimulatedAnnealing<ModelInfo>( ms, eka, nsearch, Tinit2, Tfinal, cooltype, std::cout, 0, true );	// save info for accepted searches
					VO::Output( SIV, eka.outname_misF, true );	// append to file
					// centralize the model space around the current MState
					ms.Centralize();
					// output
					eka.OutputFits( ms );
					eka.OutputMisfits( ms );
					nsearch /= 2, Tinit2 /= 2;
				}
				//ms.unFix();	// free both to perturb // not necessary, freed in 'Bound()'
			}
		}

		// ********** secondary simulated annealing for deeper optimization ********** //
		if( doSA2 ) {
			//double Tinit = (cooltype==0?0.01:0.002) * Emean, Tfinal = cooltype==0 ? 1e-7*Emean : 0;
			// constrain model to perturb near the current Mstate ( Rparam = ? * (0.15, 0.15, 2, 30, 20, 30, 5) )
			// with a small pertfactor to approach the optimum solution faster
			if( pt > 0 ) ms.Bound( 2.5, 0.03 );
			ms.SetPerturb( true, true, true, false, true, true, true, true );	// have M0 fixed
			// initial MC search around the SA result to stablize
			int nsearch = 3000;
			//auto SIV = Searcher::MonteCarlo<ModelInfo>( ms, eka, nsearch, std::cout );
			//Searcher::MonteCarlo<ModelInfo>( ms, eka, nsearch, eka.outname_pos );
			//double alpha = Searcher::Alpha(nsearch, Tfactor);
			//ms.SetPerturb( false, false, false, true, false, false, false, false );
			Searcher::SimulatedAnnealing<ModelInfo>( ms, eka, nsearch, Tinit*0.001, Tfinal*0.001, cooltype, std::cout, 0, false );	// do not save Sinfo
			//Searcher::SimulatedAnnealing<ModelInfo>( ms, eka, 10000, alpha, 0.5f, std::cout, -1 );	// do not save Sinfo
			eka.OutputFits( ms );
			eka.OutputMisfits( ms );
			eka.OutputSourcePatterns( ms );
			eka.OutputWaveforms( ms );

		}

		// -uev: estimate/use sigmaS to be the current (after SA) variance across all stations
		if( options.find("uev") != options.end() ) {
			eka.EstimateSigmas( ms ); eka.OutputSigmas();
		}

		if( doMC ) {
			// ********** monte carlo for posterior distributions ********** //
			// constrain model to perturb near the current Mstate ( Rparam = ? * (0.15, 0.15, 2, 30, 20, 30, 5) )
			// perturbation steps are decided later by EstimatePerturbs
			//ms.Bound( 2. );	// set Rfactor = 2.0 to be safe
			eka.SetCorrectM0(false);	// M0 will not be corrected to produce least chiS
			ms.SetFreeFocal();			// allow perturbing to any focal mechanism, but start at the current focal info
			// decide perturb step length for each parameter based on the model sensitivity to them
			// perturb steps are defined to be (ub-lb) * sfactor, where ub and lb are the boundaries decided by:
			// assuming current model to be the best fitting model, move away
			// from this state until the probability of acceptance <= Pthreshold
			if( pt > 0 ) ms.EstimatePerturbs( eka, 0.12 );	// sfactor default= 0.1
			// second (final) Monte Carlo Search with desired perturb sizes
			int nsearch = 100000; 
			if( options.find("mco")!=options.end() && !options["mco"].empty() ) 
				nsearch = std::stoi(options["mco"]);
			Searcher::MonteCarlo<ModelInfo>( ms, eka, nsearch, eka.outname_pos );

			// final output
			eka.OutputFits( ms );				// appended
			eka.OutputMisfits( ms );			// appended
			eka.OutputSourcePatterns( ms );	// overwritten
			eka.OutputWaveforms( ms );			// overwritten
		}

	} catch(std::exception& e) {
      std::cerr<<e.what()<<std::endl;
      return -1;
   } catch(...) {
      std::cerr<<"Unknown Exception!"<<std::endl;
      return -2;
   }

	return 0;
}
示例#6
0
int fido_brev(char *tillpers,char *adr,struct Mote *motpek) {
        int length=0,x=0,editret,chrs;
        struct FidoDomain *fd;
        struct FidoText *komft,ft;
        struct MinNode *first, *last;
        char *foo,tmpfrom[100],fullpath[100],filnamn[20],subject[80],msgid[50],tkn;
        if(!(Servermem->inne[nodnr].grupper & Servermem->fidodata.mailgroups) &&
                Servermem->inne[nodnr].status < Servermem->fidodata.mailstatus) {
                puttekn("\n\n\rDu har ingen rätt att skicka FidoNet NetMail.\n\r",-1);
                return(0);
        }
        Servermem->action[nodnr] = SKRIVER;
        Servermem->varmote[nodnr] = -1;
        memset(&ft,0,sizeof(struct FidoText));
        if(!tillpers) { /* Det handlar om en kommentar */
                if(motpek) { /* Det är en personlig kommentar */
                        strcpy(fullpath,motpek->dir);
                        sprintf(filnamn,"%d.msg",senast_text_nr - motpek->renumber_offset);
                        AddPart(fullpath,filnamn,99);
                        komft = ReadFidoTextTags(fullpath,RFT_HeaderOnly,TRUE,TAG_DONE);
                        if(!komft) {
                                puttekn("\n\n\rTexten finns inte.\n\r",-1);
                                return(0);
                        }
                        strcpy(ft.touser,komft->fromuser);
                        ft.tozone = komft->fromzone;
                        ft.tonet = komft->fromnet;
                        ft.tonode = komft->fromnode;
                        ft.topoint = komft->frompoint;
                        strcpy(subject,komft->subject);
                        strcpy(msgid,komft->msgid);
                        FreeFidoText(komft);
                } else { /* Det är en kommentar av ett brev */
                        strcpy(tmpfrom,brevread.from);
                        foo=strchr(tmpfrom,'(');
                        if(!foo) {
                                puttekn("\n\n\rDen kommenterade texten saknar adress!\n\r",-1);
                                return(0);
                        }
                        *(foo-1)='\0';
                        foo++;
                        strcpy(ft.touser,tmpfrom);
                        ft.tozone=getzone(foo);
                        ft.tonet=getnet(foo);
                        ft.tonode=getnode(foo);
                        ft.topoint=getpoint(foo);
                        strcpy(subject,brevread.subject);
                        strcpy(msgid,brevread.messageid);

                }
        } else { /* Det är ett helt nytt brev */
                strcpy(ft.touser,tillpers);
                sprattgok(ft.touser);
                ft.tozone=getzone(adr);
                ft.tonet=getnet(adr);
                ft.tonode=getnode(adr);
                ft.topoint=getpoint(adr);
        }
        fd = getfidodomain(0,ft.tozone);
        if(!fd) {
                puttekn("\n\n\rDu kan inte skriva brev till den zonen.\n\r",-1);
                return(0);
        }
        if(!tillpers && !motpek) {
                foo = strchr(brevread.to,'(')+1;
                ft.fromzone = getzone(foo);
                ft.fromnet = getnet(foo);
                ft.fromnode = getnode(foo);
                ft.frompoint = getpoint(foo);
        } else {
                ft.fromzone = fd->zone;
                ft.fromnet = fd->net;
                ft.fromnode = fd->node;
                ft.frompoint = fd->point;
        }
        ft.attribut = FIDOT_PRIVATE | FIDOT_LOCAL;
        makefidousername(ft.fromuser,inloggad);
        makefidodate(ft.date);
        sprintf(outbuffer,"\r\n\nMöte: %s\r\n",Servermem->cfg.brevnamn);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Fido-nätbrev,  %s\n\r",ft.date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s (%d:%d/%d.%d)\r\n",ft.fromuser,ft.fromzone,ft.fromnet,ft.fromnode,ft.frompoint);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Mottagare: %s (%d:%d/%d.%d)\n\r",ft.touser,ft.tozone,ft.tonet,ft.tonode,ft.topoint);
        puttekn(outbuffer,-1);
        puttekn("Ärende: ",-1);
        if(!tillpers) {
                if(!strncmp(subject,"Re:",3)) strcpy(ft.subject,subject);
                else sprintf(ft.subject,"Re: %s",subject);
                puttekn(ft.subject,-1);
        } else {
                if(getstring(EKO,40,NULL)) return(1);
                if(!inmat[0]) {
                        eka('\n');
                        return(0);
                }
                strcpy(ft.subject,inmat);
        }
        puttekn("\r\n",-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(ft.subject);
                for(x=0;x<length+8;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else puttekn("\n",-1);
        crashmail = FALSE;
        editret = edittext(NULL);
        if(editret==1) return(1);
        if(editret==2) return(0);
        if(crashmail) ft.attribut |= FIDOT_CRASH;
        Servermem->inne[nodnr].skrivit++;
        Servermem->info.skrivna++;
        Statstr.write++;
        puttekn("\n\n\rTill vilken teckenuppsättning ska brevet konverteras?\r\n\n",-1);
        puttekn("1: ISO Latin 8-bitars tecken (Default)\n\r",-1);
        puttekn("2: IBM PC 8-bitars tecken\r\n",-1);
        puttekn("3: Macintosh 8-bitars tecken\r\n",-1);
        puttekn("4: Svenska 7-bitars tecken\r\n\n",-1);
        puttekn("Val: ",-1);
        for(;;) {
                tkn=gettekn();
                if(tkn==13 || tkn==10) tkn='1';
                if(tkn >= '1' && tkn <= '4') break;
        }
        sprintf(outbuffer,"%c\r\n\n",tkn);
        puttekn(outbuffer,-1);
        switch(tkn) {
                case '1' : chrs=CHRS_LATIN1; break;
                case '2' : chrs=CHRS_CP437; break;
                case '3' : chrs=CHRS_MAC; break;
                case '4' : chrs=CHRS_SIS7; break;
        }
        NewList((struct List *)&ft.text);
        first =  edit_list.mlh_Head;
        last = edit_list.mlh_TailPred;
        ft.text.mlh_Head = first;
        ft.text.mlh_TailPred = last;
        last->mln_Succ = (struct MinNode *)&ft.text.mlh_Tail;
        first->mln_Pred = (struct MinNode *)&ft.text;
        if(tillpers) x = WriteFidoTextTags(&ft,WFT_MailDir,Servermem->fidodata.matrixdir,
                                                      WFT_Domain,fd->domain,
                                                      WFT_CharSet,chrs,
                                                      TAG_DONE);
        else x = WriteFidoTextTags(&ft,WFT_MailDir,Servermem->fidodata.matrixdir,
                                            WFT_Domain,fd->domain,
                                            WFT_Reply,msgid,
                                            WFT_CharSet,chrs,
                                            TAG_DONE);
        sprintf(outbuffer,"Brevet fick nummer %d\r\n\n",x);
        puttekn(outbuffer,-1);
        if(Servermem->cfg.logmask & LOG_BREV) {
                strcpy(tmpfrom,getusername(inloggad));
                sprintf(outbuffer,"%s skickar brev %d till %s (%d:%d/%d.%d)",tmpfrom,x,ft.touser,ft.tozone,ft.tonet,ft.tonode,ft.topoint);
                logevent(outbuffer);
        }
        puttekn("Vill du ha en kopia av brevet i din egen brevlåda? ",-1);
        if(jaellernej('j','n',2)) savefidocopy(&ft,inloggad);
        while(first=(struct MinNode *)RemHead((struct List *)&ft.text)) FreeMem(first,sizeof(struct EditLine));
        NewList((struct List *)&edit_list);
        return(0);
}
示例#7
0
int initbrevheader(int tillpers) {
        int length=0,x=0,lappnr;
        long tid,tempmott;
        struct tm *ts;
        struct User usr;
        char filnamn[40],*mottagare,tempbuf[10],*vemskrev;
        Servermem->action[nodnr] = SKRIVER;
        Servermem->varmote[nodnr] = -1;
        memset(&brevspar,0,sizeof(struct ReadLetter));
        if(tillpers==-1) {
                strcpy(brevspar.to,brevread.from);
                mottagare=brevread.to;
                while(mottagare[0]) {
                        tempmott=atoi(mottagare);
                        if(tempmott==inloggad || recisthere(brevspar.to,tempmott)) {
                                mottagare=hittaefter(mottagare);
                                continue;
                        }
                        sprintf(tempbuf," %d",tempmott);
                        strcat(brevspar.to,tempbuf);
                        mottagare=hittaefter(mottagare);
                }
                sprintf(brevspar.reply,"%d %d %s",senast_brev_anv,senast_brev_nr,brevread.from);
        } else {
                sprintf(brevspar.to,"%d",tillpers);
        }
        sprintf(brevspar.from,"%d",inloggad);
        readuser(atoi(brevspar.to),&usr);
        if(usr.flaggor & LAPPBREV) {
                puttekn("\r\n\n",-1);
                lappnr=atoi(brevspar.to);
                sprintf(filnamn,"NiKom:Users/%d/%d/Lapp",lappnr/100,lappnr);
                if(!access(filnamn,0)) sendfile(filnamn);
                puttekn("\r\n",-1);
        }
        time(&tid);
        ts=localtime(&tid);
        sprintf(brevspar.date,"%2d%02d%02d %02d:%02d",ts->tm_year,ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min);
        strcpy(brevspar.systemid,"NiKom");
        sprintf(outbuffer,"\r\n\nMöte: %s\r\n",Servermem->cfg.brevnamn);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Lokalt brev,  %s\n\r",brevspar.date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s\r\n",getusername(inloggad));
        puttekn(outbuffer,-1);
        if(brevspar.reply[0]) {
                vemskrev=hittaefter(hittaefter(brevspar.reply));
                sprintf(outbuffer,"Kommentar till en text av %s\r\n",getusername(atoi(vemskrev)));
                puttekn(outbuffer,-1);
        }
        mottagare=brevspar.to;
        while(mottagare[0]) {
                sprintf(outbuffer,"Mottagare: %s\n\r",getusername(atoi(mottagare)));
                puttekn(outbuffer,-1);
                mottagare=hittaefter(mottagare);
        }
        puttekn("Ärende: ",-1);
        if(tillpers==-1) {
                strcpy(brevspar.subject,brevread.subject);
                puttekn(brevspar.subject,-1);
        } else {
                if(getstring(EKO,40,NULL)) return(1);
                if(!inmat[0]) {
                        eka('\n');
                        return(2);
                }
                strcpy(brevspar.subject,inmat);
        }
        puttekn("\r\n",-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(brevspar.subject);
                for(x=0;x<length+8;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else puttekn("\n",-1);
        return(0);
}
示例#8
0
void visabrev(int brev,int anv) {
        BPTR fh;
        int x,length=0,tillmig=FALSE;
        char filnamn[40],*mottagare,textbuf[100],*vemskrev;
        sprintf(filnamn,"NiKom:Users/%d/%d/%d.letter",anv/100,anv,brev);
        if(!(fh=Open(filnamn,MODE_OLDFILE))) {
                sprintf(outbuffer,"\n\n\rKunde inte öppna %s\n\r",filnamn);
                puttekn(outbuffer,-1);
                return;
        }
        readletterheader(fh,&brevread);
        if(!strncmp(brevread.systemid,"Fido",4)) {
                visafidobrev(&brevread,fh,brev,anv);
                return;
        }
        mottagare=brevread.to;
        while(mottagare[0]) {
                if(inloggad==atoi(mottagare)) {
                        tillmig=TRUE;
                        break;
                }
                mottagare=hittaefter(mottagare);
        }
        if(!tillmig && inloggad!=atoi(brevread.from) && Servermem->inne[nodnr].status<Servermem->cfg.st.brev) {
                puttekn("\n\n\rDu har inte rätt att läsa det brevet!\n\r",-1);
                return;
        }
        Servermem->inne[nodnr].read++;
        Servermem->info.lasta++;
        Statstr.read++;
        sprintf(outbuffer,"\r\n\nText %d  i %s hos %s\r\n",brev,Servermem->cfg.brevnamn,getusername(anv));
        puttekn(outbuffer,-1);
        if(!strncmp(brevread.systemid,"NiKom",5)) sprintf(outbuffer,"Lokalt brev,  %s\n\r",brevread.date);
        else sprintf(outbuffer,"<Okänd brevtyp>  %s\n\r",brevread.date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s\r\n",getusername(atoi(brevread.from)));
        puttekn(outbuffer,-1);
        if(brevread.reply[0]) {
                vemskrev=hittaefter(hittaefter(brevread.reply));
                sprintf(outbuffer,"Kommentar till en text av %s\r\n",getusername(atoi(vemskrev)));
                puttekn(outbuffer,-1);
        }
        mottagare=brevread.to;
        while(mottagare[0]) {
                sprintf(outbuffer,"Mottagare: %s\n\r",getusername(atoi(mottagare)));
                puttekn(outbuffer,-1);
                mottagare=hittaefter(mottagare);
        }
        sprintf(outbuffer,"Ärende: %s\r\n",brevread.subject);
        puttekn(outbuffer,-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(outbuffer);
                for(x=0;x<length-2;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else puttekn("\n",-1);

        while(FGets(fh,textbuf,99)) {
                if(puttekn(textbuf,-1)) break;
                eka('\r');
        }
        Close(fh);
        sprintf(outbuffer,"\r\n(S**t på text %d av %s)\r\n",brev,getusername(atoi(brevread.from)));
        puttekn(outbuffer,-1);
        senast_text_typ=BREV;
        senast_brev_nr=brev;
        senast_brev_anv=anv;
}
示例#9
0
int GetStringX(int echo, int maxchrs, char *defaultStr,
               int (*isCharacterAccepted)(unsigned char),
               int (*isStringAccepted)(char *, void *),
               void *customData) {
    int size = 0, pos=0, i, modified = FALSE, ch;
    static int historycnt = -1;
    radcnt = 0;

    memset(inmat,0,1023);
    if(defaultStr != NULL) {
        size = pos = strlen(defaultStr);
        SendStringNoBrk(defaultStr);
        strcpy(inmat, defaultStr);
    }
    if(isCharacterAccepted == NULL) {
        isCharacterAccepted = &IsPrintableCharacter;
    }

    for(;;) {
        ch = GetChar();

        if(ch == GETCHAR_LOGOUT) {
            return 1;
        }
        if(ch == GETCHAR_RETURN) {
            inmat[size] = '\0';
            if(isStringAccepted == NULL || isStringAccepted(inmat, customData)) {
                break;
            }
        }
        else if(ch == GETCHAR_SOL) {
            if(pos == 0) {
                continue;
            }
            if(echo) {
                SendStringNoBrk("\x1b\x5b%d\x44", pos);
            }
            pos = 0;
        }
        else if(ch == GETCHAR_EOL) {
            if(pos == size) {
                continue;
            }
            if(echo) {
                SendStringNoBrk("\x1b\x5b%d\x43", size - pos);
            }
            pos = size;
        }
        else if(ch == GETCHAR_BACKSPACE) {
            if(pos == 0) {
                continue;
            }
            if(echo) {
                if(Servermem->inne[nodnr].flaggor & SEKVENSANSI) {
                    SendStringNoBrk("\x1b\x5b\x44\x1b\x5b\x50",-1,0);
                }
                else {
                    SendStringNoBrk("\b \b",-1,0);
                }
            }
            movmem(&inmat[pos], &inmat[pos - 1], size - pos);
            pos--;
            size--;
            modified = TRUE;
        }
        else if(ch == GETCHAR_DELETE) {
            if(pos == size) {
                continue;
            }
            if(echo) {
                SendStringNoBrk("\x1b\x5b\x50");
            }
            movmem(&inmat[pos + 1], &inmat[pos], size - pos);
            size--;
            modified = TRUE;
        }
        else if(ch == GETCHAR_DELETELINE) {
            if(echo) {
                if(pos > 0) {
                    SendStringNoBrk("\x1b\x5b%d\x44\x1b\x5b\x4a", pos);
                } else {
                    SendStringNoBrk("\x1b\x5b\x4a");
                }
            }
            memset(inmat, 0, 1023);
            pos = size = 0;
        }
        else if(ch == GETCHAR_LEFT) {
            if(pos == 0) {
                continue;
            }
            if(echo) {
                SendStringNoBrk("\x1b\x5b\x44",-1,0);
            }
            pos--;
        } else if(ch == GETCHAR_RIGHT) {
            if(pos == size) {
                continue;
            }
            if(echo) {
                SendStringNoBrk("\x1b\x5b\x43",-1,0);
            }
            pos++;
        } else if(ch == GETCHAR_UP) {
            if(!echo || historycnt >= 9 || commandhistory[historycnt + 1][0] == '\0') {
                continue;
            }
            historycnt++;
            strncpy(inmat, commandhistory[historycnt], maxchrs);
            inmat[maxchrs] = '\0';
            if(pos > 0) {
                SendStringNoBrk("\x1b\x5b%d\x44\x1b\x5b\x4a%s", pos, inmat);
            } else {
                SendStringNoBrk("\x1b\x5b\x4a%s", inmat);
            }
            pos = size = strlen(inmat);
            modified=FALSE;
        } else if(ch == GETCHAR_DOWN) {
            if(!echo) {
                continue;
            }
            if(historycnt == 0 || historycnt == -1) {
                historycnt = -1;
                if(echo == 1) {
                    if(pos > 0) {
                        SendStringNoBrk("\x1b\x5b%d\x44\x1b\x5b\x4a",pos);
                    } else {
                        SendStringNoBrk("\x1b\x5b\x4a");
                    }
                }
                memset(inmat,0,1023);
                pos=size=0;
                continue;
            }

            if(historycnt == 0 || commandhistory[historycnt-1][0] == '\0') {
                continue;
            }

            historycnt--;
            strncpy(inmat, commandhistory[historycnt], maxchrs);
            inmat[maxchrs] = '\0';
            if(pos) {
                SendStringNoBrk("\x1b\x5b%d\x44\x1b\x5b\x4a%s", pos, inmat);
            } else {
                SendStringNoBrk("\x1b\x5b\x4a%s", inmat);
            }
            pos = size = strlen(inmat);
            modified=FALSE;
        }
        else if(isCharacterAccepted(ch)) {
            if(size >= maxchrs) {
                eka('\a');
                continue;
            }
            if(echo) {
                if(Servermem->inne[nodnr].flaggor & SEKVENSANSI) {
                    SendStringNoBrk("\x1b\x5b\x31\x40");
                }
                if(echo != STAREKO) {
                    if(ch == '+') {
                        SendStringNoBrk(" \b");
                    }
                    eka(ch);
                } else {
                    eka('*');
                }
            }
            movmem(&inmat[pos], &inmat[pos+1], size - pos);
            inmat[pos++] = ch;
            size++;
            modified = TRUE;
        }
    }
    inmat[size] = 0;
    if(echo == STAREKO) {
        if(pos != size) {
            SendStringNoBrk("\x1b\x5b%d\x43", size - pos);
        }

        for(i = 0; i < size; i++) {
            if(Servermem->inne[nodnr].flaggor & SEKVENSANSI) {
                SendStringNoBrk("\x1b\x5b\x44\x1b\x5b\x50");
            } else {
                SendStringNoBrk("\b \b");
            }
        }
    }
    eka('\r');

    if(inmat[0] && echo == 1 && modified) {
        for(i = 9; i > 0; i--) {
            strcpy(commandhistory[i], commandhistory[i-1]);
        }
        strncpy(commandhistory[0], inmat, 1023);
        historycnt=-1;
    }
    if(historycnt > -1) {
        historycnt--;
    }
    return 0;
}