home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / i / inifn135.zip / DEMO.C < prev    next >
Text File  |  1993-03-05  |  4KB  |  198 lines

  1. /*
  2. ** demo.c
  3. **
  4. ** Simple demonstration program for INI file functions set
  5. **
  6. ** (c) Copyright 1992, 1993 DAF, Inc. - All rights reserved
  7. */
  8.  
  9.  
  10. #include <daf\types.h>
  11. #include <conio.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15.  
  16. #include <daf\inifunc.h>
  17.  
  18.  
  19. int main(int argc, char *argv[]);
  20.  
  21.  
  22. int main(int argc, char *argv[])
  23. {
  24.     INIHNDL        ih;
  25.     int        j, res;
  26.     long        l;
  27.     ushort        us[5];
  28.     static char    s1[50], s2[50], s3[50], s4[50], s5[50];
  29.     static char    *strarr[6] = { s1, s2, s3, s4, s5, NULL };
  30.  
  31.  
  32.  
  33.     puts("INI file functions demonstration program.");
  34.  
  35.     /*
  36.     ** Create an INI handle
  37.     */
  38.     ih = CreateIniHandle("test");
  39.     if(ih==NULL) {
  40.         puts("CreateIniHandle()==NULL");
  41.         exit(1);
  42.         }
  43.  
  44.  
  45.     /*
  46.     ** Build items
  47.     */
  48.     if((res=BuildBoolIniItem(ih, "bool", 0))!=IF_OK) {
  49.         printf("BuildBoolIniItem()==%02x\n", res);
  50.         exit(1);
  51.         }
  52.  
  53.     if((res=BuildShortIniItem(ih, "short", 0, 0, 0))!=IF_OK) {
  54.         printf("BuildShortIniItem()==%02x\n", res);
  55.         exit(1);
  56.         }
  57.  
  58.     if((res=BuildUshortIniItem(ih, "ushort", 0, 0, 0))!=IF_OK) {
  59.         printf("BuildUshortIniItem()==%02x\n", res);
  60.         exit(1);
  61.         }
  62.  
  63.     if((res=BuildLongIniItem(ih, "long", 0L, 0L, 0L))!=IF_OK) {
  64.         printf("BuildLongIniItem()==%02x\n", res);
  65.         exit(1);
  66.         }
  67.  
  68.     if((res=BuildUlongIniItem(ih, "ulong", 0L, 0L, 0L))!=IF_OK) {
  69.         printf("BuildUlongIniItem()==%02x\n", res);
  70.         exit(1);
  71.         }
  72.  
  73.     if((res=BuildStringIniItem(ih, "string", 50, NULL))!=IF_OK) {
  74.         printf("BuildStringIniItem()==%02x\n", res);
  75.         exit(1);
  76.         }
  77.  
  78.     if((res=BuildUshortsIniItem(ih, "ushorts", 5, 0, 0, 0))!=IF_OK) {
  79.         printf("BuildUshortsIniItem()==%02x\n", res);
  80.         exit(1);
  81.         }
  82.  
  83.     if((res=BuildStringsIniItem(ih, "strings", 5, 40, NULL))!=IF_OK) {
  84.         printf("BuildStringsIniItem()==%02x\n", res);
  85.         exit(1);
  86.         }
  87.  
  88.  
  89.     /*
  90.     ** Read information from file (if any)
  91.     */
  92.     if((res=ReadIniInfo(ih, "demo.ini"))&IF_ERROR) {
  93.         printf("ReadIniInfo()==%02x\n", res);
  94.         /* Fall through here and use default values */
  95.         }
  96.  
  97.  
  98.     /*
  99.     ** Change the long value
  100.     */
  101.     for(j=0; j<5; j++) {
  102.         if((res=GetLongIniItem(ih, "long", &l))!=IF_OK) {
  103.             printf("GetLongIniItem()==%02x\n", res);
  104.             break;
  105.             }
  106.         if((res=GetLongIniItem(ih, "ulong", &l))==IF_OK) {
  107.             printf("GetLongIniItem()==%02x\n", res);
  108.             break;
  109.             }
  110.         l++;
  111.         if((res=SetLongIniItem(ih, "long", l))!=IF_OK) {
  112.             printf("GetLongIniItem()==%02x\n", res);
  113.             break;
  114.             }
  115.         }
  116.     if(res!=IF_OK)
  117.         exit(1);
  118.  
  119.  
  120.     /*
  121.     ** Change array of unsigned shorts values
  122.     */
  123.     if((res=GetUshortsIniItem(ih, "ushorts", us, 5))!=IF_OK) {
  124.         printf("GetUshortsIniItem()==%02x\n", res);
  125.         exit(1);
  126.         }
  127.     for(j=0; j<5; j++)
  128.         us[j] += (j+1);
  129.     if((res=SetUshortsIniItem(ih, "ushorts", us, 5))!=IF_OK) {
  130.         printf("SetUshortsIniItem()==%02x\n", res);
  131.         exit(1);
  132.         }
  133.  
  134.  
  135.     /*
  136.     ** Change string
  137.     */
  138.     if((res=GetStringsIniItem(ih, "strings", strarr, 5))!=IF_OK) {
  139.         printf("GetStringsIniItem()==%02x\n", res);
  140.         exit(1);
  141.         }
  142.     strarr[5] = strarr[0];
  143.     for(j=0; j<5; j++) {
  144.         strarr[j] = strarr[j+1];
  145.         }
  146.     if((res=SetStringsIniItem(ih, "strings", strarr, 5))!=IF_OK) {
  147.         printf("SetStringsIniItem()==%02x\n", res);
  148.         exit(1);
  149.         }
  150.  
  151.  
  152.     /*
  153.     ** Update file
  154.     */
  155.     if((res=WriteIniInfo(ih, "demo.ini"))!=IF_OK) {
  156.         printf("WriteIniInfo()==%02x\n", res);
  157.         exit(1);
  158.         }
  159.  
  160.  
  161.     /*
  162.     ** Delete items from handle
  163.     */
  164.     if((res=DeleteIniItem(ih, "ushort"))!=IF_OK) {
  165.         printf("DeleteIniItem('ushort', 1st)==%02x\n", res);
  166.         exit(1);
  167.         }
  168.  
  169.     if((res=DeleteIniItem(ih, "ushort"))==IF_OK) {
  170.         printf("DeleteIniItem('ushort', 2nd)==%02x\n", res);
  171.         exit(1);
  172.         }
  173.  
  174.     if((res=DeleteIniItem(ih, "ulong"))!=IF_OK) {
  175.         printf("DeleteIniItem('ulong', 1st)==%02x\n", res);
  176.         exit(1);
  177.         }
  178.  
  179.  
  180.     /*
  181.     ** Dispose of the handle
  182.     */
  183.     if((res=DeleteIniHandle(ih))!=IF_OK) {
  184.         printf("DeleteIniHandle()==%02x\n", res);
  185.         exit(1);
  186.         }
  187.  
  188.  
  189.     puts("INI file updated.");
  190.  
  191.     /* Arguments are not used, keep checker silent */
  192.     argc = argc;
  193.     argv = argv;
  194.  
  195.     return(0);
  196. }
  197.  
  198.