FilesAssociations.c File Reference

#include "FilesAssociations.h"
#include "Messages.h"
#include "Warnings.h"
#include "Errors.h"
#include "win_mem_alloc.h"

Include dependency graph for FilesAssociations.c:

Go to the source code of this file.

Functions

void ReplaceSlash (char *pathout, char *pathin)
void PrintFile (char *filename)
BOOL SendCommandToAnotherScilab (char *ScilabWindowNameSource, char *ScilabWindowNameDestination, char *CommandLine)
BOOL HaveAnotherWindowScilab (void)
char * ChooseAnotherWindowScilab (void)
BOOL IsAFile (char *chainefichier)
BOOL IsABinOrSavFile (char *chainefichier)
BOOL IsAGraphFile (char *chainefichier)
BOOL IsAGraphFilegraph (char *chainefichier)
BOOL IsAGraphFilegraphb (char *chainefichier)
BOOL IsAScicosFile (char *chainefichier)
BOOL IsAScicosFileCOS (char *chainefichier)
BOOL IsAScicosFileCOSF (char *chainefichier)
int CommandByFileExtension (char *fichier, int OpenCode, char *Cmd)
void ExtensionFileIntoLowerCase (char *fichier)


Function Documentation

char* ChooseAnotherWindowScilab ( void   ) 

Definition at line 63 of file FindScilab.c.

Referenced by CommandByFileExtension().

00064 {
00065         char *TitleScilabChoose=NULL;
00066         if (NumberScilab == 1)
00067         {
00068                 TitleScilabChoose=MALLOC( (strlen(ListScilabName[NumberScilab-1])+1) * sizeof(char) );
00069                 wsprintf(TitleScilabChoose,"%s",ListScilabName[NumberScilab-1]);
00070         }
00071         else
00072         {
00073                 HWND hWndScilab=NULL;
00074                 TitleScilabChoose=ChooseScilabBox();
00075                 hWndScilab=FindWindow(NULL,TitleScilabChoose);
00076                 if (hWndScilab==NULL) /* La fenetre n'existe plus */
00077                 {
00078                         FREE(TitleScilabChoose);
00079                         TitleScilabChoose=NULL;
00080                 }
00081         }
00082 
00083         return TitleScilabChoose;
00084 
00085 
00086 }

Here is the caller graph for this function:

int CommandByFileExtension ( char *  fichier,
int  OpenCode,
char *  Cmd 
)

Definition at line 124 of file FilesAssociations.c.

References ChooseAnotherWindowScilab(), ExtensionFileIntoLowerCase(), FALSE, FREE, HaveAnotherWindowScilab(), i, int, IsABinOrSavFile(), IsAFile(), IsAGraphFile(), IsAScicosFile(), MAX_PATH, MSG_SCIMSG1, MSG_SCIMSG2, MSG_SCIMSG3, MSG_SCIMSG4, MSG_SCIMSG5, MSG_SCIMSG6, MSG_SCIMSG7, MSG_SCIMSG8, NULL, PrintFile(), ReplaceSlash(), SendCommandToAnotherScilab(), and TRUE.

Referenced by Windows_Main().

00125 {
00126         int Retour=FALSE;
00127         char FinalFileName[MAX_PATH];
00128         char ShortPath[MAX_PATH];
00129         char PathWScilex[MAX_PATH];
00130         
00131         if (fichier[0]=='\"')
00132         {
00133                 char buffertemp[MAX_PATH];
00134                 int i=1;
00135                 
00136                 while (fichier[i] != '"')
00137                 {
00138                         buffertemp[i-1]=fichier[i];
00139                         i++;
00140                         if (i> (int)strlen(fichier))
00141                         {
00142                                 i=(int)strlen(fichier);
00143                                 break;
00144                         }
00145                 }
00146                 buffertemp[i-1]='\0';
00147                 strcpy(fichier,buffertemp);
00148         }
00149         if (fichier[strlen(fichier)-1]=='\"') fichier[strlen(fichier)-1]='\0';
00150 
00151         if (IsAFile(fichier))
00152         {
00153                 GetShortPathName(fichier,ShortPath,MAX_PATH); /* Recuperation du nom du fichier au format 8.3 */
00154                 ReplaceSlash(FinalFileName,ShortPath);
00155                 GetModuleFileName ((HINSTANCE)GetModuleHandle(NULL), PathWScilex, MAX_PATH);
00156                 Retour=TRUE;
00157 
00158                 switch (OpenCode)
00159                    {
00160                         case 1: /* Execute -X*/
00161                                 {
00162                                         if ( IsABinOrSavFile(FinalFileName)== TRUE )
00163                                         {
00164                                                 /* C'est un fichier .BIN ou .SAV d'ou load */
00165                                                 wsprintf(Cmd,MSG_SCIMSG1,PathWScilex,FinalFileName,FinalFileName);
00166                                         }
00167                                         else
00168                                         if  ( IsAScicosFile(fichier)== TRUE )
00169                                         {
00170                                           ExtensionFileIntoLowerCase(FinalFileName);    
00171                                                 wsprintf(Cmd,MSG_SCIMSG2,PathWScilex,FinalFileName);
00172                                         }
00173                                         else
00174                                         if ( IsAGraphFile(fichier)== TRUE )
00175                                         {
00176                                                 ExtensionFileIntoLowerCase(FinalFileName);      
00177                                                 wsprintf(Cmd,MSG_SCIMSG3,PathWScilex,FinalFileName);
00178                                         }
00179                                         else wsprintf(Cmd,MSG_SCIMSG4,PathWScilex,FinalFileName);
00180                                 }
00181                         break;
00182                         case 2: /* Print -P*/
00183                                 {
00184                                         PrintFile(fichier);
00185                                         strcpy(Cmd," ");
00186                                         exit(0);
00187                                 }
00188                         break;
00189                         case 0:default: /* Open -O*/
00190                                 {
00191                                         if (! HaveAnotherWindowScilab())
00192                                         {
00193                                                 wsprintf(Cmd,MSG_SCIMSG5,PathWScilex,FinalFileName);
00194                                         }
00195                                         else
00196                                         {
00197                                                 char *ScilabDestination=NULL;
00198                                                 wsprintf(Cmd,MSG_SCIMSG6,FinalFileName);
00199 
00200                                                 ScilabDestination=(char*)ChooseAnotherWindowScilab();
00201                                                 if (ScilabDestination)
00202                                                 {
00203                                                         SendCommandToAnotherScilab(MSG_SCIMSG7,ScilabDestination,Cmd);
00204                                                         FREE(ScilabDestination);
00205                                                         exit(0);
00206                                                 }
00207                                                 else
00208                                                 {
00209                                                         wsprintf(Cmd,MSG_SCIMSG8,PathWScilex,FinalFileName);
00210                                                 }
00211                                                 
00212                                         }
00213                                 }
00214                         break;
00215                 
00216         }
00217         
00218         }       
00219         
00220         
00221         return Retour;
00222 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ExtensionFileIntoLowerCase ( char *  fichier  ) 

Definition at line 224 of file FilesAssociations.c.

References buffer, FREE, MALLOC, and NULL.

Referenced by CommandByFileExtension().

00225 {
00226         char *tmpfile=NULL;
00227         char *buffer=NULL;
00228         char *lastdot=NULL;
00229         char *ext=NULL;
00230         
00231         tmpfile=(char*)MALLOC(strlen(fichier)*sizeof(char));
00232         strcpy(tmpfile,fichier);
00233         
00234         buffer=strtok(tmpfile,".");
00235         while ( buffer = strtok(NULL,"."))
00236         {
00237                 lastdot=buffer;
00238         }
00239         /* le dernier . permet d'avoir l'extension */
00240         ext=_strlwr(lastdot); /* Fichier en Majuscule */
00241         
00242         strcpy(&fichier[strlen(fichier)-strlen(ext)],ext);
00243         
00244         FREE(tmpfile);
00245 }

Here is the caller graph for this function:

BOOL HaveAnotherWindowScilab ( void   ) 

Definition at line 28 of file FindScilab.c.

Referenced by CommandByFileExtension().

00029 {
00030         BOOL Retour=FALSE;
00031         HWND CurrenthWnd=NULL;
00032         
00033         int a=0;
00034 
00035         wsprintf(BeginningWindowScilabName,"%s (",SCI_VERSION_STRING);
00036         
00037         CurrenthWnd=GetWindow(GetDesktopWindow(),GW_CHILD);
00038         CurrenthWnd=GetWindow(CurrenthWnd,GW_HWNDFIRST);
00039 
00040         while ( CurrenthWnd!= NULL )
00041         {
00042                 char Title[LineMax];
00043 
00044                 GetWindowText(CurrenthWnd,Title,strlen(BeginningWindowScilabName)+1);
00045                 if (strcmp(Title,BeginningWindowScilabName) == 0)
00046                 {
00047                         GetWindowText(CurrenthWnd,Title,LineMax);
00048                         if (NumberScilab<NumberScilabMax)
00049                         {
00050                                 wsprintf(ListScilabName[NumberScilab],"%s",Title);
00051                         }
00052                         else MoreMaxNumberScilabMax=TRUE;
00053                         NumberScilab++;
00054                         Retour=TRUE;
00055                 }
00056         
00057                 CurrenthWnd=GetWindow(CurrenthWnd,GW_HWNDNEXT);
00058         }
00059 
00060         return Retour;
00061 }

Here is the caller graph for this function:

BOOL IsABinOrSavFile ( char *  chainefichier  ) 

Definition at line 35 of file FilesAssociations.c.

References FALSE, FREE, NULL, and TRUE.

Referenced by CommandByFileExtension().

00036 {
00037         BOOL retour=FALSE;
00038         char *ExtensionFilename=NULL;
00039 
00040         ExtensionFilename=PathFindExtension(chainefichier);
00041         
00042         /* Comparaison avec les extension BIN et SAV */
00043         if ( (_stricmp(ExtensionFilename,".BIN")==0) || (_stricmp(ExtensionFilename,".SAV")==0) ) retour=TRUE;
00044 
00045         if (ExtensionFilename) {FREE(ExtensionFilename);ExtensionFilename=NULL;}
00046         return retour;
00047 
00048 }

Here is the caller graph for this function:

BOOL IsAFile ( char *  chainefichier  ) 

Definition at line 17 of file FilesAssociations.c.

References FALSE, and TRUE.

Referenced by CommandByFileExtension(), CreateButton(), and OpenSelection().

00018 {
00019      BOOL retour=FALSE; 
00020         
00021      WIN32_FIND_DATA FindFileData;
00022      HANDLE handle = FindFirstFile (chainefichier, &FindFileData);
00023      if (handle != INVALID_HANDLE_VALUE)
00024      {
00025          FindClose (handle);
00026          retour=TRUE;
00027      }
00028      else retour=FALSE;
00029 
00030      return retour;
00031 }

Here is the caller graph for this function:

BOOL IsAGraphFile ( char *  chainefichier  ) 

Definition at line 50 of file FilesAssociations.c.

References FALSE, IsAGraphFilegraph(), IsAGraphFilegraphb(), and TRUE.

Referenced by CommandByFileExtension(), and Windows_Main().

00051 {
00052         BOOL retour=FALSE;
00053         
00054         if ( IsAGraphFilegraphb(chainefichier) || IsAGraphFilegraph(chainefichier) ) retour=TRUE;
00055         
00056         return retour;
00057 }

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL IsAGraphFilegraph ( char *  chainefichier  ) 

Definition at line 59 of file FilesAssociations.c.

References FALSE, FREE, NULL, and TRUE.

Referenced by IsAGraphFile().

00060 {
00061         BOOL retour=FALSE;
00062         char *ExtensionFilename=NULL;
00063 
00064         ExtensionFilename=PathFindExtension(chainefichier);
00065 
00066         /* Comparaison avec l'extension Graph */
00067         if (_stricmp(ExtensionFilename,".GRAPH")==0) retour=TRUE;
00068 
00069         if (ExtensionFilename) {FREE(ExtensionFilename);ExtensionFilename=NULL;}
00070         return retour;
00071 }

Here is the caller graph for this function:

BOOL IsAGraphFilegraphb ( char *  chainefichier  ) 

Definition at line 73 of file FilesAssociations.c.

References FALSE, FREE, NULL, and TRUE.

Referenced by IsAGraphFile().

00074 {
00075         BOOL retour=FALSE;
00076         char *ExtensionFilename=NULL;
00077 
00078         ExtensionFilename=PathFindExtension(chainefichier);
00079 
00080         /* Comparaison avec l'extension Graphb */
00081         if (_stricmp(ExtensionFilename,".GRAPHB")==0) retour=TRUE;
00082 
00083         if (ExtensionFilename) {FREE(ExtensionFilename);ExtensionFilename=NULL;}
00084         return retour;
00085 }

Here is the caller graph for this function:

BOOL IsAScicosFile ( char *  chainefichier  ) 

Definition at line 87 of file FilesAssociations.c.

References FALSE, IsAScicosFileCOS(), IsAScicosFileCOSF(), and TRUE.

Referenced by CommandByFileExtension(), and Windows_Main().

00088 {
00089         BOOL retour=FALSE;
00090         
00091         if ( IsAScicosFileCOS(chainefichier) || IsAScicosFileCOSF(chainefichier) ) retour=TRUE;
00092         
00093         return retour;
00094 }

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL IsAScicosFileCOS ( char *  chainefichier  ) 

Definition at line 96 of file FilesAssociations.c.

References FALSE, FREE, NULL, and TRUE.

Referenced by IsAScicosFile().

00097 {
00098         BOOL retour=FALSE;
00099         char *ExtensionFilename=NULL;
00100 
00101         ExtensionFilename=PathFindExtension(chainefichier);
00102 
00103         /* Comparaison avec l'extension cos */
00104         if (_stricmp(ExtensionFilename,".COS")==0) retour=TRUE;
00105 
00106         if (ExtensionFilename) {FREE(ExtensionFilename);ExtensionFilename=NULL;}
00107         return retour;
00108 }

Here is the caller graph for this function:

BOOL IsAScicosFileCOSF ( char *  chainefichier  ) 

Definition at line 110 of file FilesAssociations.c.

References FALSE, FREE, NULL, and TRUE.

Referenced by IsAScicosFile().

00111 {
00112         BOOL retour=FALSE;
00113         char *ExtensionFilename=NULL;
00114 
00115         ExtensionFilename=PathFindExtension(chainefichier);
00116 
00117         /* Comparaison avec l'extension cosf */
00118         if (_stricmp(ExtensionFilename,".COSF")==0) retour=TRUE;
00119 
00120         if (ExtensionFilename) {FREE(ExtensionFilename);ExtensionFilename=NULL;}
00121         return retour;
00122 }

Here is the caller graph for this function:

void PrintFile ( char *  filename  ) 

Definition at line 180 of file TextToPrint.c.

Referenced by C2F(), and CommandByFileExtension().

00181 {
00182 #define MAXBUF 4096
00183         HDC PrintDC;
00184         HFONT hFont, hOldFont;
00185         HDC hDCmem;
00186         DOCINFO di;
00187         int Index2 = 3;
00188         int numero=1;
00189         // Extrait les informations sur la police
00190         TEXTMETRIC tm;
00191         int NbLigneParPage = 0;
00192         int HauteurCaractere=0;
00193         int NombredeCaracteresparLignes=0;
00194         FILE * pFile;
00195         char  line[MAXBUF];
00196 
00197         PrintDC=GetPrinterDC();
00198         if (PrintDC != NULL)
00199         {
00200 
00201                 hFont=EzCreateFont (PrintDC, TEXT ("Courier New"),120, 0, 0, TRUE) ;
00202                 hOldFont = SelectObject(PrintDC, hFont );
00203 
00204                 hDCmem = CreateCompatibleDC(PrintDC);
00205                 memset( &di, 0, sizeof( DOCINFO ) );
00206                 di.cbSize      = sizeof( DOCINFO );
00207                 di.lpszDocName = MSG_SCIMSG105;
00208 
00209                 GetTextMetrics(PrintDC,(TEXTMETRIC *)&tm);
00210 
00211                 NombredeCaracteresparLignes=GetDeviceCaps(PrintDC,HORZRES) / (tm.tmMaxCharWidth+1);
00212                 // la valeur HauteurCaractere contient hauteur des caractéres + l'interligne
00213                 HauteurCaractere= tm.tmHeight+tm.tmExternalLeading;
00214                 NbLigneParPage = GetDeviceCaps(PrintDC,VERTRES) / HauteurCaractere;
00215 
00216                 pFile = fopen (filename,"rt");
00217                 if (pFile)
00218                 {
00219                         if ( StartDoc( PrintDC, &di ) > 0 )
00220                         {
00221                                 char *LignePrint=NULL;
00222                                 StartPage(PrintDC);
00223                                 PageHeader(PrintDC,filename);
00224 
00225                                 while(fgets (line,sizeof(line),pFile) != NULL)
00226                                 {
00227                                         if (line[strlen(line)-1] == '\n') line[strlen(line)-1]='\0'; /* enleve le retour chariot */
00228                                         if (line[strlen(line)-2] == '\r') line[strlen(line)-2]='\0'; /* enleve le retour chariot */
00229 
00230                                         if ( strlen(line)> (unsigned int )NombredeCaracteresparLignes)
00231                                         {
00232                                                 int i=0;
00233                                                 int j=0;
00234                                                 int subline=0;
00235                                                 int restsubline=0;
00236                                                 subline = (int)strlen(line) / NombredeCaracteresparLignes ;
00237                                                 restsubline=(int)strlen(line) % NombredeCaracteresparLignes ;
00238 
00239                                                 for (i=0;i<subline;i++)
00240                                                 {
00241                                                         LignePrint=(char*)MALLOC( (NombredeCaracteresparLignes+1)*sizeof(char));
00242                                                         for (j=0;j<(NombredeCaracteresparLignes);j++)
00243                                                         {
00244                                                                 if (line[(i*NombredeCaracteresparLignes)+j] == 9) /* == \t */
00245                                                                 {
00246                                                                         LignePrint[j]=' ';
00247                                                                 }
00248                                                                 else
00249                                                                 {
00250                                                                         LignePrint[j]=line[(i*NombredeCaracteresparLignes)+j];
00251                                                                 }
00252 
00253                                                         }
00254                                                         LignePrint[j]='\0';
00255 
00256                                                         TextOut (PrintDC,(tm.tmMaxCharWidth+10), Index2*HauteurCaractere, LignePrint, (int)strlen(LignePrint));
00257                                                         if (LignePrint)
00258                                                         {
00259                                                                 FREE(LignePrint);
00260                                                                 LignePrint=NULL;
00261                                                         }
00262                                                         Index2 ++;
00263                                                         if (Index2 == NbLigneParPage-4)
00264                                                         {
00265                                                                 Footer(PrintDC,numero);
00266                                                                 EndPage (PrintDC);
00267                                                                 StartPage(PrintDC);
00268                                                                 numero++;
00269                                                                 PageHeader(PrintDC,filename);
00270                                                                 Index2 = 3;
00271                                                         }
00272                                                 }
00273                                                 if (restsubline>0)
00274                                                 {
00275                                                         LignePrint=(char*)MALLOC( (NombredeCaracteresparLignes+1)*sizeof(char));
00276                                                         for (j=0;j<(restsubline);j++)
00277                                                         {
00278                                                                 if (line[(i*NombredeCaracteresparLignes)+j] == 9) /* == \t */
00279                                                                 {
00280                                                                         LignePrint[j]=' ';
00281                                                                 }
00282                                                                 else
00283                                                                 {
00284                                                                         LignePrint[j]=line[(i*NombredeCaracteresparLignes)+j];
00285                                                                 }
00286                                                         }
00287                                                         LignePrint[j]='\0';
00288                                                         TextOut (PrintDC,(tm.tmMaxCharWidth+10), Index2*HauteurCaractere, LignePrint, (int)strlen(LignePrint));
00289                                                         if (LignePrint)
00290                                                         {
00291                                                                 FREE(LignePrint);
00292                                                                 LignePrint=NULL;
00293                                                         }
00294                                                         Index2 ++;
00295                                                         if (Index2 == NbLigneParPage-4)
00296                                                         {
00297                                                                 Footer(PrintDC,numero);
00298                                                                 EndPage (PrintDC);
00299                                                                 StartPage(PrintDC);
00300                                                                 numero++;
00301                                                                 PageHeader(PrintDC,filename);
00302                                                                 Index2 = 3;
00303                                                         }
00304                                                 }
00305                                         }
00306                                         else
00307                                         {
00308                                                 LignePrint=(char*)MALLOC( (NombredeCaracteresparLignes+1)*sizeof(char));
00309                                                 strcpy(LignePrint,line);
00310                                                 TextOut (PrintDC,(tm.tmMaxCharWidth+10), Index2*HauteurCaractere, LignePrint, (int)strlen(LignePrint));
00311                                                 if (LignePrint)
00312                                                 {
00313                                                         FREE(LignePrint);
00314                                                         LignePrint=NULL;
00315                                                 }
00316                                                 Index2 ++;
00317                                                 if (Index2 == NbLigneParPage-4)
00318                                                 {
00319                                                         Footer(PrintDC,numero);
00320                                                         EndPage (PrintDC);
00321                                                         StartPage(PrintDC);
00322                                                         numero++;
00323                                                         PageHeader(PrintDC,filename);
00324                                                         Index2 = 3;
00325                                                 }
00326                                         }
00327                                 }
00328                                 fclose(pFile);
00329 
00330                                 Footer(PrintDC,numero);
00331                                 EndPage (PrintDC);
00332                                 EndDoc (PrintDC);
00333                         }
00334                 }
00335                 SelectObject(PrintDC, hOldFont );
00336         }
00337 }

Here is the caller graph for this function:

void ReplaceSlash ( char *  pathout,
char *  pathin 
)

Definition at line 1682 of file wmenu.c.

Referenced by CommandByFileExtension(), and OpenSelection().

01683 {
01684         int i=0;
01685         for (i=0;i < (int)strlen(pathin);i++)
01686                 {
01687 
01688                         if (pathin[i]=='\\')
01689                         {
01690                                 pathout[i]='/';
01691                         }
01692                         else
01693                         {
01694                                 pathout[i]=pathin[i];
01695                         }
01696 
01697                 }
01698         pathout[i]='\0';
01699 }

Here is the caller graph for this function:

BOOL SendCommandToAnotherScilab ( char *  ScilabWindowNameSource,
char *  ScilabWindowNameDestination,
char *  CommandLine 
)

Definition at line 34 of file wmcopydata.c.

Referenced by CommandByFileExtension().

00035 {
00036    COPYDATASTRUCT MyCDS;
00037    MYREC MyRec;
00038    HWND hWndSource=NULL;
00039    HWND hWndDestination=NULL;
00040  
00041 
00042    if (wsprintf(MyRec.CommandFromAnotherScilab,"%s",CommandLine) <= 0) return FALSE;
00043   
00044 
00045    MyCDS.dwData = 0; 
00046    MyCDS.cbData = sizeof( MyRec );
00047    MyCDS.lpData = &MyRec;
00048    
00049    hWndSource=FindWindow(NULL,ScilabWindowNameSource);
00050    hWndDestination=FindWindow(NULL, ScilabWindowNameDestination);
00051 
00052    if ( (hWndDestination != NULL) )
00053    {
00054              SendMessage( hWndDestination,
00055                                           WM_COPYDATA,
00056                                           (WPARAM)(HWND) hWndDestination,
00057                                           (LPARAM) (LPVOID) &MyCDS );
00058    }
00059    else return FALSE;
00060 
00061    return TRUE;
00062 }

Here is the caller graph for this function:


Generated on Sun Mar 4 15:57:36 2007 for Scilab [trunk] by  doxygen 1.5.1