Beispiel #1
0
LRESULT CALLBACK DocWin::IdmEvalWithArgv(
    HWND hwnd,
    WPARAM wParam,
    LPARAM lParam
    ) {
    ARGVDLG argvdlg(theRubyWin.GetArgvInfo());
    CHARFORMAT & cfm = theRubyWin.CharFormat();
    if (cfm.cbSize) {
        argvdlg.SetFont(cfm.bCharSet, cfm.szFaceName);
    }
    if (argvdlg.Open(hwnd, theRubyWin.hInstance()) == IDOK) {
        char szTitle[MAX_PATH];
        GetWindowText(hwnd, szTitle, MAX_PATH);

        char tmpfname[MAX_PATH];
        CreateTempFileName(tmpfname);

        WriteFile(hwnd, tmpfname, m_filecode);
        int state = theRubyWin.run_file_with_argv(tmpfname, szTitle, 
                                                  argvdlg.Argv(), 
                                                  IOBUF_SPLIT_CONSOLE,
                                                  m_hwnd);
        DeleteFile(tmpfname);
        if (!state) {
            SetFocus(hwnd);
        }
    }
    return 0;
}
Beispiel #2
0
CTempFile::CTempFile(const char * c_pszPrefix)
{
	strncpy(m_szFileName, CreateTempFileName(c_pszPrefix), MAX_PATH);

	if (!Create(m_szFileName, CFileBase::FILEMODE_WRITE))
	{
		TraceError("CTempFile::CTempFile cannot create temporary file. (filename: %s)", m_szFileName);
		return;
	}
}
Beispiel #3
0
LRESULT CALLBACK DocWin::IdmCheckSyntax(
    HWND hwnd,
    WPARAM wParam,
    LPARAM lParam
    ) {
    char szTitle[MAX_PATH + 1];
    GetWindowText(hwnd, szTitle, MAX_PATH);
    char tmpfile[MAX_PATH + 1];
    CreateTempFileName(tmpfile);
    WriteFile(hwnd, tmpfile, m_filecode);
    int state = theRubyWin.check_syntax(tmpfile, szTitle,
                                        IOBUF_SPLIT_CONSOLE, m_hwnd);
    DeleteFile(tmpfile);
    if (!state) {
        SetFocus(hwnd);
    }
    return 0;
}
Beispiel #4
0
LRESULT CALLBACK DocWin::IdmEvalSelect(
    HWND hwnd,
    WPARAM wParam,
    LPARAM lParam
    ) {

    char szTitle[MAX_PATH];
    GetWindowText(hwnd, szTitle, MAX_PATH);

    char tmpfname[MAX_PATH];
    CreateTempFileName(tmpfname);

    WriteSelectionFile(hwnd, tmpfname);
    int state = theRubyWin.run_file(tmpfname, szTitle, 
                                    IOBUF_SPLIT_CONSOLE, m_hwnd);
    DeleteFile(tmpfname);
    if (!state) {
        SetFocus(hwnd);
    }
    return 0;
}
Beispiel #5
0
static int
UpdateCfgStr(char *FileName,char *SectionName,char *VarWanted, char *NewData)
/*
** This will update a variable in a specific section in your .ini file.
** It will do so safely by copying it to a new file, and when finished,
** will delete the old one and rename the new one to the correct name.
** If any fatal error occurs, it will return a FALSE to indicate failure
** and TRUE to indicate success.  I generally don't care why it failed,
** just knowing that it failed is usually enough.
*/
{
 FILE *CfgFile,*NewCfgFile;
 char SectionWanted[LINE_INPUT_MAX];
 char line[LINE_INPUT_MAX];
 char var[LINE_INPUT_MAX];
 char data[LINE_INPUT_MAX];
 char TempFileName[MAX_FILENAME+1];
 int Status=TRUE;
 int Updated=FALSE;
 int InSection=FALSE;
 int BlankLines=0;

if (!CreateTempFileName(TempFileName))
  {
   DumpDebug("Unable to create a temporary filename to update %s\n",FileName);
   return FALSE;
  }

NewCfgFile=fopen(TempFileName,"w");
if (NewCfgFile==NULL)
  {
   DumpDebug("Unable to open a temporary file to update %s\n",TempFileName);
   return FALSE;
  }

sprintf(SectionWanted,"[%s]",SectionName);

CfgFile=fopen(FileName,"r");
if (CfgFile)
  {
   while (ReadLine(CfgFile,line))
      {
       if (StrEq(line,SectionWanted)) InSection=TRUE;
       else if (InSection && (line[0]=='['))
         {/* leaving our section */
           InSection=FALSE;
           if (!Updated) /* Variable wasn't found, we have to add it */
             {
              fprintf(NewCfgFile,"%s = %s\n",VarWanted,NewData);
              while (BlankLines) {fprintf(NewCfgFile,"\n");BlankLines--;}
              Updated=TRUE;
             }
         }
       if (line[0]=='\0') BlankLines++;
       else
         {
          while (BlankLines) {fprintf(NewCfgFile,"\n");BlankLines--;}
          ParseLine(line,var,data);
          if (InSection && StrEq(var,VarWanted) && !Updated)
            {
             fprintf(NewCfgFile,"%s = %s\n",var,NewData);
             Updated=TRUE;
            }
          else fprintf(NewCfgFile,"%s\n",line);
         }
      }
  }

/*
** Our section may not have even been there (or there wasn't already
** a config file) in which case we have to add both the variable and
** the section itself.
*/
if (!Updated)
  {  /* We may have hit EOF while still in our section. */
     /* If so, we don't need to add the section header. */
   if (!InSection)
     {
      if (BlankLines!=0) fprintf(NewCfgFile,"\n");
      fprintf(NewCfgFile,"%s\n",SectionWanted);
     }
   fprintf(NewCfgFile,"%s = %s\n",VarWanted,NewData);
  }

fprintf(NewCfgFile,"\n");

if (CfgFile && ferror(CfgFile))    Status=FALSE;
if (ferror(NewCfgFile)) Status=FALSE;
if (CfgFile) fclose(CfgFile);
fclose(NewCfgFile);

if (!Status) remove(TempFileName);
else
  {/*if (remove(FileName)) return FALSE;*/
   remove(FileName);
   if (rename(TempFileName,FileName)) return FALSE;
  }

return Status;
}