home *** CD-ROM | disk | FTP | other *** search
- /* Reunit les articles listes dans UUSPOOL:BATCH/<SYSNAME>
- * dans le fichier liste en parametre -- MSC94
- * Support: schaefer@alphanet.ch
- * CDate: 09/01/94
- * MDate: 09/01/94
- * PV: 1
- */
-
- #undef DEBUGGING
-
- #define BATCHFROM "UUNEWS:%s"
- #define BATCHINST "UUSPOOL:BATCH/%s"
- #define MAXPATHLEN 300 /* Some more thought here, please */
- #define MAXLINELENGTH 256
- #define TRUE 1
- #define FALSE 0
-
- #include <stdio.h>
- /* #include <fnctl.h> */
- #include <sys/stat.h>
-
- int create_batch_file(char *sysname, char *tofile);
- int cat_batch(FILE *tof, char *current_line);
- void convert_path(char *str);
- unsigned long get_file_length(char *file);
-
- int main(argc, argv)
- int argc;
- char *argv[];
- {
- if (argc < 3) {
- printf("%s sysname tofile\n", argv[0]);
- printf("%s: expected 2 args\n", argv[0]);
- exit(1);
- }
-
- #ifdef DEBUGGING
- printf("debug: syname='%s'\n", argv[1]);
- printf("debug: tofile='%s'\n", argv[2]);
- #endif
-
- if (create_batch_file(argv[1], argv[2]))
- exit(0);
- else
- exit(1);
- }
-
- int create_batch_file(sysname, tofile)
- char *sysname;
- char *tofile;
- {
- char instfile[MAXPATHLEN];
- FILE *instf;
- FILE *tof;
- int err = FALSE;
-
- sprintf(instfile, BATCHINST, sysname);
-
- if (instf = fopen(instfile, "r")) {
- if (tof = fopen(tofile, "w")) {
- int ok = TRUE;
- char current_line[MAXPATHLEN];
-
- while (ok && fgets(current_line, sizeof(current_line), instf)) {
- #ifdef DEBUGGING
- printf("todo: %s\n", current_line);
- #endif
- convert_path(current_line); /* will also remove the leading \n */
- if (!(cat_batch(tof, current_line))) {
- ok = FALSE;
- err = TRUE;
- printf("cat_batch failed on %s\n", current_line);
- }
- }
- fclose(tof);
- }
- else {
- err = TRUE;
- printf("open %s failed\n", tofile);
- }
- fclose(instf);
- }
- else {
- err = TRUE;
- printf("open %s failed\n", instfile);
- }
- return !err;
- }
-
- int cat_batch(tof, current_line)
- FILE *tof;
- char *current_line;
- {
- char buf[MAXLINELENGTH];
- char filename[MAXPATHLEN];
- FILE *fi;
-
- sprintf(filename, BATCHFROM, current_line);
- if (fi = fopen(filename, "r")) {
-
- #ifdef DEBUGGING
- printf("file is %ld bytes long\n", get_file_length(filename));
- #endif
- fprintf(tof, "#! rnews %.6d\n", get_file_length(filename));
-
- while (fgets(buf, sizeof(buf), fi)) /* here we need the \n */
- fputs(buf, tof);
- fclose(fi);
- return TRUE;
- }
- else {
- printf("open %s failed\n", current_line);
- return FALSE;
- }
- }
-
- void convert_path(str)
- char *str;
- {
- while (*str != '\n') {
- if (*str == '.')
- *str = '/';
- str++;
- }
- *str = '\0';
- }
-
- unsigned long get_file_length(file)
- char *file;
- {
- struct stat stat_buf;
-
- stat(file, &stat_buf); /* highly non portable ? */
- /* we should do something with returncode ... */
-
- return stat_buf.st_size;
- }
-