[Trainsched-commit] csv2pdb .cvsignore, 1.1, 1.2 Makefile, 1.4, 1.5 csv2trainschedpdb.c, 1.7, 1.8 c
Brought to you by:
philm
|
From: Steve M. <sma...@us...> - 2009-05-16 08:07:49
|
Update of /cvsroot/trainsched/csv2pdb In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18585 Modified Files: .cvsignore Makefile csv2trainschedpdb.c csvformat.txt Log Message: Merge from PDB_VER2 branch. Index: .cvsignore =================================================================== RCS file: /cvsroot/trainsched/csv2pdb/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .cvsignore 14 Apr 2002 15:23:49 -0000 1.1 --- .cvsignore 16 May 2009 08:07:45 -0000 1.2 *************** *** 1 **** --- 1,2 ---- *.pdb + csv2trainschedpdb.exe \ No newline at end of file Index: csvformat.txt =================================================================== RCS file: /cvsroot/trainsched/csv2pdb/csvformat.txt,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** csvformat.txt 22 Jun 2001 18:53:21 -0000 1.1.1.1 --- csvformat.txt 16 May 2009 08:07:45 -0000 1.2 *************** *** 1,23 **** All line endings are Unix style (LF only) ! There are no " Fields are separated by tabs ! The file MUST NOT have an empty line at the end - First line: Station names separated by Tab ! The max length of a station name is 20 characters by default. - Second line: Days ! The max length of a day is 9 characters by default. ! - Third line ! Fields: - Line number in csv for 1st Day, 1st Direction ! - Line number in csv for 2nd Day, 1st Direction ! - Line number in csv for 3rd Day, 1st Direction ! - Line number in csv for 1st Day, 2nd Direction ! ... ! - Data ! times are of the form 00:00 in 24 hour format ! there must be at least 1 dash ('-') if no stop. ! ie: 00:00 00:15 00:20 01:40 ----- 15:50 --- 1,57 ---- All line endings are Unix style (LF only) ! There are no quote (" or ') character. Fields are separated by tabs ! The file MUST NOT have any empty lines at the end, but the last line MUST end with a LF. - First line: Station names separated by Tab ! The max length of a station name is 20 characters. ! - Second line: Days ! The max length of a day is 9 characters. ! ! - Third line: ! Starting row for timetable entries for each day and direction, each line number ! is separated by a Tab: ! Line number in csv for 1st Day, 1st Direction ! Line number in csv for 2nd Day, 1st Direction ! Line number in csv for 3rd Day, 1st Direction ! Line number in csv for 1st Day, 2nd Direction ! ... ! ! - Fourth line: ! Abbreviations separated by a Tab. ! The max length of an abbreviation is 5 characters. ! This line may be blank if the timetable does not use any abbreviations. ! ! - Fifth line: ! Abbreviation definitions separated by a Tab. ! The max length of an abbreviation definition is 23 characters. There should ! be the same number of abbreviation definitions as there are abbreviations. ! ! - Sixth line: ! Timetable notes. Any special notes from the service operator. '|' characters ! may be included to indicate line breaks. This line may be blank if there are ! no additional notes. ! ! - Seventh line onwards: ! Timetable data is of the form: ! <time>tab<abbreviation>tab<time>tab<abbreviation> ! There must be as many times as there are station names. Abbreviation is zero ! for none or the number of defined abbreviation on line 4 (starting a 1) If ! line 4 is blank then no abbreviation values are to be entered, ! i.e. <time>tab<time>tab<time>... ! ! Times are of the form 00:00 in 24 hour format. ! ! There must be at least 1 dash ('-') and no colon (':') if no stop. ! ! A '#' character may be used as a wildcard for hours where the times apply to every hour. ! ! e.g.: ! With Abbreviations: ! 00:00 0 00:15 0 00:20 1 01:40 1 ----- 0 15:50 ! Without Abbreviations: 00:00 00:15 00:20 01:40 ----- 15:50 Index: Makefile =================================================================== RCS file: /cvsroot/trainsched/csv2pdb/Makefile,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile 3 Apr 2003 13:54:35 -0000 1.4 --- Makefile 16 May 2009 08:07:45 -0000 1.5 *************** *** 2,6 **** # ! VERS=0.3 CC=gcc --- 2,6 ---- # ! VERS=1.0 CC=gcc *************** *** 34,38 **** rm -rf $(PROGRAM)-win-$(VERS) mkdir $(PROGRAM)-win-$(VERS) ! cp -a $(PROGRAM).exe cygwin1.dll csvformat.txt breteche.csv breteche.pdb LICENSE README $(PROGRAM)-win-$(VERS) zip -r9 ../$(PROGRAM)-win-$(VERS).zip $(PROGRAM)-win-$(VERS) rm -rf $(PROGRAM)-win-$(VERS) --- 34,38 ---- rm -rf $(PROGRAM)-win-$(VERS) mkdir $(PROGRAM)-win-$(VERS) ! cp -a $(PROGRAM).exe csvformat.txt breteche.csv breteche.pdb LICENSE README $(PROGRAM)-win-$(VERS) zip -r9 ../$(PROGRAM)-win-$(VERS).zip $(PROGRAM)-win-$(VERS) rm -rf $(PROGRAM)-win-$(VERS) Index: csv2trainschedpdb.c =================================================================== RCS file: /cvsroot/trainsched/csv2pdb/csv2trainschedpdb.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** csv2trainschedpdb.c 30 Mar 2007 10:10:22 -0000 1.7 --- csv2trainschedpdb.c 16 May 2009 08:07:45 -0000 1.8 *************** *** 35,40 **** #define CREATORID "TRSC" #define DBTYPE "DATA" ! #define FATTRIBS "\x0\x0" /* 0x0020 = RO | backup | OK to overwrite */ ! #define VERSION "\x1\x0" /* 0.1 */ #define TIME_CONSTANT 2082844800 --- 35,41 ---- #define CREATORID "TRSC" #define DBTYPE "DATA" ! #define FATTRIBS "\x0\x0" /* 0x0020 = RO | backup | OK to overwrite */ ! #define VERSION_1_0 "\x1\x0" /* 1.0 Original Trainsched format. */ ! #define VERSION_2_0 "\x2\x0" /* 2.0 Enhanced Trainsched format */ #define TIME_CONSTANT 2082844800 *************** *** 42,46 **** typedef struct station { ! char nom[LGMAXNOMGARE+1]; } station; --- 43,47 ---- typedef struct station { ! char nom[LGMAXNOMGARE+1]; } station; *************** *** 54,333 **** * record number */ - int writerecordinfo(FILE *pdbfd, unsigned int record_num, long pos) { ! char temp[4]={0}; ! int i; ! long saved_pos=0; ! /* store current pos in pdb file */ ! saved_pos = ftell(pdbfd); ! /* write record info */ ! fseek(pdbfd,(record_num-1)*8 + end_header_pos,SEEK_SET); ! i = pos; ! // printf("record: %i %i\n",record_num,i); ! temp[0]= i >> 24 ; ! temp[1]= i >> 16; ! temp[2]= i >> 8; ! temp[3]= i & 0xFFFFFF; ! fwrite(temp,4,1,pdbfd); ! /* go back to saved position */ ! fseek(pdbfd,saved_pos,SEEK_SET); ! return 0; } int main(int argc, char *argv[]) { ! FILE *fd, *pdbfd; ! int c=1, nbgares=0, i,j=0, nbdays=0, nbdir=0, notrain=0; ! char temp[LGMAXNOMGARE+1]={0}; ! int cur_record; ! long cur_record_pos=0; ! if (argc != 4) { ! printf("usage : %s <source> <dest> <PDB Name>\n",argv[0]); ! exit(0); ! } ! /* open source file */ ! fd = fopen(argv[1],"r"); ! if (fd == NULL) { ! printf("Erreur d'ouverture du fichier %s\n",argv[1]); ! exit(-1); ! } ! /* create destination file */ ! /* the b mode is necessary for Cygwin and harmless for Posix systems */ ! pdbfd = fopen(argv[2],"wb"); ! if (pdbfd == NULL) { ! printf("Erreur de création du fichier %s\n",argv[1]); ! exit(-1); ! } ! /* header */ ! /*PDB Name Max 32 chars , \0 terminated */ ! fwrite(argv[3],1,strlen(argv[3]),pdbfd); ! for(i=0;i<(32-strlen(argv[3]));i++) ! fwrite("\x0",1,1,pdbfd); ! /* File attribs */ ! fwrite(FATTRIBS,2,1,pdbfd); ! /* Version */ ! fwrite(VERSION,2,1,pdbfd); ! /* creation date FIXME */ ! fwrite("\xB7\x2D\xB1\x9A",4,1,pdbfd); ! /* Modification date FIXME */ ! fwrite("\xB7\x2D\xB1\x9A",4,1,pdbfd); ! /* last Backup date */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* Modification number */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* AppInfo Area */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* SortInfo Area */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* Database Type */ ! fwrite(DBTYPE,4,1,pdbfd); ! /* Creator ID */ ! fwrite(CREATORID,4,1,pdbfd); ! /* Unique ID Seed */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* Next record List ID */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* Number of records to go here */ ! fwrite("\x0\x0",2,1,pdbfd); ! end_header_pos=ftell(pdbfd); ! /* count number of records in source file */ ! while ((c = fgetc(fd)) != EOF) { ! if (c == '\n') ! num_records++; ! } ! printf("There are %i lines (records)\n",num_records); ! /* save it in PDB Header */ ! /* write number of records in header */ ! fseek(pdbfd,end_header_pos-2,SEEK_SET); ! temp[0] = num_records >> 8; ! temp[1] = num_records & 0xFF; ! fwrite(temp,2,1,pdbfd); ! /* leave room for records info */ ! for (i=0;i<num_records;i++) ! fwrite("\x0\x0\x0\x0\x0\x0\x0\x0",8,1,pdbfd); ! rewind(fd); ! cur_record=1; ! cur_record_pos=ftell(pdbfd); ! /* read Station Names on 1st line */ ! for(;;) { ! c = fgetc(fd); ! if(c == '\t') ! nbgares++; ! if (c != '\n') { ! fwrite(&c,1,1,pdbfd); ! } else { ! fwrite("\x0",1,1,pdbfd); ! break; ! } ! } ! nbgares++; ! printf("I found %i stations\n",nbgares); ! /* Write record info in record List */ ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! /* read Day List */ ! for(;;) { ! c = fgetc(fd); ! if(c == '\t') ! nbdays++; ! if (c != '\n') { ! fwrite(&c,1,1,pdbfd); ! } else { ! fwrite("\x0",1,1,pdbfd); ! break; ! } ! } ! nbdays++; ! printf("%i days found\n",nbdays); ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! /* Read line offset for the various days and directions schedules */ ! i=0; ! for(;;) { ! c = fgetc(fd); ! if(c == '\t') { ! temp[i]='\0'; ! j = atoi(temp); ! temp[0]=j >> 8; ! temp[1]=j & 0xFF; ! fwrite(temp,2,1,pdbfd); ! i=0; ! nbdir++; ! } ! if (c != '\n') { ! temp[i++]=c; ! } else { ! temp[i]='\0'; ! j = atoi(temp); ! temp[0] = j >> 8; ! temp[1] = j & 0xFF; ! fwrite(temp,2,1,pdbfd); ! fwrite("\x0",1,1,pdbfd); ! break; ! } ! } ! nbdir++; ! printf("%i time tables found\n",nbdir); ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! /* Let's go for the real thing */ ! i=0; ! notrain=0; ! for(;;) { ! c=fgetc(fd); ! /* we write time as int */ ! if ((c != '\t') && (c != '\n')) { ! if (c != ':') ! temp[i++]=c; ! } else if (c == '\t') { ! temp[i]='\0'; ! for(j=0;j<i;j++) { ! if (temp[j]=='-') { ! notrain=1; ! fwrite("\xFF\xFF",2,1,pdbfd); ! memset(temp,0,sizeof(temp)); ! break; ! } ! } ! if (notrain==0) { ! j = atoi(temp); ! memset(temp,0,4); ! temp[0] = j >> 8; ! temp[1] = j & 0xFF; ! fwrite(temp,2,1,pdbfd); ! fflush(pdbfd); ! memset(temp,0,sizeof(temp)); ! } ! notrain=0; ! i=0; ! } ! if ((c == '\n') || (c == EOF)) { ! temp[i]='\0'; ! for(j=0;j<i;j++) { ! if (temp[j]=='-') { ! notrain=1; ! fwrite("\xFF\xFF",2,1,pdbfd); ! memset(temp,0,sizeof(temp)); ! break; ! } ! } ! if (notrain==0) { ! j = atoi(temp); ! temp[0] = j >> 8; ! temp[1] = j & 0xFF; ! fwrite(temp,2,1,pdbfd); ! memset(temp,0,sizeof(temp)); ! } ! notrain=0; ! i=0; ! if (c != EOF) { ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! } else { ! break; ! } ! } ! } ! fflush(pdbfd); ! fclose(pdbfd); ! fclose(fd); ! return 0; } --- 55,407 ---- * record number */ int writerecordinfo(FILE *pdbfd, unsigned int record_num, long pos) { ! char temp[4]={0}; ! int i; ! long saved_pos=0; ! /* store current pos in pdb file */ ! saved_pos = ftell(pdbfd); ! /* write record info */ ! fseek(pdbfd,(record_num-1)*8 + end_header_pos,SEEK_SET); ! i = pos; ! // printf("record: %i %i\n",record_num,i); ! temp[0]= i >> 24 ; ! temp[1]= i >> 16; ! temp[2]= i >> 8; ! temp[3]= i & 0xFFFFFF; ! fwrite(temp,4,1,pdbfd); ! /* go back to saved position */ ! fseek(pdbfd,saved_pos,SEEK_SET); ! return 0; } int main(int argc, char *argv[]) { + FILE *fd, *pdbfd; + int c=1, nbgares=0, i,j=0, nbdays=0, nabbrev=0, nabdef=0, nbdir=0, num_colon=0, datawtn=0; + char temp[LGMAXNOMGARE+1]={0}; + int cur_record; + long cur_record_pos=0; ! if (argc != 4) { ! printf("usage : %s <source> <dest> <PDB Name>\n",argv[0]); ! exit(0); ! } ! /* open source file */ ! fd = fopen(argv[1],"r"); ! if (fd == NULL) { ! printf("Erreur d'ouverture du fichier %s\n",argv[1]); ! exit(-1); ! } ! /* count number of records in source file */ ! while ((c = fgetc(fd)) != EOF) { ! if ((num_records < 5) && c == ':') ! num_colon++; // Colons (i.e times) in the first 5 records indicates that this is a version 1.0 PDB. ! if (c == '\n') ! num_records++; ! } ! printf("There are %i lines (records)\n",num_records); ! /* create destination file */ ! /* the b mode is necessary for Cygwin and harmless for Posix systems */ ! pdbfd = fopen(argv[2],"wb"); ! if (pdbfd == NULL) { ! printf("Erreur de création du fichier %s\n",argv[1]); ! exit(-1); ! } ! /* header */ ! /*PDB Name Max 32 chars , \0 terminated */ ! fwrite(argv[3],1,strlen(argv[3]),pdbfd); ! for(i=0;i<(32-strlen(argv[3]));i++) ! fwrite("\x0",1,1,pdbfd); ! /* File attribs */ ! fwrite(FATTRIBS,2,1,pdbfd); ! /* Version */ ! if (num_colon > 3) { ! printf("Writing a Version 1.0 PDB file.\n"); ! fwrite(VERSION_1_0,2,1,pdbfd); ! } else { ! printf("Writing a Version 2.0 PDB file.\n"); ! fwrite(VERSION_2_0,2,1,pdbfd); ! } ! /* creation date FIXME */ ! fwrite("\xB7\x2D\xB1\x9A",4,1,pdbfd); ! /* Modification date FIXME */ ! fwrite("\xB7\x2D\xB1\x9A",4,1,pdbfd); ! /* last Backup date */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* Modification number */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* AppInfo Area */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* SortInfo Area */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* Database Type */ ! fwrite(DBTYPE,4,1,pdbfd); ! /* Creator ID */ ! fwrite(CREATORID,4,1,pdbfd); ! /* Unique ID Seed */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* Next record List ID */ ! fwrite("\x0\x0\x0\x0",4,1,pdbfd); ! /* Number of records to go here */ ! temp[0] = num_records >> 8; ! temp[1] = num_records & 0xFF; ! fwrite(temp,2,1,pdbfd); ! end_header_pos=ftell(pdbfd); ! /* leave room for records info */ ! for (i=0;i<num_records;i++) ! fwrite("\x0\x0\x0\x0\x0\x0\x0\x0",8,1,pdbfd); ! rewind(fd); ! cur_record=1; ! cur_record_pos=ftell(pdbfd); ! /* read Station Names on 1st line */ ! for(;;) { ! c = fgetc(fd); ! if(c == '\t') ! nbgares++; ! if (c != '\n') { ! fwrite(&c,1,1,pdbfd); ! } else { ! fwrite("\x0",1,1,pdbfd); ! break; ! } ! } ! nbgares++; ! printf("I found %i stations\n",nbgares); ! /* Write record info in record List */ ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! /* read Day List */ ! for(;;) { ! c = fgetc(fd); ! if(c == '\t') ! nbdays++; ! if (c != '\n') { ! fwrite(&c,1,1,pdbfd); ! } else { ! fwrite("\x0",1,1,pdbfd); ! break; ! } ! } ! nbdays++; ! printf("%i days found\n",nbdays); ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! /* Read line offset for the various days and directions schedules */ ! i=0; ! for(;;) { ! c = fgetc(fd); ! if(c == '\t') { ! temp[i]='\0'; ! j = atoi(temp); ! temp[0]=j >> 8; ! temp[1]=j & 0xFF; ! fwrite(temp,2,1,pdbfd); ! i=0; ! nbdir++; ! } ! if (c != '\n') { ! temp[i++]=c; ! } else { ! temp[i]='\0'; ! j = atoi(temp); ! temp[0] = j >> 8; ! temp[1] = j & 0xFF; ! fwrite(temp,2,1,pdbfd); ! fwrite("\x0",1,1,pdbfd); ! break; ! } ! } ! nbdir++; ! printf("%i time tables found\n",nbdir); ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! if (num_colon < 4) { // Only for 2.0 Version PDB files. ! /* read Abbreviations List */ ! datawtn = 0; ! for(;;) { ! c = fgetc(fd); ! if(c == '\t') ! nabbrev++; ! if (c != '\n') { ! fwrite(&c,1,1,pdbfd); ! datawtn = 1; ! } else { ! fwrite("\x0",1,1,pdbfd); ! break; ! } ! } ! if (datawtn) nabbrev++; // Only if we wrote at lease /something/. ! printf("%i abbreviations found\n",nabbrev); ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! /* read Abbreviations Definitions */ ! datawtn = 0; ! for(;;) { ! c = fgetc(fd); ! if(c == '\t') ! nabdef++; ! if (c != '\n') { ! fwrite(&c,1,1,pdbfd); ! datawtn = 1; ! } else { ! fwrite("\x0",1,1,pdbfd); ! break; ! } ! } ! if (datawtn) nabdef++; // Only if we wrote at lease /something/. ! if (nabbrev != nabdef) ! { ! printf("WARNING: I found %i abbreviations, but %i abbreviation definitions.\n", nabbrev, nabdef); ! } ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! /* read timetable notes.*/ ! for(;;) { ! c = fgetc(fd); ! if(c == '|') ! fwrite("\n",1,1,pdbfd); ! else if (c != '\n') { ! fwrite(&c,1,1,pdbfd); ! } else { ! fwrite("\x0",1,1,pdbfd); ! break; ! } ! } ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! } ! /* Write the timetable records. */ ! i=0; ! if (num_colon > 3) { ! // Version 1.0 PDB ! for(;;) { ! c=fgetc(fd); ! if (c == EOF) break; ! /* we write time as a single 16bit int */ ! if ((c != '\t') && (c != '\n') && (c != ':')) temp[i++]=c; ! if ((c == '\t') || (c == '\n')) { ! temp[i]='\0'; ! if (temp[0]=='-') { ! fwrite("\xFF\xFF",2,1,pdbfd); ! } else { ! j = atoi(temp); ! memset(temp,0,4); ! temp[0] = j >> 8; ! temp[1] = j & 0xFF; ! fwrite(temp,2,1,pdbfd); ! } ! fflush(pdbfd); ! memset(temp,0,sizeof(temp)); ! i=0; ! } ! if (c == '\n') { ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! } ! } ! } ! else ! { ! // Version 2.0 PDB ! for(;;) { ! c=fgetc(fd); ! if (c == EOF) break; ! ! /* we write time and abbreviation as three 8 bit ints (hours, minutes & abbrev) */ ! if ((c != '\t') && (c != '\n') && (c != ':')) temp[i++]=c; ! else { ! temp[i]='\0'; ! ! if (temp[0]=='-') { ! fwrite("\xFF\xFF",2,1,pdbfd); // Hours and Minutes ! } else if (temp[0]=='#') { ! fwrite("\xFE",1,1,pdbfd); ! } else { ! j = atoi(temp); ! temp[0] = j & 0xFF; ! fwrite(temp,1,1,pdbfd); ! } ! ! // If no defined abbreviations, write a blank ! if ((c != ':') && (nabbrev == 0)) { ! fwrite("\x0",1,1,pdbfd); ! } ! ! fflush(pdbfd); ! memset(temp,0,sizeof(temp)); ! i=0; ! } ! ! if (c == '\n') { ! writerecordinfo(pdbfd, cur_record, cur_record_pos); ! cur_record_pos=ftell(pdbfd); ! cur_record++; ! } ! } ! } ! fflush(pdbfd); ! fclose(pdbfd); ! fclose(fd); ! ! return 0; } |