void printErrorMsg(const char * prefix) { char * msgBuf; const char * format=NULL; DWORD dw = GetLastError(); if (dw==WSAECONNRESET) format = "%s: remote host forcibly closed the connection\n"; else if (dw==WSAECONNREFUSED) format = "%s: server refused connection request\n"; else { FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msgBuf, 0, NULL ); } if (format) printq(format, prefix); else { printq("\n%s error(%d): %s\n", prefix, dw, msgBuf); LocalFree(msgBuf); // allocated by FORMAT_MESSAGE_ALLOCATE_BUFFER } }
/* * ncurses_binding_add() * * przypisuje danemu klawiszowi akcjê. * * - key - opis klawisza, * - action - akcja, * - internal - czy to wewnêtrzna akcja interfejsu? * - quiet - czy byæ cicho i nie wy¶wietlaæ niczego? */ void ncurses_binding_add(const char *key, const char *action, int internal, int quiet) { struct binding b, *c = NULL, *d; if (!key || !action) return; memset(&b, 0, sizeof(b)); b.internal = internal; for (d = bindings; d; d = d->next) { if (!xstrcasecmp(key, d->key)) { if (d->internal) { c = d; break; } printq("bind_seq_exist", d->key); return; } } binding_parse(&b, action); if (internal) { b.default_action = xstrdup(b.action); b.default_function = b.function; b.default_arg = xstrdup(b.arg); } if (binding_key(&b, key, (c) ? 0 : 1)) { printq("bind_seq_incorrect", key); xfree(b.action); xfree(b.arg); xfree(b.default_action); xfree(b.default_arg); xfree(b.key); } else { printq("bind_seq_add", b.key); if (c) { xfree(c->action); c->action = b.action; xfree(c->arg); c->arg = b.arg; c->function = b.function; xfree(b.default_action); xfree(b.default_arg); xfree(b.key); c->internal = 0; } if (!in_autoexec) config_changed = 1; } }
/* * ncurses_binding_set() * * it sets some sequence to the given key */ void ncurses_binding_set(int quiet, const char *key, const char *sequence) { struct binding *d; binding_added_t *b; struct binding *binding_orginal = NULL; char *joined = NULL; int count = 0; for (d = bindings; d; d = d->next) { if (!xstrcasecmp(key, d->key)) { binding_orginal = d; break; } } if (!binding_orginal) { printq("bind_doesnt_exist", key); return; } if (!sequence) { char **chars = NULL; char ch; printq("bind_press_key"); nodelay(input, FALSE); while ((ch = wgetch(input)) != ERR) { array_add(&chars, xstrdup(itoa(ch))); nodelay(input, TRUE); count++; } joined = array_join(chars, (" ")); array_free(chars); } else joined = xstrdup(sequence); for (b = bindings_added; b; b = b->next) { if (!xstrcasecmp(b->sequence, joined)) { b->binding = binding_orginal; xfree(joined); goto end; } } b = xmalloc(sizeof(binding_added_t)); b->sequence = joined; b->binding = binding_orginal; LIST_ADD2(&bindings_added, b); end: if (!in_autoexec) config_changed = 1; printq("bind_added"); if (count > bindings_added_max) bindings_added_max = count; }
// Spins forever waiting for connections. For each one that comes // in, create a thread to handle it and go back to waiting for // connections DWORD serverListenThread(LPVOID arg) { SOCKET serverSocket = (SOCKET) arg; sockaddr_in sinRemote; int nAddrSize = sizeof(sinRemote); char host[256]; SOCKET socket; struct socketDescriptor * serverSd; struct socketDescriptor sd = DEFAULT_SOCKET_DESCRIPTOR; sd.description = "client sd"; while (1) { socket = accept(serverSocket, (sockaddr*)&sinRemote, &nAddrSize); if (serverListenSd.exit) { CloseHandle(serverListenSd.hThread); serverListenSd.hThread=NULL; printq("serverListenThread thread exit\n"); ExitThread(0); } if (socket==INVALID_SOCKET) { if (WSAGetLastError()==WSAEINTR) { // WSAEINTR is normal when process ends CloseHandle(serverListenSd.hThread); serverListenSd.hThread=NULL; printq("serverListenThread WSAEINTR thread exit\n"); ExitThread(0); } printq("serverListenThread: accept failed from %s:%u errno %u\n", inet_ntoa(sinRemote.sin_addr), ntohs(sinRemote.sin_port), WSAGetLastError()); } else { HANDLE hThread; printq("\rServer accepted connection from %s on socket %d\n", lookupName(inet_ntoa(sinRemote.sin_addr), host, sizeof(host)), socket); sd.port = ntohs(sinRemote.sin_port); sd.socket = socket; sd.connected = TRUE; serverSd = allocateServerSocketDescriptor(&sd); singleThreadSd = serverSd; if ( !(serverSd->hThread=CreateThread(0, 0, (LPTHREAD_START_ROUTINE) &rxServerThread, (LPVOID) serverSd, 0, NULL)) ) { printErrorMsg("serverListenThread: create rxServerThread"); } } } }
// establish a client side connection int establishConnection(struct socketDescriptor * sd) { // create a stream socket if (!sd->description) sd->description = ""; sd->socket = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in sinRemote; sinRemote.sin_family = AF_INET; if ((sinRemote.sin_addr.s_addr = lookupAddress(sd->host)) == INADDR_NONE) return FALSE; sinRemote.sin_port = htons(sd->port); char hostname[256]; lookupName(inet_ntoa(sinRemote.sin_addr), hostname, sizeof(hostname)); if (sd->socket==INVALID_SOCKET || connect(sd->socket, (sockaddr*)&sinRemote, sizeof(sockaddr_in))==SOCKET_ERROR) { if (sd->lastError != WSAGetLastError()) { sd->lastError = WSAGetLastError(); if (sd->lastError == WSAECONNREFUSED) printq("establishConnection %s: server %s refused connection request\n", szTime(), hostname); else if (sd->lastError == WSAETIMEDOUT) printq("establishConnection %s: server %s connection request timed out\n", szTime(), hostname); else if (!sd->exit) printErrorMsg("establishConnection"); } if (sd->socket != INVALID_SOCKET) { closesocket(sd->socket); sd->socket = INVALID_SOCKET; } sd->connected=FALSE; return FALSE; } else { sd->lastError = NO_ERROR; } printq("Client established connection to %s on socket %d\n", hostname, sd->socket); processServerConnect(sd->host); if (sd->reconnectMsg) sendMsg(sd, sd->reconnectMsg, sd->debugMsg); singleThreadSd = sd; sd->connected=TRUE; return TRUE; }
/* * python_list() * * wy¶wietla listê za³adowanych skryptów. * * 0/-1 */ int python_list(int quiet) { list_t l; if (!modules) printq("python_list_empty"); for (l = modules; l; l = l->next) { struct module *m = l->data; printq("python_list", m->name); } return 0; }
/* * ncurses_binding_delete() * * usuwa akcjê z danego klawisza. */ void ncurses_binding_delete(const char *key, int quiet) { struct binding *b; if (!key) return; for (b = bindings; b; b = b->next) { int i; if (!b->key || xstrcasecmp(key, b->key)) continue; if (b->internal) { printq("bind_seq_incorrect", key); return; } xfree(b->action); xfree(b->arg); if (b->default_action) { b->action = xstrdup(b->default_action); b->arg = xstrdup(b->default_arg); b->function = b->default_function; b->internal = 1; } else { xfree(b->key); for (i = 0; i < KEY_MAX + 1; i++) { if (ncurses_binding_map[i] == b) ncurses_binding_map[i] = NULL; if (ncurses_binding_map_meta[i] == b) ncurses_binding_map_meta[i] = NULL; } LIST_REMOVE2(&bindings, b, NULL); } config_changed = 1; printq("bind_seq_remove", key); return; } printq("bind_seq_incorrect", key); }
/* we return 0 even if rmwatch fails, because xmsg_handle_data checks * if our session is still connected, so it'll ignore unneeded events */ static COMMAND(xmsg_disconnect) { if (!session_connected_get(session)) { printq("not_connected", session_name(session)); return -1; } xmsg_timer_change(session, NULL); if (!timer_remove_session(session, "o")) xdebug("old oneshot resume timer removed"); session_status_set(session, EKG_STATUS_NA); if (quiet == -1) protocol_disconnected_emit(session, format_find("xmsg_umount"), EKG_DISCONNECT_NETWORK); else protocol_disconnected_emit(session, NULL, EKG_DISCONNECT_USER); #ifdef HAVE_INOTIFY if (session->priv && inotify_rm_watch(in_fd, (long int) session->priv)) xdebug2(DEBUG_ERROR, "rmwatch failed"); else xdebug("inotify watch removed: %d", (long int) session->priv); #endif /*HAVE_INOTIFY*/ return 0; }
int body() { char c; myprintf("proc %d starts from body()\n", running->pid); while(1){ printq("freelist ", freeList);// optional: show the freeList printq("readyQueue", readyQueue); // show the readyQueue myprintf("proc %d running: parent=%d\n",running->pid,running->ppid); myprintf("enter a char [s|f] : "); c = getc(); myprintf("%c\n", c); switch(c){ case 'f' : do_kfork(); break; case 's' : do_tswitch(); break; } } }
// override the default debug message when calling sendMsg() void sendMsg(struct socketDescriptor * sd, const char * msg, const char * debugMsg) { if (!sd) { printq("sendMsg: NULL socketDescriptor\n"); return; } sd->debugMsg = debugMsg; sendMsg(sd, msg); }
int main() { creat(7); printq(); enq(9); printq(); outq(); printq(); return 0; }
// receive and process agent/server notifications DWORD rxClientThread(LPVOID arg) { char buffer[1024], msg[2048], * delim; int nBytes; struct socketDescriptor * sd = (struct socketDescriptor *) arg; SOCKET socket=sd->socket; msg[0]='\0'; addSocketDescriptorToClientList(sd); while(!sd->exit) { if (!sd->connected) { if (establishConnection(sd)) socket=sd->socket; else Sleep(10000); } else { nBytes=recv(sd->socket, buffer, sizeof(buffer-1), 0); if (nBytes==0) { // graceful close shutdownConnection(sd); } else if(nBytes==SOCKET_ERROR) { // forceful close if (WSAGetLastError()!=WSAECONNABORTED) { // an aborted connection error is normal on a half closed connection printErrorMsg("rxClientThread"); } shutdownConnection(sd); } else { // concatenate packets into a single carriage return terminated message // or process multiple carriage return terminated messages individually if (strlen(msg) + nBytes > sizeof(msg)) { // prevent an overrun msg[0]='\0'; } buffer[nBytes]='\0'; strcat(msg, buffer); while (delim=strstr(msg, "\r")) { *delim='\0'; processServerMsg(msg, sd); strcpy(msg, delim+1); } } } } CloseHandle(sd->hThread); sd->hThread=NULL; printq("rxClientThread exit host %s socket %d\n", sd->host, socket); ExitThread(0); }
/* * python_unload() * * usuwa z pamiêci podany skrypt. * * - name - nazwa skryptu, * - quiet. * * 0/-1 */ int python_unload(const char *name, int quiet) { list_t l; if (!name) { printq("python_need_name"); return -1; } for (l = modules; l; l = l->next) { struct module *m = l->data; if (strcmp(m->name, name)) continue; gg_debug(GG_DEBUG_MISC, "m->deinit = %p, hmm?\n", m->deinit); if (m->deinit) { PyObject *res = PyObject_CallFunction(m->deinit, "()"); Py_XDECREF(res); Py_XDECREF(m->deinit); } Py_XDECREF(m->handle_msg); Py_XDECREF(m->handle_msg_own); Py_XDECREF(m->handle_connect); Py_XDECREF(m->handle_disconnect); Py_XDECREF(m->handle_status); Py_XDECREF(m->handle_status_own); Py_XDECREF(m->handle_redraw_header); Py_XDECREF(m->handle_redraw_statusbar); Py_XDECREF(m->handle_keypress); Py_XDECREF(m->handle_command_line); Py_XDECREF(m->module); list_remove(&modules, m, 1); printq("python_removed"); return 0; } printq("python_not_found", name); return -1; }
void initTcpServer(const char * host, int port) { serverListenSd.host = host; serverListenSd.port = port; serverListenSd.socket = socketBind(host, port); serverListenSd.hThread = createServerListenThread(serverListenSd.socket); serverListenSd.exit = FALSE; serverListenSd.description = "TCP Server"; printq("Host %s listening on port %d\n", host, port); }
// receive and process client commands DWORD rxServerThread(LPVOID arg) { struct socketDescriptor * sd = (struct socketDescriptor *) arg; char buffer[1024], msg[2048], * delim; int nBytes; LinkedList * l; SOCKET socket = sd->socket; msg[0]='\0'; while(1) { nBytes=recv(socket, buffer, sizeof(buffer-1), 0); buffer[nBytes]='\0'; if (nBytes==0 || nBytes==SOCKET_ERROR || sd->exit) { if (!sd->exit) { if (nBytes==SOCKET_ERROR) { printErrorMsg("rxServerThread"); closesocket(socket); sd->socket = INVALID_SOCKET; } else { // close the connection normally processClientDisconnect(sd); shutdownConnection(sd); } } sd->connected = FALSE; free((char *) sd->host); free((char *) sd->description); CloseHandle(sd->hThread); sd->hThread = NULL; printq("rxServerThread exit socket %d\n", socket); ExitThread(0); } else { // concatenate packets into a single carriage return terminated message // or process multiple carriage return terminated messages sequentially if (strlen(msg) + nBytes > sizeof(msg)) msg[0]='\0'; // prevent an overrun strcat(msg, buffer); while (delim=strstr(msg, "\r")) { *delim='\0'; processClientMsg(msg, sd); strcpy(msg, delim+1); } } } }
// Try to gracefully shut down a connection using a given socket void shutdownConnection(struct socketDescriptor * sd) { sd->connected = FALSE; if (sd->socket==INVALID_SOCKET) return; SOCKET socket = sd->socket; sd->socket=INVALID_SOCKET; SOCKADDR sa; int salen=sizeof(sa); if (getpeername(socket, &sa, &salen) == SOCKET_ERROR) { // calling to shutdown an unconnected socket is normal if (WSAGetLastError() != WSAENOTCONN) printErrorMsg("shutdownConnection getpeername"); } printq("Shutdown connection host %s socket %d\n", sd->host, socket); // Disallow any further data sends. This will tell the other side // that we want to go away now. If we skip this step, we don't // shut the connection down nicely. if (shutdown(socket, SD_SEND) == SOCKET_ERROR) { printErrorMsg("shutdownConnection shutdown"); } // Receive any extra data still sitting on the socket. After all // data is received, this call will block until the remote host // acknowledges the TCP control packet sent by the shutdown above. // Then we'll get a 0 back from recv, signalling that the remote // host has closed its side of the connection. char acReadBuffer[KBUFFERSIZE]; while (1) { int afterBytes = recv(socket, acReadBuffer, KBUFFERSIZE, 0); if (afterBytes == SOCKET_ERROR) { if (WSAGetLastError() != WSAECONNRESET) { // ignore a recv error if the remote host forcibly closed the connection printErrorMsg("shutdownConnection recv"); } closesocket(socket); return; } else if (afterBytes); // read and ignore extraneous data else break; } // Close the socket. if (closesocket(socket) == SOCKET_ERROR) printErrorMsg("shutdownConnection close socket"); return; }
int main(){ int q[maxsize],head=1,tail=1,i; srand(time(NULL)); printf("enqueue 5:\n"); for(i=0;i<5;i++) enqueue(q,&head,&tail,maxsize,rand()%100); printf("\nhead is %d tail is %d\n",head,tail); printf("dequeue 6:\n"); for(i=0;i<6;i++) printf("%d\t",dequeue(q,&head,&tail,maxsize)); printf("\nhead is %d tail is %d\n",head,tail); printf("enqueue 10:\n"); for(i=0;i<10;i++) enqueue(q,&head,&tail,maxsize,rand()%100); printf("\nhead is %d tail is %d\n",head,tail); printf("dequeue 4:\n"); for(i=0;i<4;i++) printf("%d\t",dequeue(q,&head,&tail,maxsize)); printf("\nhead is %d tail is %d\n",head,tail); printf("dequeue 1:\n"); printf("%d\t",dequeue(q,&head,&tail,maxsize)); printf("\nhead is %d tail is %d\n",head,tail); printf("enqueue 10:\n"); for(i=0;i<10;i++) enqueue(q,&head,&tail,maxsize,rand()%100); printf("\nhead is %d tail is %d\n",head,tail); printf("dequeue 10:\n"); for(i=0;i<10;i++) printf("%d\t",dequeue(q,&head,&tail,maxsize)); printf("\nhead is %d tail is %d\n",head,tail); printf("enqueue 10:\n"); for(i=0;i<10;i++) enqueue(q,&head,&tail,maxsize,rand()%100); printq(q,&head,&tail,maxsize); printf("\nhead is %d tail is %d\n",head,tail); printf("dequeue 10:\n"); for(i=0;i<10;i++) printf("%d\t",dequeue(q,&head,&tail,maxsize)); printq(q,&head,&tail,maxsize); printf("\nhead is %d tail is %d\n",head,tail); return 0; }
void sendMsg(struct socketDescriptor * sd, const char * msg) { if (!sd) { printq("sendMsg: NULL socketDescriptor\n"); return; } printq("Send msg to host %s: %s\n", sd->host, sd->debugMsg ? sd->debugMsg : msg); int len = strlen(msg); char * buf = (char *) malloc(len + 2); const char * crMsg; crMsg = msg[len-1]=='\r' ? msg : strcat(strcpy(buf, msg), "\r"); if (send(sd->socket, crMsg, strlen(crMsg), 0)==SOCKET_ERROR && WSAGetLastError()!=WSAECONNABORTED) { // an aborted connection error is normal on a half closed connection printErrorMsg("sendMsg"); } free(buf); }
/* * handle_change50() * * zajmuje siê obs³ug± zmiany danych w katalogu publicznym. * * - s - sesja * - e - opis zdarzenia */ void gg_session_handler_change50(session_t *s, struct gg_event *e) { gg_private_t *g = session_private_get(s); int quiet; if (!g) return; quiet = (g->quiet & GG_QUIET_CHANGE); printq("change"); }
int main () { int x, n, i; unsigned int* spi = (unsigned int *)0177714; puts ("hello.jpg\n"); disk_sbuf(buffer); do { puts("SD "); x = pf_mount(&fatfs); puts(x == FR_OK ? "mounted\n" : "fail\n"); } while (x != FR_OK); puts("Opening BK0010/ "); puts(pf_opndir(&dir, "BK0010") == FR_OK ? "opened\n" : "fail\n"); /*return 0;*/ for (x=0;; x++) { if (pf_rddir(&dir,&fno) == FR_OK) { if (!fno.fname[0]) break; puts(fno.fname); if (fno.fattrib & AM_DIR) { puts("/"); } else { for(i=0; fname[i+7]=fno.fname[i]; i++); puts("\nTrying to open: "); puts(fname); puts(" size=0x"); printq(fno.fsize,1); if (pf_open(fname) == FR_OK) { for(; pf_read(buf, sizeof(buf), &n) == FR_OK;) { /*putchar('[');printhex(n);putchar(']');*/ for (i = 0; i < n; i++) { putchar(buf[i]); } if (n < sizeof(buf)) break; } } else { puts(" - couldn't open"); } } puts("\n"); } } return 0; }
PyObject *ekg_cmd_echo(PyObject * self, PyObject * args) { char *str = NULL; int quiet = 0; if (!PyArg_ParseTuple(args, "s", &str)) { return NULL; } printq("generic", str); Py_INCREF(Py_None); return Py_None; }
/* * python_run() * * uruchamia jednorazowo skrypt pythona. * * 0/-1 */ int python_run(const char *filename, int quiet) { FILE *f = fopen(filename, "r"); if (!f) { printq("python_not_found", filename); return -1; } PyRun_SimpleFile(f, (char*) filename); fclose(f); return 0; }
int body() { char c; printf("proc %d resumes to body()\n", running->pid); while (1) { printf("--------------------------------------\n"); printq(&freeList); printq(&readyQueue); printf("--------------------------------------\n"); printf("proc %d running: parent=%d enter a char[s|f|w|q|u] : ", running->pid, running->parent->pid); c = getc(); printf("%c\n", c); switch(c) { case 's': do_tswitch(); break; case 'f': do_kfork(); break; case 'w': do_wait(); break; case 'q': do_exit(); break; case 'u': goUmode(); break; } } }
void test() { Queue<int> q; auto q1 = q.push_back(1); q1.printq(); auto q2 = q1.push_back(2); q1.printq(); q2.printq(); auto q3 = q2.push_back(3); q1.printq(); q2.printq(); q3.printq(); std::cout << "--Popping\n\n"; std::cout << "pop " << q3.front() << std::endl; auto q4 = q3.pop_front(); q4.printq(); std::cout << "pop " << q4.front() << std::endl; auto q5 = q4.pop_front(); q5.printq(); std::cout << "pop " << q5.front() << std::endl; auto q6 = q5.pop_front(); q6.printq(); }
static COMMAND(sniff_command_disconnect) { if (!session_connected_get(session)) { printq("not_connected", session_name(session)); return -1; } protocol_disconnected_emit(session, NULL, EKG_DISCONNECT_USER); if (!GET_DEV(session)) { debug_error("sniff_command_disconnect() not dev?!\n"); return -1; } pcap_close(GET_DEV(session)); session->priv = NULL; return 0; }
static K printitem(K x, int index) { switch (xt) { case 0: printq(kK(x)[index]); break; case 1: showatom(kb, kG, x, index); break; case 4: showatom(kg, kG, x, index); break; case 5: showatom(kh, kH, x, index); break; case 6: showatom(ki, kI, x, index); break; case 7: showatom(kj, kJ, x, index); break; case 8: showatom(ke, kE, x, index); break; case 9: showatom(kf, kF, x, index); break; case 10: showatom(kc, kC, x, index); break; case 11: showatom(ks, kS, x, index); break; case 14: showatom(kd, kI, x, index); break; case 15: showatom(kz, kF, x, index); break; default: return krr("notimplemented"); } return (K) 0; }
static COMMAND(xmsg_connect) { if (session_connected_get(session)) { printq("already_connected", session_name(session)); return -1; } if (command_exec(NULL, session, "/session --lock", 0) == -1) return -1; if (xmsg_add_watch(session, session_uid_get(session)+XMSG_UID_DIROFFSET)) { print("conn_failed", format_find("xmsg_addwatch_failed"), session_name(session)); return -1; } session_status_set(session, EKG_STATUS_AVAIL); protocol_connected_emit(session); xmsg_iterate_dir(0, (void*) session); xmsg_timer_change(session, "rescan_timer"); return 0; }
/* * python_load() * * ³aduje skrypt pythona o podanej nazwie z ~/.gg/scripts * * - name - nazwa skryptu, * - quiet. * * 0/-1 */ int python_load(const char *name, int quiet) { PyObject *module, *init; struct module m; char *name2; if (!name) { printq("python_need_name"); return -1; } if (strchr(name, '/')) { printq("python_wrong_location", prepare_path("scripts", 0)); return -1; } name2 = xstrdup(name); if (strlen(name2) > 3 && !strcasecmp(name2 + strlen(name2) - 3, ".py")) name2[strlen(name2) - 3] = 0; module = PyImport_ImportModule(name2); if (!module) { printq("python_not_found", name2); PyErr_Print(); xfree(name2); return -1; } if ((init = PyObject_GetAttrString(module, "init"))) { if (PyCallable_Check(init)) { PyObject *result = PyObject_CallFunction(init, "()"); if (result) { int resulti = PyInt_AsLong(result); if (!resulti) { } Py_XDECREF(result); } } Py_XDECREF(init); } memset(&m, 0, sizeof(m)); m.name = xstrdup(name2); m.module = module; m.deinit = python_get_func(module, "deinit"); m.handle_msg = python_get_func(module, "handle_msg"); m.handle_msg_own = python_get_func(module, "handle_msg_own"); m.handle_connect = python_get_func(module, "handle_connect"); m.handle_disconnect = python_get_func(module, "handle_disconnect"); m.handle_status = python_get_func(module, "handle_status"); m.handle_status_own = python_get_func(module, "handle_status_own"); m.handle_redraw_header = python_get_func(module, "handle_redraw_header"); m.handle_redraw_statusbar = python_get_func(module, "handle_redraw_statusbar"); m.handle_keypress = python_get_func(module, "handle_keypress"); m.handle_command_line = python_get_func(module, "handle_command_line"); PyErr_Clear(); list_add(&modules, &m, sizeof(m)); xfree(name2); return 0; }
/***************************************************** * main function *****************************************************/ int main(int argc, char** argv) { freopen("i.txt", "r", stdin); freopen("o.txt", "w", stdout); // read input file if(input(stdin)) { printf("Read successfully!\n"); } putchar('\n'); // construct SDF graph constructSDF(); printMatrix(stdout); putchar('\n'); // solve vector q printf("==== Solve Matrix ====\n"); if(solveMatrix()) { printf("Solve Matrix successfully!\n"); printq(stdout); putchar('\n'); } else { printf("Can't solve Matrix...\n"); exit(1); } putchar('\n'); // translate SDF to DAG printf("======== DAG ========\n"); if(SDF2DAG()) { printDAG(stdout); } else { printf("DAG error!\n"); exit(2); } putchar('\n'); #ifndef NDEBUG // calc Static b-level printf("======== SBL ========\n"); calcBLevel(); printBLevel(stdout); putchar('\n'); #endif // calc shortest Message Route printf("====== NextHop ======\n"); calcNextHop(); printNextHop(stdout); putchar('\n'); // Schedules printf("===== Schedules =====\n"); if(doDLS()) { printSchedules(stdout); putchar('\n'); printf(" ---- Task ----\n"); printTaskSchedules(stdout); FILE *datafile = fopen("data.txt", "w"); if(datafile == NULL){ printf("Error open data.txt file!\n"); exit(3); } printScheduleData(datafile); fclose(datafile); } else { printf("Schedule failed...\n"); exit(4); } putchar('\n'); return 0; }
void am (void) { double t; double halfstep = HALF * tstep; double sconst = tstep / 24.0; /* step constant */ double onesixth = 1.0 / 6.0; /* Runge-Kutta startup */ for (it = 0, t = tstart; it <= PASTVAL && !STOPR; t = tstart + (++it) * tstep) { symtab->sy_value = symtab->sy_val[0] = t; field(); for (fsp = dqueue; fsp != NULL; fsp = fsp->sy_link) { int j; for (j = it; j > 0; j--) { fsp->sy_val[j] = fsp->sy_val[j-1]; fsp->sy_pri[j] = fsp->sy_pri[j-1]; } fsp->sy_pri[0] = fsp->sy_prime; fsp->sy_val[0] = fsp->sy_value; } /* output */ printq(); if (it == PASTVAL) break; /* startup complete */ for (fsp = dqueue; fsp != NULL; fsp = fsp->sy_link) { fsp->sy_k[0] = tstep * fsp->sy_prime; fsp->sy_value = fsp->sy_val[0] + HALF * fsp->sy_k[0]; } symtab->sy_value = t + halfstep; field(); for (fsp = dqueue; fsp != NULL; fsp = fsp->sy_link) { fsp->sy_k[1] = tstep * fsp->sy_prime; fsp->sy_value = fsp->sy_val[0] + HALF * fsp->sy_k[1]; } symtab->sy_value = t + halfstep; field(); for (fsp = dqueue; fsp != NULL; fsp = fsp->sy_link) { fsp->sy_k[2] = tstep * fsp->sy_prime; fsp->sy_value = fsp->sy_val[0] + fsp->sy_k[2]; } symtab->sy_value = t + tstep; field(); for (fsp = dqueue; fsp != NULL; fsp = fsp->sy_link) fsp->sy_k[3] = tstep * fsp->sy_prime; for (fsp = dqueue; fsp != NULL; fsp = fsp->sy_link) { fsp->sy_value = fsp->sy_val[0] + onesixth * (fsp->sy_k[0] + TWO * fsp->sy_k[1] + TWO * fsp->sy_k[2] + fsp->sy_k[3]); } } /* predictor - corrector */ while (!STOPA) { /* Adams-Bashforth predictor */ for (fsp = dqueue; fsp != NULL ; fsp = fsp->sy_link) { fsp->sy_value = fsp->sy_val[0] + (sconst) * (55 * fsp->sy_pri[0] -59 * fsp->sy_pri[1] +37 * fsp->sy_pri[2] -9 * fsp->sy_pri[3]); } symtab->sy_val[0] = symtab->sy_value = t = tstart + (++it) * tstep; field(); /* Adams-Moulton corrector */ for (fsp = dqueue; fsp != NULL; fsp = fsp->sy_link) { fsp->sy_value = fsp->sy_val[0] + (sconst) * (9 * fsp->sy_prime +19 * fsp->sy_pri[0] -5 * fsp->sy_pri[1] + fsp->sy_pri[2]); } field(); /* cycle indices */ for (fsp = dqueue; fsp != NULL; fsp = fsp->sy_link) { int j; for (j = PASTVAL; j > 0; j--) { fsp->sy_val[j] = fsp->sy_val[j-1]; fsp->sy_pri[j] = fsp->sy_pri[j-1]; } fsp->sy_val[0] = fsp->sy_value; fsp->sy_pri[0] = fsp->sy_prime; } /* output */ printq(); } }