Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use arguments as files to read #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions eqn.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ static char eqn_lineup[128]; /* the lineup horizontal request */
static int eqn_lineupreg; /* the number register holding lineup width */
static int eqn_mk; /* the value of MK */

FILE *e_fp;

static struct box *eqn_box(int flg, struct box *pre, int sz0, char *fn0);

/* read equations until delim is read */
Expand Down Expand Up @@ -540,25 +542,9 @@ void errdie(char *msg)
exit(1);
}

int main(int argc, char **argv)
{
void doeqn(void) {
struct box *box;
char eqnblk[128];
int i;
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-' || !argv[i][1])
break;
if (argv[i][1] == 'c') {
def_choppedset(argv[i][2] ? argv[i] + 2 : argv[++i]);
} else {
fprintf(stderr, "Usage: neateqn [options] <input >output\n\n"
"Options:\n"
" -c chars \tcharacters that chop equations\n");
return 1;
}
}
for (i = 0; def_macros[i][0]; i++)
src_define(def_macros[i][0], def_macros[i][1]);
while (!tok_eqn()) {
reg_reset();
eqn_mk = 0;
Expand All @@ -579,6 +565,42 @@ int main(int argc, char **argv)
nregrm(eqn_lineupreg);
box_free(box);
}
}

int main(int argc, char **argv)
{
int i;
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-' || !argv[i][1])
break;
if (argv[i][1] == 'c') {
def_choppedset(argv[i][2] ? argv[i] + 2 : argv[++i]);
} else {
fprintf(stderr, "Usage: neateqn [options] <input >output\n\n"
"Options:\n"
" -c chars \tcharacters that chop equations\n");
return 1;
}
}
for (int j = 0; def_macros[j][0]; j++)
src_define(def_macros[j][0], def_macros[j][1]);

if (i == argc) {
e_fp = stdin;
doeqn();
} else {
for (; i < argc; i++) {
e_fp = fopen(argv[i], "r");
if (!e_fp) {
fprintf(stderr, "neateqn: %s:", *argv);
perror("");
return 1;
}

doeqn();
}
}

src_done();
return 0;
}
1 change: 1 addition & 0 deletions eqn.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,5 @@ extern int e_columnsep;
extern int e_baselinesep;
extern int e_bodyheight;
extern int e_bodydepth;
extern FILE *e_fp;
void def_set(char *name, int val);
2 changes: 1 addition & 1 deletion src.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void src_pop(void)

static int src_stdin(void)
{
int c = fgetc(stdin);
int c = fgetc(e_fp);
if (c == '\n')
lineno++;
return c;
Expand Down