void *nice_input(char *t, char *p, char *d) { int x1=0,y1=0,x2=79,y2=25; bar(x1,y1+1,x2,y2,176,0x01); put_title(t); box(x1,(y1+y2)/2-1,x2,(y1+y2)/2+1,0x17); bar(x1+1,(y1+y2)/2,x2-1,(y1+y2)/2,' ',0x17); put_string(x1+1,(y1+y2)/2,p,0x17); bar (x1+1+strlen(p)+1,(y1+y2)/2,x2-1,(y1+y2)/2,' ',0x0f); put_string(x1+1+strlen(p)+1,(y1+y2)/2,d,0x70); set_cursor(x1+1+strlen(p)+1,(y1+y2)/2); while (!_bios_keybrd(_KEYBRD_READY)); if (_bios_keybrd(_KEYBRD_READY)==7181) { getch(); cls(); char ln[100]; strcpy(ln,d); // d might get collect in next new return new_lisp_string(ln); } else { bar (x1+1+strlen(p)+1,(y1+y2)/2,x2-1,(y1+y2)/2,' ',0x0f); int key; char ln[100]; ln[0]=0; do { key=getch(); if (key==8 && ln[0]) { ln[strlen(ln)-1]=0; bar(x1+1+strlen(p)+1,(y1+y2)/2,x2-1,(y1+y2)/2,' ',0x0f); put_string(x1+1+strlen(p)+1,(y1+y2)/2,ln,0x0f); } else if (isprint(key)) { ln[strlen(ln)+1]=0; ln[strlen(ln)]=key; put_string(x1+1+strlen(p)+1,(y1+y2)/2,ln,0x0f); } set_cursor(x1+1+strlen(p)+1+strlen(ln),(y1+y2)/2); } while (key!=13 && key!=27); cls(); if (key==27) return NULL; return new_lisp_string(ln); } }
int nice_copy(char *title, char *source, char *dest) { int x1=0,y1=0,x2=79,y2=25; bar(x1,y1+1,x2,y2,176,0x01); put_title(title); box(x1,(y1+y2)/2-1,x2,(y1+y2)/2+3,0x17); bar(x1+1,(y1+y2)/2,x2-1,(y1+y2)/2+2,' ',0x17); char msg[100]; sprintf(msg,"Copying %s -> %s",source,dest); put_string(x1+1,(y1+y2)/2,msg,0x17); bar(x1+1,(y1+y2)/2+2,x2-1,(y1+y2)/2+2,176,0x17); char *buffer=(char *)jmalloc(0xf000,"read buf"); if (!buffer) return 0; FILE *out=fopen(dest,"wb"); if (!out) { jfree(buffer) ; return 0; } FILE *in=fopen(source,"rb"); if (!in) { jfree(buffer); fclose(out); unlink(dest); return 0; } fseek(in,0,SEEK_END); long size=ftell(in); fseek(in,0,SEEK_SET); int osize=size; while (size) { long tr=fread(buffer,1,0xf000,in); bar(x1+1,(y1+y2)/2+2,x1+1+(x2-x1)*(osize-size-tr)/osize,(y1+y2)/2+2,178,0x17); if (fwrite(buffer,1,tr,out)!=tr) { fclose(out); fclose(in); unlink(dest); jfree(buffer); return 0; } size-=tr; } fclose(in); fclose(out); jfree(buffer); cls(); return 1; }
void *show_yes_no(void *t, void *msg, void *y, void *n) { p_ref r1(t),r2(msg),r3(y),r4(n); y=eval(y); n=eval(n); put_title(lstring_value(eval(t))); int x1=0,y1=0,x2=79,y2=25; bar(x1,y1+1,x2,y2,176,0x01); center_tbox(eval(msg),0x1f); int key; char *yes=lstring_value(y); char *no=lstring_value(n); set_cursor(0,25); do { key=getch(); set_cursor(0,0); } while (toupper(key)!=toupper(yes[0]) && toupper(key)!=toupper(no[0])); cls(); if (toupper(key)==toupper(yes[0])) return true_symbol; else return NULL; }
int main (int argc, char * const argv[]) { PROG = "aa-start"; const char *path_repo = "/run/services"; const char *path_list = NULL; int i; aa_secs_timeout = DEFAULT_TIMEOUT_SECS; for (;;) { struct option longopts[] = { { "double-output", no_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { "listdir", required_argument, NULL, 'l' }, { "dry-list", no_argument, NULL, 'n' }, { "repodir", required_argument, NULL, 'r' }, { "timeout", required_argument, NULL, 't' }, { "version", no_argument, NULL, 'V' }, { "verbose", no_argument, NULL, 'v' }, { "no-wants", no_argument, NULL, 'W' }, { NULL, 0, 0, 0 } }; int c; c = getopt_long (argc, argv, "Dhl:nr:t:VvW", longopts, NULL); if (c == -1) break; switch (c) { case 'D': aa_set_double_output (1); break; case 'h': dieusage (0); case 'l': unslash (optarg); path_list = optarg; break; case 'n': if (mode & AA_MODE_IS_DRY) mode |= AA_MODE_IS_DRY_FULL; else mode |= AA_MODE_IS_DRY; break; case 'r': unslash (optarg); path_repo = optarg; break; case 't': if (!uint0_scan (optarg, &aa_secs_timeout)) aa_strerr_diefu2sys (ERR_IO, "set default timeout to ", optarg); break; case 'V': aa_die_version (); case 'v': verbose = 1; break; case 'W': no_wants = 1; break; default: dieusage (1); } } argc -= optind; argv += optind; cols = get_cols (1); is_utf8 = is_locale_utf8 (); if (!path_list && argc < 1) dieusage (1); if (aa_init_repo (path_repo, (mode & AA_MODE_IS_DRY) ? AA_REPO_READ : AA_REPO_WRITE) < 0) aa_strerr_diefu2sys (ERR_IO, "init repository ", path_repo); if (path_list) { stralloc sa = STRALLOC_ZERO; int r; if (*path_list != '/' && *path_list != '.') stralloc_cats (&sa, LISTDIR_PREFIX); stralloc_catb (&sa, path_list, strlen (path_list) + 1); r = aa_scan_dir (&sa, 1, it_start, NULL); stralloc_free (&sa); if (r < 0) aa_strerr_diefu3sys (-r, "read list directory ", (*path_list != '/' && *path_list != '.') ? LISTDIR_PREFIX : path_list, (*path_list != '/' && *path_list != '.') ? path_list : ""); } tain_now_g (); for (i = 0; i < argc; ++i) if (str_equal (argv[i], "-")) { if (process_names_from_stdin ((names_cb) add_service, NULL) < 0) aa_strerr_diefu1sys (ERR_IO, "process names from stdin"); } else add_service (argv[i], NULL); mainloop (mode, scan_cb); if (!(mode & AA_MODE_IS_DRY)) { aa_bs_noflush (AA_OUT, "\n"); put_title (1, PROG, "Completed.", 1); aa_show_stat_nb (nb_already, "Already up", ANSI_HIGHLIGHT_GREEN_ON); aa_show_stat_nb (nb_done, "Started", ANSI_HIGHLIGHT_GREEN_ON); show_stat_service_names (&ga_timedout, "Timed out", ANSI_HIGHLIGHT_RED_ON); show_stat_service_names (&ga_failed, "Failed", ANSI_HIGHLIGHT_RED_ON); show_stat_service_names (&ga_depend, "Dependency failed", ANSI_HIGHLIGHT_RED_ON); aa_show_stat_names (aa_names.s, &ga_io, "I/O error", ANSI_HIGHLIGHT_RED_ON); aa_show_stat_names (aa_names.s, &ga_unknown, "Unknown", ANSI_HIGHLIGHT_RED_ON); aa_show_stat_names (aa_names.s, &ga_skipped, "Skipped", ANSI_HIGHLIGHT_YELLOW_ON); } genalloc_free (int, &ga_timedout); genalloc_free (int, &ga_failed); genalloc_free (int, &ga_depend); genalloc_free (size_t, &ga_io); genalloc_free (size_t, &ga_unknown); genalloc_free (size_t, &ga_skipped); genalloc_free (pid_t, &ga_pid); genalloc_free (int, &aa_tmp_list); genalloc_free (int, &aa_main_list); stralloc_free (&aa_names); genalloc_deepfree (struct progress, &ga_progress, free_progress); aa_free_services (close_fd); genalloc_free (iopause_fd, &ga_iop); return rc; }
static int add_service (const char *name, void *data) { int si = -1; int type; int r; type = aa_get_service (name, &si, 1); if (type < 0) r = type; else r = aa_mark_service (mode, si, type == AA_SERVICE_FROM_MAIN, no_wants, autoload_cb); if (r < 0) { if (r == -ERR_UNKNOWN) { put_err_service (name, ERR_UNKNOWN, 1); add_name_to_ga (name, &ga_unknown); } else if (r == -ERR_IO) { /* ERR_IO from aa_get_service() means we don't have a si (it is * actually set to the return value); but from aa_mark_service() * (e.g. to read "needs") then we do */ if (si < 0) { put_err_service (name, ERR_IO, 1); add_name_to_ga (name, &ga_io); } else { int e = errno; put_err_service (name, ERR_IO, 0); add_err (": "); add_err (strerror (e)); end_err (); add_to_list (&ga_failed, si, 0); check_essential (si); } } else if (r == -ERR_ALREADY_UP) { if (!(mode & AA_MODE_IS_DRY)) put_title (1, name, errmsg[-r], 1); ++nb_already; r = 0; } else { aa_service *s = aa_service (si); const char *msg = aa_service_status_get_msg (&s->st); int has_msg; has_msg = s->st.event == AA_EVT_ERROR && s->st.code == -r && !!msg; put_err_service (name, -r, !has_msg); if (has_msg) { add_err (": "); add_err (msg); end_err (); } add_to_list ((r == -ERR_DEPEND) ? &ga_depend : &ga_failed, si, 0); check_essential (si); } } else r = 0; return r; }
void *nice_menu(void *main_title, void *menu_title, void *list) { int x1=0,y1=0,x2=79,y2=25; p_ref r1(main_title),r2(menu_title),r3(list); main_title=eval(main_title); menu_title=eval(menu_title); char *t=lstring_value(main_title); put_title(t); bar(x1,y1+1,x2,y2,176,0x01); void *l=eval(list); p_ref r4(l); int menu_height=list_length(l),menu_length=0; void *m; for (m=l;m;m=CDR(m)) { long l=strlen(lstring_value(CAR(m))); if (l>menu_length) menu_length=l; } char *mt=lstring_value(menu_title); if (strlen(mt)>menu_length) menu_length=strlen(mt); int mx=(x2+x1)/2-menu_length/2-1,my=(y2+y1)/2-menu_height/2-2; box(mx,my,mx+menu_length+2,my+menu_height+3,0x17); bar(mx+1,my+1,mx+menu_length+1,my+menu_height+2,' ',0x17); put_string(mx+1+menu_length/2-strlen(mt)/2,my,mt,0x1f); // draw menu title set_cursor(0,25); int cur_sel=0; int key; do { int y=0; for (m=l;m;m=CDR(m),y++) { char *s=lstring_value(CAR(m)); if (y==cur_sel) { bar(mx+1,my+2+y,mx+1+menu_length,my+2+y,' ',0x0f); put_string(mx+1+menu_length/2-strlen(s)/2,my+2+y,s,0x0f); } else { bar(mx+1,my+2+y,mx+1+menu_length,my+2+y,' ',0x1f); put_string(mx+1+menu_length/2-strlen(s)/2,my+2+y,s,0x1f); } } key=_bios_keybrd(_KEYBRD_READ); if (key==18432) { cur_sel--; if (cur_sel==-1) cur_sel=menu_height-1; } if (key==20480) { cur_sel++; if (cur_sel==menu_height) cur_sel=0; } } while (key!=283 && key!=7181); cls(); if (key==283) return new_lisp_number(-1); return new_lisp_number(cur_sel); }
FUNCTION CODE hard_help ( struct SFILE *fctx, /* In: file context block for opened file */ TEXT curlib[], /* In: library name of opened file */ TEXT procname[], /* In: proc name for LHS of help display */ TEXT outname[], /* In: name of output file */ struct HELPBLK *helpblk /* out: help output control block */ ) { IMPORT struct VARIABLE *char_gbl; /* system characteristics */ struct DIRBLK dirblk; /* directive control block */ struct TXTSTOR title; /* context for dynamically stored title text */ struct SFILE f; struct POSCTX saved_pos; struct POSCTX level2_pos; BOOL has_level2; TEXT str[STRINGSIZ+1]; CODE code; TEXT field[STRINGSIZ+1]; /* text field after a directive */ TEXT name[STRINGSIZ+1]; TEXT key[KEYSIZ+1]; TEXT msg[STRINGSIZ+1]; /* If no output name was given, */ if (NULLSTR(outname)) /* use pdf or command name */ { f_name(procname, outname); s_append(".MEM", outname); /* procname.MEM for output */ } /* note -- SAVELUN is safe because |save| qual is not allowed for this command */ code = f_ophf(&f, SAVELUN, outname, F_WRITE); /* open output file */ if (code != SUCCESS) { sprintf(msg, "Error opening output, host code = %d", f.host_code); store_help_error(helpblk, msg, "TAE-OPNWRT"); return(FAIL); } d_init(&dirblk, fctx, curlib, (TEXT **)(*char_gbl).v_cvp, (*char_gbl).v_count); /* init directive block */ if ((*helpblk).compiled) /* if PDF is compiled */ { if ((code = prep_c_help(&dirblk, &title, msg, key)) != SUCCESS) /* prepare*/ goto put_error; str[0] = EOS; } else /* PDF is not compiled */ { code = d_dirctv(&dirblk, str, field); if (s_equal(str, ".TITLE")) { /* read the title into dynamic store */ if ((code = gettitle(&dirblk, &title, msg, key))!= SUCCESS) goto put_error; code = d_dirctv(&dirblk, str, field); } else /* no title */ { title.numline = 0; } } code = put_title(&f, &title, msg, key); /* start filling output file */ if (code != SUCCESS) goto put_error; if (title.tp != NULL) fretxt(&title); /* free the dyamically-stored title */ /* str should contain .HELP directive now. If not, find it */ if (! s_equal( str, ".HELP")) { code = d_search(&dirblk, ".HELP", field); if (code != SUCCESS) { store_help_error(helpblk, "No help available on '%s'.", "TAE-NOHELP"); return (FAIL); } } code = put_text_block(&f, &dirblk, msg, key); /* output general help */ if (code != SUCCESS) goto put_error; code = d_search(&dirblk, ".LEVEL1", field); if (code != SUCCESS) /* if there is no level1 help then */ goto return_success; /* assume we are done and exit */ f_movpos(CURRENT_POS, &saved_pos); /* save position in input */ code = d_search(&dirblk, ".LEVEL2", field); /* find detailed help */ has_level2 = (code == SUCCESS); if (has_level2) /* if detailed help exists, */ f_movpos(CURRENT_POS, &level2_pos); /* save the position in file */ f_setpos(dirblk.sfileptr, &saved_pos); /* reset position to curr pos */ code = d_dirctv(&dirblk, str, name); /* gives str=".TITLE" */ while (1) { code = d_dirctv(&dirblk, str, name); if (code != SUCCESS) /* if no more directives, we */ break; /* are done */ if (s_equal(str, ".END") || s_equal(str, ".LEVEL2")) /* done */ break; code = put_header(&f, &dirblk, str, name, msg, key); if (code != SUCCESS) goto put_error; if (has_level2) code = put_level2_text(&f, &dirblk, &level2_pos, str, name, msg, key); if (code != SUCCESS) goto put_error; } return_success: f_close(&f, F_KEEP); s_lower(outname); sprintf(msg, "Wrote file \"%s\".", outname); put_stdout(msg); return (SUCCESS); put_error: store_help_error(helpblk, msg, key); return (FAIL); }