Advertisement
lilezek

Untitled

Mar 31st, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #ifndef PLATFORMSPECIFIC_H_INCLUDED
  2. #define PLATFORMSPECIFIC_H_INCLUDED
  3.  
  4. #include <string.h>
  5.  
  6. #ifdef XDG_COMPATIBLE
  7.     static char command[] = "xdg-open";
  8.     #define SYSTEM_FUNCTION
  9. #elif GNOME_COMPATIBLE
  10.     static char command[] = "gnome-open";
  11.     #define SYSTEM_FUNCTION
  12. #elif KDE_COMPATIBLE
  13.     static char command[] = "kde-open";
  14.     #define SYSTEM_FUNCTION
  15. #elif WINDOWS_COMPATIBLE
  16.     static char command[] = "start";
  17.     #define SYSTEM_FUNCTION
  18. #elif MACOSX_COMPATIBLE
  19.     // Mac Os X compatibility here...
  20. #endif
  21.  
  22. #ifdef SYSTEM_FUNCTION
  23.  
  24. int execute(char * command, char * arguments)
  25. {
  26.     // Definitions:
  27.     int size;
  28.     int result;
  29.     char * tmp;
  30.  
  31.     // Calculate size of command and arguments
  32.     // + 2 means:
  33.     // The c string style needs one more byte for the null-end.
  34.     // Command and arguments must be separated by one space at least.
  35.     size = strlen(command) + strlen(arguments) + 2;
  36.     // Allocate enough memory to join command and arguments in once.
  37.     tmp = (char*)malloc((size)*sizeof(char));
  38.     // Concatenate command and arguments:
  39.     // First copy command
  40.     strcpy(tmp,command);
  41.     // Concatenate an empty space:
  42.     strcat(tmp," ");
  43.     // Concatenate arguments to command:
  44.     strcat(tmp,arguments);
  45.     // Execute os dependent command:
  46.     result = system(tmp);
  47.     // Free tmp pointer.
  48.     free(tmp);
  49.     return result;
  50. }
  51.  
  52. #endif
  53.  
  54. #endif // PLATFORMSPECIFIC_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement