-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgen_clis.c
135 lines (126 loc) · 3.61 KB
/
gen_clis.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* gen_clis.c
*
* Copyright 2019 Ryan Koehler, VerdAscend Sciences, ryan@verdascend.com
*
* The programs and source code of the vertools collection are free software.
* They are distributed in the hope that they will be useful,
* WITHOUT ANY WARRANTY OF FITNESS FOR ANY PARTICULAR PURPOSE.
*
* Permission is granted for research, educational, and possibly commercial use
* and modification as long as 1) Code and any derived works are not
* redistributed for any fee, and 2) Proper credit is given to the authors.
* If you wish to include this software in a product, or use it commercially,
* please contact the authors.
*
* See https://www.verdascend.com/ for more
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define __MAIN__
#include "prim.h"
#define VERSION_S "gen_clis Version 0.32"
#define INFILE_S "cfile.lis"
#define DEF_EXT_S "cfl"
int main(int argc, char **argv);
void Gen_ClisUse(void);
int Gen_ClisfileI(int argc, char **argv);
/**************************************************************************/
int main(int argc, char **argv)
{ Init(argc,argv); exit(AllDoneI(Gen_ClisfileI(argc,argv),NULL)); }
/**************************************************************************/
void Gen_ClisUse()
{
VersionSplash(NULL,VERSION_S,"# ",TRUE);
printf("Usage: ...[options]\n");
printf(" -i XXX Read in XXX (default = %s)\n",INFILE_S);
printf(" -ext XXX Set extent to XXX (default = %s)\n",DEF_EXT_S);
}
/**************************************************************************/
int Gen_ClisfileI(int argc, char **argv)
{
int line,n,pb,com;
char bufS[DEF_BS],inS[NSIZE],outS[NSIZE],extS[NSIZE];
FILE *inPF, *outPF;
sprintf(inS,"%s",INFILE_S);
sprintf(extS,"%s",DEF_EXT_S);
if(!ParseArgsI(argc,argv,
"-i S -ext S",
inS,extS,
(int *)NULL))
{
Gen_ClisUse();
return(FALSE);
}
if(!(inPF = OpenUFilePF(inS,"r",NULL)))
{
return(FALSE);
}
outPF = NULL;
pb = TRUE;
com = FALSE;
line = n = 0;
while(fgets(bufS,LINEGRAB,inPF) != NULL)
{
line++;
if( (!com) && strstr(bufS,"/*") )
com = TRUE;
if( (com) && strstr(bufS,"*/") )
com = FALSE;
if(com)
continue;
if((pb) && (bufS[0] == '#'))
{
INIT_S(outS);
sscanf(bufS,"# %s",outS);
if(NO_S(outS))
{
printf("Error on line %d\n",line);
printf("Need name to follow '#'\n");
printf("ABORTING\n");
break;
}
strcat(outS,".");
strcat(outS,extS);
if(!(outPF = OpenUFilePF(outS,"w",NULL)))
{
printf("ABORTING\n");
break;
}
GetFilePartsI(outS,NULL,bufS,NULL);
fprintf(outPF,"# Source listing for %s\n",bufS);
fprintf(outPF,"# Generated by gen_clis\n");
FillDateString(bufS);
fprintf(outPF,"# %s\n",bufS);
pb = FALSE;
n++;
continue;
}
if(!outPF)
{
continue;
}
if((!isgraph(INT(bufS[0]))) || (strstr(bufS,"break")))
{
pb = TRUE;
if(outPF)
{
FILECLOSE(outPF);
printf("NEW FILE: %s\n",outS);
}
continue;
}
pb = FALSE;
fputs(bufS,outPF);
}
if(outPF)
{
FILECLOSE(outPF);
printf("NEW FILE: %s\n",outS);
}
FILECLOSE(inPF);
return(TRUE);
}