int main(void) { char str[100]; long n; int s, k; char section[50]; /* string reading */ n = ini_gets("first", "string", "dummy", str, sizearray(str), inifile); assert(n==4 && strcmp(str,"noot")==0); n = ini_gets("second", "string", "dummy", str, sizearray(str), inifile); assert(n==4 && strcmp(str,"mies")==0); n = ini_gets("first", "undefined", "dummy", str, sizearray(str), inifile); assert(n==5 && strcmp(str,"dummy")==0); /* ----- */ n = ini_gets("", "string", "dummy", str, sizearray(str), inifile2); assert(n==4 && strcmp(str,"noot")==0); n = ini_gets(NULL, "string", "dummy", str, sizearray(str), inifile2); assert(n==4 && strcmp(str,"noot")==0); /* ----- */ printf("1. String reading tests passed\n"); /* value reading */ n = ini_getl("first", "val", -1, inifile); assert(n==1); n = ini_getl("second", "val", -1, inifile); assert(n==2); n = ini_getl("first", "undefined", -1, inifile); assert(n==-1); /* ----- */ n = ini_getl(NULL, "val", -1, inifile2); assert(n==1); /* ----- */ printf("2. Value reading tests passed\n"); /* string writing */ n = ini_puts("first", "alt", "flagged as \"correct\"", inifile); assert(n==1); n = ini_gets("first", "alt", "dummy", str, sizearray(str), inifile); assert(n==20 && strcmp(str,"flagged as \"correct\"")==0); /* ----- */ n = ini_puts("second", "alt", "correct", inifile); assert(n==1); n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile); assert(n==7 && strcmp(str,"correct")==0); /* ----- */ n = ini_puts("third", "test", "correct", inifile); assert(n==1); n = ini_gets("third", "test", "dummy", str, sizearray(str), inifile); assert(n==7 && strcmp(str,"correct")==0); /* ----- */ n = ini_puts("second", "alt", "overwrite", inifile); assert(n==1); n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile); assert(n==9 && strcmp(str,"overwrite")==0); /* ----- */ n = ini_puts(NULL, "alt", "correct", inifile2); assert(n==1); n = ini_gets(NULL, "alt", "dummy", str, sizearray(str), inifile2); assert(n==7 && strcmp(str,"correct")==0); /* ----- */ printf("3. String writing tests passed\n"); /* section/key enumeration */ printf("4. Section/key enumertion, file contents follows\n"); for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) { printf(" [%s]\n", section); for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) { printf("\t%s\n", str); } /* for */ } /* for */ /* browsing through the file */ printf("5. browse through all settings, file contents follows\n"); ini_browse(Callback, NULL, inifile); /* string deletion */ n = ini_puts("first", "alt", NULL, inifile); assert(n==1); n = ini_puts("second", "alt", NULL, inifile); assert(n==1); n = ini_puts("third", NULL, NULL, inifile); assert(n==1); /* ----- */ n = ini_puts(NULL, "alt", NULL, inifile2); assert(n==1); printf("6. String deletion tests passed\n"); return 0; }
void testIni(void) { xputs(PSTR("TestIni\n")); char str[100]; long n; int s, k; char section[50]; xputs(PSTR("Test 1\n")); /* string reading */ n = ini_gets("first", "string", "aap", str, sizearray(str), inifile); xprintf(PSTR("n=%d\n"),n); xprintf(PSTR("Test 1 str=%s (supposed to say noot)\n"),str); // assert(n==4 && strcmp(str,"noot")==0); n = ini_gets("second", "string", "aap", str, sizearray(str), inifile); xprintf(PSTR("Test 1 str=%s (supposed to say mies)\n"),str); // assert(n==4 && strcmp(str,"mies")==0); n = ini_gets("first", "dummy", "aap", str, sizearray(str), inifile); // assert(n==3 && strcmp(str,"aap")==0); xputs(PSTR("1. String reading tests passed\n")); /* value reading */ n = ini_getl("first", "val", -1, inifile); // assert(n==1); n = ini_getl("second", "val", -1, inifile); // assert(n==2); n = ini_getl("first", "dummy", -1, inifile); // assert(n==-1); xputs(PSTR("2. Value reading tests passed\n")); /* string writing */ n = ini_puts("first", "alt", "flagged as \"correct\"", inifile); // assert(n==1); n = ini_gets("first", "alt", "aap", str, sizearray(str), inifile); // assert(n==20 && strcmp(str,"flagged as \"correct\"")==0); /* ----- */ n = ini_puts("second", "alt", "correct", inifile); // assert(n==1); n = ini_gets("second", "alt", "aap", str, sizearray(str), inifile); // assert(n==7 && strcmp(str,"correct")==0); /* ----- */ n = ini_puts("third", "alt", "correct", inifile); // assert(n==1); n = ini_gets("third", "alt", "aap", str, sizearray(str), inifile); // assert(n==7 && strcmp(str,"correct")==0); /* ----- */ xputs(PSTR("3. String writing tests passed\n")); /* section/key enumeration */ for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) { xprintf(PSTR("[%s]\n"), section); for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) { xprintf(PSTR("\t%s\n"), str); } /* for */ } /* for */ /* string deletion */ n = ini_puts("first", "alt", NULL, inifile); // assert(n==1); n = ini_puts("second", "alt", NULL, inifile); // assert(n==1); n = ini_puts("third", NULL, NULL, inifile); // assert(n==1); xputs(PSTR("All done\n")); }
int main(void) { char str[100]; long n; int s, k; char section[50]; /* string reading */ n = ini_gets("first", "string", "aap", str, sizearray(str), inifile); assert(n==4 && strcmp(str,"noot")==0); n = ini_gets("second", "string", "aap", str, sizearray(str), inifile); assert(n==4 && strcmp(str,"mies")==0); n = ini_gets("first", "dummy", "aap", str, sizearray(str), inifile); assert(n==3 && strcmp(str,"aap")==0); printf("1. String reading tests passed\n"); /* value reading */ n = ini_getl("first", "val", -1, inifile); assert(n==1); n = ini_getl("second", "val", -1, inifile); assert(n==2); n = ini_getl("first", "dummy", -1, inifile); assert(n==-1); printf("2. Value reading tests passed\n"); /* string writing */ n = ini_puts("first", "alt", "flagged as \"correct\"", inifile); assert(n==1); n = ini_gets("first", "alt", "aap", str, sizearray(str), inifile); assert(n==20 && strcmp(str,"flagged as \"correct\"")==0); /* ----- */ n = ini_puts("second", "alt", "correct", inifile); assert(n==1); n = ini_gets("second", "alt", "aap", str, sizearray(str), inifile); assert(n==7 && strcmp(str,"correct")==0); /* ----- */ n = ini_puts("third", "alt", "correct", inifile); assert(n==1); n = ini_gets("third", "alt", "aap", str, sizearray(str), inifile); assert(n==7 && strcmp(str,"correct")==0); /* ----- */ printf("3. String writing tests passed\n"); /* section/key enumeration */ for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) { printf("[%s]\n", section); for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) { printf("\t%s\n", str); } /* for */ } /* for */ /* string deletion */ n = ini_puts("first", "alt", NULL, inifile); assert(n==1); n = ini_puts("second", "alt", NULL, inifile); assert(n==1); n = ini_puts("third", NULL, NULL, inifile); assert(n==1); return 0; }
int TestMiniIni(void) { char str[100]; long n; int s, k; char section[50]; /* string reading */ n = ini_gets("first", "string", "dummy", str, sizearray(str), inifile); Check(n==4 && UTIL1_strcmp(str,"noot")==0); n = ini_gets("second", "string", "dummy", str, sizearray(str), inifile); Check(n==4 && UTIL1_strcmp(str,"mies")==0); n = ini_gets("first", "undefined", "dummy", str, sizearray(str), inifile); Check(n==5 && UTIL1_strcmp(str,"dummy")==0); /* ----- */ n = ini_gets("", "string", "dummy", str, sizearray(str), inifile2); Check(n==4 && UTIL1_strcmp(str,"noot")==0); n = ini_gets(NULL, "string", "dummy", str, sizearray(str), inifile2); Check(n==4 && UTIL1_strcmp(str,"noot")==0); /* ----- */ SHELL_SendString((unsigned char*)"1. String reading tests passed\n"); /* value reading */ n = ini_getl("first", "val", -1, inifile); Check(n==1); n = ini_getl("second", "val", -1, inifile); Check(n==2); n = ini_getl("first", "undefined", -1, inifile); Check(n==-1); /* ----- */ n = ini_getl(NULL, "val", -1, inifile2); Check(n==1); /* ----- */ SHELL_SendString((unsigned char*)"2. Value reading tests passed\n"); /* string writing */ n = ini_puts("first", "alt", "flagged as \"correct\"", inifile); Check(n==1); n = ini_gets("first", "alt", "dummy", str, sizearray(str), inifile); Check(n==20 && UTIL1_strcmp(str,"flagged as \"correct\"")==0); /* ----- */ n = ini_puts("second", "alt", "correct", inifile); Check(n==1); n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile); Check(n==7 && UTIL1_strcmp(str,"correct")==0); /* ----- */ n = ini_puts("third", "test", "correct", inifile); Check(n==1); n = ini_gets("third", "test", "dummy", str, sizearray(str), inifile); Check(n==7 && UTIL1_strcmp(str,"correct")==0); /* ----- */ n = ini_puts("second", "alt", "overwrite", inifile); Check(n==1); n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile); Check(n==9 && UTIL1_strcmp(str,"overwrite")==0); /* ----- */ n = ini_puts(NULL, "alt", "correct", inifile2); Check(n==1); n = ini_gets(NULL, "alt", "dummy", str, sizearray(str), inifile2); Check(n==7 && UTIL1_strcmp(str,"correct")==0); /* ----- */ SHELL_SendString((unsigned char*)"3. String writing tests passed\n"); /* section/key enumeration */ SHELL_SendString((unsigned char*)"4. Section/key enumeration, file contents follows\n"); for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) { SHELL_SendString((unsigned char*)" ["); SHELL_SendString((unsigned char*)section); SHELL_SendString((unsigned char*)"]\r\n"); for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) { SHELL_SendString((unsigned char*)"\t"); SHELL_SendString((unsigned char*)str); SHELL_SendString((unsigned char*)"\r\n"); } /* for */ } /* for */ /* browsing through the file */ SHELL_SendString((unsigned char*)"5. browse through all settings, file contents follows\n"); ini_browse(Callback, NULL, inifile); /* string deletion */ n = ini_puts("first", "alt", NULL, inifile); Check(n==1); n = ini_puts("second", "alt", NULL, inifile); Check(n==1); n = ini_puts("third", NULL, NULL, inifile); Check(n==1); /* ----- */ n = ini_puts(NULL, "alt", NULL, inifile2); Check(n==1); SHELL_SendString((unsigned char*)"6. String deletion tests passed\n"); return 0; }
void FanucAdapter::configMacrosAndPMC(const char *aIniFile) { // Read adapter configuration mPort = ini_getl("adapter", "port", mPort, aIniFile); ini_gets("adapter", "service", "MTConnect Fanuc Adapter", mName, SERVICE_NAME_LEN, aIniFile); ini_gets("focus", "host", mDeviceIP, mDeviceIP, MAX_HOST_LEN, aIniFile); mDevicePort = ini_getl("focus", "port", mDevicePort, aIniFile); // Read adapter.ini to get additional macro variables and // PMC registers char name[100]; int idx; const static char *sDigits = "0123456789"; mMacroMin = 99999; mMacroMax = 0; // First look for macro variables for (idx = 0; ini_getkey("macros", idx, name, sizeof(name), aIniFile) > 0 && idx < MAX_MACROS; idx++) { char numbers[256]; ini_gets("macros", name, "", numbers, 256, aIniFile); if (numbers[0] == '[') { // We have a path macro. int x, y, z; char *cp = numbers + 1, *n; x = strtol(cp, &n, 10); if (cp == n) continue; cp = n; y = strtol(cp, &n, 10); if (cp == n) continue; cp = n; z = strtol(cp, &n, 10); if (cp == n) continue; int i = mMacroPathCount++; mMacroPath[i] = new MacroPathPosition(name, x, y, z); addDatum(*mMacroPath[i]); printf("Adding path macro '%s' at location %d %d %d\n", name, x, y, z); if (x > mMacroMax) mMacroMax = x; if (x < mMacroMin) mMacroMin = x; if (y > mMacroMax) mMacroMax = y; if (y < mMacroMin) mMacroMin = y; if (z > mMacroMax) mMacroMax = z; if (z < mMacroMin) mMacroMin = z; } else { char *cp = numbers, *n; long v = strtol(cp, &n, 10); if (cp == n) continue; int i = mMacroSampleCount++; mMacroSample[i] = new MacroSample(name, v); addDatum(*mMacroSample[i]); printf("Adding sample macro '%s' at location %d\n", name, v); if (v > mMacroMax) mMacroMax = v; if (v < mMacroMin) mMacroMin = v; } } for (idx = 0; ini_getkey("pmc", idx, name, sizeof(name), aIniFile) > 0 && idx < MAX_PMC; idx++) { long v = ini_getl("pmc", name, 0, aIniFile); mPMCVariable[idx] = new IntEvent(name); mPMCAddress[idx] = v; addDatum(*mPMCVariable[idx]); printf("Adding pmc '%s' at location %d\n", name, v); } mPMCCount = idx; }