9c0a8fd2d62b279b39fed6071827eed8f0d740e7
[mw/micromonitor-lm32.git] / umon_main / target / misc / newlib_main.c
1 /* newlib_main.c:
2  * This is an example of some of the stuff that "just works" as a result
3  * of including the newlib_hooks.c file with a MicroMonitor application.
4  */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/stat.h>
8 #include "monlib.h"
9
10 void
11 input_stuff(void)
12 {
13         char    c;
14         int             d1, d2, d3;
15
16         /* getchar():
17          */
18         printf("Gimme a character...\n");
19         c = getchar();
20         printf("You gave me '%c'\n",c);
21
22         /* scanf():
23          */
24         printf("Enter 3 whitespace-delimited integers\n");
25         scanf("%d %d %d",&d1,&d2,&d3);
26         printf("%d %d %d\n",d1,d2,d3);
27 }
28
29 void
30 env_stuff(void)
31 {
32         printf("IPADD: %s\n",getenv("IPADD"));
33         setenv("abc","def",1);
34 }
35
36 void
37 file_read(char *name)
38 {
39         int             i=1;
40         FILE    *fp;
41         char    line[256];
42
43         if ((fp = fopen(name,"r")) != (FILE *)NULL) {
44                 while(fgets(line,sizeof(line),fp) != NULL) {
45                         printf("%3d: ",i++);
46                         printf("%s",line);
47                 }
48                 fclose(fp);
49         }
50 }
51
52 void
53 file_write(char *name)
54 {
55         FILE    *fp;
56
57         if ((fp = fopen(name,"w")) != (FILE *)NULL) {
58                 printf("Writing three lines...\n");
59                 fwrite("this is line1\n",14,1,fp);
60                 fwrite("this is line2\n",14,1,fp);
61                 fwrite("this is line3\n",14,1,fp);
62                 fclose(fp);
63         }
64 }
65
66 void
67 file_append(char *name)
68 {
69         FILE    *fp;
70
71         if ((fp = fopen(name,"a")) != (FILE *)NULL) {
72                 printf("Writing three lines...\n");
73                 fwrite("this is line4\n",14,1,fp);
74                 fwrite("this is line5\n",14,1,fp);
75                 fwrite("this is line6\n",14,1,fp);
76                 fclose(fp);
77         }
78 }
79
80 void
81 file_script(void)
82 {
83         FILE    *fp;
84
85         if ((fp = fopen("script,e,test","w")) != (FILE *)NULL) {
86                 printf("Writing three lines...\n");
87                 fwrite("echo abcde\n",11,1,fp);
88                 fwrite("echo fghij\n",11,1,fp);
89                 fwrite("echo klmno\n",11,1,fp);
90                 fclose(fp);
91         }
92 }
93
94 int
95 main(int argc, char *argv[])
96 {
97         fprintf(stderr,"Hello errored world\n");
98 mon_sendenetpkt(0,0);
99 mon_recvenetpkt(0,0);
100
101 //      input_stuff();
102 //      env_stuff();
103         file_read("monrc");
104         file_write("filex");
105         file_append("filex");
106         file_script();
107         exit(0);
108 }