Changeset 44 for trunk/src


Ignore:
Timestamp:
Mar 28, 2003, 12:22:18 PM (22 years ago)
Author:
bird
Message:

Playing with the shell code.

Location:
trunk/src/kShell
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kShell/kShell.c

    r23 r44  
    254254#define KSHELL_WILDCHAR(ch)     ( (ch) == '*' || (ch) == '?' )
    255255
     256/**
     257 * the a default kShell slash.
     258 */
     259#define KSHELL_SLASH            '/'
     260
     261/**
     262 * Checks if the character is a slash or not.
     263 */
     264#define KSHELL_ISSLASH(ch)      ( (ch) == KSHELL_SLASH )
    256265
    257266
     
    432441    pWords = kshellWordsParse(pszCmd, 1, NULL);
    433442    if (!pWords)
    434         return KSHELL_ERROR_NOT_ENOUGHT_MEMORY;
     443        return KSHELL_ERROR_NOT_ENOUGH_MEMORY;
    435444    if (!pWords->cWords)
    436445        return 0;
     
    455464        pWords = kshellWordsParse(pszCmd, aCmds[i].cWords, pWords);
    456465        if (!pWords)
    457             return KSHELL_ERROR_NOT_ENOUGHT_MEMORY;
     466            return KSHELL_ERROR_NOT_ENOUGH_MEMORY;
    458467    }
    459468    rc = aCmds[i].pfnCmd(pszCmd, pWords);
     
    688697int             kshellCmd_copy(const char *pszCmd, PKSHELLWORDS pWords)
    689698{
     699    int     iDst = pWords->cWords - 1;  /* Last word is destination. */
     700    KBOOL   fDstDir = -1;
     701    int     iSrc;
     702
     703    /*
     704     * Syntax validation.
     705     */
     706    if (pWords->cWords < 3)
     707        return kshellSyntaxError("copy", "too few arguments.");
     708
     709    /*
     710     * Figure out if the destion is a directory or file specification.
     711     */
     712    if (KSHELL_ISSLASH(pWords->aWords[iDst].pszWord[pWords->aWords[iDst].cchWord - 1]))
     713    {
     714        fDstDir = TRUE;
     715        while (KSHELL_ISSLASH(pWords->aWords[iDst].pszWord[pWords->aWords[iDst].cchWord - 1]))
     716            pWords->aWords[iDst].cchWord--;
     717        pWords->aWords[iDst].pszWord[pWords->aWords[iDst].cchWord] = '\0';
     718    }
     719    else
     720        fDstDir = kDirExist(pWords->aWords[iDst].pszWord);
     721
     722    /*
     723     * Copy sources to destination.
     724     */
     725    for (iSrc = 1; iSrc < iDst && !rc; iSrc++)
     726    {
     727        if (pWords->aWords[iSrc].fFlags & KSWORD_FLAGS_PATTERN)
     728        {
     729            /*
     730             *
     731             */
     732        }
     733        else
     734        {   /*
     735             * Construct destination name.
     736             */
     737            char *pszDst;
     738            KBOOL fDstFree = FALSE;
     739            if (fDstDir)
     740            {
     741                fDstFree = TRUE;
     742                pszDst = malloc(pWords->aWords[iDst].cchWord + 1 + pWords->aWords[iSrc].cchWord + 1);
     743                if (pszDst)
     744                    return KSHELL_ERROR_NOT_ENOUGH_MEMORY;
     745                kMemCpy(pszDst, pWords->aWords[iDst].pszWord, pWords->aWords[iDst].cchWord);
     746                pszDst[pWords->aWords[iDst].cchWord] = KSHELL_SLASH;
     747                kMemCpy(pszDst + pWords->aWords[iDst].cchWord + 1,
     748                        pWords->aWords[iSrc].pszWord
     749                        pWords->aWords[iSrc].cchWord + 1);
     750            }
     751            else
     752                pszDst = pWords->aWords[iDst].pszWord;
     753
     754            /*
     755             * Do the copy.
     756             */
     757            rc = kFileCopy(pWords->aWords[iSrc].pszWord, pszDst);
     758            if (rc)
     759            {
     760                kshellError("copy", "failed to copy '%s' to '%s' rc=%d.",
     761                            pWords->aWords[iSrc].pszWord,
     762                            pDst, rc);
     763            }
     764
     765            if (fDstFree)
     766                free(pszDst);
     767        }
     768    }
     769
    690770    return -1;
    691771}
     
    787867    if (pWords->cWords >= 2)
    788868    {
    789         unsigned uMsgLevel = kStrToUnsigned(pWords->aWords[1].pszWord, -2);
     869        unsigned uMsgLevel = kStrToUDef(pWords->aWords[1].pszWord, -2, 0);
    790870        if (uMsgLevel != -2)
    791871        {
    792             if (uMsgLevel <= kEnvGetUnsigned("KBUILD_MSG_LEVEL", 0))
     872            if (uMsgLevel <= kEnvGetUDef("KBUILD_MSG_LEVEL", 0, 0))
    793873            {
    794874                /* output all the words forcing one space separation */
  • trunk/src/kShell/kShell.h

    r19 r44  
    3131 */
    3232#define KSHELL_ERROR_SYNTAX_ERROR           1700
    33 #define KSHELL_ERROR_NOT_ENOUGHT_MEMORY     1708
     33#define KSHELL_ERROR_NOT_ENOUGH_MEMORY      1708
    3434#define KSHELL_ERROR_PROGRAM_NOT_FOUND      1742
    3535#define KSHELL_ERROR_COMMAND_TOO_LONG       1743
  • trunk/src/kShell/makefile

    r23 r44  
    22
    33#CC = icc /Q /Ti+ /I../kLib/Generic/include
    4 CC = icc /Q /Ti+ -DOS2 -D__i386__ -DDEBUG /Ig:/ktaskmgr/tree/Generic/include
    5 CC = icc /Q /Ti+ /O /Oi+ -DOS2 -D__i386__ -DDEBUG /Ig:/ktaskmgr/tree/Generic/include
     4CC = icc /Q /Ti+ -DOS2 -D__i386__ -DDEBUG /I/ktaskmgr/tree/Generic/include
     5CC = icc /Q /Ti+ /O /Oi+ -DOS2 -D__i386__ -DDEBUG /I/ktaskmgr/tree/Generic/include
    66
    77
     
    1010                       
    1111kShellMain.exe: kShellMain.c kShell.c kShell.h
    12         $(CC) kShellmain.c kShell.c
     12        $(CC) kShellmain.c kShell.c /ktaskmgr/tree/lib/debug/klib.lib
    1313       
    1414kShellMain.obj: kShellMain.c kShell.h
Note: See TracChangeset for help on using the changeset viewer.