⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resource.cc

📁 蒙特卡洛仿真源代码很有参考价值要按照步骤进行操作
💻 CC
📖 第 1 页 / 共 3 页
字号:
voidResource::LoadInfoTexts(void){    XrmValue value;    char *value_type, str1[32], str2[32];    bool exists = true;    int infotext_counter = 1;        infotexts.clear();    infotexts.push_back("");    do {	sprintf(str1, "bbsmount.infotext%u", infotext_counter);	sprintf(str2, "Bbsmount.InfoText%u", infotext_counter);	if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {	    infotexts.push_back(string(value.addr));#if DEBUG	    if (debug_level >= dbg_all_work)		printf("Saving infotext nr. %d (%s).\n", infotext_counter, value.addr);#endif /* DEBUG */	}	else	    exists = false;	infotext_counter++;    } while (exists);    #if DEBUG    if (debug_level >= dbg_summary)	printf("%d infotexts found.\n", infotext_counter - 2);#endif /* DEBUG */}voidResource::LoadMountPoints(void){    XrmValue value;    char *value_type, str1[45], str2[45];    bool exists = true;    int mountpoint_counter = 1;    unsigned int image_number;        mount_points.clear();    do {	sprintf(str1, "bbsmount.mount%u", mountpoint_counter);	sprintf(str2, "Bbsmount.Mount%u", mountpoint_counter);	if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {	    mount_points.push_back(MountPoint(string(value.addr)));	    LoadActions(mountpoint_counter);	    LoadInfoText(mountpoint_counter);	    sprintf(str1, "bbsmount.mount%u.mountedimage", mountpoint_counter);	    sprintf(str2, "Bbsmount.Mount%u.MountedImage", mountpoint_counter);	    if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {		if (sscanf(value.addr, "%u", &image_number) == 1 && image_number <= images.size())		    mount_points.back().SetMountedImage(image_number);#if DEBUG		else		    printf("Image number assigned to mount point nr. %d is not correct (%s)!\n", mountpoint_counter, value.addr);#endif /* DEBUG */	    }#if DEBUG	    else		if (debug_level >= dbg_warning)		    printf("Mount point nr. %d don't have assigned mounted image!\n", mountpoint_counter);#endif /* DEBUG */	    sprintf(str1, "bbsmount.mount%u.notmountedimage", mountpoint_counter);	    sprintf(str2, "Bbsmount.Mount%u.NotMountedImage", mountpoint_counter);	    if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {		if (sscanf(value.addr, "%u", &image_number) == 1 && image_number <= images.size())		    mount_points.back().SetNotMountedImage(image_number);#if DEBUG		else		    printf("Image number assigned to mount point nr. %d is not correct (%s)!\n", mountpoint_counter, value.addr);#endif /* DEBUG */	    }#if DEBUG	    else		if (debug_level >= dbg_warning)		    printf("Mount point nr. %d don't have assigned not mounted image!\n", mountpoint_counter);#endif /* DEBUG */	    sprintf(str1, "bbsmount.mount%u.description", mountpoint_counter);	    sprintf(str2, "Bbsmount.Mount%u.Description", mountpoint_counter);	    if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {		mount_points.back().setDescription(value.addr);	    }#if DEBUG	    if (debug_level >= dbg_all_work)		printf("Loading data about mount point nr. %d.\n", mountpoint_counter);#endif /* DEBUG */	}	else	    exists = false;	mountpoint_counter++;    } while (exists);    #if DEBUG    if (debug_level >= dbg_summary)	printf("%d mount point definitions found.\n", mountpoint_counter - 2);#endif /* DEBUG */}voidResource::LoadActions(const int mount_point){    XrmValue value;    char *value_type, str1[54], str2[54];    bool exists = true;    int action_counter = 1;    unsigned int number, number2;    set<unsigned int> positive_mod, negative_mod;    int command_m = 0, command_n = 0, button = 0;    do {	positive_mod.clear();	negative_mod.clear();	sprintf(str1, "bbsmount.mount%u.action%u.command", mount_point, action_counter);	sprintf(str2, "Bbsmount.Mount%u.Action%u.Command", mount_point, action_counter);	if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {	    if (sscanf(value.addr, "%u,%u", &number, &number2) == 2 && number < commands.size() && number2 < commands.size()) {		command_n = number;		command_m = number2;	    }	    else {		if (sscanf(value.addr, "%u", &number) == 1 && number < commands.size()) {		    command_n = number;		    command_m = number;#if DEBUG		    if (debug_level >= dbg_all_work)			printf("Only one command found -- setting it to both mounted/not mounted commands.\n");#endif /* DEBUG */		}		else {#if DEBUG		    printf("Command number(s) assigned to mount point nr. %d is not correct (%s)!\n", mount_point, value.addr);#endif /* DEBUG */		    continue;		}	    }	}	else	    exists = false;	sprintf(str1, "bbsmount.mount%u.action%u.button", mount_point, action_counter);	sprintf(str2, "Bbsmount.Mount%u.Action%u.Button", mount_point, action_counter);	if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {	    if (!exists) {		exists = true;		continue;	    }	    if (sscanf(value.addr, "%u", &number) == 1 && number > 0 && number < max_button_number)		button = number;	    else {#if DEBUG		printf("Button number assigned to mount point nr. %d is not correct (%s)!\n", mount_point, value.addr);#endif /* DEBUG */		continue;	    }	}	else	    exists = false;	if (exists) {	    Action new_action;	    	    new_action.SetButton(button);	    new_action.SetCommand(command_m, true);	    new_action.SetCommand(command_n, false);	    sprintf(str1, "bbsmount.mount%u.action%u.modifiers", mount_point, action_counter);	    sprintf(str2, "Bbsmount.Mount%u.Action%u.Modifiers", mount_point, action_counter);	    if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {		GetModifiers(value.addr, positive_mod, negative_mod);		set<unsigned int>::iterator pointer;		for (pointer = positive_mod.begin(); pointer != positive_mod.end(); pointer++)		    new_action.AddModifier(*pointer);		for (pointer = negative_mod.begin(); pointer != negative_mod.end(); pointer++)		    new_action.AddNegativeModifier(*pointer);#if DEBUG		if (debug_level >= dbg_summary)		    printf("%u positive and %u negative modifiers added to action nr %d.\n", positive_mod.size(), negative_mod.size(), action_counter);#endif /* DEBUG */	    }	    mount_points.back().AddAction(new_action);	}	action_counter++;    } while (exists);#if DEBUG    if (debug_level >= dbg_summary)	printf("%d actions found for mount point nr %d.\n", action_counter - 2, mount_point);#endif /* DEBUG */}voidResource::LoadInfoText(const int mount_point){    XrmValue value;    char *value_type, str1[54], str2[54];    unsigned int number;    sprintf(str1, "bbsmount.mount%u.mountedtext", mount_point);    sprintf(str2, "Bbsmount.Mount%u.MountedText", mount_point);    if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {	if (sscanf(value.addr, "%u", &number) == 1 && number < infotexts.size())	    mount_points.back().setMountedInfo(number);#if DEBUG	else	    printf("Infotext number assigned to mount point nr. %d is not correct (%s)!\n", mount_point, value.addr);#endif /* DEBUG */    }    sprintf(str1, "bbsmount.mount%u.notmountedtext", mount_point);    sprintf(str2, "Bbsmount.Mount%u.NotMountedText", mount_point);    if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {	if (sscanf(value.addr, "%u", &number) == 1 && number < infotexts.size())	    mount_points.back().setNotMountedInfo(number);#if DEBUG	else	    printf("Infotext number assigned to mount point nr. %d is not correct (%s)!\n", mount_point, value.addr);#endif /* DEBUG */    }    sprintf(str1, "bbsmount.mount%u.errortext", mount_point);    sprintf(str2, "Bbsmount.Mount%u.ErrorText", mount_point);    if (XrmGetResource(resource_db, str1, str2, &value_type, &value)) {	if (sscanf(value.addr, "%u", &number) == 1 && number < infotexts.size())	    mount_points.back().setErrorInfo(number);#if DEBUG	else	    printf("Infotext number assigned to mount point nr. %d is not correct (%s)!\n", mount_point, value.addr);#endif /* DEBUG */    }}voidResource::GetModifiers(const string str, set<unsigned int> &positive, set<unsigned int> &negative) const{    int start = 0, stop = 0;    bool is_negative = false;    const char **result;        while (start < (int)str.length()) {	if (isalnum(str[start])) {	    stop = start + 1;	    while (stop <= (int)str.length() && isalnum(str[stop]))		stop++;	    const_cast<char **>(result) = find(modifiers, modifiers + modifiers_count, str.substr(start, stop - start));	    if (result < modifiers + modifiers_count) {		if (is_negative)		    negative.insert(modifiers_mask[distance(modifiers, result)]);		else		    positive.insert(modifiers_mask[distance(modifiers, result)]);	    }#if DEBUG	    else		printf("(%s) is not valid modifier!\n", str.substr(start, stop - start).c_str());#endif /* DEBUG */	    is_negative = false;	    start = stop;	}	else	    if (str[start] == '!')		is_negative = true;	start++;    }}/* from blackbox/src/Screen.cc */static const char *getFontElement(const char *pattern, char *buf, int bufsiz, ...) {  const char *p, *v;  char *p2;  va_list va;  va_start(va, bufsiz);  buf[bufsiz-1] = 0;  buf[bufsiz-2] = '*';  while((v = va_arg(va, char *)) != NULL) {    p = strcasestr(pattern, v);    if (p) {      strncpy(buf, p+1, bufsiz-2);      p2 = strchr(buf, '-');      if (p2) *p2=0;      va_end(va);      return p;    }  }  va_end(va);  strncpy(buf, "*", bufsiz);  return NULL;}static const char *getFontSize(const char *pattern, int *size) {  const char *p;  const char *p2=NULL;  int n=0;  for (p=pattern; 1; p++) {    if (!*p) {      if (p2!=NULL && n>1 && n<72) {        *size = n; return p2+1;      } else {        *size = 16; return NULL;      }    } else if (*p=='-') {      if (n>1 && n<72 && p2!=NULL) {        *size = n;        return p2+1;      }      p2=p; n=0;    } else if (*p>='0' && *p<='9' && p2!=NULL) {      n *= 10;      n += *p-'0';    } else {      p2=NULL; n=0;    }  }}XFontSetResource::createFontSet(const string &fontname) {  XFontSet fs;  char **missing, *def = "-";  int nmissing, pixel_size = 0, buf_size = 0;  char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE];  fs = XCreateFontSet(bbtool->getXDisplay(),                      fontname.c_str(), &missing, &nmissing, &def);  if (fs && (! nmissing))    return fs;  const char *nfontname = fontname.c_str();#ifdef    HAVE_SETLOCALE  if (! fs) {    if (nmissing) XFreeStringList(missing);    setlocale(LC_CTYPE, "C");    fs = XCreateFontSet(bbtool->getXDisplay(), fontname.c_str(),                        &missing, &nmissing, &def);    setlocale(LC_CTYPE, "");  }#endif // HAVE_SETLOCALE  if (fs) {    XFontStruct **fontstructs;    char **fontnames;    XFontsOfFontSet(fs, &fontstructs, &fontnames);    nfontname = fontnames[0];  }  getFontElement(nfontname, weight, FONT_ELEMENT_SIZE,                 "-medium-", "-bold-", "-demibold-", "-regular-", NULL);  getFontElement(nfontname, slant, FONT_ELEMENT_SIZE,                 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL);  getFontSize(nfontname, &pixel_size);  if (! strcmp(weight, "*"))    strncpy(weight, "medium", FONT_ELEMENT_SIZE);  if (! strcmp(slant, "*"))    strncpy(slant, "r", FONT_ELEMENT_SIZE);  if (pixel_size < 3)    pixel_size = 3;  else if (pixel_size > 97)    pixel_size = 97;  buf_size = strlen(nfontname) + (FONT_ELEMENT_SIZE * 2) + 64;  char *pattern2 = new char[buf_size];  sprintf(pattern2,           "%s,"           "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"           "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",           nfontname, weight, slant, pixel_size, pixel_size);  nfontname = pattern2;  if (nmissing)    XFreeStringList(missing);  if (fs)    XFreeFontSet(bbtool->getXDisplay(), fs);  fs = XCreateFontSet(bbtool->getXDisplay(), nfontname, &missing,                      &nmissing, &def);  delete [] pattern2;  return fs;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -