Advertisement
Crazykk1449

Untitled

Dec 14th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1.  clude <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "trim/trim.h"
  5. #include "asprintf/asprintf.h"
  6. #include "which/which.h"
  7. #include "str-flatten/str-flatten.h"
  8. #include "strdup/strdup.h"
  9. #include "debug/debug.h"
  10. #include "version.h"
  11. int main(int argc, const char **argv) {
  12.     char *cmd = NULL;
  13.     char *args = NULL;
  14.     char *command = NULL;
  15.     char *command_with_args = NULL;
  16.     char *bin = NULL;
  17.     int rc = 1;
  18.  
  19.     debug_init(&debugger, "clib");
  20.  
  21.     //usage
  22.     if (NULL == argv[1]
  23.         || 0 == strncmp(argv[1], "-h", 2
  24.             printf("%s\n", CLIB_VERSION);
  25.             return 0;
  26.     }
  27.  
  28.     // unkown
  29.     if (0 == strncmp(argv[1]);
  30.     if (NULL == cmd) {
  31.         fprintf(stderr, "Memory allocation failure\n");
  32.         return 1;
  33.     }
  34.     cmd = trim(cmd);
  35.  
  36.     if (0 == strcmp(cmd, "help")) {
  37.         if (argc >= 3){
  38.             free(cmd);
  39.             cmd = strdup(argv[2]);
  40.             args = strdup("--help");
  41.         } else {
  42.             fprintf(stderr, "Help command required.\n");
  43.             goto cleanup;
  44.         }
  45.     } else {
  46.         if (argc >= 3) {
  47.             args = str_flatten(argv, 2, argc);
  48.             if (NULL == args) goto cleanup;
  49.         }
  50.     }
  51.     debug(&debugger, "args: %s", args);
  52.  
  53. #ifdef _WIN32
  54.     format(&command, "");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement