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

prompt.c
Go to the documentation of this file.
00001 /*
00002  *  PROMPT.C - prompt handling.
00003  *
00004  *
00005  *  History:
00006  *
00007  *    14/01/95 (Tim Normal)
00008  *        started.
00009  *
00010  *    08/08/95 (Matt Rains)
00011  *        i have cleaned up the source code. changes now bring this source
00012  *        into guidelines for recommended programming practice.
00013  *
00014  *    01/06/96 (Tim Norman)
00015  *        added day of the week printing (oops, forgot about that!)
00016  *
00017  *    08/07/96 (Steffan Kaiser)
00018  *        small changes for speed
00019  *
00020  *    20-Jul-1998 (John P Price <linux-guru@gcfl.net>)
00021  *        removed redundant day strings. Use ones defined in date.c.
00022  *
00023  *    27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
00024  *        added config.h include
00025  *
00026  *    28-Jul-1998 (John P Price <linux-guru@gcfl.net>)
00027  *        moved cmd_prompt from internal.c to here
00028  *
00029  *    09-Dec-1998 (Eric Kohl)
00030  *        Added help text ("/?").
00031  *
00032  *    14-Dec-1998 (Eric Kohl)
00033  *        Added "$+" option.
00034  *
00035  *    09-Jan-1999 (Eric Kohl)
00036  *        Added "$A", "$C" and "$F" option.
00037  *        Added locale support.
00038  *        Fixed "$V" option.
00039  *
00040  *    20-Jan-1999 (Eric Kohl)
00041  *        Unicode and redirection safe!
00042  *
00043  *    24-Jan-1999 (Eric Kohl)
00044  *        Fixed Win32 environment handling.
00045  *
00046  *    30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
00047  *        Remove all hardcode string to En.rc
00048  */
00049 #include <precomp.h>
00050 
00051 /*
00052  * print the command-line prompt
00053  */
00054 VOID PrintPrompt(VOID)
00055 {
00056     static TCHAR default_pr[] = _T("$P$G");
00057     TCHAR  szPrompt[256];
00058     LPTSTR pr;
00059 
00060     if (GetEnvironmentVariable (_T("PROMPT"), szPrompt, 256))
00061         pr = szPrompt;
00062     else
00063         pr = default_pr;
00064 
00065     while (*pr)
00066     {
00067         if (*pr != _T('$'))
00068         {
00069             ConOutChar (*pr);
00070         }
00071         else
00072         {
00073             pr++;
00074 
00075             switch (_totupper (*pr))
00076             {
00077                 case _T('A'):
00078                     ConOutChar (_T('&'));
00079                     break;
00080 
00081                 case _T('B'):
00082                     ConOutChar (_T('|'));
00083                     break;
00084 
00085                 case _T('C'):
00086                     ConOutChar (_T('('));
00087                     break;
00088 
00089                 case _T('D'):
00090                     ConOutPrintf(_T("%s"), GetDateString());
00091                     break;
00092 
00093                 case _T('E'):
00094                     ConOutChar (_T('\x1B'));
00095                     break;
00096 
00097                 case _T('F'):
00098                     ConOutChar (_T(')'));
00099                     break;
00100 
00101                 case _T('G'):
00102                     ConOutChar (_T('>'));
00103                     break;
00104 
00105                 case _T('H'):
00106                     ConOutChar (_T('\x08'));
00107           ConOutChar (_T(' '));
00108           ConOutChar (_T('\x08'));
00109                     break;
00110 
00111                 case _T('L'):
00112                     ConOutChar (_T('<'));
00113                     break;
00114 
00115                 case _T('N'):
00116                     {
00117                         TCHAR szPath[MAX_PATH];
00118                         GetCurrentDirectory (MAX_PATH, szPath);
00119                         ConOutChar (szPath[0]);
00120                     }
00121                     break;
00122 
00123                 case _T('P'):
00124                     {
00125                         TCHAR szPath[MAX_PATH];
00126                         GetCurrentDirectory (MAX_PATH, szPath);
00127                         ConOutPrintf (_T("%s"), szPath);
00128                     }
00129                     break;
00130 
00131                 case _T('Q'):
00132                     ConOutChar (_T('='));
00133                     break;
00134 
00135         case _T('S'):
00136                     ConOutChar (_T(' '));
00137                     break;
00138 
00139                 case _T('T'):
00140                     ConOutPrintf(_T("%s"), GetTimeString());
00141                     break;
00142 
00143                 case _T('V'):
00144                     switch (osvi.dwPlatformId)
00145                     {
00146                         case VER_PLATFORM_WIN32_WINDOWS:
00147                             if (osvi.dwMajorVersion == 4 &&
00148                                 osvi.dwMinorVersion == 1)
00149                                 ConOutPrintf (_T("Windows 98"));
00150                             else
00151                                 ConOutPrintf (_T("Windows 95"));
00152                             break;
00153 
00154 
00155                         case VER_PLATFORM_WIN32_NT:
00156                             ConOutPrintf (_T("Windows NT Version %lu.%lu"),
00157                                           osvi.dwMajorVersion, osvi.dwMinorVersion);
00158                             break;
00159                     }
00160                     break;
00161 
00162                 case _T('_'):
00163                     ConOutChar (_T('\n'));
00164                     break;
00165 
00166                 case '$':
00167                     ConOutChar (_T('$'));
00168                     break;
00169 
00170 #ifdef FEATURE_DIRECTORY_STACK
00171                 case '+':
00172                     {
00173                         INT i;
00174                         for (i = 0; i < GetDirectoryStackDepth (); i++)
00175                             ConOutChar (_T('+'));
00176                     }
00177                     break;
00178 #endif
00179             }
00180         }
00181         pr++;
00182     }
00183 }
00184 
00185 
00186 #ifdef INCLUDE_CMD_PROMPT
00187 
00188 INT cmd_prompt (LPTSTR param)
00189 {
00190     if (!_tcsncmp (param, _T("/?"), 2))
00191     {
00192         ConOutResPaging(TRUE,STRING_PROMPT_HELP1);
00193 
00194 #ifdef FEATURE_DIRECTORY_STACK
00195         ConOutResPaging(FALSE,STRING_PROMPT_HELP2);
00196 #endif
00197         ConOutResPaging(FALSE,STRING_PROMPT_HELP3);
00198         return 0;
00199     }
00200 
00201     /* if it is null, then it needs to set to default,
00202        because that means the user entered "prompt" only.
00203         so even if param is null you _must_ still set prompt
00204         to the default.  There seems to be some kinda difference
00205         between winxp and 2k in this matter and this way will
00206         cover both. Do not use fixed size of szParam for param the buffer are 8192bytes
00207         and will later change to dymatic buffer */
00208 
00209     /* set PROMPT environment variable */
00210     if (param[0] != _T('\0'))
00211     {
00212         if (!SetEnvironmentVariable (_T("PROMPT"), param))
00213         return 1;
00214     }
00215     else
00216     {
00217         TCHAR szParam[5];
00218         _tcscpy(szParam,_T("$P$G"));
00219         if (!SetEnvironmentVariable (_T("PROMPT"),szParam))
00220         return 1;
00221     }
00222 
00223 
00224 
00225     return 0;
00226 }
00227 #endif
00228 
00229 /* EOF */

Generated on Fri May 25 2012 04:16:32 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.