📄 io.c
字号:
/* Copyright (c) 1999, 2000 Carlo Wood. All rights reserved. * Copyright (c) 1994 Joseph Arceneaux. All rights reserved. * Copyright (c) 1992 Free Software Foundation, Inc. All rights reserved. * * Copyright (c) 1985 Sun Microsystems, Inc. Copyright (c) 1980 The Regents * of the University of California. Copyright (c) 1976 Board of Trustees of * the University of Illinois. All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that * the above copyright notice and this paragraph are duplicated in all such * forms and that any documentation, advertising materials, and other * materials related to such distribution and use acknowledge that the * software was developed by the University of California, Berkeley, the * University of Illinois, Urbana, and Sun Microsystems, Inc. The name of * either University or Sun Microsystems may not be used to endorse or * promote products derived from this software without specific prior written * permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * HISTORY * 2002-01-17 D.Ingamells Add a final newline if not present in file. */#include "sys.h"#include <ctype.h>#include <stdlib.h>#if defined (HAVE_UNISTD_H) #include <unistd.h>#endif#include <string.h>#ifdef VMS #include <file.h> #include <types.h> #include <stat.h>#else /* not VMS */ #include <sys/types.h> #include <sys/stat.h> /* POSIX says that <fcntl.h> should exist. Some systems might need to use * <sys/fcntl.h> or <sys/file.h> instead. */ #include <fcntl.h> #if defined (_WIN32) && !defined (__CYGWIN__) #include <io.h> #endif#endif /* not VMS */#include "indent.h"#include "io.h"#include "globs.h"#include "output.h"RCSTAG_CC ("$Id: io.c,v 1.50 2002/08/04 17:08:41 david Exp $");/* number of levels a label is placed to left of code */#define LABEL_OFFSET 2/******************************************************************************//* Stuff that needs to be shared with the rest of indent. Documented in * indent.h. */char * in_prog_pos = NULL; /* used in output.c io.c indent.c */char * buf_ptr = NULL; /* used in output.c lexi.c io.c indent.c comments.c */char * buf_end = NULL; /* used in output.c lexi.c io.c indent.c comments.c */BOOLEAN had_eof = false; /* used in output.c io.c comments.c parse.c */char * cur_line = NULL; /* used in output.c io.c *//******************************************************************************/char * skip_horiz_space(const char * p){ while ((*p == ' ') || (*p == TAB)) { p++; } return (char *)p;}/******************************************************************************/void skip_buffered_space(void){ while ((*buf_ptr == ' ') || (*buf_ptr == TAB)) { buf_ptr++; if (buf_ptr >= buf_end) { fill_buffer (); } }}/******************************************************************************/static BOOLEAN is_comment_start(const char * p){ BOOLEAN ret; if ((*p == '/') && ((*(p + 1) == '*') || (*(p + 1) == '/'))) { ret = true; } else { ret = false; } return ret;}/******************************************************************************/int count_columns ( int column, char *bp, int stop_char){ while (*bp != stop_char && *bp != NULL_CHAR) { switch (*bp++) { case EOL: case '\f': /* form feed */ column = 1; break; case TAB: column += settings.tabsize - (column - 1) % settings.tabsize; break; case 010: /* backspace */ --column; break;#ifdef COLOR_DEBUG case '\e': /* ANSI color */ while (*bp++ != 'm') { } break;#endif default: ++column; break; } } return column;}#ifdef VMS/******************************************************************************//* Folks say VMS requires its own read routine. Then again, some folks * say it doesn't. Different folks have also sent me conflicting versions * of this function. Who's right? * * Anyway, this version was sent by MEHRDAD@glum.dev.cf.ac.uk and modified * slightly by me. */static int vms_read ( int file_desc, char * buffer, int nbytes){ char * bufp; int nread; int nleft; bufp = buffer; nread = 0; nleft = nbytes; nread = read (file_desc, bufp, nleft); while (nread > 0) { bufp += nread; nleft -= nread; if (nleft < 0) { fatal (_("Internal buffering error"), 0); } nread = read (file_desc, bufp, nleft); } return nbytes - nleft;}#endif /* VMS *//******************************************************************************//* Return the column we are at in the input line. */int current_column (void){ char *p; int column; /* Use save_com.size here instead of save_com.end, because save_com is * already emptied at this point. */ if ((buf_ptr >= save_com.ptr) && (buf_ptr <= save_com.ptr + save_com.len)) { p = save_com.ptr; column = save_com.start_column; } else { p = cur_line; column = 1; } while (p < buf_ptr) { switch (*p) { case EOL: case 014: /* form feed */ column = 1; break; case TAB: column += settings.tabsize - (column - 1) % settings.tabsize; break; case '\b': /* backspace */ column--; break; default: column++; break; } p++; } return column;}/******************************************************************************//* Return the column in which we should place the code in s_code. */int compute_code_target ( int paren_targ){ int target_col; if (buf_break_used) { return prev_target_col_break; } if (parser_state_tos->procname[0] && (s_code_corresponds_to == parser_state_tos->procname)) { target_col = 1; if (!parser_state_tos->paren_level) { return target_col; } } else { target_col = parser_state_tos->ind_level + 1; } if (!parser_state_tos->paren_level) { if (parser_state_tos->ind_stmt) { target_col += settings.continuation_indent; } return target_col; } if (!settings.lineup_to_parens) { return target_col + settings.continuation_indent + (settings.paren_indent * (parser_state_tos->paren_level - 1)); } return paren_targ;}/******************************************************************************/int compute_label_target (void){ /* maybe there should be some option to tell indent where to put public:, * private: etc. ? */ if (*s_lab == '#') { return 1; } if (parser_state_tos->pcase)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -