// int ReadINIFile(char *Fname, RS_232 *COMM232eeee) int ReadINIFile(char *Fname) { FILE *fptr; #define MAXLINE 1000 char Work[MAXLINE]; char *Line; char *Parms = "PORTNUM BAUDRATE NUMEROBIT STOPBIT PARITYBIT"; enum {PORTNUM=1, BAUDRATE, NUMEROBIT, STOPBIT, PARITYBIT} ParmKey; char *KeyName; char *KeyValue; int Rcode = 0; // Set DEFAULT Values if (FileExists(Fname) < 0) { /* if file doesn't exist. Create it (return FileSize */ if (WriteINIFile(Fname) == FALSE) return FALSE; } // ------------------------- // Read the .ini File // ------------------------- if ((fptr = fopen(Fname, "r")) == NULL) { MessageBox(NULL, "Errore nella apertura del File", "Error!", MB_ICONEXCLAMATION | MB_OK); Rcode = FALSE; } /* End if */ while (GetFileLine(Work, MAXLINE, fptr, 'u') != EOF) { Line = CleanString(Work, "=", ' '); /* togli '=' */ KeyName = Word(Line, 1); /* get parameter name */ KeyValue = Word(Line, 2); /* get parameter value */ ParmKey = WordPos(KeyName, Parms); /* get value for switch */ switch (ParmKey) { case PORTNUM: //COMM232->PortNum = atoi(KeyValue); //COMM232->PortName[3] = COMM232->PortNum+'0'; break; case BAUDRATE: //COMM232->BaudRate = atoi(KeyValue); break; case NUMEROBIT: //COMM232->NumeroBits = atoi(KeyValue); break; case STOPBIT: //COMM232->StopBit = atoi(KeyValue); break; case PARITYBIT: //COMM232->ParityBit = atoi(KeyValue); break; default: break; } /* End switch */ } /* End while */ fclose(fptr); /* close file.ini */ return TRUE; }
DataElement::~DataElement() { WriteINIFile(); }