static void startLog(char *path, char *logFileNam) { char logFilePath[MAXPATH+1]; if(path) { trim_trailing_slash(path); pgxcCtlMkdir(path); if(logFileNam) { if (logFileNam[0] == '/') { fprintf(stderr, "ERROR: both --logdir and --logfile are specified and logfile was abosolute path.\n"); exit(1); } if (path[0] == '/') snprintf(logFilePath, MAXPATH, "%s/%s", path, logFileNam); else snprintf(logFilePath, MAXPATH, "%s/%s/%s", pgxc_ctl_home, path, logFileNam); initLog(NULL, logFilePath); } else { if (path[0] == '/') initLog(path, NULL); else { snprintf(logFilePath, MAXPATH, "%s/%s", pgxc_ctl_home, path); initLog(logFilePath, NULL); } } } else { if (logFileNam && logFileNam[0] == '/') { /* This is used as log file path */ initLog(NULL, logFileNam); return; } else { snprintf(logFilePath, MAXPATH, "%s/pgxc_log", pgxc_ctl_home); pgxcCtlMkdir(logFilePath); initLog(logFilePath, NULL); } } return; }
/*====================================================================*/ int freeProgram(DFHEIBLK *inDfheiptr, TraceParms* inTraceParms, CICSProgramDesc* pProgramDesc, Message* pRequestMessage, Message* pResponseMessage) { int rc = OK_CODE; dfheiptr = inDfheiptr; g_pTraceParms = inTraceParms; initLog(dfheiptr, inTraceParms); if (strlen(pProgramDesc->CICSChannel) > 0 && pProgramDesc->CICSChannel[0] != ' ') { rc = freeChannel(dfheiptr, g_pTraceParms, pProgramDesc, pRequestMessage, pResponseMessage); } else { rc = freeCommarea(dfheiptr, g_pTraceParms, pProgramDesc, pRequestMessage, pResponseMessage); } return rc; }
void SeafileApplet::start() { refreshQss(); configurator_->checkInit(); initLog(); account_mgr_->start(); certs_mgr_->start(); #if defined(Q_OS_WIN32) QString crash_rpt_path = QDir(configurator_->ccnetDir()).filePath("logs/seafile-crash-report.txt"); if (!g_setenv ("CRASH_RPT_PATH", toCStr(crash_rpt_path), FALSE)) qWarning("Failed to set CRASH_RPT_PATH env variable.\n"); #endif // // start daemons // daemon_mgr_->startCcnetDaemon(); connect(daemon_mgr_, SIGNAL(daemonStarted()), this, SLOT(onDaemonStarted())); }
/** * initLog - 初始化一个日志文件 * * @handle: [in] 全局句柄 * @logName: [in] 日志文件名 * @logSuffix [in] 日志文件的后缀名 * * Note: 如果传入的dir是非法的或是不存在的,该函数会返回失败 * * return * 0 成功 * <0 失败 */ int MWriteLog::initLog(HANDLE handle, char *logName, char *logSuffix) { char szPath[256] = {0}; char gcCliLog[256] = {0}; /* gcClient.log的绝对路径 */ bool writeDisk = false; /* 默认不写日志 */ int rc; /*定义需要生成日志文件所创建的文件名(在handle所在的目录下)*/ #define GCLOG "gcClient.log" m_handle = handle; rc = ::GetModuleFileName((HMODULE)handle, szPath, sizeof(szPath)-1); if(rc == 0) return BUILD_ERROR(_OSerrno(), 0); rc = _getDir(szPath, strlen(szPath)); if(rc != 0) return rc; rc = _snprintf(gcCliLog, sizeof(gcCliLog)-1-sizeof(GCLOG), szPath); if(gcCliLog[strlen(gcCliLog)-1] != '\\'){ gcCliLog[strlen(gcCliLog)] = '\\'; ++rc; } _snprintf(gcCliLog+rc, sizeof(GCLOG), "%s", GCLOG); if(_access(gcCliLog, 0) != -1)/*存在*/ writeDisk = true; return initLog(szPath, writeDisk, logName, logSuffix); #undef GCLOG }
void SeafileApplet::start() { refreshQss(); configurator_->checkInit(); initLog(); account_mgr_->start(); certs_mgr_->start(); AvatarService::instance()->start(); SeahubNotificationsMonitor::instance()->start(); #if defined(Q_WS_WIN) QString crash_rpt_path = QDir(configurator_->ccnetDir()).filePath("logs/seafile-crash-report.txt"); if (!g_setenv ("CRASH_RPT_PATH", toCStr(crash_rpt_path), FALSE)) qDebug("Failed to set CRASH_RPT_PATH env variable.\n"); #endif daemon_mgr_->startCcnetDaemon(); connect(daemon_mgr_, SIGNAL(daemonStarted()), this, SLOT(onDaemonStarted())); }
int log(const char* format, ...) { initLog(); int numWritten = 0; if (newline) { time_t rawtime; time(&rawtime); localtime_s(&timeInfo, &rawtime); strftime(timeBuf, 64, "%y-%m-%d %H:%M:%S: ", &timeInfo); numWritten = fprintf(logFile, "%s", timeBuf); } va_list args; va_start(args, format); numWritten += vfprintf(logFile, format, args); va_end(args); char last_char = format[strlen(format) - 1]; newline = (last_char == '\n'); fflush(logFile); closeLog(); return numWritten; }
int main(int argc, char **argv) { initLog(); sfera_webserver::http_server_config serverConfig; serverConfig.port = 8000; serverConfig.wwwHomeDir = "./www_home"; serverConfig.host = "127.0.0.1"; b_po::options_description desc("Server usage"); fillProgramOptions(desc); b_po::variables_map cmdLineOptions; b_po::store(b_po::command_line_parser(argc, argv).options(desc).run(), cmdLineOptions); b_po::notify(cmdLineOptions); if (cmdLineOptions.count("help")) { std::cout << desc << std::endl; return 0; } if (cmdLineOptions.count("port") == 1) serverConfig.port = cmdLineOptions["port"].as<unsigned>(); if (cmdLineOptions.count("dir") == 1) serverConfig.wwwHomeDir = cmdLineOptions["dir"].as<std::string>(); if (cmdLineOptions.count("host") == 1) serverConfig.host = cmdLineOptions["host"].as<std::string>(); sfera_webserver::master_listener listener(std::move(serverConfig)); listener.run(); return 0; }
int main(void) { // local variables pthread_t l_thread; int l_thread_id = 1; int l_thread_return_code = 0; int l_counter = 0; int l_result = 0; double pi = 3.14159265358979323846; puts("motionplatform info : started."); testModelOnly(); l_result = loadSettings(); l_result = initLog(); printf("motionplatform info : setting loaded %d - %d - %d\n", l_result, parameterX, parameterY); printf("motionplatform info : creating thread %d\n", l_thread_id); l_shared_data.thread_id = l_thread_id; l_shared_data.mode = 0; l_shared_data.stop = 0; l_shared_data.speed = 1.0; l_thread_return_code = pthread_create(&l_thread, NULL, run, (void *) &l_shared_data); if (l_thread_return_code) { printf( "motionplatform error: return code from pthread_create() is %d\n", l_thread_return_code); exit(-1); } while (STOP_PROGRAM == FALSE) { #if IBM Sleep(WAIT_TIME); #endif #if LIN sleep(WAIT_TIME / 1000); #endif // update pitch and bank l_shared_data.pitch = (3.4 - l_counter / 10.0) * pi/180.0; l_shared_data.bank = (2.4 + l_counter / 10.0) * pi/180.0; l_counter++; printf("motionplatform info : running %d\n", l_counter); printf( "motionplatform info : pitch: %f bank: %f / cyl1: %f - cyl2: %f\n", l_shared_data.pitch, l_shared_data.bank, l_shared_data.elongation1, l_shared_data.elongation2); if (l_counter > 10) { STOP_PROGRAM = TRUE; } } l_shared_data.stop = 1; l_result = saveSettings(); printf("motionplatform info : save settings: %d\n", l_result); l_result = closeLog(); printf("motionplatform info : exit program.\n"); return EXIT_SUCCESS; }
/** * init. Method that stores the parentBroker. * @param parentBroker Parent broker of the component. **/ void Component::init(const string newName, const AL::ALPtr<AL::ALBroker> parentBroker) { this->parentBroker = parentBroker; name = newName; initLog(name); Register::getInstance()->regist(name, this); }
int main(int argc, char *argv[]) { initLog(); QApplication a(argc, argv); ats::display::GuiFactory *factory = ats::display::GuiFactory::getInstance(); factory->showAtsMainWindow(); return a.exec(); }
int main() { int appFailureCode = 1; int sigError = -1; //Ready to catch signals sigset_t mask; sigemptyset(&mask); sigaddset(&mask, SIGUSR1); sigaddset(&mask, SIGUSR2); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGTERM); if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) { sigError = errno; } initLog(false); Led redLed(24); redLed.on(); try{ if(sigError != -1){ throw Error::system(sigError, "Unable to listen to signals: "); } Chapi chapi(mask, redLed); chapi.exec(); appFailureCode = 0; } catch(Error &e){ log(LOG_ERR, "%s", e.what()); redLed.blinkNumber((e.getKind() == Error::configError) ? 2 : ((e.getKind() == Error::systemError) ? 3 : 4)); loop(); } catch(std::exception &e){ log(LOG_ERR, "%s", e.what()); redLed.blinkNumber(5); loop(); } catch(char const*err) { log(LOG_ERR, "%s", err); redLed.blinkNumber(5); loop(); } catch(...){ log(LOG_ERR, "unknown error"); redLed.blinkNumber(5); loop(); } redLed.off(); log(LOG_INFO, "chapi ended"); return appFailureCode; }
/*====================================================================*/ int invokeProgram(DFHEIBLK *inDfheiptr, TraceParms* inTraceParms, CICSProgramDesc* pProgramDesc, Message* pRequestMessage, Message* pResponseMessage) { int rc; HeaderPartContent* pRequestHeaderPartContent = (HeaderPartContent*) pRequestMessage->pHeaderPart->content; dfheiptr = inDfheiptr; g_pTraceParms = inTraceParms; initLog(dfheiptr, inTraceParms); initProgramDesc(pProgramDesc); if (g_pTraceParms->traceMode == TRUE_CODE) { traceMessage(MODULE_NAME, "About to invoke program"); } /* Parse the request header key/value pairs */ rc = parseKeyValues( pRequestHeaderPartContent->keyValuesSize.as_int, pRequestHeaderPartContent + 1, pProgramDesc); /* Link to the target program */ if (OK_CODE == rc) { if (strlen(pProgramDesc->CICSChannel) > 0 && pProgramDesc->CICSChannel[0] != ' ') { rc = linkChannel(dfheiptr, g_pTraceParms, pProgramDesc, pRequestMessage, pResponseMessage); } else { rc = linkCommarea(dfheiptr, g_pTraceParms, pProgramDesc, pRequestMessage, pResponseMessage); } } if (g_pTraceParms->traceMode == TRUE_CODE) { if (ERROR_CODE == rc) { traceMessage(MODULE_NAME, "Invoke program failed"); } else { traceMessage(MODULE_NAME, "Return from invoke program"); } } return rc; }
void SeafileApplet::start() { configurator_->checkInit(); tray_icon_->show(); initLog(); account_mgr_->start(); daemon_mgr_->startCcnetDaemon(); connect(daemon_mgr_, SIGNAL(daemonStarted()), this, SLOT(onDaemonStarted())); }
pthread_t daemonStart(unsigned int window, unsigned short basePort, char *logName) { pthread_t thread; ViewerWindow = window; initLog(logName); daemonPort = findPort(basePort,DEFAULT_END); srvSock = listenOnPort(daemonPort); fprintf(logfd, "\nSet GLSTUB var in guest to point to port %hu\n", daemonPort); if (pthread_create(&thread,NULL,acceptLoop,NULL)) fail("couldn't create thread"); return thread; }
Log* OdbcLogFactory::create() { QF_STACK_PUSH(OdbcLogFactory::create) std::string database; std::string user; std::string connectionString; init( m_settings.get(), database, user, connectionString ); OdbcLog* result = new OdbcLog( database, user, connectionString ); initLog( m_settings.get(), *result ); return result; QF_STACK_POP }
int main() { int i = 0; int ret = 0; initLog(NULL, LOG_DEBUG, 10240, 0); setDaemon_s(0); ret = setSockFun_s(LOG_TYPE_FUN, &send_data); printf("%d\n", ret); for (i = 0; i < 100; ++i) LogErr("hello world %d", i); finiLog_s(); return 0; }
int main() { int k = 1; int *pointer = NULL; if( !initLog(INFO, "log_file.txt") ) { printf("Error with init log file\n"); return 0; } LOG(INFO, "This is log file"); LOG(INFO, "%s%d", "Value of var k is equal to ", k); if(!pointer) { LOG(ERROR, "Error: address of the pointer %p, its value is %p", &pointer, pointer); } closeLogFile(); return 0; }
Log* OdbcLogFactory::create( const SessionID& s ) { QF_STACK_PUSH(OdbcLogFactory::create) std::string database; std::string user; std::string connectionString; Dictionary settings; if( m_settings.has(s) ) settings = m_settings.get( s ); init( settings, database, user, connectionString ); OdbcLog* result = new OdbcLog( s, database, user, connectionString ); initLog( settings, *result ); return result; QF_STACK_POP }
ConsoleWindow::ConsoleWindow(ProjectBase* project,QStringList commands,QWidget *parent) : QMainWindow(parent), _ui(new Ui::ConsoleWindowClass) { this->resize(800, 600); this->setStyleSheet("QMainWindow::separator {height:0;width:0}"); //************************ // Basic initialization //************************ _ui->setupUi(this); _project = project; _commands = commands; actualizeGuiFromProject(); initLog(); }
int main(int argc, char *argv[]) { initLog(); LOG("main", "Starting Where's Wally? ..."); /* Initialize service */ sef_startup(); /* Enable IO-sensitive operations for ourselves */ sys_enable_iop(SELF); printf("Starting \"Where's Wally?\" ....\n"); initGraphics(MODE_1280_1024); WallyNIX* wally = (WallyNIX*) startWallyNIX(); while (!wally->exit) { updateWallyNIX(wally); if (!wally->exit) { if (wally->timerFPS->ticked) { wally->timerFPS->ticked = 0; drawWallyNIX(wally); copyToMouseBuffer(); if (getMouse()->draw) { drawMouse(); } copyToVideoMem(); } } } stopWallyNIX(wally); exitGraphics(); LOG("main", "Terminated Where's Wally? ..."); printf("\"Where's Wally?\" exited successfully.\n"); return EXIT_SUCCESS; }
static void init(bool pDaemon, const char *pLogName, const char *pSafeDir) { if (pDaemon) { forkChildAndExit(); becomeSessionLeader(); initSignals(); forkChildAndExit(); // guarantee daemon is detached from a terminal permanently setFilePermissions(); closeAllOpenFileDescrtiptors(); } // always do the following initLog(pLogName); moveToSafeDirectory(pSafeDir); if (pDaemon) { notice("Started as daemon."); } else { notice("Started as interactive program."); } }
/*====================================================================*/ int freeCommarea(DFHEIBLK *inDfheiptr, TraceParms* inTraceParms, CICSProgramDesc* pProgramDesc, Message* pRequestMessage, Message* pResponseMessage) { int rc = OK_CODE; dfheiptr = inDfheiptr; g_pTraceParms = inTraceParms; initLog(dfheiptr, inTraceParms); if (g_pTraceParms->traceMode == TRUE_CODE) { traceMessage(MODULE_NAME, "Entered freeCommarea"); } rc = freeMessage(pRequestMessage); rc = freeMessage(pResponseMessage); if (g_pTraceParms->traceMode == TRUE_CODE) { traceMessage(MODULE_NAME, "Return from freeCommarea"); } return rc; }
void Log::open(std::string fileName, std::string fileExtension) { string outputFile = G->SOLUTION_DIR + "Visor\\Logs\\" + fileName + "." + fileExtension; file = new std::ofstream(); file->open (outputFile.c_str(), ios::out | ios::trunc); initLog(); }
int main(int argc, char **argv) { // ------------------------------------------------------------------------ // Handle commandline arguments if (argc < 5) { printf("usage: emulator -p <port> -f <filename>\n"); exit(1); } char *portStr = NULL; const char *filename = NULL; int cmd; while ((cmd = getopt(argc, argv, "p:f:")) != -1) { switch(cmd) { case 'p': portStr = optarg; break; case 'f': filename = optarg; break; case '?': if (optopt == 'p' || optopt == 'f') fprintf(stderr, "Option -%c requires an argument.\n", optopt); else if (isprint(optopt)) fprintf(stderr, "Unknown option -%c.\n", optopt); else fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt); exit(EXIT_FAILURE); break; default: printf("Unhandled argument: %d\n", cmd); exit(EXIT_FAILURE); } } printf("Port : %s\n", portStr); printf("File Name : %s\n", filename); // Convert program args to values int emulPort = atoi(portStr); int maxTime = 1500; int minTime = 500; // Validate the argument values if (emulPort <= 1024 ||emulPort >= 65536) ferrorExit("Invalid emul port"); puts(""); srand(time(NULL)); initLog("log_file.txt"); // ------------------------------------------------------------------------ // Setup emul address info struct addrinfo ehints; bzero(&ehints, sizeof(struct addrinfo)); ehints.ai_family = AF_INET; ehints.ai_socktype = SOCK_DGRAM; ehints.ai_flags = AI_PASSIVE; char localhost[80]; gethostname(localhost, sizeof(localhost)); // Get the emul's address info struct addrinfo *emulinfo; int errcode = getaddrinfo(localhost, portStr, &ehints, &emulinfo); if (errcode != 0) { fprintf(stderr, "emul getaddrinfo: %s\n", gai_strerror(errcode)); exit(EXIT_FAILURE); } // Loop through all the results of getaddrinfo and try to create a socket for emul int sockfd; struct addrinfo *sp; for(sp = emulinfo; sp != NULL; sp = sp->ai_next) { // Try to create a new socket sockfd = socket(sp->ai_family, sp->ai_socktype, sp->ai_protocol); if (sockfd == -1) { perror("Socket error"); continue; } // Try to bind the socket if (bind(sockfd, sp->ai_addr, sp->ai_addrlen) == -1) { perror("Bind error"); close(sockfd); continue; } break; } if (sp == NULL) perrorExit("Send socket creation failed"); else printf("emul socket created.\n"); struct sockaddr_in *tmp = (struct sockaddr_in *)sp->ai_addr; unsigned long eIpAddr = tmp->sin_addr.s_addr; //printf("eIpAddr: %lu\n", eIpAddr); initTable(filename, tmp); exit(0); // ------------------------------------------------------------------------ // The Big Loop of DOOM struct sockaddr_in *nextSock; int shouldForward; fd_set fds; struct timespec *tv = malloc(sizeof(struct timespec)); tv->tv_sec = (long) 0; tv->tv_nsec = 0; int retval = 0; int numRecv = 0; int routesMade = 0; unsigned long long start; struct packet *dpkt; struct ip_packet *pkt = malloc(sizeof(struct ip_packet)); void *msg = malloc(sizeof(struct ip_packet)); for (;;) { FD_ZERO(&fds); FD_SET(sockfd, &fds); start = getTimeMS(); retval = pselect(sockfd + 1, &fds, NULL, NULL, tv, NULL); // ------------------------------------------------------------------------ // receiving half if (retval > 0 /*&& routesMade == 1*/) { // Receive and forward packet printf("retval > 0\n"); bzero(msg, sizeof(struct ip_packet)); size_t bytesRecvd = recvfrom(sockfd, msg, sizeof(struct ip_packet), 0, NULL, NULL); if (bytesRecvd == -1) { perror("Recvfrom error"); fprintf(stderr, "Failed/incomplete receive: ignoring\n"); continue; } // Deserialize the message into a packet bzero(pkt, sizeof(struct ip_packet)); deserializeIpPacket(msg, pkt); dpkt = (struct packet *)pkt->payload; printIpPacketInfo(pkt, NULL); // Check packet type to see if any action needs to be taken nextSock = malloc(sizeof(struct sockaddr_in)); if (dpkt->type == 'T') { if (dpkt->len == 0) { bzero(nextSock, sizeof(struct sockaddr_in)); shouldForward = 1; nextSock->sin_family = AF_INET; nextSock->sin_addr.s_addr = htonl(pkt->src); nextSock->sin_port = htons(pkt->srcPort); pkt->src = eIpAddr; pkt->srcPort = emulPort; } else { dpkt->len--; shouldForward = nextHop(pkt, nextSock); } } else if (dpkt->type == 'S') { /*if ((pkt->dest == eIpAddr && pkt->destPort == emulPort) || dpkt->len == 0) { dpkt = createNeighborPkt(); bzero(pkt, sizeof(struct ip_packet)); pkt->length = dpkt->len + HEADER_SIZE; pkt->priority = 0; memcpy(pkt->payload, dpkt, sizeof(struct packet)); }*/ if (updateLSP(pkt)) { floodLSP(sockfd, tmp, pkt); } shouldForward = 0; routesMade = 0; } else { shouldForward = nextHop(pkt, nextSock); } // Forward the packet if there is an entry for it if (shouldForward) { printf("send packet\n"); //printf("socket is %lu %u", nextSock->sin_addr.s_addr, nextSock->sin_port); sendIpPacketTo(sockfd, pkt, (struct sockaddr*)nextSock); free(nextSock); } else { logP(pkt, "No forwarding entry found"); } // update timespec long sec = tv->tv_sec - (long)((getTimeMS() - start) / 1000); long nsec = tv->tv_nsec - (long)(1000000 * ((getTimeMS() - start) % 1000)); if (nsec < 0) { nsec = 1000000 * 1000 + nsec; sec--; } if (sec < 0 || !numRecv) { sec = 0; nsec = 0; } tv->tv_sec = sec; tv->tv_nsec = nsec; } if (retval == 0 || routesMade == 0) { // ------------------------------------------------------------------------ // refresh forward table printf("retval == 0\n"); if (retval == 0) { floodLSP(sockfd, tmp, NULL); } routesMade = createRoutes(tmp); int delay = minTime + (rand() % (maxTime - minTime)); tv->tv_sec = (long)delay / 1000; tv->tv_nsec = (long)(delay % 1000) * 1000000; } else { //printf("Sockfd = %d\n", sockfd); //printf("tv%d delay=%li s %li us\n", x, tv->tv_sec, tv->tv_nsec); perrorExit("Select()"); } } // Cleanup packets free(pkt); free(msg); }
int init(int argc, char **argv, char **env) { #ifdef _ITEM_QUITPARTY FILE *f; int i; char line[256]; #endif srand(getpid()); print("This Program is compiled at %s %s by gcc %s\n", __DATE__, __TIME__, __VERSION__); defaultConfig(argv[0]); signalset(); GOTORETURNFALSEIFFALSE(parseCommandLine(argc, argv)); GOTORETURNFALSEIFFALSE(parseEnvironment(env)); { Char aho; debug(sizeof(aho), d); debug(sizeof(aho.data), d); debug(sizeof(aho.string), d); debug(sizeof(aho.flg), d); debug(sizeof(aho.indexOfExistItems), d); debug(sizeof(aho.haveSkill), d); debug(sizeof(aho.indexOfHaveTitle), d); debug(sizeof(aho.addressBook), d); debug(sizeof(aho.workint), d); debug(sizeof(aho.workchar), d); } print("配置文件: %s\n", getConfigfilename()); GOTORETURNFALSEIFFALSE(readconfigfile(getConfigfilename())); nice(getrunlevel()); { int iWork = setAcWBSize(); if(iWork == 0) { printf("----------------------------------------\n"); printf("-------------[AC缓冲] 无法设置 %s\n", getConfigfilename()); printf("----------------------------------------\n"); exit(1); } else { printf("AC缓冲 = %d\n", iWork); } } if(getDebuglevel() >= 1) { print("调试等级: %d\n", getDebuglevel()); print("运行等级: %d\n", getrunlevel()); print("接收缓冲: %d\n", getrecvbuffer() * 1024); print("发送缓冲: %d\n", getsendbuffer() * 1024); print("接收缓冲下限: %d\n", getrecvlowatbuffer()); print("内存单元大小: %d\n", getMemoryunit()); print("内存单元数量: %d\n", getMemoryunitnum()); print("账号服务器地址: %s\n", getAccountservername()); print("账号服务器端口: %d\n", getAccountserverport()); print("登陆服务器名称: %s\n", getGameservername()); print("登陆服务器密码: %s\n", getAccountserverpasswd()); print("等待连接端口: %d\n", getPortnumber()); print("服务端序列号: %d\n", getServernumber()); print("重复地址使用: %d\n", getReuseaddr()); print("最大在线人数: %d\n", getFdnum()); print("最大在线宠数: %d\n", getPetcharnum()); print("最大其他数目: %d\n", getOtherscharnum()); print("最大对象数目: %d\n", getObjnum()); print("最大物品数目: %d\n", getItemnum()); print("最大战斗数目: %d\n", getBattlenum()); print("顶层文件目录: %s\n", getTopdir()); print("地图文件目录: %s\n", getMapdir()); print("地图标识文件: %s\n", getMaptilefile()); print("物品配置文件: %s\n", getItemfile()); print("不可战斗文件: %s\n", getInvfile()); print("显示位置文件: %s\n", getAppearfile()); print("头衔名称文件: %s\n", getTitleNamefile()); print("头衔配置文件: %s\n", getTitleConfigfile()); print("遇敌坐标文件: %s\n", getEncountfile()); print("遇敌组群文件: %s\n", getGroupfile()); print("宠物基本文件: %s\n", getEnemyBasefile()); print("创建宠物文件: %s\n", getEnemyfile()); print("精灵魔法文件: %s\n", getMagicfile()); #ifdef _ATTACK_MAGIC print("攻击魔法文件: %s\n", getAttMagicfileName()); #endif print("宠物技能文件: %s\n", getPetskillfile()); print("物品成份文件: %s\n", getItematomfile()); print("猜迷问题文件: %s\n", getQuizfile()); #ifdef _GMRELOAD print("G M 配置文件: %s\n", getGMSetfile()); #endif print("日志记录文件: %s\n", getLsgenlogfilename()); print("还原资料目录: %s\n", getStoredir()); print("NPC 配置目录: %s\n", getNpcdir()); print("日志记载文件: %s\n", getLogdir()); print("日志配置文件: %s\n", getLogconffile()); print("GM的指命密码: %s\n", getChatMagicPasswd()); print("使用GM的权限: %d\n", getChatMagicCDKeyCheck()); print("NPC 模板数目: %d\n", getNpctemplatenum()); print("NPC 最大数目: %d\n", getNpccreatenum()); print("走路时间间隔: %d\n", getWalksendinterval()); print("清除所有间隔: %d\n", getCAsendinterval_ms()); print("清除目标间隔: %d\n", getCDsendinterval_ms()); print("执行一次时间: %d\n", getOnelooptime_ms()); print("宠物清除时间: %d\n", getPetdeletetime()); print("道具清除时间: %d\n", getItemdeletetime()); #ifdef _DEL_DROP_GOLD print("石器清除时间: %d\n", getGolddeletetime()); #endif print("数据保存间隔: %d\n", getCharSavesendinterval()); print("名片最大数目: %d\n", getAddressbookoffmsgnum()); print("读取频率协议: %d\n", getProtocolreadfrequency()); print("连接错误上限: %d\n", getAllowerrornum()); #ifdef _GET_BATTLE_EXP print("战斗经验倍数: %d倍\n", getBattleexp() ); #endif #ifdef _NEW_PLAYER_CF print("出生人物转数: %d转\n", getNewplayertrans()); print("出生人物等级: %d级\n", getNewplayerlv()); print("出生人物金钱: %d S\n", getNewplayergivegold()); print("出生宠物等级: %d级\n", getNewplayerpetlv()); #ifdef _VIP_SERVER print("出生拥有点数: %d点\n", getNewplayergivevip()); #endif print("出生能骑等级: %d\n", getRidePetLevel()); #ifdef _NEW_PLAYER_RIDE print("出生配套骑宠: %s\n", getPlayerRide()); #endif print("出生拥有宠物: NO1:%d NO2:%d NO3:%d NO4:%d NO5:%d\n", getNewplayergivepet(0), getNewplayergivepet(1), getNewplayergivepet(2), getNewplayergivepet(3), getNewplayergivepet(4)); print("出生拥有物品: ITEM1:%d ITEM2:%d ITEM3:%d ITEM4:%d ITEM5:%d\n" " ITEM1:%d ITEM2:%d ITEM3:%d ITEM4:%d ITEM5:%d\n" " ITEM1:%d ITEM2:%d ITEM3:%d ITEM4:%d ITEM5:%d\n", getNewplayergiveitem(0), getNewplayergiveitem(1), getNewplayergiveitem(2), getNewplayergiveitem(3), getNewplayergiveitem(4), getNewplayergiveitem(5), getNewplayergiveitem(6), getNewplayergiveitem(7), getNewplayergiveitem(8), getNewplayergiveitem(9), getNewplayergiveitem(10), getNewplayergiveitem(11), getNewplayergiveitem(12), getNewplayergiveitem(13), getNewplayergiveitem(14)); #endif #ifdef _UNREG_NEMA print("禁止人物名称: 名字1:%s 名字2:%s 名字3:%s 名字4:%s 名字5:%s\n", getUnregname(0), getUnregname(1), getUnregname(2), getUnregname(3), getUnregname(4)); #endif #ifdef _UNLAW_WARP_FLOOR print("禁止传送地图: 地图1:%d 地图2:%d 地图3:%d 地图4:%d 地图5:%d\n" " 地图1:%d 地图2:%d 地图3:%d 地图4:%d 地图5:%d\n", getUnlawwarpfloor(0), getUnlawwarpfloor(1), getUnlawwarpfloor(2), getUnlawwarpfloor(3), getUnlawwarpfloor(4), getUnlawwarpfloor(5), getUnlawwarpfloor(6), getUnlawwarpfloor(7), getUnlawwarpfloor(8), getUnlawwarpfloor(9)); #endif #ifdef _WATCH_FLOOR print("是否全图观战: %s\n",getWatchFloorCF()); if(strcmp(getWatchFloorCF(),"是")) print("允许观战地图: 地图1:%d 地图2:%d 地图3:%d 地图4:%d 地图5:%d\n",getWatchFloor(1), getWatchFloor(2), getWatchFloor(3), getWatchFloor(4), getWatchFloor(5)); #endif #ifdef _BATTLE_FLOOR print("是否强制战斗: %s\n",getBattleFloorCF()); if(strcmp(getBattleFloorCF(),"是")) print("强制战斗地图: 地图1:%d 地图2:%d 地图3:%d 地图4:%d 地图5:%d\n",getBattleFloor(1), getBattleFloor(2), getBattleFloor(3), getBattleFloor(4), getBattleFloor(5)); #endif #ifdef _TRANS_LEVEL_CF print("人物等级转数: %d级\n", getChartrans()); print("宠物等级转数: %d级\n", getPettrans()); #endif #ifdef _POINT print("禁止点数上限: %s\n", getPoint()); if(strcmp(getPoint(), "是")) print("每转点数上限: 0转:%d 1转:%d 2转:%d 3转:%d 4转:%d 5转:%d 6转:%d\n", getTransPoint(0), getTransPoint(1), getTransPoint(2), getTransPoint(3), getTransPoint(4), getTransPoint(5), getTransPoint(6)); #endif #ifdef _PET_UP print("宠物能否捡获: %s\n", getPetup()); #endif #ifdef _LOOP_ANNOUNCE print("循环公告路径: %s\n",getLoopAnnouncePath()); print("循环时间间隔: %d分钟\n",getLoopAnnounceTime()); #endif #ifdef _SKILLUPPOINT_CF print("每级升级点数: %d\n",getSkup()); #endif #ifdef _RIDELEVEL print("骑宠等级相差: %d级\n",getRideLevel()); #endif #ifdef _REVLEVEL print("还原上限等级: %s级\n",getRevLevel()); #endif #ifdef _TRANS_LEVEL_CF print("一般等级上限: %d级\n", getYBLevel()); print("最高等级上限: %d级\n", getMaxLevel()); #endif #ifdef _FIX_CHARLOOPS print("恶魔时间倍数: %d倍\n", getCharloops()); #endif #ifdef _PLAYER_ANNOUNCE if(getPAnnounce() == -1) print("喇叭消耗点数: 关闭使用\n"); else print("喇叭消耗点数: %d点\n", getPAnnounce()); #endif #ifdef _PLAYER_MOVE if(getPMove() == -1) print("顺移消耗点数: 关闭使用\n"); else print("顺移消耗点数: %d点\n", getPMove()); #endif #ifdef _BATTLE_GOLD print("战斗获得金钱: %d%\n", getBattleGold()); #endif #ifdef _ANGEL_TIME print("精灵召唤时间: (%d人/在线人数)分\n", getAngelPlayerTime()); print("精灵召唤人数: %d人\n", getAngelPlayerMun()); #endif #ifdef _RIDEMODE_20 print("2.0 骑宠模式: %d\n", getRideMode()); #endif #ifdef _FM_POINT_PK print("庄园互抢模式: %s\n", getFmPointPK()); #endif } { //andy_add 2003/05/05 check GameServer Name char *GameServerName; GameServerName = getGameserverID(); if(GameServerName == NULL || strlen(GameServerName) <= 0) return FALSE; print("\n游戏服务器ID: %s\n", GameServerName); } print("开始初始化\n"); //#define DEBUG1( arg... ) if( getDebuglevel()>1 ){##arg} print("建立内存空间..."); GOTORETURNFALSEIFFALSE(configmem(getMemoryunit(), getMemoryunitnum())); GOTORETURNFALSEIFFALSE(memInit()); print("完成\n"); print("始终化连接空间..."); if(!initConnect(getFdnum())) goto MEMEND; print("完成\n"); while(1) { print("尝试绑定本地端口 %d... ", getPortnumber()); bindedfd = bindlocalhost(getPortnumber()); if(bindedfd == -1) sleep(10); else break; } print("完成\n"); print("建立对象..."); if(!initObjectArray(getObjnum())) goto CLOSEBIND; print("完成\n"); print("建立人物..."); if(!CHAR_initCharArray(getFdnum(), getPetcharnum(), getOtherscharnum())) goto CLOSEBIND; print("完成\n"); print("建立物品..."); if(!ITEM_readItemConfFile(getItemfile())) goto CLOSEBIND; if(!ITEM_initExistItemsArray(getItemnum())) goto CLOSEBIND; print("完成\n"); print("建立战斗..."); if(!BATTLE_initBattleArray(getBattlenum())) goto CLOSEBIND; print("完成\n"); print("建立功能模块..."); if(!initFunctionTable()) goto CLOSEBIND; print("完成\n"); print("初始化邮件..."); if(!PETMAIL_initOffmsgBuffer(getAddressbookoffmsgnum())) goto CLOSEBIND; print("完成\n"); print("读取不可战斗文件..."); if(!CHAR_initInvinciblePlace(getInvfile())) goto CLOSEBIND; print("完成\n"); print("读取显示位置文件..."); if(!CHAR_initAppearPosition(getAppearfile())) goto CLOSEBIND; print("完成\n"); print("读取头衔名称文件..."); if(!TITLE_initTitleName(getTitleNamefile())) goto CLOSEBIND; print("完成\n"); print("读取头衔配置文件..."); if(!TITLE_initTitleConfig(getTitleConfigfile())) goto CLOSEBIND; print("完成\n"); print("读取遇敌坐标文件..."); if(!ENCOUNT_initEncount(getEncountfile())) goto CLOSEBIND; print("完成\n"); print("读取宠物基本文件..."); if(!ENEMYTEMP_initEnemy(getEnemyBasefile())) goto CLOSEBIND; print("完成\n"); print("读取创建宠物文件..."); if(!ENEMY_initEnemy(getEnemyfile())) goto CLOSEBIND; print("完成\n"); print("读取遇敌组群文件..."); if(!GROUP_initGroup(getGroupfile())) goto CLOSEBIND; print("完成\n"); print("读取魔法文件..."); if(!MAGIC_initMagic(getMagicfile())) goto CLOSEBIND; print("完成\n"); #ifdef _ATTACK_MAGIC print("读取魔法攻击文件..."); if(!ATTMAGIC_initMagic(getAttMagicfileName())) // if( !ATTMAGIC_initMagic( getMagicfile() ) ) goto CLOSEBIND; print("魔法攻击文件 -->%s...", getAttMagicfileName()); print("完成\n"); #endif print("读取宠物技能文件..."); if(!PETSKILL_initPetskill(getPetskillfile())) goto CLOSEBIND; print("完成\n"); print("读取物品成份文件..."); if(!ITEM_initItemAtom(getItematomfile())) goto CLOSEBIND; print("完成\n"); print("初始化料理合成物品..."); if(!ITEM_initItemIngCache()) goto CLOSEBIND; print("完成\n"); print("初始料理合成随机设定..."); if(!ITEM_initRandTable()) goto CLOSEBIND; print("完成\n"); print("读取猜迷问题文件..."); if(!QUIZ_initQuiz(getQuizfile())) goto CLOSEBIND; print("完成\n"); #ifdef _GMRELOAD print("读取GM配置文件..."); if(!LoadGMSet(getGMSetfile())) goto CLOSEBIND; print("完成\n"); #endif #ifdef _USER_EXP_CF print( "读取经验配置文件..." ); if ( !LoadEXP( getEXPfile() ) ) goto CLOSEBIND; print("最高等级: %d...",getMaxLevel()); print("一般等级: %d...",getYBLevel()); print( "完成\n" ); #endif #ifdef _LOOP_ANNOUNCE print("读取循环公告文件..."); if(!loadLoopAnnounce()) print("...失败\n"); else print("完成\n"); #endif #ifdef _RIDE_CF print("读取自定义骑宠文件..."); if(!CHAR_Ride_CF_init()) print("...失败\n"); print("完成\n"); #endif #ifdef _FM_LEADER_RIDE print("读取庄园族长专用骑宠文件..."); if(!CHAR_FmLeaderRide_init()) print("...失败\n"); print("完成\n"); #endif #ifdef _NEED_ITEM_ENEMY print("读取融合宠配置文件..."); if(!need_item_eneny_init()) print("...失败\n"); print("完成\n"); #endif print("建立地图..."); if(!MAP_initReadMap(getMaptilefile(), getMapdir())) goto CLOSEBIND; print("完成\n"); print("读取NPC文件..."); if(!NPC_readNPCSettingFiles(getNpcdir(), getNpctemplatenum(), getNpccreatenum())) goto CLOSEBIND; print("完成\n"); print("初始化 NPC 服务器... "); if(lssproto_InitServer(lsrpcClientWriteFunc, LSGENWORKINGBUFFER) < 0) goto CLOSEBIND; print("完成\n"); print("尝试连接账号服务器... "); acfd = connectHost(getAccountservername(), getAccountserverport()); if(acfd == -1) goto CLOSEBIND; print("完成\n"); initConnectOne(acfd, NULL, 0); if(!CONNECT_acfdInitRB(acfd)) goto CLOSEAC; if(!CONNECT_acfdInitWB(acfd)) goto CLOSEAC; CONNECT_setCtype(acfd, AC); print("初始化 NPC 客户端 ... "); if(saacproto_InitClient(lsrpcClientWriteFunc, LSGENWORKINGBUFFER, acfd) < 0) goto CLOSEAC; print("完成\n"); print("向账号服务器发送登陆请求... "); saacproto_ACServerLogin_send(acfd, getGameservername(), getAccountserverpasswd()); print("完成\n"); if(isExistFile(getLsgenlogfilename())) { lssproto_SetServerLogFiles(getLsgenlogfilename(), getLsgenlogfilename()); saacproto_SetClientLogFiles(getLsgenlogfilename(), getLsgenlogfilename()); } print("初始化已完成\n"); print("开始记始日志\n"); { if(!initLog(getLogconffile())) goto CLOSEAC; } #ifdef _ITEM_QUITPARTY print("读取队伍解散物品消失文件..."); //读取档案 f = fopen(getitemquitparty(), "r"); if(f != NULL) { while(fgets(line, sizeof(line), f)) { if(line[0] == '#')continue; if(line[0] == '\n')continue; chomp(line); itemquitparty_num++; } if(fseek(f, 0, SEEK_SET) == -1) { print("物品录找错误\n"); fclose(f); goto CLOSEAC; } //配记忆体 Disappear_Item = allocateMemory(sizeof(struct tagDisappearItem) * itemquitparty_num); if(Disappear_Item == NULL) { print("无法分配内存 %d\n", sizeof(struct tagDisappearItem) * itemquitparty_num); fclose(f); goto CLOSEAC; } i = 0; //将道具编号存入 Disappear_Item.string while(fgets(line, sizeof(line), f)) { if(line[0] == '#')continue; if(line[0] == '\n')continue; chomp(line); sprintf(Disappear_Item[i].string, "%s", line); print("\n道具编号:%s", Disappear_Item[i].string); i++; } fclose(f); } #endif DEBUG_ADJUSTTIME = 0; return TRUE; CLOSEAC: close(acfd); CLOSEBIND: close(bindedfd); endConnect(); MEMEND: memEnd(); RETURNFALSE: return FALSE; }
int main(int argc, char **argv) { FdEventHandlerPtr listener; int i; int rc; int expire = 0, printConfig = 0; initAtoms(); CONFIG_VARIABLE(daemonise, CONFIG_BOOLEAN, "Run as a daemon"); CONFIG_VARIABLE(pidFile, CONFIG_ATOM, "File with pid of running daemon."); preinitChunks(); preinitLog(); preinitObject(); preinitIo(); preinitDns(); preinitServer(); preinitHttp(); preinitDiskcache(); preinitLocal(); preinitForbidden(); preinitSocks(); preinitOffline(); i = 1; while(i < argc) { if(argv[i][0] != '-') break; if(strcmp(argv[i], "--") == 0) { i++; break; } else if(strcmp(argv[i], "-h") == 0) { usage(argv[0]); exit(0); } else if(strcmp(argv[i], "-v") == 0) { printConfig = 1; i++; } else if(strcmp(argv[i], "-x") == 0) { expire = 1; i++; } else if(strcmp(argv[i], "-c") == 0) { i++; if(i >= argc) { usage(argv[0]); exit(1); } if(configFile) releaseAtom(configFile); configFile = internAtom(argv[i]); i++; } else { usage(argv[0]); exit(1); } } if(configFile) configFile = expandTilde(configFile); if(configFile == NULL) { configFile = expandTilde(internAtom("~/.polipo")); if(configFile) if(access(configFile->string, F_OK) < 0) { releaseAtom(configFile); configFile = NULL; } } if(configFile == NULL) { if(access("/etc/polipo/config", F_OK) >= 0) configFile = internAtom("/etc/polipo/config"); if(configFile && access(configFile->string, F_OK) < 0) { releaseAtom(configFile); configFile = NULL; } } rc = parseConfigFile(configFile); if(rc < 0) exit(1); while(i < argc) { rc = parseConfigLine(argv[i], "command line", 0, 0); if(rc < 0) exit(1); i++; } initChunks(); initLog(); initObject(); if(!expire && !printConfig) initEvents(); initIo(); initDns(); initHttp(); initServer(); initDiskcache(); initForbidden(); initSocks(); initOffline(); if(printConfig) { printConfigVariables(stdout, 0); exit(0); } if(expire) { expireDiskObjects(); exit(0); } if(daemonise) do_daemonise(logFile == NULL || logFile->length == 0); if(pidFile) writePid(pidFile->string); listener = create_listener(proxyAddress->string, proxyPort, httpAccept, NULL); if(!listener) { if(pidFile) unlink(pidFile->string); exit(1); } eventLoop(); if(pidFile) unlink(pidFile->string); return 0; }
int main(void) { setBoardName("TITAN ELECTRONICAL MAIN BOARD 32bits V-JJ_7"); i2cMasterInitialize(); //setRobotMustStop(false); // Open the serial Link for debug openSerialLink(&debugSerialStreamLink, &debugInputBuffer, &debugInputBufferArray, MAIN_BOARD_DEBUG_INPUT_BUFFER_LENGTH, &debugOutputBuffer, &debugOutputBufferArray, MAIN_BOARD_DEBUG_OUTPUT_BUFFER_LENGTH, &debugOutputStream, SERIAL_PORT_DEBUG, DEFAULT_SERIAL_SPEED); // Open the serial Link for the PC openSerialLink(&pcSerialStreamLink, &pcInputBuffer, &pcInputBufferArray, MAIN_BOARD_PC_INPUT_BUFFER_LENGTH, &pcOutputBuffer, &pcOutputBufferArray, MAIN_BOARD_PC_OUTPUT_BUFFER_LENGTH, &pcOutputStream, SERIAL_PORT_PC, DEFAULT_SERIAL_SPEED); // LCD (LCD03 via Serial interface) initLCDOutputStream(&lcdOutputStream); initTimerList(&timerListArray, MAIN_BOARD_TIMER_LENGTH); // Init the logs initLog(DEBUG); addLogHandler(&debugSerialLogHandler, "UART", &debugOutputStream, DEBUG); addLogHandler(&lcdLogHandler, "LCD", &lcdOutputStream, ERROR); appendString(getAlwaysOutputStreamLogger(), getBoardName()); println(getAlwaysOutputStreamLogger()); initDevicesDescriptor(); initDriversDescriptor(); i2cMasterInitialize(); // Initialize EEPROM and RTC initClockPCF8563(&globalClock); init24C512Eeprom(&eeprom_); initRobotConfigPic32(&robotConfig); initStartMatchDetector32(&startMatchDetector); // Initializes the opponent robot // initOpponentRobot(); /* // Creates a composite to notify both PC and Debug initCompositeOutputStream(&compositePcAndDebugOutputStream); addOutputStream(&compositePcAndDebugOutputStream, &debugOutputStream); addOutputStream(&compositePcAndDebugOutputStream, &pcOutputStream); // Creates a composite to redirect to driverRequest and Debug initCompositeOutputStream(&compositeDriverAndDebugOutputStream); addOutputStream(&compositeDriverAndDebugOutputStream, &debugOutputStream); addOutputStream(&compositeDriverAndDebugOutputStream, getDriverRequestOutputStream()); */ appendString(&debugOutputStream, "DEBUG\n"); // Start interruptions //startTimerList(); //////RALENTI FORTEMENT LE PIC!!! PLANTE I2C !!!!!!!! // Configure data dispatcher //addLocalDriverDataDispatcher(); // Stream for motorBoard /* addI2CDriverDataDispatcher(&motorI2cDispatcher, "MOTOR_BOARD_DISPATCHER", &motorBoardInputBuffer, &motorBoardInputBufferArray, MAIN_BOARD_LINK_TO_MOTOR_BOARD_BUFFER_LENGTH, &motorBoardOutputStream, &motorBoardInputStream, MOTOR_BOARD_I2C_ADDRESS); */ /* // Stream for Mechanical Board 2 addI2CDriverDataDispatcher(&mechanical2I2cDispatcher, "MECHANICAL_BOARD_2_DISPATCHER", &mechanical2BoardInputBuffer, &mechanical2BoardInputBufferArray, MAIN_BOARD_LINK_TO_MECA_BOARD_2_BUFFER_LENGTH, &mechanical2BoardOutputStream, &mechanical2BoardInputStream, MECHANICAL_BOARD_2_I2C_ADDRESS); */ /* // Stream for Air Conditioning addI2CDriverDataDispatcher(&airConditioningI2cDispatcher, "AIR_CONDITIONING_DISPATCHER", &airConditioningBoardInputBuffer, &airConditioningBoardInputBufferArray, MAIN_BOARD_LINK_TO_AIR_CONDITIONING_BOARD_BUFFER_LENGTH, &airConditioningBoardOutputStream, &airConditioningBoardInputStream, AIR_CONDITIONING_BOARD_I2C_ADDRESS); */ // I2C Debug initI2CDebugBuffers(&i2cMasterDebugInputBuffer, &i2cMasterDebugInputBufferArray, MAIN_BOARD_I2C_DEBUG_MASTER_IN_BUFFER_LENGTH, &i2cMasterDebugOutputBuffer, &i2cMasterDebugOutputBufferArray, MAIN_BOARD_I2C_DEBUG_MASTER_OUT_BUFFER_LENGTH); appendStringConfig(&lcdOutputStream); //pingDriverDataDispatcherList(getDebugOutputStreamLogger()); // Inform PC waiting showWaitingStart(&debugOutputStream); // wait other board initialization delaymSec(1500); // 2012 VALUE unsigned int configValue = getConfigValue(); unsigned int homologationIndex = configValue & CONFIG_STRATEGY_MASK; unsigned int color = configValue & CONFIG_COLOR_BLUE_MASK; appendString(getAlwaysOutputStreamLogger(), "Homologation:"); appendCRLF(getAlwaysOutputStreamLogger()); appendDec(getAlwaysOutputStreamLogger(), homologationIndex); appendString(getAlwaysOutputStreamLogger(), "Config:"); appendHex4(getAlwaysOutputStreamLogger(), configValue); appendCRLF(getAlwaysOutputStreamLogger()); useBalise = configValue & CONFIG_USE_BALISE_MASK; useInfrared = configValue & CONFIG_USE_SONAR_MASK; if (color != 0) { appendString(getAlwaysOutputStreamLogger(), "COLOR:VIOLET\n"); } else { appendString(getAlwaysOutputStreamLogger(), "COLOR:RED\n"); } // TODO 2012 SV motionDriverMaintainPosition(); // wait for start // setInitialPosition(color); // notify game strategy // sendStrategyConfiguration(configValue); loopUntilStart(&waitForInstruction); // Enable the sonar Status only after start //setSonarStatus(configValue & CONFIG_USE_SONAR_MASK); // mark that match begins markStartMatch(); // write begin of match showStarted(&pcOutputStream); if (homologationIndex == 0) { // MATCH while (1) { waitForInstruction(); //CLOCK Read if (isEnd()) { break; } } } else { setReadyForNextMotion(true); while (1) { portableStartI2C(i2cBus); WaitI2C(i2cBus); portableMasterWriteI2C(FREE_ADDRESS_2);//0x54 WaitI2C(i2cBus); portableMasterWriteI2C('H'); WaitI2C(i2cBus); portableMasterWriteI2C('E'); WaitI2C(i2cBus); portableMasterWriteI2C('L'); WaitI2C(i2cBus); portableMasterWriteI2C('L'); WaitI2C(i2cBus); portableMasterWriteI2C('O'); portableStopI2C(i2cBus); WaitI2C(i2cBus); int data1,data2,data3; while(1){ waitForInstruction(); //globalClock.readClock(&globalClock); //printClock(&debugOutputStream,&globalClock); //appendCR(&debugOutputStream); int data = 0; portableMasterWaitSendI2C(i2cBus); portableStartI2C(i2cBus); IdleI2C1(); portableMasterWriteI2C(FREE_ADDRESS_2 + 1);//0x54 WaitI2C(i2cBus); data = portableMasterReadI2C(i2cBus); portableAckI2C(i2cBus); IdleI2C1(); data1 = portableMasterReadI2C(i2cBus); portableAckI2C(i2cBus); IdleI2C1(); data2= portableMasterReadI2C(i2cBus); portableAckI2C(i2cBus); IdleI2C1(); data3 = portableMasterReadI2C(i2cBus); portableNackI2C(i2cBus); IdleI2C1(); append(&lcdOutputStream,data); append(&lcdOutputStream,data1); append(&lcdOutputStream,data2); append(&lcdOutputStream,data3); portableStopI2C(i2cBus); IdleI2C1(); delaymSec(500); } homologation(homologationIndex, color); // We stop if we are in homologation mode if (isRobotMustStop()) { motionDriverStop(); break; } // ultimate tentative to restart the robot if it is blocked forceRobotNextStepIfNecessary(); } } showEnd(&lcdOutputStream); while (1) { // Avoid reboot even at end } }
//int main() //{ int _tmain(int argc, _TCHAR* argv[]){ clock_t startTime = clock(); clock_t duration = 0; int msecDuration = 0; int i = 0; int nrofTests = 0; errno_t error; eIDTest eIDTests[] = { \ // {{0,TEST_SKIPPED},"Tests C_getinfo results in a single thread",&test_getinfo}, //#ifdef WIN32 // {{0,TEST_SKIPPED},"Tests multiple finalize/initialize sessions in multiple threads with different args",&test_finalize_initialize}, // {{0,TEST_SKIPPED},"Tests multiple finalize/initialize sessions in a single thread",&test_finalize_initialize_st}, // {{0,TEST_SKIPPED},"Tests C_initialize when bad parameters are supplied 1",&test_initialize_ownmutex}, // {{0,TEST_SKIPPED},"Tests C_initialize when bad parameters are supplied",&test_initialize_preserved}, // {{0,TEST_SKIPPED},"Tests C_finalize when bad parameters are supplied",&test_finalize_preserved}, //#endif //WIN32 // {{0,TEST_SKIPPED},"Tests C_getslotlist in single and two call usage",&test_getslotlist}, // {{0,TEST_SKIPPED},"Tests C_getslotlist when insufficient memory is reserved",&test_getslotlist_multiple_slots}, // {{0,TEST_SKIPPED},"Tests opening and closing of a session in a single thread",&test_open_close_session}, // {{0,TEST_SKIPPED},"Tests getting slotID and slotdescription",&test_open_close_session_info}, // {{0,TEST_SKIPPED},"Tests C_opensession with wrong parameters supplied",&test_open_close_session_bad_params}, // {{0,TEST_SKIPPED},"Tests how many sessions can be opened",&test_open_close_session_limits}, //#ifdef WIN32 //{{0,TEST_SKIPPED},"tests getting all the objects from the card",&test_logslotevents_blocking}, // #ifdef USER_INTERACTION // {{0,TEST_SKIPPED},"Tests waitforslot event (needs user interaction)",&test_waitforslotevent_userinteraction},// // {{0,TEST_SKIPPED},"tests signing with the card",&test_sign}, // {{0,TEST_SKIPPED},"tests signing sequence with all mechanisms on the card",&test_sign_allmechs}, // {{0,TEST_SKIPPED},"Tests waiting for slot event blocking",&test_waitforslotevent_blocking}, // #endif // {{0,TEST_SKIPPED},"Tests waiting for slot event non-blocking",&test_waitforslotevent_nonblocking}, // {{0,TEST_SKIPPED},"Tests waiting for slot event blocking, while another thread calls c_finalize",&test_waitforslotevent_whilefinalize}, //#endif //WIN32 // {{0,TEST_SKIPPED},"Tests the retrieval of slot and token info",&test_get_token_info}, // {{0,TEST_SKIPPED},"Shows info on the mechanisms supported by the card",&test_getmechanisms}, // {{0,TEST_SKIPPED},"tests getting the keys from the card",&test_getkeys}, // {{0,TEST_SKIPPED},"tests the return values of the getattributes function",&test_getkeys_retvals}, //{{0,TEST_SKIPPED},"tests getting all the objects from the card",&test_getallobjects}, {0,CKR_OK,"tests initialize/finalize",&init_finalize}, {0,CKR_OK,"tests getinfo",&getinfo}, //{0,CKR_OK,"tests initialize/finalize",&funclist}, {0,CKR_OK,"tests slotlist",&slotlist}, {0,CKR_OK,"tests slotinfo",&slotinfo}, {0,CKR_OK,"tests tkinfo",&tkinfo}, {0,CKR_OK,"tests double_init",&double_init}, {0,CKR_OK,"tests slotevent",&slotevent}, {0,CKR_OK,"tests mechlist",&mechlist}, {0,CKR_OK,"tests mechinfo",&mechinfo}, {0,CKR_OK,"tests sessions",&sessions}, {0,CKR_OK,"tests sessions_nocard",&sessions_nocard}, {0,CKR_OK,"tests sessioninfo",&sessioninfo}, {0,CKR_OK,"tests login",&login}, {0,CKR_OK,"tests nonsensible",&nonsensible}, {0,CKR_OK,"tests objects",&objects}, {0,CKR_OK,"tests readdata",&readdata}, {0,CKR_OK,"tests digest",&digest}, {0,CKR_OK,"tests sign_state",&sign_state}, //{0,CKR_OK,"tests initialize/finalize",&decode_photo}, // {{0,TEST_SKIPPED},"tests getting all the objects from the card",&test_getallidobjects}, // {{0,TEST_SKIPPED},"tests getting object's attributes from the card",&test_getattributevalue_all}, // {{0,TEST_SKIPPED},"tests getting object's attributes from the card",&test_getattributevalue_rrn}, // {{0,TEST_SKIPPED},"tests getting the lastname object's attributes from the card",&test_getattributevalue_lastname}, //#ifdef WIN32 // {{0,TEST_SKIPPED},"tests adding and removing readers",&test_add_remove_readers}, // {{0,TEST_SKIPPED},"tests waiting for card and reader events",&test_add_remove_readerevents}, //#endif //WIN32 // {{0,TEST_SKIPPED},"tests getting the private object's from the card without logging in",&test_findPrivateKeyWithoutLoginShouldFail}, // {{0,TEST_SKIPPED},"tests the return value of C_FindObjectsFinal when called without C_FindObjectsInit",&test_findObjectsFinalNotInitialized}, }; if(argc >=2) eid_robot_style = argv[1]; if(argc >=3) eid_dialogs_style = argv[2]; error = initLog(); if(error != 0) { printf("Can't open logfile"); return -1; } nrofTests = (sizeof(eIDTests)/sizeof(eIDTest)); while (i < nrofTests ) { eIDTests[i].result = eIDTests[i].test_function_ptr(); i++; } //testlog(LVL_NOLEVEL,"\n\n_______________________________________________\n"); for (i = 0; i < nrofTests; i++) { if (eIDTests[i].testDescription != NULL) { testlog(LVL_NOLEVEL,"_______________________________________________\n"); testlog(LVL_NOLEVEL,"Test %d %s \n", i, eIDTests[i].testDescription); } if(eIDTests[i].result != eIDTests[i].expectresult) { testlog(LVL_NOLEVEL,"FAILED : Result = 0x%.8x Expected Result\n", eIDTests[i].result, eIDTests[i].expectresult ); } /* else { switch(eIDTests[i].result.basetestrv) { case TEST_PASSED: testlog(LVL_NOLEVEL,"PASSED\n"); break; case TEST_SKIPPED: testlog(LVL_NOLEVEL,"SKIPPED\n"); break; case TEST_WARNING: testlog(LVL_NOLEVEL,"WARNING\n"); break; case TEST_ERROR: case TEST_FAILED: testlog(LVL_NOLEVEL,"FAILED : Result = 0x%.8x \n", eIDTests[i].result.pkcs11rv); break; default: testlog(LVL_NOLEVEL,"UNKNOWN : Result = 0x%.8x \n", eIDTests[i].result.pkcs11rv); break; }; }*/ //testlog(LVL_NOLEVEL,"\n_______________________________________________\n"); } duration = clock() - startTime; msecDuration = (duration * 1000) / CLOCKS_PER_SEC; printf("Duration: %d,%d seconds", msecDuration/1000, msecDuration%1000); testlog(LVL_NOLEVEL,"\n===============================================\n"); //short summary /*for (i = 0; i < nrofTests; i++) { if(eIDTests[i].result.pkcs11rv != CKR_OK) { testlog(LVL_NOLEVEL," F "); } else { switch(eIDTests[i].result.basetestrv) { case TEST_PASSED: testlog(LVL_NOLEVEL,"P"); break; case TEST_SKIPPED: testlog(LVL_NOLEVEL," S "); break; case TEST_WARNING: testlog(LVL_NOLEVEL," W "); break; case TEST_ERROR: case TEST_FAILED: testlog(LVL_NOLEVEL," F "); break; default: testlog(LVL_NOLEVEL," X "); break; }; } }*/ testlog(LVL_NOLEVEL,"\n===============================================\n"); endLog(); testlog(LVL_NOLEVEL,"press a key to end the test\n"); // Wait for user to end this test #ifdef WIN32 getchar(); #endif }
//--------------- //--entry point-- //--------------- int main(int argc, char* argv[]) { initLog(); log("Interpreter pokrenut"); if(argc != 2) WRONG_ARGUMENT_COUNT(); if(!loadExecutableFile(argv[1])) FILE_CAN_NOT_BE_LOADED(); log("Izvrsni fajl ucitan"); for(;;) { logCPUInfo(); logMemory(IP, 20); logStackTrace(); ubyte opcode = read_next_ubyte(); log("opcode = 0x%02hx", opcode); // Testiramo prvi bit instrukcije if(opcode & 0x80) { // prvi bit 1 // odredjujemo dest i src ubyte dst = read_next_ubyte(), src; src = dst & 0x0F; dst >>= 4; //if(src == 0xf && dst == 0xf) // ADRESSING_ERROR(); switch(opcode) { case 0x80: // JMP if(dst != 0x00) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); IP = read_next_word() + (src == 0xf ? 0 : REGS[src]); break; case 0x81: // JZ if(dst != 0x00) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); { word c = read_next_word(); if(TEST_FLAG_Z()) IP += c + (src == 0xf ? 0 : REGS[src]); } break; case 0x82: // JGT if(dst != 0x00) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); { word c = read_next_word(); if(!TEST_FLAG_O() && !TEST_FLAG_Z()) IP += c + (src == 0xf ? 0 : REGS[src]); } break; case 0x83: // MOV if(src == 0x0f || dst == 0x0f) ADRESSING_ERROR(); REGS[dst] = REGS[src]; SET_OR_CLEAR_FLAG_N(REGS[dst] < 0); SET_OR_CLEAR_FLAG_Z(REGS[dst] == 0); break; case 0x84: // LDR if(dst == 0x0f) ADRESSING_ERROR(); REGS[dst] = read_word(read_next_word() + (src == 0xf ? 0 : REGS[src])); SET_OR_CLEAR_FLAG_N(REGS[dst] < 0); SET_OR_CLEAR_FLAG_Z(REGS[dst] == 0); break; case 0x85: // STR if(src == 0x0f) ADRESSING_ERROR(); write_word(read_next_word() + (dst == 0xf ? 0 : REGS[dst]), REGS[src]); break; case 0x86: // IN if(src != 0x00 || dst == 0x0f) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); scanf("%d", ®S[dst]); SET_OR_CLEAR_FLAG_N(REGS[dst] < 0); SET_OR_CLEAR_FLAG_Z(REGS[dst] == 0); break; case 0x87: // OUT if(dst != 0x00 || src == 0x0f) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); printf("%d\n", REGS[src]); break; case 0x88: // CLC if(dst != 0x00 || src != 0x00) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); CLEAR_FLAG_C(); break; case 0x89: // STC if(dst != 0x00 || src != 0x00) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); SET_FLAG_C(); break; case 0x8A: // NC if(dst != 0x00 || src != 0x00) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); if(TEST_FLAG_C()) { CLEAR_FLAG_C(); } else { SET_FLAG_C(); } break; case 0x8B: // MOVF if(src != 0x00 || dst == 0x0f) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); REGS[dst] = PSW; break; case 0x8C: // MOVTSP if(dst != 0x00 || src == 0x0f) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); SP = REGS[src]; break; case 0x8D: // MOVFSP if(src != 0x00 || dst == 0x0f) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); REGS[dst] = SP; break; case 0x8E: // CALL if(dst != 0x00) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); { word c = read_next_word(); push(IP); IP = c + (src == 0xf ? 0 : REGS[src]); } break; case 0x8F: // RET if(dst != 0x00 || src != 0x00) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); IP = pop(); break; case 0x90: // HLT if(dst != 0x00 || src != 0x00) // polje koje se ne koristi mora biti 0 ADRESSING_ERROR(); HALT(); break; default: WRONG_OP_CODE(); } } else { // prvi bit 0
int main(int argn, char *argv[]) { int ret; char buf[256]; int numfonts = 0; int t; char t1searchpath[1024]; int nup_pos = 0; int x,y; int one_file_per_page = 0; initLog(0,-1,0,0,-1,loglevel); /* not needed anymore since fonts are embedded if(installPath) { fontpaths[fontpathpos++] = concatPaths(installPath, "fonts"); }*/ #ifdef HAVE_SRAND48 srand48(time(0)*getpid()); #else #ifdef HAVE_SRAND srand(time(0)*getpid()); #endif #endif processargs(argn, argv); driver = gfxsource_pdf_create(); /* pass global parameters to PDF driver*/ parameter_t*p = device_config; while(p) { driver->setparameter(driver, p->name, p->value); p = p->next; } if(!filename) { fprintf(stderr, "Please specify an input file\n"); exit(1); } if (!info_only) { if(!outputname) { if(filename) { outputname = stripFilename(filename, ".swf"); msg("<notice> Output filename not given. Writing to %s", outputname); } } if(!outputname) { fprintf(stderr, "Please use -o to specify an output file\n"); exit(1); } } // test if the page range is o.k. is_in_range(0x7fffffff, pagerange); if (!filename) { args_callback_usage(argv[0]); exit(0); } char fullname[256]; if(password && *password) { sprintf(fullname, "%s|%s", filename, password); filename = fullname; } if(pagerange) driver->setparameter(driver, "pages", pagerange); /* add fonts */ for(t=0;t<fontpathpos;t++) { driver->setparameter(driver, "fontdir", fontpaths[t]); } if(info_only) { show_info(driver, filename); return 0; } char*u = 0; if((u = strchr(outputname, '%'))) { if(strchr(u+1, '%') || strchr(outputname, '%')!=u) { msg("<error> only one %% allowed in filename\n"); return 1; } if(preloader || viewer) { msg("<error> -b/-l/-B/-L not supported together with %% in filename\n"); return 1; } msg("<notice> outputting one file per page"); one_file_per_page = 1; char*pattern = (char*)malloc(strlen(outputname)+2); /* convert % to %d */ int l = u-outputname+1; memcpy(pattern, outputname, l); pattern[l]='d'; strcpy(pattern+l+1, outputname+l); outputname = pattern; } gfxdocument_t* pdf = driver->open(driver, filename); if(!pdf) { msg("<error> Couldn't open %s", filename); exit(1); } /* pass global parameters document */ p = device_config; while(p) { pdf->setparameter(pdf, p->name, p->value); p = p->next; } struct mypage_t { int x; int y; gfxpage_t*page; } pages[4]; int pagenum = 0; int frame = 1; int pagenr; for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { char mapping[80]; sprintf(mapping, "%d:%d", pagenr, frame); pdf->setparameter(pdf, "pagemap", mapping); pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { pagenum = 0; frame++; } } if(pagerange && !pagenum && frame==1) { fprintf(stderr, "No pages in range %s", pagerange); exit(1); } pagenum = 0; gfxdevice_t*out = create_output_device();; pdf->prepare(pdf, out); for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { gfxpage_t* page = pages[pagenum].page = pdf->getpage(pdf, pagenr); pages[pagenum].x = 0; pages[pagenum].y = 0; pages[pagenum].page = page; pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { int t; int xmax[xnup], ymax[xnup]; int x,y; int width=0, height=0; memset(xmax, 0, xnup*sizeof(int)); memset(ymax, 0, ynup*sizeof(int)); for(y=0;y<ynup;y++) for(x=0;x<xnup;x++) { int t = y*xnup + x; if(pages[t].page->width > xmax[x]) xmax[x] = (int)pages[t].page->width; if(pages[t].page->height > ymax[y]) ymax[y] = (int)pages[t].page->height; } for(x=0;x<xnup;x++) { width += xmax[x]; xmax[x] = width; } for(y=0;y<ynup;y++) { height += ymax[y]; ymax[y] = height; } if(custom_clip) { out->startpage(out,clip_x2 - clip_x1, clip_y2 - clip_y1); } else { out->startpage(out,width,height); } for(t=0;t<pagenum;t++) { int x = t%xnup; int y = t/xnup; int xpos = x>0?xmax[x-1]:0; int ypos = y>0?ymax[y-1]:0; msg("<verbose> Render (%d,%d) move:%d/%d\n", (int)(pages[t].page->width + xpos), (int)(pages[t].page->height + ypos), xpos, ypos); pages[t].page->rendersection(pages[t].page, out, custom_move? move_x : xpos, custom_move? move_y : ypos, custom_clip? clip_x1 : 0 + xpos, custom_clip? clip_y1 : 0 + ypos, custom_clip? clip_x2 : pages[t].page->width + xpos, custom_clip? clip_y2 : pages[t].page->height + ypos); } out->endpage(out); for(t=0;t<pagenum;t++) { pages[t].page->destroy(pages[t].page); } pagenum = 0; if(one_file_per_page) { gfxresult_t*result = out->finish(out);out=0; char buf[1024]; sprintf(buf, outputname, pagenr); if(result->save(result, buf) < 0) { return 1; } result->destroy(result);result=0; out = create_output_device();; pdf->prepare(pdf, out); msg("<notice> Writing SWF file %s", buf); } } } if(one_file_per_page) { // remove empty device gfxresult_t*result = out->finish(out);out=0; result->destroy(result);result=0; } else { gfxresult_t*result = out->finish(out); msg("<notice> Writing SWF file %s", outputname); if(result->save(result, outputname) < 0) { exit(1); } int width = (int)(ptroff_t)result->get(result, "width"); int height = (int)(ptroff_t)result->get(result, "height"); result->destroy(result);result=0; if(preloader || viewer) { const char*zip = ""; if(zlib) { zip = "-z"; } if(!preloader && viewer) { systemf("swfcombine %s -X %d -Y %d \"%s\" viewport=\"%s\" -o \"%s\"",zip,width,height, viewer, outputname, outputname); if(!system_quiet) printf("\n"); } if(preloader && !viewer) { msg("<warning> --preloader option without --viewer option doesn't make very much sense."); ret = systemf("swfcombine %s -Y %d -X %d %s/PreLoaderTemplate.swf loader=\"%s\" movie=\"%s\" -o \"%s\"",zip,width,height, SWFDIR, preloader, outputname, outputname); if(!system_quiet) printf("\n"); } if(preloader && viewer) { #ifdef HAVE_MKSTEMP char tmpname[] = "__swf__XXXXXX"; mkstemp(tmpname); #else char*tmpname = "__tmp__.swf"; #endif systemf("swfcombine \"%s\" viewport=%s -o %s", viewer, outputname, tmpname); systemf("swfcombine %s -X %d -Y %d -r %f %s/PreLoaderTemplate.swf loader=%s movie=%s -o \"%s\"",zip,width,height, getRate(preloader), SWFDIR, preloader, tmpname, outputname); systemf("rm %s", tmpname); } } } pdf->destroy(pdf); driver->destroy(driver); /* free global parameters */ p = device_config; while(p) { parameter_t*next = p->next; if(p->name) free((void*)p->name);p->name = 0; if(p->value) free((void*)p->value);p->value =0; p->next = 0;free(p); p = next; } if(filters) { free(filters); } return 0; }