ALT Linux Bugzilla
– Attachment 5070 Details for
Bug 26177
Не запускается
New bug
|
Search
|
[?]
|
Help
Register
|
Log In
[x]
|
Forgot Password
Login:
[x]
|
EN
|
RU
test case
test_ddcci.c (text/x-csrc), 4.17 KB, created by
viy
on 2011-08-28 00:26:42 MSK
(
hide
)
Description:
test case
Filename:
MIME Type:
Creator:
viy
Created:
2011-08-28 00:26:42 MSK
Size:
4.17 KB
patch
obsolete
>#include <stdio.h> >#include <string.h> >#include <unistd.h> >#include <stdlib.h> > ># define _(X) X > >struct profile; > >enum monitor_type { >unk = 0, >lcd = 1, >crt = 2 >}; > >/* Structure to store CAPS vcp entry (control and related values) */ >struct vcp_entry { > int values_len; /* -1 if values are not specified */ > unsigned short* values; >}; > >/* Structure to store CAPS */ >struct caps { > struct vcp_entry* vcp[256]; /* vcp entries */ > enum monitor_type type; > char* raw_caps; /* raw text caps */ >}; > > >/* See documentation Appendix D. > * Returns : > * -1 if an error occured > * number of controls added > * > * add: if true: add caps_str to caps, otherwise remove caps_str from the caps. > */ >int ddcci_parse_caps(const char* caps_str, struct caps* caps, int add) >{ >// printf("Parsing CAPS (%s).\n", caps_str); > int pos = 0; /* position in caps_str */ > > int level = 0; /* CAPS parenthesis level */ > int svcp = 0; /* Current CAPS section is vcp */ > int stype = 0; /* Current CAPS section is type */ > > char buf[8]; > char* endptr; > int ind = -1; > long val = -1; > int i; > int removeprevious = 0; > > int num = 0; > > for (pos = 0; caps_str[pos] != 0; pos++) > { > if (caps_str[pos] == '(') { > level++; > } > else if (caps_str[pos] == ')') > { > level--; > if (level == 1) { > svcp = 0; > stype = 0; > } > } > else if (caps_str[pos] != ' ') > { > if (level == 1) { > if ((strncmp(caps_str+pos, "vcp(", 4) == 0) || (strncmp(caps_str+pos, "vcp ", 4) == 0)) { > svcp = 1; > pos += 2; > } > else if (strncmp(caps_str+pos, "type", 4) == 0) { > stype = 1; > pos += 3; > } > } > else if ((stype == 1) && (level == 2)) { > if (strncmp(caps_str+pos, "lcd", 3) == 0) { > caps->type = lcd; > pos += 2; > } > else if (strncmp(caps_str+pos, "crt", 3) == 0) { > caps->type = crt; > pos += 2; > } > } > else if ((svcp == 1) && (level == 2)) { > if (!add && ((removeprevious == 1) || (caps->vcp[ind] && caps->vcp[ind]->values_len == 0))) { > if(caps->vcp[ind]) { > if (caps->vcp[ind]->values) { > free(caps->vcp[ind]->values); > } > free(caps->vcp[ind]); > caps->vcp[ind] = NULL; > } > } > buf[0] = caps_str[pos]; > buf[1] = caps_str[++pos]; > buf[2] = 0; > ind = strtol(buf, &endptr, 16); > if (*endptr != 0) { > printf(_("Can't convert value to int, invalid CAPS (buf=%s, pos=%d).\n"), buf, pos); > return -1; > } > if (add) { > caps->vcp[ind] = malloc(sizeof(struct vcp_entry)); > caps->vcp[ind]->values_len = -1; > caps->vcp[ind]->values = NULL; > } > else { > removeprevious = 1; > } > num++; > } > else if ((svcp == 1) && (level == 3)) { > i = 0; > while ((caps_str[pos+i] != ' ') && (caps_str[pos+i] != ')')) { > buf[i] = caps_str[pos+i]; > i++; > } > buf[i] = 0; > val = strtol(buf, &endptr, 16); > if (*endptr != 0) { > printf(_("Can't convert value to int, invalid CAPS (buf=%s, pos=%d).\n"), buf, pos); > return -1; > } > if (add) { > if (caps->vcp[ind]->values_len == -1) { > caps->vcp[ind]->values_len = 1; > } > else { > caps->vcp[ind]->values_len++; > } > caps->vcp[ind]->values = realloc(caps->vcp[ind]->values, caps->vcp[ind]->values_len*sizeof(unsigned short)); > caps->vcp[ind]->values[caps->vcp[ind]->values_len-1] = val; > } > else { > if (caps->vcp[ind]->values_len > 0) { > removeprevious = 0; > int j = 0; > for (i = 0; i < caps->vcp[ind]->values_len; i++) { > if (caps->vcp[ind]->values[i] != val) { > caps->vcp[ind]->values[j++] = caps->vcp[ind]->values[i]; > } > } > caps->vcp[ind]->values_len--; > } > } > } > } > } > > if (!add && ((removeprevious == 1) || (caps->vcp[ind] && caps->vcp[ind]->values_len == 0))) { > if(caps->vcp[ind]) { > if (caps->vcp[ind]->values) { > free(caps->vcp[ind]->values); > } > free(caps->vcp[ind]); > caps->vcp[ind] = NULL; > } > } > > return num; >} > >int main(int argc, char **argv) >{ > struct caps caps; > char* caps_str="(prot(monitor)type(lcd)model(L196WTQ)cmds(0102030CE3F3)vcp(0203040506080B0C0E101214(01050607080B)16181A1E20303E5260(0103)6C6E7087ACAEB6C0C6C8C9D6(0104)DFF1F2(000102)F3(00010203)FC(00010203)FD(0001)FE(000102)FF)mswhql(1)mccs_ver(2.1))"; > return ddcci_parse_caps(caps_str, &caps, 1); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 26177
:
5069
| 5070 |
5071