root/trunk/splitm.c

Revision 389, 1.7 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

Line 
1#include <stdio.h>
2#include <string.h>
3#include <ctype.h>  /* tolower */
4#include <stdlib.h> /* exit */
5
6#define PC    0
7#define MPE   0
8#define ANSI  0
9#define TRACE 0
10
11#if PC
12#include <process.h>
13#endif
14
15#if ANSI
16void erro(char *s1, char *s2);
17#else
18void erro();
19#endif
20
21char line[16*BUFSIZ+1];
22
23void main(argc,argv)
24int argc;
25char *argv[];
26{
27    FILE *fp;
28    char filn[64+1];
29    char *p,*q;
30    long count,skipl;
31
32    if (argc > 1) {
33        if (sscanf(argv[1],"%ld",&skipl) != 1)
34            erro("fatal: ",argv[1]);
35        while (skipl-- > 0) gets(line);
36    }
37
38    p=gets(line);
39    count=0;
40
41    while (p) {
42
43        if (strncmp(line,"/******",7))
44            erro("not 7 aster: ",line);
45
46        gets(line); sscanf(line,"%s",filn);
47        if (argc > 2) {
48            for (q=filn; *q ; q++)
49                if (*q == '.') {
50                    *q='\0';
51                    break;
52                }
53        }
54        for (q=filn; *q ; q++) 
55                if (*q>='A' && *q<='Z') *q = tolower(*q);
56        printf("\nWriting file %s.. \n",filn);
57#if MPE
58        fp=fopen(filn,"w R80");
59        fprintf(stderr,"\g\g+++ w R80");
60#else
61        fp=fopen(filn,"w");
62#endif
63        if (fp == NULL)
64            erro("Open error: ",filn);
65        gets(line); /* 2nd aster line */
66
67        while ((p=gets(line)) != NULL) {
68            if (strncmp(line,"}/******",8) == 0) {    /* final crlf missing */
69                fprintf(fp,"}\n");
70                count++;
71                strcpy(line,"/******");
72            }
73            if (strncmp(line,"/******",7)) {
74                fprintf(fp,"%s\n",line);
75                count++;
76#if TRACE
77 printf("%6ld: %s",count,line);
78 getchar();
79#endif
80            }
81            else {
82                printf("%ld lines written\n",count);
83                fclose(fp);
84                count=0;
85                break;
86            }
87        }
88    }
89
90    if (count)
91        printf("%ld lines written\n",count);
92       
93    exit(0);
94}
95
96void erro(s1,s2)
97char *s1,*s2;
98{
99    fprintf(stderr,"\n%s%s\n\n",s1,s2);
100    exit(1);
101}
Note: See TracBrowser for help on using the browser.