void MpVerticalScrollbar::AdaptSlider (int shp) { // adapt to new slider height sh = MpMax(shp,2*GetFrameWidth()); // set a minimum slider height sh = MpMin(sh,Height()-2*GetFrameWidth()); // set a maximum slider height set_vars(); bar->Resize(sw,sh); SetSlider(0); }
MpVerticalScrollbar::MpVerticalScrollbar (MpWindow &parent, int w, int h, int x, int y, int sh) : MpCanvas (parent,w,h,x,y,Panel|Sunken|Enhanced), sh(sh) { SetBackingStore(true); // this is crucial for a smooth scrolling! AddEventMask(PointerMotionMask | ButtonPressMask); set_vars(); bar = new MpSlider(*this,sw,sh,sx,sy,MpGlobal::horizontal); SetCursor( MpCursor::SlideVertical ); SetBackground(&Mp.MediumColor); }
static int netalloc(int n1, int n2) #endif { int c; neurone *n; typedef neurone *neuronePtr; #ifdef ITERATIVE if (n3>n2) error(NIL,"you never need more weights than connections",NIL); #endif zero_reseau(); neurbase = (neurone *)malloc(n1 * sizeof(neurone)); neurmax = n1; synbase = (synapse *)malloc(n2 * sizeof(synapse)); synmax = n2; #ifdef ITERATIVE { int dim[2]; struct index *arr; dim[0] = n3; dim[1] = sizeof(weight) / sizeof(flt); w_matrix = F_matrix(2,dim); protect(w_matrix); UNLOCK(w_matrix); if (w_matrix_var) var_SET(w_matrix_var,w_matrix); arr = w_matrix->Object; weightbase = arr->st->srg.data; weightmax = n3; } #endif neuraddress = (neurone **)malloc(n1 * sizeof( neuronePtr )); netconvert = (int *)malloc(n1 * sizeof(int)); if ( neurbase==NIL || synbase==NIL || neuraddress==NIL || netconvert ==NIL ) { zero_reseau(); error(NIL,"not enough memory",NIL); }; memset(neurbase, 0, n1*sizeof(neurone)); memset(synbase, 0, n2*sizeof(synapse)); neurnombre = 1; neurbase[0].Nval=fptoF(1.0); /* neurone 0 = seuil */ for (c=0, n=neurbase ; c<neurmax; c++, n++) neuraddress[c]=n; set_vars(); #ifdef ITERATIVE return ( n3*sizeof(weight) + n2*sizeof(synapse) + n1*sizeof(neurone) ); #else return ( n2*sizeof(synapse) + n1*sizeof(neurone) ); #endif }
int main (int argc, char ** argv) { int err, step ; int do_write = 1; int do_read = 1; int m = 0; char write_method[16]; MPI_Init (&argc, &argv); MPI_Comm_rank (comm, &rank); MPI_Comm_size (comm, &size); if (argc > 1) { m = strtol (argv[1], NULL, 10); if (errno) { printf("Invalid 1st argument %s\n", argv[1]); Usage(); return 1;} } if (argc > 2) { if (argv[2][0] == 'w' || argv[2][0] == 'W') { do_read = 0; } else if (argv[2][0] == 'r' || argv[2][0] == 'R') { do_write = 0; } else { printE ("Invalid command line argument %s. Allowed ones:\n" " w: do write only\n" " r: do read only\n", argv[2]); MPI_Finalize (); return 1; } } if (m==0) { read_method = ADIOS_READ_METHOD_BP; strcpy(write_method,"MPI"); } else { read_method = ADIOS_READ_METHOD_DATASPACES; strcpy(write_method,"DATASPACES"); } log ("Writing: %s method=%s\n" "Reading: %s method=%d\n", (do_write ? "yes" : "no"), write_method, (do_read ? "yes" : "no"), read_method); alloc_vars(); if (do_write) { adios_init_noxml (comm); adios_allocate_buffer (ADIOS_BUFFER_ALLOC_NOW, 10); } if (do_read) { err = adios_read_init_method(read_method, comm, "verbose=2"); if (err) { printE ("%s\n", adios_errmsg()); } } if (do_write) { adios_declare_group (&m_adios_group, "selections", "iter", adios_flag_yes); adios_select_method (m_adios_group, write_method, "verbose=2", ""); define_vars(); for (step=0; step<NSTEPS; step++) { if (!err) { set_vars (step); err = write_file (step); sleep(1); } } adios_free_group (m_adios_group); } if (!err && do_read) err = read_points (); //if (!err && do_read) // err = read_writerblocks (); if (do_read) { adios_read_finalize_method (read_method); } fini_vars(); if (do_write) { adios_finalize (rank); } MPI_Finalize (); return err; }
int main (int argc, char ** argv) { int err,i,M; int iconnect; MPI_Init (&argc, &argv); MPI_Comm_rank (wcomm, &wrank); MPI_Comm_size (wcomm, &wsize); if (argc < 2) { Usage(); return 1; } errno = 0; M = strtol (argv[1], NULL, 10); if (errno || M < 1 || M > wsize) { printE("Invalid 1st argument %s\n", argv[1]); Usage(); return 1; } iconnect = (wrank >= wsize-M); // connect to server from ranks N-M, N-M+1, ..., N MPI_Comm_split (wcomm, iconnect, wrank+M-wsize, &subcomm); MPI_Comm_rank (subcomm, &subrank); MPI_Comm_size (subcomm, &subsize); if (iconnect) { if (subsize != M) { printE ("Something wrong with communicator split: N=%d, M=%d, splitted size=%d\n", wsize, M, subsize); return 2; } log ("connect as subrank %d\n", subrank); } alloc_vars(); adios_read_init_method(ADIOS_READ_METHOD_DATASPACES, subcomm, "verbose=4"); adios_init_noxml (subcomm); adios_allocate_buffer (ADIOS_BUFFER_ALLOC_NOW, 1); if (iconnect) { adios_declare_group (&m_adios_group, "connect", "iter", adios_flag_yes); adios_select_method (m_adios_group, "DATASPACES", "verbose=4", ""); adios_define_var (m_adios_group, "ldim1", "", adios_integer, 0, 0, 0); adios_define_var (m_adios_group, "gdim1", "", adios_integer, 0, 0, 0); adios_define_var (m_adios_group, "offs1", "", adios_integer, 0, 0, 0); adios_define_var (m_adios_group, "a1", "", adios_integer, "ldim1", "gdim1", "offs1"); for (i=0; i<NSTEPS; i++) { if (!err) { set_vars (i); err = write_file (i); } } } log ("done with work, sync with others...\n"); MPI_Barrier (wcomm); log ("call adios_finalize...\n"); adios_finalize (wrank); log ("call adios_read_finalize_method...\n"); adios_read_finalize_method (ADIOS_READ_METHOD_DATASPACES); fini_vars(); MPI_Finalize (); return err; }
SEXP copy_vars(SEXP target, SEXP source) { return set_vars(target, get_vars(source)); }
int gen_super_filter_index2(char *index, struct fileheader* fileinfo, char * boardname, int isbm) { struct fileheader *ptr1; struct flock ldata, ldata2; int fd, fd2, size = sizeof(fileheader), total, i, count = 0; char direct[PATHLEN]; char newdirect[PATHLEN]; char *ptr; struct stat buf; int load_content=0, found=0, load_stat=0; int gid = fileinfo->groupid; //TODO: 这么大的index! load_content = (strstr(index, "content")!=NULL||strstr(index, "文章内容")!=NULL); load_stat = (strstr(index, "asize")!=NULL||strstr(index, "总长度")!=NULL); setbdir(DIR_MODE_NORMAL, direct, boardname); setbdir(DIR_MODE_SUPERFITER, newdirect, boardname); if ((fd = open(newdirect, O_WRONLY | O_CREAT, 0664)) == -1) { bbslog("user", "%s", "recopen err"); return -9999; } ldata.l_type = F_WRLCK; ldata.l_whence = 0; ldata.l_len = 0; ldata.l_start = 0; if (fcntl(fd, F_SETLKW, &ldata) == -1) { bbslog("user", "%s", "reclock err"); close(fd); return -9999; } if ((fd2 = open(direct, O_RDONLY, 0664)) == -1) { bbslog("user", "%s", "recopen err"); ldata.l_type = F_UNLCK; fcntl(fd, F_SETLKW, &ldata); close(fd); return -9999; } fstat(fd2, &buf); ldata2.l_type = F_RDLCK; ldata2.l_whence = 0; ldata2.l_len = 0; ldata2.l_start = 0; fcntl(fd2, F_SETLKW, &ldata2); total = buf.st_size / size; if ((i = safe_mmapfile_handle(fd2, PROT_READ, MAP_SHARED, (void **) &ptr, &buf.st_size)) != 1) { if (i == 2) end_mmapfile((void *) ptr, buf.st_size, -1); ldata2.l_type = F_UNLCK; fcntl(fd2, F_SETLKW, &ldata2); close(fd2); ldata.l_type = F_UNLCK; fcntl(fd, F_SETLKW, &ldata); close(fd); return -9999; } ptr1 = (struct fileheader *) ptr; libs = (char*)malloc(LIBLEN); for (i = 0; i < total; i++) { struct stat st; char* p; char ffn[80]; int j=0; off_t fsize; libptr = libs; ferr = 0; set_vard(fvars+fget_var("cid"), fileinfo->id); set_vard(fvars+fget_var("creid"), fileinfo->reid); set_vard(fvars+fget_var("cgroupid"), fileinfo->groupid); set_vars(fvars+fget_var("cauthor"), fileinfo->owner); set_vars(fvars+fget_var("cfname"), fileinfo->filename); set_vard(fvars+fget_var("cftime"), get_posttime(fileinfo)); set_vard(fvars+fget_var("ceffsize"), fileinfo->eff_size); set_vard(fvars+fget_var("no"), i+1); set_vard(fvars+fget_var("文章号"), i+1); set_vard(fvars+fget_var("id"), ptr1->id); set_vard(fvars+fget_var("reid"), ptr1->reid); set_vard(fvars+fget_var("groupid"), ptr1->groupid); set_vard(fvars+fget_var("thread"), ptr1->groupid==gid); set_vard(fvars+fget_var("本主题"), ptr1->groupid==gid); set_vard(fvars+fget_var("origin"), ptr1->id==ptr1->groupid); set_vard(fvars+fget_var("原作"), ptr1->id==ptr1->groupid); set_vard(fvars+fget_var("m"), ptr1->accessed[0]&FILE_MARKED); set_vard(fvars+fget_var("保留"), ptr1->accessed[0]&FILE_MARKED); set_vard(fvars+fget_var("g"), ptr1->accessed[0]&FILE_DIGEST); set_vard(fvars+fget_var("文摘"), ptr1->accessed[0]&FILE_DIGEST); set_vard(fvars+fget_var("b"), (ptr1->accessed[0]&FILE_MARKED)&&(ptr1->accessed[0]&FILE_DIGEST)); if (isbm) { set_vard(fvars+fget_var("noreply"), ptr1->accessed[1]&FILE_READ); set_vard(fvars+fget_var("不可回复"), ptr1->accessed[1]&FILE_READ); set_vard(fvars+fget_var("sign"), ptr1->accessed[0]&FILE_SIGN); set_vard(fvars+fget_var("标记"), ptr1->accessed[0]&FILE_SIGN); #ifdef PERCENT_SIGN_SUPPORT set_vard(fvars+fget_var("percent"), ptr1->accessed[0]&FILE_PERCENT); set_vard(fvars+fget_var("百分号"), ptr1->accessed[0]&FILE_PERCENT); #endif #ifdef FILTER set_vard(fvars+fget_var("censor"), ptr1->accessed[1]&FILE_CENSOR); set_vard(fvars+fget_var("审核"), ptr1->accessed[1]&FILE_CENSOR); #endif set_vard(fvars+fget_var("del"), ptr1->accessed[1]&FILE_DEL); set_vard(fvars+fget_var("删除"), ptr1->accessed[1]&FILE_DEL); set_vard(fvars+fget_var("import"), ptr1->accessed[0]&FILE_IMPORTED); set_vard(fvars+fget_var("精华"), ptr1->accessed[0]&FILE_IMPORTED); } set_vard(fvars+fget_var("attach"), ptr1->attachment); set_vard(fvars+fget_var("附件"), ptr1->attachment); set_vars(fvars+fget_var("title"), ptr1->title); set_vars(fvars+fget_var("标题"), ptr1->title); set_vars(fvars+fget_var("author"), ptr1->owner); set_vars(fvars+fget_var("作者"), ptr1->owner); set_vars(fvars+fget_var("fname"), ptr1->filename); set_vars(fvars+fget_var("文件名"), ptr1->filename); set_vard(fvars+fget_var("my"), !strcmp(ptr1->owner,getCurrentUser()->userid)); set_vard(fvars+fget_var("我的"), !strcmp(ptr1->owner,getCurrentUser()->userid)); #ifdef HAVE_BRC_CONTROL set_vard(fvars+fget_var("unread"), brc_unread(ptr1->id, getSession())); set_vard(fvars+fget_var("未读"), brc_unread(ptr1->id, getSession())); #endif setbfile(ffn, boardname, ptr1->filename); set_vard(fvars+fget_var("ftime"), get_posttime(ptr1)); set_vard(fvars+fget_var("时间"), get_posttime(ptr1)); set_vard(fvars+fget_var("effsize"), ptr1->eff_size); set_vard(fvars+fget_var("有效长度"), ptr1->eff_size); if(load_stat) { if(stat(ffn, &st)!=-1) { set_vard(fvars+fget_var("asize"), st.st_size); set_vard(fvars+fget_var("总长度"), st.st_size); } else { set_vard(fvars+fget_var("asize"), 0); set_vard(fvars+fget_var("总长度"), 0); } } if(load_content) { set_vars(fvars+fget_var("content"), ptr1->filename); set_vars(fvars+fget_var("文章内容"), ptr1->filename); j = safe_mmapfile(ffn, O_RDONLY, PROT_READ, MAP_SHARED, (void **) &p, &fsize, NULL); if(j) { set_vars(fvars+fget_var("content"), p); set_vars(fvars+fget_var("文章内容"), p); } } ferr=0; feval(fvars+fget_var("res"), index, 0, strlen(index)-1); if(ferr) break; if(fvars[fget_var("res")].s) { write(fd, ptr1, size); count++; found++; } if(load_content) { if(j) end_mmapfile((void*)p, fsize, -1); } ptr1++; } free(libs); end_mmapfile((void *) ptr, buf.st_size, -1); ldata2.l_type = F_UNLCK; fcntl(fd2, F_SETLKW, &ldata2); close(fd2); ftruncate(fd, count * size); ldata.l_type = F_UNLCK; fcntl(fd, F_SETLKW, &ldata); /* 退出互斥区域*/ close(fd); if(ferr) { return -ferr; } else { return count; } }
int init_with_instance(HMODULE hmod_exe, char *frozen) { int rc = 0; HMODULE hmod_pydll; /* Py_NoSiteFlag = 1; /* Suppress 'import site' */ /* Py_InspectFlag = 1; /* Needed to determine whether to exit at SystemExit */ calc_dirname(hmod_exe); // wprintf(L"modulename %s\n", modulename); // wprintf(L"dirname %s\n", dirname); if (!locate_script(hmod_exe)) { SystemError(-1, "FATAL ERROR: Could not locate script"); // printf("FATAL ERROR locating script\n"); return -1; } hmod_pydll = load_pythondll(); if (hmod_pydll == NULL) { SystemError(-1, "FATAL ERROR: Could not load python library"); // printf("FATAL Error: could not load python library\n"); return -1; } if (PythonLoaded(hmod_pydll) < 0) { SystemError(-1, "FATAL ERROR: Failed to load some Python symbols"); // printf("FATAL Error: failed to load some Python symbols\n"); return -1; } set_vars(hmod_pydll); /* _memimporter contains the magic which allows to load dlls from memory, without unpacking them to the file-system. It is compiled into all the exe-stubs. */ PyImport_AppendInittab("_memimporter", PyInit__memimporter); /* Start the ball rolling. */ Py_SetProgramName(modulename); Py_SetPath(libfilename); Py_Initialize(); /* Set sys.frozen so apps that care can tell. If the caller did pass NULL, sys.frozen will be set to 'True'. If a string is passed this is used as the frozen attribute. run.c passes "console_exe", run_w.c passes "windows_exe", run_dll.c passes "dll" This falls apart when you consider that in some cases, a single process may end up with two py2exe generated apps - but still, we reset frozen to the correct 'current' value for the newly initializing app. */ if (frozen == NULL) PySys_SetObject("frozen", PyBool_FromLong(1)); else { PyObject *o = PyUnicode_FromString(frozen); if (o) { PySys_SetObject("frozen", o); Py_DECREF(o); } } return rc; }
void client_run(int client_socket, char *local_ip, int local_port, char *remote_ip, int remote_port) { char sendbuf[RCVBUFSIZE], recvbuf[RCVBUFSIZE], infobuf[RCVBUFSIZE]; struct sockaddr_in addr = {0}, sendaddr = {0}; int read_bytes; int usock; int reuse_addr = 1; fax_state_t fax; char tmp[512], fn[512], *file_name = "/tmp/test.tiff"; int send_fax = FALSE; int g711 = 0; int pcmu = 0; snprintf(sendbuf, sizeof(sendbuf), "connect\n\n"); send(client_socket, sendbuf, strlen(sendbuf), 0); if ((read_bytes = recv(client_socket, infobuf, sizeof(infobuf), 0)) < 0) { die("recv() failed"); } #if SOCKET2ME_DEBUG printf("READ [%s]\n", infobuf); #endif if (cheezy_get_var(infobuf, "Channel-Read-Codec-Name", tmp, sizeof(tmp))) { if (!strcasecmp(tmp, "pcmu")) { g711 = 1; pcmu = 1; } else if (!strcasecmp(tmp, "pcma")) { g711 = 1; } } snprintf(sendbuf, sizeof(sendbuf), "sendmsg\n" "call-command: unicast\n" "local-ip: %s\n" "local-port: %d\n" "remote-ip: %s\n" "remote-port: %d\n" "transport: udp\n" "%s" "\n", local_ip, local_port, remote_ip, remote_port, g711 ? "flags: native\n" : "" ); if (cheezy_get_var(infobuf, "variable_fax_file_name", fn, sizeof(fn))) { file_name = fn; } if (cheezy_get_var(infobuf, "variable_fax_mode", tmp, sizeof(tmp))) { if (!strcasecmp(tmp, "send")) { send_fax = TRUE; } } if (cheezy_get_var(infobuf, "variable_fax_preexec", tmp, sizeof(tmp))) { set_vars(infobuf); system(tmp); } #if SOCKET2ME_DEBUG printf("SEND: [%s]\n", sendbuf); #endif send(client_socket, sendbuf, strlen(sendbuf), 0); memset(recvbuf, 0, sizeof(recvbuf)); if ((read_bytes = recv(client_socket, recvbuf, sizeof(recvbuf), 0)) < 0) { die("recv() failed"); } #if SOCKET2ME_DEBUG printf("READ [%s]\n", recvbuf); #endif if ((usock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { die("socket() failed"); } setsockopt(usock, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); /*addr.sin_addr.s_addr = inet_addr(remote_ip);*/ addr.sin_port = htons(remote_port); sendaddr.sin_family = AF_INET; sendaddr.sin_addr.s_addr = inet_addr(local_ip); sendaddr.sin_port = htons(local_port); if (bind(usock, (struct sockaddr *) &addr, sizeof(addr)) < 0) { die("bind() failed"); } printf("%s Fax filename: [%s] from %s:%d -> %s:%d\n", send_fax ? "Sending" : "Receiving", file_name, local_ip, local_port, remote_ip, remote_port); fax_init(&fax, send_fax); t30_set_local_ident(&fax.t30_state, "Socket 2 ME"); t30_set_header_info(&fax.t30_state, "Socket 2 ME"); if (send_fax) { t30_set_tx_file(&fax.t30_state, file_name, -1, -1); } else { t30_set_rx_file(&fax.t30_state, file_name, -1); } t30_set_phase_b_handler(&fax.t30_state, phase_b_handler, NULL); t30_set_phase_d_handler(&fax.t30_state, phase_d_handler, NULL); t30_set_phase_e_handler(&fax.t30_state, phase_e_handler, NULL); t30_set_document_handler(&fax.t30_state, document_handler, NULL); t30_set_ecm_capability(&fax.t30_state, TRUE); t30_set_supported_compressions(&fax.t30_state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION); t30_set_supported_image_sizes(&fax.t30_state, T30_SUPPORT_US_LETTER_LENGTH | T30_SUPPORT_US_LEGAL_LENGTH | T30_SUPPORT_UNLIMITED_LENGTH | T30_SUPPORT_215MM_WIDTH | T30_SUPPORT_255MM_WIDTH | T30_SUPPORT_303MM_WIDTH); t30_set_supported_resolutions(&fax.t30_state, T30_SUPPORT_STANDARD_RESOLUTION | T30_SUPPORT_FINE_RESOLUTION | T30_SUPPORT_SUPERFINE_RESOLUTION | T30_SUPPORT_R8_RESOLUTION | T30_SUPPORT_R16_RESOLUTION); for (;;) { struct sockaddr_in local_addr = {0}; size_t cliAddrLen = sizeof(local_addr); unsigned char audiobuf[1024], rawbuf[1024], outbuf[1024]; short *usebuf = NULL; int tx, tx_bytes, bigger, sample_count; fd_set ready; FD_ZERO(&ready); FD_SET(usock, &ready); FD_SET(client_socket, &ready); bigger = usock > client_socket ? usock : client_socket; select(++bigger, &ready, NULL, NULL, NULL); if (FD_ISSET(client_socket, &ready)) { memset(recvbuf, 0, sizeof(recvbuf)); if ((read_bytes = recv(client_socket, recvbuf, sizeof(recvbuf), 0)) < 0) { die("recv() failed"); } if (read_bytes == 0) { break; } #if SOCKET2ME_DEBUG printf("READ [%s]\n", recvbuf); #endif } if (!FD_ISSET(usock, &ready)) { continue; } if ((read_bytes = recvfrom(usock, audiobuf, sizeof(audiobuf), 0, (struct sockaddr *) &local_addr, &cliAddrLen)) < 0) { die("recvfrom() failed"); } if (g711) { int i; short *rp = (short *) rawbuf; for (i = 0; i < read_bytes; i++) { if (pcmu) { rp[i] = ulaw_to_linear(audiobuf[i]); } else { rp[i] = alaw_to_linear(audiobuf[i]); } } usebuf = rp; sample_count = read_bytes; } else { usebuf = (short *) audiobuf; sample_count = read_bytes / 2; } fax_rx(&fax, usebuf, sample_count); #if SOCKET2ME_DEBUG printf("Handling client %s:%d %d bytes\n", inet_ntoa(local_addr.sin_addr), ntohs(local_addr.sin_port), read_bytes); #endif if ((tx = fax_tx(&fax, (short *)outbuf, sample_count)) < 0) { printf("Fax Error\n"); break; } else if (!tx) { continue; } if (g711) { int i; short *bp = (short *) outbuf; for (i = 0; i < tx; i++) { if (pcmu) { rawbuf[i] = linear_to_ulaw(bp[i]); } else { rawbuf[i] = linear_to_alaw(bp[i]); } } usebuf = (short *) rawbuf; tx_bytes = tx; } else { usebuf = (short *)outbuf; tx_bytes = tx * 2; } cliAddrLen = sizeof(sendaddr); if (sendto(usock, usebuf, tx_bytes, 0, (struct sockaddr *) &sendaddr, sizeof(sendaddr)) != tx_bytes) { die("sendto() sent a different number of bytes than expected"); } } close(client_socket); close(usock); t30_terminate(&fax.t30_state); fax_release(&fax); if (cheezy_get_var(infobuf, "variable_fax_postexec", tmp, sizeof(tmp))) { set_vars(infobuf); system(tmp); } printf("Done\n"); snprintf(sendbuf, sizeof(sendbuf), "hangup\n\n"); send(client_socket, sendbuf, strlen(sendbuf), 0); }
/* * Main application. This is where the requests come in and routed. */ void handle_request(void) { bool logged_in = false; char *request_uri; struct timespec stp; struct timespec etp; clock_gettime(CLOCK_REALTIME, &stp); qvars = NULL; avars = NULL; u_files = NULL; set_env_vars(); set_vars(); request_uri = strdupa(env_vars.request_uri); /* Initialise the database connection */ conn = db_conn(); if (!conn) goto out2; /* * Some routes need to come before the login / session stuff as * they can't be logged in and have no session. */ if (match_uri(request_uri, "//")) { /* function call goes here */ goto out2; } if (match_uri(request_uri, "/login/")) { login(); goto out2; } logged_in = is_logged_in(); if (!logged_in) { printf("Location: /login/\r\n\r\n"); goto out2; } /* Logged in, set-up the user_session structure */ set_user_session(); /* Add new url handlers after here */ if (match_uri(request_uri, "/logout/")) { logout(); goto out; } /* Default location */ printf("Location: /login/\r\n\r\n"); out: free_user_session(); out2: free_vars(qvars); free_avars(); free_u_files(); clock_gettime(CLOCK_REALTIME, &etp); d_fprintf(access_log, "Got request from %s for %s (%s), %ums\n", env_vars.remote_addr, request_uri, env_vars.request_method, (unsigned int)((etp.tv_sec * 1000 + etp.tv_nsec / NS_MSEC) - (stp.tv_sec * 1000 + stp.tv_nsec / NS_MSEC))); free_env_vars(); mysql_close(conn); }
int main(int argc, char *argv[]) { struct Cell_head cellhd; char *name, *result; char **mapname; FCELL **fbuf; int n_measures, n_outputs, *measure_idx; int nrows, ncols; int row, col, first_row, last_row, first_col, last_col; int i, j; CELL **data; /* Data structure containing image */ DCELL *dcell_row; struct FPRange range; DCELL min, max, inscale; FCELL measure; /* Containing measure done */ int dist, size; /* dist = value of distance, size = s. of moving window */ int offset; int have_px, have_py, have_sentr, have_pxpys, have_pxpyd; int infd, *outfd; RASTER_MAP_TYPE data_type, out_data_type; struct GModule *module; struct Option *opt_input, *opt_output, *opt_size, *opt_dist, *opt_measure; struct Flag *flag_ind, *flag_all; struct History history; char p[1024]; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("raster")); G_add_keyword(_("algebra")); G_add_keyword(_("statistics")); G_add_keyword(_("texture")); module->description = _("Generate images with textural features from a raster map."); module->overwrite = 1; /* Define the different options */ opt_input = G_define_standard_option(G_OPT_R_INPUT); opt_output = G_define_standard_option(G_OPT_R_BASENAME_OUTPUT); opt_size = G_define_option(); opt_size->key = "size"; opt_size->key_desc = "value"; opt_size->type = TYPE_INTEGER; opt_size->required = NO; opt_size->description = _("The size of moving window (odd and >= 3)"); opt_size->answer = "3"; /* Textural character is in direct relation of the spatial size of the texture primitives. */ opt_dist = G_define_option(); opt_dist->key = "distance"; opt_dist->key_desc = "value"; opt_dist->type = TYPE_INTEGER; opt_dist->required = NO; opt_dist->description = _("The distance between two samples (>= 1)"); opt_dist->answer = "1"; for (i = 0; menu[i].name; i++) { if (i) strcat(p, ","); else *p = 0; strcat(p, menu[i].name); } opt_measure = G_define_option(); opt_measure->key = "method"; opt_measure->type = TYPE_STRING; opt_measure->required = NO; opt_measure->multiple = YES; opt_measure->options = p; opt_measure->description = _("Textural measurement method"); flag_ind = G_define_flag(); flag_ind->key = 's'; flag_ind->description = _("Separate output for each angle (0, 45, 90, 135)"); flag_all = G_define_flag(); flag_all->key = 'a'; flag_all->description = _("Calculate all textural measurements"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); name = opt_input->answer; result = opt_output->answer; size = atoi(opt_size->answer); if (size <= 0) G_fatal_error(_("Size of the moving window must be > 0")); if (size % 2 != 1) G_fatal_error(_("Size of the moving window must be odd")); dist = atoi(opt_dist->answer); if (dist <= 0) G_fatal_error(_("The distance between two samples must be > 0")); n_measures = 0; if (flag_all->answer) { for (i = 0; menu[i].name; i++) { menu[i].useme = 1; } n_measures = i; } else { for (i = 0; opt_measure->answers[i]; i++) { if (opt_measure->answers[i]) { const char *measure_name = opt_measure->answers[i]; int n = find_measure(measure_name); menu[n].useme = 1; n_measures++; } } } if (!n_measures) G_fatal_error(_("Nothing to compute. Use at least one textural measure.")); measure_idx = G_malloc(n_measures * sizeof(int)); j = 0; for (i = 0; menu[i].name; i++) { if (menu[i].useme == 1) { measure_idx[j] = menu[i].idx; j++; } } /* variables needed */ if (menu[2].useme || menu[11].useme || menu[12].useme) have_px = 1; else have_px = 0; if (menu[11].useme || menu[12].useme) have_py = 1; else have_py = 0; if (menu[6].useme || menu[7].useme) have_sentr = 1; else have_sentr = 0; if (menu[5].useme || menu[6].useme || menu[7].useme) have_pxpys = 1; else have_pxpys = 0; if (menu[9].useme || menu[10].useme) have_pxpyd = 1; else have_pxpyd = 0; infd = Rast_open_old(name, ""); /* determine the inputmap type (CELL/FCELL/DCELL) */ data_type = Rast_get_map_type(infd); Rast_get_cellhd(name, "", &cellhd); out_data_type = FCELL_TYPE; /* Allocate output buffers, use FCELL data_type */ n_outputs = n_measures; if (flag_ind->answer) { n_outputs = n_measures * 4; } fbuf = G_malloc(n_outputs * sizeof(FCELL *)); mapname = G_malloc(n_outputs * sizeof(char *)); for (i = 0; i < n_outputs; i++) { mapname[i] = G_malloc(GNAME_MAX * sizeof(char)); fbuf[i] = Rast_allocate_buf(out_data_type); } /* open output maps */ outfd = G_malloc(n_outputs * sizeof(int)); for (i = 0; i < n_measures; i++) { if (flag_ind->answer) { for (j = 0; j < 4; j++) { sprintf(mapname[i * 4 + j], "%s%s_%d", result, menu[measure_idx[i]].suffix, j * 45); outfd[i * 4 + j] = Rast_open_new(mapname[i * 4 + j], out_data_type); } } else { sprintf(mapname[i], "%s%s", result, menu[measure_idx[i]].suffix); outfd[i] = Rast_open_new(mapname[i], out_data_type); } } nrows = Rast_window_rows(); ncols = Rast_window_cols(); /* Load raster map. */ /* allocate the space for one row of cell map data *A* */ dcell_row = Rast_allocate_d_buf(); /* Allocate appropriate memory for the structure containing the image */ data = (int **)G_malloc(nrows * sizeof(int *)); for (i = 0; i < nrows; i++) { data[i] = (int *)G_malloc(ncols * sizeof(int)); } /* read input range */ Rast_init_fp_range(&range); Rast_read_fp_range(name, "", &range); Rast_get_fp_range_min_max(&range, &min, &max); inscale = 0; if (min < 0 || max > 255) { inscale = 255. / (max - min); } /* input has 0 - 1 range */ else if (max <= 1.) { inscale = 255. / (max - min); } /* Read in cell map values */ /* TODO: use r.proj cache */ G_important_message(_("Reading raster map...")); for (j = 0; j < nrows; j++) { Rast_get_row(infd, dcell_row, j, DCELL_TYPE); for (i = 0; i < ncols; i++) { if (Rast_is_d_null_value(&(dcell_row[i]))) data[j][i] = -1; else if (inscale) { data[j][i] = (CELL)((dcell_row[i] - min) * inscale); } else data[j][i] = (CELL)dcell_row[i]; } } /* close input cell map and release the row buffer */ Rast_close(infd); G_free(dcell_row); /* Now raster map is loaded to memory. */ /* ************************************************************************************************* * * Compute of the matrix S.G.L.D. (Spatial Gray-Level Dependence Matrices) or co-occurrence matrix. * The image is analized for piece, every piece is naming moving window (s.w.). The s.w. must be * square with number of size's samples odd, that because we want the sample at the center of matrix. * ***************************************************************************************************/ offset = size / 2; first_row = first_col = offset; last_row = nrows - offset; last_col = ncols - offset; Rast_set_f_null_value(fbuf[0], ncols); for (row = 0; row < first_row; row++) { for (i = 0; i < n_outputs; i++) { Rast_put_row(outfd[i], fbuf[0], out_data_type); } } if (n_measures > 1) G_message(n_("Calculating %d texture measure", "Calculating %d texture measures", n_measures), n_measures); else G_message(_("Calculating %s"), menu[measure_idx[0]].desc); alloc_vars(size, dist); for (row = first_row; row < last_row; row++) { G_percent(row, nrows, 2); for (i = 0; i < n_outputs; i++) Rast_set_f_null_value(fbuf[i], ncols); /*process the data */ for (col = first_col; col < last_col; col++) { if (!set_vars(data, row, col, size, offset, dist)) { for (i = 0; i < n_outputs; i++) Rast_set_f_null_value(&(fbuf[i][col]), 1); continue; } /* for all angles (0, 45, 90, 135) */ for (i = 0; i < 4; i++) { set_angle_vars(i, have_px, have_py, have_sentr, have_pxpys, have_pxpyd); /* for all requested textural measures */ for (j = 0; j < n_measures; j++) { measure = (FCELL) h_measure(measure_idx[j]); if (flag_ind->answer) { /* output for each angle separately */ fbuf[j * 4 + i][col] = measure; } else { /* use average over all angles for each measure */ if (i == 0) fbuf[j][col] = measure; else if (i < 3) fbuf[j][col] += measure; else fbuf[j][col] = (fbuf[j][col] + measure) / 4.0; } } } } for (i = 0; i < n_outputs; i++) { Rast_put_row(outfd[i], fbuf[i], out_data_type); } } Rast_set_f_null_value(fbuf[0], ncols); for (row = last_row; row < nrows; row++) { for (i = 0; i < n_outputs; i++) { Rast_put_row(outfd[i], fbuf[0], out_data_type); } } G_percent(nrows, nrows, 1); for (i = 0; i < n_outputs; i++) { Rast_close(outfd[i]); Rast_short_history(mapname[i], "raster", &history); Rast_command_history(&history); Rast_write_history(mapname[i], &history); G_free(fbuf[i]); } G_free(fbuf); G_free(data); exit(EXIT_SUCCESS); }