/* * 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 * */ #include #include #include #include #define CDP_PROPS_CNT (34) #define CDP_PROGRAM_DIR ("cdprog") #define ENDOFSTR ('\0') #define NUMERICVAL_MARKER ('@') void get_progname(int progno,char *p); int skipwordandspace(char **q); int getvalandskipspace(char **q,int *ival); int getwordandskipspace(char **q,char *j); void get_modename(int progno,int modeno,char *p); void to_ucase(char *str); const char* cdp_version = "7.1.0"; int main(int argc,char *argv[]) { char temp[1000], temp2[1000], temp3[32], c, *p, *q, *r; FILE *fpo, *fpi; int OK, i, isprog = 1, linecnt = 1, filecnt, progno, modeno; if(argc==2 && (strcmp(argv[1],"--version") == 0)) { fprintf(stdout,"%s\n",cdp_version); fflush(stdout); return 0; } if(argc != 3) { fprintf(stderr,"USAGE: histconv infile outfile\n"); return 1; } if((fpi = fopen(argv[1],"r"))==NULL) { fprintf(stderr,"Cannot open file %s\n",argv[1]); return 1; } if((fpi = fopen(argv[1],"r"))==NULL) { fprintf(stderr,"Cannot open file %s to read\n",argv[1]); return 1; } if((fpo = fopen(argv[2],"w"))==NULL) { fprintf(stderr,"Cannot open file %s to write\n",argv[2]); return 1; } while(fgets(temp,1000,fpi)!=NULL) { if(strlen(temp) <= 0) { fprintf(fpo,"Insufficient information on line %d\n",linecnt); isprog = !isprog; linecnt++; continue; } if(isprog) { p = temp; if(*p == '#') { p++; p += strlen(CDP_PROGRAM_DIR); p++; if(!isprint(*p)) { fprintf(fpo,"Invalid program name on line %d\n",linecnt); isprog = !isprog; linecnt++; continue; } q = temp; while(*p != ENDOFSTR) { /* Get rid of directory name */ *q = *p; q++; p++; } *q = ENDOFSTR; p = temp; if(!skipwordandspace(&p)) { fprintf(fpo,"Not enough words on line %d\n",linecnt); isprog = !isprog; linecnt++; continue; } c = *p; *p = ENDOFSTR; strcpy(temp2,temp); q = temp2; to_ucase(temp2); *p = c; if(!getvalandskipspace(&p,&progno)) { fprintf(fpo,"Failed to get program number on line %d\n",linecnt); isprog = !isprog; linecnt++; continue; } r = temp3; get_progname(progno,r); to_ucase(temp3); strcat(temp2,temp3); strcat(temp2," "); if(!getvalandskipspace(&p,&modeno)) { fprintf(fpo,"Failed to get mode number on line %d\n",linecnt); isprog = !isprog; linecnt++; continue; } get_modename(progno,modeno,r); to_ucase(temp3); strcat(temp2,temp3); strcat(temp2," "); if(!getvalandskipspace(&p,&filecnt)) { fprintf(fpo,"Failed to get filecnt on line %d\n",linecnt); isprog = !isprog; linecnt++; continue; } if(*p == ENDOFSTR) { fprintf(fpo,"Insufficient information on line %d\n",linecnt); isprog = !isprog; linecnt++; continue; } if(filecnt > 0) { OK = 1; for(i=0;i 96) { cc = (char)(*p - 32); *p = cc; } p++; } }