int main() { unsigned int adc; float vol; int n; copy_vec(); irq_init(); button_init(); uart0_init(); timer_init(); // timer4_init(); lcd_init(); lcd_clean(0xffff); adc_ts_init(); ts_init(); while(1); while(1) { adc = read_adc(0); vol = adc * 3.3 / 0x3ff; n = (vol - (int)vol) * 1000; printf("AIN0: adc = %u voltage:%d.%03d\r\n", adc, (int)vol, n); delayms(1000); } return 0; }
int main(int argc, char** argv){ int retval = 0; int i, Navg; param_obj param; kw_obj kw; ts_obj ts; vsip_mview_f *dtaIn, *gramOut; if(retval += param_read(argv[1],¶m)){ printf("Failed to read parameter file\n"); exit(-1); } param_log(¶m); kw_init(&kw, ¶m); ts_init(&ts, ¶m); /* simulate time series and beamform */ Navg = (int) param.Navg; dtaIn = ts_instance(&ts); gramOut = kw_instance(&kw); kw_zero(&kw); for(i=0; i<Navg; i++){ ts_zero(&ts); ts_sim_noise(&ts); ts_sim_nb(&ts); komega(&kw,dtaIn); } /* beamform done. Gram should be in gramOut */ /*************/ /* Massage gram data and save to file for plotting */ for(i=0; i<vsip_mgetrowlength_f(gramOut); i++) {/* move zero to middle */ vsip_vview_f *v = vsip_mcolview_f(gramOut, i); vsip_vfreqswap_f(v); vsip_vdestroy_f(v); } {/* massage the data for plot*/ vsip_scalar_f max = vsip_mmaxval_f(gramOut, NULL),min; vsip_scalar_f avg = vsip_mmeanval_f(gramOut); vsip_mclip_f(gramOut,0.0, max, avg/100000.0, max, gramOut); vsip_mlog10_f(gramOut,gramOut); min = -vsip_mminval_f(gramOut, NULL); vsip_smadd_f(min, gramOut, gramOut); max = vsip_mmaxval_f(gramOut, NULL); vsip_smmul_f(1.0/max, gramOut, gramOut); } { /* output data and plot with octave */ FILE *fptr = fopen("gramOut","w"); size_t size = vsip_mgetrowlength_f(gramOut) * vsip_mgetcollength_f(gramOut); vsip_scalar_f *out = (vsip_scalar_f*)malloc(size * sizeof(vsip_scalar_f)); vsip_mcopyto_user_f(gramOut, VSIP_COL, out); fwrite(out,size,sizeof(vsip_scalar_f),fptr); fclose(fptr); free(out); } /* cleanup */ kw_fin(&kw); ts_fin(&ts); param_free(¶m); return retval; }
static void init(void) { options_init(); comm_init(); tl_init(); ts_init(); ti_init(); sb_init(); tl_show(); // others... }
int main(int argc, char *argv[]) { int rc = ts_init(); if (rc == -1) return 1; /* parse arguments */ switch (ts_options_process(&tss.opts, argc, argv)) { case TS_MODE_USAGE: ts_options_free(&tss.opts); return ts_options_usage(); case TS_MODE_VERSION: ts_options_free(&tss.opts); return 0; case TS_MODE_CREATE: break; } /* load configuration file */ rc = ts_config_load(&tss.opts); if (rc == -1) goto done; /* create spaces */ rc = ts_space_init(&tss.s); if (rc == -1) goto done; rc = ts_space_fill(&tss.s, &tss.opts); if (rc == -1) goto done; printf("work_dir: %s\n", tss.opts.cfg.work_dir); printf("snap_dir: %s\n", tss.opts.cfg.snap_dir); printf("wal_dir: %s\n", tss.opts.cfg.wal_dir); printf("spaces: %d\n", mh_size(tss.s.t)); /* indexate snapshot and xlog data */ rc = ts_indexate(); if (rc == -1) goto done; /* write snapshot */ rc = ts_snapshot_create(); if (rc == -1) goto done; printf("complete.\n"); done: ts_free(); return (rc == -1 ? 1 : 0); }
int tsload_init(struct subsystem* xsubsys, unsigned xs_count) { struct subsystem** subsys_list = NULL; unsigned s_count = sizeof(subsys) / sizeof(struct subsystem); int si, xsi; /* Mempool is not yet initialized, so use libc; freed by ts_finish */ subsys_list = malloc((s_count + xs_count) * sizeof(struct subsystem*)); /* Initialize [0:s_count] subsystems with tsload's subsystems * and [s_count:s_count+xs_count] with extended subsystems */ for(si = 0; si < s_count; ++si) subsys_list[si] = &subsys[si]; for(xsi = 0; xsi < xs_count; ++si, ++xsi) subsys_list[si] = &xsubsys[xsi]; return ts_init(subsys_list, s_count + xs_count); }
void xfs_init(libxfs_init_t *args) { memset(args, 0, sizeof(libxfs_init_t)); if (isa_file) { args->disfile = 1; args->dname = fs_name; args->volname = NULL; } else { args->disfile = 0; args->volname = fs_name; args->dname = NULL; } if (log_spec) { /* External log specified */ args->logname = log_name; args->lisfile = (isa_file?1:0); /* XXX assume data file also means log file */ /* REVISIT: Need to do fs sanity / log validity checking */ } if (rt_spec) { /* RT device specified */ args->rtname = rt_name; args->risfile = (isa_file?1:0); /* XXX assume data file also means rt file */ } args->usebuflock = do_prefetch; args->setblksize = 0; args->isdirect = LIBXFS_DIRECT; if (no_modify) args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE); else if (dangerously) args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY); else args->isreadonly = LIBXFS_EXCLUSIVELY; if (!libxfs_init(args)) do_error(_("couldn't initialize XFS library\n")); ts_create(); ts_init(); increase_rlimit(); pftrace_init(); }
int main() { copy_vec(); irq_init(); button_init(); uart0_init(); timer_init(); // timer4_init(); lcd_init(); lcd_clean(0xffff); adc_ts_init(); ts_init(); // tslib_calibrate(); // lcd_clean(0xffff); nand_init(); #if 1 nand_read_id(); while(1); #endif printf("\r\n\n"); printf("===============================================\r\n"); printf(" NAND FLASH PROGRAMMING \r\n"); unsigned int size = 512 * 1024; // 512KB nand_read_id(); printf("erase entire flash, waiting ... \r\n"); int i; for(i = 0; i < 2048; i++) nand_erase_block(i); printf("start program ... \r\n"); nand_write_bytes(0x0, (unsigned char *)0x31000000, size); printf("program end ... \r\n"); printf("===============================================\r\n"); while(1); return 0; }
void flang_init() { memset(fl_on_error_jmp, 0, sizeof(jmp_buf)); // reset error state ast_last_error_message = 0; ast_last_error_node = 0; pool_init(2048); st_replace_allocators(pool_new, pool_realloc_fix_string, pool_free); hash_replace_allocators(pool_new, pool_realloc, pool_free); array_replace_allocators(pool_new, pool_realloc, pool_free); identifiers = malloc(sizeof(array)); array_new(identifiers); ast_dump_file = stdout; ts_init(); }
void brd_driver_init(){ #ifdef CFG_DRV_CON_UART con_uart_init(); #endif #ifdef CFG_DRV_CON_TELNET con_telnet_init(); #endif #ifdef CFG_DRV_SDI sd_init(); #endif #ifdef CFG_DRV_LCD lcd_init(); #endif #ifdef CFG_DRV_TS ts_init(); #endif #ifdef CFG_DRV_NET_DM9000 dm9000_init(); #endif }
void bcr_initBarcodeReader(void) { EncoderInit(); MotorDir(FWD,FWD); FrontLED(ON); lineCounter = 0; rawCounter = 0; latestLineData = 0; unsigned int tmp[2]; util_getStableLineData(tmp); tolFactor = getToleranceValue(tmp[LEFT] + tmp[RIGHT]); int i; util_pauseInterrupts(); for(i = 0; i < (M_RAW_DATAPOINTS * M_WINDOW_SIZE); i++) { measureDataPoint(); Msleep(5); } ts_init(); ts_addFunction(&measureDataPoint, M_SAMPLING_FREQ); sei(); }
int main(int argc, char *argv[]) { int ret; struct tsdev *ts; lua_State *L; myfb = myfb_open(); set_vfb_buf(1); ts = ts_init(); L = luaL_newstate(); luaL_openlibs(L); lua_register(L, "SET_COUNT", lua_set_icon_count); lua_register(L, "SET_ICON", lua_set_icon_info); lua_register(L, "SET_CMD", lua_set_cmd_list); lua_register(L, "SET_BGCOLOR", lua_set_bgcolor); lua_register(L, "SET_BGIMAGE", lua_set_bgimage); luaL_dofile(L, file_ui); lua_close(L); while (1) { int c, da_count, old_da_count, pid, state = 0; struct ts_sample samp; struct icon *i; struct cmd_list *j; da_count = get_DeviceAttached(); if (!da_count) da_count = 0; if (!old_da_count) old_da_count = da_count; else { if (old_da_count != da_count) { clear_screen(); put_string_center(myfb->fbvar.xres/2, myfb->fbvar.yres/2 - 10, "Attached Info is changed!", white); put_string_center(myfb->fbvar.xres/2, myfb->fbvar.yres/2 + 10, "Touch the screen!", white); old_da_count = da_count; ret = ts_read(ts, &samp, 1); continue; } } set_bgimage(); set_bgcolor(); for (c=0; c<=da_count; c++) draw_block(myfb->fbvar.xres-12*c-12, 3); if (head == NULL) { put_string_center(myfb->fbvar.xres/2, myfb->fbvar.yres/2, "Sorry, No Apps. registered!", white); #ifdef DEBUG fprintf(stderr, "No Apps!\n"); #endif break; } for (i=head; i != NULL; i=i->next) draw_icon(i); ret = ts_read(ts, &samp, 1); if (ret < 0) { perror("ts_read"); continue; } if (ret != 1) continue; if (samp.x > 310 && samp.y >230) break; for (i=head, j=cmdlist; i != NULL; i=i->next, j=j->next) { if (icon_handle(i, &samp) > 0) { if (chat_count < 20) continue; chat_count = 0; pid = fork(); if (pid == 0) { #ifdef DEBUG fprintf(stderr, " *** This is CHILD! ***\n"); #endif if (j) ret = execl(j->path, j->args, 0); if (ret < 0) { perror("execl"); exit(1); } } else { sleep(1); wait(&state); no_count = 0; put_string_center(myfb->fbvar.xres/2, myfb->fbvar.yres/2, "End of Program!", white); #ifdef DEBUG fprintf(stderr, " *** End of CHILD! ***\n"); #endif } } } } clear_screen(); put_string_center(myfb->fbvar.xres/2, myfb->fbvar.yres/2, "Thanks for Use!", white); free_icon(); free_cmd(); ts_close(ts); free_vfb_buf(1); myfb_close(); return 0; }
int My_boot_main() { //unsigned char buff[2048]; int num; #ifdef MMU_ON mmu_init(); #endif led_init(); button_init(); init_irq(); uart_init(); ts_init(); //lcd_init(); //lcd_test(); dm9000_init(); while(1) { printf("\n**********************************************\n\r"); printf("\n*******************My-boot********************\n\r"); printf("[1], Download Linux Kernel from TFTP Server!\n\r"); printf("[2], Boot Linux from RAM!\n\r"); printf("[3], Boot Linux from Nand Flash\n\r"); printf("\n Please Select:"); int num; scanf("%d", &num); switch (num) { case 1: //tftp_load(); tftp_send_request("start.o"); break; case 2: //boot_linux_ram(); //arp_request(); boot_linux(); break; case 3: //boot_linux_nand(); arp_request(); break; default: printf("Error: wrong selection!\n\r"); break; } return 0; } }
int main(int argc,char **argv) { int ret; pthread_t view_id; pid_t view_pid=0,audio_pid=0; // LCD 初始化 fb_init(); // 触摸屏初始化 ts_init(); // 显示一张启动logo show_jpglogo("./image/welcome.jpg"); sleep(3); // 显示控制主界面菜单 show_menu(); ret = pthread_create(&view_id, NULL,picview_thread, NULL); if(ret == -1) goto pthread_create_err; while(1) { // 等待获取坐标 pthread_mutex_lock(&mutex); printf(" main get lock!\n"); m = get_motion(); printf(" main put lock!\n"); pthread_mutex_unlock(&mutex); usleep(1000); switch(m) { case button1: printf("button1 Prev\n"); if(audio_pid != 0) kill(audio_pid,SIGKILL); audio_pid = start_audio(BACKWARD); //kill(view_pid,SIGUSR1); break; case button2: printf("button2 Next\n"); if(audio_pid != 0) kill(audio_pid,SIGKILL); audio_pid = start_audio(FORWARD); //kill(view_pid,SIGUSR2); break; case button3: printf("button3 Stop\n"); kill(audio_pid,SIGSTOP); //kill(view_pid,SIGSTOP); break; case button4: printf("button4 Continue\n"); kill(audio_pid,SIGCONT); //kill(view_pid,SIGCONT); break; case button5: printf("button5 Load\n"); traverse_file_dir("/photo/dir"); //view_pid = start_picview(); signal(SIGCHLD,waitp); break; } } fb_uninit(); ts_uninit(); return 0; pthread_create_err: printf(" pthread_create err!\n"); return -1; }
DH_FILE * dh_open(char path[]) { DH_FILE * dh_file = NULL; FILE_ENTRY * fptr; char filename[MAX_PATHNAME_LEN+1]; char pathname[MAX_PATHNAME_LEN+1]; short int i; char * p; struct DH_HEADER header; struct DH_AK_HEADER ak_header; char * ibuff = NULL; short int file_id = -1; OSFILE fu = INVALID_FILE_HANDLE; /* Primary subfile */ OSFILE ofu = INVALID_FILE_HANDLE; /* Overflow subfile */ int bytes; unsigned long int ak_map; short int no_of_subfiles; short int no_of_aks; bool read_only = FALSE; DESCRIPTOR * descr; int n; int subfile; long int ak_node_num; OBJECT_HEADER * obj; struct stat statbuf; unsigned long int device = 0; unsigned long int inode = 0; dh_err = 0; process.os_error = 0; /* Validate file name */ p = strrchr(path, DS); /* Find final directory separator */ if (p == NULL) p = path; if ((*p == '\0') /* Null name in last component */ || !fullpath(filename, path)) /* Unable to map to absolute pathname */ { dh_err = DHE_FILE_NOT_FOUND; goto exit_dh_open; } /* Check if this file is already open to this process */ if (stat(filename, &statbuf) != 0) { dh_err = DHE_FILE_NOT_FOUND; goto exit_dh_open; } device = statbuf.st_dev; inode = statbuf.st_ino; for (dh_file = dh_file_head; dh_file != NULL; dh_file = dh_file->next_file) { fptr = FPtr(dh_file->file_id); if ((device == 0) && (inode == 0)) /* Compare by name */ { if (strcmp((char *)(fptr->pathname), filename) != 0) continue; } else { if ((fptr->device != device) || (fptr->inode != inode)) continue; } /* Found a match */ if (fptr->ref_ct < 0) /* Already open for exclusive access */ { dh_err = DHE_EXCLUSIVE; goto exit_dh_open; } dh_file->open_count++; goto exit_dh_open; } /* Open primary subfile */ sprintf(pathname, "%s%c~0", filename, DS); if (access(pathname, 2)) read_only = TRUE; fu = dio_open(pathname, (read_only)?DIO_READ:DIO_UPDATE); if (!ValidFileHandle(fu)) { dh_err = DHE_FILE_NOT_FOUND; goto exit_dh_open; } /* Validate primary subfile header */ if (Read(fu, (char *)(&header), DH_HEADER_SIZE) < 0) { dh_err = DHE_READ_ERROR; process.os_error = OSError; goto exit_dh_open; } switch(header.magic) { case DH_PRIMARY: if (header.hash) { dh_err = DHE_HASH_TYPE; goto exit_dh_open; } break; default: dh_err = DHE_PSFH_FAULT; goto exit_dh_open; } if ((header.flags & DHF_TRUSTED) /* Access requires trusted status */ && (!(process.program.flags & HDR_IS_TRUSTED))) { dh_err = DHE_TRUSTED; goto exit_dh_open; } /* !!FILE_VERSION!! */ if (header.file_version > DH_VERSION) { dh_err = DHE_VERSION; goto exit_dh_open; } /* Check if this file may contain a record id longer than the maximum we can support. The longest_id element of the DH_PARAMS structure is set to the length of the longest id written to the file. This record may not be there anymore. QMFix will sort this out. */ if ((header.file_version > 0) && (header.params.longest_id > sysseg->maxidlen)) { dh_err = DHE_ID_LEN; goto exit_dh_open; } /* Open overflow subfile */ sprintf(pathname, "%s%c~1", filename, DS); if (access(pathname, 2)) read_only = TRUE; ofu = dio_open(pathname, (read_only)?DIO_READ:DIO_UPDATE); if (!ValidFileHandle(ofu)) { dh_err = DHE_FILE_NOT_FOUND; goto exit_dh_open; } /* Allocate new DH_FILE structure AKs use subfile numbers from AK_BASE_SUBFILE upwards, based on position in the AK map. Because AKs can be deleted, there may be gaps in the numbering. At this stage, simply find the highest used AK number so that we know how big the data structures need to be. We will go through the map again once we have created the AK data array. */ no_of_aks = 0; for(i = 0, ak_map = header.ak_map; i < MAX_INDICES; i++, ak_map = ak_map >> 1) { if (ak_map & 1) no_of_aks = i + 1; /* Not really - There may be gaps */ } no_of_subfiles = AK_BASE_SUBFILE + no_of_aks; bytes = sizeof(struct DH_FILE) + (sizeof(struct SUBFILE_INFO) * (no_of_subfiles - 1)); dh_file = (DH_FILE *)k_alloc(9,bytes); if (dh_file == NULL) { dh_err = DHE_OPEN_NO_MEMORY; goto exit_dh_open; } for (i = 0; i < no_of_subfiles; i++) dh_file->sf[i].fu = INVALID_FILE_HANDLE; dh_file->file_version = header.file_version; dh_file->header_bytes = DHHeaderSize(header.file_version, header.group_size); dh_file->ak_header_bytes = AKHeaderSize(header.file_version); dh_file->group_size = header.group_size; dh_file->no_of_subfiles = no_of_subfiles; dh_file->open_count = 1; dh_file->flags = 0; dh_file->ak_map = header.ak_map; dh_file->trigger_name = NULL; dh_file->trigger = NULL; dh_file->trigger_modes = 0; if (read_only) dh_file->flags |= DHF_RDONLY; /* Read only */ if (header.akpath[0] == '\0') dh_file->akpath = NULL; else { dh_file->akpath = (char *)k_alloc(106, strlen(header.akpath) + 1); strcpy(dh_file->akpath, header.akpath); } /* Transfer file units into DH_FILE structure so that we do not have to open them again on the first access. */ dh_set_subfile(dh_file, PRIMARY_SUBFILE, fu); fu = INVALID_FILE_HANDLE; dh_set_subfile(dh_file, OVERFLOW_SUBFILE, ofu); ofu = INVALID_FILE_HANDLE; /* Load trigger function, if any */ if (header.trigger_name[0] != '\0') { dh_file->trigger_name = (char *)k_alloc(69,strlen(header.trigger_name) + 1); /* 0259 */ strcpy(dh_file->trigger_name, header.trigger_name); /* Attempt to snap link to trigger function */ obj = (OBJECT_HEADER *)load_object(header.trigger_name, FALSE); if (obj != NULL) obj->ext_hdr.prog.refs += 1; dh_file->trigger = (u_char *)obj; dh_file->flags |= DHF_TRIGGER; /* Copy the trigger mode flags. If this file pre-dates the introduction of these flags, the byte will be zero. Set the defaults to be as they were for old versions of the system. */ if (header.trigger_modes) dh_file->trigger_modes = header.trigger_modes; else dh_file->trigger_modes = TRG_PRE_WRITE | TRG_PRE_DELETE; } /* Now process any AK indices */ if (no_of_aks) /* Has AK indices */ { dh_file->flags |= DHF_AK; /* Set up AK data matrix */ dh_file->ak_data = a_alloc(no_of_aks, AKD_COLS, TRUE); for(i = 0, ak_map = header.ak_map; i < no_of_aks; i++, ak_map = ak_map >> 1) { /* AK field name - Set as null string for now, filled in for used entries after we have validated the subfile. */ descr = Element(dh_file->ak_data, (i * AKD_COLS) + AKD_NAME); InitDescr(descr, STRING); descr->data.str.saddr = NULL; if (ak_map & 1) { /* Open AK subfile and validate header */ subfile = i + AK_BASE_SUBFILE; if (!dh_open_subfile(dh_file, filename, subfile, FALSE)) { dh_err = DHE_AK_NOT_FOUND; goto exit_dh_open; } if (!dh_read_group(dh_file, subfile, 0, (char *)(&ak_header), DH_AK_HEADER_SIZE)) { dh_err = DHE_AK_HDR_READ_ERROR; process.os_error = OSError; goto exit_dh_open; } if (ak_header.magic != DH_INDEX) { dh_err = DHE_AK_HDR_FAULT; goto exit_dh_open; } /* Cross-check the index subfile with the primary data subfile */ if (header.creation_timestamp != ak_header.data_creation_timestamp) { dh_err = DHE_AK_CROSS_CHECK; goto exit_dh_open; } /* Fill in AK name */ ts_init(&(descr->data.str.saddr), strlen(ak_header.ak_name)); ts_copy_c_string(ak_header.ak_name); (void)ts_terminate(); /* Field number */ descr = Element(dh_file->ak_data, (i * AKD_COLS) + AKD_FNO); InitDescr(descr, INTEGER); descr->data.value = ak_header.fno; /* Flags */ descr = Element(dh_file->ak_data, (i * AKD_COLS) + AKD_FLGS); InitDescr(descr, INTEGER); descr->data.value = ak_header.flags; /* I-type code */ descr = Element(dh_file->ak_data, (i * AKD_COLS) + AKD_OBJ); InitDescr(descr, STRING); descr->data.str.saddr = NULL; ts_init(&(descr->data.str.saddr), ak_header.itype_len); ak_node_num = GetAKFwdLink(dh_file, ak_header.itype_ptr); if (ak_node_num != 0) /* Long expression */ { /* Fetch I-type from separate node */ ibuff = (char *)k_alloc(53, DH_AK_NODE_SIZE); do { if (!dh_read_group(dh_file, subfile, ak_node_num, ibuff, DH_AK_NODE_SIZE)) { goto exit_dh_open; } n = ((DH_ITYPE_NODE *)ibuff)->used_bytes - offsetof(DH_ITYPE_NODE, data); ts_copy((char *)(((DH_ITYPE_NODE *)ibuff)->data), n); ak_node_num = GetAKFwdLink(dh_file, ((DH_ITYPE_NODE *)ibuff)->next); } while(ak_node_num); } else { ts_copy((char *)ak_header.itype, ak_header.itype_len); } (void)ts_terminate(); descr->data.str.saddr = s_make_contiguous(descr->data.str.saddr, NULL); /* Collation map name */ descr = Element(dh_file->ak_data, (i * AKD_COLS) + AKD_MAPNAME); InitDescr(descr, STRING); k_put_c_string(ak_header.collation_map_name, descr); /* Collation map (contiguous string) */ descr = Element(dh_file->ak_data, (i * AKD_COLS) + AKD_MAP); if (ak_header.collation_map_name[0] == '\0') { InitDescr(descr, STRING); descr->data.str.saddr = NULL; } else { k_put_string(ak_header.collation_map, 256, descr); } } } } else {
void op_ospath() { /* Stack: |================================|=============================| | BEFORE | AFTER | |================================|=============================| top | Key | Information | |--------------------------------|-----------------------------| | Pathname string | | |================================|=============================| Key values: Action Returns 0 OS_PATHNAME Test if valid pathname True/False 1 OS_FILENAME Test if valid filename True/False or directory file record name 2 OS_EXISTS Test if file exists True/False 3 OS_UNIQUE Make a unique file name Name 4 OS_FULLPATH Return full pathname Name 5 OS_DELETE Delete file Success/Failure 6 OS_CWD Get current working directory Pathname 7 OS_DTM Return date/time modified DTM value 8 OS_FLUSH_CACHE Flush DH file cache - 9 OS_CD Change working directory Success/Failure 10 OS_MAPPED_NAME Map a directory file name Mapped name 11 OS_OPEN Check if path is an open file True/False 12 OS_DIR Return content of directory Filenames 13 OS_MKDIR Make a directory True/False 14 OS_MKPATH Make a directory path True/False Pathnames with lengths outside the range 1 to MAX_PATHNAME_LEN return 0 regardless of the action key. */ long int status = 0; short int key; DESCRIPTOR * descr; char path[MAX_PATHNAME_LEN+1]; short int path_len; char name[MAX_PATHNAME_LEN+1]; char * p; char * q; STRING_CHUNK * head; int file_id; FILE_ENTRY * fptr; struct stat stat_buff; DIR * dfu; struct dirent * dp; long int n; /* Get action key */ descr = e_stack - 1; GetInt(descr); key = (short int)(descr->data.value); k_pop(1); /* Get pathname */ descr = e_stack - 1; path_len = k_get_c_string(descr, path, MAX_PATHNAME_LEN); k_dismiss(); if (path_len < 0) goto set_status; #ifdef CASE_INSENSITIVE_FILE_SYSTEM UpperCaseString(path); #endif switch(key) { case OS_PATHNAME: /* Test if valid pathname */ p = path; if (*p == '/') p++; do { q = strchr(p, '/'); if (q != NULL) *q = '\0'; if (!valid_name(p)) goto set_status; p = q + 1; } while(q != NULL); status = 1; break; case OS_FILENAME: /* Test if valid pathname */ status = (long int)valid_name(path); break; case OS_EXISTS: /* Test if file exists */ status = !access(path, 0); break; case OS_UNIQUE: /* Make unique file name. Path variable holds directory name */ n = (time(NULL) * 10) & 0xFFFFFFFL; do { sprintf(name, "%s\\D%07lX", path, n); n--; } while(!access(name, 0)); sprintf(name, "D%07lX", n); k_put_c_string(name, e_stack); e_stack++; goto exit_op_pathinfo; case OS_FULLPATH: /* Expand path to full OS pathname */ fullpath(name, path); k_put_c_string(name, e_stack); e_stack++; goto exit_op_pathinfo; case OS_DELETE: flush_dh_cache(); status = (long int)delete_path(path); break; case OS_CWD: (void)getcwd(name, MAX_PATHNAME_LEN); #ifdef CASE_INSENSITIVE_FILE_SYSTEM UpperCaseString(name); #endif k_put_c_string(name, e_stack); e_stack++; goto exit_op_pathinfo; case OS_DTM: if (stat(path, &stat_buff) == 0) status = stat_buff.st_mtime; break; case OS_FLUSH_CACHE: flush_dh_cache(); break; case OS_CD: status = attach(path); break; case OS_MAPPED_NAME: /* Map a directory file record name */ (void)map_t1_id(path, strlen(path), name); k_put_c_string(name, e_stack); e_stack++; goto exit_op_pathinfo; case OS_OPEN: fullpath(name, path); for(file_id = 1; file_id <= sysseg->used_files; file_id++) { fptr = FPtr(file_id); if ((fptr->ref_ct != 0) && (strcmp((char *)(fptr->pathname), name) == 0)) { status = TRUE; break; } } break; case OS_DIR: head = NULL; ts_init(&head, 1024); if ((dfu = opendir(path)) != NULL) { if (path[path_len-1] == DS) path[path_len-1] = '\0'; while((dp = readdir(dfu)) != NULL) { if (strcmp(dp->d_name, ".") == 0) continue; if (strcmp(dp->d_name, "..") == 0) continue; sprintf(name, "%s%c%s", path, DS, dp->d_name); if (stat(name, &stat_buff)) continue; strcpy(name+1, dp->d_name); #ifdef CASE_INSENSITIVE_FILE_SYSTEM UpperCaseString(name+1); #endif if (stat_buff.st_mode & S_IFDIR) { name[0] = 'D'; if (head != NULL) ts_copy_byte(FIELD_MARK); ts_copy_c_string(name); } else if (stat_buff.st_mode & S_IFREG) { name[0] = 'F'; if (head != NULL) ts_copy_byte(FIELD_MARK); ts_copy_c_string(name); } } closedir(dfu); } ts_terminate(); InitDescr(e_stack, STRING); (e_stack++)->data.str.saddr = head; goto exit_op_pathinfo; case OS_MKDIR: status = !MakeDirectory(path); break; case OS_MKPATH: status = make_path(path); break; default: k_error(sysmsg(1010)); } set_status: /* Set status value on stack */ InitDescr(e_stack, INTEGER); (e_stack++)->data.value = status; exit_op_pathinfo: return; }
Private STRING_CHUNK * get_file_status(FILE_VAR * fvar) { STRING_CHUNK * str = NULL; u_char ftype; DH_FILE * dh_file; SQ_FILE * sq_file; int64 file_size = 0; int file_type_num = 0; bool is_seq = FALSE; char * path; int64 n64; struct stat statbuf; memset(&statbuf, 0, sizeof(statbuf)); ftype = fvar->type; path = (char *)(FPtr(fvar->file_id)->pathname); /* !!FVAR_TYPES!! */ switch(ftype) { case DYNAMIC_FILE: file_type_num = FL_TYPE_DH; dh_file = fvar->access.dh.dh_file; FDS_open(dh_file, PRIMARY_SUBFILE); fstat(dh_file->sf[PRIMARY_SUBFILE].fu, &statbuf); file_size = dh_filesize(dh_file, PRIMARY_SUBFILE) + dh_filesize(dh_file, OVERFLOW_SUBFILE); break; case DIRECTORY_FILE: file_type_num = FL_TYPE_DIR; stat((char *)(FPtr(fvar->file_id)->pathname), &statbuf); file_size = dir_filesize(fvar); break; case SEQ_FILE: file_type_num = FL_TYPE_SEQ; is_seq = TRUE; sq_file = fvar->access.seq.sq_file; if (!(sq_file->flags & SQ_NOTFL)) fstat(sq_file->fu, &statbuf); file_size = statbuf.st_size; path = sq_file->pathname; break; } ts_init(&str, 128); /* 1 File position */ n64 = (is_seq)?sq_file->posn:0; ts_printf("%lld\xfe", n64); /* 2 At EOF? */ ts_printf("%d\xfe", (is_seq)?sq_file->posn == file_size:0); /* 3 Not used */ ts_printf("\xfe"); /* 4 Bytes available to read */ n64 = (is_seq)?(file_size - sq_file->posn):0; ts_printf("%lld\xfe", n64); /* 5 File mode */ ts_printf("%u\xfe", statbuf.st_mode & 0777); /* 6 File size */ ts_printf("%lld\xfe", file_size); /* 7 Hard links */ ts_printf("%d\xfe", statbuf.st_nlink); /* 8 UID of owner */ ts_printf("%d\xfe", statbuf.st_uid); /* 9 GID of owner */ ts_printf("%d\xfe", statbuf.st_gid); /* 10 Inode number */ ts_printf("%d\xfe", statbuf.st_ino); /* 11 Device number */ ts_printf("%d\xfe", statbuf.st_dev); /* 12 Not used */ ts_printf("\xfe"); /* 13 Time of last access */ ts_printf("%d\xfe", statbuf.st_atime % 86400); /* 14 Date of last access */ ts_printf("%d\xfe", (statbuf.st_atime / 86400) + 732); /* 15 Time of last modification */ ts_printf("%d\xfe", statbuf.st_mtime % 86400); /* 16 Date of last modification */ ts_printf("%d\xfe", (statbuf.st_mtime / 86400) + 732); /* 17 - 19 unused */ ts_printf("\xfe\xfe\xfe"); /* 20 Operating system file name */ ts_printf("%s\xfe", path); /* 21 File type */ ts_printf("%d", file_type_num); (void)ts_terminate(); return str; }
void op_field() { /* Stack: |=============================|=============================| | BEFORE | AFTER | |=============================|=============================| top | Number of fields | Substring | |-----------------------------|-----------------------------| | Occurrence number | | |-----------------------------|-----------------------------| | Delimiter | | |-----------------------------|-----------------------------| | Source string | | |=============================|=============================| */ DESCRIPTOR * descr; /* Various descriptors */ long int num_fields; long int occurrence; char delimiter; STRING_CHUNK * delim_str; DESCRIPTOR result_descr; /* Result string */ STRING_CHUNK * src_str; short int src_bytes_remaining; char * src; char * p; short int len; bool nocase; nocase = (process.program.flags & HDR_NOCASE) != 0; process.program.col1 = 0; process.program.col2 = 0; /* Get number of fields to return */ descr = e_stack - 1; GetInt(descr); num_fields = descr->data.value; if (num_fields < 1) num_fields = 1; /* Get start field position */ descr = e_stack - 2; GetInt(descr); occurrence = descr->data.value; if (occurrence < 1) occurrence = 1; k_pop(2); /* Get delimiter character */ descr = e_stack - 1; k_get_string(descr); if ((delim_str = descr->data.str.saddr) != NULL) { delimiter = delim_str->data[0]; if (nocase) delimiter = UpperCase(delimiter); } k_dismiss(); /* Get source string */ descr = e_stack - 1; k_get_string(descr); src_str = descr->data.str.saddr; if (src_str == NULL) goto exit_op_field; /* Return source string */ if (delim_str == NULL) /* Delimiter is null string */ { process.program.col2 = src_str->string_len + 1; goto exit_op_field; /* Return source string */ } /* Set up a string descriptor to receive the result */ InitDescr(&result_descr, STRING); result_descr.data.str.saddr = NULL; ts_init(&(result_descr.data.str.saddr), 32); /* Walk the string looking for the start of this item */ src = src_str->data; src_bytes_remaining = src_str->bytes; if (occurrence-- == 1) goto found_start; do { process.program.col1 += src_str->bytes; while(src_bytes_remaining) { if (nocase) { p = (char *)memichr(src, delimiter, src_bytes_remaining); } else { p = (char *)memchr(src, delimiter, src_bytes_remaining); } if (p == NULL) break; /* No delimiter in this chunk */ src_bytes_remaining -= (p - src) + 1; src = p + 1; if (--occurrence == 0) { process.program.col1 -= src_bytes_remaining; goto found_start; } } if ((src_str = src_str->next) == NULL) { process.program.col1 = 0; goto return_null_string; /* We did not find the desired field */ } src = src_str->data; src_bytes_remaining = src_str->bytes; } while(TRUE); found_start: /* We have found the start of the field and its offset is in col1. Now copy the specified number of fields to the result string. */ do { /* Look for delimiter in the current chunk */ while(src_bytes_remaining) { if (nocase) { p = (char *)memichr(src, delimiter, src_bytes_remaining); } else { p = (char *)memchr(src, delimiter, src_bytes_remaining); } if (p != NULL) /* Found delimiter */ { len = p - src; if (len) ts_copy(src, len); /* Copy up to delimiter */ src_bytes_remaining -= len + 1; src = p + 1; if (--num_fields == 0) goto found_end; ts_copy_byte(*p); /* Copy delimiter */ } else /* No delimiter - copy all to target */ { ts_copy(src, src_bytes_remaining); break; } } if ((src_str = src_str->next) == NULL) break; src = src_str->data; src_bytes_remaining = src_str->bytes; } while(1); found_end: process.program.col2 = process.program.col1 + ts_terminate() + 1; return_null_string: k_dismiss(); /* Dismiss source string */ *(e_stack++) = result_descr; exit_op_field: return; }
void op_extract() { /* Stack: |=============================|=============================| | BEFORE | AFTER | |=============================|=============================| top | Subvalue number | Substring | |-----------------------------|-----------------------------| | Value number | | |-----------------------------|-----------------------------| | Field number | | |-----------------------------|-----------------------------| | Source string | | |=============================|=============================| */ DESCRIPTOR * field_descr; /* Position descriptor */ DESCRIPTOR * value_descr; /* Position descriptor */ DESCRIPTOR * subvalue_descr; /* Position descriptor */ DESCRIPTOR * src_descr; /* Source string */ DESCRIPTOR result_descr; /* Result string */ long int field; long int value; long int subvalue; short int offset; STRING_CHUNK * str_hdr; short int bytes_remaining; short int len; char * p; char * q; bool end_on_value_mark; bool end_on_subvalue_mark; register char c; subvalue_descr = e_stack - 1; value_descr = e_stack - 2; field_descr = e_stack - 3; GetInt(subvalue_descr); subvalue = subvalue_descr->data.value; GetInt(value_descr); value = value_descr->data.value; GetInt(field_descr); field = field_descr->data.value; k_pop(3); /* Set up a string descriptor on our C stack to receive the result */ InitDescr(&result_descr, STRING); result_descr.data.str.saddr = NULL; ts_init(&result_descr.data.str.saddr, 32); if (field <= 0) /* Field zero or negative - Return null string */ { goto done; } else if (value == 0) /* Extracting field */ { end_on_value_mark = FALSE; end_on_subvalue_mark = FALSE; value = 1; subvalue = 1; } else if (subvalue == 0) /* Extracting value */ { end_on_value_mark = TRUE; end_on_subvalue_mark = FALSE; subvalue = 1; } else /* Extracting subvalue */ { end_on_value_mark = TRUE; end_on_subvalue_mark = TRUE; } src_descr = e_stack - 1; k_get_string(src_descr); str_hdr = src_descr->data.str.saddr; if (find_item(str_hdr, field, value, subvalue, &str_hdr, &offset)) { if (str_hdr == NULL) goto done; p = str_hdr->data + offset; bytes_remaining = str_hdr->bytes - offset; while(1) { /* Is there any data left in this chunk? */ if (bytes_remaining) { /* Look for delimiter in the current chunk */ for (q = p; bytes_remaining-- > 0; q++) { c = *q; if ((IsDelim(c)) && ((c == FIELD_MARK) || ((c == VALUE_MARK) && end_on_value_mark) || ((c == SUBVALUE_MARK) && end_on_subvalue_mark))) { /* Copy up to mark */ len = q - p; if (len > 0) ts_copy(p, len); goto done; } } /* Copy remainder of this chunk (must be at least one byte) */ ts_copy(p, q - p); } if ((str_hdr = str_hdr->next) == NULL) break; p = str_hdr->data; bytes_remaining = str_hdr->bytes; } } done: ts_terminate(); k_dismiss(); /* Dismiss source string ADDR */ *(e_stack++) = result_descr; }
Private void rdi( DESCRIPTOR * src_descr, /* Source string */ long int field, long int value, long int subvalue, short int mode, DESCRIPTOR * new_descr, /* Replacement / insertion string */ DESCRIPTOR * result_descr, /* Resultant string */ bool compatible) /* Append style ($MODE COMPATIBLE.APPEND) */ { long int f, v, sv; STRING_CHUNK * str_hdr; short int bytes_remaining; STRING_CHUNK * new_str; short int len; char * p; bool done; char c; char mark; bool mark_skipped = FALSE; bool end_on_value_mark; bool end_on_subvalue_mark; bool item_found; char last_char = '\0'; str_hdr = src_descr->data.str.saddr; /* Set up a string descriptor to receive the result */ InitDescr(result_descr, STRING); result_descr->data.str.saddr = NULL; ts_init(&(result_descr->data.str.saddr), (str_hdr == NULL)?64:str_hdr->string_len); if (field == 0) field = 1; if (value == 0) /* <n, 0, 0> */ { end_on_value_mark = FALSE; end_on_subvalue_mark = FALSE; value = 1; subvalue = 1; mark = FIELD_MARK; } else if (subvalue == 0) /* <n, n, 0> */ { end_on_value_mark = TRUE; end_on_subvalue_mark = FALSE; subvalue = 1; mark = VALUE_MARK; } else /* <n, n, n> */ { end_on_value_mark = TRUE; end_on_subvalue_mark = TRUE; mark = SUBVALUE_MARK; } f = 1; v = 1; sv = 1; /* Current position */ bytes_remaining = 0; /* For null string path */ /* Copy to start of selected item */ if ((field == 1) && (value == 1) && (subvalue == 1)) { /* <1,0,0> or <1,1,0> or <1,1,1> */ if (str_hdr != NULL) { p = str_hdr->data; bytes_remaining = str_hdr->bytes; } item_found = TRUE; goto found; } /* Walk the string to the desired item */ if (str_hdr != NULL) { do { p = str_hdr->data; bytes_remaining = str_hdr->bytes; do { c = *p; if (IsDelim(c)) { switch(c) { case FIELD_MARK: if (f == field) goto not_found; /* No such value or subvalue */ f++; v = 1; sv = 1; break; case VALUE_MARK: if ((f == field) && (v == value)) { goto not_found; /* No such subvalue */ } v++; sv = 1; break; case SUBVALUE_MARK: sv++; break; } if ((f == field) && (v == value) && (sv == subvalue)) { p++; bytes_remaining--; item_found = TRUE; goto found; /* At start position */ } } last_char = c; p++; } while(--bytes_remaining); /* Copy all of source chunk just searched */ ts_copy(str_hdr->data, str_hdr->bytes); } while((str_hdr = str_hdr->next) != NULL); } /* We have reached the end of the string without finding the field we were looking for. */ not_found: found: if (str_hdr != NULL) /* Not run off end of string */ { /* Copy up to current position in source chunk */ len = p - str_hdr->data; if ((mode == DYN_DELETE) && (len > 0) && (c == mark)) /* Don't copy this mark */ { mark_skipped = TRUE; len--; } if (len > 0) ts_copy(str_hdr->data, len); /* Skip old data if we are doing REPLACE or DELETE */ if (item_found) { switch(mode) { case DYN_REPLACE: case DYN_DELETE: done = FALSE; /* Skip old item */ do { /* Is there any data left in this chunk? */ if (bytes_remaining > 0) { /* Look for delimiter in the current chunk */ do { c = *p; if ((IsDelim(c)) && ((c == FIELD_MARK) || ((c == VALUE_MARK) && end_on_value_mark) || ((c == SUBVALUE_MARK) && end_on_subvalue_mark))) { done = TRUE; break; } p++; } while(--bytes_remaining); } if (!done) /* Find next chunk */ { if (str_hdr->next == NULL) done = TRUE; else { str_hdr = str_hdr->next; p = str_hdr->data; bytes_remaining = str_hdr->bytes; } } } while(!done); if ((mode == DYN_DELETE) && !mark_skipped && (c == mark)) { /* Skip the mark too */ p++; bytes_remaining--; } break; } } } /* Insert new data for REPLACE or INSERT */ switch(mode) { case DYN_REPLACE: case DYN_INSERT: /* We may not be at the desired position. For example, if we try to insert <3,2,2> we might not have the necessary number of fields, values or subvalues to get to this position. We must insert marks to get us to the right position. */ if (result_descr->data.str.saddr != NULL) /* Not at start of string */ { if (field < 0) { if (compatible && last_char == FIELD_MARK) { f = 1; /* Kill mark insertion */ field = 1; } else { field = f + 1; /* Insert a single field mark */ } v = 1; sv = 1; } else if (value < 0) { if ((field != f) /* No mark if adding new field... */ || (last_char == FIELD_MARK) /* ... or at start of a field */ || (compatible && last_char == VALUE_MARK)) { v = 1; /* 0222 Set both to one to kill mark insertion */ value = 1; } else value = v + 1; sv = 1; } else if (subvalue < 0) { if ((field != f) /* No mark if adding new field... */ || (value != v) /* ...or adding new value... */ || (last_char == FIELD_MARK) /* ...or at start of a field... */ || (last_char == VALUE_MARK) /* ...or at start of a value */ || (compatible && last_char == SUBVALUE_MARK)) { sv = 1; /* 0222 Set both to one to kill mark insertion */ subvalue = 1; } else subvalue = sv + 1; } } while(f < field) { ts_copy_byte(FIELD_MARK); f++; v = 1; sv = 1; } while(v < value) { ts_copy_byte(VALUE_MARK); v++; sv = 1; } while(sv < subvalue) { ts_copy_byte(SUBVALUE_MARK); sv++; } /* Insert replacement item */ for (new_str = new_descr->data.str.saddr; new_str != NULL; new_str = new_str->next) { ts_copy(new_str->data, new_str->bytes); } /* For insert mode, if we are not at the end of the source string and the next character of the source string is not a mark we must insert a mark to delimit the new data from the following item. */ if ((mode == DYN_INSERT) && (str_hdr != NULL)) { if (bytes_remaining == 0) /* Mark was at end of chunk */ { if ((str_hdr = str_hdr->next) == NULL) goto no_mark_required; p = str_hdr->data; bytes_remaining = str_hdr->bytes; } if ((!IsDelim(*p)) || (*p <= mark)) ts_copy_byte(mark); } no_mark_required: break; } /* Copy remainder of source string */ if (str_hdr != NULL) { /* Is there any data left in this chunk? */ if (bytes_remaining > 0) ts_copy(p, bytes_remaining); /* Copy any remaining chunks */ while((str_hdr = str_hdr->next) != NULL) { ts_copy(str_hdr->data, str_hdr->bytes); } } ts_terminate(); }
void op_fileinfo() { /* Stack: |================================|=============================| | BEFORE | AFTER | |================================|=============================| top | Key | Information | |--------------------------------|-----------------------------| | ADDR to file variable | | |================================|=============================| Key values: Action Returns 0 FL_OPEN Test if is open file variable True/False 1 FL_VOCNAME Get VOC name of file VOC name 2 FL_PATH Get file pathname Pathname 3 FL_TYPE Check file type DH: FL_TYPE_DH (3) Directory: FL_TYPE_DIR (4) Sequential: FL_TYPE_SEQ (5) 5 FL_MODULUS File modulus Modulus value 6 FL_MINMOD Minimum modulus Minimum modulus value 7 FL_GRPSIZE Group size Group size 8 FL_LARGEREC Large record size Large record size 9 FL_MERGE Merge load percentage Merge load 10 FL_SPLIT Split load percentage Split load 11 FL_LOAD Current load percentage Current load 13 FL_AK File has AK indices? Boolean 14 FL_LINE Number of next line Line number 1000 FL_LOADBYTES Current load in bytes Current load bytes 1001 FL_READONLY Read only file? Boolean 1002 FL_TRIGGER Get trigger function name Call name 1003 FL_PHYSBYTES Physical file size Size in bytes, excl indices 1004 FL_VERSION File version 1005 FL_STATS_QUERY Query file stats status Boolean 1006 FL_SEQPOS File position File offset 1007 FL_TRG_MODES Get trigger modes Mode mask 1008 FL_NOCASE File uses case insensitive ids? Boolean 1009 FL_FILENO Return internal file number File number 1010 FL_JNL_FNO Return journalling file no File no, zero if not journalling 1011 FL_AKPATH Returns AK subfile location Pathname of directory 1012 FL_ID Id of last record read Id 1013 FL_STATUS As STATUS statement Dynamic array 1014 FL_MARK_MAPPING Is mark mapping enabled? Boolean 1015 FL_RECORD_COUNT Approximate record count 1016 FL_PRI_BYTES Primary subfile size in bytes 1017 FL_OVF_BYTES Overflow subfile size in bytes 1018 FL_NO_RESIZE Resizing inhibited? 1019 FL_UPDATE Update counter 1020 FL_ENCRYPTED File uses encryption? Boolean 10000 FL_EXCLUSIVE Set exclusive access Successful? 10001 FL_FLAGS Fetch file flags File flags 10002 FL_STATS_ON Turn on file statistics 10003 FL_STATS_OFF Turn off file statistics 10004 FL_STATS Return file statistics 10005 FL_SETRDONLY Set file as read only */ short int key; DESCRIPTOR * descr; FILE_VAR * fvar; DH_FILE * dh_file; char * p = NULL; long int n = 0; FILE_ENTRY * fptr; OSFILE fu; bool dynamic; bool internal; long int * q; STRING_CHUNK * str; short int i; double floatnum; u_char ftype; int64 n64; /* Get action key */ descr = e_stack - 1; GetInt(descr); key = (short int)(descr->data.value); k_pop(1); /* Get file variable */ descr = e_stack - 1; while(descr->type == ADDR) {descr = descr->data.d_addr;} if (key == FL_OPEN) /* Test if file is open */ { n = (descr->type == FILE_REF); } else { if (descr->type != FILE_REF) k_error(sysmsg(1200)); fvar = descr->data.fvar; ftype = fvar->type; if (ftype == NET_FILE) /* Network file */ { str = net_fileinfo(fvar, key); k_dismiss(); InitDescr(e_stack, STRING); (e_stack++)->data.str.saddr = str; return; } fptr = FPtr(fvar->file_id); dynamic = (ftype == DYNAMIC_FILE); if (dynamic) dh_file = fvar->access.dh.dh_file; internal = ((process.program.flags & HDR_INTERNAL) != 0); switch(key) { case FL_VOCNAME: /* 1 VOC name of file */ if (fvar->voc_name != NULL) p = fvar->voc_name; else p = ""; goto set_string; case FL_PATH: /* 2 File pathname */ p = (char *)(fptr->pathname); goto set_string; case FL_TYPE: /* 3 File type */ /* !!FVAR_TYPES!! */ switch(ftype) { case DYNAMIC_FILE: n = FL_TYPE_DH; break; case DIRECTORY_FILE: n = FL_TYPE_DIR; break; case SEQ_FILE: n = FL_TYPE_SEQ; break; } break; case FL_MODULUS: /* 5 Modulus of file */ if (dynamic) n = fptr->params.modulus; break; case FL_MINMOD: /* 6 Minimum modulus of file */ if (dynamic) n = fptr->params.min_modulus; break; case FL_GRPSIZE: /* 7 Group size of file */ if (dynamic) n = dh_file->group_size / DH_GROUP_MULTIPLIER; break; case FL_LARGEREC: /* 8 Large record size */ if (dynamic) n = fptr->params.big_rec_size; break; case FL_MERGE: /* 9 Merge load percentage */ if (dynamic) n = fptr->params.merge_load; break; case FL_SPLIT: /* 10 Split load percentage */ if (dynamic) n = fptr->params.split_load; break; case FL_LOAD: /* 11 Load percentage */ if (dynamic) { n = DHLoad(fptr->params.load_bytes, dh_file->group_size, fptr->params.modulus); } break; case FL_AK: /* 13 File has AKs? */ if (dynamic) n = (dh_file->ak_map != 0); break; case FL_LINE: /* 14 Sequential file line position */ if (ftype == SEQ_FILE) { n64 = fvar->access.seq.sq_file->line; if (n64 > LONG_MAX) { floatnum = (double)n64; goto set_float; } n = (long)n64; } break; case FL_LOADBYTES: /* 1000 Load bytes */ if (dynamic) { floatnum = (double)(fptr->params.load_bytes); goto set_float; } break; case FL_READONLY: /* 1001 Read-only? */ n = ((fvar->flags & FV_RDONLY) != 0); break; case FL_TRIGGER: /* 1002 Trigger function name */ if (dynamic) { p = dh_file->trigger_name; goto set_string; } break; case FL_PHYSBYTES: /* 1003 Physical file size */ switch(ftype) { case DIRECTORY_FILE: floatnum = (double)dir_filesize(fvar); break; case DYNAMIC_FILE: floatnum = (double)dh_filesize(dh_file, PRIMARY_SUBFILE) + dh_filesize(dh_file, OVERFLOW_SUBFILE); break; case SEQ_FILE: fu = fvar->access.seq.sq_file->fu; floatnum = (double)(ValidFileHandle(fu)?filelength64(fu):-1); break; } goto set_float; case FL_VERSION: /* 1004 File version */ if (dynamic) n = dh_file->file_version; break; case FL_STATS_QUERY: /* 1005 File statistics enabled? */ if (dynamic) n = (fptr->stats.reset != 0); break; case FL_SEQPOS: /* 1006 Sequential file offset */ if (ftype == SEQ_FILE) { n64 = fvar->access.seq.sq_file->posn; if (n64 > LONG_MAX) { floatnum = (double)n64; goto set_float; } n = (long)n64; } break; case FL_TRG_MODES: /* 1007 Trigger modes */ if (dynamic) n = dh_file->trigger_modes; break; case FL_NOCASE: /* 1008 Case insensitive ids? */ switch(ftype) { case DIRECTORY_FILE: case DYNAMIC_FILE: n = (fptr->flags & DHF_NOCASE) != 0; break; } break; case FL_FILENO: /* 1009 Internal file number */ n = fvar->file_id; break; case FL_JNL_FNO: /* 1010 Journalling file number */ break; case FL_AKPATH: /* 1011 AK subfile pathname */ if (dynamic) { p = dh_file->akpath; goto set_string; } break; case FL_ID: /* 1012 Id of last record read */ k_dismiss(); k_put_string(fvar->id, fvar->id_len, e_stack); e_stack++; return; case FL_STATUS: /* 1013 STATUS array */ str = get_file_status(fvar); k_dismiss(); InitDescr(e_stack, STRING); (e_stack++)->data.str.saddr = str; return; case FL_MARK_MAPPING: /* 1014 Mark mapping enabled? */ if (ftype == DIRECTORY_FILE) n = fvar->access.dir.mark_mapping; break; case FL_RECORD_COUNT: /* 1015 Approximate record count */ if (dynamic) { floatnum = (double)(fptr->record_count); goto set_float; } else n = -1; case FL_PRI_BYTES: /* 1016 Physical size of primary subfile */ if (dynamic) { floatnum = (double)dh_filesize(dh_file, PRIMARY_SUBFILE); goto set_float; } break; case FL_OVF_BYTES: /* 1017 Physical size of overflow subfile */ if (dynamic) { floatnum = (double)dh_filesize(dh_file, OVERFLOW_SUBFILE); goto set_float; } break; case FL_NO_RESIZE: /* 1018 Resizing inhibited? */ if (dynamic) n = ((fptr->flags & DHF_NO_RESIZE) != 0); break; case FL_UPDATE: /* 1019 File update counter */ n = (long)(fptr->upd_ct); break; case FL_ENCRYPTED: /* 1020 File uses encryption? */ /* Recognised but returns default zero */ break; case FL_EXCLUSIVE: /* 10000 Set exclusive access mode */ if (internal) { /* To gain exclusive access to a file it must be open only to this process (fptr->ref_ct = 1) and must not be open more than once in this process. The latter condition only affects dynamic files as other types produce multiply referenced file table entries. We need to ensure a dynamic file is only open once so that when we close the file we really are going to kill off the DH_FILE structure. This is essential, for example, in AK creation where the DH_FILE structure has to change its size. */ flush_dh_cache(); /* Ensure we are not stopped by a cached reference from our own process. */ n = FALSE; for (i = 0; i < 6; i++) { StartExclusive(FILE_TABLE_LOCK, 37); if ((fptr->ref_ct == 1) && ((ftype != DYNAMIC_FILE) || (dh_file->open_count == 1))) { fptr->ref_ct = -1; fptr->fvar_index = fvar->index; n = TRUE; } EndExclusive(FILE_TABLE_LOCK); if (n) break; if (i == 0) /* First attempt */ { /* Cannot gain exclusive access. Maybe some other process has the file in its DH cache. Fire an EVT_FLUSH_CACHE event to all processes to see if this clears the problem. We then continue trying for a short time until either we get the required access or we reach our retry count. */ raise_event(EVT_FLUSH_CACHE, -1); } Sleep(500); /* Pause for something to happen */ } } break; case FL_FLAGS: /* 10001 File flags */ if (dynamic && internal) n = (long int)(dh_file->flags); break; case FL_STATS_ON: /* 10002 Enable file statistics */ if (dynamic && internal) { memset((char *)&(fptr->stats), 0, sizeof(struct FILESTATS)); fptr->stats.reset = qmtime(); } break; case FL_STATS_OFF: /* 10003 Disable file statistics */ if (dynamic && internal) fptr->stats.reset = 0; break; case FL_STATS: /* 10004 Return file statistics data */ if (dynamic && internal) { str = NULL; ts_init(&str, 5 * FILESTATS_COUNTERS); for (i = 0, q = (long int *)&(fptr->stats.reset); i < FILESTATS_COUNTERS; i++, q++) { ts_printf("%ld\xfe", *q); } (void)ts_terminate(); k_dismiss(); /* 0363 */ InitDescr(e_stack, STRING); (e_stack++)->data.str.saddr = str; return; } break; case FL_SETRDONLY: /* 10005 Set read-only */ if (internal) { fvar->flags |= FV_RDONLY; if (dynamic) dh_file->flags |= DHF_RDONLY; } break; default: k_error(sysmsg(1010)); } } /* Set integer return value on stack */ set_integer: k_dismiss(); InitDescr(e_stack, INTEGER); (e_stack++)->data.value = n; return; /* Set string return value on stack */ set_string: k_dismiss(); k_put_c_string(p, e_stack); e_stack++; return; set_float: if (floatnum <= (double)LONG_MAX) { n = (long)floatnum; goto set_integer; } k_dismiss(); InitDescr(e_stack, FLOATNUM); (e_stack++)->data.float_value = floatnum; return; }
int main() { char c; init_uart(); lcd_init(); lcd_enable(); ts_init(); ts_calibrate(); printf("can update program with serial port\n\r"); while (1) { printf("[w] write the nand flash\n\r"); printf("[r] read the nand flash\n\r"); printf("[e] erase the nand flash\n\r"); printf("[g] get file, and write to nand flash 0 block\n\r"); printf("[x] get file to ddr(0x52000000), run it\n\r"); printf("[t] test lcd\n\r"); printf("[s] test touch screem\n\r"); do { c = getc(); if (c == '\n' || c == '\r') { printf("\n\r"); } else { putc(c); } } while (c == '\n' || c == '\r'); switch (c) { case 'w': case 'W': { nand_write_test(); break; } case 'r': case 'R': { nand_read_test(); break; } case 'e': case 'E': { nand_erase_test(); break; } case 'g': case 'G': { update_program(); break; } case 'x': case 'X': { run_program(); break; } case 't': case 'T': { lcd_test(); break; } case 's': case 'S': { ts_test(); break; } } } return 0; }