Example #1
0
static void   getVarIndexDialog(int *loc, int nDim, int *maxVal)
{
    int i, valt, ok;
    char *endPtr, *t1;
	
    if (nDim == 1) {
        ok = -1;
        while (ok == -1) { 
        DialogF(DF_PROMPT,OneDHistShellW, 0,
           "The variable you wish to histogram is a Vector\n\
  Please fill in the requested index", BrowseUtil2htitle);
        mcfioC_RemoveWhiteSpace(BrowseUtil2htitle);
        valt = strtol(BrowseUtil2htitle, &endPtr, 10);
	if ((strlen(BrowseUtil2htitle) == 0) || (*endPtr != '\0'))
	   DialogF(DF_ERR,OneDHistShellW, 1,
	    "Please Try again, we need an integer number! ","Acknowledged");
	else {
	  if ((valt < 1) || (valt > maxVal[0]))  
	   DialogF(DF_ERR,OneDHistShellW, 1,
          "Wrong Index Value\nWe need a number between 1 and %d",
          "Acknowledged",maxVal[0]);
          else {
              ok = valt;
              loc[0] = valt;
          }
       }
     }
   } else {
Example #2
0
static void okAction(Widget widget, xfselControlBlkType *ctrlBlk,
                 XmPushButtonCallbackStruct *call_data)
{
    char    *fontPattern;
    char    **fontName;
    int i;

    fontPattern = XmTextGetString(ctrlBlk->fontNameField);
    fontName    = XListFonts(XtDisplay(ctrlBlk->form), fontPattern, 1, &i);
    XtFree(fontPattern);
    
    if (i != 1)
    {
        DialogF (DF_ERR, ctrlBlk->okButton, 1, "Font Specification",
                "Invalid Font Specification", "OK");
        XFreeFontNames(fontName);
    }
    else
    {
        XtFree(ctrlBlk->fontName);
        ctrlBlk->fontName = XtMalloc(strlen(fontName[0]) + 1);
        strcpy(ctrlBlk->fontName, fontName[0]);

        XtFree(ctrlBlk->sel1);
        XtFree(ctrlBlk->sel2);
        XtFree(ctrlBlk->sel3);
    
        XFreeFontNames(fontName);
        XFreeFontNames(ctrlBlk->fontData);

        ctrlBlk->exitFlag = TRUE;
    }
}
Example #3
0
static void choiceMade(xfselControlBlkType *ctrlBlk)
{
    int i;

    XtFree(ctrlBlk->fontName);
    ctrlBlk->fontName = NULL;

    for (i = 0; i < ctrlBlk->numFonts; i++)
    {
        if ((fontMatch(ctrlBlk, ctrlBlk->fontData[i])) &&
            (styleMatch(ctrlBlk, ctrlBlk->fontData[i])) &&
            (sizeMatch (ctrlBlk, ctrlBlk->fontData[i])))
        {
            ctrlBlk->fontName = XtMalloc(
                          strlen(ctrlBlk->fontData[i]) + 1);
            strcpy(ctrlBlk->fontName, ctrlBlk->fontData[i]);
            break;
        }
    }

    if (ctrlBlk->fontName != NULL)
    {
        XmTextSetString(ctrlBlk->fontNameField, ctrlBlk->fontName);
        dispSample(ctrlBlk);
    }
    else
    {
        DialogF (DF_ERR, ctrlBlk->form, 1, "Font Specification",
                "Invalid Font Specification", "OK");
    }
}
Example #4
0
/*
** Search the help text.  If allSections is true, searches all of the help
** text, otherwise searches only in parentTopic.
*/
static void searchHelpText(Widget parent, int parentTopic,
        const char *searchFor, int allSections, int startPos, int startTopic)
{    
    int topic, beginMatch, endMatch;
    int found = False;
    char * helpText  = NULL;
    
    /* Search for the string */
    for (topic=startTopic; topic<NUM_TOPICS; topic++)
    {
        if (!allSections && topic != parentTopic)
            continue;
        helpText = stitch(parent, HelpText[topic], NULL);

        if (SearchString(helpText, searchFor, SEARCH_FORWARD, SEARCH_LITERAL,
                False, topic == startTopic ? startPos : 0, &beginMatch,
                &endMatch, NULL, NULL, GetPrefDelimiters()))
        {
            found = True;
            XtFree(helpText);
            break;
        }
        XtFree(helpText);
    }

    if (!found)
    {
        if (startPos != 0 || (allSections && startTopic != 0))
        {
            /* Wrap search */
            searchHelpText(parent, parentTopic, searchFor, allSections, 0, 0);
            return;
        }
        DialogF(DF_INF, parent, 1, "String Not Found", "String Not Found", "OK");
        return;
    }
    
    /* update navigation history */  
    if (parentTopic != topic)
    {
        navHistForw[parentTopic]= topic;
        navHistBack[topic]= parentTopic;
    }
    
    /* If the appropriate window is already up, bring it to the top, if not,
       make the parent window become this topic */
    changeTopicOrRaise(parentTopic, topic);
    BufSelect(TextGetBuffer(HelpTextPanes[topic]), beginMatch, endMatch);
    TextSetCursorPos(HelpTextPanes[topic], endMatch);
    
    /* Save the search information for search-again */
    strcpy(LastSearchString, searchFor);
    LastSearchTopic = topic;
    LastSearchPos = endMatch;
    LastSearchWasAllTopics = allSections;
}
Example #5
0
int GetIntTextWarn(Widget text, int *value, char *fieldName, int warnBlank)
{
    int result;
    char *valueStr;
    
    result = GetIntText(text, value);
    if (result == TEXT_READ_OK || (result == TEXT_IS_BLANK && !warnBlank))
    	return result;
    valueStr = XmTextGetString(text);
    if (result == TEXT_IS_BLANK)
    	DialogF (DF_ERR, text, 1, "Please supply a value for %s",
    		 "Acknowledged", fieldName);
    else /* TEXT_NOT_NUMBER */
    	DialogF (DF_ERR, text, 1,
    		 "Can't read integer value \"%s\" in %s",
    		 "Acknowledged", valueStr, fieldName);
    XtFree(valueStr);
    return result;
}
Example #6
0
int GetFloatTextWarn(Widget text, double *value, char *fieldName, int warnBlank)
{
    int result;
    char *valueStr;
    
    result = GetFloatText(text, value);
    if (result == TEXT_READ_OK || (result == TEXT_IS_BLANK && !warnBlank))
    	return result;
    valueStr = XmTextGetString(text);
    if (result == TEXT_IS_BLANK)
    	DialogF (DF_ERR, text, 1, "Please supply %s value",
    		 "Acknowledged", fieldName);
    else /* TEXT_NOT_NUMBER */
    	DialogF (DF_ERR, text, 1,
    		 "Can't read %s value: \"%s\"",
    		 "Acknowledged", fieldName, valueStr);
    XtFree(valueStr);
    return result;
}
Example #7
0
static void oneDHistListCB(Widget w, nTuBrowserInfo *nTuBrDummy,
                               caddr_t call_data)
{
    int i, idPos, *posList, count, id, l, jn, uid, ivar;
    float aa, bb;                               
    nTuBrowserInfo *nTuBr;
    nTuBroHs1D *nTuH1;

    XmListGetSelectedPos(OneDHistHistoListW, &posList, &count);
    if (count < 1) return;
    id = OneDHistListedIDs[((*posList) -1)];
    uid = hs_uid(id);
    /*
    ** Select the variable associated with this histogram.
    */
    nTuBr = oneDHistNTupleSource(id);
    if (nTuBr != CurrentNTupleBrowserSelected ) 
                    if (!mcfioC_SetSpecificNTupleBr(nTuBr)) return;
    for(i=0; i<CurrentNTupleBrowserSelected->sizeOfLists; i++) {
       nTuH1 = (nTuBroHs1D *) CurrentNTupleBrowserSelected->hsItemList[i];
       if (nTuH1 == NULL) continue;
       if (nTuH1->id == id) break;
    } 
    if (nTuH1 == NULL) {
         DialogF(DF_ERR, OneDHistShellW, 1,
                 "Internal Error in oneDHistListCB\nPlease report",
		"Acknowledged");
         return;
    }     
    ivar =  nTuH1->varNumber;
    XmListSelectPos(OneDHistVariableListW, (ivar+1), False);
    l = hs_title(id, BrowseUtil2htitle);
    XmTextSetString(OneDHistTitleW, BrowseUtil2htitle);
    l = hs_1d_hist_num_bins(id);
    SetIntText(OneDHistNumBinsW, l);
    hs_1d_hist_range(id, &aa, &bb);
    SetFloatText(OneDHistLowBinW, aa);
    SetFloatText(OneDHistHighBinW, bb);
    /*
    ** We now have to related this histogram to the associated Ntuple 
    */
    for (i=0; i<nTuBr->sizeOfLists; i++) {
       if (nTuBr->hsItemList[i] == NULL) continue;
           if (nTuBr->hsItemList[i]->id == id) {
               nTuH1 = (nTuBroHs1D *) nTuBr->hsItemList[i];
               if (nTuH1->subBlock == -1)  
                   XmTextSetString(OneDHistMultW, "All");
                else 
                   SetIntText(OneDHistMultW, nTuH1->subBlock);
            }
            break;
    }
    XtSetSensitive(OneDHistModifyW, True);
    XtSetSensitive(OneDHistDeleteW, True);
}
Example #8
0
static void modifyOneDHistCB(Widget w, nTuBrowserInfo * nTuBr,
                               caddr_t call_data)
{
    int *posList, count;
    if (!XmListGetSelectedPos(OneDHistHistoListW, &posList, &count)) {
	DialogF(DF_WARN, OneDHistShellW, 1, 
	"Please select a Histogram", "Acknowledged");
	return;
    }
     deleteOneDHistCB(w, NULL, NULL);
     createOneDHistActual(False);
}
Example #9
0
static void previousEvtCB(Widget w, SpaceWindow *window, caddr_t call_data)
{
    int ievt = window->event.eventNum;
    ievt--;
    if (ievt <= 0)  {
        DialogF(DF_INF, w, 1,
         "You went back to the beginning this file",
                        "OK");
        return;
     }
    GetSetStdHep((StdHepWindow *) window, ievt);
} 
Example #10
0
static void nextEvtCB(Widget w, SpaceWindow *window, caddr_t call_data)
{
    int ievt = window->event.eventNum;
    ievt++;
    if (ievt > window->nEvents) {
        DialogF(DF_INF, w, 1,
         "You reached the end of this file",
                        "OK");
        return;
     }
    GetSetStdHep((StdHepWindow *) window, ievt);
}
Example #11
0
/*
** Execute the line of text where the the insertion cursor is positioned
** as a shell command.
*/
void ExecCursorLine(WindowInfo *window, int fromMacro)
{
    char *cmdText;
    int left, right, insertPos;
    char *subsCommand, fullName[MAXPATHLEN];
    int pos, line, column;
    char lineNumber[11];

    /* Can't do two shell commands at once in the same window */
    if (window->shellCmdData != NULL) {
    	XBell(TheDisplay, 0);
    	return;
    }

    /* get all of the text on the line with the insert position */
    pos = TextGetCursorPos(window->lastFocus);
    if (!GetSimpleSelection(window->buffer, &left, &right)) {
	left = right = pos;
	left = BufStartOfLine(window->buffer, left);
	right = BufEndOfLine(window->buffer, right);
	insertPos = right;
    } else
    	insertPos = BufEndOfLine(window->buffer, right);
    cmdText = BufGetRange(window->buffer, left, right);
    BufUnsubstituteNullChars(cmdText, window->buffer);
    
    /* insert a newline after the entire line */
    BufInsert(window->buffer, insertPos, "\n");

    /* Substitute the current file name for % and the current line number
       for # in the shell command */
    strcpy(fullName, window->path);
    strcat(fullName, window->filename);
    TextPosToLineAndCol(window->lastFocus, pos, &line, &column);
    sprintf(lineNumber, "%d", line);
    
    subsCommand = shellCommandSubstitutes(cmdText, fullName, lineNumber);
    if (subsCommand == NULL)
    {
        DialogF(DF_ERR, window->shell, 1, "Shell Command",
                "Shell command is too long due to\n"
                "filename substitutions with '%%' or\n"
                "line number substitutions with '#'", "OK");
        return;
    }

    /* issue the command */
    issueCommand(window, subsCommand, NULL, 0, 0, window->lastFocus, insertPos+1,
	    insertPos+1, fromMacro);
    free(subsCommand);
    XtFree(cmdText);
}
Example #12
0
static void deleteOneDHistCB(Widget w, nTuBrowserInfo *nTuBrDummy,
                               caddr_t call_data)
{
    int i, idPos, *posList, count, id, uid, jn;
    nTuBrowserInfo *nTuBr;
    nTuBroHs1D *nTuH1;
     
                                  
    if (!XmListGetSelectedPos(OneDHistHistoListW, &posList, &count)) {
	DialogF(DF_WARN, OneDHistShellW, 1, "Please select a Histogram",
		"Acknowledged");
	return;
    }
    id = OneDHistListedIDs[((*posList) -1)];
    CurrentHistoUID = hs_uid(id);
    nTuBr = oneDHistNTupleSource(id);
    if (nTuBr == NULL) {
         DialogF(DF_ERR, OneDHistShellW, 1,
                 "Internal Error in deleteOneDHist\nPlease report",
		"Acknowledged");
         return;
     }
    hs_delete(id);
    hs_update();
    for (i=0; i<nTuBr->sizeOfLists; i++) { 
       if (nTuBr->hsItemList[i] == NULL) continue;
        if (id == nTuBr->hsItemList[i]->id ) {
             nTuH1 = (nTuBroHs1D *) nTuBr->hsItemList[i];
             if (nTuH1->varIndices != NULL) free(nTuH1->varIndices);
             free(nTuH1);
             nTuBr->hsItemList[i] = NULL;       
             break;
         }
    }
    nTuBr->nHistoItems--;
    nTuBr->nHisto1D--;
    redisplay1DHistoList();
}
Example #13
0
void GotoLineNumber(WindowInfo *window)
{
    char lineNumText[DF_MAX_PROMPT_LENGTH], *params[1];
    int lineNum, column, response;
    
    response = DialogF(DF_PROMPT, window->shell, 2, "Goto Line Number",
            "Goto Line (and/or Column)  Number:", lineNumText, "OK", "Cancel");
    if (response == 2)
    	return;

    if (StringToLineAndCol(lineNumText, &lineNum, &column) == -1) {
    	XBell(TheDisplay, 0);
	return;
    }
    params[0] = lineNumText;
    XtCallActionProc(window->lastFocus, "goto_line_number", NULL, params, 1);
}
Example #14
0
static void searchHelpCB(Widget w, XtPointer clientData, XtPointer callData)
{
    char promptText[DF_MAX_PROMPT_LENGTH];
    int response, topic;
    static char **searchHistory = NULL;
    static int nHistoryStrings = 0;
    
    if ((topic = findTopicFromShellWidget((Widget)clientData)) == -1)
        return; /* shouldn't happen */
    SetDialogFPromptHistory(searchHistory, nHistoryStrings);
    response = DialogF(DF_PROMPT, HelpWindows[topic], 3, "Find",
            "Search for:    (use up arrow key to recall previous)", promptText,
            "This Section", "All Sections", "Cancel");
    if (response == 3)
        return;
    AddToHistoryList(promptText, &searchHistory, &nHistoryStrings);
    searchHelpText(HelpWindows[topic], topic, promptText, response == 2, 0, 0);
}
Example #15
0
/*
** Execute shell command "command", depositing the result at the current
** insert position or in the current selection if the window has a
** selection.
*/
void ExecShellCommand(WindowInfo *window, const char *command, int fromMacro)
{
    int left, right, flags = 0;
    char *subsCommand, fullName[MAXPATHLEN];
    int pos, line, column;
    char lineNumber[11];

    /* Can't do two shell commands at once in the same window */
    if (window->shellCmdData != NULL) {
    	XBell(TheDisplay, 0);
    	return;
    }
    
    /* get the selection or the insert position */
    pos = TextGetCursorPos(window->lastFocus);
    if (GetSimpleSelection(window->buffer, &left, &right))
    	flags = ACCUMULATE | REPLACE_SELECTION;
    else
    	left = right = pos;
    
    /* Substitute the current file name for % and the current line number
       for # in the shell command */
    strcpy(fullName, window->path);
    strcat(fullName, window->filename);
    TextPosToLineAndCol(window->lastFocus, pos, &line, &column);
    sprintf(lineNumber, "%d", line);
    
    subsCommand = shellCommandSubstitutes(command, fullName, lineNumber);
    if (subsCommand == NULL)
    {
        DialogF(DF_ERR, window->shell, 1, "Shell Command",
                "Shell command is too long due to\n"
                "filename substitutions with '%%' or\n"
                "line number substitutions with '#'", "OK");
        return;
    }

    /* issue the command */
    issueCommand(window, subsCommand, NULL, 0, flags, window->lastFocus, left,
	    right, fromMacro);
    free(subsCommand);
}
Example #16
0
void MarkDialog(WindowInfo *window)
{
    char letterText[DF_MAX_PROMPT_LENGTH], *params[1];
    int response;
    
    response = DialogF(DF_PROMPT, window->shell, 2, "Mark",
            "Enter a single letter label to use for recalling\n"
            "the current selection and cursor position.\n\n"
            "(To skip this dialog, use the accelerator key,\n"
            "followed immediately by a letter key (a-z))", letterText, "OK",
            "Cancel");
    if (response == 2)
    	return;
    if (strlen(letterText) != 1 || !isalpha((unsigned char)letterText[0])) {
    	XBell(TheDisplay, 0);
	return;
    }
    params[0] = letterText;
    XtCallActionProc(window->lastFocus, "mark", NULL, params, 1);
}
Example #17
0
void GotoMarkDialog(WindowInfo *window, int extend)
{
    char letterText[DF_MAX_PROMPT_LENGTH], *params[2];
    int response;
    
    response = DialogF(DF_PROMPT, window->shell, 2, "Goto Mark",
            "Enter the single letter label used to mark\n"
            "the selection and/or cursor position.\n\n"
            "(To skip this dialog, use the accelerator\n"
            "key, followed immediately by the letter)", letterText, "OK",
            "Cancel");
    if (response == 2)
    	return;
    if (strlen(letterText) != 1 || !isalpha((unsigned char)letterText[0])) {
    	XBell(TheDisplay, 0);
	return;
    }
    params[0] = letterText;
    params[1] = "extend";
    XtCallActionProc(window->lastFocus, "goto_mark", NULL, params,
	    extend ? 2 : 1);
}
Example #18
0
/*
** Fork a subprocess to execute a command, return file descriptors for pipes
** connected to the subprocess' stdin, stdout, and stderr streams.  cmdDir
** sets the default directory for the subprocess.  If stderrFD is passed as
** NULL, the pipe represented by stdoutFD is connected to both stdin and
** stderr.  The function value returns the pid of the new subprocess, or -1
** if an error occured.
*/
static pid_t forkCommand(Widget parent, const char *command, const char *cmdDir,
	int *stdinFD, int *stdoutFD, int *stderrFD)
{
    int childStdoutFD, childStdinFD, childStderrFD, pipeFDs[2];
    int dupFD;
    pid_t childPid;
    
    /* Ignore SIGPIPE signals generated when user attempts to provide
       input for commands which don't take input */
    signal(SIGPIPE, SIG_IGN);
    
    /* Create pipes to communicate with the sub process.  One end of each is
       returned to the caller, the other half is spliced to stdin, stdout
       and stderr in the child process */
    if (pipe(pipeFDs) != 0) {
    	perror("NEdit: Internal error (opening stdout pipe)");
        return -1;
    }
    *stdoutFD = pipeFDs[0];
    childStdoutFD = pipeFDs[1];
    if (pipe(pipeFDs) != 0) {
    	perror("NEdit: Internal error (opening stdin pipe)");
        return -1;
    }
    *stdinFD = pipeFDs[1];
    childStdinFD = pipeFDs[0];
    if (stderrFD == NULL)
    	childStderrFD = childStdoutFD;
    else {
	if (pipe(pipeFDs) != 0) {
    	    perror("NEdit: Internal error (opening stdin pipe)");
            return -1;
        }
	*stderrFD = pipeFDs[0];
	childStderrFD = pipeFDs[1];
    }
    
    /* Fork the process */
    childPid = fork();
    
    /*
    ** Child process context (fork returned 0), clean up the
    ** child ends of the pipes and execute the command
    */
    if (0 == childPid) {

	/* close the parent end of the pipes in the child process   */
	close(*stdinFD);
	close(*stdoutFD);
	if (stderrFD != NULL)
	    close(*stderrFD);

	/* close current stdin, stdout, and stderr file descriptors before
	   substituting pipes */
	close(fileno(stdin));
	close(fileno(stdout));
	close(fileno(stderr));

	/* duplicate the child ends of the pipes to have the same numbers
	   as stdout & stderr, so it can substitute for stdout & stderr */
 	dupFD = dup2(childStdinFD, fileno(stdin));
	if (dupFD == -1)
	    perror("dup of stdin failed");
 	dupFD = dup2(childStdoutFD, fileno(stdout));
	if (dupFD == -1)
	    perror("dup of stdout failed");
 	dupFD = dup2(childStderrFD, fileno(stderr));
	if (dupFD == -1)
	    perror("dup of stderr failed");

        /* now close the original child end of the pipes
           (we now have the 0, 1 and 2 descriptors in their place) */
        close(childStdinFD);
        close(childStdoutFD);
        close(childStderrFD);
	
	/* make this process the leader of a new process group, so the sub
	   processes can be killed, if necessary, with a killpg call */
#ifndef __EMX__  /* OS/2 doesn't have this */
	setsid();
#endif
      
       /* change the current working directory to the directory of the current
	  file. */ 
       if(cmdDir[0] != 0)
	   if(chdir(cmdDir) == -1)
	       perror("chdir to directory of current file failed");
     
	/* execute the command using the shell specified by preferences */
	execl(GetPrefShell(), GetPrefShell(), "-c", command, (char *)0);

	/* if we reach here, execl failed */
	fprintf(stderr, "Error starting shell: %s\n", GetPrefShell());
	exit(EXIT_FAILURE);
    }
    
    /* Parent process context, check if fork succeeded */
    if (childPid == -1)
    {
        DialogF(DF_ERR, parent, 1, "Shell Command",
                "Error starting shell command process\n(fork failed)",
                "OK");
    }

    /* close the child ends of the pipes */
    close(childStdinFD);
    close(childStdoutFD);
    if (stderrFD != NULL)
    	close(childStderrFD);

    return childPid;
}    
Example #19
0
/*
** Clean up after the execution of a shell command sub-process and present
** the output/errors to the user as requested in the initial issueCommand
** call.  If "terminatedOnError" is true, don't bother trying to read the
** output, just close the i/o descriptors, free the memory, and restore the
** user interface state.
*/
static void finishCmdExecution(WindowInfo *window, int terminatedOnError)
{
    shellCmdInfo *cmdData = window->shellCmdData;
    textBuffer *buf;
    int status, failure, errorReport, reselectStart, outTextLen, errTextLen;
    int resp, cancel = False, fromMacro = cmdData->fromMacro;
    char *outText, *errText = NULL;

    /* Cancel any pending i/o on the file descriptors */
    if (cmdData->stdoutInputID != 0)
    	XtRemoveInput(cmdData->stdoutInputID);
    if (cmdData->stdinInputID != 0)
    	XtRemoveInput(cmdData->stdinInputID);
    if (cmdData->stderrInputID != 0)
    	XtRemoveInput(cmdData->stderrInputID);

    /* Close any file descriptors remaining open */
    close(cmdData->stdoutFD);
    if (cmdData->flags & ERROR_DIALOGS)
    	close(cmdData->stderrFD);
    if (cmdData->inPtr != NULL)
    	close(cmdData->stdinFD);

    /* Free the provided input text */
    if (cmdData->input != NULL)
	XtFree(cmdData->input);
    
    /* Cancel pending timeouts */
    if (cmdData->flushTimeoutID != 0)
    	XtRemoveTimeOut(cmdData->flushTimeoutID);
    if (cmdData->bannerTimeoutID != 0)
    	XtRemoveTimeOut(cmdData->bannerTimeoutID);
    
    /* Clean up waiting-for-shell-command-to-complete mode */
    if (!cmdData->fromMacro) {
	EndWait(window->shell);
	SetSensitive(window, window->cancelShellItem, False);
	if (cmdData->bannerIsUp)
    	    ClearModeMessage(window);
    }
    
    /* If the process was killed or became inaccessable, give up */
    if (terminatedOnError) {
	freeBufList(&cmdData->outBufs);
	freeBufList(&cmdData->errBufs);
    	waitpid(cmdData->childPid, &status, 0);
	goto cmdDone;
    }

    /* Assemble the output from the process' stderr and stdout streams into
       null terminated strings, and free the buffer lists used to collect it */
    outText = coalesceOutput(&cmdData->outBufs, &outTextLen);
    if (cmdData->flags & ERROR_DIALOGS)
    	errText = coalesceOutput(&cmdData->errBufs, &errTextLen);

    /* Wait for the child process to complete and get its return status */
    waitpid(cmdData->childPid, &status, 0);
    
    /* Present error and stderr-information dialogs.  If a command returned
       error output, or if the process' exit status indicated failure,
       present the information to the user. */
    if (cmdData->flags & ERROR_DIALOGS)
    {
        failure = WIFEXITED(status) && WEXITSTATUS(status) != 0;
        errorReport = *errText != '\0';

        if (failure && errorReport)
        {
            removeTrailingNewlines(errText);
            truncateString(errText, DF_MAX_MSG_LENGTH);
            resp = DialogF(DF_WARN, window->shell, 2, "Warning", "%s", "Cancel",
                    "Proceed", errText);
            cancel = resp == 1;
        } else if (failure)
        {
            truncateString(outText, DF_MAX_MSG_LENGTH-70);
            resp = DialogF(DF_WARN, window->shell, 2, "Command Failure",
                    "Command reported failed exit status.\n"
                    "Output from command:\n%s", "Cancel", "Proceed", outText);
            cancel = resp == 1;
        } else if (errorReport)
        {
            removeTrailingNewlines(errText);
            truncateString(errText, DF_MAX_MSG_LENGTH);
            resp = DialogF(DF_INF, window->shell, 2, "Information", "%s",
                    "Proceed", "Cancel", errText);
            cancel = resp == 2;
        }

        XtFree(errText);
        if (cancel)
        {
            XtFree(outText);
            goto cmdDone;
        }
    }
    
    /* If output is to a dialog, present the dialog.  Otherwise insert the
       (remaining) output in the text widget as requested, and move the
       insert point to the end */
    if (cmdData->flags & OUTPUT_TO_DIALOG) {
    	removeTrailingNewlines(outText);
	if (*outText != '\0')
    	    createOutputDialog(window->shell, outText);
    } else if (cmdData->flags & OUTPUT_TO_STRING) {
    	ReturnShellCommandOutput(window,outText, WEXITSTATUS(status));
    } else {
	buf = TextGetBuffer(cmdData->textW);
	if (!BufSubstituteNullChars(outText, outTextLen, buf)) {
	    fprintf(stderr,"NEdit: Too much binary data in shell cmd output\n");
	    outText[0] = '\0';
	}
	if (cmdData->flags & REPLACE_SELECTION) {
	    reselectStart = buf->primary.rectangular ? -1 : buf->primary.start;
	    BufReplaceSelected(buf, outText);
	    TextSetCursorPos(cmdData->textW, buf->cursorPosHint);
	    if (reselectStart != -1)
	    	BufSelect(buf, reselectStart, reselectStart + strlen(outText));
	} else {
	    safeBufReplace(buf, &cmdData->leftPos, &cmdData->rightPos, outText);
	    TextSetCursorPos(cmdData->textW, cmdData->leftPos+strlen(outText));
	}
    }

    /* If the command requires the file to be reloaded afterward, reload it */
    if (cmdData->flags & RELOAD_FILE_AFTER)
    	RevertToSaved(window);

    /* Command is complete, free data structure and continue macro execution */
    XtFree(outText);
cmdDone:
    XtFree((char *)cmdData);
    window->shellCmdData = NULL;
    if (fromMacro)
    	ResumeMacroExecution(window);
}
Example #20
0
/*
** Do a shell command, with the options allowed to users (input source,
** output destination, save first and load after) in the shell commands
** menu.
*/
void DoShellMenuCmd(WindowInfo *window, const char *command,
        int input, int output,
	int outputReplacesInput, int saveFirst, int loadAfter, int fromMacro) 
{
    int flags = 0;
    char *text;
    char *subsCommand, fullName[MAXPATHLEN];
    int left, right, textLen;
    int pos, line, column;
    char lineNumber[11];
    WindowInfo *inWindow = window;
    Widget outWidget;

    /* Can't do two shell commands at once in the same window */
    if (window->shellCmdData != NULL) {
    	XBell(TheDisplay, 0);
    	return;
    }

    /* Substitute the current file name for % and the current line number
       for # in the shell command */
    strcpy(fullName, window->path);
    strcat(fullName, window->filename);
    pos = TextGetCursorPos(window->lastFocus);
    TextPosToLineAndCol(window->lastFocus, pos, &line, &column);
    sprintf(lineNumber, "%d", line);
    
    subsCommand = shellCommandSubstitutes(command, fullName, lineNumber);
    if (subsCommand == NULL)
    {
        DialogF(DF_ERR, window->shell, 1, "Shell Command",
                "Shell command is too long due to\n"
                "filename substitutions with '%%' or\n"
                "line number substitutions with '#'", "OK");
        return;
    }

    /* Get the command input as a text string.  If there is input, errors
      shouldn't be mixed in with output, so set flags to ERROR_DIALOGS */
    if (input == FROM_SELECTION) {
	text = BufGetSelectionText(window->buffer);
	if (*text == '\0') {
    	    XtFree(text);
            free(subsCommand);
    	    XBell(TheDisplay, 0);
    	    return;
    	}
    	flags |= ACCUMULATE | ERROR_DIALOGS;
    } else if (input == FROM_WINDOW) {
	text = BufGetAll(window->buffer);
    	flags |= ACCUMULATE | ERROR_DIALOGS;
    } else if (input == FROM_EITHER) {
	text = BufGetSelectionText(window->buffer);
	if (*text == '\0') {
	    XtFree(text);
	    text = BufGetAll(window->buffer);
    	}
    	flags |= ACCUMULATE | ERROR_DIALOGS;
    } else /* FROM_NONE */
    	text = NULL;
    
    /* If the buffer was substituting another character for ascii-nuls,
       put the nuls back in before exporting the text */
    if (text != NULL) {
	textLen = strlen(text);
	BufUnsubstituteNullChars(text, window->buffer);
    } else
	textLen = 0;
    
    /* Assign the output destination.  If output is to a new window,
       create it, and run the command from it instead of the current
       one, to free the current one from waiting for lengthy execution */
    if (output == TO_DIALOG) {
    	outWidget = NULL;
	flags |= OUTPUT_TO_DIALOG;
    	left = right = 0;
    } else if (output == TO_NEW_WINDOW) {
    	EditNewFile(GetPrefOpenInTab()?inWindow:NULL, NULL, False, NULL, window->path);
    	outWidget = WindowList->textArea;
	inWindow = WindowList;
    	left = right = 0;
	CheckCloseDim();
    } else { /* TO_SAME_WINDOW */
    	outWidget = window->lastFocus;
    	if (outputReplacesInput && input != FROM_NONE) {
    	    if (input == FROM_WINDOW) {
    		left = 0;
    		right = window->buffer->length;
    	    } else if (input == FROM_SELECTION) {
    	    	GetSimpleSelection(window->buffer, &left, &right);
	        flags |= ACCUMULATE | REPLACE_SELECTION;
    	    } else if (input == FROM_EITHER) {
    	    	if (GetSimpleSelection(window->buffer, &left, &right))
	            flags |= ACCUMULATE | REPLACE_SELECTION;
	        else {
	            left = 0;
	            right = window->buffer->length;
	        }
	    }
    	} else {
	    if (GetSimpleSelection(window->buffer, &left, &right))
	        flags |= ACCUMULATE | REPLACE_SELECTION;
	    else
    		left = right = TextGetCursorPos(window->lastFocus);
    	}
    }
    
    /* If the command requires the file be saved first, save it */
    if (saveFirst) {
    	if (!SaveWindow(window)) {
    	    if (input != FROM_NONE)
    		XtFree(text);
            free(subsCommand);
    	    return;
	}
    }
    
    /* If the command requires the file to be reloaded after execution, set
       a flag for issueCommand to deal with it when execution is complete */
    if (loadAfter)
    	flags |= RELOAD_FILE_AFTER;
    	
    /* issue the command */
    issueCommand(inWindow, subsCommand, text, textLen, flags, outWidget, left,
	    right, fromMacro);
    free(subsCommand);
}
Example #21
0
static void createOneDHistActual(int newHisto)
{
   int countHisto, countNTu, countVar, ivar, ivarH, nBins, idh, uid, im, jn;
   int i, index, k, *ivk, ll, lastFixed;
   float from, to;
   double dfrom, dto;
   XmString *selectedItems;
   int *posListHisto, *posListNTu, *posListVar;
   char *str, category[24], x_label[20]; 
   nTuDDL *ddl;
   descrGenNtuple *dNTu;
   nTuBrowserInfo *nTuBr;
   varGenNtuple *var;
   Arg args[2];
   nTuBroHs1D *nTuH1;
   char *cDat;
   long pp; 


    if (HistoIsBrowserNtuInit == NULL) {
       hs_initialize("Mcfio Ntuple Browser");
       hs_histoscope(1);
       HistoIsBrowserNtuInit = 1;
       XtSetSensitive(McfioHsResetBtnW, True);
       hs_update();
       setTimer(500);
    }
    nTuBr = CurrentNTupleBrowserSelected;
    ddl = mcf_GetNTuByPtrID(CurrentNTupleBrowserSelected->id);
    if (ddl->descrNtu == NULL) dNTu = ddl->reference->descrNtu;
	    else dNTu = ddl->descrNtu;
    
    if (!XmListGetSelectedPos(OneDHistVariableListW, &posListVar, &countVar)) {
	DialogF(DF_WARN, OneDHistShellW, 1, "Please select a Variable",
		"Acknowledged");
	return;
    }
    ivarH = (*posListVar) - 1; ivar = ivarH -1;
    /*
    ** Get how many time we have to histogram the variable
    */
    if (ivar < dNTu->firstIndexed) im = -1;
    else {
     str = XmTextGetString(OneDHistMultW);
     if (GetIntText(OneDHistMultW, &im) == TEXT_READ_OK) {
        if (im > dNTu->maxMultiplicity) {
             DialogF(DF_WARN, OneDHistShellW, 1, 
 "Incorrect instance, above maximum Multiplicty.","Acknowledged");
             return;
        } else im--;
      } else {
        if ((strcmp(str,"All") == 0) || (strcmp(str,"ALL") == 0) ||
            (strcmp(str,"all") == 0)) im = -1;
        else if ((strcmp(str,"First") == 0) || (strcmp(str,"FIRST") == 0) ||
            (strcmp(str,"first") == 0)) im = 0;
        else if ((strcmp(str,"Second") == 0) || (strcmp(str,"SECOND") == 0) ||
            (strcmp(str,"second") == 0)) im = 1;
        else if ((strcmp(str,"Third") == 0) || (strcmp(str,"THIRD") == 0) ||
            (strcmp(str,"third") == 0)) im = 2;
        else {
             DialogF(DF_WARN, OneDHistShellW, 1, 
 "Incorrect instance, please use a number","Acknowledged");
             return;
        }
      }
    }     
/*
** We now read out the widget and define the histogram
*/
     str = XmTextGetString(OneDHistTitleW);
     if (GetIntTextWarn(OneDHistNumBinsW, &nBins,
                        "Number of Bins", TRUE) != TEXT_READ_OK) return;
     if (GetFloatTextWarn(OneDHistLowBinW, &dfrom,
                        "Low Bin Edge", TRUE) != TEXT_READ_OK) return;
     if (GetFloatTextWarn(OneDHistHighBinW, &dto,
                        "High Bin Edge", TRUE) != TEXT_READ_OK) return;
      from = (float) dfrom; to = (float) dto;
      /*
      ** At the beginning, the HistoList has a dummy item
      */
      if (FirstOneDHistogram) uid = 1;
      else if (newHisto) {
        XtSetArg (args[0], XmNitemCount, &uid);
        XtGetValues(OneDHistHistoListW, args, 1);
        uid++;
      } else uid = CurrentHistoUID; 
      if (ivarH == 0) 
          strcpy(x_label,"Multiplicity");
      else {
         var = dNTu->variables[ivar];
         if(strlen(var->name) < 17) strcpy(x_label,var->name);
         else {
            strncpy(x_label,var->name,16);
            strcpy(&x_label[16],"...");
         }
     }    
     idh = hs_create_1d_hist(uid, str,  "OneDHist", x_label, "Yield", 
                             nBins, from, to);
     XtFree(str);                        
     /*
     ** Store the idh, we need it for filling. Find the first free place on
     ** the list.
     */
    if (nTuBr->nHistoItems == nTuBr->sizeOfLists)
           mcfioC_ExtendBrowserAnalysis(nTuBr);
     nTuH1 = (nTuBroHs1D *) malloc(sizeof(nTuBroHs1D));
     index=0; 
     while (nTuBr->hsItemList[index] != NULL)  index++;
     nTuBr->hsItemList[index] =  (nTuBroHsGeneral *) nTuH1;
     nTuBr->nHistoItems++;
     nTuBr->nHisto1D++;
     nTuH1->id = idh;
     nTuH1->type = HS_1D_HISTOGRAM;
     nTuH1->varNumber = ivarH;
     nTuH1->subBlock = im;
     nTuH1->varIndices = NULL;
     if(dNTu->firstIndexed == -1) lastFixed = dNTu->numVariables;
           else lastFixed = dNTu->firstIndexed;
     if (ivarH != 0) { 
        var = dNTu->variables[ivar];
       if (var->numDim >= 1) {
          nTuH1->varIndices= (int *) malloc(sizeof(int) * var->numDim);
          ivk = nTuH1->varIndices;
          getVarIndexDialog(ivk, var->numDim, var->dimensions);
       } 
     }  
     if (nTuBr->data == NULL) mcfioC_createBrowserData(nTuBr);
     cDat = (char *) nTuBr->data;
     if (ivarH == 0) {
        cDat += dNTu->multOffset;
        nTuH1->lDat = (long *) cDat;
     } else {
          if (ivar < lastFixed) { 
            pp = ((long) nTuBr->data) +  dNTu->variables[ivar]->offset;
            nTuH1->lDat = (long *) pp;
          } else  nTuH1->lDat = NULL; 
               /* A specific subVariable (leaf), we'll compute the 
          		data pointer at filling time */
     }     		
     XtSetSensitive(OneDHistModifyW, True);
     XtSetSensitive(OneDHistDeleteW, True); 
     redisplay1DHistoList(); 
     FirstOneDHistogram = False; 
     hs_update();
}