40 const char *zwc_file = NULL;
42 while (*argv && argv[0][0] ==
'-') {
43 if (strcmp(argv[0],
"-n") == 0) {
45 zwarnnam(nam,
"-n requires an argument");
48 count = atoi(argv[1]);
52 if (strcmp(argv[0],
"--threshold") == 0) {
54 zwarnnam(nam,
"--threshold requires an argument");
57 threshold = atoi(argv[1]);
61 if (strcmp(argv[0],
"--zwc") == 0) {
63 zwarnnam(nam,
"--zwc requires an argument");
70 if (strcmp(argv[0],
"--") == 0) {
78 #ifndef ZPMOD_HAVE_SOURCE_STUDY
87 char **history =
getaparam(
"zsh_source_history");
92 int history_len =
arrlen(history);
96 for (
int i = 0; i < history_len; i++) {
97 char *line = history[i];
98 int len = (int)strlen(line);
99 char *copy = (
char *)
zalloc(len + 1);
100 memcpy(copy, line, len + 1);
101 char *saveptr = NULL;
102 char *
path = strtok_r(copy,
" ", &saveptr);
103 char *ms_str = strtok_r(NULL,
" ", &saveptr);
104 if (!
path || !ms_str) {
108 long ms = atol(ms_str);
109 if (threshold > 0 && ms < threshold) {
114 for (
int j = 0; j < script_count; j++) {
115 if (strcmp(scripts[j].
path,
path) == 0) {
124 scripts[script_count].
total_ms = ms;
125 scripts[script_count].
count = 1;
128 zfree(copy, len + 1);
133 int limit = (count > 0 && count < script_count) ? count : script_count;
135 for (
int i = 0; i < limit; i++) {
138 cmd =
zalloc(strlen(scripts[i].
path) + strlen(zwc_file) + 20);
139 sprintf(cmd,
"zcompile -o %s %s", zwc_file, scripts[i].
path);
142 sprintf(cmd,
"zcompile %s", scripts[i].
path);
144 execstring(cmd, 1, 0, NULL);
148 for (
int i = 0; i < script_count; i++) {
static int compare_hot_scripts(const void *a, const void *b)
int cmd_source_hot(char *nam, char **argv)
Implements zpmod source-hot.
Module declaration header (mdh) for zpmod.
Prototype stub for zpmod when building out-of-tree.
void * zalloc(size_t size)
void zfree(void *ptr, size_t size)
char ** getaparam(const char *name)
void zwarnnam(const char *, const char *,...)
char * ztrdup(const char *)