Exemplo n.º 1
0
void PrintChars(const char* str)
{
	if (*str != NULL)
	{
		printf("%c", *str);
		PrintChars(str + 1);
	}else
		return;
}
Exemplo n.º 2
0
int main(int argc, char* argv[])
{
	char * string = "Hello Kookmin Univ.";
	printf("The Length of \"%s\" = %d\n", string, Length(string));

	PrintChars(string);
	printf("\n");

	ReversePrintChars(string);
	printf("\n");
	return 0;
}
Exemplo n.º 3
0
int main (int argc, const char * argv[]) {
	PrintChars( 32, 47 );
	PrintChars( 48, 57 );
	PrintChars( 58, 64 );
	PrintChars( 65, 90 );
	PrintChars( 91, 96 );
	PrintChars( 97, 122 );
	PrintChars( 123, 126 );
	
	return 0;
}
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
  int test_font = 0;  // set to 1 to print on text console
  if (argc!=2)
  {
    Help(argv[0]);
  }
  if (test_font)
  {
    InitBuffer(80, 30);
  }
  else
  {
    InitFrameBuffer(320, 200);
  }
  
  PrintChars(argv[1], test_font);
  
  if (test_font)
  {
    PrintBuffer();
  }
  return 0;
}
Exemplo n.º 5
0
VOID
FileEvtIoDeviceControl(
    IN WDFQUEUE         Queue,
    IN WDFREQUEST       Request,
    IN size_t            OutputBufferLength,
    IN size_t            InputBufferLength,
    IN ULONG            IoControlCode
    )
/*++
Routine Description:

    This event is called when the framework receives IRP_MJ_DEVICE_CONTROL
    requests from the system.

Arguments:

    Queue - Handle to the framework queue object that is associated
            with the I/O request.
    Request - Handle to a framework request object.

    OutputBufferLength - length of the request's output buffer,
                        if an output buffer is available.
    InputBufferLength - length of the request's input buffer,
                        if an input buffer is available.

    IoControlCode - the driver-defined or system-defined I/O control code
                    (IOCTL) that is associated with the request.

Return Value:

   VOID

--*/
{
    NTSTATUS            status = STATUS_SUCCESS;// Assume success
    PCHAR               inBuf = NULL, outBuf = NULL; // pointer to Input and output buffer
    PCHAR               data = "this String is from Device Driver !!!";
    ULONG               datalen = (ULONG) strlen(data)+1;//Length of data including null
    PCHAR               buffer = NULL;
    PREQUEST_CONTEXT    reqContext = NULL;
    size_t               bufSize;

    UNREFERENCED_PARAMETER( Queue );

    PAGED_CODE();

    if(!OutputBufferLength || !InputBufferLength)
    {
        WdfRequestComplete(Request, STATUS_INVALID_PARAMETER);
        return;
    }

    //
    // Determine which I/O control code was specified.
    //

    switch (IoControlCode)
    {
    case IOCTL_NONPNP_METHOD_BUFFERED:


        TraceEvents(TRACE_LEVEL_VERBOSE, DBG_IOCTL, "Called IOCTL_NONPNP_METHOD_BUFFERED\n");

        //
        // For bufffered ioctls WdfRequestRetrieveInputBuffer &
        // WdfRequestRetrieveOutputBuffer return the same buffer
        // pointer (Irp->AssociatedIrp.SystemBuffer), so read the
        // content of the buffer before writing to it.
        //
        status = WdfRequestRetrieveInputBuffer(Request, 0, &inBuf, &bufSize);
        if(!NT_SUCCESS(status)) {
            status = STATUS_INSUFFICIENT_RESOURCES;
            break;
        }

        ASSERT(bufSize == InputBufferLength);

        //
        // Read the input buffer content.
        // We are using the following function to print characters instead
        // TraceEvents with %s format because the string we get may or
        // may not be null terminated. The buffer may contain non-printable
        // characters also.
        //
        Hexdump((TRACE_LEVEL_VERBOSE,  DBG_IOCTL, "Data from User : %!HEXDUMP!\n",
                        log_xstr(inBuf, (USHORT)InputBufferLength)));
        PrintChars(inBuf, InputBufferLength  );


        status = WdfRequestRetrieveOutputBuffer(Request, 0, &outBuf, &bufSize);
        if(!NT_SUCCESS(status)) {
            status = STATUS_INSUFFICIENT_RESOURCES;
            break;
        }

        ASSERT(bufSize == OutputBufferLength);

        //
        // Writing to the buffer over-writes the input buffer content
        //

        RtlCopyMemory(outBuf, data, OutputBufferLength);

        Hexdump((TRACE_LEVEL_VERBOSE,  DBG_IOCTL, "Data to User : %!HEXDUMP!\n",
                        log_xstr(outBuf, (USHORT)datalen)));
        PrintChars(outBuf, datalen  );

        //
        // Assign the length of the data copied to IoStatus.Information
        // of the request and complete the request.
        //
        WdfRequestSetInformation(Request,
                OutputBufferLength < datalen? OutputBufferLength:datalen);

        //
        // When the request is completed the content of the SystemBuffer
        // is copied to the User output buffer and the SystemBuffer is
        // is freed.
        //

       break;


    case IOCTL_NONPNP_METHOD_IN_DIRECT:


        TraceEvents(TRACE_LEVEL_VERBOSE, DBG_IOCTL, "Called IOCTL_NONPNP_METHOD_IN_DIRECT\n");

        //
        // Get the Input buffer. WdfRequestRetrieveInputBuffer returns
        // Irp->AssociatedIrp.SystemBuffer.
        //
        status = WdfRequestRetrieveInputBuffer(Request, 0, &inBuf, &bufSize);
        if(!NT_SUCCESS(status)) {
            status = STATUS_INSUFFICIENT_RESOURCES;
            break;
        }

        ASSERT(bufSize == InputBufferLength);

        Hexdump((TRACE_LEVEL_VERBOSE,  DBG_IOCTL, "Data from User : %!HEXDUMP!\n",
                        log_xstr(inBuf, (USHORT)InputBufferLength)));
        PrintChars(inBuf, InputBufferLength);

        //
        // Get the output buffer. Framework calls MmGetSystemAddressForMdlSafe
        // on the Irp->MdlAddress and returns the system address.
        // Oddity: For this method, this buffer is intended for transfering data
        // from the application to the driver.
        //

        status = WdfRequestRetrieveOutputBuffer(Request, 0, &buffer, &bufSize);
        if(!NT_SUCCESS(status)) {
            break;
        }

        ASSERT(bufSize == OutputBufferLength);

        Hexdump((TRACE_LEVEL_VERBOSE,  DBG_IOCTL, "Data from User in OutputBuffer: %!HEXDUMP!\n",
                        log_xstr(buffer, (USHORT)OutputBufferLength)));
        PrintChars(buffer, OutputBufferLength);

        //
        // Return total bytes read from the output buffer.
        // Note OutputBufferLength = MmGetMdlByteCount(Irp->MdlAddress)
        //

        WdfRequestSetInformation(Request, OutputBufferLength);

        //
        // NOTE: Changes made to the  SystemBuffer are not copied
        // to the user input buffer by the I/O manager
        //

      break;

    case IOCTL_NONPNP_METHOD_OUT_DIRECT:


        TraceEvents(TRACE_LEVEL_VERBOSE, DBG_IOCTL, "Called IOCTL_NONPNP_METHOD_OUT_DIRECT\n");

        //
        // Get the Input buffer. WdfRequestRetrieveInputBuffer returns
        // Irp->AssociatedIrp.SystemBuffer.
        //
        status = WdfRequestRetrieveInputBuffer(Request, 0, &inBuf, &bufSize);
        if(!NT_SUCCESS(status)) {
            status = STATUS_INSUFFICIENT_RESOURCES;
            break;
        }

        ASSERT(bufSize == InputBufferLength);

        Hexdump((TRACE_LEVEL_VERBOSE,  DBG_IOCTL, "Data from User : %!HEXDUMP!\n",
                        log_xstr(inBuf, (USHORT)InputBufferLength)));
        PrintChars(inBuf, InputBufferLength);

        //
        // Get the output buffer. Framework calls MmGetSystemAddressForMdlSafe
        // on the Irp->MdlAddress and returns the system address.
        // For this method, this buffer is intended for transfering data from the
        // driver to the application.
        //
        status = WdfRequestRetrieveOutputBuffer(Request, 0, &buffer, &bufSize);
        if(!NT_SUCCESS(status)) {
            break;
        }

        ASSERT(bufSize == OutputBufferLength);

        //
        // Write data to be sent to the user in this buffer
        //
        RtlCopyMemory(buffer, data, OutputBufferLength);

        Hexdump((TRACE_LEVEL_VERBOSE,  DBG_IOCTL, "Data to User : %!HEXDUMP!\n",
                        log_xstr(buffer, (USHORT)datalen)));
        PrintChars(buffer, datalen);

        WdfRequestSetInformation(Request,
                    OutputBufferLength < datalen? OutputBufferLength: datalen);

        //
        // NOTE: Changes made to the  SystemBuffer are not copied
        // to the user input buffer by the I/O manager
        //

        break;

    case IOCTL_NONPNP_METHOD_NEITHER:
        {
            size_t inBufLength, outBufLength;

            //
            // The NonPnpEvtDeviceIoInCallerContext has already probe and locked the
            // pages and mapped the user buffer into system address space and
            // stored memory buffer pointers in the request context. We can get the
            // buffer pointer by calling WdfMemoryGetBuffer.
            //
            TraceEvents(TRACE_LEVEL_VERBOSE, DBG_IOCTL, "Called IOCTL_NONPNP_METHOD_NEITHER\n");

            reqContext = GetRequestContext(Request);

            inBuf = WdfMemoryGetBuffer(reqContext->InputMemoryBuffer, &inBufLength);
            outBuf = WdfMemoryGetBuffer(reqContext->OutputMemoryBuffer, &outBufLength);

            if(inBuf == NULL || outBuf == NULL) {
                status = STATUS_INVALID_PARAMETER;
            }

            ASSERT(inBufLength == InputBufferLength);
            ASSERT(outBufLength == OutputBufferLength);

            //
            // Now you can safely read the data from the buffer in any arbitrary
            // context.
            //
            Hexdump((TRACE_LEVEL_VERBOSE,  DBG_IOCTL, "Data from User : %!HEXDUMP!\n",
                            log_xstr(inBuf, (USHORT)inBufLength)));
            PrintChars(inBuf, inBufLength);

            //
            // Write to the buffer in any arbitrary context.
            //
            RtlCopyMemory(outBuf, data, outBufLength);

            Hexdump((TRACE_LEVEL_VERBOSE,  DBG_IOCTL, "Data to User : %!HEXDUMP!\n",
                            log_xstr(outBuf, (USHORT)datalen)));
            PrintChars(outBuf, datalen);

            //
            // Assign the length of the data copied to IoStatus.Information
            // of the Irp and complete the Irp.
            //
            WdfRequestSetInformation(Request,
                    outBufLength < datalen? outBufLength:datalen);

            break;
        }
    default:

        //
        // The specified I/O control code is unrecognized by this driver.
        //
        status = STATUS_INVALID_DEVICE_REQUEST;
        TraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTL, "ERROR: unrecognized IOCTL %x\n", IoControlCode);
        break;
    }

    TraceEvents(TRACE_LEVEL_VERBOSE, DBG_IOCTL, "Completing Request %p with status %X",
                   Request, status );

    WdfRequestComplete( Request, status);

}
Exemplo n.º 6
0
void GTerm::pc_arg( void )
{
    int i, yp, yp2;

    //printf("pc_arg: pc_curcmd = %d...\n", pc_curcmd);

    pc_args[pc_argcount++ ] = * input_data;

    if (pc_argcount == pc_numargs)
    {
        switch (pc_curcmd)
        {
            case GTERM_PC_CMD_CURONOFF:
                //printf("pc_arg: curonoff got %d\n", *input_data);
                if (* input_data)
                    clear_mode_flag(CURSORINVISIBLE);
                else
                    set_mode_flag(CURSORINVISIBLE);

                current_state = pc_cmd_state;
                changed_line(cursor_y, cursor_x, cursor_x);
                break;

            case GTERM_PC_CMD_MOVECURSOR:
                //printf("pc_arg: movecursor (%d, %d)\n", pc_args[0], pc_args[1]);
                move_cursor(pc_args[0], pc_args[1]);
                current_state = pc_cmd_state;
                break;

            case GTERM_PC_CMD_PUTTEXT:
                //printf("pc_arg: puttext got %d, %d, %d, %d\n", pc_args[0], pc_args[1], pc_args[2], pc_args[3]);
                pc_numdata = pc_args[2] * pc_args[3] * 2;
                pc_datacount = 0;
                pc_curx = pc_args[0];
                pc_cury = pc_args[1];

                if (pc_numdata)
                    current_state = pc_data_state;
                else
                    current_state = pc_cmd_state;

                break;

            case GTERM_PC_CMD_WRITE:
                //printf("pc_arg: write got %d, %d, %d, %d\n", pc_args[0], pc_args[1], pc_args[2], pc_args[3]);
                pc_numdata = pc_args[2];
                pc_datacount = 0;
                pc_curx = pc_args[0];
                pc_cury = pc_args[1];

                if (pc_numdata)
                    current_state = pc_data_state;
                else
                    current_state = pc_cmd_state;

                break;

            case GTERM_PC_CMD_MOVETEXT: // <sx> <sy> <wid> <len> <dx> <dy>
                if (pc_args[1]<pc_args[5])
                {
                    for (i = 0; i<pc_args[3]; i++)
                    {
						int idx1 = pc_args[1] + i;
						yp = linenumbers[idx1] * MAXWIDTH;

						int idx2 = pc_args[5] + i;
						yp2 = linenumbers[idx2] * MAXWIDTH;

                        memmove(& text[yp2 + pc_args[4]], & text[yp + pc_args[0]], pc_args[2]);

						string substring = tm[idx1].substr(pc_args[0], pc_args[2]);
						tm[idx2].replace(pc_args[4], pc_args[2], substring);

                        memmove(& color[yp2 + pc_args[4]], & color[yp + pc_args[0]], pc_args[2]);
						// TODO Doesn't seem to get here in normal use, but probably ought to
						//		eventually figure out what's going on so I can manipulate the text manager here
                        changed_line(pc_args[5] + i, pc_args[4], pc_args[4] + pc_args[2] - 1);
                    }
                }
                else
                {
                    for (i = pc_args[3] - 1; i>=0; i--)
                    {
						int idx1 = pc_args[1] + i;
						yp = linenumbers[idx1] * MAXWIDTH;

						int idx2 = pc_args[5] + i;
						yp2 = linenumbers[idx2] * MAXWIDTH;

                        memmove(& text[yp2 + pc_args[4]], & text[yp + pc_args[0]], pc_args[2]);

						string substring = tm[idx1].substr(pc_args[0], pc_args[2]);
						tm[idx2].replace(pc_args[4], pc_args[2], substring);

                        memmove(& color[yp2 + pc_args[4]], & color[yp + pc_args[0]], pc_args[2]);
						// TODO ditto as with previous
                        changed_line(pc_args[5] + i, pc_args[4], pc_args[4] + pc_args[2] - 1);
                    }
                }

                current_state = pc_cmd_state;
                break;

            case GTERM_PC_CMD_SELECTPRINTER:
                pc_numdata = pc_args[0];
                pc_datacount = 0;
                memset(pc_printername, 0, sizeof(pc_printername));

                if (pc_numdata)
                    current_state = pc_data_state;
                else
                {
                    SelectPrinter("");

                    current_state = pc_cmd_state;
                }

                break;

            case GTERM_PC_CMD_PRINTCHAR:
                PrintChars(1, & pc_args[0]);
                current_state = pc_cmd_state;
                break;

            case GTERM_PC_CMD_PRINTCHARS:
                pc_numdata = (pc_args[0] << 8) + pc_args[1];
                pc_datacount = 0;

                if (pc_numdata)
                    current_state = pc_data_state;
                else
                    current_state = pc_cmd_state;

                break;
        }
    }
}
Exemplo n.º 7
0
void GTerm::pc_data( void )
{
    int yp;
	int altY;

    //printf("pc_data: pc_curcmd = %d, pc_datacount = %d, pc_numdata = %d, pc_curx = %d, pc_cur_y = %d...\n", pc_curcmd, pc_datacount, pc_numdata, pc_curx, pc_cury);
    switch (pc_curcmd)
    {
        case GTERM_PC_CMD_PUTTEXT:
            yp = linenumbers[pc_cury] * MAXWIDTH;

			altY = m_nextLineCounter * MAXWIDTH;

            if (!(pc_datacount & 1))
            {
                //printf("pc_data: got char %d\n", *input_data);
                //text[yp + pc_curx] = * input_data;

				tm[pc_cury][pc_curx] = *input_data;
            }
            else
            {
                //printf("pc_data: got attr %d\n", *input_data);
                //color[yp + pc_curx] = * input_data << 4;
				tm.SetColorAdjusted(pc_cury, pc_curx, (*input_data << 4));
            }

            if (pc_datacount & 1)
            {
                changed_line(pc_cury, pc_args[0], pc_curx);

                pc_curx++;

                if (pc_curx == pc_args[0] + pc_args[2])
                {
                    pc_curx = pc_args[0];

                    pc_cury++;
                }
            }

            break;

        case GTERM_PC_CMD_WRITE:
            yp = linenumbers[pc_cury] * MAXWIDTH;
			altY = m_nextLineCounter * MAXWIDTH;

            //text[yp + pc_curx] = * input_data;
			tm[pc_cury][pc_curx] = *input_data;

            //color[yp + pc_curx] = (unsigned short)pc_args[3] << 4;
			tm.SetColorAdjusted(pc_cury, pc_curx, ((unsigned short)pc_args[3] << 4) );
            changed_line(pc_cury, pc_args[0], pc_curx);
            pc_curx++;
            break;

        case GTERM_PC_CMD_SELECTPRINTER:
            if (pc_datacount<GTERM_PC_MAXPRINTERNAME - 1)
                pc_printername[pc_datacount] = * input_data;

            if (pc_datacount == pc_numdata - 1)
                SelectPrinter(pc_printername);

            break;

        case GTERM_PC_CMD_PRINTCHARS:
            PrintChars(1, input_data);
            break;
    }

    pc_datacount++;

    if (pc_datacount == pc_numdata)
        current_state = pc_cmd_state;
}