static int os_date(lua_State* L) { const char* s = luaL_optstring(L, 1, "%c"); time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); struct tm* stm; if (*s == '!') /* UTC? */ { stm = gmtime(&t); s++; /* skip `!' */ } else stm = localtime(&t); if (stm == NULL) /* invalid date? */ lua_pushnil(L); else if (strcmp(s, "*t") == 0) { lua_createtable(L, 0, 9); /* 9 = number of fields */ setfield(L, "sec", stm->tm_sec); setfield(L, "min", stm->tm_min); setfield(L, "hour", stm->tm_hour); setfield(L, "day", stm->tm_mday); setfield(L, "month", stm->tm_mon + 1); setfield(L, "year", stm->tm_year + 1900); setfield(L, "wday", stm->tm_wday + 1); setfield(L, "yday", stm->tm_yday + 1); setboolfield(L, "isdst", stm->tm_isdst); } else { char cc[3]; luaL_Buffer b; cc[0] = '%'; cc[2] = '\0'; luaL_buffinit(L, &b); for (; *s; s++) { if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ luaL_addchar(&b, *s); else { size_t reslen; char buff[200]; /* should be big enough for any conversion result */ cc[1] = *(++s); reslen = strftime(buff, sizeof(buff), cc, stm); luaL_addlstring(&b, buff, reslen); } } luaL_pushresult(&b); } return 1; }
int lh_getevent(lua_State *L) { for(int i=0; i<size(eventobjs); i++) { if(objs[eventobjs[i]] && objs[eventobjs[i]]->checkEvent(L)) { return 1; } } SDL_Delay(10); lua_newtable(L); setfield(L, "type", 0); return 1; }
/* ----> Create an alarm <---- */ dbref create_alarm(CONTEXT) { dbref alarm,owner = (!in_command && (Uid(player) != player)) ? Uid(player):Owner(player); setreturn(ERROR,COMMAND_FAIL); if(Level3(Owner(player))) { if(!Blank(arg1)) { if(strlen(arg1) <= 128) { if(ok_name(arg1)) { if(adjustquota(player,owner,ALARM_QUOTA)) { /* ----> Create and initialise alarm <---- */ alarm = new_object(); db[alarm].destination = NOTHING; db[alarm].location = player; db[alarm].flags = OBJECT; db[alarm].owner = owner; db[alarm].type = TYPE_ALARM; if(!in_command && (Uid(player) == owner) && friendflags_set(owner,player,NOTHING,FRIEND_SHARABLE)) db[alarm].flags |= SHARABLE; ansi_code_filter((char *) arg1,arg1,1); initialise_data(alarm); setfield(alarm,NAME,arg1,1); setfield(alarm,DESC,arg2,0); stats_tcz_update_record(0,0,0,1,0,0,0); PUSH(alarm,db[player].fuses); if(!in_command) output(getdsc(player),player,0,1,0,ANSI_LGREEN"Alarm "ANSI_LWHITE"%s"ANSI_LGREEN" created with ID "ANSI_LYELLOW"#%d"ANSI_LGREEN".",getfield(alarm,NAME),alarm); else writelog(HACK_LOG,1,"HACK","Alarm %s(%d) created within compound command %s(%d) owned by %s(%d).",getname(alarm),alarm,getname(current_command),current_command,getname(Owner(current_command)),Owner(current_command)); setreturn(getnameid(player,alarm,NULL),COMMAND_SUCC); return(alarm); } else warnquota(player,owner,"to build an alarm"); } else output(getdsc(player),player,0,1,0,ANSI_LGREEN"Sorry, an alarm can't have that name."); } else output(getdsc(player),player,0,1,0,ANSI_LGREEN"Sorry, the maximum length of an alarm's name is 128 characters."); } else output(getdsc(player),player,0,1,0,ANSI_LGREEN"Please specify a name for the new alarm."); } else output(getdsc(player),player,0,1,0,ANSI_LGREEN"Sorry, only Wizards/Druids and above can create an alarm."); return(NOTHING); }
static int os_date (lua_State *L) { const char *s = luaL_optstring(L, 1, "%c"); // FIXME: Rewrite the code below to use OSystem::getTimeAndDate // Alternatively, remove it, if sword25 does not use it. // // The former would mean sacrificing the ability to choose the timezone, *or* // we would have to drive an effort to add time zone support to OSystem (is it // worth that, though???) time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); struct tm *stm; if (*s == '!') { /* UTC? */ stm = gmtime(&t); s++; /* skip `!' */ } else stm = localtime(&t); if (stm == NULL) /* invalid date? */ lua_pushnil(L); else if (strcmp(s, "*t") == 0) { lua_createtable(L, 0, 9); /* 9 = number of fields */ setfield(L, "sec", stm->tm_sec); setfield(L, "min", stm->tm_min); setfield(L, "hour", stm->tm_hour); setfield(L, "day", stm->tm_mday); setfield(L, "month", stm->tm_mon+1); setfield(L, "year", stm->tm_year+1900); setfield(L, "wday", stm->tm_wday+1); setfield(L, "yday", stm->tm_yday+1); setboolfield(L, "isdst", stm->tm_isdst); } else { char cc[3]; luaL_Buffer b; cc[0] = '%'; cc[2] = '\0'; luaL_buffinit(L, &b); for (; *s; s++) { if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ luaL_addchar(&b, *s); else { size_t reslen; char buff[200]; /* should be big enough for any conversion result */ cc[1] = *(++s); reslen = strftime(buff, sizeof(buff), cc, stm); luaL_addlstring(&b, buff, reslen); } } luaL_pushresult(&b); } return 1; }
static int os_date (LuaThread *L) { THREAD_CHECK(L); const char *s = luaL_optstring(L, 1, "%c"); time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); struct tm tmr, *stm; if (*s == '!') { /* UTC? */ stm = l_gmtime(&t, &tmr); s++; /* skip `!' */ } else stm = l_localtime(&t, &tmr); if (stm == NULL) { /* invalid date? */ L->stack_.push(LuaValue::Nil()); } else if (strcmp(s, "*t") == 0) { lua_createtable(L, 0, 9); /* 9 = number of fields */ setfield(L, "sec", stm->tm_sec); setfield(L, "min", stm->tm_min); setfield(L, "hour", stm->tm_hour); setfield(L, "day", stm->tm_mday); setfield(L, "month", stm->tm_mon+1); setfield(L, "year", stm->tm_year+1900); setfield(L, "wday", stm->tm_wday+1); setfield(L, "yday", stm->tm_yday+1); setboolfield(L, "isdst", stm->tm_isdst); } else { char cc[4]; luaL_Buffer b; cc[0] = '%'; luaL_buffinit(L, &b); while (*s) { if (*s != '%') /* no conversion specifier? */ luaL_addchar(&b, *s++); else { size_t reslen; char buff[200]; /* should be big enough for any conversion result */ s = checkoption(L, s + 1, cc); reslen = strftime(buff, sizeof(buff), cc, stm); luaL_addlstring(&b, buff, reslen); } } luaL_pushresult(&b); } return 1; }
static int os_date (LUA_State *L) { const char *s = LUAL_optstring(L, 1, "%c"); time_t t = LUAL_opt(L, (time_t)LUAL_checknumber, 2, time(NULL)); struct tm tmr, *stm; if (*s == '!') { /* UTC? */ stm = l_gmtime(&t, &tmr); s++; /* skip `!' */ } else stm = l_localtime(&t, &tmr); if (stm == NULL) /* invalid date? */ LUA_pushnil(L); else if (strcmp(s, "*t") == 0) { LUA_createtable(L, 0, 9); /* 9 = number of fields */ setfield(L, "SEC", stm->tm_sec); setfield(L, "MIN", stm->tm_min); setfield(L, "HOUR", stm->tm_hour); setfield(L, "DAY", stm->tm_mday); setfield(L, "MONTH", stm->tm_mon+1); setfield(L, "YEAR", stm->tm_year+1900); setfield(L, "WDAY", stm->tm_wday+1); setfield(L, "YDAY", stm->tm_yday+1); setboolfield(L, "ISDST", stm->tm_isdst); } else { char cc[4]; LUAL_Buffer b; cc[0] = '%'; LUAL_buffinit(L, &b); while (*s) { if (*s != '%') /* no conversion specifier? */ LUAL_addchar(&b, *s++); else { size_t reslen; char buff[200]; /* should be big enough for any conversion result */ s = checkoption(L, s + 1, cc); reslen = strftime(buff, sizeof(buff), cc, stm); LUAL_addlstring(&b, buff, reslen); } } LUAL_pushresult(&b); } return 1; }
static int os_date (lua_State *L) { const char *s = luaL_optstring(L, 1, "%c"); time_t t = luaL_opt(L, l_checktime, 2, time(NULL)); struct tm tmr, *stm; if (*s == '!') { /* UTC? */ stm = l_gmtime(&t, &tmr); s++; /* skip '!' */ } else stm = l_localtime(&t, &tmr); if (stm == NULL) /* invalid date? */ luaL_error(L, "time result cannot be represented in this installation"); if (strcmp(s, "*t") == 0) { lua_createtable(L, 0, 9); /* 9 = number of fields */ setfield(L, "sec", stm->tm_sec); setfield(L, "min", stm->tm_min); setfield(L, "hour", stm->tm_hour); setfield(L, "day", stm->tm_mday); setfield(L, "month", stm->tm_mon+1); setfield(L, "year", stm->tm_year+1900); setfield(L, "wday", stm->tm_wday+1); setfield(L, "yday", stm->tm_yday+1); setboolfield(L, "isdst", stm->tm_isdst); } else { char cc[4]; luaL_Buffer b; cc[0] = '%'; luaL_buffinit(L, &b); while (*s) { if (*s != '%') /* not a conversion specifier? */ luaL_addchar(&b, *s++); else { size_t reslen; char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT); s = checkoption(L, s + 1, cc); reslen = strftime(buff, SIZETIMEFMT, cc, stm); luaL_addsize(&b, reslen); } } luaL_pushresult(&b); } return 1; }
int navdata_ihm_raw_navdata_update ( const navdata_unpacked_t* const navdata ) { int cpt; long int period; double frequence,lowpass_frequence; static double previous_frequence=0.0f; struct timeval current_time; static struct timeval previous_time; static unsigned long int lastRefreshTime=0; navdata_t* packed_navdata = (navdata_t*) &navdata_buffer[0]; if (!window || !view) { return -1; } gettimeofday(¤t_time,NULL); period = ((current_time.tv_sec-previous_time.tv_sec))*1000000+(current_time.tv_usec-previous_time.tv_usec); lastRefreshTime+=period; frequence = 1000000.0f / (double)period; lowpass_frequence = frequence * 0.005f + previous_frequence * 0.95f; if (lastRefreshTime > 100000 /*ms*/) { lastRefreshTime = 0; gdk_threads_enter(); //http://library.gnome.org/devel/gdk/stable/gdk-Threads.html snprintf(buf,sizeof(buf),"%d",packed_navdata->sequence); snprintf(buf2,sizeof(buf2),"%3.1f Hz",lowpass_frequence); gtk_tree_store_set(treestore, &sequence_number,COL_VALUE, buf,COL_COMMENT,buf2,-1); cpt=0; snprintf(buf,sizeof(buf),"%x",navdata->navdata_demo.ctrl_state); setfield(NAVDATA_DEMO_TAG,buf,&cpt); snprintf(buf,sizeof(buf),"%3.1f",navdata->navdata_demo.phi/1000); setfield(NAVDATA_DEMO_TAG,buf,&cpt); snprintf(buf,sizeof(buf),"%3.1f",navdata->navdata_demo.psi/1000); setfield(NAVDATA_DEMO_TAG,buf,&cpt); snprintf(buf,sizeof(buf),"%3.1f",navdata->navdata_demo.theta/1000); setfield(NAVDATA_DEMO_TAG,buf,&cpt); cpt=0; snprintf(buf,sizeof(buf),"%x",navdata->navdata_games.double_tap_counter); setfield(NAVDATA_GAMES_TAG,buf,&cpt); snprintf(buf,sizeof(buf),"%x",navdata->navdata_games.finish_line_counter); setfield(NAVDATA_GAMES_TAG,buf,&cpt); gtk_widget_draw(GTK_WIDGET(view), NULL); gdk_threads_leave(); //http://library.gnome.org/devel/gdk/stable/gdk-Threads.html } previous_time = current_time; previous_frequence = lowpass_frequence; return C_OK; }
static int io_date (lua_State *L) { #if 0 const char *s = luaL_optstring(L, 1, "%c"); time_t t = (time_t)(luaL_optnumber(L, 2, -1)); struct tm *stm; if (t == (time_t)(-1)) /* no time given? */ t = time(NULL); /* use current time */ if (*s == '!') { /* UTC? */ stm = gmtime(&t); s++; /* skip `!' */ } else stm = localtime(&t); if (stm == NULL) /* invalid date? */ lua_pushnil(L); else if (strcmp(s, "*t") == 0) { lua_newtable(L); setfield(L, "sec", stm->tm_sec); setfield(L, "min", stm->tm_min); setfield(L, "hour", stm->tm_hour); setfield(L, "day", stm->tm_mday); setfield(L, "month", stm->tm_mon+1); setfield(L, "year", stm->tm_year+1900); setfield(L, "wday", stm->tm_wday+1); setfield(L, "yday", stm->tm_yday+1); setboolfield(L, "isdst", stm->tm_isdst); } else { char b[256]; if (strftime(b, sizeof(b), s, stm)) lua_pushstring(L, b); else return luaL_error(L, "`date' format too long"); } #endif lua_pushnil(L); return 1; }
int main (int argc, char* argv[]) { lua_State* L = lua_open(); luaopen_base(L); luaopen_io(L); luaopen_string(L); luaopen_table(L); luaopen_math(L); luaopen_debug(L); lua_pushstring(L,TOLUA_VERSION); lua_setglobal(L,"TOLUA_VERSION"); if (argc==1) { help(); return 0; } else { int i, t; lua_newtable(L); lua_pushvalue(L,-1); lua_setglobal(L,"flags"); t = lua_gettop(L); for (i=1; i<argc; ++i) { if (*argv[i] == '-') { switch (argv[i][1]) { case 'v': version(); return 0; case 'h': help(); return 0; case 'p': setfield(L,t,"p",""); break; case 'P': setfield(L,t,"P",""); break; case 'o': setfield(L,t,"o",argv[++i]); break; case 'n': setfield(L,t,"n",argv[++i]); break; case 'H': setfield(L,t,"H",argv[++i]); break; case 'S': setfield(L,t,"S",""); break; case '1': setfield(L,t,"1",""); break; case 'L': setfield(L,t,"L",argv[++i]); break; default: error(argv[i]); break; } } else { setfield(L,t,"f",argv[i]); break; } } lua_pop(L,1); } /* #define TOLUA_SCRIPT_RUN */ #ifndef TOLUA_SCRIPT_RUN { int tolua_tolua_open (lua_State* L); tolua_tolua_open(L); } #else { char* p; char path[BUFSIZ]; strcpy(path,argv[0]); p = strrchr(path,'/'); if (p==NULL) p = strrchr(path,'\\'); p = (p==NULL) ? path : p+1; sprintf(p,"%s","../src/bin/lua/"); lua_pushstring(L,path); lua_setglobal(L,"path"); strcat(path,"all.lua"); lua_dofile(L,path); } #endif return 0; }
/* execute the command */ BOOL command(int commandc) { char filename[PATHLEN + 1]; /* file path name */ MOUSE *p; /* mouse data */ int c, i; FILE *file; struct cmd *curritem, *item; /* command history */ char *s; switch (commandc) { case ctrl('C'): /* toggle caseless mode */ if (caseless == NO) { caseless = YES; postmsg2("Caseless mode is now ON"); } else { caseless = NO; postmsg2("Caseless mode is now OFF"); } egrepcaseless(caseless); /* turn on/off -i flag */ return(NO); case ctrl('R'): /* rebuild the cross reference */ if (isuptodate == YES) { postmsg("The -d option prevents rebuilding the symbol database"); return(NO); } exitcurses(); freefilelist(); /* remake the source file list */ makefilelist(); rebuild(); if (errorsfound == YES) { errorsfound = NO; askforreturn(); } entercurses(); clearmsg(); /* clear any previous message */ totallines = 0; disprefs = 0; topline = nextline = 1; selecting = 0; break; #if UNIXPC case ESC: /* possible unixpc mouse selection */ #endif case ctrl('X'): /* mouse selection */ if ((p = getmouseaction(DUMMYCHAR)) == NULL) { return(NO); /* unknown control sequence */ } /* if the button number is a scrollbar tag */ if (p->button == '0') { scrollbar(p); break; } /* ignore a sweep */ if (p->x2 >= 0) { return(NO); } /* if this is a line selection */ if (p->y1 < FLDLINE) { /* find the selected line */ /* note: the selection is forced into range */ for (i = disprefs - 1; i > 0; --i) { if (p->y1 >= displine[i]) { break; } } /* display it in the file with the editor */ editref(i); } else { /* this is an input field selection */ field = p->y1 - FLDLINE; /* force it into range */ if (field >= FIELDS) { field = FIELDS - 1; } setfield(); resetcmd(); return(NO); } break; case '\t': /* go to next input field */ if (disprefs) { selecting = !selecting; if (selecting) { move(displine[curdispline], 0); refresh(); } else { atfield(); resetcmd(); } } return(NO); #ifdef KEY_ENTER case KEY_ENTER: #endif case '\r': case '\n': /* go to reference */ if (selecting) { editref(curdispline); return(YES); } /* FALLTHROUGH */ case ctrl('N'): #ifdef KEY_DOWN case KEY_DOWN: #endif #ifdef KEY_RIGHT case KEY_RIGHT: #endif if (selecting) { if ((curdispline + 1) < disprefs) { move(displine[++curdispline], 0); refresh(); } } else { field = (field + 1) % FIELDS; setfield(); atfield(); resetcmd(); } return(NO); case ctrl('P'): /* go to previous input field */ #ifdef KEY_UP case KEY_UP: #endif #ifdef KEY_LEFT case KEY_LEFT: #endif if (selecting) { if (curdispline) { move(displine[--curdispline], 0); refresh(); } } else { field = (field + (FIELDS - 1)) % FIELDS; setfield(); atfield(); resetcmd(); } return(NO); #ifdef KEY_HOME case KEY_HOME: /* go to first input field */ if (selecting) { curdispline = 0; move(REFLINE, 0); refresh(); } else { field = 0; setfield(); atfield(); resetcmd(); } return(NO); #endif #ifdef KEY_LL case KEY_LL: /* go to last input field */ if (selecting) { move(displine[disprefs - 1], 0); refresh(); } else { field = FIELDS - 1; setfield(); atfield(); resetcmd(); } return(NO); #endif /* def(KEY_LL) */ case ' ': /* display next page */ case '+': case ctrl('V'): #ifdef KEY_NPAGE case KEY_NPAGE: #endif /* don't redisplay if there are no lines */ if (totallines == 0) { return(NO); } /* note: seekline() is not used to move to the next * page because display() leaves the file pointer at * the next page to optimize paging forward */ curdispline = 0; break; case ctrl('H'): case '-': /* display previous page */ #ifdef KEY_PPAGE case KEY_PPAGE: #endif /* don't redisplay if there are no lines */ if (totallines == 0) { return(NO); } curdispline = 0; /* if there are only two pages, just go to the other one */ if (totallines <= 2 * mdisprefs) { break; } /* if on first page but not at beginning, go to beginning */ nextline -= mdisprefs; /* already at next page */ if (nextline > 1 && nextline <= mdisprefs) { nextline = 1; } else { nextline -= mdisprefs; if (nextline < 1) { nextline = totallines - mdisprefs + 1; if (nextline < 1) { nextline = 1; } } } seekline(nextline); break; case '>': /* write or append the lines to a file */ if (totallines == 0) { postmsg("There are no lines to write to a file"); } else { /* get the file name */ move(PRLINE, 0); addstr("Write to file: "); s = "w"; if ((c = mygetch()) == '>') { move(PRLINE, 0); addstr(appendprompt); c = '\0'; s = "a"; } if (c != '\r' && mygetline("", newpat, COLS - sizeof(appendprompt), c, NO) > 0 ) { shellpath(filename, sizeof(filename), newpat); if ((file = myfopen(filename, s)) == NULL) { cannotopen(filename); } else { seekline(1); while ((c = getc(refsfound)) != EOF) { putc(c, file); } seekline(topline); fclose(file); } } clearprompt(); } return(NO); /* return to the previous field */ case '<': /* read lines from a file */ move(PRLINE, 0); addstr(readprompt); if (mygetline("", newpat, COLS - sizeof(readprompt), '\0', NO) > 0) { clearprompt(); shellpath(filename, sizeof(filename), newpat); if (readrefs(filename) == NO) { postmsg2("Ignoring an empty file"); return(NO); } return(YES); } clearprompt(); return(NO); case '^': /* pipe the lines through a shell command */ case '|': /* pipe the lines to a shell command */ if (totallines == 0) { postmsg("There are no lines to pipe to a shell command"); return(NO); } /* get the shell command */ move(PRLINE, 0); addstr(pipeprompt); if (mygetline("", newpat, COLS - sizeof(pipeprompt), '\0', NO) == 0) { clearprompt(); return(NO); } /* if the ^ command, redirect output to a temp file */ if (commandc == '^') { strcat(strcat(newpat, " >"), temp2); /* HBB 20020708: somebody might have even * their non-interactive default shells * complain about clobbering * redirections... --> delete before * overwriting */ remove(temp2); } exitcurses(); if ((file = mypopen(newpat, "w")) == NULL) { fprintf(stderr, "\ cscope: cannot open pipe to shell command: %s\n", newpat); } else {
int main(int argc, char *argv[]) { int ch, i, stdinflag = 0; char cflag = 0, mflag = 0; char *outfile, *outpath = NULL; struct field *fldtab; size_t fldtab_sz, fld_cnt; size_t alloc_size; struct filelist filelist; int num_input_files; FILE *outfp = NULL; struct rlimit rl; struct stat st; setlocale(LC_ALL, ""); /* bump RLIMIT_NOFILE to maximum our hard limit allows */ if (getrlimit(RLIMIT_NOFILE, &rl) < 0) err(2, "getrlimit"); rl.rlim_cur = rl.rlim_max; if (setrlimit(RLIMIT_NOFILE, &rl) < 0) err(2, "setrlimit"); d_mask[REC_D = '\n'] = REC_D_F; d_mask['\t'] = d_mask[' '] = BLANK | FLD_D; /* fldtab[0] is the global options. */ fldtab_sz = 3; fld_cnt = 0; alloc_size = fldtab_sz * sizeof(*fldtab); fldtab = malloc(alloc_size); if (fldtab == NULL) err(1, "Cannot allocate %zu bytes", alloc_size); memset(fldtab, 0, alloc_size); #define SORT_OPTS "bcdD:fHik:lmno:rR:sSt:T:ux" /* Convert "+field" args to -f format */ fixit(&argc, argv, SORT_OPTS); if (!(tmpdir = getenv("TMPDIR"))) tmpdir = _PATH_TMP; while ((ch = getopt(argc, argv, SORT_OPTS)) != -1) { switch (ch) { case 'b': fldtab[0].flags |= BI | BT; break; case 'c': cflag = 1; break; case 'D': /* Debug flags */ for (i = 0; optarg[i]; i++) debug_flags |= 1 << (optarg[i] & 31); break; case 'd': case 'f': case 'i': case 'n': case 'l': fldtab[0].flags |= optval(ch, 0); break; case 'H': /* -H was ; use merge sort for blocks of large files' */ /* That is now the default. */ break; case 'k': alloc_size = (fldtab_sz + 1) * sizeof(*fldtab); fldtab = realloc(fldtab, alloc_size); if (fldtab == NULL) err(1, "Cannot re-allocate %zu bytes", alloc_size); memset(&fldtab[fldtab_sz], 0, sizeof(fldtab[0])); fldtab_sz++; setfield(optarg, &fldtab[++fld_cnt], fldtab[0].flags); break; case 'm': mflag = 1; break; case 'o': outpath = optarg; break; case 'r': REVERSE = 1; break; case 's': /* * Nominally 'stable sort', keep lines with equal keys * in input file order. (Default for NetBSD) * (-s for GNU sort compatibility.) */ posix_sort = 0; break; case 'S': /* * Reverse of -s! * This needs to enforce a POSIX sort where records * with equal keys are then sorted by the raw data. * Currently not implemented! * (using libc radixsort() v sradixsort() doesn't * have the desired effect.) */ posix_sort = 1; break; case 't': if (SEP_FLAG) usage("multiple field delimiters"); SEP_FLAG = 1; d_mask[' '] &= ~FLD_D; d_mask['\t'] &= ~FLD_D; d_mask[(u_char)*optarg] |= FLD_D; if (d_mask[(u_char)*optarg] & REC_D_F) errx(2, "record/field delimiter clash"); break; case 'R': if (REC_D != '\n') usage("multiple record delimiters"); REC_D = *optarg; if (REC_D == '\n') break; if (optarg[1] != '\0') { char *ep; int t = 0; if (optarg[0] == '\\') optarg++, t = 8; REC_D = (int)strtol(optarg, &ep, t); if (*ep != '\0' || REC_D < 0 || REC_D >= (int)__arraycount(d_mask)) errx(2, "invalid record delimiter %s", optarg); } d_mask['\n'] = d_mask[' ']; d_mask[REC_D] = REC_D_F; break; case 'T': /* -T tmpdir */ tmpdir = optarg; break; case 'u': UNIQUE = 1; break; case '?': default: usage(NULL); } } if (UNIQUE) /* Don't sort on raw record if keys match */ posix_sort = 0; if (cflag && argc > optind+1) errx(2, "too many input files for -c option"); if (argc - 2 > optind && !strcmp(argv[argc-2], "-o")) { outpath = argv[argc-1]; argc -= 2; } if (mflag && argc - optind > (MAXFCT - (16+1))*16) errx(2, "too many input files for -m option"); for (i = optind; i < argc; i++) { /* allow one occurrence of /dev/stdin */ if (!strcmp(argv[i], "-") || !strcmp(argv[i], _PATH_STDIN)) { if (stdinflag) warnx("ignoring extra \"%s\" in file list", argv[i]); else stdinflag = 1; /* change to /dev/stdin if '-' */ if (argv[i][0] == '-') { static char path_stdin[] = _PATH_STDIN; argv[i] = path_stdin; } } else if ((ch = access(argv[i], R_OK))) err(2, "%s", argv[i]); } if (fldtab[1].icol.num == 0) { /* No sort key specified */ if (fldtab[0].flags & (I|D|F|N|L)) { /* Modified - generate a key that covers the line */ fldtab[0].flags &= ~(BI|BT); setfield("1", &fldtab[++fld_cnt], fldtab->flags); fldreset(fldtab); } else { /* Unmodified, just compare the line */ SINGL_FLD = 1; fldtab[0].icol.num = 1; } } else { fldreset(fldtab); } settables(); if (optind == argc) { static const char * const names[] = { _PATH_STDIN, NULL }; filelist.names = names; num_input_files = 1; } else { filelist.names = (const char * const *) &argv[optind]; num_input_files = argc - optind; } if (cflag) { order(&filelist, fldtab); /* NOT REACHED */ } if (!outpath) { toutpath[0] = '\0'; /* path not used in this case */ outfile = outpath = toutpath; outfp = stdout; } else if (lstat(outpath, &st) == 0 && !S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode)) { /* output file exists and isn't character or block device */ struct sigaction act; static const int sigtable[] = {SIGHUP, SIGINT, SIGPIPE, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, 0 }; int outfd; errno = 0; if (access(outpath, W_OK)) err(2, "%s", outpath); (void)snprintf(toutpath, sizeof(toutpath), "%sXXXXXX", outpath); if ((outfd = mkstemp(toutpath)) == -1) err(2, "Cannot create temporary file `%s'", toutpath); (void)atexit(cleanup); act.sa_handler = onsignal; (void) sigemptyset(&act.sa_mask); act.sa_flags = SA_RESTART | SA_RESETHAND; for (i = 0; sigtable[i]; ++i) /* always unlink toutpath */ sigaction(sigtable[i], &act, 0); outfile = toutpath; if ((outfp = fdopen(outfd, "w")) == NULL) err(2, "Cannot open temporary file `%s'", toutpath); } else { outfile = outpath; if ((outfp = fopen(outfile, "w")) == NULL) err(2, "output file %s", outfile); } if (mflag) fmerge(&filelist, num_input_files, outfp, fldtab); else fsort(&filelist, num_input_files, outfp, fldtab); if (outfile != outpath) { if (access(outfile, F_OK)) err(2, "%s", outfile); /* * Copy file permissions bits of the original file. * st is initialized above, when we create the * temporary spool file. */ if (lchmod(outfile, st.st_mode & ALLPERMS) != 0) { err(2, "cannot chmod %s: output left in %s", outpath, outfile); } (void)unlink(outpath); if (link(outfile, outpath)) err(2, "cannot link %s: output left in %s", outpath, outfile); (void)unlink(outfile); toutpath[0] = 0; } exit(0); }
int lixp_pushstat (lua_State *L, const struct IxpStat *stat) { static char buf[32]; lua_newtable (L); setfield(number, "type", stat->type); setfield(number, "dev", stat->dev); //setfield(Qid, "qid", stat->qid); // TODO: what is this? setfield(number, "mode", stat->mode); setfield(number, "atime", stat->atime); setfield(number, "mtime", stat->mtime); setfield(number, "length", stat->length); setfield(string, "name", stat->name); setfield(string, "uid", stat->uid); setfield(string, "gid", stat->gid); setfield(string, "muid", stat->muid); build_modestr(buf, stat); setfield(string, "modestr", buf); build_timestr(buf, stat); setfield(string, "timestr", buf); return 1; }
__declspec(dllexport) int luaopen_libusb(lua_State *L) { #else int luaopen_libusb(lua_State *L) { #endif usb_init(); usb_find_busses(); usb_find_devices(); luaL_openlib(L, "libusb", libusb, 0); //connect_usb() // add a table in the registry to hold all C pointer / userdata equivalents // the table has "weak values" mode /*lua_pushliteral(L, "usb_userdata_map"); // "dbus_userdata_map" lua_newtable(L); // "usb_userdata_map" {} lua_newtable(L); // "usb_userdata_map" {} map_meta lua_pushliteral(L, "__mode"); // "usb_userdata_map" {} map_meta "__mode" lua_pushliteral(L, "v"); // "usb_userdata_map" {} map_meta "__mode" "v" lua_settable(L, -3); // "usb_userdata_map" {} map_meta lua_setmetatable(L, -2); // "usb_userdata_map" {} lua_settable(L, LUA_REGISTRYINDEX); // luaL_register(L, "libusb", libusb); // {usb}*/ setfield(L, USB_CLASS_PER_INTERFACE, "USB_CLASS_PER_INTERFACE"); setfield(L, USB_CLASS_AUDIO,"USB_CLASS_AUDIO"); setfield(L, USB_CLASS_COMM,"USB_CLASS_COMM"); setfield(L, USB_CLASS_HID,"USB_CLASS_HID"); setfield(L, USB_CLASS_PRINTER,"USB_CLASS_PRINTER"); setfield(L, USB_CLASS_PTP,"USB_CLASS_PTP"); setfield(L, USB_CLASS_MASS_STORAGE,"USB_CLASS_MASS_STORAGE"); setfield(L, USB_CLASS_HUB,"USB_CLASS_HUB"); setfield(L, USB_CLASS_DATA,"USB_CLASS_DATA"); setfield(L, USB_CLASS_VENDOR_SPEC,"USB_CLASS_VENDOR_SPEC"); setfield(L, USB_DT_DEVICE,"USB_DT_DEVICE"); setfield(L, USB_DT_CONFIG,"USB_DT_CONFIG"); setfield(L, USB_DT_STRING,"USB_DT_STRING"); setfield(L, USB_DT_INTERFACE,"USB_DT_INTERFACE"); setfield(L, USB_DT_ENDPOINT,"USB_DT_ENDPOINT"); setfield(L, USB_DT_HID,"USB_DT_HID"); setfield(L, USB_DT_REPORT,"USB_DT_REPORT"); setfield(L, USB_DT_PHYSICAL,"USB_DT_PHYSICAL"); setfield(L, USB_DT_HUB,"USB_DT_HUB"); setfield(L, USB_DT_DEVICE_SIZE,"USB_DT_DEVICE_SIZE"); setfield(L, USB_DT_CONFIG_SIZE,"USB_DT_CONFIG_SIZE"); setfield(L, USB_DT_INTERFACE_SIZE,"USB_DT_INTERFACE_SIZE"); setfield(L, USB_DT_ENDPOINT_SIZE,"USB_DT_ENDPOINT_SIZE"); setfield(L, USB_DT_ENDPOINT_AUDIO_SIZE,"USB_DT_ENDPOINT_AUDIO_SIZE"); setfield(L, USB_DT_HUB_NONVAR_SIZE,"USB_DT_HUB_NONVAR_SIZE"); return 1; }
Tchar getch(void) { int k; Tchar i, j; g0: if (ch) { i = ch; if (cbits(i) == '\n') nlflg++; ch = 0; return(i); } if (nlflg) return('\n'); i = getch0(); if (ismot(i)) return(i); k = cbits(i); if (k >= sizeof(gchtab)/sizeof(gchtab[0]) || gchtab[k] == 0) /* nothing special */ return(i); if (k != ESC) { if (k == '\n') { nlflg++; if (ip == 0) numtabp[CD].val++; /* line number */ return(k); } if (k == FLSS) { copyf++; raw++; i = getch0(); if (!fi) flss = i; copyf--; raw--; goto g0; } if (k == RPT) { setrpt(); goto g0; } if (!copyf) { if (k == 'f' && lg && !lgf) { i = getlg(i); return(i); } if (k == fc || k == tabch || k == ldrch) { if ((i = setfield(k)) == 0) goto g0; else return(i); } if (k == '\b') { i = makem(-width(' ' | chbits)); return(i); } } return(i); } k = cbits(j = getch0()); if (ismot(j)) return(j); switch (k) { case 'n': /* number register */ setn(); goto g0; case '$': /* argument indicator */ seta(); goto g0; case '*': /* string indicator */ setstr(); goto g0; case '{': /* LEFT */ i = LEFT; goto gx; case '}': /* RIGHT */ i = RIGHT; goto gx; case '"': /* comment */ while (cbits(i = getch0()) != '\n') ; if (ip == 0) numtabp[CD].val++; /* line number */ nlflg++; return(i); /* experiment: put it here instead of copy mode */ case '(': /* special char name \(xx */ case 'C': /* \C'...' */ if ((i = setch(k)) == 0) goto g0; goto gx; case ESC: /* double backslash */ i = eschar; goto gx; case 'e': /* printable version of current eschar */ i = PRESC; goto gx; case '\n': /* concealed newline */ numtabp[CD].val++; goto g0; case ' ': /* unpaddable space */ i = UNPAD; goto gx; case '\'': /* \(aa */ i = ACUTE; goto gx; case '`': /* \(ga */ i = GRAVE; goto gx; case '_': /* \(ul */ i = UNDERLINE; goto gx; case '-': /* current font minus */ i = MINUS; goto gx; case '&': /* filler */ i = FILLER; goto gx; case 'c': /* to be continued */ i = CONT; goto gx; case '!': /* transparent indicator */ i = XPAR; goto gx; case 't': /* tab */ i = '\t'; return(i); case 'a': /* leader (SOH) */ /* old: *pbp++ = LEADER; goto g0; */ i = LEADER; return i; case '%': /* ohc */ i = OHC; return(i); case 'g': /* return format of a number register */ setaf(); /* should this really be in copy mode??? */ goto g0; case '.': /* . */ i = '.'; gx: setsfbits(i, sfbits(j)); return(i); } if (copyf) { *pbp++ = j; return(eschar); } switch (k) { case 'f': /* font indicator */ setfont(0); goto g0; case 's': /* size indicator */ setps(); goto g0; case 'v': /* vert mot */ numerr.type = numerr.escarg = 0; numerr.esc = k; if (i = vmot()) { return(i); } goto g0; case 'h': /* horiz mot */ numerr.type = numerr.escarg = 0; numerr.esc = k; if (i = hmot()) return(i); goto g0; case '|': /* narrow space */ if (NROFF) goto g0; return(makem((int)(EM)/6)); case '^': /* half narrow space */ if (NROFF) goto g0; return(makem((int)(EM)/12)); case 'w': /* width function */ setwd(); goto g0; case 'p': /* spread */ spread++; goto g0; case 'N': /* absolute character number */ numerr.type = numerr.escarg = 0; numerr.esc = k; if ((i = setabs()) == 0) goto g0; return i; case 'H': /* character height */ numerr.type = numerr.escarg = 0; numerr.esc = k; return(setht()); case 'S': /* slant */ numerr.type = numerr.escarg = 0; numerr.esc = k; return(setslant()); case 'z': /* zero with char */ return(setz()); case 'l': /* hor line */ numerr.type = numerr.escarg = 0; numerr.esc = k; setline(); goto g0; case 'L': /* vert line */ numerr.type = numerr.escarg = 0; numerr.esc = k; setvline(); goto g0; case 'D': /* drawing function */ numerr.type = numerr.escarg = 0; numerr.esc = k; setdraw(); goto g0; case 'X': /* \X'...' for copy through */ setxon(); goto g0; case 'b': /* bracket */ setbra(); goto g0; case 'o': /* overstrike */ setov(); goto g0; case 'k': /* mark hor place */ if ((k = findr(getsn())) != -1) { numtabp[k].val = numtabp[HP].val; } goto g0; case '0': /* number space */ return(makem(width('0' | chbits))); case 'x': /* extra line space */ numerr.type = numerr.escarg = 0; numerr.esc = k; if (i = xlss()) return(i); goto g0; case 'u': /* half em up */ case 'r': /* full em up */ case 'd': /* half em down */ return(sethl(k)); default: return(j); } /* NOTREACHED */ }
int main(int argc, char **argv) { int envc; /* environment argument count */ char **envv; /* environment argument list */ FILE *names; /* name file pointer */ int oldnum; /* number in old cross-ref */ char path[PATHLEN + 1]; /* file path */ FILE *oldrefs; /* old cross-reference file */ char *s; int c, i; pid_t pid; /* save the command name for messages */ argv0 = basename(argv[0]); /* get the current directory for build() and line-oriented P command */ if (mygetwd(currentdir) == NULL) { (void) fprintf(stderr, "cscope: warning: cannot get current directory name\n"); (void) strcpy(currentdir, "<unknown>"); } /* initialize any view path; (saves time since currendir is known) */ vpinit(currentdir); dbvpndirs = vpndirs; /* number of directories in database view path */ /* directories (including current) in database view path */ dbvpdirs = vpdirs; /* the first source directory is the current directory */ sourcedir("."); /* read the environment */ editor = mygetenv("EDITOR", EDITOR); editor = mygetenv("VIEWER", editor); /* use viewer if set */ home = getenv("HOME"); shell = mygetenv("SHELL", SHELL); tmpdir = mygetenv("TMPDIR", TMPDIR); /* increment nesting depth */ cscopedepth = atoi(mygetenv("CSCOPEDEPTH", "0")); (void) sprintf(path, "CSCOPEDEPTH=%d", ++cscopedepth); (void) putenv(stralloc(path)); if ((s = getenv("CSCOPEOPTIONS")) != NULL) { /* parse the environment option string */ envc = 1; envv = mymalloc(sizeof (char *)); s = strtok(stralloc(s), OPTSEPS); while (s != NULL) { envv = myrealloc(envv, ++envc * sizeof (char *)); envv[envc - 1] = stralloc(s); s = strtok((char *)NULL, OPTSEPS); } /* set the environment options */ options(envc, envv); } /* set the command line options */ options(argc, argv); /* create the temporary file names */ pid = getpid(); (void) sprintf(temp1, "%s/cscope%d.1", tmpdir, (int)pid); (void) sprintf(temp2, "%s/cscope%d.2", tmpdir, (int)pid); /* if running in the foreground */ if (signal(SIGINT, SIG_IGN) != SIG_IGN) { /* cleanup on the interrupt and quit signals */ (void) signal(SIGINT, myexit); (void) signal(SIGQUIT, myexit); } /* cleanup on the hangup signal */ (void) signal(SIGHUP, myexit); /* if the database path is relative and it can't be created */ if (reffile[0] != '/' && access(".", WRITE) != 0) { /* if the database may not be up-to-date or can't be read */ (void) sprintf(path, "%s/%s", home, reffile); if (isuptodate == NO || access(reffile, READ) != 0) { /* put it in the home directory */ reffile = stralloc(path); (void) sprintf(path, "%s/%s", home, invname); invname = stralloc(path); (void) sprintf(path, "%s/%s", home, invpost); invpost = stralloc(path); (void) fprintf(stderr, "cscope: symbol database will be %s\n", reffile); } } /* if the cross-reference is to be considered up-to-date */ if (isuptodate == YES) { if ((oldrefs = vpfopen(reffile, "r")) == NULL) { cannotopen(reffile); exit(1); } /* * get the crossref file version but skip the current * directory */ if (fscanf(oldrefs, "cscope %d %*s", &fileversion) != 1) { (void) fprintf(stderr, "cscope: cannot read file version from file %s\n", reffile); exit(1); } if (fileversion >= 8) { /* override these command line options */ compress = YES; invertedindex = NO; /* see if there are options in the database */ for (;;) { /* no -q leaves multiple blanks */ while ((c = getc(oldrefs)) == ' ') { ; } if (c != '-') { (void) ungetc(c, oldrefs); break; } switch (c = getc(oldrefs)) { case 'c': /* ASCII characters only */ compress = NO; break; case 'q': /* quick search */ invertedindex = YES; (void) fscanf(oldrefs, "%ld", &totalterms); break; case 'T': /* truncate symbols to 8 characters */ dbtruncated = YES; truncatesyms = YES; break; } } initcompress(); /* seek to the trailer */ if (fscanf(oldrefs, "%ld", &traileroffset) != 1) { (void) fprintf(stderr, "cscope: cannot read trailer offset from " "file %s\n", reffile); exit(1); } if (fseek(oldrefs, traileroffset, 0) != 0) { (void) fprintf(stderr, "cscope: cannot seek to trailer in " "file %s\n", reffile); exit(1); } } /* * read the view path for use in converting relative paths to * full paths * * note: don't overwrite vp[n]dirs because this can cause * the wrong database index files to be found in the viewpath */ if (fileversion >= 13) { if (fscanf(oldrefs, "%d", &dbvpndirs) != 1) { (void) fprintf(stderr, "cscope: cannot read view path size from " "file %s\n", reffile); exit(1); } if (dbvpndirs > 0) { dbvpdirs = mymalloc( dbvpndirs * sizeof (char *)); for (i = 0; i < dbvpndirs; ++i) { if (fscanf(oldrefs, "%s", path) != 1) { (void) fprintf(stderr, "cscope: cannot read view " "path from file %s\n", reffile); exit(1); } dbvpdirs[i] = stralloc(path); } } } /* skip the source and include directory lists */ skiplist(oldrefs); skiplist(oldrefs); /* get the number of source files */ if (fscanf(oldrefs, "%d", &nsrcfiles) != 1) { (void) fprintf(stderr, "cscope: cannot read source file size from " "file %s\n", reffile); exit(1); } /* get the source file list */ srcfiles = mymalloc(nsrcfiles * sizeof (char *)); if (fileversion >= 9) { /* allocate the string space */ if (fscanf(oldrefs, "%d", &oldnum) != 1) { (void) fprintf(stderr, "cscope: cannot read string space size " "from file %s\n", reffile); exit(1); } s = mymalloc(oldnum); (void) getc(oldrefs); /* skip the newline */ /* read the strings */ if (fread(s, oldnum, 1, oldrefs) != 1) { (void) fprintf(stderr, "cscope: cannot read source file names " "from file %s\n", reffile); exit(1); } /* change newlines to nulls */ for (i = 0; i < nsrcfiles; ++i) { srcfiles[i] = s; for (++s; *s != '\n'; ++s) { ; } *s = '\0'; ++s; } /* if there is a file of source file names */ if (namefile != NULL && (names = vpfopen(namefile, "r")) != NULL || (names = vpfopen(NAMEFILE, "r")) != NULL) { /* read any -p option from it */ while (fscanf(names, "%s", path) == 1 && *path == '-') { i = path[1]; s = path + 2; /* for "-Ipath" */ if (*s == '\0') { /* if "-I path" */ (void) fscanf(names, "%s", path); s = path; } switch (i) { case 'p': /* file path components */ /* to display */ if (*s < '0' || *s > '9') { (void) fprintf(stderr, "cscope: -p option " "in file %s: " "missing or " "invalid numeric " "value\n", namefile); } dispcomponents = atoi(s); } } (void) fclose(names); } } else { for (i = 0; i < nsrcfiles; ++i) { if (fscanf(oldrefs, "%s", path) != 1) { (void) fprintf(stderr, "cscope: cannot read source file " "name from file %s\n", reffile); exit(1); } srcfiles[i] = stralloc(path); } } (void) fclose(oldrefs); } else { /* get source directories from the environment */ if ((s = getenv("SOURCEDIRS")) != NULL) { sourcedir(s); } /* make the source file list */ srcfiles = mymalloc(msrcfiles * sizeof (char *)); makefilelist(); if (nsrcfiles == 0) { (void) fprintf(stderr, "cscope: no source files found\n"); printusage(); exit(1); } /* get include directories from the environment */ if ((s = getenv("INCLUDEDIRS")) != NULL) { includedir(s); } /* add /usr/include to the #include directory list */ includedir("/usr/include"); /* initialize the C keyword table */ initsymtab(); /* create the file name(s) used for a new cross-reference */ (void) strcpy(path, reffile); s = basename(path); *s = '\0'; (void) strcat(path, "n"); ++s; (void) strcpy(s, basename(reffile)); newreffile = stralloc(path); (void) strcpy(s, basename(invname)); newinvname = stralloc(path); (void) strcpy(s, basename(invpost)); newinvpost = stralloc(path); /* build the cross-reference */ initcompress(); build(); if (buildonly == YES) { exit(0); } } opendatabase(); /* * removing a database will not release the disk space if a cscope * process has the file open, so a project may want unattended cscope * processes to exit overnight, including their subshells and editors */ if (noacttime) { (void) signal(SIGALRM, timedout); (void) alarm(noacttime); } /* * if using the line oriented user interface so cscope can be a * subprocess to emacs or samuel */ if (linemode == YES) { if (*pattern != '\0') { /* do any optional search */ if (search() == YES) { while ((c = getc(refsfound)) != EOF) { (void) putchar(c); } } } if (onesearch == YES) { myexit(0); } for (;;) { char buf[PATLEN + 2]; if (noacttime) { (void) alarm(noacttime); } (void) printf(">> "); (void) fflush(stdout); if (fgets(buf, sizeof (buf), stdin) == NULL) { myexit(0); } /* remove any trailing newline character */ if (*(s = buf + strlen(buf) - 1) == '\n') { *s = '\0'; } switch (*buf) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* samuel only */ field = *buf - '0'; (void) strcpy(pattern, buf + 1); (void) search(); (void) printf("cscope: %d lines\n", totallines); while ((c = getc(refsfound)) != EOF) { (void) putchar(c); } break; case 'c': /* toggle caseless mode */ case ctrl('C'): if (caseless == NO) { caseless = YES; } else { caseless = NO; } egrepcaseless(caseless); break; case 'r': /* rebuild database cscope style */ case ctrl('R'): freefilelist(); makefilelist(); /* FALLTHROUGH */ case 'R': /* rebuild database samuel style */ rebuild(); (void) putchar('\n'); break; case 'C': /* clear file names */ freefilelist(); (void) putchar('\n'); break; case 'F': /* add a file name */ (void) strcpy(path, buf + 1); if (infilelist(path) == NO && vpaccess(path, READ) == 0) { addsrcfile(path); } (void) putchar('\n'); break; case 'P': /* print the path to the files */ if (prependpath != NULL) { (void) puts(prependpath); } else { (void) puts(currentdir); } break; case 'q': /* quit */ case ctrl('D'): case ctrl('Z'): myexit(0); default: (void) fprintf(stderr, "cscope: unknown command '%s'\n", buf); break; } } /* NOTREACHED */ } /* pause before clearing the screen if there have been error messages */ if (errorsfound == YES) { errorsfound = NO; askforreturn(); } (void) signal(SIGINT, SIG_IGN); /* ignore interrupts */ (void) signal(SIGPIPE, SIG_IGN); /* | command can cause pipe signal */ /* initialize the curses display package */ (void) initscr(); /* initialize the screen */ setfield(); /* set the initial cursor position */ entercurses(); (void) keypad(stdscr, TRUE); /* enable the keypad */ dispinit(); /* initialize display parameters */ putmsg(""); /* clear any build progress message */ display(); /* display the version number and input fields */ /* do any optional search */ if (*pattern != '\0') { atfield(); /* move to the input field */ (void) command(ctrl('A')); /* search */ display(); /* update the display */ } else if (reflines != NULL) { /* read any symbol reference lines file */ (void) readrefs(reflines); display(); /* update the display */ } for (;;) { if (noacttime) { (void) alarm(noacttime); } atfield(); /* move to the input field */ /* exit if the quit command is entered */ if ((c = mygetch()) == EOF || c == ctrl('D') || c == ctrl('Z')) { break; } /* execute the commmand, updating the display if necessary */ if (command(c) == YES) { display(); } } /* cleanup and exit */ myexit(0); /* NOTREACHED */ return (0); }
int main (int argc, char* argv[]) { lua_State* L = luaL_newstate(); luaL_openlibs(L); lua_pushstring(L,TOLUA_VERSION); lua_setglobal(L,"TOLUA_VERSION"); if (argc==1) { help(); return 0; } else { int i, t; lua_newtable(L); lua_pushvalue(L,-1); lua_setglobal(L,"flags"); t = lua_gettop(L); for (i=1; i<argc; ++i) { if (*argv[i] == '-') { switch (argv[i][1]) { case 'v': version(); return 0; case 'h': help(); return 0; case 'p': setfield(L,t,"p",""); break; case 'P': setfield(L,t,"P",""); break; case 'o': setfield(L,t,"o",argv[++i]); break; case 'n': setfield(L,t,"n",argv[++i]); break; case 'H': setfield(L,t,"H",argv[++i]); break; default: error(argv[i]); break; } } else { setfield(L,t,"f",argv[i]); break; } } lua_pop(L,1); } #ifndef LUA_SOURCE { tolua_tolua_open(L); } #else { char* p; char path[BUFSIZ]; strcpy(path,argv[0]); p = strrchr(path,'/'); if (p==NULL) p = strrchr(path,'\\'); p = (p==NULL) ? path : p+1; sprintf(p,"%s","../src/bin/lua/"); lua_pushstring(L,path); lua_setglobal(L,"path"); strcat(path,"all.lua"); if (luaL_dofile(L,path)) { printf("error loading all.lua: %s\n",lua_tostring(L,-1)); return 1; } } #endif return 0; }
BOOL command(int commandc) { char filename[PATHLEN + 1]; /* file path name */ MOUSEEVENT *p; /* mouse data */ int c, i; FILE *file; HISTORY *curritem, *item; /* command history */ char *s; switch (commandc) { case ctrl('C'): /* toggle caseless mode */ if (caseless == NO) { caseless = YES; putmsg2("Caseless mode is now ON"); } else { caseless = NO; putmsg2("Caseless mode is now OFF"); } egrepcaseless(caseless); /* turn on/off -i flag */ return (NO); case ctrl('R'): /* rebuild the cross reference */ if (isuptodate == YES) { putmsg("The -d option prevents rebuilding the " "symbol database"); return (NO); } exitcurses(); freefilelist(); /* remake the source file list */ makefilelist(); rebuild(); if (errorsfound == YES) { errorsfound = NO; askforreturn(); } entercurses(); putmsg(""); /* clear any previous message */ totallines = 0; topline = nextline = 1; break; case ctrl('X'): /* mouse selection */ if ((p = getmouseevent()) == NULL) { return (NO); /* unknown control sequence */ } /* if the button number is a scrollbar tag */ if (p->button == '0') { scrollbar(p); break; } /* ignore a sweep */ if (p->x2 >= 0) { return (NO); } /* if this is a line selection */ if (p->y1 < FLDLINE) { /* find the selected line */ /* note: the selection is forced into range */ for (i = disprefs - 1; i > 0; --i) { if (p->y1 >= displine[i]) { break; } } /* display it in the file with the editor */ editref(i); } else { /* this is an input field selection */ field = mouseselection(p, FLDLINE, FIELDS); setfield(); resetcmd(); return (NO); } break; case '\t': /* go to next input field */ case '\n': case '\r': case ctrl('N'): case KEY_DOWN: case KEY_ENTER: case KEY_RIGHT: field = (field + 1) % FIELDS; setfield(); resetcmd(); return (NO); case ctrl('P'): /* go to previous input field */ case KEY_UP: case KEY_LEFT: field = (field + (FIELDS - 1)) % FIELDS; setfield(); resetcmd(); return (NO); case KEY_HOME: /* go to first input field */ field = 0; setfield(); resetcmd(); return (NO); case KEY_LL: /* go to last input field */ field = FIELDS - 1; setfield(); resetcmd(); return (NO); case ' ': /* display next page */ case '+': case ctrl('V'): case KEY_NPAGE: /* don't redisplay if there are no lines */ if (totallines == 0) { return (NO); } /* * note: seekline() is not used to move to the next * page because display() leaves the file pointer at * the next page to optimize paging forward */ break; case '-': /* display previous page */ case KEY_PPAGE: /* don't redisplay if there are no lines */ if (totallines == 0) { return (NO); } i = topline; /* save the current top line */ nextline = topline; /* go back to this page */ /* if on first page but not at beginning, go to beginning */ if (nextline > 1 && nextline <= mdisprefs) { nextline = 1; } else { /* go back the maximum displayable lines */ nextline -= mdisprefs; /* if this was the first page, go to the last page */ if (nextline < 1) { nextline = totallines - mdisprefs + 1; if (nextline < 1) { nextline = 1; } /* old top is past last line */ i = totallines + 1; } } /* * move down til the bottom line is just before the * previous top line */ c = nextline; for (;;) { seekline(nextline); display(); if (i - bottomline <= 0) { break; } nextline = ++c; } return (NO); /* display already up to date */ case '>': /* write or append the lines to a file */ if (totallines == 0) { putmsg("There are no lines to write to a file"); } else { /* get the file name */ (void) move(PRLINE, 0); (void) addstr("Write to file: "); s = "w"; if ((c = mygetch()) == '>') { (void) move(PRLINE, 0); (void) addstr(appendprompt); c = '\0'; s = "a"; } if (c != '\r' && c != '\n' && c != KEY_ENTER && c != KEY_BREAK && getaline(newpat, COLS - sizeof (appendprompt), c, NO) > 0) { shellpath(filename, sizeof (filename), newpat); if ((file = fopen(filename, s)) == NULL) { cannotopen(filename); } else { seekline(1); while ((c = getc(refsfound)) != EOF) { (void) putc(c, file); } seekline(topline); (void) fclose(file); } } clearprompt(); } return (NO); /* return to the previous field */ case '<': /* read lines from a file */ (void) move(PRLINE, 0); (void) addstr(readprompt); if (getaline(newpat, COLS - sizeof (readprompt), '\0', NO) > 0) { clearprompt(); shellpath(filename, sizeof (filename), newpat); if (readrefs(filename) == NO) { putmsg2("Ignoring an empty file"); return (NO); } return (YES); } clearprompt(); return (NO); case '^': /* pipe the lines through a shell command */ case '|': /* pipe the lines to a shell command */ if (totallines == 0) { putmsg("There are no lines to pipe to a shell command"); return (NO); } /* get the shell command */ (void) move(PRLINE, 0); (void) addstr(pipeprompt); if (getaline(newpat, COLS - sizeof (pipeprompt), '\0', NO) == 0) { clearprompt(); return (NO); } /* if the ^ command, redirect output to a temp file */ if (commandc == '^') { (void) strcat(strcat(newpat, " >"), temp2); } exitcurses(); if ((file = mypopen(newpat, "w")) == NULL) { (void) fprintf(stderr, "cscope: cannot open pipe to shell command: %s\n", newpat); } else { seekline(1); while ((c = getc(refsfound)) != EOF) { (void) putc(c, file); } seekline(topline); (void) mypclose(file); } if (commandc == '^') { if (readrefs(temp2) == NO) { putmsg("Ignoring empty output of ^ command"); } } askforreturn(); entercurses(); break; case ctrl('L'): /* redraw screen */ case KEY_CLEAR: (void) clearok(curscr, TRUE); (void) wrefresh(curscr); drawscrollbar(topline, bottomline, totallines); return (NO); case '!': /* shell escape */ (void) execute(shell, shell, (char *)NULL); seekline(topline); break; case '?': /* help */ (void) clear(); help(); (void) clear(); seekline(topline); break; case ctrl('E'): /* edit all lines */ editall(); break; case ctrl('A'): /* repeat last pattern */ case ctrl('Y'): /* (old command) */ if (*pattern != '\0') { (void) addstr(pattern); goto repeat; } break; case ctrl('B'): /* cmd history back */ case ctrl('F'): /* cmd history fwd */ curritem = currentcmd(); item = (commandc == ctrl('F')) ? nextcmd() : prevcmd(); clearmsg2(); if (curritem == item) { /* inform user that we're at history end */ putmsg2( "End of input field and search pattern history"); } if (item) { field = item->field; setfield(); atfield(); (void) addstr(item->text); (void) strcpy(pattern, item->text); switch (c = mygetch()) { case '\r': case '\n': case KEY_ENTER: goto repeat; default: ungetch(c); atfield(); (void) clrtoeol(); /* clear current field */ break; } } return (NO); case '\\': /* next character is not a command */ (void) addch('\\'); /* display the quote character */ /* get a character from the terminal */ if ((commandc = mygetch()) == EOF) { return (NO); /* quit */ } (void) addstr("\b \b"); /* erase the quote character */ goto ispat; case '.': atfield(); /* move back to the input field */ /* FALLTHROUGH */ default: /* edit a selected line */ if (isdigit(commandc) && commandc != '0' && !mouse) { if (returnrequired == NO) { editref(commandc - '1'); } else { (void) move(PRLINE, 0); (void) addstr(selectionprompt); if (getaline(newpat, COLS - sizeof (selectionprompt), commandc, NO) > 0 && (i = atoi(newpat)) > 0) { editref(i - 1); } clearprompt(); } } else if (isprint(commandc)) { /* this is the start of a pattern */ ispat: if (getaline(newpat, COLS - fldcolumn - 1, commandc, caseless) > 0) { (void) strcpy(pattern, newpat); resetcmd(); /* reset history */ repeat: addcmd(field, pattern); /* add to history */ if (field == CHANGE) { /* prompt for the new text */ (void) move(PRLINE, 0); (void) addstr(toprompt); (void) getaline(newpat, COLS - sizeof (toprompt), '\0', NO); } /* search for the pattern */ if (search() == YES) { switch (field) { case DEFINITION: case FILENAME: if (totallines > 1) { break; } topline = 1; editref(0); break; case CHANGE: return (changestring()); } } else if (field == FILENAME && access(newpat, READ) == 0) { /* try to edit the file anyway */ edit(newpat, "1"); } } else { /* no pattern--the input was erased */ return (NO); } } else { /* control character */ return (NO); } } return (YES); }
EVENT UIAPI uivfieldedit( VSCREEN *vptr, VFIELDEDIT *header ) /************************************************************/ { register EVENT ev; register VFIELD* cur; auto VBUFFER buffer; auto SAREA area; if( header->reset ) { header->reset = false; header->prevfield = NULL; header->curfield = NULL; header->cursor = true; area.height = 1; for( cur = header->fieldlist ; cur != NULL ; cur = cur->link ) { area.row = cur->row; area.col = cur->col; area.width = cur->length; uivattribute( vptr, area, header->exit ); } } if( header->cursor ) { header->cursor = false; header->delpending = false; header->fieldpending = false; header->cancel = false; if( vptr->cursor == C_OFF ) { vptr->cursor = C_NORMAL; } return( movecursor( vptr, header, vptr->row, vptr->col ) ); } if( header->fieldpending ) { header->update = true; if( header->cancel ) { header->cancel = false; header->curfield = NULL; setfield( vptr, header, header->prevfield, 0 ); } header->fieldpending = false; } cur = header->curfield; if( header->update ) { header->update = false; if( cur ) { /* this should always be non-NULL */ uipadblanks( header->buffer, cur->length ); if( header->delpending ) { buffer.content = header->buffer; buffer.length = cur->length; buffer.index = vptr->col - cur->col; uieditevent( EV_DELETE, &buffer ); header->dirty = true; header->delpending = false; } uivtextput( vptr, cur->row, cur->col, header->enter, header->buffer, cur->length ); } } if( header->oktomodify ) { uipushlist( livefieldevents ); } else { uipushlist( deadfieldevents ); } ev = uivgetevent( vptr ); if( ev > EV_NO_EVENT ) { if( uiintoplist( ev ) ) { if( cur ) { buffer.content = header->buffer; buffer.length = cur->length; buffer.index = vptr->col - cur->col; buffer.insert = ( vptr->cursor == C_INSERT ); buffer.dirty = false; uieditevent( ev, &buffer ); header->dirty |= buffer.dirty; } switch( ev ) { case EV_HOME: if( cur != NULL ) break; /* home is within field */ /* WARNING: this case falls through to the next */ case EV_TAB_FORWARD: case EV_TAB_BACKWARD: cur = tabfield( vptr, header->fieldlist, ev == EV_TAB_FORWARD ); /* WARNING: the EV_HOME case falls through */ if( cur != NULL ) { ev = setfield( vptr, header, cur, 0 ); cur = NULL; /* kludge - avoid calling movecursor */ } break; case EV_INSERT: if( vptr->cursor == C_INSERT ) { vptr->cursor = C_NORMAL ; } else { vptr->cursor = C_INSERT ; } break; case EV_CURSOR_UP: ev = movecursor( vptr, header, vptr->row - 1, vptr->col ); break; case EV_CURSOR_DOWN: ev = movecursor( vptr, header, vptr->row + 1, vptr->col ); break; case EV_RUB_OUT: header->delpending = true; /* WARNING: this case falls through to the next !!!! */ case EV_CURSOR_LEFT: if( cur ) { if( vptr->col > cur->col ) { break; /* cursor movement within field */ } } ev = movecursor( vptr, header, vptr->row, vptr->col - 1 ); break; case EV_CURSOR_RIGHT: case ' ': if( header->curfield ) { if( vptr->col < cur->col + cur->length - 1 ) { break; /* cursor movement within field */ } } ev = movecursor( vptr, header, vptr->row, vptr->col + 1 ); break; } if( ev != EV_FIELD_CHANGE ) { if( cur ) { ev = movecursor( vptr, header, vptr->row, cur->col + buffer.index ); if( buffer.dirty && ( ev == EV_NO_EVENT ) ) { uivtextput( vptr, cur->row, cur->col, header->enter, header->buffer, cur->length ); } } else { ev = EV_NO_EVENT; } header->delpending = false; } } } uipoplist(); return( ev ); }
int main (int argc, char* argv[]) { lua_State* L = lua_open(0); lua_baselibopen(L); lua_iolibopen(L); lua_strlibopen(L); lua_pushstring(L,TOLUA_VERSION); lua_setglobal(L,"TOLUA_VERSION"); if (argc==1) { help(); return 0; } else { int i, t; lua_newtable(L); lua_pushvalue(L,-1); lua_setglobal(L,"flags"); t = lua_gettop(L); for (i=1; i<argc; ++i) { if (*argv[i] == '-') { switch (argv[i][1]) { case 'v': version(); return 0; case 'h': help(); return 0; case 'p': setfield(L,t,"p",""); break; case 'P': setfield(L,t,"P",""); break; case 'o': setfield(L,t,"o",argv[++i]); break; case 'n': setfield(L,t,"n",argv[++i]); break; case 'H': setfield(L,t,"H",argv[++i]); break; default: error(argv[i]); break; } } else { setfield(L,t,"f",argv[i]); break; } } lua_pop(L,1); } #if 1 { int tolua_tolualua_open(lua_State* L); tolua_tolualua_open(L); } #else { int i; char* p; char path[BUFSIZ]; char* files[] = { "basic.lua", "feature.lua", "verbatim.lua", "code.lua", "typedef.lua", "container.lua", "package.lua", "module.lua", "define.lua", "enumerate.lua", "declaration.lua", "variable.lua", "array.lua", "function.lua", "operator.lua", "class.lua", "clean.lua", "doit.lua", NULL }; strcpy(path,argv[0]); p = strrchr(path,'/'); p = (p==NULL) ? path : p+1; for (i=0; files[i]; ++i) { sprintf(p,"%s",files[i]); lua_dofile(L,path); } } #endif return 0; }