static void skip_comment(ParseInfo pi) { char c = reader_get(&pi->rd); if ('*' == c) { while ('\0' != (c = reader_get(&pi->rd))) { if ('*' == c) { c = reader_get(&pi->rd); if ('/' == c) { return; } } } } else if ('/' == c) { while ('\0' != (c = reader_get(&pi->rd))) { switch (c) { case '\n': case '\r': case '\f': case '\0': return; default: break; } } } else { oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid comment format"); } if ('\0' == c) { oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "comment not terminated"); return; } }
static uint32_t read_hex(ParseInfo pi) { uint32_t b = 0; int i; char c; for (i = 0; i < 4; i++) { c = reader_get(&pi->rd); b = b << 4; if ('0' <= c && c <= '9') { b += c - '0'; } else if ('A' <= c && c <= 'F') { b += c - 'A' + 10; } else if ('a' <= c && c <= 'f') { b += c - 'a' + 10; } else { oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid hex character"); return 0; } } return b; }
/*-------------------------------------------------------------------------*/ static int readfiles (void) /* Read and analyse all files. * If a file can't be read, print a message. * Return 0 if all went well, RETURN_WARN if one of the files could not be * found, RETURN_ERROR if one of the files could not be read properly. */ { int rc; /* Return value */ Node * pNode; /* Node of the file under examination */ int srcRead; /* Number of source files read */ const char * pName; /* Includefile name returned by reader */ rc = 0; srcRead = 0; while (NULL != (pNode = nodes_todo()) ) { int bSystem; /* TRUE if it's a <> include */ if (pNode->flags & NODE_NOTFND) continue; if (!reader_open(pNode->pName)) { rc = readerror(pNode, rc, FALSE); continue; } /* If (can't open pNode->pName) */ if (bVerbose) { printf(" reading %-65s\r", pNode->pName); fflush(stdout); } while (NULL != (pName = reader_get(&bSystem)) ) { int index; /* index into aIncl[] */ Node * pChild; /* Node of included file, NULL if not found */ Node * pChFirst; /* First 'direct' child node */ for (index = -1, pChild = NULL, pChFirst = NULL ; !pChild && index < iInclSize ; index++) { char aName[FILENAME_MAX+1]; char * pCName; /* aName[] cleaned up */ char * pCBase; /* Namepart in *pCName */ /* Don't look for system includes in non-system directories. */ if (index >= 0 && bSplitPath && bSystem && !aIncl[index].bSysPath) continue; aName[FILENAME_MAX] = '\0'; if (index < 0) { /* Special case: look directly for the filename. * If bSplitPath is given, or if the filename is absolute, * use it unchanged. Else, use the path of the including * file as anchor. */ if (bSplitPath || '/' == *pName) strcpy(aName, pName); else { size_t oFilename; oFilename = (unsigned)(pNode->pBase - pNode->pName); strncpy(aName, pNode->pName, oFilename); strcpy(aName+oFilename, pName); } } else { /* Standard case: build the pathname from the include * pathname. */ strcpy(aName, aIncl[index].pPath); strcat(aName, pName); } /* Cleanup the filename and check if it is listed in * the tree */ pCName = util_getpath(aName, &pCBase); if (!pCName) { if (bVerbose) printf("%-78s\r", ""); reader_close(); exit_nomem(" (readfiles: 1. util_getpath)"); } pChild = nodes_findadd(pCName, TRUE); if (pChild->flags & NODE_NEW) { /* New file: check if it exists and set up the * node properly */ struct stat aStat; pChild->pName = pCName; pChild->pBase = pCBase; if (index >= 0) { pChild->pPath = util_getpath(pName, NULL); pChild->iInclude = index; } else if (pNode->iInclude < 0 || pNode->flags & NODE_SOURCE) { pChild->pPath = util_getpath(pCName, NULL); pChild->iInclude = -1; } else { strcpy(aName, pNode->pPath); strcat(aName, pName); pChild->pPath = util_getpath(aName, NULL); pChild->iInclude = pNode->iInclude; } if (!pChild->pPath) { if (bVerbose) printf("%-78s\r", ""); reader_close(); exit_nomem(" (readfiles: 2. util_getpath)"); } pChild->flags = (short)(bSystem ? NODE_SYSTEM : 0); /* It's ok to not find <>-includes - they just don't have * to appear in the output then. */ if (stat(pCName, &aStat)) pChild->flags |= NODE_NOTFND | (bSystem ? NODE_IGNORE : 0); } /* The pChFirst is needed if the include can't be found * so we can keep track from where it is included. */ if (index < 0) pChFirst = pChild; /* Test if the file for pChild exists. */ if (pChild->flags & NODE_NOTFND) { /* Make sure that the file is listed in the warnings * if appropriate. */ if (index >= 0) pChild->flags |= NODE_IGNORE; else if ((pChild->flags & NODE_IGNORE) && !bSystem) pChild->flags ^= NODE_IGNORE; pChild = NULL; } /* For absolute pNames, only index -1 is tried */ if ('/' == *pName) break; } /* for (index = -1..iInclSize) */ assert(pChFirst != NULL); if (pChild ? nodes_depend(pChild, pNode) : nodes_depend(pChFirst, pNode)) { if (bVerbose) printf("%-78s\r", ""); reader_close(); exit_nomem(" (readfiles: nodes_depend)"); } } /* while(get pName from file */ if (bVerbose) printf("%-78s\r", ""); if (!reader_eof() || reader_close()) { perror(aPgmName); printf("%s: Error reading '%s'\n", aPgmName, pNode->pName); rc = RETURN_ERROR; } else if (pNode->flags & NODE_SOURCE) { srcRead++; } } /* while (nodes_todo()) */ if (!srcRead) { printf("%s: No source file read.\n", aPgmName); rc = RETURN_ERROR; } /* Walk tree and print all include files not found */ nodes_initwalk(); while (rc != RETURN_ERROR && NULL != (pNode = nodes_inorder()) ) { if ((pNode->flags & (NODE_NOTFND|NODE_IGNORE)) == NODE_NOTFND) { if (pNode->pUsers) rc = readerror(pNode, rc, TRUE); else pNode->flags |= NODE_IGNORE; } } if (bVerbose) fflush(stdout); return rc; }