home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / cmdline / asmfix4 / b next >
Encoding:
Text File  |  1979-12-31  |  12.7 KB  |  312 lines

  1. /*
  2.     Execute DOS .EXE file with standard handles redirected.
  3.     Accept redirection arguments of the form:
  4.  
  5.     e -r file command  : stdout and stderr to file. ( space opt. )
  6.     e -r #hnd command  : stdout and stderr to handle hnd. ( space req.)
  7.     e -rhnd file command : handle hnd to file.
  8.     e -rhnd1 #hnd2 command : handle hnd1 to handle hnd2. 
  9.  
  10.     Same as above with -a instead of -r will append.
  11.  
  12.     Standard handles are:
  13.  
  14.             0 - standard input ( not useful here )
  15.             1 - standard output.
  16.             2 - standard error.
  17.             3 - standard auxillary ( usually serial port ).
  18.             4 - standard printer ( usually parallel port ).
  19.  
  20.     Examples:
  21.  
  22.         e -r out masm test,,test;
  23.             -- send all standard output and standard error output
  24.                to the file 'out'.  Note that due to the
  25.                difference in the way C stream level stdout and
  26.                stderr are handled, 'out' may contain output in
  27.                a different order from that seen on the screen.
  28.  
  29.         e -r2 errors masm test;
  30.             -- send all standard error output to the file
  31.                errors.  Standard out still goes to the
  32.                console. 
  33.  
  34.         e -r1 out -r2 errs masm test;
  35.             -- send standard output to file 'out'.
  36.             -- send standard error to file 'errs'.
  37.  
  38.         e -r4 #1 masm test;
  39.             -- send printer output to console.
  40.  
  41. */
  42.  
  43. #include <process.h>
  44. #include <io.h>
  45. #include <stdlib.h>
  46. #include <fcntl.h>
  47. #include <sys\types.h>
  48. #include <sys\stat.h>
  49. #include <ctype.h>
  50. #include <string.h>
  51.  
  52. /*  Error return codes */
  53. #define NO_ARGS    1
  54. #define DUP    2
  55. #define EXEC    3
  56. #define OPEN    4
  57. #define BAD_SWITCH    5
  58.  
  59. /*  Known handles */
  60. #define STDOUT    1
  61. #define STDERR    2
  62.  
  63. #define SWITCHARS    "-/"
  64. #define DIGITS        "0123456789"
  65. #define FALSE    0
  66. #define TRUE    -1
  67.  
  68. int Redirect();
  69.  
  70. /*****            ************            ***********************/
  71. main( argc, argv )
  72. int argc;
  73. char *argv[];
  74. {
  75. int argcount = 1;
  76.  
  77.     if ( argc < 2 )
  78.     {
  79.         puts( "Usage is: e [<-r|-a[hnd] filename|hnd>] <.EXE file> <arglist>" );
  80.         exit( NO_ARGS );
  81.     }
  82.  
  83.     while( strcspn( argv[argcount], SWITCHARS ) == 0 )
  84.  
  85.         argcount += Redirect( argv + argcount );
  86.  
  87.     if ( execvp( argv[argcount], argv + argcount ) == -1 )
  88.     {
  89.         printf( argv[argcount] );
  90.         perror( ": Exec Error" );
  91.         exit( EXEC );
  92.     }
  93. }
  94.  
  95.  
  96. /*********    *********    **********    *************/
  97. int Redirect( argv )
  98. char *argv[];
  99. {
  100. char * cur = argv[0] + 1; /* Start looking at second char */
  101. int  handle1 = -1;    /* Handle directed from */
  102. int  handle2 = -1;    /* Handle directed to */
  103. int  append = FALSE;    /* Append to output file? */
  104. int  numargs = 2;    /* Number of command line arguments used */
  105. int  index;        /* Used for distinguishing cases */
  106.  
  107.  
  108.     switch ( *cur )
  109.     {
  110.         case 'a' : append = TRUE;
  111.         case 'r' : cur++;
  112.                break;
  113.         default  : printf( "Mal-formed switch: '%s'\n", cur - 1 );
  114.                exit( BAD_SWITCH );
  115.     }
  116.     index = strspn( cur, DIGITS ); /* Find first non-digit */
  117.     if ( cur[ index ] == '\0'  &&  index ) /* If it's end-of-string, and
  118.                           string len > 1, then we're
  119.                           looking at -r# filename */
  120.     {
  121.         if ( !sscanf( cur, "%d" , &handle1 ) )
  122.         {
  123.             printf( "Bad handle in switch expression: '%s'\n",
  124.                 cur );
  125.             exit( BAD_SWITCH );
  126.         }
  127.         cur = argv[1];
  128.     }
  129.     else { /* If first char is nul, we're looking at -r filename */
  130.         if ( *cur == '\0' ) cur = argv[1];
  131.         else    numargs = 1; /* Else we're looking at -rfilename */
  132.         }
  133.  
  134.  
  135.     if ( *cur == '#' )  /* handle2 is in command string */
  136.     {
  137.         if ( !sscanf( cur + 1, "%d", &handle2 ) )
  138.         {
  139.             printf( "Bad handle in switch expression: '%s'", 
  140.                 cur + 1 );
  141.             exit( BAD_SWITCH );
  142.         }
  143.     }
  144.     else    /* handle2 must be generated with open() */
  145.         if ( (handle2 = open( cur , 
  146.               O_WRONLY | (append ? O_APPEND : O_TRUNC ) | O_CREAT, 
  147.               S_IWRITE )) == -1 )
  148.         {
  149.             printf( cur );
  150.             perror( ": Open Error" );
  151.             exit( OPEN );
  152.         }
  153.  
  154.     if ( !(handle1 == -1) ) /* Handle to redirect is specified */
  155.     {
  156.         if ( dup2( handle2, handle1 ) == -1 )
  157.         {
  158.             perror( "Dup2 Error" );
  159.             exit( DUP );
  160.         }
  161.     }
  162.     else
  163.     {
  164.         if ( dup2( handle2, STDOUT ) == -1 )
  165.         {
  166.             perror( "Dup2 Error on Standard Out" );
  167.             exit( DUP );
  168.         }
  169.         if ( dup2( handle2, STDERR ) == -1 )
  170.         {
  171.             perror( "Dup2 Error on Standard Error" );
  172.             exit( DUP );
  173.         }
  174.     }
  175.  
  176.     return numargs;
  177. }
  178. MZ2 ─  wù/▒╓╙▓t*╞*Uï∞╕ΦdV╟F■â~}(╕PPΦpâ─╕PΦNâ─δïF■╤αFPΦcâ─F■╕ÄPï^■╤πïv 0Φ3â─ └t╓ïF■╤αFPï^■╤πïv 0Φìâ─@u$ï^■╤πïv 0Φ└â─╕æPΦ¡â─╕PΦΓâ─^ïσ]├Uï∞╕ Φ╩Vï^ï@ëF■╟F÷  ╟F⌠  ╟Fⁿ╟F·ï╪èÿ=at=rtï├HP╕₧PΦcâ─╕PΦÅâ─δ╟Fⁿ   F■╕╖P v■Φ╧â─ëF°ï╪ïv■Ç8u9 └t5ìF÷P╕┬PVΦìâ─ └u v■╕┼PΦâ─╕PΦ=â─ï^ïGëF■δ
  179. ï^■Ç?tφ╟F·ï^■Ç?#u*ìF⌠P╕∞Pï├@PΦ@â─ └uVïF■@P╕∩PΦ┬â─╕δ;╕ÇPâ~ⁿt╕δ╕
  180. P v■Φ@â─ëF⌠@u v■ΦÅâ─╕PΦ|â─╕PΦ▒â─â~÷ t v÷ v⌠Φtâ─@uM╕"δ7╕P v⌠Φ_â─@u╕-PΦ>â─╕PΦsâ─╕P v⌠Φ;â─@u╕HPΦ#include <stdio.h>
  181.  
  182. main()
  183. {
  184.     fprintf( stdout, "Hello, standard out\n" );
  185.     fprintf( stderr, "Hello, standard error\n" );
  186.     fprintf( stdaux, "Hello, standard aux\n" );
  187.     fprintf( stdprn, "Hello, standard prn\n" );
  188. }
  189. MZä  ├  ¢▄qe45f|╬Uï∞3└Φ9╕\P╕║PΦïâ─╕qP╕┬PΦ}â─╕êP╕╩PΦoâ─╕¥P╕╥PΦaïσ]├Yï▄+╪r
  190. ;|rïπ ßΘ"┐0ï6+≈ü■r╛·Ä╫ü─«√sΘüΣ■ 6ë&é6ë&Çï╞▒╙αH6ú~┤0═!<s*3└P║│┤    ═!╦DOS 2.0 or later required
  191. $≈ë6î├+▐≈█┤J═!6îεⁿ┐ä╣░+╧3└≤¬ΦbΦΦn
  192. Φn ╣+ß╛÷ïⁿ≤ñΦâ3φΦ≈■PΦz
  193. error 2000: Stack overflow
  194.  
  195. error 2003: Integer divide by 0
  196.  
  197. error 2002: Floating point not loaded
  198. ▒║2φ╗┤@═!╕ PΦE▒#║;δσ▒)║^δ▐Uï∞â∞WV vΦ_â─ï≡ìFP v vΦ┘â─ï° vVΦ⌡â─ï╟^_ïσ]├Uï∞Φ≡ Φn
  199. Σt
  200. Ç~u╞F■┼Γ╕%═!ïpπ╗ nïF┤L═!Uï∞Vïv @ü■║u6÷D u0èDÿï╪╤π÷çRu!╟D░èDÿï╪╤π╞çR╟DïDë╕δhü■┬tü■╥uZ÷DuTèDÿï╪╤π÷çRuEü>╛░t╟D░èDÿúäèDÿï╪╤π╞çRÇd√δ⌐╕PΦ╪ â─ëD └t
  201. èDÿúäÇLδ▄3└^ïσ]├Uï∞Vïvâ~uí╛9Du VΦ â─3└δhâ~tbü■║uèDÿPΦX â─ └t    VΦΓ
  202. â─δ0ü■┬tü■╥u8VΦ═
  203. â─áä$D÷Dt tΦA â─Çd≈δ
  204. èDÿï╪╤π╞çR3└ëëD^ïσ]├Uï∞V3÷╣52Σⁿ¼2αΓ√Ç⌠U■5uê&4δ
  205. Σt
  206. ║6╗╣%┤@═!2└ó5^ïσ]├Uï∞â∞WVï6·δ╕ P╕╘P 4Φ6 â─ └tâ╞â<uΣâ<t9ï<â╟ ╟F■èGÿëF·δèÿ= u2└δèï^■ F■êç N·Gâ~·u▐╟^_ïσ]├╗zü√ÇsS [CCδ≥├╗╕D═!r
  207. ÷┬ÇtÇÅ@Ky∞├┤0═!ú⌠├Äε&ï6,╕5═!ëΓîΣ╕%║á═!6ïpπ"6┼rî┌3█6 nsΘ6²6┼vî┌╗6 n├╣3█÷çt┤>═!CΓ≥├Uï∞Φ,     vΦB²ïσ]├Uï∞╕bΦí√WVïvìåó■úÆïFúÄïFúè╟á╟₧Ç<uΘIÇ<%tΘ
  208. ╟ÿ3└úûúåúÜúîúÉúêúñúª╟ö δ2Ç<-u ªδ'Ç<+u  û╟êδÇ< u
  209. â>ûu
  210.  êδ ñFèÿPΦâ─ └u┐V╕£PΦëâ─ï≡Ç<.u ÉFV╕ÿPΦrâ─ï≡Ç<lu╟îFÇ<uΘáèÿëå₧■=Et
  211. =Gt=Xu     åâå₧■ ïå₧■-c=w>└ô. º≥ Ü╟ñ╕
  212. PΦçâ─δP╕δ≥╕δφ3└PΦáδΘ╕δ⌡ ╢₧■Φδ█ï■δAα╝σσσεεεεεεε╬εεε╪ε╕εε╙â>átí₧δ FΘª■Ç=%tGÇ=u⌡ï╟+╞PVΦâ─ï≈Θè■^_ïσ]├Uï∞╕Φ°∙WVâ~
  213. t Üâ>îtïÄïïWëF°ëV·âÄδ)â>ÜtïÄïëF°╟F·δ
  214. ïÄïÖëF°ëV·âÄâ>ñt
  215. ïF° F·tïFδ3└úóï6Æâ>Üu*â~·}$â~
  216. u╞-FïF°ïV·≈╪â╥≈┌ëF°ëV·╟F÷δ╟F÷ï²â∩ vW v· v°Φâ─â>Ét WΦ▒â─ïÿ+╚ëN■δ╞0FïF■ N■ └≥èêâ>åt<a|Ç, FGÇ} uµâ>Üuíû êt â~÷u╕δ3└PΦUâ─^_ïσ]├Uï∞╕Φ╩°WV╟ö â~t╛íÄâÄëFⁿδ3ïÄïëFⁿâÄ └u╟Fⁿ0 vⁿΦ
  217. â─ï≡â>Ét
  218. 9ÿsï6ÿï>£+■â>ªuWΦâ─V vⁿΦmâ─â>ªtWΦ÷â─^_ïσ]├Uï∞╕Φ>°íÄëF■â>Éu╟ÿ 6å 6ÿ v 6Æ v■Φ▓â─
  219. â~gtâ~Guâ>ñuâ>ÿt
  220.  6ÆΦÄâ─â>ñtâ>ÿu
  221.  6ÆΦvâ─âÄ╟óíû êt v■ΦYâ─ └t╕δ3└PΦ$ïσ]├Uï∞3└Φƒ≈Vâ>áu8ïè Oâ|èFïèï7 ê*Σδ
  222.  6è vΦδâ─@u áδ ₧^ïσ]├Uï∞╕ΦQ≈WVâ>áuQïv ÷~Jδ3ïè Oâ|áöïèï? ê*Σδ 6è 6öΦÆâ─@u áï╞N └╞â>áuïF₧^_ïσ]├Uï∞╕ΦΦ÷WVïvï~â>áuLδ5ïè Oâ|èïèï ï┘ê*Σδ 6èèÿPΦ)â─@u áFï╟O └u─â>áuïF₧^_ïσ]├Uï∞╕
  223. Φ~÷WVï6Æ3└ëFⁿëF°ï>£VΦµâ─ëF·+°+~â>ªuÇ<-uâ>ö0u    ¼ÿPΦ¥■â─â>ö0t  ~â>ªtâ~t F°Φ^â>ót FⁿΦpâ>ªu&WΦ▒■â─â~t    â~°uΦ4â>ót    â~ⁿuΦC v·VΦ±■â─â>ªt
  224. ╟ö WΦt■â─^_ïσ]├Uï∞3└Φ╜⌡â>ût╕+δ╕ PΦ■ïσ]├Uï∞3└Φ₧⌡╕0PΦ≡²â─â>óuâ>åt╕Xδ╕xPΦ╙²â─ïσ]├Uï∞╕Φj⌡WVïvÇ<*uïÄâÄï?Fδ:3 Ç<0|3Ç<9.9>Éu Ç<0u╟ö0¼ÿï╧╤ß╤ß╧╤ß╚âΘ0ï∙Ç<0|Ç<9~πï^ë?ï╞^_ïσ]├Uï∞╕Φ⌡V╛7δ
  225. è8Fu╕δFÇ<uε3└^ïσ]├Å<Äε╛Ǽÿ3╥&Ç>⌠rePÄ,3└ï╚≈╤ï°≥«&8u∙â╟ï╚≈╤ï≈&èGA:αt<"t<    t< uδX╛üδ+O+■  t±ï╧B[ï├┴%■ +αïⁿ≤ñ░ ¬ï╦╛üδï╚$■+αïⁿ╕C ½≤ñï┴¬ï⌠Pï▄ï■¼
  226. └t Φ=t⌠NV ÷¼Φ8¬
  227. └t Φ)u≥╞E δ┌¬ï⌠KK;≤s¡çëD■δ≥ï▄ ╥u ë&° &<<    t< ├<"u¼
  228. └t╧<"u Ç} \uOδ¼u¬δΦ├Å>Äε3╔ï┴ïΘï∙Iï6, ÷tÄ╞≥«E«u·Eù@$■ï²╤σ┼Φ»≤ï╧ïⁿ²ï∞Ä▐3÷Iπ
  229. ë~EE¼¬
  230. └u·Γ≤ëNë&· &>Uï∞â∞WVïvèDÿ⌐ât÷D@t
  231. ÇL ╕  Θ╥÷Du≡ÇLÇd∩3└ëDï°ë~■÷DuèDÿï╪╤π÷çRt0ï<+|  ~W tèDÿPΦèâ─ëF■ïD@ë╟D ï\èFêδh÷DuLü■║u+èDÿPΦ∙â─ └u3 @╟D░èDÿï╪╤π╞çR╟▒δ║╕PΦ²â─ëD └tÇLδ¥ÇL┐WìFPèDÿPΦ
  232. â─ëF■9~■tΘ) èF*Σ^_ïσ]├╗Çü√ésS [CCδ≥├╗éü√äsS [CCδ≥├Φ╖≤Uï∞â∞WVïv3 VΦ|â─èD$<u<÷DuèDÿï╪╤π÷çRt'ï+DëFⁿ └~P tèDÿPΦââ─;FⁿtÇL ┐  ïDë╟Dï╟^_ïσ]├Uï∞ï^â√}â√| ÷ç@t╕δ3└]├Uï∞ï^ÇO■ïσ]├Uï∞VW╗Bâ?u)╕Φ└u3└Öδ$@$■úBúDû╟â╞╟D■■ ë6HïNî╪Ä└Φj_^ïσ]├Uï∞Wï~3└╣  ≥«ï┴@@≈╪_]├Uï∞WVïNπ.ï┘ï~ï≈3└╣  ≥«A≈┘;╦vï╦ï■ïv≤ªèD 3╔:E wtII≈╤ï┴^_]├Uï∞│Θ`Θ╦â∙εs°AÇß■ïwⁿ¡ï■¿tBH;┴sï╨≡¡¿t4┬ï≈ëD■δµï■t ∙ëL■+┴Hëδ∙■L■ï╞î┌ü·0t&îPë├&╞T=■ t%ï■≡¡¿t≥ï■H;┴s╜ï╨≡¡¿tΓ┬ï≈ëD■δµïG └tÄ╪δ&■Ttî╪=0t&ÄLï7δ╜ïw3└ΦY;╞t
  233. $@@ÿΦMt
  234. ■M■Φ tûNNδÜ3└Ö├QïE■¿t+╚IAA║ &;Rv╤Ωu⌡ï┴╞r┬r
  235. ≈╥#┬+╞Φ u≈╥╤Ωuσ3└Y├RQΦtWï■ï≡≥╟D■■ ëwï╓+╫JëU■XYZ├SP3╥RRP╕PΦ~â─â· Z[t ╥├Uï∞ï^Çg╧]├Uï∞â∞WV╛▓3 δèDÿ⌐ât VΦK²â─@tGâ╞96zsπï╟^_ïσ]├Uï∞ï^÷ç t╕B3╔ï╤═!sΘß÷çÇuΘüïNïV3└ⁿWVï≡ï·πe╕
  236. @≥«u2Qï╧+╩Iπ═!£≡¥s┤    δI └t/F╣║V┤@═!s┤    δ4 └t        Microsoft Macro Assembler 4.00 and Utilities
  237.                     Correction Notice
  238.  
  239.                  Utility for Redirection
  240.                     December 11, 1985
  241.  
  242.  
  243.  
  244. With pre-4.0 versions of MASM, it is possible to redirect
  245. the Assembler's output.  For example, 
  246.  
  247.        MASM example; >errors.dat
  248.  
  249. will send the Assembler's error messages to 'errors.dat',
  250. instead of to the console.  However, the above command will
  251. not redirect error messages with MASM 4.0.
  252.  
  253. MASM 4.0 sends error messages to standard error, one of the
  254. MS-DOS standard device handles.  It is not possible to
  255. redirect output from MASM 4.0 because MS-DOS does not allow
  256. redirection of standard error from the console.  This disk
  257. contains a utility which allows you to run MASM with
  258. standard handles redirected.  The files on this disk are:
  259.  
  260. WRITE.C
  261. WRITE.EXE
  262. E.C
  263. E.EXE
  264. README
  265.  
  266.  
  267. The following is a description of the files and their
  268. purpose:
  269.  
  270. WRITE.EXE
  271.  
  272. Allows you to determine where information for standard
  273. output, standard error, standard auxiliary (usually serial
  274. port), and standard printer (usually parallel port) will be
  275. directed.  The source code for the program is WRITE.C.
  276.  
  277. E.EXE
  278.  
  279. Executes a program after redirection of standard handles has
  280. taken place.  The program accepts arguments of the form:
  281.  
  282. e -r file command         stdout and stderr to file
  283. e -r #hnd command         stdout and stderr to handle hnd
  284. e -rhnd file command    handle hnd to file
  285. e -rhnd1 #hnd2 command    handle hnd1 to handle hnd2
  286.  
  287. To append in addition to redirecting, use -a instead of -r.
  288.  
  289. The standard handles are:
  290.  
  291. 0 - standard input (not useful here)
  292. 1 - standard output
  293. 2 - standard error
  294. 3 - standard auxiliary
  295. 4 - standard printer
  296.  
  297.  
  298. The following are examples of command lines:
  299.  
  300. e -r out.dat masm test,,test;
  301.  
  302. send all standard output and standard error output to the
  303. file 'out.dat'.  Note that due to the difference in the way
  304. C stream level stdout and stderr are handled, 'out.dat' may
  305. contain output in a different order from that seen on the
  306. screen.
  307.  
  308. e -r #4 masm test,,test;
  309.  
  310. send all standard output and standard error output to the
  311. standard printer
  312.  
  313. e -r1 out.dat -r2 errs.dat masm test;
  314.  
  315. -- send standard output to file 'out.dat'
  316. -- send standard error to file 'errs.dat'
  317.  
  318. e -r4 #1 masm test;
  319.  
  320. send standard printer data to standard output (console)
  321.  
  322. e -r1 nul -a2 errlog.dat -r4 out.dat masm test;
  323.  
  324. -- throw away standard output
  325. -- append standard error to errlog.dat
  326. -- send standard printer into out.dat
  327.  
  328. The source code for the program is E.C.
  329.