⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ramdemo.c

📁 嵌入式操作系统Nucleus Plus中使用的文件系统
💻 C
📖 第 1 页 / 共 5 页
字号:

            /* Make a path.  */
            pc_mpath((UTEXT*)path, (UTEXT*)path, (UTEXT*)scan_stack[i]);
        }

        /* If the stack is NULL for this dir we just got here so display files.
           Otherwise we are scanning back to where we left off */
        if (scan_stack[stackp][0])
            display_files = NO;
        else
        {
            RAM_Directories_Scanned[task_id]++;
            display_files = YES;
        }

        /*  Initialize the indicator for determining if a directory has
            been found. */
        found_dir = NO;

        /* Get first entry the directory */
        if (!NU_Get_First(&statobj, "*.*"))
        {
            /* No entries. This is an error in any subdirectories  (they
               should at least have . and .. */
            if (stackp)
                return(error_log(INVALID_DIR));
            return(YES);                     
        }

        do
        {
            /* make into file.nam  */
            mkname(fname_buffer, &statobj);

            /* Make sure we have a directory. */
            if (statobj.fattribute & ADIRENT)
            {
                /* If it's a directory push it on our stack */
                if (fname_buffer[0] != '.')
                {
                    /* If we have a blank entry, put the name on it.  */
                    if (!scan_stack[stackp][0])
                    {
                        /* First time at this level. Push the dir name and
                           break so we can visit this dir (in a recursive 
                           function we would recurse right here */
                        scan_stack[stackp][0] = '\0';

                        /*  Put the name in.  */
                        pc_strcat(scan_stack[stackp],fname_buffer);

                        /*  Indicate that we have a directory.  */
                        found_dir = YES;

                        /*  Look at the next entry. */
                        stackp += 1;

                        /*  If we have gone to far, it is an error.  */
                        if (stackp >= 30)
                        {
                            error_log(TOO_MANY_SUBS);
                            return(NO);
                        }

                        /*  Indicate that the next entry is blank.  */
                        scan_stack[stackp][0] = 0;

                        /*  Process the current one.  */
                        break;
                    }
                    else
                    {
                        /* Here we simulate the continuation after the return
                           from the recursion */
                        if (bad_strcmp(scan_stack[stackp],fname_buffer)==0)
                        {
                            /* 0 the stack so we take the next directory.
                              plus display files again */
                            display_files = YES;
                            scan_stack[stackp][0] = 0;
                        }
                    }
                }
            }
            else if (!(statobj.fattribute & AVOLUME))
            {
                /* It's a file, display it. */
                if (display_files)
                {
                    RAM_Files_Scanned[task_id]++;
                }
            }

		} while (NU_Get_Next(&statobj));

        /* Call NU_Done to free up internal resources used by statobj */
		NU_Done(&statobj);

        /* If found_dir is NO it means we reached the end of the directory
           and do not require a scan of a subdirectory. Pop this directory
           off the stack */
        if (!found_dir)
        {
            /* If at the top level we are done */
            if (!stackp)
                return(YES);

            /* Clean up the stack and decrement the pointer */
             scan_stack[stackp--][0] = 0;
        }
    }
    return(YES);
}


/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "mkname"                         */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine extracts the name and extension from a directory   */
/*      entry and converts it to a file name.                           */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      write_test                          Performs writes to the disk.*/
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      NONE                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      buffer                              Where file name is to be    */
/*                                          placed.                     */
/*      pstat                               Pointer to directory entry. */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void mkname(char *buffer, DSTAT *pstat)
{
char *pfr, *pto;

    /*  Get a temporary pointer to the buffer. */
    pto = buffer;

    /*  Get a temporary pointer to the name in the directory entry.  */
    pfr = (char *) pstat->fname;

    /*  Copy the name to the buffer.  */
    while (*pfr && *pfr!=' ')
        *pto++ = *pfr++;

    /*  Get a temporary pointer to the extension in the directory entry.  */
    pfr = pstat->fext;

    /*  Place the period in the file name.  */
    if (*pfr != ' ')
        *pto++ = '.';

    /*  Copy the extension.  */
    while (*pfr && *pfr!=' ')
        *pto++ = *pfr++;

    /*  Null terminate the string. */
    *pto = '\0';
}

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "bail_out"                       */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine processes a fatal error and suspends the task      */
/*      that called it.                                                 */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      most functions in demo                                          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      NU_Suspend_Task                     Suspends the caller.        */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      error_no                            Number of error being       */
/*                                          reported.                   */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void bail_out(int error_no)
{
    /*  Validate the error number.  */
    if (RAM_Fatal_Errors_Index > 9)
        RAM_Fatal_Errors_Index = 0;

    /*  Record the error.  */
    RAM_Fatal_Errors[RAM_Fatal_Errors_Index] = error_no;

    /*  Suspend the task.  */
    NU_Suspend_Task(NU_Current_Task_Pointer());
}

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "looping"                        */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine processes any user input.  It will both start and  */
/*      stop tasks as well as process an exit request if supported.     */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      most functions in demo                                          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      NU_Change_Preemption                Changes task to non-preempt */
/*                                          during formatting and back  */
/*      NU_Suspend_Task                     Suspends the caller.        */
/*      [US_Is_Char]                        Port specific routine for   */
/*                                          determining if there are    */
/*                                          characters available.       */
/*                                                                      */
/*      [US_fgetc]                          Port specific routine for   */
/*                                          reading a character.        */
/*                                                                      */
/*      NU_Resume_Task                      Starts other tasks.         */
/*  INPUTS                                                              */
/*                                                                      */
/*      NONE                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
BOOL looping()
{
#if (ACCEPT_KEYS || USE_PUTS)
char c;
int i;
#endif
BOOL stay_in;
OPTION      preempt_status;

    /*  Don't let any other tasks interrupt us here.  */
    preempt_status = NU_Change_Preemption(NU_NO_PREEMPT);

    /* If the user requested the task be stopped, from a previous entry
       into this routine, do so here. */
    if (!task_is_running[NUIP_Current_Task_ID()])
    {
        NU_Suspend_Task(NU_Current_Task_Pointer());
    }
    /* Put inside a do loop in case they pause all of there tasks. This lets
       them run again. */
    stay_in = NO;

#if ACCEPT_KEYS
    /*  Process any user requests.  */
    do
    {
        /*  See if there is a character available.  */
        if (kbhit())
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -