Esempio n. 1
0
int ParseConfigInjectDLL(TCHAR *pszLine, CONFIG *pConfig)
{
	TCHAR *pszToken;
	TCHAR *pszFilename;
	struct Command1psz *pC1P;

	if (!OneRemainingToken(pszLine, &pszToken))
    return -1;

	pszFilename = ParseFilename(pszToken);
	if (NULL == pszFilename)
	{
		free(pszToken);
		return -2;
	}
	
	free(pszToken);

	pC1P = malloc(sizeof(struct Command1psz));
	if (NULL == pC1P)
	{
		free(pszFilename);
		return -3;
	}
	pC1P->pszArgument = pszFilename;
	return AddStatement(pConfig, COMMAND_INJECT_DLL, pC1P);
}
Esempio n. 2
0
int ParseConfigStart(TCHAR *pszLine, CONFIG *pConfig)
{
	TCHAR *pszToken;
	
	if (!OneRemainingToken(pszLine, &pszToken))
    return -1;
	
	pConfig->szStart = ParseFilename(pszToken);
	
	free(pszToken);
	
	return NULL == pConfig->szStart ? -2 : 0;
}
Esempio n. 3
0
int svlVideoCodecTCPStream::Open(const std::string &filename, unsigned int &width, unsigned int &height, double &framerate)
{
    if (Opened || ParseFilename(filename) != SVL_OK) return SVL_FAIL;

    std::string extensionlist(GetExtensions());
    std::string extension;
    svlVideoIO::GetExtension(filename, extension);
         if (extension == "ncvi") Compressor = CVI;
    else if (extension == "njpg") Compressor = JPEG;
    else return SVL_FAIL;

    while (1) {

        Opened = true;
        Writing = false;
        Width = Height = 0;

        // Releasing existing buffers
        delete [] yuvBuffer;
        yuvBuffer = 0;
        yuvBufferSize = 0;
        AccumulatedSize = 0;

        // Start data receiving thread
        ReceiveInitialized = false;
        KillReceiveThread = false;
        ReceiveThread = new osaThread;
        ReceiveInitEvent = new osaThreadSignal;
        ReceiveThread->Create<svlVideoCodecTCPStream, int>(this, &svlVideoCodecTCPStream::ReceiveProc, 0);
        ReceiveInitEvent->Wait();
        if (ReceiveInitialized == false) break;

        // Wait until header is received
        while (Width == 0 || Height == 0) osaSleep(0.1);

        Pos = BegPos = EndPos = 0;
        width = Width;
        height = Height;
        framerate = -1.0;

        return SVL_OK;
    }

    Close();
    return SVL_FAIL;
}
Esempio n. 4
0
static void processServerCommandString(char *string)
{
    char *fullname, filename[MAXPATHLEN], pathname[MAXPATHLEN];
    char *doCommand, *geometry, *langMode, *inPtr;
    int editFlags, stringLen = strlen(string);
    int lineNum, createFlag, readFlag, iconicFlag, lastIconic = 0, tabbed = -1;
    int fileLen, doLen, lmLen, geomLen, charsRead, itemsRead;
    WindowInfo *window, *lastFile = NULL;
    long currentDesktop = QueryCurrentDesktop(TheDisplay, 
       RootWindow(TheDisplay, DefaultScreen(TheDisplay)));

    /* If the command string is empty, put up an empty, Untitled window
       (or just pop one up if it already exists) */
    if (string[0] == '\0') {
    	for (window=WindowList; window!=NULL; window=window->next)
    	    if (!window->filenameSet && !window->fileChanged &&
                isLocatedOnDesktop(window, currentDesktop))
    	    	break;
    	if (window == NULL) {
            EditNewFile(findWindowOnDesktop(tabbed, currentDesktop), NULL, 
                        False, NULL, NULL);
    	    CheckCloseDim();
    	} 
	else {
	    RaiseDocument(window);
            WmClientMsg(TheDisplay, XtWindow(window->shell),
                    "_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0);
    	    XMapRaised(TheDisplay, XtWindow(window->shell));
    	}
	return;
    }

    /*
    ** Loop over all of the files in the command list
    */
    inPtr = string;
    while (TRUE) {
	
	if (*inPtr == '\0')
	    break;
	    
	/* Read a server command from the input string.  Header contains:
	   linenum createFlag fileLen doLen\n, followed by a filename and -do
	   command both followed by newlines.  This bit of code reads the
	   header, and converts the newlines following the filename and do
	   command to nulls to terminate the filename and doCommand strings */
	itemsRead = sscanf(inPtr, "%d %d %d %d %d %d %d %d %d%n", &lineNum,
		&readFlag, &createFlag, &iconicFlag, &tabbed, &fileLen,
		&doLen, &lmLen, &geomLen, &charsRead);
	if (itemsRead != 9)
    	    goto readError;
	inPtr += charsRead + 1;
	if (inPtr - string + fileLen > stringLen)
	    goto readError;
	fullname = inPtr;
	inPtr += fileLen;
	*inPtr++ = '\0';
	if (inPtr - string + doLen > stringLen)
	    goto readError;
	doCommand = inPtr;
	inPtr += doLen;
	*inPtr++ = '\0';
	if (inPtr - string + lmLen > stringLen)
	    goto readError;
	langMode = inPtr;
	inPtr += lmLen;
	*inPtr++ = '\0';
	if (inPtr - string + geomLen > stringLen)
	    goto readError;
	geometry = inPtr;
	inPtr += geomLen;
	*inPtr++ = '\0';
	
	/* An empty file name means: 
	 *   put up an empty, Untitled window, or use an existing one
	 *   choose a random window for executing the -do macro upon
	 */
	if (fileLen <= 0) {
    	    for (window=WindowList; window!=NULL; window=window->next)
    		if (!window->filenameSet && !window->fileChanged &&
                    isLocatedOnDesktop(window, currentDesktop))
    	    	    break;

    	    if (*doCommand == '\0') {
                if (window == NULL) {
    		    EditNewFile(findWindowOnDesktop(tabbed, currentDesktop), 
                                NULL, iconicFlag, lmLen==0?NULL:langMode, NULL);
    	        } else {
	            if (iconicFlag)
		    	RaiseDocument(window);
		    else
		    	RaiseDocumentWindow(window);
	        }
            } else {
                WindowInfo *win = WindowList;
		/* Starting a new command while another one is still running
		   in the same window is not possible (crashes). */
		while (win != NULL && win->macroCmdData != NULL) {
		    win = win->next;
		}
		
		if (!win) {
		    XBell(TheDisplay, 0);
		} else {
		    /* Raise before -do (macro could close window). */
	            if (iconicFlag)
		    	RaiseDocument(win);
		    else
		    	RaiseDocumentWindow(win);
		    DoMacro(win, doCommand, "-do macro");
		}
	    }
	    CheckCloseDim();
	    return;
	}
	
	/* Process the filename by looking for the files in an
	   existing window, or opening if they don't exist */
	editFlags = (readFlag ? PREF_READ_ONLY : 0) | CREATE |
		(createFlag ? SUPPRESS_CREATE_WARN : 0);
	if (ParseFilename(fullname, filename, pathname) != 0) {
	   fprintf(stderr, "NEdit: invalid file name\n");
           deleteFileClosedProperty2(filename, pathname);
	   break;
	}

    	window = FindWindowWithFile(filename, pathname);
    	if (window == NULL) {
	    /* Files are opened in background to improve opening speed
	       by defering certain time  consuiming task such as syntax
	       highlighting. At the end of the file-opening loop, the 
	       last file opened will be raised to restore those deferred
	       items. The current file may also be raised if there're
	       macros to execute on. */
	    window = EditExistingFile(findWindowOnDesktop(tabbed, currentDesktop),
		    filename, pathname, editFlags, geometry, iconicFlag, 
		    lmLen == 0 ? NULL : langMode, 
		    tabbed == -1? GetPrefOpenInTab() : tabbed, True);

    	    if (window) {
	    	CleanUpTabBarExposeQueue(window);
		if (lastFile && window->shell != lastFile->shell) {
		    CleanUpTabBarExposeQueue(lastFile);
		    RaiseDocument(lastFile);
		}
	    }
	    
	}
	
	/* Do the actions requested (note DoMacro is last, since the do
	   command can do anything, including closing the window!) */
	if (window != NULL) {
            deleteFileOpenProperty(window);
            getFileClosedProperty(window);

	    if (lineNum > 0)
		SelectNumberedLine(window, lineNum);

	    if (*doCommand != '\0') {
		RaiseDocument(window);

                if (!iconicFlag) {
                    WmClientMsg(TheDisplay, XtWindow(window->shell),
                            "_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0);
		    XMapRaised(TheDisplay, XtWindow(window->shell));
                }

		/* Starting a new command while another one is still running
		   in the same window is not possible (crashes). */
		if (window->macroCmdData != NULL) {
		    XBell(TheDisplay, 0);
		} else {
		    DoMacro(window, doCommand, "-do macro");
		    /* in case window is closed by macro functions
		       such as close() or detach_document() */
		    if (!IsValidWindow(window))
		    	window = NULL;
		    if (lastFile && !IsValidWindow(lastFile))
		    	lastFile = NULL;
		}
	    }
	    
	    /* register the last file opened for later use */
	    if (window) {
	    	lastFile = window;
		lastIconic = iconicFlag;
	    }
	} else {
            deleteFileOpenProperty2(filename, pathname);
            deleteFileClosedProperty2(filename, pathname);
        }
    }
    
    /* Raise the last file opened */
    if (lastFile) {
	CleanUpTabBarExposeQueue(lastFile);
	if (lastIconic)
	    RaiseDocument(lastFile);
	else
	    RaiseDocumentWindow(lastFile);
	CheckCloseDim();
    }
    return;

readError:
    fprintf(stderr, "NEdit: error processing server request\n");
    return;
}
Esempio n. 5
0
static void fileCB(Widget widget, WindowInfo *window, Atom *sel,
    	Atom *type, char *value, int *length, int *format)
{
    char nameText[MAXPATHLEN], includeName[MAXPATHLEN];
    char filename[MAXPATHLEN], pathname[MAXPATHLEN];
    char *inPtr, *outPtr;
#ifdef VMS
#ifndef __DECC
    static char includeDir[] = "sys$library:";
#else
    static char includeDir[] = "decc$library_include:";
#endif
#else
    static char includeDir[] = "/usr/include/";
#endif /* VMS */
    
    /* get the string, or skip if we can't get the selection data, or it's
       obviously not a file name */
    if (*type == XT_CONVERT_FAIL || value == NULL) {
    	XBell(TheDisplay, 0);
	return;
    }
    if (*length > MAXPATHLEN || *length == 0) {
    	XBell(TheDisplay, 0);
	XtFree(value);
	return;
    }
    /* should be of type text??? */
    if (*format != 8) {
    	fprintf(stderr, "NEdit: Can't handle non 8-bit text\n");
    	XBell(TheDisplay, 0);
	XtFree(value);
	return;
    }
    strncpy(nameText, value, *length);
    XtFree(value);
    nameText[*length] = '\0';
    
    /* extract name from #include syntax */
    if (sscanf(nameText, "#include \"%[^\"]\"", includeName) == 1)
    	strcpy(nameText, includeName);
    else if (sscanf(nameText, "#include <%[^<>]>", includeName) == 1)
    	sprintf(nameText, "%s%s", includeDir, includeName);
    
    /* strip whitespace from name */
    for (inPtr=nameText, outPtr=nameText; *inPtr!='\0'; inPtr++)
    	if (*inPtr != ' ' && *inPtr != '\t' && *inPtr != '\n')
    	    *outPtr++ = *inPtr;
    *outPtr = '\0';

#ifdef VMS
    /* If path name is relative, make it refer to current window's directory */
    if ((strchr(nameText, ':') == NULL) && (strlen(nameText) > 1) &&
      	    !((nameText[0] == '[') && (nameText[1] != '-') &&
	      (nameText[1] != '.'))) {
	strcpy(filename, window->path);
	strcat(filename, nameText);
	strcpy(nameText, filename);
    }
#else
    /* Process ~ characters in name */
    ExpandTilde(nameText);
        
    /* If path name is relative, make it refer to current window's directory */
    if (nameText[0] != '/') {
	strcpy(filename, window->path);
	strcat(filename, nameText);
	strcpy(nameText, filename);
    }
#endif
    
    /* Expand wildcards in file name.
       Some older systems don't have the glob subroutine for expanding file
       names, in these cases, either don't expand names, or try to use the
       Motif internal parsing routine _XmOSGetDirEntries, which is not
       guranteed to be available, but in practice is there and does work. */
#if defined(DONT_HAVE_GLOB) || defined(VMS)
    /* Open the file */
    if (ParseFilename(nameText, filename, pathname) != 0) {
        XBell(TheDisplay, 0);
	return;
    }	
    EditExistingFile(window, filename, 
            pathname, 0, NULL, False, NULL, GetPrefOpenInTab(), False);
#elif defined(USE_MOTIF_GLOB)
    { char **nameList = NULL;
      int i, nFiles = 0, maxFiles = 30;

      if (ParseFilename(nameText, filename, pathname) != 0) {
           XBell(TheDisplay, 0);
	   return;
      }
      _XmOSGetDirEntries(pathname, filename, XmFILE_ANY_TYPE, False, True,
	      &nameList, &nFiles, &maxFiles);
      for (i=0; i<nFiles; i++) {
	  if (ParseFilename(nameList[i], filename, pathname) != 0) {
	      XBell(TheDisplay, 0);
	  }
        else {
    	      EditExistingFile(window, filename, pathname, 0, 
	              NULL, False, NULL, GetPrefOpenInTab(), False);
	  }
      }
      for (i=0; i<nFiles; i++) {
	   XtFree(nameList[i]);
	}
      XtFree((char *)nameList);
    }
#else
    { glob_t globbuf;
      int i;

      glob(nameText, GLOB_NOCHECK, NULL, &globbuf);
      for (i=0; i<(int)globbuf.gl_pathc; i++) {
	  if (ParseFilename(globbuf.gl_pathv[i], filename, pathname) != 0)
	      XBell(TheDisplay, 0);
	  else
    	      EditExistingFile(GetPrefOpenInTab()? window : NULL, 
	              filename, pathname, 0, NULL, False, NULL, 
		      GetPrefOpenInTab(), False);
      }
      globfree(&globbuf);
    }
#endif
    CheckCloseDim();
}
Esempio n. 6
0
/*
** Action procedure for processing characters typed in a list, finds the
** first item matching the characters typed so far.
*/
static int nKeystrokes = 0; /* Global key stroke history counter */
static void listCharEH(Widget w, XtPointer callData, XEvent *event,
	Boolean *continueDispatch)
{
    char charString[5], c, *itemString;
    int nChars, nItems, i, cmp, selectPos, topPos, nVisible;
    XmString *items;
    KeySym kSym;
    char name[MAXPATHLEN], path[MAXPATHLEN];
    static char keystrokes[MAX_LIST_KEYSTROKES];
    static Time lastKeyTime = 0;
    
    /* Get the ascii character code represented by the event */
    nChars = XLookupString((XKeyEvent *)event, charString, sizeof(charString),
    	    &kSym, NULL);
    c = charString[0];
    
    /* Process selected control keys, but otherwise ignore the keystroke
       if it isn't a single printable ascii character */
    *continueDispatch = False;
    if (kSym==XK_BackSpace || kSym==XK_Delete) {
    	nKeystrokes = nKeystrokes > 0 ? nKeystrokes-1 : 0;
    	return;
    } else if (kSym==XK_Clear || kSym==XK_Cancel || kSym==XK_Break) {
    	nKeystrokes = 0;
    	return;
    } else if (nChars!=1 || c<0x021 || c>0x07e) {
    	*continueDispatch = True;
    	return;
    }
    
    /* Throw out keystrokes and start keystroke accumulation over from 
       scratch if user waits more than MAX_LIST_KESTROKE_WAIT milliseconds */
    if (((XKeyEvent *)event)->time - lastKeyTime > MAX_LIST_KESTROKE_WAIT)
    	nKeystrokes = 0;
    lastKeyTime = ((XKeyEvent *)event)->time;
    	
    /* Accumulate the current keystroke, just beep if there are too many */
    if (nKeystrokes >= MAX_LIST_KEYSTROKES)
    	XBell(XtDisplay(w), 0);
    else
#ifdef VMS
    	keystrokes[nKeystrokes++] = toupper(c);
#else
    	keystrokes[nKeystrokes++] = c;
#endif
    
    /* Get the items (filenames) in the list widget */
    XtVaGetValues(w, XmNitems, &items, XmNitemCount, &nItems, NULL);
    
    /* compare them with the accumulated user keystrokes & decide the
       appropriate line in the list widget to select */
    selectPos = 0;
    for (i=0; i<nItems; i++) {
    	XmStringGetLtoR(items[i], XmSTRING_DEFAULT_CHARSET, &itemString);
    	if (ParseFilename(itemString, name, path) != 0) {
	   XtFree(itemString);
	   return;
	}
	XtFree(itemString);
    	cmp = strncmp(name, keystrokes, nKeystrokes);
    	if (cmp == 0) {
    	    selectPos = i+1;
    	    break;
    	} else if (cmp > 0) {
    	    selectPos = i;
    	    break;
    	}
    }

    /* Make the selection, and make sure it will be visible */
    XmListSelectPos(w, selectPos, True);
    if (selectPos == 0) /* XmListSelectPos curiously returns 0 for last item */
    	selectPos = nItems + 1;
    XtVaGetValues(w, XmNtopItemPosition, &topPos,
    	    XmNvisibleItemCount, &nVisible, NULL);
    if (selectPos < topPos)
    	XmListSetPos(w, selectPos-2 > 1 ? selectPos-2 : 1);
    else if (selectPos > topPos+nVisible-1)
    	XmListSetBottomPos(w, selectPos+2 <= nItems ? selectPos+2 : 0);
    /* For LessTif 0.89.9. Obsolete now? */
    XmListSelectPos(w, selectPos, True);
}
Esempio n. 7
0
int svlVideoCodecTCPStream::Create(const std::string &filename, const unsigned int width, const unsigned int height, const double CMN_UNUSED(framerate))
{
	if (Opened || ParseFilename(filename) != SVL_OK ||
        width < 1 || width > MAX_DIMENSION || height < 1 || height > MAX_DIMENSION) return SVL_FAIL;

    if (!Codec) {
        // Get default codec parameters
        Codec = GetCompression();
    }

    std::string extension(Codec->extension);
         if (extension == ".ncvi") Compressor = CVI;
    else if (extension == ".njpg") Compressor = JPEG;
    else return SVL_FAIL;

    unsigned int size;

    while (1) {

        Opened = true;
	    Writing = true;

        // Allocate YUV buffer if not done yet
        size = width * height * 2;
        if (!yuvBuffer) {
            yuvBuffer = new unsigned char[size];
            yuvBufferSize = size;
        }
        else if (yuvBuffer && yuvBufferSize < size) {
            delete [] yuvBuffer;
            yuvBuffer = new unsigned char[size];
            yuvBufferSize = size;
        }

        // Allocate compression buffer if not done yet
        size = width * height * 3;
        size += size / 100 + 4096;
        if (!comprBuffer) {
            comprBuffer = new unsigned char[size];
            comprBufferSize = size;
        }
        else if (comprBuffer && comprBufferSize < size) {
            if (comprBufferSize) delete [] comprBuffer;
            comprBuffer = new unsigned char[size];
            comprBufferSize = size;
        }

        // Allocate streaming buffers if not done yet
        for (unsigned int i = 0; i < MAX_CLIENTS; i ++) {
            if (!SendBuffer[i]) {
                SendBuffer[i] = new svlBufferMemory(size);
            }
            else if (SendBuffer[i] && SendBuffer[i]->GetMaxSize() < size) {
                delete SendBuffer[i];
                SendBuffer[i] = new svlBufferMemory(size);
            }
        }

        // Start data saving thread
        ServerInitialized = false;
        KillServerThread = false;
        ServerThread = new osaThread;
        ServerInitEvent = new osaThreadSignal;
        ServerThread->Create<svlVideoCodecTCPStream, unsigned short>(this, &svlVideoCodecTCPStream::ServerProc, SocketPort);
        ServerInitEvent->Wait();
        if (ServerInitialized == false) break;

        BegPos = EndPos = Pos = 0;
        Width = width;
        Height = height;

        return SVL_OK;
    }

	Close();
	return SVL_FAIL;
}