/* Copyright (C) 1993 Bell-Northern Research This file is part of vsplit. Vmkr is distributed in the hope that it will be useful, but without any warranty. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Everyone is granted permission to copy, modify and redistribute vsplit, but only under the conditions described in the document "vsplit copying permission notice". An exact copy of the document is supposed to have been given to you along with vsplit so that you can know how you may redistribute it all. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. */ #include "typedef.h" #define VERSION "1.2" #define CREATE_DATE "Nov 19/92 14:27" /* * Author : Himanshu M. Thaker * Date : July 29, 1991 */ struct names *hashtab[BASE]; struct names *fname_tab[BASE]; int return_code; int interactive; int verbose; char dir_name[MAXTOKEN]; /* holds the directory name */ main(argc, argv) int argc; char *argv[]; { void free_tokens(); struct token_holder *get_tokens(); char file_name[MAXTOKEN]; char token[MAXTOKEN]; struct token_holder *tokens; int i; int err, err_val; char *s; char ans; int dont_move_source; int c; int errflg; extern int optind, opterr; extern char *optarg; int cont; return_code = 0; dont_move_source = FALSE; verbose = FALSE; err = FALSE; errflg = 0; interactive = FALSE; strcpy(dir_name, ""); while ((c = getopt (argc, argv, "ivd:n?")) != EOF) switch (c) { case 'i': interactive = TRUE; break; case 'v': verbose = TRUE; break; case 'd': strcpy(dir_name, optarg); dont_move_source = TRUE; break; case 'n': dont_move_source = TRUE; break; case '?': errflg++; } if (errflg) { fprintf(stderr,"usage: vsplit [-ivn] [-d directory] file1 [file2]...\n"); exit (2); } fprintf(stderr, "BNR vsplit version %s (%s)\n", VERSION, CREATE_DATE); fprintf(stderr, "Copyright (C) 1991 Bell-Northern Research\n"); fprintf(stderr, "Please email bugs/suggestions to hemi@bnr.ca\n"); /* * First, create the database of names. */ create_database(); /* * for all the files... */ for ( ; optind < argc; optind++) { sprintf(file_name, "%s", argv[optind]); /* * if the user has asked to be prompted before splitting files up, * print the message to the screen. */ cont = TRUE; if (interactive) { printf("\nFrom file '%s' :\n", file_name); tokens = get_tokens(file_name, 0); ans = 'x'; while ( (ans != 'y') && (ans != 'n') ) { printf("split this file into the above subfiles (y or n)? "); scanf("%s", &ans); if (ans == 'n') cont = FALSE; } free_tokens(tokens); } if (cont) { /* * at this point, we can split the file up. */ tokens = get_tokens(file_name, 1); free_tokens(tokens); /* * Finally, move the old file to .old_ */ if (dont_move_source == FALSE) { if (interactive) printf("moving '%s' to '.old_%s'\n",file_name,file_name); sprintf(token, "mv %s .old_%s", file_name, file_name); err_val = system(token); if (err_val == 127) printf("ERROR : couldn't move %s\n", file_name); } } } exit(return_code); } void free_tokens(tokens) struct token_holder *tokens; { struct token_holder *tmp_tokens, *tmp_tokens2; /* * this program frees up tokens starting at the point passed, until * it hits a null. */ while (tokens != NULL) { tmp_tokens = tokens->next; tmp_tokens2 = tokens; if (tokens->keywrd != NULL) free(tokens->keywrd); if (tokens->var1 != NULL) free(tokens->var1); if (tokens->var2 != NULL) free(tokens->var2); if (tokens->token != NULL) free(tokens->token); free(tokens); tokens = tmp_tokens; } }