/* * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd * http://www.trevorwishart.co.uk * http://www.composersdesktop.com * This file is part of the CDP System. The CDP System is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The CDP System is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the CDP System; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * get Nth column from a file of columned data * (skipping M lines at start of file) */ #include #include #include #include #include #define PROG "GETCOL" #define ENDOFSTR '\0' FILE *fp1, *fpout; char *skip_column(char *,int,char *); char *skip_column_wanted(char *,int,char *); void usage(void), logo(void); int ignore_s_and_e = 0, ignore_c = 0; int sloom = 0; int sloombatch = 0; const char* cdp_version = "7.1.0"; int main(int argc,char *argv[]) { char temp[2000], *p, *q; int n, skip=0, column, cnt=0; if(argc==2 && (strcmp(argv[1],"--version") == 0)) { fprintf(stdout,"%s\n",cdp_version); fflush(stdout); return 0; } /* VERSION 3 */ if(argc < 2) usage(); if(!strcmp(argv[1],"#")) { sloom = 1; argv++; argc--; } else if (!strcmp(argv[1],"##")) { p = argv[0]; argc--; argv++; argv[0] = p; sloombatch = 1; } if(!strcmp(argv[argc-1],"-e")) { ignore_s_and_e = 1; argc--; } else if(!strcmp(argv[argc-1],"-ec")) { ignore_c = 1; argc--; } if(argc<4 || argc>5) usage(); if((fp1 = fopen(argv[1],"r"))==NULL) { fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[1]); fflush(stdout); usage(); } if((fpout = fopen(argv[2],"w"))==NULL) { fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[2]); fflush(stdout); usage(); } if(sscanf(argv[3],"%d",&column)!=1) { fprintf(stdout,"ERROR: Cannot read column value.\n"); fflush(stdout); usage(); } if(column<1) { fprintf(stdout,"ERROR: Column value cannot be less than 1.\n"); fflush(stdout); usage(); } column--; if(argc==5 && sscanf(argv[4],"%d",&skip)!=1) { fprintf(stdout,"ERROR: Cannot read skip value.\n"); fflush(stdout); usage(); } for(n=0;n