MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / parse_ctl_file

Method parse_ctl_file

win32/WinController.cpp:1673–1766  ·  view source on GitHub ↗

okay, now search for a '****.ctl' file in the current directory.

Source from the content-addressed store, hash-verified

1671
1672// okay, now search for a '****.ctl' file in the current directory.
1673void gameWinController::parse_ctl_file(int devnum, const char *ctlname) {
1674 // parse each file until we find a name match, no name match, just return
1675 char filename[_MAX_FNAME];
1676 int i;
1677
1678 if (ddio_FindFileStart("*.ctl", filename)) {
1679 do {
1680 InfFile file;
1681 bool found_name = false;
1682
1683 if (file.Open(filename, "[controller settings]", CTLLex)) {
1684 // parse each line, setting the appropriate values, etc.
1685 while (file.ReadLine()) {
1686 int cmd;
1687 char operand[128];
1688
1689 while ((cmd = file.ParseLine(operand, INFFILE_LINELEN)) > INFFILE_ERROR) {
1690 // we want to assert that the name command comes before any other to verify
1691 // this is the file we really want to change.
1692 switch (cmd) {
1693 case CTLCMD_NAME:
1694 if (strcmp(ctlname, operand) != 0)
1695 goto cancel_file_parse;
1696 found_name = true;
1697 break;
1698
1699 case CTLCMD_DEAD: // deadzone
1700 if (!found_name)
1701 goto cancel_file_parse;
1702 else {
1703 m_ControlList[devnum].deadzone = atof(operand);
1704 }
1705 break;
1706
1707 case CTLCMD_AXIS: // allowable axis.
1708 // format of command is "+Z-R"
1709 // this would add a Z axis to the controller. -R would remove the Rudder.
1710 // you can do this for X,Y,Z,R,U,V.
1711 if (!found_name)
1712 goto cancel_file_parse;
1713 else {
1714 int slen = strlen(operand);
1715 for (i = 0; i <= slen; i += 2) {
1716 int axis_flag;
1717 if ((i + 1) <= slen) {
1718 char axis_cmd = tolower(operand[i + 1]);
1719 if (axis_cmd == 'x')
1720 axis_flag = CTF_X_AXIS;
1721 else if (axis_cmd == 'y')
1722 axis_flag = CTF_Y_AXIS;
1723 else if (axis_cmd == 'z')
1724 axis_flag = CTF_Z_AXIS;
1725 else if (axis_cmd == 'r')
1726 axis_flag = CTF_R_AXIS;
1727 else if (axis_cmd == 'u')
1728 axis_flag = CTF_U_AXIS;
1729 else if (axis_cmd == 'v')
1730 axis_flag = CTF_V_AXIS;

Callers

nothing calls this directly

Calls 7

ReadLineMethod · 0.80
ParseLineMethod · 0.80
ddio_FindFileStartFunction · 0.50
ddio_FindNextFileFunction · 0.50
ddio_FindFileCloseFunction · 0.50
OpenMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected