word FindProtocol(sword protocol, struct _proto *pro) { char fname[PATHLEN], *p; long seekit; word ret=FALSE; int fd; /* Handle a user-specified protocol.max file */ p=PRM(protocol_max); if (*p) strcpy(fname, p); else sprintf(fname, "%sprotocol.max", PRM(sys_path)); if ((fd=shopen(fname, O_RDONLY | O_BINARY | O_NOINHERIT))==-1) { cant_open(fname); return FALSE; } seekit=sizeof(struct _proto)*protocol; if (lseek(fd, seekit, SEEK_SET)==seekit && read(fd, (char *)pro, sizeof(struct _proto))==sizeof(struct _proto)) { ret=TRUE; } close(fd); return ret; }
static void near GetBarPwd(char *pwd) { if (! *linebuf) Display_File(0, NULL, PRM(barricade)); InputGetse(pwd, '.', bar_access); display_line=display_col=1; cfancy_str(pwd); }
int IsInUserList(char *name, int show_us) { struct _usr user; HUF huf; int rc; /* Try to open the user file */ if ((huf=UserFileOpen(PRM(user_file), 0))==NULL) { cant_open(PRM(user_file)); return FALSE; } rc=UserFileFind(huf, name, NULL, &user) || UserFileFind(huf, NULL, name, &user); if (!show_us && (eqstri(name, usr.name) || eqstri(name, usr.alias))) rc=FALSE; UserFileClose(huf); return rc; }
int GetMaxFlowIntPR (PNEANet &Net, const int& SrcNId, const int& SnkNId) { IAssert(Net->IsNode(SrcNId)); IAssert(Net->IsNode(SnkNId)); if (SrcNId == SnkNId) { return 0; } TPRManager PRM(Net); int MaxLabel = PRM.GetMaxLabel(); TNEANet::TNodeI SrcNI = Net->GetNI(SrcNId); for (int EdgeN = 0; EdgeN < SrcNI.GetOutDeg(); EdgeN++) { int EId = SrcNI.GetOutEId(EdgeN); int OutNId = SrcNI.GetOutNId(EdgeN); if (OutNId != SrcNId) { int Capacity = PRM.Capacity(EId); PRM.Flow(EId) = Capacity; PRM.Excess(OutNId) = Capacity; } } GlobalRelabel(Net, PRM, SrcNId, SnkNId); PRM.SetLabel(SrcNId, MaxLabel); int RelabelCount = 1; int GRRate = Net->GetNodes(); while (PRM.HasActive()) { int NId = PRM.PopActive(); const TNEANet::TNodeI &NI = Net->GetNI(NId); int PrevLabel = MaxLabel; while (PRM.Excess(NId) > 0 && PRM.Label(NId) <= PrevLabel) { PrevLabel = PRM.Label(NId); int NbrNId = PushRelabel(PRM, NId, NI); if (NbrNId != -1 && NbrNId != SnkNId && PRM.Excess(NbrNId) > 0 && !PRM.IsActive(NbrNId)) { PRM.PushActive(NbrNId); } } if (PRM.Excess(NId) > 0 && PRM.Label(NId) < MaxLabel) { PRM.PushActive(NId); } if (RelabelCount % GRRate == 0) { GlobalRelabel(Net, PRM, SrcNId, SnkNId); } } return PRM.Excess(SnkNId); }
static void near WFC_Init_Modem(void) { /* Fix the modem buffers */ Mdm_Flow(FLOW_OFF); Mdm_Flow(FLOW_ON); if (!out_empty()) mdm_dump(DUMP_OUTPUT); #ifdef OS_2 ComWatchDog(hcModem, FALSE, 0); #endif local=FALSE; UpdateStatWindow(wfc_initing); WFCMaxBaud(); mdm_cmd(PRM(m_init)); mdm_dtr(DTR_UP); }
int Get_FidoList_Name(XMSG *msg, char *netnode, char *fidouser) { NETADDR *d; FILE *ulfile; char line[120]; char name[60], *p; long lo, hi, last, tryit; int linelen, comp; /* If no "To:" field, always return FALSE */ if (isblstr(msg->to)) return FALSE; if (Parse_Alias_File(msg, netnode)) return TRUE; /* Handle version7 name lookups */ if (prm.nlver==NLVER_7) { struct _newnode node; NETADDR dest; if (V7FindName(msg->to, &dest, &node, PRM(net_info))) { strcpy(netnode, Address(&dest)); return TRUE; } } #if 1 /* Last, First Middle */ for (p=(char *)(msg->to+strlen(msg->to)-1); p >= (char *)msg->to && *p != ' '; p--) ; #else /* Middle Last, First */ for (p=msg->to; *p && *p != ' '; p++) ; #endif /* Try to find it in the FroDo nodelist */ if (prm.nlver==NLVER_FD) { NETADDR dest; /* Convert the name to JoHo format */ #if !defined(__GNUC__) sprintf(name, "%s %-0.*s", p+1, p-msg->to, msg->to); #else /* What the HELL did scott mean by THAT? -- wes */ sprintf(name, "%s %s", p+1, (char *)msg->to); #endif name[15]='\0'; while(strlen(name) < 15) strcat(name, " "); if (FDFindName(name, &dest, PRM(net_info))) { strcpy(netnode, Address(&dest)); return TRUE; } } if (! *fidouser) return FALSE; #if !defined(__GNUC__) sprintf(name, "%s, %-0.*s", p+1, p-msg->to, msg->to); /* WTF? */ #else sprintf(name, "%s %s", p+1, msg->to); #endif if ((ulfile=shfopen(fidouser, fopen_readb, O_RDONLY | O_BINARY | O_NOINHERIT))==NULL) return FALSE; /* Find out the length of the first line */ if (fgets(line, sizeof(line), ulfile) != NULL) { linelen=strlen(line); /* Now find out where the end of the file is */ fseek(ulfile,0L,SEEK_END); if (linelen) { hi=ftell(ulfile)/linelen; /* Now use binary search logic to find the user's name */ lo=0L; last=-1L; for (;;) { tryit=((hi-lo) >> 1)+lo; if (last==tryit) break; last=tryit; fseek(ulfile,(long)linelen*tryit,SEEK_SET); if (fgets(line,sizeof(line),ulfile)==NULL) break; comp=strnicmp(name,line,strlen(name)); if (comp==0) { /* Got it! */ p=line+strlen(name); /* Skip over the name, until we find a digit (start of z:n/n.p) */ while (*p && !isdigit(*p)) p++; /* Got a digit, so copy the address in */ if (isdigit(*p)) { d=&msg->dest; MaxParseNN(p, d); strcpy(netnode, Address(d)); } break; } else if (comp < 0) hi=tryit; else lo=tryit; } } }
static int near sendrip(char *pszFile, int fDisplay, int force) { int sendit; long filesize; char temp[PATHLEN]; if (!hasRIP()) return SENDRIP_ERROR; logit("@sendrip(%s,%s,%d)", pszFile, fDisplay ? "true" : "false", force); /* Get qualified filename for file to send */ strcpy(temp, rippath); Add_Trailing(temp, PATH_DELIM); strcat(temp, pszFile); /* See if it exists in the current RIP path */ if ((filesize=fsize(temp))==-1L) { /* Ok, then try the default RIP path */ strcpy(temp, PRM(rippath)); Add_Trailing(temp, PATH_DELIM); strcat(temp, pszFile); if ((filesize=fexist(temp))==-1) { /* Report it as an error and quit */ cant_open(temp); return SENDRIP_FILENOTEXIST; } } sendit=!ripfilesent(temp); /* Query remote if send is forced or file hasn't * yet been sent in this session */ if (force || sendit) { int hasit=RIP_HasFile(pszFile,&filesize); if (hasit==-1) return SENDRIP_ERROR; /* RIP query aborted without success */ if (!hasit) sendit=TRUE; else { /* If we know that the remote has the file, add it to our list * of "sent" files. Path must also be added to ensure that the * same icon will be sent in case rippath changes during session */ addripfile(temp); sendit=FALSE; } } /* If remote already has the file and display is true * Then simply tell the remote system to display it */ if (!sendit) { if (fDisplay) { /* Send any files "batched" for sending prior this now * to ensure that the display order remains the same */ if (!FileEntries() || (sendit=ripsendbatch(fDisplay))) { /* "play RIP scene" - note: icons are NOT supported here */ /* You must send icons in batch without playback, then */ /* use them within RIP scenes */ Printf("\r!|1R00000000%s\n", pszFile); sendit=TRUE; } } } /* We need to send them the file * Just queue it for now */ else { /* Send all batched so far if we've run out of space */ if (CanAddFileEntry() || (sendit=ripsendbatch(fDisplay))) { AddFileEntry(temp, FFLAG_NOBYTES, filesize); sendit=TRUE; } } return sendit ? SENDRIP_FILESENT : SENDRIP_ALREADYHAS; }
void Wait_For_Caller(void) { char *rsp; startbaud=baud; strcpy(usrname, us_short); ChatSetStatus(FALSE, cs_wfc); WFC_Init(); Update_Status(wfc_waiting); #if (COMMAPI_VER > 1) if (ComIsAModem(hcModem)) { #endif while ((rsp=Get_Modem_Response()) != NULL) if (Process_Modem_Response(rsp)) break; #if (COMMAPI_VER > 1) } else { while(!ComIsOnline(hcModem)) { WFC_IdleInternal(); if(local || kexit|| do_next_event) break; //usleep(250000); } ComTxWait(hcModem, 1000); goto letsgo; } #endif /* COMMAPI_VER > 1 */ if (kexit || do_next_event) { if (kexit) logit(log_wfc_exit_keyb); if (do_next_event) logit(log_wfc_exit_erl,next_event.erl); Update_Status(wfc_hanging_up); } if (local || kexit || do_next_event) { WFCMaxBaud(); mdm_cmd(PRM(m_busy)); } letsgo: WFC_Uninit(); #ifdef TTYVIDEO if (displaymode==VIDEO_IBM) #endif WinSetAttr(win, CGRAY); if (kexit) { local=TRUE; quit(ERROR_KEXIT); } else if (do_next_event) { quit(next_event.erl); } in_wfc=FALSE; do_timecheck=TRUE; timestart=timeon=time(NULL); timeoff=timeon+(1440*60L); if (!local) { max_time=(next_event_time-time(NULL))/60L; getoff=timestart+(max_time*60L); } }
static int near Process_Modem_Response(char *rsp) { int gotbaud=FALSE; int gotarq=FALSE; char *s; if (eqstri(rsp, PRM(m_ring))) { if (*PRM(m_answer)) mdm_cmd(PRM(m_answer)); } else if (eqstrni(rsp, PRM(m_connect), strlen(PRM(m_connect)))) { baud=0L; *arq_info='\0'; /* Now parse all of the junk out of the connect string */ for (s=rsp+strlen(PRM(m_connect)); *s; ) { if (*s==' ') /* Do nothing */ s++; else if (*s=='V' && !gotarq) /* DigiDial "CONNECT V120 57600" messages */ { char *space=strchr(s, ' '); if (space) { strncpy(arq_info, s+1, space-s-1); arq_info[space-s-1]=0; gotarq=TRUE; s=space+1; } else s++; } else if (eqstrni(rsp,"fast",4)) { if (!gotbaud) { baud=9600L; s += 4; gotbaud=TRUE; } else s++; } else if (isdigit(*s)) { if (!gotbaud) { baud=atol(s); while (isdigit(*s)) s++; gotbaud=TRUE; } else s++; } else if (*s=='/' && !gotarq) { gotarq=TRUE; strnncpy(arq_info, ++s, ARQ_LEN-1); } else s++; } if (!baud) baud=300L; else if (baud==1275L || baud==75 || baud==7512L || baud==212L || baud==12L) { baud=1200L; } /* Set the right baud rate on that com port */ mdm_baud(current_baud=Decimal_Baud_To_Mask((unsigned int)baud)); local=FALSE; logit(log_wfc_connect, baud, *arq_info ? " (" : blank_str, arq_info, *arq_info ? ")" : blank_str); Update_Status(wfc_connected); /* If we get a pipe, VMP or telnet connection, it should be * instantaneous. However, due to an SIO 1.4x bug, we need * to give the line a bit of time to settle. */ if (eqstri(arq_info, "pipe") || stristr(arq_info, "/vmp") || stristr(arq_info, "/tel")) { Delay(20); } else { Mdm_Flow(FLOW_OFF); /* Wait five secs or until we get two <cr>s or <esc>s */ Clear_MNP_Garbage(); mdm_dump(DUMP_ALL); Mdm_Flow(FLOW_ON); } #ifdef UNIX /* On UNIX we need to tell the comm api that our device has a carrier else WFC will be dancing with "No carrier" */ mdm_nowonline(); #endif if (!carrier()) { logit(log_byebye); /* Reinitialize the modem */ WFC_Init_Modem(); Update_Status(wfc_waiting); baud=0L; *arq_info='\0'; /* local=TRUE;*/ return 0; } #ifdef OS_2 ComWatchDog(hcModem, TRUE, 5); /* enable, 5 sec timeout */ #endif return 1; } return 0; }
int File_Get_Protocol(sword *protocol, int chng, int need_nonexit) { char temp[PATHLEN]; struct _proto_str *ps; char *s; word max, prot; byte ch; if (!chng && usr.def_proto != PROTOCOL_NONE) { if (!need_nonexit || usr.def_proto < 0 || (prm.protoflag[usr.def_proto] & XTERNEXIT)==0) { *protocol=usr.def_proto; return 0; } } *protocol=PROTOCOL_NONE; if (! *linebuf) { if (*PRM(proto_dump)) Display_File(0,NULL,PRM(proto_dump)); else { if (!chng) Puts(avail_proto); /* "Available protocols:" */ /* Now, calculate the minimum required width of the box... */ max=9; for (prot=0; prot < MAX_EXTERNP; prot++) if (!need_nonexit || (prm.protoflag[prot] & XTERNEXIT)==0) { if (strlen(s=Protocol_Name(prot, temp)) > max) max=strlen(s); } /* Display the top of the box */ Printf(proto_box_top, max+3); /* Print the middle of the box */ for (ps=intern_proto; ps->name; ps++) if (*ps->name) { if (no_zmodem && *ps->name=='Z') continue; Printf(proto_box_mid, *ps->name, max-1, max-1, ps->name+1); } for (prot=0; prot < MAX_EXTERNP; prot++) if (!need_nonexit || (prm.protoflag[prot] & XTERNEXIT)==0) if (*(s=Protocol_Name(prot, temp))) Printf(proto_box_mid, toupper(*s), max-1, max-1, s+1); Printf(proto_box_mid, chng ? *proto_none : *proto_quit, max-1, max-1, (chng ? proto_none : proto_quit)+1); Printf(proto_box_bot, max+3); } } ch=(byte)toupper(KeyGetRNP(select_p)); if (ch=='Q' || (ch=='N' && chng) || ch=='\r' || ch=='\x00') return -1; for (ps=intern_proto; ps->name; ps++) { if (no_zmodem && *ps->name=='Z') continue; if (*ps->name==ch) { *protocol=ps->num; return 0; } } for (prot=0; prot < MAX_EXTERNP; prot++) if (!need_nonexit || (prm.protoflag[prot] & XTERNEXIT)==0) if (ch==(byte)toupper(*Protocol_Name(prot, temp))) { *protocol=(int)prot; return 0; } *linebuf='\0'; Printf(dontunderstand, ch); return -1; }