scrap-code-book

dust box scratch programing code
Sat Nov 12
Fri Nov 11
Sun Jun 27

Windows & SSID

// original is here.

// http://d.hatena.ne.jp/silphire/20090113/1231827336

#include <windows.h>

#include <iostream>

#include <string>

#include <Wlanapi.h>

#pragma comment(lib, “wlanapi.lib”)

bool displayESSID(HANDLE handle, GUID *guid)

{

  unsigned i;

  WLAN_AVAILABLE_NETWORK_LIST *networkList;

  if(WlanGetAvailableNetworkList(handle, guid, WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES, NULL, &networkList) != ERROR_SUCCESS)

    return false;

  std::cout « “Num Available: ” « networkList->dwNumberOfItems « std::endl;

  for(i = 0; i < networkList->dwNumberOfItems; ++i) {

    WLAN_AVAILABLE_NETWORK *nw = &networkList->Network[i];

    std::wcout « nw->strProfileName « std::endl;

    DOT11_SSID *ssid = &nw->dot11Ssid;

    std::cout « ”  ” « std::string((char *)ssid->ucSSID, (size_t)ssid->uSSIDLength);

    std::cout « ” : ” « nw->wlanSignalQuality « std::endl;

    std::cout « “——————————” « std::endl;

  }

  WlanFreeMemory(networkList);

  return true;

}

int main(void)

{

  unsigned i;

  DWORD err, ver;

  HANDLE hClient;

  WLAN_INTERFACE_INFO_LIST *ifList;

  if((err = WlanOpenHandle(WLAN_API_MAKE_VERSION(1, 0), NULL, &ver, &hClient)) != ERROR_SUCCESS) {

    std::cerr « “error: WlanOpenHandle()” « std::endl;

    return 1;

  }

  // get interface list

  WlanEnumInterfaces(hClient, NULL, &ifList);

  std::cout « ifList->dwNumberOfItems « ” interfaces found” « std::endl;

  for(i = 0; i < ifList->dwNumberOfItems; ++i) {

    WLAN_INTERFACE_INFO wii = ifList->InterfaceInfo[i];

    std::wcout « wii.strInterfaceDescription « std::endl;

    displayESSID(hClient, &wii.InterfaceGuid);

  }

  WlanFreeMemory(ifList);

  WlanCloseHandle(hClient, NULL);

  return 0;

}

Wed Jun 16

boost spirit BOOST_FUSION_ADAPT_STRUCT test

#include <iostream>

#include <boost/config/warning_disable.hpp>

#include <boost/spirit/include/qi.hpp>

#include <boost/spirit/include/phoenix_operator.hpp>

#include <boost/fusion/include/adapt_struct.hpp>

#include <boost/fusion/include/io.hpp>

#include <boost/format.hpp>

namespace client {

  namespace qi = boost::spirit::qi;

  namespace ascii = boost::spirit::ascii;

  struct xsd_datatypes_ : qi::symbols<char,std::string> {

    xsd_datatypes_() {

      add

        (  ”string”, “s:string”       )

        (    ”bool”, “s:boolean”      )

        (   “float”, “s:float”        )

        (  ”double”, “s:double”       )

        (   “short”, “s:short”        )

        (  ”ushort”, “s:unsignedShort”)

        (     “int”, “s:integer”      )

        (    ”uint”, “s:unsignedInt”  )

        (    ”long”, “s:long”         )

        (   “ulong”, “s:ulong”        )

        (    ”date”, “s:date”         )

        (“dateTime”, “s:dateTime”     )

        (  ”binary”, “s:base64Binary” )

      ;

    }

  } xsd_datatypes;

  struct inout_ : qi::symbols<char,int> {

    inout_() {

      add

        (  ”in”, 0 )

        ( “out”, 1 )

      ;

    }

  } inout;

  struct soap_arg {

    int         inout_;

    std::string type_;

    std::string name_;

  };

}

BOOST_FUSION_ADAPT_STRUCT(

    client::soap_arg,

    // メンバ変数の並び順ではなく、構文解析の順番に合わせる事が大切

    (std::string, type_  )

    (        int, inout_ )

    (std::string, name_  )

)

namespace client {

  template <typename Iterator>

  struct soap_arg_parser : qi::grammar<Iterator, soap_arg(), ascii::space_type> {

    soap_arg_parser() : soap_arg_parser::base_type(expression) {

      ioval %= inout;

      tname %= xsd_datatypes;

      sname %= ascii::char_(“a-zA-Z”) » *ascii::char_(“a-zA-Z0-9”);

      expression = tname » ‘[’ » ioval » ‘]’ » sname;

    }

    qi::rule<Iterator, int(), ascii::space_type> ioval;

    qi::rule<Iterator, std::string(), ascii::space_type> sname, tname;

    qi::rule<Iterator, soap_arg(), ascii::space_type> expression;

  };

  struct soap_func {

    std::string name_;

    std::vector<soap_arg>  args_;

  };

}

int main( int argc, char* argv[] ) {

  const char* arg = “int [out] hoge39 “;

  typedef client::soap_arg_parser<const char*>  arg_parser;

  arg_parser g;

  client::soap_arg sarg;

  bool res = phrase_parse( arg, arg + strlen(arg), g, boost::spirit::ascii::space, sarg );

  if( res ) {

    std::cout « “success ” « std::endl;

    std::cout « sarg.inout_ « “,” « sarg.type_ « “,” « sarg.name_ « std::endl;

  } else {

    std::cout « “fault   ” « std::endl;

  }

  return 0;

}

Tue Jun 15

pod copy test

#include <vector>

#include <string>

#include <iostream>

#include <algorithm>

struct foo {

  std::vector<std::string> a_;

  std::vector<std::string> b_;

};

  void show_s( const std::string& s ) { std::cout « s « “,”; }

int main() {

  foo f;

  f.a_.push_back( “a” );

  f.a_.push_back( “b” );

  f.a_.push_back( “c” );

  f.b_.push_back( “d” );

  f.b_.push_back( “e” );

  f.b_.push_back( “f” );

  foo g = f;

  std::for_each( g.a_.begin(), g.a_.end(), show_s );

  std::for_each( g.b_.begin(), g.b_.end(), show_s );

  return 0;

}

Sat May 8

久しぶり

#include <iostream>

int main() {

  std::cout « “hello world.” « std::endl;

  return 0;

}

おおーーーーーーーっ!!!!スペースOKやん???

Thu Jul 31

プロローグ・・・そして・・・エンディング?

実験的に書いては捨てるコードをタンブラーにスクラップしてみようと思い立ったが、スペースは勝手にトリムされる仕様のようだ。 &nbsp;使えないし、<blockquote>は、ちょっと違うでしょ!

・・・という事で、早くもエンディングを迎えてしまった。

書かないけど python は絶対に無理です・・・。 さようなら・・・。

これはどう?…<div>も消されるのかよっ!

これならどうだ~

しかし、改行が…だめぽ・・・

インデント

インデント

インデント

つか、スペース使えないの痛すぎ・・・