/* * Handle one line. Returns 0 if at EOF, and a positive value if there's * more data to handle. */ static int do_line( FILE *infile, FILE *miffile, char *outdir ) /*************************************************************/ { static int curline; char line[1024]; char * p; int numwords; char ** words; struct Alias alias; int count; /*** Prepare the next line ***/ p = fgets( line, 1024, infile ); if( p == NULL ) { if( ferror( infile ) ) { FatalError( "Error reading line %d", curline ); } else if( feof( infile ) ) { return( 0 ); } else { Zoinks(); } } if( line[0] == '#' ) { curline++; return( 2 ); /* skip comment lines */ } /*** Extract the individual words ***/ numwords = parse_words( line, NULL ); if( numwords == -1 ) { FatalError( "Error on line %d", curline ); return( -1 ); } if( numwords == 0 ) { /* skip blank lines */ curline++; return( 2 ); } words = (char **)AllocMem( (numwords+1) * sizeof(char*) ); numwords = parse_words( line, words ); if( numwords < 4 ) { FatalError( "Error on line %d", curline ); return( -1 ); } /*** Construct an Alias structure and create the alias ***/ alias.filename = words[0]; alias.realname = words[1]; alias.aliasname = words[2]; alias.systems = NULL; for( count=3; words[count]!=NULL; count++ ) { /* build system list */ add_system( &alias, words[count] ); } do_alias( miffile, &alias, outdir ); curline++; return( 1 ); }
int turbo_sibling_search (Entry e, struct search_kid_arg *ska) { EntryInfo *list; Entry *tmp; DN dn; Index *pindex; *ska->ska_einfo = NULLENTRYINFO; if ( e->e_leaf ) return; if ( e->e_children == NULLAVL ) { search_refer( ska->ska_arg, e, ska->ska_local, ska->ska_refer, ska->ska_ismanager ); return; } dn = get_copy_dn( e ); if ( (pindex = get_sibling_index( dn )) == NULLINDEX ) { LLOG( log_dsap, LLOG_EXCEPTIONS, ("Cannot find sibling index") ); dn_free( dn ); return; } dn_free( dn ); g_size_normalizer = 1; list = turbo_filterkids( e, ska->ska_arg->sra_filter, ska, pindex, 1 ); apply_sacl( &list, e, ska ); /* security error coming back */ if ( ska->ska_saclerror < 0 ) { entryinfo_free( list, 0 ); return; } if ( *ska->ska_einfo == NULLENTRYINFO ) *ska->ska_einfo = list; else if ( list != NULLENTRYINFO ) entryinfo_append( *ska->ska_einfo, list ); /* sizelimit already exceeded */ if ( ska->ska_saclerror > 0 ) return; if ( ska->ska_arg->sra_searchaliases && pindex->i_nonlocalaliases != (Entry *) 0 ) { for ( tmp = pindex->i_nonlocalaliases; *tmp; tmp++ ) do_alias( ska->ska_arg, *tmp, ska->ska_local ); } }
static int builtin_alias(unsigned argc, const char **argv) { int ret; if (argc == 0) { ret = print_all_shell_aliases(); } else { ret = 0; do { ret |= do_alias(*argv++); } while (--argc); } return ret; }
/* do we add () at the end of completed word? (is it a function?) */ static int add_paren(pari_rl_interface *rl, int end) { entree *ep; const char *s; if (end < 0 || (*rl->line_buffer)[end] == '(') return 0; /* not from command_generator or already there */ ep = do_alias(current_ep); /* current_ep set in command_generator */ if (EpVALENCE(ep) < EpNEW) { /* is it a constant masked as a function (e.g Pi)? */ s = ep->help; if (!s) return 1; while (is_keyword_char(*s)) s++; return (*s != '='); } switch(EpVALENCE(ep)) { case EpVAR: return typ((GEN)ep->value) == t_CLOSURE; case EpINSTALL: return 1; } return 0; }
/* * Build aliases for all of the built-in commands which start with a dash, * using the names without the dash. */ void do_aliasall(int argc, const char **argv) { const CommandEntry * entry; const char * name; const char * newArgv[4]; for (entry = commandEntryTable; entry->name; entry++) { name = entry->name; if (*name != '-') continue; newArgv[0] = "alias"; newArgv[1] = name + 1; newArgv[2] = name; newArgv[3] = NULL; do_alias(3, newArgv); } }
int turbo_subtree_search (Entry e, struct search_kid_arg *ska) { EntryInfo *list; Entry *tmp; DN dn; Index *pindex; dn = get_copy_dn( e ); if ( (pindex = get_subtree_index( dn )) == NULLINDEX ) { LLOG( log_dsap, LLOG_EXCEPTIONS, ("Cannot find subtree index") ); dn_free( dn ); return; } dn_free( dn ); g_size_normalizer = 1; list = turbo_filterkids( e, ska->ska_arg->sra_filter, ska, pindex, 1 ); apply_sacl( &list, e, ska ); /* security error coming back */ if ( ska->ska_saclerror < 0 ) { entryinfo_free( list, 0 ); return; } if ( *ska->ska_einfo == NULLENTRYINFO ) *ska->ska_einfo = list; else if ( list != NULLENTRYINFO ) entryinfo_append( *ska->ska_einfo, list ); /* sizelimit already exceeded */ if ( ska->ska_saclerror > 0 ) return; /* * at this point, anything held locally below this point has been * searched. we now search through the nonleaf children recursively * for one whose children are not held locally, referring any that * we find. next, we search through the list of nonlocal aliases * searching for one that matches (if dereferencing is allowed). */ if ( pindex->i_nonleafkids != (Entry *) 0 ) subtree_refer( pindex, ska ); if ( ska->ska_arg->sra_searchaliases && pindex->i_nonlocalaliases != (Entry *) 0 ) { for ( tmp = pindex->i_nonlocalaliases; *tmp; tmp++ ) { int i; i = th_prefix( (*ska->ska_local)->st_originalbase, (*tmp)->e_alias ); if ( i > 0 ) { do_alias( ska->ska_arg, *tmp, ska->ska_local ); } } } }
void process_data(Logfile *logfilep, Hashtable **hash, Arraydata **arraydata, choice *count, choice *code2type, choice datacols[ITEM_NUMBER][OUTCOME_NUMBER][DATACOLS_NUMBER][2], choice data2cols[ITEM_NUMBER][DATA_NUMBER], unsigned int *no_cols, Include **wanthead, Include *ispagehead, Alias **aliashead, Include *argshead, Include *refargshead, Dateman *dman, Tree **tree, Derv **derv, choice *alltrees, choice *alldervs, choice *lowmem, logical case_insensitive, logical usercase_insensitive, unsigned char convfloor, logical multibyte, char *dirsuffix, unsigned int dirsufflength, unsigned int granularity) { extern unsigned int year, month, date, hour, minute, code; extern unsigned long unixtime, proctime; extern char am; extern double bytes; extern Memman mm[], mmq, mms, *amemman; extern choice *rep2type; extern Hashentry *unwanted_entry, *blank_entry; extern Hashindex *dummy_item; static Hashindex *gp[ITEM_NUMBER]; unsigned long data[DATA2_NUMBER]; Hashentry *item[ITEM_NUMBER]; logical wanttree[ITEM_NUMBER]; logical isitpage, last7; choice ispage = UNSET; choice wanted = TRUE, rc, outcome; timecode_t timecode = FIRST_TIME; char *name, *namestart, *nameend; size_t len; choice i, j, k; /*** check whether this line is wanted ***/ if (count[INP_CODE] != 0) { if (code == IGNORE_CODE) { for (j = 0; j < ITEM_NUMBER; j++) { /* reset strings */ if (count[j] != 0) mm[j].next_pos = mm[j].curr_pos; } mmq.next_pos = mmq.curr_pos; mms.next_pos = mms.curr_pos; logfilep->data[LOGDATA_UNKNOWN]++; return; } else if (code2type[code] == UNWANTED) wanted = FALSE; } if (wanted && count[INP_DATE] > 0) { if (count[INP_UNIXTIME]) wanted = wantunixtime(&timecode, dman, unixtime, logfilep->tz); else { if (count[INP_AM]) { if (hour > 12) { corrupt_line(logfilep, "Hour greater than 12", -1); return; } else if (hour == 12) hour = 0; if (am == 'p') hour += 12; } wanted = wantdate(&timecode, dman, hour, minute, date, month, year, logfilep->tz); } if (wanted == ERR) { /* corrupt date */ corrupt_line(logfilep, "Corrupt date or time", -1); return; } } /* end count[INP_DATE] > 0 */ for (i = 0; i < ITEM_NUMBER; i++) { wanttree[i] = FALSE; if (!wanted) { for (j = i; j < ITEM_NUMBER; j++) { /* reset not-yet-hashed strings */ if (count[j] != 0) /* NB i is now (unwanted i) + 1 */ mm[j].next_pos = mm[j].curr_pos; } mmq.next_pos = mmq.curr_pos; mms.next_pos = mms.curr_pos; logfilep->data[LOGDATA_UNWANTED]++; return; } if (i == ITEM_HOST) prealiasS(&(mm[ITEM_HOST]), &mms); name = (char *)(mm[i].curr_pos); if (count[i] == 0 || IS_EMPTY_STRING(name) || (name[0] == '-' && name[1] == '\0')) { item[i] = blank_entry; /* or unwanted_; but we get wanted right anyway */ wanted = (wanthead[i] == NULL || included("", FALSE, wanthead[i])); /* wanthead[i] == NULL is tested again in included() but it often saves a call to that function, because blankness is common. */ } else { if (i == ITEM_FILE || i == ITEM_REFERRER) { if ((j = prealias(&(mm[i]), &(mm[ITEM_VHOST]), item[ITEM_VHOST], &mmq, (logical)((i == ITEM_FILE)?case_insensitive:FALSE), (i == ITEM_FILE)?(logfilep->prefix):NULL, logfilep->prefixlen, logfilep->pvpos, (i == ITEM_FILE)?argshead:refargshead)) < 0) { if (j == -1) corrupt_line(logfilep, "%v in file prefix but no VHOST in line", -1); else corrupt_line(logfilep, "Filename too long", -1); return; } } if (lowmem[i] == 0) { if (gp[i] == NULL || !STREQ(name, gp[i]->name)) { gp[i] = hashfind(&mm[i], &(hash[i]), no_cols[i], wanthead[i], UNSET, ispagehead, aliashead[i], dirsuffix, dirsufflength, usercase_insensitive, 0, FALSE, i, FALSE); } /* if name the same as last time, don't need */ else /* to hashfind again, or save the name */ mm[i].next_pos = mm[i].curr_pos; item[i] = (Hashentry *)(gp[i]->other); wanted = (choice)(ENTRY_WANTED(item[i])); } else if (lowmem[i] == 1) { if ((rc = do_alias(name, amemman, aliashead[i], dirsuffix, dirsufflength, usercase_insensitive, 0, FALSE, i)) == FALSE) { item[i] = hashfind(&mm[i], &(hash[i]), no_cols[i], wanthead[i], UNSET, ispagehead, NULL, dirsuffix, dirsufflength, usercase_insensitive, 0, FALSE, i, TRUE)->own; } else if (rc == TRUE) { mm[i].next_pos = mm[i].curr_pos; /* don't save string */ item[i] = hashfind(amemman, &(hash[i]), no_cols[i], wanthead[i], UNSET, ispagehead, NULL, dirsuffix, dirsufflength, usercase_insensitive, 0, FALSE, i, TRUE)->own; } else { /* rc == ERR */ mm[i].next_pos = mm[i].curr_pos; if (included("", FALSE, wanthead[i])) item[i] = blank_entry; else item[i] = unwanted_entry; } wanted = (choice)(ENTRY_WANTED(item[i])); } else { /* lowmem[i] >= 2 */ if ((rc = do_alias(name, amemman, aliashead[i], dirsuffix, dirsufflength, usercase_insensitive, 0, FALSE, i)) == TRUE) { mm[i].next_pos = mm[i].curr_pos; /* don't save old string */ len = strlen((char *)(amemman->curr_pos)); memcpy(submalloc(&(mm[i]), len + 1), amemman->curr_pos, len + 1); name = (char *)(mm[i].curr_pos); /* which might have changed */ amemman->next_pos = amemman->curr_pos; } if (rc == ERR) { if (included("", FALSE, wanthead[i])) { item[i] = blank_entry; if (i == ITEM_FILE) ispage = FALSE; } else wanted = FALSE; mm[i].next_pos = mm[i].curr_pos; } else { isitpage = pageq(name, ispagehead, i); if (i == ITEM_FILE) ispage = (choice)isitpage; if (included(name, isitpage, wanthead[i])) { if (lowmem[i] == 2) { item[i] = hashfind(&(mm[i]), &(hash[i]), no_cols[i], wanthead[i], isitpage, ispagehead, NULL, dirsuffix, dirsufflength, usercase_insensitive, 0, FALSE, i, TRUE)->own; } else { item[i] = blank_entry; wanttree[i] = TRUE; mm[i].next_pos = mm[i].curr_pos; } } else { wanted = FALSE; mm[i].next_pos = mm[i].curr_pos; } } } /* end lowmem[i] >= 2 */ } } /* end for i */ if (!wanted) { logfilep->data[LOGDATA_UNWANTED]++; return; } /*** now add it to the hash tables ***/ /* add to logfile from and to if wanted, whatever status code */ if (timecode != FIRST_TIME) logfilep->from = MIN(logfilep->from, timecode); logfilep->to = MAX(logfilep->to, timecode); last7 = (timecode > dman->last7from && timecode <= dman->last7to); if (ispage == UNSET) /* NB blank_entry has ispage FALSE */ ispage = (choice)(item[ITEM_FILE]->ispage); if (count[INP_BYTES] == 0) bytes = 0; if (count[INP_CODE] == 0) { outcome = SUCCESS; if (count[ITEM_FILE] == 2) { logfilep->data[LOGDATA_SUCC]++; logfilep->data[LOGDATA_SUCC7] += (unsigned long)last7; logfilep->data[LOGDATA_PAGES] += (unsigned long)ispage; logfilep->data[LOGDATA_PAGES7] += (unsigned long)((logical)ispage && last7); } else { logfilep->data[LOGDATA_UNKNOWN]++; logfilep->data[LOGDATA_UNKNOWN7] += (unsigned long)last7; } } else if (code <= 199) { outcome = INFO; logfilep->data[LOGDATA_INFO]++; logfilep->data[LOGDATA_INFO7] += (unsigned long)last7; } else switch (outcome = code2type[code]) { case SUCCESS: logfilep->data[LOGDATA_SUCC]++; logfilep->data[LOGDATA_SUCC7] += (unsigned long)last7; logfilep->data[LOGDATA_PAGES] += (unsigned long)ispage; logfilep->data[LOGDATA_PAGES7] += (unsigned long)((logical)ispage && last7); break; case FAILURE: logfilep->data[LOGDATA_FAIL]++; logfilep->data[LOGDATA_FAIL7] += (unsigned long)last7; break; case REDIRECT: logfilep->data[LOGDATA_REDIR]++; logfilep->data[LOGDATA_REDIR7] += (unsigned long)last7; break; case INFO: logfilep->data[LOGDATA_INFO]++; logfilep->data[LOGDATA_INFO7] += (unsigned long)last7; break; } /* NB any change in what to count when will require corresponding change to end of strtoinfmt() and to fmt munching in correct() */ if (count[INP_CODE] == 2) arrayscore(arraydata[REP_CODE - FIRST_ARRAYREP], code, 1, (unsigned long)last7, 0, 0, 0., 0., timecode); if (outcome != INFO) { if (outcome == SUCCESS) { if (count[INP_DATE] == 2) /* only if file present: see strtoinfmt() */ datehash(timecode, dman, 1, (unsigned long)ispage, bytes, granularity); if (count[INP_BYTES] == 2) { arrayscore(arraydata[REP_SIZE - FIRST_ARRAYREP], bytes, 1, (unsigned long)last7, (unsigned long)ispage, (unsigned long)((logical)ispage && last7), bytes, last7?bytes:0., timecode); logfilep->bytes += bytes; if (last7) logfilep->bytes7 += bytes; } if (count[INP_PROCTIME] == 2) arrayscore(arraydata[REP_PROCTIME - FIRST_ARRAYREP], proctime, 1, (unsigned long)last7, (unsigned long)ispage, (unsigned long)((logical)ispage && last7), bytes, last7?bytes:0., timecode); if (alltrees[0] != REP_NUMBER || alldervs[0] != REP_NUMBER) { /* for LOWMEM 3, run through alltrees then alldervs */ /* NB these (POSSTREE/POSSDERV in init.c) only count successes */ for (k = 0; k <= 1; k++) { for (i = 0; (k?(alldervs[i]):(alltrees[i])) != REP_NUMBER; i++) { j = rep2type[k?(alldervs[i]):(alltrees[i])]; if (wanttree[j]) { dummy_item->name = mm[j].curr_pos; /* mm.curr_pos is marked for deletion, but still intact at present */ dummy_item->own->data[data2cols[j][REQUESTS]] = 1; if (data2cols[j][REQUESTS7] >= 0) /* see comment in genrep() */ dummy_item->own->data[data2cols[j][REQUESTS7]] = (unsigned long)last7; if (data2cols[j][PAGES] >= 0) dummy_item->own->data[data2cols[j][PAGES]] = (unsigned long)ispage; if (data2cols[j][PAGES7] >= 0) dummy_item->own->data[data2cols[j][PAGES7]] = (unsigned long)((logical)ispage && last7); if (data2cols[j][SUCCDATE] >= 0) dummy_item->own->data[data2cols[j][SUCCDATE]] = timecode; if (data2cols[j][SUCCFIRSTD] >= 0) dummy_item->own->data[data2cols[j][SUCCFIRSTD]] = timecode; dummy_item->own->bytes = bytes; dummy_item->own->bytes7 = last7?bytes:0.; if (k) makederived(derv[alldervs[i] - FIRST_DERVREP], dummy_item, NULL, convfloor, multibyte, alldervs[i], datacols[j], no_cols[j]); else { namestart = NULL; tree[G(alltrees[i])]->cutfn(&namestart, &nameend, dummy_item->name, FALSE); (void)treefind(namestart, nameend, &(tree[G(alltrees[i])]->tree), dummy_item, tree[G(alltrees[i])]->cutfn, FALSE, TRUE, FALSE, tree[G(alltrees[i])]->space, datacols[j], no_cols[j]); } } } } } /* there are trees or dervs */ } /* outcome == SUCCESS */ data[REQUESTS2] = 1; data[REQUESTS72] = (unsigned long)last7; data[PAGES2] = (unsigned long)ispage; data[PAGES72] = (unsigned long)((logical)ispage && last7); data[DATE2] = timecode; data[FIRSTD2] = timecode; for (i = 0; i < ITEM_NUMBER; i++) { if (count[i] == 2 && !ENTRY_BLANK(item[i])) hashscore(item[i], data, datacols[i][outcome], outcome, bytes); } } /* end if outcome != INFO */ }
static void help(const char *s0, int flag) { const long long_help = flag & h_LONG; long n; entree *ep; char *s = get_sep(s0); if (isdigit((int)*s)) { digit_help(s,flag); return; } if (flag & h_APROPOS) { external_help(s,-1); return; } /* Get meaningful answer on '\ps 5' (e.g. from <F1>) */ if (*s == '\\') { char *t = s+1; pari_skip_alpha(&t); *t = '\0'; } if (isalpha((int)*s)) { if (!strncmp(s, "default", 7)) { /* special-case ?default(dft_name), e.g. default(log) */ char *t = s+7; pari_skip_space(&t); if (*t == '(') { t++; pari_skip_space(&t); cut_trailing_garbage(t); if (pari_is_default(t)) { default_help(t,flag); return; } } } cut_trailing_garbage(s); } if (long_help && (n = ok_external_help(&s))) { external_help(s,n); return; } switch (*s) { case '*' : commands(-1); return; case '\0': menu_commands(); return; case '\\': slash_commands(); return; case '.' : member_commands(); return; } ep = is_entry(s); if (!ep) { if (pari_is_default(s)) default_help(s,flag); else if (long_help) external_help(s,3); else if (!cb_pari_whatnow || !cb_pari_whatnow(pariOut, s,1)) simple_help(s,"unknown identifier"); return; } if (EpVALENCE(ep) == EpALIAS) { pari_printf("%s is aliased to:\n\n",s); ep = do_alias(ep); } switch(EpVALENCE(ep)) { case EpVAR: if (!ep->help) { if (typ((GEN)ep->value)!=t_CLOSURE) simple_help(s, "user defined variable"); else { GEN str = closure_get_text((GEN)ep->value); if (typ(str) == t_VEC) pari_printf("%s =\n %Ps\n", ep->name, ep->value); } return; } break; case EpINSTALL: if (!ep->help) { simple_help(s, "installed function"); return; } break; case EpNEW: if (!ep->help) { simple_help(s, "new identifier"); return; }; break; default: /* built-in function */ if (!ep->help) pari_err_BUG("gp_help (no help found)"); /*paranoia*/ if (long_help) { external_help(ep->name,3); return; } } print_text(ep->help); }
string process_input (string arg) { arg = do_alias(arg) ; return arg ; }