⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menuutil.c

📁 本文件是ni公司的labwindows/cvi软件的部分例子和源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
Error:    /* free memory */    if (tagName) {        free(tagName);        tagName = NULL;    }       return success; }/*****************************************************//*  GetMenuListFromIniFile()                         *//*                                                   *//*  Parameters:                                      *//*      menuList from CreateMenuList()               *//*      handle for inifile Instrument driver         *//*      section name                                 *//*      tag name prefix                              *//*      flags                                        *//*                                                   *//*  Return: status                                   *//*                                                   *//*  Purpose: Routine for getting menuList items from *//*           an INIFILE handle                       *//*                                                   *//*  Example:                                         *//*     [Section Name]                                *//*     TagName1="value1"                             *//*     TagName2="value2"                             *//*     TagName3="value3"                             *//*     TagName4="value4"                             *//*                                                   *//*****************************************************/int CVIFUNC MU_GetFileListFromIniFile(    menuList menuListHandle,     IniText iniTextHandle,     char *sectionName,     char *tagPrefix,     int flags){    int success = 1;    int i, totalItems;    char *tagName = NULL;    char *tagValue = NULL;        if ((iniTextHandle) && (menuListHandle)) {        if (Ini_SectionExists (iniTextHandle, sectionName)) {            /* malloc memory for tag name buffer */            if ( (tagName = (char *) malloc(sizeof(tagPrefix)+16))==NULL) {                success = 0;                goto Error;            }               tagName[0] = 0;                        /* Loop thru list of tag/value pairs */            totalItems = Ini_NumberOfItems (iniTextHandle, sectionName);            for (i=totalItems; i>0; i--) {                /* Get the nth tagName and Value */                sprintf(tagName, "%s%d", tagPrefix, i);                if(Ini_GetPointerToRawString (iniTextHandle, sectionName, tagName, &tagValue)>0) {                    if ((tagValue != NULL) && (tagValue[0] != '\0')) {                        /* Add value to menuList */                        if (flags) {                            if (!MU_AddItemToMenuList(menuListHandle, FRONT_OF_LIST, MU_MakeShortFileName(NULL, tagValue, MAX_MENU_ITEM_LENGTH), StrDup(tagValue))) {                                success = 0;                                goto Error;                            }                        } else {                                if (!MU_AddItemToMenuList(menuListHandle, FRONT_OF_LIST, tagValue, NULL)) {                                success = 0;                                goto Error;                            }                        }                        }                   }            }        }    }    else success = 0;    Error:    /* free memory */    if (tagName) {        free (tagName);        tagName = NULL;    }               return success; }/*****************************************************//*  IniEx_PutRawStringListItem()                     *//*                                                   *//*  Parameters:                                      *//*      handle for inifile Instrument driver         *//*      section name                                 *//*      tag name prefix                              *//*      max items in rolling list                    *//*                                                   *//*  Return: status                                   *//*                                                   *//*  Purpose: INIFILE routine for putting tags info   *//*           in a rolling tag list                   *//*                                                   *//*  Example:                                         *//*     [Section Name]                                *//*     TagName1="value1"                             *//*     TagName2="value2"                             *//*     TagName3="value3"                             *//*     TagName4="value4"                             *//*                                                   *//*****************************************************/static int IniEx_PutRawStringListItem(    IniText iniTextHandle,     char *sectionName,     char *tagPrefix,     char *tagValue,     int maxItems){    int error = 0;    int status;    int i;    int count;    int tagCount;    char *tempBuf = NULL;    char *tagName = NULL;    char *tempTagName = NULL;    int size1, size2;    int tempInt;    short found;    /* Check parameters */    if ((sectionName==NULL) || (tagPrefix==NULL)) {        error = -1;         goto Error;    }           if (maxItems < 0) {        error = -1; goto Error;    }           /* malloc memory for tag name buffer */    if ( (tagName = (char *) malloc(sizeof(tagPrefix)+16))==NULL) {        error = -1; goto Error;    }       tagName[0] = 0;        found = 0;    /* See if section exists */     if (Ini_SectionExists (iniTextHandle, sectionName)) {        /* Get number of items in section */                    count = Ini_NumberOfItems (iniTextHandle, sectionName);        tagCount = 0;           /* Loop thru and find the highest prefix tag in list */        for (i=1; i<=count;i++) {            /* If prefixTag, get max item */            status = Ini_NthItemName (iniTextHandle, sectionName, i, &tempTagName);                                    size1 = strlen(tagPrefix);            size2 = strlen(tempTagName);            if ( (!strncmp(tagPrefix, tempTagName, size1)) && (size2>size1) ) {                if (sscanf(&tempTagName[size1],"%d", &tempInt) == 1) {                    tagCount = Max(tagCount, tempInt);                                        /* See if this tags value is the same value passed in */                    if (Ini_GetPointerToRawString (iniTextHandle, sectionName, tempTagName, &tempBuf)>0) {                        if (!strcmp(tempBuf, tagValue)) {                            found = tempInt;                        }                       }                       }               }        }        if (found != 1) {            for (i=tagCount; i>0;i--) {                /* Remove items after maxItems if non-zero */                if ((maxItems>0) && (i>maxItems)) {                    sprintf(tagName, "%s%d", tagPrefix, i);                    Ini_RemoveItem (iniTextHandle, sectionName, tagName);                    /* FmtOut("Removing [%s], tag=%s\n", sectionName, tagName); */                }                /* Shift items up by one */                else if ( (i<maxItems) && ((!found) || (i<found) ) ) {                    sprintf(tagName, "%s%d", tagPrefix, i);                    if (Ini_GetPointerToRawString (iniTextHandle, sectionName, tagName, &tempBuf)>0) {                        sprintf(tagName, "%s%d", tagPrefix, i+1);                        if (error = Ini_PutRawString (iniTextHandle, sectionName, tagName, tempBuf)!=0)                            goto Error;                    }                                        }            }        }       }        if (found != 1) {        /* Just put item in list as first entry */        sprintf(tagName, "%s%s", tagPrefix, "1");        if(error = Ini_PutRawString (iniTextHandle, sectionName, tagName, tagValue)!=0) {            error = -1;             goto Error;        }       }       Error:    /* free memory */    if (tagName) {        free (tagName);        tagName = NULL;    }               return error;   }/*****************************************************//*  MU_WriteRegistryInfo()                           *//*                                                   *//*  Parameters:                                      *//*      handle for inifile Instrument driver         *//*                                                   *//*  Return: success = 1                              *//*                                                   *//*  Purpose: Main routine for putting registry info  *//*****************************************************/int CVIFUNC MU_WriteRegistryInfo(    IniText iniTextHandle,     char *registryName){    int success = 1;#ifndef WIN32    char fileName[MAX_PATHNAME_LEN];#endif      if ((!registryName) || (!registryName[0]))        return 0;            /*----------------------------------------------------------*/    /* Write out the registry data                              */    /*----------------------------------------------------------*/#ifdef WIN32    if (IniEx_WriteToRegistry(iniTextHandle, 1, registryName, 1))        success = 0;#else       if (!GetProjectDir (fileName)) {        #ifdef _NI_mswin_        sprintf(fileName, "%s\\%s", fileName, registryName);        #else        sprintf(fileName, "%s/%s", fileName, registryName);        #endif        if (Ini_WriteToFile (iniTextHandle, fileName))            success = 0;    }       #endif      return success;}/*****************************************************//*  MU_ReadRegistryInfo()                            *//*                                                   *//*  Parameters:                                      *//*      handle for inifile Instrument driver         *//*                                                   *//*  Return: success = 1                              *//*                                                   *//*  Purpose: Main routine for putting registry info  *//*****************************************************/int CVIFUNC MU_ReadRegistryInfo(    IniText iniTextHandle,     char *registryName){    int success = 1;#ifndef WIN32    char fileName[MAX_PATHNAME_LEN];#endif    int BOLE;    if ((!registryName) || (!registryName[0]))        return 0;            /*----------------------------------------------------------*/    /* Write out the registry data                              */    /*----------------------------------------------------------*/#ifdef WIN32    BOLE = GetBreakOnLibraryErrors ();    SetBreakOnLibraryErrors (0);    if (IniEx_ReadFromRegistry(iniTextHandle, 1, registryName))        success = 0;    SetBreakOnLibraryErrors (BOLE);#else       if (!GetProjectDir (fileName)) {        #ifdef _NI_mswin_        sprintf(fileName, "%s\\%s", fileName, registryName);        #else        sprintf(fileName, "%s/%s", fileName, registryName);        #endif        BOLE = GetBreakOnLibraryErrors ();        SetBreakOnLibraryErrors (0);        if (Ini_ReadFromFile (iniTextHandle, fileName))            success = 0;    }           SetBreakOnLibraryErrors (BOLE);#endif      return success;}#ifdef WIN32/*****************************************************//*  IniEx_ReadFromRegistry()                         *//*                                                   *//*  Parameters:                                      *//*      handle for inifile Instrument driver         *//*      root Key  Valid values:                      *//*          0 = HKEY_CLASSES_ROOT                    *//*          1 = HKEY_CURRENT_USER                    *//*          2 = HKEY_LOCAL_MACHINE                   *//*          3 = HKEY_USERS                           *//*      base Key name                                *//*                                                   *//*  Return: status                                   *//*                                                   *//*  Purpose: Main routine for getting registry info  *//*****************************************************/static int IniEx_ReadFromRegistry(    IniText iniTextHandle,     int rootKey,     char *baseKeyName){    int error = 0;    unsigned int count, tag;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -