static char *sccsid
= "@(#)addbib.c 4.2 (Berkeley) 11/2/84";
char prompt
[20]; /* prompt user for entry */
char keylet
[5]; /* key letter for database */
int entries
= 10; /* total number of entries in bibskel */
int abstract
= 1; /* asking for abstracts is the default */
usage() /* print proper usage and exit */
puts("Usage: addbib [-p promptfile] [-a] database");
puts("\t-p: the promptfile defines alternate fields");
puts("\t-a: don't include prompting for the abstract");
main(argc
, argv
) /* addbib: bibliography entry program */
puts("You must specify a bibliography file (database).");
for (i
= 1; argv
[i
][0] == '-'; i
++)
puts("Not enough arguments for -p option.");
else if (argv
[i
][1] == 'a')
puts("No bibliofile specified after -a.");
else /* neither -p nor -a */
printf("Invalid command line flag: %s\n", argv
[i
]);
puts("Too many arguments with no options.");
if ((fp
= fopen(argv
[i
], "a")) == NULL
)
addbib(fp
, argv
[i
]); /* loop for input */
addbib(fp
, argv
) /* add entries to a bibliographic database */
int i
= 0, firstln
, repeat
= 0, escape
= 0;
printf("Instructions? ");
fgets(line
, BUFSIZ
, stdin
);
if (line
[0] == 'y' || line
[0] == 'Y')
for (i
= 0; i
< entries
; i
++)
printf("%s\t", bibskel
[i
].prompt
);
if (fgets(line
, BUFSIZ
, stdin
) == NULL
)
if (line
[0] == '-' && line
[1] == '\n')
printf("Too far back.\n");
else if (line
[strlen(line
)-2] == '\\')
line
[strlen(line
)-2] = '\n';
line
[strlen(line
)-1] = NULL
;
bibskel
[i
].keylet
, line
);
fgets(line
, BUFSIZ
, stdin
);
if (line
[strlen(line
)-2] == '\\')
line
[strlen(line
)-2] = '\n';
line
[strlen(line
)-1] = NULL
;
else if (line
[0] != '\n')
fprintf(fp
, "%s %s", bibskel
[i
].keylet
, line
);
puts(" Abstract: (ctrl-d to end)");
while (fgets(line
, BUFSIZ
, stdin
))
if (firstln
&& line
[0] != '%')
fflush(fp
); /* write to file at end of each cycle */
fgets(line
, BUFSIZ
, stdin
);
if (line
[0] == 'e' || line
[0] == 'v')
if (line
[0] == 'q' || line
[0] == 'n')
trim(line
) /* trim line of trailing white space */
bibedit(fp
, cmd
, arg
) /* edit database with edit, ex, or vi */
if (cmd
[0] == 'v' && cmd
[1] == 'i')
execlp(cmd
, cmd
, "+$", arg
, NULL
);
else /* either ed, ex, or edit */
execlp(cmd
, cmd
, arg
, NULL
);
signal(SIGQUIT
, SIG_IGN
);
signal(SIGQUIT
, SIG_DFL
);
if ((fp
= fopen(arg
, "a")) == NULL
)
instruct() /* give user elementary directions */
puts("Addbib will prompt you for various bibliographic fields.");
puts("If you don't need a particular field, just hit RETURN,");
puts("\tand that field will not appear in the output file.");
puts("If you want to return to previous fields in the skeleton,");
puts("\ta single minus sign will go back a field at a time.");
puts("\t(This is the best way to input multiple authors.)");
puts("If you have to continue a field or add an unusual field,");
puts("\ta trailing backslash will allow a temporary escape.");
puts("Finally, (without -a) you will be prompted for an abstract.");
puts("Type in as many lines as you need, and end with a ctrl-d.");
puts("To quit, type `q' or `n' when asked if you want to continue.");
puts("To edit the database, type `edit', `vi', or `ex' instead.");
rd_skel(arg
) /* redo bibskel from user-supplied file */
if ((pfp
= fopen(arg
, "r")) == NULL
)
fprintf(stderr
, "Promptfile ");
for (entry
= 0; fgets(str
, BUFSIZ
, pfp
); entry
++)
for (i
= 0; str
[i
] != '\t' && str
[i
] != '\n'; i
++)
bibskel
[entry
].prompt
[i
] = str
[i
];
bibskel
[entry
].prompt
[i
] = NULL
;
fprintf(stderr
, "No tabs between promptfile fields.\n");
fprintf(stderr
, "Format: prompt-string <TAB> %%key\n");
for (i
++, j
= 0; str
[i
] != '\n'; i
++, j
++)
bibskel
[entry
].keylet
[j
] = str
[i
];
bibskel
[entry
].keylet
[j
] = NULL
;
fprintf(stderr
, "Too many entries in promptfile.\n");