editline/TEST/test.c File Reference

#include "config.h"
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/wait.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include "histedit.h"
#include "tokenizer.h"

Include dependency graph for editline/TEST/test.c:

Go to the source code of this file.

Functions

 __COPYRIGHT ("@(#) Copyright (c) 1992, 1993\n\ The Regents of the University of California. All rights reserved.\n")
 __RCSID ("$NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $")
static u_char complete (EditLine *, int)
int main (int argc, char *argv[])
int main (int, char **)
static char * prompt (EditLine *)
static void sig (int)

Variables

static int continuation = 0
static EditLineel = NULL


Function Documentation

__COPYRIGHT ( "@(#) Copyright (c)   1992,
1993\n\The Regents of the University of California.All rights reserved.\n"   
)

__RCSID ( "$NetBSD: test.  c,
v 1.9 2000/09/04 23:36:41 lukem Exp $"   
)

static unsigned char complete ( EditLine el,
int  ch 
) [static]

Definition at line 94 of file editline/TEST/test.c.

References lineinfo::buffer, CC_ERROR, CC_REFRESH, lineinfo::cursor, el_insertstr(), el_line(), len(), and NULL.

Referenced by AST_TEST_DEFINE(), and main().

00095 {
00096    DIR *dd = opendir(".");
00097    struct dirent *dp;
00098    const char* ptr;
00099    const LineInfo *lf = el_line(el);
00100    int len;
00101 
00102    /*
00103     * Find the last word
00104     */
00105    for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
00106       continue;
00107    len = lf->cursor - ++ptr;
00108 
00109    for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
00110       if (len > strlen(dp->d_name))
00111          continue;
00112       if (strncmp(dp->d_name, ptr, len) == 0) {
00113          closedir(dd);
00114          if (el_insertstr(el, &dp->d_name[len]) == -1)
00115             return (CC_ERROR);
00116          else
00117             return (CC_REFRESH);
00118       }
00119    }
00120 
00121    closedir(dd);
00122    return (CC_ERROR);
00123 }

int main ( int  argc,
char *  argv[] 
)

Definition at line 126 of file editline/TEST/test.c.

References buf, complete(), continuation, EL_ADDFN, EL_BIND, EL_EDITOR, el_end(), el_gets(), EL_HIST, el_init(), el_parse(), EL_PROMPT, el_set(), EL_SIGNAL, el_source(), H_ADD, H_APPEND, H_CLEAR, H_ENTER, H_LAST, H_LOAD, H_PREV, H_SAVE, H_SET, H_SETSIZE, history(), history_end(), history_init(), NULL, HistEvent::num, prompt, sig(), HistEvent::str, tok_end(), tok_init(), tok_line(), and tok_reset().

00127 {
00128    int num;
00129    const char *buf;
00130    Tokenizer *tok;
00131 #if 0
00132    int lastevent = 0;
00133 #endif
00134    int ncontinuation;
00135    History *hist;
00136    HistEvent ev;
00137 
00138    (void) signal(SIGINT, sig);
00139    (void) signal(SIGQUIT, sig);
00140    (void) signal(SIGHUP, sig);
00141    (void) signal(SIGTERM, sig);
00142 
00143    hist = history_init();     /* Init the builtin history   */
00144                /* Remember 100 events     */
00145    history(hist, &ev, H_SETSIZE, 100);
00146 
00147    tok  = tok_init(NULL);     /* Initialize the tokenizer   */
00148 
00149                /* Initialize editline     */
00150    el = el_init(*argv, stdin, stdout, stderr);
00151 
00152    el_set(el, EL_EDITOR, "vi");  /* Default editor is vi    */
00153    el_set(el, EL_SIGNAL, 1);  /* Handle signals gracefully  */
00154    el_set(el, EL_PROMPT, prompt);   /* Set the prompt function */
00155 
00156          /* Tell editline to use this history interface  */
00157    el_set(el, EL_HIST, history, hist);
00158 
00159                /* Add a user-defined function   */
00160    el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
00161 
00162                /* Bind tab to it       */
00163    el_set(el, EL_BIND, "^I", "ed-complete", NULL);
00164 
00165    /*
00166     * Bind j, k in vi command mode to previous and next line, instead
00167     * of previous and next history.
00168     */
00169    el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
00170    el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
00171 
00172    /*
00173     * Source the user's defaults file.
00174     */
00175    el_source(el, NULL);
00176 
00177    while ((buf = el_gets(el, &num)) != NULL && num != 0)  {
00178       int ac;
00179       const char **av;
00180 #ifdef DEBUG
00181       (void) fprintf(stderr, "got %d %s", num, buf);
00182 #endif
00183       if (!continuation && num == 1)
00184          continue;
00185 
00186       ncontinuation = tok_line(tok, buf, &ac, &av) > 0;
00187 #if 0
00188       if (continuation) {
00189          /*
00190           * Append to the right event in case the user
00191           * moved around in history.
00192           */
00193          if (history(hist, &ev, H_SET, lastevent) == -1)
00194             err(1, "%d: %s\n", lastevent, ev.str);
00195          history(hist, &ev, H_ADD , buf);
00196       } else {
00197          history(hist, &ev, H_ENTER, buf);
00198          lastevent = ev.num;
00199       }
00200 #else
00201             /* Simpler */
00202       history(hist, &ev, continuation ? H_APPEND : H_ENTER, buf);
00203 #endif
00204 
00205       continuation = ncontinuation;
00206       ncontinuation = 0;
00207 
00208       if (strcmp(av[0], "history") == 0) {
00209          int rv;
00210 
00211          switch (ac) {
00212          case 1:
00213             for (rv = history(hist, &ev, H_LAST); rv != -1;
00214                 rv = history(hist, &ev, H_PREV))
00215                (void) fprintf(stdout, "%4d %s",
00216                    ev.num, ev.str);
00217             break;
00218 
00219          case 2:
00220             if (strcmp(av[1], "clear") == 0)
00221                 history(hist, &ev, H_CLEAR);
00222             else
00223                 goto badhist;
00224             break;
00225 
00226          case 3:
00227             if (strcmp(av[1], "load") == 0)
00228                 history(hist, &ev, H_LOAD, av[2]);
00229             else if (strcmp(av[1], "save") == 0)
00230                 history(hist, &ev, H_SAVE, av[2]);
00231             break;
00232 
00233          badhist:
00234          default:
00235             (void) fprintf(stderr,
00236                 "Bad history arguments\n");
00237             break;
00238          }
00239       } else if (el_parse(el, ac, av) == -1) {
00240          switch (fork()) {
00241          case 0:
00242             execvp(av[0], (char *const *)av);
00243             perror(av[0]);
00244             _exit(1);
00245             /*NOTREACHED*/
00246             break;
00247 
00248          case -1:
00249             perror("fork");
00250             break;
00251 
00252          default:
00253             if (wait(&num) == -1)
00254                perror("wait");
00255             (void) fprintf(stderr, "Exit %x\n", num);
00256             break;
00257          }
00258       }
00259 
00260       tok_reset(tok);
00261    }
00262 
00263    el_end(el);
00264    tok_end(tok);
00265    history_end(hist);
00266 
00267    return (0);
00268 }

int main ( int  ,
char **   
)

Definition at line 8 of file stdtime/test.c.

References ael2_print(), ael_external_load_module(), all_bits_set(), ast_context::alts, ast_exten::app, args, AST_LIST_FIRST, ast_localtime(), ast_log, ast_strdup, ast_exten::data, ast_timing::daymask, destroy_namelist(), ast_timing::dowmask, e, ast_context::eswitches, ast_exten::exten, extens, ast_context::extension_count, free, get_start_stop(), ast_include::hastime, ast_context::ignorepats, ast_context::includes, localized_pbx_load_module(), localized_use_conf_dir(), localized_use_local_dir(), localized_walk_context_extensions(), localized_walk_context_switches(), localized_walk_contexts(), localized_walk_extension_priorities(), LOG_ERROR, min, ast_timing::minmask, ast_timing::monthmask, ast_sw::name, ast_include::name, namelist::name, ast_context::name, namelist::name2, ast_ignorepat::next, ast_include::next, namelist::next, ast_context::next, NULL, parse_file(), ast_ignorepat::pattern, ast_exten::peer, ast_exten::priority, priors, PV_APPLICATION_CALL, PV_CONTEXT, PV_EXTENSION, PV_IGNOREPAT, PV_INCLUDES, PV_STATEMENTBLOCK, PV_SWITCHES, PV_WORD, pvalAppCallAddArg(), pvalAppCallSetAppName(), pvalContextAddStatement(), pvalContextSetName(), pvalCreateNode(), pvalExtenSetHints(), pvalExtenSetName(), pvalExtenSetStatement(), pvalIgnorePatSetPattern(), pvalIncludesAddInclude(), pvalIncludesAddIncludeWithTimeConstraints(), pvalStatementBlockAddStatement(), pvalSwitchesAddSwitch(), pvalTopLevAddObject(), pvalWordSetString(), set_var(), strdup, ast_context::switches, ast_include::timing, and tmp().

00008                                 {
00009    struct timeval tv;
00010    struct tm   tm;
00011    char  *zone[4] = { "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles" };
00012    int   i;
00013 
00014    gettimeofday(&tv,NULL);
00015 
00016    for (i=0;i<4;i++) {
00017       ast_localtime(&tv.tv_sec,&tm,zone[i]);
00018       printf("Localtime at %s is %04d/%02d/%02d %02d:%02d:%02d\n",zone[i],tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
00019    }
00020    return 0;
00021 }

static char * prompt ( EditLine el  )  [static]

Definition at line 77 of file editline/TEST/test.c.

References a, b, and continuation.

00078 {
00079    static char a[] = "Edit$";
00080    static char b[] = "Edit>";
00081 
00082    return (continuation ? b : a);
00083 }

static void sig ( int  i  )  [static]

Definition at line 86 of file editline/TEST/test.c.

References el_reset().

Referenced by ast_check_signature(), ast_sign(), authenticate(), iax2_provision(), iax_provision_build(), and main().

00087 {
00088 
00089    (void) fprintf(stderr, "Got signal %d.\n", i);
00090    el_reset(el);
00091 }


Variable Documentation

int continuation = 0 [static]

Definition at line 68 of file editline/TEST/test.c.

Referenced by main(), and prompt().

EditLine* el = NULL [static]

Definition at line 69 of file editline/TEST/test.c.


Generated on Thu Apr 16 06:34:10 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6