int main(int argc, const char * argv[]) { int *array1 = scanNum(); int *array2 = scanNum(); int *array3 = GBB(array1, array2); printNum(array3); return 0; }
int main(int argc, char **argv) { // test scanNum { const char *psz; unsigned n; psz = scanNum("123.", &n); eq_i(123, n); eq_i('.', *psz); psz = scanNum("123 ", &n); eq_i(123, n); eq_i(' ', *psz); psz = scanNum("2147483647", &n); eq_i(2147483647, n); eq_i('\0', *psz); } // test addrFromString { // Perversely, sockaddr_in keeps exposes integer values (sin_addr and // sin_port) as if they can be treated as numeric values, but stores // them in network byte order. struct sockaddr_in sin; struct sockaddr *psa = (struct sockaddr *) &sin; unsigned char *pby = (unsigned char *)&psa->sa_data; int e; e = addrFromString(&sin, "123.4.5.255:258"); eq_i(0, e); eq_i(AF_INET, psa->sa_family); eq_i(1, pby[0]); // sin_port eq_i(2, pby[1]); eq_i(123, pby[2]); // sin_addr eq_i(4, pby[3]); eq_i(5, pby[4]); eq_i(255, pby[5]); e = addrFromString(&sin, ":123"); eq_i(0, e); eq_i(AF_INET, psa->sa_family); eq_i(123, htons(sin.sin_port)); eq_i(0, sin.sin_addr.s_addr); e = addrFromString(&sin, "1.2.3.4"); eq_i(0, e); eq_i(AF_INET, psa->sa_family); eq_i(0, htons(sin.sin_port)); eq_i(0x01020304, htonl(sin.sin_addr.s_addr)); } return 0; }
int main (int argc, char **argv) { options opts; prog_name = basename (argv[0]); int check = 1; scan_options(argc, argv, &opts); if(opts.print_debug == true) check = 2; if(argc == check){ scanNum(); print_nodes(head, &opts); } else{ for (int argi = check; argi < argc; ++argi) { char *filename = argv[argi]; if (strcmp (filename, STDIN_NAME) == 0) { scanNum(); print_nodes(head, &opts); }else { FILE *input = fopen (filename, "r"); if (input != NULL) { scanNum(); print_nodes(head, &opts); fclose (input); }else { //If the file is empty //Print error message exit_status = EXIT_FAILURE; fflush (NULL); fprintf (stderr, "%s: %s: %s\n", prog_name, filename, strerror (errno)); fflush (NULL); } } } } return exit_status; }
WicErrors getNextToken(pToken tok) { pTokTab tokTabPtr; WicErrors retVal = ERR_NONE; static long tokAfterDefine = 2; // used to flag '(' in #define x( as a // special parentheses int temp; assert(currTokF >= 0); currTokLen = 0; currTok[currTokLen] = 0; TOK_NUM_AFTER_NEW_LINE++; /* Used for #preprocessor directives */ tokAfterDefine++; /* Used for #preprocessor directives */ g_currLineNum = LINE_NUM; g_currColNum = COL_NUM; /* When getNextToken gets called, STATE may be one of: TS_START, TS_COMMENT. */ temp = skipBlank(); if (STATE == TS_START) { setTokPos( tok->pos, TOK_FILE_NAME, currTokF, LINE_NUM, COL_NUM, LINES_BEFORE, temp, orderLineNum ); while (NEXT_CHAR == '') { getNextChar(); tok->pos->spacesBefore = skipBlank(); } if (isalpha(NEXT_CHAR) || NEXT_CHAR == '_') { if (!scanId()) { char saveChar = NEXT_CHAR; currTokLen = 0; currTok[currTokLen] = 0; getNextChar(); if (saveChar == '"') { retVal = scanStr(tok->data); } else { retVal = scanChar(tok->data); } goto Return; } } else if (isdigit(NEXT_CHAR)) { retVal = scanNum(tok->data); goto Return; } else switch (NEXT_CHAR) { case '\'': getNextChar(); retVal = scanChar(tok->data); goto Return; break; case '"': if (currLineIsInclude) { getNextChar(); retVal = scanIncludeFileName(tok->data, '"'); goto Return; } else { getNextChar(); retVal = scanStr(tok->data); goto Return; break; } case '\n': pushGetNextChar(); currLineIsInclude = 0; break; case '!': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case '#': pushGetNextChar(); if (TOK_NUM_AFTER_NEW_LINE == 1) { skipBlank(); if (isalpha(NEXT_CHAR) || NEXT_CHAR == '_') { scanId(); } else { tok->data->code = Y_PRE_NULL; retVal = ERR_NONE; goto Return; } } else { if (NEXT_CHAR == '#') { pushGetNextChar(); } } break; case '%': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case '&': pushGetNextChar(); if (NEXT_CHAR == '&') { pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } } break; case '(': pushGetNextChar(); break; case ')': pushGetNextChar(); break; case '*': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case '+': pushGetNextChar(); if (NEXT_CHAR == '+') { pushGetNextChar(); } else if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case ',': pushGetNextChar(); break; case '-': pushGetNextChar(); if (NEXT_CHAR == '-') { pushGetNextChar(); } else if (NEXT_CHAR == '=') { pushGetNextChar(); } else if (NEXT_CHAR == '>') { pushGetNextChar(); } break; case '.': pushGetNextChar(); if (NEXT_CHAR == '.') { pushGetNextChar(); if (NEXT_CHAR == '.') { pushGetNextChar(); } else { retVal = RERR_INV_CHAR; goto Return; } } else if (isdigit(NEXT_CHAR)) { if (pushFloatDotExp(tok->data, 1)) { retVal = convStr2Const(tok->data); goto Return; } else { retVal = RERR_INV_CHAR; goto Return; } } break; case '/': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } else if (NEXT_CHAR == '*') { /* comment begin */ popChars(1); STATE = TS_COMMENT; getNextChar(); retVal = scanComment(tok->data); goto Return; } else if (NEXT_CHAR == '/') { popChars(1); STATE = TS_COMMENT; getNextChar(); retVal = scanCPlusPlusComment(tok->data); goto Return; } break; case ':': pushGetNextChar(); if (NEXT_CHAR == '>') { pushGetNextChar(); } break; case ';': pushGetNextChar(); break; case '<': if (currLineIsInclude) { getNextChar(); retVal = scanIncludeFileName(tok->data, '>'); goto Return; } else { pushGetNextChar(); if (NEXT_CHAR == '<') { pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } } else if (NEXT_CHAR == '=') { pushGetNextChar(); } } break; case '=': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case '>': pushGetNextChar(); if (NEXT_CHAR == '>') { pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } } else if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case '?': pushGetNextChar(); break; case '[': pushGetNextChar(); break; case ']': pushGetNextChar(); break; case '^': pushGetNextChar(); if (NEXT_CHAR == '=') pushGetNextChar(); break; case '{': pushGetNextChar(); break; case '|': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } else if (NEXT_CHAR == '|') { pushGetNextChar(); } break; case '}': pushGetNextChar(); break; case '~': pushGetNextChar(); break; case (char) EOF: tok->data->code = Y_EOF; retVal = ERR_NONE; goto Return; break; default: /* Eat up an ivalid character */ getNextChar(); retVal = RERR_INV_CHAR; goto Return; } tokTabPtr = tabLookup(currTok); if (tokTabPtr != NULL) { tok->data->code = tokTabPtr->code; if (tok->data->code == Y_PRE_INCLUDE) { currLineIsInclude = 1; } if (tok->data->code == Y_PRE_DEFINE) { tokAfterDefine = 0; } if (tok->data->code == Y_LEFT_PAREN && tokAfterDefine == 2) { // the case of #define x(... if (tok->pos->spacesBefore == 0) { tok->data->code = Y_PRE_SPECIAL_LEFT_PAREN; } } tok->data->repr.string = registerString(tokTabPtr->name, !FREE_STRING); } else { if (currTok[0] == '#') { retVal = RERR_INV_PREPROCESSOR; goto Return; } else { tok->data->code = Y_ID; tok->data->repr.string = registerString(wicStrdup(currTok), FREE_STRING); } } } else if (STATE == TS_COMMENT) { setTokPos(tok->pos, TOK_FILE_NAME, currTokF, LINE_NUM, COL_NUM, LINES_BEFORE, 0, orderLineNum); retVal = scanComment(tok->data); goto Return; } else { assert(0); } Return: if (tok->data->code != Y_PRE_NEWLINE) { tok->pos->linesBefore = tok->pos->lineNum - PREV_TOK_LINE_NUM; PREV_TOK_LINE_NUM = tok->pos->lineNum; } else { tok->pos->linesBefore = 0; } zapTokPos(g_currPos); g_currPos = dupTokPos(tok->pos, NULL); return retVal; }