Back to index

lightning-sunbird  0.9+nobinonly
toolpaths.h
Go to the documentation of this file.
00001 #include <windows.h>
00002 #include <stdio.h>
00003 #include <process.h>
00004 
00005 #ifndef TOPSRCDIR
00006 #include "../topsrcdir.h"
00007 #endif
00008 
00009 #define WCE_BIN   "c:/Program Files/Microsoft Visual Studio 8/VC/ce/bin/x86_arm/"
00010 #ifdef WM50
00011 
00012 #ifdef SMARTPHONE
00013 
00014 #define WCE_INC   "C:/Program Files/Windows CE Tools/wce500/Windows Mobile 5.0 Smartphone SDK/Include/ARMV4I"
00015 #define WCE_LIB        "C:/Program Files/Windows CE Tools/wce500/Windows Mobile 5.0 Smartphone SDK/Lib/ARMV4I"
00016 
00017 #else  //Smartphone
00018 #define WCE_INC   "C:/Program Files/Windows CE Tools/wce500/Windows Mobile 5.0 Pocket PC SDK/Include/ARMV4I"
00019 #define WCE_LIB        "C:/Program Files/Windows CE Tools/wce500/Windows Mobile 5.0 Pocket PC SDK/Lib/ARMV4I"
00020 #endif  //WM50
00021 #else
00022 #if SMARTPHONE
00023 #define WCE_INC   "c:/Program Files/Microsoft Visual Studio 8/SmartDevices/SDK/Smartphone2003/Include"
00024 #define WCE_LIB   "c:/Program Files/Microsoft Visual Studio 8/SmartDevices/SDK/Smartphone2003/Lib/armv4"
00025 #else  //Smartphone
00026 #define WCE_INC   "c:/Program Files/Microsoft Visual Studio 8/SmartDevices/SDK/PocketPC2003/Include"
00027 #define WCE_LIB   "c:/Program Files/Microsoft Visual Studio 8/SmartDevices/SDK/PocketPC2003/Lib/armv4"
00028 #endif  //Smartphone
00029 #endif //WM50
00030 
00031 
00032 #define SHUNT_LIB TOPSRCDIR "/build/wince/shunt/build/vs8/"
00033 #define SHUNT_INC TOPSRCDIR "/build/wince/shunt/include/"
00034 
00035 #define ASM_PATH WCE_BIN "armasm.exe"
00036 #define CL_PATH WCE_BIN "cl.exe"
00037 #define LIB_PATH WCE_BIN "lib.exe"
00038 #define LINK_PATH WCE_BIN "link.exe"
00039 
00040 #define MAX_NOLEAK_BUFFERS 100
00041 char noleak_buffers[MAX_NOLEAK_BUFFERS][1024];
00042 static int next_buffer = 0;
00043  
00044 int argpath_conv(char **args_in, char **args_out)
00045 {
00046   int i = 0;
00047 
00048   while (args_in[i])
00049   {
00050     args_out[i] = args_in[i];
00051 
00052     if (args_in[i])
00053     {
00054       char *offset = strstr(args_out[i], "/cygdrive/");
00055       
00056       if (offset) {
00057       
00058         strcpy(offset, offset+9);
00059         offset[0] = offset[1];
00060         offset[1] = ':';
00061         offset[2] = '/';
00062       }
00063 
00064       if ( (args_out[i][0] == '-' || args_out[i][0] == '/') &&
00065            (args_out[i][1] == 'D'))
00066       {
00067 
00068         offset = strstr(args_out[i]+2, "=");
00069         if (offset)
00070         {
00071           char* equalsChar = offset;
00072           
00073           if (equalsChar[1] == '"')
00074           {
00075             *equalsChar = '\0';
00076      
00077             strcpy(noleak_buffers[next_buffer], args_out[i]);        
00078             
00079             *equalsChar = '=';
00080             
00081             strcat(noleak_buffers[next_buffer], "=\\\"");
00082             strcat(noleak_buffers[next_buffer], equalsChar+1);
00083             strcat(noleak_buffers[next_buffer], "\\\"");
00084             
00085             args_out[i] = noleak_buffers[next_buffer];
00086             
00087             next_buffer++;
00088             
00089             if (next_buffer > MAX_NOLEAK_BUFFERS) {
00090               printf("next_buffer>MAX_NOLEAK_BUFFERS\n");
00091               exit(-1);
00092             }
00093           }
00094         }
00095       }
00096     }
00097     i++;
00098   }
00099   args_out[i] = NULL;
00100   return i;
00101 }
00102 
00103 void dumpargs(char** args)
00104 {
00105   int i = 0;
00106 
00107   if (args[0] == NULL)
00108     printf(":: first element is null!\n");
00109 
00110   while(args[i])
00111     printf("%s ", args[i++]);
00112 
00113   printf("\n");
00114   fflush(stdout);
00115   fflush(stderr);
00116 }
00117 
00118 
00119 void run(char** args)
00120 {
00121 
00122   STARTUPINFO si;
00123   PROCESS_INFORMATION pi;
00124 
00125   char theArgs[1024*16];
00126 
00127   int totalLen = 0;
00128   int i, j;
00129 
00130 
00131   // Clear any link env variable that might get us tangled up
00132   _putenv("LINK=");
00133   _putenv("LIBPATH=");
00134   _putenv("CC=");
00135 
00136   _putenv("INCLUDE=" WCE_INC);
00137   _putenv("LIB=" WCE_LIB);
00138   
00139   for (j=1; args[j]; j++)
00140   {
00141     int len = strlen(args[j]);
00142     strcat(&theArgs[totalLen], args[j]);
00143     totalLen += len;
00144     
00145     strcat(&theArgs[totalLen], " ");
00146     totalLen++;
00147   }
00148   
00149   i = strlen(args[0]);
00150   for (j=0; j<i; j++)
00151   {
00152     if (args[0][j] == '/')
00153       args[0][j] = '\\';
00154   }
00155   
00156   ZeroMemory( &si, sizeof(si) );
00157   si.cb = sizeof(si);
00158   ZeroMemory( &pi, sizeof(pi));
00159   
00160   CreateProcess(args[0],
00161                 theArgs,
00162                 NULL,
00163                 NULL,
00164                 0,
00165                 0,
00166                 NULL,
00167                 NULL,
00168                 &si,              // Pointer to STARTUPINFO structure.
00169                 &pi);
00170   
00171   
00172   // Wait until child process exits.
00173   WaitForSingleObject( pi.hProcess, INFINITE );
00174   
00175   // Close process and thread handles. 
00176   CloseHandle( pi.hProcess );
00177   CloseHandle( pi.hThread );
00178 }