Пример #1
0
void writer(string args)
{
	if (streql(splitArg(args, 1),"-H"))
	{
		writerHelp();
	}
	else if (streql(splitArg(args, 1),"STABLE"))
	{
		oldWriter();
	}
	else
	{
		//writing = true;
		writerContents = initWriter();
		//writing = false;
		clearScreen();
	}
}
Пример #2
0
void me(string args)
{
    if (!hasSetup)
    {
        if (streql(splitArg(args, 1), "-H"))
        {
            // a super legit help section brought to you by @plankp
            print("\nMe is here to help you... Believe me...", brown);
        }
        else if (streql(splitArg(args, 1), "TEST") && !hasSetup)
        {
            hasSetup = true;
            messageBox("\nYou have skipped the Me setup process.");
        }
        else if (!hasSetup)
        {
            meHeader();

            messageBox("\nWelcome to Me. To start using Me,\n\rpress <RET> to setup Me.");

            meHeader();

            name = messageBox_I("What is your name?");

            meHeader();

            while (!birthYearValid)
            {
                birthYear = messageBox_I("What year were you born in?");
                birthYearInt = stoi(birthYear);

                // need to make this always the current year + 1
                if (birthYearInt < getTime("year") && birthYearInt > 1900)
                {
                    birthYearValid = true;
                    goodAnswer();
                }

                if (!birthYearValid)
                {
                    badAnswer();
                }
            }

            meHeader();

            while (!birthDateValid)
            {
                newline();
                birthDate = messageBox_I("What day were you born on");
                birthDateInt = stoi(birthDate);

                if (birthDateInt < 32)
                {
                    birthDateValid = true;
                    goodAnswer();
                }

                if (!birthDateValid)
                {
                    badAnswer();
                }
            }

            meHeader();

            while (!birthMonthValid)
            {
                newline();
                birthMonth = messageBox_I("What month were you born in?");
                birthMonth = toUpper(birthMonth);

                if (findInDictionary("me/setup/month.text",birthMonth))
                {
                    birthMonthValid = true;
                    goodAnswer();
                }

                if (!birthMonthValid)
                {
                    badAnswer();
                }
            }

            meHeader();

            while (!continentValid)
            {

                newline();
                continent = messageBox_I("What continent do you live in?");
                continent = toUpper(continent);

                if (findInDictionary("me/setup/continent.text",continent))
                {
                    continentValid = true;
                    goodAnswer();
                }

                if (!continentValid)
                {
                    badAnswer();
                }
            }

            meHeader();

            while (!countryValid)
            {
                newline();
                country = messageBox_I("What country do you live in?");
                country = toUpper(country);

                if (findInDictionary("me/setup/country.text",country))
                {
                    countryValid = true;
                    goodAnswer();
                }

                if (!countryValid)
                {
                    badAnswer();
                }
            }

            meHeader();

            while (!stateValid)
            {
                newline();
                state = messageBox_I("What state/province do you live in?");
                state = toUpper(state);

                if (findInDictionary("me/setup/state.text",state))
                {
                    stateValid = true;
                    goodAnswer();
                }

                if (!stateValid)
                {
                    badAnswer();
                }
            }

            meHeader();

            newline();
            city = messageBox_I("What city/town do you live in?");

            clearLine(0,26,0x88);

            drawFrame(header_background, 20, 8, 60, 11);
            printAt("Me Setup Process", 0x3D, 21, 9);

            while (!zipValid)
            {
                newline();
                zip = messageBox_I("What is your zip/post code?");
                zipInt = htoi(zip);
                if (zipInt > 0)
                {
                    zipValid = true;
                    goodAnswer();
                }
                else
                {
                    badAnswer();
                }
            }

            meHeader();

            hasSetup = "true";
            messageBox("Me is now ready to use! Type 'me' on\n\rthe command line to begin.");

            printIntro();
            drawBorder(screen_background, 0, 4, 80, sh - 1);

            actualY = 5;
            printAt("Q-Kernel>  ", light_grey, 1, actualY);
        }
        else
        {
            print("\nYou have already completed the setup process for Me!",purple);
        }
    }
    else if (streql(splitArg(args, 1),""))
    {
        querying = true;
        string meArgs = NULL;

        while (querying)
        {
            newline();

            //meArgs = "";
            print("me>  ",green);
            meArgs = readstr();

            print(answer(meArgs,0),red);
        }
    }
    else
    {
        answer(args,1);
    }
}
Пример #3
0
int painter(string args)
{
    if (streql(splitArg(args, 1), "-H"))
    {
        print("\nPainter is a simple drawing app for Q OS",red);
        print("\nTo use it, type 'painter' on the command line.",red);
        print("\nUse the arrow keys to draw lines on your screen.",red);
        print("\nPress the spacebar to reset your drawing.",red);
        print("\nPress X to change the X location of your pen and Y to change the Y location.",red);
    }
    else
    {
        // Run the setup function for painter
        resetPainter();
        bool isDrawing = true;
#define GET_PAINT_COLOR isDrawing ? 0x00 : screen_color
        // Begin the actual painter program
        while (true)
        {

            if (paintX < 1)
            {
                paintX = 1;
            }
            else if (paintX > 78)
            {
                paintX = 78;
            }

            if (paintY < 5)
            {
                paintY = 5;
            }
            else if (paintY > 23)
            {
                paintY = 23;
            }

            printAt("*",0xDD,paintX,paintY);
            printStatus(isDrawing);

            int key = getKeycode() / KC_MAGIC_VAL;

            switch (key)
            {
            case 1:
                // Escape Pressed
                clearScreen();
                return 0;
            case 72:
                // Up Arrow Pressed
                printAt(" ", GET_PAINT_COLOR, paintX, paintY);
                paintY--;
                break;
            case 80:
                // Down Arrow Pressed
                printAt(" ", GET_PAINT_COLOR, paintX, paintY);
                paintY++;
                break;
            case 75:
                // Left Arrow Pressed
                printAt(" ", GET_PAINT_COLOR, paintX, paintY);
                paintX--;
                break;
            case 77:
                // Right Arrow Pressed
                printAt(" ", GET_PAINT_COLOR, paintX, paintY);
                paintX++;
                break;
            case 57:
                // Spacebar Pressed
                resetPainter();
                break;
            case 0x2E:
                // C pressed
                isDrawing = true;
                break;
            case 0x12:
                // E pressed
                isDrawing = false;
                break;
            case -82:
                // X Released
                printAt(" ",screen_color,paintX,paintY);

                drawFrame(header_background, 0, 0, 80, 4);
                printAt("What X Posiiton do you want to move the pen to?\r\n", header_foreground, 1, 1);

                cursorX = 1;
                cursorY = 2;

                // we need to make the text below when input show in a blue on aqua font...
                paintX = stoi(readstr());

                painterIntro();
                break;
            case -106:
                // Y Pressed
                printAt(" ",screen_color,paintX,paintY);

                drawFrame(header_background, 0, 0, 80, 4);
                printAt("What Y Posiiton do you want to move the pen to?\r\n", header_foreground, 1, 1);

                cursorX = 1;
                cursorY = 2;

                // we need to make the text below when input show in a blue on aqua font...
                paintY = stoi(readstr());

                painterIntro();
                break;
            default:
                break;
            }
        }
    }


    return 0;

}
Пример #4
0
void test(string args)
{
    args = splitArg(args, 1);
    if(streql(args, "") || streql(args, "-H"))
    {
        print("\nThis file is in charge of testing the data types embedded in Q-OS.",black);
        print("\nAccepted Arguments:\n-list\tTests the list.c file\n-set \ttests the set.c file", black);
        print("\n-strb\ttests the strbuilder.c file\n-y   \tshould return the current year...",black);
    }
    else if(streql(args, "-LIST"))//For testing lists
    {
        newline();
        list_t test_list = list_init();
        test_list.autoShrink = true;

        for(uint8 i = 0; i < 4; i++)
        {
            list_add(&test_list, "1");
            list_add(&test_list, "2");
            list_add(&test_list, "3");
            list_add(&test_list, "4");
            list_add(&test_list, "5");
            list_add(&test_list, "6");
            list_add(&test_list, "7");
            list_add(&test_list, "8");
            list_add(&test_list, "9");
            list_add(&test_list, "10");
            list_add(&test_list, "11");
            list_add(&test_list, "12");
            list_add(&test_list, "13");
            list_add(&test_list, "14");
            list_add(&test_list, "15");
            list_add(&test_list, "16");
        }
        list_add(&test_list, "Pointless");

        println("Done sizing up", white);
        printint(test_list.capt, white);

        element_t t;
        for(uint8 i = 0; i < 64; i++)
        {
            t = list_shift(&test_list);
        }
        println("\nLast item deleted should be \"16\"", white);
        println(t.udata.strdata, white);
        println("\nDeleting all but element \"Pointless\"", white);
        for(uint8 i = 0; i < test_list.size; i++)
        {
            println(list_get(test_list, i), white);
        }
        println("Done resizing up", white);
        printint(test_list.capt, white);
        list_destroy(&test_list);
    }
    else if(streql(args,"-SET"))
    {
        set_t test_set = set_init();
        for(uint8 i = 0; i < 4; i++)
        {
            set_add(&test_set, "0");
            set_add(&test_set, "1");
            set_add(&test_set, "2");
            set_add(&test_set, "3");
            set_add(&test_set, "4");
            set_add(&test_set, "5");
            set_add(&test_set, "6");
            set_add(&test_set, "7");
            set_add(&test_set, "8");
            set_add(&test_set, "9");
            set_add(&test_set, "10");
            set_add(&test_set, "11");
            set_add(&test_set, "12");
            set_add(&test_set, "13");
            set_add(&test_set, "14");
            set_add(&test_set, "15");
            set_add(&test_set, "16");
            print("\nIteration: ", white);
            printint(i, white);
        }
        println("\n\nInsertion::Output should be 17", white);
        printint(test_set.size, white);

        set_t tmp = set_init();
        set_add(&tmp, "Union item");
        set_union(&test_set, &tmp);
        println("\n\nUnion::Output should be 18", white);
        printint(test_set.size, white);

        set_intersect(&test_set, &tmp);
        println("\n\nIntersect::Output should be 1", white);
        printint(test_set.size, white);

        println("\n\nPreparing for diff test", white);
        set_add(&test_set, "1");
        set_add(&test_set, "2");
        set_add(&test_set, "3");
        set_add(&tmp, "2");
        set_add(&tmp, "3");
        set_add(&tmp, "4");
        set_diff(&test_set, &tmp);
        println("Diff::Output should be 2", white);
        printint(test_set.size, white);

        set_destroy(&tmp);
        set_destroy(&test_set);
    }
    else if(streql(args, "-STRB"))
    {
        static const string bak = "Hello, world ";
        static const uint32 bln = 13;
        strbuilder_t test_strb = strbuilder_init();

        strbuilder_append(&test_strb, bak);
        strbuilder_append(&test_strb, "Hello, 2nd world");
        println("\nTesting backup text. Output should 1", red);
        printint(streql(bak, test_strb.prevTxt), green);
        println("\nOutput should be \"Hello, world Hello, 2nd world\"", red);
        println(strbuilder_tostr(test_strb), green);
        println("\nRemoving greeters from first world", red);
        strbuilder_delete(&test_strb, 0, bln);
        println("\nOutput should be \"Hello, 2nd world\"", red);
        println(strbuilder_tostr(test_strb), green);
        strbuilder_flip(&test_strb);
        println("\nOutput should be \"dlrow dn2 ,olleH\"", red);
        println(strbuilder_tostr(test_strb), green);
        list_t tmp = strbuilder_split(test_strb, " ");
        println("\nOutput should be last str split by spaces", red);
        for(uint8 i = 0; i < tmp.size; i++)
        {
            println(list_get(tmp, i), white);
        }
        list_destroy(&tmp);
        strbuilder_destroy(&test_strb);
    }
    else if(streql(args,"-Y"))
    {
       //getTime() test
       printint(getTime("year"),white);
    }
}
Пример #5
0
void me(string args) {
    if (strEql(splitArg(args, 1), "setup") || !hasSetup)
    {
        if (strEql(splitArg(args, 2), "skip") && !hasSetup)
        {
            hasSetup = true;
            print("\nYou have skipped the Me setup process, some answers may be strange :D",0x06);
        }
        else if (!hasSetup)
        {
            print("\nWelcome to Me.",0x03);
            print("\nMe is the worlds first truly rubbish personal assistant.",0x03);
            print("\nTo use me, simply ask it a question.",0x03);
            print("\nFor example, type 'me what is the time?'",0x03);
            print("\nTo start using Me, please enter some basic information below when prompted.",0x03);
            newline();

            newline();
            print("What is your name: ",0x0B);
            readStr(name,128);

            while (!birthYearValid)
            {
                newline();
                print("What year were you born in: ",0x0B);
                readStr(birthYear,5);
                birthYearInt = stoi(birthYear);

                // need to make this always the current year + 1
                if (birthYearInt < 2016 && birthYearInt > 1900)
                {
                    birthYearValid = true;
                    print(" Good",0x02);
                }

                if (!birthYearValid)
                {
                    print(" Invalid",0x0C);
                }
            }


            while (!birthDateValid)
            {
                newline();
                print("What day of the month were you born in: ",0x0B);
                readStr(birthDate,3);
                birthDateInt = stoi(birthDate);

                if (birthDateInt < 32)
                {
                    birthDateValid = true;
                    print(" Good",0x02);
                }

                if (!birthDateValid)
                {
                    print(" Invalid",0x0C);
                }
            }

            while (!birthMonthValid)
            {
                newline();
                print("What month were you born in: ",0x0B);
                readStr(birthMonth,128);
                birthMonth = toUpper(birthMonth);

                for(uint32 tmp = 0; tmp < arrLength(months); tmp++)
                {
                    if (strEql(months[tmp],birthMonth))
                    {
                        birthMonthValid = true;
                        print(" Good",0x02);
                    }
                }

                if (!birthMonthValid)
                {
                    print(" Invalid",0x0C);
                }
            }

            while (!continentValid)
            {

                newline();
                print("What continent do you live in: ",0x0B);
                readStr(continent,128);
                continent = toUpper(continent);

                for(uint32 tmp = 0; tmp < arrLength(continents); tmp++)
                {
                    if (strEql(continents[tmp],continent))
                    {
                        continentValid = true;
                        print(" Good",0x02);
                    }
                }

                if (!continentValid)
                {
                    print(" Invalid",0x0C);
                }
            }


            while (!countryValid)
            {
                newline();
                print("What country do you live in: ",0x0B);
                readStr(country,128);
                country = toUpper(country);

                for(uint32 tmp = 0; tmp < arrLength(countries); tmp++)
                {
                    if (strEql(countries[tmp],country))
                    {
                        countryValid = true;
                        print(" Good",0x02);
                    }
                }

                if (!countryValid)
                {
                    print(" Invalid",0x0C);
                }
            }

            while (!stateValid)
            {
                newline();
                print("What state/province do you currently live in: ",0x0B);
                readStr(state,128);
                state = toUpper(state);

                for(uint8 tmp = 0; tmp < arrLength(states); tmp++)
                {
                    if(strEql(states[tmp],country))
                    {
                        stateValid = true;
                        print(" Good",0x02);
                    }
                }

                if (!stateValid)
                {
                    print(" Invalid",0x0C);
                }
            }

            newline();
            print("What city do you live in: ",0x0B);
            readStr(city,128);

            while (!zipValid)
            {
                newline();
                print("What is the zip/post code in your area: ",0x0B);
                readStr(zip,17);

                if (strEql(country,"CANADA"))
                {
                    print(" Good Enough",0x02);
                    zipValid = true;
                }
                else
                {
                    zipInt = stoi(zip);
                    if (zipInt < 9999999999999999 && zipInt > 0)
                    {
                        zipValid = true;
                        print(" Good",0x02);
                    }

                    if (!zipValid)
                    {
                        print(" Invalid",0x0C);
                    }
                }
            }

            newline();
            hasSetup = "true";
            print("Me is now ready to use!",0x03);

            newline();
            print("When Me dosen't know information, it can ask you for help.",0x03);
        }
        else
        {
            print("\nYou have already completed the setup process for Me!",0x05);
        }
    }
    else
    {
        bool over = false;
        int tmp = 0;
        while (!over)
        {
            tmp++;

            if (strEql(splitArg(args, tmp),""))
            {
                over = true;
            }
            else
            {
                newline();
                printint(tmp,0x0A);
                print(" : ",0x0B);
                print(curWord,0x0A);
                print(" : ",0x0B);
                printfloat(sort(splitArg(args, tmp)),0x09);

            }
        }
    }
}