int iges_lire (FILE* lefic, int *numsec, char ligne[100], int modefnes) /*int iges_lire (lefic,numsec,ligne,modefnes)*/ /*FILE* lefic; int *numsec; char ligne[100]; int modefnes;*/ { int i,result; char typesec; /* int length;*/ if (iges_fautrelire == 0) { if (*numsec == 0) ligne[72] = ligne[79] = ' '; ligne[0] = '\0'; if(modefnes) { if (fgets(ligne,99,lefic) == NULL) return (feof(lefic) ? 0 : -1); } /*for kept compatibility with fnes*/ else { /* PTV: 21.03.2002 it is neccessary for files that have only `\r` but no `\n` examle file is 919-001-T02-04-CP-VL.iges */ while ( fgets ( ligne, 2, lefic ) && ( ligne[0] == '\r' || ligne[0] == '\n' ) ) { } if (fgets(&ligne[1],80,lefic) == NULL) return (feof(lefic) ? 0 : -1); /* fgets(ligne,81,lefic); */ } if (*numsec == 0 && ligne[72] != 'S' && ligne[79] == ' ') { /* ON A DU FNES : Sauter la 1re ligne */ ligne[0] = '\0'; if(modefnes) { if (fgets(ligne,99,lefic) == NULL) return (feof(lefic) ? 0 : -1); } /*for kept compatibility with fnes*/ else { while ( fgets ( ligne, 2, lefic ) && ( ligne[0] == '\r' || ligne[0] == '\n' ) ) { } if (fgets(&ligne[1],80,lefic) == NULL) return (feof(lefic) ? 0 : -1); /* fgets(ligne,81,lefic); */ } } if ((ligne[0] & 128)&&modefnes) { for (i = 0; i < 80; i ++) ligne[i] = ligne[i] ^ (150 + (i & 3)); } } if (feof(lefic)) return 0; iges_fautrelire = 0; if (ligne[0] == '\0' || ligne[0] == '\n' || ligne[0] == '\r') return iges_lire(lefic,numsec,ligne,modefnes); /* 0 */ if (sscanf(&ligne[73],"%d",&result) == 0) return -1; /* { printf("Erreur, ligne n0.%d :\n%s\n",*numl,ligne); return (*numsec > 0 ? -1 : -2); } */ *numsec = result; typesec = ligne[72]; switch (typesec) { case 'S' : ligne[72] = '\0'; return (1); case 'G' : ligne[72] = '\0'; return (2); case 'D' : ligne[72] = '\0'; return (3); case 'P' : ligne[72] = '\0'; return (4); case 'T' : ligne[72] = '\0'; return (5); default :; /* printf("Ligne incorrecte, ignoree n0.%d :\n%s\n",*numl,ligne); */ } /* the column 72 is empty, try to check the neghbour*/ if(strlen(ligne)==80 && (ligne[79]=='\n' || ligne[79]=='\r') && (ligne[0]<='9' && ligne[0]>='0')) { /*check if the case of losted .*/ int index; for(index = 1; ligne[index]<='9' && ligne[index]>='0'; index++); if (ligne[index]=='D' || ligne[index]=='d') { for(index = 79; index > 0; index--) ligne[index] = ligne[index-1]; ligne[0]='.'; } typesec = ligne[72]; switch (typesec) { case 'S' : ligne[72] = '\0'; return (1); case 'G' : ligne[72] = '\0'; return (2); case 'D' : ligne[72] = '\0'; return (3); case 'P' : ligne[72] = '\0'; return (4); case 'T' : ligne[72] = '\0'; return (5); default :; /* printf("Ligne incorrecte, ignoree n0.%d :\n%s\n",*numl,ligne); */ } } return -1; }
int iges_lire (FILE* lefic, int *numsec, char ligne[100], int modefnes) /*int iges_lire (lefic,numsec,ligne,modefnes)*/ /*FILE* lefic; int *numsec; char ligne[100]; int modefnes;*/ { int i,result; char typesec; /* int length;*/ if (iges_fautrelire == 0) { if (*numsec == 0) ligne[72] = ligne[79] = ' '; ligne[0] = '\0'; if(modefnes) { if (fgets(ligne,99,lefic) == NULL) return (feof(lefic) ? 0 : -1); /*for kept compatibility with fnes*/ } else { /* PTV: 21.03.2002 it is neccessary for files that have only `\r` but no `\n` examle file is 919-001-T02-04-CP-VL.iges */ while ( fgets ( ligne, 2, lefic ) && ( ligne[0] == '\r' || ligne[0] == '\n' ) ) { } if (fgets(&ligne[1],80,lefic) == NULL) return (feof(lefic) ? 0 : -1); } if (*numsec == 0 && ligne[72] != 'S' && ligne[79] == ' ') { /* ON A DU FNES : Sauter la 1re ligne */ ligne[0] = '\0'; if(modefnes) { if (fgets(ligne,99,lefic) == NULL) return (feof(lefic) ? 0 : -1); /*for kept compatibility with fnes*/ } else { while ( fgets ( ligne, 2, lefic ) && ( ligne[0] == '\r' || ligne[0] == '\n' ) ) { } if (fgets(&ligne[1],80,lefic) == NULL) return (feof(lefic) ? 0 : -1); } } if ((ligne[0] & 128) && modefnes) { for (i = 0; i < 80; i ++) ligne[i] = (char)(ligne[i] ^ (150 + (i & 3))); } } if (feof(lefic)) return 0; { //0x1A is END_OF_FILE for OS DOS and WINDOWS. For other OS we set this rule forcefully. char *fc = strchr(ligne, 0x1A); if(fc != 0) { fc[0] = '\0'; return 0; } } iges_fautrelire = 0; if (ligne[0] == '\0' || ligne[0] == '\n' || ligne[0] == '\r') return iges_lire(lefic,numsec,ligne,modefnes); /* 0 */ if (sscanf(&ligne[73],"%d",&result) != 0) { *numsec = result; typesec = ligne[72]; switch (typesec) { case 'S' : ligne[72] = '\0'; return (1); case 'G' : ligne[72] = '\0'; return (2); case 'D' : ligne[72] = '\0'; return (3); case 'P' : ligne[72] = '\0'; return (4); case 'T' : ligne[72] = '\0'; return (5); default : ; } /* the column 72 is empty, try to check the neighbour*/ if(strlen(ligne)==80 && (ligne[79]=='\n' || ligne[79]=='\r') && (ligne[0]<='9' && ligne[0]>='0')) { /*check if the case of losted .*/ int index; for(index = 1; ligne[index]<='9' && ligne[index]>='0'; index++); if (ligne[index]=='D' || ligne[index]=='d') { for(index = 79; index > 0; index--) ligne[index] = ligne[index-1]; ligne[0]='.'; } typesec = ligne[72]; switch (typesec) { case 'S' : ligne[72] = '\0'; return (1); case 'G' : ligne[72] = '\0'; return (2); case 'D' : ligne[72] = '\0'; return (3); case 'P' : ligne[72] = '\0'; return (4); case 'T' : ligne[72] = '\0'; return (5); default : ; } } } // the line is not conform to standard, try to read it (if there are some missing spaces) // find the number end i = (int)strlen(ligne); while ((ligne[i] == '\0' || ligne[i] == '\n' || ligne[i] == '\r' || ligne[i] == ' ') && i > 0) i--; if (i != (int)strlen(ligne)) ligne[i + 1] = '\0'; // find the number start while (ligne[i] >= '0' && ligne[i] <= '9' && i > 0) i--; if (sscanf(&ligne[i + 1],"%d",&result) == 0) return -1; *numsec = result; // find type of line while (ligne[i] == ' ' && i > 0) i--; typesec = ligne[i]; switch (typesec) { case 'S' : ligne[i] = '\0'; return (1); case 'G' : ligne[i] = '\0'; return (2); case 'D' : ligne[i] = '\0'; return (3); case 'P' : ligne[i] = '\0'; return (4); case 'T' : ligne[i] = '\0'; return (5); default :; /* printf("Ligne incorrecte, ignoree n0.%d :\n%s\n",*numl,ligne); */ } return -1; }
int igesread (char* nomfic, int lesect[6], int modefnes) { /* MGE 16/06/98 */ FILE* lefic; char ligne[100]; int numsec, numl; int i; int i0;int j; char str[2]; int Dstat = 0; int Pstat = 0; char c_separ = ','; char c_fin = ';'; iges_initfile(); lefic = stdin; i0 = numsec = 0; numl = 0; if (nomfic[1] != '\0') lefic = fopen(nomfic,"r"); if (lefic == NULL) return -1; /* fichier pas pu etre ouvert */ for (i = 1; i < 6; i++) lesect[i] = 0; for (j = 0; j < 100; j++) ligne[j] = 0; for(;;) { numl ++; i = iges_lire(lefic,&numsec,ligne,modefnes); if (i <= 0) { if (i == 0) break; /* Sending of message : Syntax error */ { str[1] = '\0'; str[0] = sects[i0]; IGESFile_Check2 (0,"XSTEP_18",numl,str); /* //gka 15 Sep 98: str instead of sects[i0]); */ } if (i0 == 0) return -1; lesect[i0] ++; continue; } lesect[i] ++; i0 = i; if (numsec != lesect[i]) { /* Sending of message : Syntax error */ str[1] = '\0'; str[0] = sects[i0]; IGESFile_Check2 (0,"XSTEP_19",numl,str); /* //gka 15 Sep 98: str instead of sects[i0]); */ } if (i == 1) { /* Start Section (comm.) */ ligne[72] = '\0'; iges_newparam (0,72,ligne); } if (i == 2) { /* Header (Global sect) */ iges_setglobal(); for (;;) { if (lesect[i] == 1) { /* Separation specifique */ int n0 = 0; if (ligne[0] != ',') { c_separ = ligne[2]; n0 = 3; } if (ligne[n0+1] != c_separ) { c_fin = ligne[n0+3]; } } iges_param(&Pstat,ligne,c_separ,c_fin,72); if (Pstat != 2) break; } } if (i == 3) iges_Dsect(&Dstat,numsec,ligne); /* Directory (Dsect) */ if (i == 4) { /* Parametres (Psect) */ iges_Psect(numsec,ligne); for (;;) { iges_param(&Pstat,ligne,c_separ,c_fin,64); if (Pstat != 2) break; } } } /* Sending of message : No Terminal Section */ if (lesect[5] == 0) { IGESFile_Check3 (1, "XSTEP_20"); //return -1; } fclose (lefic); return 0; }