QT¸¦ »ç¿ëÇÑ XÀ©µµ¿ì¿ë ³×Æ®¿öÅ© °ü¸®Åø ¹Ú¿µ¼±(youngsun@i-top.co.kr) ³¯Â¥: 1999.12.26 ÄÄÆÄÀÏ·¯: gcc ¾ð¾î : C++ (QT 1.44 Library »ç¿ë) ȯ°æ : ¾ËÂ¥¸®´ª½º 6.1 XWindowȯ°æ =============================================================== <µé¾î°¡±âÀü¿¡...> ¾È³çÇϼ¼¿ä. (ÁÖ)¾ÆÀÌž¿¡¼­ °³¹ß¿¬±¸¿øÀ¸·Î ÀÏÇÏ°í ÀÖ´Â ¹Ú¿µ¼±À̶ó°í ÇÕ´Ï´Ù. ¿ì¼±, °£´ÜÇÏ°Ô ÀÌ ÀÚ·áÀÇ ³»¿ëÀ» ¼Ò°³ÇÑ µÚ ½ÃÀÛÇϱâ·Î ÇÏÁÒ. Á¦°¡ ¸®´ª½º¸¦ óÀ½ Á¢ÇÏ°í, ¶Ç Gtk¿Í QT¸¦ ¸¸³ª°Ô µÇ¸é¼­, ½ÇÁ¦ Àú Èñȸ»ç Á¦Ç°°³¹ß´ç½Ã Èûµé¾ú´ø Á¡°ú °³¹ß ÈÄ¿¡ ´À²¼´ø ¹ÌºñÇÑ Á¡µî À» Âü°íÇؼ­ ÀÌ ÇÁ·ÎÁ§Æ®¸¦ °èȹÇÏ°Ô µÇ¾ú½À´Ï´Ù. ÀÌ ÇÁ·ÎÁ§Æ®´Â ÀúÈñȸ»ç °³¹ß¿øµéÀÌ °³¹ßÇß´ø Topflash¶ó´Â, ³× Æ®¿öÅ©, ÇÁ¶ô½Ã, ¹æÈ­º®, ¸Þ½ÅÀúµîÀ» Á¾ÇÕÀûÀ¸·Î °ü¸®ÇÒ ¼ö ÀÖ´Â ÅëÇÕÀÎÅͳݼַç¼ÇÁß Á¦°¡ °³¹ßÇÑ TopmanagerX¸¦ ±â¹ÝÀ¸·Î ¸¸µé¾îÁ³ ½À´Ï´Ù. ÀÌ´Â QT¶óÀ̺귯¸®¿Í, ANSI-C±â¹ÝÀÇ file󸮷çƾÀ» ¶óÀ̺귯¸®·Î ¹­¾î ±¸ÇöÇÑ ³»¿ëÀÔ´Ï´Ù. »çÁ¤»ó ÀÌ Áß¿¡¼­ ³×Æ®¿öÅ©°ü¸®¸¦ QT¸¦ »ç¿ëÇÏ¿© ±¸ÇöÇغ¸µµ·Ï ÇÏ°Ú ½À´Ï´Ù. ´ÙÀ½¿¡´Â Gtk¸¦ ÀÌ¿ëÇÑ ¹öÁ¯À» ´Ù¸¥ ó¸® ³»¿ëÀÇ ±Û·Î ¿Ã¸®°Ú½À´Ï´Ù. ¹®ÀÇ»çÇ×À̳ª °³¼±Á¡À» ¹ß°ßÇϽźеéÀº À§ÀÇ E-mailÁÖ¼Ò·Î ²À ¿¬¶ô ÇØÁֽñ⠹ٶø´Ï´Ù. ±×¸®°í GtkÀÇ ±ÛÀÌ ³¡³ª¸é ¸¶Áö¸·À¸·Î KernelºÐ¼®¿¡ °üÇÑ ÀڷḦ ¸¸ µé±î »ý°¢ÁßÀÔ´Ï´Ù. ¸¹Àº °ü½É°ú °Ý·Á ºÎŹµå¸³´Ï´Ù. =============================================================== <¸ñÂ÷> 0. RedHat Linux 6.1ÀÇ System°ü¸®File¿¡ °üÇÏ¿©... 0.1. /etcµð·ºÅ丮¿¡ ÀÖ´Â fileµé 0.1.1. /etc/conf.modules 0.1.2. /etc/sysconfig/network-scripts/ifcfg-eth0 0.1.3. /etc/sysconfig/network 1. ÀÌÁß¿¬°á¸®½ºÆ®¸¦ ÀÌ¿ëÇÑ Fileó¸® ·çƾ¿¡ °üÇÏ¿©... 1.1. ÀÌÁß¿¬°á¸®½ºÆ®(Double LinkedList) ±¸Çö 1.2. fileó¸® ¶óÀ̺귯¸® ±¸Çö 1.3. °³¼±µÇ¾î¾ßÇÒ ³»¿ë 2. QT ±âº» ´ÙÁö±â 2.1. QTÀÇ Class°èÃþÁ¤º¸ 2.2. WidgetÀ̶õ? 2.2.1. À§Á¬(QWidget), ÇÁ·¹ÀÓ(QFrame), ¹öÆ°(QButton) 2.2.2. Makefile ¸¸µé±â 2.2.3. ¶óº§(QLabel) 2.2.4. ÆíÁý¹Ú½º(QLineEdit) 2.2.4.1 QObject::connect, SIGNAL°ú SLOT 2.2.5. ÄÞº¸¹Ú½º(QComboBox) 2.2.6. ¸®½ºÆ®(QListView) 2.2.7. üũ¹Ú½º(QCheckBox), ¶óµð¿À¹öÆ°(QRadioButton) 2.2.8. ¸Þ´º(QMenu) 2.2.9. Åø¹Ù(QToolBar)¿Í ¸ÞÀÎÀ©µµ¿ì(QMainWindow) 2.3. QT¸¦ ¾òÀ¸·Á¸é? < ÇѸ¶µð >. 3. ±âº» Format ÀÛ¼ºÇϱâ 3.1. ¸Þ´º ¸¸µé±â 3.2. Åø¹Ù Áý¾î³Ö±â 3.3. Network°ü·Ã ¶óÀ̺귯¸® ±¸ÇöÇϱâ 3.4. Class¸¸µé±â 3.4.1 ÀϹݳ×Æ®¿öÅ©°ü¸® 3.4.2 DNS°ü¸® 3.4.3 IP-Aliasing°ü¸® < *** Àüü Source *** > 3.5. °³¼±µÇ¾î¾ßÇÒ ³»¿ë 4. ÇÁ·ÎÁ§Æ®¸¦ ¸¶Ä¡°í... =============================================================== < 0. RedHat Linux 6.1ÀÇ System°ü¸®File¿¡ °üÇÏ¿©... > 0.1. /etcµð·ºÅ丮¿¡ ÀÖ´Â fileµé 0.1.1. /etc/conf.modules ÀÌ fileÀº Çϵå¿þ¾î¿¡ »õ·Î¿î µð¹ÙÀ̽º°¡ Ãß°¡µÇ¾úÀ» ¶§ ÇØ´ç µð¹ÙÀ̽º¸ð µâÀ» ¾Ë±â ½¬¿î À̸§À¸·Î ¼ÓÀÌ´Â ¿ªÇÒÀ» ÇÑ´Ù. ¿¹¸¦µé¾î Lan CardÀÇ ChipsetÀ̸§ÀÌ 3c59x¶ó¸é /etc/conf.modules¿¡´Â ´Ù À½°ú °°Àº ³»¿ëÀÌ µé¾î°¡¾ßÇÑ´Ù. alias eth0 3c59x ¿©±â¼­ 3c59x´Â ¾ö¹ÐÈ÷ ¸»ÇÏÀÚ¸é ChipsetÀÇ À̸§ÀÌ ¾Æ´Ï¶ó ¸®´ª½º¿¡¼­ Á¦ °øÇÏ´Â Network ModuleÀÇ À̸§ÀÌ´Ù. ¸®´ª½ºÀÇ Á¦°ø Network ModuleµéÀº °¢°¢ ChipsetÀ̸§¿¡ 1:1 ¸ÅÄ¡µÈ´Ù.(¿©±â¼­ÀÇ ModuleÀ̶õ Windows¿¡¼­ÀÇ µå¶óÀ̹ö°³³ä°ú ºñ½ÁÇÏ´Ù.) Module fileµéÀº *.o·Î ³¡³ª¸ç À̵鿡 ´ëÇÑ Á¤º¸´Â /lib/modules/2.2.12-20kr/net µð·ºÅ丮¿¡ ÀÖ´Ù. À§ÀÇ "alias eth0 3c59x"ÀÇ Àǹ̴ 3c59x¸ðµâÀ» eth0·Î aliasingÇؼ­ ¾²°Ú ´Ù´Â ¶æÀÌ´Ù. ¸¸¾à Lan Card°¡ µÎÀåÀÌ»ó ½Ã½ºÅÛ¿¡ ¼³Ä¡µÇ¾îÀÖ´Ù¸é ¾Æ·¡¿Í °°Àº Á¤º¸°¡ Ãß °¡µÇ¾îÀÖÀ» °ÍÀÌ´Ù. alias eth1 '¸ðµâÀ̸§' alias eth2 '¸ðµâÀ̸§' ¸¸¾à Ä«µå°¡ ISA¶ó¸é ÀÌ file¾È¿¡¼­ io¿Í irq¹øÈ£¸¦ ¼öµ¿À¸·Î ¼³Á¤ÇØÁÖ¾î¾ß ÇÑ´Ù. ¿ø·¡ io, irq¶ÇÇÑ ¼³Á¤ÇÏ´Â ·çƾµµ °°ÀÌ ³ÖÀ¸·Á°í ÇßÁö¸¸, ¿äÁîÀ½ 90% ÀÌ»ó PCIÄ«µå¸¦ »ç¿ëÇÏ°í ÀÖÀ¸¹Ç·Î ÀÌ ¼³Á¤Àº »°´Ù. 0.1.2. /etc/sysconfig/network-scripts/ifcfg-eth0 À§ ÀÛ¾÷À» ¸¶ÃÆ´Ù¸é ´ÙÀ½ fileÀÇ ³»¿ëÀ» scanÇغ¸ÀÚ. cat /etc/sysconfig/network-scripts/ifcfg-eth0 ´ÙÀ½°ú °°Àº ³»¿ëÀÌ Ãâ·ÂµÉ °ÍÀÌ´Ù. DEVICE=eth0 BROADCAST=172.31.255.255 IPADDR=172.31.0.202 NETMASK=255.255.0.0 NETWORK=172.31.0.0 ONBOOT=yes ¹°·Ð IP, Netmask, Network, BroadcastµîÀº ÀÌ·¸°Ô µÇ¾îÀÖÁö´Â ¾ÊÀ» °ÍÀÌ´Ù. ¸Ç ¸¶Áö¸·ÁÙÀÇ "ONBOOT=yes"ÀÇ ¶æÀº ½Ã½ºÅÛÀÇ ºÎÆýÿ¡ ¸ðµâÀ» ¿Ã¸± °ÍÀÎÁö¿¡ ´ëÇÑ ¿É¼ÇÀÌ´Ù. ÀÌ fileÀÌ ¾ø´Ù¸é ¿¡µðÅ͸¦ ½á¼­ fileÀ» »ý¼º½ÃÅ°±â ¹Ù¶õ´Ù. ÀÌ·¸°Ô settingÀ» ÇÏ°í, ¸¸¾à Lan CardÀÇ ChipsetÀÌ 3c59x¿¡ ÇØ´çµÇ´Â ¸ðµâ¿¡ ¸ÅÄ¡µÈ´Ù¸é ´ÙÀ½ ¸í·É¾î¸¦ ½ÇÇàÇغ¸¶ó. /etc/rc.d/init.d/network restart ÀÌ ¸í·É¾î¸¦ ½ÇÇàÇÏ°Ô µÇ¸é ¸ðµâ¿Ã¸®±â¿¡ ¼º°øÇÏ´ÂÁö ½ÇÆÐÇÏ´ÂÁö¸¦ ³ªÅ¸³»ÁØ´Ù. ¸¸¾à ¼º°øÇÑ´Ù¸é ¸¶Áö¸·À¸·Î ´ÙÀ½ ¸í·É¾î¸¦ ½ÇÇàÇغ»´Ù. ifconfig ÀÌ ¸í·É¾î¿¡ ´ëÇÑ ÇÊÀÚÀÇ ½Ã½ºÅÛ¿¡¼­ÀÇ °á°ú°ªÀº ´ÙÀ½°ú °°´Ù. eth0 Link encap:Ethernet HWaddr 00:90:27:A2:70:DE inet addr:172.31.0.1 Bcast:172.31.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:88055 errors:0 dropped:0 overruns:0 frame:0 TX packets:119306 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 Interrupt:17 Base address:0xef00 eth1 Link encap:Ethernet HWaddr 00:90:27:57:17:27 inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 Interrupt:16 Base address:0xef40 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:3924 Metric:1 RX packets:146 errors:0 dropped:0 overruns:0 frame:0 TX packets:146 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 À§ÀÇ °á°ú°ª¿¡¼­ º¼ ¼ö ÀÖµíÀÌ ÇÊÀÚÀÇ IP(°¡»ó)Àº "inet addr:172.31.0.1"¿¡ ¸í½ÃµÇ¾î ÀÖ°í ³ª¸ÓÁö Broadcast¿Í Netmask¿¡ ´ëÇÑ Á¤º¸ ¶ÇÇÑ ³ªÅ¸³ªÀÖ´Ù. ¿©±â¼­ eth1¿¡ ´ëÇÑ Á¤º¸´Â µÎ¹ø° Lan Card¸¦ ÀåÂøÇßÀ» ¶§, ¶Ç ±× Card¸¦ OS¿¡¼­ ¿Ã¹Ù¸£°Ô ÀνÄÇßÀ» ¶§ ³ªÅ¸³ª´Â Á¤º¸ÀÌ´Ù. ¼³Á¤ fileµé¿¡ ´ëÇÑ Á¤º¸´Â eth0¿Í Èí»çÇÏ´Ù. Ãâ·Â°á°úÁß ¼¼¹ø° ´Ü¶ôÀÇ "lo"´Â localhost¿¡ ´ëÇÑ Á¤º¸ÀÌ´Ù. ÀÌ °á°ú°ªÀº kernel¿¡¼­ default·Î settingÇÏ¿©ÁֹǷΠº°·Î ½Å°æ¾µ ÇÊ¿ä°¡ ¾ø´Ù. 0.1.3. /etc/sysconfig/network ÀÌ fileÀº È£½ºÆ®³×ÀÓ°ú °ÔÀÌÆ®¿þÀ̸¦ ¼³Á¤ÇÏ´Â fileÀÌ´Ù. ÀÌ fileÀ» catÇغ¸ÀÚ. NETWORKING=yes FORWARD_IPV4=false HOSTNAME=superbug.i-top.co.kr GATEWAY=172.31.0.200 À§ÀÇ Ã³À½ µÎÁÙÀº Ưº°ÇÑ ¼ÂÆÃÀÌ ÇÊ¿äÇÑ °æ¿ì¸¦ Á¦¿ÜÇÏ°í´Â º°·Î ¼³Á¤°ªÀ» ¹Ù²Ü ÀÏÀÌ ¾øÀ¸¸®¶ó »ý°¢ÇÑ´Ù. ·¹µåÇò 6.xÀÌÀü ¹öÁ¯±îÁö´Â ÀÌ°÷¿¡ DOMAINNAME°ú GATEWAYDEVÇ׸ñÀÌ µé¾îÀÖ ¾úÀ¸³ª 6.xÀÌÈĺÎÅÍ´Â ±× ºÎºÐÀÌ ºüÁ³´Ù. ÀÌ Ç׸ñµéÀº À־ ±×¸¸, ¾ø¾îµµ ±×¸¸À̹ǷΠ½Å°æ¾µ ÇÊ¿ä´Â ¾ø´Ù. DOMAINNAMEÇ׸ñÀº HOSTNAME¿¡ Æ÷ÇÔÀÌ µÇ¾ú °í, GATEWAYDEV´Â µðÆúÆ®·Î eth0¸¦ ¼ÂÆÃÇϵµ·Ï µÇ¾îÀÖ´Ù. < 1. ÀÌÁß¿¬°á¸®½ºÆ®¸¦ ÀÌ¿ëÇÑ Fileó¸® ·çƾ¿¡ °üÇÏ¿©... > -> File󸮷çƾ¿¡ ÀÌÁß¿¬°á¸®½ºÆ®¸¦ ÀÌ¿ëÇÑ ¸ñÀû: File󸮷çƾÀº ÀÌÁß¿¬°á¸®½ºÆ®¸¦ ÀÌ¿ëÇÑ ¹æ¹ýÀ» ¼±ÅÃÇÏ¿´´Ù. ¿¬°á¸®½ºÆ®¸¦ ¼±ÅÃÇÑ °¡Àå Áß¿äÇÑ ÀÌÀ¯´Â È®À强ÀÇ ¿ëÀÌÇÔ¶§¹®ÀÌ´Ù. °¡Àå ÈçÇÑ File󸮹æ¹ýÀº DB(ISAM, Postgre sql, mysql±âŸµîµî)¸¦ ÀÌ¿ëÇÏ´Â ¹æ¹ýÀÌ ÀÖ°í, ȤÀº File¿¡¼­ ÇÑ°³ÀÇ ¹®ÀÚ¾¿ Àоîµé¿© ó¸® ÇÏ´Â ¹æ¹ýµî ¿©·¯°¡Áö°¡ ÀÖ´Ù. ÇÏÁö¸¸ DB¸¦ ÀÌ¿ëÇÏ´Â ¹æ¹ýÀº ´ë¿ë·® µ¥ÀÌÅ͸¦ ó¸®ÇÒ ¶§, ±×¸®°í µ¥ÀÌÅÍ Æ÷¸ËÀÌ Á¤ÇüÈ­µÇ¾îÀÖÀ» ¶§ ¾²´Â ¹æ¹ýÀÌ°í, ÇÑ°³ÀÇ ¹®ÀÚ¾¿ ÀÐ ¾îµé¿© ó¸®ÇÏ´Â ¹æ¹ýÀº Çѵΰ³Á¤µµÀÇ FileÀ» ó¸®ÇÒ ¶§³ª À¯¿ëÇÑ ¹æ¹ýÀ̹ǷΠ¹ü¿ëÀûÀÌÁö ¸øÇÏ´Ù. LinuxÀÇ Network °ü·Ã FileµéÀº °¢°¢ÀÇ Á¤º¸°¡ ¸ðµÎ Á¤ÇüÈ­µÇ¾îÀÖÁöµµ ¾Ê°í ¶ÇÇÑ ÀÚÁÖ ¾÷±×·¹À̵åµÇ´Â Á¤º¸µéÀ̹ǷΠ¹ü¿ëÀûÀΠ󸮷çƾÀÌ ÇÊ ¿äÇÏ´Ù. ´Ù¸¥ ÁÁÀº ¹æ¹ýµéµµ ÀÖ°ÚÁö¸¸, ±×¸®°í ¹®ÀÚ󸮹æ½ÄÀ» È®Àå½ÃÅ°´Â ¹æ ¹ýµµ ÀÖ°ÚÁö¸¸, ¼Õ½±°Ô FileÀ» ó¸®Çϱâ À§ÇØ, ¸Þ¸ð¸®°ü¸®¸¦ È®½ÇÇÏ°Ô ÇϱâÀ§ÇØ ¿¬°á¸®½ºÆ®¸¦ »ç¿ëÇß´Ù. ¿©·¯ºÐ²²¼­ ´õ ÁÁÀº ¹æ¹ýÀ̳ª ȤÀº ´õ ÁÁÀº ·çƾÀ» °¡Áö°í °è½ÅºÐÀº ÁúŸ¿Í °¡¸£Ä§À» Áֽñ⠹ٶõ´Ù. =============================================================== 1.1. ÀÌÁß¿¬°á¸®½ºÆ®(Double LinkedList) ±¸Çö ÀÌÁß¿¬°á¸®½ºÆ®¿¡ ´ëÇÑ source´Â ÀÎÅÍ³Ý»ó¿¡ ³Î·ÁÀÖ°í, ÇкΰúÁ¤¿¡¼­µµ Áö°ã°Ô ´Ù·ç´Â ºÎºÐÀ̹ǷΠÀÌ ºÎºÐ¿¡ ´ë ÇÑ ¼³¸íÀº Á¢¾îµÎ±â·Î ÇÏ°í file³»¿ë¸¸ º¸¿©ÁÖµµ·Ï ÇÏ°Ú´Ù. --- < source 1.1.1 Double LinkedList. Filename:procfile.h > --- #include #ifndef _LINKLIST_H_ #define _LINKLIST_H_ #ifndef SUCCESS #define SUCCESS 1 #define FAIL 0 #endif #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif #ifndef _DOUBLE_LINKLIST_ #define _DOUBLE_LINKLIST_ typedef struct tagDOUBLELINK { void *pzKey; struct tagDOUBLELINK *next; struct tagDOUBLELINK *prev; } DList; void initDL(void); DList *searchDL(void *pzSearch); DList *insertAsFirstDL(void *pzInsert); DList *insertDL(void *pzInsert, DList *pIns); /* insert front node p */ DList *insertDLAsKey(void *pzInsert, void *pzSearch); DList *insertDLAsSort(void *pzInsert); int deleteDL(DList *pDel); int deleteDLAsKey(void *pzSearch); void deleteAllDL(void); void deletePerfectDL(void); void *printDL(DList *pPrint); #endif #endif ---------------------------------------------------------------- --- < source 1.1.2 Double LinkedList. Filename:procfile.c > --- #include #include #include #include #include "proc_file.h" DList *dblhead; DList *dbltail; void initDL(void) { dblhead = (DList *)malloc(sizeof(DList)); dbltail = (DList *)malloc(sizeof(DList)); dblhead->prev = dblhead; dblhead->next = dbltail; dbltail->prev = dblhead; dbltail->next = dbltail; } DList *searchDL(void *pzSearch) { DList *s; s = dblhead->next; while (s != dbltail) { if (memcmp(s->pzKey, pzSearch, sizeof(pzSearch)) == 0) break; s = s->next; } return s; } DList *insertAsFirstDL(void *pzInsert) { DList *p; p = (DList *)malloc(sizeof(DList)); p->pzKey = pzInsert; p->next = dblhead->next; dblhead->next->prev = p; dblhead->next = p; p->prev = dblhead; return p; } DList *insertAsLastDL(void *pzInsert) { insertDL(pzInsert, dbltail); return (DList *)NULL; } DList *insertDL(void *pzInsert, DList *pIns) /* insert front node pIns */ { DList *s; if (pIns == dblhead) return NULL; s = (DList *)malloc(sizeof(DList)); s->pzKey = pzInsert; pIns->prev->next = s; s->prev = pIns->prev; s->next = pIns; pIns->prev = s; return s; } DList *insertDLAsKey(void *pzInsert, void *pzSearch) { /* insert insk front findk */ DList *s; DList *r = NULL; s = searchDL(pzSearch); if (s != dbltail) { r = (DList *)malloc(sizeof(DList)); r->pzKey = pzInsert; s->prev->next = r; r->prev = s->prev; r->next = s; s->prev = r; } return r; } DList *insertDLAsSort(void *pzInsert) { DList *s; DList *r; s = dblhead->next; while (s != dbltail) { if (memcmp(s->pzKey, pzInsert, sizeof(pzInsert)) >= 0) break; s = s->next; } r = (DList *)malloc(sizeof(DList)); r->pzKey = pzInsert; s->prev->next = r; r->prev = s->prev; r->next = s; s->prev = r; return r; } int deleteDL(DList *pDel) { if (pDel == dblhead || pDel == dbltail) return FAIL; pDel->prev->next = pDel->next; pDel->next->prev = pDel->prev; free(pDel); return SUCCESS; } int deleteDLAsKey(void *pzSearch) { DList *s; s = searchDL(pzSearch); if (s != dbltail) { s->prev->next = s->next; s->next->prev = s->prev; free(s); return SUCCESS; } return FAIL; } void deleteAllDL(void) { DList *s; DList *p; p = dblhead->next; while (p != dbltail) { s = p; p = p->next; free(s); } dblhead->next = dbltail; dbltail->prev = dblhead; } void deletePerfectDL(void) { DList *s; DList *p; p = dblhead->next; while (p != dbltail) { s = p; p = p->next; free(s); } free(dblhead); free(dbltail); } void *printDL(DList *pPrint) { pPrint = dblhead->next; while (pPrint != dbltail) { printf("%s", (char *)(pPrint->pzKey)); pPrint = pPrint->next; } return pPrint->pzKey; } ------------------------------------------------------------------------ 1.2. fileó¸® ¶óÀ̺귯¸® ±¸Çö ÀÚ, ÀÌÁ¨ ÀÌÁß¿¬°á¸®½ºÆ®¸¦ ÀÌ¿ëÇÏ¿© File󸮸¦ Çغ¸µµ·Ï ÇÏÀÚ. °¡Àå ±âº»ÀûÀÎ algorithmÀº ´ÙÀ½°ú °°´Ù. < ¿¬°á¸®½ºÆ®¸¦ ÀÌ¿ëÇÑ fileó¸® algorithm 1.2.1 > 1) fileÀ» Àбâ¸ðµå·Î ¿­°í 2) ÇÑ ¶óÀÎÀ» ÀоîµéÀδÙ. 3) ÀоîµéÀÎ ¶óÀÎÀÌ Search Á¶°Ç¿¡ ¸Â´ÂÁö °Ë»çÇÑ´Ù. 3-1) Á¶°Ç¿¡ ¸ÂÀ¸¸é 4)·Î À̵¿. 3-2) ¸ÂÁö ¾ÊÀ¸¸é ¿¬°á¸®½ºÆ®ÀÇ node¿¡ »ðÀÔÇÏ°í 2)·Î À̵¿ 4) Á¶°Ç¿¡ µû¶ó ¿¬°á¸®½ºÆ®ÀÇ node¿¡ ó¸®ÇÑ(»ðÀÔ È¤Àº »èÁ¦, º¯°æµî) ¹®ÀÚ¿­À» »ðÀÔÇÑ´Ù. 5) 󸮰¡ ´Ù ³¡³ª¸é fileÀ» ´Ý´Â´Ù. 6) fileÀ» ¾²±â¸ðµå·Î ¿¬´Ù. 7) ¸Þ¸ð¸®¿¡ ÀûÀçÇÏ°í ÀÖ´Â ¿¬°á¸®½ºÆ®ÀÇ °¢ ³ëµåµéÀ» ¼ø¼­´ë·Î file¿¡ printÇÑ´Ù. 8) fileÀ» ´Ý´Â´Ù. ÀÌ·¸°Ô¸¸ ½á³õÀ¸¸é Àß ÀÌÇØ°¡ °¡Áö ¾ÊÀ» °ÍÀÌ´Ù. ±×·¯¹Ç·Î ÀÌÁ¦ºÎÅÍ source¿Í ±×¿¡ µû¸¥ algorithmÀ» Åä´ë·Î ¼³¸íÇÏ°Ú´Ù. ¿ì¼± algorithm 1.2.1ÀÇ 2)°úÁ¤¿¡ ÇØ´çÇÏ´Â ÇÔ¼ö¸¦ ¸¸µé¾îº¸ÀÚ. -------- < source 1.2.1 readOneLineSearchFile > ------------------- int readOneLineSearchFile(char pszBuffer[], FILE *fp) { int i = 0; char c = '\0'; do { c = getc(fp); /* file¿¡¼­ ÇÑ ¹®ÀÚ¸¦ ÀоîµéÀδÙ. */ pszBuffer[i++] = c; /* ½ÇÁ¦ fileó¸®ÇÔ¼ö¿¡¼­ »ç¿ëÇÏ°ÔµÉ buffer¿¡ ÀÐ */ /* ¾îµéÀÎ ¹®ÀÚ¸¦ »ðÀÔÇÑ´Ù. */ if (c == EOF || c == '\n') /* ¹®ÀÚ°¡ fileÀÇ ³¡À̰ųª ij¸®Áö¸®ÅÏ°ªÀ̸é */ break; /* loop¸¦ ºüÁ®³ª°£´Ù. Áï, °³Ç๮ÀÚ¸¦ ¸¸³ª¸é */ } while (1); /* ±×¶§±îÁöÀÇ ¹®ÀÚ¸¦ ¸ðµÎ ¹öÆÛ¿¡ ÀúÀåÇÏ°í */ /* loop¸¦ ³¡³½´Ù. */ pszBuffer[i] = '\0'; /* ¹öÆÛ¿¡ µé¾îÀÖ´Â °³Ç๮ÀÚ³ª EOF¸¦ »èÁ¦ÇÑ´Ù. */ nLine++; /* fileÀÇ line¼ö¸¦ üũÇϱâ À§ÇÑ ¿ÜºÎº¯¼öÀÌ´Ù. */ /* ÇÑ ¶óÀÎÀ» ÀÐ°í³ª¼­ 1¾¿ Áõ°¡½ÃŲ´Ù. */ return c; /* °³Ç๮ÀÚ'\n', ȤÀº EOF°¡ returnµÉ °ÍÀÌ´Ù. */ } ------------------------------------------------------------------- ´ÙÀ½À¸·Î ¿¬°á¸®½ºÆ®ÀÇ ³»¿ëÀ» file¿¡ ÇÁ¸°Æ®ÇÏ´Â ÇÔ¼ö¸¦ ±¸ÇöÇغ¸µµ·Ï ÇÏÀÚ. ¿¬°á¸®½ºÆ®¿¡ °üÇÑ ÇÔ¼öµéÀº À§¿¡¼­ ¾ð±ÞÇÑ ¹Ù¿Í °°´Ù. °£´ÜÇϹǷΠÀÌÇØÇϱ⵵ ½¬¿ï °ÍÀÌ´Ù. --------------- < source 1.2.2 printToFileDL > ------------------- void *printToFileDL(DList *pPrint, FILE *fp) { pPrint = dblhead->next; /* node pPrint¸¦ ÃʱâÈ­ÇÑ´Ù. */ while (pPrint != dbltail) /* pPrint°¡ ¸¶Áö¸·ÀÌ µÉ ¶§±îÁö ¹Ýº¹Çؼ­ */ { fprintf(fp, pPrint->pzKey); /* file¿¡ ÇÁ¸°Æ®ÇÑ´Ù. */ pPrint = pPrint->next; /* node¸¦ ´ÙÀ½À¸·Î À̵¿ */ } return pPrint->pzKey; } ------------------------------------------------------------------- ¾Æ·¡ ¼Ò°³ÇÒ source 1.2.3ÀÌ ¹Ù·Î À§¿¡¼­ ¾ð±ÞÇÑ algorithm¿¡ ÀÇÇÑ ·çƾÀÌ´Ù. Code line ¿ìÃø¿¡ °¢°¢ ÇØ´çÇÏ´Â algorithmÀÇ ¹øÈ£¸¦ Ç¥½ÃÇسõ°Ú´Ù. ÀÌ ÇÔ¼ö´Â file(pszFileName)¿¡¼­ ƯÁ¤ ¹®ÀÚ¿­(pszSearch)ÀÌ µé¾îÀÖ´Â ¶óÀÎ À» ã¾Æ ±× ¶óÀÎÀ» Åë°·Î »ðÀÔÇÒ ¹®ÀÚ¿­(pszInsert)·Î ¹Ù²Ù´Â ÇÔ¼öÀÌ´Ù. ¸¸¾à °Ë»öÇÒ ¹®ÀÚ¿­ÀÌ ¹ß°ßµÇÁö ¾ÊÀ¸¸é fileÀº ¾Æ¹« º¯È­µµ ÀϾÁö ¾Ê´Â´Ù. --------------- < source 1.2.3 insertStrToFile > ------------------- void insertStrToFile(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char *pszBuffer[nMaxLine]; /* nMaxLine°ú nMaxColÀ» ÀÎÀÚ·Î µÎ´Â ÀÌÀ¯´Â ¸Þ¸ð¸®¸¦ °ü¸®Çϱâ */ /* À§Çؼ­ÀÌ´Ù. Áï pszBuffer ÀÌÁßÆ÷ÀÎÅͺ¯¼ö¸¦ Àü¿ªº¯¼ö·Î ÀâÁö */ /* ¾Ê±â À§Çؼ­Àε¥, ¸¸¾à ÀÌ º¯¼ö¸¦ Àü¿ªº¯¼ö·Î Àâ°ÔµÇ¸é ÇÁ·Î */ /* ±×·¥Àº Ç×»ó nMaxLine*nMaxCol byte¸¸Å­ÀÇ ¸Þ¸ð¸®¸¦ Â÷ÁöÇÏ°Ô */ /* µÇ¹Ç·Î ¸Þ¸ð¸®ÀÇ ¸·´ëÇÑ ³¶ºñ¸¦ ÃÊ·¡ÇÒ ¼ö ÀÖ´Â ¹®Á¦Á¡ÀÌ ÀÖ´Ù.*/ /* ÀÌ ·çƾ¿¡¼­´Â fileÀÇ ÃÖ´ë line¼ö¿Í ÃÖ´ë coloum¼ö¸¦ ÀÎÀÚ·Î */ /* ¹Þ¾Æ¼­ ±× ÀÎÀÚ ¸¸Å­¿¡ ÇØ´çµÇ´Â ¸Þ¸ð¸®¸¦ ÇÒ´çÇÏ¿© ÁØ´Ù. */ /* ÀÌ·¸°Ô ó¸®ÇßÀ» ¶§ÀÇ ¸Þ¸ð¸®ÀÇ »ç¿ë·®Àº, ÀÌ ·çƾÀÌ ½ÇÇàµÇ¾ú */ /* À» ¶§¸¸ nMaxLine*nMaxCol byte¸¸Å­ ¸Þ¸ð¸®¿¡ ÇÒ´çÀÌ µÇ±â¶§¹® */ /* ¿¡, ±âº»¸Þ¸ð¸®°¡ Å« linux½Ã½ºÅÛ¿¡¼­´Â º° ¹«¸® ¾øÀÌ »ç¿ëÇÒ */ /* ¼ö ÀÖ´Ù. */ nLine = 0; fp = fopen(pszFileName, "r"); /* algor 1) fileÀ» Àбâ¸ðµå·Î ¿¬´Ù. */ if (fp == NULL) /* fileÀÌ Á¸ÀçÇÏÁö ¾Ê´Â´Ù¸é ¾Æ¹«Ã³¸® ¾øÀÌ ³¡³½´Ù. */ return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); /* double linkedlist¸¦ ÃʱâÈ­ÇÑ´Ù. */ for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) /* algor 2) file·ÎºÎÅÍ ÇѶóÀÎ(pszBuffer[i])¾¿ ÀоîµéÀδÙ. */ { /* algor 3-2) ÀоîµéÀÎ ¶óÀÎ(pszBuffer[i])ÀÌ °Ë»öÇÒ ¹®ÀÚ¿­ */ /* (pszSearch)À» Æ÷ÇÔÇÏ°í ÀÖÁö ¾Ê´Ù¸é */ if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) /* algor 3-2) node¿¡ »ðÀÔÇÑ ÈÄ for (i = 0; ~)·Î À̵¿ÇØ ´ÙÀ½¶óÀÎ */ /* À» ÀоîµéÀδÙ.(algor 2) */ insertAsLastDL(pszBuffer[i]); else /* algor 3-1) °Ë»öÇÒ ¹®ÀÚ¿­ÀÌ Æ÷ÇԵǾîÀÖ´Ù¸é */ /* algor 4) °Ë»öÇÑ ¹®ÀÚ¿­ÀÌ Æ÷ÇÔµÈ line´ë½Å »ðÀÔÇÒ ¹®ÀÚ¿­À» ¿¬ */ /* °á¸®½ºÆ®¿¡ »ðÀÔÇÑ´Ù. */ insertAsLastDL(pszInsert); } /* ¸¸¾à À§ for ·çƾ¿¡¼­ °Ë»öÇÒ ¹®ÀÚ¿­ÀÌ ¹ß°ßµÇÁö ¾Ê´Â´Ù¸é ¿¬°á¸®½ºÆ® */ /* ¿¡´Â fileÀÇ ¸ðµç ¶óÀÎÀ» °¡Áö°í ÀÖ´Â nodeµé¸¸ÀÌ ÀÖÀ» °ÍÀÌ´Ù. */ /* ÀÌ·± »óÅ¿¡¼­ ¹Ù·Î ¾Æ·¡ÂÊÀÇ printToFileDLÇÔ¼ö¸¦ È£ÃâÇÏ°Ô µÇ¸é */ /* fileÀÇ ³»¿ëÀÌ ¾Æ¹«°Íµµ º¯ÇÏÁö ¾ÊÀ¸¸é¼­ ±× fileÀÚü¿¡ ³»¿ëÀ» º¹»ç */ /* ÇÏ°Ô µÇ´Â °ÍÀÌ´Ù. */ fclose(fp); /* algor 5) fileÀ» ´Ý´Â´Ù. */ fp = fopen(pszFileName, "w"); /* algor 6) fileÀ» ¾²±â¸ðµå·Î ¿¬´Ù. */ printToFileDL(dblhead->next, fp); /* algor 7) ¸Þ¸ð¸®¿¡ ÀûÀçÇÏ°í */ /* ÀÖ´ø ¿¬°á¸®½ºÆ®ÀÇ ¸ðµç ³ëµå */ /* µéÀ» ¼ø¼­´ë·Î file¿¡ printÇÑ´Ù.*/ deletePerfectDL(); /* ¿¬°á¸®½ºÆ® ÃʱâÈ­½Ã ÇÒ´çÇß´ø ¸Þ¸ð¸®¸¦ ȸ¼öÇÑ´Ù.*/ fclose(fp); /* algor 8) fileÀ» ´Ý´Â´Ù. */ for (i = 0; i < nMaxLine; i++) /* ¹öÆÛ¿¡ ÇÒ´çÇß´ø ¸Þ¸ð¸®¸¦ ÇØÁ¦(ȸ¼ö)*/ free(pszBuffer[i]); } ------------------------------------------------------------------- ÀÌÁß¿¬°á¸®½ºÆ®ÀÇ ±¸Á¶¸¦ ¾Ë°íÀÖ´Ù¸é ÀÌÇØÇϱⰡ »ó´çÈ÷ ½¬¿ï °ÍÀÌ´Ù. ÀÌ ÇÔ¼ö¸¦ ÀÌÇØÇÏÁö ¸øÇß´Ù¸é ´ÙÀ½À¸·Î ³Ñ¾î°¡Áö ¸øÇϹǷΠöÀúÇÏ°Ô ÀÌÇØÇϱ⠹ٶõ´Ù. ÀÌ ÇÔ¼öÀÇ ¾²ÀÓ»õ´Â µÎ°¡Áö°¡ ÀÖ´Ù. ù¹ø°, ƯÁ¤¹®ÀÚ¿­ ¹Ù²Ù±â. µÎ¹ø°, ƯÁ¤¹®ÀÚ¿­ÀÌ ¼ÓÇÑ ¶óÀÎ Áö¿ì±â. ¿©±â¼­ µÎ¹ø°¾²ÀÓ»õÀÇ ³»¿ëÀ» º¸¶ó. ƯÁ¤¹®ÀÚ¿­(pszSearch)ÀÌ ¼ÓÇÑ lineÀ» Áö ¿ì·Á¸é ¾î¶»°Ô ÇؾßÇÒ±î? ³Ê¹«µµ ½¬¿î ³»¿ëÀÌ´Ù. ÀÎÀÚ pszInsert¿¡ "", Áï, °ø¹é¹®ÀÚ¿­À» ³Ñ°ÜÁÖ¸é µÈ´Ù. ÀÌ ÇÔ¼ö´Â ƯÁ¤ fileÀ» ÀÓ½ÃÆÄÀÏ·Î ÀúÀåÇÏ´Â °úÁ¤ ¾øÀÌ ¹Ù·Î ±× fileÀ» °»½ÅÇÑ ´Ù. ÀÓ½ÃÆÄÀÏ·Î ÀúÀåÇÏ´Â °Í°ú ¸Þ¸ð¸®¿¡ ÀúÀåÇÏ´Â °ÍÀº ¼­·Î Àå´ÜÁ¡ÀÌ Àִµ¥ ±×¿¡ ´ëÇÑ ¼³¸íÀº ¾ð±ÞÇÏÁö ¾Ê¾Æµµ Àß ¾Æ½Ã¸®¶ó ¹Ï´Â´Ù. strstrÇÔ¼ö¿¡ °üÇÑ ³»¿ëÀº manÆäÀÌÁö¸¦ ÂüÁ¶Çϰųª library ¸Þ´º¾óÀ» Âü°íÇϱ⠹ٶõ´Ù. ´ÙÀ½À¸·Î ±¸ÇöÇÒ ÇÔ¼ö´Â À§ÀÇ ÇÔ¼ö¿Í °ÅÀÇ ºñ½ÁÇÏÁö¸¸ ¾à°£ ´Ù¸£´Ù. À§ÀÇ ÇÔ¼ö ¿¡¼­´Â °Ë»ö¹®ÀÚ¿­(pszSearch)ÀÌ ¾øÀ» °æ¿ì ¾Æ¹«Àϵµ ÀϾÁö ¾ÊÁö¸¸ ÀÌ ÇÔ¼ö ´Â ¹®ÀÚ¿­ÀÌ °Ë»öµÇÁö ¾ÊÀ¸¸é fileÀÇ ¸Ç ³¡¿¡ »ðÀÔÇÒ ¹®ÀÚ¿­(pszInsert)À» ³¢ ¿ö³Ö°Ô µÈ´Ù. °Ë»öÇÒ ¹®ÀÚ¿­ÀÌ ¸¸¾à °Ë»öµÈ´Ù¸é ¹Ù·Î ¾Æ¹«ÀÏÀ» ÇÏÁö ¾Ê°í ·çƾÀ» ³¡³½´Ù. ´ëºÎºÐÀÇ °úÁ¤Àº À§¿¡¼­ ¼³¸íÇßÀ¸¹Ç·Î »õ·Î¿î ÁÖ¸ñÇؾßÇÒ ºÎºÐ¸¸À» Comment ÇÏ°Ú´Ù. --------------- < source 1.2.4 insertStrToFileLast > ------------------- void insertStrToFileLast(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else /* °Ë»öÇÒ ¹®ÀÚ¿­(pszSearch)ÀÌ °Ë»ö µÈ´Ù¸é ·çƾÀ» ³¡³½´Ù. */ { for (j = 0; j < nMaxLine; j++) free(pszBuffer[j]); fclose(fp); deletePerfectDL(); return; } } /* ¸¸¾à ¹®ÀÚ¿­(pszSearch)ÀÌ °Ë»öµÇÁö ¾Ê¾Ò´Ù¸é À̺κÐÀ¸·Î ³Ñ¾î¿À°Ô */ /* µÈ´Ù. ÀÌ °æ¿ì ¹Ù·Î ¾Æ·¡¿Í °°ÀÌ »ðÀÔÇÒ ¹®ÀÚ¿­À» ¿¬°á¸®½ºÆ®ÀÇ ¸Ç */ /* ³¡³ëµå¿¡ »ðÀÔÀ» ½ÃÅ°°í file·Î ÇÁ¸°Æ®ÇÑ´Ù. */ insertAsLastDL(pszInsert); fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (j = 0; j < nMaxLine; j++) free(pszBuffer[j]); } ------------------------------------------------------------------- À̹ø¿¡ ¼³¸íÇÒ ÇÔ¼ö´Â file¿¡¼­ ƯÁ¤¹®ÀÚ¿­À» ã¾Æ ±× ¹®ÀÚ¿­À» ¿øÇÏ´Â ¹®ÀÚ¿­·Î ¹Ù²Ù¾îÁÖ´Â ÇÔ¼öÀÌ´Ù. À§¿¡¼­ ¼³¸íÇÑ insertStrToFileÇÔ¼ö¿Í´Â ´Ù¸¥ ¿ªÇÒÀ» ÇÑ´Ù. Áï, insertStrToFileÇÔ¼ö´Â line´ÜÀ§·Î ¹®ÀÚ¿­À» »ðÀÔ, º¯°æÇÏ´Â ¹Ý¸é changeStrToOneLineToFileÇÔ¼ö´Â ¹®ÀÚ¿­´ÜÀ§·Î º¯°æÇÏ´Â ÇÔ¼öÀÌ´Ù. ±âº» algorithmÀº < algorithm 1.2.1 >¿¡ ÀÇ°ÅÇÑ´Ù. ¸¸¾à À§ÀÇ °úÁ¤À» ¸ðµÎ ÀÌÇØÇß´Ù¸é ÀÌ ÇÔ¼öµµ º° ¾î·Á¿òÀÌ ¾øÀ» °ÍÀÌ´Ù. ÀÌ ÇÔ¼ö´Â changeSearchStrÀ̶ó´Â ÇÔ¼ö¸¦ callÇϴµ¥, changeSearchStr ÇÔ¼ö´Â ¾î¶² ÁÖ¾îÁø ¹®ÀÚ¿­(pszLine)¿¡¼­ ƯÁ¤¹®ÀÚ¿­(pszSearch)¸¦ ã¾Æ »ðÀÔÇÒ ¹®ÀÚ¿­(pszIns)·Î ¹Ù²Ù´Â ¿ªÇÒÀ» ÇÑ´Ù. ÇÑ ¶óÀÎ(pszLine)¿¡ ¿©·¯ °³ÀÇ Æ¯Á¤¹®ÀÚ¿­(pszSearch)°¡ ÀÖÀ» ¼ö ÀÖÀ¸¹Ç·Î Àç±ÍÈ£Ãâ(recursive call)À» »ç¿ëÇß´Ù. ±âº»ÀûÀÎ C¹®¹ýÀ» ¾Ë°íÀÖ´Ù¸é ·çƾ ÀÚü´Â ÀÌÇØÇϱ⠽¬¿ï °ÍÀ̶ó ¹Ï´Â´Ù. À§¿Í ¸¶Âù°¡Áö·Î Áߺ¹µÇ´Â Comment´Â »ý·«ÇÏ°Ú´Ù. -------- < source 1.2.5 changeStrToOneLineToFile > ----------- void changeSearchStr(char *pszIns, char *pszSearch, char *pszLine, char *pszSave, int nMaxCol) /* ¿©±â¼­ Æ÷ÀÎÅÍ ÀÎÀÚÀÎ pszSave´Â ¹Ù²ï ¶óÀÎÀ» ÀúÀåÇÒ °ø°£ÀÌ´Ù. */ { int i = 0; char *pszPos; int nPos; /* ¶óÀÎ(pszLine)¿¡¼­ °Ë»ö¹®ÀÚ¿­(pszSearch)ÀÇ À§Ä¡¸¦ °è»êÇϱâ */ /* À§ÇØ °Ë»ö¹®ÀÚ¿­ÀÇ pszLine¿¡¼­ÀÇ Æ÷ÀÎÅÍ À§Ä¡¸¦ ÀúÀåÇصдÙ. */ pszPos = (char *)strstr(pszLine, pszSearch); /* °Ë»ö¹®ÀÚ¿­ÀÇ À§Ä¡¸¦ °è»êÇÑ´Ù. */ nPos = pszPos-pszLine; /* °Ë»ö¹®ÀÚ¿­ÀÇ À§Ä¡(nPos)±îÁö pszSave¿¡ pszLineÀÇ ³»¿ëÀ» º¹»ç */ for (i = 0; i < nPos; i++) pszSave[i] = pszLine[i]; /* ÀúÀåÇÒ º¯¼ö(pszSave)¿¡ ¹Ù²Ü ¹®ÀÚ¿­(pszIns)¸¦ ºÙÈù´Ù.*/ strcat(pszSave, pszIns); /* ÀúÀåÇÒ º¯¼ö(pszSave)¿¡ ±× ÀÌÈÄÀÇ ¹®ÀÚ¿­À» ºÙÈù´Ù. */ strcat(pszSave, pszLine+nPos+strlen(pszSearch)); /* ´õÀÌ»ó °Ë»ö¹®ÀÚ¿­(pszSearch)°¡ */ pszPos = (char *)strstr(pszSave, pszSearch); /* Á¸ÀçÇÏÁö ¾Ê´Â´Ù¸é ·çƾÀ» ³¡³½´Ù. */ if (pszPos == NULL) return; memset(pszLine, '\0', nMaxCol); /* ¹Ù²ï ¶óÀÎ(pszSave)¸¦ ¿ø·¡ ¶óÀο¡ º¹»çÇÑ´Ù. */ strcpy(pszLine, pszSave); /* Àç±ÍÈ£ÃâÀ» À§ÇØ pszSave¸¦ ÃʱâÈ­ÇÑ´Ù. */ memset(pszSave, '\0', nMaxCol); /* ù¹ø° ¸¸³ª´Â °Ë»ö¹®ÀÚ¿­À» ¹Ù²Ù¾úÀ¸¹Ç·Î µÎ¹ø°, ¼¼¹ø°µîµî */ /* ÀÇ ¹®ÀÚ¿­À» ¹Ù²Ù±â À§ÇØ Àç±ÍÈ£ÃâÀ» ÇÑ´Ù. */ changeSearchStr(pszIns, pszSearch, pszLine, pszSave, nMaxCol); } /* ÀÌÁ¦ ÇÑ ¶óÀο¡ ´ëÇÑ ¹®ÀÚ¿­º¯°æ·çƾÀº ³¡³ÂÀ¸¹Ç·Î À§ ÇÔ¼ö¿¡ ½ÇÁ¦ */ /* file¿¡¼­ ÇÑ ¶óÀξ¿ Àоîµé¿© ÀÎÀÚ·Î ³Ñ°ÜÁÖ¸é µÈ´Ù. */ void changeStrToOneLineToFile(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0, j = 0; FILE *fp; /* pszLineÀº ¹Ù²ï ¹®ÀÚ¿­À» ÀúÀåÇÒ °ø°£ÀÌ´Ù. */ char *pszLine[nMaxLine]; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); pszLine[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszLine[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) /* ÇÑ ¶óÀξ¿ Àоîµé¿©¼­ */ { /* °Ë»ö¹®ÀÚ¿­(pszSearch)ÀÌ ¾ø´Ù¸é ¿¬°á¸®½ºÆ®¿¡ »ðÀÔÇÑ´Ù.*/ if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); /* °Ë»ö¹®ÀÚ¿­ÀÌ ÀÖ´Ù¸é changeSearchStrÇÔ¼ö¸¦ ÀÌ¿ëÇØ °Ë»ö¹®ÀÚ¿­ÀÌ */ /* Æ÷ÇÔµÈ ¶óÀÎÀ» ¼öÁ¤ÇÏ°í ¼öÁ¤µÈ ¶óÀÎÀ» ¿¬°á¸®½ºÆ®¿¡ »ðÀÔÇÑ´Ù. */ else { changeSearchStr(pszIns, pszSearch, pszBuffer[i], pszLine[j], nMaxCol); insertAsLastDL(pszLine[j]); j++; } } fclose(fp); /* file ¾²±â */ fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) { free(pszBuffer[i]); free(pszLine[i]); } } ------------------------------------------------------------------- ¿¹»ó¿Ü·Î °£´ÜÇÒ °ÍÀÌ´Ù. ƯÁ¤ ±â´É(¿¹¸¦µé¾î, »èÁ¦, »ðÀÔ, º¯°æµî)¿¡ ´ëÇÑ ÇÔ¼öµéÀÇ ±¸ÇöÀº À§ ¹æ¹ý°ú ±¸Á¶°¡ Ç×»ó °°´Ù. ÀÌ´Â ¿¬°á¸®½ºÆ®¸¦ »ç¿ëÇßÀ»¶§ÀÇ ÀåÁ¡ÀÌ À¯°¨¾øÀÌ ¹ßÈÖµÈ Æ¯Â¡Áß Çϳª ÀÌ´Ù. Áï, ÀÌÇØÇϱ⠽±°í ±¸ÇöÀÌ ¿ëÀÌÇÏ°í, ¶Ç °¡Àå Áß¿äÇÑ ¹ü¿ë¼ºÀÌ ÀÖ´Ù´Â Á¡ÀÌ´Ù. À̹ø¿£ À§ÀÇ sourceµéÀÇ ±¸Á¶¸¦ ¾à°£ ÀÀ¿ëÇؼ­ ±¸Á¶È­µÈ fileÀÇ Ã³¸® ·çƾÀ» ÀÛ¼ºÇغ¸±â·Î ÇÏÀÚ. ¾Æ·¡ÀÇ ÇÔ¼ö´Â °Ë»ö¹®ÀÚ¿­(pszSearch)ÀÌ file(pszFileName)¿¡ ¾ø´Ù¸é »ðÀÔÇÒ ¹®ÀÚ¿­(pszInsert)À» ¶óÀÎÀ¸·Î »ðÀÔÇÏ°í °Ë»ö¹®ÀÚ¿­ÀÌ Á¸ÀçÇÑ ´Ù¸é ±× °Ë»ö¹®ÀÚ¿­À» Æ÷ÇÔÇÑ ¶óÀÎÀ» »ðÀÔÇÒ ¹®ÀÚ¿­·Î ¹Ù²Ù´Â ÇÔ¼öÀÌ ´Ù. À§ÀÇ ÇÔ¼öµé°ú ´Ù¸¥Á¡ÀÌ ÀÖ´Ù¸é ÀÌ ÇÔ¼ö¿¡´Â flag¸¦ µÎ¾ú´Ù´Â Á¡ ÀÌ´Ù. ÀÌ flag´Â file¿¡ °Ë»öµÈ ¶óÀÎÀ» »ðÀÔ¹®ÀÚ¿­·Î ¹Ù²Ü °ÍÀÎÁö ¾Æ ´Ï¸é ±×³É »ðÀÔ¹®ÀÚ¿­À» ¶óÀδÜÀ§·Î »ðÀÔÇÒ °ÍÀÎÁö¸¦ °áÁ¤ÇÑ´Ù. ¸¸¾à ¹®ÀÚ¿­ÀÌ °Ë»öµÇÁö ¾Ê´Â´Ù¸é flag´Â TRUE·Î settingµÈ´Ù. -------- < source 1.2.6 addOnNotExistChangeOnExist > ----------- void addOnNotExistChangeOnExist(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; /* »ðÀÔÇÒ Áö ȤÀº º¯°æÇÒ ÁöÀÇ flag(flgAdd) */ int flgAdd = TRUE; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); /* ¸¸¾à °Ë»ö¹®ÀÚ¿­(pszSearch)ÀÌ °Ë»öµÈ´Ù¸é */ else { /* »ðÀÔ¹®ÀÚ¿­(pszIns)À» node¿¡ »ðÀÔÇÏ°í */ insertAsLastDL(pszIns); /* flag¸¦ FALSE·Î reset½ÃŲ´Ù. */ flgAdd = FALSE; } } fclose(fp); /* flag°¡ TRUE¶ó¸é °Ë»ö¹®ÀÚ¿­ÀÌ ¹ß°ßµÇÁö ¾Ê¾Ò´Ù´Â °ÍÀ̹ǷΠ*/ /* ¸µÅ©¸®½ºÆ®ÀÇ ¸Ç ³¡node¿¡ »ðÀÔ¹®ÀÚ¿­À» »ðÀÔÇÑ´Ù. */ if (flgAdd == TRUE) insertAsLastDL(pszIns); /* file ¾²±â */ fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } ------------------------------------------------------------------- °£´ÜÇÏ°Ô ¸îÁÙ¸¸ Ãß°¡ ȤÀº º¯°æ½ÃÄÑ ±â´ÉÀ» ¹Ù²Ù¾î³õ¾Ò´Ù. ¾ÕÀ¸·Î ¼³¸íÇÏ°ÔµÉ ¸ðµç file󸮰ü·Ã ÇÔ¼öµéÀÌ ´Ù ÀÌ·±½ÄÀÌ´Ù. ÀÌ routineÀ» ÀÀ¿ëÇÏ¿© °®°¡Áö sourceµéÀ» Àç»ý¼ºÇغ¸½Ã±â¸¦... ÀÌÁ¦ºÎÅÍ´Â À§ÀÇ routineµéÀº ¹°·Ð ÇÊÀÚ°¡ ±¸ÇöÇسõÀº ¸ðµç procedureµé À» ÇѲ¨¹ø¿¡ º¸¿©ÁÖ±â·Î ÇÏ°Ú´Ù. ±×¸®°í ¼³¸íÀº µÇµµ·Ï ±â´É À§ÁÖ·Î ÇÏ °Ú´Ù. À§ °úÁ¤±îÁö ¸ðµÎ ÀÌÇØÇß´Ù¸é º°´Ù¸¥ Comment¾øÀ̵µ ÀÌÇØÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù. -------- < source 1.2.7 total functions > ----------- /**************** proc_file.h *****************/ #include #ifndef _LINKLIST_H_ #define _LINKLIST_H_ #ifndef SUCCESS #define SUCCESS 1 #define FAIL 0 #endif #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif #ifndef _DOUBLE_LINKLIST_ #define _DOUBLE_LINKLIST_ typedef struct tagDOUBLELINK { void *pzKey; struct tagDOUBLELINK *next; struct tagDOUBLELINK *prev; } DList; void initDL(void); DList *searchDL(void *pzSearch); DList *insertAsFirstDL(void *pzInsert); DList *insertDL(void *pzInsert, DList *pIns); /* insert front node p */ DList *insertDLAsKey(void *pzInsert, void *pzSearch); DList *insertDLAsSort(void *pzInsert); int deleteDL(DList *pDel); int deleteDLAsKey(void *pzSearch); void deleteAllDL(void); void deletePerfectDL(void); void *printDL(DList *pPrint); void deleteStrFromOneLine(char *pszSave, char *pszDel, char *pszLine); void insertStrForeSearch(char *pszSave, char *pszInsert, char *pszSearch, char *pszLine, char *pszTempLine); void insertStrToOneLine(char *pszSave, char *pszIns, char *pszLine); void changeSearchStr(char *pszIns, char *pszSearch, char *pszLine, char *pszSave, int nMaxCol); void *printToFileDL(DList *pPrint, FILE *fp); int readOneLineSearchFile(char pszBuffer[], FILE *fp); void insertStrToFile(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void insertStrToFileLast(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); int countAllLineToFile(char *pszFileName, int nMaxLine, int nMaxCol); int countSearchLineToFile(char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); int saveAllLineToFile(char *pszSaveListStr[], char *pszFileName, int nMaxLine, int nMaxCol); int saveSearchLineToFile(char *pszSearch, char *pszSaveListStr[], char *pszFileName, int nMaxLine, int nMaxCol); int saveSearchLineToFileWithoutComment(char *pszSearch, char *pszSaveListStr[], char cComment, char *pszFileName, int nMaxLine, int nMaxCol); void changeStrToOneLineToFile(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void insertStrToOneLineToFile(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void deleteStrToOneLineToFile(char *pszDel, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); int searchStrInFile(char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void addOnNotExistChangeOnExist(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void addOnNotExistChangeOnExistWithoutComment(char *pszIns, char *pszSearch, char cComment, char *pszFileName, int nMaxLine, int nMaxCol); void addOnNotExistChangeOnExist2Search(char *pszIns, char *pszFirstSearch, char *pszSecondSearch, char *pszFileName, int nMaxLine, int nMaxCol); void insertForeSearchToFile(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void attatchStrToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void saveStrIdxToFileLine(char *pszSave, char *pszSearch, char *pszFileName, int nStartIdx, int nEndIdx, int nMaxLine, int nMaxCol); void changeStrIdxToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nStartIdx, int nEndIdx, int nMaxLine, int nMaxCol); void attatchStrIdxToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nIdx, int nMaxLine, int nMaxCol); void attatchStrToFileIdxLine(char *pszInsert, char *pszFileName, int nLineIdx, int nColIdx, int nMaxLine, int nMaxCol); void saveBetweenStrToFile(char *pszSaveLine[], char *pszStartLine, char *pszEndLine, char *pszFileName, int nMaxLine, int nMaxCol); void changeBetweenStrToFile(char *pszInsert[], int nInsertNum, char *pszStartLine, char *pszEndLine, char *pszFileName, int nMaxLine, int nMaxCol); void insertAfterStrToFile(char *pszInsert, char *pszStartLine, char *pszFileName, int nMaxLine, int nMaxCol); #endif #endif /**********************************************/ /**************** proc_file.c *****************/ #include #include #include #include #include "proc_file.h" DList *dblhead; DList *dbltail; void initDL(void) { dblhead = (DList *)malloc(sizeof(DList)); dbltail = (DList *)malloc(sizeof(DList)); dblhead->prev = dblhead; dblhead->next = dbltail; dbltail->prev = dblhead; dbltail->next = dbltail; } DList *searchDL(void *pzSearch) { DList *s; s = dblhead->next; while (s != dbltail) { if (memcmp(s->pzKey, pzSearch, sizeof(pzSearch)) == 0) break; s = s->next; } return s; } DList *insertAsFirstDL(void *pzInsert) { DList *p; p = (DList *)malloc(sizeof(DList)); p->pzKey = pzInsert; p->next = dblhead->next; dblhead->next->prev = p; dblhead->next = p; p->prev = dblhead; return p; } DList *insertAsLastDL(void *pzInsert) { insertDL(pzInsert, dbltail); return (DList *)NULL; } DList *insertDL(void *pzInsert, DList *pIns) /* insert front node pIns */ { DList *s; if (pIns == dblhead) return NULL; s = (DList *)malloc(sizeof(DList)); s->pzKey = pzInsert; pIns->prev->next = s; s->prev = pIns->prev; s->next = pIns; pIns->prev = s; return s; } DList *insertDLAsKey(void *pzInsert, void *pzSearch) { /* insert insk front findk */ DList *s; DList *r = NULL; s = searchDL(pzSearch); if (s != dbltail) { r = (DList *)malloc(sizeof(DList)); r->pzKey = pzInsert; s->prev->next = r; r->prev = s->prev; r->next = s; s->prev = r; } return r; } DList *insertDLAsSort(void *pzInsert) { DList *s; DList *r; s = dblhead->next; while (s != dbltail) { if (memcmp(s->pzKey, pzInsert, sizeof(pzInsert)) >= 0) break; s = s->next; } r = (DList *)malloc(sizeof(DList)); r->pzKey = pzInsert; s->prev->next = r; r->prev = s->prev; r->next = s; s->prev = r; return r; } int deleteDL(DList *pDel) { if (pDel == dblhead || pDel == dbltail) return FAIL; pDel->prev->next = pDel->next; pDel->next->prev = pDel->prev; free(pDel); return SUCCESS; } int deleteDLAsKey(void *pzSearch) { DList *s; s = searchDL(pzSearch); if (s != dbltail) { s->prev->next = s->next; s->next->prev = s->prev; free(s); return SUCCESS; } return FAIL; } void deleteAllDL(void) { DList *s; DList *p; p = dblhead->next; while (p != dbltail) { s = p; p = p->next; free(s); } dblhead->next = dbltail; dbltail->prev = dblhead; } void deletePerfectDL(void) { DList *s; DList *p; p = dblhead->next; while (p != dbltail) { s = p; p = p->next; free(s); } free(dblhead); free(dbltail); } void *printDL(DList *pPrint) { pPrint = dblhead->next; while (pPrint != dbltail) { printf("%s", (char *)(pPrint->pzKey)); pPrint = pPrint->next; } return pPrint->pzKey; } /****** FILE procedure ******/ /* ÇÑ ¶óÀο¡¼­ °Ë»ö¹®ÀÚ¿­(pszDel)À» Áö¿î´Ù. */ void deleteStrFromOneLine(char *pszSave, char *pszDel, char *pszLine) { char *pszPnt; int i, nFirstLen; if ((pszPnt = (char *)strstr(pszLine, pszDel)) == NULL) return; nFirstLen = pszPnt-pszLine; for (i = 0; i < nFirstLen; i++) pszSave[i] = pszLine[i]; for (i = nFirstLen; pszLine[i+strlen(pszDel)] != '\0'; i++) pszSave[i] = pszLine[i+strlen(pszDel)]; pszSave[i] = '\0'; } /* ÇÑ ¶óÀο¡¼­ °Ë»ö¹®ÀÚ¿­(pszSearch)¾Õ¿¡ »ðÀÔ¹®ÀÚ¿­(pszInsert) */ /* À» »ðÀÔÇÑ´Ù. */ void insertStrForeSearch(char *pszSave, char *pszInsert, char *pszSearch, char *pszLine, char *pszTempLine) { int i = 0; int nLen; char *pszPos; if ((char *)strstr(pszLine, pszInsert) != NULL) { strcat(pszSave, pszTempLine); return; } pszPos = (char *)strstr(pszLine, pszSearch); nLen = pszPos-pszLine; for (i = 0; i < nLen; i++) pszSave[i] = pszLine[i]; strcat(pszSave, pszInsert); strcat(pszSave, strstr(pszLine, pszSearch)); } /* ÇÑ ¶óÀο¡¼­ °Ë»ö¹®ÀÚ¿­(pszIns)ÀÌ ÀÖ´Ù¸é returnÇÏ°í ¾ø´Ù¸é */ /* ¶óÀÎ ³¡¿¡ °Ë»ö¹®ÀÚ¿­À» »ðÀÔÇÑ´Ù. */ void insertStrToOneLine(char *pszSave, char *pszIns, char *pszLine) { int nFirstPos, nSecondPos; if ((char *)strstr(pszLine, pszIns) != NULL) return; for (nFirstPos = 0; nFirstPos < strlen(pszLine); nFirstPos++) pszSave[nFirstPos] = pszLine[nFirstPos]; for (nSecondPos = 0; nSecondPos < strlen(pszIns); nSecondPos++) pszSave[nSecondPos+nFirstPos] = pszIns[nSecondPos]; pszSave[nSecondPos+nFirstPos] = '\0'; } void changeSearchStr(char *pszIns, char *pszSearch, char *pszLine, char *pszSave, int nMaxCol) { int i = 0; char *pszPos; int nPos; pszPos = (char *)strstr(pszLine, pszSearch); nPos = pszPos-pszLine; for (i = 0; i < nPos; i++) pszSave[i] = pszLine[i]; strcat(pszSave, pszIns); strcat(pszSave, pszLine+nPos+strlen(pszSearch)); pszPos = (char *)strstr(pszSave, pszSearch); if (pszPos == NULL) return; memset(pszLine, '\0', nMaxCol); strcpy(pszLine, pszSave); memset(pszSave, '\0', nMaxCol); changeSearchStr(pszIns, pszSearch, pszLine, pszSave, nMaxCol); } int nLine; void *printToFileDL(DList *pPrint, FILE *fp) { pPrint = dblhead->next; while (pPrint != dbltail) { fprintf(fp, pPrint->pzKey); pPrint = pPrint->next; } return pPrint->pzKey; } int readOneLineSearchFile(char pszBuffer[], FILE *fp) { int i = 0; char c = '\0'; do { c = getc(fp); pszBuffer[i++] = c; if (c == EOF || c == '\n') break; } while (1); pszBuffer[i] = '\0'; nLine++; return c; } void insertStrToFileLast(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else { for (j = 0; j < nMaxLine; j++) free(pszBuffer[j]); fclose(fp); deletePerfectDL(); return; } } insertAsLastDL(pszInsert); fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (j = 0; j < nMaxLine; j++) free(pszBuffer[j]); } /* fileÀÇ ¶óÀμö¸¦ returnÇÑ´Ù. */ int countAllLineToFile(char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, nCount = 0; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return 0; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (nCount = 0; (readOneLineSearchFile(pszBuffer[nCount], fp) != EOF) && (nCount < nMaxLine); nCount++); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return nCount; } /* file¿¡¼­ °Ë»ö¹®ÀÚ¿­(pszSearch)°¡ ÀÖ´Â line ¼ö¸¦ returnÇÑ´Ù. */ int countSearchLineToFile(char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0; int nCount = 0; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return 0; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) nCount++; } fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return nCount; } /* fileÀÇ ¸ðµç ¶óÀÎÀ» ÀÌÁßÆ÷ÀÎÅÍ(pszSaveListStr)¿¡ ÀúÀåÇÑ´Ù. */ int saveAllLineToFile(char *pszSaveListStr[], char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return 0; for (j = 0; j < nMaxLine; j++) { pszBuffer[j] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[j], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) strcpy(pszSaveListStr[i], pszBuffer[i]); fclose(fp); for (j = 0; j < nMaxLine; j++) free(pszBuffer[j]); return i; } /* file¿¡¼­ °Ë»ö¹®ÀÚ¿­(pszSearch)ÀÌ ÀÖ´Â line¿¡ Comment(cComment)°¡ */ /* ¾ø´Ù¸é ÀÌÁßÆ÷ÀÎÅÍ(pszSaveListStr)¿¡ ÀúÀåÇÑ´Ù. */ int saveSearchLineToFileWithoutComment(char *pszSearch, char *pszSaveListStr[], char cComment, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; int j = 0; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; if ((fp = fopen(pszFileName, "r")) == NULL) return FALSE; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL && pszBuffer[i][0] != cComment) { strcpy(pszSaveListStr[j], pszBuffer[i]); j++; } } fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return TRUE; } /* file¿¡¼­ °Ë»ö¹®ÀÚ¿­(pszSearch)ÀÌ ÀÖ´Â lineÀ» Comment(cComment)¿¡ »ó */ /* °ü¾øÀÌ ÀÌÁßÆ÷ÀÎÅÍ(pszSaveListStr)¿¡ ÀúÀåÇÑ´Ù. */ int saveSearchLineToFile(char *pszSearch, char *pszSaveListStr[], char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; int j = 0; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; if ((fp = fopen(pszFileName, "r")) == NULL) return FALSE; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { strcpy(pszSaveListStr[j], pszBuffer[i]); j++; } } fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return TRUE; } void changeStrToOneLineToFile(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0, j = 0; FILE *fp; char *pszLine[nMaxLine]; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); pszLine[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszLine[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else { changeSearchStr(pszIns, pszSearch, pszBuffer[i], pszLine[j], nMaxCol); insertAsLastDL(pszLine[j]); j++; } } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) { free(pszBuffer[i]); free(pszLine[i]); } } /* °Ë»ö¹®ÀÚ¿­(pszSearch)ÀÌ ÀÖ´Â ¶óÀο¡¼­ °Ë»ö¹®ÀÚ¿­ ¹Ù·Î */ /* ¾Õ¿¡ »ðÀÔ¹®ÀÚ¿­(pszIns)À» »ðÀÔÇÑ´Ù. */ void insertStrToOneLineToFile(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char pszLine[nMaxCol]; char *pszBuffer[nMaxLine]; memset(pszLine, '\0', nMaxCol); nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else { insertStrForeSearch(pszLine, pszIns, pszSearch, pszBuffer[i], pszBuffer[i]); insertAsLastDL(pszLine); } } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } /* file¿¡¼­ °Ë»ö¹®ÀÚ¿­(pszSearch)À» ã¾Æ ±× ¹®ÀÚ¿­¸¸ Áö¿öÁØ´Ù. */ void deleteStrToOneLineToFile(char *pszDel, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char pszLine[nMaxCol]; char *pszBuffer[nMaxLine]; memset(pszLine, '\0', nMaxCol); nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else { deleteStrFromOneLine(pszLine, pszDel, pszBuffer[i]); insertAsLastDL(pszLine); } } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void insertStrToFile(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else insertAsLastDL(pszInsert); } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } /* file¿¡¼­ °Ë»ö¹®ÀÚ¿­(pszSearch)ÀÌ ÀÖÀ¸¸é TRUE, */ /* ¾øÀ¸¸é FALSE¸¦ returnÇÑ´Ù. */ int searchStrInFile(char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return FALSE; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); fclose(fp); return TRUE; } } fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return FALSE; } void addOnNotExistChangeOnExist(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; int flgAdd = TRUE; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else { insertAsLastDL(pszIns); flgAdd = FALSE; } } fclose(fp); if (flgAdd == TRUE) insertAsLastDL(pszIns); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } /* Comment(cComment)°¡ ¾øÀ» ¶§, °Ë»ö¹®ÀÚ¿­(pszSearch)ÀÌ */ /* ¾øÀ¸¸é file ¸Ç ³¡¿¡ »ðÀÔ¹®ÀÚ¿­(pszIns)¸¦ ¶óÀÎÀ¸·Î »ðÀÔ */ /* ÇÏ°í, ÀÖÀ¸¸é °Ë»ö¹®ÀÚ¿­ÀÌ ÀÖ´Â ¶óÀÎÀ» »ðÀÔ¹®ÀÚ¿­·Î ¹Ù */ /* ²Û´Ù. */ void addOnNotExistChangeOnExistWithoutComment(char *pszIns, char *pszSearch, char cComment, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; int flgAdd = TRUE; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL || pszBuffer[i][0] == cComment) insertAsLastDL(pszBuffer[i]); else { insertAsLastDL(pszIns); flgAdd = FALSE; } } fclose(fp); if (flgAdd == TRUE) insertAsLastDL(pszIns); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } /* µÎ°³ÀÇ °Ë»ö¹®ÀÚ¿­(pszFirstSearch, pszSecondSearch)ÀÌ ¸ðµÎ ÀÖÀ¸¸é */ /* ±× ¶óÀÎÀ» »ðÀÔ¹®ÀÚ¿­(pszIns)·Î ¹Ù²Ù°í, µÑ Áß Çϳª¶óµµ ¾øÀ¸¸é */ /* »ðÀÔ¹®ÀÚ¿­À» file¸Ç ³¡¿¡ ¶óÀÎÀ¸·Î »ðÀÔÇÑ´Ù. */ void addOnNotExistChangeOnExist2Search(char *pszIns, char *pszFirstSearch, char *pszSecondSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; int flgAdd = TRUE; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszFirstSearch) != NULL && (char *)strstr(pszBuffer[i], pszSecondSearch) != NULL) { insertAsLastDL(pszIns); flgAdd = FALSE; } else insertAsLastDL(pszBuffer[i]); } fclose(fp); if (flgAdd == TRUE) insertAsLastDL(pszIns); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } /* °Ë»ö¹®ÀÚ¿­(pszSearch)¸¦ ã¾Æ ±× ¶óÀÎÀÇ ¹Ù·Î ¾Õ¿¡ »ðÀÔ */ /* ¹®ÀÚ¿­À» ¶óÀÎÀ¸·Î »ðÀÔÇÑ´Ù. */ void insertForeSearchToFile(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) insertAsLastDL(pszBuffer[i]); fclose(fp); insertDLAsKey(pszInsert, pszSearch); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } /* °Ë»ö¹®ÀÚ¿­(pszSearch)À» ã¾Æ ±× ¶óÀÎÀÇ ³¡À§Ä¡¿¡ »ðÀÔ¹®ÀÚ¿­ */ /* (pszInsert)À» »ðÀÔÇÑ´Ù. */ void attatchStrToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0, j; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { pszBuffer[i][strlen(pszBuffer[i])-1] = '\0'; strcat(pszBuffer[i], pszInsert); pszBuffer[i][strlen(pszBuffer[i])] = '\n'; } insertAsLastDL(pszBuffer[i]); } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } /* °Ë»ö¹®ÀÚ¿­(pszSearch)¸¦ ã¾Æ ±×¶óÀÎÀÇ Æ¯Á¤Coloum(nStartIdx)¿¡¼­ */ /* ƯÁ¤Coloum(nEndIdx)±îÁöÀÇ ¹®ÀÚ¿­À» Save(pszSave)ÇÑ´Ù. */ void saveStrIdxToFileLine(char *pszSave, char *pszSearch, char *pszFileName, int nStartIdx, int nEndIdx, int nMaxLine, int nMaxCol) { int i = 0, j; FILE *fp; char *pszBuffer[nMaxLine]; char pszEndBuffer[nMaxCol]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { memset(pszEndBuffer, '\0', nMaxCol); strcpy(pszEndBuffer, pszBuffer[i]+nStartIdx); for (j = 0; j < nEndIdx-nStartIdx; j++) pszSave[j] = pszEndBuffer[j]; } } fclose(fp); } /* °Ë»ö¹®ÀÚ¿­(pszSearch)¸¦ ã¾Æ ±×¶óÀÎÀÇ Æ¯Á¤Coloum(nStartIdx)¿¡¼­ */ /* ƯÁ¤Coloum(nEndIdx)±îÁöÀÇ ¹®ÀÚ¿­À» »ðÀÔ¹®ÀÚ¿­(pszInsert)·Î ±³Ã¼ÇÑ´Ù. */ void changeStrIdxToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nStartIdx, int nEndIdx, int nMaxLine, int nMaxCol) { int i = 0, j; FILE *fp; char *pszBuffer[nMaxLine]; char pszEndBuffer[nMaxCol]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { memset(pszEndBuffer, '\0', nMaxCol); strcpy(pszEndBuffer, pszBuffer[i]+nEndIdx); pszBuffer[i][nStartIdx] = '\0'; strcat(pszBuffer[i], pszInsert); strcat(pszBuffer[i], pszEndBuffer); pszBuffer[i][strlen(pszBuffer[i])] = '\0'; } insertAsLastDL(pszBuffer[i]); } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } /* °Ë»ö¹®ÀÚ¿­(pszSearch)¸¦ ã¾Æ ±×¶óÀÎÀÇ Æ¯Á¤Coloum(nIdx) ÀÌÈÄÀÇ ¹®ÀÚ¿­ */ /* À» ¸ðµÎ ¾ø¾Ö°í, »ðÀÔ¹®ÀÚ¿­(pszInsert)À» ºÙÈù´Ù. */ void attatchStrIdxToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nIdx, int nMaxLine, int nMaxCol) { int i = 0, j; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { pszBuffer[i][nIdx] = '\0'; strcat(pszBuffer[i], pszInsert); pszBuffer[i][strlen(pszBuffer[i])] = '\n'; } insertAsLastDL(pszBuffer[i]); } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } /* ƯÁ¤¶óÀÎ(nLineIdx)ÀÇ Æ¯Á¤Coloum(nColIdx) ÀÌÈÄÀÇ ¹®ÀÚ¿­ */ /* À» ¸ðµÎ ¾ø¾Ö°í, »ðÀÔ¹®ÀÚ¿­(pszInsert)À» ºÙÈù´Ù. */ void attatchStrToFileIdxLine(char *pszInsert, char *pszFileName, int nLineIdx, int nColIdx, int nMaxLine, int nMaxCol) { int i = 0, j; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if (i == nLineIdx-1) { pszBuffer[i][nColIdx] = '\0'; strcat(pszBuffer[i], pszInsert); pszBuffer[i][strlen(pszBuffer[i])] = '\n'; } insertAsLastDL(pszBuffer[i]); } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } /* °Ë»ö¹®ÀÚ¿­(pszStartLine)À» ã¾Æ ±× ¶óÀÎÀÇ ¹Ù·Î ´ÙÀ½¶óÀο¡ */ /* »ðÀÔ¹®ÀÚ¿­(pszInsert)À» ¶óÀÎÀ¸·Î »ðÀÔÇÑ´Ù. */ void insertAfterStrToFile(char *pszInsert, char *pszStartLine, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j, k; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { insertAsLastDL(pszBuffer[i]); if ((char *)strstr(pszBuffer[i], pszStartLine) != NULL) { insertAsLastDL(pszInsert); insertAsLastDL("\n"); for (j = i+1; readOneLineSearchFile(pszBuffer[j], fp) != EOF; j++) insertAsLastDL(pszBuffer[j]); break; } } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return; } /* ù¹ø° °Ë»ö¹®ÀÚ¿­(pszStartLine)°ú µÎ¹ø° °Ë»ö¹®ÀÚ¿­(pszEndLine) */ /* À» ã¾Æ ±× »çÀÌ¿¡ ÀÖ´Â lineµéÀ» ÀúÀå(pszSaveLine)ÇÑ´Ù. */ void saveBetweenStrToFile(char *pszSaveLine[], char *pszStartLine, char *pszEndLine, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszStartLine) != NULL) { for (j = i+1; readOneLineSearchFile(pszBuffer[j], fp) != EOF; j++) { if ((char *)strstr(pszBuffer[j], pszEndLine) == NULL) strcpy(pszSaveLine[j-(i+1)], pszBuffer[j]); else break; } fclose(fp); for (j = 0; j < nMaxLine; j++) free(pszBuffer[j]); return; } } } /* ù¹ø° °Ë»ö¹®ÀÚ¿­(pszStartLine)°ú µÎ¹ø° °Ë»ö¹®ÀÚ¿­(pszEndLine) */ /* À» ã¾Æ ±× »çÀÌ¿¡ ÀÖ´Â lineµéÀ» »ðÀÔ¹®ÀÚ¿­(pszInsert)·Î ´ëü */ /* ½ÃŲ´Ù. */ void changeBetweenStrToFile(char *pszInsert[], int nInsertNum, char *pszStartLine, char *pszEndLine, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j, k; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { insertAsLastDL(pszBuffer[i]); if ((char *)strstr(pszBuffer[i], pszStartLine) != NULL) { for (j = i+1; readOneLineSearchFile(pszBuffer[j], fp) != EOF; j++) if ((char *)strstr(pszBuffer[j], pszEndLine) != NULL) break; for (k = 0; k < nInsertNum; k++) insertAsLastDL(pszInsert[k]); insertAsLastDL(pszBuffer[j]); for (k = j+1; readOneLineSearchFile(pszBuffer[k], fp) != EOF; k++) insertAsLastDL(pszBuffer[k]); break; } } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return; } ------------------------------------------------------- Áö±Ý±îÁö ¸µÅ©¸®½ºÆ®¸¦ ÀÌ¿ëÇÑ file󸮿¡ °üÇÑ ³»¿ëÀ» ´Ù·ç¾îº¸¾Ò´Ù. ±×·±µ¥, ¿Ö ±»ÀÌ Simple LinkedList¸¦ ¾²Áö ¾Ê°í, Double LinkedList ¸¦ »ç¿ëÇß´ÂÁö ±Ã±ÝÇÒ °ÍÀÌ´Ù. ³ª´Â ÈÄ¿¡¶óµµ ÀÌ Source¸¦ ´õ¿í °­È­½ÃÅ°±âÀ§ÇØ È®À强ÀÌ ÁÁÀº ÀÌÁß ¿¬°á¸®½ºÆ®¸¦ »ç¿ëÇÑ °ÍÀÌ´Ù. ¹°·Ð ´Ü¼ø¿¬°á¸®½ºÆ®¸¦ »ç¿ëÇÑ´Ù¸é ¸Þ ¸ð¸®¸¦ ¾à°£ Àý¾àÇÒ ¼ö´Â ÀÖ°ÚÁö¸¸ È®À强¿¡¼­´Â ÈξÀ ¶³¾îÁø´Ù. µû¶ó¼­, Library¸¦ ÈÄ¿¡ °­È­½Ãų ÀÏÀÌ ÀÖ´Ù¸é ÀÌÁß¿¬°á¸®½ºÆ®¸¦ ½á ¾ßÇÑ´Ù°í »ý°¢ÇÑ´Ù. 1.3. °³¼±µÇ¾î¾ßÇÒ ³»¿ë ¾Õ¼­ ¸»ÇßµíÀÌ À§ÀÇ Source´Â ƯÁ¤ RoutineÀÌ ¼öÇàµÉ ¶§ ¼ø°£ÀûÀ¸·Î Resource¸¦ Å©°Ô Â÷ÁöÇÒ ¼öµµ ÀÖ´Â ´ÜÁ¡ÀÌ ÀÖ´Ù. À̸¦ º¸¿ÏÇÏ·Á¸é LinkListÀÇ node¿¡ key°ªÀ» »ðÀÔÇÒ ¶§ ¸ðµç fileÀÇ ³»¿ëÀ» ÀüºÎ LinkList¿¡ »ðÀÔÇÒ °ÍÀÌ ¾Æ´Ï¶ó Á¶°Ç¿¡ ¸ÂÀ» ¶§¸¸ file ÀÇ ³»¿ëÀ» º¯°æÇϵµ·Ï ÇÏ´Â °ÍÀÌ ÁÁ´Ù. ÀÌ·¯ÇÑ °³¼±Á¡À» »ý°¢ÇØ À§ÀÇ SourceµéÀ» Çѹø ¼öÁ¤Çغ¸½Ã±â¸¦ ¹Ù¶õ ´Ù. =============================================================== < 2. QT ±âº» ´ÙÁö±â > -> ÇÊÀÚ´Â Ansi-C¸¦ »ç¿ëÇÏ´Â ¿ø½Ã ÇÁ·Î±×·¡¸Ó¿´´Ù. ÁÖ·Î ´Ù·ð´ø ºÐ¾ß´Â Network °ü·Ã ÇÁ·Î±×·¥À̾ú°í °³¹ß ȯ°æ¶ÇÇÑ X-window°¡ ¾Æ´Ñ text-mode¿¡¼­¿´´Ù. text-mode¿¡¼­ÀÇ GUI±¸Ãà¿¡ ¿Â ÈûÀ» ½ñ¾Ò°í ±× °á°ú·Î Curses³ª Slangº¸´Ùµµ ´õ ÁÁ´Ù°í ³»¼¼ ¿ï ¼ö ÀÖ´Â Library¸¦ °³¹ßÇß´Ù. ³ª´Â ³» ÀÚ½ÅÀÌ »ó´çÇÑ ¼öÁØ¿¡ ¿Ã¶ó¿Í ÀÖ´Ù°í Âø°¢Çϱ⠽ÃÀÛÇß°í Á¡Â÷ ÀÚ¸¸¿¡ ºüÁö°Ô µÇ¾ú´Ù. ÇÏÁö¸¸ Á¡Â÷ Linux°¡ ¾÷±×·¹ÀÌµå µÇ¸é¼­ ±²ÀåÇÑ ¼öÁØÀÇ ±×·¡ÇÈȯ °æÀÌ Á¦°øµÇ¸é¼­ ±× ÀÚ¸¸Àº ±úÁö±â ½ÃÀÛÇß´Ù. ±× Ãæ°ÝÀ̶õ ¾öû ³­ °ÍÀ̾ú´Ù. ³ª¿Í ºñ½ÁÇÑ ºÐµéÀÌ ÇѺÐÀÌ¶óµµ ÀÌ ±ÛÀ» Àд ºÐµé Áß¿¡ °è½Ã´Ù¸é ÀÌ ÀڷḦ ¿Ã¸° º¸¶÷ÀÌ ÀÖÀ» °ÍÀÌ´Ù. ±âŸµîµîÀÇ ÀÌÀ¯·Î C++¿¡ ´ëÇÑ Å¬·¡½º °³³äÁ¶Â÷µµ °ÅÀÇ ¸ð¸¥ »óÅ ¿¡¼­ ¾à 3°³¿ù ÀüºÎÅÍ QT¸¦ ½ÃÀÛÇß´Ù. ¾î¶°ÇÑ ÀÚ·áµµ ¾øÀÌ Alzza ¸®´ª½º¿¡ Æ÷ÇԵǾîÀÖ´Â QT 1.44 ÀÇ ¿¹Á¦ Source¸¸À¸·Î C++°ú QT¸¦ °øºÎÇÏÀÚ´Ï ¹«Ã´À̳ª ÈûÀÌ µé¾ú´Ù. ÀÌ·¸°Ô Èûµé°Ô °øºÎÇϸ鼭 QT¿¡ »¡¸® Á¢±ÙÇÒ ¼ö ÀÖ´Â ¹æ¹ýÀ» ÀúÀý ·Î Å͵æÇÏ°Ô µÇ¾ú´Âµ¥ ÀÌ ¹æ¹ýÀ» ¿©·¯ºÐ²² °¡Àå ÁÁ´Ù°í »ý°¢ÇÏ´Â °úÁ¤¿¡ ÀÇ°ÅÇÏ¿© ±ÛÀ» ¾²°Ú´Ù. ªÀº ½Ç·ÂÀ¸·Î ±ÛÀ» ¿Ã¸®´Ï ¿©·¯ºÐ ²² ÁËÃ¥°¨ÀÌ ¸ÕÀú ¾Õ¼­Áö¸¸ Source°øÀ¯¶ó´Â Â÷¿ø¿¡¼­ ±Í¿±°Ô º¸¾Æ Áֽñ⠹ٶõ´Ù. 2.1. QTÀÇ Class°èÃþÁ¤º¸ ¿ì¼± º»°ÝÀûÀÎ QT Á¦°ø ClassµéÀ» °øºÎÇϱ⿡ ¾Õ¼­ Class°èÃþ¿¡ ´ëÇØ ´«À¸·Î ÀÍÇôµÎ±â ¹Ù¶õ´Ù. ÀÌ °èÃþÁ¤º¸´Â »ó´çÈ÷ Áß¿äÇÏÁö¸¸ ¿Ü¿ï ÇÊ¿ä´Â ¾ø´Ù. ±×³É ÇÊ¿äÇÒ ¶§ ã¾Æº¸´Â Á¤µµ·Î È°¿ëÇϱ⠹٠¶õ´Ù. ¾Æ·¡ÀÇ Ç¥´Â /usr/lib/qt/html/hierarchy.html ¿¡¼­ ¹ßÃéÇÑ ³»¿ëÁß ¾ÕÀ¸·Î ¾²°ÔµÉÁöµµ ¸ð¸¦ ÁÖ¿ä Ŭ·¡½º¸¸À» Á¤¸®ÇÑ °ÍÀÌ´Ù. -------- < Ç¥ 2.1.1 QT Class °èÃþÁ¤º¸ > --------- QBrush QCollection QGList QList QStrList QStrIList QColor QColorGroup QConnection QCursor QEvent QChildEvent QCloseEvent QCustomEvent QDragMoveEvent QDropEvent QFocusEvent QKeyEvent QMouseEvent QMoveEvent QPaintEvent QResizeEvent QTimerEvent QFont QFontInfo QFontMetrics QGArray QArray QByteArray QString QPointArray QIconSet QImage QListBoxItem QListBoxPixmap QListBoxText QListViewItem QCheckListItem QMenuData QMenuBar QPopupMenu QMovie QObject QAccel QApplication QXtApplication QDragObject QImageDrag QStoredDrag QTextDrag QUrlDrag QLayout QBoxLayout QHBoxLayout QVBoxLayout QGridLayout QSignal QToolTipGroup QValidator QDoubleValidator QIntValidator QWidget QButton QCheckBox QPushButton QRadioButton QToolButton QComboBox QDialog QFileDialog QMessageBox QPrintDialog QTabDialog QFrame QGroupBox QButtonGroup QLCDNumber QLabel QMenuBar QProgressBar QScrollView QListView QSpinBox QSplitter QTableView QHeader QListBox QMultiLineEdit QPopupMenu QWidgetStack QLineEdit QMainWindow QNPWidget QScrollBar QSemiModal QProgressDialog QSlider QStatusBar QTabBar QToolBar QWindow QXtWidget QPaintDevice QPicture QPixmap QBitmap QPrinter QWidget QPaintDeviceMetrics QPainter QPalette QPen QPixmapCache QPoint QRangeControl QScrollBar QSlider QSpinBox QRect QSize QTextStream QTime QToolTip QWhatsThis QWMatrix ----------------------------------------- 2.2. Widget(QWidget)À̶õ? -> ¸ðµç »ç¿ëÀÚ ÀÎÅÍÆäÀ̽º(User Interface)ÀÇ ±âº» ClassÀÌ´Ù. À§ÀÇ Ç¥¿Í °°ÀÌ ¹öÆ°, ÇÁ·¹ÀÓ, ÆíÁý¹Ú½ºµî Graphic Interface¸¦ ÁÖµµÇÏ´Â ClassµéÁß ÃÖ »óÀ§¿¡ À§Ä¡ÇØÀÖ´Ù. ¸ðµç Widgetµé¿¡ ´ëÇÑ °øºÎ´Â öÀúÇÏ°Ô ¿¹Á¦À§ÁÖ·Î ÇÏ°Ú´Ù. 2.2.1. À§Á¬(QWidget), ÇÁ·¹ÀÓ(QFrame), ¹öÆ°(QButton) ---------- < source 2.2.1.1. testFrameButton.cpp > ----------- #include /* QApplicationÀ» À§ÇÑ header file */ #include /* QWidgetÀ» À§ÇÑ header file */ int main(int argc, char* argv[]) { /* ÀÌ ºÎºÐÀº QT ÇÁ·Î±×·¥ÀÇ mainÇÔ¼ö¿¡¼­ Ç×»ó ½áÁÖ¾î¾ß */ /* ÇÏ´Â ºÎºÐÀÌ´Ù. */ QApplication myapp(argc, argv); /* ÀÎÀÚ°¡ ¾øÀ½¿¡ ÁÖÀÇ */ QWidget *wdgtTest = new QWidget(); /* setGeometry(xÁÂÇ¥, yÁÂÇ¥, ³ÐÀÌ, ³ôÀÌ) */ wdgtTest->setGeometry(100, 100, 200, 100); /* applicationÀÇ ¸ÞÀÎ À©µµ¿ì¸¦ wdgtTest·Î Á¤ÀÇ */ myapp.setMainWidget(wdgtTest); /* wdgtTest¸¦ º¸¿©ÁØ´Ù. */ wdgtTest->show(); /* qt¸¦ ½ÇÇà½ÃŲ´Ù. ¸¸¾à ÀÌ ºÎºÐÀÌ ¾ø´Ù¸é À©µµ¿ì°¡ ¶ßÁö */ /* ¾ÊÀ» °ÍÀÌ´Ù. Ç×»ó µé¾î°¡¾ßÇÒ ºÎºÐÀÌ´Ù. */ return myapp.exec(); } ----------------------------------------------------------- À§ÀÇ Source¿¡¼­ °ü½ÉÀÖ°Ô º¸¾Æ¾ßÇÒ ºÎºÐÀº QWidget, QFrame, QPushButton ClassÀÇ ÀÎÀÚµéÀÌ´Ù. ¿ì¼± header fileÀ» »ìÆ캸ÀÚ. header file¿¡ °üÇÑ Á¤º¸´Â /usr/lib/qt/include/ ¿¡¼­ º¼ ¼ö ÀÖ´Ù. public: QWidget( QWidget *parent=0, const char *name=0, WFlags f=0 ); private: // Disabled copy constructor and operator= #if defined(Q_DISABLE_COPY) QWidget( const QWidget & ); QWidget &operator=( const QWidget & ); #endif À§ ºÎºÐÀº header file(/usr/lib/qt/include/qwidget.h)¿¡ µé¾îÀÖ ´Â QWidgetÀÇ »ý¼ºÀÚ ºÎºÐÀÌ´Ù. ¿©±â¼­ À¯½ÉÈ÷ º¸¾Æ¾ßÇÒ ºÎºÐÀº ÀÎÀÚµéÀÇ Á¤ÀÇ ºÎºÐÀÌ´Ù. Áï, QWidget *parent = 0, const char *name = 0, WFlags f = 0 ÀÌ·¸°Ô Ŭ·¡½ºÁ¤ÀǺκп¡¼­ ÀÎÀÚ°ª±îÁöµµ Á¤ÀÇÇÒ ¼ö ÀÖ´Ù´Â °ÍÀº C++À» ÇѹøÂë ´Ù·ïº» ºÐÀ̶ó¸é ¸ðµÎ ¾Æ½Ç °ÍÀÌ´Ù. C¿¡¼­ NULL°ªÀº #define¹®À¸·Î 0À¸·Î ¼±¾ðµÇ¾îÀÖ´Ù. Áï parent, name, f ¸ðµÎ NULL·Î Á¤ÀǸ¦ Çß´Ù´Â ¶æÀε¥ ±×³É ÃʱâÈ­½ÃÄ×´Ù ´Â Àǹ̷Π¹Þ¾ÆµéÀÌÀÚ. ¹°·Ð ÀÌ ºÎºÐÀº class »ý¼ºÀÚ(constructor) ºÎºÐ¿¡¼­ Á÷Á¢ Á¤ÀÇÇÒ ¼öµµ ÀÖ´Ù. ÀÌ´Â C++ÀÇ Æ¯±ÇÀ̶ó°í ÇÒ ¼ö ÀÖ°Ú´Ù. ÀÌ·± ¹æ¹ýÀº ¿©·¯°÷¿¡¼­ »ó ´çÈ÷ À¯¿ëÇÏ°Ô ¾µ ¼ö ÀÖ´Â ±â´ÉÀÌ´Ù. ÀÚ¼¼ÇÑ ¿¹´Â Â÷Â÷ À̾߱âÇÏ µµ·Ï ÇÏ°Ú´Ù. ÀÌÁ¨ ÀÎÀڵ鿡 ´ëÇØ »ìÆ캸ÀÚ. -> QWidget *parent: parent widgetÀ» ¶æÇÑ´Ù. À§ÀÇ header file¿¡ ³ªÅ¸³­ class¼±¾ð¿¡¼­µµ º¸¾Ò µíÀÌ µðÆúÆ®·Î NULL(0)À¸·Î ¼³Á¤µÇ¾îÀִµ¥ ÀÌ´Â ÀÚ½ÅÀ» ÃÖ»óÀ§ À©µµ¿ì·Î Á¤ÇÏ°Ú´Ù´Â ¶æÀÌ´Ù. Áï parent°¡ Á¤ÀǵÇÁö ¾ÊÀº(ÀÎÀÚ°¡ ¾ø´Â) widgetÀº ºÎ¸ðclass°¡ ¾øÀÌ µ¶¸³ÀûÀÎ À©µµ¿ì üÁ¦¸¦ °¡Áø´Ù. parentÀÎÀÚ¿¡ ¸¸¾à ´Ù¸¥ widget°ªÀ» ³Ñ°ÜÁشٸé parentÀÎÀÚ¿¡ Á¾¼ÓµÇ°Ô µÈ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº source 2.2.1.2¿¡¼­ ´Ù½Ã ´Ù·ç°Ú´Ù. -> const char *name:ÀÌ°ÍÀº widget¿¡ ´ëÇÑ ½Äº°ÀÚ ¿ªÇÒÀ» ÇÑ´Ù. ÀÌ ½Äº°ÀÚ´Â ÇÁ·Î±×·¡¸Ó°¡ °ÅÀÇ »ç¿ëÇÒ ÀÏÀÌ ¾ø´Ù. library¿¡¼­ ÀÚüÀûÀ¸·Î compile½Ã debuggingÀÛ¾÷ À» ÇÒ ¶§, ȤÀº »ç¿ëÀÚ°¡ debugging toolÀ» »ç¿ëÇÒ ¶§ ƯÁ¤ ºÎºÐ¿¡ ´ëÇÑ Á¤º¸¸¦ º¸°í ½ÍÀ» ¶§ name() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© Á¤º¸¸¦ ÃßÃâÇÒ ¼ö ÀÖ´Ù. ÇÊÀÚ´Â °ÅÀÇ debugging toolÀ» »ç¿ëÇÏÁö ¾ÊÀ¸¹Ç·Î ÀÌ ÀÎÀÚ¿¡ ´ëÇÑ Á¤ÀÇ´Â Çѹøµµ ÇÑÀûÀÌ ¾ø´Ù. µû¶ó¼­ ÀÌ ÀÎÀÚ¿¡ ´ëÇÑ ¼³¸íÀº »ý·«Çϱâ·Î ÇÏ°Ú´Ù. -> WFlags f: °ÅÀÇ »ç¿ëÇÒ ÀÏÀÌ ¾øÀ¸¹Ç·Î µðÆúÆ®°ªÀ» µû¸£±â·Î ÇÏÀÚ. ¼³¸íµµ »ý·«ÇÏ°Ú´Ù. ÀÚ¼¼ÇÑ Á¤º¸´Â /usr/lib/qt/html/qwidget.html fileÀ» ÂüÁ¶Çϱ⠹ٶõ´Ù. ---------- < source 2.2.1.2. testFrameButton.cpp > ----------- #include #include #include /* QFrameÀ» À§ÇÑ header file */ int main(int argc, char* argv[]) { QApplication myapp(argc, argv); QWidget *wdgtTest = new QWidget(); wdgtTest->setGeometry(100, 100, 200, 100); /* parent ÀÎÀÚ¸¦ wdgtTest·Î ¼³Á¤ÇÑ´Ù. */ QFrame *frTest = new QFrame(wdgtTest); /* parent°¡ wdgtTestÀ̹ǷΠfrTest¿¡ ´ëÇÑ ¼Ó¼º */ /* µé(xÁÂÇ¥, yÁÂÇ¥)ÀÇ ÁÂÇ¥°ªÀº wdgtTest¿¡ ´ëÇÑ */ /* »ó´ëÀûÀÎ ÁÂÇ¥·Î º¯È¯µÈ´Ù. */ frTest->setGeometry(10, 10, 150, 60); /* frameÀÇ ÇüŸ¦ Á¤ÇÑ´Ù. */ frTest->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); myapp.setMainWidget(wdgtTest); wdgtTest->show(); return myapp.exec(); } ----------------------------------------------------------- QFrame¿¡ ´ëÇÑ class¼±¾ð Á¤º¸´Â /usr/lib/qt/include/qframe.h¿¡ Á¤ÀǵǾîÀÖ´Ù. ´ÙÀ½°ú °°ÀÌ public°ú private¾çÂÊ¿¡ ¼±¾ðµÇ¾îÀÖ´Ù. public: QFrame( QWidget *parent=0, const char *name=0, WFlags f=0, bool allowLines=TRUE ); private: // Disabled copy constructor and operator= #if defined(Q_DISABLE_COPY) QFrame( const QFrame & ); QFrame &operator=( const QFrame & ); #endif public member¿Í private member¿¡ ´ëÇؼ­´Â ±»ÀÌ ¾ð±ÞÇÏÁö ¾Ê¾Æµµ µÇ °ÚÁö¸¸ ÂüÁ¶¹üÀ§¿¡ ´ëÇØ ¾ÆÁÖ °£´ÜÇÏ°Ô ¼³¸íÀ» ÇÏ°Ú´Ù. -> public member: ÇÏÀ§, »óÀ§, ȤÀº ÇüÁ¦ class¿¡¼­ ÀÌ member¸¦ ÂüÁ¶ÇÒ ¼ö ÀÖ´Ù. -> private member: ´Ù¸¥ ¾î¶² classµµ ÀÌ member¸¦ ÂüÁ¶ÇÒ ¼ö ¾ø´Ù. ÀÎÀÚ¿¡ ´ëÇØ ¾Ë¾Æº¸µµ·Ï ÇÏÀÚ. -> QWidget *parent: À§¿¡¼­ ¾ð±ÞÇÑ QWidgetÀÇ parentÀÎÀÚ¿Í °°´Ù. -> const char *name: " " -> WFlags f: " " -> bool allowLines: ¸¸¾à FALSE·Î settingµÈ´Ù¸é ¼öÆò¶óÀΰú ¼öÁ÷¶óÀÎ À» ¾²Áö ¾Ê´Â´Ù. ---------- < source 2.2.1.3. testFrameButton.cpp > ----------- #include #include #include #include /* QPushButtonÀ» À§ÇÑ header file */ int main(int argc, char* argv[]) { QApplication myapp(argc, argv); QWidget *wdgtTest = new QWidget(); wdgtTest->setGeometry(100, 100, 200, 100); QFrame *frTest = new QFrame(wdgtTest); frTest->setGeometry(10, 10, 150, 60); /* ÇüÅ¿¡ ÁÖÀÇÇÏ¿© º¸ÀÚ. */ frTest->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); /* text°¡ "Å×½ºÆ®", parent°¡ frTest·Î ¼³Á¤µÇ¾îÀÖ´Ù. */ QPushButton *bttnTest = new QPushButton("Å×½ºÆ®", frTest); /* frTest¿Í ¸¶Âù°¡Áö·Î bttnTest ¶ÇÇÑ frTest¿¡ ´ëÇÑ »ó´ë */ /* ÀûÀÎ ÁÂÇ¥·Î ¼³Á¤µÈ´Ù. */ bttnTest->setGeometry(20, 20, 100, 30); // bttnTest->resize(100, 30); myapp.setMainWidget(wdgtTest); wdgtTest->show(); return myapp.exec(); } ----------------------------------------------------------- /usr/lib/qt/include/qframe.h¿¡ º¸¸é setFrameStyle¿¡ ´ëÇØ ´ÙÀ½ °ú °°ÀÌ ¾²¿©Á® ÀÖ´Ù. void setFrameStyle(int); ÀÎÀںκÐÀ» º¸¸é integerÇüÀε¥ ÀÌ°÷¿¡ µé¾î°¥ ¼ö ÀÖ´Â ÀÎÀÚ ¶ÇÇÑ header file¿¡ Àß ³ªÅ¸³ªÀÖ´Ù. enum { NoFrame = 0, // no frame Box = 0x0001, // rectangular box Panel = 0x0002, // rectangular panel WinPanel = 0x0003, // rectangular panel (Windows) HLine = 0x0004, // horizontal line VLine = 0x0005, // vertical line MShape = 0x000f, Plain = 0x0010, // plain line Raised = 0x0020, // raised shadow effect Sunken = 0x0030, // sunken shadow effect MShadow = 0x00f0 }; enumeration µÇ¾îÁø memberµéÀ» ÁÖÀDZí°Ô º¸¸é ¼ýÀÚ°¡ ²÷¾îÁ®ÀÖ´Â °Í À» ¾Ë ¼ö ÀÖ´Ù. Áï 0x0001~0x0005, 0x000f, 0x0010, 0x0020, 0x0030, 0x00f0. ÀÌ 16Áø¼öµéÀ» 2Áø¼ö·Î Ç®¾îº¸ÀÚ. 0x0001 => 0000 0000 0000 0001 0x0002 => 0000 0000 0000 0010 0x0003 => 0000 0000 0000 0011 0x0004 => 0000 0000 0000 0100 0x0005 => 0000 0000 0000 0101 0x000f => 0000 0000 0000 1111 0x0010 => 0000 0000 0001 0000 0x0020 => 0000 0000 0010 0000 0x0030 => 0000 0000 0011 0000 0x00f0 => 0000 0000 1111 0000 À§ÀÇ 2Áø¼ö °ª¿¡¼­µµ º¼ ¼ö ÀÖµíÀÌ bit operationÀ» Àû´çÇÏ°Ô¸¸ ¾´ ´Ù¸é ¿©·¯ ¸ð¾çÀÇ Frame StyleÀ» ³ªÅ¸³¾ ¼ö ÀÖ´Â Á¶ÇÕÀÌ ³ª¿À°Ô µÈ´Ù. ¿¹¸¦ µé¾î [ Box | WinPanel | Sunken ]À» ÇÏ°Ô µÇ¸é À©µµ¿ìÁî ½ºÅ¸ ÀÏÀÇ ¿òÇ« µé¾î°£ ÀÔü ¶óÀÎÀ» ³ªÅ¸³»ÁØ´Ù. /usr/lib/qt/include/qpushbutton.h¿¡´Â ´ÙÀ½°ú °°ÀÌ class°¡ ¼± ¾ðµÇ¾îÀÖ´Ù. public: QPushButton( QWidget *parent=0, const char *name=0 ); QPushButton( const char *text, QWidget *parent=0, const char *name=0 ); private: // Disabled copy constructor and operator= #if defined(Q_DISABLE_COPY) QPushButton( const QPushButton & ); QPushButton &operator=( const QPushButton & ); #endif Ȥ¿© ±Ã±ÝÇÏ°Ô »ý°¢ÇÒ ¼öµµ ÀÖ´Â ºÎºÐ QPushButton &operator=( const QPushButton & ); Àº ´ÙÀ½ º¸¿©µå¸± source 2.2.1.4¿¡¼­ ¼³¸íÇÏ°Ú´Ù. º¸´Â ¹Ù¿Í °°ÀÌ QPushButtonÀÇ ÀÎÀÚ¿¡´Â ¹®ÀÚ¿­ "Å×½ºÆ®"¿Í frTest°¡ µé¾î°¡ÀÖ´Ù. Á¾¼Ó¼º¿¡ ´ëÇÑ ¼³¸íÀº À§Çؼ­ ÀÌ¹Ì Çß À¸¹Ç·Î ¿©±â¼­´Â »ý·«ÇÏ°Ú´Ù. °¢ widgetµéÀÇ ¼Ó¼º¿¡ ´ëÇÑ ¼³Á¤Àº setGeometry·Î ÇÒ ¼öµµ ÀÖ°í, resize¶ó´Â ÇÔ¼ö·Îµµ ¼³Á¤ÀÌ °¡´É ÇÏ´Ù. ÀÌ µÎ ÇÔ¼ö´Â ¼³Á¤°ª¿¡¼­ ¾à°£ÀÇ Â÷ÀÌ°¡ ÀÖ´Ù. setGeometry´Â ÁÂÇ¥¿Í Å©±â¿¡ ´ëÇÑ ¼³Á¤ÀÌ ¸ðµÎ µé¾î°¡Áö¸¸ resize ÇÔ¼ö´Â xÁÂÇ¥¿Í yÁÂÇ¥¸¸ÀÌ ÀÎÀÚ·Î µé¾î°£´Ù. ÀÌ µÎ ÇÔ¼ö´Â widget µé¿¡ ´ëÇÑ ¼Ó¼º ¼³Á¤À̹ǷΠQWidgetÀÇ ÇÏÀ§ classµéÀÇ publicÇÔ¼ö ¿¡ ¸ðµÎ ¼±¾ðÀÌ µÇ¾îÀÖ´Ù. ¹°·Ð QWidgetµµ À̵é ÇÔ¼ö¸¦ Æ÷ÇÔÇÏ°í ÀÖ´Ù. 2.2.1.1. Class¸¦ »ý¼ºÇÏ¿© ¸¸µé±â ÀÌÁ¦ºÎÅÍ´Â À§¿¡¼­ ¼³¸íÇÑ sourceµéÀ» »ç¿ëÇÏ¿© ºÐÇÒ ÄÄÆÄÀÏÇÏ´Â ¹æ ¹ýÀ» ¾Ë¾Æº¸ÀÚ. ¿ì¼± sourceµéÀ» °¢ Ư¼º´ÜÀ§·Î ºÐ¸®½ÃÄѾßÇÑ´Ù. ´ÙÀ½Àº ÀÌ·¸°Ô ºÐ¸®µÈ source codeµéÀÌ´Ù. --------- < source 2.2.1.1.1 clssTestWidget.h > ----------- #include /* ¾Æ·¡ÂÊÀÇ public QWidget ºÎºÐ¿¡ ´ëÇÑ header */ /* ¾Æ·¡ÂÊ¿¡ ÀÖ´Â frTest¿Í bttnTest¸¦ ¼±¾ðÇϱâ À§ÇÑ class ¼±¾ð. */ /* ÀϹÝÇÔ¼ö ¼±¾ð°ú ºñ½ÁÇÔ¿¡ À¯ÀÇ */ class QFrame; class QPushButton; /* clssTestWidget class´Â QWidgetÀÇ ¸ðµç publicº¯¼ö ȤÀº class¸¦ */ /* °øÀ¯ÇÒ ¼ö ÀÖ´Ù. Áï clssTestWidget class´Â QWidgetÀ¸·ÎºÎÅÍ '»ó¼Ó' */ /* ¹ÞÀº classÀÌ´Ù. */ class clssTestWidget : public QWidget { /* Qt library¸¦ ¾²´Â class¶ó¸é Ç×»ó ÀÌ·¸°Ô ¼±¾ðÇسõ¾Æ¾ß ÇÑ´Ù. */ Q_OBJECT public: clssTestWidget(); /* »ý¼ºÀÚ */ ~clssTestWidget(); /* ¼Ò¸êÀÚ */ /* widget(bttnTest)ÀÇ Æ¯Á¤ SIGNALÀÌ ¹ß»ýÇßÀ» ¶§, event¸¦ ¹Þ¾Æ */ /* ¿øÇϴ ó¸®¸¦ ÇØÁÙ ¼ö ÀÖ´Â slot function ¼±¾ð */ public slots: void printMessage(); /* ÈÄ¿¡ ¼³¸íÇÏ°Ú´Ù. ¿ì¼±Àº ÀÌ·± formatµµ ÀÖ´Ù´Â Á¤µµ·Î ¾Ë¾ÆµÎÀÚ. */ protected: private: QFrame *frTest; QPushButton *bttnTest; }; ----------------------------------------------------------- --------- < source 2.2.1.1.2 clssTestWidget.cpp > --------- #include /* frTest¸¦ À§ÇÑ header ¼±¾ð */ #include /* bttnTest¸¦ À§ÇØ */ #include #include "clssTestWidget.h" clssTestWidget::clssTestWidget() { QFrame *frTest = new QFrame(this); frTest->setGeometry(10, 10, 150, 60); frTest->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); QPushButton *bttnTest = new QPushButton("Å×½ºÆ®", frTest); bttnTest->setGeometry(20, 20, 100, 30); /* ¹öÆ°ÀÌ 'clicked()'µÇ¾úÀ» ¶§ printMessage()ÇÔ¼ö¸¦ È£ÃâÇ϶ó´Â */ /* Çൿ Áöħ */ QObject::connect(bttnTest, SIGNAL(clicked()), this, SLOT(printMessage())); } clssTestWidget::~clssTestWidget() { } /* ¹öÆ°ÀÌ ´­·ÈÀ» ¶§ 󸮵Ǵ ÇÔ¼ö */ void clssTestWidget::printMessage() { emit printf("¹öÆ°ÀÌ ´­·È½À´Ï´Ù.\n"); } ----------------------------------------------------------- --------- < source 2.2.1.1.3 main_test1.cpp > --------- #include /* QApplicationÀ» À§ÇÑ header file */ #include "clssTestWidget.h" int main(int argc, char* argv[]) { QApplication myapp(argc, argv); /* class »ý¼º */ clssTestWidget *wdgtTest = new clssTestWidget(); /* class ¼Ó¼ºÁ¤ÀÇ */ wdgtTest->setGeometry(100, 100, 200, 100); /* mainÀ¸·Î ¾µ widget Á¤ÀÇ */ myapp.setMainWidget(wdgtTest); /* widgetÀ» º¸¿©ÁÜ */ wdgtTest->show(); return myapp.exec(); } ----------------------------------------------------------- ÀÌ sourceµé¿¡ ¾Õ¼­ ¼³¸íÇÑ source¿ÍÀÇ Â÷ÀÌÁ¡Àº, fileµéÀÌ ºÐ¸® µÇ¾ú°í class¸¦ Á¤ÀÇÇÏ¿© ±× class¸¦ main¿¡¼­ È£ÃâÇÑ´Ù´Â °Í ¸»°í´Â °ÅÀÇ ¾ø´Ù. µû¶ó¼­ ´õÀÌ»óÀÇ ¼³¸íÀº »ý·«ÇÏ°í ´ÙÀ½À¸·Î Maikfile¿¡ ´ëÇÑ °£´ÜÇÑ ¼³¸í°ú ÇÔ²² ÀÌ ºÐÇÒ moduleµéÀ» compile ÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ ¾Ë¾Æº¸°Ú´Ù. 2.2.2. Makefile ¸¸µé±â 2.2.1.¿¡¼­ÀÇ sourceµéÀ» compileÇÏ´Â ¹æ¹ý¿¡ ´ëÇؼ­´Â ¾ÆÁ÷ ¾ð ±ÞÇÏÁö ¾Ê¾Ò´Ù. Qt 2.0ÀÌ»óºÎÅÍ´Â Á¦¹ý GUI ToolÀÌ ±¦Âú¾ÆÁø ¸ð ¾çÀÌ´øµ¥ ÇÊÀÚµµ ÇѹøÀº »ç¿ëÀ» ÇØ º¸¾ÒÁö¸¸ ¹ö±×°¡ ¸î °¡Áö ÀÖ ´Â °Í °°¾Æ Áö±ÝÀº ÀüÇô »ç¿ëÇÏÁö ¾Ê°í ÀÖ´Ù. MakefileÀ» ¸¸µå´Â ¹æ¹ý¿¡ À־µµ ¿ä»÷ tmake¶ó´Â GUI ToolÀ» »ç¿ëÇÑ´Ù°í µé¾ú´Ù. ÇÊÀÚ´Â ÀÌ Toolµµ »ç¿ëÇÏÁö ¾Ê´Â´Ù. ÀÌÀ¯´Â °£´ÜÇÏ´Ù. Makefile À» ¸¶À½´ë·Î ÁÖ¹«¸£±â À§Çؼ­ÀÌ´Ù. MakefileÀ» ¿ÏÀüÇÏ°Ô ÀÌÇØÇÏ°í ½±°Ô ¾µ ¼ö ÀÖ´Â ¼öÁØÀ̶ó¸é tmake ¸¦ »ç¿ëÇÏ´Â °Íµµ ³ª»ÚÁö´Â ¾ÊÀ» °ÍÀÌ´Ù. ¾Æ·¡ÀÇ code´Â 2.2.1.1ÀÇ sourceµéÀ» ºÐÇÒ CompileÇϱâ À§ÇÑ MakefileÀÌ´Ù. ---------------- < Makefile 2.2.2 > --------------------- PROGS = main_test1 ### º¸Åë ½ÇÇàfileÀÇ À̸§À» Àû´Â´Ù. ### X-window ȯ°æ¿¡ °üÇÑ libraryµéÀ» Æ÷ÇÔ½ÃŲ´Ù. (Qt Æ÷ÇÔ) LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm ### Compiler¸¦ Á¤ÀÇÇÑ´Ù. CC = g++ GCC = gcc ### Header fileµéÀ» Æ÷ÇÔ½ÃŲ´Ù. INCLUDE = -I/usr/lib/qt/include ### Compile optionÀ» Á¤ÀÇÇÑ´Ù. C_FLAG = -pipe -DNO_DEBUG -O2 ### Header file¿¡ ´ëÇÑ option°ú Compile optionÀ» ÇÕÇÑ´Ù. CFLAGS = $(INCLUDE) $(C_FLAG) ### ½ÇÇàfile»ý¼ºÀ» À§ÇÑ Linker¸¦ Á¤ÀÇÇÑ´Ù. ¿©±â¼­´Â g++ÀÌ µÈ´Ù. SYSCONF_LINK = $(CC) ### class¸¦ ºÐ¸®½ÃÄѳõÀº Header fileÀ» .cpp source file°ú ¿¬µ¿ ### ½ÃÅ°¸ç ½Ã½ºÅÛ¿¡¼­ ÃʱâÈ­µÈ graphic device¿¡ °üÇÑ settingÀ» ### ½ÃÅ°±â À§ÇÑ Æ¯¼öÇÑ cpp fileÀÎ moc fileÀ» »ý¼º½ÃÅ°´Â toolÀÌ ### ´Ù. moc file¿¡ ´ëÇÑ ºÐ¼®Àº º°·Î ÇÊ¿ä¾ø´Â ºÎºÐÀ̹ǷΠ»ý·«ÇÏ ### °Ú´Ù. SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) ### mainÇÔ¼ö°¡ µé¾îÀÖ´Â source fileÀ» Link½Ãų ¶§ ÇÊ¿äÇÑ Object file ### µéÀ» ÈÄ¿¡ ÂüÁ¶Çϱâ ÆíÇϵµ·Ï Label·Î ¹­¾î³õ´Â´Ù. MNU_OBJS = \ main_test1.o \ clssTestWidget_moc.o \ clssTestWidget.o ### 'make all'Àº ÀÌ MakefileÀ» ½ÇÇàÇÑ´Ù. (= make) all: $(PROGS) ### 'make clean'Àº make¸¦ ½ÇÇà½ÃÄ×À»¶§ »õ·Î »ý¼ºµÇ´Â ¸ðµç file ### À» Áö¿ì´Â ¿ªÇÒÀ» ÇÑ´Ù. clean, all, ¸ðµÎ »ç¿ëÀÚ°¡ ¾î¶»°Ô Á¤ ### ÀÇÇϴ°¡¿¡ µû¶ó ¿ªÇÒÀÌ Æ²·ÁÁö°Ô µÈ´Ù. clean: rm -f *.o rm -f main_test1 rm -f *_moc.* ############# COMPILE ############# ### main fileÀ» ÄÄÆÄÀÏÇÑ´Ù. main_test1.o: main_test1.cpp $(CC) -c main_test1.cpp $(CFLAGS) -o $@ ### Header file·ÎºÎÅÍ moc fileÀ» ¸¸µé¾î³½´Ù. clssTestWidget_moc.cpp: clssTestWidget.h $(MOC) clssTestWidget.h -o clssTestWidget_moc.cpp ### ¸¸µé¾îÁø moc fileÀ» ÄÄÆÄÀÏÇÑ´Ù. clssTestWidget_moc.o: clssTestWidget_moc.cpp $(CC) -c clssTestWidget_moc.cpp $(CFLAGS) -o $@ ### »õ·Î ºÐ¸®µÈ module fileÀ» ÄÄÆÄÀÏÇÑ´Ù. clssTestWidget.o: clssTestWidget.cpp $(CC) -c clssTestWidget.cpp $(CFLAGS) -o $@ ### ¸Ç À­ºÎºÐÀÇ PROGÁ¤ÀǺο¡ ÀÖ´Â À̸§À» Label·Î ¾´´Ù. main_test1: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ ------------------------------------------------------------ shell»ó¿¡¼­ 'make' ȤÀº 'make all' À» ½ÇÇà½ÃÅ°¸é ÀÚµ¿ÀûÀ¸·Î compile ¹× link¸¦ ½ÃÄÑÁØ´Ù. make´Â object fileÀÇ »ý¼º½Ã°£, Áï compileµÈ ½ÃÁ¡À» ±âÁØÀ¸·Î source¿¡ º¯È­°¡ »ý°åÀ» ¶§ ±× º¯È­µÈ source module¸¸À» compileÇÔÀ¸·Î½á Àüü¸¦ CompileÇÏ´Â ½Ã°£À» Å© °Ô ÁÙ¿©ÁÖ´Â È¿°ú°¡ ÀÖ´Ù. ¹°·Ð source moduleÀÌ µÎ¼¼°³ Á¤µµ·Î ÀÛ ´Ù¸é ±»ÀÌ MakefileÀ» ¸¸µé¾îÁÙ ÇÊ¿ä°¡ ¾ø´Ù. ÇÏÁö¸¸ º¸Åë ½ÇÁ¦ projectµéÀÇ °æ¿ì »ó´çÇÑ ¼öÀÇ source moduleÀ» ÇÊ¿ä·Î Çϱ⶧¹®¿¡ MakefileÀÇ »ý¼ºÀº ÇʼöÀûÀ̶ó ÇÒ ¼ö ÀÖ´Ù. ´ÙÀ½À¸·Î ¼Ò°³ÇÏ´Â sourceµé¿¡ ´ëÇؼ­´Â ¸ðµç sourceÀÇ Makefile À» source¹Ù·Î ¹Ø¿¡ ÁÖ¼®¾øÀÌ ¼Ò°³Çϵµ·Ï ÇÏ°Ú´Ù. MakefileÀ» »ç¿ë Çϴµ¥ ÀÖ¾î Àû°Ô¶óµµ µµ¿òÀÌ µÇ¾úÀ¸¸é ÇÑ´Ù. 2.2.3. ¶óº§(QLabel) ÀÌÁ¦ºÎÅÍ 2.2.10±îÁöÀÇ ¸ðµç ¿¹Á¦´Â ¾Õ¿¡¼­ »ç¿ëÇÑ ºÐÇÒ module compile ¹æ¹ýÀ» µû¸£±â·Î ÇÏ°Ú´Ù. ¹°·Ð ±âÁ¸¿¡ ¼³¸íÇß´ø ºÎºÐµéÀº ¸ðµÎ »ý·«ÇÑ´Ù. ¿ì¼± source¸¦ º¸µµ·Ï ÇÏÀÚ. -------------- < source 2.2.3.1 clssTestLabel.h > --------------- #include class QLabel; class clssTestLabel : public QWidget { Q_OBJECT public: clssTestLabel(); ~clssTestLabel(); public slots: protected: private: QLabel *lblTest1; QLabel *lblTest2; QLabel *lblTest3; }; ------------------------------------------------------------------- -------------- < source 2.2.3.2 clssTestLabel.cpp > --------------- #include #include #include "clssTestLabel.h" clssTestLabel::clssTestLabel() { QLabel *lblTest1 = new QLabel(this); lblTest1->setText("Å×½ºÆ® 1"); lblTest1->setGeometry(20, 20, 100, 30); /* QLabel¿¡¼­ setFrameStyleÇÔ¼ö¸¦ È£ÃâÇß´Ù´Â °ÍÀ» ¸í½ÉÇÏÀÚ. */ lblTest1->setFrameStyle(QFrame::Box | QFrame::Panel | QFrame::Raised); QLabel *lblTest2 = new QLabel(this); lblTest2->setText("Å×½ºÆ® 2"); lblTest2->setGeometry(20, 60, 100, 30); lblTest2->setFrameStyle(QFrame::Box | QFrame::Panel | QFrame::Sunken); QLabel *lblTest3 = new QLabel(this); lblTest3->setText("Å×½ºÆ® 3"); lblTest3->setGeometry(20, 100, 100, 30); lblTest3->setFrameStyle(QFrame::Box | QFrame::Panel | QFrame::Plain); } clssTestLabel::~clssTestLabel() { } ------------------------------------------------------------------- À§ÀÇ Source´Â ÃÑ ¼¼°¡Áö ¸ð¾çÀÇ Label formatÀ» ³ªÅ¸³»ÁØ´Ù. ƯÀÌÇÒ ¸¸ÇÑ Á¡Àº QLabel¿¡¼­ setFrameStyleÀ» È£ÃâÇß´Ù´Â °ÍÀε¥ /usr/lib/qt/include/qlabel.h¿¡¼­´Â setFrameStyleÇÔ¼ö°¡ ¼±¾ðµÇ¾îÀÖÁö ¾Ê´Ù. qframe.h file¿¡¼­¸¸ÀÌ ¼±¾ðµÇ¾îÀִµ¥ QLabelÀº QFrame class¿¡¼­ ÆÄ»ýµÇ¾î ³ª¿Â ÀÚ½Ä classÀ̹ǷΠQFrame class¿¡¼­ ¼±¾ðµÇ¾îÀÖ´Â ¸ðµç publicÇÔ¼öµéÀ» °øÀ¯ÇÏ¿© ¾µ ¼ö ÀÖ´Ù. ¹°·Ð enumerationµÈ Box, Panelµî À» ¾µ ¶§´Â QLabelÀÇ memberµéÀÌ ¾Æ´Ï¹Ç·Î QFrame::°ú °°ÀÌ ¼Ò¼ÓÀ» Àû¾î ÁÖ¾î¾ß Compiler°¡ ¾Ë¾ÆµéÀ» ¼ö ÀÖ´Ù. -------------- < source 2.2.3.3 main_test2.cpp > --------------- #include #include "clssTestLabel.h" int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssTestLabel *clssTest = new clssTestLabel(); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } ------------------------------------------------------------------- ---------------------- < Makefile 2.2.3.1 > ---------------------- PROGS = main_test2 LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm CC = g++ GCC = gcc INCLUDE = -I/usr/lib/qt/include C_FLAG = -pipe -DNO_DEBUG -O2 CFLAGS = $(INCLUDE) $(C_FLAG) SYSCONF_LINK = $(CC) SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) MNU_OBJS = \ main_test2.o \ clssTestLabel_moc.o \ clssTestLabel.o all: $(PROGS) clean: rm -f *.o rm -f main_test2 rm -f *_moc.* ############# COMPILE ############# main_test2.o: main_test2.cpp $(CC) -c main_test2.cpp $(CFLAGS) -o $@ clssTestLabel_moc.cpp: clssTestLabel.h $(MOC) clssTestLabel.h -o clssTestLabel_moc.cpp clssTestLabel_moc.o: clssTestLabel_moc.cpp $(CC) -c clssTestLabel_moc.cpp $(CFLAGS) -o $@ clssTestLabel.o: clssTestLabel.cpp $(CC) -c clssTestLabel.cpp $(CFLAGS) -o $@ main_test2: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ ------------------------------------------------------------------- 2.2.4. ÆíÁý¹Ú½º(QLineEdit) -------------- < source 2.2.4.1 clssTestLineEdit.h > --------------- #include class QLineEdit; class QPushButton; class clssTestLineEdit : public QWidget { Q_OBJECT public: clssTestLineEdit(); ~clssTestLineEdit(); public slots: void testClick(); protected: private: QLineEdit *leTest1; QLineEdit *leTest2; QPushButton *bttnTest; }; ------------------------------------------------------------------- -------------- < source 2.2.4.2 clssTestLineEdit.cpp > --------------- #include #include #include #include "clssTestLineEdit.h" clssTestLineEdit::clssTestLineEdit() { leTest1 = new QLineEdit(this); leTest1->setGeometry(20, 20, 100, 30); leTest2 = new QLineEdit(this); leTest2->setGeometry(20, 60, 100, 30); leTest2->setText("ȯ¿µ!"); /* setEnabled´Â ÆíÁýÀ» ÇÒ ¼ö ÀÖ°Ô ÇÒ °ÍÀÎÁö ¾Æ´ÑÁö¸¦ °áÁ¤ÇÑ´Ù. */ /* true->ÆíÁý°¡´É, false->ÆíÁýºÒ°¡´É */ leTest2->setEnabled(false); bttnTest = new QPushButton("È® ÀÎ", this); bttnTest->setGeometry(20, 100, 100, 30); /* ¹öÆ°(bttnTest)ÀÌ ´­·È(clicked())À» ¶§ testClick()ÇÔ¼ö¸¦ ½ÇÇàÇ϶ó */ QObject::connect(bttnTest, SIGNAL(clicked()), this, SLOT(testClick())); } clssTestLineEdit::~clssTestLineEdit() { } void clssTestLineEdit::testClick() { /* leTest1->text()´Â ÇöÀç leTest1 ÆíÁý¹Ú½º¾È¿¡ Ç¥½ÃµÇ¾îÀÖ´Â */ /* text¸¦ °¡Á®¿Â´Ù. */ emit printf("ÆíÁý¹Ú½º1ÀÇ ÅؽºÆ®´Â < %s >ÀÔ´Ï´Ù.\n", leTest1->text()); emit printf("ÆíÁý¹Ú½º2ÀÇ ÅؽºÆ®´Â < %s >ÀÔ´Ï´Ù.\n", leTest2->text()); } ------------------------------------------------------------------- QLineEdit class´Â À©µµ¿ìÁîÀÇ edit box¿Í °°Àº ±â´ÉÀ» ÇÏ´Â classÀÌ´Ù. Ư¼öÅ°(¿¹: ¹æÇâÅ°, insert, delete, home, endµî)µéÀ» ¾µ ¼ö ÀÖÀ¸¸ç X-window¿ÍÀÇ È£È¯µµ ÀÌ·ç¾îÁø´Ù. Áï ÆíÁý¹Ú½º¿¡ ÀÖ´Â ¹®ÀÚ¿­Àº ¸¶¿ì½º ·Î < copy and paste > ÇÒ ¼ö ÀÖ´Ù´Â À̾߱â´Ù. °¡Àå ÀÚÁÖ ¾²ÀÌ´Â Widget ÀÌ´Ï ²À ±â¾ïÇصÎÀÚ. -------------- < source 2.2.4.3 main_test3.cpp > --------------- #include #include "clssTestLineEdit.h" int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssTestLineEdit *clssTest = new clssTestLineEdit(); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } ------------------------------------------------------------------- ---------------------- < Makefile 2.2.4 > ---------------------- PROGS = main_test3 LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm CC = g++ GCC = gcc INCLUDE = -I/usr/lib/qt/include C_FLAG = -pipe -DNO_DEBUG -O2 CFLAGS = $(INCLUDE) $(C_FLAG) SYSCONF_LINK = $(CC) SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) MNU_OBJS = \ main_test3.o \ clssTestLineEdit_moc.o \ clssTestLineEdit.o all: $(PROGS) clean: rm -f *.o rm -f main_test3 rm -f *_moc.* ############# COMPILE ############# main_test3.o: main_test3.cpp $(CC) -c main_test3.cpp $(CFLAGS) -o $@ clssTestLineEdit_moc.cpp: clssTestLineEdit.h $(MOC) clssTestLineEdit.h -o clssTestLineEdit_moc.cpp clssTestLineEdit_moc.o: clssTestLineEdit_moc.cpp $(CC) -c clssTestLineEdit_moc.cpp $(CFLAGS) -o $@ clssTestLineEdit.o: clssTestLineEdit.cpp $(CC) -c clssTestLineEdit.cpp $(CFLAGS) -o $@ main_test3: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ ------------------------------------------------------------------- 2.2.4.1 QObject::connect, SIGNAL°ú SLOT /usr/lib/qt/include/qobject.h¿¡ ¼±¾ðµÇ¾îÀÖ´Â connectÇÔ¼ö¸¦ º¸ÀÚ. static bool connect( const QObject *sender, const char *signal, const QObject *receiver, const char *member ); bool connect( const QObject *sender, const char *signal, const char *member ) const; À§¿Í °°ÀÌ µÎ°¡Áö·Î ¼±¾ðµÇ¾îÀִµ¥ ¹Ø¿¡ ÀÖ´Â bool typeÀÇ ÇüÅ¿¡¼­ ºüÁ®ÀÖ´Â const QObject *receiver ´Â default·Î < this >·Î Á¤ÇØÁ®ÀÖ´Ù. Áï const char *member ´Â this class ÀÇ member¶ó¾ßÇÑ´Ù. ¸¶Âù°¡Áö·Î ù¹ø°ÀÇ static bool typeÀÇ ÇüÅ¿¡¼­´Â member°¡ < const QObject *receiver >ÀÇ memberÀ̾î¾ß ÇÑ´Ù. °¢ ÀÎÀÚµéÀ» º¸¸é ÀÌ ÇÔ¼ö°¡ ÇÏ´Â ±â´ÉÀÌ ¹«¾ùÀÎÁö ¾Ë ¼ö ÀÖ´Ù. const QObject *sender : signalÀ» º¸³»ÁÙ class °´Ã¼. const char *signal : '»ç¿ëÀÚ°¡ ÃëÇÑ Çൿ'ÀÌ´Ù. const QObject *receiver : signalÀ» ¹Þ¾Æ¼­ ó¸®ÇÒ class °´Ã¼. const char *member : º¸Åë receiver classÀÇ public member ÇÔ¼ö¸¦ ¾´´Ù. const char *signal¿¡ ´ëÇØ Á»´õ ÀÚ¼¼È÷ ¾Ë¾Æº¸ÀÚ. ¿¹Á¦ 2.2.4.2ÀÇ SourceÁß QObject::connect(bttnTest, SIGNAL(clicked()), this, SLOT(testClick())); ºÎºÐ¿¡¼­ º¸¸é const char *signal ºÎºÐÀ» SIGNAL(clicked())·Î Çسõ¾Ò´Ù. QPushButtonÀÇ header fileÀ» º¸¸é ´ÙÀ½°ú °°ÀÌ signal ÇÔ¼öµéÀÌ ¼±¾ðµÇ¾î ÀÖ´Â °ÍÀ» ¾Ë ¼ö ÀÖ´Ù. signals: void pressed(); void released(); void clicked(); void toggled( bool ); °¢°¢ÀÇ ÇÔ¼öµéÀº ÇÔ¼ö ÀÚüÀÇ À̸§¿¡ ÇØ´çµÇ´Â »ç¿ëÀÚÀÇ ÇൿÀÌ ÀϾÀ» ¶§ ºÎÇÕÇÏ´Â signalÀ» 'this'¶ó´Â class¿¡ ÀüÇØÁÖ°Ô µÈ´Ù. ¿©±â¼­ this´Â class clssTestLineEdit¸¦ ¸»Çϸç, µû¶ó¼­ connectÇÔ¼öÀÇ ¸¶Áö¸· ÀÎÀÚÀÎ const char *memberºÎºÐ¿¡´Â clssTestLineEditÀÇ memberÇÔ¼öÀÎ testClick ÇÔ¼ö°¡ ¿À°Ô µÈ °ÍÀÌ´Ù. < SLOT >ÀÌ ÇÏ´Â ÀÏÀº Â÷Â÷ À̾߱â ÇÏ°Ú´Ù. ¿ì¼± ±×³É ÀÌ·¸°Ô ¾´´Ù°í ¹®¹ý ó·³ »ý°¢À» ÇصÎÀÚ. member ÀÎÀںκÐÀº ¸¸¾à member ÇÔ¼ö¸¦ ¾µ °æ¿ì ¹Ýµå ½Ã SLOT¾È¿¡ member¸¦ µÎ¾î¾ßÇÏ¸ç ¶ÇÇÑ ÀÌ member ÇÔ¼ö´Â public slots: ȤÀº private slots: ¿¡ ¼±¾ðµÇ¾îÀÖ¾î¾ß ÇÑ´Ù. 2.2.5. ÄÞº¸¹Ú½º(QComboBox) -------------- < source 2.2.5.1 clssTestComboBox.h > --------------- #include class QComboBox; class QPushButton; class clssTestComboBox : public QWidget { Q_OBJECT public: clssTestComboBox(); ~clssTestComboBox(); public slots: void testClick(); protected: private: QComboBox *cbTest; /* ÄÞº¸¹Ú½º¿¡ ´ëÇÑ class */ QPushButton *bttnTest; }; ------------------------------------------------------------------- -------------- < source 2.2.5.2 clssTestComboBox.cpp > --------------- #include #include #include #include "clssTestComboBox.h" clssTestComboBox::clssTestComboBox() { cbTest = new QComboBox(this); cbTest->setGeometry(20, 20, 100, 30); /* ComboBox¿¡ itemµéÀ» ³Ö´Â´Ù. */ cbTest->insertItem("ù¹ø°", 0); cbTest->insertItem("µÎ¹ø°", 1); cbTest->insertItem("¼¼¹ø°", 2); cbTest->insertItem("³×¹ø°", 3); cbTest->setCurrentItem(0); bttnTest = new QPushButton("È® ÀÎ", this); bttnTest->setGeometry(20, 100, 100, 30); QObject::connect(bttnTest, SIGNAL(clicked()), this, SLOT(testClick())); } clssTestComboBox::~clssTestComboBox() { } void clssTestComboBox::testClick() { /* cbTest->currentText()´Â ÇöÀç ComboBox¿¡¼­ º¸ÀÌ´Â */ /* text¸¦ returnÇÑ´Ù. */ emit printf("ÄÞº¸¹Ú½º1ÀÇ ÅؽºÆ®´Â < %s >ÀÔ´Ï´Ù.\n", cbTest->currentText()); } ------------------------------------------------------------------- Ʋ¸°ºÎºÐÀÌ °ÅÀÇ ¾øÀ¸¹Ç·Î QComboBox¿¡ ´ëÇؼ­¸¸ ¼³¸íÇÏ°Ú´Ù. /usr/lib/qt/include/qcombobox.h¸¦ ¿­¾îº¸ÀÚ.(ÁÖÀÇ: ¸¸¾à ´ç½ÅÀÌ Qt¸¦ ´Ù¿î¹Þ¾Æ ´Ù¸¥ °÷¿¡ ÀνºÅç ½ÃÄ×´Ù¸é path°¡ Ʋ·ÁÁú °ÍÀÓ.) public: QComboBox( QWidget *parent=0, const char *name=0 ); QComboBox( bool rw, QWidget *parent=0, const char *name=0 ); ¸î¸î ƯÁ¤ widgetµéÀ» Á¦¿ÜÇÏ°í´Â °ÅÀÇ ÀÎÀÚ°¡ ºñ½ÁÇÏ´Ù. ÀÎÀڵ鿡 °ü ÇÑ ¼³¸íÀº ¾Õ¼­ À̾߱âÇß´ø ºÎºÐµé°ú °°À¸¹Ç·Î ¼³¸íÀ» »ý·«ÇÏ°Ú´Ù. ±×·¯¸é À̹ø¿¡´Â < cbTest->insertItem("ù¹ø°", 0); >ºÎºÐÀ» º¸ÀÚ. header file¿¡´Â insertItemÇÔ¼ö°¡ ´ÙÀ½°ú °°ÀÌ ¼±¾ðµÇ¾îÀÖ´Ù. ÀÌ ÇÔ¼ö´Â ÄÞº¸¹Ú½º¿¡ itemÀ» Ãß°¡ÇÒ ¶§ »ç¿ëÇÏ´Â ÇÔ¼öÀÌ´Ù. void insertItem( const char *text, int index=-1 ); void insertItem( const QPixmap &pixmap, int index=-1 ); ù¹ø° ¼±¾ð¹®À» º¸ÀÚ. const char *text´Â ÄÞº¸¹Ú½º¿¡ Ãß°¡½Ãų textÀÌ°í int index´Â ±× text ÀÇ ¼ø¹øÀÌ´Ù. index´Â 0¹øºÎÅÍ ½ÃÀÛÇÑ´Ù. -1·Î ÃʱâÈ­µÇ¾îÀÖ´Ù´Â °ÍÀº ÄÞº¸¹Ú½º¿¡ ¾Æ¹« itemµµ µé¾îÀÖÁö ¾Ê´Ù´Â ¶æÀÌ´Ù. CompileÇؼ­ ½ÇÇà½ÃÄÑ º¸±â ¹Ù¶õ´Ù. Á»´õ È®½ÇÇÏ°Ô ÀÌÇØ°¡ µÉ °ÍÀÌ´Ù. ´ÙÀ½À¸·Î cbTest->currentText()ºÎºÐÀ» º¸ÀÚ. header fileÀÇ ¼±¾ðÀ» º¸¸é ´ÙÀ½°ú °°´Ù. const char *currentText() const; ÀÌ ÇÔ¼ö´Â ÇöÀç ÄÞº¸¹Ú½º¿¡ ³ªÅ¸³ªÀÖ´Â text¸¦ returnÇÑ´Ù. ÄÞº¸¹Ú½ºÀÇ ÇöÀç text¸¦ settingÇÏ´Â ÇÔ¼ö´Â void setCurrentItem( int index ); ÀÌ´Ù. ¿©±â¼­ÀÇ indexÀÇ Àǹ̴ insertItemÀÇ indexÀÇ ÀÇ¹Ì¿Í µ¿ÀÏÇÏ´Ù. < cbTest->setCurrentItem(0); >ÀÌ ¶æÇÏ´Â °ÍÀº ù¹ø° itemÀ» ÇöÀç text ·Î º¸¿©ÁÖ°Ú´Ù´Â À̾߱â´Ù. -------------- < source 2.2.5.3 main_test4.cpp > --------------- #include #include "clssTestComboBox.h" int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssTestComboBox *clssTest = new clssTestComboBox(); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } ------------------------------------------------------------------- ---------------------- < Makefile 2.2.5 > ---------------------- PROGS = main_test4 LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm CC = g++ GCC = gcc INCLUDE = -I/usr/lib/qt/include C_FLAG = -pipe -DNO_DEBUG -O2 CFLAGS = $(INCLUDE) $(C_FLAG) SYSCONF_LINK = $(CC) SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) MNU_OBJS = \ main_test4.o \ clssTestComboBox_moc.o \ clssTestComboBox.o all: $(PROGS) clean: rm -f *.o rm -f main_test4 rm -f *_moc.* ############# COMPILE ############# main_test4.o: main_test4.cpp $(CC) -c main_test4.cpp $(CFLAGS) -o $@ clssTestComboBox_moc.cpp: clssTestComboBox.h $(MOC) clssTestComboBox.h -o clssTestComboBox_moc.cpp clssTestComboBox_moc.o: clssTestComboBox_moc.cpp $(CC) -c clssTestComboBox_moc.cpp $(CFLAGS) -o $@ clssTestComboBox.o: clssTestComboBox.cpp $(CC) -c clssTestComboBox.cpp $(CFLAGS) -o $@ main_test4: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ ------------------------------------------------------------------- 2.2.6. ¸®½ºÆ®(QListView) -------------- < source 2.2.6.1 clssTestListView.h > --------------- #include class QListView; class QListViewItem; class QLabel; class QFrame; class clssTestListView : public QWidget { Q_OBJECT public: clssTestListView(); ~clssTestListView(); public slots: void appearItem(); protected: private: QFrame *frTest; QListView *lvTest; QListViewItem *lviTest[10]; QLabel *lblTest1; QLabel *lblTest2; QLabel *lblTest3; }; ------------------------------------------------------------------- -------------- < source 2.2.6.2 clssTestListView.cpp > --------------- #include #include #include #include #include "clssTestListView.h" clssTestListView::clssTestListView() { int i; char szTest1[50], szTest2[50], szTest3[50]; /* ListÀÇ °¡ÀåÀÚ¸®¼±ÀÇ Ã³¸®¸¦ À§ÇØ frameÀ» ±×¸°´Ù. */ frTest = new QFrame(this); frTest->setGeometry(20, 20, 200, 200); frTest->setFrameStyle(QFrame::Box | QFrame::Sunken | QFrame::WinPanel); lvTest = new QListView(frTest); /* frame¿¡¼­ ¾à 3Á¤µµ »ç¹æÀ¸·Î ÀûÀº Å©±â°¡ °¡Àå Àû´çÇÏ´Ù. */ lvTest->setGeometry(3, 3, 194, 194); /* °¢ fieldÀÇ titleÀ» Á¤ÇÑ´Ù. */ lvTest->addColumn(" ù¹ø° "); lvTest->addColumn(" µÎ¹ø° "); lvTest->addColumn(" ¼¼¹ø° "); /* treeÀå½ÄÀ» ÇÒ °ÍÀÎÁö ¾Æ´ÑÁö¸¦ °áÁ¤ÇÑ´Ù. */ lvTest->setRootIsDecorated(true); for (i = 0; i < 9; i++) { memset(szTest1, '\0', 50); memset(szTest2, '\0', 50); memset(szTest3, '\0', 50); sprintf(szTest1, "ȯ¿µ %d", i); sprintf(szTest2, "¸®´ª½º %d", i); sprintf(szTest3, "¸¸¼¼ %d", i); /* ù¹ø° µÎ¹ø° ¼¼¹ø°*/ lviTest[i] = new QListViewItem(lvTest, szTest1, szTest2, szTest3); } /* List(lvTest)¿¡¼­ item(lviTest[])ÀÌ ¼±ÅÃ(selectionChanged()) */ /* µÇ¾îÁú ¶§ this class(clssTestListView)ÀÇ member function */ /* (appearItem())À» ¼öÇàÇضó. */ QObject::connect(lvTest, SIGNAL(selectionChanged()), this, SLOT(appearItem())); lblTest1 = new QLabel(this); lblTest1->setGeometry(20, 230, 150, 20); lblTest2 = new QLabel(this); lblTest2->setGeometry(20, 260, 150, 20); lblTest3 = new QLabel(this); lblTest3->setGeometry(20, 290, 150, 20); } clssTestListView::~clssTestListView() { } void clssTestListView::appearItem() { /* ¼±ÅÃµÈ itemÀÇ Ã¹¹ø° field¸¦ Label·Î ³ªÅ¸³¿ */ lblTest1->setText(lvTest->currentItem()->text(0)); /* ¼±ÅÃµÈ itemÀÇ µÎ¹ø° field¸¦ Label·Î ³ªÅ¸³¿ */ lblTest2->setText(lvTest->currentItem()->text(1)); /* ¼±ÅÃµÈ itemÀÇ ¼¼¹ø° field¸¦ Label·Î ³ªÅ¸³¿ */ lblTest3->setText(lvTest->currentItem()->text(2)); } ------------------------------------------------------------------- /usr/lib/qt/include/qlistview.h fileÀÇ ¼±¾ðÀ» º¸ÀÚ. public: QListView( QWidget * parent = 0, const char * name = 0 ); ´Ù¸¥ widgetµé°ú º° Â÷ÀÌ°¡ ¾øÀ¸¹Ç·Î ¼³¸íÀº »ý·«ÇÑ´Ù. virtual int addColumn( const char * label, int size = -1); fieldÀÇ Á¦¸ñ(const char *label)À» ÁöÁ¤ÇÑ´Ù. size¿¡ ´ëÇؼ­´Â °ªÁ¤ÀÇ°¡ µÇ¾îÀÖÀ¸¹Ç·Î ½áµµ ±×¸¸ ¾È½áµµ ±×¸¸À̶ó´Â À̾߱âÀε¥ ÈçÈ÷ fieldÀÇ size¸¦ ÀÓÀÇ·Î Á¤Çؼ­ ÇØ´ç fieldÀÇ °ªÀ» 㠾Ƴ»´Âµ¥ ¾²ÀÌ´Â ÀÎÀÚÀÌ´Ù. ´Ù½Ã À̾߱âÇÒ ±âȸ°¡ ÀÖÀ» Áö´Â ¸ð¸£°ÚÁö ¸¸ ±×·¸°Ô Áß¿äÇÑ ÀÎÀÚ´Â ¾Æ´Ï¹Ç·Î ¼³¸íÀº ÀÌÂë ÇØ µÎ°Ú´Ù. virtual void setRootIsDecorated( bool ); ¸¸¾à ÀÎÀÚ°ªÀ» false·Î Áشٸé ù¹ø° fieldÀÇ itemµé ¾Õ¿¡´Â ¾Æ¹«°Í µµ ¾ø°Ô µÈ´Ù. ÇöÀç treeÀå½ÄÀÌ µÇ¾îÀÖ´ÂÁö ¾Æ´ÑÁö¸¦ °Ë»çÇÏ°í ½Í´Ù¸é ´ÙÀ½ ÇÔ¼ö¸¦ ½á¶ó. bool rootIsDecorated() const; À̹ø¿¡´Â ½ÇÁ¦ itemÀ» List¿¡ »ðÀÔÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ ¾Ë¾Æº¸ÀÚ. header file¿¡´Â ´ÙÀ½°ú °°ÀÌ QListViewItemÀ» ¼±¾ðÇÏ°í ÀÖ´Ù. public: QListViewItem( QListView * parent ); QListViewItem( QListViewItem * parent ); QListViewItem( QListView * parent, QListViewItem * after ); QListViewItem( QListViewItem * parent, QListViewItem * after ); QListViewItem( QListView * parent, const char *, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0 ); QListViewItem( QListViewItem * parent, const char *, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0 ); QListViewItem( QListView * parent, QListViewItem * after, const char *, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0 ); QListViewItem( QListViewItem * parent, QListViewItem * after, const char *, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0, const char * = 0 ); ¾à°£ º¹ÀâÇÏ´Ù°í »ý°¢ÇÒ Áöµµ ¸ð¸£Áö¸¸ »ó´çÈ÷ °£´ÜÇÑ ¼±¾ðÀÌ´Ù. ¿ì¼± parentÀÎÀÚºÎÅÍ »ìÆ캸ÀÚ. À§¿¡¼­ ¼±¾ðµÈ parentÀÎÀÚÀÇ typeÀº < QListView * > ¿Í < QListViewItem * > ÀÌ µÎ°¡ÁöÀÌ´Ù. < QListView * >¸¦ parentÀÎÀÚ·Î ¹Þ´Â´Ù´Â °ÍÀº ÇöÀç »ý¼ºµÇ¾îÀÖ´Â List ¿¡ < const char * > ÇüÅÂÀÇ text¸¦ itemÀ¸·Î »ðÀÔÇÑ´Ù´Â ¶æÀÌ´Ù. < QListViewItem * >¸¦ parentÀÎÀÚ·Î ¹Þ´Â´Ù´Â °ÍÀº ListÀÇ Æ¯Á¤ item(parent) À» root·Î ÇÏ´Â tree±¸Á¶·Î¼­ ±× itemÀÇ ÀÚ½Ä node¸¦ »ðÀÔÇÑ´Ù´Â ¶æÀÌ´Ù. ¾ð¶æ ÀÌÇØ°¡ °¡Áö ¾ÊÀ» °ÍÀÌ´Ù. À§ source¿¡¼­ < lviTest[i] = new QListViewItem(lvTest, szTest1, szTest2, szTest3); > ÀÌ Æ÷ÇԵǾîÀÖ´Â for loop¹®À» ´ÙÀ½°ú °°ÀÌ ¹Ù²Û ÈÄ CompileÇÏ¿© ½ÇÇà½ÃÄÑ º¸¶ó. lviTest[0] = new QListViewItem(lvTest, "Å×½ºÆ®1-1", "Å×½ºÆ®1-2", "Å×½ºÆ®1-3"); lviTest[1] = new QListViewItem(lviTest[0], "Å×½ºÆ®2-1", "Å×½ºÆ®2-2", "Å×½ºÆ®2-3"); ½ÇÇà½ÃÄѺ¸¸é À§¿¡¼­ ÇÊÀÚ°¡ À̾߱âÇß´ø ºÎºÐµéÀÌ ½±°Ô ÀÌÇØ°¡ °¥ °ÍÀÌ´Ù. ´ÙÀ½Àº List¿¡¼­ »ðÀÔµÈ text¸¦ ¾ò´Â ¹æ¹ý¿¡ ´ëÇÑ ¼³¸íÀÌ´Ù. lblTest1->setText(lvTest->currentItem()->text(0)); QListViewItemÀÇ text¸¦ ¾ò´Â ¹æ¹ýÀº °£´ÜÇÏ´Ù. ¸¸¾à QListViewItem typeÀÇ class°¡ lviTest1À̶ó¸é, lviTest1ÀÇ Ã¹¹ø° fieldÀÇ text¸¦ ¾òÀ¸·Á¸é < lviTest1->text(0); >À̶ó°í ÇÏ¸é µÉ °ÍÀÌ´Ù. ComboBox¿Í ºñ½ÁÇÏÁö¸¸ index°¡ ÀǹÌÇÏ´Â °ÍÀÌ Æ²¸®¹Ç·Î À¯ÀÇÇϱ⠹ٶõ´Ù. À§¿¡¼­ lvTest->currentItem()ÀÌ ÀǹÌÇÏ´Â °ÍÀº ÇöÀç List¿¡¼­ ¼±ÅÃµÈ Item setÀ» ¸»ÇÑ´Ù. header file¿¡´Â currentItem()ÇÔ¼ö°¡ ´ÙÀ½°ú °°ÀÌ ¼±¾ðµÇ¾î ÀÖ´Ù. QListViewItem * currentItem() const; typeÀ» º¸¸é QListViewItemÀÌ´Ù. ÀÌ´Â currentItem()ÀÌ QListViewItem classÀÇ ¸ðµç memberµéÀ» ÂüÁ¶ÇÒ ¼ö ÀÖ´Ù´Â À̾߱Ⱑ µÈ´Ù. µû¶ó¼­ ÇöÀç List¿¡¼­ ¼±ÅÃµÈ ItemÀÇ µÎ¹ø° fieldÀÇ text¸¦ ¾Ë°í ½Í´Ù¸é ´ÙÀ½°ú °°ÀÌ ÇÏ¸é µÈ´Ù. lblTest1->setText(lvTest->currentItem()->text(1)); À̹ø¿£ QListView¿¡¼­ ¹ß»ý°¡´ÉÇÑ Signal¿¡ ´ëÇØ ¾Ë¾Æº¸µµ·Ï ÇÏÀÚ. header fileÀ» º¸¸é ´ÙÀ½°ú °°ÀÌ ÃÑ 6°³ÀÇ signalÇÔ¼ö°¡ ÀÖ´Ù. signals: void selectionChanged(); void selectionChanged( QListViewItem * ); void currentChanged( QListViewItem * ); void doubleClicked( QListViewItem * ); void returnPressed( QListViewItem * ); void rightButtonClicked( QListViewItem *, const QPoint&, int ); void rightButtonPressed( QListViewItem *, const QPoint&, int ); °¢ SignalµéÀÇ ¹ß»ý¿äÀÎÀº À§ÇÔ¼öÀÇ Á¦¸ñ°ú µ¿ÀÏÇÏ´Ù. -------------- < source 2.2.6.3 main_test5.cpp > --------------- #include #include "clssTestListView.h" int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssTestListView *clssTest = new clssTestListView(); clssTest->setGeometry(100, 100, 500, 350); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } ------------------------------------------------------------------- ---------------------- < Makefile 2.2.6 > ---------------------- PROGS = main_test5 LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm CC = g++ GCC = gcc INCLUDE = -I/usr/lib/qt/include C_FLAG = -pipe -DNO_DEBUG -O2 CFLAGS = $(INCLUDE) $(C_FLAG) SYSCONF_LINK = $(CC) SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) MNU_OBJS = \ main_test5.o \ clssTestListView_moc.o \ clssTestListView.o all: $(PROGS) clean: rm -f *.o rm -f main_test5 rm -f *_moc.* ############# COMPILE ############# main_test5.o: main_test5.cpp $(CC) -c main_test5.cpp $(CFLAGS) -o $@ clssTestListView_moc.cpp: clssTestListView.h $(MOC) clssTestListView.h -o clssTestListView_moc.cpp clssTestListView_moc.o: clssTestListView_moc.cpp $(CC) -c clssTestListView_moc.cpp $(CFLAGS) -o $@ clssTestListView.o: clssTestListView.cpp $(CC) -c clssTestListView.cpp $(CFLAGS) -o $@ main_test5: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ ------------------------------------------------------------------- 2.2.7. üũ¹Ú½º(QCheckBox), ¶óµð¿À¹öÆ°(QRadioButton) -------------- < source 2.2.7.1 clssTestButton.h > --------------- #include class QButtonGroup; class QRadioButton; class QCheckBox; class QPushButton; class clssTestButton : public QWidget { Q_OBJECT public: clssTestButton(); ~clssTestButton(); public slots: void procButton(); protected: private: /* QRadioButtonÀ» ¹­±â À§ÇÑ Group class ¼±¾ð */ QButtonGroup *bgTest; QRadioButton *rbTest1; QRadioButton *rbTest2; QCheckBox *chkbTest1; QCheckBox *chkbTest2; QPushButton *bttnTest; }; ------------------------------------------------------------------- -------------- < source 2.2.7.2 clssTestButton.cpp > --------------- #include #include #include #include #include #include "clssTestButton.h" clssTestButton::clssTestButton() { /* radio buttonÀº ¾î´À ÇÑ ¹öÆ°ÀÌ È°¼ºÈ­µÇ¸é ´Ù¸¥ ¹öÆ°µéÀº */ /* ºñÈ°¼ºÈ­µÇ¾î¾ß ÇÑ´Ù. ÀÌ·± ±â´ÉÀ» À§ÇØ QButtonGroup class */ /* ¸¦ Á¤ÀÇÇÑ´Ù. */ bgTest = new QButtonGroup(this); bgTest->setGeometry(20, 20, 300, 100); /* radio buttonµéÀ» bgTest¿¡ Á¾¼Ó½ÃŲ´Ù. */ rbTest1 = new QRadioButton("¸®´ª½º ¶óµð¿À", bgTest); rbTest1->setGeometry(20, 20, 100, 20); rbTest2 = new QRadioButton("¸¸¼¼ ¶óµð¿À", bgTest); rbTest2->setGeometry(150, 20, 100, 20); /* radio buttonµéÀÌ ´ÜÁö ÇϳªÀÇ ¹öÆ°¸¸ÀÌ ¼±ÅÃµÇ°Ô Çϱâ À§ÇØ */ /* ¸¶Áö¸·À¸·Î QButtonGroup classº¯¼ö¿¡ »ðÀÔ½ÃŲ´Ù. */ bgTest->insert(rbTest1, 0); bgTest->insert(rbTest2, 1); /* üũ¹Ú½º Á¤ÀÇ */ chkbTest1 = new QCheckBox("¸®´ª½º üũ", this); chkbTest1->setGeometry(20, 160, 100, 20); chkbTest2 = new QCheckBox("¸¸¼¼ üũ", this); chkbTest2->setGeometry(150, 160, 100, 20); bttnTest = new QPushButton("È® ÀÎ", this); bttnTest->setGeometry(60, 250, 100, 30); QObject::connect(bttnTest, SIGNAL(clicked()), this, SLOT(procButton())); } clssTestButton::~clssTestButton() { } void clssTestButton::procButton() { if (rbTest1->isChecked()) emit printf("¸®´ª½º ¶óµð¿À ¹öÆ°ÀÌ Ã¼Å©µÇ¾î ÀÖ½À´Ï´Ù.\n"); else if (rbTest2->isChecked()) emit printf("¸¸¼¼ ¶óµð¿À ¹öÆ°ÀÌ Ã¼Å©µÇ¾î ÀÖ½À´Ï´Ù.\n"); else emit printf("üũµÇ¾îÀÖ´Â ¶óµð¿À ¹öÆ°ÀÌ ¾ø½À´Ï´Ù.\n"); if (chkbTest1->isChecked()) emit printf("¸®´ª½º üũ ¹Ú½º°¡ üũµÇ¾î ÀÖ½À´Ï´Ù.\n"); if (chkbTest2->isChecked()) emit printf("¸¸¼¼ üũ ¹Ú½º°¡ üũµÇ¾î ÀÖ½À´Ï´Ù.\n"); if (chkbTest1->isChecked() == false && chkbTest2->isChecked() == false) emit printf("üũµÇ¾îÀִ üũ¹Ú½º°¡ ¾ø½À´Ï´Ù.\n"); } ------------------------------------------------------------------- QButtonGroupºÎÅÍ º¸µµ·ÏÇÏÀÚ. /usr/lib/qt/include/qbuttongroup.h¿¡´Â ´ÙÀ½°ú °°ÀÌ ¼±¾ðµÇ¾îÀÖ´Ù. public: QButtonGroup( QWidget *parent=0, const char *name=0 ); QButtonGroup( const char *title, QWidget *parent=0, const char *name=0 ); ÀÎÀڵ鿡 ´ëÇÑ ¼³¸íÀº º°·Î ÇÊ¿ä¾øÀ¸¸®¶ó »ý°¢ÇϹǷΠ»ý·«ÇÏ°Ú´Ù. »ý¼ºÀںκк¸´Ù´Â insertÇÏ´Â ºÎºÐÀÇ ¼³¸íÀÌ ÇÊ¿äÇϸ®¶ó »ý°¢ÇÑ´Ù. int insert( QButton *, int id=-1 ); int id ´Â group¿¡ Æ÷ÇԵǴ ¹öÆ°µéÀÇ id¸¦ ÁöÁ¤ÇØÁÖ´Â ¿ªÇÒÀ» ÇÑ´Ù. ¼ø¼­¿¡´Â »ó°ü ¾øÀ¸³ª °ªÀº °íÀ¯°ªÀ» °¡Á®¾ß ÇÑ´Ù. ´ÙÀ½À¸·Î checkboxÀÇ header file /usr/lib/qt/include/qradiobutton.h ¿¡ ³ªÅ¸³­ »ý¼ºÀںκÐÀ» º¸µµ·Ï ÇÏÀÚ. public: QRadioButton( QWidget *parent=0, const char *name=0 ); QRadioButton( const char *text, QWidget *parent=0, const char *name=0 ); QRadioButtonÀÇ < const char *text > ÀÎÀÚ¿¡ ¹®ÀÚ¿­À» ³Ñ°ÜÁÖ¸é ±× ¹®ÀÚ¿­ÀÌ ÀÌ radiobuttonÀÇ titleÀÌ µÈ´Ù. üũ°¡ µÇ¾îÀÖ´ÂÁö¸¦ °Ë»çÇÏ´Â ÇÔ¼ö´Â isChecked()ÀÌ´Ù. ÀÎÀ§ÀûÀ¸·Î checkingÇÏ´Â ÇÔ¼ö´Â header file¿¡ ÀÌ·¸°Ô ¼± ¾ðµÇ¾îÀÖ´Ù. void setChecked( bool check ); isChecked(), setChecked(bool check) µÎ ÇÔ¼ö ¸ðµÎ QRadioButton°ú QCheckBox¿¡ ¶È°°ÀÌ ¼±¾ðµÇ¾îÀÖ°í ¶ÇÇÑ ±â´Éµµ °°´Ù. -------------- < source 2.2.7.3 main_test6.cpp > --------------- #include #include "clssTestButton.h" int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssTestButton *clssTest = new clssTestButton(); clssTest->setGeometry(100, 100, 500, 350); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } ------------------------------------------------------------------- ---------------------- < Makefile 2.2.7 > ---------------------- PROGS = main_test6 LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm CC = g++ GCC = gcc INCLUDE = -I/usr/lib/qt/include C_FLAG = -pipe -DNO_DEBUG -O2 CFLAGS = $(INCLUDE) $(C_FLAG) SYSCONF_LINK = $(CC) SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) MNU_OBJS = \ main_test6.o \ clssTestButton_moc.o \ clssTestButton.o all: $(PROGS) clean: rm -f *.o rm -f main_test6 rm -f *_moc.* ############# COMPILE ############# main_test6.o: main_test6.cpp $(CC) -c main_test6.cpp $(CFLAGS) -o $@ clssTestButton_moc.cpp: clssTestButton.h $(MOC) clssTestButton.h -o clssTestButton_moc.cpp clssTestButton_moc.o: clssTestButton_moc.cpp $(CC) -c clssTestButton_moc.cpp $(CFLAGS) -o $@ clssTestButton.o: clssTestButton.cpp $(CC) -c clssTestButton.cpp $(CFLAGS) -o $@ main_test6: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ ------------------------------------------------------------------- 2.2.8. ¸Þ´º(QMenu) -------------- < source 2.2.8.1 clssTestMenu.h > --------------- #include class QMenuBar; class QPopupMenu; class clssTestMenu : public QWidget { Q_OBJECT public: clssTestMenu(); ~clssTestMenu(); public slots: void funcTest1(); void funcTest2(); void funcTest3(); void funcTest4(); void funcTest5(); void funcTest6(); protected: private: /* Pulldown ¸Þ´º¸¦ À§ÇÑ ¸Þ´º¹Ù */ QMenuBar *mnuMainBar; /* Popup ¸Þ´º¸¦ À§ÇÑ ¸Þ´º */ QPopupMenu *mnuTest1; QPopupMenu *mnuTest2; QPopupMenu *mnuTest3; }; ------------------------------------------------------------------- -------------- < source 2.2.8.2 clssTestMenu.cpp > --------------- #include /* hot key¸¦ À§ÇÑ header. ¿©±â¼­´Â hot key¸¦ ¾²Áö ¾Ê´Â´Ù. */ /* ÇÑ ¹ø ½ÃÇè»ï¾Æ hot key±â´É±îÁö ³Ö¾îº¸±â ¹Ù¶õ´Ù. */ #include /* QMenuBar¸¦ À§ÇÑ header */ #include /* QPopupMenu¸¦ À§ÇÑ header */ #include #include #include "clssTestMenu.h" clssTestMenu::clssTestMenu() { /* ÀüüÀûÀÎ windowÀÇ ÇüŸ¦ Microsoft WindowsÀÇ ÇüÅ·Π¸ÂÃá´Ù. */ qApp->setStyle(WindowsStyle); mnuTest1 = new QPopupMenu; /* Popup menu¿¡ ¾ÆÀÌÅÛÀ» ³Ö´Â´Ù. */ mnuTest1->insertItem("Å×½ºÆ®1¸Þ´ºÀÇ ¼­ºê¸Þ´º1", this, SLOT(funcTest1())); mnuTest1->insertItem("Å×½ºÆ®1¸Þ´ºÀÇ ¼­ºê¸Þ´º2", this, SLOT(funcTest2())); mnuTest1->insertItem("Å×½ºÆ®1¸Þ´ºÀÇ ¼­ºê¸Þ´º3", this, SLOT(funcTest3())); mnuTest2 = new QPopupMenu; mnuTest2->insertItem("Å×½ºÆ®2¸Þ´ºÀÇ ¼­ºê¸Þ´º1", this, SLOT(funcTest4())); mnuTest2->insertItem("Å×½ºÆ®2¸Þ´ºÀÇ ¼­ºê¸Þ´º2", this, SLOT(funcTest5())); mnuTest3 = new QPopupMenu; mnuTest3->insertItem("Å×½ºÆ®3¸Þ´ºÀÇ ¼­ºê¸Þ´º1", this, SLOT(funcTest6())); /* °¢ popup menuµéÀ» pulldown menu¿¡ »ðÀÔ½ÃŲ´Ù. */ mnuMainBar = new QMenuBar(this); mnuMainBar->insertItem(" Å×½ºÆ®1 ", mnuTest1); mnuMainBar->insertItem(" Å×½ºÆ®2 ", mnuTest2); mnuMainBar->insertItem(" Å×½ºÆ®3 ", mnuTest3); } clssTestMenu::~clssTestMenu() { } void clssTestMenu::funcTest1() { emit printf("test1 ¸Þ´º\n"); } void clssTestMenu::funcTest2() { emit printf("test2 ¸Þ´º\n"); } void clssTestMenu::funcTest3() { emit printf("test3 ¸Þ´º\n"); } void clssTestMenu::funcTest4() { emit printf("test4 ¸Þ´º\n"); } void clssTestMenu::funcTest5() { emit printf("test5 ¸Þ´º\n"); } void clssTestMenu::funcTest6() { emit printf("test6 ¸Þ´º\n"); } ------------------------------------------------------------------- À§ÀÇ °á°úÄ¡¸¦ ¹Ì¸® ³ªÅ¸³»ÀÚ¸é ´ÙÀ½°ú °°´Ù. --------------------------------------------------------- | Å×½ºÆ®1 | Å×½ºÆ®2 | Å×½ºÆ®3 | |---------------------------------------------------------| || Å×½ºÆ®1¸Þ´ºÀÇ ¼­ºê¸Þ´º1 | | || Å×½ºÆ®1¸Þ´ºÀÇ ¼­ºê¸Þ´º2 | | || Å×½ºÆ®1¸Þ´ºÀÇ ¼­ºê¸Þ´º3 | | | ------------------------- | | | | | | -------------------------- | ---------------- --------------- ¹¹ ±×·¸°Ô Ưº°ÇÑ ³»¿ëÀº ¾ø´Ù. Çѹø¸¸ ÈȾ¸é ±Ý¹æ ÀÌÇØ°¡ °¥ °ÍÀÌ´Ù. /usr/lib/qt/include/qpopupmenu.h¸¦ »ìÆ캸ÀÚ. public: QPopupMenu( QWidget *parent=0, const char *name=0 ); º°·Î ¼³¸íÇÒ ÇÊ¿ä´Â ¾øÀ¸¸®¶ó »ý°¢ÇÑ´Ù. Áß¿äÇÑ °ÍÀº insertItemÇÔ¼öÀε¥ header fileÀ» ã¾Æº¸¸é ¾Ë°ÚÁö¸¸ ÀÌ ÇÔ¼ö°¡ member·Î ¼±¾ðµÇ¾îÀÖÁö ¾ÊÀ» °ÍÀÌ´Ù. ±×·¯¸é ¾îµð¿¡ ¼±¾ðÀÌ µÇ¾î ÀÖÀ»±î? QPopupMenu classÀÇ ¼±¾ðºÎ¸¦ º¸ÀÚ. class Q_EXPORT QPopupMenu : public QTableView, public QMenuData ¿©±â¼­ º¸¸é QPopupMenu class´Â QMenuData class·ÎºÎÅÍ »ó¼ÓÀ» ¹Þ¾Ò´Ù. Áï, QMenuData classÀÇ public memberµéÀ» ¸ðµÎ QPopupMenuµµ Á¢±ÙÇÒ ¼ö ÀÖ´Ù´Â À̾߱â´Ù. ±×·¯¸é ´Ù½Ã /usr/lib/qt/include/pmenudata.h¸¦ ¿­¾î º¸ÀÚ. insertItemÇÔ¼ö¿¡ ´ëÇÑ ¼±¾ðÀÌ ´ÙÀ½°ú °°ÀÌ ¿©·¯°³°¡ ¼±¾ðµÇ¾îÀÖ´Ù. int insertItem( const char *text, const QObject *receiver, const char *member, int accel=0 ); int insertItem( const QPixmap &pixmap, const QObject *receiver, const char *member, int accel=0 ); int insertItem( const QPixmap &pixmap, const char *text, const QObject *receiver, const char *member, int accel=0 ); int insertItem( const char *text, const QObject *receiver, const char *member, int accel, int id, int index = -1 ); int insertItem( const QPixmap &pixmap, const QObject *receiver, const char *member, int accel, int id, int index = -1 ); int insertItem( const QPixmap &pixmap, const char *text, const QObject *receiver, const char *member, int accel, int id, int index = -1 ); int insertItem( const char *text, int id=-1, int index=-1 ); int insertItem( const char *text, QPopupMenu *popup, int id=-1, int index=-1 ); int insertItem( const QPixmap &pixmap, int id=-1, int index=-1 ); int insertItem( const QPixmap &pixmap, QPopupMenu *popup, int id=-1, int index=-1 ); int insertItem( const QPixmap &pixmap, const char *text, int id=-1, int index=-1 ); int insertItem( const QPixmap &pixmap, const char *text, QPopupMenu *popup, int id=-1, int index=-1 ); ÀÌÁ¦´Â ¹Øµµ³¡µµ ¾øÀÌ insertItemÀ̶ó´Â ÇÔ¼ö°¡ ¾îµð¼­ Æ¢¾î³ª¿Ô´ÂÁö ÀÌ ÇØ°¡ µÉ °ÍÀÌ´Ù. ¾ÕÀ¸·Îµµ member functionÀÌ ÀÌ·± ½ÄÀ¸·Î È£ÃâµÇ´Â °æ¿ì °¡ °¡²û¾¿ ÀÖÀ» °ÍÀÌ´Ù. ´çȲÇÏÁö ¸»°í Â÷±ÙÂ÷±Ù ÀÌÇØÇϱ⠹ٶõ´Ù. insertItem ÇÔ¼ö¿¡ ´ëÇÑ ¼³¸íÀ» ÇÏÀÚ. ¹Ù·Î À§¿¡ ÀÖ´Â ¸ðµç °æ¿ì¸¦ ´Ù ¼³ ¸íÇÒ ÇÊ¿ä´Â ¾øÀ» °Í °°´Ù. source 2.2.8.2¿¡¼­ ¾²ÀÎ insertItemÇÔ¼ö¿¡ ´ëÇÑ ¼³¸í¸¸À» ÇÏ°Ú´Ù. ±× source¿¡¼­ ¾²ÀÎ ÇÔ¼ö´Â ¹Ù·Î ÀÌ ÇÔ¼öÀÌ´Ù. int insertItem( const char *text, const QObject *receiver, const char *member, int accel=0 ); °¢ ÀÎÀÚ¿¡ ´ëÇØ ¼³¸íÇÏ°Ú´Ù. ù¹ø° ÀÎÀÚ < const char *text >´Â Popup menu¿¡ µé¾î°¥ ItemÀÇ À̸§ÀÌ´Ù. µÎ¹ø° ÀÎÀÚ < const QObject *receiver >´Â ItemÀÇ À̸§ÀÌ »ðÀԵǴ class ÀÌ´Ù. ¼¼¹ø° ÀÎÀÚ < const char *member >´Â ÀÌ ItemÀÌ »ç¿ëÀÚ¿¡ ÀÇÇØ ¼±ÅõǾî clickµÇ¾úÀ» ¶§ ½ÇÇàÇÒ receiverÀÇ member functionÀÌ´Ù. ³×¹ø° ÀÎÀÚ < int accel >Àº header source ¿¡¼­ Àá±ñ ¼³¸íÇÑ hot-key(Ȥ Àº accel-key)¸¦ ¸»ÇÑ´Ù. accel-key¿¡ ´ëÇØ ¾à°£¸¸ ´õ ¾Ë¾Æº¸ÀÚ. /usr/lib/qt/include/qkeycode.h¿¡ º¸¸é ¸ðµç key°ªµéÀÌ ÀÌ·±½ÄÀ¸·Î ¼±¾ð ȤÀº Á¤ÀǵǾîÀÖ´Ù. . . . const uint SHIFT = 0x00002000; // accelerator modifiers const uint CTRL = 0x00004000; const uint ALT = 0x00008000; const uint ASCII_ACCEL = 0x10000000; #define Key_Escape 0x1000 // misc keys #define Key_Tab 0x1001 #define Key_Backtab 0x1002 #define Key_Backspace 0x1003 #define Key_Return 0x1004 #define Key_Enter 0x1005 #define Key_Insert 0x1006 #define Key_Delete 0x1007 #define Key_Pause 0x1008 #define Key_Print 0x1009 #define Key_SysReq 0x100a #define Key_Home 0x1010 // cursor movement #define Key_End 0x1011 #define Key_Left 0x1012 . . . À§¿¡¼­ º¸¸é SHIFT, CTRL, ALT, ASCII_ACCELµîÀº 4byte unsigned int ÇüÅ·ΠÁ¤ÀǵǾîÀÖ°í ³ª¸ÓÁö key°ªµéÀº ¸ðµÎ 2byteÇüÅ·Π¼±¾ðµÇ¾îÀÖ ´Ù. À̴ Ư¼öÈ®ÀåÅ°ÀÎ SHIFT, CTRL, ALT key¿Í ³ª¸ÓÁö keyµéÀ» Á¶ÇÕ ÇÏ¿© ¾µ¼ö ÀÖ´Ù´Â À̾߱âÀε¥ ¿¹¸¦ µé¾î ´Ù½Ã Çѹø ¼³¸íÇÏ°Ú´Ù. ¸¸¾à »ç¿ëÀÚ°¡ < Å×½ºÆ®1¸Þ´ºÀÇ ¼­ºê¸Þ´º1 >À» ´ÜÃàÅ° ALT+ENTER·Î ¼³Á¤ÇÏ°í ½Í´Ù¸é ´ÙÀ½°ú °°ÀÌ ÇÏ¸é µÈ´Ù. mnuTest1->insertItem("Å×½ºÆ®1¸Þ´ºÀÇ ¼­ºê¸Þ´º1", this, SLOT(funcTest1()), ALT|ENTER); ÀÌÁ¨ QMenuBar¿¡ ´ëÇØ »ìÆ캸ÀÚ. /usr/lib/qt/include/qmenubar.h¿¡´Â ´ÙÀ½°ú °°ÀÌ ¼±¾ðÇÏ°í ÀÖ´Ù. class Q_EXPORT QMenuBar : public QFrame, public QMenuData { friend class QPopupMenu; Q_OBJECT public: QMenuBar( QWidget *parent=0, const char *name=0 ); . . . }; ¾Æ¹«¸® ã¾Æº¸¾Æµµ insertItemÇÔ¼ö¸¦ ãÀ» ¼ö ¾ø´Ù. ÇÏÁö¸¸ QPopupMenu ÀÇ °æ¿ì¿Í ¸¶Âù°¡Áö·Î QMenuDataÀÇ ¸ðµç public memberµéÀ» »ó¼Ó¹Þ°í ÀÖ´Ù. ±×·¯¹Ç·Î ÀÌ¿¡ ´ëÇÑ ¼³¸íÀº ´õÀÌ»ó ÇÏÁö ¾Ê¾Æµµ µÇ¸®¶ó ¹Ï´Â´Ù. -------------- < source 2.2.8.3 main_test7.cpp > --------------- #include #include "clssTestMenu.h" int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssTestMenu *clssTest = new clssTestMenu(); clssTest->setGeometry(100, 100, 500, 350); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } ------------------------------------------------------------------- ---------------------- < Makefile 2.2.8 > ---------------------- PROGS = main_test7 LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm CC = g++ GCC = gcc INCLUDE = -I/usr/lib/qt/include C_FLAG = -pipe -DNO_DEBUG -O2 CFLAGS = $(INCLUDE) $(C_FLAG) SYSCONF_LINK = $(CC) SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) MNU_OBJS = \ main_test7.o \ clssTestMenu_moc.o \ clssTestMenu.o all: $(PROGS) clean: rm -f *.o rm -f main_test7 rm -f *_moc.* ############# COMPILE ############# main_test7.o: main_test7.cpp $(CC) -c main_test7.cpp $(CFLAGS) -o $@ clssTestMenu_moc.cpp: clssTestMenu.h $(MOC) clssTestMenu.h -o clssTestMenu_moc.cpp clssTestMenu_moc.o: clssTestMenu_moc.cpp $(CC) -c clssTestMenu_moc.cpp $(CFLAGS) -o $@ clssTestMenu.o: clssTestMenu.cpp $(CC) -c clssTestMenu.cpp $(CFLAGS) -o $@ main_test7: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ ------------------------------------------------------------------- 2.2.9. Åø¹Ù(QToolBar), MainWindow(QMainWindow) -------------- < source 2.2.9.1 clssTestToolBar.h > --------------- #include class QToolBar; /* À̺κР< : public QMainWindow >À» ÁÖÀÇ ±í°Ô º¸±â ¹Ù¶õ´Ù. */ class clssTestToolBar : public QMainWindow { Q_OBJECT public: clssTestToolBar(); ~clssTestToolBar(); public slots: void funcTest1(); void funcTest2(); void funcTest3(); protected: private: QToolBar *tbTest; }; ------------------------------------------------------------------- -------------- < source 2.2.9.2 clssTestToolBar.cpp > --------------- #include #include #include #include #include #include "clssTestToolBar.h" #ifndef TEST1_TOOLTIP /* ToolButton¿¡ ¸¶¿ì½º¸¦ °®´Ù´ë¾úÀ» ¶§ ³ª¿Ã dz¼±µµ¿ò¸»À» ¼±¾ðÇÑ´Ù. */ #define TEST1_TOOLTIP "ù¹ø° Å×½ºÆ®" #define TEST2_TOOLTIP "µÎ¹ø° Å×½ºÆ®" #define TEST3_TOOLTIP "¼¼¹ø° Å×½ºÆ®" #endif clssTestToolBar::clssTestToolBar() { /* Icon¸¦ ÀúÀåÇÒ QPixmapº¯¼ö ¼±¾ð */ QPixmap iconTest1, iconTest2, iconTest3; qApp->setStyle(WindowsStyle); /* ToolBar¿¡ µé¾î°¥ imageµéÀ» ¼±¾ðÇÑ QPixmapº¯¼ö¿¡ LoadingÇÑ´Ù. */ iconTest1.load("./test1.gif"); iconTest2.load("./test2.gif"); iconTest3.load("./test3.gif"); tbTest = new QToolBar(this); /* ToolBarÀÇ ¹æÇâÀº ¼öÆòÀÌ´Ù. */ tbTest->setOrientation(tbTest->Horizontal); /* ToolButtonÀ» »ý¼ºÇÑ´Ù. */ QToolButton *tbttnTest1 = new QToolButton(iconTest1, TEST1_TOOLTIP, 0, this, SLOT(funcTest1()), tbTest, "test1"); QToolButton *tbttnTest2 = new QToolButton(iconTest2, TEST2_TOOLTIP, 0, this, SLOT(funcTest2()), tbTest, "test2"); QToolButton *tbttnTest3 = new QToolButton(iconTest3, TEST3_TOOLTIP, 0, this, SLOT(funcTest3()), tbTest, "test3"); } clssTestToolBar::~clssTestToolBar() { } void clssTestToolBar::funcTest1() { emit printf("ù¹ø° ´ÜÃà¾ÆÀÌÄÜ\n"); } void clssTestToolBar::funcTest2() { emit printf("µÎ¹ø° ´ÜÃà¾ÆÀÌÄÜ\n"); } void clssTestToolBar::funcTest3() { emit printf("¼¼¹ø° ´ÜÃà¾ÆÀÌÄÜ\n"); } ------------------------------------------------------------------- /usr/lib/qt/include/qtoolbar.h¸¦ »ìÆ캸ÀÚ. public: QToolBar( const char * label, QMainWindow *, QMainWindow::ToolBarDock = QMainWindow::Top, bool newLine = FALSE, const char * name = 0 ); QToolBar( const char * label, QMainWindow *, QWidget *, bool newLine = FALSE, const char * name = 0, WFlags f = 0 ); QToolBar( QMainWindow * parent = 0, const char * name = 0 ); ¿©±â¼­ ÁÖÀDZí°Ô º¸¾Æ¾ß ÇÒ ºÎºÐÀÌ Çѱºµ¥ ÀÖ´Ù. ¹Ù·Î QMainWindow *parent ÀÎÀÚ ºÎºÐÀÌ´Ù. ÀÌÁ¦±îÁö ´Ù·ð´ø widgetµéÀº parent ÀÇ typeÀÌ ¸ðµÎ QWidget À̾ú´Ù. ÇÏÁö¸¸ ¿©±â¼­´Â QMainWindowÀÌ´Ù. ±×·¯¸é °èÃþÁ¤º¸¸¦ Á» º¸ÀÚ. QMainWindow¿Í QToolBar ¸ðµÎ QWidgetÀÇ ÇÏÀ§ class·Î¼­ ¼­·Î ÇüÁ¦°£ÀÌ´Ù. ÇüÁ¦°£¿¡´Â ¼­·Î Á¾¼ÓµÉ ¼ö ÀÖÀ¸¹Ç·Î QToolBarÀÇ parent¸¦ QMainWindow·Î Á¤ ÀÇÇÒ ¼ö ÀÖ´Ù. QMenuBar¶ÇÇÑ ¸¶Âù°¡ÁöÀÌ´Ù. ÀÌ·¸µí class°èÃþÁ¤º¸¸¦ ¹ÙÅÁÀ¸ ·Î »óÇÏ°ü°è¸¦ ¼³Á¤ÇØÁØ´Ù¸é ¸íÈ®ÇÑ ÇÁ·Î±×·¡¹ÖÀÌ °¡´ÉÇÏ°Ô µÈ´Ù. /usr/lib/qt/include/qtoolbutton.h¸¦ º¸ÀÚ. public: QToolButton( QWidget * parent = 0, const char * name = 0 ); QToolButton( const QPixmap & pm, const char * textLabel, const char * grouptext, QObject * receiver, const char * slot, QToolBar * parent, const char * name = 0 ); QToolButton( QIconSet s, const char * textLabel, const char * grouptext, QObject * receiver, const char * slot, QToolBar * parent, const char * name = 0 ); source 2.2.9.2¿¡¼­ ¾²ÀÎ QToolButton ÇÔ¼ö¿Í ºñ±³Çؼ­ ¼³¸íÇÏ°Ú´Ù. QToolButton *tbttnTest1 = new QToolButton(iconTest1, TEST1_TOOLTIP, 0, this, SLOT(funcTest1()), tbTest, "test1"); ÀÌ ÇÔ¼ö´Â header file¿¡ ¼±¾ðµÈ ¼¼°³ÀÇ ÇÔ¼öÁß µÎ¹ø° ÇÔ¼ö°¡ ¾²ÀÎ °ÍÀÌ´Ù. µÎ¹ø° ÇÔ¼öÀÇ Ã¹¹ø° ÀÎÀÚ´Â iconÀ» ³ªÅ¸³½´Ù. Qt¿¡¼­´Â ¿©·¯°¡Áö image fileµé Áï, bmp, gif, jpg, xpm µîµîÀ» Áö¿øÇÑ´Ù. °¢ fileµéÀ» loadingÇÏ´Â ¹æ¹ýÀº ¾à°£¾¿ ´Ù¸£´Ù. ÀÌ·± fileµéÀ» loadingÇÏ´Â ¹æ¹ý Àº header fileÀ̳ª ȤÀº Qt¿¡¼­ Á¦°øÇÏ´Â ¿¹Á¦ ÇÁ·Î±×·¥µéÀ» º¸¸é ±Ý¹æ ¾Ë ¼ö ÀÖÀ» °ÍÀÌ´Ù. gif¿Í jpg´Â ¾ÐÃàfileÀ̹ǷΠ¸ÕÀú LinuxÀÇ X-window¿¡¼­ »ç¿ëÇÒ ¸¸ÇÑ formatÀ¸·Î º¯È¯½ÃÄѾßÇÑ´Ù. X-window¿¡¼­ »ç¿ëÇÏ´Â file formatÀº xpm fileÀε¥ ´ÙÀ½Àº °£´ÜÇÑ xpm fileÀÇ ³» ºÎ¸¦ vi·Î ¿­¾îº» °ÍÀÌ´Ù. static char * Ant_xpm[] = { "48 48 60 1", " c None", ". c #492449244924", "X c #618561856185", "o c #9E799E799E79", "O c #208120812081", "+ c #514455555144", "@ c #410341034103", "# c #965896589658", "$ c #082008200820", "% c #8E388A288E38", "& c #69A669A669A6", "* c #71C675D671C6", "= c #861782078617", "- c #28A228A228A2", "; c #104014511040", ": c #10400C300000", "> c #410324921040", ", c #082004100000", "< c #000000000000", "1 c #71C63CF32081", "2 c #8E38492428A2", "3 c #208114511040", "4 c #30C234D330C2", "5 c #208110400820", "6 c #492424921040", "7 c #51442CB21861", "8 c #38E320811040", "9 c #104008200000", "0 c #208114510820", "q c #28A214510820", "w c #79E741032081", "e c #596530C21861", "r c #10400C300820", "t c #618534D32081", "y c #30C218611040", "u c #28A218610820", "i c #79E7451428A2", "p c #9658514430C2", "a c #18610C300820", "s c #186110400820", "d c #30C21C711040", "f c #49242CB21861", "g c #104010400820", "h c #59652CB21861", "j c #492428A21861", "k c #618538E32081", "l c #30C21C710820", "z c #69A634D32081", "x c #20811C711861", "c c #30C224921861", "v c #30C22CB228A2", "b c #186110401040", "n c #410328A21861", "m c #8617451428A2", "M c #38E31C711040", "N c #61855D755965", "B c #69A638E32081", "V c #410320811040", "C c #51443CF330C2", "Z c #514430C22081", " . ", " X. ", " oOo ", " +@ ", " # $% ", " %+ O ", " &* =O ", " O* =- ", " o; =O ", " &@ =-=X+= ", " O. X:>,--# ", " #<# *<12>3* = ", " &4- ;56789<&$# ", " o+$-= *0q<6,w,$;= o#", " %;4* +8wq,ee<<<% *;%", " %tw<<<; o#.;+# ", " %4% #+;,08<<<<<$-4# ", " X;*$% &O<@5ipa<<mtd --------------- #include #include "clssTestToolBar.h" int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssTestToolBar *clssTest = new clssTestToolBar(); clssTest->setGeometry(100, 100, 500, 350); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } ------------------------------------------------------------------- ---------------------- < Makefile 2.2.9 > ---------------------- PROGS = main_test8 LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm CC = g++ GCC = gcc INCLUDE = -I/usr/lib/qt/include C_FLAG = -pipe -DNO_DEBUG -O2 CFLAGS = $(INCLUDE) $(C_FLAG) SYSCONF_LINK = $(CC) SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) MNU_OBJS = \ main_test8.o \ clssTestToolBar_moc.o \ clssTestToolBar.o all: $(PROGS) clean: rm -f *.o rm -f main_test8 rm -f *_moc.* ############# COMPILE ############# main_test8.o: main_test8.cpp $(CC) -c main_test8.cpp $(CFLAGS) -o $@ clssTestToolBar_moc.cpp: clssTestToolBar.h $(MOC) clssTestToolBar.h -o clssTestToolBar_moc.cpp clssTestToolBar_moc.o: clssTestToolBar_moc.cpp $(CC) -c clssTestToolBar_moc.cpp $(CFLAGS) -o $@ clssTestToolBar.o: clssTestToolBar.cpp $(CC) -c clssTestToolBar.cpp $(CFLAGS) -o $@ main_test8: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ ------------------------------------------------------------------- 2.3. QT Library¸¦ ´Ù¿î¹ÞÀ¸·Á¸é? ¿©·¯ Site°¡ ÀÖÁö¸¸ °¡Àå ´ëÇ¥ÀûÀÎ UrlÀº < http://www.troll.no > ¿¡¼­ ´Ù¿î¹Þ¾Æ »ç¿ëÇÒ ¼ö ÀÖ´Ù. < ÇѸ¶µð >. Áö±Ý±îÁö ÇϳªÀÇ Project¸¦ ²Ù¹Ì±â À§ÇØ ±×¸® ªÁö¸¸Àº ¾ÊÀº °úÁ¤À» °ÅÃÄ¿Ô½À ´Ï´Ù. ±âÃÊ °úÁ¤Àº ¸ðµÎ ³¡³­ °ÍÀÔ´Ï´Ù. ¾ÆÁ÷ ±âÃÊ°úÁ¤¿¡ ¼ÓÇÑ network°ü·Ã Library ¿¡ ´ëÇÑ ¼³¸íÀÇ È­µÎµµ ³ª¿ÀÁö ¾ÊÀº »óÅÂÀÌÁö¸¸ Project¸¦ ±¸ÇöÇϱ⿡´Â ÃæºÐÇÑ ½Ç·ÂÀ» ½×¾Ò´Ù°í ÇÒ ¼ö ÀÖ°ÚÁÒ. ±âÃÊ °úÁ¤Àº ´ë·« ¼³¸íÀÌ ³¡³µÀ¸¹Ç·Î ¾ÕÀ¸·Î ³ª¿Ã ±âÃÊ ºÎºÐ¿¡ ¿¬°üµÈ codeµé¿¡ ´ëÇؼ­´Â µÇµµ·ÏÀÌ¸é ¼³¸íÀ» »ý·«Çϵµ·Ï ÇÏ °Ú½À´Ï´Ù. =============================================================== < 3. ±âº» Format ÀÛ¼ºÇϱâ > ÀÌÁ¦ºÎÅÍ º»°ÝÀûÀ¸·Î Project¸¦ ½ÃÀÛÇغ¸ÀÚ. Programming ¼ø¼­´Â ¿©·¯ºÐµéµµ Àß ¾Æ½Ã°ÚÁö¸¸ < ÀÔ·Â->ó¸®->Ãâ·Â > ÀÇ ¼ø¼­·Î ¸¸µé¾î¾ß ÇÑ´Ù. ÀÌ·¯ÇÑ °úÁ¤Àº ¿©·¯ºÐ µéÀÌ Á÷Á¢ Project¸¦ °³¹ßÇÒ ¶§ À¯¿ëÇÑ ¹æ¹ýÀÌÁö ÀÌ·¸°Ô ¹ßǥȤÀº ¼¼¹Ì ³ªÇü½ÄÀÇ ´ëÈ­¿¡¼­´Â º°·Î ¾µ¸ð°¡ ¾ø´Ù. µû¶ó¼­ ÇÊÀÚ´Â ¿©·¯ºÐÀÌ °¡Àå ÀÌÇØÇϱ⠽¬¿î Ãø¸éºÎÅÍ ÆÄ°íµé°íÀÚ ÇÑ´Ù. ¿ì¼± ±âº» formatÀ» Àâ¾Æº¸ÀÚ. ±âº» formatÀº WindowsÇüÅÂÀÇ window°¡ °¡Àå ÁÁÀ» µí ÇÏ´Ù. ¿ä»õ´Â ¸®´ª½º Applicationµéµµ WindowsÇüÅÂ¿Í GUI°¡ ºñ½ÁÇÏ´Ù. µû¶ó¼­ ÇÊÀÚµµ ÀÌ Format¿¡ µû¸£°Ú´Ù. -------------------------------------------------------- | ¸Þ´º ¿µ¿ª | |--------------------------------------------------------| | Icon ¿µ¿ª | |--------------------------------------------------------| | | | | | | | | | ÀÛ¾÷ ¿µ¿ª | | | | | | ---------------- | | ---- --------- | |---- -----------------------| 3.1. ¸Þ´º ¸¸µé±â ¸Þ´º´Â ´ÙÀ½°ú °°ÀÌ ÇϳªÀÇ Popup Menu¸¦ Æ÷ÇÔ½ÃÅ°´Â °ÍÀ¸·Î ÇÑ´Ù. -------------------------------------------------------- | ³×Æ®¿öÅ©°ü¸® | |--------------------------------------------------------| | | ÀϹݳ×Æ®¿öÅ©°ü¸® | | |-| DNS °ü¸® |-----------------------------------| | | IP-Aliasing°ü¸® | | | |------------------| | | | | ------------------------- | | ----------- ------- | |---- ---------| ´ÙÀ½Àº Source¸¦ º¸±â·Î ÇÏÀÚ. -------------- < Source 3.1.1 Network_menu.h > ----------------- #include class QMenuBar; class QPopupMenu; class clssNetwork : public QMainWindow { Q_OBJECT public: clssNetwork(); ~clssNetwork(); public slots: void funcGenericNetwork(); void funcDNS(); void funcAlias(); void funcQuit(); protected: private: QMenuBar *mnuMainBar; QPopupMenu *mnuNetwork; }; ---------------------------------------------------------------- -------------- < Source 3.1.2 Network_menu.cpp > --------------- #include #include #include #include #include #include "Network_menu.h" clssNetwork::clssNetwork() { qApp->setStyle(WindowsStyle); /* ¸Þ´º¸¦ ¸¸µé°í ±× ¸Þ´º¿¡ ÇØ´çÇÏ´Â ÇÔ¼ö¸¦ °£´ÜÇÏ°Ô */ /* Á¤ÀÇÇØ ³õ´Â´Ù. */ mnuNetwork = new QPopupMenu; mnuNetwork->insertItem("ÀÏ¹Ý ³×Æ®¿öÅ© °ü¸®", this, SLOT(funcGenericNetwork())); mnuNetwork->insertItem("DNS °ü¸®", this, SLOT(funcDNS())); mnuNetwork->insertItem("IP-Aliasing °ü¸®", this, SLOT(funcAlias())); mnuNetwork->insertItem("Á¾·á", this, SLOT(funcQuit())); mnuMainBar = new QMenuBar(this); mnuMainBar->insertItem(" ³×Æ®¿öÅ© ", mnuNetwork); } clssNetwork::~clssNetwork() { } void clssNetwork::funcGenericNetwork() { } void clssNetwork::funcDNS() { } void clssNetwork::funcAlias() { } void clssNetwork::funcQuit() { exit(0); } ---------------------------------------------------------------- ---------------- < Source 3.1.3 main_menu.cpp > ---------------- #include #include "Network_menu.h" int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssNetwork *clssTest = new clssNetwork(); clssTest->setGeometry(100, 100, 800, 600); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } ---------------------------------------------------------------- --------------------- < Makefile 3.1. > ------------------------ PROGS = main_menu LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm CC = g++ GCC = gcc INCLUDE = -I/usr/lib/qt/include C_FLAG = -pipe -DNO_DEBUG -O2 CFLAGS = $(INCLUDE) $(C_FLAG) SYSCONF_LINK = $(CC) SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) MNU_OBJS = \ main_menu.o \ Network_menu_moc.o \ Network_menu.o all: $(PROGS) clean: rm -f *.o rm -f main_menu rm -f *_moc.* ############# COMPILE ############# main_menu.o: main_menu.cpp $(CC) -c main_menu.cpp $(CFLAGS) -o $@ Network_menu_moc.cpp: Network_menu.h $(MOC) Network_menu.h -o Network_menu_moc.cpp Network_menu_moc.o: Network_menu_moc.cpp $(CC) -c Network_menu_moc.cpp $(CFLAGS) -o $@ Network_menu.o: Network_menu.cpp $(CC) -c Network_menu.cpp $(CFLAGS) -o $@ main_menu: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ ---------------------------------------------------------------- 3.2. Åø¹Ù Áý¾î³Ö±â ToolBar¿¡ µé¾î°¥ ICONÀº 16*16Å©±âÁ¤µµÀÇ gif fileÀÌ ÁÁ°Ú´Ù. Source¸¦ º¸ÀÚ. -------------- < Source 3.2.1 Network_menu.h > ----------------- #include class QMenuBar; class QPopupMenu; class QToolBar; class clssNetwork : public QMainWindow { Q_OBJECT public: clssNetwork(); ~clssNetwork(); public slots: void funcGenericNetwork(); void funcDNS(); void funcAlias(); void funcQuit(); protected: private: QMenuBar *mnuMainBar; QPopupMenu *mnuNetwork; QToolBar *tbNetwork; }; ---------------------------------------------------------------- -------------- < Source 3.2.2 Network_menu.cpp > --------------- #include #include #include #include #include #include #include #include #include "Network_menu.h" /* icon¿¡ ´ëÇÑ Ç³¼±µµ¿ò¸»À» ¼±¾ðÇÑ´Ù. */ #ifndef GENERIC_TOOLTIP #define GENERIC_TOOLTIP "ÀϹÝÀûÀÎ ³×Æ®¿öÅ© ¼³Á¤" #define DNS_TOOLTIP "DNS ¼³Á¤" #define ALIAS_TOOLTIP "Alias ¼³Á¤" #endif clssNetwork::clssNetwork() { QPixmap iconGeneric, iconDNS, iconAlias; iconGeneric.load("./generic.gif"); iconDNS.load("./dns.gif"); iconAlias.load("./alias.gif"); /* À©µµ¿ìÇüŸ¦ Windows½ºÅ¸ÀÏ·Î */ qApp->setStyle(WindowsStyle); mnuNetwork = new QPopupMenu; mnuNetwork->insertItem("ÀÏ¹Ý ³×Æ®¿öÅ© °ü¸®", this, SLOT(funcGenericNetwork())); mnuNetwork->insertItem("DNS °ü¸®", this, SLOT(funcDNS())); mnuNetwork->insertItem("IP-Aliasing °ü¸®", this, SLOT(funcAlias())); mnuNetwork->insertSeparator(); mnuNetwork->insertItem("Á¾·á", this, SLOT(funcQuit())); mnuMainBar = new QMenuBar(this); mnuMainBar->insertItem(" ³×Æ®¿öÅ© ", mnuNetwork); tbNetwork = new QToolBar(this); tbNetwork->setOrientation(tbNetwork->Horizontal); QToolButton *tbttnGeneric = new QToolButton(iconGeneric, GENERIC_TOOLTIP, 0, this, SLOT(funcGenericNetwork()), tbNetwork, "generic"); QToolButton *tbttnDNS = new QToolButton(iconDNS, DNS_TOOLTIP, 0, this, SLOT(funcDNS()), tbNetwork, "dns"); QToolButton *tbttnAlias = new QToolButton(iconAlias, ALIAS_TOOLTIP, 0, this, SLOT(funcAlias()), tbNetwork, "alias"); } clssNetwork::~clssNetwork() { } void clssNetwork::funcGenericNetwork() { } void clssNetwork::funcDNS() { } void clssNetwork::funcAlias() { } void clssNetwork::funcQuit() { exit(0); } ---------------------------------------------------------------- ------------------ < Source 3.2.3 main_menu.cpp > -------------- #include #include "Network_menu.h" int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssNetwork *clssTest = new clssNetwork(); clssTest->setGeometry(100, 100, 800, 600); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } ---------------------------------------------------------------- ---------------------- < Makefile 3.2. > ----------------------- MakefileÀº < Makefile 3.1. >°ú °°´Ù. ---------------------------------------------------------------- 3.3. Network°ü·Ã ¶óÀ̺귯¸® ±¸ÇöÇϱ⠸޴º¿Í Åø¹Ù¸¦ ±âº»ÀûÀ¸·Î ÀÛ¼ºÀ» ÇßÀ¸¹Ç·Î ÀÌÁ¦ºÎÅÍ´Â Network°ü·Ã ¶óÀ̺귯¸®¸¦ ±¸ÇöÇϱâ·Î ÇÏÀÚ. ÀÌ ¶óÀ̺귯¸®´Â À§ÂÊ¿¡¼­ ±¸ÇöÇß´ø file󸮷çƾÀ» »ç¿ëÇϱ⵵ ÇÏ°í gcc°¡ Á¦°øÇÏ´Â network library¸¦ »ç¿ëÇϱ⵵ ÇÑ´Ù. ¸¶Áö¸·À¸·Î ÀÌ ºÎºÐ¸¸ Àß ÀÌÇظ¦ ÇÑ´Ù¸é °ÅÀÇ ¾î ·Á¿ò ¾øÀÌ ³¡±îÁö °úÁ¤À» Áö³ª°¥ ¼ö ÀÖ´Ù. ¿ì¼± header fileºÎÅÍ º¸±â·Î ÇÏÀÚ. --------------- < Source 3.3.1 network.h > --------------------- #ifndef _NETWORK_H #define _NETWORK_H #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif #ifndef MAX_LINE #define MAX_LINE 100 #define MAX_COL 1000 #endif #ifndef NO_SETTING #define NO_SETTING "¼ÂÆõǾîÀÖÁö ¾Ê½À´Ï´Ù." #endif extern char pszNetConfHost[256]; extern char pszNetConfDomain[256]; extern char pszNetConfGateway[18]; extern char pszNetConfIPAddr[18]; extern char pszNetConfPrivate1IPAddr[18]; extern char pszNetConfPrivate2IPAddr[18]; extern char pszNetConfNetmask[18]; extern char pszNetConfPrivate1Netmask[18]; extern char pszNetConfPrivate2Netmask[18]; extern char pszNetconfBroadcast[18]; extern char pszNetconfPrivate1Broadcast[18]; extern char pszNetconfPrivate2Broadcast[18]; extern char pszNetConfNetwork[18]; extern char pszNetConfPrivate1Network[18]; extern char pszNetConfPrivate2Network[18]; extern char pszNetConfNetCard[3][30]; extern int nCountListStr; extern char pszSaveNameServer[20][30]; extern int nCountNameServer; extern int nCountClient; extern int nAccountCount; /* IP¿Í Netmask¸¦ ¾Ë¾Æ³ÂÀ» ¶§ ±×¿¡ ÇØ´çÇÏ´Â Network°ú Broadcast */ /* ¸¦ ¾Ë¾Æ³»±â À§ÇÑ ±¸Á¶Ã¼ */ typedef struct tagNETMASKTAB { char pszNetwork[18]; char pszBroadcast[18]; } NetTab; NetTab calculateNetMaskTab(char *pszIPAddr, char *pszNetmask); /* IP¿¡ ´ëÇØ dot·Î ³ª´©¾îÁø 4°³ÀÇ ¹øÈ£¸¦ ¾ò±âÀ§ÇØ ¾²ÀÏ ±¸Á¶Ã¼ */ typedef struct tagSEPADDR { char pszFirst[6]; char pszSecond[6]; char pszThird[6]; char pszFourth[6]; } S_Addr; S_Addr separateAddress(char *pszAddr); /* ÇöÀç ³¯Â¥¸¦ °è»êÇÑ´Ù. */ char *calculateDate(void); /* ÇöÀç ù¹ø° Network card¿¡ ´ëÇÑ Netmask¸¦ ¾Ë¾Æ³½´Ù. */ void getCurrentNetmask(char *pszNetmask); /* ÇöÀç ù¹ø° Network card¿¡ ´ëÇÑ Gateway¸¦ ¾Ë¾Æ³½´Ù. */ void getCurrentGateway(char *pszGateway); /* ÇöÀç ù¹ø° Network card¿¡ ´ëÇÑ HostnameÀ» ¾Ë¾Æ³½´Ù. */ void getCurrentHostName(char *pszHostName, char *pszDomainName); /* ÇöÀç ù¹ø° Network card¿¡ ´ëÇÑ IP¸¦ ¾Ë¾Æ³½´Ù. */ void getCurrentIPAddr(char *pszIPAddr); /* ÇöÀç ¼³Á¤µÈ µÎ¹ø° Network card¿¡ ´ëÇÑ Netmask¸¦ ¾Ë¾Æ³½´Ù. */ void getPrivate1Netmask(char *pszPrivateNetmask); /* ÇöÀç µÎ¹ø° Network card¿¡ ´ëÇÑ »ç¼³IP¸¦ ¾Ë¾Æ³½´Ù. */ void getPrivate1IPAddr(char *pszPrivateIPAddr); /* ÇöÀç ¼³Á¤µÈ ¼¼¹ø° Network card¿¡ ´ëÇÑ Netmask¸¦ ¾Ë¾Æ³½´Ù. */ void getPrivate2Netmask(char *pszPrivateNetmask); /* ÇöÀç ¼¼¹ø° Network card¿¡ ´ëÇÑ »ç¼³IP¸¦ ¾Ë¾Æ³½´Ù. */ void getPrivate2IPAddr(char *pszPrivateIPAddr); /* Network card°¡ ISAÀÏ °æ¿ì Io number¿Í Irq number¸¦ ¾Ë¾Æ³½´Ù. */ void getNetCardIoIrq(char *pszIo, char *pszIrq, int nCardIdx); /* ÇöÀç DNS ¼­¹öÀÇ ¼³Á¤°ªÀ» ¾Ë¾Æ³½´Ù. */ void getDNSServer(char *pszDNSServer[]); /* ¸¸¾à IP°¡ Aliasing µÇ¾îÀÖ´Ù¸é Aliasing IP¿¡ ´ëÇÑ Netmask¸¦ ¾Ë¾Æ³½´Ù. */ void getAliasNetmask(char *pszNetmask, int nIdx); /* Aliasing IP¸¦ ¾Ë¾Æ³½´Ù. */ void getAliasIP(char *pszIPAddr, int nIdx); /* NetworkÄ«µåÀÇ Á¤º¸¸¦ ¾Ë¾Æ³½´Ù. */ void getEthNetworkCard(char *pszSaveNetCard[], char *pszCardInfo[]); /* IP¹üÀ§°ªÀ» ¾Ë¾Æ³½´Ù. ¿¹: 172.31.0.0/24 -> 172.31.0.0~172.31.0.255 */ void calcIPRange(char *pszStartIP, char *pszEndIP, int nIPFourth, int nRange); /* IP¹üÀ§°ªÀ» ¹Þ¾Æ IP/numberºÎºÐÀÇ number°ªÀ» ¾Ë¾Æ³½´Ù. */ void calcIPDiffToRange(char *pszStartIP, char *pszEndIP, int *nRange); #endif ---------------------------------------------------------------- --------------- < Source 3.3.1 network.cpp > ------------------- #include #include #include #include #include #include #include #include #include "network.h" #include "proc_file.h" /*************** Calculate Netmask table **************/ NetTab calculateNetMaskTab(char *pszIPAddr, char *pszNetmask) { struct in_addr IP; struct in_addr Mask; struct in_addr pNetwork; struct in_addr pBroadcast; NetTab pNet; memset(pNet.pszNetwork, '\0', 18); memset(pNet.pszBroadcast, '\0', 18); IP.s_addr = inet_addr(pszIPAddr); Mask.s_addr = inet_addr(pszNetmask); /* NetworkÀÇ °è»ê¹ýÀº IP & NetmaskÀÌ´Ù. */ pNetwork.s_addr = IP.s_addr & Mask.s_addr; /* NetworkÀ» °è»êÇÏ¿© pNet±¸Á¶Ã¼ÀÇ network º¯¼ö¿¡ ÀüÇØÁØ´Ù. */ memcpy(pNet.pszNetwork, inet_ntoa(pNetwork), 18); /* BroadcastÀÇ °è»ê¹ýÀº Network | NetmaskÀÌ´Ù. */ pBroadcast.s_addr = pNetwork.s_addr | ~Mask.s_addr; /* Broadcast¸¦ °è»êÇÏ¿© pNet±¸Á¶Ã¼ÀÇ broadcast º¯¼ö¿¡ ÀüÇØÁØ´Ù. */ memcpy(pNet.pszBroadcast, inet_ntoa(pBroadcast), 18); return pNet; } /***************************************/ S_Addr separateAddress(char *pszAddr) { int i = 0, j = 0, k = 0; S_Addr pAddr; memset(pAddr.pszFirst, '\0', 6); memset(pAddr.pszSecond, '\0', 6); memset(pAddr.pszThird, '\0', 6); memset(pAddr.pszFourth, '\0', 6); /* ±¸Á¶Ã¼ÀÇ °¢ member(pszFirst, pszSecond, pszThird, pszFourth) */ /* ¿¡ ÇØ´çÇÏ´Â °ªÀ» ³ª´² º¹»çÇÏ´Â ÀÛ¾÷. ¾î·ÆÁö ¾ÊÀ¸¹Ç·Î À¯½ÉÈ÷ */ /* º¸½Ã±æ. */ for (k = 0; *(pszAddr+i) != '\0'; i++, k++) { if (*(pszAddr+i) == '.') { i++; k = 0; j++; } switch (j) { case 0: pAddr.pszFirst[k] = *(pszAddr+i); break; case 1: pAddr.pszSecond[k] = *(pszAddr+i); break; case 2: pAddr.pszThird[k] = *(pszAddr+i); break; case 3: pAddr.pszFourth[k] = *(pszAddr+i); break; default: break; } } return pAddr; } /* ½ÇÁ¦ ±¸Çö¿¡¼­´Â º°·Î ¾µ¸ð¾ø´Â ÇÔ¼öÀÌÁö¸¸ ³¯Â¥¸¦ ¾ò¾î³»´Â ÇÔ¼öÁ¤ */ /* µµ´Â ÀÖ¾î¾ß°Ú´Ù ½Í¾î ³Ö¾î³õ¾Ò´Ù. */ char pszDate[11]; char *calculateDate() { time_t tTime; int i; memset(pszDate, '\0', 11); tTime = time(NULL); for (i = 0; i < 4; i++) pszDate[i] = *(ctime(&tTime)+20+i); for (i = 0; i < 3; i++) pszDate[i+4] = *(ctime(&tTime)+4+i); for (i = 0; i < 2; i++) pszDate[i+4+3] = *(ctime(&tTime)+8+i); return pszDate; } void getCurrentNetmask(char *pszNetmask) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); /* Netmask¸¦ ¾ò¾î³¾ ¶§´Â ¹Ø¿¡ÀÖ´Â ifcfg-eth0 file¿¡ ÀÖ´Â */ /* Á¤º¸¸¦ »ç¿ëÇÏ¿© ¾Ë¾Æ³½´Ù. */ /* ifcfg-eth0 fileÀ» ¿­¾îº¸¸é Redhat 6.0¹öÁ¯±îÁö´Â ÀÌ·¸°Ô µÇ¾î */ /* ÀÖ´Ù. */ /* DEVICE=eth0 IPADDR=172.31.10.1 NETMASK=255.255.0.0 NETWORK=172.31.0.0 BROADCAST=172.31.255.255 ONBOOT=yes */ /* ÀÌÁß¿¡¼­ NETMASK= µÞºÎºÐ¸¸À» Àо´Â °ÍÀÌ´Ù. */ if ((fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth0", "r")) == NULL) return; while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "NETMASK=")); for (i = 0; pszSave[i+8] != 'N'; i++) pszNetmask[i] = pszSave[i+8]; pszNetmask[i-1] = '\0'; } void getCurrentGateway(char *pszGateway) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); /* gateway¸¦ ¾Ë¾Æ³¾ ¶§´Â network fileÀ» ÀÌ¿ëÇÑ´Ù. */ if ((fp = fopen("/etc/sysconfig/network", "r")) == NULL) return; while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); /* GATEWAY=µÞºÎºÐÀ» ÀúÀåÇÑ´Ù. */ strcpy(pszSave, (char *)strstr(pszSaveFile, "GATEWAY=")); for (i = 0; pszSave[i+8] != 'G'; i++) pszGateway[i] = pszSave[i+8]; pszGateway[i-1] = '\0'; } void getPrivate1Netmask(char *pszPrivateNetmask) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); /* ifcfg-eth1 fileÀ» ÀÌ¿ëÇÑ´Ù. */ if ((fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth1", "r")) == NULL) { // strcpy(pszPrivateNetmask, "255.255.0.0"); return; } while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "NETMASK=")); for (i = 0; pszSave[i+8] != 'N'; i++) pszPrivateNetmask[i] = pszSave[i+8]; pszPrivateNetmask[i-1] = '\0'; } void getPrivate1IPAddr(char *pszPrivateIPAddr) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); if ((fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth1", "r")) == NULL) { // strcpy(pszPrivateIPAddr, "172.31.0.1"); return; } while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "IPADDR=")); for (i = 0; pszSave[i+7] != 'N'; i++) pszPrivateIPAddr[i] = pszSave[i+7]; pszPrivateIPAddr[i-1] = '\0'; } void getPrivate2Netmask(char *pszPrivateNetmask) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); if ((fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth2", "r")) == NULL) { // strcpy(pszPrivateNetmask, "255.255.0.0"); return; } while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "NETMASK=")); for (i = 0; pszSave[i+8] != 'N'; i++) pszPrivateNetmask[i] = pszSave[i+8]; pszPrivateNetmask[i-1] = '\0'; } void getPrivate2IPAddr(char *pszPrivateIPAddr) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); /* ifcfg-eth2 fileÀ» ÀÌ¿ëÇÑ´Ù. */ if ((fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth2", "r")) == NULL) { // strcpy(pszPrivateIPAddr, "192.168.1.1"); return; } while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "IPADDR=")); for (i = 0; pszSave[i+7] != 'N'; i++) pszPrivateIPAddr[i] = pszSave[i+7]; pszPrivateIPAddr[i-1] = '\0'; } /* network ±¸Á¶Ã¼ utsnameÀ» ÀÌ¿ëÇÑ´Ù. */ /* utsnameÀÇ memberÀÎ nodenameÀº hostname.domainnameÀÇ ÇüÅ */ /* ·Î µé¾î°¡°Ô µÇ¾îÀÖ´Ù. */ void getCurrentHostName(char *pszHostName, char *pszDomainName) { struct utsname name; int i, j; uname(&name); for (i = 0; name.nodename[i] != '.'; i++) pszHostName[i] = name.nodename[i]; i++; for (j = 0; name.nodename[i] != '\0'; i++, j++) pszDomainName[j] = name.nodename[i]; } void getCurrentIPAddr(char *pszIPAddr) { char *pszSaveListStr[20]; int i; for (i = 0; i < 20; i++) { pszSaveListStr[i] = (char *)malloc(sizeof(char)*80); memset(pszSaveListStr[i], '\0', 80); } /* ifcfg-eth0 file¿¡¼­ IPADDR¹®ÀÚ¿­À» ã¾Æ ±× ¶óÀÎÀ» ÀúÀåÇÑ´Ù. */ saveSearchLineToFile("IPADDR", pszSaveListStr, "/etc/sysconfig/network-scripts/ifcfg-eth0", 20, 80); /* IP ºÎºÐÀ» ²ôÁý¾î³½´Ù. */ for (i = 0; pszSaveListStr[0][i+7] != '\n'; i++) pszIPAddr[i] = pszSaveListStr[0][i+7]; for (i = 0; i < 20; i++) free(pszSaveListStr[i]); } /* ¿ä»õ´Â Network cardµé ´ëºÎºÐÀÌ PCI Card·Î¹Û¿¡´Â ³ª¿ÀÁö ¾Ê´Â´Ù. */ /* Io, Irq number¸¦ ¼öµ¿À¸·Î settingÇؾßÇÏ´Â Card´Â ISA CardÀε¥ */ /* ISA Card¸¦ ¾²´Â »ç¶÷Àº 1000¸íÁß 1¸íÀ̳ª µÉ±î? µû¶ó¼­ ÀÌ ·çƾ */ /* Àº º°·Î ÇÊ¿ä°¡ ¾ø´Â ·çƾÀÌÁö¸¸ ÇÊ¿äÇÒ Áöµµ ¸ð¸¥´Ù´Â »ý°¢¿¡ Áý */ /* ¾î³Ö¾ú´Ù. ÀÌ ·çƾÀº /etc/conf.modules fileÀÌ ÇÊ¿äÇÏ´Ù. */ /* conf.modules file¿¡ io=0x230 irq=11 °°Àº Çü½ÄÀ¸·Î µé¾î°¡±â ¶§¹® */ /* ¿¡ ÀÌ ºÎºÐ¿¡ ´ëÇÑ ¹®ÀÚ¿­ 󸮰¡ ÇÊ¿äÇÏ´Ù. ÀÚ¼¼ÇÑ ¼³¸íÀº ±×¸¸ */ /* µÎ°Ú´Ù. */ void getNetCardIoIrq(char *pszIo, char *pszIrq, int nNetCardIdx) { int i; char *pszPosIo, *pszPosIrq; int nIrqIdx, nIoIdx; char *pszTmpStr = "options eth%d"; char pszOptionStr[30]; char *pszSaveListStr[3]; for (i = 0; i < 3; i++) { if ((pszSaveListStr[i] = (char *)malloc(sizeof(char)*200)) == NULL) { printf("Memory allocation error!\n"); memset(pszSaveListStr[i], '\0', 200); exit(1); } } memset(pszOptionStr, '\0', 30); sprintf(pszOptionStr, pszTmpStr, nNetCardIdx); saveSearchLineToFile(pszOptionStr, pszSaveListStr, "/etc/conf.modules", 200, 200); pszPosIo = strstr(pszSaveListStr[0], "0x"); nIoIdx = pszPosIo-pszSaveListStr[0]; pszPosIrq = strstr(pszSaveListStr[0], "irq="); nIrqIdx = pszPosIrq-pszSaveListStr[0]; for (i = nIoIdx-1; i < nIrqIdx-4; i++) pszIo[i-nIoIdx+1] = pszSaveListStr[0][i+3]; for (i = nIrqIdx; pszSaveListStr[0][i+4] != '\n'; i++) pszIrq[i-nIrqIdx] = pszSaveListStr[0][i+4]; for (i = 0; i < 3; i++) free(pszSaveListStr[i]); } /* DNS Server´Â /etc/resolv.conf file¿¡ µé¾î°£´Ù. */ /* resolv.conf file¿¡ µé¾îÀÖ´Â IP´Â ¼ø¼­´ë·Î DNS Server ¿ªÇÒÀ» */ /* ÇÑ´Ù. Áï nameserver·Î¼­ º°·Î ÁÁÁö¾ÊÀº server IP°¡ ùÁÙ¿¡ ÀÖ */ /* ´Ù¸é ±×¸¦ »èÁ¦Çϰųª µÚ·Î ¿Å°ÜÁÙ ¼ö ÀÖ´Ù. ÀÌ ÇÔ¼ö´Â ´Ü¼øÈ÷ */ /* settingµÇ¾îÀÖ´Â DNS Server IP¸¸À» pszDNSServer¿¡ ÀúÀåÇÑ´Ù. */ void getDNSServer(char *pszDNSServer[]) { char *pszSaveListStr[50]; int i; int nCntDNS; for (i = 0; i < 50; i++) { if ((pszSaveListStr[i] = (char *)malloc(sizeof(char)*200)) == NULL) { printf("Memory allocation error!\n"); exit(1); } memset(pszSaveListStr[i], '\0', 200); } saveSearchLineToFile("nameserver", pszSaveListStr, "/etc/resolv.conf", 50, 200); nCntDNS = countAllLineToFile("/etc/resolv.conf", 50, 200); nCntDNS--; for (i = 0; i < nCntDNS; i++) { strcpy(pszDNSServer[i], pszSaveListStr[i]+11); pszDNSServer[i][strlen(pszDNSServer[i])-1] = '\0'; } for (i = 0; i < 50; i++) free(pszSaveListStr[i]); } /* nIdx´Â AliasingµÇ¾îÀÖ´Â ¼ø¹øÀ» ¶æÇÑ´Ù. Áï nIdx=1À϶§ */ /* ÀÌ°ÍÀÌ ÀǹÌÇÏ´Â °ÍÀº eth0:1ÀÌ´Ù. ¹øÈ£´Â ¼øÂ÷ÀûÀÌ´Ù. */ /* ÀÌ ¶§ eth0:1 ¿¡ ´ëÇÑ Á¤º¸´Â ifcfg-eth0:1 file¿¡ ÀúÀåµÈ´Ù. */ void getAliasIP(char *pszIPAddr, int nIdx) { char *pszSaveListStr[20]; int i, j = 0; char pszSaveFile[100]; FILE *fp; for (i = 0; i < 20; i++) { pszSaveListStr[i] = (char *)malloc(sizeof(char)*80); memset(pszSaveListStr[i], '\0', 80); } memset(pszSaveFile, '\0', 100); sprintf(pszSaveFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:%d", nIdx); if ((fp = fopen(pszSaveFile, "r")) == NULL) { printf("File Open Error!\n"); for (i = 0; i < 20; i++) free(pszSaveListStr[i]); return; } fclose(fp); saveSearchLineToFile("IPADDR", pszSaveListStr, pszSaveFile, 20, 80); for (i = 0; pszSaveListStr[0][i+7] != '\n'; i++) pszIPAddr[i] = pszSaveListStr[0][i+7]; for (i = 0; i < 20; i++) free(pszSaveListStr[i]); } /* À§¿Í ¸¶Âù°¡Áö·Î nIdx´Â AliasingµÇ¾îÀÖ´Â ¼ø¹øÀÌ´Ù. */ void getAliasNetmask(char *pszNetmask, int nIdx) { char *pszSaveListStr[20]; int i, j = 0; char pszSaveFile[100]; FILE *fp; for (i = 0; i < 20; i++) { pszSaveListStr[i] = (char *)malloc(sizeof(char)*80); memset(pszSaveListStr[i], '\0', 80); } memset(pszSaveFile, '\0', 100); sprintf(pszSaveFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:%d", nIdx); if ((fp = fopen(pszSaveFile, "r")) == NULL) { printf("File Open Error!\n"); for (i = 0; i < 20; i++) free(pszSaveListStr[i]); return; } fclose(fp); saveSearchLineToFile("NETMASK", pszSaveListStr, pszSaveFile, 20, 80); for (i = 0; pszSaveListStr[0][i+8] != '\n'; i++) pszNetmask[i] = pszSaveListStr[0][i+8]; for (i = 0; i < 20; i++) free(pszSaveListStr[i]); } /* Network cardÁ¤º¸´Â /proc/interrupts file¿¡¼­ ÀоîµéÀδÙ. */ /* interrupts fileÀº systemÀÇ ¿©·¯°¡Áö ¼³Á¤°ªµéÀÌ µé¾î°¡´Âµ¥ */ /* ÀÌ´Â »ç¿ëÀÚ°¡ Àý´ë settingÇؼ­´Â ¾ÈµÇ´Â fileÀÌ´Ù. */ /* Network card°¡ ¼³Ä¡µÇ¾úÀ» ¶§ µÎ°¡Áö file¿¡ ±× Á¤º¸°¡ ³ªÅ¸ */ /* ³ª´Âµ¥ Çϳª´Â /etc/conf.modules fileÀÌ°í ³ª¸ÓÁö Çϳª´Â */ /* interrupts fileÀÌ´Ù. settingÀ» ÇÒ ¶§´Â conf.modules file */ /* À» »ç¿ëÇÏ°í Á¤º¸¸¦ ÀоîµéÀÏ ¶§´Â interrupts fileÀ» »ç¿ëÇÑ´Ù. */ void getEthNetworkCard(char *pszSaveNetCard[], char *pszCardInfo[]) { FILE *fp; int i, j, nIdx, nCount, nCardCount = 0; char *pszSaveListStr[100]; char *pszSaveLine[4]; if ((fp = fopen("/proc/interrupts", "r")) == NULL) { printf("file open error!\n"); return; } fclose(fp); for (i = 0; i < 4; i++) { if ((pszSaveLine[i] = (char *)malloc(sizeof(char)*200)) == NULL) { printf("memory allocation error!\n"); exit(1); } memset(pszSaveLine[i], '\0', 200); } for (i = 0; i < 100; i++) { if ((pszSaveListStr[i] = (char *)malloc(sizeof(char)*200)) == NULL) { printf("memory allocation error!\n"); exit(1); } memset(pszSaveListStr[i], '\0', 200); } nCount = saveAllLineToFile(pszSaveListStr, "/proc/interrupts", 100, 200); for (i = 0, nIdx = 0; i < nCount; i++) { for (j = 0; j < 40; j++) { if (strstr(pszSaveListStr[i], pszCardInfo[j]) != (char *)NULL) { nCardCount++; strcpy(pszSaveLine[nIdx++], pszSaveListStr[i]); break; } } } if (nCardCount == 0) { strcpy(pszSaveNetCard[0], NO_SETTING); strcpy(pszSaveNetCard[1], NO_SETTING); strcpy(pszSaveNetCard[2], NO_SETTING); } else if (nCardCount == 1) { strcpy(pszSaveNetCard[0], pszSaveLine[0]+33); strcpy(pszSaveNetCard[1], NO_SETTING); strcpy(pszSaveNetCard[2], NO_SETTING); } else if (nCardCount == 2) { strcpy(pszSaveNetCard[0], pszSaveLine[0]+33); strcpy(pszSaveNetCard[1], pszSaveLine[1]+33); strcpy(pszSaveNetCard[2], NO_SETTING); } else { strcpy(pszSaveNetCard[0], pszSaveLine[0]+33); strcpy(pszSaveNetCard[1], pszSaveLine[1]+33); strcpy(pszSaveNetCard[2], pszSaveLine[2]+33); } for (i = 0; i < 4; i++) free(pszSaveLine[i]); for (i = 0; i < 100; i++) free(pszSaveListStr[i]); } /* ¿¹¸¦ µé¾î 172.31.0.0/16 À̶ó¸é nRangeÀÇ °ªÀº 16ÀÌ´Ù. */ /* ±×¸®°í pszStartIP´Â 172.31.0.0À̵Ǹç pszEndIP´Â 172.31.255.255 */ /* °¡ µÈ´Ù. ÀÌ °ª¿¡ ´ëÇÑ Á¤º¸´Â ÀÌ ÀÚ·áÀÇ ¸Ç ³¡¿¡ Ç¥·Î ¼³¸íÀ» ÇÏ°Ú´Ù. */ void calcIPRange(char *pszStartIP, char *pszEndIP, int nIPFourth, int nRange) { char pszSaveStartIP[4], pszSaveEndIP[4]; memset(pszSaveStartIP, '\0', 4); memset(pszSaveEndIP, '\0', 4); if (nIPFourth%nRange != 0) { sprintf(pszSaveStartIP, "%d", (nIPFourth/nRange)*nRange); sprintf(pszSaveEndIP, "%d", (nIPFourth/nRange)*nRange+nRange-1); } else { sprintf(pszSaveStartIP, "%d", nIPFourth); sprintf(pszSaveEndIP, "%d", nIPFourth+nRange-1); } strcat(pszStartIP, pszSaveStartIP); strcat(pszEndIP, pszSaveEndIP); } /* À§¿Í´Â ¹Ý´ë·Î pszStartIP¿Í pszEndIP¸¦ °¡Áö°í nRange°ªÀ» ¾Ë¾Æ³½´Ù. */ /* ¾Ë¾Æ³½ ¹üÀ§Á¤º¸´Â nRangeº¯¼ö¿¡ ÀúÀåµÇ´Âµ¥ ÀúÀåÀ» À§ÇØ Æ÷ÀÎÅ͸¦ */ /* ½è´Ù. ÀÌ´Â IPÀÇ ³×¹ø° ¹øÈ£¸¦ °¡Áö°í ÃßÃâÇÑ´Ù. Áï A, B class */ /* ´Â °í·ÁÇÏÁö ¾Ê¾Ò´Ù. */ void calcIPDiffToRange(char *pszStartIP, char *pszEndIP, int *nRange) { S_Addr pAddr; int i, nSaveRange; int nStart, nEnd; pAddr = separateAddress(pszStartIP); nStart = atoi(pAddr.pszFourth); pAddr = separateAddress(pszEndIP); nEnd = atoi(pAddr.pszFourth); nSaveRange = nEnd-nStart+1; for (i = 0; nSaveRange > 0; i++) nSaveRange /= 2; *nRange = 32-(i-1); } ---------------------------------------------------------------- 3.4. Class¸¸µé±â 3.4.1. ÀϹݳ×Æ®¿öÅ©°ü¸® ÀÌÁ¦ºÎÅÍ´Â º»°ÝÀûÀÎ network °ü¸® ±¸Çö¿¡ µé¾î°¡°Ú´Ù. Áö±ÝºÎÅÍ ³ª¿À´Â ´ëºÎºÐÀÇ Source µéÀº À§¿¡¼­ ÀÌ¹Ì ¼³¸íÇß´ø ºÎºÐµéÀÌ´Ù. µû¶ó¼­ Source¿¡ ´ëÇÑ ¼³¸íÀº °¡±ÞÀûÀÌ¸é »ý·«ÇÏ°í SourceÀ§ÁÖ·Î Project ¸¦ À̲ø¾î ³ª°¡°Ú´Ù. ÀϹݳ×Æ®¿öÅ©°ü¸®¸Þ´º¿¡´Â ³×Æ®¿öÅ©Ä«µå¼³Á¤, IP¹× Netmask,gateway¼³Á¤µî ÀϹÝÀûÀ¸·Î ¸®´ª½º¿¡¼­ ³×Æ®¿öÅ©¿¡ °üÇÑ ¼³Á¤À» ÇÒ ¶§ °¡Àå ¸ÕÀú ¼ÕÀ» º¸ ¾Æ¾ß ÇÏ´Â, ȤÀº °¡Àå ÀÚÁÖ Á¢ÇÏ°Ô µÇ´Â ºÎºÐµéÀ» ±¸ÇöÇغ¸¾Ò´Ù. ¿ì¼± Source¸¦ ÄÄÆÄÀÏ Çؼ­ Á÷Á¢ ½ÇÇà½ÃÄѺ¸±â ¹Ù¶õ´Ù. ÀÌÇØ°¡ »¡¶óÁú °Í ÀÌ´Ù. Source´Â ¾Õ¼­ ¼³¸íÇß´ø proc_file.c¿Í network.cºÎºÐÀÌ »ó´çºÎºÐ Æ÷ÇԵǾî ÀÖ´Ù. file ó¸® ·çƾ°ú network ó¸® ·çƾÀ» ¸ðµÎ ÀÌÇØÇß´Ù¸é ¾î·Á¿ò ¾øÀÌ Áö±Ý ÀÌÈÄÀÇ ºÎºÐµéµµ ÀÌÇØÇÒ ¼ö ÀÖÀ¸¸®¶ó »ý°¢ÇÑ´Ù. ---------------- < Source 3.4.1 clssGeneric.h > ---------------- #include class QLabel; class QLineEdit; class QComboBox; /* to combobox */ class QPushButton; class QFrame; class clssDefGeneric : public QWidget { Q_OBJECT public: clssDefGeneric(); ~clssDefGeneric(); private slots: void setApply(); void setCancel(); void printLabelFormat(QLabel *lblBold); private: QLabel *lblGenericNetworkTitle; QLabel *lblGateway; QLineEdit *leGateway; /* Eth0¿¡ ´ëÇÑ memberµé */ QLabel *lblEth0; QLabel *lblEth0IPAddr; QLineEdit *leEth0IPAddr; QLabel *lblEth0Netmask; QLineEdit *leEth0Netmask; QLabel *lblEth0Network; QLineEdit *leEth0Network; QLabel *lblEth0Broadcast; QLineEdit *leEth0Broadcast; QLabel *lblEth0NetCard; /* ³×Æ®¿öÅ© Ä«µå´Â combobox·Î ¼³Á¤ÇÏ°Ô ÇÑ´Ù. */ QComboBox *cbEthNetCard[3]; /* to combobox */ /* Eth1¿¡ ´ëÇÑ members */ QLabel *lblEth1; QLineEdit *leEth1IPAddr; QLineEdit *leEth1Netmask; QLineEdit *leEth1Network; QLineEdit *leEth1Broadcast; QLabel *lblEth1NetCard; /* Eth2¿¡ ´ëÇÑ members */ QLabel *lblEth2; QLineEdit *leEth2IPAddr; QLineEdit *leEth2Netmask; QLineEdit *leEth2Network; QLineEdit *leEth2Broadcast; QLabel *lblEth2NetCard; QPushButton *bttnCancel; QPushButton *bttnApply; QFrame *frEthInfo; QLabel *lblSeparator1; QLabel *lblSeparator2; }; ---------------------------------------------------------------- --------------- < Source 3.4.2 clssGeneric.cpp > --------------- #include #include #include #include #include #include #include #include #include #include "network.h" #include "proc_file.h" #include "clssGeneric.h" clssDefGeneric::clssDefGeneric() { char *pszIPAddr, *pszNetmask, *pszGateway; char *pszPrivate1IPAddr, *pszPrivate1Netmask, *pszPrivate2IPAddr; char *pszPrivate2Netmask; int i, j, nCardIdx; NetTab pNet, pNetPrivate1, pNetPrivate2; char *pszSaveListStr[2]; /* Linux¿¡¼­ Á¦°øÇÏ´Â PCI type Network Card Modules */ /* °¢ stringÀÇ ³¡¿¡ ÀÖ´Â °ýÈ£¾ÈÀÇ ³»¿ëÀÌ ¹Ù·Î module À̸§ÀÌ´Ù. */ const char *pszNetCard[40] = { " 3Com Vortex series (3c590, 3c592, 3c597, 3c595) (3c59x) ", " 3Com Boomerang (3c900, 3c905, 3c575) (3c59x) ", " 3Com Cyclone (3c905B) (3c59x) ", " Intel EtherExpress Pro 100 (eepro100) ", " HP J2585B, J2585A, J2970, J2973 (hp100) ", " HP J2573 (hp100) ", " Compex ReadyLink ENET100-VG4 (hp100) ", " Compex FreedomLine 100/VG (hp100) ", " IBM token ring (ibmtr) ", " NE2000 (PCI) (ne2k-pci) ", " AMD PCnet/PCI 79C970/PCnet32/PCnet/PCI II 79C970A (pcnet32) ", " PCnet/PCI II 79C971A (pcnet32) ", " Allied Telesyn AT2550 (rtl8139) ", " Genius GF100TXR (RTL8139) (rtl8139) ", " NDC Communications NE100TX-E (rtl8139) ", " RealTek RTL8129/8139 Fast (rtl8139) ", //15 " SMC Ultra/SMC UltraEZ/SMC Ultra32 (smc-ultra) ", " Compaq Netelligent 10 T PCI UTP (tlan) ", " Compaq Netelligent 10/100 TX PCI UTP (tlan) ", " Compaq Netelligent Integrated 10/100 TX UTP (tlan) ", " Compaq Netelligent 10/100 TX Embedded UTP (tlan) ", " Compaq Netelligent 10/100 TX UTP (tlan) ", " Compaq Netelligent 10 T/2 PCI UTP/Coax (tlan) ", " Accton EtherDuo PCI/Accton EN1207 (tulip) ", " Adaptec ANA6901/C/Adaptec ANA6911/TX (tulip) ", " C-NET CNE-935 (tulip) ", " Cogent EM100/Cogent EM110/Cogent EM400 (tulip) ", " Cogent EM960/Cogent EM964 Quartet (tulip) ", " Danpex EN-9400P3 (tulip) ", " D-Link DFE500-Tx/D-Link DE-530CT (tulip) ", " Linksys EtherPCI (tulip) ", " Kingston EtherX KNT40T/Kingston EtherX KNE100TX (tulip) ", " Netgear FX310 TX 10/100 (tulip) ", " SMC EtherPower/SMC 8432BT/ SMC Ether Power10/100 (tulip) ", " Surecom EP-320X (tulip) ", " Thomas Conrad TC5048 (tulip) ", " Znyx ZX312 EtherAction/Znyx ZX314/ZX315 (tulip) ", " Znyx ZX342/ZX344/ZX345/ZX346/ZX348 (tulip) ", " Znyx ZX351 (tulip) ", " ¼¼ÆõǾîÀÖÁö ¾Ê½À´Ï´Ù! (No Setting)" }; if (((pszIPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszNetmask = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate1IPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate1Netmask = (char *)malloc(sizeof(char)*18)) == NULL)|| ((pszPrivate2IPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate2Netmask = (char *)malloc(sizeof(char)*18)) == NULL)|| ((pszGateway = (char *)malloc(sizeof(char)*18)) == NULL)) { emit printf("DefGeneric Class/Network: Memory ÇÒ´ç ¿¡·¯\n"); exit(1); } /* ù¹ø° ³×Æ®¿öÅ© Ä«µåÀÇ ¼Ó¼º(IP, Netmask)¸¦ ÀúÀåÇÒ º¯¼ö ÃʱâÈ­ */ memset(pszIPAddr, '\0', 18); memset(pszNetmask, '\0', 18); /* µÎ¹ø° ³×Æ®¿öÅ© Ä«µåÀÇ ¼Ó¼º(IP, Netmask)¸¦ ÀúÀåÇÒ º¯¼ö ÃʱâÈ­ */ memset(pszPrivate1IPAddr, '\0', 18); memset(pszPrivate1Netmask, '\0', 18); /* ¼¼¹ø° ³×Æ®¿öÅ© Ä«µåÀÇ ¼Ó¼º(IP, Netmask)¸¦ ÀúÀåÇÒ º¯¼ö ÃʱâÈ­ */ memset(pszPrivate2IPAddr, '\0', 18); memset(pszPrivate2Netmask, '\0', 18); memset(pszGateway, '\0', 18); /* gateway, IP, Netmask µîÀ» ¾ò´Â´Ù. */ getCurrentGateway(pszGateway); getCurrentIPAddr(pszIPAddr); getCurrentNetmask(pszNetmask); /* network°ú broadcast¸¦ °è»êÇÑ´Ù. */ pNet = calculateNetMaskTab(pszIPAddr, pszNetmask); getPrivate1Netmask(pszPrivate1Netmask); getPrivate1IPAddr(pszPrivate1IPAddr); pNetPrivate1 = calculateNetMaskTab(pszPrivate1IPAddr, pszPrivate1Netmask); getPrivate2Netmask(pszPrivate2Netmask); getPrivate2IPAddr(pszPrivate2IPAddr); pNetPrivate2 = calculateNetMaskTab(pszPrivate2IPAddr, pszPrivate2Netmask); /***********************/ lblGenericNetworkTitle = new QLabel("Network Setting (ÀϹÝÀûÀÎ ³×Æ®¿öÅ© ¼³Á¤)", this); lblGenericNetworkTitle->setGeometry(20, 20, 400, 20); // printLabelFormat(lblGenericNetworkTitle); /***********************/ frEthInfo = new QFrame(this); frEthInfo->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); frEthInfo->setGeometry(25, 50, 700, 362); lblGateway = new QLabel("°ÔÀÌÆ®¿þÀÌ", frEthInfo); lblGateway->setGeometry(10, 15, 80, 20); leGateway = new QLineEdit(frEthInfo); leGateway->setGeometry(90, 15, 150, 20); /* getCurrentGatewayÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¿© ¾òÀº gateway¸¦ ÆíÁý¹Ú½º */ /* ¿¡ »ðÀÔÇÑ´Ù. */ leGateway->setText(pszGateway); /* separator¸¦ ±×¸°´Ù. */ lblSeparator1 = new QLabel(frEthInfo); lblSeparator1->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); lblSeparator1->setGeometry(20, 45, 630, 2); /******** Ethernet Card 0 ********/ lblEth0 = new QLabel("ù¹ø° ÀÌ´õ³ÝÄ«µå", frEthInfo); lblEth0->setGeometry(90, 10+50, 100, 20); lblEth0IPAddr = new QLabel("IP ÁÖ¼Ò ", frEthInfo); lblEth0IPAddr->setGeometry(10, 40+50, 80, 20); leEth0IPAddr = new QLineEdit(frEthInfo); leEth0IPAddr->setGeometry(90, 40+50, 150, 20); leEth0IPAddr->setText(pszIPAddr); /*** text -> proc ***/ lblEth0Netmask = new QLabel("Netmask ", frEthInfo); lblEth0Netmask->setGeometry(10, 40+30+50, 80, 20); leEth0Netmask = new QLineEdit(frEthInfo); leEth0Netmask->setGeometry(90, 40+30+50, 150, 20); leEth0Netmask->setText(pszNetmask); lblEth0Network = new QLabel("Network ", frEthInfo); lblEth0Network->setGeometry(10, 40+60+50, 80, 20); leEth0Network = new QLineEdit(frEthInfo); leEth0Network->setGeometry(90, 40+60+50, 150, 20); /* NetworkÀº IP¿Í NetmaskÀÇ °ªÀ» Á¶ÇÕÇÏ¿© ³ª¿Â °ªÀ̹ǷΠÀÌ´Â */ /* µû·Î ¼³Á¤ÇÒ ÇÊ¿ä°¡ ¾ø´Â ºÎºÐÀ̹ǷΠÆíÁý¹Ú½º¸¦ editÇÒ ¼ö */ /* ¾øµµ·Ï ¼³Á¤ÇصдÙ.(setEnabled(0)) */ leEth0Network->setEnabled(0); /* pNet = calculateNetMaskTab(pszIPAddr, pszNetmask);¸¦ ÅëÇÏ¿© */ /* ¾ò¾î³½ pNet.pszNetwork°ªÀ» ÆíÁý¹Ú½º¿¡ »ðÀÔ. */ leEth0Network->setText(pNet.pszNetwork); lblEth0Broadcast = new QLabel("Broadcast ", frEthInfo); lblEth0Broadcast->setGeometry(10, 40+90+50, 80, 20); leEth0Broadcast = new QLineEdit(frEthInfo); leEth0Broadcast->setGeometry(90, 40+90+50, 150, 20); leEth0Broadcast->setEnabled(0); leEth0Broadcast->setText(pNet.pszBroadcast); lblSeparator2 = new QLabel(frEthInfo); lblSeparator2->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); lblSeparator2->setGeometry(20, 40+90+50+40, 630, 2); /*** text -> proc ***/ /*********************************/ /******** Ethernet Card 1 ********/ lblEth1 = new QLabel("µÎ¹ø° ÀÌ´õ³ÝÄ«µå", frEthInfo); lblEth1->setGeometry(300, 10+50, 100, 20); leEth1IPAddr = new QLineEdit(frEthInfo); leEth1IPAddr->setGeometry(300, 40+50, 150, 20); leEth1IPAddr->setText(pszPrivate1IPAddr); /*** text -> proc ***/ leEth1Netmask = new QLineEdit(frEthInfo); leEth1Netmask->setGeometry(300, 40+30+50, 150, 20); leEth1Netmask->setText(pszPrivate1Netmask); /*** text -> proc ***/ leEth1Network = new QLineEdit(frEthInfo); leEth1Network->setGeometry(300, 40+60+50, 150, 20); leEth1Broadcast = new QLineEdit(frEthInfo); leEth1Broadcast->setGeometry(300, 40+90+50, 150, 20); leEth1Network->setEnabled(0); leEth1Broadcast->setEnabled(0); if (strlen(pszPrivate1IPAddr) >= 7) { leEth1Network->setText(pNetPrivate1.pszNetwork); leEth1Broadcast->setText(pNetPrivate1.pszBroadcast); } /*********************************/ /******** Ethernet Card 2 ********/ lblEth2 = new QLabel("¼¼¹ø° ÀÌ´õ³ÝÄ«µå", frEthInfo); lblEth2->setGeometry(520, 10+50, 100, 20); leEth2IPAddr = new QLineEdit(frEthInfo); leEth2IPAddr->setGeometry(520, 40+50, 150, 20); leEth2IPAddr->setText(pszPrivate2IPAddr); /*** text -> proc ***/ leEth2Netmask = new QLineEdit(frEthInfo); leEth2Netmask->setGeometry(520, 40+30+50, 150, 20); leEth2Netmask->setText(pszPrivate2Netmask); /*** text -> proc ***/ leEth2Network = new QLineEdit(frEthInfo); leEth2Network->setGeometry(520, 40+60+50, 150, 20); leEth2Broadcast = new QLineEdit(frEthInfo); leEth2Broadcast->setGeometry(520, 40+90+50, 150, 20); leEth2Network->setEnabled(0); leEth2Broadcast->setEnabled(0); if (strlen(pszPrivate2IPAddr) >= 7) { leEth2Broadcast->setText(pNetPrivate2.pszBroadcast); leEth2Network->setText(pNetPrivate2.pszNetwork); } /*********************************/ for (i = 0; i < 2; i++) { pszSaveListStr[i] = (char *)malloc(sizeof(char)*200); memset(pszSaveListStr[i], '\0', 200); } /*********************************/ lblEth0NetCard = new QLabel("Ethernet 0 Ä«µå", frEthInfo); lblEth0NetCard->setGeometry(10, 40+90+70+60, 90, 20); cbEthNetCard[0] = new QComboBox(frEthInfo, "comboBox_Eth0"); cbEthNetCard[0]->setGeometry(110, 40+90+70+60, 470, 20); for (i = 0; i < 40; i++) cbEthNetCard[0]->insertItem(pszNetCard[i]); cbEthNetCard[0]->setAutoResize(FALSE); /* conf.modules file¿¡¼­ CardÁ¤º¸¸¦ ã¾Æ ¿ÜºÎº¯¼öÀÎ */ /* pszNetConfNetCard¿¡ ÀúÀåÇÑ´Ù. */ if (saveSearchLineToFile("alias eth0", pszSaveListStr, "/etc/conf.modules", 80, 200)) { strcpy(pszNetConfNetCard[0], pszSaveListStr[0]+11); pszNetConfNetCard[0][strlen(pszNetConfNetCard[0])-1] = '\0'; } /* À§¿¡¼­ Á¤ÀÇÇÑ pszNetCard, Áï Network Card Modules¿Í ÀÏ */ /* Ä¡µÇ´Â Card°¡ conf.modules file¿¡ ÀÖ´ÂÁö °Ë»öÇÏ°í */ if (strlen(pszIPAddr) >= 7) { for (nCardIdx = 0; nCardIdx < 40; nCardIdx++) if (strstr(pszNetCard[nCardIdx], pszNetConfNetCard[0]) != (char *)NULL) break; /* ¸¸¾à ¾ø´Ù¸é No Setting¹®ÀÚ¿­À» combobox¿¡ SettingÇÑ´Ù. */ if (strlen(pszNetConfNetCard[0]) < 2) nCardIdx = 39; cbEthNetCard[0]->setCurrentItem(nCardIdx); } else { nCardIdx = 39; cbEthNetCard[0]->setCurrentItem(nCardIdx); } /*********************************/ lblEth1NetCard = new QLabel("Ethernet 1 Ä«µå", frEthInfo); lblEth1NetCard->setGeometry(10, 40+90+70+90, 90, 20); cbEthNetCard[1] = new QComboBox(frEthInfo, "comboBox_Eth1"); cbEthNetCard[1]->setGeometry(110, 40+90+70+90, 470, 20); for (i = 0; i < 40; i++) cbEthNetCard[1]->insertItem(pszNetCard[i]); cbEthNetCard[1]->setAutoResize(FALSE); for (i = 0; i < 2; i++) memset(pszSaveListStr[i], '\0', 200); if (saveSearchLineToFile("alias eth1", pszSaveListStr, "/etc/conf.modules", 80, 200)) { strcpy(pszNetConfNetCard[1], pszSaveListStr[0]+11); pszNetConfNetCard[1][strlen(pszNetConfNetCard[1])-1] = '\0'; } if (strlen(pszPrivate1IPAddr) >= 7) { for (nCardIdx = 0; nCardIdx < 40; nCardIdx++) if (strstr(pszNetCard[nCardIdx], pszNetConfNetCard[1]) != (char *)NULL) break; if (strlen(pszNetConfNetCard[1]) < 2) nCardIdx = 39; cbEthNetCard[1]->setCurrentItem(nCardIdx); } else { nCardIdx = 39; cbEthNetCard[1]->setCurrentItem(nCardIdx); } /**********************************/ lblEth2NetCard = new QLabel("Ethernet 2 Ä«µå", frEthInfo); lblEth2NetCard->setGeometry(10, 40+90+70+120, 90, 20); cbEthNetCard[2] = new QComboBox(frEthInfo, "comboBox_Eth2"); cbEthNetCard[2]->setGeometry(110, 40+90+70+120, 470, 20); for (i = 0; i < 40; i++) cbEthNetCard[2]->insertItem(pszNetCard[i]); cbEthNetCard[2]->setAutoResize(FALSE); for (i = 0; i < 2; i++) memset(pszSaveListStr[i], '\0', 200); if (saveSearchLineToFile("alias eth2", pszSaveListStr, "/etc/conf.modules", 80, 200)) { strcpy(pszNetConfNetCard[2], pszSaveListStr[0]+11); pszNetConfNetCard[2][strlen(pszNetConfNetCard[2])-1] = '\0'; } if (strlen(pszPrivate2IPAddr) >= 7) { for (nCardIdx = 0; nCardIdx < 40; nCardIdx++) if (strstr(pszNetCard[nCardIdx], pszNetConfNetCard[2]) != (char *)NULL) break; if (strlen(pszNetConfNetCard[2]) < 2) nCardIdx = 39; cbEthNetCard[2]->setCurrentItem(nCardIdx); } else { nCardIdx = 39; cbEthNetCard[2]->setCurrentItem(nCardIdx); } cbEthNetCard[2]->setGeometry(110, 40+90+70+125, 470, 20); /*************************************/ bttnApply = new QPushButton("Àû ¿ë", this); bttnApply->setGeometry(150, 50+60+90+70+120+80, 150, 30); QObject::connect(bttnApply, SIGNAL(clicked()), this, SLOT(setApply())); bttnCancel = new QPushButton("Ãë ¼Ò", this); bttnCancel->setGeometry(450, 50+60+90+70+120+80, 150, 30); QObject::connect(bttnCancel, SIGNAL(clicked()), this, SLOT(setCancel())); /************************************/ for (i = 0; i < 2; i++) free(pszSaveListStr[i]); free(pszIPAddr); free(pszNetmask); free(pszPrivate1IPAddr); free(pszPrivate1Netmask); free(pszPrivate2IPAddr); free(pszPrivate2Netmask); free(pszGateway); } clssDefGeneric::~clssDefGeneric() { int i; delete lblEth0; delete lblEth0IPAddr; delete lblEth0Netmask; delete lblEth0Network; delete lblEth0Broadcast; delete leEth0IPAddr; delete leEth0Netmask; delete leEth0Network; delete leEth0Broadcast; delete lblEth1; delete leEth1IPAddr; delete leEth1Netmask; delete leEth1Network; delete leEth1Broadcast; delete lblEth2; delete leEth2IPAddr; delete leEth2Netmask; delete leEth2Network; delete leEth2Broadcast; delete lblGateway; delete leGateway; delete lblSeparator1; delete lblSeparator2; for (i = 0; i < 3; i++) delete cbEthNetCard[i]; delete lblEth0NetCard; delete lblEth1NetCard; delete lblEth2NetCard; delete bttnCancel; delete bttnApply; delete lblGenericNetworkTitle; delete frEthInfo; } /* Network¿¡ °üÇÑ SettingÀÌ À§ÀÇ ¸î½ÊÁÙ·Î ³¡³ª´Â °ÍÀº ¾Æ´Ï´Ù. */ /* Network ¼³Á¤°ªÀÌ º¯ÇÒ ¶§ °°ÀÌ º¯°æµÇ´Â °ü·Ã fileµéµµ ´Ù·ïÁÖ¾î */ /* ¾ßÇϱ⠶§¹®ÀÌ´Ù. */ /* ÀÌ ÇÔ¼ö´Â ¼³Á¤°ªÀ» º¯°æÇÏ°í Àû¿ë¹öÆ°À» ´­·¶À» ¶§, ±×·¯ÇÑ °ü·Ã */ /* fileµéÀ» °ü¸®ÇÑ´Ù. */ void clssDefGeneric::setApply() { char *pszIfCfgEthFile = "DEVICE=%s\nIPADDR=%s\nNETMASK=%s\n\ NETWORK=%s\nBROADCAST=%s\nONBOOT=yes\n"; char *pszNetworkFile = "NETWORKING=yes\nFORWARD_IPV4=true\n\ HOSTNAME=%s.%s\nDOMAINNAME=%s\nGATEWAY=%s\nGATEWAYDEV=eth0\n"; char pszOptions[95]; char *pszSaveCardLine[3], pszSaveHostName[256], pszSaveDomainName[256]; NetTab pNet, pNetPrivate1, pNetPrivate2; FILE *fp; S_Addr pAddr, pSaveAddr; char pszTmpSearch[100]; char pszTmpInsert[100]; char pszSaveIP[18]; int i; memset(pszSaveIP, '\0', 18); getCurrentIPAddr(pszSaveIP); pSaveAddr = separateAddress(pszSaveIP); pNet = calculateNetMaskTab((char *)leEth0IPAddr->text(), (char *)leEth0Netmask->text()); pNetPrivate1 = calculateNetMaskTab((char *)leEth1IPAddr->text(), (char *)leEth1Netmask->text()); pNetPrivate2 = calculateNetMaskTab((char *)leEth2IPAddr->text(), (char *)leEth2Netmask->text()); memset(pszSaveHostName, '\0', 256); memset(pszSaveDomainName, '\0', 256); getCurrentHostName(pszSaveHostName, pszSaveDomainName); leEth0Network->setText(pNet.pszNetwork); leEth0Broadcast->setText(pNet.pszBroadcast); leEth1Network->setText(pNetPrivate1.pszNetwork); leEth1Broadcast->setText(pNetPrivate1.pszBroadcast); leEth2Network->setText(pNetPrivate2.pszNetwork); leEth2Broadcast->setText(pNetPrivate2.pszBroadcast); /* ifcfg-eth0, ifcfg-eth1, ifcfg-eth2 fileµéÀ» ´Ù·é´Ù. */ fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth0", "w"); fprintf(fp, pszIfCfgEthFile, "eth0", leEth0IPAddr->text(), leEth0Netmask->text(), leEth0Network->text(), leEth0Broadcast->text()); fclose(fp); if (strlen((char *)leEth1IPAddr->text()) >= 7) { char pszPrivate1IPAddr[20]; char pszCommand[150]; fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth1", "w"); fprintf(fp, pszIfCfgEthFile, "eth1", leEth1IPAddr->text(), leEth1Netmask->text(), leEth1Network->text(), leEth1Broadcast->text()); fclose(fp); } if (strlen((char *)leEth2IPAddr->text()) >= 7) { char pszPrivate2IPAddr[20]; char pszCommand[150]; fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth2", "w"); fprintf(fp, pszIfCfgEthFile, "eth2", leEth2IPAddr->text(), leEth2Netmask->text(), leEth2Network->text(), leEth2Broadcast->text()); fclose(fp); } fp = fopen("/etc/sysconfig/network", "w"); fprintf(fp, pszNetworkFile, pszSaveHostName, pszSaveDomainName, pszSaveDomainName, leGateway->text()); fclose(fp); for (i = 0; i < 3; i++) { if ((pszSaveCardLine[i] = (char *)malloc(sizeof(char)*50)) == NULL) { printf("pszSaveCardLine Memory Error!\n"); exit(1); } memset(pszSaveCardLine[i], '\0', 50); } for (i = 0; i < 3; i++) { sprintf(pszSaveCardLine[i], "alias eth%d ", i); if (cbEthNetCard[i]->currentItem() >= 0 && cbEthNetCard[i]->currentItem() <= 2) strcat(pszSaveCardLine[i], "3c59x"); else if (cbEthNetCard[i]->currentItem() == 3) strcat(pszSaveCardLine[i], "eepro100"); else if (cbEthNetCard[i]->currentItem() >= 4 && cbEthNetCard[i]->currentItem() <= 7) strcat(pszSaveCardLine[i], "hp100"); else if (cbEthNetCard[i]->currentItem() == 8) strcat(pszSaveCardLine[i], "ibmtr"); else if (cbEthNetCard[i]->currentItem() == 9) strcat(pszSaveCardLine[i], "ne2k-pci"); else if (cbEthNetCard[i]->currentItem() == 10 || cbEthNetCard[i]->currentItem() == 11) strcat(pszSaveCardLine[i], "pcnet32"); else if (cbEthNetCard[i]->currentItem() >= 12 && cbEthNetCard[i]->currentItem() <= 15) strcat(pszSaveCardLine[i], "rtl8139"); else if (cbEthNetCard[i]->currentItem() == 16) strcat(pszSaveCardLine[i], "smc-ultra"); else if (cbEthNetCard[i]->currentItem() >= 17 || cbEthNetCard[i]->currentItem() <= 22) strcat(pszSaveCardLine[i], "tlan"); else if (cbEthNetCard[i]->currentItem() >= 23 || cbEthNetCard[i]->currentItem() <= 38) strcat(pszSaveCardLine[i], "tulip"); } for (i = 0; i < 3; i++) strcat(pszSaveCardLine[i], "\n"); /* conf.modules fileÀ» º¯°æÇÑ´Ù. proc_file.c¿¡¼­ ¼³¸íÇÑ ¹Ù¿Í */ /* °°ÀÌ ¹Ù·Î ¾Æ·¡ÇÔ¼ö°¡ ÀǹÌÇÏ´Â °ÍÀº */ /* conf.modules file¿¡¼­ ÃÖ´ë 200line, 100column À» Çã¿ëÇÏ¿© */ /* alias eth0¶ó´Â ¹®ÀÚ¿­ÀÌ Æ÷ÇÔµÈ lineÀ» ã¾Æ Network Card */ /* °ªÀÎ pszSaveCardLine[0]À» ´ëÄ¡½ÃÄѶó ¶ó´Â ¶æÀÌ´Ù. */ addOnNotExistChangeOnExist(pszSaveCardLine[0], "alias eth0", "/etc/conf.modules", 200, 100); addOnNotExistChangeOnExist(pszSaveCardLine[1], "alias eth1", "/etc/conf.modules", 200, 100); addOnNotExistChangeOnExist(pszSaveCardLine[2], "alias eth2", "/etc/conf.modules", 200, 100); if (cbEthNetCard[0]->currentItem() == 39) insertStrToFile("", "alias eth0", "/etc/conf.modules", 200, 100); if (cbEthNetCard[1]->currentItem() == 39) insertStrToFile("", "alias eth1", "/etc/conf.modules", 200, 100); if (cbEthNetCard[2]->currentItem() == 39) insertStrToFile("", "alias eth2", "/etc/conf.modules", 200, 100); for (i = 0; i < 3; i++) free(pszSaveCardLine[i]); if (cbEthNetCard[0]->currentItem() == 39) { /* ¸¸¾à Eth0 Card°¡ SettingµÇ¾î ÀÖÁö ¾Ê´Ù¸é ifcfg-eth0 file */ /* À» »èÁ¦ÇÏ°í °¢ Network¼³Á¤°ªµéÀº °ø¹é¹®ÀÚ¿­·Î ³õ´Â´Ù. */ system("rm -f /etc/sysconfig/network-scripts/ifcfg-eth0"); leEth0IPAddr->setText(""); leEth0Netmask->setText(""); leEth0Network->setText(""); leEth0Broadcast->setText(""); } if (cbEthNetCard[1]->currentItem() == 39) { system("rm -f /etc/sysconfig/network-scripts/ifcfg-eth1"); leEth1IPAddr->setText(""); leEth1Netmask->setText(""); leEth1Network->setText(""); leEth1Broadcast->setText(""); } if (cbEthNetCard[2]->currentItem() == 39) { system("rm -f /etc/sysconfig/network-scripts/ifcfg-eth2"); leEth2IPAddr->setText(""); leEth2Netmask->setText(""); leEth2Network->setText(""); leEth2Broadcast->setText(""); } /**************************************/ system("cp -f /etc/sysconfig/network-scripts/ifcfg-eth0 \ /etc/sysconfig/network-scripts/ifcfg-eth0.org\n"); system("cp -f /etc/sysconfig/network-scripts/ifcfg-eth1 \ /etc/sysconfig/network-scripts/ifcfg-eth1.org\n"); system("cp -f /etc/sysconfig/network-scripts/ifcfg-eth2 \ /etc/sysconfig/network-scripts/ifcfg-eth2.org\n"); system("cp -f /etc/sysconfig/network /etc/sysconfig/network.org\n"); system("cp -f /etc/conf.modules /etc/conf.modules.org\n"); system("cp -f /etc/resolv.conf /etc/resolv.conf.org\n"); system("/etc/rc.d/init.d/network \ stop;/etc/rc.d/init.d/network start\n"); } /* Ãë¼Ò¹öÆ°À» ´­·¶À» ¶§¿¡´Â ¼³Á¤Çß´ø °ªµéÀÌ Á¦ÀÚ¸®¸¦ ã¾Æ°£´Ù. */ /* ¹°·Ð Àû¿ë¹öÆ°À» ´©¸£°í ´Ù½Ã Ãë¼Ò¹öÆ°À» ´©¸£¸é ¼Ò¿ëÀÌ ¾ø´Ù. */ void clssDefGeneric::setCancel() { char *pszIPAddr, *pszNetmask, *pszGateway; char **pszHostName, *pszDomainName; char *pszPrivate1IPAddr, *pszPrivate1Netmask; char *pszPrivate2IPAddr, *pszPrivate2Netmask; NetTab pNet, pNetPrivate1, pNetPrivate2; char *pszSaveListStr[2]; if (((pszIPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszNetmask = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate1IPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate1Netmask = (char *)malloc(sizeof(char)*18)) == NULL)|| ((pszPrivate2IPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate2Netmask = (char *)malloc(sizeof(char)*18)) == NULL)|| ((pszGateway = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszHostName = (char *)malloc(sizeof(char)*256)) == NULL) || ((pszDomainName = (char *)malloc(sizeof(char)*256)) == NULL)) { emit printf("DefGeneric Class/Network: Memory ÇÒ´ç ¿¡·¯\n"); exit(1); } memset(pszIPAddr, '\0', 18); memset(pszNetmask, '\0', 18); memset(pszPrivate1IPAddr, '\0', 18); memset(pszPrivate1Netmask, '\0', 18); memset(pszPrivate2IPAddr, '\0', 18); memset(pszPrivate2Netmask, '\0', 18); memset(pszGateway, '\0', 18); memset(pszHostName, '\0', 256); memset(pszDomainName, '\0', 256); getCurrentHostName(pszHostName, pszDomainName); getCurrentGateway(pszGateway); getCurrentIPAddr(pszIPAddr); getCurrentNetmask(pszNetmask); pNet = calculateNetMaskTab(pszIPAddr, pszNetmask); getPrivate1Netmask(pszPrivate1Netmask); getPrivate1IPAddr(pszPrivate1IPAddr); pNetPrivate1 = calculateNetMaskTab(pszPrivate1IPAddr, pszPrivate1Netmask); getPrivate2Netmask(pszPrivate2Netmask); getPrivate2IPAddr(pszPrivate2IPAddr); pNetPrivate2 = calculateNetMaskTab(pszPrivate2IPAddr, pszPrivate2Netmask); /***** lineeditbox init: proc -> segmentation fault *****/ leGateway->setText(pszGateway);; leEth0IPAddr->setText(pszIPAddr); leEth0Netmask->setText(pszNetmask); leEth0Network->setText(pNet.pszNetwork); leEth0Broadcast->setText(pNet.pszBroadcast); leEth1IPAddr->setText(pszPrivate1IPAddr); leEth1Netmask->setText(pszPrivate1Netmask); leEth1Network->setText(pNetPrivate1.pszNetwork); leEth1Broadcast->setText(pNetPrivate1.pszBroadcast); leEth2IPAddr->setText(pszPrivate2IPAddr); leEth2Netmask->setText(pszPrivate2Netmask); leEth2Network->setText(pNetPrivate2.pszNetwork); leEth2Broadcast->setText(pNetPrivate2.pszBroadcast); } /* TitleÀ» ³ªÅ¸³»ÁÖ´Â ºÎºÐÀÌ´Ù. º°·Î Áß¿äÇÏÁö ¾ÊÀº ºÎºÐÀ̹ǷΠ*/ /* ¼³¸íÀº »ý·«ÇÏ°Ú´Ù. */ void clssDefGeneric::printLabelFormat(QLabel *lblBold) { QPalette p = QWidget::palette(); QColorGroup n = palette().normal(); QColorGroup g(n.background(), n.foreground(), n.light(), n.dark(), n.mid(), n.background(), n.base()); p.setNormal(g); setPalette(p); lblBold->setPalette(p); lblBold->setMargin(3); QFont bold = *QApplication::font(); bold.setBold(TRUE); bold.setPointSize(bold.pointSize()+2); lblBold->setFont(bold); lblBold->setFixedSize(lblBold->sizeHint()); lblBold->setFixedSize(lblBold->sizeHint()); } ---------------------------------------------------------------- /* ¿©±âºÎÅÍ´Â ÁÖ¸Þ´º, Áï Ç®´Ù¿î¸Þ´º¿Í icon boxµîÀ» Á¤ÀÇÇÏ´Â ºÎºÐ */ /* ÀÌ´Ù. ÀÌ ºÎºÐµé¿¡ ´ëÇÑ ¼³¸íÀº 2.2Àå¿¡¼­ ¸ðµÎ ¼³¸íÇßÀ¸¹Ç·Î */ /* ¼³¸íÀ» »ý·«ÇÏ°Ú´Ù. */ --------------- < Source 3.4.3 Network_menu.h > ---------------- #include class QMenuBar; class QPopupMenu; class QToolBar; class clssDefGeneric; class clssNetwork : public QMainWindow { Q_OBJECT public: clssNetwork(); ~clssNetwork(); public slots: void funcGenericNetwork(); void funcDNS(); void funcAlias(); void funcQuit(); protected: private: QMenuBar *mnuMainBar; QPopupMenu *mnuNetwork; QToolBar *tbNetwork; clssDefGeneric *clssGeneric; }; ---------------------------------------------------------------- -------------- < Source 3.4.4 Network_menu.cpp > --------------- #include #include #include #include #include #include #include #include #include "Network_menu.h" #include "clssGeneric.h" //#include "clssDNS.h" //#include "clssAlias.h" #ifndef GENERIC_TOOLTIP #define GENERIC_TOOLTIP "ÀϹÝÀûÀÎ ³×Æ®¿öÅ© ¼³Á¤" #define DNS_TOOLTIP "DNS ¼³Á¤" #define ALIAS_TOOLTIP "Alias ¼³Á¤" #endif clssNetwork::clssNetwork() { QPixmap iconGeneric, iconDNS, iconAlias; iconGeneric.load("./generic.gif"); iconDNS.load("./dns.gif"); iconAlias.load("./alias.gif"); qApp->setStyle(WindowsStyle); mnuNetwork = new QPopupMenu; mnuNetwork->insertItem("ÀÏ¹Ý ³×Æ®¿öÅ© °ü¸®", this, SLOT(funcGenericNetwork())); mnuNetwork->insertItem("DNS °ü¸®", this, SLOT(funcDNS())); mnuNetwork->insertItem("IP-Aliasing °ü¸®", this, SLOT(funcAlias())); mnuNetwork->insertSeparator(); mnuNetwork->insertItem("Á¾·á", this, SLOT(funcQuit())); mnuMainBar = new QMenuBar(this); mnuMainBar->insertItem(" ³×Æ®¿öÅ© ", mnuNetwork); tbNetwork = new QToolBar(this); tbNetwork->setOrientation(tbNetwork->Horizontal); QToolButton *tbttnGeneric = new QToolButton(iconGeneric, GENERIC_TOOLTIP, 0, this, SLOT(funcGenericNetwork()), tbNetwork, "generic"); QToolButton *tbttnDNS = new QToolButton(iconDNS, DNS_TOOLTIP, 0, this, SLOT(funcDNS()), tbNetwork, "dns"); QToolButton *tbttnAlias = new QToolButton(iconAlias, ALIAS_TOOLTIP, 0, this, SLOT(funcAlias()), tbNetwork, "alias"); } clssNetwork::~clssNetwork() { } void clssNetwork::funcGenericNetwork() { clssGeneric = new clssDefGeneric(); clssGeneric->setGeometry(150, 150, 750, 550); clssGeneric->show(); } void clssNetwork::funcDNS() { } void clssNetwork::funcAlias() { } void clssNetwork::funcQuit() { exit(0); } ---------------------------------------------------------------- --------------------- < Makefile 3.4. > ------------------------ PROGS = main_menu LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm CC = g++ GCC = gcc INCLUDE = -I/usr/lib/qt/include C_FLAG = -pipe -DNO_DEBUG -O2 CFLAGS = $(INCLUDE) $(C_FLAG) SYSCONF_LINK = $(CC) SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) OTHER_OBJS = \ network.o \ proc_file.o MNU_OBJS = \ main_menu.o \ Network_menu_moc.o \ Network_menu.o \ clssGeneric.o \ clssGeneric_moc.o all: $(PROGS) clean: rm -f *.o rm -f main_menu rm -f *_moc.* ############# COMPILE ############# network.o: network.c $(CC) -c network.c -o $@ proc_file.o: proc_file.c $(CC) -c proc_file.c -o $@ main_menu.o: main_menu.cpp $(CC) -c main_menu.cpp $(CFLAGS) -o $@ Network_menu_moc.cpp: Network_menu.h $(MOC) Network_menu.h -o Network_menu_moc.cpp Network_menu_moc.o: Network_menu_moc.cpp $(CC) -c Network_menu_moc.cpp $(CFLAGS) -o $@ Network_menu.o: Network_menu.cpp $(CC) -c Network_menu.cpp $(CFLAGS) -o $@ clssGeneric_moc.cpp: clssGeneric.h $(MOC) clssGeneric.h -o clssGeneric_moc.cpp clssGeneric_moc.o: clssGeneric_moc.cpp $(CC) -c clssGeneric_moc.cpp $(CFLAGS) -o $@ clssGeneric.o: clssGeneric.cpp $(CC) -c clssGeneric.cpp $(CFLAGS) -o $@ main_menu: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ ---------------------------------------------------------------- 3.4.2. DNS°ü¸® ÀÌ ÀåÀº È£½ºÆ® ¹× µµ¸ÞÀÎ À̸§ ¼³Á¤, ±×¸®°í DNS Server¸¦ ¼ÂÆÃÇÏ´Â ¹æ¹ý¿¡ ´ëÇÑ ³»¿ëÀÌ´Ù. ÀÚ¼¼ÇÑ ¼³¸íÀº »ý·«ÇÏ°Ú´Ù. Source°¡ º°·Î ¾î ·ÆÁö ¾ÊÀ¸¹Ç·Î ÀÌÇØÇϱ⠽¬¿ì¸®¶ó »ý°¢ÇÑ´Ù. -------------- < Source 3.4.2.1. clssDNS.h > ------------------- #include class QLabel; class QLineEdit; class QComboBox; /* to combobox */ class QPushButton; class QFrame; class clssDefDNS : public QWidget { Q_OBJECT public: clssDefDNS(); ~clssDefDNS(); public slots: void printLabelFormat(QLabel *lblDNSTitle); void rebootSystem(); private slots: void applySetting(); void cancelSetting(); void addDNS(); void delDNS(); private: QLabel *lblHostName; QLabel *lblDomainName; QLineEdit *leHostName; QLineEdit *leDomainName; QLabel *lblDNSServer; QComboBox *cbDNSServer; QPushButton *bttnCancel; QPushButton *bttnApply; QFrame *frWorkArea; QLabel *lblSeparator; QPushButton *bttnAdd; QPushButton *bttnDel; QLabel *lblDNSTitle; }; ---------------------------------------------------------------- -------------- < Source 3.4.2.2. clssDNS.cpp > ----------------- #include #include #include #include #include #include #include #include #include "network.h" #include "proc_file.h" #include "clssDNS.h" clssDefDNS::clssDefDNS() { char *pszNetmask, *pszHostName, *pszDomainName; int i, j; NetTab pNet; if (((pszNetmask = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszHostName = (char *)malloc(sizeof(char)*256)) == NULL) || ((pszDomainName = (char *)malloc(sizeof(char)*256)) == NULL)) { emit printf("GenericNetwork Class/Network: Memory ÇÒ´ç ¿¡·¯\n"); exit(1); } memset(pszHostName, '\0', 256); memset(pszDomainName, '\0', 256); /* Hostname°ú DomainnameÀ» ¾ò´Â´Ù. */ getCurrentHostName(pszHostName, pszDomainName); /***********************/ lblDNSTitle = new QLabel("DNS Setting (DNS ¼³Á¤)", this); lblDNSTitle->setGeometry(10, 10, 400, 20); // printLabelFormat(lblDNSTitle); frWorkArea = new QFrame(this); frWorkArea->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); frWorkArea->setGeometry(30, 30, 330, 430); /******** Ethernet Card 0 ********/ lblHostName = new QLabel("È£½ºÆ®¸í", frWorkArea); lblHostName->setGeometry(20, 50, 80, 20); leHostName = new QLineEdit(frWorkArea); leHostName->setGeometry(100, 50, 180, 20); leHostName->setText(pszHostName); lblDomainName = new QLabel("µµ¸ÞÀθí", frWorkArea); lblDomainName->setGeometry(20, 80, 80, 20); leDomainName = new QLineEdit(frWorkArea); leDomainName->setGeometry(100, 80, 180, 20); leDomainName->setText(pszDomainName); bttnApply = new QPushButton("Àû ¿ë", frWorkArea); bttnApply->setGeometry(50, 160, 80, 30); QObject::connect(bttnApply, SIGNAL(clicked()), this, SLOT(applySetting())); bttnCancel = new QPushButton("Ãë ¼Ò", frWorkArea); bttnCancel->setGeometry(180, 160, 80, 30); QObject::connect(bttnCancel, SIGNAL(clicked()), this, SLOT(cancelSetting())); /*************************************/ lblSeparator = new QLabel(frWorkArea); lblSeparator->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); lblSeparator->setGeometry(20, 230, 290, 2); lblDNSServer = new QLabel("DNS¼­¹ö", frWorkArea); lblDNSServer->setGeometry(20, 280, 80, 20); cbDNSServer = new QComboBox(TRUE, frWorkArea, "comboBox_DNS"); cbDNSServer->setGeometry(100, 280, 150, 20); char *pszDNSServer[50]; int nCntDNS = countAllLineToFile("/etc/resolv.conf", 50, 200); for (i = 0; i < 50; i++) { if ((pszDNSServer[i] = (char *)malloc(sizeof(char)*200)) == NULL) { printf("Memory allocation error!\n"); exit(1); } memset(pszDNSServer[i], '\0', 200); } /* DNSServerÀÇ À̸§À» ¾ò°í ±×µéÀ» ÄÞº¸¹Ú½º¿¡ »ðÀÔÇÑ´Ù. */ getDNSServer(pszDNSServer); for (i = 0; i < nCntDNS-1; i++) cbDNSServer->insertItem(pszDNSServer[i]); cbDNSServer->setAutoResize(FALSE); for (i = 0; i < 50; i++) free(pszDNSServer[i]); bttnAdd = new QPushButton("Ãß °¡", frWorkArea); bttnAdd->setGeometry(50, 350, 80, 30); QObject::connect(bttnAdd, SIGNAL(clicked()), this, SLOT(addDNS())); bttnDel = new QPushButton("»è Á¦", frWorkArea); bttnDel->setGeometry(180, 350, 80, 30); QObject::connect(bttnDel, SIGNAL(clicked()), this, SLOT(delDNS())); /************************************/ free(pszHostName); free(pszDomainName); } clssDefDNS::~clssDefDNS() { int i; delete lblHostName; delete lblDomainName; delete leHostName; delete leDomainName; delete bttnCancel; delete bttnApply; delete lblDNSServer; delete cbDNSServer; delete bttnAdd; delete bttnDel; delete frWorkArea; delete lblDNSTitle; } /* DNSÀÇ Ãß°¡ ¹öÆ°À» ´­·¶À» ¶§ ½ÇÇàµÇ´Â ÇÔ¼öÀÌ´Ù. */ /* ¿©±â¼­´Â resolv.conf fileÀ» ´Ù·é´Ù. */ void clssDefDNS::addDNS() { char pszTmpSearch[100], pszTmpInsert[100]; if (strlen(cbDNSServer->text(cbDNSServer->currentItem())) != 0) { if (strcmp(cbDNSServer->text(cbDNSServer->currentItem()), cbDNSServer->currentText()) != 0) cbDNSServer->insertItem(cbDNSServer->currentText()); /*** resolv.conf DNS server changed ***/ memset(pszTmpSearch, '\0', 100); memset(pszTmpInsert, '\0', 100); sprintf(pszTmpInsert, "nameserver %s\n", cbDNSServer->currentText()); sprintf(pszTmpSearch, "nameserver %s", cbDNSServer->currentText()); /* ¸¸¾à resolv.conf¿¡¼­ pszTempSearch¿¡ ÀúÀåµÇ¾îÀÖ´Â ¹® */ /* ÀÚ¿­À» ãÁö ¸øÇß´Ù¸é */ if (!searchStrInFile(pszTmpSearch, "/etc/resolv.conf", 100, 100)) /* resolv.conf¿¡¼­ pszTmpSearch¹®ÀÚ¿­ÀÌ ÀÖ´Ù¸é ±× ¶ó */ /* ÀÎÀ» pszTmpInsert¹®ÀÚ¿­·Î ¹Ù²Ù°í, ¾ø´Ù¸é file */ /* ¸¶Áö¸· ºÎºÐ¿¡ pszTmpInsert¹®ÀÚ¿­À» ¶óÀδÜÀ§·Î */ /* »ðÀÔÇ϶ó. */ addOnNotExistChangeOnExist(pszTmpInsert, pszTmpSearch, "/etc/resolv.conf", 100, 100); } } /* DNSÀÇ »èÁ¦¹öÆ°À» ´­·¶À» ¶§ ½ÇÇàµÇ´Â ÇÔ¼öÀÌ´Ù. */ /* addDNS()¿Í ºñ½ÁÇÏ´Ù. */ void clssDefDNS::delDNS() { char pszTmpSearch[100], pszTmpInsert[100]; if (strlen(cbDNSServer->text(cbDNSServer->currentItem())) != 0) { /*** resolv.conf DNS server changed ***/ memset(pszTmpSearch, '\0', 100); sprintf(pszTmpSearch, "nameserver %s", cbDNSServer->text(cbDNSServer->currentItem())); if (!searchStrInFile(pszTmpSearch, "/etc/resolve.conf", 100, 100)) /* pszTmpSearch¹®ÀÚ¿­À» ã¾Ò´Ù¸é ±× ¶óÀÎÀ» °ø¹é¹®ÀÚ */ /* ¿­·Î ¹Ù²Ù¾î¶ó. */ insertStrToFile("", pszTmpSearch, "/etc/resolv.conf", 100, 100); cbDNSServer->removeItem(cbDNSServer->currentItem()); cbDNSServer->setCurrentItem(0); } } /* Hostname ȤÀº DomainnameÀÌ º¯°æµÇ¾ú°í Àû¿ë¹öÆ°À» ´­·¶À» °æ¿ì */ /* ½ÇÇàµÇ´Â ÇÔ¼öÀÌ´Ù. */ /* Hostname ¹× DomainnameÀÌ º¯°æµÇ¾úÀ» ¶§´Â ÀçºÎÆÃÀ» Çؾ߸¸ º¯°æ */ /* µÈ ³»¿ëÀ» Àû¿ë½Ãų ¼ö ÀÖ´Ù. µû¶ó¼­ ¿©±â¼­µµ Hostname ȤÀº */ /* DomainnameÀ» ¹Ù²åÀ» °æ¿ì ÀçºÎÆÃÀ» ÇØÁØ´Ù. */ /* Source»ó ¾î·Á¿î ºÎºÐÀÌ °ÅÀÇ ¾øÀ¸¹Ç·Î ¼³¸íÀº »ý·«ÇÏ°Ú´Ù. */ void clssDefDNS::applySetting() { char *pszNetworkFile = "NETWORKING=yes\nFORWARD_IPV4=true\n\ HOSTNAME=%s.%s\nDOMAINNAME=%s\nGATEWAY=%s\nGATEWAYDEV=eth0\n"; char pszGateway[18]; char pszOptions[95]; char *pszSaveCardLine[3]; FILE *fp; S_Addr pAddr; char pszTmpSearch[100], pszTmpInsert[100]; char pszSaveIP[18], pszSaveHostName[256], pszSaveDomainName[256]; int i; char pszCommand[200]; memset(pszSaveIP, '\0', 18); memset(pszGateway, '\0', 18); memset(pszSaveHostName, '\0', 256); memset(pszSaveDomainName, '\0', 256); getCurrentIPAddr(pszSaveIP); getCurrentGateway(pszGateway); getCurrentHostName(pszSaveHostName, pszSaveDomainName); fp = fopen("/etc/sysconfig/network", "w"); fprintf(fp, pszNetworkFile, leHostName->text(), leDomainName->text(), leDomainName->text(), pszGateway); fclose(fp); /**** update named daemon ****/ if (strlen(leHostName->text()) >= 1) { pAddr = separateAddress(pszSaveIP); /*** HOSTNAME Host,Domain changed ***/ char pszTmpDomain[100]; char pszTmpHost[50]; memset(pszTmpInsert, '\0', 100); memset(pszTmpHost, '\0', 50); memset(pszTmpDomain, '\0', 100); strcpy(pszTmpHost, leHostName->text()); strcpy(pszTmpDomain, leDomainName->text()); sprintf(pszTmpInsert, "%s.%s\n", pszTmpHost, pszTmpDomain); addOnNotExistChangeOnExist(pszTmpInsert, pszSaveHostName, "/etc/HOSTNAME", 100, 100); memset(pszTmpDomain, '\0', 100); memset(pszTmpHost, '\0', 50); strcpy(pszTmpHost, leHostName->text()); strcpy(pszTmpDomain, leDomainName->text()); if (strcmp(pszSaveDomainName, pszTmpDomain) != 0 || strcmp(pszSaveHostName, pszTmpHost) != 0) { QWidget *wdgtRebooting = new QWidget(); wdgtRebooting->setGeometry(300, 300, 300, 150); QLabel *lblRebooting = new QLabel( "È£½ºÆ®À̸§ ȤÀº µµ¸ÞÀÎ À̸§ÀÌ ¹Ù²î¾úÀ¸¹Ç·Î\nÀçºÎÆÃÀ» ÇÏ°Ú½À´Ï´Ù.", wdgtRebooting); lblRebooting->setGeometry(20, 20, 250, 50); QPushButton *bttnRebooting = new QPushButton("Àç ºÎ ÆÃ", wdgtRebooting); bttnRebooting->setGeometry(120, 90, 120, 30); QObject::connect(bttnRebooting, SIGNAL(clicked()), this, SLOT(rebootSystem())); wdgtRebooting->show(); } } system( "/etc/rc.d/init.d/network stop;/etc/rc.d/init.d/network restart\n"); } void clssDefDNS::cancelSetting() { char *pszHostName, *pszDomainName; char *pszSaveListStr[2]; if (((pszHostName = (char *)malloc(sizeof(char)*256)) == NULL) || ((pszDomainName = (char *)malloc(sizeof(char)*256)) == NULL)) { emit printf("GenericNetwork Class/Network: Memory ÇÒ´ç ¿¡·¯\n"); exit(1); } memset(pszHostName, '\0', 256); memset(pszDomainName, '\0', 256); getCurrentHostName(pszHostName, pszDomainName); leHostName->setText(pszHostName); leDomainName->setText(pszDomainName); } void clssDefDNS::rebootSystem() { system("sync;sync;sync;sync;sync;init 6\n"); } void clssDefDNS::printLabelFormat(QLabel *lblBold) { QPalette p = QWidget::palette(); QColorGroup n = palette().normal(); QColorGroup g(n.background(), n.foreground(), n.light(), n.dark(), n.mid(), n.background(), n.base()); p.setNormal(g); setPalette(p); lblBold->setPalette(p); lblBold->setMargin(3); QFont bold = *QApplication::font(); bold.setBold(TRUE); bold.setPointSize(bold.pointSize()+2); lblBold->setFont(bold); lblBold->setFixedSize(lblBold->sizeHint()); lblBold->setFixedSize(lblBold->sizeHint()); } ---------------------------------------------------------------- -------------- < Source 3.4.2.3. Network_menu.h > -------------- #include class QMenuBar; class QPopupMenu; class QToolBar; class clssDefGeneric; class clssDefDNS; class clssNetwork : public QMainWindow { Q_OBJECT public: clssNetwork(); ~clssNetwork(); public slots: void funcGenericNetwork(); void funcDNS(); void funcAlias(); void funcQuit(); protected: private: QMenuBar *mnuMainBar; QPopupMenu *mnuNetwork; QToolBar *tbNetwork; clssDefGeneric *clssGeneric; clssDefDNS *clssDNS; }; ---------------------------------------------------------------- -------------- < Source 3.4.2.4. Network_menu.cpp > ------------ #include #include #include #include #include #include #include #include #include "Network_menu.h" #include "clssGeneric.h" #include "clssDNS.h" //#include "clssAlias.h" #ifndef GENERIC_TOOLTIP #define GENERIC_TOOLTIP "ÀϹÝÀûÀÎ ³×Æ®¿öÅ© ¼³Á¤" #define DNS_TOOLTIP "DNS ¼³Á¤" #define ALIAS_TOOLTIP "Alias ¼³Á¤" #endif clssNetwork::clssNetwork() { QPixmap iconGeneric, iconDNS, iconAlias; iconGeneric.load("./generic.gif"); iconDNS.load("./dns.gif"); iconAlias.load("./alias.gif"); qApp->setStyle(WindowsStyle); mnuNetwork = new QPopupMenu; mnuNetwork->insertItem("ÀÏ¹Ý ³×Æ®¿öÅ© °ü¸®", this, SLOT(funcGenericNetwork())); mnuNetwork->insertItem("DNS °ü¸®", this, SLOT(funcDNS())); mnuNetwork->insertItem("IP-Aliasing °ü¸®", this, SLOT(funcAlias())); mnuNetwork->insertSeparator(); mnuNetwork->insertItem("Á¾·á", this, SLOT(funcQuit())); mnuMainBar = new QMenuBar(this); mnuMainBar->insertItem(" ³×Æ®¿öÅ© ", mnuNetwork); tbNetwork = new QToolBar(this); tbNetwork->setOrientation(tbNetwork->Horizontal); QToolButton *tbttnGeneric = new QToolButton(iconGeneric, GENERIC_TOOLTIP, 0, this, SLOT(funcGenericNetwork()), tbNetwork, "generic"); QToolButton *tbttnDNS = new QToolButton(iconDNS, DNS_TOOLTIP, 0, this, SLOT(funcDNS()), tbNetwork, "dns"); QToolButton *tbttnAlias = new QToolButton(iconAlias, ALIAS_TOOLTIP, 0, this, SLOT(funcAlias()), tbNetwork, "alias"); } clssNetwork::~clssNetwork() { } void clssNetwork::funcGenericNetwork() { clssGeneric = new clssDefGeneric(); clssGeneric->setGeometry(150, 150, 750, 550); clssGeneric->show(); } void clssNetwork::funcDNS() { clssDNS = new clssDefDNS(); clssDNS->setGeometry(150, 150, 400, 500); clssDNS->show(); } void clssNetwork::funcAlias() { } void clssNetwork::funcQuit() { exit(0); } ---------------------------------------------------------------- --------------------- < Makefile 3.4.2. > ---------------------- 3.4.1ÀÇ Makefile°ú ¸¶Âù°¡Áö·Î clssDNS_moc.cpp, clssDNS.cpp, clssDNS.hµîÀ» ¼³Á¤ÇØÁØ´Ù. ---------------------------------------------------------------- 3.4.3. IP-Aliasing°ü¸® IP-Aliasing¿¡ ´ëÇؼ­´Â 3.3Àå¿¡¼­ ¾î´ÀÁ¤µµ ¼³¸íÀº ÇßÀ¸¹Ç·Î ÀÌ°÷¿¡ ¼­´Â 3.3Àå¿¡¼­ ¼³¸íµÇÁö ¾ÊÀº ºÎºÐµé¸¸À» ÁÖ¼®Ã³¸®ÇÏ°Ú´Ù. -------------- < Source 3.4.3.1 clssAlias.h > ------------------ #include class QLineEdit; class QLabel; class QLineEdit; class QListView; class QListViewItem; class QFrame; class QPushButton; class clssDefAlias : public QWidget { Q_OBJECT public: clssDefAlias(); ~clssDefAlias(); public slots: void addSetting(); void deleteSetting(); void getAliasingItem(); void printLabelFormat(QLabel *lblAliasingTitle); private slots: private: QFrame *frWorkArea; QPushButton *bttnAdd; QPushButton *bttnDelete; QFrame *frAliasList; QListView *lvAliasList; QListViewItem *lviAlias[100]; QLabel *lblNetworkArea; QLabel *lblIP; QLineEdit *leIP; QLabel *lblNetmask; QLineEdit *leNetmask; QLabel *lblNetwork; QLineEdit *leNetwork; QLabel *lblBroadcast; QLineEdit *leBroadcast; QLabel *lblAliasingTitle; int nAliasCount; }; ---------------------------------------------------------------- -------------- < Source 3.4.3.2 clssAlias.cpp > ---------------- #include #include #include #include #include #include #include #include #include #include "proc_file.h" #include "network.h" #include "clssAlias.h" clssDefAlias::clssDefAlias() { int i; char pszSaveFile[100]; char pszVirtualIP[18]; FILE *fp; for (nAliasCount = 0; nAliasCount < 10; nAliasCount++) { memset(pszSaveFile, '\0', 100); sprintf(pszSaveFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:%d", nAliasCount); if ((fp = fopen(pszSaveFile, "r")) == NULL) break; fclose(fp); } lblAliasingTitle = new QLabel("Virtual LAN (°¡»ó ³×Æ®¿öÅ© Ä«µå ¼³Á¤)", this); lblAliasingTitle->setGeometry(10, 10, 400, 20); // printLabelFormat(lblAliasingTitle); frWorkArea = new QFrame(this, "IP Aliasing Area"); frWorkArea->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); frWorkArea->setGeometry(40, 60, 670, 310); lblNetworkArea = new QLabel("³×Æ®¿öÅ©¿µ¿ª ¼±ÅÃ", frWorkArea); lblNetworkArea->setGeometry(30, 20, 120, 20); frAliasList = new QFrame(frWorkArea, "Alias List Area"); frAliasList->setFrameStyle(QFrame::Box | QFrame::Sunken | QFrame::WinPanel); frAliasList->setGeometry(30, 60, 320, 220); lvAliasList = new QListView(frAliasList); lvAliasList->setGeometry(3, 3, 314, 214); lvAliasList->addColumn(" °¡»ó ³×Æ®¿öÅ© "); lvAliasList->addColumn(" IP ÁÖ¼Ò "); lvAliasList->setRootIsDecorated(true); if (nAliasCount > 0) { char pszVirtualCard[10]; for (i = 0; i < nAliasCount; i++) { memset(pszVirtualCard, '\0', 10); memset(pszVirtualIP, '\0', 18); sprintf(pszVirtualCard, "eth0:%d", i); /* AliasingµÈ IP¸¦ ¾ò´Â´Ù. i´Â indexÀÌ´Ù. */ /* 3.3¿¡¼­ ¼³¸íÇÑ ¹Ù¿Í °°ÀÌ ¸¸¾à i¿¡ 2°¡ ³Ñ°Ü */ /* Áø´Ù¸é ifcfg-eth0:1¿¡ °üÇÑ, Áï, eth0:2 Card */ /* ¿¡ ´ëÀÀÇÏ´Â IP¸¦ ¾ò°Ô µÉ °ÍÀÌ´Ù. */ getAliasIP(pszVirtualIP, i); lviAlias[i] = new QListViewItem(lvAliasList, pszVirtualCard, pszVirtualIP); } } QObject::connect(lvAliasList, SIGNAL(selectionChanged()), this, SLOT(getAliasingItem())); lblIP = new QLabel("IP ÁÖ¼Ò", frWorkArea); lblIP->setGeometry(400, 60, 70, 20); leIP = new QLineEdit(frWorkArea); leIP->setGeometry(480, 60, 130, 20); lblNetmask = new QLabel("³Ý¸¶½ºÅ©", frWorkArea); lblNetmask->setGeometry(400, 100, 70, 20); leNetmask = new QLineEdit(frWorkArea); leNetmask->setGeometry(480, 100, 130, 20); leNetmask->setEnabled(false); lblNetwork = new QLabel("³×Æ®¿öÅ©", frWorkArea); lblNetwork->setGeometry(400, 140, 70, 20); leNetwork = new QLineEdit(frWorkArea); leNetwork->setGeometry(480, 140, 130, 20); leNetwork->setEnabled(false); lblBroadcast = new QLabel("ºê·Îµåij½ºÆ®", frWorkArea); lblBroadcast->setGeometry(400, 180, 70, 20); leBroadcast = new QLineEdit(frWorkArea); leBroadcast->setGeometry(480, 180, 130, 20); leBroadcast->setEnabled(false); bttnAdd = new QPushButton("Ãß°¡", this); bttnAdd->setGeometry(100, 410, 150, 30); QObject::connect(bttnAdd, SIGNAL(clicked()), this, SLOT(addSetting())); bttnDelete = new QPushButton("»èÁ¦", this); bttnDelete->setGeometry(480, 410, 150, 30); QObject::connect(bttnDelete, SIGNAL(clicked()), this, SLOT(deleteSetting())); } clssDefAlias::~clssDefAlias() { int i; delete lblNetworkArea; if (nAliasCount > 0) for (i = 0; i < nAliasCount; i++) lviAlias[i]; delete lvAliasList; delete lblIP; delete leIP; delete lblNetmask; delete leNetmask; delete lblNetwork; delete leNetwork; delete lblBroadcast; delete leBroadcast; delete frAliasList; delete frWorkArea; delete bttnAdd; delete bttnDelete; delete lblAliasingTitle; } void clssDefAlias::getAliasingItem() { char pszNetmask[18]; NetTab pNet; memset(pszNetmask, '\0', 18); getCurrentNetmask(pszNetmask); leIP->setText(lvAliasList->currentItem()->text(1)); pNet = calculateNetMaskTab((char *)leIP->text(), pszNetmask); leNetmask->setText(pszNetmask); leNetwork->setText(pNet.pszNetwork); leBroadcast->setText(pNet.pszBroadcast); } void clssDefAlias::addSetting() { FILE *fp; char pszVirtualCard[10], pszFile[100]; char pszCommand[150]; memset(pszVirtualCard, '\0', 10); memset(pszFile, '\0', 100); sprintf(pszVirtualCard, "eth0:%d", nAliasCount); sprintf(pszFile, "/etc/sysconfig/network-scripts/ifcfg-%s", pszVirtualCard); lviAlias[nAliasCount] = new QListViewItem(lvAliasList, pszVirtualCard, leIP->text()); if ((fp = fopen(pszFile, "w")) == NULL) { emit printf("file open error!\n"); exit(1); } fprintf(fp, "DEVICE=%s\nIPADDR=%s\nONBOOT=yes\n", pszVirtualCard, leIP->text()); fclose(fp); nAliasCount++; system("/etc/rc.d/init.d/network restart\n"); } void clssDefAlias::deleteSetting() { int i, j; char pszCommand[150], pszFile[100]; char pszVirtualIP[18]; FILE *fp; memset(pszFile, '\0', 100); sprintf(pszFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:%d", lvAliasList->itemPos(lvAliasList->currentItem())/18); if ((fp = fopen(pszFile, "r")) == NULL) return; fclose(fp); nAliasCount--; memset(pszCommand, '\0', 150); memset(pszFile, '\0', 100); sprintf(pszFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:*"); sprintf(pszCommand, "rm -f %s\n", pszFile); system(pszCommand); if (nAliasCount > 0) { for (i = 0, j = 0; i < nAliasCount+1; i++) { if (i != lvAliasList->itemPos(lvAliasList->currentItem())/18) { memset(pszFile, '\0', 100); sprintf(pszFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:%d", j); if ((fp = fopen(pszFile, "w")) == NULL) return; fprintf(fp, "DEVICE=eth0:%d\nIPADDR=%s\nONBOOT=yes\n", j, lviAlias[i]->text(1)); fclose(fp); j++; } } } /* ¿©±â¼­ clear½ÃÅ°°Ô µÇ¸é List¿¡ ÀÖ´ø ¸ðµç Ç׸ñµéÀÌ Áö¿ö */ /* Áö°Ô µÈ´Ù. ±×¸®°í ³ª¼­ ´Ù½Ã ÇÊ¿äÇÑ Ç׸ñÀ» »ðÀÔ½ÃÅ°¸é */ /* ¸¶Ä¡ refreshÇÏ´Â È¿°ú¸¦ ¾òÀ» ¼ö ÀÖ´Ù. ÀÌ·¸°Ô ÇÔÀ¸·Î½á */ /* ƯÁ¤ itemÀÇ »èÁ¦°¡ °¡´ÉÇØÁø´Ù. ¹°·Ð ÀÌ·¯ÇÑ ¹æ¹ýÀº ´ÜÁ¡ */ /* ÀÌ ³²´Â´Ù. ¸¸¾à List¿¡ ÀÖ´Â itemÀÇ °³¼ö°¡ ¸î°³ ¾ÈµÉ ¶§ */ /* ´Â clearÇß´Ù°¡ ´Ù½Ã itemµéÀ» »ðÀÔ½ÃÄѵµ systemÀÌ ÃæºÐÈ÷ */ /* ¼Óµµ¸¦ °¨´çÇس¾ ¼ö ÀÖÁö¸¸ itemÀÇ °³¼ö°¡ ¼ö½Ê, ¼ö¹é, ¼öõ */ /* °³ÀÏ °æ¿ì´Â Ʋ·ÁÁø´Ù. refreshµÇ´Â °úÁ¤ÀÌ ±×´ë·Î º¸ÀÌ°Ô */ /* µÇ¹Ç·Î ¾à°£ Â¥ÁõÀÌ ³¯ ¼öµµ ÀÖ´Ù´Â °ÍÀÌ´Ù. */ /* µû¶ó¼­ À̺κп¡ ´ëÇÑ ¼öÁ¤À» ±ÇÇÏ°í ½Í´Ù. Qt¿¡¼­´Â Ư */ /* Á¤ item¿¡ ´ëÇÑ »èÁ¦ÇÔ¼ö°¡ ÀÖ´Ù. ÀÌ ÇÔ¼ö¸¦ ¾²±â ¹Ù¶õ´Ù. */ /* ÇÔ¼ö »ç¿ë¹ýµµ °£´ÜÇϹǷΠ»ç¿ëÇϱ⠽¬¿ï °ÍÀÌ´Ù. */ /* /usr/lib/qt/include/qlistview.h¿¡ º¸¸é QListViewItem */ /* class¿¡ removeItem°ú QListView class¿¡ repaintÇÔ¼ö°¡ ÀÖ */ /* ´Ù À̵éÀ» ÀûÀýÇÏ°Ô ÀÌ¿ëÇÏ¸é µÉ °ÍÀÌ´Ù. */ lvAliasList->clear(); if (nAliasCount > 0) { char pszVirtualCard[10]; for (i = 0; i < nAliasCount; i++) { memset(pszVirtualCard, '\0', 10); memset(pszVirtualIP, '\0', 18); sprintf(pszVirtualCard, "eth0:%d", i); getAliasIP(pszVirtualIP, i); lviAlias[i] = new QListViewItem(lvAliasList, pszVirtualCard, pszVirtualIP); } } system("/etc/rc.d/init.d/network restart\n"); } void clssDefAlias::printLabelFormat(QLabel *lblBold) { QPalette p = QWidget::palette(); QColorGroup n = palette().normal(); QColorGroup g(n.background(), n.foreground(), n.light(), n.dark(), n.mid(), n.background(), n.base()); p.setNormal(g); setPalette(p); lblBold->setPalette(p); lblBold->setMargin(3); QFont bold = *QApplication::font(); bold.setBold(TRUE); bold.setPointSize(bold.pointSize()+2); lblBold->setFont(bold); lblBold->setFixedSize(lblBold->sizeHint()); lblBold->setFixedSize(lblBold->sizeHint()); } ---------------------------------------------------------------- -------------- < Source 3.4.3.3 Network_menu.h > --------------- #include class QMenuBar; class QPopupMenu; class QToolBar; class clssDefGeneric; class clssDefDNS; class clssDefAlias; class clssNetwork : public QMainWindow { Q_OBJECT public: clssNetwork(); ~clssNetwork(); public slots: void funcGenericNetwork(); void funcDNS(); void funcAlias(); void funcQuit(); protected: private: QMenuBar *mnuMainBar; QPopupMenu *mnuNetwork; QToolBar *tbNetwork; clssDefGeneric *clssGeneric; clssDefDNS *clssDNS; clssDefAlias *clssAlias; }; ---------------------------------------------------------------- ------------ < Source 3.4.3.4 Network_menu.cpp > --------------- #include #include #include #include #include #include #include #include #include "Network_menu.h" #include "clssGeneric.h" #include "clssDNS.h" #include "clssAlias.h" #ifndef GENERIC_TOOLTIP #define GENERIC_TOOLTIP "ÀϹÝÀûÀÎ ³×Æ®¿öÅ© ¼³Á¤" #define DNS_TOOLTIP "DNS ¼³Á¤" #define ALIAS_TOOLTIP "Alias ¼³Á¤" #endif clssNetwork::clssNetwork() { QPixmap iconGeneric, iconDNS, iconAlias; iconGeneric.load("./generic.gif"); iconDNS.load("./dns.gif"); iconAlias.load("./alias.gif"); qApp->setStyle(WindowsStyle); mnuNetwork = new QPopupMenu; mnuNetwork->insertItem("ÀÏ¹Ý ³×Æ®¿öÅ© °ü¸®", this, SLOT(funcGenericNetwork())); mnuNetwork->insertItem("DNS °ü¸®", this, SLOT(funcDNS())); mnuNetwork->insertItem("IP-Aliasing °ü¸®", this, SLOT(funcAlias())); mnuNetwork->insertSeparator(); mnuNetwork->insertItem("Á¾·á", this, SLOT(funcQuit())); mnuMainBar = new QMenuBar(this); mnuMainBar->insertItem(" ³×Æ®¿öÅ© ", mnuNetwork); tbNetwork = new QToolBar(this); tbNetwork->setOrientation(tbNetwork->Horizontal); QToolButton *tbttnGeneric = new QToolButton(iconGeneric, GENERIC_TOOLTIP, 0, this, SLOT(funcGenericNetwork()), tbNetwork, "generic"); QToolButton *tbttnDNS = new QToolButton(iconDNS, DNS_TOOLTIP, 0, this, SLOT(funcDNS()), tbNetwork, "dns"); QToolButton *tbttnAlias = new QToolButton(iconAlias, ALIAS_TOOLTIP, 0, this, SLOT(funcAlias()), tbNetwork, "alias"); } clssNetwork::~clssNetwork() { } void clssNetwork::funcGenericNetwork() { clssGeneric = new clssDefGeneric(); clssGeneric->setGeometry(150, 150, 750, 550); clssGeneric->show(); } void clssNetwork::funcDNS() { clssDNS = new clssDefDNS(); clssDNS->setGeometry(150, 150, 400, 500); clssDNS->show(); } void clssNetwork::funcAlias() { clssAlias = new clssDefAlias(); clssAlias->setGeometry(150, 150, 750, 500); clssAlias->show(); } void clssNetwork::funcQuit() { exit(0); } ---------------------------------------------------------------- ------------ < Source 3.4.3.5 main_menu.cpp > ------------------ #include #include "Network_menu.h" char pszNetConfHost[256]; char pszNetConfDomain[256]; char pszNetConfGateway[18]; char pszNetConfIPAddr[18]; char pszNetConfPrivate1IPAddr[18]; char pszNetConfPrivate2IPAddr[18]; char pszNetConfNetmask[18]; char pszNetConfPrivate1Netmask[18]; char pszNetConfPrivate2Netmask[18]; char pszNetconfBroadcast[18]; char pszNetconfPrivate1Broadcast[18]; char pszNetconfPrivate2Broadcast[18]; char pszNetConfNetwork[18]; char pszNetConfPrivate1Network[18]; char pszNetConfPrivate2Network[18]; char pszNetConfNetCard[3][30]; int nCountListStr; char pszSaveNameServer[20][30]; int nCountNameServer; int nCountClient; extern int nAccountCount; int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssNetwork *clssTest = new clssNetwork(); clssTest->setGeometry(100, 100, 800, 600); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } ---------------------------------------------------------------- --------------------- < Makefile 3.4.3. > ---------------------- 3.4.1ÀÇ Makefile°ú ¸¶Âù°¡Áö·Î clssAlias_moc.cpp, clssAlias.cpp, clssAlias.hµîÀ» ¼³Á¤ÇØÁØ´Ù. ---------------------------------------------------------------- ÀÚ. À̷μ­ ¸ðµç °úÁ¤ÀÌ ´Ù ³¡³µ´Ù. ºÎÁ·ÇÑ ºÎºÐÀÌ¾ß ¼öµµ ¾øÀÌ ¸¹Áö¸¸ ´õ¿í ¿Ïº®ÇÑ Source´Â ´ÙÀ½¿¡ ¿Ã¸®±â·Î ÇÏ°í ÀÌÂë¿¡¼­ Project¿¡ ´ëÇÑ ¸ðµç ¼³¸íÀº À̸¸ Á¢±â·Î ÇÏ°Ú´Ù. ÀÌ ÀڷḦ º¸½Ã´Â ºÐµé²² ²À ÇѸ¶µð ÇÏ °í ´ÙÀ½ Àüü Source¸¦ ¾²±â·Î ÇÏ°Ú´Ù. ¿ì¼± ÀÌ ÀڷḦ Qt¸¦ °øºÎÇϱâ À§ ÇØ º¸½Ã´Â ºÐµéÀ̶ó¸é Á¦ÀÏ ¸ÕÀú ²À ¹Ø¿¡ ÀÖ´Â Àüü Source¸¦ file·Î ÀúÀå ÇØ compileÇÏ°í ½ÇÇà½ÃÅ°½Ã±â ¹Ù¶õ´Ù. º¸Åë GUI¿¡ ´ëÇÑ °øºÎ´Â ¼³¸íÀÌ ¸Õ Àú°¡ ¾Æ´Ï¶ó ´«À¸·Î º¸´Â°ÍÀÌ ¼±ÇàµÇ¾î¾ßÇÑ´Ù. ²À ¸ÕÀú ÀÌ Project¸¦ ´«À¸·Î È®ÀÎ Çغ¸½Ã±â ¹Ù¶õ´Ù. ------------------------------------------------------------------------ < *** Àüü Source *** > // ------------------- < Source : network.h > --------------------- #ifndef _NETWORK_H #define _NETWORK_H #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif #ifndef MAX_LINE #define MAX_LINE 100 #define MAX_COL 1000 #endif #ifndef NO_SETTING #define NO_SETTING "¼ÂÆõǾîÀÖÁö ¾Ê½À´Ï´Ù." #endif extern char pszNetConfHost[256]; extern char pszNetConfDomain[256]; extern char pszNetConfGateway[18]; extern char pszNetConfIPAddr[18]; extern char pszNetConfPrivate1IPAddr[18]; extern char pszNetConfPrivate2IPAddr[18]; extern char pszNetConfNetmask[18]; extern char pszNetConfPrivate1Netmask[18]; extern char pszNetConfPrivate2Netmask[18]; extern char pszNetconfBroadcast[18]; extern char pszNetconfPrivate1Broadcast[18]; extern char pszNetconfPrivate2Broadcast[18]; extern char pszNetConfNetwork[18]; extern char pszNetConfPrivate1Network[18]; extern char pszNetConfPrivate2Network[18]; extern char pszNetConfNetCard[3][30]; extern int nCountListStr; extern char pszSaveNameServer[20][30]; extern int nCountNameServer; extern int nCountClient; extern int nAccountCount; typedef struct tagNETMASKTAB { char pszNetwork[18]; char pszBroadcast[18]; } NetTab; NetTab calculateNetMaskTab(char *pszIPAddr, char *pszNetmask); typedef struct tagSEPADDR { char pszFirst[6]; char pszSecond[6]; char pszThird[6]; char pszFourth[6]; } S_Addr; S_Addr separateAddress(char *pszAddr); char *calculateDate(void); void getCurrentNetmask(char *pszNetmask); void getCurrentGateway(char *pszGateway); void getCurrentHostName(char *pszHostName, char *pszDomainName); void getCurrentIPAddr(char *pszIPAddr); void getPrivate1Netmask(char *pszPrivateNetmask); void getPrivate1IPAddr(char *pszPrivateIPAddr); void getPrivate2Netmask(char *pszPrivateNetmask); void getPrivate2IPAddr(char *pszPrivateIPAddr); void getNetCardIoIrq(char *pszIo, char *pszIrq, int nCardIdx); void getDNSServer(char *pszDNSServer[]); void getAliasNetmask(char *pszNetmask, int nIdx); void getAliasIP(char *pszIPAddr, int nIdx); void getEthNetworkCard(char *pszSaveNetCard[], char *pszCardInfo[]); void calcIPRange(char *pszStartIP, char *pszEndIP, int nIPFourth, int nRange); void calcIPDiffToRange(char *pszStartIP, char *pszEndIP, int *nRange); #endif // ---------------------------------------------------------------- // ------------------- < Source : network.c > --------------------- #include #include #include #include #include #include #include #include #include "network.h" #include "proc_file.h" /*************** Calculate Netmask table **************/ NetTab calculateNetMaskTab(char *pszIPAddr, char *pszNetmask) { struct in_addr IP; struct in_addr Mask; struct in_addr pNetwork; struct in_addr pBroadcast; NetTab pNet; memset(pNet.pszNetwork, '\0', 18); memset(pNet.pszBroadcast, '\0', 18); IP.s_addr = inet_addr(pszIPAddr); Mask.s_addr = inet_addr(pszNetmask); pNetwork.s_addr = IP.s_addr & Mask.s_addr; memcpy(pNet.pszNetwork, inet_ntoa(pNetwork), 18); pBroadcast.s_addr = pNetwork.s_addr | ~Mask.s_addr; memcpy(pNet.pszBroadcast, inet_ntoa(pBroadcast), 18); return pNet; } /***************************************/ S_Addr separateAddress(char *pszAddr) { int i = 0, j = 0, k = 0; S_Addr pAddr; memset(pAddr.pszFirst, '\0', 6); memset(pAddr.pszSecond, '\0', 6); memset(pAddr.pszThird, '\0', 6); memset(pAddr.pszFourth, '\0', 6); for (k = 0; *(pszAddr+i) != '\0'; i++, k++) { if (*(pszAddr+i) == '.') { i++; k = 0; j++; } switch (j) { case 0: pAddr.pszFirst[k] = *(pszAddr+i); break; case 1: pAddr.pszSecond[k] = *(pszAddr+i); break; case 2: pAddr.pszThird[k] = *(pszAddr+i); break; case 3: pAddr.pszFourth[k] = *(pszAddr+i); break; default: break; } } return pAddr; } char pszDate[11]; char *calculateDate() { time_t tTime; int i; memset(pszDate, '\0', 11); tTime = time(NULL); for (i = 0; i < 4; i++) pszDate[i] = *(ctime(&tTime)+20+i); for (i = 0; i < 3; i++) pszDate[i+4] = *(ctime(&tTime)+4+i); for (i = 0; i < 2; i++) pszDate[i+4+3] = *(ctime(&tTime)+8+i); return pszDate; } void getCurrentNetmask(char *pszNetmask) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); if ((fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth0", "r")) == NULL) return; while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "NETMASK=")); for (i = 0; pszSave[i+8] != 'N'; i++) pszNetmask[i] = pszSave[i+8]; pszNetmask[i-1] = '\0'; } void getCurrentGateway(char *pszGateway) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); if ((fp = fopen("/etc/sysconfig/network", "r")) == NULL) return; while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "GATEWAY=")); for (i = 0; pszSave[i+8] != 'G'; i++) pszGateway[i] = pszSave[i+8]; pszGateway[i-1] = '\0'; } void getPrivate1Netmask(char *pszPrivateNetmask) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); if ((fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth1", "r")) == NULL) { // strcpy(pszPrivateNetmask, "255.255.0.0"); return; } while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "NETMASK=")); for (i = 0; pszSave[i+8] != 'N'; i++) pszPrivateNetmask[i] = pszSave[i+8]; pszPrivateNetmask[i-1] = '\0'; } void getPrivate1IPAddr(char *pszPrivateIPAddr) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); if ((fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth1", "r")) == NULL) { // strcpy(pszPrivateIPAddr, "172.31.0.1"); return; } while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "IPADDR=")); for (i = 0; pszSave[i+7] != 'N'; i++) pszPrivateIPAddr[i] = pszSave[i+7]; pszPrivateIPAddr[i-1] = '\0'; } void getPrivate2Netmask(char *pszPrivateNetmask) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); if ((fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth2", "r")) == NULL) { // strcpy(pszPrivateNetmask, "255.255.0.0"); return; } while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "NETMASK=")); for (i = 0; pszSave[i+8] != 'N'; i++) pszPrivateNetmask[i] = pszSave[i+8]; pszPrivateNetmask[i-1] = '\0'; } void getPrivate2IPAddr(char *pszPrivateIPAddr) { int i = 0; char pszSaveFile[1024]; char pszSave[1024]; FILE *fp; memset(pszSaveFile, '\0', 1024); memset(pszSave, '\0', 1024); if ((fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth2", "r")) == NULL) { // strcpy(pszPrivateIPAddr, "192.168.1.1"); return; } while ((pszSaveFile[i] = fgetc(fp)) != EOF) i++; fclose(fp); strcpy(pszSave, (char *)strstr(pszSaveFile, "IPADDR=")); for (i = 0; pszSave[i+7] != 'N'; i++) pszPrivateIPAddr[i] = pszSave[i+7]; pszPrivateIPAddr[i-1] = '\0'; } void getCurrentHostName(char *pszHostName, char *pszDomainName) { struct utsname name; int i, j; uname(&name); for (i = 0; name.nodename[i] != '.'; i++) pszHostName[i] = name.nodename[i]; i++; for (j = 0; name.nodename[i] != '\0'; i++, j++) pszDomainName[j] = name.nodename[i]; } void getCurrentIPAddr(char *pszIPAddr) { char *pszSaveListStr[20]; int i; for (i = 0; i < 20; i++) { pszSaveListStr[i] = (char *)malloc(sizeof(char)*80); memset(pszSaveListStr[i], '\0', 80); } saveSearchLineToFile("IPADDR", pszSaveListStr, "/etc/sysconfig/network-scripts/ifcfg-eth0", 20, 80); for (i = 0; pszSaveListStr[0][i+7] != '\n'; i++) pszIPAddr[i] = pszSaveListStr[0][i+7]; for (i = 0; i < 20; i++) free(pszSaveListStr[i]); } void getNetCardIoIrq(char *pszIo, char *pszIrq, int nNetCardIdx) { int i; char *pszPosIo, *pszPosIrq; int nIrqIdx, nIoIdx; char *pszTmpStr = "options eth%d"; char pszOptionStr[30]; char *pszSaveListStr[3]; for (i = 0; i < 3; i++) { if ((pszSaveListStr[i] = (char *)malloc(sizeof(char)*200)) == NULL) { printf("Memory allocation error!\n"); memset(pszSaveListStr[i], '\0', 200); exit(1); } } memset(pszOptionStr, '\0', 30); sprintf(pszOptionStr, pszTmpStr, nNetCardIdx); saveSearchLineToFile(pszOptionStr, pszSaveListStr, "/etc/conf.modules", 200, 200); pszPosIo = strstr(pszSaveListStr[0], "0x"); nIoIdx = pszPosIo-pszSaveListStr[0]; pszPosIrq = strstr(pszSaveListStr[0], "irq="); nIrqIdx = pszPosIrq-pszSaveListStr[0]; for (i = nIoIdx-1; i < nIrqIdx-4; i++) pszIo[i-nIoIdx+1] = pszSaveListStr[0][i+3]; for (i = nIrqIdx; pszSaveListStr[0][i+4] != '\n'; i++) pszIrq[i-nIrqIdx] = pszSaveListStr[0][i+4]; for (i = 0; i < 3; i++) free(pszSaveListStr[i]); } void getDNSServer(char *pszDNSServer[]) { char *pszSaveListStr[50]; int i; int nCntDNS; for (i = 0; i < 50; i++) { if ((pszSaveListStr[i] = (char *)malloc(sizeof(char)*200)) == NULL) { printf("Memory allocation error!\n"); exit(1); } memset(pszSaveListStr[i], '\0', 200); } saveSearchLineToFile("nameserver", pszSaveListStr, "/etc/resolv.conf", 50, 200); nCntDNS = countAllLineToFile("/etc/resolv.conf", 50, 200); nCntDNS--; for (i = 0; i < nCntDNS; i++) { strcpy(pszDNSServer[i], pszSaveListStr[i]+11); pszDNSServer[i][strlen(pszDNSServer[i])-1] = '\0'; } for (i = 0; i < 50; i++) free(pszSaveListStr[i]); } void getAliasIP(char *pszIPAddr, int nIdx) { char *pszSaveListStr[20]; int i, j = 0; char pszSaveFile[100]; FILE *fp; for (i = 0; i < 20; i++) { pszSaveListStr[i] = (char *)malloc(sizeof(char)*80); memset(pszSaveListStr[i], '\0', 80); } memset(pszSaveFile, '\0', 100); sprintf(pszSaveFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:%d", nIdx); if ((fp = fopen(pszSaveFile, "r")) == NULL) { printf("File Open Error!\n"); for (i = 0; i < 20; i++) free(pszSaveListStr[i]); return; } fclose(fp); saveSearchLineToFile("IPADDR", pszSaveListStr, pszSaveFile, 20, 80); for (i = 0; pszSaveListStr[0][i+7] != '\n'; i++) pszIPAddr[i] = pszSaveListStr[0][i+7]; for (i = 0; i < 20; i++) free(pszSaveListStr[i]); } void getAliasNetmask(char *pszNetmask, int nIdx) { char *pszSaveListStr[20]; int i, j = 0; char pszSaveFile[100]; FILE *fp; for (i = 0; i < 20; i++) { pszSaveListStr[i] = (char *)malloc(sizeof(char)*80); memset(pszSaveListStr[i], '\0', 80); } memset(pszSaveFile, '\0', 100); sprintf(pszSaveFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:%d", nIdx); if ((fp = fopen(pszSaveFile, "r")) == NULL) { printf("File Open Error!\n"); for (i = 0; i < 20; i++) free(pszSaveListStr[i]); return; } fclose(fp); saveSearchLineToFile("NETMASK", pszSaveListStr, pszSaveFile, 20, 80); for (i = 0; pszSaveListStr[0][i+8] != '\n'; i++) pszNetmask[i] = pszSaveListStr[0][i+8]; for (i = 0; i < 20; i++) free(pszSaveListStr[i]); } void getEthNetworkCard(char *pszSaveNetCard[], char *pszCardInfo[]) { FILE *fp; int i, j, nIdx, nCount, nCardCount = 0; char *pszSaveListStr[100]; char *pszSaveLine[4]; if ((fp = fopen("/proc/interrupts", "r")) == NULL) { printf("file open error!\n"); return; } fclose(fp); for (i = 0; i < 4; i++) { if ((pszSaveLine[i] = (char *)malloc(sizeof(char)*200)) == NULL) { printf("memory allocation error!\n"); exit(1); } memset(pszSaveLine[i], '\0', 200); } for (i = 0; i < 100; i++) { if ((pszSaveListStr[i] = (char *)malloc(sizeof(char)*200)) == NULL) { printf("memory allocation error!\n"); exit(1); } memset(pszSaveListStr[i], '\0', 200); } nCount = saveAllLineToFile(pszSaveListStr, "/proc/interrupts", 100, 200); for (i = 0, nIdx = 0; i < nCount; i++) { for (j = 0; j < 40; j++) { if (strstr(pszSaveListStr[i], pszCardInfo[j]) != (char *)NULL) { nCardCount++; strcpy(pszSaveLine[nIdx++], pszSaveListStr[i]); break; } } } if (nCardCount == 0) { strcpy(pszSaveNetCard[0], NO_SETTING); strcpy(pszSaveNetCard[1], NO_SETTING); strcpy(pszSaveNetCard[2], NO_SETTING); } else if (nCardCount == 1) { strcpy(pszSaveNetCard[0], pszSaveLine[0]+33); strcpy(pszSaveNetCard[1], NO_SETTING); strcpy(pszSaveNetCard[2], NO_SETTING); } else if (nCardCount == 2) { strcpy(pszSaveNetCard[0], pszSaveLine[0]+33); strcpy(pszSaveNetCard[1], pszSaveLine[1]+33); strcpy(pszSaveNetCard[2], NO_SETTING); } else { strcpy(pszSaveNetCard[0], pszSaveLine[0]+33); strcpy(pszSaveNetCard[1], pszSaveLine[1]+33); strcpy(pszSaveNetCard[2], pszSaveLine[2]+33); } for (i = 0; i < 4; i++) free(pszSaveLine[i]); for (i = 0; i < 100; i++) free(pszSaveListStr[i]); } void calcIPRange(char *pszStartIP, char *pszEndIP, int nIPFourth, int nRange) { char pszSaveStartIP[4], pszSaveEndIP[4]; memset(pszSaveStartIP, '\0', 4); memset(pszSaveEndIP, '\0', 4); if (nIPFourth%nRange != 0) { sprintf(pszSaveStartIP, "%d", (nIPFourth/nRange)*nRange); sprintf(pszSaveEndIP, "%d", (nIPFourth/nRange)*nRange+nRange-1); } else { sprintf(pszSaveStartIP, "%d", nIPFourth); sprintf(pszSaveEndIP, "%d", nIPFourth+nRange-1); } strcat(pszStartIP, pszSaveStartIP); strcat(pszEndIP, pszSaveEndIP); } void calcIPDiffToRange(char *pszStartIP, char *pszEndIP, int *nRange) { S_Addr pAddr; int i, nSaveRange; int nStart, nEnd; pAddr = separateAddress(pszStartIP); nStart = atoi(pAddr.pszFourth); pAddr = separateAddress(pszEndIP); nEnd = atoi(pAddr.pszFourth); nSaveRange = nEnd-nStart+1; for (i = 0; nSaveRange > 0; i++) nSaveRange /= 2; *nRange = 32-(i-1); } // ---------------------------------------------------------------- // ------------------- < Source : proc_file.h > ------------------- #include #ifndef _LINKLIST_H_ #define _LINKLIST_H_ #ifndef SUCCESS #define SUCCESS 1 #define FAIL 0 #endif #ifndef MAX_XXX_NUM #define MAX_XXX_NUM 10000 #define BLACKLIST_INSERT 1 #define BLACKLIST_DELETE 0 #endif #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif #ifndef _DOUBLE_LINKLIST_ #define _DOUBLE_LINKLIST_ typedef struct tagDOUBLELINK { void *pzKey; struct tagDOUBLELINK *next; struct tagDOUBLELINK *prev; } DList; void initDL(void); DList *searchDL(void *pzSearch); DList *insertAsFirstDL(void *pzInsert); DList *insertDL(void *pzInsert, DList *pIns); /* insert front node p */ DList *insertDLAsKey(void *pzInsert, void *pzSearch); DList *insertDLAsSort(void *pzInsert); int deleteDL(DList *pDel); int deleteDLAsKey(void *pzSearch); void deleteAllDL(void); void deletePerfectDL(void); void *printDL(DList *pPrint); void deleteStrFromOneLine(char *pszSave, char *pszDel, char *pszLine); void insertStrForeSearch(char *pszSave, char *pszInsert, char *pszSearch, char *pszLine, char *pszTempLine); void insertStrToOneLine(char *pszSave, char *pszIns, char *pszLine); void changeSearchStr(char *pszIns, char *pszSearch, char *pszLine, char *pszSave, int nMaxCol); void *printToFileDL(DList *pPrint, FILE *fp); int readOneLineSearchFile(char pszBuffer[], FILE *fp); void insertStrToFile(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void insertStrToFileLast(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); int countAllLineToFile(char *pszFileName, int nMaxLine, int nMaxCol); int countSearchLineToFile(char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); int saveAllLineToFile(char *pszSaveListStr[], char *pszFileName, int nMaxLine, int nMaxCol); int saveSearchLineToFile(char *pszSearch, char *pszSaveListStr[], char *pszFileName, int nMaxLine, int nMaxCol); int saveSearchLineToFileWithoutComment(char *pszSearch, char *pszSaveListStr[], char cComment, char *pszFileName, int nMaxLine, int nMaxCol); void changeStrToOneLineToFile(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void insertStrToOneLineToFile(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void deleteStrToOneLineToFile(char *pszDel, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); int searchStrInFile(char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void addOnNotExistChangeOnExist(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void addOnNotExistChangeOnExistWithoutComment(char *pszIns, char *pszSearch, char cComment, char *pszFileName, int nMaxLine, int nMaxCol); void addOnNotExistChangeOnExist2Search(char *pszIns, char *pszFirstSearch, char *pszSecondSearch, char *pszFileName, int nMaxLine, int nMaxCol); void insertForeSearchToFile(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void attatchStrToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol); void saveStrIdxToFileLine(char *pszSave, char *pszSearch, char *pszFileName, int nStartIdx, int nEndIdx, int nMaxLine, int nMaxCol); void changeStrIdxToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nStartIdx, int nEndIdx, int nMaxLine, int nMaxCol); void attatchStrIdxToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nIdx, int nMaxLine, int nMaxCol); void attatchStrToFileIdxLine(char *pszInsert, char *pszFileName, int nLineIdx, int nColIdx, int nMaxLine, int nMaxCol); void saveBetweenStrToFile(char *pszSaveLine[], char *pszStartLine, char *pszEndLine, char *pszFileName, int nMaxLine, int nMaxCol); void changeBetweenStrToFile(char *pszInsert[], int nInsertNum, char *pszStartLine, char *pszEndLine, char *pszFileName, int nMaxLine, int nMaxCol); void insertAfterStrToFile(char *pszInsert, char *pszStartLine, char *pszFileName, int nMaxLine, int nMaxCol); void changeStrInFile(char *pszFile, char *pszSrc, char *pszDest, int nStatus); int getUserBlackList(char *pszXXXData[MAX_XXX_NUM], int nMode); #endif #endif // ---------------------------------------------------------------- // ------------------- < Source : proc_file.c > ------------------- #include #include #include #include #include "proc_file.h" DList *dblhead; DList *dbltail; void initDL(void) { dblhead = (DList *)malloc(sizeof(DList)); dbltail = (DList *)malloc(sizeof(DList)); dblhead->prev = dblhead; dblhead->next = dbltail; dbltail->prev = dblhead; dbltail->next = dbltail; } DList *searchDL(void *pzSearch) { DList *s; s = dblhead->next; while (s != dbltail) { if (memcmp(s->pzKey, pzSearch, sizeof(pzSearch)) == 0) break; s = s->next; } return s; } DList *insertAsFirstDL(void *pzInsert) { DList *p; p = (DList *)malloc(sizeof(DList)); p->pzKey = pzInsert; p->next = dblhead->next; dblhead->next->prev = p; dblhead->next = p; p->prev = dblhead; return p; } DList *insertAsLastDL(void *pzInsert) { insertDL(pzInsert, dbltail); return (DList *)NULL; } DList *insertDL(void *pzInsert, DList *pIns) /* insert front node pIns */ { DList *s; if (pIns == dblhead) return NULL; s = (DList *)malloc(sizeof(DList)); s->pzKey = pzInsert; pIns->prev->next = s; s->prev = pIns->prev; s->next = pIns; pIns->prev = s; return s; } DList *insertDLAsKey(void *pzInsert, void *pzSearch) { /* insert insk front findk */ DList *s; DList *r = NULL; s = searchDL(pzSearch); if (s != dbltail) { r = (DList *)malloc(sizeof(DList)); r->pzKey = pzInsert; s->prev->next = r; r->prev = s->prev; r->next = s; s->prev = r; } return r; } DList *insertDLAsSort(void *pzInsert) { DList *s; DList *r; s = dblhead->next; while (s != dbltail) { if (memcmp(s->pzKey, pzInsert, sizeof(pzInsert)) >= 0) break; s = s->next; } r = (DList *)malloc(sizeof(DList)); r->pzKey = pzInsert; s->prev->next = r; r->prev = s->prev; r->next = s; s->prev = r; return r; } int deleteDL(DList *pDel) { if (pDel == dblhead || pDel == dbltail) return FAIL; pDel->prev->next = pDel->next; pDel->next->prev = pDel->prev; free(pDel); return SUCCESS; } int deleteDLAsKey(void *pzSearch) { DList *s; s = searchDL(pzSearch); if (s != dbltail) { s->prev->next = s->next; s->next->prev = s->prev; free(s); return SUCCESS; } return FAIL; } void deleteAllDL(void) { DList *s; DList *p; p = dblhead->next; while (p != dbltail) { s = p; p = p->next; free(s); } dblhead->next = dbltail; dbltail->prev = dblhead; } void deletePerfectDL(void) { DList *s; DList *p; p = dblhead->next; while (p != dbltail) { s = p; p = p->next; free(s); } free(dblhead); free(dbltail); } void *printDL(DList *pPrint) { pPrint = dblhead->next; while (pPrint != dbltail) { printf("%s", (char *)(pPrint->pzKey)); pPrint = pPrint->next; } return pPrint->pzKey; } /****** Insert to FILE ******/ void deleteStrFromOneLine(char *pszSave, char *pszDel, char *pszLine) { char *pszPnt; int i, nFirstLen; if ((pszPnt = (char *)strstr(pszLine, pszDel)) == NULL) return; nFirstLen = pszPnt-pszLine; for (i = 0; i < nFirstLen; i++) pszSave[i] = pszLine[i]; for (i = nFirstLen; pszLine[i+strlen(pszDel)] != '\0'; i++) pszSave[i] = pszLine[i+strlen(pszDel)]; pszSave[i] = '\0'; } void insertStrForeSearch(char *pszSave, char *pszInsert, char *pszSearch, char *pszLine, char *pszTempLine) { int i = 0; int nLen; char *pszPos; if ((char *)strstr(pszLine, pszInsert) != NULL) { strcat(pszSave, pszTempLine); return; } pszPos = (char *)strstr(pszLine, pszSearch); nLen = pszPos-pszLine; for (i = 0; i < nLen; i++) pszSave[i] = pszLine[i]; strcat(pszSave, pszInsert); strcat(pszSave, strstr(pszLine, pszSearch)); } void insertStrToOneLine(char *pszSave, char *pszIns, char *pszLine) { int nFirstPos, nSecondPos; if ((char *)strstr(pszLine, pszIns) != NULL) return; for (nFirstPos = 0; nFirstPos < strlen(pszLine); nFirstPos++) pszSave[nFirstPos] = pszLine[nFirstPos]; for (nSecondPos = 0; nSecondPos < strlen(pszIns); nSecondPos++) pszSave[nSecondPos+nFirstPos] = pszIns[nSecondPos]; pszSave[nSecondPos+nFirstPos] = '\0'; } void changeSearchStr(char *pszIns, char *pszSearch, char *pszLine, char *pszSave, int nMaxCol) { int i = 0; char *pszPos; int nPos; pszPos = (char *)strstr(pszLine, pszSearch); nPos = pszPos-pszLine; for (i = 0; i < nPos; i++) pszSave[i] = pszLine[i]; strcat(pszSave, pszIns); strcat(pszSave, pszLine+nPos+strlen(pszSearch)); pszPos = (char *)strstr(pszSave, pszSearch); if (pszPos == NULL) return; memset(pszLine, '\0', nMaxCol); strcpy(pszLine, pszSave); memset(pszSave, '\0', nMaxCol); changeSearchStr(pszIns, pszSearch, pszLine, pszSave, nMaxCol); } int nLine; void *printToFileDL(DList *pPrint, FILE *fp) { pPrint = dblhead->next; while (pPrint != dbltail) { fprintf(fp, pPrint->pzKey); pPrint = pPrint->next; } return pPrint->pzKey; } int readOneLineSearchFile(char pszBuffer[], FILE *fp) { int i = 0; char c = '\0'; do { c = getc(fp); pszBuffer[i++] = c; if (c == EOF || c == '\n') break; } while (1); pszBuffer[i] = '\0'; nLine++; return c; } void insertStrToFileLast(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else { for (j = 0; j < nMaxLine; j++) free(pszBuffer[j]); fclose(fp); deletePerfectDL(); return; } } insertAsLastDL(pszInsert); fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (j = 0; j < nMaxLine; j++) free(pszBuffer[j]); } int countAllLineToFile(char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, nCount = 0; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return 0; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (nCount = 0; (readOneLineSearchFile(pszBuffer[nCount], fp) != EOF) && (nCount < nMaxLine); nCount++); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return nCount; } int countSearchLineToFile(char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0; int nCount = 0; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return 0; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) nCount++; } fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return nCount; } int saveAllLineToFile(char *pszSaveListStr[], char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return 0; for (j = 0; j < nMaxLine; j++) { pszBuffer[j] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[j], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) strcpy(pszSaveListStr[i], pszBuffer[i]); fclose(fp); for (j = 0; j < nMaxLine; j++) free(pszBuffer[j]); return i; } int saveSearchLineToFileWithoutComment(char *pszSearch, char *pszSaveListStr[], char cComment, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; int j = 0; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; if ((fp = fopen(pszFileName, "r")) == NULL) return FALSE; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL && pszBuffer[i][0] != cComment) { strcpy(pszSaveListStr[j], pszBuffer[i]); j++; } } fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return TRUE; } int saveSearchLineToFile(char *pszSearch, char *pszSaveListStr[], char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; int j = 0; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; if ((fp = fopen(pszFileName, "r")) == NULL) return FALSE; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { strcpy(pszSaveListStr[j], pszBuffer[i]); j++; } } fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return TRUE; } void changeStrToOneLineToFile(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0, j = 0; FILE *fp; char *pszLine[nMaxLine]; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); pszLine[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszLine[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else { changeSearchStr(pszIns, pszSearch, pszBuffer[i], pszLine[j], nMaxCol); insertAsLastDL(pszLine[j]); j++; } } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) { free(pszBuffer[i]); free(pszLine[i]); } } void insertStrToOneLineToFile(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char pszLine[nMaxCol]; char *pszBuffer[nMaxLine]; memset(pszLine, '\0', nMaxCol); nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else { insertStrForeSearch(pszLine, pszIns, pszSearch, pszBuffer[i], pszBuffer[i]); insertAsLastDL(pszLine); } } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void deleteStrToOneLineToFile(char *pszDel, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char pszLine[nMaxCol]; char *pszBuffer[nMaxLine]; memset(pszLine, '\0', nMaxCol); nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else { deleteStrFromOneLine(pszLine, pszDel, pszBuffer[i]); insertAsLastDL(pszLine); } } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void insertStrToFile(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else insertAsLastDL(pszInsert); } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } int searchStrInFile(char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return FALSE; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); fclose(fp); return TRUE; } } fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return FALSE; } /** if Search is true, change.. else add **/ void addOnNotExistChangeOnExist(char *pszIns, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; int flgAdd = TRUE; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL) insertAsLastDL(pszBuffer[i]); else { insertAsLastDL(pszIns); flgAdd = FALSE; } } fclose(fp); if (flgAdd == TRUE) insertAsLastDL(pszIns); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void addOnNotExistChangeOnExistWithoutComment(char *pszIns, char *pszSearch, char cComment, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; int flgAdd = TRUE; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) == NULL || pszBuffer[i][0] == cComment) insertAsLastDL(pszBuffer[i]); else { insertAsLastDL(pszIns); flgAdd = FALSE; } } fclose(fp); if (flgAdd == TRUE) insertAsLastDL(pszIns); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void addOnNotExistChangeOnExist2Search(char *pszIns, char *pszFirstSearch, char *pszSecondSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; int flgAdd = TRUE; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszFirstSearch) != NULL && (char *)strstr(pszBuffer[i], pszSecondSearch) != NULL) { insertAsLastDL(pszIns); flgAdd = FALSE; } else insertAsLastDL(pszBuffer[i]); } fclose(fp); if (flgAdd == TRUE) insertAsLastDL(pszIns); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void insertForeSearchToFile(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) insertAsLastDL(pszBuffer[i]); fclose(fp); insertDLAsKey(pszInsert, pszSearch); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void attatchStrToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nMaxLine, int nMaxCol) { int i = 0, j; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { pszBuffer[i][strlen(pszBuffer[i])-1] = '\0'; strcat(pszBuffer[i], pszInsert); pszBuffer[i][strlen(pszBuffer[i])] = '\n'; } insertAsLastDL(pszBuffer[i]); } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void saveStrIdxToFileLine(char *pszSave, char *pszSearch, char *pszFileName, int nStartIdx, int nEndIdx, int nMaxLine, int nMaxCol) { int i = 0, j; FILE *fp; char *pszBuffer[nMaxLine]; char pszEndBuffer[nMaxCol]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { memset(pszEndBuffer, '\0', nMaxCol); strcpy(pszEndBuffer, pszBuffer[i]+nStartIdx); for (j = 0; j < nEndIdx-nStartIdx; j++) pszSave[j] = pszEndBuffer[j]; } } fclose(fp); } void changeStrIdxToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nStartIdx, int nEndIdx, int nMaxLine, int nMaxCol) { int i = 0, j; FILE *fp; char *pszBuffer[nMaxLine]; char pszEndBuffer[nMaxCol]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { memset(pszEndBuffer, '\0', nMaxCol); strcpy(pszEndBuffer, pszBuffer[i]+nEndIdx); pszBuffer[i][nStartIdx] = '\0'; strcat(pszBuffer[i], pszInsert); strcat(pszBuffer[i], pszEndBuffer); pszBuffer[i][strlen(pszBuffer[i])] = '\0'; } insertAsLastDL(pszBuffer[i]); } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void attatchStrIdxToFileLine(char *pszInsert, char *pszSearch, char *pszFileName, int nIdx, int nMaxLine, int nMaxCol) { int i = 0, j; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszSearch) != NULL) { pszBuffer[i][nIdx] = '\0'; strcat(pszBuffer[i], pszInsert); pszBuffer[i][strlen(pszBuffer[i])] = '\n'; } insertAsLastDL(pszBuffer[i]); } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void attatchStrToFileIdxLine(char *pszInsert, char *pszFileName, int nLineIdx, int nColIdx, int nMaxLine, int nMaxCol) { int i = 0, j; FILE *fp; char *pszBuffer[nMaxLine]; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if (i == nLineIdx-1) { pszBuffer[i][nColIdx] = '\0'; strcat(pszBuffer[i], pszInsert); pszBuffer[i][strlen(pszBuffer[i])] = '\n'; } insertAsLastDL(pszBuffer[i]); } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); } void insertAfterStrToFile(char *pszInsert, char *pszStartLine, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j, k; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { insertAsLastDL(pszBuffer[i]); if ((char *)strstr(pszBuffer[i], pszStartLine) != NULL) { insertAsLastDL(pszInsert); insertAsLastDL("\n"); for (j = i+1; readOneLineSearchFile(pszBuffer[j], fp) != EOF; j++) insertAsLastDL(pszBuffer[j]); break; } } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return; } void saveBetweenStrToFile(char *pszSaveLine[], char *pszStartLine, char *pszEndLine, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { if ((char *)strstr(pszBuffer[i], pszStartLine) != NULL) { for (j = i+1; readOneLineSearchFile(pszBuffer[j], fp) != EOF; j++) { if ((char *)strstr(pszBuffer[j], pszEndLine) == NULL) strcpy(pszSaveLine[j-(i+1)], pszBuffer[j]); else break; } fclose(fp); for (j = 0; j < nMaxLine; j++) free(pszBuffer[j]); return; } } } void changeBetweenStrToFile(char *pszInsert[], int nInsertNum, char *pszStartLine, char *pszEndLine, char *pszFileName, int nMaxLine, int nMaxCol) { char *pszBuffer[nMaxLine]; int i = 0, j, k; FILE *fp; nLine = 0; fp = fopen(pszFileName, "r"); if (fp == NULL) return; for (i = 0; i < nMaxLine; i++) { pszBuffer[i] = (char *)malloc(sizeof(char)*nMaxCol); memset(pszBuffer[i], '\0', nMaxCol); } initDL(); for (i = 0; readOneLineSearchFile(pszBuffer[i], fp) != EOF; i++) { insertAsLastDL(pszBuffer[i]); if ((char *)strstr(pszBuffer[i], pszStartLine) != NULL) { for (j = i+1; readOneLineSearchFile(pszBuffer[j], fp) != EOF; j++) if ((char *)strstr(pszBuffer[j], pszEndLine) != NULL) break; for (k = 0; k < nInsertNum; k++) insertAsLastDL(pszInsert[k]); insertAsLastDL(pszBuffer[j]); for (k = j+1; readOneLineSearchFile(pszBuffer[k], fp) != EOF; k++) insertAsLastDL(pszBuffer[k]); break; } } fclose(fp); fp = fopen(pszFileName, "w"); printToFileDL(dblhead->next, fp); deletePerfectDL(); fclose(fp); for (i = 0; i < nMaxLine; i++) free(pszBuffer[i]); return; } // ---------------------------------------------------------------- // ---------------- < Source : clssGeneric.h > -------------------- #include class QLabel; class QLineEdit; class QComboBox; /* to combobox */ class QPushButton; class QFrame; class clssDefGeneric : public QWidget { Q_OBJECT public: clssDefGeneric(); ~clssDefGeneric(); private slots: void setApply(); void setCancel(); void printLabelFormat(QLabel *lblBold); private: QLabel *lblGenericNetworkTitle; QLabel *lblGateway; QLineEdit *leGateway; QLabel *lblEth0; QLabel *lblEth0IPAddr; QLineEdit *leEth0IPAddr; QLabel *lblEth0Netmask; QLineEdit *leEth0Netmask; QLabel *lblEth0Network; QLineEdit *leEth0Network; QLabel *lblEth0Broadcast; QLineEdit *leEth0Broadcast; QLabel *lblEth0NetCard; QComboBox *cbEthNetCard[3]; /* to combobox */ QLabel *lblEth1; QLineEdit *leEth1IPAddr; QLineEdit *leEth1Netmask; QLineEdit *leEth1Network; QLineEdit *leEth1Broadcast; QLabel *lblEth1NetCard; QLabel *lblEth2; QLineEdit *leEth2IPAddr; QLineEdit *leEth2Netmask; QLineEdit *leEth2Network; QLineEdit *leEth2Broadcast; QLabel *lblEth2NetCard; QPushButton *bttnCancel; QPushButton *bttnApply; QFrame *frEthInfo; QLabel *lblSeparator1; QLabel *lblSeparator2; }; // ---------------------------------------------------------------- // ---------------- < Source : clssGeneric.cpp > ------------------ #include #include #include #include #include #include /* test */ #include #include #include #include #include #include "network.h" #include "proc_file.h" #include "clssGeneric.h" clssDefGeneric::clssDefGeneric() { char *pszIPAddr, *pszNetmask, *pszGateway; char *pszPrivate1IPAddr, *pszPrivate1Netmask, *pszPrivate2IPAddr; char *pszPrivate2Netmask; int i, j, nCardIdx; NetTab pNet, pNetPrivate1, pNetPrivate2; char *pszSaveListStr[2]; const char *pszNetCard[40] = { " 3Com Vortex series (3c590, 3c592, 3c597, 3c595) (3c59x) ", " 3Com Boomerang (3c900, 3c905, 3c575) (3c59x) ", " 3Com Cyclone (3c905B) (3c59x) ", " Intel EtherExpress Pro 100 (eepro100) ", " HP J2585B, J2585A, J2970, J2973 (hp100) ", " HP J2573 (hp100) ", " Compex ReadyLink ENET100-VG4 (hp100) ", " Compex FreedomLine 100/VG (hp100) ", " IBM token ring (ibmtr) ", " NE2000 (PCI) (ne2k-pci) ", " AMD PCnet/PCI 79C970/PCnet32/PCnet/PCI II 79C970A (pcnet32) ", " PCnet/PCI II 79C971A (pcnet32) ", " Allied Telesyn AT2550 (rtl8139) ", " Genius GF100TXR (RTL8139) (rtl8139) ", " NDC Communications NE100TX-E (rtl8139) ", " RealTek RTL8129/8139 Fast (rtl8139) ", " SMC Ultra/SMC UltraEZ/SMC Ultra32 (smc-ultra) ", " Compaq Netelligent 10 T PCI UTP (tlan) ", " Compaq Netelligent 10/100 TX PCI UTP (tlan) ", " Compaq Netelligent Integrated 10/100 TX UTP (tlan) ", " Compaq Netelligent 10/100 TX Embedded UTP (tlan) ", " Compaq Netelligent 10/100 TX UTP (tlan) ", " Compaq Netelligent 10 T/2 PCI UTP/Coax (tlan) ", " Accton EtherDuo PCI/Accton EN1207 (tulip) ", " Adaptec ANA6901/C/Adaptec ANA6911/TX (tulip) ", " C-NET CNE-935 (tulip) ", " Cogent EM100/Cogent EM110/Cogent EM400 (tulip) ", " Cogent EM960/Cogent EM964 Quartet (tulip) ", " Danpex EN-9400P3 (tulip) ", " D-Link DFE500-Tx/D-Link DE-530CT (tulip) ", " Linksys EtherPCI (tulip) ", " Kingston EtherX KNT40T/Kingston EtherX KNE100TX (tulip) ", " Netgear FX310 TX 10/100 (tulip) ", " SMC EtherPower/SMC 8432BT/ SMC Ether Power10/100 (tulip) ", " Surecom EP-320X (tulip) ", " Thomas Conrad TC5048 (tulip) ", " Znyx ZX312 EtherAction/Znyx ZX314/ZX315 (tulip) ", " Znyx ZX342/ZX344/ZX345/ZX346/ZX348 (tulip) ", " Znyx ZX351 (tulip) ", " ¼¼ÆõǾîÀÖÁö ¾Ê½À´Ï´Ù! (No Setting)" }; if (((pszIPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszNetmask = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate1IPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate1Netmask = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate2IPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate2Netmask = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszGateway = (char *)malloc(sizeof(char)*18)) == NULL)) { emit printf("DefGeneric Class/Network: Memory ÇÒ´ç ¿¡·¯\n"); exit(1); } memset(pszIPAddr, '\0', 18); memset(pszNetmask, '\0', 18); memset(pszPrivate1IPAddr, '\0', 18); memset(pszPrivate1Netmask, '\0', 18); memset(pszPrivate2IPAddr, '\0', 18); memset(pszPrivate2Netmask, '\0', 18); memset(pszGateway, '\0', 18); getCurrentGateway(pszGateway); getCurrentIPAddr(pszIPAddr); getCurrentNetmask(pszNetmask); pNet = calculateNetMaskTab(pszIPAddr, pszNetmask); getPrivate1Netmask(pszPrivate1Netmask); getPrivate1IPAddr(pszPrivate1IPAddr); pNetPrivate1 = calculateNetMaskTab(pszPrivate1IPAddr, pszPrivate1Netmask); getPrivate2Netmask(pszPrivate2Netmask); getPrivate2IPAddr(pszPrivate2IPAddr); pNetPrivate2 = calculateNetMaskTab(pszPrivate2IPAddr, pszPrivate2Netmask); /***********************/ lblGenericNetworkTitle = new QLabel( "Network Setting (ÀϹÝÀûÀÎ ³×Æ®¿öÅ© ¼³Á¤)", this); lblGenericNetworkTitle->setGeometry(20, 20, 400, 20); // printLabelFormat(lblGenericNetworkTitle); /***********************/ frEthInfo = new QFrame(this); frEthInfo->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); frEthInfo->setGeometry(25, 50, 700, 362); lblGateway = new QLabel("°ÔÀÌÆ®¿þÀÌ", frEthInfo); lblGateway->setGeometry(10, 15, 80, 20); leGateway = new QLineEdit(frEthInfo); leGateway->setGeometry(90, 15, 150, 20); leGateway->setText(pszGateway); lblSeparator1 = new QLabel(frEthInfo); lblSeparator1->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); lblSeparator1->setGeometry(20, 45, 630, 2); /******** Ethernet Card 0 ********/ lblEth0 = new QLabel("ù¹ø° ÀÌ´õ³ÝÄ«µå", frEthInfo); lblEth0->setGeometry(90, 10+50, 100, 20); lblEth0IPAddr = new QLabel("IP ÁÖ¼Ò ", frEthInfo); lblEth0IPAddr->setGeometry(10, 40+50, 80, 20); leEth0IPAddr = new QLineEdit(frEthInfo); leEth0IPAddr->setGeometry(90, 40+50, 150, 20); leEth0IPAddr->setText(pszIPAddr); /*** text -> proc ***/ lblEth0Netmask = new QLabel("Netmask ", frEthInfo); lblEth0Netmask->setGeometry(10, 40+30+50, 80, 20); leEth0Netmask = new QLineEdit(frEthInfo); leEth0Netmask->setGeometry(90, 40+30+50, 150, 20); leEth0Netmask->setText(pszNetmask); lblEth0Network = new QLabel("Network ", frEthInfo); lblEth0Network->setGeometry(10, 40+60+50, 80, 20); leEth0Network = new QLineEdit(frEthInfo); leEth0Network->setGeometry(90, 40+60+50, 150, 20); leEth0Network->setEnabled(0); leEth0Network->setText(pNet.pszNetwork); lblEth0Broadcast = new QLabel("Broadcast ", frEthInfo); lblEth0Broadcast->setGeometry(10, 40+90+50, 80, 20); leEth0Broadcast = new QLineEdit(frEthInfo); leEth0Broadcast->setGeometry(90, 40+90+50, 150, 20); leEth0Broadcast->setEnabled(0); leEth0Broadcast->setText(pNet.pszBroadcast); lblSeparator2 = new QLabel(frEthInfo); lblSeparator2->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); lblSeparator2->setGeometry(20, 40+90+50+40, 630, 2); /*** text -> proc ***/ /*********************************/ /******** Ethernet Card 1 ********/ lblEth1 = new QLabel("µÎ¹ø° ÀÌ´õ³ÝÄ«µå", frEthInfo); lblEth1->setGeometry(300, 10+50, 100, 20); leEth1IPAddr = new QLineEdit(frEthInfo); leEth1IPAddr->setGeometry(300, 40+50, 150, 20); leEth1IPAddr->setText(pszPrivate1IPAddr); /*** text -> proc ***/ leEth1Netmask = new QLineEdit(frEthInfo); leEth1Netmask->setGeometry(300, 40+30+50, 150, 20); leEth1Netmask->setText(pszPrivate1Netmask); /*** text -> proc ***/ leEth1Network = new QLineEdit(frEthInfo); leEth1Network->setGeometry(300, 40+60+50, 150, 20); leEth1Broadcast = new QLineEdit(frEthInfo); leEth1Broadcast->setGeometry(300, 40+90+50, 150, 20); leEth1Network->setEnabled(0); leEth1Broadcast->setEnabled(0); if (strlen(pszPrivate1IPAddr) >= 7) { leEth1Network->setText(pNetPrivate1.pszNetwork); leEth1Broadcast->setText(pNetPrivate1.pszBroadcast); } /*********************************/ /******** Ethernet Card 2 ********/ lblEth2 = new QLabel("¼¼¹ø° ÀÌ´õ³ÝÄ«µå", frEthInfo); lblEth2->setGeometry(520, 10+50, 100, 20); leEth2IPAddr = new QLineEdit(frEthInfo); leEth2IPAddr->setGeometry(520, 40+50, 150, 20); leEth2IPAddr->setText(pszPrivate2IPAddr); /*** text -> proc ***/ leEth2Netmask = new QLineEdit(frEthInfo); leEth2Netmask->setGeometry(520, 40+30+50, 150, 20); leEth2Netmask->setText(pszPrivate2Netmask); /*** text -> proc ***/ leEth2Network = new QLineEdit(frEthInfo); leEth2Network->setGeometry(520, 40+60+50, 150, 20); leEth2Broadcast = new QLineEdit(frEthInfo); leEth2Broadcast->setGeometry(520, 40+90+50, 150, 20); leEth2Network->setEnabled(0); leEth2Broadcast->setEnabled(0); if (strlen(pszPrivate2IPAddr) >= 7) { leEth2Broadcast->setText(pNetPrivate2.pszBroadcast); leEth2Network->setText(pNetPrivate2.pszNetwork); } /*********************************/ for (i = 0; i < 2; i++) { pszSaveListStr[i] = (char *)malloc(sizeof(char)*200); memset(pszSaveListStr[i], '\0', 200); } /*********************************/ lblEth0NetCard = new QLabel("Ethernet 0 Ä«µå", frEthInfo); lblEth0NetCard->setGeometry(10, 40+90+70+60, 90, 20); cbEthNetCard[0] = new QComboBox(frEthInfo, "comboBox_Eth0"); cbEthNetCard[0]->setGeometry(110, 40+90+70+60, 470, 20); for (i = 0; i < 40; i++) cbEthNetCard[0]->insertItem(pszNetCard[i]); cbEthNetCard[0]->setAutoResize(FALSE); if (saveSearchLineToFile("alias eth0", pszSaveListStr, "/etc/conf.modules", 80, 200)) { strcpy(pszNetConfNetCard[0], pszSaveListStr[0]+11); pszNetConfNetCard[0][strlen(pszNetConfNetCard[0])-1] = '\0'; } if (strlen(pszIPAddr) >= 7) { for (nCardIdx = 0; nCardIdx < 40; nCardIdx++) if (strstr(pszNetCard[nCardIdx], pszNetConfNetCard[0]) != (char *)NULL) break; if (strlen(pszNetConfNetCard[0]) < 2) nCardIdx = 39; cbEthNetCard[0]->setCurrentItem(nCardIdx); } else { nCardIdx = 39; cbEthNetCard[0]->setCurrentItem(nCardIdx); } /*********************************/ lblEth1NetCard = new QLabel("Ethernet 1 Ä«µå", frEthInfo); lblEth1NetCard->setGeometry(10, 40+90+70+90, 90, 20); cbEthNetCard[1] = new QComboBox(frEthInfo, "comboBox_Eth1"); cbEthNetCard[1]->setGeometry(110, 40+90+70+90, 470, 20); for (i = 0; i < 40; i++) cbEthNetCard[1]->insertItem(pszNetCard[i]); cbEthNetCard[1]->setAutoResize(FALSE); for (i = 0; i < 2; i++) memset(pszSaveListStr[i], '\0', 200); if (saveSearchLineToFile("alias eth1", pszSaveListStr, "/etc/conf.modules", 80, 200)) { strcpy(pszNetConfNetCard[1], pszSaveListStr[0]+11); pszNetConfNetCard[1][strlen(pszNetConfNetCard[1])-1] = '\0'; } if (strlen(pszPrivate1IPAddr) >= 7) { for (nCardIdx = 0; nCardIdx < 40; nCardIdx++) if (strstr(pszNetCard[nCardIdx], pszNetConfNetCard[1]) != (char *)NULL) break; if (strlen(pszNetConfNetCard[1]) < 2) nCardIdx = 39; cbEthNetCard[1]->setCurrentItem(nCardIdx); } else { nCardIdx = 39; cbEthNetCard[1]->setCurrentItem(nCardIdx); } /**********************************/ lblEth2NetCard = new QLabel("Ethernet 2 Ä«µå", frEthInfo); lblEth2NetCard->setGeometry(10, 40+90+70+120, 90, 20); cbEthNetCard[2] = new QComboBox(frEthInfo, "comboBox_Eth2"); cbEthNetCard[2]->setGeometry(110, 40+90+70+120, 470, 20); for (i = 0; i < 40; i++) cbEthNetCard[2]->insertItem(pszNetCard[i]); cbEthNetCard[2]->setAutoResize(FALSE); for (i = 0; i < 2; i++) memset(pszSaveListStr[i], '\0', 200); if (saveSearchLineToFile("alias eth2", pszSaveListStr, "/etc/conf.modules", 80, 200)) { strcpy(pszNetConfNetCard[2], pszSaveListStr[0]+11); pszNetConfNetCard[2][strlen(pszNetConfNetCard[2])-1] = '\0'; } if (strlen(pszPrivate2IPAddr) >= 7) { for (nCardIdx = 0; nCardIdx < 40; nCardIdx++) if (strstr(pszNetCard[nCardIdx], pszNetConfNetCard[2]) != (char *)NULL) break; if (strlen(pszNetConfNetCard[2]) < 2) nCardIdx = 39; cbEthNetCard[2]->setCurrentItem(nCardIdx); } else { nCardIdx = 39; cbEthNetCard[2]->setCurrentItem(nCardIdx); } cbEthNetCard[2]->setGeometry(110, 40+90+70+125, 470, 20); /*************************************/ bttnApply = new QPushButton("Àû ¿ë", this); bttnApply->setGeometry(150, 50+60+90+70+120+80, 150, 30); QObject::connect(bttnApply, SIGNAL(clicked()), this, SLOT(setApply())); bttnCancel = new QPushButton("Ãë ¼Ò", this); bttnCancel->setGeometry(450, 50+60+90+70+120+80, 150, 30); QObject::connect(bttnCancel, SIGNAL(clicked()), this, SLOT(setCancel())); /************************************/ for (i = 0; i < 2; i++) free(pszSaveListStr[i]); free(pszIPAddr); free(pszNetmask); free(pszPrivate1IPAddr); free(pszPrivate1Netmask); free(pszPrivate2IPAddr); free(pszPrivate2Netmask); free(pszGateway); } clssDefGeneric::~clssDefGeneric() { int i; delete lblEth0; delete lblEth0IPAddr; delete lblEth0Netmask; delete lblEth0Network; delete lblEth0Broadcast; delete leEth0IPAddr; delete leEth0Netmask; delete leEth0Network; delete leEth0Broadcast; delete lblEth1; delete leEth1IPAddr; delete leEth1Netmask; delete leEth1Network; delete leEth1Broadcast; delete lblEth2; delete leEth2IPAddr; delete leEth2Netmask; delete leEth2Network; delete leEth2Broadcast; delete lblGateway; delete leGateway; delete lblSeparator1; delete lblSeparator2; for (i = 0; i < 3; i++) delete cbEthNetCard[i]; delete lblEth0NetCard; delete lblEth1NetCard; delete lblEth2NetCard; delete bttnCancel; delete bttnApply; delete lblGenericNetworkTitle; delete frEthInfo; } void clssDefGeneric::setApply() { char *pszIfCfgEthFile = "DEVICE=%s\nIPADDR=%s\nNETMASK=%s\nNETWORK=%s\nBROADCAST=%s\nONBOOT=yes\n"; char *pszNetworkFile = "NETWORKING=yes\nFORWARD_IPV4=true\nHOSTNAME=%s.%s\nDOMAINNAME=%s\nGATEWAY=%s\nGATEWAYDEV=eth0\n"; char pszOptions[95]; char *pszSaveCardLine[3], pszSaveHostName[256], pszSaveDomainName[256]; NetTab pNet, pNetPrivate1, pNetPrivate2; FILE *fp; S_Addr pAddr, pSaveAddr; char pszTmpSearch[100]; char pszTmpInsert[100]; char pszSaveIP[18]; int i; memset(pszSaveIP, '\0', 18); getCurrentIPAddr(pszSaveIP); pSaveAddr = separateAddress(pszSaveIP); pNet = calculateNetMaskTab((char *)leEth0IPAddr->text(), (char *)leEth0Netmask->text()); pNetPrivate1 = calculateNetMaskTab((char *)leEth1IPAddr->text(), (char *)leEth1Netmask->text()); pNetPrivate2 = calculateNetMaskTab((char *)leEth2IPAddr->text(), (char *)leEth2Netmask->text()); memset(pszSaveHostName, '\0', 256); memset(pszSaveDomainName, '\0', 256); getCurrentHostName(pszSaveHostName, pszSaveDomainName); leEth0Network->setText(pNet.pszNetwork); leEth0Broadcast->setText(pNet.pszBroadcast); leEth1Network->setText(pNetPrivate1.pszNetwork); leEth1Broadcast->setText(pNetPrivate1.pszBroadcast); leEth2Network->setText(pNetPrivate2.pszNetwork); leEth2Broadcast->setText(pNetPrivate2.pszBroadcast); fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth0", "w"); fprintf(fp, pszIfCfgEthFile, "eth0", leEth0IPAddr->text(), leEth0Netmask->text(), leEth0Network->text(), leEth0Broadcast->text()); fclose(fp); if (strlen((char *)leEth1IPAddr->text()) >= 7) { char pszPrivate1IPAddr[20]; char pszCommand[150]; fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth1", "w"); fprintf(fp, pszIfCfgEthFile, "eth1", leEth1IPAddr->text(), leEth1Netmask->text(), leEth1Network->text(), leEth1Broadcast->text()); fclose(fp); memset(pszPrivate1IPAddr, '\0', 20); memset(pszCommand, '\0', 150); getPrivate1IPAddr(pszPrivate1IPAddr); sprintf(pszCommand, "/usr/local/topflash/bin/host_ip del %s\n", pszPrivate1IPAddr); system(pszCommand); memset(pszCommand, '\0', 150); sprintf(pszCommand, "/usr/local/topflash/bin/host_ip add %s\n", leEth1IPAddr->text()); system(pszCommand); } if (strlen((char *)leEth2IPAddr->text()) >= 7) { char pszPrivate2IPAddr[20]; char pszCommand[150]; fp = fopen("/etc/sysconfig/network-scripts/ifcfg-eth2", "w"); fprintf(fp, pszIfCfgEthFile, "eth2", leEth2IPAddr->text(), leEth2Netmask->text(), leEth2Network->text(), leEth2Broadcast->text()); fclose(fp); memset(pszPrivate2IPAddr, '\0', 20); memset(pszCommand, '\0', 150); getPrivate2IPAddr(pszPrivate2IPAddr); sprintf(pszCommand, "/usr/local/topflash/bin/host_ip del %s\n", pszPrivate2IPAddr); system(pszCommand); memset(pszCommand, '\0', 150); sprintf(pszCommand, "/usr/local/topflash/bin/host_ip add %s\n", leEth2IPAddr->text()); system(pszCommand); } fp = fopen("/etc/sysconfig/network", "w"); fprintf(fp, pszNetworkFile, pszSaveHostName, pszSaveDomainName, pszSaveDomainName, leGateway->text()); fclose(fp); for (i = 0; i < 3; i++) { if ((pszSaveCardLine[i] = (char *)malloc(sizeof(char)*50)) == NULL) { printf("pszSaveCardLine Memory Error!\n"); exit(1); } memset(pszSaveCardLine[i], '\0', 50); } for (i = 0; i < 3; i++) { sprintf(pszSaveCardLine[i], "alias eth%d ", i); if (cbEthNetCard[i]->currentItem() >= 0 && cbEthNetCard[i]->currentItem() <= 2) strcat(pszSaveCardLine[i], "3c59x"); else if (cbEthNetCard[i]->currentItem() == 3) strcat(pszSaveCardLine[i], "eepro100"); else if (cbEthNetCard[i]->currentItem() >= 4 && cbEthNetCard[i]->currentItem() <= 7) strcat(pszSaveCardLine[i], "hp100"); else if (cbEthNetCard[i]->currentItem() == 8) strcat(pszSaveCardLine[i], "ibmtr"); else if (cbEthNetCard[i]->currentItem() == 9) strcat(pszSaveCardLine[i], "ne2k-pci"); else if (cbEthNetCard[i]->currentItem() == 10 || cbEthNetCard[i]->currentItem() == 11) strcat(pszSaveCardLine[i], "pcnet32"); else if (cbEthNetCard[i]->currentItem() >= 12 && cbEthNetCard[i]->currentItem() <= 15) strcat(pszSaveCardLine[i], "rtl8139"); else if (cbEthNetCard[i]->currentItem() == 16) strcat(pszSaveCardLine[i], "smc-ultra"); else if (cbEthNetCard[i]->currentItem() >= 17 || cbEthNetCard[i]->currentItem() <= 22) strcat(pszSaveCardLine[i], "tlan"); else if (cbEthNetCard[i]->currentItem() >= 23 || cbEthNetCard[i]->currentItem() <= 38) strcat(pszSaveCardLine[i], "tulip"); } for (i = 0; i < 3; i++) strcat(pszSaveCardLine[i], "\n"); addOnNotExistChangeOnExist(pszSaveCardLine[0], "alias eth0", "/etc/conf.modules", 200, 100); addOnNotExistChangeOnExist(pszSaveCardLine[1], "alias eth1", "/etc/conf.modules", 200, 100); addOnNotExistChangeOnExist(pszSaveCardLine[2], "alias eth2", "/etc/conf.modules", 200, 100); if (cbEthNetCard[0]->currentItem() == 39) insertStrToFile("", "alias eth0", "/etc/conf.modules", 200, 100); if (cbEthNetCard[1]->currentItem() == 39) insertStrToFile("", "alias eth1", "/etc/conf.modules", 200, 100); if (cbEthNetCard[2]->currentItem() == 39) insertStrToFile("", "alias eth2", "/etc/conf.modules", 200, 100); for (i = 0; i < 3; i++) free(pszSaveCardLine[i]); if (cbEthNetCard[0]->currentItem() == 39) { system("rm -f /etc/sysconfig/network-scripts/ifcfg-eth0"); leEth0IPAddr->setText(""); leEth0Netmask->setText(""); leEth0Network->setText(""); leEth0Broadcast->setText(""); } if (cbEthNetCard[1]->currentItem() == 39) { system("rm -f /etc/sysconfig/network-scripts/ifcfg-eth1"); leEth1IPAddr->setText(""); leEth1Netmask->setText(""); leEth1Network->setText(""); leEth1Broadcast->setText(""); } if (cbEthNetCard[2]->currentItem() == 39) { system("rm -f /etc/sysconfig/network-scripts/ifcfg-eth2"); leEth2IPAddr->setText(""); leEth2Netmask->setText(""); leEth2Network->setText(""); leEth2Broadcast->setText(""); } /**************************************/ system("cp -f /etc/sysconfig/network-scripts/ifcfg-eth0 \ /etc/sysconfig/network-scripts/ifcfg-eth0.org\n"); system("cp -f /etc/sysconfig/network-scripts/ifcfg-eth1 \ /etc/sysconfig/network-scripts/ifcfg-eth1.org\n"); system("cp -f /etc/sysconfig/network-scripts/ifcfg-eth2 \ /etc/sysconfig/network-scripts/ifcfg-eth2.org\n"); system("cp -f /etc/sysconfig/network /etc/sysconfig/network.org\n"); system("cp -f /etc/conf.modules /etc/conf.modules.org\n"); system("cp -f /etc/resolv.conf /etc/resolv.conf.org\n"); system("/etc/rc.d/init.d/network stop;/etc/rc.d/init.d/network start\n"); } void clssDefGeneric::setCancel() { char *pszIPAddr, *pszNetmask, *pszGateway, *pszHostName, *pszDomainName; char *pszPrivate1IPAddr, *pszPrivate1Netmask, *pszPrivate2IPAddr; char *pszPrivate2Netmask; NetTab pNet, pNetPrivate1, pNetPrivate2; char *pszSaveListStr[2]; if (((pszIPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszNetmask = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate1IPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate1Netmask = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate2IPAddr = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszPrivate2Netmask = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszGateway = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszHostName = (char *)malloc(sizeof(char)*256)) == NULL) || ((pszDomainName = (char *)malloc(sizeof(char)*256)) == NULL)) { emit printf("DefGeneric Class/Network: Memory ÇÒ´ç ¿¡·¯\n"); exit(1); } memset(pszIPAddr, '\0', 18); memset(pszNetmask, '\0', 18); memset(pszPrivate1IPAddr, '\0', 18); memset(pszPrivate1Netmask, '\0', 18); memset(pszPrivate2IPAddr, '\0', 18); memset(pszPrivate2Netmask, '\0', 18); memset(pszGateway, '\0', 18); memset(pszHostName, '\0', 256); memset(pszDomainName, '\0', 256); getCurrentHostName(pszHostName, pszDomainName); getCurrentGateway(pszGateway); getCurrentIPAddr(pszIPAddr); getCurrentNetmask(pszNetmask); pNet = calculateNetMaskTab(pszIPAddr, pszNetmask); getPrivate1Netmask(pszPrivate1Netmask); getPrivate1IPAddr(pszPrivate1IPAddr); pNetPrivate1 = calculateNetMaskTab(pszPrivate1IPAddr, pszPrivate1Netmask); getPrivate2Netmask(pszPrivate2Netmask); getPrivate2IPAddr(pszPrivate2IPAddr); pNetPrivate2 = calculateNetMaskTab(pszPrivate2IPAddr, pszPrivate2Netmask); /***** lineeditbox init: proc -> segmentation fault *****/ leGateway->setText(pszGateway);; leEth0IPAddr->setText(pszIPAddr); leEth0Netmask->setText(pszNetmask); leEth0Network->setText(pNet.pszNetwork); leEth0Broadcast->setText(pNet.pszBroadcast); leEth1IPAddr->setText(pszPrivate1IPAddr); leEth1Netmask->setText(pszPrivate1Netmask); leEth1Network->setText(pNetPrivate1.pszNetwork); leEth1Broadcast->setText(pNetPrivate1.pszBroadcast); leEth2IPAddr->setText(pszPrivate2IPAddr); leEth2Netmask->setText(pszPrivate2Netmask); leEth2Network->setText(pNetPrivate2.pszNetwork); leEth2Broadcast->setText(pNetPrivate2.pszBroadcast); } void clssDefGeneric::printLabelFormat(QLabel *lblBold) { QPalette p = QWidget::palette(); QColorGroup n = palette().normal(); QColorGroup g(n.background(), n.foreground(), n.light(), n.dark(), n.mid(), n.background(), n.base()); p.setNormal(g); setPalette(p); lblBold->setPalette(p); lblBold->setMargin(3); QFont bold = *QApplication::font(); bold.setBold(TRUE); bold.setPointSize(bold.pointSize()+2); lblBold->setFont(bold); lblBold->setFixedSize(lblBold->sizeHint()); lblBold->setFixedSize(lblBold->sizeHint()); } // ---------------------------------------------------------------- // ---------------- < Source : clssDNS.h > ------------------------ #include class QLabel; class QLineEdit; class QComboBox; /* to combobox */ class QPushButton; class QFrame; class clssDefDNS : public QWidget { Q_OBJECT public: clssDefDNS(); ~clssDefDNS(); public slots: void printLabelFormat(QLabel *lblDNSTitle); void rebootSystem(); private slots: void applySetting(); void cancelSetting(); void addDNS(); void delDNS(); private: QLabel *lblHostName; QLabel *lblDomainName; QLineEdit *leHostName; QLineEdit *leDomainName; QLabel *lblDNSServer; QComboBox *cbDNSServer; QPushButton *bttnCancel; QPushButton *bttnApply; QFrame *frWorkArea; QLabel *lblSeparator; QPushButton *bttnAdd; QPushButton *bttnDel; QLabel *lblDNSTitle; }; // ---------------------------------------------------------------- // ---------------- < Source : clssDNS.cpp > ---------------------- #include #include #include #include #include /* test */ #include #include #include #include "network.h" #include "proc_file.h" #include "clssDNS.h" clssDefDNS::clssDefDNS() { char *pszNetmask, *pszHostName, *pszDomainName; int i, j; NetTab pNet; if (((pszNetmask = (char *)malloc(sizeof(char)*18)) == NULL) || ((pszHostName = (char *)malloc(sizeof(char)*256)) == NULL) || ((pszDomainName = (char *)malloc(sizeof(char)*256)) == NULL)) { emit printf("GenericNetwork Class/Network: Memory ÇÒ´ç ¿¡·¯\n"); exit(1); } memset(pszHostName, '\0', 256); memset(pszDomainName, '\0', 256); getCurrentHostName(pszHostName, pszDomainName); /***********************/ lblDNSTitle = new QLabel("DNS Setting (DNS ¼³Á¤)", this); lblDNSTitle->setGeometry(10, 10, 400, 20); // printLabelFormat(lblDNSTitle); frWorkArea = new QFrame(this); frWorkArea->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); frWorkArea->setGeometry(30, 30, 330, 430); /******** Ethernet Card 0 ********/ lblHostName = new QLabel("È£½ºÆ®¸í", frWorkArea); lblHostName->setGeometry(20, 50, 80, 20); leHostName = new QLineEdit(frWorkArea); leHostName->setGeometry(100, 50, 180, 20); leHostName->setText(pszHostName); lblDomainName = new QLabel("µµ¸ÞÀθí", frWorkArea); lblDomainName->setGeometry(20, 80, 80, 20); leDomainName = new QLineEdit(frWorkArea); leDomainName->setGeometry(100, 80, 180, 20); leDomainName->setText(pszDomainName); bttnApply = new QPushButton("Àû ¿ë", frWorkArea); bttnApply->setGeometry(50, 160, 80, 30); QObject::connect(bttnApply, SIGNAL(clicked()), this, SLOT(applySetting())); bttnCancel = new QPushButton("Ãë ¼Ò", frWorkArea); bttnCancel->setGeometry(180, 160, 80, 30); QObject::connect(bttnCancel, SIGNAL(clicked()), this, SLOT(cancelSetting())); /*************************************/ lblSeparator = new QLabel(frWorkArea); lblSeparator->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); lblSeparator->setGeometry(20, 230, 290, 2); lblDNSServer = new QLabel("DNS¼­¹ö", frWorkArea); lblDNSServer->setGeometry(20, 280, 80, 20); cbDNSServer = new QComboBox(TRUE, frWorkArea, "comboBox_DNS"); cbDNSServer->setGeometry(100, 280, 150, 20); char *pszDNSServer[50]; int nCntDNS = countAllLineToFile("/etc/resolv.conf", 50, 200); for (i = 0; i < 50; i++) { if ((pszDNSServer[i] = (char *)malloc(sizeof(char)*200)) == NULL) { printf("Memory allocation error!\n"); exit(1); } memset(pszDNSServer[i], '\0', 200); } getDNSServer(pszDNSServer); for (i = 0; i < nCntDNS-1; i++) cbDNSServer->insertItem(pszDNSServer[i]); cbDNSServer->setAutoResize(FALSE); for (i = 0; i < 50; i++) free(pszDNSServer[i]); bttnAdd = new QPushButton("Ãß °¡", frWorkArea); bttnAdd->setGeometry(50, 350, 80, 30); QObject::connect(bttnAdd, SIGNAL(clicked()), this, SLOT(addDNS())); bttnDel = new QPushButton("»è Á¦", frWorkArea); bttnDel->setGeometry(180, 350, 80, 30); QObject::connect(bttnDel, SIGNAL(clicked()), this, SLOT(delDNS())); /************************************/ free(pszHostName); free(pszDomainName); } clssDefDNS::~clssDefDNS() { int i; delete lblHostName; delete lblDomainName; delete leHostName; delete leDomainName; delete bttnCancel; delete bttnApply; delete lblDNSServer; delete cbDNSServer; delete bttnAdd; delete bttnDel; delete frWorkArea; delete lblDNSTitle; } void clssDefDNS::addDNS() { char pszTmpSearch[100], pszTmpInsert[100]; if (strlen(cbDNSServer->text(cbDNSServer->currentItem())) != 0) { if (strcmp(cbDNSServer->text(cbDNSServer->currentItem()), cbDNSServer->currentText()) != 0) cbDNSServer->insertItem(cbDNSServer->currentText()); /*** resolv.conf DNS server changed ***/ memset(pszTmpSearch, '\0', 100); memset(pszTmpInsert, '\0', 100); sprintf(pszTmpInsert, "nameserver %s\n", cbDNSServer->currentText()); sprintf(pszTmpSearch, "nameserver %s", cbDNSServer->currentText()); if (!searchStrInFile(pszTmpSearch, "/etc/resolve.conf", 100, 100)) addOnNotExistChangeOnExist(pszTmpInsert, pszTmpSearch, "/etc/resolv.conf", 100, 100); } } void clssDefDNS::delDNS() { char pszTmpSearch[100], pszTmpInsert[100]; if (strlen(cbDNSServer->text(cbDNSServer->currentItem())) != 0) { /*** resolv.conf DNS server changed ***/ memset(pszTmpSearch, '\0', 100); sprintf(pszTmpSearch, "nameserver %s", cbDNSServer->text(cbDNSServer->currentItem())); if (!searchStrInFile(pszTmpSearch, "/etc/resolve.conf", 100, 100)) insertStrToFile("", pszTmpSearch, "/etc/resolv.conf", 100, 100); cbDNSServer->removeItem(cbDNSServer->currentItem()); cbDNSServer->setCurrentItem(0); } } void clssDefDNS::applySetting() { char *pszNetworkFile = "NETWORKING=yes\nFORWARD_IPV4=true\nHOSTNAME=%s.%s\nDOMAINNAME=%s\nGATEWAY=%s\nGATEWAYDEV=eth0\n"; char pszGateway[18]; char pszOptions[95]; char *pszSaveCardLine[3]; FILE *fp; S_Addr pAddr; char pszTmpSearch[100], pszTmpInsert[100]; char pszSaveIP[18], pszSaveHostName[256], pszSaveDomainName[256]; int i; char pszCommand[200]; memset(pszSaveIP, '\0', 18); memset(pszGateway, '\0', 18); memset(pszSaveHostName, '\0', 256); memset(pszSaveDomainName, '\0', 256); getCurrentIPAddr(pszSaveIP); getCurrentGateway(pszGateway); getCurrentHostName(pszSaveHostName, pszSaveDomainName); fp = fopen("/etc/sysconfig/network", "w"); fprintf(fp, pszNetworkFile, leHostName->text(), leDomainName->text(), leDomainName->text(), pszGateway); fclose(fp); /**** update named daemon ****/ if (strlen(leHostName->text()) >= 1) { pAddr = separateAddress(pszSaveIP); /*** HOSTNAME Host,Domain changed ***/ char pszTmpDomain[100]; char pszTmpHost[50]; memset(pszTmpInsert, '\0', 100); memset(pszTmpHost, '\0', 50); memset(pszTmpDomain, '\0', 100); strcpy(pszTmpHost, leHostName->text()); strcpy(pszTmpDomain, leDomainName->text()); sprintf(pszTmpInsert, "%s.%s\n", pszTmpHost, pszTmpDomain); addOnNotExistChangeOnExist(pszTmpInsert, pszSaveHostName, "/etc/HOSTNAME", 100, 100); memset(pszTmpDomain, '\0', 100); memset(pszTmpHost, '\0', 50); strcpy(pszTmpHost, leHostName->text()); strcpy(pszTmpDomain, leDomainName->text()); if (strcmp(pszSaveDomainName, pszTmpDomain) != 0 || strcmp(pszSaveHostName, pszTmpHost) != 0) { QWidget *wdgtRebooting = new QWidget(); wdgtRebooting->setGeometry(300, 300, 300, 150); QLabel *lblRebooting = new QLabel( "È£½ºÆ®À̸§ ȤÀº µµ¸ÞÀÎ À̸§ÀÌ ¹Ù²î¾úÀ¸¹Ç·Î\nÀçºÎÆÃÀ» ÇÏ°Ú½À´Ï´Ù.", wdgtRebooting); lblRebooting->setGeometry(20, 20, 250, 50); QPushButton *bttnRebooting = new QPushButton("Àç ºÎ ÆÃ", wdgtRebooting); bttnRebooting->setGeometry(120, 90, 120, 30); QObject::connect(bttnRebooting, SIGNAL(clicked()), this, SLOT(rebootSystem())); wdgtRebooting->show(); } } system("/etc/rc.d/init.d/network stop;/etc/rc.d/init.d/network restart\n"); } void clssDefDNS::cancelSetting() { char *pszHostName, *pszDomainName; char *pszSaveListStr[2]; if (((pszHostName = (char *)malloc(sizeof(char)*256)) == NULL) || ((pszDomainName = (char *)malloc(sizeof(char)*256)) == NULL)) { emit printf("GenericNetwork Class/Network: Memory ÇÒ´ç ¿¡·¯\n"); exit(1); } memset(pszHostName, '\0', 256); memset(pszDomainName, '\0', 256); getCurrentHostName(pszHostName, pszDomainName); leHostName->setText(pszHostName); leDomainName->setText(pszDomainName); } void clssDefDNS::rebootSystem() { system("sync;sync;sync;sync;sync;sync;sync;sync;init 6\n"); } void clssDefDNS::printLabelFormat(QLabel *lblBold) { QPalette p = QWidget::palette(); QColorGroup n = palette().normal(); QColorGroup g(n.background(), n.foreground(), n.light(), n.dark(), n.mid(), n.background(), n.base()); p.setNormal(g); setPalette(p); lblBold->setPalette(p); lblBold->setMargin(3); QFont bold = *QApplication::font(); bold.setBold(TRUE); bold.setPointSize(bold.pointSize()+2); lblBold->setFont(bold); lblBold->setFixedSize(lblBold->sizeHint()); lblBold->setFixedSize(lblBold->sizeHint()); } // ---------------------------------------------------------------- // ---------------- < Source : clssAlias.h > ---------------------- #include class QLineEdit; class QLabel; class QLineEdit; class QListView; class QListViewItem; class QFrame; class QPushButton; class clssDefAlias : public QWidget { Q_OBJECT public: clssDefAlias(); ~clssDefAlias(); public slots: void addSetting(); void deleteSetting(); void getAliasingItem(); void printLabelFormat(QLabel *lblAliasingTitle); private slots: private: QFrame *frWorkArea; QPushButton *bttnAdd; QPushButton *bttnDelete; QFrame *frAliasList; QListView *lvAliasList; QListViewItem *lviAlias[100]; QLabel *lblNetworkArea; QLabel *lblIP; QLineEdit *leIP; QLabel *lblNetmask; QLineEdit *leNetmask; QLabel *lblNetwork; QLineEdit *leNetwork; QLabel *lblBroadcast; QLineEdit *leBroadcast; QLabel *lblAliasingTitle; int nAliasCount; }; // ---------------------------------------------------------------- // ---------------- < Source : clssAlias.cpp > -------------------- #include #include #include #include #include #include #include #include #include #include "proc_file.h" #include "network.h" #include "clssAlias.h" clssDefAlias::clssDefAlias() { int i; char pszSaveFile[100]; char pszVirtualIP[18]; FILE *fp; for (nAliasCount = 0; nAliasCount < 10; nAliasCount++) { memset(pszSaveFile, '\0', 100); sprintf(pszSaveFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:%d", nAliasCount); if ((fp = fopen(pszSaveFile, "r")) == NULL) break; fclose(fp); } lblAliasingTitle = new QLabel("Virtual LAN (°¡»ó ³×Æ®¿öÅ© Ä«µå ¼³Á¤)", this); lblAliasingTitle->setGeometry(10, 10, 400, 20); // printLabelFormat(lblAliasingTitle); frWorkArea = new QFrame(this, "IP Aliasing Area"); frWorkArea->setFrameStyle(QFrame::Box | QFrame::Raised | QFrame::Plain); frWorkArea->setGeometry(40, 60, 670, 310); lblNetworkArea = new QLabel("³×Æ®¿öÅ©¿µ¿ª ¼±ÅÃ", frWorkArea); lblNetworkArea->setGeometry(30, 20, 120, 20); frAliasList = new QFrame(frWorkArea, "Alias List Area"); frAliasList->setFrameStyle(QFrame::Box | QFrame::Sunken | QFrame::WinPanel); frAliasList->setGeometry(30, 60, 320, 220); lvAliasList = new QListView(frAliasList); lvAliasList->setGeometry(3, 3, 314, 214); lvAliasList->addColumn(" °¡»ó ³×Æ®¿öÅ© "); lvAliasList->addColumn(" IP ÁÖ¼Ò "); lvAliasList->setRootIsDecorated(true); if (nAliasCount > 0) { char pszVirtualCard[10]; for (i = 0; i < nAliasCount; i++) { memset(pszVirtualCard, '\0', 10); memset(pszVirtualIP, '\0', 18); sprintf(pszVirtualCard, "eth0:%d", i); getAliasIP(pszVirtualIP, i); lviAlias[i] = new QListViewItem(lvAliasList, pszVirtualCard, pszVirtualIP); } } QObject::connect(lvAliasList, SIGNAL(selectionChanged()), this, SLOT(getAliasingItem())); lblIP = new QLabel("IP ÁÖ¼Ò", frWorkArea); lblIP->setGeometry(400, 60, 70, 20); leIP = new QLineEdit(frWorkArea); leIP->setGeometry(480, 60, 130, 20); lblNetmask = new QLabel("³Ý¸¶½ºÅ©", frWorkArea); lblNetmask->setGeometry(400, 100, 70, 20); leNetmask = new QLineEdit(frWorkArea); leNetmask->setGeometry(480, 100, 130, 20); leNetmask->setEnabled(false); lblNetwork = new QLabel("³×Æ®¿öÅ©", frWorkArea); lblNetwork->setGeometry(400, 140, 70, 20); leNetwork = new QLineEdit(frWorkArea); leNetwork->setGeometry(480, 140, 130, 20); leNetwork->setEnabled(false); lblBroadcast = new QLabel("ºê·Îµåij½ºÆ®", frWorkArea); lblBroadcast->setGeometry(400, 180, 70, 20); leBroadcast = new QLineEdit(frWorkArea); leBroadcast->setGeometry(480, 180, 130, 20); leBroadcast->setEnabled(false); bttnAdd = new QPushButton("Ãß°¡", this); bttnAdd->setGeometry(100, 410, 150, 30); QObject::connect(bttnAdd, SIGNAL(clicked()), this, SLOT(addSetting())); bttnDelete = new QPushButton("»èÁ¦", this); bttnDelete->setGeometry(480, 410, 150, 30); QObject::connect(bttnDelete, SIGNAL(clicked()), this, SLOT(deleteSetting())); } clssDefAlias::~clssDefAlias() { int i; delete lblNetworkArea; if (nAliasCount > 0) for (i = 0; i < nAliasCount; i++) lviAlias[i]; delete lvAliasList; delete lblIP; delete leIP; delete lblNetmask; delete leNetmask; delete lblNetwork; delete leNetwork; delete lblBroadcast; delete leBroadcast; delete frAliasList; delete frWorkArea; delete bttnAdd; delete bttnDelete; delete lblAliasingTitle; } void clssDefAlias::getAliasingItem() { char pszNetmask[18]; NetTab pNet; memset(pszNetmask, '\0', 18); getCurrentNetmask(pszNetmask); leIP->setText(lvAliasList->currentItem()->text(1)); pNet = calculateNetMaskTab((char *)leIP->text(), pszNetmask); leNetmask->setText(pszNetmask); leNetwork->setText(pNet.pszNetwork); leBroadcast->setText(pNet.pszBroadcast); } void clssDefAlias::addSetting() { FILE *fp; char pszVirtualCard[10], pszFile[100]; char pszCommand[150]; memset(pszVirtualCard, '\0', 10); memset(pszFile, '\0', 100); sprintf(pszVirtualCard, "eth0:%d", nAliasCount); sprintf(pszFile, "/etc/sysconfig/network-scripts/ifcfg-%s", pszVirtualCard); lviAlias[nAliasCount] = new QListViewItem(lvAliasList, pszVirtualCard, leIP->text()); if ((fp = fopen(pszFile, "w")) == NULL) { emit printf("file open error!\n"); exit(1); } fprintf(fp, "DEVICE=%s\nIPADDR=%s\nONBOOT=yes\n",pszVirtualCard, leIP->text()); fclose(fp); nAliasCount++; system("/etc/rc.d/init.d/network restart\n"); } void clssDefAlias::deleteSetting() { int i, j; char pszCommand[150], pszFile[100]; char pszVirtualIP[18]; FILE *fp; memset(pszFile, '\0', 100); sprintf(pszFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:%d", lvAliasList->itemPos(lvAliasList->currentItem())/18); if ((fp = fopen(pszFile, "r")) == NULL) return; fclose(fp); nAliasCount--; memset(pszCommand, '\0', 150); memset(pszFile, '\0', 100); sprintf(pszFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:*"); sprintf(pszCommand, "rm -f %s\n", pszFile); system(pszCommand); if (nAliasCount > 0) { for (i = 0, j = 0; i < nAliasCount+1; i++) { if (i != lvAliasList->itemPos(lvAliasList->currentItem())/18) { memset(pszFile, '\0', 100); sprintf(pszFile, "/etc/sysconfig/network-scripts/ifcfg-eth0:%d", j); if ((fp = fopen(pszFile, "w")) == NULL) return; fprintf(fp, "DEVICE=eth0:%d\nIPADDR=%s\nONBOOT=yes\n", j, lviAlias[i]->text(1)); fclose(fp); j++; } } } lvAliasList->clear(); if (nAliasCount > 0) { char pszVirtualCard[10]; for (i = 0; i < nAliasCount; i++) { memset(pszVirtualCard, '\0', 10); memset(pszVirtualIP, '\0', 18); sprintf(pszVirtualCard, "eth0:%d", i); getAliasIP(pszVirtualIP, i); lviAlias[i] = new QListViewItem(lvAliasList, pszVirtualCard, pszVirtualIP); } } system("/etc/rc.d/init.d/network restart\n"); } void clssDefAlias::printLabelFormat(QLabel *lblBold) { QPalette p = QWidget::palette(); QColorGroup n = palette().normal(); QColorGroup g(n.background(), n.foreground(), n.light(), n.dark(), n.mid(), n.background(), n.base()); p.setNormal(g); setPalette(p); lblBold->setPalette(p); lblBold->setMargin(3); QFont bold = *QApplication::font(); bold.setBold(TRUE); bold.setPointSize(bold.pointSize()+2); lblBold->setFont(bold); lblBold->setFixedSize(lblBold->sizeHint()); lblBold->setFixedSize(lblBold->sizeHint()); } // ---------------------------------------------------------------- // ---------------- < Source : Network_menu.h > ------------------- #include class QMenuBar; class QPopupMenu; class QToolBar; class clssDefGeneric; class clssDefDNS; class clssDefAlias; class clssNetwork : public QMainWindow { Q_OBJECT public: clssNetwork(); ~clssNetwork(); public slots: void funcGenericNetwork(); void funcDNS(); void funcAlias(); void funcQuit(); protected: private: QMenuBar *mnuMainBar; QPopupMenu *mnuNetwork; QToolBar *tbNetwork; clssDefGeneric *clssGeneric; clssDefDNS *clssDNS; clssDefAlias *clssAlias; }; // ---------------------------------------------------------------- // ---------------- < Source : Network_menu.cpp > ----------------- #include #include #include #include #include #include #include #include #include "Network_menu.h" #include "clssGeneric.h" #include "clssDNS.h" #include "clssAlias.h" #ifndef GENERIC_TOOLTIP #define GENERIC_TOOLTIP "ÀϹÝÀûÀÎ ³×Æ®¿öÅ© ¼³Á¤" #define DNS_TOOLTIP "DNS ¼³Á¤" #define ALIAS_TOOLTIP "Alias ¼³Á¤" #endif clssNetwork::clssNetwork() { QPixmap iconGeneric, iconDNS, iconAlias; iconGeneric.load("./generic.gif"); iconDNS.load("./dns.gif"); iconAlias.load("./alias.gif"); qApp->setStyle(WindowsStyle); mnuNetwork = new QPopupMenu; mnuNetwork->insertItem("ÀÏ¹Ý ³×Æ®¿öÅ© °ü¸®", this, SLOT(funcGenericNetwork())); mnuNetwork->insertItem("DNS °ü¸®", this, SLOT(funcDNS())); mnuNetwork->insertItem("IP-Aliasing °ü¸®", this, SLOT(funcAlias())); mnuNetwork->insertSeparator(); mnuNetwork->insertItem("Á¾·á", this, SLOT(funcQuit())); mnuMainBar = new QMenuBar(this); mnuMainBar->insertItem(" ³×Æ®¿öÅ© ", mnuNetwork); tbNetwork = new QToolBar(this); tbNetwork->setOrientation(tbNetwork->Horizontal); QToolButton *tbttnGeneric = new QToolButton(iconGeneric, GENERIC_TOOLTIP, 0, this, SLOT(funcGenericNetwork()), tbNetwork, "generic"); QToolButton *tbttnDNS = new QToolButton(iconDNS, DNS_TOOLTIP, 0, this, SLOT(funcDNS()), tbNetwork, "dns"); QToolButton *tbttnAlias = new QToolButton(iconAlias, ALIAS_TOOLTIP, 0, this, SLOT(funcAlias()), tbNetwork, "alias"); } clssNetwork::~clssNetwork() { } void clssNetwork::funcGenericNetwork() { clssGeneric = new clssDefGeneric(); clssGeneric->setGeometry(150, 150, 750, 550); clssGeneric->show(); } void clssNetwork::funcDNS() { clssDNS = new clssDefDNS(); clssDNS->setGeometry(150, 150, 400, 500); clssDNS->show(); } void clssNetwork::funcAlias() { clssAlias = new clssDefAlias(); clssAlias->setGeometry(150, 150, 750, 500); clssAlias->show(); } void clssNetwork::funcQuit() { exit(0); } // ---------------------------------------------------------------- // ------------------ < Source : main_menu.cpp > ------------------ #include #include "Network_menu.h" char pszNetConfHost[256]; char pszNetConfDomain[256]; char pszNetConfGateway[18]; char pszNetConfIPAddr[18]; char pszNetConfPrivate1IPAddr[18]; char pszNetConfPrivate2IPAddr[18]; char pszNetConfNetmask[18]; char pszNetConfPrivate1Netmask[18]; char pszNetConfPrivate2Netmask[18]; char pszNetconfBroadcast[18]; char pszNetconfPrivate1Broadcast[18]; char pszNetconfPrivate2Broadcast[18]; char pszNetConfNetwork[18]; char pszNetConfPrivate1Network[18]; char pszNetConfPrivate2Network[18]; char pszNetConfNetCard[3][30]; int nCountListStr; char pszSaveNameServer[20][30]; int nCountNameServer; int nCountClient; extern int nAccountCount; int main(int argc, char* argv[]) { QApplication myapp(argc, argv); clssNetwork *clssTest = new clssNetwork(); clssTest->setGeometry(100, 100, 800, 600); myapp.setMainWidget(clssTest); clssTest->show(); return myapp.exec(); } // ---------------------------------------------------------------- # ------------------------ < Makefile > -------------------------- PROGS = main_menu LIBS = -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm CC = g++ GCC = gcc INCLUDE = -I/usr/lib/qt/include C_FLAG = -pipe -DNO_DEBUG -O2 CFLAGS = $(INCLUDE) $(C_FLAG) SYSCONF_LINK = $(CC) SYSCONF_MOC = /usr/bin/moc MOC = $(SYSCONF_MOC) OTHER_OBJS = \ network.o \ proc_file.o MNU_OBJS = \ main_menu.o \ Network_menu_moc.o \ Network_menu.o \ clssGeneric.o \ clssGeneric_moc.o \ clssDNS.o \ clssDNS_moc.o \ clssAlias.o \ clssAlias_moc.o all: $(PROGS) clean: rm -f *.o rm -f main_menu rm -f *_moc.* ############# COMPILE ############# network.o: network.c $(CC) -c network.c -o $@ proc_file.o: proc_file.c $(CC) -c proc_file.c -o $@ main_menu.o: main_menu.cpp $(CC) -c main_menu.cpp $(CFLAGS) -o $@ Network_menu_moc.cpp: Network_menu.h $(MOC) Network_menu.h -o Network_menu_moc.cpp Network_menu_moc.o: Network_menu_moc.cpp $(CC) -c Network_menu_moc.cpp $(CFLAGS) -o $@ Network_menu.o: Network_menu.cpp $(CC) -c Network_menu.cpp $(CFLAGS) -o $@ clssGeneric_moc.cpp: clssGeneric.h $(MOC) clssGeneric.h -o clssGeneric_moc.cpp clssGeneric_moc.o: clssGeneric_moc.cpp $(CC) -c clssGeneric_moc.cpp $(CFLAGS) -o $@ clssGeneric.o: clssGeneric.cpp $(CC) -c clssGeneric.cpp $(CFLAGS) -o $@ clssDNS_moc.cpp: clssDNS.h $(MOC) clssDNS.h -o clssDNS_moc.cpp clssDNS_moc.o: clssDNS_moc.cpp $(CC) -c clssDNS_moc.cpp $(CFLAGS) -o $@ clssDNS.o: clssDNS.cpp $(CC) -c clssDNS.cpp $(CFLAGS) -o $@ clssAlias_moc.cpp: clssAlias.h $(MOC) clssAlias.h -o clssAlias_moc.cpp clssAlias_moc.o: clssAlias_moc.cpp $(CC) -c clssAlias_moc.cpp $(CFLAGS) -o $@ clssAlias.o: clssAlias.cpp $(CC) -c clssAlias.cpp $(CFLAGS) -o $@ main_menu: $(MNU_OBJS) $(OTHER_OBJS) $(CC) $(MNU_OBJS) $(OTHER_OBJS) $(LIBS) -o $@ # ---------------------------------------------------------------- 3.5. °³¼±µÇ¾î¾ßÇÒ ³»¿ë ¿©·¯°¡Áö·Î ¸ðÀÚ¶õ ÇÁ·Î±×·¥À» ¿Ã¸° °Í¿¡ ´ëÇØ ÀÌ ±ÛÀ» Àд ºÐµé²² ÁË¼Û ½º·¯¿î ¸¶À½»ÓÀÌ´Ù. Qt Library´Â Á¦°øÇÏ´Â Library¸¸À» ½á¼­ ±×´ÙÁö ¹®Á¦µÉ °ÍÀº ¾ø°ÚÁö¸¸, ÆÄÀÏ󸮷çƾ¿¡ ÀÖ¾î ¸ðµç procedureµéÀÌ ÃÖÀûÈ­µÇ¾îÀÖ´Ù°í´Â ¸»¾¸µå¸± ¼ö ¾ø´Ù. Áï, À̽ļº°ú È®À强¹®Á¦¸¦ °í·ÁÇÑ´Ù ÇÏ´õ¶óµµ ¸Þ¸ð¸®¿¡ ´ëÇÑ ¿Ïº® ÇÑ ÃÖÀûÈ­¸¦ ÀÌ·çÁö´Â ¸øÇß´Ù. ¶ÇÇÑ ³×Æ®¿öũ󸮷çƾ¿¡ ´ëÇؼ­µµ ÀÏÁ¤ÇÑ ÆÐÅÏ È¤Àº ÀÏ°ü¼ºÀִ ó¸®¸¦ ÇØÁÖ¾î¾ß Çϴµ¥ ±×·¸°Ô ÇÏÁö ¸øÇß´Ù. Áï, ¸®´ª½º ¹öÁ¯ÀÌ ¾÷µ¥ÀÌÆ®µÉ ¶§¸¶´Ù ³×Æ®¿öÅ© °ü·Ã ÆÄÀϵéÀÇ FormatÀÌ º¯ÇÒ Áöµµ ¸ð¸£´Â »óȲ¿¡¼­ À̸¦ ÅëÇÕ°ü¸®ÇÏ´Â ÆÄÀÏÀÇ »ý¼º¾øÀÌ °¢ ÆÄÀϵéÀ» Á÷Á¢ Á¢±ÙÇÑ´Ù´Â °ÍÀº ¿©·¯¸ð·Î ºñÇÕ¸®ÀûÀÎ ¹æ¹ýÀÌ´Ù. ÇÊÀÚ´Â Á÷Àå¿¡¼­ °³¹ßÇß´ø ÇÁ·Î±×·¥ÀÇ ÀϺÎÀÎ ÀÌ ³×Æ®¿öÅ© 󸮺κÐÀ» »ç Á¤»ó ±×´ë·Î ÀÌ°÷¿¡ ¿Ã·Á³õÁö´Â ¾Ê¾Ò´Ù. ÀÌÁ¡ ¹«Ã´ Á˼۽º·´°Ô »ý°¢ÇÑ´Ù. À§ÀÇ SourceµéÀº ÇÊÀÚ°¡ (ÁÖ)¾ÆÀÌžÀÇ Topflash project°³¹ß Ãʱ⿡ ¸¸µç ÃÖÀûÈ­ÀÛ¾÷ÀÌ µÇÁö¾ÊÀº SourceµéÀÌ´Ù. Áö±Ý Çг»¸ÁÂÊ¿¡ °ø±ÞµÇ¾î ³ª°¡°í ÀÖ´Â »óÇ°À̹ǷΠÃÖÀûÈ­ µÇ¾îÀÖ´Â SourceµéÀº ±»ÀÌ ½ÆÁö ¸øÇßÀ½À» ¾Ë·Áµå¸®¸ç ÀÌÁ¡ ´Ù½ÃÇѹø Á˼۽º·´°Ô »ý °¢ÇÑ´Ù. ÀÌ Sourceµé¿¡¼­ÀÇ °³¼±¹æÇâÀº ¹Ù·Î À§¿¡¼­ ¸»¾¸µå¸°¹Ù¿Í °°À¸¸ç ÀÌ ÇÁ·Î Á§Æ®¿¡ ´ëÇÑ ¸ðµç À̾߱â´Â ¿©±â¼­ ¸¶Ä¡°Ú´Ù. 4. ÇÁ·ÎÁ§Æ®¸¦ ¸¶Ä¡°í... ÀÌ ÇÁ·ÎÁ§Æ®´Â Ãʹݿ¡µµ ¸»¾¸µå·ÈµíÀÌ Qt 1.44¸¦ »ç¿ëÇÑ Network ó¸® ÇÁ·Î Á§Æ®ÀÔ´Ï´Ù. ±×¸®°í ÀÌ´Â Á¦°¡ Áö±Ý ¸ö´ã°í ÀÖ´Â (ÁÖ)¾ÆÀÌžÀÇ »ý»êÁ¦Ç°±º Áß ÇϳªÀÎ TopmanagerXÀÇ ÀϺκп¡ ´ëÇÑ-Ãʱâ ÃÖÀûÈ­µÇÁö ¾ÊÀº- ÀÚ·áÀ̱⠵µ ÇÕ´Ï´Ù. Qt¸¦ ±â¹ÝÀ¸·Î ¾î¶² ÇÁ·ÎÁ§Æ®¸¦ °³¹ßÇÏ°í ±×¸¦ »óÇ°È­½ÃÄÑ ÆÇ ¸ÅÇϱâ À§Çؼ­´Â Gtk¿Í´Â ´Ù¸£°Ô trolltech¿Í License°è¾àÀ» ¸Î¾î¾ßÇÑ´Ù´Â °ÍÀº ¸ðµÎµé ¾Æ½Ã¸®¶ó »ý°¢ÇÕ´Ï´Ù. ±×·¡¼­ Àú´Â µÇµµ·ÏÀ̸é Qtº¸´Ù´Â Gtk±â¹ÝÀÇ Application°³¹ßÀ» ±ÇÇص帮°í ½Í½À´Ï´Ù. ÃÖ±Ù¿¡ ¿Í¼­¾ß Qt°¡ ¾à°£¾¿ Àα⸦ ²ø°í ÀÖÁö¸¸ Open Source°³³ä ÀÇ ³ëÇÏ¿ì°¡ »ó´çÈ÷ ÃàÀûµÇ¾îÀÖ´Â Gtkº¸´Ù´Â ¹ßÀü °¡´É¼ºÀÌ Àû´Ù°í °¨È÷ »ý °¢ÇÕ´Ï´Ù. Qt´Â, ¹°·Ð GUI¿¡ ´ëÇؼ­ Gtkº¸´Ù ¿ùµîÇÕ´Ï´Ù¸¸ GtkÀÇ Open Source »ç»ó(?)Àº Á¶¸¸°£ QtÀÇ GUI¸¦ ¾Õ¼³ °ÍÀ̶ó »ý°¢ÇÕ´Ï´Ù. ±×¸®°í ¶Ç Borland»ç¿¡¼­ Delphi¸¦ ¸®´ª½º¿¡ Æ÷ÆÃÇÏ°í ÀÖ´Ù´Â »ç½ÇÀº ¿©·¯ ºÐµéµµ Àß ¾Æ½Ã¸®¶ó ¹Ï½À´Ï´Ù. ÀÌ·¸µí ¸®´ª½º¿ë °³¹ß ÅøµéÀÌ »ó´çÈ÷ ¸¹ÀÌ ¸¸µé¾îÁö°í ÀÖÀ¸¹Ç·Î GUI°³¹ß¿¡¼­ ȹ±âÀûÀ¸·Î µÎ°¢À» ³ªÅ¸³¾ ¸¸ÇÑ °³¹ßÅøÀÌ ¸ÓÁö¾Ê¾Æ ³ª¿Ã °ÍÀ̶ó »ý°¢ÇÕ´Ï´Ù. °¢¼³ÇÏ°í, ¾î·µç ´ÙÀ½¿¡ ±ÛÀ» ¿Ã¸± ¶§´Â MailServer Setting°ú WebServer Setting¿¡ ´ëÇØ Gtk Library¸¦ ½á¼­ ±¸ÇöÇÑ Project¸¦ ¿Ã¸®°Ú½À´Ï´Ù. ¸ðÀÚ¶õ ±Û ³¡±îÁö ÀоîÁּż­ Áø½ÉÀ¸·Î °¨»çµå¸³´Ï´Ù.