/* fSyncFile - Attempt to make logical file and physical file the same * * When editing in a network or multi-tasking environment, we need to make * sure that changes made underneath us are properly reflected to the * user. We do this by snapshotting the time-of-last-write and periodically * comparing it with the version on disk. When a mismatch is found, we * prompt the user and give him the opportunity to reread the file * * pFileLoc file structure of interest * fPrompt TRUE => prompt user for permission to refresh, else just * refresh. * * returns TRUE iff the logical file and the physical file are the same. */ flagType fSyncFile ( PFILE pFileLoc, flagType fPrompt ) { if (pFileLoc == NULL) { pFileLoc = pFileHead; } switch (FileStatus (pFileLoc, NULL)) { case FILECHANGED: if (!confirmx("%s has been changed. Refresh? ", pFileLoc->pName)) { /* No, validate this edit session */ SetModTime (pFileLoc); return FALSE; } FileRead (strcpy( buf, pFileLoc->pName ), pFileLoc, TRUE); RSETFLAG (FLAGS (pFileLoc), DIRTY); SETFLAG (fDisplay, RSTATUS); return TRUE; case FILEDELETED: domessage ("File has been deleted"); break; default: break; } return TRUE; }
void WEXPORT WMessageDialog::info( WWindow* parent, const char *text, ... ) { /***************************************************************************/ char* txt = new char[MAX_MESSAGE + 1]; va_list args; va_start( args, text ); vsprintf( txt, text, args ); domessage( parent, txt, NULL, MsgOk ); delete []txt; }
MsgRetType WEXPORT WMessageDialog::message( WWindow* parent, MsgLevel level, MsgButtons button, const char *text, const char *caption ) { /*****************************************************************/ unsigned type; type = (unsigned)level | (unsigned)button; return( domessage( parent, text, caption, type ) ); }
MsgRetType WEXPORT WMessageDialog::messager( WWindow* parent, MsgLevel level, MsgButtons button, uint text_id, uint caption_id ) { /*****************************************************************/ unsigned type; WResStr text( text_id ); WResStr caption( caption_id ); type = (unsigned)level | (unsigned)button; return( domessage( parent, text, caption, type ) ); }
MsgRetType WEXPORT WMessageDialog::messagef( WWindow* parent, MsgLevel level, MsgButtons button, const char *caption, const char *text, ... ) { /********************************************************************/ MsgRetType rc; char* txt = new char[MAX_MESSAGE + 1]; va_list args; va_start( args, text ); vsprintf( (char *)txt, text, args ); unsigned type = (unsigned)level | (unsigned)button; rc = domessage( parent, txt, caption, type ); delete []txt; return( rc ); }
/*** DeleteMark - Remove a mark * * Purpose: * * Un-define a mark. * * Input: * pszMark - Mark to remove * * Output: None * * Notes: * * A message is displayed reporting on success or failure. * *************************************************************************/ void DeleteMark ( char * pszMark ) { REGISTER PFILE pFile; MARK UNALIGNED * pm; for (pFile = pFileHead; pFile; pFile = pFile->pFileNext) { if (TESTFLAG (FLAGS(pFile), VALMARKS) && fCacheMarks (pFile)) { if (pm = FindLocalMark (pszMark, FALSE)) { DelPMark ((MARK *)pm); domessage ("%s: mark deleted", pszMark); return; } } } printerror ("%s: Mark not found", pszMark); }
void accept_cli(threadargs *newargs) { LList *userlist=newargs->list; int cli_socket=newargs->sock; int cli_sock2; int recvn; //num of recv bytes char buf[bufsize+1]=""; char buf2[bufsize+1]=""; char cmd; client newcli; client lastuser; //the user which client talk to last time bzero(&newcli,sizeof(client)); bzero(&lastuser,sizeof(client)); if(-1==Recv(cli_socket,buf)) pthread_exit(NULL); printf("%s",buf); if(-1==Send(cli_socket,"Server OCP v0.0.1\n")) pthread_exit(NULL); bzero(buf,bufsize); if(-1==Recv(cli_socket,buf)) pthread_exit(NULL); Rtrim(buf); while(useratlist(userlist,buf)==0) //username has been used { if(-1==Send(cli_socket,":x")) pthread_exit(NULL); bzero(buf,bufsize); if(-1==Recv(cli_socket,buf)) pthread_exit(NULL); Rtrim(buf); } Send (cli_socket,"Longin Successfully\n"); strncpy(newcli.nick,buf,strlen(buf)); newcli.sock=cli_socket; ListInsert(userlist,newcli); while(1) { LNode *node=userlist->head->next; //use in :a bzero(buf,bufsize); if(Recv(cli_socket,buf)==-1) //client offline { ListDelete(userlist,cli_socket); pthread_exit(NULL); } if((cmd=iscmd(buf))==0) //if message body contains only message(not have a command) { if(useratlist(userlist,lastuser.nick)==0) { cli_sock2=lastuser.sock; domessage(buf2,newcli.nick,buf); if(-1==Send(cli_sock2,buf2)) pthread_exit(NULL); } else { if(-1==Send(cli_socket,"The user you want to talk isn't online\n")) pthread_exit(NULL); } continue; } switch(cmd) { case 'l': bzero(buf,bufsize); LNode *user=userlist->head->next; while(user!=NULL) { strcat(buf,user->e.nick); strcat(buf,"\n"); user=user->next; } if(-1==Send(cli_socket,buf)) pthread_exit(NULL); break; case 'u': //client change user which will talk to if(getuser(buf,lastuser.nick,userlist)!=-1) //buf client's message //buf2 username {cli_sock2=findclientsock(userlist,lastuser.nick); lastuser.sock=cli_sock2; if(getthird(buf)!=NULL) { domessage(buf2,newcli.nick,getthird(buf)); if(-1==Send(cli_sock2,buf2)) pthread_exit(NULL); } } else { if(-1==Send(cli_socket,"You doesn't specify a user,or the user you want to talk to isn't online\n")) pthread_exit(NULL); } break; case 'q': //client quit if(-1==Send(cli_socket,buf)) pthread_exit(NULL); ListDelete(userlist,cli_socket); close(cli_socket); pthread_exit(NULL); break; case 'a': //client talk to all user while(node!=NULL) { client user=node->e; cli_sock2=user.sock; if (cli_sock2!=cli_socket) //don't send the message to your { if(getsecond(buf)!=NULL) //if the message body only contains the :a string domessage(buf2,newcli.nick,getsecond(buf)); if(-1==Send(cli_sock2,buf2)) pthread_exit(NULL); } node=node->next; } break; default : if(-1==Send(cli_socket,"Sever can't recognize your command\n")) pthread_exit(NULL); } } }
/* fChangeFile - change the current file, drive or directory. We form the * canonicalized name and attempt to find it in our internal list. If * present, then things are simple: relink it to the head of the current * window instance set. If not present, then we need to read it in. * * The actual algorithm is much simpler: * * If file not in file list then * create new entry in file list * Find file in file list * If file not in window instance list then * add file to top of window instance list * while files in window instance list do * select top file * if file is in memory then * change succeeded * else * if read in succeeds then * change succeeded * pop off top file * change failed * * * fShort TRUE => allow searching for short names * name name of file. * * Returns: TRUE if change succeeded * FALSE otherwise */ flagType fChangeFile ( flagType fShort, char *name ) { PFILE pFileTmp; pathbuf bufCanon; flagType fRead; char *p; // // If they explicitly specified .\ skip shortname checks // if (name[0] == '.' && name[1] == '\\') { fShort = FALSE; } // // Turn file name into canonical form // if (!CanonFilename (name, bufCanon)) { // // We may have failed because a drive or directory // went away. If the file named is on the file // list, we remove it. // printerror ("Cannot access %s - %s", name, error () ); pFileTmp = FileNameToHandle (name, (fShort && fShortNames) ? name : NULL); if (pFileTmp != NULL) { RemoveFile (pFileTmp); } return FALSE; } // // name has the input name // bufCanon has the full "real" name // // Check to see if the file is in the current file set // pFileTmp = FileNameToHandle (bufCanon, (fShort && fShortNames) ? name : NULL); if (pFileTmp == NULL) { // // File not loaded. If it is a directory, change to it // if (strlen (bufCanon) == 2 && bufCanon[1] == ':') { bufCanon[2] = '\\'; } if (_chdir (bufCanon) != -1) { domessage ("Changed directory to %s", bufCanon); return TRUE; } // // Must be a file. Create a new internal file for it // pFileTmp = AddFile (bufCanon); } // // Bring the found file to the top of the MRU list // pFileToTop (pFileTmp); // // if the file is not currently in memory, read it in // domessage (NULL); if (((FLAGS (pFileHead) & (REAL|REFRESH)) == REAL) || (fRead = FileRead (pFileHead->pName, pFileHead, TRUE))) { // If we just read in the file AND the file is new then // reset cached location to TOF. // if (fRead && TESTFLAG (FLAGS (pFileHead), NEW)) { YCUR(pInsCur) = 0; XCUR(pInsCur) = 0; } fSyncFile (pFileHead, TRUE); cursorfl (pInsCur->flCursorCur); fInitFileMac (pFileHead); // // Set the window's title // p = pFileHead->pName + strlen(pFileHead->pName); while ( p > pFileHead->pName && *p != '\\' ) { p--; } if ( *p == '\\' ) { p++; } sprintf( bufCanon, "%s - %s", pOrigTitle, p ); SetConsoleTitle( bufCanon ); return TRUE; } // The file was not successfully read in. Remove this instance and // return the indicated error. // RemoveTop (); return FALSE; }
/*** doreplace - perform search-replace * * Performs the actual search and replace argument verification, set up and * high level control. * * Input: * fQuery = TRUE if a query replace * pArg = pArg of parent function * fMeta = fMeta of parent function * fFiles = TRUE is multiple file search and replace. * * Output: * Returns ..... * * Exceptions: * * Notes: * *************************************************************************/ flagType doreplace ( flagType fQuery, ARG * pArg, flagType fMeta, flagType fFiles ) { buffer bufFn; /* filename buffer */ fl flStart; char *p; PCMD pCmd; PFILE pFileSave; /* file to save as top of heap */ p = "Query Search string: "; if (!fQuery) { p += 6; } fQrpl = fQuery; fSrchCasePrev = fMeta ? (flagType)!fSrchCaseSwit : fSrchCaseSwit; Display (); cRepl = 0; /* * If not menu-driven, ask the user for a search string. If none is entered, * we're done. */ if ((pCmd = getstring (srcbuf, sizeof(srcbuf), p, NULL, GS_NEWLINE | GS_INITIAL)) == NULL || (PVOID)pCmd->func == (PVOID)cancel) { return FALSE; } if (srcbuf[0] == '\0') { return FALSE; } /* * If RE search to take place, the compile the expression. */ if (pArg->arg.nullarg.cArg == 2) { if (patBuf != NULL) { FREE ((char *) patBuf); patBuf = NULL; } patBuf = RECompile (srcbuf, fSrchCaseSwit, (flagType)!fUnixRE); if (patBuf == NULL) { printerror ((RESize == -1) ? "Invalid pattern" : "Not enough memory for pattern"); return FALSE; } fRplRePrev = TRUE; } else { fRplRePrev = FALSE; } /* * If not menu driven, ask the user for a replacement string. Confirm the * entry of a null string. Error check the replacement if an RE search. */ if ((pCmd = getstring (rplbuf, sizeof(rplbuf), "Replace string: ", NULL, GS_NEWLINE | GS_INITIAL)) == NULL || (PVOID)pCmd->func == (PVOID)cancel) { return FALSE; } if (rplbuf[0] == 0) { if (!confirm ("Empty replacement string, confirm: ", NULL)) { return FALSE; } } if (fRplRePrev && !RETranslate (patBuf, rplbuf, scanreal)) { printerror ("Invalid replacement pattern"); return FALSE; } srchlen = strlen (srcbuf); switch (pArg->argType) { case NOARG: case NULLARG: setAllScan (TRUE); break; case LINEARG: rnScan.flFirst.col = 0; rnScan.flLast.col = sizeof(linebuf)-1; rnScan.flFirst.lin = pArg->arg.linearg.yStart; rnScan.flLast.lin = pArg->arg.linearg.yEnd; break; case BOXARG: rnScan.flFirst.col = pArg->arg.boxarg.xLeft; rnScan.flLast.col = pArg->arg.boxarg.xRight; rnScan.flFirst.lin = pArg->arg.boxarg.yTop; rnScan.flLast.lin = pArg->arg.boxarg.yBottom; break; case STREAMARG: if (pArg->arg.streamarg.yStart == pArg->arg.streamarg.yEnd) { rnScan.flFirst.col = pArg->arg.streamarg.xStart; rnScan.flLast.col = pArg->arg.streamarg.xEnd; rnScan.flFirst.lin = pArg->arg.streamarg.yStart; rnScan.flLast.lin = pArg->arg.streamarg.yEnd; } else { rnScan.flFirst.col = 0; /* Do all but last line first */ rnScan.flLast.col = sizeof(linebuf)-1; rnScan.flFirst.lin = pArg->arg.streamarg.yStart; rnScan.flLast.lin = pArg->arg.streamarg.yEnd - 1; flStart.col = pArg->arg.streamarg.xStart - 1; flStart.lin = rnScan.flFirst.lin; fScan (flStart, fDoReplace , TRUE, fSrchWrapSwit); rnScan.flLast.col = pArg->arg.streamarg.xEnd; rnScan.flFirst.lin = ++rnScan.flLast.lin; } } flStart.col = rnScan.flFirst.col-1; flStart.lin = rnScan.flFirst.lin; if (fRplRePrev) { MaxREStack = 512; REStack = (RE_OPCODE **)ZEROMALLOC (MaxREStack * sizeof(*REStack)); } if (fFiles) { /* * Get the list handle, and initialize to start at the head of the list. * Attempt to read each file. */ if (pCmd = GetListHandle ("mgreplist", TRUE)) { pFileSave = pFileHead; p = ScanList (pCmd, TRUE); while (p) { CanonFilename (p, bufFn); forfile (bufFn, A_ALL, mrepl1file, &p); p = ScanList (NULL, TRUE); if (fCtrlc) { return FALSE; } } pFileToTop (pFileSave); dispmsg (0); } } else { fScan (flStart, fDoReplace , TRUE, fSrchWrapSwit); } if (fRplRePrev) { FREE (REStack); } domessage ("%d occurrences replaced", cRepl); return (flagType)(cRepl != 0); }
/*** DoPrint - Does the printing * * If a <printcmd> has been defined * queue up the job for the <print> thread (synchronous exec under DOS) * else * send the file to the printer, each line at a time * * Input: * pFile = File to be printed. * * Output: * Returns True if the printing has been succesful, False otherwise * *************************************************************************/ flagType DoPrint ( PFILE pFile, flagType fDelete ) { assert (pFile); if (pPrintCmd) { buffer pCmdBuf; // Buffer for command construction if (TESTFLAG (FLAGS (pFile), DIRTY) && confirmx ("File %s is dirty, do you want to save it ?", pFile->pName)) FileWrite (pFile->pName, pFile); sprintf (pCmdBuf, pPrintCmd, pFile->pName); if (pBTDPrint->cBTQ > MAXBTQ-2) disperr (MSGERR_PRTFULL); else if (BTAdd (pBTDPrint, (PFUNCTION)NULL, pCmdBuf) && (!fDelete || BTAdd (pBTDPrint, (PFUNCTION)CleanPrint, pFile->pName))) return TRUE; else disperr (MSGERR_PRTCANT); if (fDelete) _unlink (pFile->pName); return FALSE; } else { static char szPrn[] = "PRN"; flagType fOK = TRUE; // Holds the return value LINE lCur; // Number of line we're printing char pLineBuf[sizeof(linebuf)+1]; // Holds the line we're printing unsigned int cLen; // Length of line we're printing EDITOR_KEY Key; // User input (for abortion) int hPrn; // PRN file handle dispmsg (MSG_PRINTING,pFile->pName); if ((hPrn = _open (szPrn, O_WRONLY)) == -1) { disperr (MSGERR_OPEN, szPrn, error()); fOK = FALSE; } else { for (lCur = 0; lCur < pFile->cLines; lCur++) { if (TypeAhead () && (Key = TranslateKey(ReadChar()), (Key.KeyCode == 0x130)) && (!Key.KeyInfo.KeyData.Flags)) { fOK = FALSE; break; } cLen = GetLine (lCur, pLineBuf, pFile); // * (int UNALIGNED *) (pLineBuf + cLen++) = '\n'; * (pLineBuf + cLen++) = '\n'; if (_write (hPrn, pLineBuf, cLen) == -1) { disperr (MSGERR_PRTCANT); fOK = FALSE; break; } } _close (hPrn); } domessage (NULL); if (fDelete) { _unlink (pFile->pName); } return fOK; } }