home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / fake.zip / fake.c next >
C/C++ Source or Header  |  1995-08-24  |  4KB  |  88 lines

  1. /* Faker 1.0                                               */
  2. /*                                                         */
  3. /* This code is Public Domain                              */
  4. /* compiled and tested with emx09a/fix 04                  */
  5. /*                                                         */
  6. /* Created by Radim Kolar 2:423/66.111                     */
  7. /*   SysOp of Dark side of Avalon                          */
  8. /*                                                         */
  9. /* What it is, and how-to-run:                             */
  10. /*  If want to know parameters parsed to some program, then*/
  11. /*   Faker is all what you need.                           */
  12. /* I want to know something about ppp.exe, then:           */  
  13. /*                                                         */
  14. /* Instalation and setup:                                  */
  15. /*                                                         */
  16. /* 1) rename ppp.exe to something else .EXE and leave it in*/
  17. /* original directory or move it simply out from PATH      */
  18. /* 2) rename fake.exe to ppp.exe, and place it to original */
  19. /* ppp.exe directory                                       */
  20. /* 3) in root of drive C: create ascii file fake.run with  */
  21. /* name of renamed ppp.exe on first line (or full path to  */
  22. /* old ppp.exe)                                            */
  23. /* 4) Now you are ready, simply run SLIPPM, this runs fake */
  24. /* and fake runs old ppp.                                  */
  25. /* 5) Look into file fake.it (located in root direcory on C*/
  26. /* drive and enjoy !                                       */
  27. /*                                                         */
  28. /* Note: if fake.run not exists, fake only records para-   */
  29. /*   meters into fake.it and returns with errolevel 0      */
  30. /* Note2: if fake cannot open fake.it, all infos are prin- */
  31. /*   ted to stdout                                         */
  32. /* Rev. History:                                           */
  33. /* 24.8.1995      Log date+time added                      */
  34. /*                hard-coded output filename c:\fake.it    */
  35. /*                log file is now opened in append mode    */
  36. /*                if open fake.it fails, report to stdout  */
  37. /*                Now also runs with program in c:\fake.run*/
  38. /*                   with the same parameters!             */
  39. /*                If run fails, returns errorlevel 0       */
  40. /*                if not fails returns the errorlevel, re- */
  41. /*                   turned by programm in fake.run !      */
  42.  
  43. #include <stdio.h>
  44. #include <time.h>
  45. #include <string.h>
  46. #include <process.h>
  47.  
  48. int main(int n,char *a[])
  49. {
  50.  int i;
  51.  int rc=0; /* default rc */
  52.  char frun[257];
  53.  FILE *out,*cfg;
  54.  char *cas;
  55.  time_t sec=time(NULL);
  56.  cas=ctime(&sec);
  57.  strcpy(frun,"");
  58.  fprintf(stdout,"Faker 1.0 StdOut!\n");
  59.  fprintf(stderr,"Stderr!");
  60.  out=fopen("c:\\fake.it","at");
  61.  cfg=fopen("C:\\fake.run","rt");
  62.  if (cfg!=NULL) { i=fscanf(cfg,"%s",frun);
  63.                   if(i==EOF) strcpy(frun,"");
  64.                   fclose(cfg);
  65.                 }  
  66.  if(out==NULL) { printf("\aError opening fake.it file!");
  67.                  out=stdout;}
  68.  
  69.  fprintf(out,"Faker 1.0 started at %s",cas);
  70.  fprintf(out,"Arguments count n=%d\n\n",n-1);
  71.  for(i=0;i<n;i++)
  72.    fprintf(out,"%d = %s\n",i,a[i]);
  73.  if (strlen(frun)>0) {
  74.                       fprintf(out,"Executing : %s \n",frun);
  75.                       i=spawnv(P_WAIT|P_DEFAULT,frun,a);
  76.                       if(i==-1) fprintf(out,"Execute failed, check fake.run !\n");
  77.                                 else { fprintf(out,"Returned with errorlevel %d\n",i);
  78.                                        rc=i;}
  79.                      }
  80.  fprintf(out,"---Faker 1.0 done, ");
  81.  sec=time(NULL);
  82.  cas=ctime(&sec);
  83.  fprintf(out,"%s\n",cas);
  84.  fclose(out);
  85.  return rc;
  86. }
  87.  
  88.