main()
{
        int a = 0;

        otherwise  a = 4 given (foo());
        printf("%d\n", a);
        exit(0);
}
Example #2
0
void *
test_read_init(int argc, char **argv, int duration, start_t **startp, char **rhostpathp)
{
    test_read_priv_t *priv;
    char errbuf[128];
    int optind;
    int rc;

    rc = clp_parsev(argc, argv, optionv, posparamv, errbuf, sizeof(errbuf), &optind);
    if (rc) {
        eprint("%s\n", errbuf);
        exit(rc);
    }

    if (given('h') || given('V'))
        exit(0);

    argc -= optind;
    argv += optind;

    priv = malloc(sizeof(*priv));
    if (!priv) {
        abort();
    }

    priv->pr_offset = 0;
    priv->pr_length = length;
    priv->pr_duration = duration;

    if (argc > 2) {
        priv->pr_length = strtoul(argv[2], NULL, 0);
        if (priv->pr_length < 1024 || priv->pr_length > (NCT_MSGSZ_MAX - 1024)) {
            eprint("invalid read length %zu\n", priv->pr_length);
            abort();
        }
    }

    *startp = test_read_start;
    *rhostpathp = rhostpath;

    return priv;
}
Example #3
0
int main() {
  srand(time(NULL));
  int N = 9;
  std::vector<std::vector<int>> M(N, std::vector<int>(N, 0));
  std::vector<std::vector<bool>> given(N, std::vector<bool>(N, false));
  M[1][5] = 3;
  M[1][7] = 8;
  M[1][8] = 5;
  M[2][2] = 1;
  M[2][4] = 2;
  M[3][3] = 5;
  M[3][5] = 7;
  M[4][2] = 4;
  M[4][6] = 1;
  M[5][1] = 9;
  M[6][0] = 5;
  M[6][7] = 7;
  M[6][8] = 3;
  M[7][2] = 2;
  M[7][4] = 1;
  M[8][4] = 4;

  given[1][5] = true;
  given[1][7] = true;
  given[1][8] = true;
  given[2][2] = true;
  given[2][4] = true;
  given[3][3] = true;
  given[3][5] = true;
  given[4][2] = true;
  given[4][6] = true;
  given[5][1] = true;
  given[6][0] = true;
  given[6][7] = true;
  given[6][8] = true;
  given[7][2] = true;
  given[7][4] = true;
  given[8][4] = true;
  std::cout << "Input sudoku: " << std::endl;
  print_sudoku(M, N);
  solve_sudoku(M, given, N);
  std::cout << "Result sudoku: " << std::endl;
  print_sudoku(M, N);
  return 0;
}
Example #4
0
File: cpp3.c Project: cjapes/core
int
dooptions(int argc, char** argv)
/*
 * dooptions is called to process command line arguments (-Detc).
 * It is called only at cpp startup.
 */
{
        register char           *ap;
        register DEFBUF         *dp;
        register int            c;
        int                     i, j;
        char                    *arg;
        SIZES                   *sizp;          /* For -S               */
        int                     size;           /* For -S               */
        int                     isdatum;        /* FALSE for -S*        */
        int                     endtest;        /* For -S               */

        for (i = j = 1; i < argc; i++) {
            arg = ap = argv[i];

            if (*ap++ != '-' || *ap == EOS)
            {
                    argv[j++] = argv[i];
            }
            else {
                c = *ap++;                      /* Option byte          */
                if (islower(c))                 /* Normalize case       */
                    c = toupper(c);
                switch (c) {                    /* Command character    */
                case 'C':                       /* Keep comments        */
                    cflag = TRUE;
                    keepcomments = TRUE;
                    break;

                case 'D':                       /* Define symbol        */
                    /*
                     * If the option is just "-Dfoo", make it -Dfoo=1
                     */
                    while (*ap != EOS && *ap != '=')
                        ap++;
                    if (*ap == EOS)
                        ap = "1";
                    else
                        *ap++ = EOS;
                    /*
                     * Now, save the word and its definition.
                     */
                    dp = defendel(argv[i] + 2, FALSE);
                    dp->repl = savestring(ap);
                    dp->nargs = DEF_NOARGS;
                    break;

                case 'E':                       /* Ignore non-fatal     */
                    eflag = TRUE;               /* errors.              */
                    break;

                case 'I':                       /* Include directory    */
                    AddInclude( ap );           /* BP, 11.09.91 */
                    break;

                case 'N':                       /* No predefineds       */
                    nflag++;                    /* Repeat to undefine   */
                    break;                      /* __LINE__, etc.       */

                case 'S':
                    sizp = size_table;
                    if (0 != (isdatum = (*ap != '*'))) /* If it's just -S,     */
                        endtest = T_FPTR;       /* Stop here            */
                    else {                      /* But if it's -S*      */
                        ap++;                   /* Step over '*'        */
                        endtest = 0;            /* Stop at end marker   */
                    }
                    while (sizp->bits != endtest && *ap != EOS) {
                        if (!isdigit(*ap)) {    /* Skip to next digit   */
                            ap++;
                            continue;
                        }
                        size = 0;               /* Compile the value    */
                        while (isdigit(*ap)) {
                            size *= 10;
                            size += (*ap++ - '0');
                        }
                        if (isdatum)
                            sizp->size = size;  /* Datum size           */
                        else
                            sizp->psize = size; /* Pointer size         */
                        sizp++;
                    }
                    if (sizp->bits != endtest)
                        cwarn("-S, too few values specified in %s", argv[i]);
                    else if (*ap != EOS)
                        cwarn("-S, too many values, \"%s\" unused", ap);
                    break;

                case 'U':                       /* Undefine symbol      */
                    if (defendel(ap, TRUE) == NULL)
                        cwarn("\"%s\" wasn't defined", ap);
                    break;

#if OSL_DEBUG_LEVEL > 1
                case 'X':                       /* Debug                */
                    debug = (isdigit(*ap)) ? atoi(ap) : 1;
#if (HOST == SYS_VMS || HOST == SYS_UNIX)
                    signal(SIGINT, (void (*)(int)) abort); /* Trap "interrupt" */
#endif
                    fprintf(stderr, "Debug set to %d\n", debug);
                    break;
#endif

#if OSL_DEBUG_LEVEL > 1
                case 'P':                       /* #define's dump       */
                    bDumpDefs = 1;
                    fprintf(stderr, "Dump #define's is on\n");
                    break;
#endif

                default:                        /* What is this one?    */
                    cwarn("Unknown option \"%s\"", arg);
                    fprintf(stderr, "The following options are valid:\n\
  -C\t\t\tWrite source file comments to output\n\
  -Dsymbol=value\tDefine a symbol with the given (optional) value\n\
  -Idirectory\t\tAdd a directory to the #include search list\n\
  -N\t\t\tDon't predefine target-specific names\n\
  -Stext\t\tSpecify sizes for #if sizeof\n\
  -Usymbol\t\tUndefine symbol\n");
#if OSL_DEBUG_LEVEL > 1
                    fprintf(stderr, "  -Xvalue\t\tSet internal debug flag\n");
                    fprintf(stderr, "  -P\t\t\tdump #define's\n");
#endif
                    break;
                }                       /* Switch on all options        */
            }                           /* If it's a -option            */
        }                               /* For all arguments            */
#if OSL_DEBUG_LEVEL > 1
        if ( (bDumpDefs ? j > 4 : j > 3) ) {
#else
        if (j > 3) {
#endif
            cerror(
                "Too many file arguments.  Usage: cpp [input [output]]",
                NULLST);
        }
        return (j);                     /* Return new argc              */
}

int
readoptions(char* filename, char*** pfargv)
{
        FILE           *fp;
        int c;
        int bInQuotes = 0;
        char optbuff[1024], *poptbuff;
        int fargc=0, back;
        char *fargv[PARALIMIT], **pfa;

        pfa=*pfargv=malloc(sizeof(fargv));

        poptbuff=&optbuff[0];
        filename++;
        if ((fp = fopen(filename, "r")) == NULL) {
#if OSL_DEBUG_LEVEL > 1
            if ( debug || !bDumpDefs )
                perror(filename);
#endif
            return (FALSE);
        }
        do
        {
            /*
             *  #i27914# double ticks '"' now have a duplicate function:
             *  1. they define a string ( e.g. -DFOO="baz" )
             *  2. a string can contain spaces, so -DFOO="baz zum" defines one
             *  argument no two !
             */
            c=fgetc(fp);
            if ( c != ' ' && c != CR && c != NL && c != HT && c != EOF)
            {
                *poptbuff++=(char)c;
                if( c == '"' )
                    bInQuotes = ~bInQuotes;
            }
            else
            {
                if( c != EOF && bInQuotes )
                    *poptbuff++=(char)c;
                else
                {
                    *poptbuff=EOS;
                    if (strlen(optbuff)>0)
                    {
                        pfa[fargc+1]=malloc(strlen(optbuff)+1);
                        strcpy(pfa[fargc+1],optbuff);
                        fargc++;
                        pfa[fargc+1]=0;
                        poptbuff=&optbuff[0];
                    }
                }
            }
        }
        while ( c != EOF );

        fclose(fp);
        back=dooptions(fargc+1,pfa);

        return (back);
}
void test_string_hello_is_as_expected(void){
    expect("Hello World\n");
    given(sprintf(output, "Hello %s\n", "World"));
}
void test_string_hey_is_as_expected(void){
    expect("hey");
    given(sprintf(output, "hey"));
}
Example #7
0
/*
 * dooptions is called to process command line arguments (-Detc).
 * It is called only at cpp startup.
 */
int dooptions(int argc, char** argv)
{
    char* ap;
    DEFBUF* dp;
    int c;
    int i, j;
    char* arg;
    SIZES* sizp;        /* For -S               */
    int size;           /* For -S               */
    int isdatum;        /* FALSE for -S*        */
    int endtest;        /* For -S               */

    for (i = j = 1; i < argc; i++)
    {
        arg = ap = argv[i];

        if (*ap++ != '-' || *ap == EOS)
        {
            argv[j++] = argv[i];
        }
        else
        {
            c = *ap++;                      /* Option byte          */
            if (islower(c))                 /* Normalize case       */
                c = toupper(c);
            switch (c)                      /* Command character    */
            {
            case 'C':                       /* Keep comments        */
                cflag = TRUE;
                keepcomments = TRUE;
                break;

            case 'D':                       /* Define symbol        */
                /*
                 * If the option is just "-Dfoo", make it -Dfoo=1
                 */
                while (*ap != EOS && *ap != '=')
                    ap++;
                if (*ap == EOS)
                    ap = "1";
                else
                    *ap++ = EOS;
                /*
                 * Now, save the word and its definition.
                 */
                dp = defendel(argv[i] + 2, FALSE);
                dp->repl = savestring(ap);
                dp->nargs = DEF_NOARGS;
                break;

            case 'E':                       /* Ignore non-fatal     */
                eflag = TRUE;               /* errors.              */
                break;

            case 'I':                       /* Include directory    */
                AddInclude( ap );           /* BP, 11.09.91 */
                break;

            case 'N':                       /* No predefineds       */
                nflag++;                    /* Repeat to undefine   */
                break;                      /* __LINE__, etc.       */

            case 'S':
                sizp = size_table;
                if (0 != (isdatum = (*ap != '*'))) /* If it's just -S,     */
                    endtest = T_FPTR;       /* Stop here            */
                else                        /* But if it's -S*      */
                {
                    ap++;                   /* Step over '*'        */
                    endtest = 0;            /* Stop at end marker   */
                }
                while (sizp->bits != endtest && *ap != EOS)
                {
                    if (!isdigit(*ap))      /* Skip to next digit   */
                    {
                        ap++;
                        continue;
                    }
                    size = 0;               /* Compile the value    */
                    while (isdigit(*ap))
                    {
                        size *= 10;
                        size += (*ap++ - '0');
                    }
                    if (isdatum)
                        sizp->size = size;  /* Datum size           */
                    else
                        sizp->psize = size; /* Pointer size         */
                    sizp++;
                }
                if (sizp->bits != endtest)
                    cwarn("-S, too few values specified in %s", argv[i]);
                else if (*ap != EOS)
                    cwarn("-S, too many values, \"%s\" unused", ap);
                break;

            case 'U':                       /* Undefine symbol      */
                if (defendel(ap, TRUE) == NULL)
                    cwarn("\"%s\" wasn't defined", ap);
                break;

#if OSL_DEBUG_LEVEL > 1
            case 'X':                       /* Debug                */
                debug = (isdigit(*ap)) ? atoi(ap) : 1;
#if (HOST == SYS_UNIX)
                signal(SIGINT, (void (*)(int)) abort); /* Trap "interrupt" */
#endif
                fprintf(stderr, "Debug set to %d\n", debug);
                break;
#endif

#if OSL_DEBUG_LEVEL > 1
            case 'P':                       /* #define's dump       */
                bDumpDefs = 1;
                fprintf(stderr, "Dump #define's is on\n");
                break;
#endif

            default:                        /* What is this one?    */
                cwarn("Unknown option \"%s\"", arg);
                fprintf(stderr, "The following options are valid:\n\
  -C\t\t\tWrite source file comments to output\n\
  -Dsymbol=value\tDefine a symbol with the given (optional) value\n\
  -Idirectory\t\tAdd a directory to the #include search list\n\
  -N\t\t\tDon't predefine target-specific names\n\
  -Stext\t\tSpecify sizes for #if sizeof\n\
  -Usymbol\t\tUndefine symbol\n");
#if OSL_DEBUG_LEVEL > 1
                fprintf(stderr, "  -Xvalue\t\tSet internal debug flag\n");
                fprintf(stderr, "  -P\t\t\tdump #define's\n");
#endif
                break;
            }                       /* Switch on all options        */
        }                           /* If it's a -option            */
    }                               /* For all arguments            */
#if OSL_DEBUG_LEVEL > 1
    if ( (bDumpDefs ? j > 4 : j > 3) )
#else
    if (j > 3)
#endif
    {
        cerror( "Too many file arguments.  Usage: cpp [input [output]]",
                NULLST);
    }
    return (j);                     /* Return new argc              */
}
Example #8
0
File: main.c Project: beckerg/clp
int
main(int argc, char **argv)
{
    char errbuf[128];
    int xoptind;
    int rc;
    int i;

    progname = strrchr(argv[0], '/');
    progname = (progname ? progname + 1 : argv[0]);

    rc = clp_parsev(argc, argv, optionv, NULL, errbuf, sizeof(errbuf), &xoptind);
    if (rc) {
        fprintf(stderr, "%s: %s\n\n", progname, errbuf);
        exit(rc);
    }

    argc -= xoptind;
    argv += xoptind;

    if (argc > 0)
        printf("argc=%d xoptind=%d\n", argc, xoptind);

    if (given('v'))
        printf("verbosity is %d %d\n", verbosity, given('v'));

    for (i = 0; i < argc; ++i) {
        printf("posparams: %d %s\n", i, argv[i]);
    }

    if (given('n'))
        printf("dryrun is %d %d\n", dryrun, given('n'));

    if (cf || given('C'))
        printf("cf is %s %d\n", ferror(cf) ? "in error" : "open", given('C'));

    if (given('i'))
        printf("myint is %d %d\n", myint, given('i'));

    if (given('I'))
        printf("myuint is %u %d\n", myuint, given('I'));

    if (given('l'))
        printf("mylong is %ld %d\n", mylong, given('l'));

    if (given('L'))
        printf("myulong is %lu %d\n", myulong, given('L'));

    if (given('s'))
        printf("mystring is %s %d\n", mystring, given('s'));

    if (given('x'))
        printf("x is %s %d\n", xflag ? "true" : "false", given('x'));

    if (given('y'))
        printf("y is %s %d\n", yflag ? "true" : "false", given('y'));

    if (given('z'))
        printf("z is %s %d\n", zflag ? "true" : "false", given('z'));

    if (given('f'))
        printf("f is %.*g\n", FLT_DECIMAL_DIG, myfloat);

    if (given('d'))
        printf("d is %.*lf\n", DBL_DECIMAL_DIG, mydouble);

    if (given('j')) {
        printf("intv is: ");
        for (i = 0; i < intv.len; ++i) {
            printf(" %d", intv.data[i]);
        }
        printf("\n");
    }

    if (given('t'))
        printf("t is %ld\n", mytime);

    printf("\n");

    return 0;
}
TEST(sprintf, InsertString) {

  expect("Hello world\n");
  given(sprintf(&output[1], "Hello %s\n", "world"));

}
Example #10
0
TEST(sprintf, NoFormatOperations) {

  expect("hey");
  given(sprintf(&output[1], "%s", expected));

}
Example #11
0
TEST(sprintf, InsertString)
{
    expect("Hello World\n");
    given(sprintf(output, "Hello %s\n", "World"));
}
Example #12
0
TEST(sprintf, NoFormatOperations)
{
    expect("hey");
    given(sprintf(output, "hey"));
}
void test_InsertString(void)
{
  expect("Hello, World\n");
  given(sprintf(buffer, "Hello, World\n"));
}
void test_NoFormatOperations(void)
{
  expect("hey");
  given(sprintf(buffer, "hey"));
}