Main Page | Class List | Directories | File List | Class Members | File Members

profile.c File Reference

#include "awk.h"

Go to the source code of this file.

Defines

#define SPACEOVER   0
#define hakvar   forloop->init
#define arrvar   forloop->incr
#define BREAKPOINT   70

Enumerations

enum  redir_placement { BEFORE = 0, AFTER = 1 }

Functions

static void tree_eval P ((NODE *tree))
void init_profiling (int *flag ATTRIBUTE_UNUSED, const char *def_file ATTRIBUTE_UNUSED)
void set_prof_file (const char *file)
void init_profiling_signals ()
static void indent (long count)
static void indent_in (void)
static void indent_out (void)
static void pprint (register NODE *volatile tree)
static void tree_eval (register NODE *tree)
static void eval_condition (register NODE *tree)
static void pp_op_assign (register NODE *tree)
static void pp_lhs (register NODE *ptr)
static void pp_match_op (register NODE *tree)
static void pp_redir (register NODE *tree, enum redir_placement dir)
static void pp_list (register NODE *tree)
static void pp_print_stmt (const char *command, register NODE *tree)
static void pp_delete (register NODE *tree)
static void pp_in_array (NODE *array, NODE *subscript)
static void pp_getline (register NODE *tree)
static void pp_builtin (register NODE *tree)
static void pp_func_call (NODE *tree)
void dump_prog (NODE *begin, NODE *prog, NODE *end)
void pp_func (const char *name, size_t namelen, NODE *f)
static void pp_string (const char *str, size_t len, int delim)
void pp_string_fp (FILE *fp, const char *in_str, size_t len, int delim, int breaklines)
static int is_scalar (NODETYPE type)
static int prec_level (NODETYPE type)
static void parenthesize (NODETYPE parent_type, NODE *tree)

Variables

static char ** fparms
static FILE * prof_fp
static long indent_level = 0
static int in_BEGIN_or_END = FALSE
static int in_expr = FALSE


Define Documentation

#define arrvar   forloop->incr
 

#define BREAKPOINT   70
 

Referenced by pp_string_fp().

#define hakvar   forloop->init
 

#define SPACEOVER   0
 

Definition at line 67 of file profile.c.

Referenced by pprint(), and tree_eval().


Enumeration Type Documentation

enum redir_placement
 

Enumerator:
BEFORE 
AFTER 

Definition at line 29 of file profile.c.

00029                      {
00030         BEFORE = 0,
00031         AFTER = 1
00032 };


Function Documentation

void dump_prog NODE begin,
NODE prog,
NODE end
 

Definition at line 1156 of file profile.c.

References _, FALSE, NULL, pprint(), time(), and TRUE.

Referenced by main().

01157 {
01158         time_t now;
01159 
01160         (void) time(& now);
01161         /* \n on purpose, with \n in ctime() output */
01162         fprintf(prof_fp, _("\t# gawk profile, created %s\n"), ctime(& now));
01163 
01164         if (begin != NULL) {
01165                 fprintf(prof_fp, _("\t# BEGIN block(s)\n\n"));
01166                 fprintf(prof_fp, "\tBEGIN {\n");
01167                 in_BEGIN_or_END = TRUE;
01168                 pprint(begin);
01169                 in_BEGIN_or_END = FALSE;
01170                 fprintf(prof_fp, "\t}\n");
01171                 if (prog != NULL || end != NULL)
01172                         fprintf(prof_fp, "\n");
01173         }
01174         if (prog != NULL) {
01175                 fprintf(prof_fp, _("\t# Rule(s)\n\n"));
01176                 pprint(prog);
01177                 if (end != NULL)
01178                         fprintf(prof_fp, "\n");
01179         }
01180         if (end != NULL) {
01181                 fprintf(prof_fp, _("\t# END block(s)\n\n"));
01182                 fprintf(prof_fp, "\tEND {\n");
01183                 in_BEGIN_or_END = TRUE;
01184                 pprint(end);
01185                 in_BEGIN_or_END = FALSE;
01186                 fprintf(prof_fp, "\t}\n");
01187         }
01188 }

static void eval_condition register NODE tree  )  [static]
 

Definition at line 694 of file profile.c.

References eval_condition(), Node_line_range, NULL, and tree_eval.

00695 {
00696         if (tree == NULL)       /* Null trees are the easiest kinds */
00697                 return;
00698 
00699         if (tree->type == Node_line_range) {
00700                 /* /.../, /.../ */
00701                 eval_condition(tree->condpair->lnode);
00702                 fprintf(prof_fp,", ");
00703                 eval_condition(tree->condpair->rnode);
00704                 return;
00705         }
00706 
00707         /*
00708          * Could just be J.random expression. in which case, null and 0 are
00709          * false, anything else is true 
00710          */
00711 
00712         tree_eval(tree);
00713         return;
00714 }

static void indent long  count  )  [static]
 

Definition at line 121 of file profile.c.

References i.

Referenced by pp_delete(), pp_func(), pp_print_stmt(), pprint(), and tree_eval().

00122 {
00123         int i;
00124 
00125         if (count == 0)
00126                 putc('\t', prof_fp);
00127         else
00128                 fprintf(prof_fp, "%6ld  ", count);
00129 
00130         assert(indent_level >= 0);
00131         for (i = 0; i < indent_level; i++)
00132                 putc('\t', prof_fp);
00133 }

static void indent_in void   )  [static]
 

Definition at line 138 of file profile.c.

Referenced by pp_func(), pprint(), and tree_eval().

00139 {
00140         assert(indent_level >= 0);
00141         indent_level++;
00142 }

static void indent_out void   )  [static]
 

Definition at line 147 of file profile.c.

Referenced by pp_func(), pprint(), and tree_eval().

00148 {
00149         indent_level--;
00150         assert(indent_level >= 0);
00151 }

void init_profiling int *flag  ATTRIBUTE_UNUSED,
const char *def_file  ATTRIBUTE_UNUSED
 

Definition at line 72 of file profile.c.

References FALSE, set_prof_file(), and TRUE.

Referenced by main().

00073 {
00074 #ifdef PROFILING
00075         if (*flag == FALSE) {
00076                 *flag = TRUE;
00077                 set_prof_file(def_file);
00078         }
00079 #endif
00080 }

void init_profiling_signals  ) 
 

Definition at line 101 of file profile.c.

Referenced by main().

00102 {
00103 #ifdef PROFILING
00104 #ifdef __DJGPP__
00105         signal(SIGINT, dump_and_exit);
00106         signal(SIGQUIT, just_dump);
00107 #else  /* !__DJGPP__ */
00108 #ifdef SIGHUP
00109         signal(SIGHUP, dump_and_exit);
00110 #endif
00111 #ifdef SIGUSR1
00112         signal(SIGUSR1, just_dump);
00113 #endif
00114 #endif /* !__DJGPP__ */
00115 #endif /* PROFILING */
00116 }

static int is_scalar NODETYPE  type  )  [static]
 

Definition at line 1289 of file profile.c.

References FALSE, Node_BINMODE, Node_CONVFMT, Node_FIELDWIDTHS, Node_FNR, Node_FS, Node_IGNORECASE, Node_LINT, Node_NF, Node_NR, Node_OFMT, Node_OFS, Node_ORS, Node_RS, Node_subscript, Node_TEXTDOMAIN, Node_val, Node_var, Node_var_array, Node_var_new, and TRUE.

Referenced by pp_lhs(), pp_redir(), and tree_eval().

01290 {
01291         switch (type) {
01292         case Node_var_new:
01293         case Node_var:
01294         case Node_var_array:
01295         case Node_val:
01296         case Node_BINMODE:
01297         case Node_CONVFMT:
01298         case Node_FIELDWIDTHS:
01299         case Node_FNR:
01300         case Node_FS:
01301         case Node_IGNORECASE:
01302         case Node_LINT:
01303         case Node_NF:
01304         case Node_NR:
01305         case Node_OFMT:
01306         case Node_OFS:
01307         case Node_ORS:
01308         case Node_RS:
01309         case Node_TEXTDOMAIN:
01310         case Node_subscript:
01311                 return TRUE;
01312         default:
01313                 return FALSE;
01314         }
01315 }

static void tree_eval P (NODE *tree)   )  [static]
 

static void parenthesize NODETYPE  parent_type,
NODE tree
[static]
 

Definition at line 1421 of file profile.c.

References Node_in_array, Node_not, NULL, pp_in_array(), prec_level(), tree_eval, and exp_node::type.

Referenced by tree_eval().

01422 {
01423         NODETYPE child_type;
01424 
01425         if (tree == NULL)
01426                 return;
01427 
01428         child_type = tree->type;
01429 
01430         in_expr++;
01431         /* first the special cases, then the general ones */
01432         if (parent_type == Node_not && child_type == Node_in_array) {
01433                 fprintf(prof_fp, "! (");
01434                 pp_in_array(tree->lnode, tree->rnode);
01435                 fprintf(prof_fp, ")");
01436         /* other special cases here, as needed */
01437         } else if (prec_level(child_type) < prec_level(parent_type)) {
01438                 fprintf(prof_fp, "(");
01439                 tree_eval(tree);
01440                 fprintf(prof_fp, ")");
01441         } else
01442                 tree_eval(tree);
01443         in_expr--;
01444 }

static void pp_builtin register NODE tree  )  [static]
 

Definition at line 1124 of file profile.c.

References getfname(), and pp_list().

Referenced by tree_eval().

01125 {
01126         const char *func = getfname(tree->builtin);
01127 
01128         fprintf(prof_fp, "%s(", func ? func : "extension_function");
01129         if (func)
01130                 pp_list(tree->subnode);
01131         fprintf(prof_fp, ")");
01132 }

static void pp_delete register NODE tree  )  [static]
 

Definition at line 1049 of file profile.c.

References indent(), Node_param_list, NULL, pp_list(), and exp_node::type.

Referenced by pprint().

01050 {
01051         NODE *array, *subscript;
01052 
01053         array = tree->lnode;
01054         subscript = tree->rnode;
01055         indent(array->exec_count);
01056         if (array->type == Node_param_list)
01057                 fprintf(prof_fp, "delete %s", fparms[array->param_cnt]);
01058         else
01059                 fprintf(prof_fp, "delete %s", array->vname);
01060         if (subscript != NULL) {
01061                 fprintf(prof_fp, "[");
01062                 pp_list(subscript);
01063                 fprintf(prof_fp, "]");
01064         }
01065         fprintf(prof_fp, "\n");
01066 }

void pp_func const char *  name,
size_t  namelen,
NODE f
 

Definition at line 1193 of file profile.c.

References _, FALSE, indent(), indent_in(), indent_out(), lnode, pprint(), and TRUE.

Referenced by dump_funcs().

01194 {
01195         int j;
01196         char **pnames;
01197         static int first = TRUE;
01198 
01199         if (first) {
01200                 first = FALSE;
01201                 fprintf(prof_fp, _("\n\t# Functions, listed alphabetically\n"));
01202         }
01203 
01204         fprintf(prof_fp, "\n");
01205         indent(f->exec_count);
01206         fprintf(prof_fp, "function %.*s(", (int) namelen, name);
01207         pnames = f->parmlist;
01208         fparms = pnames;
01209         for (j = 0; j < f->lnode->param_cnt; j++) {
01210                 fprintf(prof_fp, "%s", pnames[j]);
01211                 if (j < f->lnode->param_cnt - 1)
01212                         fprintf(prof_fp, ", ");
01213         }
01214         fprintf(prof_fp, ")\n\t{\n");
01215         indent_in();
01216         pprint(f->rnode);       /* body */
01217         indent_out();
01218         fprintf(prof_fp, "\t}\n");
01219 }

static void pp_func_call NODE tree  )  [static]
 

Definition at line 1137 of file profile.c.

References name, and pp_list().

Referenced by tree_eval().

01138 {
01139         NODE *name, *arglist;
01140 
01141         name = tree->rnode;
01142         arglist = tree->lnode;
01143         fprintf(prof_fp, "%s(", name->stptr);
01144         pp_list(arglist);
01145         fprintf(prof_fp, ")");
01146 }

static void pp_getline register NODE tree  )  [static]
 

Definition at line 1089 of file profile.c.

References AFTER, BEFORE, FALSE, Node_redirect_pipein, Node_redirect_twoway, NULL, pp_lhs(), pp_redir(), and exp_node::type.

Referenced by tree_eval().

01090 {
01091         NODE *redir = tree->rnode;
01092         int before, after;
01093 
01094         /*
01095          * command | getline
01096          *     or
01097          * command |& getline
01098          *     or
01099          * getline < file
01100          */
01101         if (redir != NULL) {
01102                 before = (redir->type == Node_redirect_pipein
01103                                 || redir->type == Node_redirect_twoway);
01104                 after = ! before;
01105         } else
01106                 before = after = FALSE;
01107 
01108         if (before)
01109                 pp_redir(redir, BEFORE);
01110 
01111         fprintf(prof_fp, "getline");
01112         if (tree->lnode != NULL) {      /* optional var */
01113                 fprintf(prof_fp, " ");
01114                 pp_lhs(tree->lnode);
01115         }
01116 
01117         if (after)
01118                 pp_redir(redir, AFTER);
01119 }

static void pp_in_array NODE array,
NODE subscript
[static]
 

Definition at line 1071 of file profile.c.

References Node_expression_list, Node_param_list, pp_list(), pprint(), and exp_node::type.

Referenced by parenthesize(), and tree_eval().

01072 {
01073         if (subscript->type == Node_expression_list) {
01074                 fprintf(prof_fp, "(");
01075                 pp_list(subscript);
01076                 fprintf(prof_fp, ")");
01077         } else
01078                 pprint(subscript);
01079 
01080         if (array->type == Node_param_list)
01081                 fprintf(prof_fp, " in %s", fparms[array->param_cnt]);
01082         else
01083                 fprintf(prof_fp, " in %s", array->vname);
01084 }

static void pp_lhs register NODE ptr  )  [static]
 

Definition at line 801 of file profile.c.

References _, cant_happen, fatal, is_scalar(), n, Node_BINMODE, Node_builtin, Node_CONVFMT, Node_expression_list, Node_field_spec, Node_FIELDWIDTHS, Node_FNR, Node_FS, Node_IGNORECASE, Node_LINT, Node_NF, Node_NR, Node_OFMT, Node_OFS, Node_ORS, Node_param_list, Node_RS, Node_subscript, Node_TEXTDOMAIN, Node_var, Node_var_array, Node_var_new, pp_list(), tree_eval, and exp_node::type.

Referenced by pp_getline(), pp_op_assign(), pprint(), and tree_eval().

00802 {
00803         register NODE *n;
00804 
00805         switch (ptr->type) {
00806         case Node_var_array:
00807                 fatal(_("attempt to use array `%s' in a scalar context"),
00808                         ptr->vname);
00809 
00810         case Node_var_new:
00811         case Node_var:
00812                 fprintf(prof_fp, "%s", ptr->vname);
00813                 break;
00814 
00815         case Node_FIELDWIDTHS:
00816                 fprintf(prof_fp, "FIELDWIDTHS");
00817                 break;
00818 
00819         case Node_RS:
00820                 fprintf(prof_fp, "RS");
00821                 break;
00822 
00823         case Node_FS:
00824                 fprintf(prof_fp, "FS");
00825                 break;
00826 
00827         case Node_FNR:
00828                 fprintf(prof_fp, "FNR");
00829                 break;
00830 
00831         case Node_NR:
00832                 fprintf(prof_fp, "NR");
00833                 break;
00834 
00835         case Node_NF:
00836                 fprintf(prof_fp, "NF");
00837                 break;
00838 
00839         case Node_IGNORECASE:
00840                 fprintf(prof_fp, "IGNORECASE");
00841                 break;
00842 
00843         case Node_BINMODE:
00844                 fprintf(prof_fp, "BINMODE");
00845                 break;
00846 
00847         case Node_LINT:
00848                 fprintf(prof_fp, "LINT");
00849                 break;
00850 
00851         case Node_OFMT:
00852                 fprintf(prof_fp, "OFMT");
00853                 break;
00854 
00855         case Node_CONVFMT:
00856                 fprintf(prof_fp, "CONVFMT");
00857                 break;
00858 
00859         case Node_ORS:
00860                 fprintf(prof_fp, "ORS");
00861                 break;
00862 
00863         case Node_OFS:
00864                 fprintf(prof_fp, "OFS");
00865                 break;
00866 
00867         case Node_TEXTDOMAIN:
00868                 fprintf(prof_fp, "TEXTDOMAIN");
00869                 break;
00870 
00871         case Node_param_list:
00872                 fprintf(prof_fp, "%s", fparms[ptr->param_cnt]);
00873                 break;
00874 
00875         case Node_field_spec:
00876                 fprintf(prof_fp, "$");
00877                 if (is_scalar(ptr->lnode->type))
00878                         tree_eval(ptr->lnode);
00879                 else {
00880                         fprintf(prof_fp, "(");
00881                         tree_eval(ptr->lnode);
00882                         fprintf(prof_fp, ")");
00883                 }
00884                 break;
00885 
00886         case Node_subscript:
00887                 n = ptr->lnode;
00888                 if (n->type == Node_param_list) {
00889                         fprintf(prof_fp, "%s[", fparms[n->param_cnt]);
00890                 } else
00891                         fprintf(prof_fp, "%s[", n->vname);
00892                 if (ptr->rnode->type == Node_expression_list)
00893                         pp_list(ptr->rnode);
00894                 else
00895                         tree_eval(ptr->rnode);
00896                 fprintf(prof_fp, "]");
00897                 break;
00898 
00899         case Node_builtin:
00900                 fatal(_("assignment is not allowed to result of builtin function"));
00901 
00902         default:
00903                 cant_happen();
00904         }
00905 }

static void pp_list register NODE tree  )  [static]
 

Definition at line 1003 of file profile.c.

References Node_expression_list, nodetype2str(), NULL, and tree_eval.

Referenced by pp_builtin(), pp_delete(), pp_func_call(), pp_in_array(), pp_lhs(), and pp_print_stmt().

01004 {
01005         for (; tree != NULL; tree = tree->rnode) {
01006                 if (tree->type != Node_expression_list) {
01007                         fprintf(stderr, "pp_list: got %s\n",
01008                                         nodetype2str(tree->type));
01009                         fflush(stderr);
01010                 }
01011                 assert(tree->type == Node_expression_list);
01012                 tree_eval(tree->lnode);
01013                 if (tree->rnode != NULL)
01014                         fprintf(prof_fp, ", ");
01015         }
01016 }

static void pp_match_op register NODE tree  )  [static]
 

Definition at line 910 of file profile.c.

References Node_dynregex, Node_match, Node_nomatch, Node_regex, NULL, pp_string(), and tree_eval.

Referenced by tree_eval().

00911 {
00912         register NODE *re;
00913         const char *op;
00914         const char *restr;
00915         size_t relen;
00916         NODE *text = NULL;
00917 
00918         if (tree->type == Node_dynregex) {
00919                 tree_eval(tree->re_exp);
00920                 return;
00921         }
00922 
00923         if (tree->type == Node_regex) {
00924                 re = tree->re_exp;
00925                 restr = re->stptr;
00926                 relen = re->stlen;
00927                 pp_string(restr, relen, '/');
00928                 return;
00929         }
00930 
00931         /* at this point, have either ~ or !~ */
00932 
00933         text = tree->lnode;
00934         re = tree->rnode;
00935 
00936         if (tree->type == Node_nomatch)
00937                 op = "!~";
00938         else if (tree->type == Node_match)
00939                 op = "~";
00940         else
00941                 op = "";
00942 
00943         tree_eval(text);
00944         fprintf(prof_fp, " %s ", op);
00945         tree_eval(re);
00946 }

static void pp_op_assign register NODE tree  )  [static]
 

Definition at line 719 of file profile.c.

References cant_happen, Node_assign_exp, Node_assign_minus, Node_assign_mod, Node_assign_plus, Node_assign_quotient, Node_assign_times, Node_postdecrement, Node_postincrement, Node_predecrement, Node_preincrement, NULL, pp_lhs(), and tree_eval.

Referenced by tree_eval().

00720 {
00721         const char *op = NULL;
00722         enum Order {
00723                 NA = 0,
00724                 PRE = 1,
00725                 POST = 2
00726         } order = NA;
00727 
00728         switch(tree->type) {
00729         case Node_preincrement:
00730                 op = "++";
00731                 order = PRE;
00732                 break;
00733 
00734         case Node_predecrement:
00735                 op = "--";
00736                 order = PRE;
00737                 break;
00738 
00739         case Node_postincrement:
00740                 op = "++";
00741                 order = POST;
00742                 break;
00743 
00744         case Node_postdecrement:
00745                 op = "--";
00746                 order = POST;
00747                 break;
00748 
00749         default:
00750                 break;  /* handled below */
00751         }
00752 
00753         if (order == PRE) {
00754                 fprintf(prof_fp, "%s", op);
00755                 pp_lhs(tree->lnode);
00756                 return;
00757         } else if (order == POST) {
00758                 pp_lhs(tree->lnode);
00759                 fprintf(prof_fp, "%s", op);
00760                 return;
00761         }
00762 
00763         /* a binary op */
00764         pp_lhs(tree->lnode);
00765 
00766         switch(tree->type) {
00767         case Node_assign_exp:
00768                 fprintf(prof_fp, " ^= ");
00769                 break;
00770 
00771         case Node_assign_times:
00772                 fprintf(prof_fp, " *= ");
00773                 break;
00774 
00775         case Node_assign_quotient:
00776                 fprintf(prof_fp, " /= ");
00777                 break;
00778 
00779         case Node_assign_mod:
00780                 fprintf(prof_fp, " %%= ");
00781                 break;
00782 
00783         case Node_assign_plus:
00784                 fprintf(prof_fp, " += ");
00785                 break;
00786 
00787         case Node_assign_minus:
00788                 fprintf(prof_fp, " -= ");
00789                 break;
00790 
00791         default:
00792                 cant_happen();
00793         }
00794 
00795         tree_eval(tree->rnode);
00796 }

static void pp_print_stmt const char *  command,
register NODE tree
[static]
 

Definition at line 1021 of file profile.c.

References AFTER, indent(), NULL, pp_list(), and pp_redir().

Referenced by pprint().

01022 {
01023         NODE *redir = tree->rnode;
01024 
01025         indent(tree->exec_count);
01026         fprintf(prof_fp, "%s", command);
01027         if (redir != NULL) {
01028                 if (tree->lnode != NULL) {
01029                         /* parenthesize if have a redirection and a list */
01030                         fprintf(prof_fp, "(");
01031                         pp_list(tree->lnode);
01032                         fprintf(prof_fp, ")");
01033                 } else
01034                         fprintf(prof_fp, " $0");
01035                 pp_redir(redir, AFTER);
01036         } else {
01037                 fprintf(prof_fp, " ");
01038                 if (tree->lnode != NULL)
01039                         pp_list(tree->lnode);
01040                 else
01041                         fprintf(prof_fp, "$0");
01042         }
01043         fprintf(prof_fp, "\n");
01044 }

static void pp_redir register NODE tree,
enum redir_placement  dir
[static]
 

Definition at line 951 of file profile.c.

References BEFORE, cant_happen, is_scalar(), Node_redirect_append, Node_redirect_input, Node_redirect_output, Node_redirect_pipe, Node_redirect_pipein, Node_redirect_twoway, NULL, and tree_eval.

Referenced by pp_getline(), and pp_print_stmt().

00952 {
00953         const char *op = "[BOGUS]";     /* should never be seen */
00954 
00955         if (tree == NULL)
00956                 return;
00957 
00958         switch (tree->type) {
00959         case Node_redirect_output:
00960                 op = ">";
00961                 break;
00962         case Node_redirect_append:
00963                 op = ">>";
00964                 break;
00965         case Node_redirect_pipe:
00966                 op = "|";
00967                 break;
00968         case Node_redirect_pipein:
00969                 op = "|";
00970                 break;
00971         case Node_redirect_input:
00972                 op = "<";
00973                 break;
00974         case Node_redirect_twoway:
00975                 op = "|&";
00976                 break;
00977         default:
00978                 cant_happen();
00979         }
00980         
00981         if (dir == BEFORE) {
00982                 if (! is_scalar(tree->subnode->type)) {
00983                         fprintf(prof_fp, "(");
00984                         tree_eval(tree->subnode);
00985                         fprintf(prof_fp, ")");
00986                 } else
00987                         tree_eval(tree->subnode);
00988                 fprintf(prof_fp, " %s ", op);
00989         } else {
00990                 fprintf(prof_fp, " %s ", op);
00991                 if (! is_scalar(tree->subnode->type)) {
00992                         fprintf(prof_fp, "(");
00993                         tree_eval(tree->subnode);
00994                         fprintf(prof_fp, ")");
00995                 } else
00996                         tree_eval(tree->subnode);
00997         }
00998 }

static void pp_string const char *  str,
size_t  len,
int  delim
[static]
 

Definition at line 1224 of file profile.c.

References FALSE, and pp_string_fp().

Referenced by pp_match_op(), and tree_eval().

01225 {
01226         pp_string_fp(prof_fp, str, len, delim, FALSE);
01227 }

void pp_string_fp FILE *  fp,
const char *  in_str,
size_t  len,
int  delim,
int  breaklines
 

Definition at line 1237 of file profile.c.

References BELL, BREAKPOINT, i, NULL, strchr(), and whiny_users.

Referenced by dumpintlstr(), dumpintlstr2(), pp_string(), and valinfo().

01238 {
01239         static char escapes[] = "\b\f\n\r\t\v\\";
01240         static char printables[] = "bfnrtv\\";
01241         char *cp;
01242         int i;
01243         int count;
01244 #define BREAKPOINT      70 /* arbitrary */
01245         const unsigned char *str = (const unsigned char *) in_str;
01246 
01247         fprintf(fp, "%c", delim);
01248         for (count = 0; len > 0; len--, str++) {
01249                 if (++count >= BREAKPOINT && breaklines) {
01250                         fprintf(fp, "%c\n%c", delim, delim);
01251                         count = 0;
01252                 }
01253                 if (*str == delim) {
01254                         fprintf(fp, "\\%c", delim);
01255                         count++;
01256                 } else if (*str == BELL) {
01257                         fprintf(fp, "\\a");
01258                         count++;
01259                 } else if ((cp = strchr(escapes, *str)) != NULL) {
01260                         i = cp - escapes;
01261                         putc('\\', fp);
01262                         count++;
01263                         putc(printables[i], fp);
01264                         if (breaklines && *str == '\n' && delim == '"') {
01265                                 fprintf(fp, "\"\n\"");
01266                                 count = 0;
01267                         }
01268                 /* NB: Deliberate use of lower-case versions. */
01269                 } else if (isascii(*str) && isprint(*str)) {
01270                         putc(*str, fp);
01271                 } else {
01272                         char buf[10];
01273 
01274                         /* print 'em as they came if for whiny users */
01275                         if (whiny_users)
01276                                 sprintf(buf, "%c", *str & 0xff);
01277                         else
01278                                 sprintf(buf, "\\%03o", *str & 0xff);
01279                         count += strlen(buf) - 1;
01280                         fprintf(fp, "%s", buf);
01281                 }
01282         }
01283         fprintf(fp, "%c", delim);
01284 }

static void pprint register NODE *volatile  tree  )  [static]
 

Definition at line 159 of file profile.c.

References eval_condition(), FALSE, indent(), indent_in(), indent_out(), Node_case_list, Node_K_arrayfor, Node_K_break, Node_K_case, Node_K_continue, Node_K_default, Node_K_delete, Node_K_do, Node_K_exit, Node_K_for, Node_K_if, Node_K_next, Node_K_nextfile, Node_K_print, Node_K_print_rec, Node_K_printf, Node_K_return, Node_K_switch, Node_K_while, Node_param_list, Node_rule_list, Node_rule_node, Node_statement_list, Node_switch_body, NULL, pp_delete(), pp_lhs(), pp_print_stmt(), source, sourceline, SPACEOVER, tree_eval, TRUE, and exp_node::type.

Referenced by dump_prog(), pp_func(), and pp_in_array().

00160 {
00161         register NODE *volatile t = NULL;       /* temporary */
00162         int volatile traverse = TRUE;   /* True => loop thru tree (Node_rule_list) */
00163 
00164         /* avoid false source indications */
00165         source = NULL;
00166         sourceline = 0;
00167 
00168         if (tree == NULL)
00169                 return;
00170         sourceline = tree->source_line;
00171         source = tree->source_file;
00172         switch (tree->type) {
00173         case Node_rule_node:
00174                 traverse = FALSE;  /* False => one for-loop iteration only */
00175                 /* FALL THROUGH */
00176         case Node_rule_list:
00177                 for (t = tree; t != NULL; t = t->rnode) {
00178                         if (traverse)
00179                                 tree = t->lnode;
00180                         sourceline = tree->source_line;
00181                         source = tree->source_file;
00182 
00183                         if (! in_BEGIN_or_END)
00184                                 indent(tree->exec_count);
00185 
00186                         if (tree->lnode) {
00187                                 eval_condition(tree->lnode);
00188                                 if (tree->rnode)
00189                                         fprintf(prof_fp, "\t");
00190                         }
00191 
00192                         if (tree->rnode) {
00193                                 if (! in_BEGIN_or_END) {
00194                                         fprintf(prof_fp, "{");
00195                                         if (tree->lnode != NULL
00196                                             && tree->lnode->exec_count)
00197                                                 fprintf(prof_fp, " # %ld",
00198                                                         tree->lnode->exec_count);
00199                                         fprintf(prof_fp, "\n");
00200                                 }
00201                                 indent_in();
00202                                 pprint(tree->rnode);
00203                                 indent_out();
00204                                 if (! in_BEGIN_or_END) {
00205                                         indent(SPACEOVER);
00206                                         fprintf(prof_fp, "}\n");
00207                                 }
00208                         }
00209 
00210                         if (! traverse)         /* case Node_rule_node */
00211                                 break;          /* don't loop */
00212 
00213                         if (t->rnode && ! in_BEGIN_or_END)
00214                                 fprintf(prof_fp, "\n");
00215                 }
00216                 break;
00217 
00218         case Node_statement_list:
00219                 for (t = tree; t != NULL; t = t->rnode) {
00220                         pprint(t->lnode);
00221