flength FileWin::DoGetLengthOfOpened( void ) const { FBL_CHECK(mHandle); #if FBL_LENGTH <= 32 DWORD dw; if(!::GetFileSize(mHandle, &dw)) throw(xOSFileError( (ERROR_TYPE) ::GetLastError() )); return (static_cast<flength>(dw)); #else // IS: 03.03.2008 // http://valentina-db.com/bt/view.php?id=3056 // Commented because GetFileSize returns zero in case file is zero-length. // /* DWORD dwh, dwl; if(!(dwl = ::GetFileSize(mHandle, &dwh))) throw(xOSFileError( (ERROR_TYPE) ::GetLastError() )); return (flength(dwh) << 32) | flength(dwl); */ LARGE_INTEGER res; if( ::GetFileSizeEx(mHandle, &res) == false ) throw(xOSFileError( (ERROR_TYPE) ::GetLastError() )); return (flength(res.HighPart) << 32) | flength(res.LowPart); #endif }
void getnodemsg() { char str[81], *buf; int file; ulong length; nodesync(); sprintf(str,"message.%d",node_num); if(flength(str)<1L) /* v1.02 fix */ return; if((file=nopen(str,O_RDWR))==-1) { bprintf("Couldn't open %s\r\n",str); return; } length=filelength(file); if((buf=malloc(length+1L))==NULL) { close(file); bprintf("\7\r\ngetnodemsg: Error allocating %lu bytes of memory for %\r\n" ,length+1L,str); return; } buf[read(file,buf,length)]=0; chsize(file,0); close(file); if(!symbols) strip_symbols(buf); bputs(buf); free(buf); }
int sbbs_t::getuserxfers(int fromuser, int destuser, char *fname) { char str[256]; int file,found=0; FILE *stream; SAFEPRINTF(str,"%sxfer.ixt",cfg.data_dir); if(!fexist(str)) return(0); if(!flength(str)) { remove(str); return(0); } if((stream=fnopen(&file,str,O_RDONLY))==NULL) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); return(0); } while(!ferror(stream)) { if(!fgets(str,81,stream)) break; str[22]=0; if(fname!=NULL && fname[0] && !strncmp(str+5,fname,12)) found++; else if(fromuser && atoi(str+18)==fromuser) found++; else if(destuser && atoi(str)==destuser) found++; } fclose(stream); return(found); }
/* Checks the header information of a bitmap file. Terminates the program if * the file is not a bitmap, or has invalid format. * Returns the size (in bytes) of (i) the header, (ii) the pixel data. */ BmpData check_bitmap(FILE *fp) { BmpData data; Header header; Info info; long len; len = flength(fp); header = get_header(fp); info = get_info(fp); rewind(fp); if (header.bfType != 0x4d42) /* magic number for 'MB', which is little-endian for 'B' then 'M' */ error("Bitmap file does not start with BM."); if (header.bfSize != len) error("Bitmap header gives incorrect file size."); if (info.biBitCount != 24) error("This program only works with 24-bit bitmaps."); if (info.biCompression != 0 || info.biClrImportant != 0 || info.biClrUsed != 0) error("Incompatible bitmap, unexpected properties."); data.headersize = header.bfOffBits; data.numpixelbytes = header.bfSize - header.bfOffBits; return data; }
int DLLCALL getmail(scfg_t* cfg, int usernumber, BOOL sent) { char str[128]; int i=0; long l; idxrec_t idx; smb_t smb; ZERO_VAR(smb); sprintf(smb.file,"%smail",cfg->data_dir); smb.retry_time=cfg->smb_retry_time; sprintf(str,"%s.sid",smb.file); l=flength(str); if(l<(long)sizeof(idxrec_t)) return(0); if(!usernumber) return(l/sizeof(idxrec_t)); /* Total system e-mail */ smb.subnum=INVALID_SUB; if(smb_open(&smb)!=0) return(0); while(!smb_feof(smb.sid_fp)) { if(smb_fread(&smb,&idx,sizeof(idx),smb.sid_fp) != sizeof(idx)) break; if(idx.number==0) /* invalid message number, ignore */ continue; if(idx.attr&MSG_DELETE) continue; if((!sent && idx.to==usernumber) || (sent && idx.from==usernumber)) i++; } smb_close(&smb); return(i); }
/* and -1 if other error. */ void CMKDIR (struct dsc$descriptor_s *path, struct dsc$descriptor_s *cmode, int *result) { size_t Length; char name[MAXFLEN]; mode_t mode; /* truncate path to MAXFLEN - 1 characters, MAXFLEN defined in library.h */ Length = flength (path->dsc$a_pointer, path->dsc$w_length); if (Length > (size_t) MAXFLEN) Length = (size_t) MAXFLEN - 1; (void) strncpy (name, path->dsc$a_pointer, Length); name[Length] = '\0'; /* Possible modes (see stat.h) Currently pass 3-character string and interpret as octal. Try also S_IRWXU, S_IRWXG, etc. */ sscanf(cmode->dsc$a_pointer,"%o",&mode); *result = mkdir(name,mode); if (*result == -1) { /* Distinguish directory-exists error from others, since usually not a problem. */ if (errno == EEXIST) { *result = 1; } } }
void BeyeContext::draw_title(__filesize_t lastbyte) const { unsigned percent; __filesize_t flen; flen = flength(); percent = flen ? (unsigned)(( lastbyte*100 )/flen) : 100; if(percent > 100) percent = 100; title_wnd().goto_xy(title_wnd().client_width()-4,1); title_wnd().printf("%u%%",percent); title_wnd().clreol(); }
flength FileWin::Seek( flength inOff, vuint16 inFrom ) { #if FBL_LENGTH <= 32 flength dwNew = (flength) ::SetFilePointer( (HANDLE)mHandle, (vint32)inOff, NULL, (vuint32)inFrom ); if( dwNew == flength(-1) ) throw xException( (ERROR_TYPE) ::GetLastError() ); return dwNew; #else LARGE_INTEGER li; li.QuadPart = (vint64) inOff; li.LowPart = ::SetFilePointer( (HANDLE)mHandle, (vint32) li.LowPart, &li.HighPart, (DWORD)inFrom ); if( li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR ) throw xOSFileError( (ERROR_TYPE) ::GetLastError() ); return flength(li.QuadPart); #endif }
extern "C" BOOL DLLCALL putmsgptrs(scfg_t* cfg, uint usernumber, subscan_t* subscan) { char str[256]; ushort idx; uint16_t scancfg; uint i,j; int file; ulong length; uint32_t l=0L; if(!usernumber) return(FALSE); sprintf(str,"%suser/ptrs/%4.4u.ixb", cfg->data_dir,usernumber); if((file=nopen(str,O_WRONLY|O_CREAT))==-1) { return(FALSE); } length=(ulong)filelength(file); for(i=0;i<cfg->total_subs;i++) { if(subscan[i].sav_ptr==subscan[i].ptr && subscan[i].sav_last==subscan[i].last && length>=((cfg->sub[i]->ptridx+1)*10UL) && subscan[i].sav_cfg==subscan[i].cfg) continue; while(filelength(file)<(long)(cfg->sub[i]->ptridx)*10) { lseek(file,0L,SEEK_END); idx=(ushort)(tell(file)/10); for(j=0;j<cfg->total_subs;j++) if(cfg->sub[j]->ptridx==idx) break; write(file,&l,sizeof(l)); write(file,&l,sizeof(l)); scancfg=0xff; if(j<cfg->total_subs) { if(!(cfg->sub[j]->misc&SUB_NSDEF)) scancfg&=~SUB_CFG_NSCAN; if(!(cfg->sub[j]->misc&SUB_SSDEF)) scancfg&=~SUB_CFG_SSCAN; } else /* default to scan OFF for unknown sub */ scancfg&=~(SUB_CFG_NSCAN|SUB_CFG_SSCAN); write(file,&scancfg,sizeof(scancfg)); } lseek(file,(long)((long)(cfg->sub[i]->ptridx)*10),SEEK_SET); write(file,&(subscan[i].ptr),sizeof(subscan[i].ptr)); write(file,&(subscan[i].last),sizeof(subscan[i].last)); write(file,&(subscan[i].cfg),sizeof(subscan[i].cfg)); } close(file); if(!flength(str)) /* Don't leave 0 byte files */ remove(str); return(TRUE); }
void clearptrs(int subnum) { char str[256]; ushort idx,scancfg; int file,i,gi; long l=0L; glob_t g; uifc.pop("Clearing Pointers..."); sprintf(str,"%suser/ptrs/*.ixb",cfg.data_dir); glob(str,0,NULL,&g); for(gi=0;gi<g.gl_pathc;gi++) { if(flength(g.gl_pathv[gi])>=((long)cfg.sub[subnum]->ptridx+1L)*10L) { if((file=nopen(g.gl_pathv[gi],O_WRONLY))==-1) { errormsg(WHERE,ERR_OPEN,g.gl_pathv[gi],O_WRONLY); bail(1); } while(filelength(file)<(long)(cfg.sub[subnum]->ptridx)*10) { lseek(file,0L,SEEK_END); idx=tell(file)/10; for(i=0;i<cfg.total_subs;i++) if(cfg.sub[i]->ptridx==idx) break; write(file,&l,sizeof(l)); write(file,&l,sizeof(l)); scancfg=0xff; if(i<cfg.total_subs) { if(!(cfg.sub[i]->misc&SUB_NSDEF)) scancfg&=~SUB_CFG_NSCAN; if(!(cfg.sub[i]->misc&SUB_SSDEF)) scancfg&=~SUB_CFG_SSCAN; } else /* Default to scan OFF for unknown sub */ scancfg&=~(SUB_CFG_NSCAN|SUB_CFG_SSCAN); write(file,&scancfg,sizeof(scancfg)); } lseek(file,((long)cfg.sub[subnum]->ptridx)*10L,SEEK_SET); write(file,&l,sizeof(l)); /* date set to null */ write(file,&l,sizeof(l)); /* date set to null */ scancfg=0xff; if(!(cfg.sub[subnum]->misc&SUB_NSDEF)) scancfg&=~SUB_CFG_NSCAN; if(!(cfg.sub[subnum]->misc&SUB_SSDEF)) scancfg&=~SUB_CFG_SSCAN; write(file,&scancfg,sizeof(scancfg)); close(file); } } globfree(&g); uifc.pop(0); }
main(int argc, char *argv[]) { char *ptr; long len; while (--argc) { len = flength(ptr = *(++argv)); if (-1L == len) printf("\nUnable to get length of %s\n", ptr); else printf("\nLength of %s = %ld\n", ptr, len); } return 0; }
void sbbs_t::logonlist(void) { char str[MAX_PATH+1]; sprintf(str,"%slogon.lst", cfg.data_dir); if(flength(str)<1) { bputs("\r\n\r\n"); bputs(text[NoOneHasLoggedOnToday]); } else { bputs(text[CallersToday]); printfile(str,P_NOATCODES|P_OPENCLOSE); CRLF; } }
void sbbs_t::backout() { char str[256],code[128],*buf; int i,file; long length,l; file_t f; sprintf(str,"%sbackout.dab",cfg.node_dir); if(flength(str)<1L) { remove(str); return; } if((file=nopen(str,O_RDONLY))==-1) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); return; } length=(long)filelength(file); if((buf=(char *)malloc(length))==NULL) { close(file); errormsg(WHERE,ERR_ALLOC,str,length); return; } if(read(file,buf,length)!=length) { close(file); free(buf); errormsg(WHERE,ERR_READ,str,length); return; } close(file); for(l=0;l<length;l+=BO_LEN) { switch(buf[l]) { case BO_OPENFILE: /* file left open */ memcpy(code,buf+l+1,8); code[8]=0; for(i=0;i<cfg.total_dirs;i++) /* search by code */ if(!stricmp(cfg.dir[i]->code,code)) break; if(i<cfg.total_dirs) { /* found internal code */ f.dir=i; memcpy(&f.datoffset,buf+l+9,4); closefile(&f); } break; default: errormsg(WHERE,ERR_CHK,str,buf[l]); } } free(buf); remove(str); /* always remove the backout file */ }
char* readfile(const char* fname) { char* buf; FILE* fp; int flen = flength(fname); if ((buf=eve_calloc(flen+1, sizeof(char))) == NULL) return NULL; fp = fopen(fname, "rb"); if (fp == NULL) { free(buf); eve_custom_error(EVE_UNABLE_TO_READ_FILE, "Unable to read file \"%s\".", fname); } fread(buf, sizeof(char), flen, fp); fclose(fp); buf[flen] = 0; return buf; }
void CCHMOD (struct dsc$descriptor_s *path, struct dsc$descriptor_s *cmode, int *result) { size_t Length; char name[MAXFLEN]; mode_t mode; /* truncate path to MAXFLEN - 1 characters, MAXFLEN defined in library.h */ Length = flength (path->dsc$a_pointer, path->dsc$w_length); if (Length > (size_t) MAXFLEN) Length = (size_t) MAXFLEN - 1; (void) strncpy (name, path->dsc$a_pointer, Length); name[Length] = '\0'; /* Possible modes (see stat.h) Currently pass 3-character string and interpret as octal. Try also S_IRWXU, S_IRWXG, etc. */ sscanf(cmode->dsc$a_pointer,"%o",&mode); *result = chmod(name,mode); }
bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode) { char str[256],title[LEN_TITLE+1],top[256]; char msg_id[256]; char touser[64]; char from[64]; char pid[128]; char* editor=NULL; char* msgbuf=NULL; uint16_t xlat; ushort msgattr; int i,storage; long dupechk_hashes; long length; FILE* fp; smbmsg_t msg; uint reason; if(remsg) { sprintf(title,"%.*s",LEN_TITLE,remsg->subj); if(remsg->hdr.attr&MSG_ANONYMOUS) SAFECOPY(from,text[Anonymous]); else SAFECOPY(from,remsg->from); // If user posted this message, reply to the original recipient again if((remsg->from_ext!=NULL && atoi(remsg->from_ext)==useron.number) || stricmp(useron.alias,remsg->from)==0 || stricmp(useron.name,remsg->from)==0) SAFECOPY(touser,remsg->to); else SAFECOPY(touser,from); msgattr=(ushort)(remsg->hdr.attr&MSG_PRIVATE); sprintf(top,text[RegardingByToOn],title,from,remsg->to ,timestr(remsg->hdr.when_written.time) ,smb_zonestr(remsg->hdr.when_written.zone,NULL)); } else { title[0]=0; touser[0]=0; top[0]=0; msgattr=0; } /* Security checks */ if(!can_user_post(&cfg,subnum,&useron,&client,&reason)) { bputs(text[reason]); return false; } bprintf(text[Posting],cfg.grp[cfg.sub[subnum]->grp]->sname,cfg.sub[subnum]->lname); action=NODE_PMSG; nodesync(); if(!(msgattr&MSG_PRIVATE) && (cfg.sub[subnum]->misc&SUB_PONLY || (cfg.sub[subnum]->misc&SUB_PRIV && !noyes(text[PrivatePostQ])))) msgattr|=MSG_PRIVATE; if(sys_status&SS_ABORT) return(false); if( #if 0 /* we *do* support internet posts to specific people July-11-2002 */ !(cfg.sub[subnum]->misc&SUB_INET) && // Prompt for TO: user #endif (cfg.sub[subnum]->misc&SUB_TOUSER || msgattr&MSG_PRIVATE || touser[0])) { if(!touser[0] && !(msgattr&MSG_PRIVATE)) SAFECOPY(touser,"All"); bputs(text[PostTo]); i=LEN_ALIAS; if(cfg.sub[subnum]->misc&SUB_QNET) i=25; if(cfg.sub[subnum]->misc&SUB_FIDO) i=FIDO_NAME_LEN-1; if(cfg.sub[subnum]->misc&(SUB_PNET|SUB_INET)) i=60; getstr(touser,i,K_UPRLWR|K_LINE|K_EDIT|K_AUTODEL); if(stricmp(touser,"ALL") && !(cfg.sub[subnum]->misc&(SUB_PNET|SUB_FIDO|SUB_QNET|SUB_INET|SUB_ANON))) { if(cfg.sub[subnum]->misc&SUB_NAME) { if(!userdatdupe(useron.number,U_NAME,LEN_NAME,touser)) { bputs(text[UnknownUser]); return(false); } } else { if((i=finduser(touser))==0) return(false); username(&cfg,i,touser); } } if(sys_status&SS_ABORT) return(false); } if(!touser[0]) SAFECOPY(touser,"All"); // Default to ALL if(!stricmp(touser,"SYSOP") && !SYSOP) // Change SYSOP to user #1 username(&cfg,1,touser); if(msgattr&MSG_PRIVATE && !stricmp(touser,"ALL")) { bputs(text[NoToUser]); return(false); } if(msgattr&MSG_PRIVATE) wm_mode|=WM_PRIVATE; if(cfg.sub[subnum]->misc&SUB_AONLY || (cfg.sub[subnum]->misc&SUB_ANON && useron.exempt&FLAG('A') && !noyes(text[AnonymousQ]))) msgattr|=MSG_ANONYMOUS; if(cfg.sub[subnum]->mod_ar[0] && chk_ar(cfg.sub[subnum]->mod_ar,&useron,&client)) msgattr|=MSG_MODERATED; if(cfg.sub[subnum]->misc&SUB_SYSPERM && sub_op(subnum)) msgattr|=MSG_PERMANENT; if(msgattr&MSG_PRIVATE) bputs(text[PostingPrivately]); if(msgattr&MSG_ANONYMOUS) bputs(text[PostingAnonymously]); if(cfg.sub[subnum]->misc&SUB_NAME) bputs(text[UsingRealName]); msg_tmp_fname(useron.xedit, str, sizeof(str)); if(!writemsg(str,top,title,wm_mode,subnum,touser,&editor) || (length=(long)flength(str))<1) { /* Bugfix Aug-20-2003: Reject negative length */ bputs(text[Aborted]); return(false); } bputs(text[WritingIndx]); if((i=smb_stack(&smb,SMB_STACK_PUSH))!=SMB_SUCCESS) { errormsg(WHERE,ERR_OPEN,cfg.sub[subnum]->code,i,smb.last_error); return(false); } smb.subnum=subnum; if((i=msgbase_open(&cfg,&smb,&storage,&dupechk_hashes,&xlat))!=SMB_SUCCESS) { errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); smb_stack(&smb,SMB_STACK_POP); return(false); } if((i=smb_locksmbhdr(&smb))!=SMB_SUCCESS) { smb_close(&smb); errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error); smb_stack(&smb,SMB_STACK_POP); return(false); } if((i=smb_getstatus(&smb))!=SMB_SUCCESS) { smb_close(&smb); errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error); smb_stack(&smb,SMB_STACK_POP); return(false); } if((msgbuf=(char*)calloc(length+1,sizeof(char))) == NULL) { smb_close(&smb); errormsg(WHERE,ERR_ALLOC,"msgbuf",length+1); smb_stack(&smb,SMB_STACK_POP); return(false); } if((fp=fopen(str,"rb"))==NULL) { free(msgbuf); smb_close(&smb); errormsg(WHERE,ERR_OPEN,str,O_RDONLY|O_BINARY); smb_stack(&smb,SMB_STACK_POP); return(false); } i=fread(msgbuf,1,length,fp); fclose(fp); if(i != length) { free(msgbuf); smb_close(&smb); errormsg(WHERE,ERR_READ,str,length); smb_stack(&smb,SMB_STACK_POP); return(false); } truncsp(msgbuf); /* ToDo: split body/tail */ memset(&msg,0,sizeof(msg)); msg.hdr.attr=msgattr; msg.hdr.when_written.time=msg.hdr.when_imported.time=time32(NULL); msg.hdr.when_written.zone=msg.hdr.when_imported.zone=sys_timezone(&cfg); msg.hdr.number=smb.status.last_msg+1; /* this *should* be the new message number */ if(remsg) { msg.hdr.thread_back=remsg->hdr.number; /* needed for threading backward */ if((msg.hdr.thread_id=remsg->hdr.thread_id) == 0) msg.hdr.thread_id=remsg->hdr.number; /* Add RFC-822 Reply-ID (generate if necessary) */ if(remsg->id!=NULL) smb_hfield_str(&msg,RFC822REPLYID,remsg->id); /* Add FidoNet Reply if original message has FidoNet MSGID */ if(remsg->ftn_msgid!=NULL) smb_hfield_str(&msg,FIDOREPLYID,remsg->ftn_msgid); if((i=smb_updatethread(&smb, remsg, smb.status.last_msg+1))!=SMB_SUCCESS) errormsg(WHERE,"updating thread",smb.file,i,smb.last_error); } smb_hfield_str(&msg,RECIPIENT,touser); SAFECOPY(str,cfg.sub[subnum]->misc&SUB_NAME ? useron.name : useron.alias); smb_hfield_str(&msg,SENDER,str); sprintf(str,"%u",useron.number); smb_hfield_str(&msg,SENDEREXT,str); /* Security logging */ msg_client_hfields(&msg,&client); smb_hfield_str(&msg,SENDERSERVER,startup->host_name); smb_hfield_str(&msg,SUBJECT,title); /* Generate default (RFC822) message-id (always) */ get_msgid(&cfg,subnum,&msg,msg_id,sizeof(msg_id)); smb_hfield_str(&msg,RFC822MSGID,msg_id); /* Generate FTN (FTS-9) MSGID */ if(cfg.sub[subnum]->misc&SUB_FIDO) { ftn_msgid(cfg.sub[subnum],&msg,msg_id,sizeof(msg_id)); smb_hfield_str(&msg,FIDOMSGID,msg_id); } /* Generate FidoNet Program Identifier */ smb_hfield_str(&msg,FIDOPID,msg_program_id(pid)); if(editor!=NULL) smb_hfield_str(&msg,SMB_EDITOR,editor); i=smb_addmsg(&smb,&msg,storage,dupechk_hashes,xlat,(uchar*)msgbuf,NULL); free(msgbuf); if(i==SMB_DUPE_MSG) { attr(cfg.color[clr_err]); bprintf(text[CantPostMsg], smb.last_error); } else if(i!=SMB_SUCCESS) errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); smb_freemsgmem(&msg); if(i!=SMB_SUCCESS) return(false); logon_posts++; user_posted_msg(&cfg, &useron, 1); bprintf(text[Posted],cfg.grp[cfg.sub[subnum]->grp]->sname ,cfg.sub[subnum]->lname); sprintf(str,"%s posted on %s %s" ,useron.alias,cfg.grp[cfg.sub[subnum]->grp]->sname,cfg.sub[subnum]->lname); logline("P+",str); signal_sub_sem(&cfg,subnum); user_event(EVENT_POST); return(true); }
void sbbs_t::readmail(uint usernumber, int which) { char str[256],str2[256],str3[256],done=0,domsg=1 ,*p,*tp,*sp,ch; char tmp[512]; int i,j; int error; int mismatches=0,act; long length,l,lm_mode; ulong last; bool replied; file_t fd; mail_t *mail; smbmsg_t msg; if(which==MAIL_SENT && useron.rest&FLAG('K')) { bputs(text[R_ReadSentMail]); return; } msg.total_hfields=0; /* init to NULL, cause not allocated yet */ fd.dir=cfg.total_dirs+1; /* temp dir for file attachments */ if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) { errormsg(WHERE,ERR_OPEN,"MAIL",i); return; } sprintf(smb.file,"%smail",cfg.data_dir); smb.retry_time=cfg.smb_retry_time; smb.subnum=INVALID_SUB; if((i=smb_open(&smb))!=0) { smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return; } if(cfg.sys_misc&SM_SYSVDELM && (SYSOP || cfg.sys_misc&SM_USRVDELM)) lm_mode=LM_INCDEL; else lm_mode=0; mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode); if(!smb.msgs) { if(which==MAIL_SENT) bputs(text[NoMailSent]); else if(which==MAIL_ALL) bputs(text[NoMailOnSystem]); else bputs(text[NoMailWaiting]); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); return; } last=smb.status.last_msg; if(which==MAIL_SENT) act=NODE_RSML; else if(which==MAIL_ALL) act=NODE_SYSP; else act=NODE_RMAL; action=act; if(smb.msgs>1 && which!=MAIL_ALL) { if(which==MAIL_SENT) bputs(text[MailSentLstHdr]); else bputs(text[MailWaitingLstHdr]); for(smb.curmsg=0;smb.curmsg<smb.msgs && !msgabort();smb.curmsg++) { if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=mail[smb.curmsg].offset; if(!loadmsg(&msg,mail[smb.curmsg].number)) continue; smb_unlockmsghdr(&smb,&msg); bprintf(text[MailWaitingLstFmt],smb.curmsg+1 ,which==MAIL_SENT ? msg.to : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP ? text[Anonymous] : msg.from ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R' : msg.hdr.attr&MSG_READ ? ' ' : msg.from_net.type || msg.to_net.type ? 'N':'*' ,msg.subj); smb_freemsgmem(&msg); msg.total_hfields=0; } ASYNC; if(!(sys_status&SS_ABORT)) { bprintf(text[StartWithN],1L); if((long)(smb.curmsg=getnum(smb.msgs))>0) smb.curmsg--; else if((long)smb.curmsg==-1) { free(mail); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); return; } } sys_status&=~SS_ABORT; } else { smb.curmsg=0; if(which==MAIL_ALL) domsg=0; } if(which==MAIL_SENT) { sprintf(str,"%s read sent mail",useron.alias); logline("E",str); } else if(which==MAIL_ALL) { sprintf(str,"%s read all mail",useron.alias); logline("S+",str); } else { sprintf(str,"%s read mail",useron.alias); logline("E",str); } if(useron.misc&RIP) { strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ? "allmail" : "sentmail"); menu(str); } while(online && !done) { action=act; if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=mail[smb.curmsg].offset; msg.idx.number=mail[smb.curmsg].number; msg.idx.to=mail[smb.curmsg].to; msg.idx.from=mail[smb.curmsg].from; msg.idx.subj=mail[smb.curmsg].subj; if((i=smb_locksmbhdr(&smb))!=0) { errormsg(WHERE,ERR_LOCK,smb.file,i); break; } if((i=smb_getstatus(&smb))!=0) { smb_unlocksmbhdr(&smb); errormsg(WHERE,ERR_READ,smb.file,i); break; } smb_unlocksmbhdr(&smb); if(smb.status.last_msg!=last) { /* New messages */ last=smb.status.last_msg; free(mail); mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode); /* So re-load */ if(!smb.msgs) break; for(smb.curmsg=0;smb.curmsg<smb.msgs;smb.curmsg++) if(mail[smb.curmsg].number==msg.idx.number) break; if(smb.curmsg>=smb.msgs) smb.curmsg=(smb.msgs-1); continue; } if(!loadmsg(&msg,mail[smb.curmsg].number)) { /* Message header gone */ if(mismatches>5) { /* We can't do this too many times in a row */ errormsg(WHERE,ERR_CHK,"message number",mail[smb.curmsg].number); break; } free(mail); mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode); if(!smb.msgs) break; if(smb.curmsg>(smb.msgs-1)) smb.curmsg=(smb.msgs-1); mismatches++; continue; } smb_unlockmsghdr(&smb,&msg); msg.idx.attr=msg.hdr.attr; mismatches=0; if(domsg && !(sys_status&SS_ABORT)) { show_msg(&msg ,msg.from_ext && msg.idx.from==1 && !msg.from_net.type ? 0:P_NOATCODES); if(msg.hdr.auxattr&MSG_FILEATTACH) { /* Attached file */ smb_getmsgidx(&smb,&msg); strcpy(str,msg.subj); /* filenames in title */ // strupr(str); tp=str; while(online) { p=strchr(tp,' '); if(p) *p=0; sp=strrchr(tp,'/'); /* sp is slash pointer */ if(!sp) sp=strrchr(tp,'\\'); if(sp) tp=sp+1; padfname(tp,fd.name); sprintf(str2,"%sfile/%04u.in/%s" /* str2 is path/fname */ ,cfg.data_dir,msg.idx.to,tp); length=flength(str2); if(length<1) bputs(text[FileNotFound]); else if(!(useron.exempt&FLAG('T')) && cur_cps && !SYSOP && length/(long)cur_cps>(time_t)timeleft) bputs(text[NotEnoughTimeToDl]); else { sprintf(str3,text[DownloadAttachedFileQ] ,tp,ultoac(length,tmp)); if(length>0L && yesno(str3)) { #if 0 /* no such thing as local logon */ if(online==ON_LOCAL) { bputs(text[EnterPath]); if(getstr(str3,60,K_LINE)) { backslashcolon(str3); sprintf(tmp,"%s%s",str3,tp); if(!mv(str2,tmp,which!=MAIL_YOUR)) { logon_dlb+=length; logon_dls++; useron.dls=(ushort)adjustuserrec(&cfg,useron.number ,U_DLS,5,1); useron.dlb=adjustuserrec(&cfg,useron.number ,U_DLB,10,length); bprintf(text[FileNBytesSent] ,fd.name,ultoac(length,tmp)); } } } else #endif { /* Remote User */ xfer_prot_menu(XFER_DOWNLOAD); mnemonics(text[ProtocolOrQuit]); strcpy(str3,"Q"); for(i=0;i<cfg.total_prots;i++) if(cfg.prot[i]->dlcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) { sprintf(tmp,"%c",cfg.prot[i]->mnemonic); strcat(str3,tmp); } ch=(char)getkeys(str3,0); for(i=0;i<cfg.total_prots;i++) if(cfg.prot[i]->dlcmd[0] && ch==cfg.prot[i]->mnemonic && chk_ar(cfg.prot[i]->ar,&useron)) break; if(i<cfg.total_prots) { error=protocol(cfg.prot[i],XFER_DOWNLOAD,str2,nulstr,false); if(checkprotresult(cfg.prot[i],error,&fd)) { if(which==MAIL_YOUR) remove(str2); logon_dlb+=length; /* Update stats */ logon_dls++; useron.dls=(ushort)adjustuserrec(&cfg,useron.number ,U_DLS,5,1); useron.dlb=adjustuserrec(&cfg,useron.number ,U_DLB,10,length); bprintf(text[FileNBytesSent] ,fd.name,ultoac(length,tmp)); sprintf(str3 ,"%s downloaded attached file: %s" ,useron.alias ,fd.name); logline("D-",str3); } autohangup(); } } } } if(!p) break; tp=p+1; while(*tp==' ') tp++; } sprintf(str,"%sfile/%04u.in",cfg.data_dir,usernumber); rmdir(str); } if(which==MAIL_YOUR && !(msg.hdr.attr&MSG_READ)) { mail[smb.curmsg].attr|=MSG_READ; if(thisnode.status==NODE_INUSE) telluser(&msg); if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=0; /* Search by number */ if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */ if(loadmsg(&msg,msg.idx.number)) { msg.hdr.attr|=MSG_READ; msg.idx.attr=msg.hdr.attr; if((i=smb_putmsg(&smb,&msg))!=0) errormsg(WHERE,ERR_WRITE,smb.file,i); smb_unlockmsghdr(&smb,&msg); } smb_unlocksmbhdr(&smb); } if(!msg.total_hfields) { /* unsuccessful reload */ domsg=0; continue; } } } else domsg=1; if(useron.misc&WIP) { strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ? "allmail" : "sentmail"); menu(str); } ASYNC; if(which==MAIL_SENT) bprintf(text[ReadingSentMail],smb.curmsg+1,smb.msgs); else if(which==MAIL_ALL) bprintf(text[ReadingAllMail],smb.curmsg+1,smb.msgs); else bprintf(text[ReadingMail],smb.curmsg+1,smb.msgs); sprintf(str,"ADFLNQRT?<>[]{}-+"); if(SYSOP) strcat(str,"CUSPH"); if(which!=MAIL_YOUR) strcat(str,"E"); l=getkeys(str,smb.msgs); if(l&0x80000000L) { if(l==-1) /* ctrl-c */ break; smb.curmsg=(l&~0x80000000L)-1; continue; } switch(l) { case 'A': /* Auto-reply to last piece */ case 'R': if(l==(cfg.sys_misc&SM_RA_EMU ? 'A' : 'R')) /* re-read last message */ break; if(which==MAIL_SENT) break; if((msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP) { bputs(text[CantReplyToAnonMsg]); break; } quotemsg(&msg,1); if(msg.from_net.addr==NULL) SAFECOPY(str,msg.from); else if(msg.from_net.type==NET_FIDO) /* FidoNet type */ SAFEPRINTF2(str,"%s@%s",msg.from ,smb_faddrtoa((faddr_t *)msg.from_net.addr,tmp)); else if(msg.from_net.type==NET_INTERNET) { if(msg.replyto_net.type==NET_INTERNET) SAFECOPY(str,(char *)msg.replyto_net.addr); else SAFECOPY(str,(char *)msg.from_net.addr); } else SAFEPRINTF2(str,"%s@%s",msg.from,(char*)msg.from_net.addr); SAFECOPY(str2,str); bputs(text[Email]); if(!getstr(str,64,K_EDIT|K_AUTODEL)) break; msg.hdr.number=msg.idx.number; smb_getmsgidx(&smb,&msg); if(!stricmp(str2,str)) /* Reply to sender */ sprintf(str2,text[Regarding],msg.subj); else /* Reply to other */ sprintf(str2,text[RegardingByOn],msg.subj,msg.from ,timestr((time_t *)&msg.hdr.when_written.time)); p=strrchr(str,'@'); if(p) { /* name @addr */ replied=netmail(str,msg.subj,WM_QUOTE); sprintf(str2,text[DeleteMailQ],msg.from); } else { if(!msg.from_net.type && !stricmp(str,msg.from)) replied=email(msg.idx.from,str2,msg.subj,WM_EMAIL|WM_QUOTE); else if(!stricmp(str,"SYSOP")) replied=email(1,str2,msg.subj,WM_EMAIL|WM_QUOTE); else if((i=finduser(str))!=0) replied=email(i,str2,msg.subj,WM_EMAIL|WM_QUOTE); else replied=false; sprintf(str2,text[DeleteMailQ],msg.from); } if(replied==true && !(msg.hdr.attr&MSG_REPLIED)) { if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=0; if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */ if(loadmsg(&msg,msg.idx.number)) { msg.hdr.attr|=MSG_REPLIED; msg.idx.attr=msg.hdr.attr; if((i=smb_putmsg(&smb,&msg))!=0) errormsg(WHERE,ERR_WRITE,smb.file,i); smb_unlockmsghdr(&smb,&msg); } smb_unlocksmbhdr(&smb); } } if(msg.hdr.attr&MSG_DELETE || !yesno(str2)) { if(smb.curmsg<smb.msgs-1) smb.curmsg++; else done=1; break; } /* Case 'D': must follow! */ case 'D': /* Delete last piece (toggle) */ if(msg.hdr.attr&MSG_PERMANENT) { bputs("\r\nPermanent message.\r\n"); domsg=0; break; } if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=0; if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */ if(loadmsg(&msg,msg.idx.number)) { msg.hdr.attr^=MSG_DELETE; msg.idx.attr=msg.hdr.attr; // mail[smb.curmsg].attr=msg.hdr.attr; if((i=smb_putmsg(&smb,&msg))!=0) errormsg(WHERE,ERR_WRITE,smb.file,i); smb_unlockmsghdr(&smb,&msg); } smb_unlocksmbhdr(&smb); } if(smb.curmsg<smb.msgs-1) smb.curmsg++; else done=1; break; case 'F': /* Forward last piece */ domsg=0; bputs(text[ForwardMailTo]); if(!getstr(str,LEN_ALIAS,cfg.uq&UQ_NOUPRLWR ? K_NONE:K_UPRLWR)) break; i=finduser(str); if(!i) break; domsg=1; if(smb.curmsg<smb.msgs-1) smb.curmsg++; else done=1; smb_getmsgidx(&smb,&msg); forwardmail(&msg,i); if(msg.hdr.attr&MSG_PERMANENT) break; sprintf(str2,text[DeleteMailQ],msg.from); if(!yesno(str2)) break; if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=0; if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */ if(loadmsg(&msg,msg.idx.number)) { msg.hdr.attr|=MSG_DELETE; msg.idx.attr=msg.hdr.attr; // mail[smb.curmsg].attr=msg.hdr.attr; if((i=smb_putmsg(&smb,&msg))!=0) errormsg(WHERE,ERR_WRITE,smb.file,i); smb_unlockmsghdr(&smb,&msg); } smb_unlocksmbhdr(&smb); } break; case 'H': domsg=0; msghdr(&msg); break; case 'L': /* List mail */ domsg=0; bprintf(text[StartWithN],(long)smb.curmsg+1); if((i=getnum(smb.msgs))>0) i--; else if(i==-1) break; else i=smb.curmsg; if(which==MAIL_SENT) bputs(text[MailSentLstHdr]); else if(which==MAIL_ALL) bputs(text[MailOnSystemLstHdr]); else bputs(text[MailWaitingLstHdr]); for(;i<smb.msgs && !msgabort();i++) { if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=mail[i].offset; if(!loadmsg(&msg,mail[i].number)) continue; smb_unlockmsghdr(&smb,&msg); if(which==MAIL_ALL) bprintf(text[MailOnSystemLstFmt] ,i+1,msg.from,msg.to ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R' : msg.hdr.attr&MSG_READ ? ' ' : msg.from_net.type || msg.to_net.type ? 'N':'*' ,msg.subj); else bprintf(text[MailWaitingLstFmt],i+1 ,which==MAIL_SENT ? msg.to : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP ? text[Anonymous] : msg.from ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R' : msg.hdr.attr&MSG_READ ? ' ' : msg.from_net.type || msg.to_net.type ? 'N':'*' ,msg.subj); smb_freemsgmem(&msg); msg.total_hfields=0; } break; case 'Q': done=1; break; case 'C': /* Change attributes of last piece */ i=chmsgattr(msg.hdr.attr); if(msg.hdr.attr==i) break; if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=0; if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */ if(loadmsg(&msg,msg.idx.number)) { msg.hdr.attr=msg.idx.attr=(ushort)i; if((i=smb_putmsg(&smb,&msg))!=0) errormsg(WHERE,ERR_WRITE,smb.file,i); smb_unlockmsghdr(&smb,&msg); } smb_unlocksmbhdr(&smb); } break; case '>': for(i=smb.curmsg+1;i<smb.msgs;i++) if(mail[i].subj==msg.idx.subj) break; if(i<smb.msgs) smb.curmsg=i; else domsg=0; break; case '<': /* Search Title backward */ for(i=smb.curmsg-1;i>-1;i--) if(mail[i].subj==msg.idx.subj) break; if(i>-1) smb.curmsg=i; else domsg=0; break; case '}': /* Search Author forward */ strcpy(str,msg.from); for(i=smb.curmsg+1;i<smb.msgs;i++) if(mail[i].from==msg.idx.from) break; if(i<smb.msgs) smb.curmsg=i; else domsg=0; break; case 'N': /* Got to next un-read message */ for(i=smb.curmsg+1;i<smb.msgs;i++) if(!(mail[i].attr&MSG_READ)) break; if(i<smb.msgs) smb.curmsg=i; else domsg=0; break; case '{': /* Search Author backward */ strcpy(str,msg.from); for(i=smb.curmsg-1;i>-1;i--) if(mail[i].from==msg.idx.from) break; if(i>-1) smb.curmsg=i; else domsg=0; break; case ']': /* Search To User forward */ strcpy(str,msg.to); for(i=smb.curmsg+1;i<smb.msgs;i++) if(mail[i].to==msg.idx.to) break; if(i<smb.msgs) smb.curmsg=i; else domsg=0; break; case '[': /* Search To User backward */ strcpy(str,msg.to); for(i=smb.curmsg-1;i>-1;i--) if(mail[i].to==msg.idx.to) break; if(i>-1) smb.curmsg=i; else domsg=0; break; case 0: case '+': if(smb.curmsg<smb.msgs-1) smb.curmsg++; else done=1; break; case '-': if(smb.curmsg>0) smb.curmsg--; break; case 'S': domsg=0; /* if(!yesno(text[SaveMsgToFile])) break; */ bputs(text[FileToWriteTo]); if(getstr(str,40,K_LINE)) msgtotxt(&msg,str,1,1); break; case 'E': editmsg(&msg,INVALID_SUB); break; case 'T': domsg=0; i=smb.curmsg; if(i) i++; j=i+10; if(j>smb.msgs) j=smb.msgs; if(which==MAIL_SENT) bputs(text[MailSentLstHdr]); else if(which==MAIL_ALL) bputs(text[MailOnSystemLstHdr]); else bputs(text[MailWaitingLstHdr]); for(;i<j;i++) { if(msg.total_hfields) smb_freemsgmem(&msg); msg.total_hfields=0; msg.idx.offset=mail[i].offset; if(!loadmsg(&msg,mail[i].number)) continue; smb_unlockmsghdr(&smb,&msg); if(which==MAIL_ALL) bprintf(text[MailOnSystemLstFmt] ,i+1,msg.from,msg.to ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R' : msg.hdr.attr&MSG_READ ? ' ' : msg.from_net.type || msg.to_net.type ? 'N':'*' ,msg.subj); else bprintf(text[MailWaitingLstFmt],i+1 ,which==MAIL_SENT ? msg.to : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP ? text[Anonymous] : msg.from ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R' : msg.hdr.attr&MSG_READ ? ' ' : msg.from_net.type || msg.to_net.type ? 'N':'*' ,msg.subj); smb_freemsgmem(&msg); msg.total_hfields=0; } smb.curmsg=(i-1); break; case 'U': /* user edit */ msg.hdr.number=msg.idx.number; smb_getmsgidx(&smb,&msg); useredit(which==MAIL_SENT ? msg.idx.to : msg.idx.from); break; case 'P': /* Purge author and all mail to/from */ if(noyes(text[AreYouSureQ])) break; msg.hdr.number=msg.idx.number; smb_getmsgidx(&smb,&msg); purgeuser(msg.idx.from); if(smb.curmsg<smb.msgs-1) smb.curmsg++; break; case '?': strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ? "allmail" : "sentmail"); menu(str); if(SYSOP && which==MAIL_SENT) menu("syssmail"); else if(SYSOP && which==MAIL_YOUR) menu("sysmailr"); /* Sysop Mail Read */ domsg=0; break; } } if(msg.total_hfields) smb_freemsgmem(&msg); if(smb.msgs) free(mail); /***************************************/ /* Delete messages marked for deletion */ /***************************************/ if(cfg.sys_misc&SM_DELEMAIL) { if((i=smb_locksmbhdr(&smb))!=0) /* Lock the base, so nobody */ errormsg(WHERE,ERR_LOCK,smb.file,i); /* messes with the index */ else delmail(usernumber,which); } smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); }
static int send_files(char** fname, uint fnames) { char path[MAX_PATH+1]; int i; uint errors; uint fnum; uint cps; glob_t g; int gi; BOOL success=TRUE; long fsize; ulong sent_bytes; ulong total_bytes=0; time_t t,startfile; time_t startall; FILE* fp; startall=time(NULL); /****************************************************/ /* Search through all to find total files and bytes */ /****************************************************/ for(fnum=0;fnum<fnames;fnum++) { if(glob(fname[fnum],0,NULL,&g)) { lprintf(LOG_WARNING,"%s not found",fname[fnum]); continue; } for(i=0;i<(int)g.gl_pathc;i++) { if(isdir(g.gl_pathv[i])) continue; xm.total_files++; xm.total_bytes+=flength(g.gl_pathv[i]); } globfree(&g); } if(xm.total_files<1) { lprintf(LOG_ERR,"No files to send"); return(-1); } if(xm.total_files>1) lprintf(LOG_INFO,"Sending %u files (%lu KB total)" ,xm.total_files,xm.total_bytes/1024); zm.files_remaining = xm.total_files; zm.bytes_remaining = xm.total_bytes; /***********************************************/ /* Send every file matching names or filespecs */ /***********************************************/ for(fnum=0;fnum<fnames;fnum++) { if(glob(fname[fnum],0,NULL,&g)) { lprintf(LOG_WARNING,"%s not found",fname[fnum]); continue; } for(gi=0;gi<(int)g.gl_pathc;gi++) { SAFECOPY(path,g.gl_pathv[gi]); if(isdir(path)) continue; if((fp=fnopen(NULL,path,O_RDONLY|O_BINARY))==NULL && (fp=fopen(path,"rb"))==NULL) { lprintf(LOG_ERR,"Error %d opening %s for read",errno,path); continue; } setvbuf(fp,NULL,_IOFBF,0x10000); fsize=filelength(fileno(fp)); errors=0; success=FALSE; startfile=time(NULL); lprintf(LOG_INFO,"Sending %s (%lu KB) via %s" ,path,fsize/1024 ,mode&XMODEM ? "Xmodem" : mode&YMODEM ? "Ymodem" : "Zmodem"); if(mode&ZMODEM) success=zmodem_send_file(&zm, path, fp, /* ZRQINIT? */fnum==0, &startfile, &sent_bytes); else /* X/Ymodem */ success=xmodem_send_file(&xm, path, fp, &startfile, &sent_bytes); fclose(fp); if((t=time(NULL)-startfile)<=0) t=1; if((cps=sent_bytes/t)==0) cps=1; if(success) { xm.sent_files++; xm.sent_bytes+=fsize; lprintf(LOG_INFO,"Successful - Time: %lu:%02lu CPS: %lu" ,t/60,t%60,cps); if(xm.total_files-xm.sent_files) lprintf(LOG_INFO,"Remaining - Time: %lu:%02lu Files: %u KBytes: %lu" ,((xm.total_bytes-xm.sent_bytes)/cps)/60 ,((xm.total_bytes-xm.sent_bytes)/cps)%60 ,xm.total_files-xm.sent_files ,(xm.total_bytes-xm.sent_bytes)/1024 ); } else lprintf(LOG_WARNING,"File Transfer %s", aborted ? "Aborted" : "Failure"); /* DSZLOG entry */ if(logfp) { lprintf(LOG_DEBUG,"Updating DSZLOG: %s", dszlog); fprintf(logfp,"%c %7lu %5u bps %6lu cps %3u errors %5u %4u " "%s -1\n" ,success ? (mode&ZMODEM ? 'z':'S') : (mode&ZMODEM && zm.file_skipped) ? 's' : 'E' ,sent_bytes ,115200 /* baud */ ,cps ,mode&ZMODEM ? zm.errors : xm.errors ,flows ,mode&ZMODEM ? zm.block_size : xm.block_size ,dszlog_filename(path)); fflush(logfp); } total_bytes += sent_bytes; if(aborted) { xm.cancelled=FALSE; xmodem_cancel(&xm); break; } if(xm.cancelled || zm.cancelled) break; } /* while(gi<(int)g.gl_pathc) */ if(gi<(int)g.gl_pathc)/* error occurred */ break; } if(mode&ZMODEM && !zm.cancelled && is_connected(NULL)) zmodem_get_zfin(&zm); if(fnum<fnames) /* error occurred */ return(-1); if(!success) return(-1); if(mode&XMODEM) return(0); if(mode&YMODEM) { if(xmodem_get_mode(&xm)) { lprintf(LOG_INFO,"Sending Ymodem termination block"); memset(block,0,128); /* send short block for terminator */ xmodem_put_block(&xm, block, 128 /* block_size */, 0 /* block_num */); if(!xmodem_get_ack(&xm,6,0)) { lprintf(LOG_WARNING,"Failed to receive ACK after terminating block"); } } } if(xm.total_files>1) { t=time(NULL)-startall; if(!t) t=1; lprintf(LOG_INFO,"Overall - Time %02lu:%02lu KBytes: %lu CPS: %lu" ,t/60,t%60,total_bytes/1024,total_bytes/t); } return(0); /* success */ }
void sbbs_t::closefile(file_t* f) { char str1[256],str2[4],str3[4],ch,*buf; int file; long length,l,offset; /************************************/ /* Decrement open count in dat file */ /************************************/ sprintf(str1,"%s%s.dat",cfg.dir[f->dir]->data_dir,cfg.dir[f->dir]->code); if((file=nopen(str1,O_RDWR))==-1) { errormsg(WHERE,ERR_OPEN,str1,O_RDWR); return; } lseek(file,f->datoffset+F_OPENCOUNT,SEEK_SET); if(read(file,str2,3)!=3) { close(file); errormsg(WHERE,ERR_READ,str1,3); return; } str2[3]=0; ch=atoi(str2); if(ch) ch--; ultoa(ch,str3,10); putrec(str2,0,3,str3); lseek(file,f->datoffset+F_OPENCOUNT,SEEK_SET); if(write(file,str2,3)!=3) { close(file); errormsg(WHERE,ERR_WRITE,str1,3); return; } close(file); /*****************************************/ /* Removing transaction from BACKOUT.DAB */ /*****************************************/ sprintf(str1,"%sbackout.dab",cfg.node_dir); if(flength(str1)<1L) /* file is not there or empty */ return; if((file=nopen(str1,O_RDONLY))==-1) { errormsg(WHERE,ERR_OPEN,str1,O_RDONLY); return; } length=filelength(file); if((buf=(char *)malloc(length))==NULL) { close(file); errormsg(WHERE,ERR_ALLOC,str1,length); return; } if(read(file,buf,length)!=length) { close(file); free(buf); errormsg(WHERE,ERR_READ,str1,length); return; } close(file); if((file=nopen(str1,O_WRONLY|O_TRUNC))==-1) { errormsg(WHERE,ERR_OPEN,str1,O_WRONLY|O_TRUNC); return; } ch=0; /* 'ch' is a 'file already removed' flag */ for(l=0;l<length;l+=BO_LEN) { /* in case file is in backout.dab > 1 */ if(!ch && buf[l]==BO_OPENFILE) { memcpy(str1,buf+l+1,8); str1[8]=0; memcpy(&offset,buf+l+9,4); if(!stricmp(str1,cfg.dir[f->dir]->code) && offset==f->datoffset) { ch=1; continue; } } write(file,buf+l,BO_LEN); } free(buf); close(file); }
int sbbs_t::exec_misc(csi_t* csi, char *path) { char str[512],tmp[512],buf[1025],ch,op,*p,**pp,**pp1,**pp2; ushort w; uint i=0,j; long l,*lp=NULL,*lp1=NULL,*lp2=NULL; void *vp; struct dirent *de; struct tm tm; switch(*(csi->ip++)) { case CS_VAR_INSTRUCTION: switch(*(csi->ip++)) { /* sub-op-code stored as next byte */ case PRINT_VAR: pp=getstrvar(csi,*(long *)csi->ip); if(!pp || !*pp) { lp=getintvar(csi,*(long *)csi->ip); if(lp) bprintf("%ld",*lp); } else putmsg(cmdstr(*pp,path,csi->str,buf) ,P_SAVEATR|P_NOABORT|P_NOATCODES); csi->ip+=4; return(0); case VAR_PRINTF: case VAR_PRINTF_LOCAL: op=*(csi->ip-1); p=format_string(this, csi); if(op==VAR_PRINTF) putmsg(cmdstr(p,path,csi->str,buf),P_SAVEATR|P_NOABORT|P_NOATCODES); else { if(online==ON_LOCAL) eprintf(LOG_INFO,"%s",cmdstr(p,path,csi->str,buf)); else lputs(LOG_INFO,cmdstr(p,path,csi->str,buf)); } free(p); return(0); case SHOW_VARS: bprintf("shell str=(%08lX) %s\r\n" ,csi->str,csi->str); for(i=0;i<csi->str_vars;i++) bprintf("local str[%d]=(%08lX) (%08lX) %s\r\n" ,i,csi->str_var_name[i] ,csi->str_var[i] ,csi->str_var[i]); for(i=0;i<csi->int_vars;i++) bprintf("local int[%d]=(%08lX) (%08lX) %ld\r\n" ,i,csi->int_var_name[i] ,csi->int_var[i] ,csi->int_var[i]); for(i=0;i<global_str_vars;i++) bprintf("global str[%d]=(%08lX) (%08lX) %s\r\n" ,i,global_str_var_name[i] ,global_str_var[i] ,global_str_var[i]); for(i=0;i<global_int_vars;i++) bprintf("global int[%d]=(%08lX) (%08lX) %ld\r\n" ,i,global_int_var_name[i] ,global_int_var[i] ,global_int_var[i]); return(0); case DEFINE_STR_VAR: if(getstrvar(csi,*(long *)csi->ip)) { csi->ip+=4; return(0); } csi->str_vars++; csi->str_var=(char **)realloc(csi->str_var ,sizeof(char *)*csi->str_vars); csi->str_var_name=(long *)realloc(csi->str_var_name ,sizeof(long)*csi->str_vars); if(csi->str_var==NULL || csi->str_var_name==NULL) { /* REALLOC failed */ errormsg(WHERE,ERR_ALLOC,"local str var" ,sizeof(char *)*csi->str_vars); if(csi->str_var_name) { free(csi->str_var_name); csi->str_var_name=0; } if(csi->str_var) { free(csi->str_var); csi->str_var=0; } csi->str_vars=0; } else { csi->str_var_name[csi->str_vars-1]=*(long *)csi->ip; csi->str_var[csi->str_vars-1]=0; } csi->ip+=4; /* Skip variable name */ return(0); case DEFINE_INT_VAR: if(getintvar(csi,*(long *)csi->ip)) { csi->ip+=4; return(0); } csi->int_vars++; csi->int_var=(long *)realloc(csi->int_var ,sizeof(char *)*csi->int_vars); csi->int_var_name=(long *)realloc(csi->int_var_name ,sizeof(long)*csi->int_vars); if(csi->int_var==NULL || csi->int_var_name==NULL) { /* REALLOC failed */ errormsg(WHERE,ERR_ALLOC,"local int var" ,sizeof(char *)*csi->int_vars); if(csi->int_var_name) { free(csi->int_var_name); csi->int_var_name=0; } if(csi->int_var) { free(csi->int_var); csi->int_var=0; } csi->int_vars=0; } else { csi->int_var_name[csi->int_vars-1]=*(long *)csi->ip; csi->int_var[csi->int_vars-1]=0; } csi->ip+=4; /* Skip variable name */ return(0); case DEFINE_GLOBAL_STR_VAR: if(getstrvar(csi,*(long *)csi->ip)) { csi->ip+=4; return(0); } global_str_vars++; global_str_var=(char **)realloc(global_str_var ,sizeof(char *)*global_str_vars); global_str_var_name=(long *)realloc(global_str_var_name ,sizeof(long)*global_str_vars); if(global_str_var==NULL || global_str_var_name==NULL) { /* REALLOC failed */ errormsg(WHERE,ERR_ALLOC,"global str var" ,sizeof(char *)*global_str_vars); if(global_str_var_name) { free(global_str_var_name); global_str_var_name=0; } if(global_str_var) { free(global_str_var); global_str_var=0; } global_str_vars=0; } else { global_str_var_name[global_str_vars-1]= *(long *)csi->ip; global_str_var[global_str_vars-1]=0; } csi->ip+=4; /* Skip variable name */ return(0); case DEFINE_GLOBAL_INT_VAR: if(getintvar(csi,*(long *)csi->ip)) { csi->ip+=4; return(0); } global_int_vars++; global_int_var=(long *)realloc(global_int_var ,sizeof(char *)*global_int_vars); global_int_var_name=(long *)realloc(global_int_var_name ,sizeof(long)*global_int_vars); if(global_int_var==NULL || global_int_var_name==NULL) { /* REALLOC failed */ errormsg(WHERE,ERR_ALLOC,"local int var" ,sizeof(char *)*global_int_vars); if(global_int_var_name) { free(global_int_var_name); global_int_var_name=0; } if(global_int_var) { free(global_int_var); global_int_var=0; } global_int_vars=0; } else { global_int_var_name[global_int_vars-1] =*(long *)csi->ip; global_int_var[global_int_vars-1]=0; } csi->ip+=4; /* Skip variable name */ return(0); case SET_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(pp) *pp=copystrvar(csi,*pp ,cmdstr((char *)csi->ip,path,csi->str,buf)); while(*(csi->ip++)); /* Find NULL */ return(0); case SET_INT_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(lp) *lp=*(long *)csi->ip; csi->ip+=4; /* Skip value */ return(0); case COMPARE_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(pp && *pp) csi->logic=stricmp(*pp ,cmdstr((char *)csi->ip,path,csi->str,buf)); else { /* Uninitialized str var */ if(*(csi->ip)==0) /* Blank static str */ csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; } while(*(csi->ip++)); /* Find NULL */ return(0); case STRSTR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(pp && *pp && strstr(*pp ,cmdstr((char *)csi->ip,path,csi->str,buf))) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; while(*(csi->ip++)); /* Find NULL */ return(0); case STRNCMP_VAR: i=*csi->ip++; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(pp && *pp) csi->logic=strnicmp(*pp ,cmdstr((char *)csi->ip,path,csi->str,buf),i); else csi->logic=LOGIC_FALSE; while(*(csi->ip++)); /* Find NULL */ return(0); case STRNCMP_VARS: i=*csi->ip++; pp1=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp1 && *pp1 && pp2 && *pp2) csi->logic=strnicmp(*pp1,*pp2,i); else csi->logic=LOGIC_FALSE; return(0); case STRSTR_VARS: pp1=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp1 && *pp1 && pp2 && *pp2 && strstr(*pp1,*pp2)) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case COMPARE_INT_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ l=*(long *)csi->ip; csi->ip+=4; /* Skip static value */ if(!lp) { /* Unknown variable */ csi->logic=LOGIC_FALSE; return(0); } if(*lp>l) csi->logic=LOGIC_GREATER; else if(*lp<l) csi->logic=LOGIC_LESS; else csi->logic=LOGIC_EQUAL; return(0); case COMPARE_VARS: lp1=lp2=0; pp1=getstrvar(csi,*(long *)csi->ip); if(!pp1) lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); if(!pp2) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(((!pp1 || !*pp1) && !lp1) || ((!pp2 || !*pp2) && !lp2)) { if(pp1 && pp2) /* Both unitialized or blank */ csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); } if(pp1) { /* ASCII */ if(!pp2) { ultoa(*lp2,tmp,10); csi->logic=stricmp(*pp1,tmp); } else csi->logic=stricmp(*pp1,*pp2); return(0); } /* Binary */ if(!lp2) { l=strtol(*pp2,0,0); if(*lp1>l) csi->logic=LOGIC_GREATER; else if(*lp1<l) csi->logic=LOGIC_LESS; else csi->logic=LOGIC_EQUAL; return(0); } if(*lp1>*lp2) csi->logic=LOGIC_GREATER; else if(*lp1<*lp2) csi->logic=LOGIC_LESS; else csi->logic=LOGIC_EQUAL; return(0); case COPY_VAR: lp1=lp2=0; pp1=getstrvar(csi,*(long *)csi->ip); if(!pp1) lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); if(!pp2) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if((!pp1 && !lp1) || ((!pp2 || !*pp2) && !lp2)) { csi->logic=LOGIC_FALSE; return(0); } csi->logic=LOGIC_TRUE; if(pp1) { /* ASCII */ if(!pp2) ultoa(*lp2,tmp,10); else strcpy(tmp,*pp2); *pp1=copystrvar(csi,*pp1,tmp); return(0); } if(!lp2) *lp1=strtol(*pp2,0,0); else *lp1=*lp2; return(0); case SWAP_VARS: lp1=lp2=0; pp1=getstrvar(csi,*(long *)csi->ip); if(!pp1) lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); if(!pp2) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(((!pp1 || !*pp1) && !lp1) || ((!pp2 || !*pp2) && !lp2)) { csi->logic=LOGIC_FALSE; return(0); } csi->logic=LOGIC_TRUE; if(pp1) { /* ASCII */ if(!pp2) { if(!strnicmp(*pp2,"0x",2)) { l=strtol((*pp1)+2,0,16); ultoa(*lp2,tmp,16); } else { l=atol(*pp1); ultoa(*lp2,tmp,10); } *pp1=copystrvar(csi,*pp1,tmp); *lp2=l; } else { p=*pp1; *pp1=*pp2; *pp2=p; } return(0); } /* Binary */ if(!lp2) { if(!strnicmp(*pp2,"0x",2)) { l=strtol((*pp2)+2,0,16); ultoa(*lp1,tmp,16); } else { l=atol(*pp2); ultoa(*lp1,tmp,10); } *pp2=copystrvar(csi,*pp2,tmp); *lp1=l; } else { l=*lp1; *lp1=*lp2; *lp2=l; } return(0); case CAT_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ strcpy(tmp,(char *)csi->ip); while(*(csi->ip++)); if(pp && *pp) for(i=0;i<MAX_SYSVARS;i++) if(*pp==sysvar_p[i]) break; if(pp && *pp!=csi->str && i==MAX_SYSVARS) { if(*pp) *pp=(char *)realloc(*pp,strlen(*pp)+strlen(tmp)+1); else *pp=(char *)realloc(*pp,strlen(tmp)+1); } if(pp && *pp) strcat(*pp,tmp); return(0); case CAT_STR_VARS: pp1=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip dest variable name */ pp2=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip source variable name */ /* Concatenate an int var to a str var (as char) */ if(pp2==NULL) { lp=getintvar(csi,*(long *)(csi->ip-4)); if(lp==NULL) { csi->logic=LOGIC_FALSE; return(0); } pp=pp1; tmp[0]=(uchar)*lp; tmp[1]=0; if(pp && *pp) for(i=0;i<MAX_SYSVARS;i++) if(*pp==sysvar_p[i]) break; if(pp && *pp!=csi->str && i==MAX_SYSVARS) { if(*pp) *pp=(char *)realloc(*pp,strlen(*pp)+strlen(tmp)+1); else *pp=(char *)realloc(*pp,strlen(tmp)+1); } if(pp && *pp) strcat(*pp,tmp); return(0); } if(!pp1 || !pp2 || !*pp2) { csi->logic=LOGIC_FALSE; return(0); } csi->logic=LOGIC_TRUE; if(*pp1) for(i=0;i<MAX_SYSVARS;i++) if(*pp1==sysvar_p[i]) break; if(*pp1!=csi->str && (!*pp1 || i==MAX_SYSVARS)) { if(*pp1) *pp1=(char *)realloc(*pp1,strlen(*pp1)+strlen(*pp2)+1); else *pp1=(char *)realloc(*pp1,strlen(*pp2)+1); } strcat(*pp1,*pp2); return(0); case FORMAT_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ p=format_string(this, csi); cmdstr(p,path,csi->str,str); if(pp) *pp=copystrvar(csi,*pp,str); free(p); return(0); case FORMAT_TIME_STR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ strcpy(str,(char *)csi->ip); while(*(csi->ip++)); /* Find NULL */ lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && lp) { if(localtime_r((time_t *)lp,&tm)!=NULL) { strftime(buf,128,str,&tm); *pp=copystrvar(csi,*pp,buf); } } return(0); case TIME_STR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip str variable name */ lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip int variable name */ if(pp && lp) { strcpy(str,timestr((time_t *)lp)); *pp=copystrvar(csi,*pp,str); } return(0); case DATE_STR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip str variable name */ lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip int variable name */ if(pp && lp) { unixtodstr(&cfg,*lp,str); *pp=copystrvar(csi,*pp,str); } return(0); case SECOND_STR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip str variable name */ lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip int variable name */ if(pp && lp) { sectostr(*lp,str); *pp=copystrvar(csi,*pp,str); } return(0); case STRUPR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) strupr(*pp); return(0); case STRLWR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) strlwr(*pp); return(0); case TRUNCSP_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) truncsp(*pp); return(0); case STRIP_CTRL_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) strip_ctrl(*pp); return(0); case ADD_INT_VAR: case SUB_INT_VAR: case MUL_INT_VAR: case DIV_INT_VAR: case MOD_INT_VAR: case AND_INT_VAR: case OR_INT_VAR: case NOT_INT_VAR: case XOR_INT_VAR: i=*(csi->ip-1); lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; l=*(long *)csi->ip; csi->ip+=4; if(!lp) return(0); switch(i) { case ADD_INT_VAR: *lp+=l; break; case SUB_INT_VAR: *lp-=l; break; case MUL_INT_VAR: *lp*=l; break; case DIV_INT_VAR: *lp/=l; break; case MOD_INT_VAR: *lp%=l; break; case AND_INT_VAR: *lp&=l; break; case OR_INT_VAR: *lp|=l; break; case NOT_INT_VAR: *lp&=~l; break; case XOR_INT_VAR: *lp^=l; break; } return(0); case COMPARE_ANY_BITS: case COMPARE_ALL_BITS: i=*(csi->ip-1); lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; l=*(long *)csi->ip; csi->ip+=4; csi->logic=LOGIC_FALSE; if(!lp) return(0); if(i==COMPARE_ANY_BITS) { if(((*lp)&l)!=0) csi->logic=LOGIC_TRUE; } else { if(((*lp)&l)==l) csi->logic=LOGIC_TRUE; } return(0); case ADD_INT_VARS: case SUB_INT_VARS: case MUL_INT_VARS: case DIV_INT_VARS: case MOD_INT_VARS: case AND_INT_VARS: case OR_INT_VARS: case NOT_INT_VARS: case XOR_INT_VARS: i=*(csi->ip-1); lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; lp2=getintvar(csi,*(long *)csi->ip); if(!lp2) { pp=getstrvar(csi,*(long *)csi->ip); if(!pp || !*pp) return(0); l=strtol(*pp,0,0); } else l=*lp2; csi->ip+=4; if(!lp1) return(0); switch(i) { case ADD_INT_VARS: *lp1+=l; break; case SUB_INT_VARS: *lp1-=l; break; case MUL_INT_VARS: *lp1*=l; break; case DIV_INT_VARS: *lp1/=l; break; case MOD_INT_VARS: *lp1%=l; break; case AND_INT_VARS: *lp1&=l; break; case OR_INT_VARS: *lp1|=l; break; case NOT_INT_VARS: *lp1&=~l; break; case XOR_INT_VARS: *lp1^=l; break; } return(0); case RANDOM_INT_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; l=*(long *)csi->ip; csi->ip+=4; if(lp) *lp=sbbs_random(l); return(0); case TIME_INT_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) *lp=time(NULL); return(0); case DATE_STR_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp && pp && *pp) *lp=dstrtounix(&cfg,*pp); return(0); case STRLEN_INT_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=strlen(*pp); else *lp=0; } return(0); case CRC16_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=crc16(*pp,0); else *lp=0; } return(0); case CRC32_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=crc32(*pp,0); else *lp=0; } return(0); case CHKSUM_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { *lp=0; if(pp && *pp) { i=0; while(*((*pp)+i)) *lp+=(uchar)*((*pp)+(i++)); } } return(0); case FLENGTH_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=flength(*pp); else *lp=0; } return(0); case FTIME_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=fdate(*pp); else *lp=0; } return(0); case CHARVAL_TO_INT: case COPY_FIRST_CHAR: // duplicate functionality - doh! lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=**pp; else *lp=0; } return(0); case GETSTR_VAR: case GETLINE_VAR: case GETNAME_VAR: case GETSTRUPR_VAR: case GETSTR_MODE: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; i=*(csi->ip++); csi->logic=LOGIC_FALSE; switch(*(csi->ip-6)) { case GETNAME_VAR: getstr(buf,i,K_UPRLWR); break; case GETSTRUPR_VAR: getstr(buf,i,K_UPPER); break; case GETLINE_VAR: getstr(buf,i,K_LINE); break; case GETSTR_MODE: l=*(long *)csi->ip; csi->ip+=4; if(l&K_EDIT) { if(pp && *pp) strcpy(buf,*pp); else buf[0]=0; } getstr(buf,i,l); break; default: getstr(buf,i,0); } if(sys_status&SS_ABORT) return(0); if(pp) { *pp=copystrvar(csi,*pp,buf); csi->logic=LOGIC_TRUE; } return(0); case GETNUM_VAR: pp=getstrvar(csi,*(long *)csi->ip); if(!pp) lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; i=*(short *)csi->ip; csi->ip+=2; csi->logic=LOGIC_FALSE; l=getnum(i); if(!pp && !lp) return(0); if(pp) { if(l<=0) str[0]=0; else ultoa(l,str,10); *pp=copystrvar(csi,*pp,str); csi->logic=LOGIC_TRUE; return(0); } if(lp) { *lp=l; csi->logic=LOGIC_TRUE; } return(0); case SHIFT_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; i=*(csi->ip++); if(!pp || !*pp) return(0); if(strlen(*pp)>=i) memmove(*pp,*pp+i,strlen(*pp)+1); return(0); case SHIFT_TO_FIRST_CHAR: case SHIFT_TO_LAST_CHAR: i=*(csi->ip-1); pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; ch=*(csi->ip++); csi->logic=LOGIC_FALSE; if(!pp || !*pp) return(0); if(i==SHIFT_TO_FIRST_CHAR) p=strchr(*pp,ch); else /* _TO_LAST_CHAR */ p=strrchr(*pp,ch); if(p==NULL) return(0); csi->logic=LOGIC_TRUE; i=p-*pp; if(i>0) memmove(*pp,*pp+i,strlen(p)+1); return(0); case CHKFILE_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp && fexistcase(cmdstr(*pp,path,csi->str,buf))) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case PRINTFILE_VAR_MODE: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; i=*(short *)(csi->ip); csi->ip+=2; if(pp && *pp) printfile(*pp,i); return(0); case PRINTTAIL_VAR_MODE: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; i=*(short *)(csi->ip); csi->ip+=2; j=*csi->ip; csi->ip++; if(pp && *pp) printtail(*pp,j,i); return(0); case TELNET_GATE_VAR: l=*(ulong *)(csi->ip); // Mode csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) telnet_gate(*pp,l); return(0); case TELNET_GATE_STR: l=*(ulong *)(csi->ip); // Mode csi->ip+=4; strcpy(str,(char *)csi->ip); while(*(csi->ip++)); /* Find NULL */ telnet_gate(str,l); return(0); case COPY_CHAR: pp=getstrvar(csi,*(long *)csi->ip); if(pp==NULL) lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp==NULL && lp!=NULL) *lp=csi->cmd; else if(pp!=NULL) { sprintf(tmp,"%c",csi->cmd); *pp=copystrvar(csi,*pp,tmp); } return(0); case COMPARE_FIRST_CHAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; ch=*(csi->ip++); /* char const */ if(pp==NULL || *pp==NULL) csi->logic=LOGIC_FALSE; else { if(**pp==ch) csi->logic=LOGIC_EQUAL; else if(**pp>ch) csi->logic=LOGIC_GREATER; else csi->logic=LOGIC_LESS; } return(0); case SEND_FILE_VIA: case RECEIVE_FILE_VIA: j=*(csi->ip-1); ch=*(csi->ip++); /* Protocol */ cmdstr((char *)csi->ip,csi->str,csi->str,str); while(*(csi->ip++)); /* Find NULL */ for(i=0;i<cfg.total_prots;i++) if(cfg.prot[i]->mnemonic==ch && chk_ar(cfg.prot[i]->ar,&useron)) break; csi->logic=LOGIC_FALSE; if(i<cfg.total_prots) if(protocol(cfg.prot[i],j==SEND_FILE_VIA ? XFER_DOWNLOAD : XFER_UPLOAD ,str,str,true)==0) csi->logic=LOGIC_TRUE; return(0); case SEND_FILE_VIA_VAR: case RECEIVE_FILE_VIA_VAR: j=*(csi->ip-1); ch=*(csi->ip++); /* Protocol */ pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; for(i=0;i<cfg.total_prots;i++) if(cfg.prot[i]->mnemonic==ch && chk_ar(cfg.prot[i]->ar,&useron)) break; csi->logic=LOGIC_FALSE; if(!pp || !(*pp)) return(0); if(i<cfg.total_prots) if(protocol(cfg.prot[i] ,j==SEND_FILE_VIA_VAR ? XFER_DOWNLOAD : XFER_UPLOAD ,*pp,*pp,true)==0) csi->logic=LOGIC_TRUE; return(0); case MATCHUSER: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=matchuser(&cfg, *pp, TRUE /*sysop_alias*/); else *lp=0; } return(0); default: errormsg(WHERE,ERR_CHK,"var sub-instruction",*(csi->ip-1)); return(0); } case CS_FIO_FUNCTION: switch(*(csi->ip++)) { /* sub-op-code stored as next byte */ case FIO_OPEN: case FIO_OPEN_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; w=*(ushort *)csi->ip; csi->ip+=2; csi->logic=LOGIC_FALSE; if(*(csi->ip-7)==FIO_OPEN) { cmdstr((char *)csi->ip,path,csi->str,str); while(*(csi->ip++)); } /* skip filename */ else { pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(!pp || !*pp) return(0); strcpy(str,*pp); } if(csi->files>=MAX_FOPENS) return(0); if(lp) { /* Access flags are not cross-platform, so convert */ i=0; if(w&0x001) i|=O_RDONLY; if(w&0x002) i|=O_WRONLY; if(w&0x004) i|=O_RDWR; if(w&0x040) i|=O_DENYNONE; if(w&0x100) i|=O_CREAT; if(w&0x200) i|=O_TRUNC; if(w&0x400) i|=O_EXCL; if(w&0x800) i|=O_APPEND; *lp=(long)fnopen((int *)&j,str,i); if(*lp) { for(i=0;i<csi->files;i++) if(!csi->file[i]) break; csi->file[i]=(FILE *)*lp; if(i==csi->files) csi->files++; csi->logic=LOGIC_TRUE; } } return(0); case FIO_CLOSE: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp && *lp) { csi->logic=fclose((FILE *)*lp); for(i=0;i<csi->files;i++) if(csi->file[i]==(FILE *)*lp) csi->file[i]=0; *lp=0; } else csi->logic=LOGIC_FALSE; return(0); case FIO_FLUSH: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp && *lp) csi->logic=fflush((FILE *)*lp); else csi->logic=LOGIC_FALSE; return(0); case FIO_READ: case FIO_READ_VAR: lp1=getintvar(csi,*(long *)csi->ip); /* Handle */ csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); if(!pp) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-9)==FIO_READ) { i=*(short *)csi->ip; csi->ip+=2; /* Length */ } else { /* FIO_READ_VAR */ vp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!vp) return(0); i=*(short *)vp; } if(i>sizeof(buf)-1) i=sizeof(buf)-1; if(!lp1 || !(*lp1) || (!pp && !lp2)) return(0); if(pp) { if(i<1) { if(*pp && **pp) i=strlen(*pp); else i=128; } if((j=fread(buf,1,i,(FILE *)*lp1))==i) csi->logic=LOGIC_TRUE; buf[j]=0; if(csi->etx) { p=strchr(buf,csi->etx); if(p) *p=0; } *pp=copystrvar(csi,*pp,buf); } else { *lp2=0; if(i>4 || i<1) i=4; if(fread(lp2,1,i,(FILE *)*lp1)==i) csi->logic=LOGIC_TRUE; } return(0); case FIO_READ_LINE: lp1=getintvar(csi,*(long *)csi->ip); /* Handle */ csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); if(!pp) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(!lp1 || !(*lp1) || feof((FILE *)*lp1) || (!pp && !lp2)) return(0); csi->logic=LOGIC_TRUE; for(i=0;i<sizeof(buf)-1;i++) { if(!fread(buf+i,1,1,(FILE *)*lp1)) break; if(*(buf+i)==LF) { i++; break; } } buf[i]=0; if(csi->etx) { p=strchr(buf,csi->etx); if(p) *p=0; } if(pp) *pp=copystrvar(csi,*pp,buf); else *lp2=strtol(buf,0,0); return(0); case FIO_WRITE: case FIO_WRITE_VAR: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); if(!pp) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-9)==FIO_WRITE) { i=*(short *)csi->ip; csi->ip+=2; /* Length */ } else { /* FIO_WRITE_VAR */ vp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!vp) return(0); i=*(short *)vp; } if(i>sizeof(buf)-1) i=sizeof(buf)-1; if(!lp1 || !(*lp1) || (!pp && !lp2) || (pp && !*pp)) return(0); if(pp) { j=strlen(*pp); if(i<1) i=j; if(j>i) j=i; if(fwrite(*pp,1,j,(FILE *)*lp1)!=j) csi->logic=LOGIC_FALSE; else { if(j<i) { memset(buf,csi->etx,i-j); fwrite(buf,1,i-j,(FILE *)*lp1); } csi->logic=LOGIC_TRUE; } } else { if(i<1 || i>4) i=4; if(fwrite(lp2,1,i,(FILE *)*lp1)==i) csi->logic=LOGIC_TRUE; } return(0); case FIO_GET_LENGTH: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp1 && *lp1 && lp2) *lp2=filelength(fileno((FILE *)*lp1)); return(0); case FIO_GET_TIME: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp1 && *lp1 && lp2) *lp2=filetime(fileno((FILE *)*lp1)); return(0); case FIO_SET_TIME: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; #if 0 /* ftime */ if(lp1 && *lp1 && lp2) { ft=unixtoftime(*lp2); setftime(fileno((FILE *)*lp1),&ft); } #endif return(0); case FIO_EOF: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(lp && *lp) if(ftell((FILE *)*lp)>=filelength(fileno((FILE *)*lp))) csi->logic=LOGIC_TRUE; return(0); case FIO_GET_POS: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp1 && *lp1 && lp2) *lp2=ftell((FILE *)*lp1); return(0); case FIO_SEEK: case FIO_SEEK_VAR: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-5)==FIO_SEEK) { l=*(long *)csi->ip; csi->ip+=4; } else { lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!lp2) { csi->ip+=2; return(0); } l=*lp2; } i=*(short *)csi->ip; csi->ip+=2; if(lp1 && *lp1) if(fseek((FILE *)*lp1,l,i)!=-1) csi->logic=LOGIC_TRUE; return(0); case FIO_LOCK: case FIO_LOCK_VAR: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-5)==FIO_LOCK) { l=*(long *)csi->ip; csi->ip+=4; } else { lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!lp2) return(0); l=*lp2; } if(lp1 && *lp1) { fflush((FILE *)*lp1); csi->logic=!lock(fileno((FILE *)*lp1),ftell((FILE*)*lp1),l); } return(0); case FIO_UNLOCK: case FIO_UNLOCK_VAR: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-5)==FIO_UNLOCK) { l=*(long *)csi->ip; csi->ip+=4; } else { lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!lp2) return(0); l=*lp2; } if(lp1 && *lp1) { fflush((FILE *)*lp1); csi->logic=!unlock(fileno((FILE *)*lp1),ftell((FILE*)*lp1),l); } return(0); case FIO_SET_LENGTH: case FIO_SET_LENGTH_VAR: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-5)==FIO_SET_LENGTH) { l=*(long *)csi->ip; csi->ip+=4; } else { lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!lp2) return(0); l=*lp2; } if(lp1 && *lp1) csi->logic=chsize(fileno((FILE *)*lp1),l); return(0); case FIO_PRINTF: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; p=format_string(this, csi); if(lp1 && *lp1) { cmdstr(p,path,csi->str,str); fwrite(str,1,strlen(str),(FILE *)*lp1); } free(p); return(0); case FIO_SET_ETX: csi->etx=*(csi->ip++); return(0); case REMOVE_FILE: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp && remove(*pp)==0) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case RENAME_FILE: case COPY_FILE: case MOVE_FILE: pp1=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp1 && *pp1 && pp2 && *pp2) switch(*(csi->ip-9)) { case RENAME_FILE: csi->logic=rename(*pp1,*pp2); break; case COPY_FILE: csi->logic=mv(*pp1,*pp2,1); break; case MOVE_FILE: csi->logic=mv(*pp1,*pp2,0); break; } else csi->logic=LOGIC_FALSE; return(0); case GET_FILE_ATTRIB: case SET_FILE_ATTRIB: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp && lp) { if(*(csi->ip-9)==GET_FILE_ATTRIB) *lp=getfattr(*pp); else *lp=CHMOD(*pp,(int)*lp); } return(0); case MAKE_DIR: case REMOVE_DIR: case CHANGE_DIR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) switch(*(csi->ip-5)) { case MAKE_DIR: csi->logic=MKDIR(*pp); break; case REMOVE_DIR: csi->logic=rmdir(*pp); break; case CHANGE_DIR: csi->logic=chdir(*pp); break; } else csi->logic=LOGIC_FALSE; return(0); case OPEN_DIR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(pp && *pp && lp) { *lp=(long)opendir((char *)*pp); if(*lp) csi->logic=LOGIC_TRUE; } return(0); case READ_DIR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(pp && lp) { de=readdir((DIR *)(*lp)); if(de!=NULL) { csi->logic=LOGIC_TRUE; *pp=copystrvar(csi,*pp,de->d_name); } } return(0); case REWIND_DIR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { rewinddir((DIR *)(*lp)); csi->logic=LOGIC_TRUE; } else csi->logic=LOGIC_FALSE; return(0); case CLOSE_DIR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp && closedir((DIR *)(*lp))==0) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); default: errormsg(WHERE,ERR_CHK,"fio sub-instruction",*(csi->ip-1)); return(0); } case CS_NET_FUNCTION: return(exec_net(csi)); case CS_SWITCH: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!lp) { skipto(csi,CS_END_SWITCH); csi->ip++; } else { csi->misc|=CS_IN_SWITCH; csi->switch_val=*lp; } return(0); case CS_CASE: l=*(long *)csi->ip; csi->ip+=4; if(csi->misc&CS_IN_SWITCH && csi->switch_val!=l) skipto(csi,CS_NEXTCASE); else csi->misc&=~CS_IN_SWITCH; return(0); case CS_COMPARE_ARS: i=*(csi->ip++); /* Length of ARS stored as byte before ARS */ csi->logic=!chk_ar(csi->ip,&useron); csi->ip+=i; return(0); case CS_TOGGLE_USER_MISC: useron.misc^=*(ulong *)csi->ip; putuserrec(&cfg,useron.number,U_MISC,8,ultoa(useron.misc,tmp,16)); csi->ip+=4; return(0); case CS_COMPARE_USER_MISC: if((useron.misc&*(ulong *)csi->ip)==*(ulong *)csi->ip) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; csi->ip+=4; return(0); case CS_TOGGLE_USER_CHAT: useron.chat^=*(ulong *)csi->ip; putuserrec(&cfg,useron.number,U_CHAT,8,ultoa(useron.chat,tmp,16)); csi->ip+=4; return(0); case CS_COMPARE_USER_CHAT: if((useron.chat&*(ulong *)csi->ip)==*(ulong *)csi->ip) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; csi->ip+=4; return(0); case CS_TOGGLE_USER_QWK: useron.qwk^=*(ulong *)csi->ip; putuserrec(&cfg,useron.number,U_QWK,8,ultoa(useron.qwk,tmp,16)); csi->ip+=4; return(0); case CS_COMPARE_USER_QWK: if((useron.qwk&*(ulong *)csi->ip)==*(ulong *)csi->ip) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; csi->ip+=4; return(0); case CS_REPLACE_TEXT: i=*(ushort *)csi->ip; csi->ip+=2; i--; if(i>=TOTAL_TEXT) { errormsg(WHERE,ERR_CHK,"replace text #",i); while(*(csi->ip++)); /* Find NULL */ return(0); } if(text[i]!=text_sav[i] && text[i]!=nulstr) free(text[i]); j=strlen(cmdstr((char *)csi->ip,path,csi->str,buf)); if(!j) text[i]=nulstr; else text[i]=(char *)malloc(j+1); if(!text[i]) { errormsg(WHERE,ERR_ALLOC,"replacement text",j); while(*(csi->ip++)); /* Find NULL */ text[i]=text_sav[i]; return(0); } if(j) strcpy(text[i],buf); while(*(csi->ip++)); /* Find NULL */ return(0); case CS_USE_INT_VAR: // Self-modifying code! pp=getstrvar(csi,*(long *)csi->ip); if(pp && *pp) l=strtol(*pp,0,0); else { lp=getintvar(csi,*(long *)csi->ip); if(lp) l=*lp; else l=0; } csi->ip+=4; // Variable i=*(csi->ip++); // Offset if(i<1 || csi->ip+1+i>=csi->cs+csi->length) { errormsg(WHERE,ERR_CHK,"offset",i); csi->ip++; return(0); } switch(*(csi->ip++)) { // Length case sizeof(char): *(csi->ip+i)=(char)l; break; case sizeof(short): *((short *)(csi->ip+i))=(short)l; break; case sizeof(long): *((long *)(csi->ip+i))=l; break; default: errormsg(WHERE,ERR_CHK,"length",*(csi->ip-1)); break; } return(0); default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); } }
uint sbbs_t::finduser(char *instr) { int file,i; char str[128],str2[256],str3[256],ynq[25],c,pass=1; long l,length; FILE *stream; i=atoi(instr); if(i>0) { username(&cfg, i,str2); if(str2[0] && strcmp(str2,"DELETED USER")) return(i); } strcpy(str,instr); strupr(str); SAFEPRINTF(str3,"%suser/name.dat",cfg.data_dir); if(flength(str3)<1L) return(0); if((stream=fnopen(&file,str3,O_RDONLY))==NULL) { errormsg(WHERE,ERR_OPEN,str3,O_RDONLY); return(0); } SAFEPRINTF(ynq,"%.2s",text[YN]); ynq[2]='Q'; ynq[3]=0; length=(long)filelength(file); while(pass<3) { fseek(stream,0L,SEEK_SET); /* seek to beginning for each pass */ for(l=0;l<length;l+=LEN_ALIAS+2) { if(!online) break; fread(str2,LEN_ALIAS+2,1,stream); for(c=0;c<LEN_ALIAS;c++) if(str2[c]==ETX) break; str2[c]=0; if(!c) /* deleted user */ continue; strcpy(str3,str2); strupr(str2); if(pass==1 && !strcmp(str,str2)) { fclose(stream); return((l/(LEN_ALIAS+2))+1); } if(pass==2 && strstr(str2,str)) { bprintf(text[DoYouMeanThisUserQ],str3 ,(uint)(l/(LEN_ALIAS+2))+1); c=(char)getkeys(ynq,0); if(sys_status&SS_ABORT) { fclose(stream); return(0); } if(c==text[YN][0]) { fclose(stream); return((l/(LEN_ALIAS+2))+1); } if(c=='Q') { fclose(stream); return(0); } } } pass++; } bputs(text[UnknownUser]); fclose(stream); return(0); }
void sbbs_t::resort(uint dirnum) { char str[25],ixbfname[128],datfname[128],exbfname[128],txbfname[128] ,ext[512],nulbuf[512]; char tmp[512]; uchar* ixbbuf, *datbuf; uchar* ixbptr[MAX_FILES]; int ixbfile,datfile,exbfile,txbfile,i,j; long ixblen,datlen,offset,newoffset,l; memset(nulbuf,0,512); bprintf(text[ResortLineFmt],cfg.lib[cfg.dir[dirnum]->lib]->sname,cfg.dir[dirnum]->sname); sprintf(ixbfname,"%s%s.ixb",cfg.dir[dirnum]->data_dir,cfg.dir[dirnum]->code); sprintf(datfname,"%s%s.dat",cfg.dir[dirnum]->data_dir,cfg.dir[dirnum]->code); sprintf(exbfname,"%s%s.exb",cfg.dir[dirnum]->data_dir,cfg.dir[dirnum]->code); sprintf(txbfname,"%s%s.txb",cfg.dir[dirnum]->data_dir,cfg.dir[dirnum]->code); if(flength(ixbfname)<1L || flength(datfname)<1L) { remove(exbfname); remove(txbfname); remove(ixbfname); remove(datfname); bputs(text[ResortEmptyDir]); return; } bputs(text[Sorting]); if((ixbfile=nopen(ixbfname,O_RDONLY))==-1) { errormsg(WHERE,ERR_OPEN,ixbfname,O_RDONLY); return; } if((datfile=nopen(datfname,O_RDONLY))==-1) { close(ixbfile); errormsg(WHERE,ERR_OPEN,datfname,O_RDONLY); return; } ixblen=(long)filelength(ixbfile); datlen=(long)filelength(datfile); if((ixbbuf=(uchar *)malloc(ixblen))==NULL) { close(ixbfile); close(datfile); errormsg(WHERE,ERR_ALLOC,ixbfname,ixblen); return; } if((datbuf=(uchar *)malloc(datlen))==NULL) { close(ixbfile); close(datfile); free((char *)ixbbuf); errormsg(WHERE,ERR_ALLOC,datfname,datlen); return; } if(lread(ixbfile,ixbbuf,ixblen)!=ixblen) { close(ixbfile); close(datfile); free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_READ,ixbfname,ixblen); return; } if(lread(datfile,datbuf,datlen)!=datlen) { close(ixbfile); close(datfile); free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_READ,datfname,datlen); return; } close(ixbfile); close(datfile); if((ixbfile=nopen(ixbfname,O_WRONLY|O_TRUNC))==-1) { free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_OPEN,ixbfname,O_WRONLY|O_TRUNC); return; } if((datfile=nopen(datfname,O_WRONLY|O_TRUNC))==-1) { close(ixbfile); free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_OPEN,datfname,O_WRONLY|O_TRUNC); return; } for(l=0,i=0;l<ixblen && i<MAX_FILES;l+=F_IXBSIZE,i++) ixbptr[i]=ixbbuf+l; switch(cfg.dir[dirnum]->sort) { case SORT_NAME_A: qsort((void *)ixbptr,ixblen/F_IXBSIZE,sizeof(ixbptr[0]) ,(int(*)(const void*, const void*))fnamecmp_a); break; case SORT_NAME_D: qsort((void *)ixbptr,ixblen/F_IXBSIZE,sizeof(ixbptr[0]) ,(int(*)(const void*, const void*))fnamecmp_d); break; case SORT_DATE_A: qsort((void *)ixbptr,ixblen/F_IXBSIZE,sizeof(ixbptr[0]) ,(int(*)(const void*, const void*))fdatecmp_a); break; case SORT_DATE_D: qsort((void *)ixbptr,ixblen/F_IXBSIZE,sizeof(ixbptr[0]) ,(int(*)(const void*, const void*))fdatecmp_d); break; } if((exbfile=nopen(exbfname,O_RDWR|O_CREAT))==-1) { close(ixbfile); close(datfile); free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_OPEN,exbfname,O_RDWR|O_CREAT); return; } if((txbfile=nopen(txbfname,O_RDWR|O_CREAT))==-1) { close(exbfile); close(datfile); close(exbfile); free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_OPEN,txbfname,O_RDWR|O_CREAT); return; } for(i=0;i<ixblen/F_IXBSIZE;i++) { offset=ixbptr[i][11]|((long)ixbptr[i][12]<<8)|((long)ixbptr[i][13]<<16); lwrite(datfile,&datbuf[offset],F_LEN); newoffset=(ulong)i*(ulong)F_LEN; j=datbuf[offset+F_MISC]; /* misc bits */ if(j!=ETX) j-=' '; if(j&FM_EXTDESC) { /* extended description */ lseek(exbfile,(offset/F_LEN)*512L,SEEK_SET); memset(ext,0,512); read(exbfile,ext,512); while(filelength(txbfile)<(newoffset/F_LEN)*512L) { // lseek(txbfile,0L,SEEK_END); write(txbfile,nulbuf,512); } lseek(txbfile,(newoffset/F_LEN)*512L,SEEK_SET); write(txbfile,ext,512); } str[0]=newoffset&0xff; /* Get offset within DAT file for IXB file */ str[1]=(newoffset>>8)&0xff; str[2]=(newoffset>>16)&0xff; lwrite(ixbfile,ixbptr[i],11); /* filename */ lwrite(ixbfile,str,3); /* offset */ lwrite(ixbfile,ixbptr[i]+14,8); } /* upload and download times */ close(exbfile); close(txbfile); close(ixbfile); close(datfile); remove(exbfname); rename(txbfname,exbfname); if(!flength(exbfname)) remove(exbfname); free((char *)ixbbuf); free((char *)datbuf); if(ixblen/F_IXBSIZE==datlen/F_LEN) bputs(text[Sorted]); else bprintf(text[Compressed] ,(uint)((datlen/F_LEN)-(ixblen/F_IXBSIZE)) ,ultoac(((datlen/F_LEN)-(ixblen/F_IXBSIZE))*F_LEN,tmp)); }
bool sbbs_t::inetmail(char *into, char *subj, long mode) { char str[256],str2[256],msgpath[256],title[256],name[256],ch ,buf[SDT_BLOCK_LEN],*p,addr[256]; char tmp[512]; char your_addr[128]; ushort xlat=XLAT_NONE,net=NET_INTERNET; int i,j,x,file; long l; ulong length,offset; FILE *instream; smbmsg_t msg; if(useron.etoday>=cfg.level_emailperday[useron.level] && !SYSOP) { bputs(text[TooManyEmailsToday]); return(false); } strcpy(name,into); strcpy(addr,into); strcpy(title,subj); if((!SYSOP && !(cfg.inetmail_misc&NMAIL_ALLOW)) || useron.rest&FLAG('M')) { bputs(text[NoNetMailAllowed]); return(false); } if(cfg.inetmail_cost && !(useron.exempt&FLAG('S'))) { if(useron.cdt+useron.freecdt<cfg.inetmail_cost) { bputs(text[NotEnoughCredits]); return(false); } sprintf(str,text[NetMailCostContinueQ],cfg.inetmail_cost); if(noyes(str)) return(false); } /* Get destination user name */ p=strrchr(name,'@'); if(!p) p=strrchr(name,'!'); if(p) { *p=0; truncsp(name); } /* Get this user's internet mailing address */ usermailaddr(&cfg,your_addr ,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name); bprintf(text[InternetMailing],addr,your_addr); action=NODE_SMAL; nodesync(); sprintf(msgpath,"%snetmail.msg",cfg.node_dir); if(!writemsg(msgpath,nulstr,title,mode,INVALID_SUB,into)) { bputs(text[Aborted]); return(false); } if(mode&WM_FILE) { sprintf(str2,"%sfile/%04u.out",cfg.data_dir,useron.number); MKDIR(str2); sprintf(str2,"%sfile/%04u.out/%s",cfg.data_dir,useron.number,title); if(fexistcase(str2)) { bputs(text[FileAlreadyThere]); remove(msgpath); return(false); } #if 0 /* no such thing as local logon */ if(online==ON_LOCAL) { /* Local upload */ bputs(text[EnterPath]); if(!getstr(str,60,K_LINE|K_UPPER)) { bputs(text[Aborted]); remove(msgpath); return(false); } backslash(str); strcat(str,title); mv(str,str2,1); } else #endif { /* Remote */ xfer_prot_menu(XFER_UPLOAD); mnemonics(text[ProtocolOrQuit]); strcpy(str,"Q"); for(x=0;x<cfg.total_prots;x++) if(cfg.prot[x]->ulcmd[0] && chk_ar(cfg.prot[x]->ar,&useron)) { sprintf(tmp,"%c",cfg.prot[x]->mnemonic); strcat(str,tmp); } ch=(char)getkeys(str,0); if(ch=='Q' || sys_status&SS_ABORT) { bputs(text[Aborted]); remove(msgpath); return(false); } for(x=0;x<cfg.total_prots;x++) if(cfg.prot[x]->ulcmd[0] && cfg.prot[x]->mnemonic==ch && chk_ar(cfg.prot[x]->ar,&useron)) break; if(x<cfg.total_prots) /* This should be always */ protocol(cfg.prot[x],XFER_UPLOAD,str2,nulstr,true); } sprintf(tmp,"%s%s",cfg.temp_dir,title); if(!fexistcase(str2) && fexistcase(tmp)) mv(tmp,str2,0); l=flength(str2); if(l>0) bprintf(text[FileNBytesReceived],title,ultoac(l,tmp)); else { bprintf(text[FileNotReceived],title); remove(msgpath); return(false); } } if((i=smb_stack(&smb,SMB_STACK_PUSH))!=SMB_SUCCESS) { errormsg(WHERE,ERR_OPEN,"MAIL",i); return(false); } sprintf(smb.file,"%smail",cfg.data_dir); smb.retry_time=cfg.smb_retry_time; smb.subnum=INVALID_SUB; if((i=smb_open(&smb))!=SMB_SUCCESS) { smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return(false); } if(filelength(fileno(smb.shd_fp))<1) { /* Create it if it doesn't exist */ smb.status.max_crcs=cfg.mail_maxcrcs; smb.status.max_age=cfg.mail_maxage; smb.status.max_msgs=0; smb.status.attr=SMB_EMAIL; if((i=smb_create(&smb))!=SMB_SUCCESS) { smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_CREATE,smb.file,i); return(false); } } if((i=smb_locksmbhdr(&smb))!=SMB_SUCCESS) { smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_LOCK,smb.file,i); return(false); } length=flength(msgpath)+2; /* +2 for translation string */ if(length&0xfff00000UL) { smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_LEN,msgpath,length); return(false); } if((i=smb_open_da(&smb))!=SMB_SUCCESS) { smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return(false); } if(cfg.sys_misc&SM_FASTMAIL) offset=smb_fallocdat(&smb,length,1); else offset=smb_allocdat(&smb,length,1); smb_close_da(&smb); if((file=open(msgpath,O_RDONLY|O_BINARY))==-1 || (instream=fdopen(file,"rb"))==NULL) { smb_freemsgdat(&smb,offset,length,1); smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY|O_BINARY); return(false); } setvbuf(instream,NULL,_IOFBF,2*1024); fseek(smb.sdt_fp,offset,SEEK_SET); xlat=XLAT_NONE; fwrite(&xlat,2,1,smb.sdt_fp); x=SDT_BLOCK_LEN-2; /* Don't read/write more than 255 */ while(!feof(instream)) { memset(buf,0,x); j=fread(buf,1,x,instream); if(j<1) break; if(j>1 && (j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR) buf[j-1]=buf[j-2]=0; fwrite(buf,j,1,smb.sdt_fp); x=SDT_BLOCK_LEN; } fflush(smb.sdt_fp); fclose(instream); memset(&msg,0,sizeof(smbmsg_t)); msg.hdr.version=smb_ver(); if(mode&WM_FILE) msg.hdr.auxattr|=MSG_FILEATTACH; msg.hdr.when_written.time=msg.hdr.when_imported.time=time(NULL); msg.hdr.when_written.zone=msg.hdr.when_imported.zone=sys_timezone(&cfg); msg.hdr.offset=offset; net=NET_INTERNET; smb_hfield_str(&msg,RECIPIENT,name); smb_hfield(&msg,RECIPIENTNETTYPE,sizeof(net),&net); smb_hfield_str(&msg,RECIPIENTNETADDR,addr); strcpy(str,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name); smb_hfield_str(&msg,SENDER,str); sprintf(str,"%u",useron.number); smb_hfield_str(&msg,SENDEREXT,str); /* smb_hfield(&msg,SENDERNETTYPE,sizeof(net),&net); smb_hfield(&msg,SENDERNETADDR,strlen(sys_inetaddr),sys_inetaddr); */ /* Security logging */ msg_client_hfields(&msg,&client); smb_hfield_str(&msg,SUBJECT,title); strcpy(str,title); smb_dfield(&msg,TEXT_BODY,length); i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); // calls smb_unlocksmbhdr() smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); smb_freemsgmem(&msg); if(i!=SMB_SUCCESS) { errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); smb_freemsgdat(&smb,offset,length,1); return(false); } if(mode&WM_FILE && online==ON_REMOTE) autohangup(); if(cfg.inetmail_sem[0]) /* update semaphore file */ ftouch(cmdstr(cfg.inetmail_sem,nulstr,nulstr,NULL)); if(!(useron.exempt&FLAG('S'))) subtract_cdt(&cfg,&useron,cfg.inetmail_cost); useron.emails++; logon_emails++; putuserrec(&cfg,useron.number,U_EMAILS,5,ultoa(useron.emails,tmp,10)); useron.etoday++; putuserrec(&cfg,useron.number,U_ETODAY,5,ultoa(useron.etoday,tmp,10)); sprintf(str,"%s sent Internet Mail to %s (%s)" ,useron.alias ,name,addr); logline("EN",str); return(true); }
bool sbbs_t::qnetmail(char *into, char *subj, long mode) { char str[256],msgpath[128],title[128],to[128],fulladdr[128] ,buf[SDT_BLOCK_LEN],*addr; char tmp[512]; ushort xlat=XLAT_NONE,net=NET_QWK,touser; int i,j,x,file; ulong length,offset; FILE *instream; smbmsg_t msg; if(useron.etoday>=cfg.level_emailperday[useron.level] && !SYSOP) { bputs(text[TooManyEmailsToday]); return(false); } strcpy(to,into); strcpy(title,subj); if(useron.rest&FLAG('M')) { bputs(text[NoNetMailAllowed]); return(false); } addr=strrchr(to,'@'); if(!addr) { bputs(text[InvalidNetMailAddr]); return(false); } *addr=0; addr++; strupr(addr); truncsp(addr); touser=qwk_route(addr,fulladdr); if(!fulladdr[0]) { bputs(text[InvalidNetMailAddr]); return(false); } truncsp(to); if(!stricmp(to,"SBBS") && !SYSOP) { bputs(text[InvalidNetMailAddr]); return(false); } bprintf(text[NetMailing],to,fulladdr ,useron.alias,cfg.sys_id); action=NODE_SMAL; nodesync(); sprintf(msgpath,"%snetmail.msg",cfg.node_dir); if(!writemsg(msgpath,nulstr,title,mode|WM_QWKNET,INVALID_SUB,to)) { bputs(text[Aborted]); return(false); } if((i=smb_stack(&smb,SMB_STACK_PUSH))!=SMB_SUCCESS) { errormsg(WHERE,ERR_OPEN,"MAIL",i); return(false); } sprintf(smb.file,"%smail",cfg.data_dir); smb.retry_time=cfg.smb_retry_time; smb.subnum=INVALID_SUB; if((i=smb_open(&smb))!=SMB_SUCCESS) { smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return(false); } if(filelength(fileno(smb.shd_fp))<1) { /* Create it if it doesn't exist */ smb.status.max_crcs=cfg.mail_maxcrcs; smb.status.max_msgs=0; smb.status.max_age=cfg.mail_maxage; smb.status.attr=SMB_EMAIL; if((i=smb_create(&smb))!=SMB_SUCCESS) { smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_CREATE,smb.file,i,smb.last_error); return(false); } } if((i=smb_locksmbhdr(&smb))!=SMB_SUCCESS) { smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error); return(false); } length=flength(msgpath)+2; /* +2 for translation string */ if(length&0xfff00000UL) { smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_LEN,msgpath,length); return(false); } if((i=smb_open_da(&smb))!=SMB_SUCCESS) { smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return(false); } if(cfg.sys_misc&SM_FASTMAIL) offset=smb_fallocdat(&smb,length,1); else offset=smb_allocdat(&smb,length,1); smb_close_da(&smb); if((file=open(msgpath,O_RDONLY|O_BINARY))==-1 || (instream=fdopen(file,"rb"))==NULL) { smb_freemsgdat(&smb,offset,length,1); smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY|O_BINARY); return(false); } setvbuf(instream,NULL,_IOFBF,2*1024); fseek(smb.sdt_fp,offset,SEEK_SET); xlat=XLAT_NONE; fwrite(&xlat,2,1,smb.sdt_fp); x=SDT_BLOCK_LEN-2; /* Don't read/write more than 255 */ while(!feof(instream)) { memset(buf,0,x); j=fread(buf,1,x,instream); if(j<1) break; if(j>1 && (j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR) buf[j-1]=buf[j-2]=0; fwrite(buf,j,1,smb.sdt_fp); x=SDT_BLOCK_LEN; } fflush(smb.sdt_fp); fclose(instream); memset(&msg,0,sizeof(smbmsg_t)); msg.hdr.version=smb_ver(); if(mode&WM_FILE) msg.hdr.auxattr|=MSG_FILEATTACH; msg.hdr.when_written.time=msg.hdr.when_imported.time=time(NULL); msg.hdr.when_written.zone=msg.hdr.when_imported.zone=sys_timezone(&cfg); msg.hdr.offset=offset; net=NET_QWK; smb_hfield_str(&msg,RECIPIENT,to); sprintf(str,"%u",touser); smb_hfield_str(&msg,RECIPIENTEXT,str); smb_hfield(&msg,RECIPIENTNETTYPE,sizeof(net),&net); smb_hfield_str(&msg,RECIPIENTNETADDR,fulladdr); smb_hfield_str(&msg,SENDER,useron.alias); sprintf(str,"%u",useron.number); smb_hfield_str(&msg,SENDEREXT,str); /* Security logging */ msg_client_hfields(&msg,&client); smb_hfield_str(&msg,SUBJECT,title); smb_dfield(&msg,TEXT_BODY,length); i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); // calls smb_unlocksmbhdr() smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); smb_freemsgmem(&msg); if(i!=SMB_SUCCESS) { errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); smb_freemsgdat(&smb,offset,length,1); return(false); } useron.emails++; logon_emails++; putuserrec(&cfg,useron.number,U_EMAILS,5,ultoa(useron.emails,tmp,10)); useron.etoday++; putuserrec(&cfg,useron.number,U_ETODAY,5,ultoa(useron.etoday,tmp,10)); sprintf(str,"%s sent QWK NetMail to %s (%s)" ,useron.alias ,to,fulladdr); logline("EN",str); return(true); }
bool sbbs_t::logon() { char str[256],c; char tmp[512]; int file; uint i,j,mailw; long kmode; ulong totallogons; node_t node; struct tm tm; now=time(NULL); if(localtime_r(&now,&tm)==NULL) return(false); if(!useron.number) return(false); client.user=useron.alias; client_on(client_socket,&client,TRUE /* update */); #ifdef JAVASCRIPT js_create_user_objects(); #endif if(useron.rest&FLAG('Q')) qwklogon=1; if(SYSOP && !(cfg.sys_misc&SM_R_SYSOP)) return(false); if(useron.rest&FLAG('G')) { /* Guest account */ useron.misc=(cfg.new_misc&(~ASK_NSCAN)); useron.rows=0; useron.misc&=~(ANSI|RIP|WIP|NO_EXASCII|COLOR|HTML); useron.misc|=autoterm; if(!(useron.misc&ANSI) && text[AnsiTerminalQ][0] && yesno(text[AnsiTerminalQ])) useron.misc|=ANSI; if(useron.misc&(RIP|WIP|HTML) || (useron.misc&ANSI && text[ColorTerminalQ][0] && yesno(text[ColorTerminalQ]))) useron.misc|=COLOR; if(text[ExAsciiTerminalQ][0] && !yesno(text[ExAsciiTerminalQ])) useron.misc|=NO_EXASCII; for(i=0;i<cfg.total_xedits;i++) if(!stricmp(cfg.xedit[i]->code,cfg.new_xedit) && chk_ar(cfg.xedit[i]->ar,&useron,&client)) break; if(i<cfg.total_xedits) useron.xedit=i+1; else useron.xedit=0; useron.prot=cfg.new_prot; useron.shell=cfg.new_shell; } if(!chk_ar(cfg.node_ar,&useron,&client)) { bputs(text[NoNodeAccess]); sprintf(str,"(%04u) %-25s Insufficient node access" ,useron.number,useron.alias); logline(LOG_NOTICE,"+!",str); return(false); } getnodedat(cfg.node_num,&thisnode,1); if(thisnode.misc&NODE_LOCK) { putnodedat(cfg.node_num,&thisnode); /* must unlock! */ if(!SYSOP && !(useron.exempt&FLAG('N'))) { bputs(text[NodeLocked]); sprintf(str,"(%04u) %-25s Locked node logon attempt" ,useron.number,useron.alias); logline(LOG_NOTICE,"+!",str); return(false); } if(yesno(text[RemoveNodeLockQ])) { getnodedat(cfg.node_num,&thisnode,1); logline("S-","Removed Node Lock"); thisnode.misc&=~NODE_LOCK; } else getnodedat(cfg.node_num,&thisnode,1); } if(useron.exempt&FLAG('H')) console|=CON_NO_INACT; if((useron.exempt&FLAG('Q') && useron.misc&QUIET)) thisnode.status=NODE_QUIET; else thisnode.status=NODE_INUSE; action=thisnode.action=NODE_LOGN; thisnode.connection=node_connection; thisnode.misc&=~(NODE_ANON|NODE_INTR|NODE_MSGW|NODE_POFF|NODE_AOFF); if(useron.chat&CHAT_NOACT) thisnode.misc|=NODE_AOFF; if(useron.chat&CHAT_NOPAGE) thisnode.misc|=NODE_POFF; thisnode.useron=useron.number; putnodedat(cfg.node_num,&thisnode); getusrsubs(); getusrdirs(); if(useron.misc&CURSUB && !(useron.rest&FLAG('G'))) { for(i=0;i<usrgrps;i++) { for(j=0;j<usrsubs[i];j++) { if(!strcmp(cfg.sub[usrsub[i][j]]->code,useron.cursub)) break; } if(j<usrsubs[i]) { curgrp=i; cursub[i]=j; break; } } for(i=0;i<usrlibs;i++) { for(j=0;j<usrdirs[i];j++) if(!strcmp(cfg.dir[usrdir[i][j]]->code,useron.curdir)) break; if(j<usrdirs[i]) { curlib=i; curdir[i]=j; break; } } } if(useron.misc&AUTOTERM) { useron.misc&=~(ANSI|RIP|WIP|HTML); useron.misc|=autoterm; } if(!chk_ar(cfg.shell[useron.shell]->ar,&useron,&client)) { useron.shell=cfg.new_shell; if(!chk_ar(cfg.shell[useron.shell]->ar,&useron,&client)) { for(i=0;i<cfg.total_shells;i++) if(chk_ar(cfg.shell[i]->ar,&useron,&client)) break; if(i==cfg.total_shells) useron.shell=0; } } logon_ml=useron.level; logontime=time(NULL); starttime=logontime; useron.logontime=(time32_t)logontime; last_ns_time=ns_time=useron.ns_time; // ns_time-=(useron.tlast*60); /* file newscan time == last logon time */ delfiles(cfg.temp_dir,ALLFILES); sprintf(str,"%smsgs/n%3.3u.msg",cfg.data_dir,cfg.node_num); remove(str); /* remove any pending node messages */ sprintf(str,"%smsgs/n%3.3u.ixb",cfg.data_dir,cfg.node_num); remove(str); /* remove any pending node message indices */ if(!SYSOP && online==ON_REMOTE && !qwklogon) { rioctl(IOCM|ABORT); /* users can't abort anything */ rioctl(IOCS|ABORT); } CLS; if(useron.rows) rows=useron.rows; unixtodstr(&cfg,(time32_t)logontime,str); if(!strncmp(str,useron.birth,5) && !(useron.rest&FLAG('Q'))) { bputs(text[HappyBirthday]); pause(); CLS; user_event(EVENT_BIRTHDAY); } useron.ltoday++; gettimeleft(); sprintf(str,"%sfile/%04u.dwn",cfg.data_dir,useron.number); batch_add_list(str); if(!qwklogon) { /* QWK Nodes don't go through this */ if(cfg.sys_pwdays && (ulong)logontime>(useron.pwmod+((ulong)cfg.sys_pwdays*24UL*60UL*60UL))) { bprintf(text[TimeToChangePw],cfg.sys_pwdays); c=0; while(c<LEN_PASS) { /* Create random password */ str[c]=sbbs_random(43)+'0'; if(isalnum(str[c])) c++; } str[c]=0; bprintf(text[YourPasswordIs],str); if(cfg.sys_misc&SM_PWEDIT && yesno(text[NewPasswordQ])) while(online) { bputs(text[NewPassword]); getstr(str,LEN_PASS,K_UPPER|K_LINE); truncsp(str); if(chkpass(str,&useron,true)) break; CRLF; } while(online) { if(cfg.sys_misc&SM_PWEDIT) { CRLF; bputs(text[VerifyPassword]); } else bputs(text[NewUserPasswordVerify]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER); console&=~(CON_R_ECHOX|CON_L_ECHOX); if(strcmp(str,tmp)) { bputs(text[Wrong]); continue; } break; } strcpy(useron.pass,str); useron.pwmod=time32(NULL); putuserrec(&cfg,useron.number,U_PWMOD,8,ultoa((ulong)useron.pwmod,str,16)); bputs(text[PasswordChanged]); pause(); } if(useron.ltoday>cfg.level_callsperday[useron.level] && !(useron.exempt&FLAG('L'))) { bputs(text[NoMoreLogons]); sprintf(str,"(%04u) %-25s Out of logons" ,useron.number,useron.alias); logline(LOG_NOTICE,"+!",str); hangup(); return(false); } if(useron.rest&FLAG('L') && useron.ltoday>1) { bputs(text[R_Logons]); sprintf(str,"(%04u) %-25s Out of logons" ,useron.number,useron.alias); logline(LOG_NOTICE,"+!",str); hangup(); return(false); } kmode=(cfg.uq&UQ_NOEXASC); if(!(cfg.uq&UQ_NOUPRLWR)) kmode|=K_UPRLWR; if(!(useron.rest&FLAG('G'))) { if(!useron.name[0] && ((cfg.uq&UQ_ALIASES && cfg.uq&UQ_REALNAME) || cfg.uq&UQ_COMPANY)) while(online) { if(cfg.uq&UQ_ALIASES && cfg.uq&UQ_REALNAME) bputs(text[EnterYourRealName]); else bputs(text[EnterYourCompany]); getstr(useron.name,LEN_NAME,kmode); if(cfg.uq&UQ_ALIASES && cfg.uq&UQ_REALNAME) { if(trashcan(useron.name,"name") || !useron.name[0] || !strchr(useron.name,' ') || strchr(useron.name,0xff) || (cfg.uq&UQ_DUPREAL && userdatdupe(useron.number,U_NAME,LEN_NAME ,useron.name,0,0))) bputs(text[YouCantUseThatName]); else break; } else break; } if(cfg.uq&UQ_HANDLE && !useron.handle[0]) { sprintf(useron.handle,"%.*s",LEN_HANDLE,useron.alias); while(online) { bputs(text[EnterYourHandle]); if(!getstr(useron.handle,LEN_HANDLE ,K_LINE|K_EDIT|K_AUTODEL|(cfg.uq&UQ_NOEXASC)) || strchr(useron.handle,0xff) || (cfg.uq&UQ_DUPHAND && userdatdupe(useron.number,U_HANDLE,LEN_HANDLE ,useron.handle,0,0)) || trashcan(useron.handle,"name")) bputs(text[YouCantUseThatName]); else break; } } if(cfg.uq&UQ_LOCATION && !useron.location[0]) while(online) { bputs(text[EnterYourCityState]); if(getstr(useron.location,LEN_LOCATION,kmode)) break; } if(cfg.uq&UQ_ADDRESS && !useron.address[0]) while(online) { bputs(text[EnterYourAddress]); if(getstr(useron.address,LEN_ADDRESS,kmode)) break; } if(cfg.uq&UQ_ADDRESS && !useron.zipcode[0]) while(online) { bputs(text[EnterYourZipCode]); if(getstr(useron.zipcode,LEN_ZIPCODE,K_UPPER|(cfg.uq&UQ_NOEXASC))) break; } if(cfg.uq&UQ_PHONE && !useron.phone[0]) { if(text[CallingFromNorthAmericaQ][0]) i=yesno(text[CallingFromNorthAmericaQ]); else i=0; while(online) { bputs(text[EnterYourPhoneNumber]); if(i) { if(gettmplt(useron.phone,cfg.sys_phonefmt ,K_LINE|(cfg.uq&UQ_NOEXASC))<strlen(cfg.sys_phonefmt)) continue; } else { if(getstr(useron.phone,LEN_PHONE ,K_UPPER|(cfg.uq&UQ_NOEXASC))<5) continue; } if(!trashcan(useron.phone,"phone")) break; } } if(!(cfg.uq&UQ_NONETMAIL) && !useron.netmail[0]) { while(online) { bputs(text[EnterNetMailAddress]); if(getstr(useron.netmail,LEN_NETMAIL,K_EDIT|K_AUTODEL|K_LINE) && !trashcan(useron.netmail,"email")) break; } if(useron.netmail[0] && cfg.sys_misc&SM_FWDTONET && !noyes(text[ForwardMailQ])) useron.misc|=NETMAIL; else useron.misc&=~NETMAIL; } if(cfg.new_sif[0]) { sprintf(str,"%suser/%4.4u.dat",cfg.data_dir,useron.number); if(flength(str)<1L) create_sif_dat(cfg.new_sif,str); } } } if(!online) { sprintf(str,"(%04u) %-25s Unsuccessful logon" ,useron.number,useron.alias); logline(LOG_NOTICE,"+!",str); return(false); } SAFECOPY(useron.modem,connection); useron.logons++; putuserdat(&cfg,&useron); getmsgptrs(); sys_status|=SS_USERON; /* moved from further down */ if(useron.rest&FLAG('Q')) { sprintf(str,"(%04u) %-25s QWK Network Connection" ,useron.number,useron.alias); logline("++",str); return(true); } /********************/ /* SUCCESSFUL LOGON */ /********************/ totallogons=logonstats(); sprintf(str,"(%04u) %-25s Logon %lu - %u" ,useron.number,useron.alias,totallogons,useron.ltoday); logline("++",str); if(!qwklogon && cfg.logon_mod[0]) exec_bin(cfg.logon_mod,&main_csi); if(thisnode.status!=NODE_QUIET && (!REALSYSOP || cfg.sys_misc&SM_SYSSTAT)) { sprintf(str,"%slogon.lst",cfg.data_dir); if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) { errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_CREAT|O_APPEND); return(false); } getuserrec(&cfg,useron.number,U_NOTE,LEN_NOTE,useron.note); getuserrec(&cfg,useron.number,U_LOCATION,LEN_LOCATION,useron.location); sprintf(str,text[LastFewCallersFmt],cfg.node_num ,totallogons,useron.alias ,cfg.sys_misc&SM_LISTLOC ? useron.location : useron.note ,tm.tm_hour,tm.tm_min ,connection,useron.ltoday > 999 ? 999 : useron.ltoday); write(file,str,strlen(str)); close(file); } if(cfg.sys_logon[0]) /* execute system logon event */ external(cmdstr(cfg.sys_logon,nulstr,nulstr,NULL),EX_STDOUT); /* EX_SH */ if(qwklogon) return(true); sys_status|=SS_PAUSEON; /* always force pause on during this section */ mailw=getmail(&cfg,useron.number,0); if(!(cfg.sys_misc&SM_NOSYSINFO)) { bprintf(text[SiSysName],cfg.sys_name); //bprintf(text[SiNodeNumberName],cfg.node_num,cfg.node_name); bprintf(text[LiUserNumberName],useron.number,useron.alias); bprintf(text[LiLogonsToday],useron.ltoday ,cfg.level_callsperday[useron.level]); bprintf(text[LiTimeonToday],useron.ttoday ,cfg.level_timeperday[useron.level]+useron.min); bprintf(text[LiMailWaiting],mailw); strcpy(str,text[LiSysopIs]); if(startup->options&BBS_OPT_SYSOP_AVAILABLE || (cfg.sys_chat_ar[0] && chk_ar(cfg.sys_chat_ar,&useron,&client))) strcat(str,text[LiSysopAvailable]); else strcat(str,text[LiSysopNotAvailable]); bprintf("%s\r\n\r\n",str); } if(sys_status&SS_EVENT) bprintf(text[ReducedTime],timestr(event_time)); getnodedat(cfg.node_num,&thisnode,1); thisnode.misc&=~(NODE_AOFF|NODE_POFF); if(useron.chat&CHAT_NOACT) thisnode.misc|=NODE_AOFF; if(useron.chat&CHAT_NOPAGE) thisnode.misc|=NODE_POFF; putnodedat(cfg.node_num,&thisnode); getsmsg(useron.number); /* Moved from further down */ SYNC; c=0; for(i=1;i<=cfg.sys_nodes;i++) if(i!=cfg.node_num) { getnodedat(i,&node,0); if(!(cfg.sys_misc&SM_NONODELIST) && (node.status==NODE_INUSE || ((node.status==NODE_QUIET || node.errors) && SYSOP))) { if(!c) bputs(text[NodeLstHdr]); printnodedat(i,&node); c=1; } if(node.status==NODE_INUSE && i!=cfg.node_num && node.useron==useron.number && !SYSOP && !(useron.exempt&FLAG('G'))) { SAFEPRINTF2(str,"(%04u) %-25s On two nodes at the same time" ,useron.number,useron.alias); logline(LOG_NOTICE,"+!",str); bputs(text[UserOnTwoNodes]); hangup(); return(false); } if(thisnode.status!=NODE_QUIET && (node.status==NODE_INUSE || node.status==NODE_QUIET) && !(node.misc&NODE_AOFF) && node.useron!=useron.number) { sprintf(str,text[NodeLoggedOnAtNbps] ,cfg.node_num ,thisnode.misc&NODE_ANON ? text[UNKNOWN_USER] : useron.alias ,connection); putnmsg(&cfg,i,str); } } if(cfg.sys_exp_warn && useron.expire && useron.expire>now /* Warn user of coming */ && (useron.expire-now)/(1440L*60L)<=cfg.sys_exp_warn) /* expiration */ bprintf(text[AccountWillExpireInNDays],(useron.expire-now)/(1440L*60L)); if(criterrs && SYSOP) bprintf(text[CriticalErrors],criterrs); if((i=getuserxfers(0,useron.number,0))!=0) bprintf(text[UserXferForYou],i,i>1 ? "s" : nulstr); if((i=getuserxfers(useron.number,0,0))!=0) bprintf(text[UnreceivedUserXfer],i,i>1 ? "s" : nulstr); SYNC; sys_status&=~SS_PAUSEON; /* Turn off the pause override flag */ if(online==ON_REMOTE) rioctl(IOSM|ABORT); /* Turn abort ability on */ if(text[ReadYourMailNowQ][0] && mailw) { if(yesno(text[ReadYourMailNowQ])) readmail(useron.number,MAIL_YOUR); } if(usrgrps && useron.misc&ASK_NSCAN && text[NScanAllGrpsQ][0] && yesno(text[NScanAllGrpsQ])) scanallsubs(SCAN_NEW); if(usrgrps && useron.misc&ASK_SSCAN && text[SScanAllGrpsQ][0] && yesno(text[SScanAllGrpsQ])) scanallsubs(SCAN_TOYOU); return(true); }
bool sbbs_t::email(int usernumber, const char *top, const char *subj, long mode) { char str[256],str2[256],msgpath[256],title[LEN_TITLE+1],ch ,buf[SDT_BLOCK_LEN]; char tmp[512]; char pid[128]; char* editor=NULL; ushort msgattr=0; uint16_t xlat=XLAT_NONE; ushort nettype; int i,j,x,file; long l; long length; ulong offset; uint32_t crc=0xffffffffUL; FILE* instream; node_t node; smbmsg_t msg; SAFECOPY(title,subj); if(useron.etoday>=cfg.level_emailperday[useron.level] && !SYSOP && !(useron.exempt&FLAG('M'))) { bputs(text[TooManyEmailsToday]); return(false); } if(usernumber==1 && useron.rest&FLAG('S') && (cfg.node_valuser!=1 || useron.fbacks || useron.emails)) { /* ! val fback */ bprintf(text[R_Feedback],cfg.sys_op); return(false); } if(usernumber!=1 && useron.rest&FLAG('E') && (cfg.node_valuser!=usernumber || useron.fbacks || useron.emails)) { bputs(text[R_Email]); return(false); } if(!usernumber) { bputs(text[UnknownUser]); return(false); } getuserrec(&cfg,usernumber,U_MISC,8,str); l=ahtoul(str); if(l&(DELETED|INACTIVE)) { /* Deleted or Inactive User */ bputs(text[UnknownUser]); return(false); } if((l&NETMAIL) && (cfg.sys_misc&SM_FWDTONET)) { getuserrec(&cfg,usernumber,U_NETMAIL,LEN_NETMAIL,str); bprintf(text[UserNetMail],str); if((mode & WM_FORCEFWD) || text[ForwardMailQ][0]==0 || yesno(text[ForwardMailQ])) /* Forward to netmail address */ return(netmail(str,subj,mode)); } bprintf(text[Emailing],username(&cfg,usernumber,tmp),usernumber); action=NODE_SMAL; nodesync(); sprintf(str,"%sfeedback.*", cfg.exec_dir); if(usernumber==cfg.node_valuser && useron.fbacks && fexist(str)) { exec_bin("feedback",&main_csi); if(main_csi.logic!=LOGIC_TRUE) return(false); } if(cfg.sys_misc&SM_ANON_EM && useron.exempt&FLAG('A') && !noyes(text[AnonymousQ])) msgattr|=MSG_ANONYMOUS; if(cfg.sys_misc&SM_DELREADM) msgattr|=MSG_KILLREAD; msg_tmp_fname(useron.xedit, msgpath, sizeof(msgpath)); username(&cfg,usernumber,str2); if(!writemsg(msgpath,top,title,mode,INVALID_SUB,str2,&editor)) { bputs(text[Aborted]); return(false); } if(mode&WM_FILE && !SYSOP && !(cfg.sys_misc&SM_FILE_EM)) mode&=~WM_FILE; if(mode&WM_FILE) { sprintf(str2,"%sfile/%04u.in", cfg.data_dir,usernumber); MKDIR(str2); sprintf(str2,"%sfile/%04u.in/%s", cfg.data_dir,usernumber,title); if(fexistcase(str2)) { bputs(text[FileAlreadyThere]); remove(msgpath); return(false); } { /* Remote */ xfer_prot_menu(XFER_UPLOAD); mnemonics(text[ProtocolOrQuit]); strcpy(str,"Q"); for(x=0;x<cfg.total_prots;x++) if(cfg.prot[x]->ulcmd[0] && chk_ar(cfg.prot[x]->ar,&useron,&client)) { sprintf(tmp,"%c",cfg.prot[x]->mnemonic); strcat(str,tmp); } ch=(char)getkeys(str,0); if(ch=='Q' || sys_status&SS_ABORT) { bputs(text[Aborted]); remove(msgpath); return(false); } for(x=0;x<cfg.total_prots;x++) if(cfg.prot[x]->ulcmd[0] && cfg.prot[x]->mnemonic==ch && chk_ar(cfg.prot[x]->ar,&useron,&client)) break; if(x<cfg.total_prots) /* This should be always */ protocol(cfg.prot[x],XFER_UPLOAD,str2,nulstr,true); } safe_snprintf(tmp,sizeof(tmp),"%s%s",cfg.temp_dir,title); if(!fexistcase(str2) && fexistcase(tmp)) mv(tmp,str2,0); l=(long)flength(str2); if(l>0) bprintf(text[FileNBytesReceived],title,ultoac(l,tmp)); else { bprintf(text[FileNotReceived],title); remove(msgpath); return(false); } } bputs(text[WritingIndx]); if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) { errormsg(WHERE,ERR_OPEN,"MAIL",i); return(false); } sprintf(smb.file,"%smail", cfg.data_dir); smb.retry_time=cfg.smb_retry_time; smb.subnum=INVALID_SUB; if((i=smb_open(&smb))!=0) { smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return(false); } if(smb_fgetlength(smb.shd_fp)<1) { /* Create it if it doesn't exist */ smb.status.max_crcs=cfg.mail_maxcrcs; smb.status.max_age=cfg.mail_maxage; smb.status.max_msgs=0; smb.status.attr=SMB_EMAIL; if((i=smb_create(&smb))!=0) { smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_CREATE,smb.file,i,smb.last_error); return(false); } } if((i=smb_locksmbhdr(&smb))!=0) { smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error); return(false); } length=(long)flength(msgpath)+2; /* +2 for translation string */ if(length&0xfff00000UL) { smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_LEN,msgpath,length); return(false); } if((i=smb_open_da(&smb))!=0) { smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); return(false); } if(cfg.sys_misc&SM_FASTMAIL) offset=smb_fallocdat(&smb,length,1); else offset=smb_allocdat(&smb,length,1); smb_close_da(&smb); if((instream=fnopen(&file,msgpath,O_RDONLY|O_BINARY))==NULL) { smb_freemsgdat(&smb,offset,length,1); smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY|O_BINARY); return(false); } setvbuf(instream,NULL,_IOFBF,2*1024); smb_fseek(smb.sdt_fp,offset,SEEK_SET); xlat=XLAT_NONE; smb_fwrite(&smb,&xlat,2,smb.sdt_fp); x=SDT_BLOCK_LEN-2; /* Don't read/write more than 255 */ while(!feof(instream)) { memset(buf,0,x); j=fread(buf,1,x,instream); if(j<1) break; if(j>1 && (j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR) buf[j-1]=buf[j-2]=0; if(cfg.mail_maxcrcs) { for(i=0;i<j;i++) crc=ucrc32(buf[i],crc); } smb_fwrite(&smb,buf,j,smb.sdt_fp); x=SDT_BLOCK_LEN; } smb_fflush(smb.sdt_fp); fclose(instream); crc=~crc; memset(&msg,0,sizeof(smbmsg_t)); msg.hdr.version=smb_ver(); msg.hdr.attr=msgattr; if(mode&WM_FILE) msg.hdr.auxattr|=MSG_FILEATTACH; msg.hdr.when_written.time=msg.hdr.when_imported.time=time32(NULL); msg.hdr.when_written.zone=msg.hdr.when_imported.zone=sys_timezone(&cfg); if(cfg.mail_maxcrcs) { i=smb_addcrc(&smb,crc); if(i) { smb_freemsgdat(&smb,offset,length,1); smb_unlocksmbhdr(&smb); smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); attr(cfg.color[clr_err]); bputs(text[CantPostMsg]); return(false); } } msg.hdr.offset=offset; username(&cfg,usernumber,str); smb_hfield_str(&msg,RECIPIENT,str); sprintf(str,"%u",usernumber); smb_hfield_str(&msg,RECIPIENTEXT,str); SAFECOPY(str,useron.alias); smb_hfield_str(&msg,SENDER,str); sprintf(str,"%u",useron.number); smb_hfield_str(&msg,SENDEREXT,str); if(useron.misc&NETMAIL) { if(useron.rest&FLAG('G')) smb_hfield_str(&msg,REPLYTO,useron.name); nettype=smb_netaddr_type(useron.netmail); if(nettype!=NET_NONE && nettype!=NET_UNKNOWN) { smb_hfield(&msg,REPLYTONETTYPE,sizeof(nettype),&nettype); smb_hfield_str(&msg,REPLYTONETADDR,useron.netmail); } } /* Security logging */ msg_client_hfields(&msg,&client); smb_hfield_str(&msg,SENDERSERVER,startup->host_name); smb_hfield_str(&msg,SUBJECT,title); /* Generate FidoNet Program Identifier */ smb_hfield_str(&msg,FIDOPID,msg_program_id(pid)); if(editor!=NULL) smb_hfield_str(&msg,SMB_EDITOR,editor); smb_dfield(&msg,TEXT_BODY,length); i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); // calls smb_unlocksmbhdr() smb_close(&smb); smb_stack(&smb,SMB_STACK_POP); smb_freemsgmem(&msg); if(i!=SMB_SUCCESS) { smb_freemsgdat(&smb,offset,length,1); errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); return(false); } if(usernumber==1) logon_fbacks++; else logon_emails++; user_sent_email(&cfg, &useron, 1, usernumber==1); bprintf(text[Emailed],username(&cfg,usernumber,tmp),usernumber); safe_snprintf(str,sizeof(str),"%s sent e-mail to %s #%d" ,useron.alias,username(&cfg,usernumber,tmp),usernumber); logline("E+",str); if(mode&WM_FILE && online==ON_REMOTE) autohangup(); if(msgattr&MSG_ANONYMOUS) /* Don't tell user if anonymous */ return(true); for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */ getnodedat(i,&node,0); if(node.useron==usernumber && !(node.misc&NODE_POFF) && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { safe_snprintf(str,sizeof(str),text[EmailNodeMsg],cfg.node_num,useron.alias); putnmsg(&cfg,i,str); break; } } if(i>cfg.sys_nodes) { /* User wasn't online, so leave short msg */ safe_snprintf(str,sizeof(str),text[UserSentYouMail],useron.alias); putsmsg(&cfg,usernumber,str); } return(true); }
int main(int argc, char * argv[]) { //-o-o-o-o-o-o-o-o Declaring Variables o-o-o-o-o-o-o-o-o-// FILE * pmass , * phess , * pEqCrd , * poutDXDR , * poutFreq ; //, *pmo2ao; char massFileName[ 100 ] , hessFileName[ 100 ] , EqCrdFileName[ 100 ] ; char outDXDRFileName[ 100 ] , outFreqFileName[ 100 ] ; char massunit[ 100 ] , hessunit[ 100 ] , crdunit[ 100 ] ; int sdouble = sizeof(double); int natom , ncart , nmode ; int iatom , icart , imode ; int natomselect , natomprovide , ncartselect , ncartprovide ; int len_hess_cart, len_tri_hess_cart; int j,k,m; int itmp; double dtmp; char * keyword; int debuggingMode = NO ; //char gessname[ 100 ] ; double * hess_cart , * hess_cart_select ; double * freq , * vib_freq , * dxdr , * vib_dxdr ; double hessconvert , crdconvert , massconvert ; double * mass_provide , * mass; char ** pcmd ; pcmd = argv ; int icmd = 1 ; int iline , iload ; int irow , icol ; int blank_signal , groinfo ; char buffer[ MAXCHARINLINE ] ; char cache[ MAXCHARINLINE ] ; char tmpString[ MAXCHARINLINE ] ; // ---> For debugging output FILE * debug; //-o-o-o-o-o-o-o-o Recording cmd-line and time stamp o-o-o-o-o-o-o-o-o-// time_t current_time; time( ¤t_time ); char now[ 300 ] ; strcpy( now , ctime( ¤t_time ) ); int lennow = strlen( now ) ; *( now + lennow - 1 ) = ' '; printf("\n**********************************************************************\n"); printf("* G_GMXFREQ_D : Stand-Alone Utility to Calculate Normal Modes *\n"); printf("* From Hessian File and Mass File. *\n"); printf("* *\n"); printf("* "); for( icmd = 0 ; icmd < argc ; icmd ++ ) { printf("%s " , *( pcmd + icmd ) ); } printf("\n"); printf("* *\n"); printf("* *\n"); printf("* Current Time : %s *\n" , now ); printf("* *\n"); printf("* *\n"); printf("**********************************************************************\n"); //-o-o-o-o-o-o-o Read input command-line arguments and input files while deciding some parameters ...o-o-o-o-o-o-o-o-o-o-// // -------> Parsing the Command Line Arguments ... pcmd = argv ; //int exn = 10 ; int exr = 16 ; int exR = 18 ; int exH = 22 ; int exM = 28 ; int exL = 30 ; int exc = 20 ; int exs = 18 ; int exm = 88 ; int exH = 70 ; int exo = 22 , exw = 26 ; char * flag ; int internalOrNot = NO ; icmd = 1 ; printf("\n%d command-line arguments provided ...\n" , argc ); if( argc == 1 ) { printf("\n\nNo command-line arguments provided ... Mission aborting ...\n\n"); printf("\nPlease refer to the usage by typing ' %s -h '\n\n" , * argv ); exit(1); } while( icmd < argc ) { pcmd ++ ; flag = * pcmd ; printf("\nNo.%d argument , Currently @ flag = %s ...\n\n" , icmd , flag ); if( ( * flag == '-' ) && ( strlen( flag ) == 2 ) ) { switch ( *( flag + 1 ) ) { case 'c' : strcpy( tmpString , *( ++ pcmd ) ); strcpy( buffer , *( ++ pcmd ) ); if( strcmp( tmpString , "none" ) == 0 ) { strcpy( EqCrdFileName , "dirtroad.anthem" ) ; internalOrNot = NO ; printf("\nCommand-line argument indicates : NO INPUT Eq. Coordinate ... Hence NO Internal Coordinate Transformation \n" ); } else { strcpy( EqCrdFileName , tmpString ) ; strcpy( crdunit , buffer ) ; if( * crdunit == '-' ) { printf("\nHey, you did not specify the unit of you Coordinate file ... !\n"); exit( 11 ) ; } internalOrNot = YES ; printf("\nCommand-line argument indicates : Input Eq. Coordinate File name : %s . Format is %s ...\n" , EqCrdFileName , crdunit ); } exc = 21 ; icmd = icmd + 3 ; break ; case 'H' : strcpy( hessFileName , *( ++ pcmd ) ); strcpy( hessunit , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Input Hessian File name : %s . Unit is %s ...\n" , hessFileName , hessunit ); if( * hessunit == '-' ) { printf("\nHey, you did not specify the unit of you Hessian file ... !\n"); exit( 11 ); } exH = 71 ; icmd = icmd + 3 ; break ; case 'm' : strcpy( massFileName , *( ++ pcmd ) ); strcpy( massunit , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Input Mass File name : %s . Unit is %s ...\n" , massFileName , massunit ); if( * crdunit == '-' ) { printf("\nHey, you did not specify the unit of you Coordinate file ... !\n"); exit( 11 ); } exm = 89 ; icmd = icmd + 3 ; break ; case 's' : strcpy( tmpString , *( ++ pcmd ) ) ; if( strcmp( tmpString , "all" ) == 0 || strcmp( tmpString , "All" ) == 0 ) { exs = 20 ; printf("\nCommand-line argument indicates : All atoms will be chosen as solute ...\n" ); } else { printf("\nReceived information : %s ...\n" , tmpString ) ; natomselect = atoi( tmpString ); exs = 19 ; printf("\nCommand-line argument indicates : First %d atoms will be chosen as solute ...\n" , natomselect ); } icmd = icmd + 2 ; break ; case 'o' : strcpy( outDXDRFileName , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Output Normal Mode file name : %s ...\n" , outDXDRFileName ); exo = 23 ; icmd = icmd + 2 ; break ; case 'w' : strcpy( outFreqFileName , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Output frequency file name : %s ...\n" , outFreqFileName ); exw = 27 ; icmd = icmd + 2 ; break ; case 'g' : strcpy( cache , *( ++ pcmd ) ) ; printf("\nCommand-line argument indicates : Debugging Mode Invoking : %s ...\n" , cache ); if( strcmp( cache , "YES" ) == 0 || strcmp( cache , "Yes" ) == 0 || strcmp( cache , "yes" ) == 0 || strcmp( cache , "Y" ) == 0 || strcmp( cache , "y" ) == 0 ) { debuggingMode = YES ; } else if( strcmp( cache , "NO" ) == 0 || strcmp( cache , "No" ) == 0 || strcmp( cache , "no" ) == 0 || strcmp( cache , "N" ) == 0 || strcmp( cache , "n" ) == 0 ) { debuggingMode = NO ; } else { printf("\nInvalid choice of debugging mode ... Mission Aborted ...\n\n") ; exit( 21 ) ; } icmd = icmd + 2 ; break ; case 'h' : printf("\nUsage: % 15s [ -c 'input Equilibrium Geometry' ( gro / gmxcrd / g09crd )] [ -H 'Hessian file name' ' unit : au or gmx' ] [ -s # of atoms chosen as the solute ]" , * argv) ; printf("\n [ -m Mass file name & unit ( au or amu ) ] [ -w output frequency file name ] [ -o output dxdr file name ]\n\n"); //printf("\n [ -c 'input EqMD gro file of solvent' ][ -p P Group Name ][ -q Q Group Name ][ -N atom number of L-Shape reference atom ]"); //printf("\n [ -w whether to perform van der Waals contacting check ( YES / Yes / yes ) or ( NO / No / no ) or floating point number to indicate scaling factor ]"); //printf("\n [ -s # of atoms in solute molecule ] [ -t distance threshold to accept one alignment , unit = Angstrom ]\n\n" ); //printf("\nNote : 1) For \"-w\" option, YES/Yes/yes will cause the vdw-check to perform with default scaling 1.00 while NO/No/no will shut down the vdw-check.\n"); //printf("\n Specifying a floating number will also cause the vdw-check to perform but the floating number will be the user-defined scaling factor (vdwFactor).\n"); //printf("\n 2) For \"-t\" option, YES/Yes/yes will cause the universal-distance-check to perform with default threshold 1.20Å while NO/No/no will shut down the unidist-check.\n"); //printf("\n Specifying a floating number will also cause the unidist-check to perform but the floating number will be the user-defined distance threshold (vdwFactor).\n"); printf("\nNote : 1) For \"-s\" option, [ -s all ] or [ -s All ] indicates all atoms chosen as solute;\n"); printf("\n Default for -s is all atoms when nresidue = 1 or natom in 1st residue when nresidue != 1 \n"); printf("\n 2) For \"-c\" option, [ -c none none ] will turn off the internal coordinate transformation and perform regular Cartesian coordinate normal mode analysis ... \n\n\n"); icmd = icmd + 1 ; exit( 1 ) ; break ; default : printf("\n\nInvalid option ' %s ' ... Please refer to the usage by typing ' %s -h '\n\n" , flag , * argv ); icmd = argc ; exit(1); } } else { printf("\n\nInvalid option ' %s ' ... Please refer to the usage by typing ' %s -h '\n\n" , flag , * argv ); exit(1); } } // -------> Default File Names if( internalOrNot == YES && exc == 20 ) { strcpy( crdunit , "gro" ) ; strcpy( EqCrdFileName , "system.gro" ) ; printf("\nNo input .gro file provided, default \"system.gro\" in play ...\n") ; } int lenEqGROFileName = strlen( EqCrdFileName ) ; if( exo == 22 ) { strncpy( outDXDRFileName , EqCrdFileName , lenEqGROFileName - 4 ) ; *( outDXDRFileName + lenEqGROFileName - 4 ) = '\0' ; strcat( outDXDRFileName , ".dxdr" ) ; printf("\nBy default , output DXDR file name will be [ %s ] ...\n\n" , outDXDRFileName ) ; } if( exw == 26 ) { strncpy( outFreqFileName , EqCrdFileName , lenEqGROFileName - 4 ) ; *( outFreqFileName + lenEqGROFileName - 4 ) = '\0' ; strcat( outFreqFileName , ".freq" ) ; printf("\nBy default , output DXDR file name will be [ %s ] ...\n\n" , outFreqFileName ) ; } if( exH == 70 ) { strncpy( hessFileName , EqCrdFileName , lenEqGROFileName - 4 ) ; *( hessFileName + lenEqGROFileName - 4 ) = '\0' ; strcat( hessFileName , ".gess" ) ; printf("\nBy default , searching for Hessian file with the name %s ...\n\n" , hessFileName ) ; strcpy( hessunit , "gmx" ) ; } if( exm == 88 ) { strncpy( massFileName , EqCrdFileName , lenEqGROFileName - 4 ) ; *( massFileName + lenEqGROFileName - 4 ) = '\0' ; strcat( massFileName , ".mass" ) ; printf("\nBy default , searching for Mass file with the name %s ...\n\n" , massFileName ) ; strcpy( massunit , "amu" ) ; } if( strcmp( hessunit , "au" ) == 0 ) { printf("\nThe unit this Hessian file in is ATOMIC UNIT : Hartree/(Bohr^2) ... \n"); hessconvert = 1.0000 ; } else if( strcmp( hessunit , "gmx" ) == 0 ) { printf("\nThe unit this Hessian file in is GMX-Unit : kJ/mol/(nm^2) ... \n"); hessconvert = HESSAU2GMX ; } else { printf("\nWhat did you say about the unit of you frequency again ??? \n"); exit( 107 ); } printf("\n===> Done Defining Default Fila Names <===\n\n\n") ; // -------> Confirming File Access ... if( ( pmass = fopen( massFileName ,"r" ) ) == NULL ) { printf("\nUser defined mass-file [ %s ] does not exist...\n" , massFileName ); exit( 63 ); } if( ( pEqCrd = fopen( EqCrdFileName ,"r" ) ) == NULL && internalOrNot == YES ) { printf("\nUser defined Equilibrium Coordinate File [ %s ] does not exist...\n" , EqCrdFileName ); exit( 63 ); } if( ( phess = fopen( hessFileName ,"r" ) ) == NULL ) { printf("\nUser defined Hessian-file [ %s ] does not exist...\n" , hessFileName ); exit( 63 ); } printf("\n===> Done Confirming File Access <===\n\n\n") ; //-o-o-o-o-o-o-o Loading Eq. Coordinate , Hessian & Mass ...o-o-o-o-o-o-o-o-o-o-// //-----> Pre-Loading Equilibrium Geometry ... char grotitlestring[MAXLINE]; iline = 3 ; iload = 0 ; int natomgroline , natomgrotitle ; int exVelocity = NO ; if( internalOrNot == YES && ( strcmp( crdunit , "gro" ) ) == 0 ) { rewind( pEqCrd ); //printf("\nCurrent character is %c ... \n" , fgetc( pEqGRO ) ); fskip( pEqCrd , 1 ); fscanf( pEqCrd , "%d" , &natomgrotitle ); fskip( pEqCrd , 1 ); printf("\n Second line of .gro file says it is describing %d atoms ... \n\n" , natomgrotitle ); while( ( groinfo = freadline( buffer , MAXCHARINLINE , pEqCrd , ';' ) ) != 0 ) { itmp = inLineWC( buffer ) ; break ; } if( itmp == 6 ) { exVelocity = NO ; printf("\nI see there is no velocity information in .gro file ...\n\n") ; } else if( itmp == 9 ) { exVelocity = YES ; printf("\nI see velocity information is also included in .gro file ...\n\n") ; } else { printf("\nPlease check the format of you .gro file ... There are %d words in one line of your molecular specification ... \n" , itmp ) ; exit( 456 ); } printf("\nNow let's pre-load the .gro file ans see how many atoms it is describing ... \n"); natomgroline = preLoadGRO( pEqCrd ) ; printf("\nIt can be seen that this .gro file is describing %d atoms ...\n" , natomgroline ); if( natomgrotitle > natomgroline ) { printf("\nYour .gro file is self-contradictory ... While the second line of your .gro file says there will be %d atoms, there are actually only %d atoms being described ... \n" , natomgrotitle , natomgroline ); printf("\nWe will take all the atoms we can to procede ... \n"); natom = natomgroline ; } else if( natomgrotitle == natomgroline ) { printf("\nOkay ... Your .gro file is fine ... NAtom will be %d ... \n" , natomgrotitle ); natom = natomgrotitle ; } else if( natomgrotitle < natomgroline ) { printf("\nThe second line of your .gro file indicates there are %d atoms in this file but there are more atoms ( %d atoms ) being described insided ... We will take the first %d atoms ... \n" , natomgrotitle , natomgroline , natomgrotitle ); natom = natomgrotitle ; } else { printf("\nSomething is wrong with checking the .gro file ... Please take a look at it ... \n"); exit( 81 ); } ncart = 3 * natom ; itmp = 0 ; if( exs == 18 ) { natomselect = natom ; } else if( exs == 19 && natomselect > natom ) // Will be dead ... { printf("\nThere are only %d atoms in this system ... you cannot select more than that ... \n" , natom ); if( natomgrotitle > natomgroline && natomselect <= natomgrotitle ) { printf("\nAlthough ... the second line of your initial .gro file did indicate there were supposed to be %d atoms in system ... So go back and make sure what you are trying to do ... \n" , natomgrotitle ); } else if( natomgrotitle < natomgroline && natomselect <= natomgroline ) { printf("\nAlthough ... your initial .gro file did describe %d atoms in system ... So go back and make sure what you are trying to do ... \n" , natomgroline ); } exit( 78 ); } else if( exs == 19 && natomselect <= natom ) { printf("\nYou have selected %d atoms as solute ... There are %d atoms en toto in this system ... \n" , natomselect , natom ); } else if( exs == 20 ) { natomselect = natom ; } else { printf("\nSomething is wrong with the atom selection process ... NAtom = %d , NAtomSelect = %d ... \n" , natom , natomselect ); exit( 78 ); } ncartselect = 3 * natomselect ; } else if( internalOrNot == YES && ( ( strcmp( crdunit , "gmxcrd" ) ) == 0 || ( strcmp( crdunit , "g09crd" ) ) == 0 ) ) { rewind( pEqCrd ); itmp = flength( pEqCrd ) ; natom = itmp / 3 ; ncart = itmp ; if( exs == 18 ) { natomselect = natom ; } else if( exs == 19 && natomselect > natom ) // Will be dead ... { printf("\nThere are only %d atoms in this system ... you cannot select more than that ... \n" , natom ); exit( 78 ); } else if( exs == 19 && natomselect <= natom ) { printf("\nYou have selected %d atoms as solute ... There are %d atoms en toto in this system ... \n" , natomselect , natom ); } else if( exs == 20 ) { natomselect = natom ; } else { printf("\nSomething is wrong with the atom selection process ... NAtom = %d , NAtomSelect = %d ... \n" , natom , natomselect ); exit( 78 ); } ncartselect = 3 * natomselect ; } //-----> Pre-Loading Mass ... itmp = flength( pmass ) ; rewind( pmass ) ; if( internalOrNot == NO ) { natom = itmp ; ncart = 3 * natom ; if( exs == 18 ) { natomselect = natom ; printf("\nBy default, all available atoms will be chosen as solute ...\n\n") ; } else if( exs == 20 ) { natomselect = natom ; printf("\nPer user's request, all available atoms will be chosen as solute ...\n\n") ; } else if( exs == 19 ) { if( natomselect == natom ) { printf("\nOKay ... I see you provided the mass for all the atom in this system ... \n"); } else if( natomselect > natom ) // will be dead { printf("\nERROR : There are only %d atoms according to mass file, I cannot select that many atoms as solute ...\n\n" , natomselect ) ; exit( 89 ) ; } else if( natomselect < natom ) { printf("\nOKay ... you provided %d floating-point numbers for mass so the total NAtom in system is %d while %d atoms are selected ...\n" , itmp , natom , natomselect ); printf("\nSo ... I will assume the first %d numbers in your mass file correspond to the selected atoms ...\n" , natomselect ); } else { printf("\nSomething is wrong with the mass file ... There are %d atomic mass in the file while the total NAtom in this system is %d and %d atoms are selected ... \n" , itmp , natom , natomselect ); exit( 81 ); } } ncartselect = natomselect * 3 ; } else if( internalOrNot == YES ) { if( itmp == natomselect ) { printf("\nOKay ... I see you provided the mass info for just the selected atoms ... \n"); } else if( itmp == natom ) { printf("\nOKay ... I see you provided the mass for all the atom in this system ... \n"); } else if( itmp > natom ) { printf("\nOKay ... you provided %d numbers for mass. The total NAtom in system is %d while %d atoms are selected ...\n" , itmp , natom , natomselect ); printf("\nSo ... I will assume the first %d numbers in your mass file correspond to the selected atoms ...\n" , natomselect ); } else { printf("\nSomething is wrong with the mass file ... There are %d atomic mass in the file while the total NAtom in this system is %d and %d atoms are selected ... \n" , itmp , natom , natomselect ); exit( 81 ); } } // ---> Loading Equilibrium Geometry ... GRO EqAtomList[ natomselect ] ; double * EqCrd = calloc( ncartselect , sizeof( double ) ) ; dzeros( ncartselect , 1 , EqCrd ) ; double boxvector[ 3 ]; dzeros( 3 , 1 , boxvector ) ; char tmp_char ; if( internalOrNot == YES && ( strcmp( crdunit , "gro" ) ) == 0 ) // We want every coordinate to be in BOHR unit { crdconvert = NM2BOHR ; rewind( pEqCrd ); fskip( pEqCrd , 1 ); fskip( pEqCrd , 1 ); printf("\nNow let's read the actual .gro file ... \n"); iload = 0 ; iline = 0 ; while( ( groinfo = freadline( buffer , MAXCHARINLINE , pEqCrd , ';' ) ) != 0 ) { //printf("\n//--------------> WORKING ON NO. %d LINE ... <-------------//\n" , iline ); blank_signal = stellblank( buffer ) ; if( blank_signal == 0 ) { //printf("\nNo.%d line is a blank line ... Moving on ...\n" , iline ) ; continue ; } else if( blank_signal == 1 ) { //printf("\nNo.%d line is NOT a blank line ... loading ...\n" , iline ); if( ( tmp_char = getfirst( buffer ) ) == ';' ) { //printf("\nThis is a comment line ... So nothing will be loaded ...\n"); //fskip( pinputfile , 1 ); continue ; } else { //printf("\nLine reads : %s ...\n" , buffer ); sscanf( buffer , "%5d%5s" , &EqAtomList[ iload ].resnumber , EqAtomList[ iload ].resname ); //printf( "%s\t" , EqAtomList[ iatom ].resname ); //sscanf( pEqGRO , "%s" , EqAtomList[ iload ].atomname ); strpickword( buffer , 2 , cache ) ; strcpy( EqAtomList[ iload ].atomname , cache ) ; //printf( "%s" , EqAtomList[ iatom ].atomname ); //sscanf( pEqGRO , "%d" , &EqAtomList[ iload ].atomnumber ); strpickword( buffer , 3 , cache ) ; EqAtomList[ iload ].atomnumber = atoi( cache ) ; //printf( "\nWorking on No. %d atom ...\n" , EqAtomList[ iatom ].atomnumber ); //sscanf( pEqGRO , "%lf" , &EqAtomList[ iload ].cx ); //printf("\n Cx is %lf ...\t" , EqAtomList[ iatom ].cx); strpickword( buffer , 4 , cache ) ; EqAtomList[ iload ].cx = atof( cache ) ; *( EqCrd + 3 * iload + 0 ) = EqAtomList[ iload ].cx / crdconvert ; //sscanf( pEqGRO , "%lf" , &EqAtomList[ iload ].cy ); //printf("\n Cy is %lf ...\t" , EqAtomList[ iatom ].cy); strpickword( buffer , 5 , cache ) ; EqAtomList[ iload ].cy = atof( cache ) ; *( EqCrd + 3 * iload + 1 ) = EqAtomList[ iload ].cy / crdconvert ; //sscanf( pEqGRO , "%lf" , &EqAtomList[ iload ].cz ); //printf("\n Cz is %lf ...\n\n" , EqAtomList[ iatom ].cz); strpickword( buffer , 6 , cache ) ; EqAtomList[ iload ].cz = atof( cache ) ; *( EqCrd + 3 * iload + 2 ) = EqAtomList[ iload ].cz / crdconvert ; if( exVelocity == YES ) { strpickword( buffer , 7 , cache ) ; EqAtomList[ iload ].vx = atof( cache ) ; strpickword( buffer , 8 , cache ) ; EqAtomList[ iload ].vy = atof( cache ) ; strpickword( buffer , 9 , cache ) ; EqAtomList[ iload ].vz = atof( cache ) ; } //fscanf( pgroinput , "%lf" , &EqAtomList[ iatom ].vx ); //printf("\n Vx is %lf ...\t" , EqAtomList[ iatom ].cx); //fscanf( pgroinput , "%lf" , &EqAtomList[ iatom ].vy ); //printf("\n Vy is %lf ...\t" , EqAtomList[ iatom ].cy); //fscanf( pgroinput , "%lf" , &EqAtomList[ iatom ].vz ); //printf("\n Vz is %lf ...\n\n" , EqAtomList[ iatom ].cz); iload ++ ; } //printf("\n%s\n" , buffer ); } else { printf("\nSomething is wrong with the reading file part ...\n"); exit(1); } iline ++ ; if( iload == natomselect ) break ; } /* if( iline < natomgroline ) { fskip( pEqCrd , natomgroline - iline ) ; } fscanf( pgroinput , "%lf" , boxvector + 0 ); fscanf( pgroinput , "%lf" , boxvector + 1 ); fscanf( pgroinput , "%lf" , boxvector + 2 ); */ } else if( internalOrNot == YES && ( strcmp( crdunit , "grocrd" ) ) == 0 ) { crdconvert = NM2BOHR ; rewind( pEqCrd ) ; for( icart = 0 ; icart < ncartselect ; icart ++ ) { fscanf( pEqCrd , "%lf" , &dtmp ) ; *( EqCrd + icart ) = dtmp / crdconvert ; } } else if( internalOrNot == YES && ( strcmp( crdunit , "g09crd" ) ) == 0 ) { crdconvert = 1.0000 ; rewind( pEqCrd ) ; for( icart = 0 ; icart < ncartselect ; icart ++ ) { fscanf( pEqCrd , "%lf" , &dtmp ) ; *( EqCrd + icart ) = dtmp / crdconvert ; } } else if( internalOrNot == NO ) { printf("\nAlready told you ... NO INTERNAL COORDINATE BUSINESS ...\n\n") ; } else { printf("\nUNKOWN ERROR : INVALID COORDINATE FILE FORMAT ...\n\n"); exit( 73 ) ; } printf("\n===> Finished Loading Equilibrium Geometry <===\n\n\n") ; //dtranspose_nonsquare( natomselect , 3 , EqCrd , EqCrd ) ; /* debug = fopen("transposed_eqgeom.deb" , "wb+") ; doutput( debug , 3 , natomselect , EqCrd ) ; fclose( debug ) ; printf("\n===> Done Transposing Equilibrium Geometry <===\n\n\n") ; */ // -------> Loading Mass ... mass = calloc( natomselect , sizeof( double ) ); dzeros( natomselect , 1 , mass ); if( strcmp( massunit , "au" ) == 0 ) { massconvert = AMU2AU ; } else if( strcmp( massunit , "amu" ) == 0 ) { massconvert = 1.000 ; } else { printf("\nUNKOWN ERROR : INVALID MASS FILE FORMAT ...\n\n"); exit( 75 ) ; } for( iatom = 0 ; iatom < natomselect ; iatom ++ ) { fscanf( pmass , "%lf" , &dtmp ) ; *( mass + iatom ) = dtmp / massconvert ; } printf("\n===> Done Loading Mass ( in %s ) <===\n\n\n" , massunit ) ; //------> Hessian File : fskip( phess , 2 ); len_hess_cart = flength( phess ); if( len_hess_cart == ncart * ncart ) { printf("\nOKay ... I see you provided the Hessian for all %d atom in system ... \n" , natom ); } else if( len_hess_cart == ncartselect * ncartselect ) { printf("\nOKay ... I see you only provided the Hessian for the %d selected atoms ... \n" , natomselect ); } else if( len_hess_cart < ncart * ncart && len_hess_cart > ncartselect * ncartselect ) { printf("\nThere are %d numbers in the Hessian file which is less than the square of total %d Cartesian coordinates in system but more than that of %d Cartesian coordinates of selected atoms ... \n" , len_hess_cart , ncart , ncartselect ); printf("\nSo I am taking the first %d number ( %d * %d ) as the Hessian for selected atoms ...\n" , ncartselect * ncartselect , ncartselect , ncartselect ); } else { printf("\nSomething is wrong with the Hessian file ... There are %d numbers in the Hessian file ... \n" , len_hess_cart ); exit( 77 ); } rewind( phess ); //-------> Allocating space for Hessian and Diagonalization Process ... ncartprovide = sqrt( len_hess_cart ); printf("\nWell ... the Hessian file you provided is a %d * %d square matrix ...\n" , ncartprovide , ncartprovide ); hess_cart = calloc( len_hess_cart , sizeof(double)); dzeros( len_hess_cart , 1, hess_cart ); hess_cart_select = calloc( ncartselect * ncartselect , sizeof(double) ) ; dzeros( ncartselect , ncartselect , hess_cart_select ); double * DMatrix = calloc( ncartselect * ncartselect , sizeof( double ) ) ; dzeros( ncartselect , ncartselect , DMatrix ) ; double * tmp_hessian = calloc( ncartselect * ncartselect , sizeof(double) ) ; dzeros( ncartselect , ncartselect , tmp_hessian ); //tri_hess_cart = calloc( ncart*(ncart+1)/2 , sizeof(double)); //dzeros(ncart*(ncart+1)/2, 1, tri_hess_cart); //-------> Loading Hessian Matrix ... rewind( phess ); fskip( phess , 2 ); fload( phess , hess_cart ); for( j = 0 ; j < len_hess_cart ; j ++ ) { *( hess_cart + j ) = *( hess_cart + j ) / hessconvert ; } printf("\n===> Done Loading Whole Provided Hessian <===\n\n\n") ; //-------> Selecting the desired part of Hessian matrix for( j = 0 ; j < ncartselect ; j ++ ) { for( k = 0 ; k < ncartselect ; k ++ ) { *( hess_cart_select + j * ncartselect + k ) = *( hess_cart + j * ncartprovide + k ); } } printf("\n===> Done Picking The Selected Hessian <===\n\n\n") ; if( debuggingMode == YES ) { debug = fopen("hess_cart.deb", "wb+"); doutput( debug , ncart , ncart , hess_cart); fclose(debug); debug = fopen("hess_cart_select.deb", "wb+"); doutput( debug , ncartselect , ncartselect , hess_cart_select ); fclose(debug); } //-------> Transpose Hessian_cart_select to pass into gausvib_ ... dtranspose( ncartselect , hess_cart_select , hess_cart_select ) ; printf("\n===> Done Transposing Selected Hessian <===\n\n\n") ; //void gausvib_( int * , double * , double * , double * , double * , double * ) ; // ( natom, mass, coordxyzinp, hessianinp, Dmatrix ) //-------> Generate D-Matrix and transform into internal coord ... if( internalOrNot == YES ) { gausvib_( &natomselect , mass , EqCrd , hess_cart_select , DMatrix ) ; dtranspose( ncartselect , DMatrix , DMatrix ) ; printf("\n===> Done Generating D-Matrix ... Currently in C-Fashion <===\n\n\n") ; } else if( internalOrNot == NO ) { for( icart = 0 ; icart < ncartselect ; icart ++ ) { *( DMatrix + icart * ncartselect + icart ) = 1.000 ; } } else { printf("\nUNKNOWN ERROR : [ internalOrNot ] = %d \n\n" , internalOrNot ) ; exit( 15 ) ; } if( debuggingMode == YES ) { debug = fopen( "DMatrix.deb" , "wb+") ; doutput( debug , ncartselect , ncartselect , DMatrix ) ; fclose( debug ) ; } for( j = 0 ; j < natomselect ; j ++ ) *( mass + j ) = ( *( mass + j ) ) * AMU2AU; printf("\n===> Done Putting Mass In AU <===\n\n\n") ; if( debuggingMode == YES ) { debug = fopen("mass_au.deb", "wb+"); doutput( debug , natomselect , 1 , mass ); fclose(debug); } //-------> Performing mass-weighting for the Force constant matrix dtranspose( ncartselect , hess_cart_select , hess_cart_select ) ; //transpose back to C-Fashion masswt( natomselect , mass , hess_cart_select , hess_cart_select ); printf("\n===> Done Mass-Weighting Selected Hessian <===\n\n\n") ; if( debuggingMode == YES ) { debug = fopen("hess_masswt_select.deb", "wb+"); doutput( debug , ncartselect , ncartselect , hess_cart_select ); fclose(debug); } //-------> Calculating f_int = (D.') * f_mwc * D ; double done = 1.0000 ; double dzero = 0.0000 ; int nmode_trans_rot , nvibmodes ; if( natom == 2 ) { nmode_trans_rot = 5 ; } else if( natom >= 3 ) { nmode_trans_rot = 6 ; } nvibmodes = ncartselect - nmode_trans_rot ; double * hess_int_mwc = calloc( ncartselect * ncartselect , sizeof( double ) ) ; dzeros( ncartselect , ncartselect , hess_int_mwc ) ; double * vib_hess_int_mwc = calloc( nvibmodes * nvibmodes , sizeof( double ) ) ; dzeros( nvibmodes , nvibmodes , vib_hess_int_mwc ) ; dgemm_( "N" , "T" , &ncartselect , &ncartselect , &ncartselect , &done , DMatrix , &ncartselect , hess_cart_select , &ncartselect , &dzero , tmp_hessian , &ncartselect ) ; dgemm_( "N" , "T" , &ncartselect , &ncartselect , &ncartselect , &done , tmp_hessian , &ncartselect , DMatrix , &ncartselect , &dzero , hess_int_mwc , &ncartselect ) ; //dtransopose // SUBROUTINE DGEMM ( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC ) printf("\n===> Done Calculating f_int = (D.') * f_mwc * D <===\n\n\n") ; if( debuggingMode == YES ) { debug = fopen( "hess_int_mwc.deb" , "wb+") ; doutput( debug , ncartselect , ncartselect , hess_int_mwc ) ; fclose( debug ) ; } //-------> Performing matrix-diagonalization for Hess_Cart and l=D*L ( for internalOrNot == YES ) freq = calloc( ncartselect , sizeof( double ) ) ; dzeros( ncartselect , 1 , freq ); vib_freq = calloc( nvibmodes , sizeof(double)); dzeros( nvibmodes , 1 , vib_freq ); dxdr = calloc( ncartselect * ncartselect , sizeof(double)); dzeros( ncartselect * ncartselect , 1 , dxdr ); vib_dxdr = calloc( ncartselect * nvibmodes , sizeof( double ) ); dzeros( ncartselect * nvibmodes , 1 , vib_dxdr ) ; double * tmp_dxdr = calloc( nvibmodes * nvibmodes , sizeof( double ) ) ; dzeros( nvibmodes , nvibmodes , tmp_dxdr ) ; double * tmp_dxdr_2 = calloc( nvibmodes * nvibmodes , sizeof( double ) ) ; dzeros( nvibmodes , nvibmodes , tmp_dxdr_2 ) ; if( internalOrNot == YES ) { // ---> Taking the vibrational ( 3N - 6 )-by-( 3N - 6 ) block for( icart = nmode_trans_rot ; icart < ncartselect ; icart ++ ) { for( itmp = nmode_trans_rot ; itmp < ncartselect ; itmp ++ ) { *( vib_hess_int_mwc + ( icart - nmode_trans_rot ) * nvibmodes + ( itmp - nmode_trans_rot ) ) = *( hess_int_mwc + icart * ncartselect + itmp ) ; } } if( debuggingMode == YES ) { debug = fopen( "vib_hess_int_mwc.deb" , "wb+" ) ; doutput( debug , nvibmodes , nvibmodes , vib_hess_int_mwc ) ; fclose( debug ) ; } // ---> Diagonalization dsyev_f2c( nvibmodes , vib_hess_int_mwc , tmp_dxdr, vib_freq ); dtranspose( nvibmodes , tmp_dxdr , tmp_dxdr ); if( debuggingMode == YES ) { /* debug = fopen( "vib_dxdr_internal.deb" , "wb+" ) ; doutput( debug , nvibmodes , nvibmodes , tmp_dxdr ) ; fclose( debug ) ; */ debug = fopen( "vib_freq_internal.deb" , "wb+" ) ; doutput( debug , nvibmodes , 1 , vib_freq ) ; fclose( debug ) ; } printf("\n===> Done Diagonalizing ( 3N - 6 )-by-( 3N - 6 ) internal coordinate mass-weighted Hessian and transpose 3N-6 normal modes back to C <===\n\n\n") ; // ---> Putting ( 3N - 6 )-by-( 3N - 6 ) dxdr into vib_dxdr which is 3N-by-( 3N - 6 ) for( icart = nmode_trans_rot ; icart < ncartselect ; icart ++ ) { for( imode = 0 ; imode < nvibmodes ; imode ++ ) { *( vib_dxdr + icart * nvibmodes + imode ) = *( tmp_dxdr + ( icart - nmode_trans_rot ) * nvibmodes + imode ) ; } } printf("\n===> Done Putting ( 3N - 6 )-by-( 3N - 6 ) dxdr into vib_dxdr which is 3N-by-( 3N - 6 ) <===\n\n\n") ; if( debuggingMode == YES ) { debug = fopen( "vib_dxdr_internal.deb" , "wb+" ) ; doutput( debug , ncartselect , nvibmodes , vib_dxdr ) ; printf("\n[===> Debug <===] [\t%lf\t%lf\t%lf\t]" , *( vib_dxdr + 10 ) , *( vib_dxdr + 19 ) , *( vib_dxdr + 38 ) ) ; fclose( debug ) ; } //---> Performing l = D*L dtranspose_nonsquare( ncartselect , nvibmodes , vib_dxdr , vib_dxdr ) ; dgemm_( "T" , "N" , &ncartselect , &nvibmodes , &ncartselect , &done , DMatrix , &ncartselect , vib_dxdr , &ncartselect , &dzero , tmp_dxdr_2 , &ncartselect ) ; dtranspose_nonsquare( nvibmodes , ncartselect , tmp_dxdr_2 , tmp_dxdr_2 ) ; if( debuggingMode == YES ) { debug = fopen( "vib_dxdr_Cartesian.deb" , "wb+" ) ; doutput( debug , ncartselect , nvibmodes , tmp_dxdr_2 ) ; fclose( debug ) ; } // ---> Putting l into the 3N-by-3N dxdr matrix ... for( icart = 0 ; icart < ncartselect ; icart ++ ) { for( imode = nmode_trans_rot ; imode < ncartselect ; imode ++ ) { *( dxdr + icart * ncartselect + imode ) = *( tmp_dxdr_2 + icart * nvibmodes + ( imode - nmode_trans_rot ) ) ; } } printf("\n===> Done Calculating l = D * L <===\n\n\n") ; // ---> Assemble variable "freq" from "vib_freq" for( imode = nmode_trans_rot ; imode < ncartselect ; imode ++ ) { *( freq + imode ) = *( vib_freq + imode - nmode_trans_rot ) ; } } else if( internalOrNot == NO ) { dsyev_f2c( ncartselect , hess_int_mwc , dxdr, freq ); dtranspose( ncartselect , dxdr , dxdr ); } ////////// ________________________ ////////// if( debuggingMode == YES ) { /* debug = fopen( "dxdr.deb" , "wb+" ) ; doutput( debug , ncartselect , ncartselect , dxdr ) ; fclose( debug ) ; */ debug = fopen("allfrequency.deb", "wb+"); doutput( debug , ncartselect , 1 , freq ); fclose( debug ); } //-------> Arranging frequencies and w=sqrt(lambda) ... if( natomselect == 1 ) { printf("\nSeriously? Only one atom ? NO WAYYYYYY ... \n"); exit( 90 ); } else if( natomselect == 2 ) { *( freq + 5 ) = sqrt( *( freq + 5 ) ) * 219474.6313705 ; } else { for( j = 0 ; j < ncartselect ; j ++ ) { if( *( freq + j ) >= 0.000 ) *( freq + j ) = sqrt( *( freq + j ) ) * 219474.6313705 ; else //*( freq + j ) = -1.000 * sqrt( -1.0000 * ( *( freq + j ) ) ) * 219474.6313705 ; *( freq + j ) = 0.0000 ; } } // Here, no matter it is internal or not, after unit change, we will need to assign freq into vib_freq again ... for( imode = 0 ; imode < nvibmodes ; imode ++ ) { *( vib_freq + imode ) = *( freq + imode + nmode_trans_rot ) ; } printf("\n===> Done Putting Vib-Frequencies Together <===\n\n\n") ; poutDXDR = fopen( outDXDRFileName , "wb+" ) ; doutput( poutDXDR , ncartselect , ncartselect , dxdr ) ; fclose( poutDXDR ) ; poutFreq = fopen( outFreqFileName, "wb+"); doutput( poutFreq , ncartselect , 1 , freq ); fclose( poutFreq ); printf("\n\nI assume it's Allllllll Done ...\n\n"); /* FILE * pmass , * phess , * pEqCrd , * poutDXDR , * poutFreq ; //, *pmo2ao; char massFileName[ 100 ] , hessFileName[ 100 ] , EqCrdFileName[ 100 ] ; char outDXDRFileName[ 100 ] , outFreqFileName[ 100 ] ; */ return( 0 ) ; }
int main() { char str[128]; char compiler[128]; char fpath[MAX_PATH+1]; char* path = "."; char* glob_pattern = "*wrap*"; int i; int ch; uint u; time_t t; glob_t g; DIR* dir; DIRENT* dirent; thread_data_t thread_data; int fd; int fd2; int canrelock=0; clock_t ticks; /* Show platform details */ DESCRIBE_COMPILER(compiler); printf("%-15s: %s\n","Platform",PLATFORM_DESC); printf("%-15s: %s\n","Version",os_version(str)); printf("%-15s: %s\n","Compiler" ,compiler); printf("%-15s: %d\n","Random Number",xp_random(1000)); for(i=0;i<3;i++) { if(_beginthread( sopen_child_thread /* entry point */ ,0 /* stack size (0=auto) */ ,(void*)i /* data */ )==(unsigned long)-1) printf("_beginthread failed\n"); else SLEEP(1); } printf("Waiting for all sopen_child_threads to close...\n"); SLEEP(5000); /* wait for all threads to quit */ /* Exclusive sopen test */ printf("\nsopen() test\n"); if((fd=sopen(LOCK_FNAME,O_RDWR|O_CREAT,SH_DENYRW,S_IREAD|S_IWRITE))==-1) { perror(LOCK_FNAME); return(errno); } printf("%s is opened with an exclusive (read/write) lock\n",LOCK_FNAME); getkey(); if(_beginthread( sopen_test_thread /* entry point */ ,0 /* stack size (0=auto) */ ,NULL /* data */ )==(unsigned long)-1) printf("_beginthread failed\n"); else SLEEP(1000); close(fd); /* sopen()/lock test */ printf("\nlock() test\n"); if((fd=sopen(LOCK_FNAME,O_RDWR|O_CREAT,SH_DENYNO,S_IREAD|S_IWRITE))==-1) { perror(LOCK_FNAME); return(errno); } write(fd,"lock testing\n",LOCK_LEN); if(lock(fd,LOCK_OFFSET,LOCK_LEN)==0) printf("lock() succeeds\n"); else printf("!FAILURE: lock() non-functional (or file already locked)\n"); if(lock(fd,LOCK_OFFSET,LOCK_LEN)==0) { printf("!FAILURE: Subsequent lock of region was allowed (will skip some tests)\n"); canrelock=1; } if(_beginthread( lock_test_thread /* entry point */ ,0 /* stack size (0=auto) */ ,NULL /* data */ )==(unsigned long)-1) printf("_beginthread failed\n"); else SLEEP(1000); if(canrelock) printf("?? Skipping some tests due to inability to detect own locks\n"); else { if(lock(fd,LOCK_OFFSET,LOCK_LEN)) printf("Locks in first thread survive open()/close() in other thread\n"); else printf("!FAILURE: lock() in first thread lost by open()/close() in other thread\n"); if(lock(fd,LOCK_OFFSET+LOCK_LEN+1,LOCK_LEN)) printf("!FAILURE: file locking\n"); else printf("Record locking\n"); } if((fd2=sopen(LOCK_FNAME,O_RDWR,SH_DENYRW))==-1) { printf("Cannot reopen SH_DENYRW while lock is held\n"); close(fd2); } else { printf("!FAILURE: can reopen SH_DENYRW while lock is held\n"); } if(unlock(fd,LOCK_OFFSET,LOCK_LEN)) printf("!FAILURE: unlock() non-functional\n"); if(lock(fd,LOCK_OFFSET+LOCK_LEN+1,LOCK_LEN)) printf("Cannot re-lock after non-overlapping unlock()\n"); else printf("!FAILURE: can re-lock after non-overlappping unlock()\n"); if(lock(fd,LOCK_OFFSET,LOCK_LEN)) printf("!FAILURE: cannot re-lock unlocked area\n"); close(fd); /* getch test */ printf("\ngetch() test (ESC to continue)\n"); do { ch=getch(); printf("getch() returned %d\n",ch); } while(ch!=ESC); /* kbhit test */ printf("\nkbhit() test (any key to continue)\n"); while(!kbhit()) { printf("."); fflush(stdout); SLEEP(500); } getch(); /* remove character from keyboard buffer */ /* BEEP test */ printf("\nBEEP() test\n"); getkey(); for(i=750;i>250;i-=5) BEEP(i,15); for(;i<1000;i+=5) BEEP(i,15); /* SLEEP test */ printf("\nSLEEP(5 second) test\n"); getkey(); t=time(NULL); printf("sleeping... "); fflush(stdout); ticks=msclock(); SLEEP(5000); printf("slept %ld seconds (%ld according to msclock)\n",time(NULL)-t,(msclock()-ticks)/MSCLOCKS_PER_SEC); /* Thread SLEEP test */ printf("\nThread SLEEP(5 second) test\n"); getkey(); i=0; if(_beginthread( sleep_test_thread /* entry point */ ,0 /* stack size (0=auto) */ ,&i /* data */ )==(unsigned long)-1) printf("_beginthread failed\n"); else { SLEEP(1); /* yield to child thread */ while(i==0) { printf("."); fflush(stdout); SLEEP(1000); } } /* glob test */ printf("\nglob(%s) test\n",glob_pattern); getkey(); i=glob(glob_pattern,GLOB_MARK,NULL,&g); if(i==0) { for(u=0;u<g.gl_pathc;u++) printf("%s\n",g.gl_pathv[u]); globfree(&g); } else printf("glob(%s) returned %d\n",glob_pattern,i); /* opendir (and other directory functions) test */ printf("\nopendir(%s) test\n",path); getkey(); printf("\nDirectory of %s\n\n",FULLPATH(fpath,path,sizeof(fpath))); dir=opendir(path); while(dir!=NULL && (dirent=readdir(dir))!=NULL) { t=fdate(dirent->d_name); printf("%.24s %10lu %06o %s%c\n" ,ctime(&t) ,flength(dirent->d_name) ,getfattr(dirent->d_name) ,dirent->d_name ,isdir(dirent->d_name) ? '/':0 ); } if(dir!=NULL) closedir(dir); printf("\nFree disk space: %lu kbytes\n",getfreediskspace(path,1024)); /* Thread (and inter-process communication) test */ printf("\nSemaphore test\n"); getkey(); if(sem_init(&thread_data.parent_sem ,0 /* shared between processes */ ,0 /* initial count */ )) { printf("sem_init failed\n"); } if(sem_init(&thread_data.child_sem ,0 /* shared between processes */ ,0 /* initial count */ )) { printf("sem_init failed\n"); } if(_beginthread( sem_test_thread /* entry point */ ,0 /* stack size (0=auto) */ ,&thread_data /* data */ )==(unsigned long)-1) printf("_beginthread failed\n"); else { sem_wait(&thread_data.child_sem); /* wait for thread to begin */ for(i=0;i<10;i++) { printf("<parent>"); sem_post(&thread_data.parent_sem); sem_wait(&thread_data.child_sem); } sem_wait(&thread_data.child_sem); /* wait for thread to end */ } sem_destroy(&thread_data.parent_sem); sem_destroy(&thread_data.child_sem); printf("\nSemaphore blocking test\n"); getkey(); sem_init(&thread_data.parent_sem ,0 /* shared between processes */ ,0 /* initial count */ ); sem_init(&thread_data.child_sem ,0 /* shared between processes */ ,0 /* initial count */ ); if(_beginthread( sem_test_thread_block /* entry point */ ,0 /* stack size (0=auto) */ ,&thread_data /* data */ )==(unsigned long)-1) printf("_beginthread failed\n"); else { sem_wait(&thread_data.child_sem); /* wait for thread to begin */ for(i=0;i<10;i++) { printf("<parent>"); SLEEP(5000); sem_post(&thread_data.parent_sem); sem_wait(&thread_data.child_sem); } sem_wait(&thread_data.child_sem); /* wait for thread to end */ } printf("\nsem_trywait_block test..."); t=time(NULL); sem_trywait_block(&thread_data.parent_sem,5000); printf("\ntimed-out after %ld seconds (should be 5 seconds)\n",time(NULL)-t); sem_destroy(&thread_data.parent_sem); sem_destroy(&thread_data.child_sem); printf("\nendian check..."); memcpy(&i,"\x01\x02\x03\x04",4); if(LE_LONG(i)==67305985) { printf("OK!\n"); } else { printf("FAILED!\n"); } return 0; }
void BeyeContext::main_loop() { __filesize_t OldCurrFilePos; /** means previous File position */ int ch; __filesize_t savep = 0,cfp,nfp,flen; unsigned long lwidth; plugin_position rc; Search& s = search(); bm_file().seek(LastOffset,binary_stream::Seek_Set); drawPrompt(); rc.textshift=0; rc = active_mode().paint(KE_SUPERKEY,rc.textshift); bm_file().seek(LastOffset,binary_stream::Seek_Set); draw_title(rc.lastbyte); while(1) { unsigned che; ch = GetEvent(drawPrompt,MainActionFromMenu,NULL); nfp = cfp = OldCurrFilePos = tell(); flen = flength(); lwidth = active_mode().curr_line_width(); che = ch & 0x00FF; if(((che >= '0' && che <= '9') || (che >= 'A' && che <= 'Z') || (che >= 'a' && che <= 'z') || ch == KE_BKSPACE) && (active_mode().flags() & Plugin::UseCodeGuide) == Plugin::UseCodeGuide) { nfp = codeguider().get_go_address(ch); goto GO; } switch(ch) { case KE_CTL_F(1): if(active_mode().action_F1()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(2): if(active_mode().action_F2()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(3): if(active_mode().action_F3()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(4): if(active_mode().action_F4()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(5): if(active_mode().action_F5()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(6): if(active_mode().action_F6()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(7): if(active_mode().action_F7()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(8): if(active_mode().action_F8()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(9): if(active_mode().action_F9()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(10): if(active_mode().action_F10()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_ALT_F(1): nfp=bin_format().action_F1(); break; case KE_ALT_F(2): nfp=bin_format().action_F2(); break; case KE_ALT_F(3): nfp=bin_format().action_F3(); break; case KE_ALT_F(4): nfp=bin_format().action_F4(); break; case KE_ALT_F(5): nfp=bin_format().action_F5(); break; case KE_ALT_F(6): nfp=bin_format().action_F6(); break; case KE_ALT_F(7): nfp=bin_format().action_F7(); break; case KE_ALT_F(8): nfp=bin_format().action_F8(); break; case KE_ALT_F(9): nfp=bin_format().action_F9(); break; case KE_ALT_F(10): nfp=bin_format().action_F10(); break; case KE_SUPERKEY: goto DRAW; case KE_F(1) : About(); continue; default : continue; case KE_SHIFT_F(1): active_mode().help(); break; case KE_F(10): case KE_ESCAPE : return; case KE_ENTER: quick_select_mode(); drawPrompt(); ch = KE_SUPERKEY; break; case KE_F(2): if(select_mode()) ch = KE_SUPERKEY; break; case KE_F(3): if(new_source()) { ch = KE_SUPERKEY; s.reset(); PaintTitle(); } break; case KE_F(4): __filesize_t sfp; sfp = tell(); active_mode().misckey_action(); ch = KE_SUPERKEY; PaintTitle(); drawPrompt(); bm_file().seek(sfp,binary_stream::Seek_Set); break; case KE_F(5): { static __filesize_t shift = 0; static unsigned long flags = GJDLG_FILE_TOP; if(GetJumpDlg(&shift,&flags)) { switch(flags&0xFF) { default: case GJDLG_PERCENTS: shift=shift>100?100:shift; nfp = flength()*shift/100; break; case GJDLG_FILE_TOP: nfp = shift; break; case GJDLG_RELATIVE: nfp += (long)shift; break; case GJDLG_REL_EOF: nfp = flength()+(long)shift; break; case GJDLG_VIRTUAL: __filesize_t temp_fp; nfp = shift; temp_fp = bin_format().va2pa(shift); if(temp_fp==Plugin::Bad_Address) ErrMessageBox(NOT_ENTRY,""); else nfp = temp_fp; break; } if((active_mode().flags() & Plugin::UseCodeGuide) == Plugin::UseCodeGuide) codeguider().add_back_address(); ch = KE_SUPERKEY; } } break; case KE_SHIFT_F(5): { WhereAMI wami(beye_context()); nfp = wami.run(nfp); } break; case KE_F(6): bm_file().reread(); s.reset(); ch = KE_SUPERKEY; PaintTitle(); break; case KE_SHIFT_F(6): select_sysinfo(); break; case KE_F(7): nfp = s.run(false); ch = KE_JUSTFIND; break; case KE_SHIFT_F(7): nfp = s.run(true); ch = KE_JUSTFIND; break; case KE_F(8): nfp = bin_format().show_header(); break; case KE_SHIFT_F(8): select_tool(); break; case KE_F(9): { class Setup* setup = new class Setup(*this); setup->run(); delete setup; } break; case KE_SHIFT_F(10): if(FileUtils()) { s.reset(); ch = KE_SUPERKEY; PaintTitle(); } break; case KE_HOME: rc.textshift = 0; break; case KE_END: rc.textshift = active_mode().get_max_line_length() - tconsole().vio_width()/2; break; case KE_UPARROW: nfp = cfp - active_mode().prev_line_width(); break; case KE_DOWNARROW: nfp = cfp + active_mode().curr_line_width(); break; case KE_RIGHTARROW: if((active_mode().flags() & Plugin::Text) == Plugin::Text) rc.textshift+=active_mode().get_symbol_size(); else nfp = cfp + active_mode().get_symbol_size(); break; case KE_LEFTARROW: if((active_mode().flags() & Plugin::Text) == Plugin::Text) rc.textshift-=active_mode().get_symbol_size(); else nfp = cfp - active_mode().get_symbol_size(); if(rc.textshift < 0) rc.textshift = 0; break; case KE_CTL_RIGHTARROW: if((active_mode().flags() & Plugin::Text) == Plugin::Text) rc.textshift+=8*active_mode().get_symbol_size(); else nfp = cfp + 8*active_mode().get_symbol_size(); break; case KE_CTL_LEFTARROW: if((active_mode().flags() & Plugin::Text) == Plugin::Text) rc.textshift-=8*active_mode().get_symbol_size(); else nfp = cfp - 8*active_mode().get_symbol_size(); if(rc.textshift < 0) rc.textshift = 0; break; case KE_PGUP: nfp = cfp - active_mode().prev_page_size(); break; case KE_PGDN: nfp = cfp + active_mode().curr_page_size(); break; case KE_CTL_PGUP: nfp = 0; break; case KE_CTL_PGDN: nfp = flen; break; case KE_CTL_(O): /** User screen */ { unsigned evt; main_wnd().hide(); title_wnd().hide(); do { evt = GetEvent(drawEmptyPrompt,NULL,NULL); } while(!(evt == KE_ESCAPE || evt == KE_F(10) || evt == KE_CTL_(O))); main_wnd().show(); title_wnd().show(); } continue; } GO: if(cfp != nfp && nfp != Plugin::Bad_Address) { unsigned long twidth = ( active_mode().flags() & Plugin::Text ) == Plugin::Text ? active_mode().get_symbol_size() : ( active_mode().flags() & Plugin::Disasm ) == Plugin::Disasm ? 1 : lwidth; __filesize_t p = flen - twidth; if((__fileoff_t)nfp < 0) nfp = 0; if(nfp > 0) if(nfp > p) nfp = p; } bm_file().seek(nfp,binary_stream::Seek_Set); DRAW: if((active_mode().flags() & Plugin::Text) != Plugin::Text) savep = tell(); rc = active_mode().paint(ch,rc.textshift); if((active_mode().flags() & Plugin::Text) != Plugin::Text) bm_file().seek(savep,binary_stream::Seek_Set); draw_title(rc.lastbyte); } }
int main( int argc , char * argv[ ] ) { FILE * pndx , * pdxdr , * pfreq , * patomlist , * passgn ; FILE * debug ; char dxdrname [ 50 ] , ndxname [ 50 ] , atomlistname [ 50 ] , freqname [ 50 ], outassgnname [ 50 ] ; char ** pcmd ; pcmd = argv ; int icmd , itmp ; int ncart , natom , nmode , nfreqprovide; int icart , iatom , imode , ifreq ; int exfreq , exatomlist ; int fakeOrNot = 0 ; time_t current_time; time( ¤t_time ); char now[ 300 ] ; strcpy( now , ctime( ¤t_time ) ); int lennow = strlen( now ) ; *( now + lennow - 1 ) = ' '; // ========> Recording Command-Line Arguments ... printf("\n**********************************************************************\n"); printf("* G_NMASSGN_D : Listing the localization of all vibrational modes. *\n"); printf("* *\n"); printf("* "); for( icmd = 0 ; icmd < argc ; icmd ++ ) { printf("%s " , *( pcmd + icmd ) ); } printf("\n"); printf("* *\n"); printf("* *\n"); printf("* Current Time : %s *\n" , now ); printf("* *\n"); printf("* *\n"); printf("**********************************************************************\n"); // =====> Setting up default file names ... strcpy( dxdrname , "dxdr.deb" ); strcpy( ndxname , "system.index" ); strcpy( freqname , "vibfrequency.deb" ); strcpy( outassgnname , "system.assgn" ); strcpy( atomlistname , "atom.list" ); // =====> Parsing command line input arguments ... if( argc == 1 ) { printf("\n\nNo command-line arguments provided ... Mission aborting ...\n\n"); printf("\nPlease refer to the usage by typing ' %s -h '\n\n" , * argv ); exit(1); } char * flag ; icmd = 1 ; while( icmd < argc ) { pcmd ++ ; flag = * pcmd ; printf("\nNo.%d argument , Currently @ flag = %s ...\n\n" , icmd , flag ); if( ( * flag == '-' ) && ( strlen( flag ) == 2 ) ) { switch ( *( flag + 1 ) ) { case 'f' : strcpy( dxdrname , *( ++ pcmd ) ) ; printf("\nCommand-line argument indicates : Input dxdr File name : %s ...\n" , dxdrname ); icmd = icmd + 2 ; break ; case 'o' : strcpy( outassgnname , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Output File name : %s ...\n" , outassgnname ); icmd = icmd + 2 ; break ; case 'w' : strcpy( freqname , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Input frequency File name : %s ...\n" , freqname ); icmd = icmd + 2 ; break ; case 'n' : strcpy( ndxname , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Input index File name : %s ...\n" , ndxname ); icmd = icmd + 2 ; break ; case 'l' : strcpy( atomlistname , *( ++ pcmd ) ); if( ( strcmp( atomlistname , "none" ) ) == 0 ) { printf("\nCommand-line argument indicates : No AtomList needed ... Will not produce fake frequency file ...\n" ); fakeOrNot = 0 ; } else { printf("\nCommand-line argument indicates : Input atom list File name : %s ...\n" , atomlistname ); fakeOrNot = 1 ; } icmd = icmd + 2 ; break ; case 'h' : printf("\nUsage: %s [ -f 'input dxdr file name' ] [ -n 'input index file name (in GROMACS .ndx format)' ] [(optional) -o 'output NM assignment file name' ] [ -l atom list file (listing the atomic number of all atoms in system ; \"none\" if no frequency file desired)][ -w 'input vibrational frequency file ; best case length = nmode' ]\n\n" , * argv ); printf("\n\n==> NOTE : In order to be fool-proof , if there is mis-match on the NAtom between dxdr file and any other file , this code will set NAtom to be the number from dxdr automatically ...\n\n"); //printf("\nUsage: %s [ -t G09 calculation type : 1=ONIOM ; 2=Point Charge ] [ -f 'input gro file name' ] [(optional) -o 'output g09 file name' ] [ -n # of layers (integer) ] [ (optional) -r radius of middle layer (real) ] [-R radius of lower layer (real) ] [ -H method for Highest layer (string) ] [ (optional) -M method for Middle layer (string) ] [ -L method for Lower layer (string) ] [ -x input GMX .itp file ]\n\n" , * argv ); //exh = 9 ; icmd = icmd + 1 ; exit(1) ; default : printf("\n\nInvalid option ' %s ' ... Please refer to the usage by typing ' %s -h '\n\n" , flag , * argv ); icmd = argc ; exit(1); } } else { printf("\n\nInvalid option ' %s ' ... Please refer to the usage by typing ' %s -h '\n\n" , flag , * argv ); exit(1); } } // =====> Open the files ... if( ( pndx = fopen( ndxname , "r" ) ) == NULL ) { printf("\nUser-defined index file %s does not exist ...\n\n" , ndxname ); exit( 1 ); } if( ( pdxdr = fopen( dxdrname , "r" ) ) == NULL ) { printf("\nUser-defined dxdr file %s does not exist ...\n\n" , dxdrname ); exit( 1 ); } double * freq ; if( ( pfreq = fopen( freqname , "r" ) ) == NULL ) { printf("\nUser-defined frequency file %s does not exist ...\n\n" , freqname ); printf("\nBut it's OK , we will procede without frequency information ... \n"); exfreq = 0 ; } else { nfreqprovide = flength( pfreq ); rewind( pfreq ) ; freq = ( double * ) calloc( nfreqprovide , sizeof( double ) ) ; fload( pfreq , freq ); rewind( pfreq ); exfreq = 1 ; } int * atomlist , natomlistprovide ; if( fakeOrNot == 1 ) { if( ( patomlist = fopen( atomlistname , "r" ) ) == NULL ) { printf("\nUser-defined atom list file %s does not exist ...\n\n" , atomlistname ); printf("\nMeaning ... All of your atoms will be carbon ...\n"); exatomlist = 0 ; } else { natomlistprovide = flength( patomlist ); rewind( patomlist ); atomlist = ( int * ) calloc( natomlistprovide , sizeof( int ) ) ; int_fload( patomlist , atomlist ); exatomlist = 1 ; } } // =====> Read the index file (*****.ndx) ... int countlrb , countrrb ; int ngroup ; int ilrb , irrb , igroup ; char c ; char ** groupnames ; char tmpstring[ 100 ] ; char tmpchar ; // -----> Finding out how many groups are defined in index file ... ilrb = 0 ; irrb = 0 ; //fsearch( pndx , "begin" ); //fscanf( pndx , "%s" , tmpstring ); //if( strcmp( tmpstring , "]" ) != 0 ) //{ // printf("\nSomething is wrong with the ndx file format at the beginning ... Mission Aborting ... \n") ; // // exit(3); // //} //fskip( pndx , 1 ) ; rewind( pndx ) ; while( ( c = fgetc( pndx ) ) != EOF ) { if( c == '[' ) { ilrb ++ ; } else if( c == ']') { irrb ++ ; } else { continue ; } } if( ilrb == irrb ) { ngroup = ilrb ; printf("\nThere are %d defined groups in the index file ...\n" , ngroup ); } else { printf("\nSomething is wrong in the index file ... There are unmatched brackets or broken entries ...\n"); exit( 2 ); } if( ngroup == 0 ) { printf("\nThis index file is an empty file ... Mission Aborting ...\n"); exit(4); } // -----> Finding out how many atoms are in each group int * natom_in_each_group = calloc( ngroup , sizeof( int ) ) ; int current_atom_index , next_atom_index ; int info ; rewind( pndx ) ; //fsearch( pndx , "begin" ); //fskip( pndx , 1 ) ; for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { printf("\n--------------------------> GROUP #%d <----------------------------" , igroup + 1 ); //itmp = 0 ; fsearch( pndx , "]" ) ; //fskip( pndx , 1 ) ; //printf("\nHere we are ... : %c " , fgetc( pndx ) ); fscanf( pndx , "%s" , tmpstring ); //printf("\nFor this group , the 1st grabbed tmpstring is %s ... \n" , tmpstring ); //while( strcmp( tmpstring , "[") != 0 ) for( itmp = 0 ; strcmp( tmpstring , "[" ) != 0 && info != EOF ; ) { //printf("\nGrabbed tmpstring is %s ... \n" , tmpstring ) ; if( strcmp( tmpstring , "-" ) == 0 ) { //printf("\nThe '-' situation happened ... before '-' we are at No.%d atom ... \n" , current_atom_index ); fscanf( pndx , "%d" , &next_atom_index ); //printf("\nAnd after '-' we are at No.%d atom ... \n" , next_atom_index ); itmp = itmp + ( next_atom_index - current_atom_index ); *( natom_in_each_group + igroup ) = itmp ; current_atom_index = next_atom_index ; info = fscanf( pndx , "%s" , tmpstring ) ; } else { itmp ++ ; *( natom_in_each_group + igroup ) = itmp ; current_atom_index = atoi( tmpstring ); //printf("\nNormal situation ... current_atom_index is %d ... \n" , current_atom_index ); info = fscanf( pndx , "%s" , tmpstring ); } } if( info == EOF ) { printf("\nHit the bottom of file ...\n\n") ; break ; } printf("\nDone with #%d group ... \n" , igroup + 1 ); } printf("\n--------------------------> Done checking up groups <----------------------------"); /* Debugging output for this part ... */ printf("\n== Group Information Summary ==\n"); for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { printf("\nNo.%d Group Has %d atoms ...\n" , igroup + 1 , *( natom_in_each_group + igroup ) ); } // -----> Recording the name of each group ... groupnames = ( char ** ) calloc( ngroup , sizeof( char * ) ) ; int tmp_groupname_length ; rewind( pndx ) ; //fsearch( pndx , "begin" ); //fskip( pndx , 1 ); for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { fsearch( pndx , "[" ) ; fscanf( pndx , "%s" , tmpstring ); tmp_groupname_length = strlen( tmpstring ) ; *( groupnames + igroup ) = ( char * ) calloc( tmp_groupname_length + 3 , sizeof( char ) ) ; strcpy( *( groupnames + igroup ) , tmpstring ) ; printf("\nName of %d group is %s ...\n" , igroup + 1 , *( groupnames + igroup ) ); } // =====> Loading the eigenvectors ( dxdr file ) ... printf("\n--------------------------> Begin reading dxdr file ... <----------------------------" ); int len_dxdr = flength( pdxdr ) ; printf("\nThere are %d numbers in eigenvectors file ... \n" , len_dxdr ); ncart = sqrt( len_dxdr ); natom = ncart / 3 ; double * dxdr = calloc( len_dxdr , sizeof( double ) ) ; rewind( pdxdr ); fload( pdxdr , dxdr ) ; rewind( pdxdr ) ; printf("\nDone with loading dxdr file ... \n"); switch( natom ) { case 1 : printf("\nSeriously? Only ONE atom? ...\n") ; exit( 9 ) ; break ; case 2 : nmode = 6 ; break ; default : nmode = ncart - 0 ; break ; } if( exfreq == 0 ) { freq = ( double * ) calloc( nmode , sizeof( double ) ) ; dzeros( nmode , 1 , freq ) ; } else { if( nfreqprovide > nmode ) { printf("\nOkay ... The number of vibrational frequency you provided is more than the normal mode we have from eigenvectors ...\n"); printf("\nSo I will take only the first #_of_eigenvectors frequencies from the file you provided ...\n"); } else if( nfreqprovide < nmode ) { printf("\nOkay ... The number of vibrational frequency you provided is less than the normal mode we have from eigenvectors ...\n"); printf("\nThe rest will be padded with zeros ... Sorry, I really don't want to do the diagonalization ...\n"); free( freq ) ; freq = ( double * ) calloc( nmode , sizeof( double ) ) ; rewind( pfreq ); fload( pfreq , freq ) ; dzeros( nmode - nfreqprovide , 1 , freq + nfreqprovide ) ; } } if( exatomlist == 0 ) { if( fakeOrNot == 1 ) { for( iatom = 0 ; iatom < natom ; iatom ++ ) { *( atomlist + iatom ) = 6 ; } } } else { if( natomlistprovide > natom ) { printf("\nOkay ... The number of atom you provided is more than the NAtom we have from eigenvectors ...\n"); printf("\nSo I will take only the first #_of_atoms from the file you provided ...\n"); } else if( natomlistprovide < natom ) { printf("\nOkay ... The number of atom you provided is less than the NAtom we have from eigenvectors ...\n"); printf("\nSo all the rest will be automatically set as Carbon ... \n"); free( atomlist ); atomlist = ( int * ) calloc( natom , sizeof( int ) ) ; rewind( patomlist ); int_fload( patomlist , atomlist ); for( iatom = natom - natomlistprovide ; iatom < natom ; iatom ++ ) { *( atomlist + iatom ) = 6 ; } } } // =====> Loading the eigenvectors ( dxdr file ) ... // -----> Based on group information, prepare the recording structures (array) ... printf("\n=================================> _ <=====================================\n"); printf("\nStarting from here, we will actually read index file and give the assignment ... \n"); double * assgninfo = calloc( ngroup * nmode , sizeof( double ) ) ; rewind( pndx ) ; //fsearch( pndx , "begin" ); //fskip( pndx , 1 ) ; double tmp_xcomponent , tmp_ycomponent , tmp_zcomponent , tmp_magnitude ; //printf("\nDebugging ... Debugging ... % 12.8E\t% 12.8E\t% 12.8E\n\n" , *( dxdr + 3 ) , *( dxdr + 4 ) , *( dxdr + 5 ) ); info = 9 ; for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { printf("\n--------------------------> GROUP #%d : %s <----------------------------" , igroup + 1 , *( groupnames + igroup ) ); fsearch( pndx , "]" ) ; fscanf( pndx , "%s" , tmpstring ); //printf("\nFor this group , the 1st grabbed tmpstring is %s ... \n" , tmpstring ); for( itmp = 0 ; strcmp( tmpstring , "[" ) != 0 && info != EOF ; ) { //printf("\nGrabbed tmpstring is %s ... \n" , tmpstring ) ; if( strcmp( tmpstring , "-" ) == 0 ) { //printf("\nThe '-' situation happened ... before '-' we are at No.%d atom ... \n" , current_atom_index ); fscanf( pndx , "%d" , &next_atom_index ); //printf("\nAnd after '-' we are at No.%d atom ... \n" , next_atom_index ); itmp = itmp + ( next_atom_index - current_atom_index ); for( iatom = current_atom_index ; iatom < next_atom_index ; iatom ++ ) { //tmp_xcomponent = 0.0000 ; tmp_ycomponent = 0.0000 ; tmp_zcomponent = 0.0000 ; //tmp_magnitude = tmp_xcomponent * tmp_xcomponent + tmp_ycomponent * tmp_ycomponent + tmp_zcomponent * tmp_zcomponent ; printf("\nWorking on No.%d atom ... in No.%d group ...\n" , iatom + 1 , igroup + 1 ); for( imode = 0 ; imode < nmode ; imode ++ ) { tmp_xcomponent = *( dxdr + ( 3 * ( iatom - 0 ) + 0 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom X ... \n" , imode + 1 , tmp_xcomponent , iatom + 1 ); tmp_ycomponent = *( dxdr + ( 3 * ( iatom - 0 ) + 1 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom Y ... \n" , imode + 1 , tmp_ycomponent , iatom + 1 ); tmp_zcomponent = *( dxdr + ( 3 * ( iatom - 0 ) + 2 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom Z ... \n" , imode + 1 , tmp_zcomponent , iatom + 1 ); tmp_magnitude = tmp_xcomponent * tmp_xcomponent + tmp_ycomponent * tmp_ycomponent + tmp_zcomponent * tmp_zcomponent ; //printf("\nNO.%d mode has % 12.8E on #%d atom ... \n" , imode + 1 , tmp_magnitude , iatom + 1 ) ; *( assgninfo + igroup * nmode + imode ) = *( assgninfo + igroup * nmode + imode ) + tmp_magnitude ; printf("\nUp to No.%d atom , No.%d mode has % 12.8E on #%d group ...\n" , iatom + 1 , imode + 1 , *( assgninfo + igroup * nmode + imode ) , igroup + 1 ); } } current_atom_index = next_atom_index ; info = fscanf( pndx , "%s" , tmpstring ) ; } else { itmp ++ ; current_atom_index = atoi( tmpstring ); //printf("\nNormal situation ... current_atom_index is %d ... \n" , current_atom_index ); printf("\nWorking on No.%d atom ... in No.%d group ...\n" , current_atom_index , igroup + 1 ); for( imode = 0 ; imode < nmode ; imode ++ ) { tmp_xcomponent = *( dxdr + ( 3 * ( current_atom_index - 1 ) + 0 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom X ... \n" , imode + 1 , tmp_xcomponent , current_atom_index ); tmp_ycomponent = *( dxdr + ( 3 * ( current_atom_index - 1 ) + 1 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom Y ... \n" , imode + 1 , tmp_ycomponent , current_atom_index ); tmp_zcomponent = *( dxdr + ( 3 * ( current_atom_index - 1 ) + 2 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom Z ... \n" , imode + 1 , tmp_zcomponent , current_atom_index ); tmp_magnitude = tmp_xcomponent * tmp_xcomponent + tmp_ycomponent * tmp_ycomponent + tmp_zcomponent * tmp_zcomponent ; //printf("\nNO.%d mode has % 12.8E on #%d atom ... \n" , imode + 1 , tmp_magnitude , current_atom_index ) ; *( assgninfo + igroup * nmode + imode ) = *( assgninfo + igroup * nmode + imode ) + tmp_magnitude ; printf("\nUp to No.%d atom , No.%d mode has % 12.8E on #%d group ...\n" , current_atom_index , imode + 1 , *( assgninfo + igroup * nmode + imode ) , igroup + 1 ); } info = fscanf( pndx , "%s" , tmpstring ); } } if( info == EOF ) { printf("\nHit the bottom of file ...\n\n") ; break ; } printf("\nDone Loading Information of [ % 5d ] group ... \n" , igroup + 1 ); } /* Debugging output ... */ debug = fopen( "assgnfull.info" , "wb+" ); fprintf( debug , "Mode#\t" ) ; for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { fprintf( debug , "% 12s\t" , *( groupnames + igroup ) ) ; } fprintf( debug , "vib-Frequencies" ); fprintf( debug , "\n\n" ); for( imode = 0 ; imode < nmode ; imode ++ ) { fprintf( debug , "%d\t" , imode + 1 ); for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { fprintf( debug , "% 12.8E\t" , *( assgninfo + igroup * nmode + imode ) ); } fprintf( debug , "% 12.8E\n\n" , *( freq + imode ) ) ; } // =====> Writing the output file ( MATLAB loadable pure number array file ) ... passgn = fopen( outassgnname , "wb+" ) ; fprintf( passgn , "\n\n" ); for( imode = 0 ; imode < nmode ; imode ++ ) { fprintf( passgn , "%d\t" , imode + 1 ); for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { fprintf( passgn , "% 12.8E\t" , *( assgninfo + igroup * nmode + imode ) ); } fprintf( passgn , "% 12.8E\n\n" , *( freq + imode ) ) ; } // =====> Writing the output file ( MATLAB loadable pure number array file ) ... FILE * pfakefreq ; int ibatch = 0 ; int nbatch = nmode / 3 ; if( fakeOrNot == 1 ) { pfakefreq = fopen( "fakeg09.freq" , "wb+" ); if( natom == 1 ) { printf("\nReally? Really?? Really???\n\n"); exit( 1 ) ; } else if( natom == 2 ) { fprintf( pfakefreq , " 1\n A\nFrequencies -- %10.4f\n" , *( freq + 5 ) ) ; fprintf( pfakefreq , "Red. masses -- %10.4f\nFrc consts -- %10.4f\nIR Inten -- %10.4f\n Atom AN X Y Z \n" , 1.00 , 1.00 , 1.00 ); for( iatom = 0 ; iatom < natom ; iatom ++ ) { fprintf( pfakefreq , "%5d%4d % 8.4f % 8.4f %8.4f\n" , iatom + 1 , *( atomlist + iatom ) , *( dxdr + 3 * iatom + 0 ) , *( dxdr + 3 * iatom + 1 ) , *( dxdr + 3 * iatom + 2 ) ); } } else { for( ibatch = 2 ; ibatch < nbatch ; ibatch ++ ) { fprintf( pfakefreq , " %5d %5d %5d\n" , 3 * ( ibatch - 2 ) + 1 , 3 * ( ibatch - 2 ) + 2 , 3 * ( ibatch - 2 ) + 3 ); fprintf( pfakefreq , " %5c %5c %5c\n" , 'A' , 'A', 'A' ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " Frequencies" , *( freq + 3 * ibatch + 0 ) , *( freq + 3 * ibatch + 1 ) , *( freq + 3 * ibatch + 2 ) ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " Red. masses" , 1.00 , 1.00 , 1.00 ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " Frc consts" , 10.00 , 10.00 , 10.00 ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " IR Inten" , 10.00 , 10.00 , 10.00 ); fprintf( pfakefreq , " Atom AN X Y Z X Y Z X Y Z\n"); for( iatom = 0 ; iatom < natom ; iatom ++ ) { fprintf( pfakefreq , "%5d%4d" , iatom + 1 , *( atomlist + iatom ) ) ; fprintf( pfakefreq , " % 8.4f % 8.4f %8.4f" , *( dxdr + nmode * ( 3 * iatom + 0 ) + ( 3 * ( ibatch + 0 ) + 0 ) ) , *( dxdr + nmode * ( 3 * iatom + 1 ) + ( 3 * ( ibatch + 0 ) + 0 ) ) , *( dxdr + nmode * ( 3 * iatom + 2 ) + ( 3 * ( ibatch + 0 ) + 0 ) ) ) ; fprintf( pfakefreq , " % 8.4f % 8.4f %8.4f" , *( dxdr + nmode * ( 3 * iatom + 0 ) + ( 3 * ( ibatch + 0 ) + 1 ) ) , *( dxdr + nmode * ( 3 * iatom + 1 ) + ( 3 * ( ibatch + 0 ) + 1 ) ) , *( dxdr + nmode * ( 3 * iatom + 2 ) + ( 3 * ( ibatch + 0 ) + 1 ) ) ) ; fprintf( pfakefreq , " % 8.4f % 8.4f %8.4f\n" , *( dxdr + nmode * ( 3 * iatom + 0 ) + ( 3 * ( ibatch + 0 ) + 2 ) ) , *( dxdr + nmode * ( 3 * iatom + 1 ) + ( 3 * ( ibatch + 0 ) + 2 ) ) , *( dxdr + nmode * ( 3 * iatom + 2 ) + ( 3 * ( ibatch + 0 ) + 2 ) ) ) ; } } } } return( 0 ); } // The End ...