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

📄 io.c

📁 indent为linux下代码自动格式化工具
💻 C
📖 第 1 页 / 共 2 页
字号:
    {        return parser_state_tos->cstk[parser_state_tos->tos] + 1;    }        if (settings.c_plus_plus && parser_state_tos->in_decl)    {        /* FIXME: does this belong here at all? */        return 1;    }    else    {        return parser_state_tos->ind_level - LABEL_OFFSET + 1;    }}/******************************************************************************//* VMS defines it's own read routine, `vms_read' */#ifndef INDENT_SYS_READ#define INDENT_SYS_READ read#endif/* Read file FILENAME into a `fileptr' structure, and return a pointer to   that structure. */file_buffer_ty * read_file (    char        * filename,    struct stat * file_stats){    static file_buffer_ty fileptr;        /*     * size is required to be unsigned for MSDOS,     * in order to read files larger than 32767     * bytes in a 16-bit world...     */      unsigned int size;    int          namelen = strlen(filename);    int          fd      = open(filename, O_RDONLY, 0777);    if (fd < 0)    {        fatal (_("Can't open input file %s"), filename);    }    if (fstat(fd, file_stats) < 0)    {        fatal (_("Can't stat input file %s"), filename);    }    if (file_stats->st_size == 0)    {        ERROR (_("Warning: Zero-length file %s"), filename, 0);    }#if !defined(__DJGPP__)    if (sizeof (int) == 2)      /* Old MSDOS */    {        if ((file_stats->st_size < 0) || (file_stats->st_size > (0xffff - 1)))        {            fatal (_("File %s is too big to read"), filename);        }    }    else#endif    {        if (file_stats->st_size < 0)        {            fatal (_("System problem reading file %s"), filename);        }    }    fileptr.size = file_stats->st_size;        if (fileptr.data != 0)    {        fileptr.data = (char *) xrealloc (fileptr.data,                                          (unsigned) file_stats->st_size + 2); /* add 1 for '\0' and 1 for                                                                                * potential final added                                                                                * newline. */    }    else    {        fileptr.data = (char *) xmalloc ((unsigned) file_stats->st_size + 2); /* add 1 for '\0' and 1 for                                                                               * potential final added                                                                               * newline. */    }    size = INDENT_SYS_READ (fd, fileptr.data, fileptr.size);        if (size == (unsigned int) -1)    {        fatal (_("Error reading input file %s"), filename);    }        if (close (fd) < 0)    {        fatal (_("Error closeing input file %s"), filename);    }        /* Apparently, the DOS stores files using CR-LF for newlines, but     * then the DOS `read' changes them into '\n'.  Thus, the size of the     * file on disc is larger than what is read into memory.  Thanks, Bill. */        if (size < fileptr.size)    {        fileptr.size = size;    }    if (fileptr.name != NULL)    {        fileptr.name = (char *) xrealloc (fileptr.name, (unsigned) namelen + 1);    }    else    {        fileptr.name = (char *) xmalloc (namelen + 1);    }        (void)strncpy(fileptr.name, filename, namelen);    fileptr.name[namelen] = EOS;    if (fileptr.data[fileptr.size - 1] != EOL)    {        fileptr.data[fileptr.size] = EOL;        fileptr.size++;    }        fileptr.data[fileptr.size] = EOS;    return &fileptr;}/* This should come from stdio.h and be some system-optimal number */#ifndef BUFSIZ#define BUFSIZ 1024#endif/******************************************************************************//* Suck the standard input into a file_buffer structure, and   return a pointer to that structure. */file_buffer_ty * read_stdin (void){    static file_buffer_ty stdinptr;    unsigned int          size = 15 * BUFSIZ;    int                   ch;    char                * p = NULL;    if (stdinptr.data != 0)    {        free (stdinptr.data);    }    stdinptr.data = (char *) xmalloc (size + 1);    stdinptr.size = 0;        p = stdinptr.data;        do    {        while (stdinptr.size < size)        {            ch = getc (stdin);                        if (ch == EOF)            {                break;            }            *p++ = ch;            stdinptr.size++;        }        if (ch != EOF)        {            size += (2 * BUFSIZ);            stdinptr.data = xrealloc (stdinptr.data, (unsigned) size);            p = stdinptr.data + stdinptr.size;        }    } while (ch != EOF);    stdinptr.name = "Standard Input";    stdinptr.data[stdinptr.size] = EOS;    return &stdinptr;}/******************************************************************************//* Advance `buf_ptr' so that it points to the next line of input. * * If the next input line contains an indent control comment turning * off formatting (a comment, C or C++, beginning with *INDENT-OFF*), * disable indenting by calling inhibit_indenting() which will cause * `dump_line ()' to simply print out all input lines without formatting * until it finds a corresponding comment containing *INDENT-0N* which * re-enables formatting. * * Note that if this is a C comment we do not look for the closing * delimiter.  Note also that older version of this program also * skipped lines containing *INDENT** which represented errors * generated by indent in some previous formatting.  This version does * not recognize such lines. */void fill_buffer (void){    char    * p = NULL;    BOOLEAN   finished_a_line = false;    /* indent() may be saving the text between "if (...)" and the following     * statement.  To do so, it uses another buffer (`save_com').  Switch     * back to the previous buffer here. */        if (bp_save != 0)    {        buf_ptr = bp_save;        buf_end = be_save;        bp_save = be_save = 0;        /* only return if there is really something in this buffer */                if (buf_ptr < buf_end)        {            return;        }    }    if (*in_prog_pos == EOS)    {        cur_line = buf_ptr = in_prog_pos;        had_eof = true;        return;    }    /* Here if we know there are chars to read.  The file is     * NULL-terminated, so we can always look one character ahead     * safely. */        p = cur_line = in_prog_pos;    finished_a_line = false;        do    {        p = skip_horiz_space(p);        /* If we are looking at the beginning of a comment, see         * if it turns off formatting with off-on directives. */                if (is_comment_start(p))        {            p += 2;                        p = skip_horiz_space(p);                        /* Skip all lines between the indent off and on directives. */                        if (strncmp (p, "*INDENT-OFF*", 12) == 0)            {                inhibit_indenting(true);            }        }        while ((*p != EOS) && *p != EOL)        {            p++;        }        /* Here for newline -- finish up unless formatting is off */                if (*p == EOL)        {            finished_a_line = true;            in_prog_pos = p + 1;        }                /* Here for embedded NULLs */                else if ((unsigned int) (p - current_input->data) < current_input->size)        {            WARNING (_("Warning: File %s contains NULL-characters\n"), current_input->name, 0);            p++;        }                /* Here for EOF with no terminating newline char. */        else        {            in_prog_pos = p;            finished_a_line = true;        }    } while (!finished_a_line);    buf_ptr = cur_line;    buf_end = in_prog_pos;        if (buf_break && ((buf_break->offset >= e_code - s_code) || (buf_break->offset <= 0)))    {        clear_buf_break_list ();    }}

⌨️ 快捷键说明

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