split.c
1 /* ************************************************************************ 2 * file: split.c Part of CircleMud * 3 * Usage: split one large file into multiple smaller ones, with index * 4 * Written by Jeremy Elson * 5 * All Rights Reserved * 6 * Copyright (C) 1993 The Trustees of The Johns Hopkins University * 7 ************************************************************************* */ 8 9 /* 10 * This utility is meant to split a large file into multiple smaller ones, 11 * mainly to help break huge world files (ala Diku) into zone-sized files 12 * that are easier to manage. 13 * 14 * At each point in the original file where you want a break, insert a line 15 * containng "=filename" at the break point. 16 */ 17 18 #define INDEX_NAME "index" 19 #define BSZ 256 20 #define MAGIC_CHAR '=' 21 22 #include "conf.h" 23 #include "sysdep.h" 24 25 int main(void) 26 { 27 char line[BSZ + 1]; 28 FILE *index = 0, *outfile = 0; 29 30 if (!(index = fopen(INDEX_NAME, "w"))) { 31 perror("error opening index for write"); 32 exit(1); 33 } 34 while (fgets(line, BSZ, stdin)) { 35 if (*line == MAGIC_CHAR) { 36 *(strchr(line, '\n')) = '\0'; 37 if (outfile) { 38 /* fputs("$\n", outfile);*/ 39 fclose(outfile); 40 } 41 if (!(outfile = fopen((line + 1), "a"))) { 42 perror("Error opening output file"); 43 exit(0); 44 } 45 fputs(line + 1, index); 46 fputs("\n", index); 47 } else if (outfile) 48 fputs(line, outfile); 49 } 50 51 fputs("$\r\n", index); 52 fclose(index); 53 if (outfile) 54 fclose(outfile); 55 56 return (0); 57 }