VPDF compiles and links but exits early after start.
[AROS-Contrib.git] / rexx / src / main.c
blobe01f6daf0e76ba10c0f80df841c8884687f26a89
1 /*
2 * $Header$
3 * $Log$
4 * Revision 1.1 2001/04/04 05:43:39 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.4 1999/11/26 13:13:47 bnv
8 * Added: A filter option.
10 * Revision 1.3 1999/05/26 16:48:06 bnv
11 * Gene corrections in RXCONIO
13 * Revision 1.2 1999/02/10 15:43:16 bnv
14 * Additions from Generoso Martello
16 * Revision 1.1 1998/07/02 17:34:50 bnv
17 * Initial revision
20 #include <stdio.h>
21 #include <string.h>
22 #include <lstring.h>
24 #include <rexx.h>
25 #include <rxdefs.h>
27 /* ------- Includes for any other external library ------- */
28 #ifdef RXCONIO
29 extern RxConIOInitialize();
30 #endif
32 /* --------------------- main ---------------------- */
33 int
34 main(int ac, char *av[])
36 Lstr args, tracestr, file;
37 int ia,ir;
38 bool input, loop_over_stdin;
40 input = loop_over_stdin = FALSE;
41 LINITSTR(args);
42 LINITSTR(tracestr);
43 LINITSTR(file);
45 if (ac<2) {
46 puts("\nsyntax: rexx [-[trace]|-F] <filename> <args>...\n\trexx -\tto use stdin\n\trexx -F\tloop over standard input\n\t\t\'linein\' contains each line from stdin.\n");
47 puts(VERSION);
48 puts("Author: "AUTHOR);
49 puts("To be distributed with AROS Operating System.\n");
50 return 0;
52 #ifdef __DEBUG__
53 __debug__ = FALSE;
54 #endif
56 /* --- Initialise --- */
57 RxInitialize(av[0]);
59 /* --- Register functions of external libraries --- */
60 #ifdef RXCONIO
61 RxConIOInitialize();
62 #endif
64 /* --- scan arguments --- */
65 ia = 1;
66 if (av[ia][0]=='-') {
67 if (av[ia][1]==0)
68 input = TRUE;
69 else
70 if (av[ia][1]=='F')
71 loop_over_stdin = input = TRUE;
72 else
73 Lscpy(&tracestr,av[ia]+1);
74 ia++;
75 } else
76 if (av[ia][0]=='?' || av[ia][0]=='!') {
77 Lscpy(&tracestr,av[ia]);
78 ia++;
81 /* --- let's read a normal file --- */
82 if (!input && ia<ac) {
83 /* prepare arguments for program */
84 for (ir=ia+1; ir<ac; ir++) {
85 Lcat(&args,av[ir]);
86 if (ir<ac-1) Lcat(&args," ");
88 RxRun(av[ia],NULL,&args,&tracestr,NULL);
89 } else {
90 if (ia>=ac)
91 Lread(STDIN,&file,LREADFILE);
92 else {
93 /* Copy a small header */
94 if (loop_over_stdin)
95 Lcat(&file,"do forever;"
96 "linein=read();"
97 "if eof(0) then exit;");
98 for (;ia<ac; ia++) {
99 Lcat(&file,av[ia]);
100 if (ia<ac-1) Lcat(&file," ");
102 /* and a footer */
103 if (loop_over_stdin)
104 Lcat(&file,";end");
106 RxRun(NULL,&file,&args,&tracestr,NULL);
109 /* --- Free everything --- */
110 RxFinalize();
111 LFREESTR(args);
112 LFREESTR(tracestr);
113 LFREESTR(file);
115 #ifdef __DEBUG__
116 if (mem_allocated()!=0) {
117 fprintf(STDERR,"\nMemory left allocated: %ld\n",mem_allocated());
118 mem_list();
120 #endif
122 return RxReturnCode;
123 } /* main */