ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

type.c
Go to the documentation of this file.
00001 /*
00002  *  TYPE.C - type internal command.
00003  *
00004  *  History:
00005  *
00006  *    07/08/1998 (John P. Price)
00007  *        started.
00008  *
00009  *    07/12/98 (Rob Lake)
00010  *        Changed error messages
00011  *
00012  *    27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
00013  *        added config.h include
00014  *
00015  *    07-Jan-1999 (Eric Kohl)
00016  *        Added support for quoted arguments (type "test file.dat").
00017  *        Cleaned up.
00018  *
00019  *    19-Jan-1999 (Eric Kohl)
00020  *        Unicode and redirection ready!
00021  *
00022  *    19-Jan-1999 (Paolo Pantaleo <paolopan@freemail.it>)
00023  *        Added multiple file support (copied from y.c)
00024  *
00025  *    30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
00026  *        Remove all hardcode string to En.rc
00027  */
00028 
00029 #include <precomp.h>
00030 
00031 #ifdef INCLUDE_CMD_TYPE
00032 
00033 
00034 INT cmd_type (LPTSTR param)
00035 {
00036     TCHAR  buff[256];
00037     HANDLE hFile, hConsoleOut;
00038     DWORD  dwRet;
00039     INT    argc,i;
00040     LPTSTR *argv;
00041     LPTSTR errmsg;
00042     BOOL bPaging = FALSE;
00043     BOOL bFirstTime = TRUE;
00044 
00045     hConsoleOut=GetStdHandle (STD_OUTPUT_HANDLE);
00046 
00047     if (!_tcsncmp (param, _T("/?"), 2))
00048     {
00049         ConOutResPaging(TRUE,STRING_TYPE_HELP1);
00050         return 0;
00051     }
00052 
00053     if (!*param)
00054     {
00055         error_req_param_missing ();
00056         return 1;
00057     }
00058 
00059     argv = split (param, &argc, TRUE, FALSE);
00060 
00061     for(i = 0; i < argc; i++)
00062     {
00063         if(*argv[i] == _T('/') && _tcslen(argv[i]) >= 2 && _totupper(argv[i][1]) == _T('P'))
00064         {
00065             bPaging = TRUE;
00066         }
00067     }
00068 
00069     for (i = 0; i < argc; i++)
00070     {
00071         if (_T('/') == argv[i][0] && _totupper(argv[i][1]) != _T('P'))
00072         {
00073             ConErrResPrintf(STRING_TYPE_ERROR1, argv[i] + 1);
00074             continue;
00075         }
00076 
00077         nErrorLevel = 0;
00078 
00079         hFile = CreateFile(argv[i],
00080             GENERIC_READ,
00081             FILE_SHARE_READ,NULL,
00082             OPEN_EXISTING,
00083             FILE_ATTRIBUTE_NORMAL,NULL);
00084 
00085         if(hFile == INVALID_HANDLE_VALUE)
00086         {
00087             FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
00088                            FORMAT_MESSAGE_IGNORE_INSERTS |
00089                            FORMAT_MESSAGE_FROM_SYSTEM,
00090                            NULL,
00091                            GetLastError(),
00092                            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00093                            (LPTSTR) &errmsg,
00094                            0,
00095                            NULL);
00096             ConErrPrintf (_T("%s - %s"), argv[i], errmsg);
00097             LocalFree (errmsg);
00098             nErrorLevel = 1;
00099             continue;
00100         }
00101 
00102         if (bPaging)
00103         {
00104             while (FileGetString (hFile, buff, sizeof(buff) / sizeof(TCHAR)))
00105             {
00106                 if (ConOutPrintfPaging(bFirstTime, _T("%s"), buff) == 1)
00107                 {
00108                     bCtrlBreak = FALSE;
00109                     CloseHandle(hFile);
00110                     freep(argv);
00111                     return 0;
00112                 }
00113                 bFirstTime = FALSE;
00114             }
00115         }
00116         else
00117         {
00118             while (ReadFile(hFile, buff, sizeof(buff), &dwRet, NULL) && dwRet > 0)
00119             {
00120                 WriteFile(hConsoleOut, buff, dwRet, &dwRet, NULL);
00121                 if (bCtrlBreak)
00122                 {
00123                     bCtrlBreak = FALSE;
00124                     CloseHandle(hFile);
00125                     freep(argv);
00126                     return 0;
00127                 }
00128             }
00129         }
00130 
00131         ConOutPuts(_T("\n"));
00132         CloseHandle(hFile);
00133     }
00134 
00135     freep (argv);
00136 
00137     return 0;
00138 }
00139 
00140 #endif

Generated on Sun May 27 2012 04:18:16 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.